@knocklabs/react-core 0.9.1 → 0.10.0
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/CHANGELOG.md +19 -0
- package/dist/cjs/modules/core/context/KnockProvider.js +1 -1
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs +19 -17
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs +19 -18
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/types/modules/core/context/KnockProvider.d.ts +2 -0
- package/dist/types/modules/core/context/KnockProvider.d.ts.map +1 -1
- package/dist/types/modules/core/hooks/useAuthenticatedKnockClient.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/modules/core/context/KnockProvider.tsx +11 -1
- package/src/modules/core/hooks/useAuthenticatedKnockClient.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5fc0af9: feat: adds `identificationStrategy` option for user identification control
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5fc0af9]
|
|
12
|
+
- @knocklabs/client@0.18.0
|
|
13
|
+
|
|
14
|
+
## 0.9.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [23b7057]
|
|
19
|
+
- Updated dependencies [1c24f68]
|
|
20
|
+
- @knocklabs/client@0.17.2
|
|
21
|
+
|
|
3
22
|
## 0.9.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("react"),P=require("../../i18n/context/KnockI18nProvider.js"),m=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function v(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const r=v(K),s=r.createContext(null),C=({apiKey:e,host:n,logLevel:t,userToken:o,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,children:l,i18n:d,identificationStrategy:a,...c})=>{const k=(c==null?void 0:c.user)||(c==null?void 0:c.userId),f=r.useMemo(()=>({host:n,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,logLevel:t,identificationStrategy:a}),[n,u,i,t,a]),b=m(e??"",k,o,f);return r.createElement(s.Provider,{value:{knock:b}},r.createElement(P.KnockI18nProvider,{i18n:d},l))},O=()=>{const e=r.useContext(s);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=C;exports.useKnockClient=O;
|
|
2
2
|
//# sourceMappingURL=KnockProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n }\n | {\n user: UserWithProperties;\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host
|
|
1
|
+
{"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAeMA,EAAeC,EAAMC,cAAyC,IAAI,EAyC3DC,EAAiEA,CAAC,CAC7EC,OAAAA,EACAC,KAAAA,EACAC,SAAAA,EACAC,UAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,SAAAA,EACAC,KAAAA,EACAC,uBAAAA,EACA,GAAGC,CACL,IAAM,CACEC,MAAAA,GAA6BD,GAAAA,YAAAA,EAAOE,QAAQF,GAAAA,YAAAA,EAAOG,QAGnDC,EAAsBhB,EAAMiB,QAChC,KAAO,CACLb,KAAAA,EACAG,oBAAAA,EACAC,yBAAAA,EACAH,SAAAA,EACAM,uBAAAA,CAAAA,GAEF,CACEP,EACAG,EACAC,EACAH,EACAM,CAAsB,CAE1B,EAEMO,EAAQC,EACZhB,GAAU,GACVU,EACAP,EACAU,CACF,EAEA,OACGhB,EAAA,cAAAD,EAAa,SAAb,CAAsB,MAAO,CAAEmB,MAAAA,CAAAA,CAC9B,EAAAlB,EAAA,cAACoB,EAAAA,kBAAkB,CAAA,KAAAV,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaY,EAAiBA,IAAa,CACnCC,MAAAA,EAAUtB,EAAMuB,WAAWxB,CAAY,EAC7C,GAAI,CAACuB,EACG,MAAA,IAAIE,MAAM,oDAAoD,EAEtE,OAAOF,EAAQJ,KACjB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const g=require("@knocklabs/client"),h=require("react");require("../context/KnockProvider.js");const o=require("./useStableOptions.js");require("date-fns");const l=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},q=l(g),d=l(h);function s(t,i,c,e={}){t.authenticate(i,c,{onUserTokenExpiring:e==null?void 0:e.onUserTokenExpiring,timeBeforeExpirationInMs:e==null?void 0:e.timeBeforeExpirationInMs,identificationStrategy:e==null?void 0:e.identificationStrategy})}function x(t,i,c,e={}){const f=d.default.useRef(void 0),u=o(e),n=o(i);return d.default.useMemo(()=>{const k=typeof n=="string"?n:n==null?void 0:n.id,r=f.current;if(r&&r.isAuthenticated()&&(r.userId!==k||r.userToken!==c))return s(r,n,c,u),r;r&&r.teardown();const a=new q.default(t,{host:u.host,logLevel:u.logLevel});return s(a,n,c,u),f.current=a,a},[t,n,c,u])}module.exports=x;
|
|
2
2
|
//# sourceMappingURL=useAuthenticatedKnockClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAUA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAA4BC,EAAW,CACxDG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAUA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAA4BC,EAAW,CACxDG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,yBACnCC,uBAAwBJ,GAAAA,YAAAA,EAASI,sBAAAA,CAClC,CACH,CAyBA,SAASC,EACPC,EACAR,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMO,MAAAA,EAAWC,EAAAA,QAAMC,OAA0BC,MAAS,EAEpDC,EAAgBC,EAAiBZ,CAAO,EACxCa,EAAuBD,EAAiBd,CAA0B,EAEjEU,OAAAA,EAAAA,QAAMM,QAAQ,IAAM,CACzB,MAAMC,EACJ,OAAOF,GAAyB,SAC5BA,EACAA,GAAAA,YAAAA,EAAsBG,GAEtBC,EAAeV,EAASW,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAaF,SAAWA,GAAUE,EAAalB,YAAcA,GAG5DkB,OAAAA,EAAAA,EACAJ,EACAd,EACAY,CACF,EACOM,EAGLA,GACFA,EAAaG,SAAS,EAIlBvB,MAAAA,EAAQ,IAAIwB,EAAAA,QAAMf,EAAQ,CAC9BgB,KAAMX,EAAcW,KACpBC,SAAUZ,EAAcY,QAAAA,CACzB,EAGC1B,OAAAA,EAAAA,EACAgB,EACAd,EACAY,CACF,EACAJ,EAASW,QAAUrB,EAEZA,GACN,CAACS,EAAQO,EAAsBd,EAAWY,CAAa,CAAC,CAC7D"}
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { KnockI18nProvider as
|
|
3
|
-
import
|
|
1
|
+
import * as t from "react";
|
|
2
|
+
import { KnockI18nProvider as C } from "../../i18n/context/KnockI18nProvider.mjs";
|
|
3
|
+
import P from "../hooks/useAuthenticatedKnockClient.mjs";
|
|
4
4
|
import "fast-deep-equal";
|
|
5
|
-
const
|
|
5
|
+
const k = t.createContext(null), x = ({
|
|
6
6
|
apiKey: n,
|
|
7
7
|
host: c,
|
|
8
8
|
logLevel: o,
|
|
9
|
-
userToken:
|
|
9
|
+
userToken: m,
|
|
10
10
|
onUserTokenExpiring: r,
|
|
11
11
|
timeBeforeExpirationInMs: u,
|
|
12
|
-
children:
|
|
12
|
+
children: s,
|
|
13
13
|
i18n: a,
|
|
14
|
-
|
|
14
|
+
identificationStrategy: i,
|
|
15
|
+
...e
|
|
15
16
|
}) => {
|
|
16
|
-
const
|
|
17
|
+
const d = (e == null ? void 0 : e.user) || (e == null ? void 0 : e.userId), K = t.useMemo(() => ({
|
|
17
18
|
host: c,
|
|
18
19
|
onUserTokenExpiring: r,
|
|
19
20
|
timeBeforeExpirationInMs: u,
|
|
20
|
-
logLevel: o
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
|
|
21
|
+
logLevel: o,
|
|
22
|
+
identificationStrategy: i
|
|
23
|
+
}), [c, r, u, o, i]), l = P(n ?? "", d, m, K);
|
|
24
|
+
return /* @__PURE__ */ t.createElement(k.Provider, { value: {
|
|
25
|
+
knock: l
|
|
26
|
+
} }, /* @__PURE__ */ t.createElement(C, { i18n: a }, s));
|
|
27
|
+
}, f = () => {
|
|
28
|
+
const n = t.useContext(k);
|
|
27
29
|
if (!n)
|
|
28
30
|
throw new Error("useKnockClient must be used within a KnockProvider");
|
|
29
31
|
return n.knock;
|
|
30
32
|
};
|
|
31
33
|
export {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
x as KnockProvider,
|
|
35
|
+
f as useKnockClient
|
|
34
36
|
};
|
|
35
37
|
//# sourceMappingURL=KnockProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n }\n | {\n user: UserWithProperties;\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host
|
|
1
|
+
{"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n identificationStrategy?: never;\n }\n | {\n user: UserWithProperties;\n identificationStrategy?: AuthenticateOptions[\"identificationStrategy\"];\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n identificationStrategy,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n }),\n [\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n identificationStrategy,\n ],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","identificationStrategy","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAeA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,GAyC3DC,IAAiEA,CAAC;AAAA,EAC7EC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,qBAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,wBAAAA;AAAAA,EACA,GAAGC;AACL,MAAM;AACEC,QAAAA,KAA6BD,KAAAA,gBAAAA,EAAOE,UAAQF,KAAAA,gBAAAA,EAAOG,SAGnDC,IAAsBhB,EAAMiB,QAChC,OAAO;AAAA,IACLb,MAAAA;AAAAA,IACAG,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAH,UAAAA;AAAAA,IACAM,wBAAAA;AAAAA,EAAAA,IAEF,CACEP,GACAG,GACAC,GACAH,GACAM,CAAsB,CAE1B,GAEMO,IAAQC,EACZhB,KAAU,IACVU,GACAP,GACAU,CACF;AAEA,SACG,gBAAAhB,EAAA,cAAAD,EAAa,UAAb,EAAsB,OAAO;AAAA,IAAEmB,OAAAA;AAAAA,EAAAA,EAC9B,GAAA,gBAAAlB,EAAA,cAACoB,GAAkB,EAAA,MAAAV,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaY,IAAiBA,MAAa;AACnCC,QAAAA,IAAUtB,EAAMuB,WAAWxB,CAAY;AAC7C,MAAI,CAACuB;AACG,UAAA,IAAIE,MAAM,oDAAoD;AAEtE,SAAOF,EAAQJ;AACjB;"}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import g from "@knocklabs/client";
|
|
2
|
+
import o from "react";
|
|
3
3
|
import "../context/KnockProvider.mjs";
|
|
4
|
-
import
|
|
4
|
+
import m from "./useStableOptions.mjs";
|
|
5
5
|
import "date-fns";
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
onUserTokenExpiring:
|
|
9
|
-
timeBeforeExpirationInMs:
|
|
6
|
+
function d(c, u, n, e = {}) {
|
|
7
|
+
c.authenticate(u, n, {
|
|
8
|
+
onUserTokenExpiring: e == null ? void 0 : e.onUserTokenExpiring,
|
|
9
|
+
timeBeforeExpirationInMs: e == null ? void 0 : e.timeBeforeExpirationInMs,
|
|
10
|
+
identificationStrategy: e == null ? void 0 : e.identificationStrategy
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
const f =
|
|
14
|
-
return
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
const
|
|
13
|
+
function v(c, u, n, e = {}) {
|
|
14
|
+
const f = o.useRef(void 0), i = m(e), t = m(u);
|
|
15
|
+
return o.useMemo(() => {
|
|
16
|
+
const l = typeof t == "string" ? t : t == null ? void 0 : t.id, r = f.current;
|
|
17
|
+
if (r && r.isAuthenticated() && (r.userId !== l || r.userToken !== n))
|
|
18
|
+
return d(r, t, n, i), r;
|
|
19
|
+
r && r.teardown();
|
|
20
|
+
const a = new g(c, {
|
|
20
21
|
host: i.host,
|
|
21
22
|
logLevel: i.logLevel
|
|
22
23
|
});
|
|
23
|
-
return
|
|
24
|
-
}, [
|
|
24
|
+
return d(a, t, n, i), f.current = a, a;
|
|
25
|
+
}, [c, t, n, i]);
|
|
25
26
|
}
|
|
26
27
|
export {
|
|
27
|
-
|
|
28
|
+
v as default
|
|
28
29
|
};
|
|
29
30
|
//# sourceMappingURL=useAuthenticatedKnockClient.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAUA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAA4BC,GAAW;AAAA,IACxDG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,EAAAA,
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n identificationStrategy: options?.identificationStrategy,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","identificationStrategy","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAUA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAA4BC,GAAW;AAAA,IACxDG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,IACnCC,wBAAwBJ,KAAAA,gBAAAA,EAASI;AAAAA,EAAAA,CAClC;AACH;AAyBA,SAASC,EACPC,GACAR,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMO,QAAAA,IAAWC,EAAMC,OAA0BC,MAAS,GAEpDC,IAAgBC,EAAiBZ,CAAO,GACxCa,IAAuBD,EAAiBd,CAA0B;AAEjEU,SAAAA,EAAMM,QAAQ,MAAM;AACzB,UAAMC,IACJ,OAAOF,KAAyB,WAC5BA,IACAA,KAAAA,gBAAAA,EAAsBG,IAEtBC,IAAeV,EAASW;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAaF,WAAWA,KAAUE,EAAalB,cAAcA;AAG5DkB,aAAAA,EAAAA,GACAJ,GACAd,GACAY,CACF,GACOM;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBvB,UAAAA,IAAQ,IAAIwB,EAAMf,GAAQ;AAAA,MAC9BgB,MAAMX,EAAcW;AAAAA,MACpBC,UAAUZ,EAAcY;AAAAA,IAAAA,CACzB;AAGC1B,WAAAA,EAAAA,GACAgB,GACAd,GACAY,CACF,GACAJ,EAASW,UAAUrB,GAEZA;AAAAA,KACN,CAACS,GAAQO,GAAsBd,GAAWY,CAAa,CAAC;AAC7D;"}
|
|
@@ -24,8 +24,10 @@ export type KnockProviderProps = {
|
|
|
24
24
|
*/
|
|
25
25
|
userId: Knock["userId"];
|
|
26
26
|
user?: never;
|
|
27
|
+
identificationStrategy?: never;
|
|
27
28
|
} | {
|
|
28
29
|
user: UserWithProperties;
|
|
30
|
+
identificationStrategy?: AuthenticateOptions["identificationStrategy"];
|
|
29
31
|
/**
|
|
30
32
|
* @deprecated The `userId` prop is deprecated and will be removed in a future version.
|
|
31
33
|
* Please pass the `user` prop instead containing an `id` value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,MAAM,kBAAkB,GAAG;IAE/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CACA;IACE;;;;;;;OAOG;IACH,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,MAAM,kBAAkB,GAAG;IAE/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CACA;IACE;;;;;;;OAOG;IACH,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,sBAAsB,CAAC,EAAE,KAAK,CAAC;CAChC,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB,sBAAsB,CAAC,EAAE,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;IACvE;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CACJ,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CA4CzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAkB3B,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB;;;;;;;GAOG;AACH,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,MAAM,EAClC,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AACT,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,0BAA0B,EACtD,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AAyDT,eAAe,2BAA2B,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@knocklabs/react-core",
|
|
3
3
|
"description": "A set of React components to build notification experiences powered by Knock",
|
|
4
4
|
"author": "@knocklabs",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.10.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/cjs/index.js",
|
|
8
8
|
"module": "dist/esm/index.mjs",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@knocklabs/client": "^0.
|
|
50
|
+
"@knocklabs/client": "^0.18.0",
|
|
51
51
|
"@tanstack/react-store": "^0.7.3",
|
|
52
52
|
"date-fns": "^4.0.0",
|
|
53
53
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -37,9 +37,11 @@ export type KnockProviderProps = {
|
|
|
37
37
|
*/
|
|
38
38
|
userId: Knock["userId"];
|
|
39
39
|
user?: never;
|
|
40
|
+
identificationStrategy?: never;
|
|
40
41
|
}
|
|
41
42
|
| {
|
|
42
43
|
user: UserWithProperties;
|
|
44
|
+
identificationStrategy?: AuthenticateOptions["identificationStrategy"];
|
|
43
45
|
/**
|
|
44
46
|
* @deprecated The `userId` prop is deprecated and will be removed in a future version.
|
|
45
47
|
* Please pass the `user` prop instead containing an `id` value.
|
|
@@ -61,6 +63,7 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
61
63
|
timeBeforeExpirationInMs,
|
|
62
64
|
children,
|
|
63
65
|
i18n,
|
|
66
|
+
identificationStrategy,
|
|
64
67
|
...props
|
|
65
68
|
}) => {
|
|
66
69
|
const userIdOrUserWithProperties = props?.user || props?.userId;
|
|
@@ -72,8 +75,15 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
|
|
|
72
75
|
onUserTokenExpiring,
|
|
73
76
|
timeBeforeExpirationInMs,
|
|
74
77
|
logLevel,
|
|
78
|
+
identificationStrategy,
|
|
75
79
|
}),
|
|
76
|
-
[
|
|
80
|
+
[
|
|
81
|
+
host,
|
|
82
|
+
onUserTokenExpiring,
|
|
83
|
+
timeBeforeExpirationInMs,
|
|
84
|
+
logLevel,
|
|
85
|
+
identificationStrategy,
|
|
86
|
+
],
|
|
77
87
|
);
|
|
78
88
|
|
|
79
89
|
const knock = useAuthenticatedKnockClient(
|
|
@@ -17,6 +17,7 @@ function authenticateWithOptions(
|
|
|
17
17
|
knock.authenticate(userIdOrUserWithProperties, userToken, {
|
|
18
18
|
onUserTokenExpiring: options?.onUserTokenExpiring,
|
|
19
19
|
timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,
|
|
20
|
+
identificationStrategy: options?.identificationStrategy,
|
|
20
21
|
});
|
|
21
22
|
}
|
|
22
23
|
|