mirror of
https://github.com/openclaw/clawhub.git
synced 2026-08-14 00:47:57 +00:00
fix: improve Safari compatibility and auth callbacks
This commit is contained in:
Vendored
+2
-4
@@ -1,7 +1,5 @@
|
||||
import { type inferred } from "arktype";
|
||||
export declare const PLATFORM_SKILL_LICENSE: "MIT-0";
|
||||
export declare const PLATFORM_SKILL_LICENSE_NAME: "MIT No Attribution";
|
||||
export declare const PLATFORM_SKILL_LICENSE_SUMMARY: "Free to use, modify, and redistribute. No attribution required.";
|
||||
export declare const PLATFORM_SKILL_LICENSE_URL: "https://spdx.org/licenses/MIT-0.html";
|
||||
import { PLATFORM_SKILL_LICENSE, PLATFORM_SKILL_LICENSE_NAME, PLATFORM_SKILL_LICENSE_SUMMARY, PLATFORM_SKILL_LICENSE_URL } from "./licenseConstants.js";
|
||||
export { PLATFORM_SKILL_LICENSE, PLATFORM_SKILL_LICENSE_NAME, PLATFORM_SKILL_LICENSE_SUMMARY, PLATFORM_SKILL_LICENSE_URL, };
|
||||
export declare const SkillPlatformLicenseSchema: import("arktype/internal/variants/string.ts").StringType<"MIT-0", {}>;
|
||||
export type SkillPlatformLicense = (typeof SkillPlatformLicenseSchema)[inferred];
|
||||
|
||||
Vendored
+2
-4
@@ -1,7 +1,5 @@
|
||||
import { type } from "arktype";
|
||||
export const PLATFORM_SKILL_LICENSE = "MIT-0";
|
||||
export const PLATFORM_SKILL_LICENSE_NAME = "MIT No Attribution";
|
||||
export const PLATFORM_SKILL_LICENSE_SUMMARY = "Free to use, modify, and redistribute. No attribution required.";
|
||||
export const PLATFORM_SKILL_LICENSE_URL = "https://spdx.org/licenses/MIT-0.html";
|
||||
import { PLATFORM_SKILL_LICENSE, PLATFORM_SKILL_LICENSE_NAME, PLATFORM_SKILL_LICENSE_SUMMARY, PLATFORM_SKILL_LICENSE_URL, } from "./licenseConstants.js";
|
||||
export { PLATFORM_SKILL_LICENSE, PLATFORM_SKILL_LICENSE_NAME, PLATFORM_SKILL_LICENSE_SUMMARY, PLATFORM_SKILL_LICENSE_URL, };
|
||||
export const SkillPlatformLicenseSchema = type('"MIT-0"');
|
||||
//# sourceMappingURL=license.js.map
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,IAAI,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,oBAA6B,CAAC;AACzE,MAAM,CAAC,MAAM,8BAA8B,GACzC,iEAA0E,CAAC;AAC7E,MAAM,CAAC,MAAM,0BAA0B,GAAG,sCAA+C,CAAC;AAE1F,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC"}
|
||||
{"version":3,"file":"license.js","sourceRoot":"","sources":["../src/license.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,IAAI,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,8BAA8B,EAC9B,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EACtB,2BAA2B,EAC3B,8BAA8B,EAC9B,0BAA0B,GAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export declare const PLATFORM_SKILL_LICENSE: "MIT-0";
|
||||
export declare const PLATFORM_SKILL_LICENSE_NAME: "MIT No Attribution";
|
||||
export declare const PLATFORM_SKILL_LICENSE_SUMMARY: "Free to use, modify, and redistribute. No attribution required.";
|
||||
export declare const PLATFORM_SKILL_LICENSE_URL: "https://spdx.org/licenses/MIT-0.html";
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export const PLATFORM_SKILL_LICENSE = 'MIT-0';
|
||||
export const PLATFORM_SKILL_LICENSE_NAME = 'MIT No Attribution';
|
||||
export const PLATFORM_SKILL_LICENSE_SUMMARY = 'Free to use, modify, and redistribute. No attribution required.';
|
||||
export const PLATFORM_SKILL_LICENSE_URL = 'https://spdx.org/licenses/MIT-0.html';
|
||||
//# sourceMappingURL=licenseConstants.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"licenseConstants.js","sourceRoot":"","sources":["../src/licenseConstants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAgB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,oBAA6B,CAAC;AACzE,MAAM,CAAC,MAAM,8BAA8B,GACzC,iEAA0E,CAAC;AAC7E,MAAM,CAAC,MAAM,0BAA0B,GAAG,sCAA+C,CAAC"}
|
||||
@@ -11,6 +11,18 @@
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"default": "./dist/index.js"
|
||||
},
|
||||
"./licenseConstants": {
|
||||
"types": "./dist/licenseConstants.d.ts",
|
||||
"default": "./dist/licenseConstants.js"
|
||||
},
|
||||
"./routes": {
|
||||
"types": "./dist/routes.d.ts",
|
||||
"default": "./dist/routes.js"
|
||||
},
|
||||
"./textFiles": {
|
||||
"types": "./dist/textFiles.d.ts",
|
||||
"default": "./dist/textFiles.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import { type inferred, type } from "arktype";
|
||||
import {
|
||||
PLATFORM_SKILL_LICENSE,
|
||||
PLATFORM_SKILL_LICENSE_NAME,
|
||||
PLATFORM_SKILL_LICENSE_SUMMARY,
|
||||
PLATFORM_SKILL_LICENSE_URL,
|
||||
} from "./licenseConstants.js";
|
||||
|
||||
export const PLATFORM_SKILL_LICENSE = "MIT-0" as const;
|
||||
export const PLATFORM_SKILL_LICENSE_NAME = "MIT No Attribution" as const;
|
||||
export const PLATFORM_SKILL_LICENSE_SUMMARY =
|
||||
"Free to use, modify, and redistribute. No attribution required." as const;
|
||||
export const PLATFORM_SKILL_LICENSE_URL = "https://spdx.org/licenses/MIT-0.html" as const;
|
||||
export {
|
||||
PLATFORM_SKILL_LICENSE,
|
||||
PLATFORM_SKILL_LICENSE_NAME,
|
||||
PLATFORM_SKILL_LICENSE_SUMMARY,
|
||||
PLATFORM_SKILL_LICENSE_URL,
|
||||
};
|
||||
|
||||
export const SkillPlatformLicenseSchema = type('"MIT-0"');
|
||||
export type SkillPlatformLicense = (typeof SkillPlatformLicenseSchema)[inferred];
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
export const PLATFORM_SKILL_LICENSE = 'MIT-0' as const;
|
||||
export const PLATFORM_SKILL_LICENSE_NAME = 'MIT No Attribution' as const;
|
||||
export const PLATFORM_SKILL_LICENSE_SUMMARY =
|
||||
'Free to use, modify, and redistribute. No attribution required.' as const;
|
||||
export const PLATFORM_SKILL_LICENSE_URL = 'https://spdx.org/licenses/MIT-0.html' as const;
|
||||
@@ -2,7 +2,7 @@
|
||||
import { render, waitFor } from "@testing-library/react";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { getAuthErrorSnapshot, clearAuthError } from "../lib/useAuthError";
|
||||
import { AuthCodeHandler } from "./AppProviders";
|
||||
import { AuthCodeHandler, AuthErrorHandler } from "./AppProviders";
|
||||
|
||||
const signInMock = vi.fn();
|
||||
|
||||
@@ -72,3 +72,67 @@ describe("AuthCodeHandler", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("AuthErrorHandler", () => {
|
||||
beforeEach(() => {
|
||||
signInMock.mockReset();
|
||||
clearAuthError();
|
||||
window.history.replaceState(null, "", "/sign-in");
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
clearAuthError();
|
||||
});
|
||||
|
||||
it("does nothing when there is no auth error in the URL", () => {
|
||||
render(<AuthErrorHandler />);
|
||||
|
||||
expect(getAuthErrorSnapshot()).toBeNull();
|
||||
});
|
||||
|
||||
it("surfaces provider errors from the URL and strips them", async () => {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
"/sign-in?error=access_denied&error_description=Account%20banned&next=%2Fdashboard#section",
|
||||
);
|
||||
|
||||
render(<AuthErrorHandler />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getAuthErrorSnapshot()).toBe("Account banned");
|
||||
});
|
||||
|
||||
expect(`${window.location.pathname}${window.location.search}${window.location.hash}`).toBe(
|
||||
"/sign-in?next=%2Fdashboard#section",
|
||||
);
|
||||
});
|
||||
|
||||
it("falls back to the provider error when there is no description", async () => {
|
||||
window.history.replaceState(null, "", "/sign-in?error=access_denied");
|
||||
|
||||
render(<AuthErrorHandler />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getAuthErrorSnapshot()).toBe("access_denied");
|
||||
});
|
||||
});
|
||||
|
||||
it("falls back to the provider error when the description is blank", async () => {
|
||||
window.history.replaceState(
|
||||
null,
|
||||
"",
|
||||
"/sign-in?error=access_denied&error_description=%20%20%20",
|
||||
);
|
||||
|
||||
render(<AuthErrorHandler />);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(getAuthErrorSnapshot()).toBe("access_denied");
|
||||
});
|
||||
|
||||
expect(`${window.location.pathname}${window.location.search}${window.location.hash}`).toBe(
|
||||
"/sign-in",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,10 +48,40 @@ export function AuthCodeHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getPendingAuthError() {
|
||||
if (typeof window === "undefined") return null;
|
||||
const url = new URL(window.location.href);
|
||||
const description =
|
||||
url.searchParams.get("error_description")?.trim() || url.searchParams.get("error")?.trim();
|
||||
if (!description) return null;
|
||||
url.searchParams.delete("error");
|
||||
url.searchParams.delete("error_description");
|
||||
return {
|
||||
description,
|
||||
relativeUrl: `${url.pathname}${url.search}${url.hash}`,
|
||||
};
|
||||
}
|
||||
|
||||
export function AuthErrorHandler() {
|
||||
const handledErrorRef = useRef<string | null>(null);
|
||||
useEffect(() => {
|
||||
const pending = getPendingAuthError();
|
||||
if (!pending) return;
|
||||
if (handledErrorRef.current === pending.description) return;
|
||||
handledErrorRef.current = pending.description;
|
||||
|
||||
window.history.replaceState(null, "", pending.relativeUrl);
|
||||
setAuthError(pending.description);
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function AppProviders({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<ConvexAuthProvider client={convex} shouldHandleCode={false}>
|
||||
<AuthCodeHandler />
|
||||
<AuthErrorHandler />
|
||||
<UserBootstrap />
|
||||
{children}
|
||||
</ConvexAuthProvider>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { ClawdisSkillMetadata } from "clawhub-schema";
|
||||
import { Link } from "@tanstack/react-router";
|
||||
import {
|
||||
type ClawdisSkillMetadata,
|
||||
PLATFORM_SKILL_LICENSE,
|
||||
PLATFORM_SKILL_LICENSE_SUMMARY,
|
||||
} from "clawhub-schema";
|
||||
} from "clawhub-schema/licenseConstants";
|
||||
import { Package } from "lucide-react";
|
||||
import type { Doc, Id } from "../../convex/_generated/dataModel";
|
||||
import { getSkillBadges } from "../lib/badges";
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { ClawdisSkillMetadata } from "clawhub-schema";
|
||||
import {
|
||||
type ClawdisSkillMetadata,
|
||||
PLATFORM_SKILL_LICENSE,
|
||||
PLATFORM_SKILL_LICENSE_SUMMARY,
|
||||
PLATFORM_SKILL_LICENSE_URL,
|
||||
} from "clawhub-schema";
|
||||
} from "clawhub-schema/licenseConstants";
|
||||
import { formatInstallCommand, formatInstallLabel } from "./skillDetailUtils";
|
||||
|
||||
type SkillInstallCardProps = {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type {
|
||||
PackageCompatibility,
|
||||
PackageVerificationSummary,
|
||||
} from "clawhub-schema";
|
||||
import { ApiRoutes } from "clawhub-schema";
|
||||
import { ApiRoutes } from "clawhub-schema/routes";
|
||||
import { getRequiredRuntimeEnv, getRuntimeEnv } from "./runtimeEnv";
|
||||
|
||||
export type PackageListItem = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { TEXT_FILE_EXTENSION_SET } from "clawhub-schema";
|
||||
import { TEXT_FILE_EXTENSION_SET } from "clawhub-schema/textFiles";
|
||||
import { gunzipSync, unzipSync } from "fflate";
|
||||
|
||||
const TEXT_TYPES = new Map([
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isTextContentType, TEXT_FILE_EXTENSION_SET } from "clawhub-schema";
|
||||
import { isTextContentType, TEXT_FILE_EXTENSION_SET } from "clawhub-schema/textFiles";
|
||||
import { getUserFacingConvexError } from "./convexError";
|
||||
|
||||
export async function uploadFile(uploadUrl: string, file: File) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
PLATFORM_SKILL_LICENSE,
|
||||
PLATFORM_SKILL_LICENSE_NAME,
|
||||
PLATFORM_SKILL_LICENSE_SUMMARY,
|
||||
} from "clawhub-schema";
|
||||
} from "clawhub-schema/licenseConstants";
|
||||
import { useAction, useMutation, useQuery } from "convex/react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import semver from "semver";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { isTextContentType, TEXT_FILE_EXTENSION_SET } from "clawhub-schema";
|
||||
import { isTextContentType, TEXT_FILE_EXTENSION_SET } from "clawhub-schema/textFiles";
|
||||
import { getUserFacingConvexError } from "../../lib/convexError";
|
||||
|
||||
export async function uploadFile(uploadUrl: string, file: File) {
|
||||
|
||||
@@ -70,6 +70,8 @@ const config = defineConfig({
|
||||
viteReact(),
|
||||
],
|
||||
build: {
|
||||
// Keep the shipped client bundle parseable in Safari/WebKit.
|
||||
target: "safari15",
|
||||
chunkSizeWarningLimit: 900,
|
||||
rollupOptions: {
|
||||
onwarn: handleRollupWarning,
|
||||
|
||||
Reference in New Issue
Block a user