@smartcrab/react-native 0.1.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 (96) hide show
  1. package/LICENSE +202 -0
  2. package/app.plugin.js +9 -0
  3. package/dist/adapters/expo-crypto-port.d.ts +3 -0
  4. package/dist/adapters/expo-crypto-port.js +8 -0
  5. package/dist/adapters/expo-linking-port.d.ts +3 -0
  6. package/dist/adapters/expo-linking-port.js +21 -0
  7. package/dist/adapters/expo-secure-store-port.d.ts +11 -0
  8. package/dist/adapters/expo-secure-store-port.js +15 -0
  9. package/dist/adapters/expo-web-browser-port.d.ts +7 -0
  10. package/dist/adapters/expo-web-browser-port.js +9 -0
  11. package/dist/adapters/react-native-app-state-port.d.ts +8 -0
  12. package/dist/adapters/react-native-app-state-port.js +13 -0
  13. package/dist/adapters/react-native-passkeys-adapter.d.ts +2 -0
  14. package/dist/adapters/react-native-passkeys-adapter.js +112 -0
  15. package/dist/adapters/react-native-passkeys-adapter.test.d.ts +1 -0
  16. package/dist/adapters/react-native-passkeys-adapter.test.js +76 -0
  17. package/dist/base64url.d.ts +20 -0
  18. package/dist/base64url.js +89 -0
  19. package/dist/base64url.test.d.ts +1 -0
  20. package/dist/base64url.test.js +36 -0
  21. package/dist/browser-port.d.ts +17 -0
  22. package/dist/browser-port.js +1 -0
  23. package/dist/client.d.ts +43 -0
  24. package/dist/client.js +871 -0
  25. package/dist/client.test.d.ts +1 -0
  26. package/dist/client.test.js +995 -0
  27. package/dist/context.d.ts +8 -0
  28. package/dist/context.js +17 -0
  29. package/dist/crypto-port.d.ts +16 -0
  30. package/dist/crypto-port.js +1 -0
  31. package/dist/errors.d.ts +113 -0
  32. package/dist/errors.js +82 -0
  33. package/dist/errors.test.d.ts +1 -0
  34. package/dist/errors.test.js +81 -0
  35. package/dist/hooks.d.ts +93 -0
  36. package/dist/hooks.js +191 -0
  37. package/dist/http.d.ts +41 -0
  38. package/dist/http.js +102 -0
  39. package/dist/index.d.ts +22 -0
  40. package/dist/index.js +29 -0
  41. package/dist/jwt.d.ts +1 -0
  42. package/dist/jwt.js +23 -0
  43. package/dist/lifecycle-ports.d.ts +29 -0
  44. package/dist/lifecycle-ports.js +1 -0
  45. package/dist/linking-port.d.ts +15 -0
  46. package/dist/linking-port.js +1 -0
  47. package/dist/passkey-adapter.d.ts +20 -0
  48. package/dist/passkey-adapter.js +1 -0
  49. package/dist/pkce.d.ts +32 -0
  50. package/dist/pkce.js +41 -0
  51. package/dist/pkce.test.d.ts +1 -0
  52. package/dist/pkce.test.js +66 -0
  53. package/dist/plugin.d.ts +89 -0
  54. package/dist/plugin.js +242 -0
  55. package/dist/plugin.test.d.ts +1 -0
  56. package/dist/plugin.test.js +210 -0
  57. package/dist/provider.d.ts +14 -0
  58. package/dist/provider.js +5 -0
  59. package/dist/secure-store.d.ts +54 -0
  60. package/dist/secure-store.js +55 -0
  61. package/dist/secure-store.test.d.ts +1 -0
  62. package/dist/secure-store.test.js +69 -0
  63. package/dist/types.d.ts +177 -0
  64. package/dist/types.js +1 -0
  65. package/package.json +69 -0
  66. package/src/adapters/expo-crypto-port.ts +11 -0
  67. package/src/adapters/expo-linking-port.ts +23 -0
  68. package/src/adapters/expo-secure-store-port.ts +20 -0
  69. package/src/adapters/expo-web-browser-port.ts +16 -0
  70. package/src/adapters/react-native-app-state-port.ts +15 -0
  71. package/src/adapters/react-native-passkeys-adapter.test.ts +87 -0
  72. package/src/adapters/react-native-passkeys-adapter.ts +138 -0
  73. package/src/base64url.test.ts +47 -0
  74. package/src/base64url.ts +92 -0
  75. package/src/browser-port.ts +19 -0
  76. package/src/client.test.ts +1275 -0
  77. package/src/client.ts +1329 -0
  78. package/src/context.ts +20 -0
  79. package/src/crypto-port.ts +16 -0
  80. package/src/errors.test.ts +94 -0
  81. package/src/errors.ts +216 -0
  82. package/src/hooks.ts +374 -0
  83. package/src/http.ts +159 -0
  84. package/src/index.ts +101 -0
  85. package/src/jwt.ts +24 -0
  86. package/src/lifecycle-ports.ts +32 -0
  87. package/src/linking-port.ts +16 -0
  88. package/src/passkey-adapter.ts +20 -0
  89. package/src/pkce.test.ts +84 -0
  90. package/src/pkce.ts +62 -0
  91. package/src/plugin.test.ts +303 -0
  92. package/src/plugin.ts +387 -0
  93. package/src/provider.tsx +20 -0
  94. package/src/secure-store.test.ts +91 -0
  95. package/src/secure-store.ts +102 -0
  96. package/src/types.ts +181 -0
