From c29586b105fb03d84b394e2029baaebfad5c7685 Mon Sep 17 00:00:00 2001 From: Nikos Douvlis Date: Fri, 17 Oct 2025 20:55:03 +0300 Subject: [PATCH 01/23] wip --- eslint.config.mjs | 1 + package.json | 5 +- packages/astro/src/stores/external.ts | 3 +- packages/backend/src/util/shared.ts | 10 +- packages/chrome-extension/tsconfig.json | 4 +- .../src/core/resources/BillingSubscription.ts | 2 + .../src/react/hooks/use-password.hook.ts | 3 +- packages/elements/src/react/sign-in/root.tsx | 1 + packages/elements/src/react/sign-up/root.tsx | 1 + packages/shared/package.json | 64 +- packages/shared/src/__tests__/color.spec.ts | 2 +- .../shared/src/__tests__/color.test.ts.bak | 2 +- .../shared/src/__tests__/deriveState.spec.ts | 2 +- .../src/__tests__/loadClerkJsScript.spec.ts | 2 +- .../shared/src/__tests__/organization.spec.ts | 2 +- packages/shared/src/alternativePhoneCode.ts | 2 +- packages/shared/src/authorization-errors.ts | 4 +- packages/shared/src/authorization.ts | 4 +- packages/shared/src/clerkEventBus.ts | 2 +- packages/shared/src/color.ts | 2 +- packages/shared/src/deriveState.ts | 2 +- packages/shared/src/errors/clerkApiError.ts | 3 +- .../src/errors/clerkApiResponseError.ts | 2 +- packages/shared/src/errors/parseError.ts | 2 +- packages/shared/src/jwtPayloadParser.ts | 2 +- packages/shared/src/keys.ts | 2 +- packages/shared/src/loadClerkJsScript.ts | 2 +- packages/shared/src/oauth.ts | 2 +- packages/shared/src/organization.ts | 2 +- packages/shared/src/pathMatcher.ts | 2 +- packages/shared/src/react/commerce.tsx | 4 +- packages/shared/src/react/contexts.tsx | 26 +- .../createBillingPaginatedHook.spec.tsx | 2 +- .../hooks/__tests__/useCheckout.type.spec.ts | 6 +- .../hooks/createBillingPaginatedHook.tsx | 2 +- .../shared/src/react/hooks/useCheckout.ts | 4 +- packages/shared/src/react/hooks/useClerk.ts | 2 +- .../src/react/hooks/useOrganization.tsx | 2 +- .../src/react/hooks/useOrganizationList.tsx | 2 +- .../src/react/hooks/usePaymentAttempts.tsx | 2 +- .../src/react/hooks/usePaymentMethods.tsx | 2 +- packages/shared/src/react/hooks/usePlans.tsx | 2 +- .../src/react/hooks/useReverification.ts | 2 +- packages/shared/src/react/hooks/useSession.ts | 2 +- .../shared/src/react/hooks/useSessionList.ts | 2 +- .../shared/src/react/hooks/useStatements.tsx | 2 +- .../src/react/hooks/useSubscription.tsx | 2 +- packages/shared/src/react/hooks/useUser.ts | 2 +- packages/shared/src/react/types.ts | 2 +- packages/shared/src/router/router.ts | 2 +- packages/shared/src/saml.ts | 2 +- packages/shared/src/telemetry/collector.ts | 2 +- .../src/telemetry/events/component-mounted.ts | 2 +- .../telemetry/events/framework-metadata.ts | 2 +- .../src/telemetry/events/method-called.ts | 2 +- .../src/telemetry/events/theme-usage.ts | 2 +- packages/shared/src/telemetry/throttler.ts | 2 +- .../src => shared/src/types}/apiKeys.ts | 0 .../src/types}/apiKeysSettings.ts | 0 .../src => shared/src/types}/appearance.ts | 48 + .../src => shared/src/types}/attributes.ts | 0 .../src => shared/src/types}/authConfig.ts | 0 .../src => shared/src/types}/authObject.ts | 0 .../src => shared/src/types}/backupCode.ts | 0 packages/shared/src/types/billing.ts | 839 +++++++++++++++++ .../{types/src => shared/src/types}/clerk.ts | 0 .../{types/src => shared/src/types}/client.ts | 0 .../src/types}/commerceSettings.ts | 0 .../src/types}/customMenuItems.ts | 0 .../src => shared/src/types}/customPages.ts | 0 .../src => shared/src/types}/deletedObject.ts | 0 .../src => shared/src/types}/displayConfig.ts | 0 .../src => shared/src/types}/elementIds.ts | 0 .../src => shared/src/types}/emailAddress.ts | 0 .../src/types}/enterpriseAccount.ts | 0 .../src => shared/src/types}/environment.ts | 0 .../{types/src => shared/src/types}/errors.ts | 0 .../src/types}/externalAccount.ts | 0 .../src => shared/src/types}/factors.ts | 0 .../{types/src => shared/src/types}/hooks.ts | 0 .../src/types}/identificationLink.ts | 0 .../src => shared/src/types}/identifiers.ts | 0 .../{types/src => shared/src/types}/image.ts | 0 packages/shared/src/types/index.ts | 84 +- .../src => shared/src/types}/instance.ts | 0 packages/shared/src/types/json copy.ts | 859 ++++++++++++++++++ packages/shared/src/types/json.ts | 859 ++++++++++++++++++ .../{types/src => shared/src/types}/jwt.ts | 0 .../{types/src => shared/src/types}/jwtv2.ts | 0 .../{types/src => shared/src/types}/key.ts | 0 .../src => shared/src/types}/localization.ts | 0 .../src => shared/src/types}/multiDomain.ts | 0 .../{types/src => shared/src/types}/oauth.ts | 0 .../src => shared/src/types}/organization.ts | 0 .../src/types}/organizationDomain.ts | 0 .../src/types}/organizationInvitation.ts | 1 + .../src/types}/organizationMembership.ts | 0 .../types}/organizationMembershipRequest.ts | 0 .../src/types}/organizationSettings.ts | 0 .../src/types}/organizationSuggestion.ts | 0 .../src => shared/src/types}/pagination.ts | 0 .../src => shared/src/types}/passkey.ts | 0 .../src => shared/src/types}/passwords.ts | 0 .../src => shared/src/types}/permission.ts | 0 .../src/types}/phoneCodeChannel.ts | 0 .../src => shared/src/types}/phoneNumber.ts | 0 .../src => shared/src/types}/protect.ts | 0 .../src => shared/src/types}/redirects.ts | 0 .../src => shared/src/types}/resource.ts | 0 .../{types/src => shared/src/types}/role.ts | 0 .../{types/src => shared/src/types}/router.ts | 0 .../src/types}/runtime-values.ts | 0 .../{types/src => shared/src/types}/saml.ts | 0 .../src => shared/src/types}/samlAccount.ts | 0 .../src/types}/samlConnection.ts | 0 .../src => shared/src/types}/session.ts | 0 .../src/types}/sessionVerification.ts | 0 .../{types/src => shared/src/types}/signIn.ts | 0 .../src => shared/src/types}/signInCommon.ts | 0 .../src => shared/src/types}/signInFuture.ts | 0 .../{types/src => shared/src/types}/signUp.ts | 0 .../src => shared/src/types}/signUpCommon.ts | 0 .../src => shared/src/types}/signUpFuture.ts | 0 .../src => shared/src/types}/snapshots.ts | 0 .../{types/src => shared/src/types}/ssr.ts | 0 .../{types/src => shared/src/types}/state.ts | 0 .../src => shared/src/types}/strategies.ts | 0 .../src => shared/src/types}/telemetry.ts | 0 .../{types/src => shared/src/types}/theme.ts | 0 .../{types/src => shared/src/types}/token.ts | 0 .../{types/src => shared/src/types}/totp.ts | 0 .../{types/src => shared/src/types}/user.ts | 4 + .../src/types}/userOrganizationInvitation.ts | 0 .../src => shared/src/types}/userSettings.ts | 0 .../src/types/utils copy.ts} | 0 packages/shared/src/types/utils.ts | 118 +++ .../src => shared/src/types}/verification.ts | 0 .../src => shared/src/types}/waitlist.ts | 0 .../{types/src => shared/src/types}/web3.ts | 0 .../src => shared/src/types}/web3Wallet.ts | 0 packages/shared/src/web3.ts | 2 +- .../src/workerTimers/createWorkerTimers.ts | 4 +- .../src/workerTimers/workerTimers.built.ts | 20 + packages/shared/tsconfig.declarations.json | 11 - packages/shared/tsconfig.json | 28 +- packages/shared/tsdown.config.mts | 45 + packages/shared/tsup.config.ts | 52 -- packages/shared/vitest.config.mts | 2 +- packages/themes/package.json | 2 +- packages/themes/src/createTheme.ts | 2 +- packages/themes/tsconfig.build.json | 23 - packages/themes/tsconfig.json | 23 +- packages/themes/tsup.config.ts | 1 - packages/types/package.json | 29 +- packages/types/src/index.d.mts | 9 + packages/types/src/index.d.ts | 9 + packages/types/src/index.js | 1 + packages/types/src/index.mjs | 1 + packages/types/src/index.ts | 83 -- packages/types/tsconfig.build.json | 20 - packages/types/tsconfig.declarations.json | 11 - packages/types/tsconfig.json | 20 - packages/types/tsup.config.ts | 16 - .../vue/src/components/CheckoutButton.vue | 2 +- .../vue/src/components/PlanDetailsButton.vue | 2 +- packages/vue/src/components/SignInButton.vue | 2 +- .../components/SignInWithMetamaskButton.vue | 2 +- packages/vue/src/components/SignOutButton.vue | 2 +- packages/vue/src/components/SignUpButton.vue | 2 +- .../components/SubscriptionDetailsButton.vue | 2 +- .../vue/src/components/controlComponents.ts | 4 +- .../ui-components/CreateOrganization.vue | 2 +- .../components/ui-components/GoogleOneTap.vue | 2 +- .../ui-components/OrganizationList.vue | 2 +- .../OrganizationProfile.vue | 2 +- .../OrganizationSwitcher.vue | 2 +- .../components/ui-components/PricingTable.vue | 2 +- .../src/components/ui-components/SignIn.vue | 2 +- .../src/components/ui-components/SignUp.vue | 2 +- .../components/ui-components/UserAvatar.vue | 2 +- .../ui-components/UserButton/UserButton.vue | 2 +- .../ui-components/UserProfile/UserProfile.vue | 2 +- .../src/components/ui-components/Waitlist.vue | 2 +- packages/vue/src/composables/useAuth.ts | 2 +- .../vue/src/composables/useOrganization.ts | 2 +- packages/vue/src/composables/useSession.ts | 2 +- .../vue/src/composables/useSessionList.ts | 2 +- packages/vue/src/composables/useSignIn.ts | 2 +- packages/vue/src/composables/useSignUp.ts | 2 +- packages/vue/src/composables/useUser.ts | 2 +- packages/vue/src/experimental.ts | 8 +- packages/vue/src/plugin.ts | 9 +- packages/vue/src/types.ts | 2 +- packages/vue/src/utils/updateClerkOptions.ts | 2 +- packages/vue/src/utils/useClerkLoaded.ts | 2 +- packages/vue/src/utils/useCustomMenuItems.ts | 2 +- packages/vue/src/utils/useCustomPages.ts | 2 +- pnpm-lock.yaml | 424 +++++++-- pnpm-workspace.yaml | 2 + 199 files changed, 3479 insertions(+), 481 deletions(-) rename packages/{types/src => shared/src/types}/apiKeys.ts (100%) rename packages/{types/src => shared/src/types}/apiKeysSettings.ts (100%) rename packages/{types/src => shared/src/types}/appearance.ts (99%) rename packages/{types/src => shared/src/types}/attributes.ts (100%) rename packages/{types/src => shared/src/types}/authConfig.ts (100%) rename packages/{types/src => shared/src/types}/authObject.ts (100%) rename packages/{types/src => shared/src/types}/backupCode.ts (100%) create mode 100644 packages/shared/src/types/billing.ts rename packages/{types/src => shared/src/types}/clerk.ts (100%) rename packages/{types/src => shared/src/types}/client.ts (100%) rename packages/{types/src => shared/src/types}/commerceSettings.ts (100%) rename packages/{types/src => shared/src/types}/customMenuItems.ts (100%) rename packages/{types/src => shared/src/types}/customPages.ts (100%) rename packages/{types/src => shared/src/types}/deletedObject.ts (100%) rename packages/{types/src => shared/src/types}/displayConfig.ts (100%) rename packages/{types/src => shared/src/types}/elementIds.ts (100%) rename packages/{types/src => shared/src/types}/emailAddress.ts (100%) rename packages/{types/src => shared/src/types}/enterpriseAccount.ts (100%) rename packages/{types/src => shared/src/types}/environment.ts (100%) rename packages/{types/src => shared/src/types}/errors.ts (100%) rename packages/{types/src => shared/src/types}/externalAccount.ts (100%) rename packages/{types/src => shared/src/types}/factors.ts (100%) rename packages/{types/src => shared/src/types}/hooks.ts (100%) rename packages/{types/src => shared/src/types}/identificationLink.ts (100%) rename packages/{types/src => shared/src/types}/identifiers.ts (100%) rename packages/{types/src => shared/src/types}/image.ts (100%) rename packages/{types/src => shared/src/types}/instance.ts (100%) create mode 100644 packages/shared/src/types/json copy.ts rename packages/{types/src => shared/src/types}/jwt.ts (100%) rename packages/{types/src => shared/src/types}/jwtv2.ts (100%) rename packages/{types/src => shared/src/types}/key.ts (100%) rename packages/{types/src => shared/src/types}/localization.ts (100%) rename packages/{types/src => shared/src/types}/multiDomain.ts (100%) rename packages/{types/src => shared/src/types}/oauth.ts (100%) rename packages/{types/src => shared/src/types}/organization.ts (100%) rename packages/{types/src => shared/src/types}/organizationDomain.ts (100%) rename packages/{types/src => shared/src/types}/organizationInvitation.ts (99%) rename packages/{types/src => shared/src/types}/organizationMembership.ts (100%) rename packages/{types/src => shared/src/types}/organizationMembershipRequest.ts (100%) rename packages/{types/src => shared/src/types}/organizationSettings.ts (100%) rename packages/{types/src => shared/src/types}/organizationSuggestion.ts (100%) rename packages/{types/src => shared/src/types}/pagination.ts (100%) rename packages/{types/src => shared/src/types}/passkey.ts (100%) rename packages/{types/src => shared/src/types}/passwords.ts (100%) rename packages/{types/src => shared/src/types}/permission.ts (100%) rename packages/{types/src => shared/src/types}/phoneCodeChannel.ts (100%) rename packages/{types/src => shared/src/types}/phoneNumber.ts (100%) rename packages/{types/src => shared/src/types}/protect.ts (100%) rename packages/{types/src => shared/src/types}/redirects.ts (100%) rename packages/{types/src => shared/src/types}/resource.ts (100%) rename packages/{types/src => shared/src/types}/role.ts (100%) rename packages/{types/src => shared/src/types}/router.ts (100%) rename packages/{types/src => shared/src/types}/runtime-values.ts (100%) rename packages/{types/src => shared/src/types}/saml.ts (100%) rename packages/{types/src => shared/src/types}/samlAccount.ts (100%) rename packages/{types/src => shared/src/types}/samlConnection.ts (100%) rename packages/{types/src => shared/src/types}/session.ts (100%) rename packages/{types/src => shared/src/types}/sessionVerification.ts (100%) rename packages/{types/src => shared/src/types}/signIn.ts (100%) rename packages/{types/src => shared/src/types}/signInCommon.ts (100%) rename packages/{types/src => shared/src/types}/signInFuture.ts (100%) rename packages/{types/src => shared/src/types}/signUp.ts (100%) rename packages/{types/src => shared/src/types}/signUpCommon.ts (100%) rename packages/{types/src => shared/src/types}/signUpFuture.ts (100%) rename packages/{types/src => shared/src/types}/snapshots.ts (100%) rename packages/{types/src => shared/src/types}/ssr.ts (100%) rename packages/{types/src => shared/src/types}/state.ts (100%) rename packages/{types/src => shared/src/types}/strategies.ts (100%) rename packages/{types/src => shared/src/types}/telemetry.ts (100%) rename packages/{types/src => shared/src/types}/theme.ts (100%) rename packages/{types/src => shared/src/types}/token.ts (100%) rename packages/{types/src => shared/src/types}/totp.ts (100%) rename packages/{types/src => shared/src/types}/user.ts (99%) rename packages/{types/src => shared/src/types}/userOrganizationInvitation.ts (100%) rename packages/{types/src => shared/src/types}/userSettings.ts (100%) rename packages/{types/src/utils.ts => shared/src/types/utils copy.ts} (100%) rename packages/{types/src => shared/src/types}/verification.ts (100%) rename packages/{types/src => shared/src/types}/waitlist.ts (100%) rename packages/{types/src => shared/src/types}/web3.ts (100%) rename packages/{types/src => shared/src/types}/web3Wallet.ts (100%) create mode 100644 packages/shared/src/workerTimers/workerTimers.built.ts delete mode 100644 packages/shared/tsconfig.declarations.json create mode 100644 packages/shared/tsdown.config.mts delete mode 100644 packages/shared/tsup.config.ts delete mode 100644 packages/themes/tsconfig.build.json create mode 100644 packages/types/src/index.d.mts create mode 100644 packages/types/src/index.d.ts create mode 100644 packages/types/src/index.js create mode 100644 packages/types/src/index.mjs delete mode 100644 packages/types/src/index.ts delete mode 100644 packages/types/tsconfig.build.json delete mode 100644 packages/types/tsconfig.declarations.json delete mode 100644 packages/types/tsconfig.json delete mode 100644 packages/types/tsup.config.ts diff --git a/eslint.config.mjs b/eslint.config.mjs index 8ad097edd9e..a311e9e2ca6 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -120,6 +120,7 @@ export default tseslint.config([ 'packages/backend/src/runtime/**/*', 'packages/clerk-js/rspack.config.js', 'packages/shared/src/compiled/path-to-regexp/index.js', + 'packages/shared/tsdown.config.mjs', ], }, { diff --git a/package.json b/package.json index 158d0ed4a27..4289dce6253 100644 --- a/package.json +++ b/package.json @@ -135,9 +135,11 @@ "react": "catalog:react", "react-dom": "catalog:react", "rimraf": "6.0.1", + "rolldown": "catalog:repo", "statuses": "^1.5.0", "tree-kill": "^1.2.2", "ts-jest": "29.2.5", + "tsdown": "catalog:repo", "tsup": "catalog:repo", "turbo": "^2.5.4", "turbo-ignore": "^2.5.4", @@ -165,9 +167,6 @@ "overrides": { "jest": "29.7.0", "jest-snapshot-prettier": "npm:prettier@^3.5.3" - }, - "patchedDependencies": { - "yalc@1.0.0-pre.53": "patches/yalc@1.0.0-pre.53.patch" } } } diff --git a/packages/astro/src/stores/external.ts b/packages/astro/src/stores/external.ts index 5805088f0c9..c5516fd5da1 100644 --- a/packages/astro/src/stores/external.ts +++ b/packages/astro/src/stores/external.ts @@ -1,5 +1,6 @@ import { deriveState } from '@clerk/shared/deriveState'; import { eventMethodCalled } from '@clerk/shared/telemetry'; +import type { SignedInSessionResource } from '@clerk/types'; import { batched, computed, onMount, type Store } from 'nanostores'; import { $clerk, $csrState, $initialState } from './internal'; @@ -51,7 +52,7 @@ export const $userStore = computed([$authStore], auth => auth.user); * @example * $sessionStore.subscribe((session) => console.log(session.id)) */ -export const $sessionStore = computed([$authStore], auth => auth.session); +export const $sessionStore = computed([$authStore], auth => auth.session as SignedInSessionResource | null | undefined); /** * A client side store that is populated after clerk-js has loaded. diff --git a/packages/backend/src/util/shared.ts b/packages/backend/src/util/shared.ts index f588a1d57fa..6df64247a52 100644 --- a/packages/backend/src/util/shared.ts +++ b/packages/backend/src/util/shared.ts @@ -1,13 +1,13 @@ -export { addClerkPrefix, getScriptUrl, getClerkJsMajorVersionOrTag } from '@clerk/shared/url'; -export { retry } from '@clerk/shared/retry'; +export { deprecated, deprecatedProperty } from '@clerk/shared/deprecated'; export { + getCookieSuffix, + getSuffixedCookieName, isDevelopmentFromSecretKey, isProductionFromSecretKey, parsePublishableKey, - getCookieSuffix, - getSuffixedCookieName, } from '@clerk/shared/keys'; -export { deprecated, deprecatedProperty } from '@clerk/shared/deprecated'; +export { retry } from '@clerk/shared/retry'; +export { addClerkPrefix, getClerkJsMajorVersionOrTag, getScriptUrl } from '@clerk/shared/url'; import { buildErrorThrower } from '@clerk/shared/error'; import { createDevOrStagingUrlCache } from '@clerk/shared/keys'; diff --git a/packages/chrome-extension/tsconfig.json b/packages/chrome-extension/tsconfig.json index 35a77fee5e1..904ccc83d88 100644 --- a/packages/chrome-extension/tsconfig.json +++ b/packages/chrome-extension/tsconfig.json @@ -9,8 +9,8 @@ "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, - "module": "esnext", - "moduleResolution": "node", + "module": "nodenext", + "moduleResolution": "nodenext", "resolveJsonModule": true, "isolatedModules": true, "jsx": "react-jsx", diff --git a/packages/clerk-js/src/core/resources/BillingSubscription.ts b/packages/clerk-js/src/core/resources/BillingSubscription.ts index 3c9e973336f..1e0a9f9c846 100644 --- a/packages/clerk-js/src/core/resources/BillingSubscription.ts +++ b/packages/clerk-js/src/core/resources/BillingSubscription.ts @@ -60,6 +60,7 @@ export class BillingSubscription extends BaseResource implements BillingSubscrip export class BillingSubscriptionItem extends BaseResource implements BillingSubscriptionItemResource { id!: string; + paymentMethodId!: string; plan!: BillingPlan; planPeriod!: BillingSubscriptionPlanPeriod; status!: BillingSubscriptionStatus; @@ -86,6 +87,7 @@ export class BillingSubscriptionItem extends BaseResource implements BillingSubs } this.id = data.id; + this.paymentMethodId = data.payment_method_id; this.plan = new BillingPlan(data.plan); this.planPeriod = data.plan_period; this.status = data.status; diff --git a/packages/elements/src/react/hooks/use-password.hook.ts b/packages/elements/src/react/hooks/use-password.hook.ts index 01516ae9116..b011e52b05a 100644 --- a/packages/elements/src/react/hooks/use-password.hook.ts +++ b/packages/elements/src/react/hooks/use-password.hook.ts @@ -1,6 +1,6 @@ import { useClerk } from '@clerk/shared/react'; +import type { PasswordSettingsData, PasswordValidation } from '@clerk/shared/types'; import { noop } from '@clerk/shared/utils'; -import type { PasswordSettingsData, PasswordValidation } from '@clerk/types'; import * as React from 'react'; import type { ErrorCodeOrTuple } from '../utils/generate-password-error-text'; @@ -21,6 +21,7 @@ type UsePasswordCallbacks = { export const usePassword = (callbacks?: UsePasswordCallbacks) => { const clerk = useClerk(); + // @ts-expect-error - ignore error for now const passwordSettings = clerk.__unstable__environment?.userSettings.passwordSettings as PasswordSettingsData; const { disable_hibp, min_zxcvbn_strength, show_zxcvbn, ...config } = passwordSettings || {}; diff --git a/packages/elements/src/react/sign-in/root.tsx b/packages/elements/src/react/sign-in/root.tsx index 77ad01cd870..5dc45196d48 100644 --- a/packages/elements/src/react/sign-in/root.tsx +++ b/packages/elements/src/react/sign-in/root.tsx @@ -41,6 +41,7 @@ function SignInFlowProvider({ children, exampleMode, fallback, isRootPath }: Sig const cb = () => { const evt: SignInRouterInitEvent = { type: 'INIT', + // @ts-expect-error - ignore error for now clerk, exampleMode, formRef, diff --git a/packages/elements/src/react/sign-up/root.tsx b/packages/elements/src/react/sign-up/root.tsx index dd21232525e..0b0ae38a809 100644 --- a/packages/elements/src/react/sign-up/root.tsx +++ b/packages/elements/src/react/sign-up/root.tsx @@ -41,6 +41,7 @@ function SignUpFlowProvider({ children, exampleMode, fallback, isRootPath }: Sig const cb = () => { const evt: SignUpRouterInitEvent = { type: 'INIT', + // @ts-expect-error - ignore error for now clerk, exampleMode, formRef, diff --git a/packages/shared/package.json b/packages/shared/package.json index fea8b58ec42..90dfa43721b 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -12,75 +12,76 @@ "exports": { ".": { "import": { - "types": "./dist/index.d.mts", - "default": "./dist/index.mjs" + "types": "./dist/runtime/index.d.mts", + "default": "./dist/runtime/index.mjs" }, "require": { - "types": "./dist/index.d.ts", - "default": "./dist/index.js" + "types": "./dist/runtime/index.d.ts", + "default": "./dist/runtime/index.js" } }, "./*": { "import": { - "types": "./dist/*.d.mts", - "default": "./dist/*.mjs" + "types": "./dist/runtime/*.d.mts", + "default": "./dist/runtime/*.mjs" }, "require": { - "types": "./dist/*.d.ts", - "default": "./dist/*.js" + "types": "./dist/runtime/*.d.ts", + "default": "./dist/runtime/*.js" } }, "./react": { "import": { - "types": "./dist/react/index.d.mts", - "default": "./dist/react/index.mjs" + "types": "./dist/runtime/react/index.d.mts", + "default": "./dist/runtime/react/index.mjs" }, "require": { - "types": "./dist/react/index.d.ts", - "default": "./dist/react/index.js" + "types": "./dist/runtime/react/index.d.ts", + "default": "./dist/runtime/react/index.js" } }, "./utils": { "import": { - "types": "./dist/utils/index.d.mts", - "default": "./dist/utils/index.mjs" + "types": "./dist/runtime/utils/index.d.mts", + "default": "./dist/runtime/utils/index.mjs" }, "require": { - "types": "./dist/utils/index.d.ts", - "default": "./dist/utils/index.js" + "types": "./dist/runtime/utils/index.d.ts", + "default": "./dist/runtime/utils/index.js" } }, "./workerTimers": { "import": { - "types": "./dist/workerTimers/index.d.mts", - "default": "./dist/workerTimers/index.mjs" + "types": "./dist/runtime/workerTimers/index.d.mts", + "default": "./dist/runtime/workerTimers/index.mjs" }, "require": { - "types": "./dist/workerTimers/index.d.ts", - "default": "./dist/workerTimers/index.js" + "types": "./dist/runtime/workerTimers/index.d.ts", + "default": "./dist/runtime/workerTimers/index.js" } }, "./dom": { "import": { - "types": "./dist/dom/index.d.mts", - "default": "./dist/dom/index.mjs" + "types": "./dist/runtime/dom/index.d.mts", + "default": "./dist/runtime/dom/index.mjs" }, "require": { - "types": "./dist/dom/index.d.ts", - "default": "./dist/dom/index.js" + "types": "./dist/runtime/dom/index.d.ts", + "default": "./dist/runtime/dom/index.js" } }, "./types": { "import": { - "types": "./dist/types/index.d.mts" + "types": "./dist/types/index.d.mts", + "default": "./dist/types/index.mjs" }, "require": { - "types": "./dist/types/index.d.ts" + "types": "./dist/types/index.d.ts", + "default": "./dist/types/index.js" } }, "./package.json": "./package.json" }, - "main": "./dist/index.js", "files": [ "dist", "scripts", @@ -135,11 +136,10 @@ "types" ], "scripts": { - "build": "tsup", + "build": "tsdown", "postbuild": "node ../../scripts/subpath-workaround.mjs shared", - "build:declarations": "tsc -p tsconfig.declarations.json", "clean": "rimraf ./dist", - "dev": "tsup --watch", + "dev": "tsdown --watch src", "dev:publish": "pnpm dev -- --env.publish", "format": "node ../../scripts/format-package.mjs", "format:check": "node ../../scripts/format-package.mjs --check", @@ -153,7 +153,7 @@ "test:coverage": "vitest --collectCoverage && open coverage/lcov-report/index.html" }, "dependencies": { - "@clerk/types": "workspace:^", + "csstype": "3.1.3", "dequal": "2.0.3", "glob-to-regexp": "0.4.1", "js-cookie": "3.0.5", @@ -166,7 +166,7 @@ "@types/glob-to-regexp": "0.4.4", "@types/js-cookie": "3.0.6", "cross-fetch": "^4.1.0", - "esbuild": "0.25.0" + "rolldown": "catalog:repo" }, "peerDependencies": { "react": "catalog:peer-react", diff --git a/packages/shared/src/__tests__/color.spec.ts b/packages/shared/src/__tests__/color.spec.ts index 0b54661b9ce..13bf59baebd 100644 --- a/packages/shared/src/__tests__/color.spec.ts +++ b/packages/shared/src/__tests__/color.spec.ts @@ -1,7 +1,7 @@ -import type { Color } from '@clerk/types'; import { describe, expect, it } from 'vitest'; import { colorToSameTypeString, hexStringToRgbaColor, stringToHslaColor, stringToSameTypeColor } from '../color'; +import type { Color } from '../types'; describe('stringToHslaColor(color)', function () { const hsla = { h: 195, s: 1, l: 0.5 }; diff --git a/packages/shared/src/__tests__/color.test.ts.bak b/packages/shared/src/__tests__/color.test.ts.bak index 7dc19e3d8c1..aa0d71b2adb 100644 --- a/packages/shared/src/__tests__/color.test.ts.bak +++ b/packages/shared/src/__tests__/color.test.ts.bak @@ -1,4 +1,4 @@ -import type { Color } from '@clerk/types'; +import type { Color } from '../types'; import { colorToSameTypeString, hexStringToRgbaColor, stringToHslaColor, stringToSameTypeColor } from '../color'; diff --git a/packages/shared/src/__tests__/deriveState.spec.ts b/packages/shared/src/__tests__/deriveState.spec.ts index 2f2dd22ee99..b1445cf9ade 100644 --- a/packages/shared/src/__tests__/deriveState.spec.ts +++ b/packages/shared/src/__tests__/deriveState.spec.ts @@ -1,7 +1,7 @@ -import type { InitialState, Resources } from '@clerk/types'; import { describe, expect, it } from 'vitest'; import { deriveState } from '../deriveState'; +import type { InitialState, Resources } from '../types'; describe('deriveState', () => { const mockInitialState = { diff --git a/packages/shared/src/__tests__/loadClerkJsScript.spec.ts b/packages/shared/src/__tests__/loadClerkJsScript.spec.ts index d7b5d754d58..817fc9bedf1 100644 --- a/packages/shared/src/__tests__/loadClerkJsScript.spec.ts +++ b/packages/shared/src/__tests__/loadClerkJsScript.spec.ts @@ -139,7 +139,7 @@ describe('loadClerkJsScript(options)', () => { try { await loadPromise; - fail('Should have thrown error'); + throw new Error('Should have thrown error'); } catch (error) { expect(error).toBeInstanceOf(ClerkRuntimeError); expect((error as Error).message).toContain('Clerk: Failed to load Clerk'); diff --git a/packages/shared/src/__tests__/organization.spec.ts b/packages/shared/src/__tests__/organization.spec.ts index 6aa1dbba74c..c65ce07d8c3 100644 --- a/packages/shared/src/__tests__/organization.spec.ts +++ b/packages/shared/src/__tests__/organization.spec.ts @@ -1,5 +1,5 @@ -import type { OrganizationMembershipResource } from '@clerk/types'; import { describe, expect, it } from 'vitest'; +import type { OrganizationMembershipResource } from '../types'; import { getCurrentOrganizationMembership } from '../organization'; diff --git a/packages/shared/src/alternativePhoneCode.ts b/packages/shared/src/alternativePhoneCode.ts index 1ad01a913db..afdb1e8b4ac 100644 --- a/packages/shared/src/alternativePhoneCode.ts +++ b/packages/shared/src/alternativePhoneCode.ts @@ -1,4 +1,4 @@ -import type { PhoneCodeChannelData } from '@clerk/types'; +import type { PhoneCodeChannelData } from './types'; export const ALTERNATIVE_PHONE_CODE_PROVIDERS: PhoneCodeChannelData[] = [ { diff --git a/packages/shared/src/authorization-errors.ts b/packages/shared/src/authorization-errors.ts index 9caa20411d2..bf1d754e170 100644 --- a/packages/shared/src/authorization-errors.ts +++ b/packages/shared/src/authorization-errors.ts @@ -1,4 +1,4 @@ -import type { ReverificationConfig } from '@clerk/types'; +import type { ReverificationConfig } from './types'; type ClerkError = { clerk_error: T; @@ -44,4 +44,4 @@ const isReverificationHint = (result: any): result is ReturnType>; type AuthorizationOptions = { @@ -341,4 +341,4 @@ const resolveAuthState = ({ } }; -export { createCheckAuthorization, validateReverificationConfig, resolveAuthState, splitByScope }; +export { createCheckAuthorization, resolveAuthState, splitByScope, validateReverificationConfig }; diff --git a/packages/shared/src/clerkEventBus.ts b/packages/shared/src/clerkEventBus.ts index bdf9bdfa73c..9773a1f31bf 100644 --- a/packages/shared/src/clerkEventBus.ts +++ b/packages/shared/src/clerkEventBus.ts @@ -1,4 +1,4 @@ -import type { ClerkEventPayload } from '@clerk/types'; +import type { ClerkEventPayload } from './types'; import { createEventBus } from './eventBus'; diff --git a/packages/shared/src/color.ts b/packages/shared/src/color.ts index 3bb94b6422f..e3c7b733c86 100644 --- a/packages/shared/src/color.ts +++ b/packages/shared/src/color.ts @@ -1,4 +1,4 @@ -import type { Color, HslaColor, RgbaColor, TransparentColor } from '@clerk/types'; +import type { Color, HslaColor, RgbaColor, TransparentColor } from './types'; const IS_HEX_COLOR_REGEX = /^#?([A-F0-9]{6}|[A-F0-9]{3})$/i; diff --git a/packages/shared/src/deriveState.ts b/packages/shared/src/deriveState.ts index 4508970fd35..7b84fb42d2c 100644 --- a/packages/shared/src/deriveState.ts +++ b/packages/shared/src/deriveState.ts @@ -7,7 +7,7 @@ import type { Resources, SignedInSessionResource, UserResource, -} from '@clerk/types'; +} from './types'; /** * Derives authentication state based on the current rendering context (SSR or client-side). diff --git a/packages/shared/src/errors/clerkApiError.ts b/packages/shared/src/errors/clerkApiError.ts index 6b0b18eaf26..2ec91934187 100644 --- a/packages/shared/src/errors/clerkApiError.ts +++ b/packages/shared/src/errors/clerkApiError.ts @@ -1,5 +1,4 @@ -import type { ClerkAPIError as ClerkAPIErrorInterface, ClerkAPIErrorJSON } from '@clerk/types'; - +import type { ClerkAPIError as ClerkAPIErrorInterface, ClerkAPIErrorJSON } from '../types'; import { createErrorTypeGuard } from './createErrorTypeGuard'; export type ClerkApiErrorMeta = Record; diff --git a/packages/shared/src/errors/clerkApiResponseError.ts b/packages/shared/src/errors/clerkApiResponseError.ts index 149fd68803a..f1871ad477e 100644 --- a/packages/shared/src/errors/clerkApiResponseError.ts +++ b/packages/shared/src/errors/clerkApiResponseError.ts @@ -1,4 +1,4 @@ -import type { ClerkAPIErrorJSON, ClerkAPIResponseError as ClerkAPIResponseErrorInterface } from '@clerk/types'; +import type { ClerkAPIErrorJSON, ClerkAPIResponseError as ClerkAPIResponseErrorInterface } from '../types'; import { ClerkAPIError } from './clerkApiError'; import type { ClerkErrorParams } from './clerkError'; diff --git a/packages/shared/src/errors/parseError.ts b/packages/shared/src/errors/parseError.ts index d5803f53b75..9b784c7b111 100644 --- a/packages/shared/src/errors/parseError.ts +++ b/packages/shared/src/errors/parseError.ts @@ -1,4 +1,4 @@ -import type { ClerkAPIError as ClerkAPIErrorInterface, ClerkAPIErrorJSON } from '@clerk/types'; +import type { ClerkAPIError as ClerkAPIErrorInterface, ClerkAPIErrorJSON } from '../types'; import { ClerkAPIError } from './clerkApiError'; diff --git a/packages/shared/src/jwtPayloadParser.ts b/packages/shared/src/jwtPayloadParser.ts index f75b8d284d3..adfc416e59e 100644 --- a/packages/shared/src/jwtPayloadParser.ts +++ b/packages/shared/src/jwtPayloadParser.ts @@ -3,7 +3,7 @@ import type { OrganizationCustomPermissionKey, OrganizationCustomRoleKey, SharedSignedInAuthObjectProperties, -} from '@clerk/types'; +} from './types'; import { splitByScope } from './authorization'; diff --git a/packages/shared/src/keys.ts b/packages/shared/src/keys.ts index c327cc0a96d..3a03ae30597 100644 --- a/packages/shared/src/keys.ts +++ b/packages/shared/src/keys.ts @@ -1,4 +1,4 @@ -import type { PublishableKey } from '@clerk/types'; +import type { PublishableKey } from './types'; import { DEV_OR_STAGING_SUFFIXES, LEGACY_DEV_INSTANCE_SUFFIXES } from './constants'; import { isomorphicAtob } from './isomorphicAtob'; diff --git a/packages/shared/src/loadClerkJsScript.ts b/packages/shared/src/loadClerkJsScript.ts index 1cb78a1e68c..8b1c977bf0c 100644 --- a/packages/shared/src/loadClerkJsScript.ts +++ b/packages/shared/src/loadClerkJsScript.ts @@ -1,4 +1,4 @@ -import type { ClerkOptions, SDKMetadata, Without } from '@clerk/types'; +import type { ClerkOptions, SDKMetadata, Without } from './types'; import { buildErrorThrower, ClerkRuntimeError } from './error'; import { createDevOrStagingUrlCache, parsePublishableKey } from './keys'; diff --git a/packages/shared/src/oauth.ts b/packages/shared/src/oauth.ts index 7e809b6f0f4..4838b6bcbe9 100644 --- a/packages/shared/src/oauth.ts +++ b/packages/shared/src/oauth.ts @@ -1,4 +1,4 @@ -import type { OAuthProvider, OAuthProviderData, OAuthStrategy } from '@clerk/types'; +import type { OAuthProvider, OAuthProviderData, OAuthStrategy } from './types'; export const OAUTH_PROVIDERS: OAuthProviderData[] = [ { diff --git a/packages/shared/src/organization.ts b/packages/shared/src/organization.ts index 19f9ea8c3e5..12d8ea0689e 100644 --- a/packages/shared/src/organization.ts +++ b/packages/shared/src/organization.ts @@ -1,4 +1,4 @@ -import type { OrganizationMembershipResource } from '@clerk/types'; +import type { OrganizationMembershipResource } from './types'; /** * Finds the organization membership for a given organization ID from a list of memberships diff --git a/packages/shared/src/pathMatcher.ts b/packages/shared/src/pathMatcher.ts index f2f07097e3a..34c78840d1b 100644 --- a/packages/shared/src/pathMatcher.ts +++ b/packages/shared/src/pathMatcher.ts @@ -1,4 +1,4 @@ -import type { Autocomplete } from '@clerk/types'; +import type { Autocomplete } from './types'; import { pathToRegexp } from './pathToRegexp'; diff --git a/packages/shared/src/react/commerce.tsx b/packages/shared/src/react/commerce.tsx index f9b7b9335da..336f7449508 100644 --- a/packages/shared/src/react/commerce.tsx +++ b/packages/shared/src/react/commerce.tsx @@ -1,10 +1,10 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ -import type { BillingCheckoutResource, EnvironmentResource, ForPayerType } from '@clerk/types'; import type { Stripe, StripeElements } from '@stripe/stripe-js'; -import React, { type PropsWithChildren, ReactNode, useCallback, useEffect, useMemo, useState } from 'react'; +import React, { type PropsWithChildren, type ReactNode, useCallback, useEffect, useMemo, useState } from 'react'; import useSWR from 'swr'; import useSWRMutation from 'swr/mutation'; +import type { BillingCheckoutResource, EnvironmentResource, ForPayerType } from '../types'; import { createContextAndHook } from './hooks/createContextAndHook'; import type { useCheckout } from './hooks/useCheckout'; import { useClerk } from './hooks/useClerk'; diff --git a/packages/shared/src/react/contexts.tsx b/packages/shared/src/react/contexts.tsx index c54ea6f7a2a..8895a5e4f4b 100644 --- a/packages/shared/src/react/contexts.tsx +++ b/packages/shared/src/react/contexts.tsx @@ -1,5 +1,7 @@ 'use client'; +import type { PropsWithChildren } from 'react'; +import React from 'react'; import type { BillingSubscriptionPlanPeriod, ClerkOptions, @@ -9,9 +11,7 @@ import type { OrganizationResource, SignedInSessionResource, UserResource, -} from '@clerk/types'; -import type { PropsWithChildren } from 'react'; -import React from 'react'; +} from '../types'; import { SWRConfig } from './clerk-swr'; import { createContextAndHook } from './hooks/createContextAndHook'; @@ -103,19 +103,19 @@ Learn more: https://clerk.com/docs/components/clerk-provider`.trim(), } export { + __experimental_CheckoutProvider, + ClerkInstanceContext, ClientContext, - useClientContext, + OptionsContext, OrganizationProvider, + SessionContext, + useAssertWrappedByClerkProvider, + useCheckoutContext, + useClerkInstanceContext, + useClientContext, + useOptionsContext, useOrganizationContext, UserContext, - OptionsContext, - useOptionsContext, - useUserContext, - SessionContext, useSessionContext, - ClerkInstanceContext, - useClerkInstanceContext, - useCheckoutContext, - __experimental_CheckoutProvider, - useAssertWrappedByClerkProvider, + useUserContext, }; diff --git a/packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx b/packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx index da7b556adc0..f2ef1cd6636 100644 --- a/packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx +++ b/packages/shared/src/react/hooks/__tests__/createBillingPaginatedHook.spec.tsx @@ -1,4 +1,4 @@ -import type { ClerkResource } from '@clerk/types'; +import type { ClerkResource } from '@clerk/shared/types'; import { renderHook, waitFor } from '@testing-library/react'; import { beforeEach, describe, expect, it, vi } from 'vitest'; diff --git a/packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts b/packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts index 5480591804d..ea64128d37c 100644 --- a/packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts +++ b/packages/shared/src/react/hooks/__tests__/useCheckout.type.spec.ts @@ -1,3 +1,5 @@ +import { describe, expectTypeOf, it } from 'vitest'; + import type { __experimental_CheckoutCacheState, __experimental_CheckoutInstance, @@ -6,9 +8,7 @@ import type { ClerkAPIResponseError, ConfirmCheckoutParams, SetActiveNavigate, -} from '@clerk/types'; -import { describe, expectTypeOf, it } from 'vitest'; - +} from '../../../types'; import type { useCheckout } from '../useCheckout'; type UseCheckoutParameters = Parameters[0]; diff --git a/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx b/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx index 58b3e1ba1be..85a18cb9bcb 100644 --- a/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx +++ b/packages/shared/src/react/hooks/createBillingPaginatedHook.tsx @@ -1,4 +1,4 @@ -import type { ClerkPaginatedResponse, ClerkResource, EnvironmentResource, ForPayerType } from '@clerk/types'; +import type { ClerkPaginatedResponse, ClerkResource, EnvironmentResource, ForPayerType } from '../../types'; import { eventMethodCalled } from '../../telemetry/events/method-called'; import { diff --git a/packages/shared/src/react/hooks/useCheckout.ts b/packages/shared/src/react/hooks/useCheckout.ts index 9bdfcc45970..537f52dfee9 100644 --- a/packages/shared/src/react/hooks/useCheckout.ts +++ b/packages/shared/src/react/hooks/useCheckout.ts @@ -1,10 +1,10 @@ +import { useMemo, useSyncExternalStore } from 'react'; import type { __experimental_CheckoutCacheState, __experimental_CheckoutInstance, BillingCheckoutResource, SetActiveNavigate, -} from '@clerk/types'; -import { useMemo, useSyncExternalStore } from 'react'; +} from '../../types'; import type { ClerkAPIResponseError } from '../..'; import type { __experimental_CheckoutProvider } from '../contexts'; diff --git a/packages/shared/src/react/hooks/useClerk.ts b/packages/shared/src/react/hooks/useClerk.ts index 87f36ca3c2c..3b259b5dbf5 100644 --- a/packages/shared/src/react/hooks/useClerk.ts +++ b/packages/shared/src/react/hooks/useClerk.ts @@ -1,4 +1,4 @@ -import type { LoadedClerk } from '@clerk/types'; +import type { LoadedClerk } from '../../types'; import { useAssertWrappedByClerkProvider, useClerkInstanceContext } from '../contexts'; diff --git a/packages/shared/src/react/hooks/useOrganization.tsx b/packages/shared/src/react/hooks/useOrganization.tsx index 16219412a3b..38c8b357f23 100644 --- a/packages/shared/src/react/hooks/useOrganization.tsx +++ b/packages/shared/src/react/hooks/useOrganization.tsx @@ -9,7 +9,7 @@ import type { OrganizationMembershipRequestResource, OrganizationMembershipResource, OrganizationResource, -} from '@clerk/types'; +} from '../../types'; import { getCurrentOrganizationMembership } from '../../organization'; import { eventMethodCalled } from '../../telemetry/events/method-called'; diff --git a/packages/shared/src/react/hooks/useOrganizationList.tsx b/packages/shared/src/react/hooks/useOrganizationList.tsx index 6cdc297c0f8..5dc663c09fa 100644 --- a/packages/shared/src/react/hooks/useOrganizationList.tsx +++ b/packages/shared/src/react/hooks/useOrganizationList.tsx @@ -9,7 +9,7 @@ import type { OrganizationSuggestionResource, SetActive, UserOrganizationInvitationResource, -} from '@clerk/types'; +} from '../../types'; import { eventMethodCalled } from '../../telemetry/events/method-called'; import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useUserContext } from '../contexts'; diff --git a/packages/shared/src/react/hooks/usePaymentAttempts.tsx b/packages/shared/src/react/hooks/usePaymentAttempts.tsx index f74ba4c09cc..46ffda33ca0 100644 --- a/packages/shared/src/react/hooks/usePaymentAttempts.tsx +++ b/packages/shared/src/react/hooks/usePaymentAttempts.tsx @@ -1,4 +1,4 @@ -import type { BillingPaymentResource, GetPaymentAttemptsParams } from '@clerk/types'; +import type { BillingPaymentResource, GetPaymentAttemptsParams } from '../../types'; import { useClerkInstanceContext } from '../contexts'; import { createBillingPaginatedHook } from './createBillingPaginatedHook'; diff --git a/packages/shared/src/react/hooks/usePaymentMethods.tsx b/packages/shared/src/react/hooks/usePaymentMethods.tsx index 2cfb7bbc3c9..d29ed890f95 100644 --- a/packages/shared/src/react/hooks/usePaymentMethods.tsx +++ b/packages/shared/src/react/hooks/usePaymentMethods.tsx @@ -1,4 +1,4 @@ -import type { BillingPaymentMethodResource, GetPaymentMethodsParams } from '@clerk/types'; +import type { BillingPaymentMethodResource, GetPaymentMethodsParams } from '../../types'; import { useOrganizationContext, useUserContext } from '../contexts'; import { createBillingPaginatedHook } from './createBillingPaginatedHook'; diff --git a/packages/shared/src/react/hooks/usePlans.tsx b/packages/shared/src/react/hooks/usePlans.tsx index 25ed68e6424..91a9fd751b9 100644 --- a/packages/shared/src/react/hooks/usePlans.tsx +++ b/packages/shared/src/react/hooks/usePlans.tsx @@ -1,4 +1,4 @@ -import type { BillingPlanResource, GetPlansParams } from '@clerk/types'; +import type { BillingPlanResource, GetPlansParams } from '../../types'; import { useClerkInstanceContext } from '../contexts'; import { createBillingPaginatedHook } from './createBillingPaginatedHook'; diff --git a/packages/shared/src/react/hooks/useReverification.ts b/packages/shared/src/react/hooks/useReverification.ts index dadbe438104..2fa27f67a41 100644 --- a/packages/shared/src/react/hooks/useReverification.ts +++ b/packages/shared/src/react/hooks/useReverification.ts @@ -1,5 +1,5 @@ -import type { Clerk, SessionVerificationLevel } from '@clerk/types'; import { useCallback, useRef } from 'react'; +import type { Clerk, SessionVerificationLevel } from '../../types'; import { validateReverificationConfig } from '../../authorization'; import { isReverificationHint, reverificationError } from '../../authorization-errors'; diff --git a/packages/shared/src/react/hooks/useSession.ts b/packages/shared/src/react/hooks/useSession.ts index 7427e53baf3..86f00be04e6 100644 --- a/packages/shared/src/react/hooks/useSession.ts +++ b/packages/shared/src/react/hooks/useSession.ts @@ -1,4 +1,4 @@ -import type { UseSessionReturn } from '@clerk/types'; +import type { UseSessionReturn } from '../../types'; import { eventMethodCalled } from '../../telemetry/events/method-called'; import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useSessionContext } from '../contexts'; diff --git a/packages/shared/src/react/hooks/useSessionList.ts b/packages/shared/src/react/hooks/useSessionList.ts index 6d0ee1b0bd1..1cd77ee3202 100644 --- a/packages/shared/src/react/hooks/useSessionList.ts +++ b/packages/shared/src/react/hooks/useSessionList.ts @@ -1,4 +1,4 @@ -import type { UseSessionListReturn } from '@clerk/types'; +import type { UseSessionListReturn } from '../../types'; import { eventMethodCalled } from '../../telemetry/events/method-called'; import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useClientContext } from '../contexts'; diff --git a/packages/shared/src/react/hooks/useStatements.tsx b/packages/shared/src/react/hooks/useStatements.tsx index 78817ffebc1..49a22670554 100644 --- a/packages/shared/src/react/hooks/useStatements.tsx +++ b/packages/shared/src/react/hooks/useStatements.tsx @@ -1,4 +1,4 @@ -import type { BillingStatementResource, GetStatementsParams } from '@clerk/types'; +import type { BillingStatementResource, GetStatementsParams } from '../../types'; import { useClerkInstanceContext } from '../contexts'; import { createBillingPaginatedHook } from './createBillingPaginatedHook'; diff --git a/packages/shared/src/react/hooks/useSubscription.tsx b/packages/shared/src/react/hooks/useSubscription.tsx index 53c48df8c08..2041fd3d96e 100644 --- a/packages/shared/src/react/hooks/useSubscription.tsx +++ b/packages/shared/src/react/hooks/useSubscription.tsx @@ -1,5 +1,5 @@ -import type { EnvironmentResource, ForPayerType } from '@clerk/types'; import { useCallback } from 'react'; +import type { EnvironmentResource, ForPayerType } from '../../types'; import { eventMethodCalled } from '../../telemetry/events'; import { useSWR } from '../clerk-swr'; diff --git a/packages/shared/src/react/hooks/useUser.ts b/packages/shared/src/react/hooks/useUser.ts index a25367b8c89..b229a2aa856 100644 --- a/packages/shared/src/react/hooks/useUser.ts +++ b/packages/shared/src/react/hooks/useUser.ts @@ -1,4 +1,4 @@ -import type { UseUserReturn } from '@clerk/types'; +import type { UseUserReturn } from '../../types'; import { eventMethodCalled } from '../../telemetry/events/method-called'; import { useAssertWrappedByClerkProvider, useClerkInstanceContext, useUserContext } from '../contexts'; diff --git a/packages/shared/src/react/types.ts b/packages/shared/src/react/types.ts index ddc2603fa59..98187e8bf4a 100644 --- a/packages/shared/src/react/types.ts +++ b/packages/shared/src/react/types.ts @@ -1,4 +1,4 @@ -import type { ClerkPaginatedResponse } from '@clerk/types'; +import type { ClerkPaginatedResponse } from '../types'; import type { ClerkAPIResponseError } from '../error'; diff --git a/packages/shared/src/router/router.ts b/packages/shared/src/router/router.ts index 69cd41eb159..7ecbc7c4b2a 100644 --- a/packages/shared/src/router/router.ts +++ b/packages/shared/src/router/router.ts @@ -1,4 +1,4 @@ -import type { ClerkHostRouter, RoutingMode } from '@clerk/types'; +import type { ClerkHostRouter, RoutingMode } from '../types'; import { isAbsoluteUrl, withLeadingSlash, withoutTrailingSlash } from '../url'; diff --git a/packages/shared/src/saml.ts b/packages/shared/src/saml.ts index 953006b3bd8..8627d160f05 100644 --- a/packages/shared/src/saml.ts +++ b/packages/shared/src/saml.ts @@ -1,4 +1,4 @@ -import type { SamlIdpMap } from '@clerk/types'; +import type { SamlIdpMap } from './types'; export const SAML_IDPS: SamlIdpMap = { saml_okta: { diff --git a/packages/shared/src/telemetry/collector.ts b/packages/shared/src/telemetry/collector.ts index 79b092e8ade..d0d792e8704 100644 --- a/packages/shared/src/telemetry/collector.ts +++ b/packages/shared/src/telemetry/collector.ts @@ -17,7 +17,7 @@ import type { TelemetryEvent, TelemetryEventRaw, TelemetryLogEntry, -} from '@clerk/types'; +} from '../types'; import { parsePublishableKey } from '../keys'; import { isTruthy } from '../underscore'; diff --git a/packages/shared/src/telemetry/events/component-mounted.ts b/packages/shared/src/telemetry/events/component-mounted.ts index 940f8a1a943..595100cc62f 100644 --- a/packages/shared/src/telemetry/events/component-mounted.ts +++ b/packages/shared/src/telemetry/events/component-mounted.ts @@ -1,4 +1,4 @@ -import type { TelemetryEventRaw } from '@clerk/types'; +import type { TelemetryEventRaw } from '../../types'; const EVENT_COMPONENT_MOUNTED = 'COMPONENT_MOUNTED'; const EVENT_COMPONENT_OPENED = 'COMPONENT_OPENED'; diff --git a/packages/shared/src/telemetry/events/framework-metadata.ts b/packages/shared/src/telemetry/events/framework-metadata.ts index 1a5f69e187e..d8a70b63a28 100644 --- a/packages/shared/src/telemetry/events/framework-metadata.ts +++ b/packages/shared/src/telemetry/events/framework-metadata.ts @@ -1,4 +1,4 @@ -import type { TelemetryEventRaw } from '@clerk/types'; +import type { TelemetryEventRaw } from '../../types'; const EVENT_FRAMEWORK_METADATA = 'FRAMEWORK_METADATA'; const EVENT_SAMPLING_RATE = 0.1; diff --git a/packages/shared/src/telemetry/events/method-called.ts b/packages/shared/src/telemetry/events/method-called.ts index 8258e0c6892..f22f21fd17f 100644 --- a/packages/shared/src/telemetry/events/method-called.ts +++ b/packages/shared/src/telemetry/events/method-called.ts @@ -1,4 +1,4 @@ -import type { TelemetryEventRaw } from '@clerk/types'; +import type { TelemetryEventRaw } from '../../types'; const EVENT_METHOD_CALLED = 'METHOD_CALLED'; const EVENT_SAMPLING_RATE = 0.1; diff --git a/packages/shared/src/telemetry/events/theme-usage.ts b/packages/shared/src/telemetry/events/theme-usage.ts index 0848bb81ced..dade8e68c61 100644 --- a/packages/shared/src/telemetry/events/theme-usage.ts +++ b/packages/shared/src/telemetry/events/theme-usage.ts @@ -1,4 +1,4 @@ -import type { Appearance, BaseTheme, TelemetryEventRaw } from '@clerk/types'; +import type { Appearance, BaseTheme, TelemetryEventRaw } from '../../types'; export const EVENT_THEME_USAGE = 'THEME_USAGE'; export const EVENT_SAMPLING_RATE = 1; diff --git a/packages/shared/src/telemetry/throttler.ts b/packages/shared/src/telemetry/throttler.ts index 9ed196783f6..04137b49af4 100644 --- a/packages/shared/src/telemetry/throttler.ts +++ b/packages/shared/src/telemetry/throttler.ts @@ -1,4 +1,4 @@ -import type { TelemetryEvent } from '@clerk/types'; +import type { TelemetryEvent } from '../types'; type TtlInMilliseconds = number; diff --git a/packages/types/src/apiKeys.ts b/packages/shared/src/types/apiKeys.ts similarity index 100% rename from packages/types/src/apiKeys.ts rename to packages/shared/src/types/apiKeys.ts diff --git a/packages/types/src/apiKeysSettings.ts b/packages/shared/src/types/apiKeysSettings.ts similarity index 100% rename from packages/types/src/apiKeysSettings.ts rename to packages/shared/src/types/apiKeysSettings.ts diff --git a/packages/types/src/appearance.ts b/packages/shared/src/types/appearance.ts similarity index 99% rename from packages/types/src/appearance.ts rename to packages/shared/src/types/appearance.ts index a36614fa0a1..b4f1d00c36e 100644 --- a/packages/types/src/appearance.ts +++ b/packages/shared/src/types/appearance.ts @@ -654,34 +654,41 @@ export type Elements = { export type Variables = { /** * The primary color used throughout the components. Set this to your brand color. + * * @default '#2F3037' */ colorPrimary?: CssColorOrScale; /** * The color of text appearing on top of an element that with a background color of {@link Variables.colorPrimary}, * eg: solid primary buttons. + * * @deprecated Use {@link Variables.colorPrimaryForeground} instead. + * * @default 'white' */ colorTextOnPrimaryBackground?: CssColor; /** * The color of text appearing on top of an element that with a background color of {@link Variables.colorPrimary}, * eg: solid primary buttons. + * * @default 'white' */ colorPrimaryForeground?: CssColor; /** * The color used to indicate errors or destructive actions. Set this to your brand's danger color. + * * @default '#EF4444' */ colorDanger?: CssColorOrScale; /** * The color used to indicate an action that completed successfully or a positive result. + * * @default '#22C543' */ colorSuccess?: CssColorOrScale; /** * The color used for potentially destructive actions or when the user's attention is required. + * * @default '#F36B16' */ colorWarning?: CssColorOrScale; @@ -689,17 +696,21 @@ export type Variables = { * The color that will be used as the neutral color for all the components. To achieve sufficient contrast, * light themes should be using dark shades ('black'), while dark themes should be using light shades ('white'). * This option applies to borders, backgrounds for hovered elements, hovered dropdown options etc. + * * @default 'black' */ colorNeutral?: CssColorOrAlphaScale; /** * The default text color. + * * @deprecated Use {@link Variables.colorForeground} instead. + * * @default '#212126' */ colorText?: CssColor; /** * The default text color. + * * @default 'inherit' */ colorForeground?: CssColor; @@ -711,65 +722,80 @@ export type Variables = { /** * The text color for elements of lower importance, eg: a subtitle text. * This color is a lighter shade of {@link Variables.colorText}. + * * @deprecated Use {@link Variables.colorMutedForeground} instead. + * * @default '#747686' */ colorTextSecondary?: CssColor; /** * The text color for elements of lower importance, eg: a subtitle text. * This color is a lighter shade of {@link Variables.colorText}. + * * @default '#747686' */ colorMutedForeground?: CssColor; /** * The background color for the card container. + * * @default 'white' */ colorBackground?: CssColor; /** * The default text color inside input elements. To customise the input background color instead, use {@link Variables.colorInputBackground}. + * * @deprecated Use {@link Variables.colorInputForeground} instead. + * * @default 'black' */ colorInputText?: CssColor; /** * The default text color inside input elements. To customise the input background color instead, use {@link Variables.colorInputBackground}. + * * @default 'black' */ colorInputForeground?: CssColor; /** * The background color for all input elements. + * * @deprecated Use {@link Variables.colorInput} instead. + * * @default 'white' */ colorInputBackground?: CssColor; /** * The background color for all input elements. + * * @default 'white' */ colorInput?: CssColor; /** * The color of the avatar shimmer + * * @default 'rgba(255, 255, 255, 0.36)' */ colorShimmer?: CssColor; /** * The color of the ring when an interactive element is focused rendered at 15% opacity. + * * @default {@link Variables.colorNeutral} at 15% opacity */ colorRing?: CssColor; /** * The base shadow color used in the components. + * * @default '#000000' */ colorShadow?: CssColor; /** * The base border color used in the components. + * * @default {@link Variables.colorNeutral} */ colorBorder?: CssColor; /** * The background color of the modal backdrop rendered at 73% opacity. + * * @default {@link Variables.colorNeutral} at 73% opacity */ colorModalBackdrop?: CssColor; @@ -777,7 +803,9 @@ export type Variables = { * The default font that will be used in all components. * This can be the name of a custom font loaded by your code or the name of a web-safe font ((@link WebSafeFont}) * If a specific fontFamily is not provided, the components will inherit the font of the parent element. + * * @default 'inherit' + * * @example * { fontFamily: 'Montserrat' } */ @@ -785,12 +813,14 @@ export type Variables = { /** * The default font that will be used in all buttons. See {@link Variables.fontFamily} for details. * If not provided, {@link Variables.fontFamily} will be used instead. + * * @default 'inherit' */ fontFamilyButtons?: FontFamily; /** * The value will be used as the base `md` to calculate all the other scale values (`xs`, `sm`, `lg` and `xl`). * By default, this value is relative to the root fontSize of the html element. + * * @default '0.8125rem' */ fontSize?: CssLengthUnit | FontSizeScale; @@ -798,6 +828,7 @@ export type Variables = { * The font weight the components will use. By default, the components will use the 400, 500, 600 and 700 weights * for normal, medium, semibold and bold text respectively. * You can override the default weights by passing a {@link FontWeightScale} object + * * @default { normal: 400, medium: 500, semibold: 600, bold: 700 }; */ fontWeight?: FontWeightScale; @@ -805,17 +836,21 @@ export type Variables = { * The size that will be used as the `md` base borderRadius value. This is used as the base to calculate the `sm`, `lg`, `xl`, * our components use. As a general rule, the bigger an element is, the larger its borderRadius is going to be. * eg: the Card element uses 'xl' + * * @default '0.375rem' */ borderRadius?: CssLengthUnit; /** * The base spacing unit that all margins, paddings and gaps between the elements are derived from. + * * @deprecated Use {@link Variables.spacing} instead. + * * @default '1rem' */ spacingUnit?: CssLengthUnit; /** * The base spacing that all margins, paddings and gaps between the elements are derived from. + * * @default '1rem' */ spacing?: CssLengthUnit; @@ -830,6 +865,7 @@ export type Theme = { * For further customisation, you can use the {@link Theme.layout}, {@link Theme.variables} and {@link Theme.elements} props. * * Supports both object-based themes and string-based themes: + * * @example * import { dark } from "@clerk/themes"; * appearance={{ theme: dark }} @@ -844,6 +880,7 @@ export type Theme = { * @deprecated Use `theme` instead. This property will be removed in a future version. * A theme used as the base theme for the components. * For further customisation, you can use the {@link Theme.layout}, {@link Theme.variables} and {@link Theme.elements} props. + * * @example * import { dark } from "@clerk/themes"; * appearance={{ baseTheme: dark }} @@ -879,6 +916,7 @@ export type Layout = { /** * Controls whether the logo will be rendered inside or outside the component card. * To customise the logo further, you can use {@link Appearance.elements} + * * @default inside */ logoPlacement?: 'inside' | 'outside' | 'none'; @@ -888,6 +926,7 @@ export type Layout = { * This option is helpful when you need to display different logos for different themes, * eg: white logo on dark themes, black logo on light themes * To customise the logo further, you can use {@link Appearance.elements} + * * @default undefined */ logoImageUrl?: string; @@ -896,6 +935,7 @@ export type Layout = { * usually found in the SignIn and SignUp components. * If a URL is provided, it will be used as the `href` of the link. * If a value is not passed in, the components will use the Home URL as set in the Clerk dashboard + * * @default undefined */ logoLinkUrl?: string; @@ -904,18 +944,21 @@ export type Layout = { * By default, the components will use block buttons if you have less than * 3 social providers enabled, otherwise icon buttons will be used. * To customise the social buttons further, you can use {@link Appearance.elements} + * * @default auto */ socialButtonsVariant?: 'auto' | 'iconButton' | 'blockButton'; /** * Controls whether the social buttons will be rendered above or below the card form. * To customise the social button container further, you can use {@link Appearance.elements} + * * @default 'top' */ socialButtonsPlacement?: 'top' | 'bottom'; /** * Controls whether the SignIn or SignUp forms will include optional fields. * You can make a field required or optional through the {@link https://dashboard.clerk.com|Clerk dashboard}. + * * @default true */ showOptionalFields?: boolean; @@ -936,12 +979,14 @@ export type Layout = { privacyPageUrl?: string; /** * This option enables the shimmer animation for the avatars of and + * * @default true */ shimmer?: boolean; /** * This option enables/disables animations for the components. If you want to disable animations, you can set this to false. * Also the prefers-reduced-motion media query is respected and animations are disabled if the user has set it to reduce motion regardless of this option. + * * @default true */ animations?: boolean; @@ -949,6 +994,7 @@ export type Layout = { /** * This option disables development mode warning. * We don't recommend disabling this unless you want to see a preview of how the components will look in production. + * * @default false */ unsafe_disableDevelopmentModeWarnings?: boolean; @@ -957,11 +1003,13 @@ export type Layout = { export type CaptchaAppearanceOptions = { /** * The widget theme. Can take the following values: light, dark, auto. + * * @default 'auto' */ theme?: 'auto' | 'light' | 'dark'; /** * The widget size. Can take the following values: normal, flexible, compact. + * * @default 'normal' */ size?: 'normal' | 'flexible' | 'compact'; diff --git a/packages/types/src/attributes.ts b/packages/shared/src/types/attributes.ts similarity index 100% rename from packages/types/src/attributes.ts rename to packages/shared/src/types/attributes.ts diff --git a/packages/types/src/authConfig.ts b/packages/shared/src/types/authConfig.ts similarity index 100% rename from packages/types/src/authConfig.ts rename to packages/shared/src/types/authConfig.ts diff --git a/packages/types/src/authObject.ts b/packages/shared/src/types/authObject.ts similarity index 100% rename from packages/types/src/authObject.ts rename to packages/shared/src/types/authObject.ts diff --git a/packages/types/src/backupCode.ts b/packages/shared/src/types/backupCode.ts similarity index 100% rename from packages/types/src/backupCode.ts rename to packages/shared/src/types/backupCode.ts diff --git a/packages/shared/src/types/billing.ts b/packages/shared/src/types/billing.ts new file mode 100644 index 00000000000..139511c38be --- /dev/null +++ b/packages/shared/src/types/billing.ts @@ -0,0 +1,839 @@ +import type { DeletedObjectResource } from './deletedObject'; +import type { ClerkPaginatedResponse, ClerkPaginationParams } from './pagination'; +import type { ClerkResource } from './resource'; + +type WithOptionalOrgType = T & { + /** + * The organization ID to perform the request on. + */ + orgId?: string; +}; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingNamespace { + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getPaymentAttempts: (params: GetPaymentAttemptsParams) => Promise>; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getPaymentAttempt: (params: { id: string; orgId?: string }) => Promise; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getPlans: (params?: GetPlansParams) => Promise>; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getPlan: (params: { id: string }) => Promise; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getSubscription: (params: GetSubscriptionParams) => Promise; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getStatements: (params: GetStatementsParams) => Promise>; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getStatement: (params: { id: string; orgId?: string }) => Promise; + + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + startCheckout: (params: CreateCheckoutParams) => Promise; +} + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type BillingPayerResourceType = 'org' | 'user'; + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type ForPayerType = 'organization' | 'user'; + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type BillingSubscriptionStatus = 'active' | 'ended' | 'upcoming' | 'past_due'; + +/** + * The billing period for the plan. + * + * @inline + */ +export type BillingSubscriptionPlanPeriod = 'month' | 'annual'; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPayerMethods { + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + initializePaymentMethod: ( + params: Exclude, + ) => Promise; + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + addPaymentMethod: (params: Exclude) => Promise; + /** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + getPaymentMethods: ( + params: Exclude, + ) => Promise>; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type GetPlansParams = ClerkPaginationParams<{ + /** + * The type of payer for the plans. + */ + for?: ForPayerType; +}>; + +/** + * The `BillingPlanResource` type represents a subscription plan with its details. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPlanResource extends ClerkResource { + /** + * The unique identifier for the plan. + */ + id: string; + /** + * The name of the plan. + */ + name: string; + /** + * The monthly price of the plan. + */ + fee: BillingMoneyAmount; + /** + * The annual price of the plan. + */ + annualFee: BillingMoneyAmount; + /** + * The effective monthly price when billed annually. + */ + annualMonthlyFee: BillingMoneyAmount; + /** + * A short description of what the plan offers. + */ + description: string; + /** + * Whether the plan is the default plan. + */ + isDefault: boolean; + /** + * Whether the plan is recurring. + */ + isRecurring: boolean; + /** + * Whether the plan has a base fee. + */ + hasBaseFee: boolean; + /** + * Specifies the subscriber type this plan is designed for. + * + * Each plan is exclusively created for either individual users or organizations, and cannot be used interchangeably. + */ + forPayerType: BillingPayerResourceType; + /** + * Whether the plan is visible to the public. + */ + publiclyVisible: boolean; + /** + * The URL-friendly identifier of the plan. + */ + slug: string; + /** + * The URL of the plan's avatar image. + */ + avatarUrl: string; + /** + * The features the plan offers. + */ + features: FeatureResource[]; + /** + * The number of days of the free trial for the plan. `null` if the plan does not have a free trial. + */ + freeTrialDays: number | null; + /** + * Whether the plan has a free trial. + */ + freeTrialEnabled: boolean; +} + +/** + * The `FeatureResource` type represents a feature of a plan. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface FeatureResource extends ClerkResource { + /** + * The unique identifier for the feature. + */ + id: string; + /** + * The display name of the feature. + */ + name: string; + /** + * A short description of what the feature provides. + */ + description: string; + /** + * A unique, URL-friendly identifier for the feature. + */ + slug: string; + /** + * The URL of the feature's avatar image. + */ + avatarUrl: string; +} + +/** + * The status of a payment method. + * @inline + */ +export type BillingPaymentMethodStatus = 'active' | 'expired' | 'disconnected'; +// TODO(@COMMERCE): Is expired returned from FAPI ? + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type GetPaymentMethodsParams = WithOptionalOrgType; + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type PaymentGateway = 'stripe' | 'paypal'; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type InitializePaymentMethodParams = WithOptionalOrgType<{ + /** + * The payment gateway to use. + */ + gateway: PaymentGateway; +}>; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type AddPaymentMethodParams = WithOptionalOrgType<{ + /** + * The payment gateway to use. + */ + gateway: PaymentGateway; + /** + * A token representing payment details, usually from a payment form. + */ + paymentToken: string; +}>; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type RemovePaymentMethodParams = WithOptionalOrgType; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type MakeDefaultPaymentMethodParams = WithOptionalOrgType; + +/** + * The `BillingPaymentMethodResource` type represents a payment method for a checkout session. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentMethodResource extends ClerkResource { + /** + * The unique identifier for the payment method. + */ + id: string; + /** + * The last four digits of the payment method. + */ + last4: string; + /** + * The type of payment method. For example, `'card'` or `'link'`. + */ + paymentType: 'card' | 'link'; + /** + * The brand or type of card. For example, `'visa'` or `'mastercard'`. + */ + cardType: string; + /** + * Whether the payment method is set as the default for the account. + */ + isDefault: boolean; + /** + * Whether the payment method can be removed by the user. + */ + isRemovable: boolean; + /** + * The current status of the payment method. + */ + status: BillingPaymentMethodStatus; + /** + * The type of digital wallet, if applicable. For example, `'apple_pay'`, or `'google_pay'`. + */ + walletType: string | undefined; + /** + * A function that removes this payment method from the account. Accepts the following parameters: + *
    + *
  • `orgId?` (`string`): The ID of the organization to remove the payment method from.
  • + *
+ * + * @param params - The parameters for the remove operation. + * @returns A promise that resolves to a `DeletedObjectResource` object. + */ + // TODO: orgId should be implied by the payment method + remove: (params?: RemovePaymentMethodParams) => Promise; + /** + * A function that sets this payment method as the default for the account. Accepts the following parameters: + *
    + *
  • `orgId?` (`string`): The ID of the organization to set as the default.
  • + *
+ * + * @param params - The parameters for the make default operation. + * @returns A promise that resolves to `null`. + */ + // TODO: orgId should be implied by the payment method + makeDefault: (params?: MakeDefaultPaymentMethodParams) => Promise; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingInitializedPaymentMethodResource extends ClerkResource { + /** + * A client secret from an external payment provider (such as Stripe) used to complete the payment on the client-side. + */ + externalClientSecret: string; + /** + * The identifier for the external payment gateway used for this checkout session. + */ + externalGatewayId: string; + /** + * The order the payment methods will be displayed in when `` renders. + */ + paymentMethodOrder: string[]; +} + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type BillingPaymentChargeType = 'checkout' | 'recurring'; + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type BillingPaymentStatus = 'pending' | 'paid' | 'failed'; + +/** + * The `BillingPaymentResource` type represents a payment attempt for a user or organization. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentResource extends ClerkResource { + /** + * The unique identifier for the payment. + */ + id: string; + /** + * The amount of the payment. + */ + amount: BillingMoneyAmount; + /** + * The date and time when the payment was successfully completed. + */ + paidAt?: Date; + /** + * The date and time when the payment failed. + */ + failedAt?: Date; + /** + * The date and time when the payment was last updated. + */ + updatedAt: Date; + /** + * The payment method being used for the payment, such as credit card or bank account. + */ + paymentMethod: BillingPaymentMethodResource; + /** + * The subscription item being paid for. + */ + subscriptionItem: BillingSubscriptionItemResource; + /** + * The type of charge this payment represents. Can be `'checkout'` for one-time payments or `'recurring'` for subscription payments. + */ + chargeType: BillingPaymentChargeType; + /** + * The current status of the payment. + */ + status: BillingPaymentStatus; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type GetPaymentAttemptsParams = WithOptionalOrgType; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type GetStatementsParams = WithOptionalOrgType; + +/** + * @inline + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ + +export type BillingStatementStatus = 'open' | 'closed'; + +/** + * The `BillingStatementResource` type represents a billing statement for a user or organization. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementResource extends ClerkResource { + /** + * The unique identifier for the statement. + */ + id: string; + /** + * An object containing the financial totals for the statement, including subtotal, grand total, tax total, credit, and past due amounts. + */ + totals: BillingStatementTotals; + /** + * The current status of the statement. Statements can be either `'open'` (still accumulating charges) or `'closed'` (finalized). + */ + status: BillingStatementStatus; + /** + * The date and time when the statement was created or last updated. + */ + timestamp: Date; + /** + * An array of statement groups, where each group contains payment items organized by timestamp. + */ + groups: BillingStatementGroup[]; +} + +/** + * The `BillingStatementGroup` type represents a group of payment items within a statement. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementGroup { + /** + * The date and time when this group of payment items was created or last updated. + */ + timestamp: Date; + /** + * An array of payment resources that belong to this group. + */ + items: BillingPaymentResource[]; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type GetSubscriptionParams = { + orgId?: string; +}; + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type CancelSubscriptionParams = WithOptionalOrgType; + +/** + * The `BillingSubscriptionItemResource` type represents an item in a subscription. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionItemResource extends ClerkResource { + /** + * The unique identifier for the subscription item. + */ + id: string; + /** + * The unique identifier for the payment method being used for the subscription item. + */ + //TODO(@COMMERCE): should this be nullable ? + paymentMethodId: string; + /** + * The plan associated with the subscription item. + */ + plan: BillingPlanResource; + /** + * The billing period for the subscription item. + */ + planPeriod: BillingSubscriptionPlanPeriod; + /** + * The status of the subscription item. + */ + status: BillingSubscriptionStatus; + /** + * The date and time when the subscription item was created. + */ + createdAt: Date; + /** + * The date and time when the subscription item became past due. `null` if the subscription item is not past due. + */ + pastDueAt: Date | null; + /** + * The date and time when the current billing period starts. + */ + periodStart: Date; + /** + * The date and time when the current billing period ends. `null` if not set. + */ + periodEnd: Date | null; + /** + * The date and time when the subscription item was canceled. `null` if the subscription item is not canceled. + */ + canceledAt: Date | null; + /** + * The amount charged for the subscription item. + */ + amount?: BillingMoneyAmount; + /** + * The credit from a previous purchase that is being applied to the subscription item. + */ + credit?: { + /** + * The amount of credit from a previous purchase that is being applied to the subscription item. + */ + amount: BillingMoneyAmount; + }; + /** + * A function to cancel the subscription item. Accepts the following parameters: + *
    + *
  • `orgId?` (`string`): The ID of the organization to cancel the subscription item from.
  • + *
+ * + * @param params - The parameters for the cancel operation. + * @returns A promise that resolves to a `DeletedObjectResource` object. + */ + cancel: (params: CancelSubscriptionParams) => Promise; + /** + * Whether the subscription item is for a free trial. + */ + isFreeTrial: boolean; +} + +/** + * The `BillingSubscriptionResource` type represents a subscription to a plan. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionResource extends ClerkResource { + /** + * The unique identifier for the subscription. + */ + id: string; + /** + * The date when the subscription became active. + */ + activeAt: Date; + /** + * The date when the subscription was created. + */ + createdAt: Date; + /** + * Information about the next payment, including the amount and the date it's due. Returns null if there is no upcoming payment. + */ + nextPayment: { + /** + * The amount of the next payment. + */ + amount: BillingMoneyAmount; + /** + * The date when the next payment is due. + */ + date: Date; + } | null; + /** + * The date when the subscription became past due, or `null` if the subscription is not past due. + */ + pastDueAt: Date | null; + + /** + * The current status of the subscription. Due to the free plan subscription item, the top level subscription can either be `active` or `past_due`. + */ + status: Extract; + + /** + * The list of subscription items included in this subscription. + */ + subscriptionItems: BillingSubscriptionItemResource[]; + + /** + * The date when the subscription was last updated, or `null` if it hasn't been updated. + */ + updatedAt: Date | null; + + /** + * Whether the payer is eligible for a free trial. + */ + eligibleForFreeTrial?: boolean; +} + +/** + * The `BillingMoneyAmount` type represents a monetary value with currency information. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingMoneyAmount { + /** + * The raw amount as a number, usually in the smallest unit of the currency (like cents for USD). For example, `1000` for $10.00. + */ + amount: number; + /** + * The amount as a formatted string. For example, `10.00` for $10.00. + */ + amountFormatted: string; + /** + * The ISO currency code for this amount. For example, `USD`. + */ + currency: string; + /** + * The symbol for the currency. For example, `$`. + */ + currencySymbol: string; +} + +/** + * The `BillingCheckoutTotals` type represents the total costs, taxes, and other pricing details for a checkout session. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutTotals { + /** + * The price of the items or plan before taxes, credits, or discounts are applied. + */ + subtotal: BillingMoneyAmount; + /** + * The total amount for the checkout, including taxes and after credits/discounts are applied. This is the final amount due. + */ + grandTotal: BillingMoneyAmount; + /** + * The amount of tax included in the checkout. + */ + taxTotal: BillingMoneyAmount; + /** + * The amount that needs to be immediately paid to complete the checkout. + */ + totalDueNow: BillingMoneyAmount; + /** + * Any credits (like account balance or promo credits) that are being applied to the checkout. + */ + credit: BillingMoneyAmount; + /** + * Any outstanding amount from previous unpaid invoices that is being collected as part of the checkout. + */ + pastDue: BillingMoneyAmount; +} + +/** + * The `BillingStatementTotals` type represents the total costs, taxes, and other pricing details for a statement. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface BillingStatementTotals extends Omit {} + +/** + * The `startCheckout()` method accepts the following parameters. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type CreateCheckoutParams = WithOptionalOrgType<{ + /** + * The unique identifier for the plan. + */ + planId: string; + /** + * The billing period for the plan. + */ + planPeriod: BillingSubscriptionPlanPeriod; +}>; + +/** + * The `confirm()` method accepts the following parameters. **Only one of `paymentSourceId`, `paymentToken`, or `useTestCard` should be provided.** + * + * @unionReturnHeadings + * ["paymentSourceId", "paymentToken", "useTestCard"] + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export type ConfirmCheckoutParams = + | { + /** + * The ID of a saved payment method to use for this checkout. + */ + paymentSourceId?: string; + } + | { + /** + * A token representing payment details, usually from a payment form. **Requires** `gateway` to be provided. + */ + paymentToken?: string; + /** + * The payment gateway to use. **Required** if `paymentToken` or `useTestCard` is provided. + */ + gateway?: PaymentGateway; + } + | { + /** + * The payment gateway to use. **Required** if `paymentToken` or `useTestCard` is provided. + */ + gateway?: PaymentGateway; + /** + * If true, uses a test card for the checkout. **Requires** `gateway` to be provided. + */ + useTestCard?: boolean; + }; + +/** + * The `BillingCheckoutResource` type represents information about a checkout session. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutResource extends ClerkResource { + /** + * The unique identifier for the checkout session. + */ + id: string; + /** + * A client secret from an external payment provider (such as Stripe) used to complete the payment on the client-side. + */ + externalClientSecret: string; + /** + * The identifier for the external payment gateway used for this checkout session. + */ + externalGatewayId: string; + /** + * The payment method being used for the checkout, such as a credit card or bank account. + */ + paymentMethod?: BillingPaymentMethodResource; + /** + * The subscription plan details for the checkout. + */ + plan: BillingPlanResource; + /** + * The billing period for the plan. + */ + planPeriod: BillingSubscriptionPlanPeriod; + /** + * Unix timestamp (milliseconds) of when the current period starts. + */ + planPeriodStart?: number; + /** + * The current status of the checkout session. + */ + status: 'needs_confirmation' | 'completed'; + /** + * The total costs, taxes, and other pricing details for the checkout. + */ + totals: BillingCheckoutTotals; + /** + * A function to confirm and finalize the checkout process, usually after payment information has been provided and validated. [Learn more.](#confirm) + */ + confirm: (params: ConfirmCheckoutParams) => Promise; + /** + * Whether the plan change will take effect immediately after checkout. + */ + isImmediatePlanChange: boolean; + /** + * Unix timestamp (milliseconds) of when the free trial ends. + */ + freeTrialEndsAt: Date | null; + /** + * The payer associated with the checkout. + */ + payer: BillingPayerResource; +} + +/** + * The `BillingPayerResource` type represents a payer associated with a billing subscription. + * + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPayerResource extends ClerkResource { + /** + * The unique identifier for the payer. + */ + id: string; + /** + * The date and time when the payer was created. + */ + createdAt: Date; + /** + * The date and time when the payer was last updated. + */ + updatedAt: Date; + /** + * The URL of the payer's avatar image. + */ + imageUrl: string | null; + /** + * The unique identifier for the payer. + */ + userId?: string; + /** + * The email address of the payer. + */ + email?: string; + /** + * The first name of the payer. + */ + firstName?: string; + /** + * The last name of the payer. + */ + lastName?: string; + /** + * The unique identifier for the organization that the payer belongs to. + */ + organizationId?: string; + /** + * The name of the organization that the payer belongs to. + */ + organizationName?: string; +} diff --git a/packages/types/src/clerk.ts b/packages/shared/src/types/clerk.ts similarity index 100% rename from packages/types/src/clerk.ts rename to packages/shared/src/types/clerk.ts diff --git a/packages/types/src/client.ts b/packages/shared/src/types/client.ts similarity index 100% rename from packages/types/src/client.ts rename to packages/shared/src/types/client.ts diff --git a/packages/types/src/commerceSettings.ts b/packages/shared/src/types/commerceSettings.ts similarity index 100% rename from packages/types/src/commerceSettings.ts rename to packages/shared/src/types/commerceSettings.ts diff --git a/packages/types/src/customMenuItems.ts b/packages/shared/src/types/customMenuItems.ts similarity index 100% rename from packages/types/src/customMenuItems.ts rename to packages/shared/src/types/customMenuItems.ts diff --git a/packages/types/src/customPages.ts b/packages/shared/src/types/customPages.ts similarity index 100% rename from packages/types/src/customPages.ts rename to packages/shared/src/types/customPages.ts diff --git a/packages/types/src/deletedObject.ts b/packages/shared/src/types/deletedObject.ts similarity index 100% rename from packages/types/src/deletedObject.ts rename to packages/shared/src/types/deletedObject.ts diff --git a/packages/types/src/displayConfig.ts b/packages/shared/src/types/displayConfig.ts similarity index 100% rename from packages/types/src/displayConfig.ts rename to packages/shared/src/types/displayConfig.ts diff --git a/packages/types/src/elementIds.ts b/packages/shared/src/types/elementIds.ts similarity index 100% rename from packages/types/src/elementIds.ts rename to packages/shared/src/types/elementIds.ts diff --git a/packages/types/src/emailAddress.ts b/packages/shared/src/types/emailAddress.ts similarity index 100% rename from packages/types/src/emailAddress.ts rename to packages/shared/src/types/emailAddress.ts diff --git a/packages/types/src/enterpriseAccount.ts b/packages/shared/src/types/enterpriseAccount.ts similarity index 100% rename from packages/types/src/enterpriseAccount.ts rename to packages/shared/src/types/enterpriseAccount.ts diff --git a/packages/types/src/environment.ts b/packages/shared/src/types/environment.ts similarity index 100% rename from packages/types/src/environment.ts rename to packages/shared/src/types/environment.ts diff --git a/packages/types/src/errors.ts b/packages/shared/src/types/errors.ts similarity index 100% rename from packages/types/src/errors.ts rename to packages/shared/src/types/errors.ts diff --git a/packages/types/src/externalAccount.ts b/packages/shared/src/types/externalAccount.ts similarity index 100% rename from packages/types/src/externalAccount.ts rename to packages/shared/src/types/externalAccount.ts diff --git a/packages/types/src/factors.ts b/packages/shared/src/types/factors.ts similarity index 100% rename from packages/types/src/factors.ts rename to packages/shared/src/types/factors.ts diff --git a/packages/types/src/hooks.ts b/packages/shared/src/types/hooks.ts similarity index 100% rename from packages/types/src/hooks.ts rename to packages/shared/src/types/hooks.ts diff --git a/packages/types/src/identificationLink.ts b/packages/shared/src/types/identificationLink.ts similarity index 100% rename from packages/types/src/identificationLink.ts rename to packages/shared/src/types/identificationLink.ts diff --git a/packages/types/src/identifiers.ts b/packages/shared/src/types/identifiers.ts similarity index 100% rename from packages/types/src/identifiers.ts rename to packages/shared/src/types/identifiers.ts diff --git a/packages/types/src/image.ts b/packages/shared/src/types/image.ts similarity index 100% rename from packages/types/src/image.ts rename to packages/shared/src/types/image.ts diff --git a/packages/shared/src/types/index.ts b/packages/shared/src/types/index.ts index fbf0cff513f..40f96733b9f 100644 --- a/packages/shared/src/types/index.ts +++ b/packages/shared/src/types/index.ts @@ -1 +1,83 @@ -export type { Simplify } from './utils'; +export type * from './apiKeys'; +export type * from './apiKeysSettings'; +export type * from './appearance'; +export type * from './attributes'; +export type * from './authConfig'; +export type * from './authObject'; +export type * from './backupCode'; +export type * from './billing'; +export type * from './clerk'; +export type * from './client'; +export type * from './commerceSettings'; +export type * from './customMenuItems'; +export type * from './customPages'; +export type * from './deletedObject'; +export type * from './displayConfig'; +export type * from './elementIds'; +export type * from './emailAddress'; +export type * from './enterpriseAccount'; +export type * from './environment'; +export type * from './errors'; +export type * from './externalAccount'; +export type * from './factors'; +export type * from './hooks'; +export type * from './identificationLink'; +export type * from './identifiers'; +export type * from './image'; +export type * from './instance'; +export type * from './json'; +export type * from './jwt'; +export type * from './jwtv2'; +export type * from './key'; +export type * from './localization'; +export type * from './multiDomain'; +export type * from './oauth'; +export type * from './organization'; +export type * from './organizationDomain'; +export type * from './organizationInvitation'; +export type * from './organizationMembership'; +export type * from './organizationMembershipRequest'; +export type * from './organizationSettings'; +export type * from './organizationSuggestion'; +export type * from './pagination'; +export type * from './passkey'; +export type * from './passwords'; +export type * from './permission'; +export type * from './phoneCodeChannel'; +export type * from './phoneNumber'; +export type * from './protect'; +export type * from './redirects'; +export type * from './resource'; +export type * from './role'; +export type * from './router'; +/** + * TODO @revamp-hooks: Drop this in the next major release. + */ +export type * from './runtime-values'; +export type * from './saml'; +export type * from './samlAccount'; +export type * from './samlConnection'; +export type * from './session'; +export type * from './sessionVerification'; +export type * from './signIn'; +export type * from './signInCommon'; +export type * from './signInFuture'; +export type * from './signUp'; +export type * from './signUpCommon'; +export type * from './signUpFuture'; +export type * from './snapshots'; +export type * from './ssr'; +export type * from './state'; +export type * from './strategies'; +export type * from './telemetry'; +export type * from './theme'; +export type * from './token'; +export type * from './totp'; +export type * from './user'; +export type * from './userOrganizationInvitation'; +export type * from './userSettings'; +export type * from './utils'; +export type * from './verification'; +export type * from './waitlist'; +export type * from './web3'; +export type * from './web3Wallet'; diff --git a/packages/types/src/instance.ts b/packages/shared/src/types/instance.ts similarity index 100% rename from packages/types/src/instance.ts rename to packages/shared/src/types/instance.ts diff --git a/packages/shared/src/types/json copy.ts b/packages/shared/src/types/json copy.ts new file mode 100644 index 00000000000..4a71431fb0a --- /dev/null +++ b/packages/shared/src/types/json copy.ts @@ -0,0 +1,859 @@ +/** + * Currently representing API DTOs in their JSON form. + */ + +import type { APIKeysSettingsJSON } from './apiKeysSettings'; +import type { + BillingPayerResourceType, + BillingPaymentChargeType, + BillingPaymentMethodStatus, + BillingPaymentStatus, + BillingStatementStatus, + BillingSubscriptionPlanPeriod, + BillingSubscriptionStatus, +} from './billing'; +import type { CommerceSettingsJSON } from './commerceSettings'; +import type { DisplayConfigJSON } from './displayConfig'; +import type { EnterpriseProtocol, EnterpriseProvider } from './enterpriseAccount'; +import type { ClerkAPIErrorJSON } from './errors'; +import type { EmailAddressIdentifier, UsernameIdentifier } from './identifiers'; +import type { ActClaim } from './jwtv2'; +import type { OAuthProvider } from './oauth'; +import type { OrganizationDomainVerificationStatus, OrganizationEnrollmentMode } from './organizationDomain'; +import type { OrganizationInvitationStatus } from './organizationInvitation'; +import type { OrganizationCustomRoleKey, OrganizationPermissionKey } from './organizationMembership'; +import type { OrganizationSettingsJSON } from './organizationSettings'; +import type { OrganizationSuggestionStatus } from './organizationSuggestion'; +import type { PhoneCodeChannel } from './phoneCodeChannel'; +import type { SamlIdpSlug } from './saml'; +import type { SessionStatus, SessionTask } from './session'; +import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification'; +import type { SignInJSON } from './signIn'; +import type { SignInFirstFactor, SignInSecondFactor } from './signInCommon'; +import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUpCommon'; +import type { + EmailCodeStrategy, + EmailLinkStrategy, + OAuthStrategy, + PasswordStrategy, + PhoneCodeStrategy, + Web3Strategy, +} from './strategies'; +import type { BoxShadow, Color, EmUnit, FontWeight, HexColor } from './theme'; +import type { UserSettingsJSON } from './userSettings'; +import type { CamelToSnake } from './utils'; +import type { VerificationStatus } from './verification'; + +export interface ClerkResourceJSON { + // TODO: Shall we make this optional? + id: string; + object: string; +} + +export type PartialWithClerkResource = Omit, 'id' | 'object'> & + Pick; + +export interface DisplayThemeJSON { + general: { + color: HexColor; + background_color: Color; + font_family: string; + font_color: HexColor; + label_font_weight: FontWeight; + padding: EmUnit; + border_radius: EmUnit; + box_shadow: BoxShadow; + }; + buttons: { + font_color: HexColor; + font_family: string; + font_weight: FontWeight; + }; + accounts: { + background_color: Color; + }; +} + +export interface ImageJSON { + object: 'image'; + id: string; + name: string; + public_url: string; +} + +export interface EnvironmentJSON extends ClerkResourceJSON { + api_keys_settings: APIKeysSettingsJSON; + auth_config: AuthConfigJSON; + client_debug_mode?: boolean; + commerce_settings: CommerceSettingsJSON; + display_config: DisplayConfigJSON; + maintenance_mode: boolean; + organization_settings: OrganizationSettingsJSON; + user_settings: UserSettingsJSON; +} + +export type LastAuthenticationStrategy = + | EmailAddressIdentifier + | EmailCodeStrategy + | EmailLinkStrategy + | PhoneCodeStrategy + | PasswordStrategy + | UsernameIdentifier + | OAuthStrategy + | Web3Strategy; + +export interface ClientJSON extends ClerkResourceJSON { + object: 'client'; + id: string; + sessions: SessionJSON[]; + sign_up: SignUpJSON | null; + sign_in: SignInJSON | null; + captcha_bypass?: boolean; // this is used by the @clerk/testing package + last_active_session_id: string | null; + last_authentication_strategy: LastAuthenticationStrategy | null; + cookie_expires_at: number | null; + created_at: number; + updated_at: number; +} + +export interface SignUpJSON extends ClerkResourceJSON { + object: 'sign_up'; + status: SignUpStatus; + required_fields: SignUpField[]; + optional_fields: SignUpField[]; + missing_fields: SignUpField[]; + unverified_fields: SignUpIdentificationField[]; + username: string | null; + first_name: string | null; + last_name: string | null; + email_address: string | null; + phone_number: string | null; + web3_wallet: string | null; + external_account_strategy: string | null; + external_account: any; + has_password: boolean; + unsafe_metadata: SignUpUnsafeMetadata; + created_session_id: string | null; + created_user_id: string | null; + abandon_at: number | null; + legal_accepted_at: number | null; + locale: string | null; + verifications: SignUpVerificationsJSON | null; +} + +/** + * @experimental + */ +export interface SignUpEnterpriseConnectionJSON extends ClerkResourceJSON { + id: string; + name: string; +} + +export interface SessionJSON extends ClerkResourceJSON { + object: 'session'; + id: string; + status: SessionStatus; + /** + * The tuple represents the minutes that have passed since the last time a first or second factor were verified. + * + * @experimental This API is experimental and may change at any moment. + */ + factor_verification_age: [firstFactorAge: number, secondFactorAge: number] | null; + expire_at: number; + abandon_at: number; + last_active_at: number; + last_active_token: TokenJSON; + last_active_organization_id: string | null; + actor: ActClaim | null; + tasks: Array | null; + user: UserJSON; + public_user_data: PublicUserDataJSON; + created_at: number; + updated_at: number; +} + +export interface SessionVerificationJSON extends ClerkResourceJSON { + object: 'session_verification'; + status: SessionVerificationStatus; + first_factor_verification: VerificationJSON | null; + session: SessionJSON; + second_factor_verification: VerificationJSON | null; + level: SessionVerificationLevel; + supported_first_factors: SignInFirstFactorJSON[] | null; + supported_second_factors: SignInSecondFactorJSON[] | null; +} + +export interface EmailAddressJSON extends ClerkResourceJSON { + object: 'email_address'; + email_address: string; + verification: VerificationJSON | null; + linked_to: IdentificationLinkJSON[]; + matches_sso_connection: boolean; +} + +export interface IdentificationLinkJSON extends ClerkResourceJSON { + id: string; + type: string; +} + +export interface PhoneNumberJSON extends ClerkResourceJSON { + object: 'phone_number'; + id: string; + phone_number: string; + reserved_for_second_factor: boolean; + default_second_factor: boolean; + linked_to: IdentificationLinkJSON[]; + verification: VerificationJSON | null; + backup_codes?: string[]; +} + +export interface PasskeyJSON extends ClerkResourceJSON { + object: 'passkey'; + id: string; + name: string | null; + verification: VerificationJSON | null; + last_used_at: number | null; + updated_at: number; + created_at: number; +} + +export interface Web3WalletJSON extends ClerkResourceJSON { + object: 'web3_wallet'; + id: string; + web3_wallet: string; + verification: VerificationJSON | null; +} + +export interface ExternalAccountJSON extends ClerkResourceJSON { + object: 'external_account'; + provider: OAuthProvider; + identification_id: string; + provider_user_id: string; + approved_scopes: string; + email_address: string; + first_name: string; + last_name: string; + image_url: string; + username: string; + phone_number: string; + public_metadata: Record; + label: string; + verification?: VerificationJSON; +} + +export interface EnterpriseAccountJSON extends ClerkResourceJSON { + object: 'enterprise_account'; + active: boolean; + email_address: string; + enterprise_connection: EnterpriseAccountConnectionJSON | null; + first_name: string | null; + last_name: string | null; + protocol: EnterpriseProtocol; + provider: EnterpriseProvider; + provider_user_id: string | null; + public_metadata: Record; + verification: VerificationJSON | null; + last_authenticated_at: number | null; + enterprise_connection_id: string | null; +} + +export interface EnterpriseAccountConnectionJSON extends ClerkResourceJSON { + active: boolean; + allow_idp_initiated: boolean; + allow_subdomains: boolean; + disable_additional_identifications: boolean; + domain: string; + logo_public_url: string | null; + name: string; + protocol: EnterpriseProtocol; + provider: EnterpriseProvider; + sync_user_attributes: boolean; + created_at: number; + updated_at: number; + enterprise_connection_id: string | null; +} + +export interface SamlAccountJSON extends ClerkResourceJSON { + object: 'saml_account'; + provider: SamlIdpSlug; + provider_user_id: string | null; + active: boolean; + email_address: string; + first_name: string; + last_name: string; + verification?: VerificationJSON; + saml_connection?: SamlAccountConnectionJSON; + last_authenticated_at: number | null; + enterprise_connection_id: string | null; +} + +export interface UserJSON extends ClerkResourceJSON { + object: 'user'; + id: string; + external_id: string | null; + primary_email_address_id: string | null; + primary_phone_number_id: string | null; + primary_web3_wallet_id: string | null; + image_url: string; + has_image: boolean; + username: string | null; + email_addresses: EmailAddressJSON[]; + phone_numbers: PhoneNumberJSON[]; + web3_wallets: Web3WalletJSON[]; + external_accounts: ExternalAccountJSON[]; + enterprise_accounts: EnterpriseAccountJSON[]; + passkeys: PasskeyJSON[]; + /** + * @deprecated Use `enterprise_accounts` instead. + */ + saml_accounts: SamlAccountJSON[]; + + organization_memberships: OrganizationMembershipJSON[]; + password_enabled: boolean; + profile_image_id: string; + first_name: string | null; + last_name: string | null; + totp_enabled: boolean; + backup_code_enabled: boolean; + two_factor_enabled: boolean; + public_metadata: UserPublicMetadata; + unsafe_metadata: UserUnsafeMetadata; + last_sign_in_at: number | null; + create_organization_enabled: boolean; + create_organizations_limit: number | null; + delete_self_enabled: boolean; + legal_accepted_at: number | null; + updated_at: number; + created_at: number; +} + +export interface PublicUserDataJSON { + first_name: string | null; + last_name: string | null; + image_url: string; + has_image: boolean; + identifier: string; + user_id?: string; +} + +export interface SessionWithActivitiesJSON extends Omit { + user: null; + latest_activity: SessionActivityJSON; +} + +export interface AuthConfigJSON extends ClerkResourceJSON { + single_session_mode: boolean; + claimed_at: number | null; + reverification: boolean; + preferred_channels?: Record; +} + +export interface VerificationJSON extends ClerkResourceJSON { + status: VerificationStatus; + verified_at_client: string; + strategy: string; + nonce?: string; + message?: string; + external_verification_redirect_url?: string; + attempts: number; + expire_at: number; + channel?: PhoneCodeChannel; + error: ClerkAPIErrorJSON; +} + +export interface SignUpVerificationsJSON { + email_address: SignUpVerificationJSON; + phone_number: SignUpVerificationJSON; + web3_wallet: SignUpVerificationJSON; + external_account: VerificationJSON; +} + +export interface SignUpVerificationJSON extends VerificationJSON { + next_action: string; + supported_strategies: string[]; + channel?: PhoneCodeChannel; +} + +export interface TokenJSON extends ClerkResourceJSON { + object: 'token'; + jwt: string; +} + +export interface SessionActivityJSON extends ClerkResourceJSON { + object: 'session_activity'; + browser_name?: string; + browser_version?: string; + device_type?: string; + ip_address?: string; + city?: string; + country?: string; + is_mobile?: boolean; +} + +export interface OrganizationJSON extends ClerkResourceJSON { + object: 'organization'; + id: string; + image_url: string; + has_image: boolean; + name: string; + slug: string; + public_metadata: OrganizationPublicMetadata; + created_at: number; + updated_at: number; + members_count: number; + pending_invitations_count: number; + admin_delete_enabled: boolean; + max_allowed_memberships: number; +} + +export interface OrganizationMembershipJSON extends ClerkResourceJSON { + object: 'organization_membership'; + id: string; + organization: OrganizationJSON; + permissions: OrganizationPermissionKey[]; + public_metadata: OrganizationMembershipPublicMetadata; + public_user_data?: PublicUserDataJSON; + role: OrganizationCustomRoleKey; + role_name: string; + created_at: number; + updated_at: number; +} + +export interface OrganizationInvitationJSON extends ClerkResourceJSON { + object: 'organization_invitation'; + id: string; + email_address: string; + organization_id: string; + public_metadata: OrganizationInvitationPublicMetadata; + status: OrganizationInvitationStatus; + role: OrganizationCustomRoleKey; + role_name: string; + created_at: number; + updated_at: number; +} + +export interface OrganizationDomainVerificationJSON { + status: OrganizationDomainVerificationStatus; + strategy: 'email_code'; // only available value for now + attempts: number; + expires_at: number; +} + +export interface OrganizationDomainJSON extends ClerkResourceJSON { + object: 'organization_domain'; + id: string; + name: string; + organization_id: string; + enrollment_mode: OrganizationEnrollmentMode; + verification: OrganizationDomainVerificationJSON | null; + affiliation_email_address: string | null; + created_at: number; + updated_at: number; + total_pending_invitations: number; + total_pending_suggestions: number; +} + +export interface RoleJSON extends ClerkResourceJSON { + object: 'role'; + id: string; + key: string; + name: string; + description: string; + permissions: PermissionJSON[]; + created_at: number; + updated_at: number; +} + +export interface PermissionJSON extends ClerkResourceJSON { + object: 'permission'; + id: string; + key: string; + name: string; + description: string; + type: 'system' | 'user'; + created_at: number; + updated_at: number; +} + +export interface PublicOrganizationDataJSON { + id: string; + name: string; + slug: string | null; + has_image: boolean; + image_url: string; +} + +export interface OrganizationSuggestionJSON extends ClerkResourceJSON { + object: 'organization_suggestion'; + id: string; + public_organization_data: PublicOrganizationDataJSON; + status: OrganizationSuggestionStatus; + created_at: number; + updated_at: number; +} + +export interface OrganizationMembershipRequestJSON extends ClerkResourceJSON { + object: 'organization_membership_request'; + id: string; + organization_id: string; + status: OrganizationInvitationStatus; + public_user_data: PublicUserDataJSON; + created_at: number; + updated_at: number; +} + +export interface UserOrganizationInvitationJSON extends ClerkResourceJSON { + object: 'organization_invitation'; + id: string; + email_address: string; + public_organization_data: PublicOrganizationDataJSON; + public_metadata: OrganizationInvitationPublicMetadata; + status: OrganizationInvitationStatus; + role: OrganizationCustomRoleKey; + created_at: number; + updated_at: number; +} + +export interface UserDataJSON { + first_name?: string; + last_name?: string; + image_url: string; + has_image: boolean; +} + +export interface TOTPJSON extends ClerkResourceJSON { + object: 'totp'; + id: string; + secret?: string; + uri?: string; + verified: boolean; + backup_codes?: string[]; + created_at: number; + updated_at: number; +} + +export interface BackupCodeJSON extends ClerkResourceJSON { + object: 'backup_code'; + id: string; + codes: string[]; + created_at: number; + updated_at: number; +} + +export interface DeletedObjectJSON { + object: string; + id?: string; + slug?: string; + deleted: boolean; +} + +export type SignInFirstFactorJSON = CamelToSnake; +export type SignInSecondFactorJSON = CamelToSnake; + +/** + * Types for WebAuthN passkeys + */ + +type Base64UrlString = string; + +interface PublicKeyCredentialUserEntityJSON { + name: string; + displayName: string; + id: Base64UrlString; +} + +interface PublicKeyCredentialDescriptorJSON { + type: 'public-key'; + id: Base64UrlString; + transports?: ('ble' | 'hybrid' | 'internal' | 'nfc' | 'usb')[]; +} + +interface AuthenticatorSelectionCriteriaJSON { + requireResidentKey: boolean; + residentKey: 'discouraged' | 'preferred' | 'required'; + userVerification: 'discouraged' | 'preferred' | 'required'; +} + +export interface PublicKeyCredentialCreationOptionsJSON { + rp: PublicKeyCredentialRpEntity; + user: PublicKeyCredentialUserEntityJSON; + challenge: Base64UrlString; + pubKeyCredParams: PublicKeyCredentialParameters[]; + timeout: number; + excludeCredentials: PublicKeyCredentialDescriptorJSON[]; + authenticatorSelection: AuthenticatorSelectionCriteriaJSON; + attestation: 'direct' | 'enterprise' | 'indirect' | 'none'; +} + +export interface PublicKeyCredentialRequestOptionsJSON { + allowCredentials: PublicKeyCredentialDescriptorJSON[]; + challenge: Base64UrlString; + rpId: string; + timeout: number; + userVerification: 'discouraged' | 'preferred' | 'required'; +} + +export interface SamlAccountConnectionJSON extends ClerkResourceJSON { + id: string; + name: string; + domain: string; + active: boolean; + provider: string; + sync_user_attributes: boolean; + allow_subdomains: boolean; + allow_idp_initiated: boolean; + disable_additional_identifications: boolean; + created_at: number; + updated_at: number; +} + +export interface WaitlistJSON extends ClerkResourceJSON { + object: 'waitlist'; + id: string; + created_at: number; + updated_at: number; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface FeatureJSON extends ClerkResourceJSON { + object: 'feature'; + id: string; + name: string; + description: string; + slug: string; + avatar_url: string; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPlanJSON extends ClerkResourceJSON { + object: 'commerce_plan'; + id: string; + name: string; + fee: BillingMoneyAmountJSON; + annual_fee: BillingMoneyAmountJSON; + annual_monthly_fee: BillingMoneyAmountJSON; + amount: number; + amount_formatted: string; + annual_amount: number; + annual_amount_formatted: string; + annual_monthly_amount: number; + annual_monthly_amount_formatted: string; + currency_symbol: string; + currency: string; + description: string; + is_default: boolean; + is_recurring: boolean; + has_base_fee: boolean; + for_payer_type: BillingPayerResourceType; + publicly_visible: boolean; + slug: string; + avatar_url: string; + features: FeatureJSON[]; + free_trial_days?: number | null; + free_trial_enabled?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentMethodJSON extends ClerkResourceJSON { + object: 'commerce_payment_method'; + id: string; + last4: string; + payment_type: 'card' | 'link'; + card_type: string; + is_default: boolean; + is_removable: boolean; + status: BillingPaymentMethodStatus; + wallet_type: string | null; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingInitializedPaymentMethodJSON extends ClerkResourceJSON { + object: 'commerce_payment_method_initialize'; + external_client_secret: string; + external_gateway_id: string; + payment_method_order: string[]; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementJSON extends ClerkResourceJSON { + object: 'commerce_statement'; + id: string; + status: BillingStatementStatus; + timestamp: number; + groups: BillingStatementGroupJSON[]; + totals: BillingStatementTotalsJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementGroupJSON extends ClerkResourceJSON { + object: 'commerce_statement_group'; + timestamp: number; + items: BillingPaymentJSON[]; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentJSON extends ClerkResourceJSON { + object: 'commerce_payment'; + id: string; + amount: BillingMoneyAmountJSON; + paid_at?: number; + failed_at?: number; + updated_at: number; + payment_method: BillingPaymentMethodJSON; + subscription: BillingSubscriptionItemJSON; + subscription_item: BillingSubscriptionItemJSON; + charge_type: BillingPaymentChargeType; + status: BillingPaymentStatus; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionItemJSON extends ClerkResourceJSON { + object: 'commerce_subscription_item'; + id: string; + amount?: BillingMoneyAmountJSON; + credit?: { + amount: BillingMoneyAmountJSON; + }; + payment_method_id: string; + plan: BillingPlanJSON; + plan_period: BillingSubscriptionPlanPeriod; + status: BillingSubscriptionStatus; + created_at: number; + period_start: number; + /** + * Period end is `null` for subscription items that are on the free plan. + */ + period_end: number | null; + canceled_at: number | null; + past_due_at: number | null; + // TODO(@COMMERCE): Remove optional after GA. + is_free_trial?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionJSON extends ClerkResourceJSON { + object: 'commerce_subscription'; + id: string; + /** + * Describes the details for the next payment cycle. It is `undefined` for subscription items that are cancelled or on the free plan. + */ + next_payment?: { + amount: BillingMoneyAmountJSON; + date: number; + }; + /** + * Due to the free plan subscription item, the top level subscription can either be `active` or `past_due`. + */ + status: Extract; + created_at: number; + active_at: number; + updated_at: number | null; + past_due_at: number | null; + subscription_items: BillingSubscriptionItemJSON[] | null; + eligible_for_free_trial?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingMoneyAmountJSON { + amount: number; + amount_formatted: string; + currency: string; + currency_symbol: string; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutTotalsJSON { + grand_total: BillingMoneyAmountJSON; + subtotal: BillingMoneyAmountJSON; + tax_total: BillingMoneyAmountJSON; + total_due_now: BillingMoneyAmountJSON; + credit: BillingMoneyAmountJSON; + past_due: BillingMoneyAmountJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface BillingStatementTotalsJSON extends Omit {} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutJSON extends ClerkResourceJSON { + object: 'commerce_checkout'; + id: string; + external_client_secret: string; + external_gateway_id: string; + payment_method?: BillingPaymentMethodJSON; + plan: BillingPlanJSON; + plan_period: BillingSubscriptionPlanPeriod; + plan_period_start?: number; + status: 'needs_confirmation' | 'completed'; + totals: BillingCheckoutTotalsJSON; + is_immediate_plan_change: boolean; + // TODO(@COMMERCE): Remove optional after GA. + free_trial_ends_at: number | null; + payer: BillingPayerJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPayerJSON extends ClerkResourceJSON { + object: 'commerce_payer'; + id: string; + created_at: number; + updated_at: number; + image_url: string | null; + + // User attributes + user_id?: string; + email?: string; + first_name?: string; + last_name?: string; + + // Organization attributes + organization_id?: string; + organization_name?: string; +} + +export interface ApiKeyJSON extends ClerkResourceJSON { + id: string; + type: string; + name: string; + subject: string; + scopes: string[]; + claims: Record | null; + revoked: boolean; + revocation_reason: string | null; + expired: boolean; + expiration: number | null; + created_by: string | null; + description: string | null; + last_used_at: number | null; + created_at: number; + updated_at: number; +} diff --git a/packages/shared/src/types/json.ts b/packages/shared/src/types/json.ts index e69de29bb2d..4a71431fb0a 100644 --- a/packages/shared/src/types/json.ts +++ b/packages/shared/src/types/json.ts @@ -0,0 +1,859 @@ +/** + * Currently representing API DTOs in their JSON form. + */ + +import type { APIKeysSettingsJSON } from './apiKeysSettings'; +import type { + BillingPayerResourceType, + BillingPaymentChargeType, + BillingPaymentMethodStatus, + BillingPaymentStatus, + BillingStatementStatus, + BillingSubscriptionPlanPeriod, + BillingSubscriptionStatus, +} from './billing'; +import type { CommerceSettingsJSON } from './commerceSettings'; +import type { DisplayConfigJSON } from './displayConfig'; +import type { EnterpriseProtocol, EnterpriseProvider } from './enterpriseAccount'; +import type { ClerkAPIErrorJSON } from './errors'; +import type { EmailAddressIdentifier, UsernameIdentifier } from './identifiers'; +import type { ActClaim } from './jwtv2'; +import type { OAuthProvider } from './oauth'; +import type { OrganizationDomainVerificationStatus, OrganizationEnrollmentMode } from './organizationDomain'; +import type { OrganizationInvitationStatus } from './organizationInvitation'; +import type { OrganizationCustomRoleKey, OrganizationPermissionKey } from './organizationMembership'; +import type { OrganizationSettingsJSON } from './organizationSettings'; +import type { OrganizationSuggestionStatus } from './organizationSuggestion'; +import type { PhoneCodeChannel } from './phoneCodeChannel'; +import type { SamlIdpSlug } from './saml'; +import type { SessionStatus, SessionTask } from './session'; +import type { SessionVerificationLevel, SessionVerificationStatus } from './sessionVerification'; +import type { SignInJSON } from './signIn'; +import type { SignInFirstFactor, SignInSecondFactor } from './signInCommon'; +import type { SignUpField, SignUpIdentificationField, SignUpStatus } from './signUpCommon'; +import type { + EmailCodeStrategy, + EmailLinkStrategy, + OAuthStrategy, + PasswordStrategy, + PhoneCodeStrategy, + Web3Strategy, +} from './strategies'; +import type { BoxShadow, Color, EmUnit, FontWeight, HexColor } from './theme'; +import type { UserSettingsJSON } from './userSettings'; +import type { CamelToSnake } from './utils'; +import type { VerificationStatus } from './verification'; + +export interface ClerkResourceJSON { + // TODO: Shall we make this optional? + id: string; + object: string; +} + +export type PartialWithClerkResource = Omit, 'id' | 'object'> & + Pick; + +export interface DisplayThemeJSON { + general: { + color: HexColor; + background_color: Color; + font_family: string; + font_color: HexColor; + label_font_weight: FontWeight; + padding: EmUnit; + border_radius: EmUnit; + box_shadow: BoxShadow; + }; + buttons: { + font_color: HexColor; + font_family: string; + font_weight: FontWeight; + }; + accounts: { + background_color: Color; + }; +} + +export interface ImageJSON { + object: 'image'; + id: string; + name: string; + public_url: string; +} + +export interface EnvironmentJSON extends ClerkResourceJSON { + api_keys_settings: APIKeysSettingsJSON; + auth_config: AuthConfigJSON; + client_debug_mode?: boolean; + commerce_settings: CommerceSettingsJSON; + display_config: DisplayConfigJSON; + maintenance_mode: boolean; + organization_settings: OrganizationSettingsJSON; + user_settings: UserSettingsJSON; +} + +export type LastAuthenticationStrategy = + | EmailAddressIdentifier + | EmailCodeStrategy + | EmailLinkStrategy + | PhoneCodeStrategy + | PasswordStrategy + | UsernameIdentifier + | OAuthStrategy + | Web3Strategy; + +export interface ClientJSON extends ClerkResourceJSON { + object: 'client'; + id: string; + sessions: SessionJSON[]; + sign_up: SignUpJSON | null; + sign_in: SignInJSON | null; + captcha_bypass?: boolean; // this is used by the @clerk/testing package + last_active_session_id: string | null; + last_authentication_strategy: LastAuthenticationStrategy | null; + cookie_expires_at: number | null; + created_at: number; + updated_at: number; +} + +export interface SignUpJSON extends ClerkResourceJSON { + object: 'sign_up'; + status: SignUpStatus; + required_fields: SignUpField[]; + optional_fields: SignUpField[]; + missing_fields: SignUpField[]; + unverified_fields: SignUpIdentificationField[]; + username: string | null; + first_name: string | null; + last_name: string | null; + email_address: string | null; + phone_number: string | null; + web3_wallet: string | null; + external_account_strategy: string | null; + external_account: any; + has_password: boolean; + unsafe_metadata: SignUpUnsafeMetadata; + created_session_id: string | null; + created_user_id: string | null; + abandon_at: number | null; + legal_accepted_at: number | null; + locale: string | null; + verifications: SignUpVerificationsJSON | null; +} + +/** + * @experimental + */ +export interface SignUpEnterpriseConnectionJSON extends ClerkResourceJSON { + id: string; + name: string; +} + +export interface SessionJSON extends ClerkResourceJSON { + object: 'session'; + id: string; + status: SessionStatus; + /** + * The tuple represents the minutes that have passed since the last time a first or second factor were verified. + * + * @experimental This API is experimental and may change at any moment. + */ + factor_verification_age: [firstFactorAge: number, secondFactorAge: number] | null; + expire_at: number; + abandon_at: number; + last_active_at: number; + last_active_token: TokenJSON; + last_active_organization_id: string | null; + actor: ActClaim | null; + tasks: Array | null; + user: UserJSON; + public_user_data: PublicUserDataJSON; + created_at: number; + updated_at: number; +} + +export interface SessionVerificationJSON extends ClerkResourceJSON { + object: 'session_verification'; + status: SessionVerificationStatus; + first_factor_verification: VerificationJSON | null; + session: SessionJSON; + second_factor_verification: VerificationJSON | null; + level: SessionVerificationLevel; + supported_first_factors: SignInFirstFactorJSON[] | null; + supported_second_factors: SignInSecondFactorJSON[] | null; +} + +export interface EmailAddressJSON extends ClerkResourceJSON { + object: 'email_address'; + email_address: string; + verification: VerificationJSON | null; + linked_to: IdentificationLinkJSON[]; + matches_sso_connection: boolean; +} + +export interface IdentificationLinkJSON extends ClerkResourceJSON { + id: string; + type: string; +} + +export interface PhoneNumberJSON extends ClerkResourceJSON { + object: 'phone_number'; + id: string; + phone_number: string; + reserved_for_second_factor: boolean; + default_second_factor: boolean; + linked_to: IdentificationLinkJSON[]; + verification: VerificationJSON | null; + backup_codes?: string[]; +} + +export interface PasskeyJSON extends ClerkResourceJSON { + object: 'passkey'; + id: string; + name: string | null; + verification: VerificationJSON | null; + last_used_at: number | null; + updated_at: number; + created_at: number; +} + +export interface Web3WalletJSON extends ClerkResourceJSON { + object: 'web3_wallet'; + id: string; + web3_wallet: string; + verification: VerificationJSON | null; +} + +export interface ExternalAccountJSON extends ClerkResourceJSON { + object: 'external_account'; + provider: OAuthProvider; + identification_id: string; + provider_user_id: string; + approved_scopes: string; + email_address: string; + first_name: string; + last_name: string; + image_url: string; + username: string; + phone_number: string; + public_metadata: Record; + label: string; + verification?: VerificationJSON; +} + +export interface EnterpriseAccountJSON extends ClerkResourceJSON { + object: 'enterprise_account'; + active: boolean; + email_address: string; + enterprise_connection: EnterpriseAccountConnectionJSON | null; + first_name: string | null; + last_name: string | null; + protocol: EnterpriseProtocol; + provider: EnterpriseProvider; + provider_user_id: string | null; + public_metadata: Record; + verification: VerificationJSON | null; + last_authenticated_at: number | null; + enterprise_connection_id: string | null; +} + +export interface EnterpriseAccountConnectionJSON extends ClerkResourceJSON { + active: boolean; + allow_idp_initiated: boolean; + allow_subdomains: boolean; + disable_additional_identifications: boolean; + domain: string; + logo_public_url: string | null; + name: string; + protocol: EnterpriseProtocol; + provider: EnterpriseProvider; + sync_user_attributes: boolean; + created_at: number; + updated_at: number; + enterprise_connection_id: string | null; +} + +export interface SamlAccountJSON extends ClerkResourceJSON { + object: 'saml_account'; + provider: SamlIdpSlug; + provider_user_id: string | null; + active: boolean; + email_address: string; + first_name: string; + last_name: string; + verification?: VerificationJSON; + saml_connection?: SamlAccountConnectionJSON; + last_authenticated_at: number | null; + enterprise_connection_id: string | null; +} + +export interface UserJSON extends ClerkResourceJSON { + object: 'user'; + id: string; + external_id: string | null; + primary_email_address_id: string | null; + primary_phone_number_id: string | null; + primary_web3_wallet_id: string | null; + image_url: string; + has_image: boolean; + username: string | null; + email_addresses: EmailAddressJSON[]; + phone_numbers: PhoneNumberJSON[]; + web3_wallets: Web3WalletJSON[]; + external_accounts: ExternalAccountJSON[]; + enterprise_accounts: EnterpriseAccountJSON[]; + passkeys: PasskeyJSON[]; + /** + * @deprecated Use `enterprise_accounts` instead. + */ + saml_accounts: SamlAccountJSON[]; + + organization_memberships: OrganizationMembershipJSON[]; + password_enabled: boolean; + profile_image_id: string; + first_name: string | null; + last_name: string | null; + totp_enabled: boolean; + backup_code_enabled: boolean; + two_factor_enabled: boolean; + public_metadata: UserPublicMetadata; + unsafe_metadata: UserUnsafeMetadata; + last_sign_in_at: number | null; + create_organization_enabled: boolean; + create_organizations_limit: number | null; + delete_self_enabled: boolean; + legal_accepted_at: number | null; + updated_at: number; + created_at: number; +} + +export interface PublicUserDataJSON { + first_name: string | null; + last_name: string | null; + image_url: string; + has_image: boolean; + identifier: string; + user_id?: string; +} + +export interface SessionWithActivitiesJSON extends Omit { + user: null; + latest_activity: SessionActivityJSON; +} + +export interface AuthConfigJSON extends ClerkResourceJSON { + single_session_mode: boolean; + claimed_at: number | null; + reverification: boolean; + preferred_channels?: Record; +} + +export interface VerificationJSON extends ClerkResourceJSON { + status: VerificationStatus; + verified_at_client: string; + strategy: string; + nonce?: string; + message?: string; + external_verification_redirect_url?: string; + attempts: number; + expire_at: number; + channel?: PhoneCodeChannel; + error: ClerkAPIErrorJSON; +} + +export interface SignUpVerificationsJSON { + email_address: SignUpVerificationJSON; + phone_number: SignUpVerificationJSON; + web3_wallet: SignUpVerificationJSON; + external_account: VerificationJSON; +} + +export interface SignUpVerificationJSON extends VerificationJSON { + next_action: string; + supported_strategies: string[]; + channel?: PhoneCodeChannel; +} + +export interface TokenJSON extends ClerkResourceJSON { + object: 'token'; + jwt: string; +} + +export interface SessionActivityJSON extends ClerkResourceJSON { + object: 'session_activity'; + browser_name?: string; + browser_version?: string; + device_type?: string; + ip_address?: string; + city?: string; + country?: string; + is_mobile?: boolean; +} + +export interface OrganizationJSON extends ClerkResourceJSON { + object: 'organization'; + id: string; + image_url: string; + has_image: boolean; + name: string; + slug: string; + public_metadata: OrganizationPublicMetadata; + created_at: number; + updated_at: number; + members_count: number; + pending_invitations_count: number; + admin_delete_enabled: boolean; + max_allowed_memberships: number; +} + +export interface OrganizationMembershipJSON extends ClerkResourceJSON { + object: 'organization_membership'; + id: string; + organization: OrganizationJSON; + permissions: OrganizationPermissionKey[]; + public_metadata: OrganizationMembershipPublicMetadata; + public_user_data?: PublicUserDataJSON; + role: OrganizationCustomRoleKey; + role_name: string; + created_at: number; + updated_at: number; +} + +export interface OrganizationInvitationJSON extends ClerkResourceJSON { + object: 'organization_invitation'; + id: string; + email_address: string; + organization_id: string; + public_metadata: OrganizationInvitationPublicMetadata; + status: OrganizationInvitationStatus; + role: OrganizationCustomRoleKey; + role_name: string; + created_at: number; + updated_at: number; +} + +export interface OrganizationDomainVerificationJSON { + status: OrganizationDomainVerificationStatus; + strategy: 'email_code'; // only available value for now + attempts: number; + expires_at: number; +} + +export interface OrganizationDomainJSON extends ClerkResourceJSON { + object: 'organization_domain'; + id: string; + name: string; + organization_id: string; + enrollment_mode: OrganizationEnrollmentMode; + verification: OrganizationDomainVerificationJSON | null; + affiliation_email_address: string | null; + created_at: number; + updated_at: number; + total_pending_invitations: number; + total_pending_suggestions: number; +} + +export interface RoleJSON extends ClerkResourceJSON { + object: 'role'; + id: string; + key: string; + name: string; + description: string; + permissions: PermissionJSON[]; + created_at: number; + updated_at: number; +} + +export interface PermissionJSON extends ClerkResourceJSON { + object: 'permission'; + id: string; + key: string; + name: string; + description: string; + type: 'system' | 'user'; + created_at: number; + updated_at: number; +} + +export interface PublicOrganizationDataJSON { + id: string; + name: string; + slug: string | null; + has_image: boolean; + image_url: string; +} + +export interface OrganizationSuggestionJSON extends ClerkResourceJSON { + object: 'organization_suggestion'; + id: string; + public_organization_data: PublicOrganizationDataJSON; + status: OrganizationSuggestionStatus; + created_at: number; + updated_at: number; +} + +export interface OrganizationMembershipRequestJSON extends ClerkResourceJSON { + object: 'organization_membership_request'; + id: string; + organization_id: string; + status: OrganizationInvitationStatus; + public_user_data: PublicUserDataJSON; + created_at: number; + updated_at: number; +} + +export interface UserOrganizationInvitationJSON extends ClerkResourceJSON { + object: 'organization_invitation'; + id: string; + email_address: string; + public_organization_data: PublicOrganizationDataJSON; + public_metadata: OrganizationInvitationPublicMetadata; + status: OrganizationInvitationStatus; + role: OrganizationCustomRoleKey; + created_at: number; + updated_at: number; +} + +export interface UserDataJSON { + first_name?: string; + last_name?: string; + image_url: string; + has_image: boolean; +} + +export interface TOTPJSON extends ClerkResourceJSON { + object: 'totp'; + id: string; + secret?: string; + uri?: string; + verified: boolean; + backup_codes?: string[]; + created_at: number; + updated_at: number; +} + +export interface BackupCodeJSON extends ClerkResourceJSON { + object: 'backup_code'; + id: string; + codes: string[]; + created_at: number; + updated_at: number; +} + +export interface DeletedObjectJSON { + object: string; + id?: string; + slug?: string; + deleted: boolean; +} + +export type SignInFirstFactorJSON = CamelToSnake; +export type SignInSecondFactorJSON = CamelToSnake; + +/** + * Types for WebAuthN passkeys + */ + +type Base64UrlString = string; + +interface PublicKeyCredentialUserEntityJSON { + name: string; + displayName: string; + id: Base64UrlString; +} + +interface PublicKeyCredentialDescriptorJSON { + type: 'public-key'; + id: Base64UrlString; + transports?: ('ble' | 'hybrid' | 'internal' | 'nfc' | 'usb')[]; +} + +interface AuthenticatorSelectionCriteriaJSON { + requireResidentKey: boolean; + residentKey: 'discouraged' | 'preferred' | 'required'; + userVerification: 'discouraged' | 'preferred' | 'required'; +} + +export interface PublicKeyCredentialCreationOptionsJSON { + rp: PublicKeyCredentialRpEntity; + user: PublicKeyCredentialUserEntityJSON; + challenge: Base64UrlString; + pubKeyCredParams: PublicKeyCredentialParameters[]; + timeout: number; + excludeCredentials: PublicKeyCredentialDescriptorJSON[]; + authenticatorSelection: AuthenticatorSelectionCriteriaJSON; + attestation: 'direct' | 'enterprise' | 'indirect' | 'none'; +} + +export interface PublicKeyCredentialRequestOptionsJSON { + allowCredentials: PublicKeyCredentialDescriptorJSON[]; + challenge: Base64UrlString; + rpId: string; + timeout: number; + userVerification: 'discouraged' | 'preferred' | 'required'; +} + +export interface SamlAccountConnectionJSON extends ClerkResourceJSON { + id: string; + name: string; + domain: string; + active: boolean; + provider: string; + sync_user_attributes: boolean; + allow_subdomains: boolean; + allow_idp_initiated: boolean; + disable_additional_identifications: boolean; + created_at: number; + updated_at: number; +} + +export interface WaitlistJSON extends ClerkResourceJSON { + object: 'waitlist'; + id: string; + created_at: number; + updated_at: number; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface FeatureJSON extends ClerkResourceJSON { + object: 'feature'; + id: string; + name: string; + description: string; + slug: string; + avatar_url: string; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPlanJSON extends ClerkResourceJSON { + object: 'commerce_plan'; + id: string; + name: string; + fee: BillingMoneyAmountJSON; + annual_fee: BillingMoneyAmountJSON; + annual_monthly_fee: BillingMoneyAmountJSON; + amount: number; + amount_formatted: string; + annual_amount: number; + annual_amount_formatted: string; + annual_monthly_amount: number; + annual_monthly_amount_formatted: string; + currency_symbol: string; + currency: string; + description: string; + is_default: boolean; + is_recurring: boolean; + has_base_fee: boolean; + for_payer_type: BillingPayerResourceType; + publicly_visible: boolean; + slug: string; + avatar_url: string; + features: FeatureJSON[]; + free_trial_days?: number | null; + free_trial_enabled?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentMethodJSON extends ClerkResourceJSON { + object: 'commerce_payment_method'; + id: string; + last4: string; + payment_type: 'card' | 'link'; + card_type: string; + is_default: boolean; + is_removable: boolean; + status: BillingPaymentMethodStatus; + wallet_type: string | null; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingInitializedPaymentMethodJSON extends ClerkResourceJSON { + object: 'commerce_payment_method_initialize'; + external_client_secret: string; + external_gateway_id: string; + payment_method_order: string[]; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementJSON extends ClerkResourceJSON { + object: 'commerce_statement'; + id: string; + status: BillingStatementStatus; + timestamp: number; + groups: BillingStatementGroupJSON[]; + totals: BillingStatementTotalsJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingStatementGroupJSON extends ClerkResourceJSON { + object: 'commerce_statement_group'; + timestamp: number; + items: BillingPaymentJSON[]; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPaymentJSON extends ClerkResourceJSON { + object: 'commerce_payment'; + id: string; + amount: BillingMoneyAmountJSON; + paid_at?: number; + failed_at?: number; + updated_at: number; + payment_method: BillingPaymentMethodJSON; + subscription: BillingSubscriptionItemJSON; + subscription_item: BillingSubscriptionItemJSON; + charge_type: BillingPaymentChargeType; + status: BillingPaymentStatus; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionItemJSON extends ClerkResourceJSON { + object: 'commerce_subscription_item'; + id: string; + amount?: BillingMoneyAmountJSON; + credit?: { + amount: BillingMoneyAmountJSON; + }; + payment_method_id: string; + plan: BillingPlanJSON; + plan_period: BillingSubscriptionPlanPeriod; + status: BillingSubscriptionStatus; + created_at: number; + period_start: number; + /** + * Period end is `null` for subscription items that are on the free plan. + */ + period_end: number | null; + canceled_at: number | null; + past_due_at: number | null; + // TODO(@COMMERCE): Remove optional after GA. + is_free_trial?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingSubscriptionJSON extends ClerkResourceJSON { + object: 'commerce_subscription'; + id: string; + /** + * Describes the details for the next payment cycle. It is `undefined` for subscription items that are cancelled or on the free plan. + */ + next_payment?: { + amount: BillingMoneyAmountJSON; + date: number; + }; + /** + * Due to the free plan subscription item, the top level subscription can either be `active` or `past_due`. + */ + status: Extract; + created_at: number; + active_at: number; + updated_at: number | null; + past_due_at: number | null; + subscription_items: BillingSubscriptionItemJSON[] | null; + eligible_for_free_trial?: boolean; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingMoneyAmountJSON { + amount: number; + amount_formatted: string; + currency: string; + currency_symbol: string; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutTotalsJSON { + grand_total: BillingMoneyAmountJSON; + subtotal: BillingMoneyAmountJSON; + tax_total: BillingMoneyAmountJSON; + total_due_now: BillingMoneyAmountJSON; + credit: BillingMoneyAmountJSON; + past_due: BillingMoneyAmountJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface BillingStatementTotalsJSON extends Omit {} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingCheckoutJSON extends ClerkResourceJSON { + object: 'commerce_checkout'; + id: string; + external_client_secret: string; + external_gateway_id: string; + payment_method?: BillingPaymentMethodJSON; + plan: BillingPlanJSON; + plan_period: BillingSubscriptionPlanPeriod; + plan_period_start?: number; + status: 'needs_confirmation' | 'completed'; + totals: BillingCheckoutTotalsJSON; + is_immediate_plan_change: boolean; + // TODO(@COMMERCE): Remove optional after GA. + free_trial_ends_at: number | null; + payer: BillingPayerJSON; +} + +/** + * @experimental This is an experimental API for the Billing feature that is available under a public beta, and the API is subject to change. It is advised to [pin](https://clerk.com/docs/pinning) the SDK version and the clerk-js version to avoid breaking changes. + */ +export interface BillingPayerJSON extends ClerkResourceJSON { + object: 'commerce_payer'; + id: string; + created_at: number; + updated_at: number; + image_url: string | null; + + // User attributes + user_id?: string; + email?: string; + first_name?: string; + last_name?: string; + + // Organization attributes + organization_id?: string; + organization_name?: string; +} + +export interface ApiKeyJSON extends ClerkResourceJSON { + id: string; + type: string; + name: string; + subject: string; + scopes: string[]; + claims: Record | null; + revoked: boolean; + revocation_reason: string | null; + expired: boolean; + expiration: number | null; + created_by: string | null; + description: string | null; + last_used_at: number | null; + created_at: number; + updated_at: number; +} diff --git a/packages/types/src/jwt.ts b/packages/shared/src/types/jwt.ts similarity index 100% rename from packages/types/src/jwt.ts rename to packages/shared/src/types/jwt.ts diff --git a/packages/types/src/jwtv2.ts b/packages/shared/src/types/jwtv2.ts similarity index 100% rename from packages/types/src/jwtv2.ts rename to packages/shared/src/types/jwtv2.ts diff --git a/packages/types/src/key.ts b/packages/shared/src/types/key.ts similarity index 100% rename from packages/types/src/key.ts rename to packages/shared/src/types/key.ts diff --git a/packages/types/src/localization.ts b/packages/shared/src/types/localization.ts similarity index 100% rename from packages/types/src/localization.ts rename to packages/shared/src/types/localization.ts diff --git a/packages/types/src/multiDomain.ts b/packages/shared/src/types/multiDomain.ts similarity index 100% rename from packages/types/src/multiDomain.ts rename to packages/shared/src/types/multiDomain.ts diff --git a/packages/types/src/oauth.ts b/packages/shared/src/types/oauth.ts similarity index 100% rename from packages/types/src/oauth.ts rename to packages/shared/src/types/oauth.ts diff --git a/packages/types/src/organization.ts b/packages/shared/src/types/organization.ts similarity index 100% rename from packages/types/src/organization.ts rename to packages/shared/src/types/organization.ts diff --git a/packages/types/src/organizationDomain.ts b/packages/shared/src/types/organizationDomain.ts similarity index 100% rename from packages/types/src/organizationDomain.ts rename to packages/shared/src/types/organizationDomain.ts diff --git a/packages/types/src/organizationInvitation.ts b/packages/shared/src/types/organizationInvitation.ts similarity index 99% rename from packages/types/src/organizationInvitation.ts rename to packages/shared/src/types/organizationInvitation.ts index 347699b254c..cc4f91eea04 100644 --- a/packages/types/src/organizationInvitation.ts +++ b/packages/shared/src/types/organizationInvitation.ts @@ -18,6 +18,7 @@ declare global { /** * The `OrganizationInvitation` object is the model around an organization invitation. + * * @interface */ export interface OrganizationInvitationResource extends ClerkResource { diff --git a/packages/types/src/organizationMembership.ts b/packages/shared/src/types/organizationMembership.ts similarity index 100% rename from packages/types/src/organizationMembership.ts rename to packages/shared/src/types/organizationMembership.ts diff --git a/packages/types/src/organizationMembershipRequest.ts b/packages/shared/src/types/organizationMembershipRequest.ts similarity index 100% rename from packages/types/src/organizationMembershipRequest.ts rename to packages/shared/src/types/organizationMembershipRequest.ts diff --git a/packages/types/src/organizationSettings.ts b/packages/shared/src/types/organizationSettings.ts similarity index 100% rename from packages/types/src/organizationSettings.ts rename to packages/shared/src/types/organizationSettings.ts diff --git a/packages/types/src/organizationSuggestion.ts b/packages/shared/src/types/organizationSuggestion.ts similarity index 100% rename from packages/types/src/organizationSuggestion.ts rename to packages/shared/src/types/organizationSuggestion.ts diff --git a/packages/types/src/pagination.ts b/packages/shared/src/types/pagination.ts similarity index 100% rename from packages/types/src/pagination.ts rename to packages/shared/src/types/pagination.ts diff --git a/packages/types/src/passkey.ts b/packages/shared/src/types/passkey.ts similarity index 100% rename from packages/types/src/passkey.ts rename to packages/shared/src/types/passkey.ts diff --git a/packages/types/src/passwords.ts b/packages/shared/src/types/passwords.ts similarity index 100% rename from packages/types/src/passwords.ts rename to packages/shared/src/types/passwords.ts diff --git a/packages/types/src/permission.ts b/packages/shared/src/types/permission.ts similarity index 100% rename from packages/types/src/permission.ts rename to packages/shared/src/types/permission.ts diff --git a/packages/types/src/phoneCodeChannel.ts b/packages/shared/src/types/phoneCodeChannel.ts similarity index 100% rename from packages/types/src/phoneCodeChannel.ts rename to packages/shared/src/types/phoneCodeChannel.ts diff --git a/packages/types/src/phoneNumber.ts b/packages/shared/src/types/phoneNumber.ts similarity index 100% rename from packages/types/src/phoneNumber.ts rename to packages/shared/src/types/phoneNumber.ts diff --git a/packages/types/src/protect.ts b/packages/shared/src/types/protect.ts similarity index 100% rename from packages/types/src/protect.ts rename to packages/shared/src/types/protect.ts diff --git a/packages/types/src/redirects.ts b/packages/shared/src/types/redirects.ts similarity index 100% rename from packages/types/src/redirects.ts rename to packages/shared/src/types/redirects.ts diff --git a/packages/types/src/resource.ts b/packages/shared/src/types/resource.ts similarity index 100% rename from packages/types/src/resource.ts rename to packages/shared/src/types/resource.ts diff --git a/packages/types/src/role.ts b/packages/shared/src/types/role.ts similarity index 100% rename from packages/types/src/role.ts rename to packages/shared/src/types/role.ts diff --git a/packages/types/src/router.ts b/packages/shared/src/types/router.ts similarity index 100% rename from packages/types/src/router.ts rename to packages/shared/src/types/router.ts diff --git a/packages/types/src/runtime-values.ts b/packages/shared/src/types/runtime-values.ts similarity index 100% rename from packages/types/src/runtime-values.ts rename to packages/shared/src/types/runtime-values.ts diff --git a/packages/types/src/saml.ts b/packages/shared/src/types/saml.ts similarity index 100% rename from packages/types/src/saml.ts rename to packages/shared/src/types/saml.ts diff --git a/packages/types/src/samlAccount.ts b/packages/shared/src/types/samlAccount.ts similarity index 100% rename from packages/types/src/samlAccount.ts rename to packages/shared/src/types/samlAccount.ts diff --git a/packages/types/src/samlConnection.ts b/packages/shared/src/types/samlConnection.ts similarity index 100% rename from packages/types/src/samlConnection.ts rename to packages/shared/src/types/samlConnection.ts diff --git a/packages/types/src/session.ts b/packages/shared/src/types/session.ts similarity index 100% rename from packages/types/src/session.ts rename to packages/shared/src/types/session.ts diff --git a/packages/types/src/sessionVerification.ts b/packages/shared/src/types/sessionVerification.ts similarity index 100% rename from packages/types/src/sessionVerification.ts rename to packages/shared/src/types/sessionVerification.ts diff --git a/packages/types/src/signIn.ts b/packages/shared/src/types/signIn.ts similarity index 100% rename from packages/types/src/signIn.ts rename to packages/shared/src/types/signIn.ts diff --git a/packages/types/src/signInCommon.ts b/packages/shared/src/types/signInCommon.ts similarity index 100% rename from packages/types/src/signInCommon.ts rename to packages/shared/src/types/signInCommon.ts diff --git a/packages/types/src/signInFuture.ts b/packages/shared/src/types/signInFuture.ts similarity index 100% rename from packages/types/src/signInFuture.ts rename to packages/shared/src/types/signInFuture.ts diff --git a/packages/types/src/signUp.ts b/packages/shared/src/types/signUp.ts similarity index 100% rename from packages/types/src/signUp.ts rename to packages/shared/src/types/signUp.ts diff --git a/packages/types/src/signUpCommon.ts b/packages/shared/src/types/signUpCommon.ts similarity index 100% rename from packages/types/src/signUpCommon.ts rename to packages/shared/src/types/signUpCommon.ts diff --git a/packages/types/src/signUpFuture.ts b/packages/shared/src/types/signUpFuture.ts similarity index 100% rename from packages/types/src/signUpFuture.ts rename to packages/shared/src/types/signUpFuture.ts diff --git a/packages/types/src/snapshots.ts b/packages/shared/src/types/snapshots.ts similarity index 100% rename from packages/types/src/snapshots.ts rename to packages/shared/src/types/snapshots.ts diff --git a/packages/types/src/ssr.ts b/packages/shared/src/types/ssr.ts similarity index 100% rename from packages/types/src/ssr.ts rename to packages/shared/src/types/ssr.ts diff --git a/packages/types/src/state.ts b/packages/shared/src/types/state.ts similarity index 100% rename from packages/types/src/state.ts rename to packages/shared/src/types/state.ts diff --git a/packages/types/src/strategies.ts b/packages/shared/src/types/strategies.ts similarity index 100% rename from packages/types/src/strategies.ts rename to packages/shared/src/types/strategies.ts diff --git a/packages/types/src/telemetry.ts b/packages/shared/src/types/telemetry.ts similarity index 100% rename from packages/types/src/telemetry.ts rename to packages/shared/src/types/telemetry.ts diff --git a/packages/types/src/theme.ts b/packages/shared/src/types/theme.ts similarity index 100% rename from packages/types/src/theme.ts rename to packages/shared/src/types/theme.ts diff --git a/packages/types/src/token.ts b/packages/shared/src/types/token.ts similarity index 100% rename from packages/types/src/token.ts rename to packages/shared/src/types/token.ts diff --git a/packages/types/src/totp.ts b/packages/shared/src/types/totp.ts similarity index 100% rename from packages/types/src/totp.ts rename to packages/shared/src/types/totp.ts diff --git a/packages/types/src/user.ts b/packages/shared/src/types/user.ts similarity index 99% rename from packages/types/src/user.ts rename to packages/shared/src/types/user.ts index 951735d88c6..54b949411d3 100644 --- a/packages/types/src/user.ts +++ b/packages/shared/src/types/user.ts @@ -50,6 +50,10 @@ declare global { interface UserUnsafeMetadata { [k: string]: unknown; } + + interface ikosadfas { + [k: string]: unknown; + } } /** diff --git a/packages/types/src/userOrganizationInvitation.ts b/packages/shared/src/types/userOrganizationInvitation.ts similarity index 100% rename from packages/types/src/userOrganizationInvitation.ts rename to packages/shared/src/types/userOrganizationInvitation.ts diff --git a/packages/types/src/userSettings.ts b/packages/shared/src/types/userSettings.ts similarity index 100% rename from packages/types/src/userSettings.ts rename to packages/shared/src/types/userSettings.ts diff --git a/packages/types/src/utils.ts b/packages/shared/src/types/utils copy.ts similarity index 100% rename from packages/types/src/utils.ts rename to packages/shared/src/types/utils copy.ts diff --git a/packages/shared/src/types/utils.ts b/packages/shared/src/types/utils.ts index 7d406a3f1f5..50c968bcd31 100644 --- a/packages/shared/src/types/utils.ts +++ b/packages/shared/src/types/utils.ts @@ -5,3 +5,121 @@ export type Simplify = { [K in keyof T]: T[K]; } & {}; + +export type SnakeToCamel = T extends `${infer A}_${infer B}` + ? `${Uncapitalize}${Capitalize>}` + : T extends object + ? { [K in keyof T as SnakeToCamel]: T[K] } + : T; + +export type DeepSnakeToCamel = T extends `${infer A}_${infer B}` + ? `${Uncapitalize}${Capitalize>}` + : T extends object + ? { [K in keyof T as DeepSnakeToCamel]: DeepSnakeToCamel } + : T; + +export type DeepCamelToSnake = T extends `${infer C0}${infer R}` + ? `${C0 extends Uppercase ? '_' : ''}${Lowercase}${DeepCamelToSnake}` + : T extends object + ? { + [K in keyof T as DeepCamelToSnake>]: DeepCamelToSnake; + } + : T; + +export type CamelToSnake = T extends `${infer C0}${infer R}` + ? `${C0 extends Uppercase ? '_' : ''}${Lowercase}${CamelToSnake}` + : T extends object + ? { + [K in keyof T as CamelToSnake>]: T[K]; + } + : T; + +/** + * @internal + */ +export type DeepPartial = { + [P in keyof T]?: T[P] extends object ? DeepPartial : T[P]; +}; + +export type DeepRequired = Required<{ + [P in keyof T]: T[P] extends object | undefined ? DeepRequired> : T[P]; +}>; + +export type Nullable = { + [P in keyof T]: P extends K ? T[P] | null : T[P]; +}; + +/** + * Internal type used by RecordToPath + */ +type PathImpl = Key extends string + ? T[Key] extends Record + ? + | `${Key}.${PathImpl> & string}` + | `${Key}.${Exclude & string}` + : never + : never; + +/** + * Internal type used by RecordToPath + */ +type PathImpl2 = PathImpl | keyof T; + +/** + * Used to construct a type union containing all the keys (even if nested) of an object defined as const + * const obj = { a: { b: '' }, c: '' } as const; + * type Paths = RecordToPath + * Paths contains: 'a' | 'a.b' | 'c' + */ +export type RecordToPath = PathImpl2 extends string | keyof T ? PathImpl2 : keyof T; + +/** + * Used to read the value of a string path inside an object defined as const + * const obj = { a: { b: 'hello' }} as const; + * type Value = PathValue + * Value is now a union set containing a single type: 'hello' + */ +export type PathValue> = P extends `${infer Key}.${infer Rest}` + ? Key extends keyof T + ? Rest extends RecordToPath + ? PathValue + : never + : never + : P extends keyof T + ? T[P] + : never; + +// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type +type IsSerializable = T extends Function ? false : true; + +/** + * Excludes any non-serializable prop from an object + * + * @hidden + */ +export type Serializable = { + [K in keyof T as IsSerializable extends true ? K : never]: T[K]; +}; + +/** + * Enables autocompletion for a union type, while keeping the ability to use any string + * or type of `T` + * + * @internal + */ +export type Autocomplete = U | (T & Record); + +/** + * Omit without union flattening + */ +export type Without = { + [P in keyof T as Exclude]: T[P]; +}; + +/** + * Overrides the type of existing properties + * const obj = { a: string, b: number } as const; + * type Value = Override + * Value contains: { a:string, b: string } + */ +export type Override = Omit & U; diff --git a/packages/types/src/verification.ts b/packages/shared/src/types/verification.ts similarity index 100% rename from packages/types/src/verification.ts rename to packages/shared/src/types/verification.ts diff --git a/packages/types/src/waitlist.ts b/packages/shared/src/types/waitlist.ts similarity index 100% rename from packages/types/src/waitlist.ts rename to packages/shared/src/types/waitlist.ts diff --git a/packages/types/src/web3.ts b/packages/shared/src/types/web3.ts similarity index 100% rename from packages/types/src/web3.ts rename to packages/shared/src/types/web3.ts diff --git a/packages/types/src/web3Wallet.ts b/packages/shared/src/types/web3Wallet.ts similarity index 100% rename from packages/types/src/web3Wallet.ts rename to packages/shared/src/types/web3Wallet.ts diff --git a/packages/shared/src/web3.ts b/packages/shared/src/web3.ts index 7f84ffcebf5..25392eece24 100644 --- a/packages/shared/src/web3.ts +++ b/packages/shared/src/web3.ts @@ -1,4 +1,4 @@ -import type { Web3ProviderData } from '@clerk/types'; +import type { Web3ProviderData } from './types'; export const WEB3_PROVIDERS: Web3ProviderData[] = [ { diff --git a/packages/shared/src/workerTimers/createWorkerTimers.ts b/packages/shared/src/workerTimers/createWorkerTimers.ts index fd465acbcc6..d2b02dcd673 100644 --- a/packages/shared/src/workerTimers/createWorkerTimers.ts +++ b/packages/shared/src/workerTimers/createWorkerTimers.ts @@ -1,4 +1,5 @@ import { noop } from '../utils/noop'; +import pollerWorkerSource from './workerTimers.built'; import type { WorkerClearTimeout, WorkerSetTimeout, @@ -7,9 +8,6 @@ import type { WorkerTimerId, WorkerTimerResponseEvent, } from './workerTimers.types'; -// @ts-ignore -// eslint-disable-next-line import/default -import pollerWorkerSource from './workerTimers.worker'; const createWebWorker = (source: string, opts: ConstructorParameters[1] = {}): Worker | null => { if (typeof Worker === 'undefined') { diff --git a/packages/shared/src/workerTimers/workerTimers.built.ts b/packages/shared/src/workerTimers/workerTimers.built.ts new file mode 100644 index 00000000000..29b404ec2cc --- /dev/null +++ b/packages/shared/src/workerTimers/workerTimers.built.ts @@ -0,0 +1,20 @@ +/** + * + * This is the minified string output of transforming workerTimers.worker.ts + * Once the tsdown docs are complete, we will write a similar plugin as the one below: + * + * (this was the previous esbuild plugin we were using) + * export const WebWorkerMinifyPlugin: Plugin = { + * name: 'WebWorkerMinifyPlugin', + * setup(build) { + * build.onLoad({ filter: /\.worker\.ts/ }, async args => { + * console.log('aaaaaaaaaaaaa'); + * const f = await readFile(args.path); + * const js = await esbuild.transform(f, { loader: 'ts', minify: true }); + * return { loader: 'text', contents: js.code }; + * }); + * }, + * }; + * + */ +export default 'const respond=r=>{self.postMessage(r)},workerToTabIds={};self.addEventListener("message",r=>{const e=r.data;switch(e.type){case"setTimeout":workerToTabIds[e.id]=setTimeout(()=>{respond({id:e.id}),delete workerToTabIds[e.id]},e.ms);break;case"clearTimeout":workerToTabIds[e.id]&&(clearTimeout(workerToTabIds[e.id]),delete workerToTabIds[e.id]);break;case"setInterval":workerToTabIds[e.id]=setInterval(()=>{respond({id:e.id})},e.ms);break;case"clearInterval":workerToTabIds[e.id]&&(clearInterval(workerToTabIds[e.id]),delete workerToTabIds[e.id]);break}});\n'; diff --git a/packages/shared/tsconfig.declarations.json b/packages/shared/tsconfig.declarations.json deleted file mode 100644 index b97a0330a47..00000000000 --- a/packages/shared/tsconfig.declarations.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "declarationDir": "./dist", - "declarationMap": true, - "emitDeclarationOnly": true, - "skipLibCheck": true - }, - "exclude": ["**/__tests__/**/*"] -} diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index 05919363e30..fbb3e74d4c8 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -1,18 +1,26 @@ { "compilerOptions": { - "target": "ES2022", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "isolatedModules": true, - "moduleResolution": "Bundler", - "module": "ESNext", - "preserveWatchOutput": true, - "skipLibCheck": true, + "rootDir": "src", + "verbatimModuleSyntax": true, + "types": ["node"], + "target": "es2022", "strict": true, - "outDir": "dist", + "skipLibCheck": true, "resolveJsonModule": true, + "preserveWatchOutput": true, + "outDir": "dist", + "noUnusedLocals": true, + "moduleResolution": "bundler", + "moduleDetection": "force", + "module": "preserve", + "lib": ["ES2023", "DOM", "WebWorker"], "jsx": "react", - "lib": ["ES2022", "DOM", "WebWorker"], + "isolatedModules": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "emitDeclarationOnly": true, + "declaration": true, + "declarationMap": true, "allowJs": true }, "exclude": ["node_modules"], diff --git a/packages/shared/tsdown.config.mts b/packages/shared/tsdown.config.mts new file mode 100644 index 00000000000..6029406da87 --- /dev/null +++ b/packages/shared/tsdown.config.mts @@ -0,0 +1,45 @@ +import type { Options } from 'tsdown'; +import { defineConfig } from 'tsdown'; + +import clerkJsPackage from '../clerk-js/package.json' with { type: 'json' }; +import sharedPackage from './package.json' with { type: 'json' }; + +export default defineConfig(({ watch }) => { + const common = { + dts: true, + sourcemap: true, + clean: true, + target: 'es2022', + platform: 'neutral', + external: ['react', 'react-dom'], + format: ['cjs', 'esm'], + minify: false, + define: { + PACKAGE_NAME: `"${sharedPackage.name}"`, + PACKAGE_VERSION: `"${sharedPackage.version}"`, + JS_PACKAGE_VERSION: `"${clerkJsPackage.version}"`, + __DEV__: `${watch}`, + }, + } satisfies Options; + + return [ + { + ...common, + entry: ['./src/types/index.ts'], + unbundle: false, + outDir: './dist/types', + }, + // { + // ...common, + // entry: [ + // // all files except types + // './src/*.{ts,tsx}', + // './src/*/index.{ts,tsx}', + // // '!./src/types/*.{ts,tsx}', + // '!./src/**/*.{test,spec}.{ts,tsx}', + // ], + // outDir: './dist/runtime', + // unbundle: false, + // }, + ]; +}); diff --git a/packages/shared/tsup.config.ts b/packages/shared/tsup.config.ts deleted file mode 100644 index 5ced114533c..00000000000 --- a/packages/shared/tsup.config.ts +++ /dev/null @@ -1,52 +0,0 @@ -import type { Plugin } from 'esbuild'; -import * as esbuild from 'esbuild'; -import { readFile } from 'fs/promises'; -import { defineConfig } from 'tsup'; - -import { version as clerkJsVersion } from '../clerk-js/package.json'; -import { name, version } from './package.json'; - -export default defineConfig(overrideOptions => { - const isWatch = !!overrideOptions.watch; - - return { - entry: [ - './src/*.{ts,tsx}', - './src/react/index.ts', - './src/utils/index.ts', - './src/workerTimers/index.ts', - './src/dom/*.ts', - './src/types/*.ts', - '!./src/**/*.test.{ts,tsx}', - ], - format: ['cjs', 'esm'], - bundle: true, - clean: true, - minify: false, - sourcemap: true, - dts: true, - target: 'es2022', - external: ['react', 'react-dom'], - esbuildPlugins: [WebWorkerMinifyPlugin as any], - define: { - PACKAGE_NAME: `"${name}"`, - PACKAGE_VERSION: `"${version}"`, - JS_PACKAGE_VERSION: `"${clerkJsVersion}"`, - __DEV__: `${isWatch}`, - }, - }; -}); - -// Read transform and minify any files ending in .worker.ts -// These files can be imported as modules and used as string when instantiating -// a new web worker, without loading an external file during runtime -export const WebWorkerMinifyPlugin: Plugin = { - name: 'WebWorkerMinifyPlugin', - setup(build) { - build.onLoad({ filter: /\.worker\.ts/ }, async args => { - const f = await readFile(args.path); - const js = await esbuild.transform(f, { loader: 'ts', minify: true }); - return { loader: 'text', contents: js.code }; - }); - }, -}; diff --git a/packages/shared/vitest.config.mts b/packages/shared/vitest.config.mts index b8782de3ebc..c9bed83ea30 100644 --- a/packages/shared/vitest.config.mts +++ b/packages/shared/vitest.config.mts @@ -13,7 +13,7 @@ export default defineConfig({ CLERK_SECRET_KEY: 'TEST_SECRET_KEY', }, environment: 'jsdom', - include: ['**/*.{spec,test}.{js,ts,jsx,tsx}'], + include: ['**/*..{js,ts,jsx,tsx}'], setupFiles: './vitest.setup.mts', }, }); diff --git a/packages/themes/package.json b/packages/themes/package.json index 1cb82b11e5b..a6083967794 100644 --- a/packages/themes/package.json +++ b/packages/themes/package.json @@ -48,7 +48,7 @@ "lint:attw": "attw --pack . --exclude-entrypoints shadcn.css --profile node16" }, "dependencies": { - "@clerk/types": "workspace:^", + "@clerk/shared": "workspace:^", "tslib": "catalog:repo" }, "devDependencies": { diff --git a/packages/themes/src/createTheme.ts b/packages/themes/src/createTheme.ts index b6e022e1e04..e5bccc19df7 100644 --- a/packages/themes/src/createTheme.ts +++ b/packages/themes/src/createTheme.ts @@ -1,6 +1,6 @@ // Temp way to import the type. We will clean this up when we extract // theming into its own package -import type { BaseTheme, DeepPartial, Elements, Theme } from '@clerk/types'; +import type { BaseTheme, DeepPartial, Elements, Theme } from '@clerk/shared/types'; import type { InternalTheme } from '../../clerk-js/src/ui/foundations'; diff --git a/packages/themes/tsconfig.build.json b/packages/themes/tsconfig.build.json deleted file mode 100644 index 4cff749aa58..00000000000 --- a/packages/themes/tsconfig.build.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "compilerOptions": { - "outDir": "dist", - "baseUrl": ".", - "lib": ["es6", "dom"], - "module": "commonjs", - "moduleResolution": "node", - "importHelpers": true, - "declaration": true, - "declarationMap": false, - "noImplicitReturns": true, - "noUnusedLocals": false, - "noUnusedParameters": true, - "resolveJsonModule": true, - "sourceMap": false, - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true, - "allowJs": true, - "target": "ES2019" - }, - "include": ["src"] -} diff --git a/packages/themes/tsconfig.json b/packages/themes/tsconfig.json index bbee8dfdabe..6cc55e67b3b 100644 --- a/packages/themes/tsconfig.json +++ b/packages/themes/tsconfig.json @@ -1,6 +1,23 @@ { - "extends": "./tsconfig.build.json", "compilerOptions": { - "incremental": true - } + "outDir": "dist", + "baseUrl": ".", + "lib": ["es6", "dom"], + "module": "nodenext", + "moduleResolution": "nodenext", + "importHelpers": true, + "declaration": true, + "declarationMap": false, + "noImplicitReturns": true, + "noUnusedLocals": false, + "noUnusedParameters": true, + "resolveJsonModule": true, + "sourceMap": false, + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "allowJs": true, + "target": "es2020" + }, + "include": ["src"] } diff --git a/packages/themes/tsup.config.ts b/packages/themes/tsup.config.ts index 4e91f53be8d..ad4d2719a51 100644 --- a/packages/themes/tsup.config.ts +++ b/packages/themes/tsup.config.ts @@ -10,7 +10,6 @@ export default defineConfig({ minify: false, sourcemap: false, dts: true, - tsconfig: './tsconfig.build.json', target: 'es2020', onSuccess: async () => { // Ensure dist/themes directory exists diff --git a/packages/types/package.json b/packages/types/package.json index ba91c3ecaca..bec0d7e5aa1 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -23,25 +23,32 @@ }, "license": "MIT", "author": "Clerk", - "main": "dist/index.js", - "module": "dist/esm/index.js", - "types": "dist/index.d.ts", + "exports": { + ".": { + "import": { + "types": "./src/index.d.mts", + "default": "./src/index.mjs" + }, + "require": { + "types": "./src/index.d.ts", + "default": "./src/index.js" + } + } + }, + "main": "src/index.js", + "module": "src/index.js", + "types": "src/index.d.ts", "files": [ - "dist" + "src" ], "scripts": { - "build": "tsup --env.NODE_ENV production", - "build:declarations": "tsc -p tsconfig.declarations.json", - "clean": "rimraf ./dist", - "dev": "tsup --watch", "format": "node ../../scripts/format-package.mjs", "format:check": "node ../../scripts/format-package.mjs --check", "lint": "eslint src", - "lint:attw": "attw --pack . --profile node16", - "publish:local": "pnpm yalc push --replace --sig" + "lint:attw": "attw --pack . --profile node16" }, "dependencies": { - "csstype": "3.1.3" + "@clerk/shared": "workspace:^" }, "devDependencies": {}, "engines": { diff --git a/packages/types/src/index.d.mts b/packages/types/src/index.d.mts new file mode 100644 index 00000000000..77f6e2f716c --- /dev/null +++ b/packages/types/src/index.d.mts @@ -0,0 +1,9 @@ +/** + * `@clerk/types` is now merged with `@clerk/shared` + * Please import from `@clerk/shared/types` instead. + * + * This export exists for backwards compatibility + * until we drop the package completely with the next major release. + */ +export type * from '@clerk/shared/types'; +//# sourceMappingURL=index.d.ts.map diff --git a/packages/types/src/index.d.ts b/packages/types/src/index.d.ts new file mode 100644 index 00000000000..77f6e2f716c --- /dev/null +++ b/packages/types/src/index.d.ts @@ -0,0 +1,9 @@ +/** + * `@clerk/types` is now merged with `@clerk/shared` + * Please import from `@clerk/shared/types` instead. + * + * This export exists for backwards compatibility + * until we drop the package completely with the next major release. + */ +export type * from '@clerk/shared/types'; +//# sourceMappingURL=index.d.ts.map diff --git a/packages/types/src/index.js b/packages/types/src/index.js new file mode 100644 index 00000000000..cb0ff5c3b54 --- /dev/null +++ b/packages/types/src/index.js @@ -0,0 +1 @@ +export {}; diff --git a/packages/types/src/index.mjs b/packages/types/src/index.mjs new file mode 100644 index 00000000000..cb0ff5c3b54 --- /dev/null +++ b/packages/types/src/index.mjs @@ -0,0 +1 @@ +export {}; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts deleted file mode 100644 index e5d17f28dc8..00000000000 --- a/packages/types/src/index.ts +++ /dev/null @@ -1,83 +0,0 @@ -export * from './apiKeys'; -export * from './apiKeysSettings'; -export * from './appearance'; -export * from './attributes'; -export * from './authConfig'; -export * from './authObject'; -export * from './backupCode'; -export * from './billing'; -export * from './clerk'; -export * from './client'; -export * from './commerceSettings'; -export * from './customMenuItems'; -export * from './customPages'; -export * from './deletedObject'; -export * from './displayConfig'; -export * from './elementIds'; -export * from './emailAddress'; -export * from './enterpriseAccount'; -export * from './environment'; -export * from './errors'; -export * from './externalAccount'; -export * from './factors'; -export * from './hooks'; -export * from './identificationLink'; -export * from './identifiers'; -export * from './image'; -export * from './instance'; -export * from './json'; -export * from './jwt'; -export * from './jwtv2'; -export * from './key'; -export * from './localization'; -export * from './multiDomain'; -export * from './oauth'; -export * from './organization'; -export * from './organizationDomain'; -export * from './organizationInvitation'; -export * from './organizationMembership'; -export * from './organizationMembershipRequest'; -export * from './organizationSettings'; -export * from './organizationSuggestion'; -export * from './pagination'; -export * from './passkey'; -export * from './passwords'; -export * from './permission'; -export * from './phoneCodeChannel'; -export * from './phoneNumber'; -export * from './protect'; -export * from './redirects'; -export * from './resource'; -export * from './role'; -export * from './router'; -/** - * TODO @revamp-hooks: Drop this in the next major release. - */ -export * from './runtime-values'; -export * from './saml'; -export * from './samlAccount'; -export * from './samlConnection'; -export * from './session'; -export * from './sessionVerification'; -export * from './signIn'; -export * from './signInCommon'; -export * from './signInFuture'; -export * from './signUp'; -export * from './signUpCommon'; -export * from './signUpFuture'; -export * from './snapshots'; -export * from './ssr'; -export * from './state'; -export * from './strategies'; -export * from './telemetry'; -export * from './theme'; -export * from './token'; -export * from './totp'; -export * from './user'; -export * from './userOrganizationInvitation'; -export * from './userSettings'; -export * from './utils'; -export * from './verification'; -export * from './waitlist'; -export * from './web3'; -export * from './web3Wallet'; diff --git a/packages/types/tsconfig.build.json b/packages/types/tsconfig.build.json deleted file mode 100644 index 7f85b7d24bb..00000000000 --- a/packages/types/tsconfig.build.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "outDir": "dist", - "baseUrl": ".", - "lib": ["es6", "dom"], - "module": "commonjs", - "moduleResolution": "node", - "declaration": true, - "declarationMap": false, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "sourceMap": false, - "strict": true, - "types": [] - }, - "include": ["src/**/*.ts"], - "exclude": ["node_modules"] -} diff --git a/packages/types/tsconfig.declarations.json b/packages/types/tsconfig.declarations.json deleted file mode 100644 index b97a0330a47..00000000000 --- a/packages/types/tsconfig.declarations.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "declaration": true, - "declarationDir": "./dist", - "declarationMap": true, - "emitDeclarationOnly": true, - "skipLibCheck": true - }, - "exclude": ["**/__tests__/**/*"] -} diff --git a/packages/types/tsconfig.json b/packages/types/tsconfig.json deleted file mode 100644 index 2dc99c17b81..00000000000 --- a/packages/types/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "outDir": "./dist", - "baseUrl": ".", - "lib": ["es6", "dom"], - "module": "NodeNext", - "moduleResolution": "NodeNext", - "declaration": true, - "declarationMap": true, - "noImplicitReturns": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "resolveJsonModule": true, - "sourceMap": false, - "strict": true, - "types": [] - }, - "include": ["src"], - "exclude": ["node_modules"] -} diff --git a/packages/types/tsup.config.ts b/packages/types/tsup.config.ts deleted file mode 100644 index 7b74421dbb4..00000000000 --- a/packages/types/tsup.config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineConfig } from 'tsup'; - -export default defineConfig(overrideOptions => { - return { - entry: { - index: 'src/index.ts', - }, - onSuccess: overrideOptions.watch ? 'pnpm build:declarations' : undefined, - minify: false, - clean: true, - sourcemap: true, - format: ['cjs', 'esm'], - legacyOutput: true, - dts: !overrideOptions.watch, - }; -}); diff --git a/packages/vue/src/components/CheckoutButton.vue b/packages/vue/src/components/CheckoutButton.vue index 8867c918fd8..3d5332a4e61 100644 --- a/packages/vue/src/components/CheckoutButton.vue +++ b/packages/vue/src/components/CheckoutButton.vue @@ -1,6 +1,6 @@