@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,74 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Developer-facing diagnostics. AuthError carries a stable machine-readable
5
+ * code, an audience (user vs developer/tenant), and a localizable message key.
6
+ * `detail` is always passed through `redact` so tokens and secrets never appear
7
+ * in logs or error objects (FR-014).
8
+ */
9
+
10
+ import { COMMON_PATTERNS, SdkError, redactPatterns } from '@chipmobilesdk/rn-core';
11
+ /** JWT-shaped values: three base64url segments separated by dots. */
12
+ const JWT_PATTERN = /[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g;
13
+ /** Any other long opaque token-like run; shorter than rn-core's payload run on purpose. */
14
+ const TOKEN_PATTERN = /[A-Za-z0-9_-]{24,}/g;
15
+
16
+ /**
17
+ * Replace token-like substrings with a placeholder so diagnostics never leak
18
+ * secrets or token values (FR-014): JWTs become `[redacted-token]`; URLs, e-mail
19
+ * addresses, UUIDs and other opaque runs become `[redacted]` (rn-core's patterns).
20
+ */
21
+ export function redact(value) {
22
+ if (!value) {
23
+ return value;
24
+ }
25
+ return redactPatterns(value.replace(JWT_PATTERN, '[redacted-token]'), [...COMMON_PATTERNS, TOKEN_PATTERN]);
26
+ }
27
+
28
+ /** Retrying can only help when the network was the problem. */
29
+ const RETRYABLE = new Set(['network-unavailable']);
30
+
31
+ /** The package's error; an `SdkError` (`@chipmobilesdk/rn-core`) with `pkg: 'rn-auth'`. */
32
+ export class AuthError extends SdkError {
33
+ constructor(args) {
34
+ const detail = redact(args.detail);
35
+ super('rn-auth', args.code, {
36
+ message: args.messageKey,
37
+ retryable: RETRYABLE.has(args.code),
38
+ redactedCause: detail
39
+ });
40
+ this.name = 'AuthError';
41
+ this.audience = args.audience ?? 'developer';
42
+ this.messageKey = args.messageKey;
43
+ this.detail = detail;
44
+ }
45
+ }
46
+ export class AuthConfigError extends AuthError {
47
+ constructor(messageKey, detail) {
48
+ super({
49
+ code: 'configuration-error',
50
+ messageKey,
51
+ audience: 'developer',
52
+ detail
53
+ });
54
+ this.name = 'AuthConfigError';
55
+ }
56
+ }
57
+ export function isAuthError(value) {
58
+ return value instanceof AuthError;
59
+ }
60
+
61
+ /** Normalize any thrown value into an AuthError without leaking secrets. */
62
+ export function toAuthError(value, fallbackCode = 'token-acquisition-failed', fallbackMessageKey = 'auth.error.token') {
63
+ if (isAuthError(value)) {
64
+ return value;
65
+ }
66
+ const message = value instanceof Error ? value.message : String(value);
67
+ return new AuthError({
68
+ code: fallbackCode,
69
+ messageKey: fallbackMessageKey,
70
+ audience: 'developer',
71
+ detail: message
72
+ });
73
+ }
74
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["COMMON_PATTERNS","SdkError","redactPatterns","JWT_PATTERN","TOKEN_PATTERN","redact","value","replace","RETRYABLE","Set","AuthError","constructor","args","detail","code","message","messageKey","retryable","has","redactedCause","name","audience","AuthConfigError","isAuthError","toAuthError","fallbackCode","fallbackMessageKey","Error","String"],"sourceRoot":"../../../src","sources":["diagnostics/errors.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,EAAEC,QAAQ,EAAEC,cAAc,QAAQ,wBAAwB;AAuBlF;AACA,MAAMC,WAAW,GAAG,0DAA0D;AAC9E;AACA,MAAMC,aAAa,GAAG,qBAAqB;;AAE3C;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,MAAMA,CAACC,KAAyB,EAAsB;EACrE,IAAI,CAACA,KAAK,EAAE;IACX,OAAOA,KAAK;EACb;EACA,OAAOJ,cAAc,CAACI,KAA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OAAOA,KAAK;EACb;EACA,MAAMS,OAAO,GAAGT,KAAK,YAAYqB,KAAK,GAAGrB,KAAK,CAACS,OAAO,GAAGa,MAAM,CAACtB,KAAK,CAAC;EACtE,OAAO,IAAII,SAAS,CAAC;IACpBI,IAAI,EAAEW,YAAY;IAClBT,UAAU,EAAEU,kBAAkB;IAC9BL,QAAQ,EAAE,WAAW;IACrBR,MAAM,EAAEE;EACT,CAAC,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Stable, localizable message keys with English default copy (UX-006 / LIB-011).
5
+ * The library takes no i18n runtime dependency: consuming apps map these keys to
6
+ * localized strings via their own i18n system. User-actionable copy and
7
+ * developer/tenant-configuration copy are kept separate (UX-005).
8
+ */
9
+
10
+ import { defineMessages } from '@chipmobilesdk/rn-core';
11
+ /**
12
+ * The catalog, as an rn-core message set: `user` copy may reach an end user,
13
+ * `developer` copy describes a tenant or configuration fault (UX-005). Register
14
+ * `authMessages.user` with rn-i18n to translate it like app copy.
15
+ */
16
+ export const authMessages = defineMessages({
17
+ user: {
18
+ 'auth.action.continueGoogle': 'Continue with Google',
19
+ 'auth.action.continueApple': 'Continue with Apple',
20
+ 'auth.action.continueFacebook': 'Continue with Facebook',
21
+ 'auth.state.signedOut': 'Sign in to continue',
22
+ 'auth.state.authenticating': 'Signing you in…',
23
+ 'auth.state.signedIn': 'You are signed in',
24
+ 'auth.state.signingOut': 'Signing out…',
25
+ 'auth.tier.free': 'Free',
26
+ 'auth.tier.premium': 'Premium',
27
+ 'auth.tier.unverified': 'Membership could not be verified',
28
+ 'auth.error.cancelled': 'Sign-in was cancelled. You can try again.',
29
+ 'auth.error.sessionExpired': 'Your session expired. Please sign in again.',
30
+ 'auth.error.entitlement': 'This feature requires a verified premium membership.',
31
+ 'auth.error.network': 'No connection. Some features are limited until you reconnect.'
32
+ },
33
+ developer: {
34
+ 'auth.error.configuration': 'Authentication is not configured correctly.',
35
+ 'auth.error.redirectMismatch': 'The sign-in redirect does not match the app configuration.',
36
+ 'auth.error.token': 'We could not complete the request. Please try again.',
37
+ 'auth.error.consentDenied': 'Access to this resource was denied.'
38
+ }
39
+ });
40
+ export const DEFAULT_MESSAGES = authMessages.defaults;
41
+
42
+ /** Resolve a message, preferring app overrides over the English defaults. */
43
+ export function resolveMessages(overrides) {
44
+ return authMessages.resolve(overrides);
45
+ }
46
+ //# sourceMappingURL=messageKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["defineMessages","authMessages","user","developer","DEFAULT_MESSAGES","defaults","resolveMessages","overrides","resolve"],"sourceRoot":"../../../src","sources":["diagnostics/messageKeys.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,wBAAwB;AA6BvD;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,YAAY,GAAGD,cAAc,CAAC;EAC1CE,IAAI,EAAE;IACL,4BAA4B,EAAE,sBAAsB;IACpD,2BAA2B,EAAE,qBAAqB;IAClD,8BAA8B,EAAE,wBAAwB;IACxD,sBAAsB,EAAE,qBAAqB;IAC7C,2BAA2B,EAAE,iBAAiB;IAC9C,qBAAqB,EAAE,mBAAmB;IAC1C,uBAAuB,EAAE,cAAc;IACvC,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,SAAS;IAC9B,sBAAsB,EAAE,kCAAkC;IAC1D,sBAAsB,EAAE,2CAA2C;IACnE,2BAA2B,EAAE,6CAA6C;IAC1E,wBAAwB,EAAE,sDAAsD;IAChF,oBAAoB,EAAE;EACvB,CAAC;EACDC,SAAS,EAAE;IACV,0BAA0B,EAAE,6CAA6C;IACzE,6BAA6B,EAAE,4DAA4D;IAC3F,kBAAkB,EAAE,sDAAsD;IAC1E,0BAA0B,EAAE;EAC7B;AACD,CAAC,CAAC;AAEF,OAAO,MAAMC,gBAAgC,GAAGH,YAAY,CAACI,QAAQ;;AAErE;AACA,OAAO,SAASC,eAAeA,CAACC,SAAmC,EAAkB;EACpF,OAAON,YAAY,CAACO,OAAO,CAACD,SAAS,CAAC;AACvC","ignoreList":[]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * @chipmobilesdk/rn-auth — reusable Microsoft Entra External ID authentication
5
+ * for ChipMobileSdk-family React Native apps (public OIDC/PKCE client, no
6
+ * backend). This is the single public entrypoint (LIB-003); modules under
7
+ * `core/`, `tokens/`, `oidc/`, `access/`, and `diagnostics/` are private.
8
+ */
9
+
10
+ import { createAuthMachine } from "./core/authMachine.js";
11
+ /** Create the auth controller. Throws AuthConfigError on invalid config (FR-005). */
12
+ export function createAuth(config, options) {
13
+ return createAuthMachine(config, options);
14
+ }
15
+
16
+ // Public types
17
+
18
+ // Ports + default adapters
19
+ export { describeProviderIdentity, mapClaimsToProfile } from "./core/profile.js";
20
+ export { createKeychainSecureStore, AUTH_STORAGE_KEY } from "./tokens/secureStore.js";
21
+ export { createAppAuthClient } from "./oidc/authClient.js";
22
+
23
+ // Access-tier evaluation (also exported for app-side reuse/testing)
24
+ export { evaluateAccessTier, failClosedTier } from "./access/accessTier.js";
25
+
26
+ // Diagnostics
27
+ export { AuthError, AuthConfigError, isAuthError, redact } from "./diagnostics/errors.js";
28
+ export { DEFAULT_MESSAGES, authMessages, resolveMessages } from "./diagnostics/messageKeys.js";
29
+ // React bindings
30
+ export { AuthProvider } from "./react/AuthProvider.js";
31
+ export { useAuthSelector } from "./react/hooks.js";
32
+ export { useAuth, useAuthMessages, useProfile, useAccessTier, useAccessToken, useSignInProvider, useSignInProviders } from "./react/hooks.js";
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createAuthMachine","createAuth","config","options","describeProviderIdentity","mapClaimsToProfile","createKeychainSecureStore","AUTH_STORAGE_KEY","createAppAuthClient","evaluateAccessTier","failClosedTier","AuthError","AuthConfigError","isAuthError","redact","DEFAULT_MESSAGES","authMessages","resolveMessages","AuthProvider","useAuthSelector","useAuth","useAuthMessages","useProfile","useAccessTier","useAccessToken","useSignInProvider","useSignInProviders"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB,QAAQ,uBAAoB;AAGtD;AACA,OAAO,SAASC,UAAUA,CAACC,MAAkB,EAAEC,OAA2B,EAAQ;EACjF,OAAOH,iBAAiB,CAACE,MAAM,EAAEC,OAAO,CAAC;AAC1C;;AAEA;;AAwBA;AACA,SAASC,wBAAwB,EAAEC,kBAAkB,QAAQ,mBAAgB;AAI7E,SAASC,yBAAyB,EAAEC,gBAAgB,QAAQ,yBAAsB;AAUlF,SAASC,mBAAmB,QAAQ,sBAAmB;;AAEvD;AACA,SAASC,kBAAkB,EAAEC,cAAc,QAAQ,wBAAqB;;AAExE;AACA,SAASC,SAAS,EAAEC,eAAe,EAAEC,WAAW,EAAEC,MAAM,QAAQ,yBAAsB;AAEtF,SAASC,gBAAgB,EAAEC,YAAY,EAAEC,eAAe,QAAQ,8BAA2B;AAG3F;AACA,SAASC,YAAY,QAAQ,yBAAsB;AACnD,SAASC,eAAe,QAAQ,kBAAe;AAE/C,SACCC,OAAO,EACPC,eAAe,EACfC,UAAU,EACVC,aAAa,EACbC,cAAc,EACdC,iBAAiB,EACjBC,kBAAkB,QACZ,kBAAe","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * `@chipmobilesdk/rn-auth/keychain`: the default secure token store over
5
+ * react-native-keychain (AUTH-09). Its own entrypoint, so an app with its own
6
+ * secure storage never reaches this module.
7
+ */
8
+ export { createKeychainSecureStore } from "./tokens/secureStore.js";
9
+ //# sourceMappingURL=keychain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createKeychainSecureStore"],"sourceRoot":"../../src","sources":["keychain.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA,SAASA,yBAAyB,QAAyC,yBAAsB","ignoreList":[]}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * OidcAuthClient port + default react-native-app-auth adapter (R1).
5
+ *
6
+ * The port abstracts the Authorization Code + PKCE public-client flow so the
7
+ * auth engine is testable without native code. The default adapter lazily
8
+ * requires react-native-app-auth and is validated on device.
9
+ */
10
+
11
+ import { lazyPeer } from '@chipmobilesdk/rn-core';
12
+ import { AuthConfigError } from "../diagnostics/errors.js";
13
+ import { classifyAppAuthError } from "./classifyError.js";
14
+ /** Decode the payload segment of a JWT without any dependency (device-safe). */
15
+ export function decodeJwtClaims(jwt) {
16
+ if (typeof jwt !== 'string') {
17
+ return {};
18
+ }
19
+ const [, payload] = jwt.split('.');
20
+ if (payload === undefined) {
21
+ return {};
22
+ }
23
+ try {
24
+ const json = base64UrlDecode(payload);
25
+ return JSON.parse(json);
26
+ } catch {
27
+ return {};
28
+ }
29
+ }
30
+ const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
31
+ function base64UrlDecode(input) {
32
+ let base64 = input.replace(/-/g, '+').replace(/_/g, '/');
33
+ while (base64.length % 4 !== 0) {
34
+ base64 += '=';
35
+ }
36
+ let bytes = '';
37
+ let buffer = 0;
38
+ let bits = 0;
39
+ for (const char of base64) {
40
+ if (char === '=') {
41
+ break;
42
+ }
43
+ const index = BASE64_CHARS.indexOf(char);
44
+ if (index === -1) {
45
+ continue;
46
+ }
47
+ // Standard base64 bit assembly; bitwise ops are intentional here.
48
+ // eslint-disable-next-line no-bitwise
49
+ buffer = buffer << 6 | index;
50
+ bits += 6;
51
+ if (bits >= 8) {
52
+ bits -= 8;
53
+ // eslint-disable-next-line no-bitwise
54
+ bytes += String.fromCharCode(buffer >> bits & 0xff);
55
+ }
56
+ }
57
+ // Interpret the byte string (each char is a 0–255 byte) as UTF-8 without
58
+ // relying on the deprecated global `escape`.
59
+ try {
60
+ const percentEncoded = Array.from(bytes).map(char => '%' + char.charCodeAt(0).toString(16).padStart(2, '0')).join('');
61
+ return decodeURIComponent(percentEncoded);
62
+ } catch {
63
+ return bytes;
64
+ }
65
+ }
66
+
67
+ /** The endpoints discovery would have returned, when an app already knows them. */
68
+
69
+ /**
70
+ * Loaded on the first sign-in, refresh or sign-out, never at startup (PERF-05):
71
+ * creating the client, or the whole auth instance, loads no native code.
72
+ */
73
+ const appAuthPeer = lazyPeer('react-native-app-auth', () => {
74
+ // Inside `try`, so Metro bundles an app that leaves this optional peer out.
75
+ try {
76
+ return require('react-native-app-auth');
77
+ } catch (cause) {
78
+ throw cause;
79
+ }
80
+ });
81
+ function appAuth() {
82
+ return appAuthPeer.require(peer => new AuthConfigError('auth.error.configuration', `${peer} is not installed or its native module is not linked`));
83
+ }
84
+
85
+ /** The module's calls, resolved only when one is made. */
86
+ const AppAuth = {
87
+ authorize: config => appAuth().authorize(config),
88
+ refresh: (config, params) => appAuth().refresh(config, params),
89
+ logout: (config, params) => appAuth().logout(config, params)
90
+ };
91
+
92
+ /**
93
+ * Default OidcAuthClient adapter wrapping react-native-app-auth (PKCE public
94
+ * client). Validated on device (R8).
95
+ */
96
+ export function createAppAuthClient(options = {}) {
97
+ const serviceConfiguration = options.serviceConfiguration;
98
+ // Discovery is pointless once the endpoints are given, whatever was asked for.
99
+ const useDiscovery = serviceConfiguration ? false : options.useDiscovery ?? true;
100
+ const baseConfig = (authority, clientId, redirectUrl, scopes) => ({
101
+ issuer: useDiscovery ? authority : undefined,
102
+ ...(serviceConfiguration ? {
103
+ serviceConfiguration
104
+ } : {}),
105
+ clientId,
106
+ redirectUrl,
107
+ scopes
108
+ });
109
+ const toTokens = result => ({
110
+ accessToken: result.accessToken,
111
+ // Absent stays absent: an empty string was indistinguishable from a real
112
+ // token by type, and silently disabled session persistence.
113
+ refreshToken: result.refreshToken || undefined,
114
+ idToken: result.idToken || undefined,
115
+ claims: decodeJwtClaims(result.idToken),
116
+ accessTokenExpiresAt: result.accessTokenExpirationDate ? new Date(result.accessTokenExpirationDate).getTime() : undefined
117
+ });
118
+ return {
119
+ async authorize(params) {
120
+ try {
121
+ const result = await AppAuth.authorize({
122
+ ...baseConfig(params.authority, params.clientId, params.redirectUrl, params.scopes),
123
+ additionalParameters: params.additionalParameters
124
+ });
125
+ return toTokens(result);
126
+ } catch (error) {
127
+ throw classifyAppAuthError(error);
128
+ }
129
+ },
130
+ async refresh(params) {
131
+ try {
132
+ const result = await AppAuth.refresh(baseConfig(params.authority, params.clientId, params.redirectUrl, params.scopes), {
133
+ refreshToken: params.refreshToken
134
+ });
135
+ return toTokens(result);
136
+ } catch (error) {
137
+ throw classifyAppAuthError(error);
138
+ }
139
+ },
140
+ async endSession(params) {
141
+ try {
142
+ await AppAuth.logout(baseConfig(params.authority, params.clientId, params.redirectUrl, []), {
143
+ idToken: params.idToken ?? '',
144
+ postLogoutRedirectUrl: params.redirectUrl
145
+ });
146
+ } catch (error) {
147
+ throw classifyAppAuthError(error);
148
+ }
149
+ }
150
+ };
151
+ }
152
+ //# sourceMappingURL=authClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["lazyPeer","AuthConfigError","classifyAppAuthError","decodeJwtClaims","jwt","payload","split","undefined","json","base64UrlDecode","JSON","parse","BASE64_CHARS","input","base64","replace","length","bytes","buffer","bits","char","index","indexOf","String","fromCharCode","percentEncoded","Array","from","map","charCodeAt","toString","padStart","join","decodeURIComponent","appAuthPeer","require","cause","appAuth","peer","AppAuth","authorize","config","refresh","params","logout","createAppAuthClient","options","serviceConfiguration","useDiscovery","baseConfig","authority","clientId","redirectUrl","scopes","issuer","toTokens","result","accessToken","refreshToken","idToken","claims","accessTokenExpiresAt","accessTokenExpirationDate","Date","getTime","additionalParameters","error","endSession","postLogoutRedirectUrl"],"sourceRoot":"../../../src","sources":["oidc/authClient.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,QAAQ,wBAAwB;AAEjD,SAASC,eAAe,QAAQ,0BAAuB;AAEvD,SAASC,oBAAoB,Q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AC;IACD,MAAMxB,OAAOA,CAACC,MAAM,EAAE;MACrB,IAAI;QACH,MAAMa,MAAM,GAAG,MAAMjB,OAAO,CAACG,OAAO,CACnCO,UAAU,CAACN,MAAM,CAACO,SAAS,EAAEP,MAAM,CAACQ,QAAQ,EAAER,MAAM,CAACS,WAAW,EAAET,MAAM,CAACU,MAAM,CAAC,EAChF;UAAEK,YAAY,EAAEf,MAAM,CAACe;QAAa,CACrC,CAAC;QACD,OAAOH,QAAQ,CAACC,MAAM,CAAC;MACxB,CAAC,CAAC,OAAOU,KAAK,EAAE;QACf,MAAMhE,oBAAoB,CAACgE,KAAK,CAAC;MAClC;IACD,CAAC;IACD,MAAMC,UAAUA,CAACxB,MAAM,EAAE;MACxB,IAAI;QACH,MAAMJ,OAAO,CAACK,MAAM,CACnBK,UAAU,CAACN,MAAM,CAACO,SAAS,EAAEP,MAAM,CAACQ,QAAQ,EAAER,MAAM,CAACS,WAAW,EAAE,EAAE,CAAC,EACrE;UACCO,OAAO,EAAEhB,MAAM,CAACgB,OAAO,IAAI,EAAE;UAC7BS,qBAAqB,EAAEzB,MAAM,CAACS;QAC/B,CACD,CAAC;MACF,CAAC,CAAC,OAAOc,KAAK,EAAE;QACf,MAAMhE,oBAAoB,CAACgE,KAAK,CAAC;MAClC;IACD;EACD,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Classifies a native OIDC error into an `AuthErrorCode`.
5
+ *
6
+ * The rules are an ordered table rather than a chain of substring checks, so a
7
+ * platform adapter (the iOS one, later) adds its own rows without touching the
8
+ * engine. Order matters: the first matching rule wins.
9
+ *
10
+ * The default is deliberately not "session expired". Restore clears the stored
11
+ * session only on `session-expired`, so anything this table cannot name — a
12
+ * timeout, a 5xx, a discovery failure, a localized message — must keep the
13
+ * session rather than sign the user out.
14
+ */
15
+
16
+ import { AuthError } from "../diagnostics/errors.js";
17
+ /**
18
+ * OAuth error codes (RFC 6749 §5.2, OIDC Core §3.1.2.6) and the Entra ID AADSTS
19
+ * codes that mean the same thing, plus the transport failures app-auth reports.
20
+ */
21
+ export const DEFAULT_CLASSIFICATION_RULES = [{
22
+ code: 'provider-cancelled',
23
+ messageKey: 'auth.error.cancelled',
24
+ pattern: /cancel|user_cancel|authorization flow (was )?dismissed/i
25
+ }, {
26
+ code: 'session-expired',
27
+ messageKey: 'auth.error.sessionExpired',
28
+ // invalid_grant is the refresh-token verdict; the AADSTS codes are Entra's
29
+ // expired, revoked, or inactive refresh token and password-changed cases.
30
+ pattern: /\binvalid_grant\b|\binteraction_required\b|\blogin_required\b|AADSTS(700082|700084|50173|70043)\b/i
31
+ }, {
32
+ code: 'redirect-mismatch',
33
+ messageKey: 'auth.error.redirectMismatch',
34
+ pattern: /redirect_uri|redirect uri|redirect_mismatch|AADSTS50011\b/i
35
+ }, {
36
+ code: 'consent-denied',
37
+ messageKey: 'auth.error.consentDenied',
38
+ pattern: /\baccess_denied\b|\bconsent_required\b|AADSTS65001\b/i
39
+ }, {
40
+ code: 'network-unavailable',
41
+ messageKey: 'auth.error.network',
42
+ pattern: /network|connection|offline|timed? ?out|unable to resolve host|unreachable|\bserver_error\b|\btemporarily_unavailable\b|\b5\d\d\b/i
43
+ }];
44
+
45
+ /** Maps a native app-auth error to a classified AuthError without leaking tokens. */
46
+ export function classifyAppAuthError(error, rules = DEFAULT_CLASSIFICATION_RULES) {
47
+ const message = error instanceof Error ? error.message : String(error);
48
+ const nativeCode = error?.code;
49
+ const haystack = `${typeof nativeCode === 'string' ? nativeCode : ''} ${message}`;
50
+ const rule = rules.find(candidate => candidate.pattern.test(haystack));
51
+ const code = rule?.code ?? 'token-acquisition-failed';
52
+ return new AuthError({
53
+ code,
54
+ messageKey: rule?.messageKey ?? 'auth.error.token',
55
+ audience: code === 'redirect-mismatch' ? 'developer' : 'user',
56
+ // AuthError redacts `detail`, so token-shaped values never survive.
57
+ detail: message
58
+ });
59
+ }
60
+ //# sourceMappingURL=classifyError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AuthError","DEFAULT_CLASSIFICATION_RULES","code","messageKey","pattern","classifyAppAuthError","error","rules","message","Error","String","nativeCode","haystack","rule","find","candidate","test","audience","detail"],"sourceRoot":"../../../src","sources":["oidc/classifyError.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,SAAS,QAA4B,0BAAuB;AAUrE;AACA;AACA;AACA;AACA,OAAO,MAAMC,4BAA2D,GAAG,CAC1E;EACCC,IAAI,EAAE,oBAAoB;EAC1BC,UAAU,EAAE,sBAAsB;EAClCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,iBAAiB;EACvBC,UAAU,EAAE,2BAA2B;EACvC;EACA;EACAC,OAAO,EACN;AACF,CAAC,EACD;EACCF,IAAI,EAAE,mBAAmB;EACzBC,UAAU,EAAE,6BAA6B;EACzCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,gBAAgB;EACtBC,UAAU,EAAE,0BAA0B;EACtCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,qBAAqB;EAC3BC,UAAU,EAAE,oBAAoB;EAChCC,OAAO,EACN;AACF,CAAC,CACD;;AAED;AACA,OAAO,SAASC,oBAAoBA,CACnCC,KAAc,EACdC,KAAoC,GAAGN,4BAA4B,EACvD;EACZ,MAAMO,OAAO,GAAGF,KAAK,YAAYG,KAAK,GAAGH,KAAK,CAACE,OAAO,GAAGE,MAAM,CAACJ,KAAK,CAAC;EACtE,MAAMK,UAAU,GAAIL,KAAK,EAAqCJ,IAAI;EAClE,MAAMU,QAAQ,GAAG,GAAG,OAAOD,UAAU,KAAK,QAAQ,GAAGA,UAAU,GAAG,EAAE,IAAIH,OAAO,EAAE;EACjF,MAAMK,IAAI,GAAGN,KAAK,CAACO,IAAI,CAACC,SAAS,IAAIA,SAAS,CAACX,OAAO,CAACY,IAAI,CAACJ,QAAQ,CAAC,CAAC;EACtE,MAAMV,IAAI,GAAGW,IAAI,EAAEX,IAAI,IAAI,0BAA0B;EACrD,OAAO,IAAIF,SAAS,CAAC;IACpBE,IAAI;IACJC,UAAU,EAAEU,IAAI,EAAEV,UAAU,IAAI,kBAAkB;IAClDc,QAAQ,EAAEf,IAAI,KAAK,mBAAmB,GAAG,WAAW,GAAG,MAAM;IAC7D;IACAgB,MAAM,EAAEV;EACT,CAAC,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Social provider routing (FR-002/FR-003, R3). Google and Apple are federated
5
+ * inside the External ID tenant; the app presents the platform-correct action
6
+ * and starts the user flow with a per-provider `domain_hint`.
7
+ */
8
+
9
+ import { AuthConfigError } from "../diagnostics/errors.js";
10
+
11
+ /** Find the configured provider, ensuring it is enabled for the platform. */
12
+ export function resolveProvider(config, providerId, platform) {
13
+ const provider = config.providers.find(candidate => candidate.id === providerId);
14
+ if (!provider) {
15
+ throw new AuthConfigError('auth.error.configuration', `Provider "${providerId}" is not configured`);
16
+ }
17
+ if (!provider.platforms.includes(platform)) {
18
+ throw new AuthConfigError('auth.error.configuration', `Provider "${providerId}" is not enabled for platform "${platform}"`);
19
+ }
20
+ if (provider.available === false) {
21
+ throw new AuthConfigError('auth.error.configuration', `Provider "${providerId}" is marked unavailable`);
22
+ }
23
+ return provider;
24
+ }
25
+
26
+ /** Build the OIDC additional parameters that route to the chosen IdP. */
27
+ export function buildAdditionalParameters(provider) {
28
+ // The routing hint last: a provider's own parameters cannot redirect the flow
29
+ // to a different IdP than the one the user tapped.
30
+ return {
31
+ ...provider.additionalParameters,
32
+ domain_hint: provider.domainHint
33
+ };
34
+ }
35
+
36
+ /**
37
+ * All providers to present on a given platform, in configuration array order
38
+ * (FR-003/FR-004). Filtered to providers enabled for the platform and not marked
39
+ * unavailable.
40
+ */
41
+ export function availableProvidersForPlatform(config, platform) {
42
+ return config.providers.filter(provider => provider.platforms.includes(platform) && provider.available !== false);
43
+ }
44
+
45
+ /**
46
+ * The first available provider for a platform (UX-004, back-compat). Equals
47
+ * `availableProvidersForPlatform(config, platform)[0]`.
48
+ */
49
+ export function defaultProviderForPlatform(config, platform) {
50
+ return availableProvidersForPlatform(config, platform)[0];
51
+ }
52
+ //# sourceMappingURL=socialRouting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AuthConfigError","resolveProvider","config","providerId","platform","provider","providers","find","candidate","id","platforms","includes","available","buildAdditionalParameters","additionalParameters","domain_hint","domainHint","availableProvidersForPlatform","filter","defaultProviderForPlatform"],"sourceRoot":"../../../src","sources":["oidc/socialRouting.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAGA,SAASA,eAAe,QAAQ,0BAAuB;;AAEvD;AACA,OAAO,SAASC,eAAeA,CAC9BC,MAAkB,EAClBC,UAAsB,EACtBC,QAAwB,EACP;EACjB,MAAMC,QAAQ,GAAGH,MAAM,CAACI,SAAS,CAACC,IAAI,CAACC,SAAS,IAAIA,SAAS,CAACC,EAAE,KAAKN,UAAU,CAAC;EAChF,IAAI,CAACE,QAAQ,EAAE;IACd,MAAM,IAAIL,eAAe,CACxB,0BAA0B,EAC1B,aAAaG,UAAU,qBACxB,CAAC;EACF;EACA,IAAI,CAACE,QAAQ,CAACK,SAAS,CAACC,QAAQ,CAACP,QAAQ,CAAC,EAAE;IAC3C,MAAM,IAAIJ,eAAe,CACxB,0BAA0B,EAC1B,aAAaG,UAAU,kCAAkCC,QAAQ,GAClE,CAAC;EACF;EACA,IAAIC,QAAQ,CAACO,SAAS,KAAK,KAAK,EAAE;IACjC,MAAM,IAAIZ,eAAe,CACxB,0BAA0B,EAC1B,aAAaG,UAAU,yBACxB,CAAC;EACF;EACA,OAAOE,QAAQ;AAChB;;AAEA;AACA,OAAO,SAASQ,yBAAyBA,CAACR,QAAwB,EAA0B;EAC3F;EACA;EACA,OAAO;IAAE,GAAGA,QAAQ,CAACS,oBAAoB;IAAEC,WAAW,EAAEV,QAAQ,CAACW;EAAW,CAAC;AAC9E;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,6BAA6BA,CAC5Cf,MAAkB,EAClBE,QAAwB,EACL;EACnB,OAAOF,MAAM,CAACI,SAAS,CAACY,MAAM,CAC7Bb,QAAQ,IAAIA,QAAQ,CAACK,SAAS,CAACC,QAAQ,CAACP,QAAQ,CAAC,IAAIC,QAAQ,CAACO,SAAS,KAAK,KAC7E,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASO,0BAA0BA,CACzCjB,MAAkB,EAClBE,QAAwB,EACK;EAC7B,OAAOa,6BAA6B,CAACf,MAAM,EAAEE,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC1D","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * React context boundary for the auth controller (LIB-002).
5
+ *
6
+ * The context carries the controller only, never its state: a context value that
7
+ * changed on every transition re-rendered every consumer on every transition
8
+ * (PERF-02). Hooks read the state through `useSyncExternalStore` with a selector,
9
+ * so a component re-renders only when the part it reads changes.
10
+ */
11
+
12
+ import React, { createContext, useContext } from 'react';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ const AuthContext = /*#__PURE__*/createContext(null);
15
+ export function AuthProvider({
16
+ auth,
17
+ children
18
+ }) {
19
+ return /*#__PURE__*/_jsx(AuthContext.Provider, {
20
+ value: auth,
21
+ children: children
22
+ });
23
+ }
24
+ export function useAuthInstance() {
25
+ const auth = useContext(AuthContext);
26
+ if (!auth) {
27
+ throw new Error('useAuth must be used within an <AuthProvider>.');
28
+ }
29
+ return auth;
30
+ }
31
+ //# sourceMappingURL=AuthProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","createContext","useContext","jsx","_jsx","AuthContext","AuthProvider","auth","children","Provider","value","useAuthInstance","Error"],"sourceRoot":"../../../src","sources":["react/AuthProvider.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGzD,MAAMC,WAAW,gBAAGJ,aAAa,CAAc,IAAI,CAAC;AAOpD,OAAO,SAASK,YAAYA,CAAC;EAAEC,IAAI;EAAEC;AAA4B,CAAC,EAAE;EACnE,oBAAOJ,IAAA,CAACC,WAAW,CAACI,QAAQ;IAACC,KAAK,EAAEH,IAAK;IAAAC,QAAA,EAAEA;EAAQ,CAAuB,CAAC;AAC5E;AAEA,OAAO,SAASG,eAAeA,CAAA,EAAS;EACvC,MAAMJ,IAAI,GAAGL,UAAU,CAACG,WAAW,CAAC;EACpC,IAAI,CAACE,IAAI,EAAE;IACV,MAAM,IAAIK,KAAK,CAAC,gDAAgD,CAAC;EAClE;EACA,OAAOL,IAAI;AACZ","ignoreList":[]}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Public hooks (LIB-002). Each reads the controller's state through
5
+ * `useSyncExternalStore` (rn-core's `useExternalStore`), selecting only what it
6
+ * returns, so `useProfile` does not re-render when only the status changes.
7
+ */
8
+
9
+ import { useExternalStore } from '@chipmobilesdk/rn-core/react';
10
+ import { useCallback, useEffect, useRef, useState } from 'react';
11
+ import { useAuthInstance } from "./AuthProvider.js";
12
+ import { failClosedTier } from "../access/accessTier.js";
13
+ /**
14
+ * Any slice of the auth state; the component re-renders only when the slice
15
+ * changes by `isEqual` (default `Object.is`).
16
+ */
17
+ export function useAuthSelector(select, isEqual) {
18
+ const auth = useAuthInstance();
19
+ return useExternalStore(auth.subscribe, auth.getState, select, isEqual);
20
+ }
21
+ const selectState = state => state;
22
+ const selectProfile = state => state.profile;
23
+ const selectAccessTier = state => state.accessTier;
24
+ export function useAuth() {
25
+ const auth = useAuthInstance();
26
+ const state = useAuthSelector(selectState);
27
+ return {
28
+ state,
29
+ signIn: useCallback(providerId => auth.signIn(providerId), [auth]),
30
+ signOut: useCallback(() => auth.signOut(), [auth]),
31
+ signOutGlobal: useCallback(() => auth.signOutGlobal(), [auth]),
32
+ restore: useCallback(() => auth.restore(), [auth]),
33
+ canAccessPremium: useCallback(() => auth.canAccessPremium(), [auth]),
34
+ requirePremium: useCallback(() => auth.requirePremium(), [auth])
35
+ };
36
+ }
37
+
38
+ /** This package's copy, with the app's `messages` overrides applied. */
39
+ export function useAuthMessages() {
40
+ return useAuthInstance().getMessages();
41
+ }
42
+ export function useProfile() {
43
+ return useAuthSelector(selectProfile);
44
+ }
45
+ export function useAccessTier() {
46
+ return useAuthSelector(selectAccessTier) ?? failClosedTier();
47
+ }
48
+
49
+ /** The first provider to present on the current platform (UX-004), or undefined. */
50
+ export function useSignInProvider() {
51
+ const auth = useAuthInstance();
52
+ return auth.getPlatformProvider();
53
+ }
54
+
55
+ /** All available providers for the current platform, in configuration order (FR-003/FR-004). */
56
+ export function useSignInProviders() {
57
+ const auth = useAuthInstance();
58
+ return auth.getPlatformProviders();
59
+ }
60
+ export function useAccessToken(resourceKey) {
61
+ const auth = useAuthInstance();
62
+ const [state, setState] = useState({
63
+ status: 'idle',
64
+ resourceKey
65
+ });
66
+
67
+ // Which request may still write. A result for a resource the component has
68
+ // moved on from, or for an unmounted one, is dropped rather than applied
69
+ // (AUTH-17, standard VII).
70
+ const live = useRef(0);
71
+ useEffect(() => () => {
72
+ live.current += 1;
73
+ }, []);
74
+ const request = useCallback(async options => {
75
+ live.current += 1;
76
+ const id = live.current;
77
+ setState({
78
+ status: 'loading',
79
+ resourceKey
80
+ });
81
+ const result = await auth.requestAccessToken(resourceKey, options);
82
+ if (id === live.current) {
83
+ setState({
84
+ status: result.status,
85
+ token: result.token,
86
+ resourceKey
87
+ });
88
+ }
89
+ return result;
90
+ }, [auth, resourceKey]);
91
+
92
+ // A new resource starts from `idle`, not from the previous resource's token.
93
+ if (state.resourceKey !== resourceKey) {
94
+ live.current += 1;
95
+ setState({
96
+ status: 'idle',
97
+ resourceKey
98
+ });
99
+ return {
100
+ status: 'idle',
101
+ token: undefined,
102
+ request
103
+ };
104
+ }
105
+ return {
106
+ status: state.status,
107
+ token: state.token,
108
+ request
109
+ };
110
+ }
111
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useExternalStore","useCallback","useEffect","useRef","useState","useAuthInstance","failClosedTier","useAuthSelector","select","isEqual","auth","subscribe","getState","selectState","state","selectProfile","profile","selectAccessTier","accessTier","useAuth","signIn","providerId","signOut","signOutGlobal","restore","canAccessPremium","requirePremium","useAuthMessages","getMessages","useProfile","useAccessTier","useSignInProvider","getPlatformProvider","useSignInProviders","getPlatformProviders","useAccessToken","resourceKey","setState","status","live","current","request","options","id","result","requestAccessToken","token","undefined"],"sourceRoot":"../../../src","sources":["react/hooks.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAChE,SAASC,eAAe,QAAQ,mBAAgB;AAWhD,SAASC,cAAc,QAAQ,yBAAsB;AAgBrD;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC9BC,MAAsC,EACtCC,OAA+C,EACpC;EACX,MAAMC,IAAI,GAAGL,eAAe,CAAC,CAAC;EAC9B,OAAOL,gBAAgB,CAACU,IAAI,CAACC,SAAS,EAAED,IAAI,CAACE,QAAQ,EAAEJ,MAAM,EAAEC,OAAO,CAAC;AACxE;AAEA,MAAMI,WAAW,GAAIC,KAAgB,IAAKA,KAAK;AAC/C,MAAMC,aAAa,GAAID,KAAgB,IAAKA,KAAK,CAACE,OAAO;AACzD,MAAMC,gBAAgB,GAAIH,KAAgB,IAAKA,KAAK,CAACI,UAAU;AAE/D,OAAO,SAASC,OAAOA,CAAA,EAAkB;EACxC,MAAMT,IAAI,GAAGL,eAAe,CAAC,CAA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