@@ -0,0 +1,36 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { base64UrlDecodeToBytes, base64UrlDecodeToUtf8String, base64UrlEncodeBytes, standardBase64ToBase64Url, } from "./base64url.js";
3
+ describe("base64UrlEncodeBytes / base64UrlDecodeToBytes", () => {
4
+ test("round-trips arbitrary byte lengths", () => {
5
+ for (const length of [0, 1, 2, 3, 4, 5, 16, 32]) {
6
+ const bytes = new Uint8Array(Array.from({ length }, (_, i) => (i * 7) % 256));
7
+ const encoded = base64UrlEncodeBytes(bytes);
8
+ expect(encoded).not.toMatch(/[+/=]/);
9
+ expect(base64UrlDecodeToBytes(encoded)).toEqual(bytes);
10
+ }
11
+ });
12
+ test("32 random bytes encode to exactly 43 base64url characters (RFC 7636 verifier length)", () => {
13
+ const bytes = new Uint8Array(32).fill(1);
14
+ expect(base64UrlEncodeBytes(bytes)).toHaveLength(43);
15
+ });
16
+ });
17
+ describe("base64UrlDecodeToUtf8String", () => {
18
+ test("decodes ASCII", () => {
19
+ const encoded = base64UrlEncodeBytes(new TextEncoder().encode('{"sub":"usr_abc"}'));
20
+ expect(base64UrlDecodeToUtf8String(encoded)).toBe('{"sub":"usr_abc"}');
21
+ });
22
+ test("decodes multi-byte UTF-8", () => {
23
+ const text = "こんにちは";
24
+ const encoded = base64UrlEncodeBytes(new TextEncoder().encode(text));
25
+ expect(base64UrlDecodeToUtf8String(encoded)).toBe(text);
26
+ });
27
+ });
28
+ describe("standardBase64ToBase64Url", () => {
29
+ test("converts padding and URL-unsafe characters", () => {
30
+ expect(standardBase64ToBase64Url("YQ==")).toBe("YQ");
31
+ expect(standardBase64ToBase64Url("Pj4/Pw==")).toBe("Pj4_Pw");
32
+ });
33
+ test("rejects non-base64 input", () => {
34
+ expect(standardBase64ToBase64Url("not base64!!")).toBeNull();
35
+ });
36
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * System-browser boundary for social sign-in / linking (design.md §20.6,
3
+ * §21.3): "埋め込みWebViewは禁止する。" This port's only production
4
+ * implementation opens `expo-web-browser`'s ephemeral/Custom Tabs auth
5
+ * session — never a `WebView` component. No `react-native-webview` import
6
+ * exists anywhere in this package.
7
+ */
8
+ export type WebBrowserResultType = "success" | "cancel" | "dismiss" | "opened" | "locked";
9
+ export interface WebBrowserAuthResult {
10
+ readonly type: WebBrowserResultType;
11
+ /** Present only when `type === "success"`: the URL the browser was redirected to. */
12
+ readonly url?: string;
13
+ }
14
+ export interface WebBrowserPort {
15
+ /** Opens `url` in the system browser and resolves once it redirects back to `redirectUrl`. */
16
+ openAuthSessionAsync(url: string, redirectUrl: string): Promise<WebBrowserAuthResult>;
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { WebBrowserPort } from "./browser-port.js";
2
+ import type { CryptoPort } from "./crypto-port.js";
3
+ import type { ReactNativeAuthError } from "./errors.js";
4
+ import type { AppStatePort } from "./lifecycle-ports.js";
5
+ import type { LinkingPort } from "./linking-port.js";
6
+ import type { PasskeyNativeAdapter } from "./passkey-adapter.js";
7
+ import type { SecureStorePort } from "./secure-store.js";
8
+ import type { ReactNativeAuthClient, ReactNativeAuthConfig } from "./types.js";
9
+ /**
10
+ * Normalizes a native `react-native-passkeys` (or DOMException-like) exception (design.md §21.2).
11
+ *
12
+ * iOS/web reject with a DOMException-like `.name`. Android
13
+ * (`react-native-passkeys@0.4.1`) rejects through Expo's
14
+ * `promise.reject(code, message)`: a plain `Error` whose `message` is one of
15
+ * `UserCancelled`/`Interrupted`/`NotConfigured`/`UnknownError`/`NotSupported`/
16
+ * `NoCredentials`, or `DomError: <DOMExceptionName> - <text>`; `.code` may
17
+ * carry the same signal, so both are matched.
18
+ *
19
+ * `NotConfigured` (a broken assetlinks/provider setup) is deliberately NOT
20
+ * `passkey_not_supported`: it falls through to `passkey_error/failed` with
21
+ * the native message preserved so the misconfiguration stays diagnosable.
22
+ */
23
+ export declare const normalizePasskeyException: (cause: unknown) => ReactNativeAuthError;
24
+ /**
25
+ * The real implementation of every port `ReactNativeAuthConfig` lets a
26
+ * consumer override (design.md §21.1's peer dependencies). Supplied by
27
+ * `index.ts` in production (see this file's top doc comment for why that
28
+ * import boundary matters); test files supply fakes for all six instead.
29
+ */
30
+ export interface NativePortDefaults {
31
+ readonly secureStore: SecureStorePort;
32
+ readonly passkeyAdapter: PasskeyNativeAdapter;
33
+ readonly browser: WebBrowserPort;
34
+ readonly linking: LinkingPort;
35
+ readonly crypto: CryptoPort;
36
+ readonly appState: AppStatePort;
37
+ }
38
+ /**
39
+ * Builds `createReactNativeAuthClient` (design.md §21.3, §21.8) given the
40
+ * real native port defaults. Pass the config up front (matching §21.8's
41
+ * sample) or omit it and call `.configure()` before using any other method.
42
+ */
43
+ export declare const createReactNativeAuthClientFactory: (defaults: NativePortDefaults) => (initialConfig?: ReactNativeAuthConfig) => ReactNativeAuthClient;