@tern-secure/shared 1.3.0-canary.v20251003171521 → 1.3.0-canary.v20251008165428
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/react/index.d.mts +5 -2
- package/dist/react/index.d.ts +5 -2
- package/dist/react/index.js +18 -18
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +18 -18
- package/dist/react/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/react/index.d.mts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
-
import { TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState
|
|
2
|
+
import { TernSecureAuth, TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState } from '@tern-secure/types';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import react__default from 'react';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* New hook that uses TernSecureAuth
|
|
8
|
+
*/
|
|
9
|
+
declare const useTernSecure: () => TernSecureAuth;
|
|
7
10
|
|
|
8
11
|
type TernSecureAuthContextType = {
|
|
9
12
|
authProvider: TernSecureAuthProvider | null | undefined;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as _tern_secure_types from '@tern-secure/types';
|
|
2
|
-
import { TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState
|
|
2
|
+
import { TernSecureAuth, TernSecureInstanceTree, TernSecureAuthProvider, TernSecureState } from '@tern-secure/types';
|
|
3
3
|
import * as react from 'react';
|
|
4
4
|
import react__default from 'react';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* New hook that uses TernSecureAuth
|
|
8
|
+
*/
|
|
9
|
+
declare const useTernSecure: () => TernSecureAuth;
|
|
7
10
|
|
|
8
11
|
type TernSecureAuthContextType = {
|
|
9
12
|
authProvider: TernSecureAuthProvider | null | undefined;
|
package/dist/react/index.js
CHANGED
|
@@ -48,7 +48,7 @@ __export(react_exports, {
|
|
|
48
48
|
});
|
|
49
49
|
module.exports = __toCommonJS(react_exports);
|
|
50
50
|
|
|
51
|
-
// src/react/
|
|
51
|
+
// src/react/ternSecureAuthProvider.tsx
|
|
52
52
|
var import_react2 = require("react");
|
|
53
53
|
|
|
54
54
|
// src/react/ternsecureCtx.ts
|
|
@@ -74,13 +74,10 @@ var createContextAndHook = (displayName, options) => {
|
|
|
74
74
|
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
// src/react/
|
|
78
|
-
var [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var [UserContext, useUserContext] = createContextAndHook("UserContext");
|
|
82
|
-
function useAssertWrappedByTernSecureProvider(displayNameOrFn) {
|
|
83
|
-
const ctx = (0, import_react2.useContext)(TernSecureInstanceContext);
|
|
77
|
+
// src/react/ternSecureAuthProvider.tsx
|
|
78
|
+
var [TernSecureAuthCtx, useTernSecureAuthCtx] = createContextAndHook("TernSecureAuthCtx");
|
|
79
|
+
function useAssertWrappedByTernSecureAuthProvider(displayNameOrFn) {
|
|
80
|
+
const ctx = (0, import_react2.useContext)(TernSecureAuthCtx);
|
|
84
81
|
if (!ctx) {
|
|
85
82
|
if (typeof displayNameOrFn === "function") {
|
|
86
83
|
displayNameOrFn();
|
|
@@ -96,17 +93,14 @@ Possible fixes:
|
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
95
|
|
|
99
|
-
// src/react/
|
|
100
|
-
var useTernSecure = () => {
|
|
101
|
-
useAssertWrappedByTernSecureProvider("useTernSecure");
|
|
102
|
-
return useTernSecureInstanceContext();
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
// src/react/ternSecureAuthProvider.tsx
|
|
96
|
+
// src/react/ternSecureProvider.tsx
|
|
106
97
|
var import_react3 = require("react");
|
|
107
|
-
var [
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
var [TernSecureInstanceContext, useTernSecureInstanceContext] = createContextAndHook("TernSecureInstanceContext");
|
|
99
|
+
var [TernSecureAuthContext, useTernSecureAuthContext] = createContextAndHook("TernSecureAuthContext");
|
|
100
|
+
var [SessionContext, useSessionContext] = createContextAndHook("SessionContext");
|
|
101
|
+
var [UserContext, useUserContext] = createContextAndHook("UserContext");
|
|
102
|
+
function useAssertWrappedByTernSecureProvider(displayNameOrFn) {
|
|
103
|
+
const ctx = (0, import_react3.useContext)(TernSecureInstanceContext);
|
|
110
104
|
if (!ctx) {
|
|
111
105
|
if (typeof displayNameOrFn === "function") {
|
|
112
106
|
displayNameOrFn();
|
|
@@ -121,6 +115,12 @@ Possible fixes:
|
|
|
121
115
|
);
|
|
122
116
|
}
|
|
123
117
|
}
|
|
118
|
+
|
|
119
|
+
// src/react/hooks/useTernSecure.ts
|
|
120
|
+
var useTernSecure = () => {
|
|
121
|
+
useAssertWrappedByTernSecureAuthProvider("useTernSecure");
|
|
122
|
+
return useTernSecureAuthCtx();
|
|
123
|
+
};
|
|
124
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
125
125
|
0 && (module.exports = {
|
|
126
126
|
SessionContext,
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/index.ts","../../src/react/
|
|
1
|
+
{"version":3,"sources":["../../src/react/index.ts","../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/ternSecureProvider.tsx","../../src/react/hooks/useTernSecure.ts"],"sourcesContent":["export * from './hooks'\n\nexport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n SessionContext,\n UserContext,\n TernSecureAuthContext,\n TernSecureInstanceContext\n} from './ternSecureProvider'\n\nexport {\n assertContextExists,\n createContextAndHook\n} from './ternsecureCtx'\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider\n} from './ternSecureAuthProvider'","'use client'\n\nimport type { \n TernSecureAuth,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\n\nconst [TernSecureAuthCtx, useTernSecureAuthCtx] =\n createContextAndHook<TernSecureAuth>('TernSecureAuthCtx');\n\nfunction useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureAuthCtx);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n \n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider,\n};","'use client'\n\nimport React from 'react';\n\n/**\n * Assert that the context value exists, otherwise throw an error.\n *\n * @internal\n */\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextAndHook<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Create and return a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n *\n * The first hook returned guarantees that the context exists so the returned value is always `CtxValue`\n * The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`\n *\n * @internal\n */\n\nexport const createContextAndHook = <CtxValue>(\n displayName: string,\n options?: Options,\n): [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxValue } | undefined >(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `${displayName} not found`);\n return (ctx as any).value as CtxValue;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n return ctx ? ctx.value : {}\n };\n\n /**\n * Assert that the context value exists, otherwise throw an error.\n if (ctx === undefined) {\n throw new Error(`use${name} must be used within a ${name}Provider`);\n }\n return ctx.value;\n */\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n}","'use client'\n\nimport type { \n TernSecureAuthProvider,\n TernSecureInstanceTree,\n TernSecureState,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nexport type TernSecureAuthContextType = {\n authProvider: TernSecureAuthProvider | null | undefined;\n authState: TernSecureState;\n}\n\n\n// Create TernSecure instance context\nconst [TernSecureInstanceContext, useTernSecureInstanceContext] = \n createContextAndHook<TernSecureInstanceTree>('TernSecureInstanceContext');\n\nconst [TernSecureAuthContext, useTernSecureAuthContext] =\n createContextAndHook<TernSecureAuthContextType>('TernSecureAuthContext');\n\nconst [SessionContext, useSessionContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['session']>('SessionContext');\n\nconst [UserContext, useUserContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['user']>('UserContext');\n\n// Assert helper\nfunction useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureInstanceContext);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\nexport {\n TernSecureInstanceContext,\n TernSecureAuthContext,\n SessionContext,\n UserContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n useTernSecureInstanceContext,\n useAssertWrappedByTernSecureProvider\n};","import type { TernSecureAuth, TernSecureInstanceTree } from '@tern-secure/types';\n\nimport {\n useAssertWrappedByTernSecureAuthProvider,\n useTernSecureAuthCtx,\n} from '../ternSecureAuthProvider';\nimport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n} from '../ternSecureProvider';\n\n/**\n * @deprecated this was a previous version with cdn. now since in this package we dont use cdn, create a new hook that uuses TernSecureAuth and rename this to useTernSecure_Deprecated\n *\n */\nexport const useTernSecure_Deprecated = (): TernSecureInstanceTree => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureProvider('useTernSecure');\n return useTernSecureInstanceContext();\n};\n\n\n/**\n * New hook that uses TernSecureAuth\n */\nexport const useTernSecure = (): TernSecureAuth => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureAuthProvider('useTernSecure');\n return useTernSecureAuthCtx();\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAAA,gBAA2B;;;ACH3B,mBAAkB;AAOX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAeO,IAAM,uBAAuB,CAClC,aACA,YAC2F;AAC3F,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,aAAAC,QAAM,cAAgD,MAAS;AAC3E,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,aAAAA,QAAM,WAAW,GAAG;AAChC,gBAAY,KAAK,GAAG,WAAW,YAAY;AAC3C,WAAQ,IAAY;AAAA,EACtB;AAEA,QAAM,yBAAyB,MAAM;AACnC,UAAM,MAAM,aAAAA,QAAM,WAAW,GAAG;AAChC,WAAO,MAAM,IAAI,QAAQ,CAAC;AAAA,EAC5B;AAUA,SAAO,CAAC,KAAK,QAAQ,sBAAsB;AAC7C;;;AD9CA,IAAM,CAAC,mBAAmB,oBAAoB,IAC5C,qBAAqC,mBAAmB;AAE1D,SAAS,yCAAyC,iBAA8C;AAE9F,QAAM,UAAM,0BAAW,iBAAiB;AAExC,MAAI,CAAC,KAAK;AACR,QAAI,OAAO,oBAAoB,YAAY;AACzC,sBAAgB;AAChB;AAAA,IACF;AAEA,UAAM,IAAI;AAAA,MACR,GAAG,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,IAKpB;AAAA,EACF;AACF;;;AExBA,IAAAC,gBAA2B;AAW3B,IAAM,CAAC,2BAA2B,4BAA4B,IAC5D,qBAA6C,2BAA2B;AAE1E,IAAM,CAAC,uBAAuB,wBAAwB,IACpD,qBAAgD,uBAAuB;AAEzE,IAAM,CAAC,gBAAgB,iBAAiB,IACxC,qBAAgE,gBAAgB;AAEhF,IAAM,CAAC,aAAa,cAAc,IAClC,qBAA6D,aAAa;AAG1E,SAAS,qCAAqC,iBAA8C;AAE1F,QAAM,UAAM,0BAAW,yBAAyB;AAEhD,MAAI,CAAC,KAAK;AACR,QAAI,OAAO,oBAAoB,YAAY;AACzC,sBAAgB;AAChB;AAAA,IACF;AAEA,UAAM,IAAI;AAAA,MACR,GAAG,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,IAKpB;AAAA,EACF;AACF;;;AChBO,IAAM,gBAAgB,MAAsB;AAUjD,2CAAyC,eAAe;AACxD,SAAO,qBAAqB;AAC9B;","names":["import_react","React","import_react"]}
|
package/dist/react/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/react/
|
|
1
|
+
// src/react/ternSecureAuthProvider.tsx
|
|
2
2
|
import { useContext } from "react";
|
|
3
3
|
|
|
4
4
|
// src/react/ternsecureCtx.ts
|
|
@@ -24,13 +24,10 @@ var createContextAndHook = (displayName, options) => {
|
|
|
24
24
|
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// src/react/
|
|
28
|
-
var [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var [UserContext, useUserContext] = createContextAndHook("UserContext");
|
|
32
|
-
function useAssertWrappedByTernSecureProvider(displayNameOrFn) {
|
|
33
|
-
const ctx = useContext(TernSecureInstanceContext);
|
|
27
|
+
// src/react/ternSecureAuthProvider.tsx
|
|
28
|
+
var [TernSecureAuthCtx, useTernSecureAuthCtx] = createContextAndHook("TernSecureAuthCtx");
|
|
29
|
+
function useAssertWrappedByTernSecureAuthProvider(displayNameOrFn) {
|
|
30
|
+
const ctx = useContext(TernSecureAuthCtx);
|
|
34
31
|
if (!ctx) {
|
|
35
32
|
if (typeof displayNameOrFn === "function") {
|
|
36
33
|
displayNameOrFn();
|
|
@@ -46,17 +43,14 @@ Possible fixes:
|
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
// src/react/
|
|
50
|
-
var useTernSecure = () => {
|
|
51
|
-
useAssertWrappedByTernSecureProvider("useTernSecure");
|
|
52
|
-
return useTernSecureInstanceContext();
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/react/ternSecureAuthProvider.tsx
|
|
46
|
+
// src/react/ternSecureProvider.tsx
|
|
56
47
|
import { useContext as useContext2 } from "react";
|
|
57
|
-
var [
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
var [TernSecureInstanceContext, useTernSecureInstanceContext] = createContextAndHook("TernSecureInstanceContext");
|
|
49
|
+
var [TernSecureAuthContext, useTernSecureAuthContext] = createContextAndHook("TernSecureAuthContext");
|
|
50
|
+
var [SessionContext, useSessionContext] = createContextAndHook("SessionContext");
|
|
51
|
+
var [UserContext, useUserContext] = createContextAndHook("UserContext");
|
|
52
|
+
function useAssertWrappedByTernSecureProvider(displayNameOrFn) {
|
|
53
|
+
const ctx = useContext2(TernSecureInstanceContext);
|
|
60
54
|
if (!ctx) {
|
|
61
55
|
if (typeof displayNameOrFn === "function") {
|
|
62
56
|
displayNameOrFn();
|
|
@@ -71,6 +65,12 @@ Possible fixes:
|
|
|
71
65
|
);
|
|
72
66
|
}
|
|
73
67
|
}
|
|
68
|
+
|
|
69
|
+
// src/react/hooks/useTernSecure.ts
|
|
70
|
+
var useTernSecure = () => {
|
|
71
|
+
useAssertWrappedByTernSecureAuthProvider("useTernSecure");
|
|
72
|
+
return useTernSecureAuthCtx();
|
|
73
|
+
};
|
|
74
74
|
export {
|
|
75
75
|
SessionContext,
|
|
76
76
|
TernSecureAuthContext,
|
package/dist/react/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/react/
|
|
1
|
+
{"version":3,"sources":["../../src/react/ternSecureAuthProvider.tsx","../../src/react/ternsecureCtx.ts","../../src/react/ternSecureProvider.tsx","../../src/react/hooks/useTernSecure.ts"],"sourcesContent":["'use client'\n\nimport type { \n TernSecureAuth,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\n\nconst [TernSecureAuthCtx, useTernSecureAuthCtx] =\n createContextAndHook<TernSecureAuth>('TernSecureAuthCtx');\n\nfunction useAssertWrappedByTernSecureAuthProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureAuthCtx);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n \n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\n\nexport {\n TernSecureAuthCtx,\n useTernSecureAuthCtx,\n useAssertWrappedByTernSecureAuthProvider,\n};","'use client'\n\nimport React from 'react';\n\n/**\n * Assert that the context value exists, otherwise throw an error.\n *\n * @internal\n */\nexport function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal {\n if (!contextVal) {\n throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`);\n }\n}\ntype Options = { assertCtxFn?: (v: unknown, msg: string) => void };\ntype ContextAndHook<T> = React.Context<{ value: T } | undefined>;\ntype UseCtxFn<T> = () => T;\n\n/**\n * Create and return a Context and two hooks that return the context value.\n * The Context type is derived from the type passed in by the user.\n *\n * The first hook returned guarantees that the context exists so the returned value is always `CtxValue`\n * The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`\n *\n * @internal\n */\n\nexport const createContextAndHook = <CtxValue>(\n displayName: string,\n options?: Options,\n): [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>] => {\n const { assertCtxFn = assertContextExists } = options || {};\n const Ctx = React.createContext<{ value: CtxValue } | undefined >(undefined);\n Ctx.displayName = displayName;\n\n const useCtx = () => {\n const ctx = React.useContext(Ctx);\n assertCtxFn(ctx, `${displayName} not found`);\n return (ctx as any).value as CtxValue;\n };\n\n const useCtxWithoutGuarantee = () => {\n const ctx = React.useContext(Ctx);\n return ctx ? ctx.value : {}\n };\n\n /**\n * Assert that the context value exists, otherwise throw an error.\n if (ctx === undefined) {\n throw new Error(`use${name} must be used within a ${name}Provider`);\n }\n return ctx.value;\n */\n\n return [Ctx, useCtx, useCtxWithoutGuarantee];\n}","'use client'\n\nimport type { \n TernSecureAuthProvider,\n TernSecureInstanceTree,\n TernSecureState,\n} from '@tern-secure/types';\nimport { useContext } from 'react';\n\nimport { createContextAndHook } from './ternsecureCtx';\n\nexport type TernSecureAuthContextType = {\n authProvider: TernSecureAuthProvider | null | undefined;\n authState: TernSecureState;\n}\n\n\n// Create TernSecure instance context\nconst [TernSecureInstanceContext, useTernSecureInstanceContext] = \n createContextAndHook<TernSecureInstanceTree>('TernSecureInstanceContext');\n\nconst [TernSecureAuthContext, useTernSecureAuthContext] =\n createContextAndHook<TernSecureAuthContextType>('TernSecureAuthContext');\n\nconst [SessionContext, useSessionContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['session']>('SessionContext');\n\nconst [UserContext, useUserContext] = \ncreateContextAndHook<TernSecureInstanceTree['auth']['user']>('UserContext');\n\n// Assert helper\nfunction useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void {\n //const ctx = useTernSecureInstanceContext();\n const ctx = useContext(TernSecureInstanceContext);\n \n if (!ctx) {\n if (typeof displayNameOrFn === 'function') {\n displayNameOrFn();\n return;\n }\n\n throw new Error(\n `${displayNameOrFn} can only be used within the <TernSecureProvider /> component.\n \nPossible fixes:\n1. Ensure that the <TernSecureProvider /> is correctly wrapping your application\n2. Check for multiple versions of @tern-secure packages in your project`\n );\n }\n}\n\n\nexport {\n TernSecureInstanceContext,\n TernSecureAuthContext,\n SessionContext,\n UserContext,\n useTernSecureAuthContext,\n useSessionContext,\n useUserContext,\n useTernSecureInstanceContext,\n useAssertWrappedByTernSecureProvider\n};","import type { TernSecureAuth, TernSecureInstanceTree } from '@tern-secure/types';\n\nimport {\n useAssertWrappedByTernSecureAuthProvider,\n useTernSecureAuthCtx,\n} from '../ternSecureAuthProvider';\nimport {\n useAssertWrappedByTernSecureProvider,\n useTernSecureInstanceContext,\n} from '../ternSecureProvider';\n\n/**\n * @deprecated this was a previous version with cdn. now since in this package we dont use cdn, create a new hook that uuses TernSecureAuth and rename this to useTernSecure_Deprecated\n *\n */\nexport const useTernSecure_Deprecated = (): TernSecureInstanceTree => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureProvider('useTernSecure');\n return useTernSecureInstanceContext();\n};\n\n\n/**\n * New hook that uses TernSecureAuth\n */\nexport const useTernSecure = (): TernSecureAuth => {\n /**\n * if no assertion is needed, you can use the following:\n * const instance = useTernSecureInstanceContext();\n * if (!instance) {\n * throw new Error('useTernSecure must be used within a TernSecureProvider');\n * }\n * return instance;\n */\n\n useAssertWrappedByTernSecureAuthProvider('useTernSecure');\n return useTernSecureAuthCtx();\n};\n"],"mappings":";AAKA,SAAS,kBAAkB;;;ACH3B,OAAO,WAAW;AAOX,SAAS,oBAAoB,YAAqB,UAA2D;AAClH,MAAI,CAAC,YAAY;AACf,UAAM,OAAO,aAAa,WAAW,IAAI,MAAM,QAAQ,IAAI,IAAI,MAAM,GAAG,SAAS,WAAW,YAAY;AAAA,EAC1G;AACF;AAeO,IAAM,uBAAuB,CAClC,aACA,YAC2F;AAC3F,QAAM,EAAE,cAAc,oBAAoB,IAAI,WAAW,CAAC;AAC1D,QAAM,MAAM,MAAM,cAAgD,MAAS;AAC3E,MAAI,cAAc;AAElB,QAAM,SAAS,MAAM;AACnB,UAAM,MAAM,MAAM,WAAW,GAAG;AAChC,gBAAY,KAAK,GAAG,WAAW,YAAY;AAC3C,WAAQ,IAAY;AAAA,EACtB;AAEA,QAAM,yBAAyB,MAAM;AACnC,UAAM,MAAM,MAAM,WAAW,GAAG;AAChC,WAAO,MAAM,IAAI,QAAQ,CAAC;AAAA,EAC5B;AAUA,SAAO,CAAC,KAAK,QAAQ,sBAAsB;AAC7C;;;AD9CA,IAAM,CAAC,mBAAmB,oBAAoB,IAC5C,qBAAqC,mBAAmB;AAE1D,SAAS,yCAAyC,iBAA8C;AAE9F,QAAM,MAAM,WAAW,iBAAiB;AAExC,MAAI,CAAC,KAAK;AACR,QAAI,OAAO,oBAAoB,YAAY;AACzC,sBAAgB;AAChB;AAAA,IACF;AAEA,UAAM,IAAI;AAAA,MACR,GAAG,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,IAKpB;AAAA,EACF;AACF;;;AExBA,SAAS,cAAAA,mBAAkB;AAW3B,IAAM,CAAC,2BAA2B,4BAA4B,IAC5D,qBAA6C,2BAA2B;AAE1E,IAAM,CAAC,uBAAuB,wBAAwB,IACpD,qBAAgD,uBAAuB;AAEzE,IAAM,CAAC,gBAAgB,iBAAiB,IACxC,qBAAgE,gBAAgB;AAEhF,IAAM,CAAC,aAAa,cAAc,IAClC,qBAA6D,aAAa;AAG1E,SAAS,qCAAqC,iBAA8C;AAE1F,QAAM,MAAMC,YAAW,yBAAyB;AAEhD,MAAI,CAAC,KAAK;AACR,QAAI,OAAO,oBAAoB,YAAY;AACzC,sBAAgB;AAChB;AAAA,IACF;AAEA,UAAM,IAAI;AAAA,MACR,GAAG,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,IAKpB;AAAA,EACF;AACF;;;AChBO,IAAM,gBAAgB,MAAsB;AAUjD,2CAAyC,eAAe;AACxD,SAAO,qBAAqB;AAC9B;","names":["useContext","useContext"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tern-secure/shared",
|
|
3
|
-
"version": "1.3.0-canary.
|
|
3
|
+
"version": "1.3.0-canary.v20251008165428",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/TernSecure/auth.git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"dependencies": {
|
|
82
82
|
"js-cookie": "^3.0.5",
|
|
83
83
|
"tslib": "2.4.1",
|
|
84
|
-
"@tern-secure/types": "1.1.0-canary.
|
|
84
|
+
"@tern-secure/types": "1.1.0-canary.v20251008165428"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"react": "^19",
|