@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,16 @@
1
+ /**
2
+ * Deep-link callback parsing (design.md §20.6, §21.3): the social/hosted
3
+ * authorization callback returns to a custom scheme or Universal/App Link
4
+ * URL, which this port turns into a flat query-parameter map.
5
+ */
6
+ export interface ParsedCallbackUrl {
7
+ readonly queryParams: Readonly<Record<string, string>>;
8
+ }
9
+
10
+ export interface LinkingPort {
11
+ parse(url: string): ParsedCallbackUrl;
12
+ /** The deep link the app was most recently launched/resumed with, if any. */
13
+ getInitialURL(): Promise<string | null>;
14
+ /** Subscribes to deep links received while the app is already running. */
15
+ addEventListener(handler: (url: string) => void): () => void;
16
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Native adapter boundary (design.md §21.2, verbatim):
3
+ *
4
+ * > 第三者native moduleのAPIをSDK公開面へ直接露出しない。
5
+ *
6
+ * `react-native-passkeys` types never appear here or anywhere in this
7
+ * package's public surface (`index.ts`) — only plain JSON strings cross this
8
+ * boundary. `create`/`get` may reject with the native module's own exception
9
+ * shape (including `react-native-passkeys`' `NotSupportedError`/
10
+ * `UnknownError`, a `DOMException`-like object on web, or a plain `Error`);
11
+ * normalizing that into a public `PasskeyOperationError` code is the
12
+ * *client's* job (design.md: "native module固有の例外は公開error codeへ正規化
13
+ * する"), not the adapter's — this interface intentionally carries no error
14
+ * type of its own.
15
+ */
16
+ export interface PasskeyNativeAdapter {
17
+ isSupported(): Promise<boolean>;
18
+ create(optionsJson: string): Promise<string>;
19
+ get(optionsJson: string): Promise<string>;
20
+ }
@@ -0,0 +1,84 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { base64UrlEncodeBytes } from "./base64url.js";
3
+ import type { CryptoPort } from "./crypto-port.js";
4
+ import { constantTimeEqual, generateNonce, generatePkcePair, generateState } from "./pkce.js";
5
+
6
+ /** Standard (padded) base64, matching what `expo-crypto`'s `digestStringAsync(..., { encoding: BASE64 })` returns. */
7
+ const bytesToStandardBase64 = (bytes: Uint8Array): string => btoa(String.fromCharCode(...bytes));
8
+
9
+ /** Real SHA-256 via the platform's Web Crypto global — ground truth, not just self-consistency. */
10
+ const sha256StandardBase64 = async (data: string): Promise<string> => {
11
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(data));
12
+ return bytesToStandardBase64(new Uint8Array(digest));
13
+ };
14
+
15
+ /** Deterministic fake `CryptoPort` backed by the real Web Crypto digest. */
16
+ const fakeCrypto = (seed: number): CryptoPort => ({
17
+ getRandomBytes: (byteCount) =>
18
+ new Uint8Array(Array.from({ length: byteCount }, (_, i) => (seed + i * 7) % 256)),
19
+ sha256Base64: sha256StandardBase64,
20
+ });
21
+
22
+ describe("generatePkcePair", () => {
23
+ test("S256 challenge is base64url(SHA-256(verifier))", async () => {
24
+ const pair = await generatePkcePair(fakeCrypto(1));
25
+ const expectedDigest = await crypto.subtle.digest(
26
+ "SHA-256",
27
+ new TextEncoder().encode(pair.verifier),
28
+ );
29
+ const expectedChallenge = base64UrlEncodeBytes(new Uint8Array(expectedDigest));
30
+ expect(pair.challenge).toBe(expectedChallenge);
31
+ expect(pair.method).toBe("S256");
32
+ });
33
+
34
+ test("verifier matches RFC 7636 §4.1 charset and length (43 chars from 32 random bytes)", async () => {
35
+ const pair = await generatePkcePair(fakeCrypto(2));
36
+ expect(pair.verifier).toHaveLength(43);
37
+ expect(pair.verifier).toMatch(/^[A-Za-z0-9._~-]{43,128}$/);
38
+ });
39
+
40
+ test("challenge is 43 base64url characters with no padding", async () => {
41
+ const pair = await generatePkcePair(fakeCrypto(3));
42
+ expect(pair.challenge).toHaveLength(43);
43
+ expect(pair.challenge).toMatch(/^[A-Za-z0-9_-]{43}$/);
44
+ });
45
+
46
+ test("different seeds produce different verifiers", async () => {
47
+ const a = await generatePkcePair(fakeCrypto(10));
48
+ const b = await generatePkcePair(fakeCrypto(20));
49
+ expect(a.verifier).not.toBe(b.verifier);
50
+ });
51
+
52
+ test("throws when the crypto port returns a non-base64 digest (integrity check, not a business error)", async () => {
53
+ const brokenCrypto: CryptoPort = {
54
+ getRandomBytes: (n) => new Uint8Array(n),
55
+ sha256Base64: () => Promise.resolve("not base64!!"),
56
+ };
57
+ await expect(generatePkcePair(brokenCrypto)).rejects.toThrow();
58
+ });
59
+ });
60
+
61
+ describe("generateState / generateNonce", () => {
62
+ test("produce 43-character base64url strings", () => {
63
+ expect(generateState(fakeCrypto(5))).toHaveLength(43);
64
+ expect(generateNonce(fakeCrypto(5))).toHaveLength(43);
65
+ });
66
+ });
67
+
68
+ describe("constantTimeEqual", () => {
69
+ test("true for identical strings", () => {
70
+ expect(constantTimeEqual("abc123", "abc123")).toBe(true);
71
+ });
72
+
73
+ test("false for different strings of the same length", () => {
74
+ expect(constantTimeEqual("abc123", "abc124")).toBe(false);
75
+ });
76
+
77
+ test("false for different lengths", () => {
78
+ expect(constantTimeEqual("abc", "abcd")).toBe(false);
79
+ });
80
+
81
+ test("false against an empty string", () => {
82
+ expect(constantTimeEqual("abc", "")).toBe(false);
83
+ });
84
+ });
package/src/pkce.ts ADDED
@@ -0,0 +1,62 @@
1
+ import { base64UrlEncodeBytes, standardBase64ToBase64Url } from "./base64url.js";
2
+ import type { CryptoPort } from "./crypto-port.js";
3
+
4
+ /**
5
+ * PKCE (RFC 7636) and anti-replay value generation for the React Native SDK
6
+ * (design.md §20.6, §21.3, §16.1). `S256` only — `plain` is never offered
7
+ * (design.md §15.3).
8
+ */
9
+
10
+ export interface PkcePair {
11
+ /** RFC 7636 §4.1 verifier: 43 chars from 32 random bytes, unreserved charset. */
12
+ readonly verifier: string;
13
+ /** RFC 7636 §4.2 S256 challenge: base64url(SHA-256(verifier)), 43 chars. */
14
+ readonly challenge: string;
15
+ readonly method: "S256";
16
+ }
17
+
18
+ const randomBase64Url = (crypto: CryptoPort, byteLength: number): string =>
19
+ base64UrlEncodeBytes(crypto.getRandomBytes(byteLength));
20
+
21
+ /** Transaction `state` (design.md §16.1: the server stores only a MAC of it). */
22
+ export const generateState = (crypto: CryptoPort): string => randomBase64Url(crypto, 32);
23
+
24
+ /** OIDC `nonce` for ID token replay protection. */
25
+ export const generateNonce = (crypto: CryptoPort): string => randomBase64Url(crypto, 32);
26
+
27
+ /**
28
+ * Generates a verifier/challenge pair. 32 random bytes -> 43 base64url chars,
29
+ * inside RFC 7636 §4.1's 43-128 window and matching contracts-public's
30
+ * `codeVerifierSchema` charset exactly.
31
+ */
32
+ export const generatePkcePair = async (crypto: CryptoPort): Promise<PkcePair> => {
33
+ const verifier = randomBase64Url(crypto, 32);
34
+ const digestBase64 = await crypto.sha256Base64(verifier);
35
+ const challenge = standardBase64ToBase64Url(digestBase64);
36
+ if (challenge === null) {
37
+ // The native crypto module violated its own documented contract (a
38
+ // base64-encoded digest); this is an integrity check on a third-party
39
+ // native module boundary, not a predictable business error.
40
+ throw new Error("CryptoPort.sha256Base64 returned a value that is not valid base64");
41
+ }
42
+ return { verifier, challenge, method: "S256" };
43
+ };
44
+
45
+ /**
46
+ * Constant-time-ish string comparison for `state` verification (design.md
47
+ * §21.3's PKCE/state flow). Real constant-time comparison over variable
48
+ * -length JS strings is not achievable in pure JS without engine-specific
49
+ * guarantees; this at least avoids the short-circuiting `===` comparison and
50
+ * always walks the full (max) length so timing does not trivially reveal how
51
+ * many leading characters matched.
52
+ */
53
+ export const constantTimeEqual = (a: string, b: string): boolean => {
54
+ const length = Math.max(a.length, b.length);
55
+ let diff = a.length === b.length ? 0 : 1;
56
+ for (let i = 0; i < length; i += 1) {
57
+ const charA = a.charCodeAt(i) || 0;
58
+ const charB = b.charCodeAt(i) || 0;
59
+ diff |= charA ^ charB;
60
+ }
61
+ return diff === 0;
62
+ };
@@ -0,0 +1,303 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import {
3
+ ASSET_STATEMENTS_RESOURCE_NAME,
4
+ mergeAndroidIntentFilters,
5
+ mergeAssetStatementsMetaData,
6
+ mergeAssetStatementsResource,
7
+ mergeAssociatedDomains,
8
+ mergeUrlScheme,
9
+ validateAndroidSdkVersions,
10
+ } from "./plugin.js";
11
+ import plugin from "./plugin.js";
12
+
13
+ /**
14
+ * `expo/config-plugins` is a plain Node CLI package (no Flow/native-runtime
15
+ * syntax, unlike `react-native`/most `expo-*` runtime modules — see
16
+ * `client.ts`'s top doc comment), so it is safe to import directly here.
17
+ *
18
+ * `ExpoConfig` itself comes from `@expo/config-types`, a transitive (not
19
+ * directly resolvable) dependency, so its shape is pulled off `plugin`'s own
20
+ * signature instead of importing the type by name.
21
+ *
22
+ * Note on scope: Expo's mod system (`withEntitlementsPlist`/
23
+ * `withAndroidManifest`/etc.) defers the actual plist/manifest file mutation
24
+ * to `expo prebuild`'s mod-compilation step, so calling `plugin(config,
25
+ * props)` in a unit test does NOT synchronously produce a mutated
26
+ * `config.ios`/`config.android` — that requires a real prebuild, explicitly
27
+ * out of scope here. What IS unit-testable, and tested below, is (a) the
28
+ * config-validation logic that runs eagerly before any mod is queued, and
29
+ * (b) the pure merge functions each mod callback delegates to.
30
+ */
31
+ type ExpoConfig = Parameters<typeof plugin>[0];
32
+
33
+ const PROPS = {
34
+ clientId: "cli_xxx",
35
+ rpDomain: "auth.customer.example",
36
+ callbackPath: "oauth/callback",
37
+ };
38
+
39
+ const baseConfig = (overrides?: Partial<ExpoConfig>): ExpoConfig => ({
40
+ name: "customer-app",
41
+ slug: "customer-app",
42
+ scheme: "com.customer.app",
43
+ ...overrides,
44
+ });
45
+
46
+ describe("auth-platform-react-native config plugin — validation (design.md §21.5)", () => {
47
+ test("a well-formed config does not throw", () => {
48
+ expect(() => plugin(baseConfig(), PROPS)).not.toThrow();
49
+ });
50
+
51
+ test("throws a build-time error when expo.scheme is missing", () => {
52
+ const configWithoutScheme: ExpoConfig = { name: "customer-app", slug: "customer-app" };
53
+ expect(() => plugin(configWithoutScheme, PROPS)).toThrow(/scheme is required/);
54
+ });
55
+
56
+ test("throws when expo.scheme is not reverse-DNS (design.md §15.9)", () => {
57
+ expect(() => plugin(baseConfig({ scheme: "notreversedns" }), PROPS)).toThrow(/reverse-DNS/);
58
+ });
59
+
60
+ test("throws when rpDomain is not a bare hostname", () => {
61
+ expect(() =>
62
+ plugin(baseConfig(), { ...PROPS, rpDomain: "https://auth.customer.example/" }),
63
+ ).toThrow(/bare hostname/);
64
+ });
65
+
66
+ test("throws when callbackPath has a leading slash", () => {
67
+ expect(() => plugin(baseConfig(), { ...PROPS, callbackPath: "/oauth/callback" })).toThrow(
68
+ /no leading slash/,
69
+ );
70
+ });
71
+
72
+ test("throws when clientId is empty", () => {
73
+ expect(() => plugin(baseConfig(), { ...PROPS, clientId: "" })).toThrow(/clientId/);
74
+ });
75
+
76
+ test("throws when the iOS deployment target is explicitly below design.md §3.2's 15.1 floor", () => {
77
+ expect(() => plugin(baseConfig({ ios: { deploymentTarget: "14.0" } }), PROPS)).toThrow(/15\.1/);
78
+ });
79
+
80
+ test("accepts an iOS deployment target at/above the floor", () => {
81
+ expect(() => plugin(baseConfig({ ios: { deploymentTarget: "15.1" } }), PROPS)).not.toThrow();
82
+ });
83
+ });
84
+
85
+ describe("mergeAssociatedDomains", () => {
86
+ test("adds both webcredentials and applinks entries", () => {
87
+ expect(mergeAssociatedDomains(undefined, "auth.customer.example")).toEqual([
88
+ "webcredentials:auth.customer.example",
89
+ "applinks:auth.customer.example",
90
+ ]);
91
+ });
92
+
93
+ test("preserves an existing, unrelated domain", () => {
94
+ const result = mergeAssociatedDomains(
95
+ ["webcredentials:other.example"],
96
+ "auth.customer.example",
97
+ );
98
+ expect(result).toContain("webcredentials:other.example");
99
+ expect(result).toContain("webcredentials:auth.customer.example");
100
+ });
101
+
102
+ test("is idempotent", () => {
103
+ const once = mergeAssociatedDomains(undefined, "auth.customer.example");
104
+ const twice = mergeAssociatedDomains(once, "auth.customer.example");
105
+ expect(twice.filter((d) => d === "webcredentials:auth.customer.example")).toHaveLength(1);
106
+ expect(twice).toHaveLength(2);
107
+ });
108
+
109
+ test("ignores non-string entries in a malformed existing entitlement", () => {
110
+ expect(
111
+ mergeAssociatedDomains([1, null, "webcredentials:kept.example"], "auth.customer.example"),
112
+ ).toContain("webcredentials:kept.example");
113
+ });
114
+ });
115
+
116
+ describe("mergeUrlScheme", () => {
117
+ test("registers the scheme when absent", () => {
118
+ expect(mergeUrlScheme(undefined, "com.customer.app")).toEqual([
119
+ { CFBundleURLSchemes: ["com.customer.app"] },
120
+ ]);
121
+ });
122
+
123
+ test("does not duplicate an already-registered scheme", () => {
124
+ const existing = [{ CFBundleURLSchemes: ["com.customer.app"] }];
125
+ expect(mergeUrlScheme(existing, "com.customer.app")).toEqual(existing);
126
+ });
127
+
128
+ test("preserves other URL type entries", () => {
129
+ const existing = [{ CFBundleURLSchemes: ["other-scheme"] }];
130
+ const result = mergeUrlScheme(existing, "com.customer.app");
131
+ expect(result).toHaveLength(2);
132
+ });
133
+ });
134
+
135
+ describe("mergeAndroidIntentFilters", () => {
136
+ test("adds a custom-scheme filter and an autoVerify HTTPS App Link filter", () => {
137
+ const result = mergeAndroidIntentFilters([], { ...PROPS, scheme: "com.customer.app" });
138
+ expect(result).toHaveLength(2);
139
+ const linkFilter = result.find((f) => f.$?.["android:autoVerify"] === "true");
140
+ expect(linkFilter?.data?.[0]?.$["android:host"]).toBe("auth.customer.example");
141
+ expect(linkFilter?.data?.[0]?.$["android:pathPrefix"]).toBe("/oauth/callback");
142
+ const schemeFilter = result.find((f) => f.$?.["android:autoVerify"] === undefined);
143
+ expect(schemeFilter?.data?.[0]?.$["android:scheme"]).toBe("com.customer.app");
144
+ });
145
+
146
+ test("does not duplicate filters already present", () => {
147
+ const once = mergeAndroidIntentFilters([], { ...PROPS, scheme: "com.customer.app" });
148
+ const twice = mergeAndroidIntentFilters(once, { ...PROPS, scheme: "com.customer.app" });
149
+ expect(twice).toHaveLength(2);
150
+ });
151
+
152
+ test("preserves an unrelated pre-existing intent filter", () => {
153
+ const unrelated = { action: [{ $: { "android:name": "android.intent.action.MAIN" } }] };
154
+ const result = mergeAndroidIntentFilters([unrelated], { ...PROPS, scheme: "com.customer.app" });
155
+ expect(result).toContainEqual(unrelated);
156
+ expect(result).toHaveLength(3);
157
+ });
158
+
159
+ test("replaces a stale HTTPS filter when callbackPath changes instead of duplicating it", () => {
160
+ const stale = mergeAndroidIntentFilters([], {
161
+ ...PROPS,
162
+ callbackPath: "old/callback",
163
+ scheme: "com.customer.app",
164
+ });
165
+ const result = mergeAndroidIntentFilters(stale, { ...PROPS, scheme: "com.customer.app" });
166
+ const linkFilters = result.filter((f) => f.$?.["android:autoVerify"] === "true");
167
+ expect(linkFilters).toHaveLength(1);
168
+ expect(linkFilters[0]?.data?.[0]?.$["android:pathPrefix"]).toBe("/oauth/callback");
169
+ expect(result).toHaveLength(2);
170
+ });
171
+ });
172
+
173
+ describe("mergeAssetStatementsResource", () => {
174
+ test("adds an asset_statements string resource pointing at the rpDomain's assetlinks.json", () => {
175
+ const result = mergeAssetStatementsResource([], "auth.customer.example");
176
+ expect(result).toHaveLength(1);
177
+ expect(result[0]?.$.name).toBe(ASSET_STATEMENTS_RESOURCE_NAME);
178
+ expect(JSON.parse(result[0]?._ ?? "[]")).toEqual([
179
+ { include: "https://auth.customer.example/.well-known/assetlinks.json" },
180
+ ]);
181
+ });
182
+
183
+ test("replaces a stale asset_statements entry rather than duplicating it", () => {
184
+ const stale = { _: "[]", $: { name: ASSET_STATEMENTS_RESOURCE_NAME, translatable: "false" } };
185
+ const result = mergeAssetStatementsResource([stale], "auth.customer.example");
186
+ expect(result).toHaveLength(1);
187
+ expect(result[0]?._).not.toBe("[]");
188
+ });
189
+
190
+ test("preserves unrelated string resources", () => {
191
+ const other = { _: "value", $: { name: "app_name" } };
192
+ const result = mergeAssetStatementsResource([other], "auth.customer.example");
193
+ expect(result).toContainEqual(other);
194
+ });
195
+ });
196
+
197
+ describe("validateAndroidSdkVersions (design.md §3.2: minSdk 28, compileSdk 34)", () => {
198
+ test("throws a build-time error mentioning 28 when minSdkVersion is 27", () => {
199
+ expect(() =>
200
+ validateAndroidSdkVersions([["expo-build-properties", { android: { minSdkVersion: 27 } }]]),
201
+ ).toThrow(/28/);
202
+ });
203
+
204
+ test("throws a build-time error mentioning 34 when compileSdkVersion is 33", () => {
205
+ expect(() =>
206
+ validateAndroidSdkVersions([
207
+ ["expo-build-properties", { android: { compileSdkVersion: 33 } }],
208
+ ]),
209
+ ).toThrow(/34/);
210
+ });
211
+
212
+ test("passes at exactly the floor and above", () => {
213
+ expect(() =>
214
+ validateAndroidSdkVersions([
215
+ ["expo-build-properties", { android: { minSdkVersion: 28, compileSdkVersion: 34 } }],
216
+ ["expo-build-properties", { android: { minSdkVersion: 34, compileSdkVersion: 35 } }],
217
+ ]),
218
+ ).not.toThrow();
219
+ });
220
+
221
+ test("passes when versions are unset", () => {
222
+ expect(() => validateAndroidSdkVersions(undefined)).not.toThrow();
223
+ expect(() => validateAndroidSdkVersions([])).not.toThrow();
224
+ expect(() => validateAndroidSdkVersions(["expo-build-properties"])).not.toThrow();
225
+ expect(() =>
226
+ validateAndroidSdkVersions([["expo-build-properties", { ios: {} }]]),
227
+ ).not.toThrow();
228
+ expect(() =>
229
+ validateAndroidSdkVersions([["expo-build-properties", { android: {} }]]),
230
+ ).not.toThrow();
231
+ });
232
+
233
+ test("ignores malformed plugin entries", () => {
234
+ expect(() =>
235
+ validateAndroidSdkVersions([
236
+ "expo-router",
237
+ [],
238
+ ["expo-build-properties"],
239
+ ["other-plugin", { android: { minSdkVersion: 21 } }],
240
+ ["expo-build-properties", null],
241
+ ["expo-build-properties", { android: null }],
242
+ ["expo-build-properties", { android: { minSdkVersion: "27" } }],
243
+ ]),
244
+ ).not.toThrow();
245
+ });
246
+
247
+ test("is enforced through the plugin entrypoint", () => {
248
+ expect(() =>
249
+ plugin(
250
+ baseConfig({ plugins: [["expo-build-properties", { android: { minSdkVersion: 27 } }]] }),
251
+ PROPS,
252
+ ),
253
+ ).toThrow(/28/);
254
+ expect(() =>
255
+ plugin(
256
+ baseConfig({
257
+ plugins: [["expo-build-properties", { android: { minSdkVersion: 28 } }]],
258
+ }),
259
+ PROPS,
260
+ ),
261
+ ).not.toThrow();
262
+ });
263
+ });
264
+
265
+ describe("mergeAssetStatementsMetaData", () => {
266
+ test("adds exactly one asset_statements meta-data entry", () => {
267
+ const result = mergeAssetStatementsMetaData(undefined);
268
+ expect(result).toEqual([
269
+ {
270
+ $: {
271
+ "android:name": ASSET_STATEMENTS_RESOURCE_NAME,
272
+ "android:resource": `@string/${ASSET_STATEMENTS_RESOURCE_NAME}`,
273
+ },
274
+ },
275
+ ]);
276
+ });
277
+
278
+ test("is idempotent on re-run", () => {
279
+ const once = mergeAssetStatementsMetaData(undefined);
280
+ const twice = mergeAssetStatementsMetaData(once);
281
+ expect(twice).toHaveLength(1);
282
+ expect(twice).toEqual(once);
283
+ });
284
+
285
+ test("preserves sibling meta-data entries", () => {
286
+ const sibling = {
287
+ $: {
288
+ "android:name": "com.google.firebase.messaging.default_notification_icon",
289
+ "android:resource": "@drawable/ic_notification",
290
+ },
291
+ };
292
+ const result = mergeAssetStatementsMetaData([sibling]);
293
+ expect(result).toContainEqual(sibling);
294
+ expect(result).toHaveLength(2);
295
+ });
296
+
297
+ test("replaces a stale same-name entry rather than duplicating it", () => {
298
+ const stale = { $: { "android:name": ASSET_STATEMENTS_RESOURCE_NAME, "android:value": "x" } };
299
+ const result = mergeAssetStatementsMetaData([stale]);
300
+ expect(result).toHaveLength(1);
301
+ expect(result[0]?.$["android:resource"]).toBe(`@string/${ASSET_STATEMENTS_RESOURCE_NAME}`);
302
+ });
303
+ });