@tern-secure/react 1.2.0-canary.v20251030165007 → 1.2.0-canary.v20251125170702
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/TernSecureHostRenderer.d.mts +24 -0
- package/dist/components/TernSecureHostRenderer.d.ts +24 -0
- package/dist/components/TernSecureHostRenderer.js +2 -0
- package/dist/components/TernSecureHostRenderer.js.map +1 -0
- package/dist/components/TernSecureHostRenderer.mjs +2 -0
- package/dist/components/TernSecureHostRenderer.mjs.map +1 -0
- package/dist/components/uiComponent.d.mts +30 -0
- package/dist/components/uiComponent.d.ts +30 -0
- package/dist/components/uiComponent.js +2 -0
- package/dist/components/uiComponent.js.map +1 -0
- package/dist/components/uiComponent.mjs +2 -0
- package/dist/components/uiComponent.mjs.map +1 -0
- package/dist/components/withTernSecure.d.mts +16 -0
- package/dist/components/withTernSecure.d.ts +16 -0
- package/dist/components/withTernSecure.js +2 -0
- package/dist/components/withTernSecure.js.map +1 -0
- package/dist/components/withTernSecure.mjs +2 -0
- package/dist/components/withTernSecure.mjs.map +1 -0
- package/dist/ctx/AuthProvider.d.mts +2 -2
- package/dist/ctx/AuthProvider.d.ts +2 -2
- package/dist/ctx/IsomorphicTernSecureCtx.d.mts +2 -2
- package/dist/ctx/IsomorphicTernSecureCtx.d.ts +2 -2
- package/dist/ctx/TernSecureCtxProvider.d.mts +2 -2
- package/dist/ctx/TernSecureCtxProvider.d.ts +2 -2
- package/dist/ctx/TernSecureCtxProvider.js +1 -1
- package/dist/ctx/TernSecureCtxProvider.js.map +1 -1
- package/dist/ctx/TernSecureCtxProvider.mjs +1 -1
- package/dist/ctx/TernSecureCtxProvider.mjs.map +1 -1
- package/dist/ctx/TernSecureProvider.d.mts +2 -2
- package/dist/ctx/TernSecureProvider.d.ts +2 -2
- package/dist/hooks/useMaxAllowedInstances.d.mts +6 -0
- package/dist/hooks/useMaxAllowedInstances.d.ts +6 -0
- package/dist/hooks/useMaxAllowedInstances.js +2 -0
- package/dist/hooks/useMaxAllowedInstances.js.map +1 -0
- package/dist/hooks/useMaxAllowedInstances.mjs +2 -0
- package/dist/hooks/useMaxAllowedInstances.mjs.map +1 -0
- package/dist/hooks/useSignIn.d.mts +4 -4
- package/dist/hooks/useSignIn.d.ts +4 -4
- package/dist/hooks/useSignIn.js +1 -1
- package/dist/hooks/useSignIn.js.map +1 -1
- package/dist/hooks/useSignIn.mjs +1 -1
- package/dist/hooks/useSignIn.mjs.map +1 -1
- package/dist/hooks/useWaitForComponentMount.d.mts +8 -0
- package/dist/hooks/useWaitForComponentMount.d.ts +8 -0
- package/dist/hooks/useWaitForComponentMount.js +2 -0
- package/dist/hooks/useWaitForComponentMount.js.map +1 -0
- package/dist/hooks/useWaitForComponentMount.mjs +2 -0
- package/dist/hooks/useWaitForComponentMount.mjs.map +1 -0
- package/dist/index.d.mts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/lib/isoTernSecureAuth.d.mts +29 -5
- package/dist/lib/isoTernSecureAuth.d.ts +29 -5
- package/dist/lib/isoTernSecureAuth.js +1 -1
- package/dist/lib/isoTernSecureAuth.js.map +1 -1
- package/dist/lib/isoTernSecureAuth.mjs +1 -1
- package/dist/lib/isoTernSecureAuth.mjs.map +1 -1
- package/dist/types.d.mts +43 -28
- package/dist/types.d.ts +43 -28
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/debug.d.mts +2 -1
- package/dist/utils/debug.d.ts +2 -1
- package/dist/utils/debug.js +1 -1
- package/dist/utils/debug.js.map +1 -1
- package/dist/utils/debug.mjs +1 -1
- package/dist/utils/debug.mjs.map +1 -1
- package/dist/utils/isConstructor.d.mts +3 -0
- package/dist/utils/isConstructor.d.ts +3 -0
- package/dist/utils/isConstructor.js +2 -0
- package/dist/utils/isConstructor.js.map +1 -0
- package/dist/utils/isConstructor.mjs +2 -0
- package/dist/utils/isConstructor.mjs.map +1 -0
- package/package.json +4 -5
- package/dist/ctx/SignInCtx.d.mts +0 -27
- package/dist/ctx/SignInCtx.d.ts +0 -27
- package/dist/ctx/SignInCtx.js +0 -2
- package/dist/ctx/SignInCtx.js.map +0 -1
- package/dist/ctx/SignInCtx.mjs +0 -2
- package/dist/ctx/SignInCtx.mjs.map +0 -1
- package/dist/ctx/SignUpCtx.d.mts +0 -22
- package/dist/ctx/SignUpCtx.d.ts +0 -22
- package/dist/ctx/SignUpCtx.js +0 -2
- package/dist/ctx/SignUpCtx.js.map +0 -1
- package/dist/ctx/SignUpCtx.mjs +0 -2
- package/dist/ctx/SignUpCtx.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/isoTernSecureAuth.ts"],"sourcesContent":["import { TernSecureAuth as TernSecureAuthImpl } from '@tern-secure/auth';\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n CreateActiveSessionParams,\n DomainOrProxyUrl,\n ListenerCallback,\n SignedInSession,\n SignInRedirectOptions,\n SignInResource,\n SignOutOptions,\n SignUpRedirectOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthOptions,\n TernSecureAuthStatus,\n UnsubscribeCallback,\n} from '@tern-secure/types';\n\nimport type { IsoTernSecureAuthOptions, TernSecureAuthProps } from '../types';\n\nconst SDK_METADATA = {\n name: __PACKAGE_NAME__,\n version: __PACKAGE_VERSION__,\n environment: process.env.NODE_ENV,\n};\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\n/**\n * IsomorphicTernSecure class manages the auth state and UI rendering\n * in both browser and server environments, acting as a proxy for TernSecureAuth\n */\nexport class IsoTernSecureAuth implements TernSecureAuth {\n private readonly _mode: 'browser' | 'server';\n private readonly options: IsoTernSecureAuthOptions;\n private readonly TernSecureAuth: TernSecureAuthProps;\n private ternauth: TernSecureAuthProps | null = null;\n private preAddListener = new Map<ListenerCallback, { unsubscribe: UnsubscribeCallback }>();\n\n #status: TernSecureAuthStatus = 'loading';\n #apiUrl: string | undefined;\n #domain: DomainOrProxyUrl['domain'];\n #proxyUrl: DomainOrProxyUrl['proxyUrl'];\n #eventBus = createTernAuthEventBus();\n\n static #instance: IsoTernSecureAuth | null | undefined;\n\n get status(): TernSecureAuthStatus {\n if (!this.ternauth) {\n return this.#status;\n }\n return this.ternauth.status || (this.ternauth.isReady ? 'ready' : 'loading');\n }\n\n get isReady(): boolean {\n return this.ternauth?.isReady || false;\n }\n\n get isLoading(): boolean {\n return this.ternauth?.isLoading || false;\n }\n\n get requiresVerification(): boolean {\n return this.options.requiresVerification ?? true;\n }\n\n get signIn(): SignInResource | undefined {\n if (this.ternauth) {\n return this.ternauth.signIn || undefined;\n }\n return undefined;\n }\n\n get signUp(): SignUpResource | undefined {\n if (this.ternauth) {\n return this.ternauth.signUp || undefined;\n }\n return undefined;\n }\n\n get user() {\n if (this.ternauth) {\n return this.ternauth.user;\n }\n return null;\n }\n\n static getOrCreateInstance(options: IsoTernSecureAuthOptions) {\n if (\n !inBrowser() ||\n !this.#instance ||\n (options.TernSecureAuth && this.#instance.TernSecureAuth !== options.TernSecureAuth)\n ) {\n this.#instance = new IsoTernSecureAuth(options);\n }\n return this.#instance;\n }\n\n static clearInstances() {\n if (this.#instance) {\n this.#instance.ternauth = null;\n this.#instance = null;\n }\n }\n\n static clearInstance() {\n this.#instance = null;\n }\n\n get domain(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#domain, new URL(window.location.href), '');\n }\n if (typeof this.#domain === 'function') {\n throw new Error('Unsupported customDomain type: function');\n }\n return this.#domain || '';\n }\n\n get proxyUrl(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#proxyUrl, new URL(window.location.href), '');\n }\n if (typeof this.#proxyUrl === 'function') {\n throw new Error('Unsupported customProxyUrl type: function');\n }\n return this.#proxyUrl || '';\n }\n\n get mode(): 'browser' | 'server' {\n return this._mode;\n }\n\n /**\n * @internal\n */\n public _internal_getOption<K extends keyof TernSecureAuthOptions>(\n key: K,\n ): TernSecureAuthOptions[K] | undefined {\n return this.ternauth?._internal_getOption\n ? this.ternauth?._internal_getOption(key)\n : this.options[key];\n }\n\n /**\n * @internal\n */\n public _internal_getAllOptions(): Readonly<TernSecureAuthOptions> {\n return Object.freeze({ ...this.options });\n }\n\n constructor(options: IsoTernSecureAuthOptions) {\n const { TernSecureAuth = null } = options || {};\n this.#domain = options.ternSecureConfig?.authDomain;\n this.options = { ...options };\n this._mode = inBrowser() ? 'browser' : 'server';\n this.#apiUrl = this.options.apiUrl;\n this.TernSecureAuth = TernSecureAuth;\n\n if (!this.options.sdkMetadata) {\n this.options.sdkMetadata = SDK_METADATA;\n }\n }\n\n get sdkMetadata() {\n return this.ternauth?.sdkMetadata || this.options.sdkMetadata;\n }\n\n get version() {\n return this.ternauth?.version;\n }\n\n get instanceType() {\n return this.ternauth?.instanceType;\n }\n\n get apiUrl() {\n return this.#apiUrl || '';\n }\n\n initTernSecureAuth() {\n if (this._mode !== 'browser' || this.isReady) {\n return;\n }\n\n const tern = TernSecureAuthImpl.initialize(this.options);\n this.loadTernSecureAuth(tern);\n }\n\n private loadTernSecureAuth = (ternauth: TernSecureAuthProps | undefined) => {\n if (!ternauth) {\n throw new Error('TernAuth instance is not initialized');\n }\n\n this.ternauth = ternauth;\n this.preAddListener.forEach((listenerHandlers, listener) => {\n listenerHandlers.unsubscribe = ternauth.addListener(listener);\n });\n\n this.#eventBus.getListeners('status').forEach(listener => {\n this.on('status', listener, { notify: true });\n });\n\n if (typeof this.ternauth.status === 'undefined') {\n console.log(\n '[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready',\n );\n this.#status = 'ready';\n this.#eventBus.emit(ternEvents.Status, 'ready');\n }\n\n return this.ternauth;\n };\n\n public on: TernSecureAuth['on'] = (...args) => {\n if (this.ternauth?.on) {\n return this.ternauth.on(...args);\n } else {\n return this.#eventBus.on(...args);\n }\n };\n\n public off: TernSecureAuth['off'] = (...args) => {\n if (this.ternauth?.off) {\n return this.ternauth.off(...args);\n } else {\n return this.#eventBus.off(...args);\n }\n };\n\n addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n if (this.ternauth) {\n return this.ternauth.addListener(listener);\n } else {\n const unsubscribe = () => {\n const listenerHandlers = this.preAddListener.get(listener);\n if (listenerHandlers) {\n listenerHandlers.unsubscribe();\n this.preAddListener.delete(listener);\n }\n };\n this.preAddListener.set(listener, { unsubscribe });\n return unsubscribe;\n }\n };\n\n createActiveSession = (params: CreateActiveSessionParams): Promise<void> => {\n if (this.ternauth) {\n return this.ternauth.createActiveSession(params);\n } else {\n return Promise.reject(new Error('TernSecureAuth not initialized'));\n }\n };\n\n signOut = async (options?: SignOutOptions): Promise<void> => {\n if (!this.ternauth) {\n throw new Error('TernSecureAuth not initialized');\n }\n await this.ternauth.signOut();\n };\n\n get currentSession(): SignedInSession | null {\n if (!this.ternauth) {\n return null;\n }\n return this.ternauth.currentSession;\n }\n\n onAuthStateChanged(callback: (user: any) => void): () => void {\n if (!this.ternauth) {\n console.warn(\n '[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener',\n );\n return () => {};\n }\n return this.ternauth.onAuthStateChanged(callback);\n }\n\n getRedirectResult = async (): Promise<any> => {\n if (!this.ternauth?.getRedirectResult) {\n throw new Error('TernSecure instance not initialized');\n }\n return this.ternauth.getRedirectResult();\n };\n\n constructUrlWithAuthRedirect = (to: string): string => {\n if (this.ternauth && this.isReady) {\n return this.ternauth.constructUrlWithAuthRedirect(to);\n }\n return '';\n };\n\n navigate = (to: string) => {\n if (this.ternauth && this.isReady) {\n this.ternauth.navigate(to);\n }\n };\n\n redirectToSignIn = async (options?: SignInRedirectOptions) => {\n if (this.ternauth?.redirectToSignIn) {\n this.ternauth.redirectToSignIn(options);\n }\n };\n\n redirectToSignUp = async (options?: SignUpRedirectOptions) => {\n if (this.ternauth?.redirectToSignUp) {\n this.ternauth.redirectToSignUp();\n }\n };\n\n redirectAfterSignIn = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignIn) {\n this.ternauth.redirectAfterSignIn();\n }\n };\n\n redirectAfterSignUp = (redirectUrl?: string): void => {\n if (this.ternauth?.redirectAfterSignUp) {\n this.ternauth.redirectAfterSignUp();\n }\n };\n\n #awaitForTernSecureAuth(): Promise<TernSecureAuthProps> {\n return new Promise<TernSecureAuthProps>(resolve => {\n resolve(this.ternauth);\n });\n }\n\n initialize = async (): Promise<void> => {\n this.initTernSecureAuth();\n try {\n await this.#awaitForTernSecureAuth();\n } catch (error) {\n console.error('[IsomorphicTernSecure] Failed to initialize TernSecureAuth:', error);\n throw error;\n }\n };\n}\n"],"mappings":"AAAA,OAAS,kBAAkBA,MAA0B,oBACrD,OAAS,0BAAAC,EAAwB,cAAAC,MAAkB,sCACnD,OAAS,mBAAAC,MAAuB,4BAmBhC,MAAMC,EAAe,CACnB,KAAM,qBACN,QAAS,+BACT,YAAa,QAAQ,IAAI,QAC3B,EAEO,SAASC,GAAqB,CACnC,OAAO,OAAO,OAAW,GAC3B,CAMO,MAAMC,CAA4C,CACtC,MACA,QACA,eACT,SAAuC,KACvC,eAAiB,IAAI,IAE7BC,GAAgC,UAChCC,GACAC,GACAC,GACAC,GAAYV,EAAuB,EAEnC,MAAOW,GAEP,IAAI,QAA+B,CACjC,OAAK,KAAK,SAGH,KAAK,SAAS,SAAW,KAAK,SAAS,QAAU,QAAU,WAFzD,KAAKL,EAGhB,CAEA,IAAI,SAAmB,CACrB,OAAO,KAAK,UAAU,SAAW,EACnC,CAEA,IAAI,WAAqB,CACvB,OAAO,KAAK,UAAU,WAAa,EACrC,CAEA,IAAI,sBAAgC,CAClC,OAAO,KAAK,QAAQ,sBAAwB,EAC9C,CAEA,IAAI,QAAqC,CACvC,GAAI,KAAK,SACP,OAA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AAuBY,GAA+B,CAChD,KAAK,UAAU,qBACjB,KAAK,SAAS,oBAAoB,CAEtC,EAEA,oBAAuBA,GAA+B,CAChD,KAAK,UAAU,qBACjB,KAAK,SAAS,oBAAoB,CAEtC,EAEAC,IAAwD,CACtD,OAAO,IAAI,QAA6BC,GAAW,CACjDA,EAAQ,KAAK,QAAQ,CACvB,CAAC,CACH,CAEA,WAAa,SAA2B,CACtC,KAAK,mBAAmB,EACxB,GAAI,CACF,MAAM,KAAKD,GAAwB,CACrC,OAASE,EAAO,CACd,cAAQ,MAAM,8DAA+DA,CAAK,EAC5EA,CACR,CACF,CACF","names":["TernSecureAuthImpl","createTernAuthEventBus","ternEvents","handleValueOrFn","SDK_METADATA","inBrowser","IsoTernSecureAuth","#status","#apiUrl","#domain","#proxyUrl","#eventBus","#instance","options","key","TernSecureAuth","tern","ternauth","listenerHandlers","listener","args","unsubscribe","params","callback","to","redirectUrl","#awaitForTernSecureAuth","resolve","error"]}
|
|
1
|
+
{"version":3,"sources":["../../src/lib/isoTernSecureAuth.ts"],"sourcesContent":["import { loadTernUIScript } from '@tern-secure/shared/loadTernUIScript';\nimport { createTernAuthEventBus, ternEvents } from '@tern-secure/shared/ternStatusEvent';\nimport { handleValueOrFn } from '@tern-secure/shared/utils';\nimport type {\n AuthErrorTree,\n CreateActiveSessionParams,\n DomainOrProxyUrl,\n ListenerCallback,\n SignedInSession,\n SignInProps,\n SignInRedirectOptions,\n SignInResource,\n SignOutOptions,\n SignUpProps,\n SignUpRedirectOptions,\n SignUpResource,\n TernSecureAuth,\n TernSecureAuthOptions,\n TernSecureAuthStatus,\n UnsubscribeCallback,\n} from '@tern-secure/types';\n\nimport type {\n Browser,\n BrowserConstructor,\n HeadlessUIBrowser,\n HeadlessUIBrowserConstructor,\n IsoTernSecureAuthOptions,\n TernSecureAuthProps,\n TernSecureProps\n} from '../types';\nimport { isConstructor } from '../utils/isConstructor';\n\nconst SDK_METADATA = {\n name: __PACKAGE_NAME__,\n version: __PACKAGE_VERSION__,\n environment: process.env.NODE_ENV,\n};\n\nexport interface Global {\n TernSecure?: HeadlessUIBrowser | Browser;\n}\n\ndeclare const global: Global;\n\ntype GenericFunction<TArgs = never> = (...args: TArgs[]) => unknown;\n\ntype MethodName<T> = {\n [P in keyof T]: T[P] extends GenericFunction ? P : never;\n}[keyof T];\n\ntype MethodCallback = () => Promise<unknown> | unknown;\n\ntype WithVoidReturn<F extends (...args: any) => any> = (\n ...args: Parameters<F>\n) => ReturnType<F> extends Promise<infer T> ? Promise<T | void> : ReturnType<F> | void;\ntype WithVoidReturnFunctions<T> = {\n [K in keyof T]: K extends 'constructAfterSignOutUrl' \n ? T[K] \n : T[K] extends (...args: any) => any \n ? WithVoidReturn<T[K]> \n : T[K];\n};\n\ntype IsoTernAuth = WithVoidReturnFunctions<TernSecureAuth>;\n\nexport function inBrowser(): boolean {\n return typeof window !== 'undefined';\n}\n\ninterface PreMountState {\n signInNodes: Map<HTMLDivElement, SignInProps | undefined>;\n signUpNodes: Map<HTMLDivElement, SignUpProps | undefined>;\n userButttonNodes: Map<HTMLDivElement, SignInProps | undefined>;\n verifyNodes: Set<HTMLDivElement>;\n methodCalls: Map<MethodName<Browser>, MethodCallback>;\n errorListeners: Set<(error: AuthErrorTree) => void>;\n}\n\n/**\n * IsomorphicTernSecure class manages the auth state and UI rendering\n * in both browser and server environments, acting as a proxy for TernSecureAuth\n */\nexport class IsoTernSecureAuth implements TernSecureAuth {\n private readonly _mode: 'browser' | 'server';\n private readonly options: IsoTernSecureAuthOptions;\n private readonly TernSecureAuth: TernSecureAuthProps;\n private readonly TernSecure: TernSecureProps;\n private ternauth: TernSecureAuthProps | null = null;\n private ternui: Browser | HeadlessUIBrowser | null = null;\n private preAddListener = new Map<ListenerCallback, { unsubscribe: UnsubscribeCallback }>();\n private premountState: PreMountState = {\n signInNodes: new Map(),\n signUpNodes: new Map(),\n userButttonNodes: new Map(),\n verifyNodes: new Set(),\n methodCalls: new Map(),\n errorListeners: new Set(),\n };\n\n #status: TernSecureAuthStatus = 'loading';\n #apiUrl: string | undefined;\n #authDomain: DomainOrProxyUrl['domain'];\n #proxyUrl: DomainOrProxyUrl['proxyUrl'];\n #eventBus = createTernAuthEventBus();\n\n static #instance: IsoTernSecureAuth | null | undefined;\n\n get status(): TernSecureAuthStatus {\n if (!this.ternui) {\n return this.#status;\n }\n return this.ternui.status || (this.ternui.isReady ? 'ready' : 'loading');\n }\n\n get isReady(): boolean {\n return this.ternui?.isReady || false;\n }\n\n get isLoading(): boolean {\n return this.ternui?.isLoading || false;\n }\n\n get requiresVerification(): boolean {\n return this.options.requiresVerification ?? true;\n }\n\n get signIn(): SignInResource | undefined {\n if (this.ternui) {\n return this.ternui.signIn || undefined;\n }\n return undefined;\n }\n\n get signUp(): SignUpResource | undefined {\n if (this.ternui) {\n return this.ternui.signUp || undefined;\n }\n return undefined;\n }\n\n get user() {\n if (this.ternui) {\n return this.ternui.user;\n }\n return null;\n }\n\n static getOrCreateInstance(options: IsoTernSecureAuthOptions) {\n if (\n !inBrowser() ||\n !this.#instance ||\n (options.TernSecureAuth && this.#instance.TernSecureAuth !== options.TernSecureAuth)\n ) {\n this.#instance = new IsoTernSecureAuth(options);\n }\n return this.#instance;\n }\n\n static clearInstances() {\n if (this.#instance) {\n this.#instance.ternui = null;\n this.#instance = null;\n }\n }\n\n static clearInstance() {\n this.#instance = null;\n }\n\n get authDomain(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#authDomain, new URL(window.location.href), '');\n }\n if (typeof this.#authDomain === 'function') {\n throw new Error('Unsupported customDomain type: function');\n }\n return this.#authDomain || '';\n }\n\n get proxyUrl(): string {\n if (typeof window !== 'undefined' && window.location) {\n return handleValueOrFn(this.#proxyUrl, new URL(window.location.href), '');\n }\n if (typeof this.#proxyUrl === 'function') {\n throw new Error('Unsupported customProxyUrl type: function');\n }\n return this.#proxyUrl || '';\n }\n\n get mode(): 'browser' | 'server' {\n return this._mode;\n }\n\n /**\n * @internal\n */\n public _internal_getOption<K extends keyof TernSecureAuthOptions>(\n key: K,\n ): TernSecureAuthOptions[K] | undefined {\n return this.ternui?._internal_getOption\n ? this.ternui?._internal_getOption(key)\n : this.options[key];\n }\n\n /**\n * @internal\n */\n public _internal_getAllOptions(): Readonly<TernSecureAuthOptions> {\n return Object.freeze({ ...this.options });\n }\n\n constructor(options: IsoTernSecureAuthOptions) {\n const { TernSecureAuth = null, TernSecure = null } = options || {};\n this.#authDomain = options.ternSecureConfig?.authDomain;\n this.options = { ...options };\n this._mode = inBrowser() ? 'browser' : 'server';\n this.#apiUrl = this.options.apiUrl;\n this.#proxyUrl = this.options.proxyUrl;\n this.TernSecureAuth = TernSecureAuth;\n this.TernSecure = TernSecure;\n\n if (!this.options.sdkMetadata) {\n this.options.sdkMetadata = SDK_METADATA;\n }\n\n if (this.#apiUrl) {\n void this.loadTernUI();\n }\n }\n\n get sdkMetadata() {\n return this.ternui?.sdkMetadata || this.options.sdkMetadata;\n }\n\n get version() {\n return this.ternui?.version;\n }\n\n get instanceType() {\n return this.ternui?.instanceType;\n }\n\n get apiUrl() {\n return this.#apiUrl || '';\n }\n\n #awaitForTernUI(): Promise<HeadlessUIBrowser | Browser> {\n return new Promise<HeadlessUIBrowser | Browser>(resolve => {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n resolve(this.ternui!);\n });\n }\n\n async loadTernUI(): Promise<HeadlessUIBrowser | Browser | undefined> {\n if (this._mode !== 'browser' || this.isReady) {\n return;\n }\n\n if (typeof window !== 'undefined') {\n window._TernSecure_authDomain = this.authDomain;\n window._TernSecure_proxyUrl = this.proxyUrl;\n window._TernSecure_apiUrl = this.apiUrl;\n }\n\n try {\n if (this.TernSecure) {\n let coreInstance: TernSecureProps;\n //console.log('[IsomorphicTernSecure] this.TernSecure: defined, checking readiness...');\n //const TernSecureHasLoadMethod = typeof this.TernSecure.load === 'function';\n if (isConstructor<BrowserConstructor | HeadlessUIBrowserConstructor>(this.TernSecure)) {\n coreInstance = new this.TernSecure(this.#apiUrl, {\n proxyUrl: this.proxyUrl,\n authDomain: this.authDomain,\n } as any);\n this.beforeLoad(coreInstance);\n await coreInstance.load(this.options);\n } else {\n //console.log('[IsomorphicTernSecure] this.TernSecure: does not have load method.');\n coreInstance = this.TernSecure;\n if (!coreInstance.isReady) {\n this.beforeLoad(coreInstance);\n await coreInstance.load(this.options);\n }\n }\n global.TernSecure = coreInstance;\n } else {\n //console.log('[IsomorphicTernSecure] Loading TernSecure from script is called...');\n if (!global.TernSecure) {\n //console.log('[IsomorphicTernSecure] Loading TernSecure from script...');\n await loadTernUIScript({\n ...this.options,\n authDomain: this.authDomain,\n nonce: this.options.nonce,\n\n })\n }\n\n if (!global.TernSecure) {\n throw new Error('TernSecure instance is not available globally');\n }\n\n this.beforeLoad(global.TernSecure);\n await global.TernSecure.load(this.options);\n }\n\n if (global.TernSecure?.isReady) {\n return this.injectTernUI(global.TernSecure);\n }\n return;\n } catch (err) {\n const error = err as Error;\n //this.#eventBus.emit(TernSecureEvents.Error, error);\n console.error(error.stack || error.message || error);\n return;\n }\n }\n\n private beforeLoad = (ternui: Browser | HeadlessUIBrowser | undefined) => {\n if (!ternui) {\n throw new Error('Failed to inject TernUI');\n }\n };\n\n\n private injectTernUI = (ternui: Browser | HeadlessUIBrowser | undefined) => {\n if (!ternui) {\n throw new Error('TernUI instance is not initialized');\n }\n\n this.ternui = ternui;\n\n this.premountState.methodCalls.forEach(cb => cb());\n\n this.preAddListener.forEach((listenerHandlers, listener) => {\n listenerHandlers.unsubscribe = ternui.addListener(listener);\n });\n\n\n this.#eventBus.getListeners('status').forEach(listener => {\n this.on('status', listener, { notify: true });\n });\n\n this.premountState.signInNodes.forEach((props, node) => {\n ternui.showSignIn(node, props);\n });\n\n this.premountState.signUpNodes.forEach((props, node) => {\n ternui.showSignUp(node, props);\n });\n\n if (typeof this.ternui.status === 'undefined') {\n console.log('[IsomorphicTernSecure] TernUI has no status, setting internal status to ready');\n this.#status = 'ready';\n this.#eventBus.emit('status', 'ready');\n console.log('[IsomorphicTernSecure] Set internal status to ready (ternui has no status)');\n }\n\n return this.ternui;\n\n };\n\n /**\n * \n * @deprecated will be moved to import package\n */\n initTernSecureAuth() {\n if (this._mode !== 'browser' || this.isReady) {\n return;\n }\n\n // @ts-ignore - Deprecated method, TernSecureAuthImpl will be moved to import package\n const tern = TernSecureAuthImpl.initialize(this.options);\n this.loadTernSecureAuth(tern);\n }\n\n private loadTernSecureAuth = (ternauth: TernSecureAuthProps | undefined) => {\n if (!ternauth) {\n throw new Error('TernAuth instance is not initialized');\n }\n\n this.ternauth = ternauth;\n this.preAddListener.forEach((listenerHandlers, listener) => {\n listenerHandlers.unsubscribe = ternauth.addListener(listener);\n });\n\n this.#eventBus.getListeners('status').forEach(listener => {\n this.on('status', listener, { notify: true });\n });\n\n if (typeof this.ternauth.status === 'undefined') {\n console.log(\n '[IsoTernSecureAuth] TernSecureAuth has no status, setting internal status to ready',\n );\n this.#status = 'ready';\n this.#eventBus.emit(ternEvents.Status, 'ready');\n }\n\n return this.ternauth;\n };\n\n public on: TernSecureAuth['on'] = (...args) => {\n if (this.ternui?.on) {\n return this.ternui.on(...args);\n } else {\n return this.#eventBus.on(...args);\n }\n };\n\n public off: TernSecureAuth['off'] = (...args) => {\n if (this.ternui?.off) {\n return this.ternui.off(...args);\n } else {\n return this.#eventBus.off(...args);\n }\n };\n\n addListener = (listener: ListenerCallback): UnsubscribeCallback => {\n if (this.ternui) {\n return this.ternui.addListener(listener);\n } else {\n const unsubscribe = () => {\n const listenerHandlers = this.preAddListener.get(listener);\n if (listenerHandlers) {\n listenerHandlers.unsubscribe();\n this.preAddListener.delete(listener);\n }\n };\n this.preAddListener.set(listener, { unsubscribe });\n return unsubscribe;\n }\n };\n\n createActiveSession = (params: CreateActiveSessionParams): Promise<void> => {\n if (this.ternui) {\n return this.ternui.createActiveSession(params);\n } else {\n return Promise.reject(new Error('TernSecureAuth not initialized'));\n }\n };\n\n signOut = async (options?: SignOutOptions): Promise<void> => {\n if (!this.ternui) {\n throw new Error('TernSecureAuth not initialized');\n }\n await this.ternui.signOut();\n };\n\n get currentSession(): SignedInSession | null {\n if (!this.ternui) {\n return null;\n }\n return this.ternui.currentSession;\n }\n\n onAuthStateChanged(callback: (user: any) => void): () => void {\n if (!this.ternui) {\n console.warn(\n '[IsoTernSecureAuth] TernAuth not initialized, cannot set up auth state listener',\n );\n return () => { };\n }\n return this.ternui.onAuthStateChanged(callback);\n }\n\n getRedirectResult = async (): Promise<any> => {\n if (!this.ternui?.getRedirectResult) {\n throw new Error('TernSecure instance not initialized');\n }\n return this.ternui.getRedirectResult();\n };\n\n constructUrlWithAuthRedirect = (to: string): string => {\n if (this.ternui && this.isReady) {\n return this.ternui.constructUrlWithAuthRedirect(to);\n }\n return '';\n };\n\n constructAfterSignOutUrl = (): string => {\n if (this.ternui && this.isReady) {\n return this.ternui.constructAfterSignOutUrl() || '';\n } else {\n const callback = () => this.ternui?.constructAfterSignOutUrl() || '';\n this.premountState.methodCalls.set('constructAfterSignOutUrl', callback);\n return '';\n }\n }\n\n navigate = (to: string) => {\n if (this.ternui && this.isReady) {\n this.ternui.navigate(to);\n }\n };\n\n\n initialize = async (): Promise<void> => {\n try {\n await this.#awaitForTernUI();\n } catch (error) {\n console.error('[IsomorphicTernSecure] Failed to initialize TernUI:', error);\n throw error;\n }\n }\n\n\n showSignIn = (node: HTMLDivElement, config?: SignInProps): void => {\n if (this.ternui && this.isReady) {\n this.ternui.showSignIn(node, config);\n } else {\n this.premountState.signInNodes.set(node, config);\n }\n };\n\n hideSignIn = (node: HTMLDivElement): void => {\n if (this.ternui && this.isReady) {\n this.ternui.hideSignIn(node);\n } else {\n this.premountState.signInNodes.delete(node);\n }\n };\n\n showSignUp = (node: HTMLDivElement, config?: SignUpProps): void => {\n if (this.ternui && this.isReady) {\n this.ternui.showSignUp(node, config);\n } else {\n this.premountState.signUpNodes.set(node, config);\n }\n };\n\n hideSignUp = (node: HTMLDivElement): void => {\n if (this.ternui && this.isReady) {\n this.ternui.hideSignUp(node);\n } else {\n this.premountState.signUpNodes.delete(node);\n }\n };\n\n showUserButton = (node: HTMLDivElement): void => {\n if (this.ternui && this.isReady) {\n this.ternui.showUserButton(node);\n } else {\n this.premountState.userButttonNodes.set(node, undefined);\n }\n }\n\n hideUserButton = (node: HTMLDivElement): void => {\n if (this.ternui && this.isReady) {\n this.ternui.hideUserButton(node);\n } else {\n this.premountState.userButttonNodes.delete(node);\n }\n };\n\n redirectToSignIn = async (options?: SignInRedirectOptions) => {\n if (this.ternui?.redirectToSignIn) {\n this.ternui.redirectToSignIn(options);\n }\n };\n\n redirectToSignUp = async (options?: SignUpRedirectOptions) => {\n if (this.ternui?.redirectToSignUp) {\n this.ternui.redirectToSignUp();\n }\n };\n\n redirectAfterSignIn = (redirectUrl?: string): void => {\n if (this.ternui?.redirectAfterSignIn) {\n this.ternui.redirectAfterSignIn();\n }\n };\n\n redirectAfterSignUp = (redirectUrl?: string): void => {\n if (this.ternui?.redirectAfterSignUp) {\n this.ternui.redirectAfterSignUp();\n }\n };\n\n /**\n * \n * @deprecated will be moved to import package\n */\n #awaitForTernSecureAuth(): Promise<TernSecureAuthProps> {\n return new Promise<TernSecureAuthProps>(resolve => {\n resolve(this.ternauth);\n });\n }\n\n /**\n * @deprecated will be moved to import package\n */\n initializeAuth = async (): Promise<void> => {\n this.initTernSecureAuth();\n try {\n await this.#awaitForTernSecureAuth();\n } catch (error) {\n console.error('[IsomorphicTernSecure] Failed to initialize TernSecureAuth:', error);\n throw error;\n }\n };\n}\n"],"mappings":"AAAA,OAAS,oBAAAA,MAAwB,uCACjC,OAAS,0BAAAC,EAAwB,cAAAC,MAAkB,sCACnD,OAAS,mBAAAC,MAAuB,4BA6BhC,OAAS,iBAAAC,MAAqB,yBAE9B,MAAMC,EAAe,CACnB,KAAM,qBACN,QAAS,+BACT,YAAa,QAAQ,IAAI,QAC3B,EA6BO,SAASC,GAAqB,CACnC,OAAO,OAAO,OAAW,G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B,CAEjC,EAEA,oBAAuBuB,GAA+B,CAChD,KAAK,QAAQ,qBACf,KAAK,OAAO,oBAAoB,CAEpC,EAEA,oBAAuBA,GAA+B,CAChD,KAAK,QAAQ,qBACf,KAAK,OAAO,oBAAoB,CAEpC,EAMAC,IAAwD,CACtD,OAAO,IAAI,QAA6BnB,GAAW,CACjDA,EAAQ,KAAK,QAAQ,CACvB,CAAC,CACH,CAKA,eAAiB,SAA2B,CAC1C,KAAK,mBAAmB,EACxB,GAAI,CACF,MAAM,KAAKmB,GAAwB,CACrC,OAAShB,EAAO,CACd,cAAQ,MAAM,8DAA+DA,CAAK,EAC5EA,CACR,CACF,CACF","names":["loadTernUIScript","createTernAuthEventBus","ternEvents","handleValueOrFn","isConstructor","SDK_METADATA","inBrowser","IsoTernSecureAuth","#status","#apiUrl","#authDomain","#proxyUrl","#eventBus","#instance","options","key","TernSecureAuth","TernSecure","#awaitForTernUI","resolve","coreInstance","err","error","ternui","cb","listenerHandlers","listener","props","node","tern","ternauth","args","unsubscribe","params","callback","to","config","redirectUrl","#awaitForTernSecureAuth"]}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TernSecureAuth, TernSecureAuthOptions, DomainOrProxyUrl, TernSecureInitialState } from '@tern-secure/types';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
_TernSecure_apiKey?: string;
|
|
6
|
+
_TernSecure_apiUrl?: TernSecureAuth["apiUrl"];
|
|
7
|
+
_TernSecure_proxyUrl?: TernSecureAuth["proxyUrl"];
|
|
8
|
+
_TernSecure_authDomain?: TernSecureAuth["authDomain"];
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -59,23 +59,13 @@ type initialState = {
|
|
|
59
59
|
sessionId: string | undefined;
|
|
60
60
|
};
|
|
61
61
|
interface BrowserConstructor {
|
|
62
|
-
new (
|
|
62
|
+
new (apiUrl?: string, option?: DomainOrProxyUrl): Browser;
|
|
63
63
|
}
|
|
64
64
|
interface HeadlessUIBrowserConstructor {
|
|
65
|
-
new (
|
|
65
|
+
new (apiUrl?: string, option?: DomainOrProxyUrl): HeadlessUIBrowser;
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* @param interface
|
|
70
|
-
*/
|
|
71
|
-
type TernSecureProviderPropsOld = IsomorphicTernSecureOptions & {
|
|
72
|
-
children: React.ReactNode;
|
|
73
|
-
initialState?: TernSecureStateExtended;
|
|
74
|
-
loadingComponent?: React.ReactNode;
|
|
75
|
-
bypassApiKey?: boolean;
|
|
76
|
-
};
|
|
77
|
-
interface HeadlessUIBrowser extends TernSecureInstanceTree {
|
|
78
|
-
load: (options?: TernSecureInstanceTreeOptions) => Promise<void>;
|
|
67
|
+
interface HeadlessUIBrowser extends TernSecureAuth {
|
|
68
|
+
load: (options?: TernSecureAuthOptions) => Promise<void>;
|
|
79
69
|
setTernAuth: (provider: any) => void;
|
|
80
70
|
}
|
|
81
71
|
interface Browser extends HeadlessUIBrowser {
|
|
@@ -83,24 +73,49 @@ interface Browser extends HeadlessUIBrowser {
|
|
|
83
73
|
components: any;
|
|
84
74
|
}
|
|
85
75
|
type TernSecureProps = HeadlessUIBrowserConstructor | HeadlessUIBrowser | Browser | BrowserConstructor | null | undefined;
|
|
86
|
-
type
|
|
76
|
+
type IsoTernSecureAuthOptions = TernSecureAuthOptions & {
|
|
77
|
+
TernSecureAuth?: TernSecureAuthProps;
|
|
87
78
|
TernSecure?: TernSecureProps;
|
|
79
|
+
ternUIUrl?: string;
|
|
88
80
|
ternUIVersion?: string;
|
|
89
81
|
apiKey?: string;
|
|
90
|
-
|
|
82
|
+
apiUrl?: string;
|
|
83
|
+
authDomain?: string;
|
|
91
84
|
proxyUrl?: string;
|
|
92
|
-
|
|
93
|
-
ternSecureConfig?: TernSecureConfig;
|
|
94
|
-
};
|
|
95
|
-
type IsoTernSecureAuthOptions = TernSecureAuthOptions & {
|
|
96
|
-
TernSecureAuth?: TernSecureAuthProps;
|
|
85
|
+
nonce?: string;
|
|
97
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* TernSecureProviderProps
|
|
89
|
+
* @param interface
|
|
90
|
+
*/
|
|
98
91
|
type TernSecureProviderProps = IsoTernSecureAuthOptions & {
|
|
99
92
|
children: React.ReactNode;
|
|
100
|
-
initialState?:
|
|
93
|
+
initialState?: TernSecureInitialState;
|
|
101
94
|
loadingComponent?: React.ReactNode;
|
|
102
95
|
bypassApiKey?: boolean;
|
|
103
96
|
};
|
|
104
97
|
type TernSecureAuthProps = TernSecureAuth | undefined | null;
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated use WithTernSecureProp
|
|
100
|
+
*/
|
|
101
|
+
type WithTernSecureProp_DEPRECATED<P> = P & {
|
|
102
|
+
ternsecure: TernSecureAuth;
|
|
103
|
+
component?: string;
|
|
104
|
+
};
|
|
105
|
+
type WithTernSecureProp<T = unknown> = T & {
|
|
106
|
+
ternsecure: TernSecureAuth;
|
|
107
|
+
component?: string;
|
|
108
|
+
};
|
|
109
|
+
interface MountProps {
|
|
110
|
+
mount: (node: HTMLDivElement, props: any) => void;
|
|
111
|
+
unmount: (node: HTMLDivElement) => void;
|
|
112
|
+
updateProps: (props: any) => void;
|
|
113
|
+
props: any;
|
|
114
|
+
}
|
|
115
|
+
interface OpenProps {
|
|
116
|
+
open: (props: any) => void;
|
|
117
|
+
close: () => void;
|
|
118
|
+
props?: any;
|
|
119
|
+
}
|
|
105
120
|
|
|
106
|
-
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsoTernSecureAuthOptions, type
|
|
121
|
+
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsoTernSecureAuthOptions, type MountProps, type OpenProps, type SignInResponse, type TernSecureAuthProps, type TernSecureAuthState, type TernSecureProps, type TernSecureProviderProps, type TernSecureUserData, type WithTernSecureProp, type WithTernSecureProp_DEPRECATED, type initialState, isSignInResponse };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TernSecureAuth, TernSecureAuthOptions, DomainOrProxyUrl, TernSecureInitialState } from '@tern-secure/types';
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
_TernSecure_apiKey?: string;
|
|
6
|
+
_TernSecure_apiUrl?: TernSecureAuth["apiUrl"];
|
|
7
|
+
_TernSecure_proxyUrl?: TernSecureAuth["proxyUrl"];
|
|
8
|
+
_TernSecure_authDomain?: TernSecureAuth["authDomain"];
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
@@ -59,23 +59,13 @@ type initialState = {
|
|
|
59
59
|
sessionId: string | undefined;
|
|
60
60
|
};
|
|
61
61
|
interface BrowserConstructor {
|
|
62
|
-
new (
|
|
62
|
+
new (apiUrl?: string, option?: DomainOrProxyUrl): Browser;
|
|
63
63
|
}
|
|
64
64
|
interface HeadlessUIBrowserConstructor {
|
|
65
|
-
new (
|
|
65
|
+
new (apiUrl?: string, option?: DomainOrProxyUrl): HeadlessUIBrowser;
|
|
66
66
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
* @param interface
|
|
70
|
-
*/
|
|
71
|
-
type TernSecureProviderPropsOld = IsomorphicTernSecureOptions & {
|
|
72
|
-
children: React.ReactNode;
|
|
73
|
-
initialState?: TernSecureStateExtended;
|
|
74
|
-
loadingComponent?: React.ReactNode;
|
|
75
|
-
bypassApiKey?: boolean;
|
|
76
|
-
};
|
|
77
|
-
interface HeadlessUIBrowser extends TernSecureInstanceTree {
|
|
78
|
-
load: (options?: TernSecureInstanceTreeOptions) => Promise<void>;
|
|
67
|
+
interface HeadlessUIBrowser extends TernSecureAuth {
|
|
68
|
+
load: (options?: TernSecureAuthOptions) => Promise<void>;
|
|
79
69
|
setTernAuth: (provider: any) => void;
|
|
80
70
|
}
|
|
81
71
|
interface Browser extends HeadlessUIBrowser {
|
|
@@ -83,24 +73,49 @@ interface Browser extends HeadlessUIBrowser {
|
|
|
83
73
|
components: any;
|
|
84
74
|
}
|
|
85
75
|
type TernSecureProps = HeadlessUIBrowserConstructor | HeadlessUIBrowser | Browser | BrowserConstructor | null | undefined;
|
|
86
|
-
type
|
|
76
|
+
type IsoTernSecureAuthOptions = TernSecureAuthOptions & {
|
|
77
|
+
TernSecureAuth?: TernSecureAuthProps;
|
|
87
78
|
TernSecure?: TernSecureProps;
|
|
79
|
+
ternUIUrl?: string;
|
|
88
80
|
ternUIVersion?: string;
|
|
89
81
|
apiKey?: string;
|
|
90
|
-
|
|
82
|
+
apiUrl?: string;
|
|
83
|
+
authDomain?: string;
|
|
91
84
|
proxyUrl?: string;
|
|
92
|
-
|
|
93
|
-
ternSecureConfig?: TernSecureConfig;
|
|
94
|
-
};
|
|
95
|
-
type IsoTernSecureAuthOptions = TernSecureAuthOptions & {
|
|
96
|
-
TernSecureAuth?: TernSecureAuthProps;
|
|
85
|
+
nonce?: string;
|
|
97
86
|
};
|
|
87
|
+
/**
|
|
88
|
+
* TernSecureProviderProps
|
|
89
|
+
* @param interface
|
|
90
|
+
*/
|
|
98
91
|
type TernSecureProviderProps = IsoTernSecureAuthOptions & {
|
|
99
92
|
children: React.ReactNode;
|
|
100
|
-
initialState?:
|
|
93
|
+
initialState?: TernSecureInitialState;
|
|
101
94
|
loadingComponent?: React.ReactNode;
|
|
102
95
|
bypassApiKey?: boolean;
|
|
103
96
|
};
|
|
104
97
|
type TernSecureAuthProps = TernSecureAuth | undefined | null;
|
|
98
|
+
/**
|
|
99
|
+
* @deprecated use WithTernSecureProp
|
|
100
|
+
*/
|
|
101
|
+
type WithTernSecureProp_DEPRECATED<P> = P & {
|
|
102
|
+
ternsecure: TernSecureAuth;
|
|
103
|
+
component?: string;
|
|
104
|
+
};
|
|
105
|
+
type WithTernSecureProp<T = unknown> = T & {
|
|
106
|
+
ternsecure: TernSecureAuth;
|
|
107
|
+
component?: string;
|
|
108
|
+
};
|
|
109
|
+
interface MountProps {
|
|
110
|
+
mount: (node: HTMLDivElement, props: any) => void;
|
|
111
|
+
unmount: (node: HTMLDivElement) => void;
|
|
112
|
+
updateProps: (props: any) => void;
|
|
113
|
+
props: any;
|
|
114
|
+
}
|
|
115
|
+
interface OpenProps {
|
|
116
|
+
open: (props: any) => void;
|
|
117
|
+
close: () => void;
|
|
118
|
+
props?: any;
|
|
119
|
+
}
|
|
105
120
|
|
|
106
|
-
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsoTernSecureAuthOptions, type
|
|
121
|
+
export { type AuthError, type Browser, type BrowserConstructor, type ConfigValidationResult, type HeadlessUIBrowser, type HeadlessUIBrowserConstructor, type IsoTernSecureAuthOptions, type MountProps, type OpenProps, type SignInResponse, type TernSecureAuthProps, type TernSecureAuthState, type TernSecureProps, type TernSecureProviderProps, type TernSecureUserData, type WithTernSecureProp, type WithTernSecureProp_DEPRECATED, type initialState, isSignInResponse };
|
package/dist/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)o(e,t,{get:r[t],enumerable:!0})},c=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of a(r))!u.call(e,n)&&n!==t&&o(e,n,{get:()=>r[n],enumerable:!(s=i(r,n))||s.enumerable});return e};var l=e=>c(o({},"__esModule",{value:!0}),e);var S={};p(S,{isSignInResponse:()=>d});module.exports=l(S);function d(e){return typeof e=="object"&&"success"in e&&typeof e.success=="boolean"}0&&(module.exports={isSignInResponse});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n DomainOrProxyUrl,\n TernSecureAuth,\n TernSecureAuthOptions,\n TernSecureInitialState,\n} from \"@tern-secure/types\";\n\ndeclare global {\n interface Window {\n _TernSecure_apiKey?: string;\n _TernSecure_apiUrl?: TernSecureAuth[\"apiUrl\"];\n _TernSecure_proxyUrl?: TernSecureAuth[\"proxyUrl\"];\n _TernSecure_authDomain?: TernSecureAuth[\"authDomain\"];\n\n }\n}\n\n/**\n * TernSecure User\n */\n//export type TernSecureUser = FirebaseUser\n\nexport type TernSecureUserData = {\n uid: string;\n email: string | null;\n emailVerified?: boolean;\n displayName?: string | null;\n};\n\n/**\n * TernSecure Firebase configuration interface\n * Extends Firebase's base configuration options\n */\n{\n /*export interface TernSecureConfig {\n apiKey: string\n authDomain: string\n projectId: string\n storageBucket: string\n messagingSenderId: string\n appId: string\n measurementId?: string\n}*/\n}\n\nexport interface SignInResponse {\n success: boolean;\n message?: string;\n error?: any | undefined;\n user?: any; // Consider a more specific user type if possible, e.g., TernSecureUserData | null\n}\n\nexport interface AuthError extends Error {\n code?: any | string; // Allow string for other potential errors, or be stricter with just AuthErrorCode\n message: string;\n response?: SignInResponse;\n}\n\nexport function isSignInResponse(value: any): value is SignInResponse {\n return (\n typeof value === \"object\" &&\n \"success\" in value &&\n typeof value.success === \"boolean\"\n );\n}\n\n/**\n * Configuration validation result\n */\nexport interface ConfigValidationResult {\n isValid: boolean;\n errors: string[];\n //config: TernSecureConfig\n}\n\n/**\n * TernSecureAuthState\n */\n\nexport type TernSecureAuthState = {\n userId: string | null;\n isLoaded: boolean;\n error: Error | null;\n isValid: boolean;\n isVerified: boolean;\n isAuthenticated: boolean;\n token: any | null;\n email: string | null;\n status: \"loading\" | \"authenticated\" | \"unauthenticated\" | \"unverified\";\n requiresVerification: boolean;\n};\n\n/**\n * TernSecureInitialState\n */\n\nexport type initialState = {\n userId: string | null;\n sessionId: string | undefined;\n};\n\nexport interface BrowserConstructor {\n new(apiUrl?: string, option?: DomainOrProxyUrl): Browser;\n}\n\nexport interface HeadlessUIBrowserConstructor {\n new(apiUrl?: string, option?: DomainOrProxyUrl): HeadlessUIBrowser;\n}\n\n\nexport interface HeadlessUIBrowser extends TernSecureAuth {\n load: (options?: TernSecureAuthOptions) => Promise<void>;\n setTernAuth: (provider: any) => void;\n}\n\nexport interface Browser extends HeadlessUIBrowser {\n onComponentsReady: Promise<void>;\n components: any;\n}\n\nexport type TernSecureProps =\n | HeadlessUIBrowserConstructor\n | HeadlessUIBrowser\n | Browser\n | BrowserConstructor\n | null\n | undefined;\n\nexport type IsoTernSecureAuthOptions = TernSecureAuthOptions & {\n TernSecureAuth?: TernSecureAuthProps;\n TernSecure?: TernSecureProps;\n ternUIUrl?: string;\n ternUIVersion?: string;\n apiKey?: string;\n apiUrl?: string;\n authDomain?: string;\n proxyUrl?: string;\n nonce?: string;\n};\n\n/**\n * TernSecureProviderProps\n * @param interface\n */\nexport type TernSecureProviderProps = IsoTernSecureAuthOptions & {\n children: React.ReactNode;\n initialState?: TernSecureInitialState;\n loadingComponent?: React.ReactNode;\n bypassApiKey?: boolean;\n};\n\nexport type TernSecureAuthProps = TernSecureAuth | undefined | null;\n\n/**\n * @deprecated use WithTernSecureProp\n */\nexport type WithTernSecureProp_DEPRECATED<P> = P & {\n ternsecure: TernSecureAuth;\n component?: string;\n};\n\nexport type WithTernSecureProp<T = unknown> = T & {\n ternsecure: TernSecureAuth;\n component?: string;\n};\n\n\nexport interface MountProps {\n mount: (node: HTMLDivElement, props: any) => void;\n unmount: (node: HTMLDivElement) => void;\n updateProps: (props: any) => void;\n props: any;\n}\n\nexport interface OpenProps {\n open: (props: any) => void;\n close: () => void;\n props?: any;\n}"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GA0DO,SAASE,EAAiBE,EAAqC,CACpE,OACE,OAAOA,GAAU,UACjB,YAAaA,GACb,OAAOA,EAAM,SAAY,SAE7B","names":["types_exports","__export","isSignInResponse","__toCommonJS","value"]}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type {\n DomainOrProxyUrl,\n TernSecureAuth,\n TernSecureAuthOptions,\n TernSecureInitialState,\n} from \"@tern-secure/types\";\n\ndeclare global {\n interface Window {\n _TernSecure_apiKey?: string;\n _TernSecure_apiUrl?: TernSecureAuth[\"apiUrl\"];\n _TernSecure_proxyUrl?: TernSecureAuth[\"proxyUrl\"];\n _TernSecure_authDomain?: TernSecureAuth[\"authDomain\"];\n\n }\n}\n\n/**\n * TernSecure User\n */\n//export type TernSecureUser = FirebaseUser\n\nexport type TernSecureUserData = {\n uid: string;\n email: string | null;\n emailVerified?: boolean;\n displayName?: string | null;\n};\n\n/**\n * TernSecure Firebase configuration interface\n * Extends Firebase's base configuration options\n */\n{\n /*export interface TernSecureConfig {\n apiKey: string\n authDomain: string\n projectId: string\n storageBucket: string\n messagingSenderId: string\n appId: string\n measurementId?: string\n}*/\n}\n\nexport interface SignInResponse {\n success: boolean;\n message?: string;\n error?: any | undefined;\n user?: any; // Consider a more specific user type if possible, e.g., TernSecureUserData | null\n}\n\nexport interface AuthError extends Error {\n code?: any | string; // Allow string for other potential errors, or be stricter with just AuthErrorCode\n message: string;\n response?: SignInResponse;\n}\n\nexport function isSignInResponse(value: any): value is SignInResponse {\n return (\n typeof value === \"object\" &&\n \"success\" in value &&\n typeof value.success === \"boolean\"\n );\n}\n\n/**\n * Configuration validation result\n */\nexport interface ConfigValidationResult {\n isValid: boolean;\n errors: string[];\n //config: TernSecureConfig\n}\n\n/**\n * TernSecureAuthState\n */\n\nexport type TernSecureAuthState = {\n userId: string | null;\n isLoaded: boolean;\n error: Error | null;\n isValid: boolean;\n isVerified: boolean;\n isAuthenticated: boolean;\n token: any | null;\n email: string | null;\n status: \"loading\" | \"authenticated\" | \"unauthenticated\" | \"unverified\";\n requiresVerification: boolean;\n};\n\n/**\n * TernSecureInitialState\n */\n\nexport type initialState = {\n userId: string | null;\n sessionId: string | undefined;\n};\n\nexport interface BrowserConstructor {\n new(apiUrl?: string, option?: DomainOrProxyUrl): Browser;\n}\n\nexport interface HeadlessUIBrowserConstructor {\n new(apiUrl?: string, option?: DomainOrProxyUrl): HeadlessUIBrowser;\n}\n\n\nexport interface HeadlessUIBrowser extends TernSecureAuth {\n load: (options?: TernSecureAuthOptions) => Promise<void>;\n setTernAuth: (provider: any) => void;\n}\n\nexport interface Browser extends HeadlessUIBrowser {\n onComponentsReady: Promise<void>;\n components: any;\n}\n\nexport type TernSecureProps =\n | HeadlessUIBrowserConstructor\n | HeadlessUIBrowser\n | Browser\n | BrowserConstructor\n | null\n | undefined;\n\nexport type IsoTernSecureAuthOptions = TernSecureAuthOptions & {\n TernSecureAuth?: TernSecureAuthProps;\n TernSecure?: TernSecureProps;\n ternUIUrl?: string;\n ternUIVersion?: string;\n apiKey?: string;\n apiUrl?: string;\n authDomain?: string;\n proxyUrl?: string;\n nonce?: string;\n};\n\n/**\n * TernSecureProviderProps\n * @param interface\n */\nexport type TernSecureProviderProps = IsoTernSecureAuthOptions & {\n children: React.ReactNode;\n initialState?: TernSecureInitialState;\n loadingComponent?: React.ReactNode;\n bypassApiKey?: boolean;\n};\n\nexport type TernSecureAuthProps = TernSecureAuth | undefined | null;\n\n/**\n * @deprecated use WithTernSecureProp\n */\nexport type WithTernSecureProp_DEPRECATED<P> = P & {\n ternsecure: TernSecureAuth;\n component?: string;\n};\n\nexport type WithTernSecureProp<T = unknown> = T & {\n ternsecure: TernSecureAuth;\n component?: string;\n};\n\n\nexport interface MountProps {\n mount: (node: HTMLDivElement, props: any) => void;\n unmount: (node: HTMLDivElement) => void;\n updateProps: (props: any) => void;\n props: any;\n}\n\nexport interface OpenProps {\n open: (props: any) => void;\n close: () => void;\n props?: any;\n}"],"mappings":"AA0DO,SAASA,EAAiBC,EAAqC,CACpE,OACE,OAAOA,GAAU,UACjB,YAAaA,GACb,OAAOA,EAAM,SAAY,SAE7B","names":["isSignInResponse","value"]}
|
package/dist/utils/debug.d.mts
CHANGED
|
@@ -10,5 +10,6 @@ declare const logAuthState: (component: string, user: TernSecureUser | null, isV
|
|
|
10
10
|
declare const logSessionState: (component: string, token: string | null, expirationTime: number | null) => void;
|
|
11
11
|
declare const logLifecycle: (component: string, lifecycle: string, props?: any) => void;
|
|
12
12
|
declare const logError: (component: string, error: Error | unknown) => void;
|
|
13
|
+
declare const debugConsoleLog: (component: string, action: string, data?: any) => void;
|
|
13
14
|
|
|
14
|
-
export { debugLog, logAuthState, logError, logLifecycle, logSessionState };
|
|
15
|
+
export { debugConsoleLog, debugLog, logAuthState, logError, logLifecycle, logSessionState };
|
package/dist/utils/debug.d.ts
CHANGED
|
@@ -10,5 +10,6 @@ declare const logAuthState: (component: string, user: TernSecureUser | null, isV
|
|
|
10
10
|
declare const logSessionState: (component: string, token: string | null, expirationTime: number | null) => void;
|
|
11
11
|
declare const logLifecycle: (component: string, lifecycle: string, props?: any) => void;
|
|
12
12
|
declare const logError: (component: string, error: Error | unknown) => void;
|
|
13
|
+
declare const debugConsoleLog: (component: string, action: string, data?: any) => void;
|
|
13
14
|
|
|
14
|
-
export { debugLog, logAuthState, logError, logLifecycle, logSessionState };
|
|
15
|
+
export { debugConsoleLog, debugLog, logAuthState, logError, logLifecycle, logSessionState };
|
package/dist/utils/debug.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var g=(t,n)=>{for(var e in n)r(t,e,{get:n[e],enumerable:!0})},u=(t,n,e,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of c(n))!l.call(t,o)&&o!==e&&r(t,o,{get:()=>n[o],enumerable:!(s=i(n,o))||s.enumerable});return t};var d=t=>u(r({},"__esModule",{value:!0}),t);var $={};g($,{debugConsoleLog:()=>y,debugLog:()=>a,logAuthState:()=>S,logError:()=>E,logLifecycle:()=>f,logSessionState:()=>m});module.exports=d($);const p=process.env.NODE_ENV!=="production",a=t=>{if(!p)return;const n=new Date().toISOString(),e=`[TernSecure][${t.component}][${t.action}]`;console.log(`${e} - ${n}`,t.data||"")},S=(t,n,e,s)=>{a({component:t,action:"AuthState",data:{user:n?{uid:n.uid,email:n.email,emailVerified:n.emailVerified}:null,isValid:e,isVerified:s}})},m=(t,n,e)=>{a({component:t,action:"SessionState",data:{hasToken:!!n,expirationTime:e?new Date(e).toISOString():null,isExpired:e?Date.now()>e:null}})},f=(t,n,e)=>{a({component:t,action:`Lifecycle.${n}`,data:e})},E=(t,n)=>{a({component:t,action:"Error",data:n instanceof Error?{name:n.name,message:n.message,stack:n.stack}:n})},y=(t,n,e)=>{console.log(`[TernSecure:${t}] ${n}`,e||"")};0&&(module.exports={debugConsoleLog,debugLog,logAuthState,logError,logLifecycle,logSessionState});
|
|
2
2
|
//# sourceMappingURL=debug.js.map
|
package/dist/utils/debug.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/debug.ts"],"sourcesContent":["import type { TernSecureUser } from '@tern-secure/types'\n\nconst DEBUG = process.env.NODE_ENV !== 'production'\n\n//type LogLevel = 'info' | 'warn' | 'error' | 'debug'\n\ninterface LogContext {\n component: string\n action: string\n data?: any\n}\n\nexport const debugLog = (context: LogContext) => {\n if (!DEBUG) return\n\n const timestamp = new Date().toISOString()\n const prefix = `[TernSecure][${context.component}][${context.action}]`\n\n console.log(`${prefix} - ${timestamp}`, context.data || '')\n}\n\nexport const logAuthState = (component: string, user: TernSecureUser | null, isValid: boolean, isVerified: boolean) => {\n debugLog({\n component,\n action: 'AuthState',\n data: {\n user: user ? {\n uid: user.uid,\n email: user.email,\n emailVerified: user.emailVerified,\n } : null,\n isValid,\n isVerified,\n },\n })\n}\n\nexport const logSessionState = (component: string, token: string | null, expirationTime: number | null) => {\n debugLog({\n component,\n action: 'SessionState',\n data: {\n hasToken: !!token,\n expirationTime: expirationTime ? new Date(expirationTime).toISOString() : null,\n isExpired: expirationTime ? Date.now() > expirationTime : null,\n },\n })\n}\n\nexport const logLifecycle = (component: string, lifecycle: string, props?: any) => {\n debugLog({\n component,\n action: `Lifecycle.${lifecycle}`,\n data: props,\n })\n}\n\nexport const logError = (component: string, error: Error | unknown) => {\n debugLog({\n component,\n action: 'Error',\n data: error instanceof Error ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n } : error,\n })\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/utils/debug.ts"],"sourcesContent":["import type { TernSecureUser } from '@tern-secure/types'\n\nconst DEBUG = process.env.NODE_ENV !== 'production'\n\n//type LogLevel = 'info' | 'warn' | 'error' | 'debug'\n\ninterface LogContext {\n component: string\n action: string\n data?: any\n}\n\nexport const debugLog = (context: LogContext) => {\n if (!DEBUG) return\n\n const timestamp = new Date().toISOString()\n const prefix = `[TernSecure][${context.component}][${context.action}]`\n\n console.log(`${prefix} - ${timestamp}`, context.data || '')\n}\n\nexport const logAuthState = (component: string, user: TernSecureUser | null, isValid: boolean, isVerified: boolean) => {\n debugLog({\n component,\n action: 'AuthState',\n data: {\n user: user ? {\n uid: user.uid,\n email: user.email,\n emailVerified: user.emailVerified,\n } : null,\n isValid,\n isVerified,\n },\n })\n}\n\nexport const logSessionState = (component: string, token: string | null, expirationTime: number | null) => {\n debugLog({\n component,\n action: 'SessionState',\n data: {\n hasToken: !!token,\n expirationTime: expirationTime ? new Date(expirationTime).toISOString() : null,\n isExpired: expirationTime ? Date.now() > expirationTime : null,\n },\n })\n}\n\nexport const logLifecycle = (component: string, lifecycle: string, props?: any) => {\n debugLog({\n component,\n action: `Lifecycle.${lifecycle}`,\n data: props,\n })\n}\n\nexport const logError = (component: string, error: Error | unknown) => {\n debugLog({\n component,\n action: 'Error',\n data: error instanceof Error ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n } : error,\n })\n}\n\nexport const debugConsoleLog = (component: string, action: string, data?: any) => {\n console.log(`[TernSecure:${component}] ${action}`, data || '');\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,aAAAC,EAAA,iBAAAC,EAAA,aAAAC,EAAA,iBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAR,GAEA,MAAMS,EAAQ,QAAQ,IAAI,WAAa,aAU1BN,EAAYO,GAAwB,CAC/C,GAAI,CAACD,EAAO,OAEZ,MAAME,EAAY,IAAI,KAAK,EAAE,YAAY,EACnCC,EAAS,gBAAgBF,EAAQ,SAAS,KAAKA,EAAQ,MAAM,IAEnE,QAAQ,IAAI,GAAGE,CAAM,MAAMD,CAAS,GAAID,EAAQ,MAAQ,EAAE,CAC5D,EAEaN,EAAe,CAACS,EAAmBC,EAA6BC,EAAkBC,IAAwB,CACrHb,EAAS,CACP,UAAAU,EACA,OAAQ,YACR,KAAM,CACJ,KAAMC,EAAO,CACX,IAAKA,EAAK,IACV,MAAOA,EAAK,MACZ,cAAeA,EAAK,aACtB,EAAI,KACJ,QAAAC,EACA,WAAAC,CACF,CACF,CAAC,CACH,EAEaT,EAAkB,CAACM,EAAmBI,EAAsBC,IAAkC,CACzGf,EAAS,CACP,UAAAU,EACA,OAAQ,eACR,KAAM,CACJ,SAAU,CAAC,CAACI,EACZ,eAAgBC,EAAiB,IAAI,KAAKA,CAAc,EAAE,YAAY,EAAI,KAC1E,UAAWA,EAAiB,KAAK,IAAI,EAAIA,EAAiB,IAC5D,CACF,CAAC,CACH,EAEaZ,EAAe,CAACO,EAAmBM,EAAmBC,IAAgB,CACjFjB,EAAS,CACP,UAAAU,EACA,OAAQ,aAAaM,CAAS,GAC9B,KAAMC,CACR,CAAC,CACH,EAEaf,EAAW,CAACQ,EAAmBQ,IAA2B,CACrElB,EAAS,CACP,UAAAU,EACA,OAAQ,QACR,KAAMQ,aAAiB,MAAQ,CAC7B,KAAMA,EAAM,KACZ,QAASA,EAAM,QACf,MAAOA,EAAM,KACf,EAAIA,CACN,CAAC,CACH,EAEanB,EAAkB,CAACW,EAAmBS,EAAgBC,IAAe,CAChF,QAAQ,IAAI,eAAeV,CAAS,KAAKS,CAAM,GAAIC,GAAQ,EAAE,CAC/D","names":["debug_exports","__export","debugConsoleLog","debugLog","logAuthState","logError","logLifecycle","logSessionState","__toCommonJS","DEBUG","context","timestamp","prefix","component","user","isValid","isVerified","token","expirationTime","lifecycle","props","error","action","data"]}
|
package/dist/utils/debug.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const s=process.env.NODE_ENV!=="production",o=
|
|
1
|
+
const s=process.env.NODE_ENV!=="production",o=t=>{if(!s)return;const n=new Date().toISOString(),e=`[TernSecure][${t.component}][${t.action}]`;console.log(`${e} - ${n}`,t.data||"")},r=(t,n,e,a)=>{o({component:t,action:"AuthState",data:{user:n?{uid:n.uid,email:n.email,emailVerified:n.emailVerified}:null,isValid:e,isVerified:a}})},i=(t,n,e)=>{o({component:t,action:"SessionState",data:{hasToken:!!n,expirationTime:e?new Date(e).toISOString():null,isExpired:e?Date.now()>e:null}})},c=(t,n,e)=>{o({component:t,action:`Lifecycle.${n}`,data:e})},l=(t,n)=>{o({component:t,action:"Error",data:n instanceof Error?{name:n.name,message:n.message,stack:n.stack}:n})},g=(t,n,e)=>{console.log(`[TernSecure:${t}] ${n}`,e||"")};export{g as debugConsoleLog,o as debugLog,r as logAuthState,l as logError,c as logLifecycle,i as logSessionState};
|
|
2
2
|
//# sourceMappingURL=debug.mjs.map
|
package/dist/utils/debug.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/debug.ts"],"sourcesContent":["import type { TernSecureUser } from '@tern-secure/types'\n\nconst DEBUG = process.env.NODE_ENV !== 'production'\n\n//type LogLevel = 'info' | 'warn' | 'error' | 'debug'\n\ninterface LogContext {\n component: string\n action: string\n data?: any\n}\n\nexport const debugLog = (context: LogContext) => {\n if (!DEBUG) return\n\n const timestamp = new Date().toISOString()\n const prefix = `[TernSecure][${context.component}][${context.action}]`\n\n console.log(`${prefix} - ${timestamp}`, context.data || '')\n}\n\nexport const logAuthState = (component: string, user: TernSecureUser | null, isValid: boolean, isVerified: boolean) => {\n debugLog({\n component,\n action: 'AuthState',\n data: {\n user: user ? {\n uid: user.uid,\n email: user.email,\n emailVerified: user.emailVerified,\n } : null,\n isValid,\n isVerified,\n },\n })\n}\n\nexport const logSessionState = (component: string, token: string | null, expirationTime: number | null) => {\n debugLog({\n component,\n action: 'SessionState',\n data: {\n hasToken: !!token,\n expirationTime: expirationTime ? new Date(expirationTime).toISOString() : null,\n isExpired: expirationTime ? Date.now() > expirationTime : null,\n },\n })\n}\n\nexport const logLifecycle = (component: string, lifecycle: string, props?: any) => {\n debugLog({\n component,\n action: `Lifecycle.${lifecycle}`,\n data: props,\n })\n}\n\nexport const logError = (component: string, error: Error | unknown) => {\n debugLog({\n component,\n action: 'Error',\n data: error instanceof Error ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n } : error,\n })\n}\n"],"mappings":"AAEA,MAAMA,EAAQ,QAAQ,IAAI,WAAa,aAU1BC,EAAYC,GAAwB,CAC/C,GAAI,CAACF,EAAO,OAEZ,MAAMG,EAAY,IAAI,KAAK,EAAE,YAAY,EACnCC,EAAS,gBAAgBF,EAAQ,SAAS,KAAKA,EAAQ,MAAM,IAEnE,QAAQ,IAAI,GAAGE,CAAM,MAAMD,CAAS,GAAID,EAAQ,MAAQ,EAAE,CAC5D,EAEaG,EAAe,CAACC,EAAmBC,EAA6BC,EAAkBC,IAAwB,CACrHR,EAAS,CACP,UAAAK,EACA,OAAQ,YACR,KAAM,CACJ,KAAMC,EAAO,CACX,IAAKA,EAAK,IACV,MAAOA,EAAK,MACZ,cAAeA,EAAK,aACtB,EAAI,KACJ,QAAAC,EACA,WAAAC,CACF,CACF,CAAC,CACH,EAEaC,EAAkB,CAACJ,EAAmBK,EAAsBC,IAAkC,CACzGX,EAAS,CACP,UAAAK,EACA,OAAQ,eACR,KAAM,CACJ,SAAU,CAAC,CAACK,EACZ,eAAgBC,EAAiB,IAAI,KAAKA,CAAc,EAAE,YAAY,EAAI,KAC1E,UAAWA,EAAiB,KAAK,IAAI,EAAIA,EAAiB,IAC5D,CACF,CAAC,CACH,EAEaC,EAAe,CAACP,EAAmBQ,EAAmBC,IAAgB,CACjFd,EAAS,CACP,UAAAK,EACA,OAAQ,aAAaQ,CAAS,GAC9B,KAAMC,CACR,CAAC,CACH,EAEaC,EAAW,CAACV,EAAmBW,IAA2B,CACrEhB,EAAS,CACP,UAAAK,EACA,OAAQ,QACR,KAAMW,aAAiB,MAAQ,CAC7B,KAAMA,EAAM,KACZ,QAASA,EAAM,QACf,MAAOA,EAAM,KACf,EAAIA,CACN,CAAC,CACH","names":["DEBUG","debugLog","context","timestamp","prefix","logAuthState","component","user","isValid","isVerified","logSessionState","token","expirationTime","logLifecycle","lifecycle","props","logError","error"]}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/debug.ts"],"sourcesContent":["import type { TernSecureUser } from '@tern-secure/types'\n\nconst DEBUG = process.env.NODE_ENV !== 'production'\n\n//type LogLevel = 'info' | 'warn' | 'error' | 'debug'\n\ninterface LogContext {\n component: string\n action: string\n data?: any\n}\n\nexport const debugLog = (context: LogContext) => {\n if (!DEBUG) return\n\n const timestamp = new Date().toISOString()\n const prefix = `[TernSecure][${context.component}][${context.action}]`\n\n console.log(`${prefix} - ${timestamp}`, context.data || '')\n}\n\nexport const logAuthState = (component: string, user: TernSecureUser | null, isValid: boolean, isVerified: boolean) => {\n debugLog({\n component,\n action: 'AuthState',\n data: {\n user: user ? {\n uid: user.uid,\n email: user.email,\n emailVerified: user.emailVerified,\n } : null,\n isValid,\n isVerified,\n },\n })\n}\n\nexport const logSessionState = (component: string, token: string | null, expirationTime: number | null) => {\n debugLog({\n component,\n action: 'SessionState',\n data: {\n hasToken: !!token,\n expirationTime: expirationTime ? new Date(expirationTime).toISOString() : null,\n isExpired: expirationTime ? Date.now() > expirationTime : null,\n },\n })\n}\n\nexport const logLifecycle = (component: string, lifecycle: string, props?: any) => {\n debugLog({\n component,\n action: `Lifecycle.${lifecycle}`,\n data: props,\n })\n}\n\nexport const logError = (component: string, error: Error | unknown) => {\n debugLog({\n component,\n action: 'Error',\n data: error instanceof Error ? {\n name: error.name,\n message: error.message,\n stack: error.stack,\n } : error,\n })\n}\n\nexport const debugConsoleLog = (component: string, action: string, data?: any) => {\n console.log(`[TernSecure:${component}] ${action}`, data || '');\n};\n"],"mappings":"AAEA,MAAMA,EAAQ,QAAQ,IAAI,WAAa,aAU1BC,EAAYC,GAAwB,CAC/C,GAAI,CAACF,EAAO,OAEZ,MAAMG,EAAY,IAAI,KAAK,EAAE,YAAY,EACnCC,EAAS,gBAAgBF,EAAQ,SAAS,KAAKA,EAAQ,MAAM,IAEnE,QAAQ,IAAI,GAAGE,CAAM,MAAMD,CAAS,GAAID,EAAQ,MAAQ,EAAE,CAC5D,EAEaG,EAAe,CAACC,EAAmBC,EAA6BC,EAAkBC,IAAwB,CACrHR,EAAS,CACP,UAAAK,EACA,OAAQ,YACR,KAAM,CACJ,KAAMC,EAAO,CACX,IAAKA,EAAK,IACV,MAAOA,EAAK,MACZ,cAAeA,EAAK,aACtB,EAAI,KACJ,QAAAC,EACA,WAAAC,CACF,CACF,CAAC,CACH,EAEaC,EAAkB,CAACJ,EAAmBK,EAAsBC,IAAkC,CACzGX,EAAS,CACP,UAAAK,EACA,OAAQ,eACR,KAAM,CACJ,SAAU,CAAC,CAACK,EACZ,eAAgBC,EAAiB,IAAI,KAAKA,CAAc,EAAE,YAAY,EAAI,KAC1E,UAAWA,EAAiB,KAAK,IAAI,EAAIA,EAAiB,IAC5D,CACF,CAAC,CACH,EAEaC,EAAe,CAACP,EAAmBQ,EAAmBC,IAAgB,CACjFd,EAAS,CACP,UAAAK,EACA,OAAQ,aAAaQ,CAAS,GAC9B,KAAMC,CACR,CAAC,CACH,EAEaC,EAAW,CAACV,EAAmBW,IAA2B,CACrEhB,EAAS,CACP,UAAAK,EACA,OAAQ,QACR,KAAMW,aAAiB,MAAQ,CAC7B,KAAMA,EAAM,KACZ,QAASA,EAAM,QACf,MAAOA,EAAM,KACf,EAAIA,CACN,CAAC,CACH,EAEaC,EAAkB,CAACZ,EAAmBa,EAAgBC,IAAe,CAChF,QAAQ,IAAI,eAAed,CAAS,KAAKa,CAAM,GAAIC,GAAQ,EAAE,CAC/D","names":["DEBUG","debugLog","context","timestamp","prefix","logAuthState","component","user","isValid","isVerified","logSessionState","token","expirationTime","logLifecycle","lifecycle","props","logError","error","debugConsoleLog","action","data"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var f=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var e=Object.prototype.hasOwnProperty;var s=(n,t)=>{for(var r in t)f(n,r,{get:t[r],enumerable:!0})},p=(n,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of c(t))!e.call(n,o)&&o!==r&&f(n,o,{get:()=>t[o],enumerable:!(i=u(t,o))||i.enumerable});return n};var y=n=>p(f({},"__esModule",{value:!0}),n);var a={};s(a,{isConstructor:()=>T});module.exports=y(a);function T(n){return typeof n=="function"}0&&(module.exports={isConstructor});
|
|
2
|
+
//# sourceMappingURL=isConstructor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/isConstructor.ts"],"sourcesContent":["export function isConstructor<T>(f: any): f is T {\n return typeof f === 'function';\n}"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,IAAA,eAAAC,EAAAH,GAAO,SAASE,EAAiBE,EAAgB,CAC/C,OAAO,OAAOA,GAAM,UACtB","names":["isConstructor_exports","__export","isConstructor","__toCommonJS","f"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/isConstructor.ts"],"sourcesContent":["export function isConstructor<T>(f: any): f is T {\n return typeof f === 'function';\n}"],"mappings":"AAAO,SAASA,EAAiBC,EAAgB,CAC/C,OAAO,OAAOA,GAAM,UACtB","names":["isConstructor","f"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tern-secure/react",
|
|
3
|
-
"version": "1.2.0-canary.
|
|
3
|
+
"version": "1.2.0-canary.v20251125170702",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TernSecure/auth.git",
|
|
@@ -35,10 +35,9 @@
|
|
|
35
35
|
"lucide-react": "^0.468.0",
|
|
36
36
|
"tailwind-merge": "^2.5.5",
|
|
37
37
|
"tailwindcss-animate": "^1.0.7",
|
|
38
|
-
"tslib": "2.
|
|
39
|
-
"@tern-secure/
|
|
40
|
-
"@tern-secure/
|
|
41
|
-
"@tern-secure/types": "1.1.0-canary.v20251030165007"
|
|
38
|
+
"tslib": "2.8.1",
|
|
39
|
+
"@tern-secure/shared": "1.3.0-canary.v20251125170702",
|
|
40
|
+
"@tern-secure/types": "1.1.0-canary.v20251125170702"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@tailwindcss/cli": "^4.1.6",
|
package/dist/ctx/SignInCtx.d.mts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
import { SignInProps, SignInForceRedirectUrl, SignInFallbackRedirectUrl, TernSecureUser, AuthErrorTree } from '@tern-secure/auth';
|
|
5
|
-
export { useTernSecure } from '@tern-secure/shared/react';
|
|
6
|
-
|
|
7
|
-
type SignInCtx = SignInProps & SignInForceRedirectUrl & SignInFallbackRedirectUrl;
|
|
8
|
-
type SignInContextType = Omit<SignInCtx, 'fallbackRedirectUrl' | 'forceRedirectUrl'> & {
|
|
9
|
-
onSignInSuccess: (user: TernSecureUser, options?: {
|
|
10
|
-
onPreRedirect?: () => Promise<boolean>;
|
|
11
|
-
}) => void;
|
|
12
|
-
handleSignInError: (error: AuthErrorTree) => void;
|
|
13
|
-
redirectAfterSignIn: () => any;
|
|
14
|
-
signInUrl: string;
|
|
15
|
-
signUpUrl: string;
|
|
16
|
-
afterSignUpUrl: string;
|
|
17
|
-
afterSignInUrl: string;
|
|
18
|
-
checkRedirectResult: () => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
declare const SignInContext: react.Context<SignInCtx | null>;
|
|
21
|
-
declare const useSignInContext: () => SignInContextType;
|
|
22
|
-
interface SignInProviderProps extends Partial<SignInCtx> {
|
|
23
|
-
children: ReactNode;
|
|
24
|
-
}
|
|
25
|
-
declare function SignInProvider({ children, ...ctxProps }: SignInProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
-
|
|
27
|
-
export { SignInContext, type SignInContextType, type SignInCtx, SignInProvider, useSignInContext };
|
package/dist/ctx/SignInCtx.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as react from 'react';
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
import { SignInProps, SignInForceRedirectUrl, SignInFallbackRedirectUrl, TernSecureUser, AuthErrorTree } from '@tern-secure/auth';
|
|
5
|
-
export { useTernSecure } from '@tern-secure/shared/react';
|
|
6
|
-
|
|
7
|
-
type SignInCtx = SignInProps & SignInForceRedirectUrl & SignInFallbackRedirectUrl;
|
|
8
|
-
type SignInContextType = Omit<SignInCtx, 'fallbackRedirectUrl' | 'forceRedirectUrl'> & {
|
|
9
|
-
onSignInSuccess: (user: TernSecureUser, options?: {
|
|
10
|
-
onPreRedirect?: () => Promise<boolean>;
|
|
11
|
-
}) => void;
|
|
12
|
-
handleSignInError: (error: AuthErrorTree) => void;
|
|
13
|
-
redirectAfterSignIn: () => any;
|
|
14
|
-
signInUrl: string;
|
|
15
|
-
signUpUrl: string;
|
|
16
|
-
afterSignUpUrl: string;
|
|
17
|
-
afterSignInUrl: string;
|
|
18
|
-
checkRedirectResult: () => Promise<void>;
|
|
19
|
-
};
|
|
20
|
-
declare const SignInContext: react.Context<SignInCtx | null>;
|
|
21
|
-
declare const useSignInContext: () => SignInContextType;
|
|
22
|
-
interface SignInProviderProps extends Partial<SignInCtx> {
|
|
23
|
-
children: ReactNode;
|
|
24
|
-
}
|
|
25
|
-
declare function SignInProvider({ children, ...ctxProps }: SignInProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
-
|
|
27
|
-
export { SignInContext, type SignInContextType, type SignInCtx, SignInProvider, useSignInContext };
|
package/dist/ctx/SignInCtx.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";"use client";var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var k=(t,r)=>{for(var o in r)p(t,o,{get:r[o],enumerable:!0})},_=(t,r,o,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of T(r))!F.call(t,n)&&n!==o&&p(t,n,{get:()=>r[n],enumerable:!(l=b(r,n))||l.enumerable});return t};var D=t=>_(p({},"__esModule",{value:!0}),t);var N={};k(N,{SignInContext:()=>E,SignInProvider:()=>O,useSignInContext:()=>L,useTernSecure:()=>R.useTernSecure});module.exports=D(N);var m=require("react/jsx-runtime"),u=require("@tern-secure/auth"),R=require("@tern-secure/shared/react"),i=require("react");const E=(0,i.createContext)(null),L=()=>{const t=(0,i.useContext)(E),r=(0,R.useTernSecure)(),o=r._internal_getAllOptions(),l=(0,i.useMemo)(()=>typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,[]);if(t===null)throw new Error("useSignInContext must be used within a SignInProvider. Please wrap your component tree with SignInProvider.");const{...n}=t,d=(0,i.useCallback)((e,s,c="AuthError",g)=>{const I=new Error(e);return I.name=c,I.code=s,I.response=g,I},[]),a=(0,i.useCallback)(e=>{console.error(e)},[]),U=new u.RedirectUrls(o,{...n,signInForceRedirectUrl:n.signInForceRedirectUrl||n.forceRedirectUrl,signInFallbackRedirectUrl:n.signInFallbackRedirectUrl||n.fallbackRedirectUrl},l),f=r.constructUrlWithAuthRedirect(U.getAfterSignInUrl()),x=r.constructUrlWithAuthRedirect(U.getAfterSignUpUrl()),S=()=>r.navigate(f),P=U.getPreservedSearchParams(),C=n.path||o.signInUrl,A=o.signUpUrl,v=(0,u.buildURL)({base:C,hashSearchParams:[l,P]},{stringify:!0}),w=(0,u.buildURL)({base:A,hashSearchParams:[l,P]},{stringify:!0}),h=(0,i.useCallback)(async(e,s)=>{try{if(await r.createActiveSession({session:e}),s?.onPreRedirect)try{await s.onPreRedirect()&&S()}catch(c){const g=d("Pre-redirect validation failed","PRE_REDIRECT_FAILED","PreRedirectError",c);a(g)}else S()}catch(c){const g=d(c instanceof Error?c.message:"Failed to create session","SESSION_CREATION_FAILED","SessionError",c);a(g)}},[r,d,a,S]),y=(0,i.useCallback)(async()=>{try{const e=await r.getRedirectResult();if(e&&e.success)await h(e.user);else if(e&&!e.success){const s=d(e.message||"Redirect sign-in failed",e.error||"REDIRECT_FAILED","RedirectError",e);a(s)}}catch(e){const s=d(e instanceof Error?e.message:"Failed to check redirect result","REDIRECT_CHECK_FAILED","RedirectError",e);a(s)}},[r,h,a,d]);return{...n,afterSignInUrl:f,afterSignUpUrl:x,signInUrl:v,signUpUrl:w,checkRedirectResult:y,onSignInSuccess:h,handleSignInError:a,redirectAfterSignIn:S}};function O({children:t,...r}){const o=r;return(0,m.jsx)(E.Provider,{value:o,children:t})}0&&(module.exports={SignInContext,SignInProvider,useSignInContext,useTernSecure});
|
|
2
|
-
//# sourceMappingURL=SignInCtx.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ctx/SignInCtx.tsx"],"sourcesContent":["'use client';\n\nimport type {\n AuthErrorTree,\n SignInFallbackRedirectUrl,\n SignInForceRedirectUrl,\n SignInProps,\n TernSecureUser,\n} from '@tern-secure/auth';\nimport { buildURL, RedirectUrls } from '@tern-secure/auth';\nimport { useTernSecure } from '@tern-secure/shared/react';\nimport type { ReactNode } from 'react';\nimport { createContext, useCallback, useContext, useMemo } from 'react';\n\nexport type SignInCtx = SignInProps & SignInForceRedirectUrl & SignInFallbackRedirectUrl;\n\nexport type SignInContextType = Omit<SignInCtx, 'fallbackRedirectUrl' | 'forceRedirectUrl'> & {\n onSignInSuccess: (\n user: TernSecureUser,\n options?: { onPreRedirect?: () => Promise<boolean> },\n ) => void;\n handleSignInError: (error: AuthErrorTree) => void;\n redirectAfterSignIn: () => any;\n signInUrl: string;\n signUpUrl: string;\n afterSignUpUrl: string;\n afterSignInUrl: string;\n checkRedirectResult: () => Promise<void>;\n};\n\nexport const SignInContext = createContext<SignInCtx | null>(null);\n\nexport const useSignInContext = (): SignInContextType => {\n const context = useContext(SignInContext);\n const ternSecure = useTernSecure();\n const ternSecureOptions = ternSecure._internal_getAllOptions();\n const currentParams = useMemo(() => {\n if (typeof window !== 'undefined') {\n return new URLSearchParams(window.location.search);\n }\n return new URLSearchParams();\n }, []);\n\n if (context === null) {\n throw new Error(\n 'useSignInContext must be used within a SignInProvider. Please wrap your component tree with SignInProvider.',\n );\n }\n\n const { ...ctx } = context;\n\n const createAuthError = useCallback(\n (message: string, code: string, name: string = 'AuthError', response?: any): AuthErrorTree => {\n const authError = new Error(message) as AuthErrorTree;\n authError.name = name;\n authError.code = code;\n authError.response = response;\n return authError;\n },\n [],\n );\n\n const handleSignInError = useCallback((authError: AuthErrorTree) => {\n console.error(authError);\n }, []);\n\n const redirectUrls = new RedirectUrls(\n ternSecureOptions,\n {\n ...ctx,\n signInForceRedirectUrl: ctx.signInForceRedirectUrl || ctx.forceRedirectUrl,\n signInFallbackRedirectUrl: ctx.signInFallbackRedirectUrl || ctx.fallbackRedirectUrl,\n },\n currentParams,\n );\n\n const afterSignInUrl = ternSecure.constructUrlWithAuthRedirect(redirectUrls.getAfterSignInUrl());\n const afterSignUpUrl = ternSecure.constructUrlWithAuthRedirect(redirectUrls.getAfterSignUpUrl());\n\n const redirectAfterSignIn = () => ternSecure.navigate(afterSignInUrl);\n\n const preservedParams = redirectUrls.getPreservedSearchParams();\n const baseSignInUrl = ctx.path || ternSecureOptions.signInUrl;\n const baseSignUpUrl = ternSecureOptions.signUpUrl;\n\n const signInUrl = buildURL(\n {\n base: baseSignInUrl,\n hashSearchParams: [currentParams, preservedParams],\n },\n { stringify: true },\n );\n\n const signUpUrl = buildURL(\n {\n base: baseSignUpUrl,\n hashSearchParams: [currentParams, preservedParams],\n },\n { stringify: true },\n );\n\n /**\n *\n * This function separates session creation from redirection, allowing consumers\n * to perform custom logic between authentication and redirect.\n *\n * Use cases:\n * 1. Check if user exists in external database (e.g., FreeSWITCH VoIP user table)\n * 2. Validate user permissions or roles\n * 3. Perform additional setup or initialization\n * 4. Custom redirect logic based on user data\n * Example:\n * await onSignInSuccess(user, {\n * onPreRedirect: async () => {\n * // user is accessible here via closure\n * const exists = await checkUser(user.email);\n * return exists;\n * }\n * });\n *\n * @param user - The authenticated TernSecureUser\n * @param options - Configuration options\n * @param options.onPreRedirect - Optional async callback executed before redirect.\n * Return false to prevent redirection, true to proceed.\n * This is where you can perform DB checks, role validation, etc.\n * The user object is accessible via closure.\n * If not provided, automatically redirects after session creation.\n */\n const onSignInSuccess = useCallback(\n async (\n user: TernSecureUser,\n options?: {\n onPreRedirect?: () => Promise<boolean>;\n },\n ) => {\n try {\n await ternSecure.createActiveSession({ session: user });\n\n if (options?.onPreRedirect) {\n try {\n const shouldRedirect = await options.onPreRedirect();\n\n if (shouldRedirect) {\n redirectAfterSignIn();\n }\n // If shouldRedirect is false, consumer handles redirect manually\n } catch (error) {\n const authError = createAuthError(\n 'Pre-redirect validation failed',\n 'PRE_REDIRECT_FAILED',\n 'PreRedirectError',\n error,\n );\n handleSignInError(authError);\n }\n } else {\n redirectAfterSignIn();\n }\n } catch (error) {\n const authError = createAuthError(\n error instanceof Error ? error.message : 'Failed to create session',\n 'SESSION_CREATION_FAILED',\n 'SessionError',\n error,\n );\n handleSignInError(authError);\n }\n },\n [ternSecure, createAuthError, handleSignInError, redirectAfterSignIn],\n );\n\n const checkRedirectResult = useCallback(async (): Promise<void> => {\n try {\n const result = await ternSecure.getRedirectResult();\n if (result && result.success) {\n await onSignInSuccess(result.user);\n } else if (result && !result.success) {\n const authError = createAuthError(\n result.message || 'Redirect sign-in failed',\n result.error || 'REDIRECT_FAILED',\n 'RedirectError',\n result,\n );\n handleSignInError(authError);\n }\n } catch (error) {\n const authError = createAuthError(\n error instanceof Error ? error.message : 'Failed to check redirect result',\n 'REDIRECT_CHECK_FAILED',\n 'RedirectError',\n error,\n );\n handleSignInError(authError);\n }\n }, [ternSecure, onSignInSuccess, handleSignInError, createAuthError]);\n\n return {\n ...(ctx as SignInCtx),\n afterSignInUrl,\n afterSignUpUrl,\n signInUrl,\n signUpUrl,\n checkRedirectResult,\n onSignInSuccess,\n handleSignInError,\n redirectAfterSignIn,\n };\n};\n\ninterface SignInProviderProps extends Partial<SignInCtx> {\n children: ReactNode;\n}\n\nexport function SignInProvider({ children, ...ctxProps }: SignInProviderProps) {\n const contextValue = ctxProps as SignInCtx;\n return <SignInContext.Provider value={contextValue}>{children}</SignInContext.Provider>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AASrB,EAAe,CAAE,SAAAiC,EAAU,GAAGC,CAAS,EAAwB,CAC7E,MAAMC,EAAeD,EACrB,SAAO,OAACnC,EAAc,SAAd,CAAuB,MAAOoC,EAAe,SAAAF,EAAS,CAChE","names":["SignInCtx_exports","__export","SignInContext","SignInProvider","useSignInContext","__toCommonJS","import_jsx_runtime","import_auth","import_react","context","ternSecure","ternSecureOptions","currentParams","ctx","createAuthError","message","code","name","response","authError","handleSignInError","redirectUrls","afterSignInUrl","afterSignUpUrl","redirectAfterSignIn","preservedParams","baseSignInUrl","baseSignUpUrl","signInUrl","signUpUrl","onSignInSuccess","user","options","error","checkRedirectResult","result","children","ctxProps","contextValue"]}
|
package/dist/ctx/SignInCtx.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";import{jsx as F}from"react/jsx-runtime";import{buildURL as p,RedirectUrls as w}from"@tern-secure/auth";import{useTernSecure as E}from"@tern-secure/shared/react";import{createContext as y,useCallback as u,useContext as b,useMemo as T}from"react";const f=y(null),L=()=>{const l=b(f),e=E(),c=e._internal_getAllOptions(),S=T(()=>typeof window<"u"?new URLSearchParams(window.location.search):new URLSearchParams,[]);if(l===null)throw new Error("useSignInContext must be used within a SignInProvider. Please wrap your component tree with SignInProvider.");const{...i}=l,s=u((r,n,t="AuthError",a)=>{const g=new Error(r);return g.name=t,g.code=n,g.response=a,g},[]),o=u(r=>{console.error(r)},[]),I=new w(c,{...i,signInForceRedirectUrl:i.signInForceRedirectUrl||i.forceRedirectUrl,signInFallbackRedirectUrl:i.signInFallbackRedirectUrl||i.fallbackRedirectUrl},S),U=e.constructUrlWithAuthRedirect(I.getAfterSignInUrl()),P=e.constructUrlWithAuthRedirect(I.getAfterSignUpUrl()),d=()=>e.navigate(U),h=I.getPreservedSearchParams(),m=i.path||c.signInUrl,x=c.signUpUrl,C=p({base:m,hashSearchParams:[S,h]},{stringify:!0}),A=p({base:x,hashSearchParams:[S,h]},{stringify:!0}),R=u(async(r,n)=>{try{if(await e.createActiveSession({session:r}),n?.onPreRedirect)try{await n.onPreRedirect()&&d()}catch(t){const a=s("Pre-redirect validation failed","PRE_REDIRECT_FAILED","PreRedirectError",t);o(a)}else d()}catch(t){const a=s(t instanceof Error?t.message:"Failed to create session","SESSION_CREATION_FAILED","SessionError",t);o(a)}},[e,s,o,d]),v=u(async()=>{try{const r=await e.getRedirectResult();if(r&&r.success)await R(r.user);else if(r&&!r.success){const n=s(r.message||"Redirect sign-in failed",r.error||"REDIRECT_FAILED","RedirectError",r);o(n)}}catch(r){const n=s(r instanceof Error?r.message:"Failed to check redirect result","REDIRECT_CHECK_FAILED","RedirectError",r);o(n)}},[e,R,o,s]);return{...i,afterSignInUrl:U,afterSignUpUrl:P,signInUrl:C,signUpUrl:A,checkRedirectResult:v,onSignInSuccess:R,handleSignInError:o,redirectAfterSignIn:d}};function O({children:l,...e}){const c=e;return F(f.Provider,{value:c,children:l})}export{f as SignInContext,O as SignInProvider,L as useSignInContext,E as useTernSecure};
|
|
2
|
-
//# sourceMappingURL=SignInCtx.mjs.map
|