@chipmobilesdk/rn-auth 0.4.0 → 0.6.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.
Files changed (180) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +74 -14
  3. package/lib/commonjs/access/accessTier.js +111 -0
  4. package/lib/commonjs/access/accessTier.js.map +1 -0
  5. package/lib/commonjs/app-auth.js +13 -0
  6. package/lib/commonjs/app-auth.js.map +1 -0
  7. package/lib/commonjs/config/types.js +50 -0
  8. package/lib/commonjs/config/types.js.map +1 -0
  9. package/lib/commonjs/config/validateConfig.js +114 -0
  10. package/lib/commonjs/config/validateConfig.js.map +1 -0
  11. package/lib/commonjs/core/authMachine.js +406 -0
  12. package/lib/commonjs/core/authMachine.js.map +1 -0
  13. package/lib/commonjs/core/profile.js +59 -0
  14. package/lib/commonjs/core/profile.js.map +1 -0
  15. package/lib/commonjs/core/session.js +125 -0
  16. package/lib/commonjs/core/session.js.map +1 -0
  17. package/lib/commonjs/diagnostics/errors.js +83 -0
  18. package/lib/commonjs/diagnostics/errors.js.map +1 -0
  19. package/lib/commonjs/diagnostics/messageKeys.js +51 -0
  20. package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
  21. package/lib/commonjs/index.js +175 -0
  22. package/lib/commonjs/index.js.map +1 -0
  23. package/lib/commonjs/keychain.js +13 -0
  24. package/lib/commonjs/keychain.js.map +1 -0
  25. package/lib/commonjs/oidc/authClient.js +157 -0
  26. package/lib/commonjs/oidc/authClient.js.map +1 -0
  27. package/lib/commonjs/oidc/classifyError.js +65 -0
  28. package/lib/commonjs/oidc/classifyError.js.map +1 -0
  29. package/lib/commonjs/oidc/socialRouting.js +58 -0
  30. package/lib/commonjs/oidc/socialRouting.js.map +1 -0
  31. package/lib/commonjs/package.json +1 -0
  32. package/lib/commonjs/react/AuthProvider.js +37 -0
  33. package/lib/commonjs/react/AuthProvider.js.map +1 -0
  34. package/lib/commonjs/react/hooks.js +122 -0
  35. package/lib/commonjs/react/hooks.js.map +1 -0
  36. package/lib/commonjs/testing/conformance.js +148 -0
  37. package/lib/commonjs/testing/conformance.js.map +1 -0
  38. package/lib/commonjs/testing/index.js +53 -0
  39. package/lib/commonjs/testing/index.js.map +1 -0
  40. package/lib/commonjs/tokens/accessToken.js +165 -0
  41. package/lib/commonjs/tokens/accessToken.js.map +1 -0
  42. package/lib/commonjs/tokens/secureStore.js +60 -0
  43. package/lib/commonjs/tokens/secureStore.js.map +1 -0
  44. package/lib/module/access/accessTier.js +106 -0
  45. package/lib/module/access/accessTier.js.map +1 -0
  46. package/lib/module/app-auth.js +9 -0
  47. package/lib/module/app-auth.js.map +1 -0
  48. package/lib/module/config/types.js +46 -0
  49. package/lib/module/config/types.js.map +1 -0
  50. package/lib/module/config/validateConfig.js +110 -0
  51. package/lib/module/config/validateConfig.js.map +1 -0
  52. package/lib/module/core/authMachine.js +402 -0
  53. package/lib/module/core/authMachine.js.map +1 -0
  54. package/lib/module/core/profile.js +54 -0
  55. package/lib/module/core/profile.js.map +1 -0
  56. package/lib/module/core/session.js +118 -0
  57. package/lib/module/core/session.js.map +1 -0
  58. package/lib/module/diagnostics/errors.js +74 -0
  59. package/lib/module/diagnostics/errors.js.map +1 -0
  60. package/lib/module/diagnostics/messageKeys.js +46 -0
  61. package/lib/module/diagnostics/messageKeys.js.map +1 -0
  62. package/lib/module/index.js +33 -0
  63. package/lib/module/index.js.map +1 -0
  64. package/lib/module/keychain.js +9 -0
  65. package/lib/module/keychain.js.map +1 -0
  66. package/lib/module/oidc/authClient.js +152 -0
  67. package/lib/module/oidc/authClient.js.map +1 -0
  68. package/lib/module/oidc/classifyError.js +60 -0
  69. package/lib/module/oidc/classifyError.js.map +1 -0
  70. package/lib/module/oidc/socialRouting.js +52 -0
  71. package/lib/module/oidc/socialRouting.js.map +1 -0
  72. package/lib/module/package.json +1 -0
  73. package/lib/module/react/AuthProvider.js +31 -0
  74. package/lib/module/react/AuthProvider.js.map +1 -0
  75. package/lib/module/react/hooks.js +111 -0
  76. package/lib/module/react/hooks.js.map +1 -0
  77. package/lib/module/testing/conformance.js +140 -0
  78. package/lib/module/testing/conformance.js.map +1 -0
  79. package/lib/module/testing/index.js +25 -0
  80. package/lib/module/testing/index.js.map +1 -0
  81. package/lib/module/tokens/accessToken.js +161 -0
  82. package/lib/module/tokens/accessToken.js.map +1 -0
  83. package/lib/module/tokens/secureStore.js +56 -0
  84. package/lib/module/tokens/secureStore.js.map +1 -0
  85. package/lib/typescript/commonjs/access/accessTier.d.ts +14 -0
  86. package/lib/typescript/commonjs/access/accessTier.d.ts.map +1 -0
  87. package/lib/typescript/commonjs/app-auth.d.ts +7 -0
  88. package/lib/typescript/commonjs/app-auth.d.ts.map +1 -0
  89. package/lib/typescript/commonjs/config/types.d.ts +171 -0
  90. package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
  91. package/lib/typescript/commonjs/config/validateConfig.d.ts +8 -0
  92. package/lib/typescript/commonjs/config/validateConfig.d.ts.map +1 -0
  93. package/lib/typescript/commonjs/core/authMachine.d.ts +14 -0
  94. package/lib/typescript/commonjs/core/authMachine.d.ts.map +1 -0
  95. package/lib/typescript/commonjs/core/profile.d.ts +15 -0
  96. package/lib/typescript/commonjs/core/profile.d.ts.map +1 -0
  97. package/lib/typescript/commonjs/core/session.d.ts +60 -0
  98. package/lib/typescript/commonjs/core/session.d.ts.map +1 -0
  99. package/lib/typescript/commonjs/diagnostics/errors.d.ts +37 -0
  100. package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
  101. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +57 -0
  102. package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
  103. package/lib/typescript/commonjs/index.d.ts +27 -0
  104. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  105. package/lib/typescript/commonjs/keychain.d.ts +7 -0
  106. package/lib/typescript/commonjs/keychain.d.ts.map +1 -0
  107. package/lib/typescript/commonjs/oidc/authClient.d.ts +75 -0
  108. package/lib/typescript/commonjs/oidc/authClient.d.ts.map +1 -0
  109. package/lib/typescript/commonjs/oidc/classifyError.d.ts +28 -0
  110. package/lib/typescript/commonjs/oidc/classifyError.d.ts.map +1 -0
  111. package/lib/typescript/commonjs/oidc/socialRouting.d.ts +22 -0
  112. package/lib/typescript/commonjs/oidc/socialRouting.d.ts.map +1 -0
  113. package/lib/typescript/commonjs/package.json +1 -0
  114. package/lib/typescript/commonjs/react/AuthProvider.d.ts +17 -0
  115. package/lib/typescript/commonjs/react/AuthProvider.d.ts.map +1 -0
  116. package/lib/typescript/commonjs/react/hooks.d.ts +42 -0
  117. package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
  118. package/lib/typescript/commonjs/testing/conformance.d.ts +32 -0
  119. package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/testing/index.d.ts +11 -0
  121. package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/tokens/accessToken.d.ts +45 -0
  123. package/lib/typescript/commonjs/tokens/accessToken.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/tokens/secureStore.d.ts +26 -0
  125. package/lib/typescript/commonjs/tokens/secureStore.d.ts.map +1 -0
  126. package/lib/typescript/module/access/accessTier.d.ts +14 -0
  127. package/lib/typescript/module/access/accessTier.d.ts.map +1 -0
  128. package/lib/typescript/module/app-auth.d.ts +7 -0
  129. package/lib/typescript/module/app-auth.d.ts.map +1 -0
  130. package/lib/typescript/module/config/types.d.ts +171 -0
  131. package/lib/typescript/module/config/types.d.ts.map +1 -0
  132. package/lib/typescript/module/config/validateConfig.d.ts +8 -0
  133. package/lib/typescript/module/config/validateConfig.d.ts.map +1 -0
  134. package/lib/typescript/module/core/authMachine.d.ts +14 -0
  135. package/lib/typescript/module/core/authMachine.d.ts.map +1 -0
  136. package/lib/typescript/module/core/profile.d.ts +15 -0
  137. package/lib/typescript/module/core/profile.d.ts.map +1 -0
  138. package/lib/typescript/module/core/session.d.ts +60 -0
  139. package/lib/typescript/module/core/session.d.ts.map +1 -0
  140. package/lib/typescript/module/diagnostics/errors.d.ts +37 -0
  141. package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
  142. package/lib/typescript/module/diagnostics/messageKeys.d.ts +57 -0
  143. package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
  144. package/lib/typescript/module/index.d.ts +27 -0
  145. package/lib/typescript/module/index.d.ts.map +1 -0
  146. package/lib/typescript/module/keychain.d.ts +7 -0
  147. package/lib/typescript/module/keychain.d.ts.map +1 -0
  148. package/lib/typescript/module/oidc/authClient.d.ts +75 -0
  149. package/lib/typescript/module/oidc/authClient.d.ts.map +1 -0
  150. package/lib/typescript/module/oidc/classifyError.d.ts +28 -0
  151. package/lib/typescript/module/oidc/classifyError.d.ts.map +1 -0
  152. package/lib/typescript/module/oidc/socialRouting.d.ts +22 -0
  153. package/lib/typescript/module/oidc/socialRouting.d.ts.map +1 -0
  154. package/lib/typescript/module/package.json +1 -0
  155. package/lib/typescript/module/react/AuthProvider.d.ts +17 -0
  156. package/lib/typescript/module/react/AuthProvider.d.ts.map +1 -0
  157. package/lib/typescript/module/react/hooks.d.ts +42 -0
  158. package/lib/typescript/module/react/hooks.d.ts.map +1 -0
  159. package/lib/typescript/module/testing/conformance.d.ts +32 -0
  160. package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
  161. package/lib/typescript/module/testing/index.d.ts +11 -0
  162. package/lib/typescript/module/testing/index.d.ts.map +1 -0
  163. package/lib/typescript/module/tokens/accessToken.d.ts +45 -0
  164. package/lib/typescript/module/tokens/accessToken.d.ts.map +1 -0
  165. package/lib/typescript/module/tokens/secureStore.d.ts +26 -0
  166. package/lib/typescript/module/tokens/secureStore.d.ts.map +1 -0
  167. package/package.json +68 -21
  168. package/skills/sdk-rn-auth/SKILL.md +35 -2
  169. package/src/config/types.ts +53 -5
  170. package/src/config/validateConfig.ts +32 -1
  171. package/src/core/authMachine.ts +40 -6
  172. package/src/core/profile.ts +6 -1
  173. package/src/core/session.ts +49 -3
  174. package/src/diagnostics/errors.ts +7 -5
  175. package/src/index.ts +7 -0
  176. package/src/oidc/authClient.ts +19 -1
  177. package/src/oidc/classifyError.ts +2 -1
  178. package/src/oidc/socialRouting.ts +3 -1
  179. package/src/react/hooks.ts +53 -14
  180. package/src/tokens/accessToken.ts +20 -9
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AuthProvider = AuthProvider;
7
+ exports.useAuthInstance = useAuthInstance;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
+ /**
12
+ * React context boundary for the auth controller (LIB-002).
13
+ *
14
+ * The context carries the controller only, never its state: a context value that
15
+ * changed on every transition re-rendered every consumer on every transition
16
+ * (PERF-02). Hooks read the state through `useSyncExternalStore` with a selector,
17
+ * so a component re-renders only when the part it reads changes.
18
+ */
19
+
20
+ const AuthContext = /*#__PURE__*/(0, _react.createContext)(null);
21
+ function AuthProvider({
22
+ auth,
23
+ children
24
+ }) {
25
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(AuthContext.Provider, {
26
+ value: auth,
27
+ children: children
28
+ });
29
+ }
30
+ function useAuthInstance() {
31
+ const auth = (0, _react.useContext)(AuthContext);
32
+ if (!auth) {
33
+ throw new Error('useAuth must be used within an <AuthProvider>.');
34
+ }
35
+ return auth;
36
+ }
37
+ //# sourceMappingURL=AuthProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_jsxRuntime","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AuthContext","createContext","AuthProvider","auth","children","jsx","Provider","value","useAuthInstance","useContext","Error"],"sourceRoot":"../../../src","sources":["react/AuthProvider.tsx"],"mappings":";;;;;;;AASA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyD,IAAAC,WAAA,GAAAD,OAAA;AAAA,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AATzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMkB,WAAW,gBAAG,IAAAC,oBAAa,EAAc,IAAI,CAAC;AAO7C,SAASC,YAAYA,CAAC;EAAEC,IAAI;EAAEC;AAA4B,CAAC,EAAE;EACnE,oBAAO,IAAAxB,WAAA,CAAAyB,GAAA,EAACL,WAAW,CAACM,QAAQ;IAACC,KAAK,EAAEJ,IAAK;IAAAC,QAAA,EAAEA;EAAQ,CAAuB,CAAC;AAC5E;AAEO,SAASI,eAAeA,CAAA,EAAS;EACvC,MAAML,IAAI,GAAG,IAAAM,iBAAU,EAACT,WAAW,CAAC;EACpC,IAAI,CAACG,IAAI,EAAE;IACV,MAAM,IAAIO,KAAK,CAAC,gDAAgD,CAAC;EAClE;EACA,OAAOP,IAAI;AACZ","ignoreList":[]}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAccessTier = useAccessTier;
7
+ exports.useAccessToken = useAccessToken;
8
+ exports.useAuth = useAuth;
9
+ exports.useAuthMessages = useAuthMessages;
10
+ exports.useAuthSelector = useAuthSelector;
11
+ exports.useProfile = useProfile;
12
+ exports.useSignInProvider = useSignInProvider;
13
+ exports.useSignInProviders = useSignInProviders;
14
+ var _react = require("@chipmobilesdk/rn-core/react");
15
+ var _react2 = require("react");
16
+ var _AuthProvider = require("./AuthProvider.js");
17
+ var _accessTier = require("../access/accessTier.js");
18
+ /**
19
+ * Public hooks (LIB-002). Each reads the controller's state through
20
+ * `useSyncExternalStore` (rn-core's `useExternalStore`), selecting only what it
21
+ * returns, so `useProfile` does not re-render when only the status changes.
22
+ */
23
+
24
+ /**
25
+ * Any slice of the auth state; the component re-renders only when the slice
26
+ * changes by `isEqual` (default `Object.is`).
27
+ */
28
+ function useAuthSelector(select, isEqual) {
29
+ const auth = (0, _AuthProvider.useAuthInstance)();
30
+ return (0, _react.useExternalStore)(auth.subscribe, auth.getState, select, isEqual);
31
+ }
32
+ const selectState = state => state;
33
+ const selectProfile = state => state.profile;
34
+ const selectAccessTier = state => state.accessTier;
35
+ function useAuth() {
36
+ const auth = (0, _AuthProvider.useAuthInstance)();
37
+ const state = useAuthSelector(selectState);
38
+ return {
39
+ state,
40
+ signIn: (0, _react2.useCallback)(providerId => auth.signIn(providerId), [auth]),
41
+ signOut: (0, _react2.useCallback)(() => auth.signOut(), [auth]),
42
+ signOutGlobal: (0, _react2.useCallback)(() => auth.signOutGlobal(), [auth]),
43
+ restore: (0, _react2.useCallback)(() => auth.restore(), [auth]),
44
+ canAccessPremium: (0, _react2.useCallback)(() => auth.canAccessPremium(), [auth]),
45
+ requirePremium: (0, _react2.useCallback)(() => auth.requirePremium(), [auth])
46
+ };
47
+ }
48
+
49
+ /** This package's copy, with the app's `messages` overrides applied. */
50
+ function useAuthMessages() {
51
+ return (0, _AuthProvider.useAuthInstance)().getMessages();
52
+ }
53
+ function useProfile() {
54
+ return useAuthSelector(selectProfile);
55
+ }
56
+ function useAccessTier() {
57
+ return useAuthSelector(selectAccessTier) ?? (0, _accessTier.failClosedTier)();
58
+ }
59
+
60
+ /** The first provider to present on the current platform (UX-004), or undefined. */
61
+ function useSignInProvider() {
62
+ const auth = (0, _AuthProvider.useAuthInstance)();
63
+ return auth.getPlatformProvider();
64
+ }
65
+
66
+ /** All available providers for the current platform, in configuration order (FR-003/FR-004). */
67
+ function useSignInProviders() {
68
+ const auth = (0, _AuthProvider.useAuthInstance)();
69
+ return auth.getPlatformProviders();
70
+ }
71
+ function useAccessToken(resourceKey) {
72
+ const auth = (0, _AuthProvider.useAuthInstance)();
73
+ const [state, setState] = (0, _react2.useState)({
74
+ status: 'idle',
75
+ resourceKey
76
+ });
77
+
78
+ // Which request may still write. A result for a resource the component has
79
+ // moved on from, or for an unmounted one, is dropped rather than applied
80
+ // (AUTH-17, standard VII).
81
+ const live = (0, _react2.useRef)(0);
82
+ (0, _react2.useEffect)(() => () => {
83
+ live.current += 1;
84
+ }, []);
85
+ const request = (0, _react2.useCallback)(async options => {
86
+ live.current += 1;
87
+ const id = live.current;
88
+ setState({
89
+ status: 'loading',
90
+ resourceKey
91
+ });
92
+ const result = await auth.requestAccessToken(resourceKey, options);
93
+ if (id === live.current) {
94
+ setState({
95
+ status: result.status,
96
+ token: result.token,
97
+ resourceKey
98
+ });
99
+ }
100
+ return result;
101
+ }, [auth, resourceKey]);
102
+
103
+ // A new resource starts from `idle`, not from the previous resource's token.
104
+ if (state.resourceKey !== resourceKey) {
105
+ live.current += 1;
106
+ setState({
107
+ status: 'idle',
108
+ resourceKey
109
+ });
110
+ return {
111
+ status: 'idle',
112
+ token: undefined,
113
+ request
114
+ };
115
+ }
116
+ return {
117
+ status: state.status,
118
+ token: state.token,
119
+ request
120
+ };
121
+ }
122
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_react2","_AuthProvider","_accessTier","useAuthSelector","select","isEqual","auth","useAuthInstance","useExternalStore","subscribe","getState","selectState","state","selectProfile","profile","selectAccessTier","accessTier","useAuth","signIn","useCallback","providerId","signOut","signOutGlobal","restore","canAccessPremium","requirePremium","useAuthMessages","getMessages","useProfile","useAccessTier","failClosedTier","useSignInProvider","getPlatformProvider","useSignInProviders","getPlatformProviders","useAccessToken","resourceKey","setState","useState","status","live","useRef","useEffect","current","request","options","id","result","requestAccessToken","token","undefined"],"sourceRoot":"../../../src","sources":["react/hooks.ts"],"mappings":";;;;;;;;;;;;;AAMA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAF,OAAA;AAWA,IAAAG,WAAA,GAAAH,OAAA;AAnBA;AACA;AACA;AACA;AACA;;AA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,CAAC,CAAC;IAC5C,MAAMW,MAAM,GAAG,MAAMzC,IAAI,CAAC0C,kBAAkB,CAACZ,WAAW,EAAES,OAAO,CAAC;IAClE,IAAIC,EAAE,KAAKN,IAAI,CAACG,OAAO,EAAE;MACxBN,QAAQ,CAAC;QAAEE,MAAM,EAAEQ,MAAM,CAACR,MAAM;QAAEU,KAAK,EAAEF,MAAM,CAACE,KAAK;QAAEb;MAAY,CAAC,CAAC;IACtE;IACA,OAAOW,MAAM;EACd,CAAC,EACD,CAACzC,IAAI,EAAE8B,WAAW,CACnB,CAAC;;EAED;EACA,IAAIxB,KAAK,CAACwB,WAAW,KAAKA,WAAW,EAAE;IACtCI,IAAI,CAACG,OAAO,IAAI,CAAC;IACjBN,QAAQ,CAAC;MAAEE,MAAM,EAAE,MAAM;MAAEH;IAAY,CAAC,CAAC;IACzC,OAAO;MAAEG,MAAM,EAAE,MAAM;MAAEU,KAAK,EAAEC,SAAS;MAAEN;IAAQ,CAAC;EACrD;EAEA,OAAO;IAAEL,MAAM,EAAE3B,KAAK,CAAC2B,MAAM;IAAEU,KAAK,EAAErC,KAAK,CAACqC,KAAK;IAAEL;EAAQ,CAAC;AAC7D","ignoreList":[]}
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.oidcAuthClientChecks = void 0;
7
+ exports.runOidcAuthClientConformance = runOidcAuthClientConformance;
8
+ exports.runSecureTokenStoreConformance = runSecureTokenStoreConformance;
9
+ exports.secureTokenStoreChecks = void 0;
10
+ var _testing = require("@chipmobilesdk/rn-core/testing");
11
+ /**
12
+ * What any `SecureTokenStore` and `OidcAuthClient` must do (IOS-12, AUTH-13).
13
+ *
14
+ * The same checks run against the in-memory doubles and against the keychain and
15
+ * app-auth adapters (native modules mocked in Jest, or for real from a demo
16
+ * screen on a device), so a test that drives a double proves something about the
17
+ * device path. Each check builds its own subject through a harness.
18
+ */
19
+
20
+ const KEY = '@chipmobilesdk/rn-auth/conformance';
21
+ const OTHER_KEY = '@chipmobilesdk/rn-auth/conformance-other';
22
+ const secureTokenStoreChecks = exports.secureTokenStoreChecks = [{
23
+ name: 'reads nothing for a key never written',
24
+ async run(harness) {
25
+ const value = await harness.create().getItem(KEY);
26
+ (0, _testing.ensure)(value === null, `expected null, got ${JSON.stringify(value)}`);
27
+ }
28
+ }, {
29
+ name: 'reads back the last value written',
30
+ async run(harness) {
31
+ const store = harness.create();
32
+ await store.setItem(KEY, 'first');
33
+ await store.setItem(KEY, 'second');
34
+ const value = await store.getItem(KEY);
35
+ (0, _testing.ensure)(value === 'second', `expected the last write, got ${JSON.stringify(value)}`);
36
+ }
37
+ }, {
38
+ name: 'keeps keys apart',
39
+ async run(harness) {
40
+ const store = harness.create();
41
+ await store.setItem(KEY, 'one');
42
+ await store.setItem(OTHER_KEY, 'two');
43
+ await store.removeItem(OTHER_KEY);
44
+ (0, _testing.ensure)((await store.getItem(KEY)) === 'one', 'removing one key touched another');
45
+ }
46
+ }, {
47
+ name: 'forgets a removed key, and removes a missing key safely',
48
+ async run(harness) {
49
+ const store = harness.create();
50
+ await store.removeItem(KEY);
51
+ await store.setItem(KEY, 'value');
52
+ await store.removeItem(KEY);
53
+ (0, _testing.ensure)((await store.getItem(KEY)) === null, 'a removed key still reads back');
54
+ }
55
+ }, {
56
+ name: 'keeps a long session artifact with non-ASCII text intact',
57
+ async run(harness) {
58
+ const store = harness.create();
59
+ const artifact = JSON.stringify({
60
+ name: 'Nguyễn Ánh',
61
+ pad: 'x'.repeat(4096)
62
+ });
63
+ await store.setItem(KEY, artifact);
64
+ (0, _testing.ensure)((await store.getItem(KEY)) === artifact, 'the artifact changed on the way back');
65
+ }
66
+ }];
67
+ const SIGN_IN = {
68
+ authority: 'https://login.example.com/tenant/v2.0',
69
+ clientId: 'conformance-client',
70
+ redirectUrl: 'com.example.app://auth',
71
+ scopes: ['openid', 'offline_access']
72
+ };
73
+ function codeOf(error) {
74
+ return error?.code;
75
+ }
76
+ const oidcAuthClientChecks = exports.oidcAuthClientChecks = [{
77
+ name: 'signs in with an access token, the id-token claims and a future expiry',
78
+ async run(harness) {
79
+ const subject = harness.create();
80
+ subject.issues({
81
+ oid: 'user-1',
82
+ name: 'Ada'
83
+ });
84
+ const before = Date.now();
85
+ const tokens = await subject.client.authorize(SIGN_IN);
86
+ (0, _testing.ensure)(typeof tokens.accessToken === 'string' && tokens.accessToken !== '', 'no access token');
87
+ (0, _testing.ensure)(tokens.claims.oid === 'user-1', `claims ${JSON.stringify(tokens.claims)}`);
88
+ (0, _testing.ensure)(tokens.accessTokenExpiresAt === undefined || tokens.accessTokenExpiresAt > before, 'the access token expires in the past');
89
+ }
90
+ }, {
91
+ name: 'refreshes with a refresh token',
92
+ async run(harness) {
93
+ const subject = harness.create();
94
+ subject.issues({
95
+ oid: 'user-1'
96
+ });
97
+ const tokens = await subject.client.refresh({
98
+ ...SIGN_IN,
99
+ refreshToken: 'refresh-1'
100
+ });
101
+ (0, _testing.ensure)(typeof tokens.accessToken === 'string' && tokens.accessToken !== '', 'no access token');
102
+ }
103
+ }, {
104
+ name: 'reports a closed sign-in sheet as provider-cancelled',
105
+ async run(harness) {
106
+ const subject = harness.create();
107
+ subject.userCancels();
108
+ let code;
109
+ try {
110
+ await subject.client.authorize(SIGN_IN);
111
+ } catch (error) {
112
+ code = codeOf(error);
113
+ }
114
+ (0, _testing.ensure)(code === 'provider-cancelled', `expected provider-cancelled, got ${String(code)}`);
115
+ }
116
+ }, {
117
+ name: 'reports a rejected refresh token as session-expired',
118
+ async run(harness) {
119
+ const subject = harness.create();
120
+ subject.rejectsRefresh();
121
+ let code;
122
+ try {
123
+ await subject.client.refresh({
124
+ ...SIGN_IN,
125
+ refreshToken: 'revoked'
126
+ });
127
+ } catch (error) {
128
+ code = codeOf(error);
129
+ }
130
+ (0, _testing.ensure)(code === 'session-expired', `expected session-expired, got ${String(code)}`);
131
+ }
132
+ }, {
133
+ name: 'ends the session',
134
+ async run(harness) {
135
+ const subject = harness.create();
136
+ await subject.client.endSession({
137
+ ...SIGN_IN,
138
+ idToken: undefined
139
+ });
140
+ }
141
+ }];
142
+ function runSecureTokenStoreConformance(harness) {
143
+ return (0, _testing.runChecks)(() => harness, secureTokenStoreChecks);
144
+ }
145
+ function runOidcAuthClientConformance(harness) {
146
+ return (0, _testing.runChecks)(() => harness, oidcAuthClientChecks);
147
+ }
148
+ //# sourceMappingURL=conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_testing","require","KEY","OTHER_KEY","secureTokenStoreChecks","exports","name","run","harness","value","create","getItem","ensure","JSON","stringify","store","setItem","removeItem","artifact","pad","repeat","SIGN_IN","authority","clientId","redirectUrl","scopes","codeOf","error","code","oidcAuthClientChecks","subject","issues","oid","before","Date","now","tokens","client","authorize","accessToken","claims","accessTokenExpiresAt","undefined","refresh","refreshToken","userCancels","String","rejectsRefresh","endSession","idToken","runSecureTokenStoreConformance","runChecks","runOidcAuthClientConformance"],"sourceRoot":"../../../src","sources":["testing/conformance.ts"],"mappings":";;;;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA8BA,MAAMC,GAAG,GAAG,oCAAoC;AAChD,MAAMC,SAAS,GAAG,0CAA0C;AAErD,MAAMC,sBAA4D,GAAAC,OAAA,CAAAD,sBAAA,GAAG,CAC3E;EACCE,IAAI,EAAE,uCAAuC;EAC7C,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAMC,KAAK,GAAG,MAAMD,OAAO,CAACE,MAAM,CAAC,CAAC,CAACC,OAAO,CAACT,GAAG,CAAC;IACjD,IAAAU,eAAM,EAACH,KAAK,KAAK,IAAI,EAAE,sBAAsBI,IAAI,CAACC,SAAS,CAACL,KAAK,CAAC,EAAE,CAAC;EACtE;AACD,CAAC,EACD;EACCH,IAAI,EAAE,mCAAmC;EACzC,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAMO,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,EAAE,qDAAqD;EAC3D,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAMsB,OAAO,GAAGtB,OAAO,CAACE,MAAM,CAAC,CAAC;IAChCoB,OAAO,CAACiB,cAAc,CAAC,CAAC;IACxB,IAAInB,IAAa;IACjB,IAAI;MACH,MAAME,OAAO,CAACO,MAAM,CAACM,OAAO,CAAC;QAAE,GAAGtB,OAAO;QAAEuB,YAAY,EAAE;MAAU,CAAC,CAAC;IACtE,CAAC,CAAC,OAAOjB,KAAK,EAAE;MACfC,IAAI,GAAGF,MAAM,CAACC,KAAK,CAAC;IACrB;IACA,IAAAf,eAAM,EAACgB,IAAI,KAAK,iBAAiB,EAAE,iCAAiCkB,MAAM,CAAClB,IAAI,CAAC,EAAE,CAAC;EACpF;AACD,CAAC,EACD;EACCtB,IAAI,EAAE,kBAAkB;EACxB,MAAMC,GAAGA,CAACC,OAAO,EAAE;IAClB,MAAMsB,OAAO,GAAGtB,OAAO,CAACE,MAAM,CAAC,CAAC;IAChC,MAAMoB,OAAO,CAACO,MAAM,CAACW,UAAU,CAAC;MAAE,GAAG3B,OAAO;MAAE4B,OAAO,EAAEP;IAAU,CAAC,CAAC;EACpE;AACD,CAAC,CACD;AAEM,SAASQ,8BAA8BA,CAC7C1C,OAA2B,EACE;EAC7B,OAAO,IAAA2C,kBAAS,EAAC,MAAM3C,OAAO,EAAEJ,sBAAsB,CAAC;AACxD;AAEO,SAASgD,4BAA4BA,CAAC5C,OAAoB,EAA8B;EAC9F,OAAO,IAAA2C,kBAAS,EAAC,MAAM3C,OAAO,EAAEqB,oBAAoB,CAAC;AACtD","ignoreList":[]}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createMemorySecureStore = createMemorySecureStore;
7
+ Object.defineProperty(exports, "oidcAuthClientChecks", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _conformance.oidcAuthClientChecks;
11
+ }
12
+ });
13
+ Object.defineProperty(exports, "runOidcAuthClientConformance", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _conformance.runOidcAuthClientConformance;
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "runSecureTokenStoreConformance", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _conformance.runSecureTokenStoreConformance;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "secureTokenStoreChecks", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _conformance.secureTokenStoreChecks;
29
+ }
30
+ });
31
+ var _conformance = require("./conformance.js");
32
+ /**
33
+ * `@chipmobilesdk/rn-auth/testing`: test doubles and the port conformance suites.
34
+ *
35
+ * A separate entrypoint so neither can reach a production bundle.
36
+ */
37
+
38
+ /** A `SecureTokenStore` held in memory, for tests and for the conformance suite. */
39
+ function createMemorySecureStore(seed = {}) {
40
+ const values = new Map(Object.entries(seed));
41
+ return {
42
+ async getItem(key) {
43
+ return values.get(key) ?? null;
44
+ },
45
+ async setItem(key, value) {
46
+ values.set(key, value);
47
+ },
48
+ async removeItem(key) {
49
+ values.delete(key);
50
+ }
51
+ };
52
+ }
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_conformance","require","createMemorySecureStore","seed","values","Map","Object","entries","getItem","key","get","setItem","value","set","removeItem","delete"],"sourceRoot":"../../../src","sources":["testing/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,IAAAA,YAAA,GAAAC,OAAA;AAvBA;AACA;AACA;AACA;AACA;;AAGA;AACO,SAASC,uBAAuBA,CAACC,IAA4B,GAAG,CAAC,CAAC,EAAoB;EAC5F,MAAMC,MAAM,GAAG,IAAIC,GAAG,CAAiBC,MAAM,CAACC,OAAO,CAACJ,IAAI,CAAC,CAAC;EAC5D,OAAO;IACN,MAAMK,OAAOA,CAACC,GAAG,EAAE;MAClB,OAAOL,MAAM,CAACM,GAAG,CAACD,GAAG,CAAC,IAAI,IAAI;IAC/B,CAAC;IACD,MAAME,OAAOA,CAACF,GAAG,EAAEG,KAAK,EAAE;MACzBR,MAAM,CAACS,GAAG,CAACJ,GAAG,EAAEG,KAAK,CAAC;IACvB,CAAC;IACD,MAAME,UAAUA,CAACL,GAAG,EAAE;MACrBL,MAAM,CAACW,MAAM,CAACN,GAAG,CAAC;IACnB;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createAccessTokenManager = createAccessTokenManager;
7
+ var _errors = require("../diagnostics/errors.js");
8
+ /**
9
+ * Per-resource delegated access-token acquisition with an in-memory cache and
10
+ * silent refresh (FR-007, PERF-003, R4). Access tokens are never persisted to
11
+ * disk (FR-021) — only kept in memory keyed by resource until expiry.
12
+ */
13
+
14
+ const EXPIRY_SKEW_MS = 60_000;
15
+ const SESSION_ENDED = {
16
+ status: 'unavailable',
17
+ errorCode: 'session-expired'
18
+ };
19
+ function createAccessTokenManager(deps) {
20
+ const cache = new Map();
21
+ /**
22
+ * Refreshes in progress, by resource. Concurrent callers for one resource
23
+ * share a single network call; with a rotating refresh token, a second call
24
+ * would race the first with a token the first may have just retired.
25
+ */
26
+ const inFlight = new Map();
27
+ const fresh = resourceKey => {
28
+ const cached = cache.get(resourceKey);
29
+ return cached && cached.expiresAt - EXPIRY_SKEW_MS > Date.now() ? cached : undefined;
30
+ };
31
+ const refresh = async resource => {
32
+ const resourceKey = resource.key;
33
+ const epoch = deps.sessionEpoch();
34
+ const refreshToken = deps.getRefreshToken();
35
+ if (!refreshToken) {
36
+ return {
37
+ resourceKey,
38
+ ...SESSION_ENDED
39
+ };
40
+ }
41
+ try {
42
+ const tokens = await deps.authClient.refresh({
43
+ authority: deps.authority,
44
+ clientId: deps.clientId,
45
+ redirectUrl: deps.redirectUrl,
46
+ refreshToken,
47
+ scopes: resource.scopes
48
+ });
49
+ // Signed out, or signed in as someone else, while this was in flight:
50
+ // nothing from it may be written back, and its token is not handed out.
51
+ if (deps.sessionEpoch() !== epoch) {
52
+ return {
53
+ resourceKey,
54
+ ...SESSION_ENDED
55
+ };
56
+ }
57
+ if (tokens.refreshToken && tokens.refreshToken !== refreshToken) {
58
+ await deps.onRefreshTokenRotated(tokens.refreshToken, epoch);
59
+ if (deps.sessionEpoch() !== epoch) {
60
+ return {
61
+ resourceKey,
62
+ ...SESSION_ENDED
63
+ };
64
+ }
65
+ }
66
+ if (!tokens.accessToken) {
67
+ return {
68
+ resourceKey,
69
+ status: 'error',
70
+ errorCode: 'token-acquisition-failed'
71
+ };
72
+ }
73
+ const expiresAt = tokens.accessTokenExpiresAt ?? Date.now() + 3_600_000;
74
+ cache.set(resourceKey, {
75
+ token: tokens.accessToken,
76
+ expiresAt
77
+ });
78
+ return {
79
+ resourceKey,
80
+ status: 'success',
81
+ token: tokens.accessToken,
82
+ expiresAt
83
+ };
84
+ } catch (error) {
85
+ if ((0, _errors.isAuthError)(error)) {
86
+ if (error.code === 'consent-denied') {
87
+ return {
88
+ resourceKey,
89
+ status: 'denied',
90
+ errorCode: error.code
91
+ };
92
+ }
93
+ if (error.code === 'network-unavailable') {
94
+ return {
95
+ resourceKey,
96
+ status: 'unavailable',
97
+ errorCode: error.code
98
+ };
99
+ }
100
+ if (error.code === 'session-expired') {
101
+ return {
102
+ resourceKey,
103
+ status: 'unavailable',
104
+ errorCode: error.code
105
+ };
106
+ }
107
+ return {
108
+ resourceKey,
109
+ status: 'error',
110
+ errorCode: error.code
111
+ };
112
+ }
113
+ return {
114
+ resourceKey,
115
+ status: 'error',
116
+ errorCode: 'token-acquisition-failed'
117
+ };
118
+ }
119
+ };
120
+ return {
121
+ clear() {
122
+ cache.clear();
123
+ inFlight.clear();
124
+ },
125
+ hasFreshToken(resourceKey) {
126
+ return fresh(resourceKey) !== undefined;
127
+ },
128
+ request(resourceKey, options = {}) {
129
+ const resource = deps.resources.find(entry => entry.key === resourceKey);
130
+ if (!resource) {
131
+ return Promise.resolve({
132
+ resourceKey,
133
+ status: 'error',
134
+ errorCode: 'configuration-error'
135
+ });
136
+ }
137
+ if (options.forceRefresh === true) {
138
+ // Dropped, not just skipped: the token is known bad, so no later
139
+ // caller should be handed it either.
140
+ cache.delete(resourceKey);
141
+ }
142
+ const cached = options.forceRefresh === true ? undefined : fresh(resourceKey);
143
+ if (cached) {
144
+ return Promise.resolve({
145
+ resourceKey,
146
+ status: 'success',
147
+ token: cached.token,
148
+ expiresAt: cached.expiresAt
149
+ });
150
+ }
151
+ const running = inFlight.get(resourceKey);
152
+ if (running) {
153
+ return running;
154
+ }
155
+ const flight = refresh(resource).finally(() => {
156
+ if (inFlight.get(resourceKey) === flight) {
157
+ inFlight.delete(resourceKey);
158
+ }
159
+ });
160
+ inFlight.set(resourceKey, flight);
161
+ return flight;
162
+ }
163
+ };
164
+ }
165
+ //# sourceMappingURL=accessToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_errors","require","EXPIRY_SKEW_MS","SESSION_ENDED","status","errorCode","createAccessTokenManager","deps","cache","Map","inFlight","fresh","resourceKey","cached","get","expiresAt","Date","now","undefined","refresh","resource","key","epoch","sessionEpoch","refreshToken","getRefreshToken","tokens","authClient","authority","clientId","redirectUrl","scopes","onRefreshTokenRotated","accessToken","accessTokenExpiresAt","set","token","error","isAuthError","code","clear","hasFreshToken","request","options","resources","find","entry","Promise","resolve","forceRefresh","delete","running","flight","finally"],"sourceRoot":"../../../src","sources":["tokens/accessToken.ts"],"mappings":";;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AARA;AACA;AACA;AACA;AACA;;AAMA,MAAMC,cAAc,GAAG,MAAM;AA8C7B,MAAMC,aAAqD,GAAG;EAC7DC,MAAM,EAAE,aAAa;EACrBC,SAAS,EAAE;AACZ,CAAC;AAEM,SAASC,wBAAwBA,CAACC,IAA4B,EAAsB;EAC1F,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAsB,CAAC;EAC5C;AACD;AACA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AAG,CAACF,WAAW,CAAC,KAAKwC,MAAM,EAAE;UACzC1C,QAAQ,CAACwC,MAAM,CAACtC,WAAW,CAAC;QAC7B;MACD,CAAC,CAAC;MACFF,QAAQ,CAACyB,GAAG,CAACvB,WAAW,EAAEwC,MAAM,CAAC;MACjC,OAAOA,MAAM;IACd;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AUTH_STORAGE_KEY = void 0;
7
+ exports.createKeychainSecureStore = createKeychainSecureStore;
8
+ var _rnCore = require("@chipmobilesdk/rn-core");
9
+ var _errors = require("../diagnostics/errors.js");
10
+ /**
11
+ * SecureTokenStore port + default react-native-keychain adapter (FR-021, R2).
12
+ *
13
+ * Refresh tokens and the session-restore artifact persist ONLY through this
14
+ * port, backed by platform secure storage (iOS Keychain / Android Keystore).
15
+ * Access tokens are never written here — they stay in memory (see accessToken).
16
+ * The default adapter loads the native module on its first read or write, so
17
+ * creating it, and unit tests that inject a fake, load no native code.
18
+ */
19
+
20
+ /** Single key under which the persisted session artifact is stored. */
21
+ const AUTH_STORAGE_KEY = exports.AUTH_STORAGE_KEY = '@chipmobilesdk/rn-auth/session';
22
+ /**
23
+ * Default secure store backed by react-native-keychain. Each logical key maps to
24
+ * a Keychain "service" so multiple keys can coexist. Validated on device.
25
+ */
26
+ function createKeychainSecureStore(options = {}) {
27
+ // The native module loads on the first read or write, never at startup (PERF-05).
28
+ const accessible = () => options.accessible ?? keychain().ACCESSIBLE?.WHEN_UNLOCKED_THIS_DEVICE_ONLY;
29
+ return {
30
+ async getItem(key) {
31
+ const result = await keychain().getGenericPassword({
32
+ service: key
33
+ });
34
+ return result ? result.password : null;
35
+ },
36
+ async setItem(key, value) {
37
+ await keychain().setGenericPassword('token', value, {
38
+ service: key,
39
+ accessible: accessible()
40
+ });
41
+ },
42
+ async removeItem(key) {
43
+ await keychain().resetGenericPassword({
44
+ service: key
45
+ });
46
+ }
47
+ };
48
+ }
49
+ const keychainPeer = (0, _rnCore.lazyPeer)('react-native-keychain', () => {
50
+ // Inside `try`, so Metro bundles an app that leaves this optional peer out.
51
+ try {
52
+ return require('react-native-keychain');
53
+ } catch (cause) {
54
+ throw cause;
55
+ }
56
+ });
57
+ function keychain() {
58
+ return keychainPeer.require(peer => new _errors.AuthConfigError('auth.error.configuration', `${peer} is not installed or its native module is not linked`));
59
+ }
60
+ //# sourceMappingURL=secureStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_rnCore","require","_errors","AUTH_STORAGE_KEY","exports","createKeychainSecureStore","options","accessible","keychain","ACCESSIBLE","WHEN_UNLOCKED_THIS_DEVICE_ONLY","getItem","key","result","getGenericPassword","service","password","setItem","value","setGenericPassword","removeItem","resetGenericPassword","keychainPeer","lazyPeer","cause","peer","AuthConfigError"],"sourceRoot":"../../../src","sources":["tokens/secureStore.ts"],"mappings":";;;;;;;AAUA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACO,MAAME,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,gCAAgC;AAahE;AACA;AACA;AACA;AACO,SAASE,yBAAyBA,CACxCC,OAAmC,GAAG,CAAC,CAAC,EACrB;EACnB;EACA,MAAMC,UAAU,GAAGA,CAAA,KAClBD,OAAO,CAACC,UAAU,IAAIC,QAAQ,CAAC,CAAC,CAACC,UAAU,EAAEC,8BAA8B;EAE5E,OAAO;IACN,MAAMC,OAAOA,CAACC,GAAG,EAAE;MAClB,MAAMC,MAAM,GAAG,MAAML,QAAQ,CAAC,CAAC,CAACM,kBAAkB,CAAC;QAAEC,OAAO,EAAEH;MAAI,CAAC,CAAC;MACpE,OAAOC,MAAM,GAAGA,MAAM,CAACG,QAAQ,GAAG,IAAI;IACvC,CAAC;IACD,MAAMC,OAAOA,CAACL,GA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