@app-swiss-knife/react-native-sdk 0.1.1 → 0.2.1

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 (54) hide show
  1. package/README.md +51 -0
  2. package/SwissKnifePurchases.podspec +16 -1
  3. package/android/build.gradle +7 -0
  4. package/android/consumer-rules.pro +64 -0
  5. package/android/src/main/java/com/swissknife/purchases/Conversions.kt +85 -0
  6. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +37 -30
  7. package/android/vendor/java/com/appswissknife/SwissKnife.kt +219 -51
  8. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +177 -25
  9. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  10. package/android/vendor/java/com/appswissknife/identity/Identity.kt +15 -0
  11. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
  12. package/ios/SwissKnifePurchases.m +8 -0
  13. package/ios/SwissKnifePurchases.swift +35 -0
  14. package/ios/vendor/SwissKnifeiOS/Attribution/Attribution.swift +25 -7
  15. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  16. package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +8 -2
  17. package/ios/vendor/SwissKnifeiOS/Net/BackendHttpClient.swift +32 -1
  18. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +35 -5
  19. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +39 -22
  20. package/ios/vendor/SwissKnifeiOS/SwissKnife+DeviceID.swift +12 -2
  21. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +270 -32
  22. package/lib/commonjs/identity.js +59 -4
  23. package/lib/commonjs/identity.js.map +1 -1
  24. package/lib/commonjs/native/spec.js.map +1 -1
  25. package/lib/commonjs/purchases.js +95 -3
  26. package/lib/commonjs/purchases.js.map +1 -1
  27. package/lib/commonjs/types.js.map +1 -1
  28. package/lib/module/identity.js +59 -4
  29. package/lib/module/identity.js.map +1 -1
  30. package/lib/module/native/spec.js.map +1 -1
  31. package/lib/module/purchases.js +95 -3
  32. package/lib/module/purchases.js.map +1 -1
  33. package/lib/module/types.js.map +1 -1
  34. package/lib/typescript/commonjs/identity.d.ts +30 -4
  35. package/lib/typescript/commonjs/identity.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/native/spec.d.ts +27 -0
  37. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
  38. package/lib/typescript/commonjs/purchases.d.ts +46 -1
  39. package/lib/typescript/commonjs/purchases.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/types.d.ts +11 -2
  41. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  42. package/lib/typescript/module/identity.d.ts +30 -4
  43. package/lib/typescript/module/identity.d.ts.map +1 -1
  44. package/lib/typescript/module/native/spec.d.ts +27 -0
  45. package/lib/typescript/module/native/spec.d.ts.map +1 -1
  46. package/lib/typescript/module/purchases.d.ts +46 -1
  47. package/lib/typescript/module/purchases.d.ts.map +1 -1
  48. package/lib/typescript/module/types.d.ts +11 -2
  49. package/lib/typescript/module/types.d.ts.map +1 -1
  50. package/package.json +1 -1
  51. package/src/identity.ts +63 -4
  52. package/src/native/spec.ts +30 -0
  53. package/src/purchases.ts +103 -4
  54. package/src/types.ts +11 -2
@@ -29,7 +29,17 @@ public final class SwissKnife: NSObject {
29
29
  // MARK: State managed entirely by SwissKnife now (no more Purchases.shared)
30
30
 
31
31
  private let stateQueue = DispatchQueue(label: "com.swissknife.state")
32
+ /// The PURCHASE engine is live (StoreKit observer running, offerings
33
+ /// service wired). Set only by `configurePurchases(...)`.
32
34
  private var configured: Bool = false
35
+ /// The CORE (ingest / identity / attribution / attributes) is live. Set by
36
+ /// `configureCore(...)` and by `ensureObservabilityBackend(...)`.
37
+ ///
38
+ /// Split out from `configured` so an app can have identity + attribution +
39
+ /// analytics WITHOUT handing the SDK ownership of StoreKit. Hosts that keep
40
+ /// another IAP library (e.g. RevenueCat) cannot afford a second
41
+ /// `Transaction.updates` observer racing theirs on `transaction.finish()`.
42
+ private var coreConfigured: Bool = false
33
43
  private var configuredApiKey: String?
34
44
  private var configuredServerURL: String?
35
45
  private var currentAppUserID: String?
@@ -48,7 +58,21 @@ public final class SwissKnife: NSObject {
48
58
  // compile. New tests should use `Identity._setNetworkForTesting(...)`.
49
59
  internal var identityClient: IdentityClient = BackendHttpClientIdentityClient()
50
60
 
51
- /// Configure the SDK. After this returns:
61
+ /// Configure the WHOLE SDK — core (ingest / identity / attribution /
62
+ /// attributes) **and** the purchase engine (StoreKit 2).
63
+ ///
64
+ /// Exactly equivalent to `configureCore(...)` followed by
65
+ /// `configurePurchases(...)`, in that order, and kept bit-for-bit
66
+ /// behaviour-compatible with the pre-split entry point. Every existing
67
+ /// integration keeps working unchanged.
68
+ ///
69
+ /// **If your app already has another IAP library** (RevenueCat, StoreKit
70
+ /// wired by hand, …), call `configureCore(...)` instead: this method starts
71
+ /// a process-wide `StoreKit.Transaction.updates` observer that calls
72
+ /// `transaction.finish()`, which will race the other library's observer on
73
+ /// live renewals. `configureCore(...)` never touches StoreKit.
74
+ ///
75
+ /// After this returns:
52
76
  /// - The three services (entitlements, purchases, offerings) are wired
53
77
  /// with the proxyURL + apiKey.
54
78
  /// - The attributes client (Phase 3) is wired the same way.
@@ -70,23 +94,58 @@ public final class SwissKnife: NSObject {
70
94
  String(apiKey.prefix(8)),
71
95
  proxyURL ?? "nil"
72
96
  )
97
+ configureCore(
98
+ apiKey: apiKey,
99
+ appUserID: appUserID,
100
+ proxyURL: proxyURL,
101
+ logLevel: logLevel,
102
+ attribution: attribution
103
+ )
104
+ configurePurchases(
105
+ apiKey: apiKey,
106
+ appUserID: appUserID,
107
+ proxyURL: proxyURL,
108
+ storeKitVersion: storeKitVersion
109
+ )
110
+ }
111
+
112
+ /// Configure everything the SDK can do **without owning the store**:
113
+ /// analytics / crash / performance ingest, `SwissKnife.Identity`,
114
+ /// `SwissKnife.Attribution`, and the subscriber-attributes client.
115
+ ///
116
+ /// Guarantees — these are asserted by
117
+ /// `Tests/…/StoreOwnershipSeparationTests.swift`:
118
+ /// - **No StoreKit observer is started.** `PurchaseService` is not
119
+ /// configured, so `StoreKit.Transaction.updates` is never iterated and
120
+ /// `transaction.finish()` is never called by us. An app that keeps
121
+ /// RevenueCat (or its own StoreKit code) can adopt identity /
122
+ /// attribution / analytics with zero risk of two observers racing to
123
+ /// finish the same renewal.
124
+ /// - **No install is registered as a side effect.** Unlike
125
+ /// `configure(...)`, this does NOT honour
126
+ /// `Attribution.Configuration.sendInstallOnFirstLaunch` — see
127
+ /// `configurePurchases(...)` for where that moved and why. Hosts that
128
+ /// want the install POST from a core-only app call
129
+ /// `SwissKnife.Attribution.registerInstall(...)` (or
130
+ /// `requestTrackingAuthorizationAndRegister()`) explicitly.
131
+ ///
132
+ /// `attribution:` is still accepted here because the *configuration*
133
+ /// (`autoPromptATT`) is a core concern — it governs the explicit
134
+ /// registration calls above.
135
+ public static func configureCore(
136
+ apiKey: String,
137
+ appUserID: String? = nil,
138
+ proxyURL: String? = nil,
139
+ logLevel: String? = nil,
140
+ attribution: SwissKnife.Attribution.Configuration = .init()
141
+ ) {
142
+ precondition(!apiKey.isEmpty, "configureCore requires a non-empty apiKey")
73
143
 
74
144
  let level = logLevel.flatMap(parseLogLevel) ?? .warn
75
- let resolvedAppUserID: String
76
- let isAnonymous: Bool
77
- if let provided = appUserID, !provided.isEmpty {
78
- resolvedAppUserID = provided
79
- isAnonymous = false
80
- } else {
81
- // Anonymous flow: use the keychain-backed device id, prefixed
82
- // to match the convention upstream consumers grep for (similar
83
- // to RC's `$RCAnonymousID:` prefix but our own).
84
- resolvedAppUserID = "$SKAnonymousID:" + DeviceID.get()
85
- isAnonymous = true
86
- }
145
+ let (resolvedAppUserID, isAnonymous) = resolveConfiguredIdentity(appUserID)
87
146
 
88
147
  shared.stateQueue.sync {
89
- shared.configured = true
148
+ shared.coreConfigured = true
90
149
  shared.configuredApiKey = apiKey
91
150
  shared.configuredServerURL = proxyURL
92
151
  shared.currentAppUserID = resolvedAppUserID
@@ -98,11 +157,80 @@ public final class SwissKnife: NSObject {
98
157
  SwissKnife.Identity._seedConfiguredUser(isAnonymous ? nil : resolvedAppUserID)
99
158
 
100
159
  AttributesClient.shared.configure(serverURL: proxyURL, apiKey: apiKey)
160
+ // EntitlementsService is core, not store: it is a disk cache in front
161
+ // of `GET /api/sdk/entitlements/list` and imports no StoreKit. It lives
162
+ // here because `Identity.logIn/logOut` re-key and refresh it, so an
163
+ // analytics-only app still needs it wired for identity to work.
164
+ EntitlementsService.shared.configure(
165
+ serverURL: proxyURL,
166
+ apiKey: apiKey,
167
+ userId: resolvedAppUserID
168
+ )
169
+ // Snapshot only — the auto-install POST is deliberately NOT triggered
170
+ // from core (see the doc comment above).
171
+ SwissKnife.Attribution._configureCore(attribution)
101
172
  os_log(
102
- "SwissKnife.configure wired AttributesClient",
173
+ "SwissKnife.configureCore wired AttributesClient + Identity + Attribution",
103
174
  log: shared.log,
104
175
  type: .info
105
176
  )
177
+
178
+ // Round A — wire cross-cutting context observers (Session ← AppLifecycle,
179
+ // IngestClient ← Reachability + AppLifecycle). Extracted into
180
+ // `ensureObservabilityBackend` so observability can also be wired
181
+ // WITHOUT configure() / the purchase engine — see that method. The
182
+ // config seeding inside is a no-op here because `coreConfigured` is
183
+ // already true by this point, so configureCore's apiKey/serverURL stand.
184
+ ensureObservabilityBackend(apiKey: apiKey, serverURL: proxyURL)
185
+ }
186
+
187
+ /// Configure the purchase engine: StoreKit 2 transaction observation,
188
+ /// purchases / restore, and the offerings catalog.
189
+ ///
190
+ /// **This is the call that starts the process-wide
191
+ /// `StoreKit.Transaction.updates` listener** (via
192
+ /// `PurchaseService.configure`). Its handler calls `transaction.finish()`,
193
+ /// so do not call this in an app that lets another library own StoreKit.
194
+ ///
195
+ /// Also the home of `Attribution.Configuration.sendInstallOnFirstLaunch`.
196
+ /// Rationale: install→campaign resolution exists to attribute *revenue*,
197
+ /// so it belongs with the revenue engine; and keeping it here makes
198
+ /// `configure()` an exact composition of the two halves, so no existing
199
+ /// integration loses the install event. A core-only app registers installs
200
+ /// explicitly via `SwissKnife.Attribution.registerInstall(...)`.
201
+ ///
202
+ /// Safe to call without `configureCore(...)` — it seeds the backend config
203
+ /// itself in that case — but the normal shape is core first.
204
+ public static func configurePurchases(
205
+ apiKey: String,
206
+ appUserID: String? = nil,
207
+ proxyURL: String? = nil,
208
+ storeKitVersion: String = "DEFAULT"
209
+ ) {
210
+ precondition(!apiKey.isEmpty, "configurePurchases requires a non-empty apiKey")
211
+ os_log(
212
+ "SwissKnife.configurePurchases called (apiKey prefix %{public}@…, proxyURL %{public}@)",
213
+ log: shared.log,
214
+ type: .info,
215
+ String(apiKey.prefix(8)),
216
+ proxyURL ?? "nil"
217
+ )
218
+
219
+ let (resolvedAppUserID, isAnonymous) = resolveConfiguredIdentity(appUserID)
220
+ shared.stateQueue.sync {
221
+ shared.configured = true
222
+ // Purchases-without-core is a supported (if unusual) shape — seed
223
+ // the backend config so the validate POST can authenticate. When
224
+ // core already ran, its values are authoritative and left alone.
225
+ if !shared.coreConfigured {
226
+ shared.configuredApiKey = apiKey
227
+ shared.configuredServerURL = proxyURL
228
+ shared.currentAppUserID = resolvedAppUserID
229
+ shared.currentIsAnonymous = isAnonymous
230
+ }
231
+ }
232
+
233
+ // Idempotent when core already configured it with the same values.
106
234
  EntitlementsService.shared.configure(
107
235
  serverURL: proxyURL,
108
236
  apiKey: apiKey,
@@ -118,19 +246,22 @@ public final class SwissKnife: NSObject {
118
246
  // parameter so existing call sites compile.
119
247
  _ = storeKitVersion
120
248
 
121
- // Wave 2 — wire the Attribution module so the first launch
122
- // auto-registers the install (and optionally shows the ATT
123
- // prompt). Fire-and-forget — configure(...) does not block on
124
- // the network call.
125
- SwissKnife.Attribution._configure(attribution)
249
+ // Wave 2 — first launch auto-registers the install (and optionally
250
+ // shows the ATT prompt). Fire-and-forget; never blocks configure.
251
+ SwissKnife.Attribution._sendInstallOnFirstLaunchIfEnabled()
252
+ }
126
253
 
127
- // Round A — wire cross-cutting context observers (Session ← AppLifecycle,
128
- // IngestClient ← Reachability + AppLifecycle). Extracted into
129
- // `ensureObservabilityBackend` so observability can also be wired
130
- // WITHOUT configure() / the purchase engine — see that method. The
131
- // config seeding inside is a no-op here because `configured` is
132
- // already true by this point, so configure's apiKey/serverURL stand.
133
- ensureObservabilityBackend(apiKey: apiKey, serverURL: proxyURL)
254
+ /// Resolve `(appUserID, isAnonymous)` the way both configure entry points
255
+ /// need it. Anonymous flow uses the keychain-backed device id, prefixed to
256
+ /// match the convention upstream consumers grep for (similar to RC's
257
+ /// `$RCAnonymousID:` prefix but our own).
258
+ private static func resolveConfiguredIdentity(
259
+ _ appUserID: String?
260
+ ) -> (resolved: String, isAnonymous: Bool) {
261
+ if let provided = appUserID, !provided.isEmpty {
262
+ return (provided, false)
263
+ }
264
+ return ("$SKAnonymousID:" + DeviceID.get(), true)
134
265
  }
135
266
 
136
267
  /// Wire the observability backend (analytics / crash / performance ingest)
@@ -147,6 +278,12 @@ public final class SwissKnife: NSObject {
147
278
  ///
148
279
  /// Semantics (identical on both platforms — keep them in lockstep):
149
280
  ///
281
+ /// - **It marks CORE configured, never purchases.** The seeded apiKey +
282
+ /// server URL are exactly what `SwissKnife.Identity` and
283
+ /// `SwissKnife.Attribution` need, so an analytics-only app gets working
284
+ /// identity and attribution from this one call —
285
+ /// `SwissKnife.isCoreConfigured` flips to `true`, `SwissKnife.isConfigured`
286
+ /// (the purchase engine) stays `false`, and no StoreKit observer starts.
150
287
  /// - **`configure(...)` is authoritative, regardless of call order.** It
151
288
  /// always writes `configuredApiKey`/`configuredServerURL`; this method
152
289
  /// only *seeds* them while the SDK is unconfigured. So
@@ -189,20 +326,44 @@ public final class SwissKnife: NSObject {
189
326
  return trimmed.isEmpty ? nil : trimmed
190
327
  }()
191
328
 
329
+ // Computed outside the lock — DeviceID.get() hits the Keychain.
330
+ let anonymousFallbackId = "$SKAnonymousID:" + DeviceID.get()
331
+
332
+ var seededCore = false
192
333
  let shouldWire: Bool = shared.stateQueue.sync {
193
334
  if shared.observabilityWired { return false }
194
335
  shared.observabilityWired = true
195
- if !shared.configured {
336
+ if !shared.coreConfigured {
196
337
  // Unconfigured: seed the shared backend config so
197
- // BackendHttpClient can authenticate. A later `configure(...)`
198
- // overwrites both fields unconditionally.
338
+ // BackendHttpClient can authenticate — and mark CORE as
339
+ // configured, which is what Identity/Attribution gate on. A
340
+ // later `configureCore(...)` overwrites both fields
341
+ // unconditionally. Purchases stay untouched: no StoreKit.
342
+ shared.coreConfigured = true
199
343
  shared.configuredApiKey = apiKey
200
344
  shared.configuredServerURL = normalizedServerURL
345
+ if shared.currentAppUserID == nil {
346
+ shared.currentAppUserID = anonymousFallbackId
347
+ shared.currentIsAnonymous = true
348
+ }
349
+ seededCore = true
201
350
  }
202
351
  return true
203
352
  }
204
353
  guard shouldWire else { return }
205
354
 
355
+ if seededCore {
356
+ // Give Identity/attributes the same backend coordinates the ingest
357
+ // path just got, so `Identity.logIn(...)` and `setEmail(...)` work
358
+ // in an app that only ever called `Analytics.init`.
359
+ AttributesClient.shared.configure(serverURL: normalizedServerURL, apiKey: apiKey)
360
+ EntitlementsService.shared.configure(
361
+ serverURL: normalizedServerURL,
362
+ apiKey: apiKey,
363
+ userId: anonymousFallbackId
364
+ )
365
+ }
366
+
206
367
  os_log(
207
368
  "SwissKnife.ensureObservabilityBackend wired (apiKey prefix %{public}@…, serverURL %{public}@)",
208
369
  log: shared.log,
@@ -221,10 +382,27 @@ public final class SwissKnife: NSObject {
221
382
  }
222
383
  }
223
384
 
385
+ /// Whether the PURCHASE engine is configured (`configure(...)` or
386
+ /// `configurePurchases(...)` ran). Gates `getOfferings`, `purchase*`,
387
+ /// `restorePurchases`, and `getCustomerInfo`.
388
+ ///
389
+ /// Deliberately stays `false` for a core-only app — those APIs genuinely
390
+ /// cannot work without the store, and a host that keeps its own IAP layer
391
+ /// must be able to tell the two states apart.
224
392
  public static var isConfigured: Bool {
225
393
  shared.stateQueue.sync { shared.configured }
226
394
  }
227
395
 
396
+ /// Whether the CORE is configured — ingest, `SwissKnife.Identity`,
397
+ /// `SwissKnife.Attribution`, subscriber attributes.
398
+ ///
399
+ /// `true` after ANY of `configure(...)`, `configureCore(...)`, or
400
+ /// `ensureObservabilityBackend(...)`. This — not `isConfigured` — is what
401
+ /// identity and attribution gate on.
402
+ public static var isCoreConfigured: Bool {
403
+ shared.stateQueue.sync { shared.coreConfigured }
404
+ }
405
+
228
406
  /// Current app user id (identified or anonymous).
229
407
  ///
230
408
  /// Prefer `SwissKnife.Identity.current` for new code — the Identity
@@ -242,6 +420,62 @@ public final class SwissKnife: NSObject {
242
420
  shared.stateQueue.sync { shared.currentIsAnonymous }
243
421
  }
244
422
 
423
+ /// The **subject identifier** the backend keys rows against — the value
424
+ /// that goes into `user_id` on `POST /api/sdk/subscriptions/validate` and
425
+ /// `GET /api/sdk/entitlements/list`. Server-side it lands in
426
+ /// `subscriptions.app_user_id`, is joined against
427
+ /// `app_users.external_user_id`, and is rendered in the dashboard.
428
+ ///
429
+ /// **It must never be the bare `DeviceID`.** The device id is a
430
+ /// Keychain-backed, reinstall-surviving, non-syncable value that the
431
+ /// server's device-binding control treats as unguessable. Writing it into
432
+ /// a user-visible column destroys that assumption. Two call sites used to
433
+ /// fall back to `DeviceID.get()` when *their own* configure step had not
434
+ /// run:
435
+ ///
436
+ /// - `PurchaseService.validateTransactionWithBackend` — reachable via
437
+ /// `configurePurchases(...)` **without** `configureCore(...)`, which
438
+ /// is a documented, supported shape. `isCoreConfigured` stays false
439
+ /// there, so the old `appUserIDOrNil()` returned nil.
440
+ /// - `EntitlementsService.performRefresh` — defensive only today (every
441
+ /// configure path seeds a non-empty user id), but one bad
442
+ /// `setCurrentUser(nil)` away from being live.
443
+ ///
444
+ /// Resolution order, and why:
445
+ ///
446
+ /// 1. `currentAppUserID` — set by **every** configure entry point
447
+ /// (`configureCore`, `configurePurchases`,
448
+ /// `ensureObservabilityBackend`) to either the host-supplied
449
+ /// `appUserID` or `"$SKAnonymousID:" + DeviceID.get()`, and kept in
450
+ /// lockstep with `Identity` by `identityDidChangeTo*`. This is the
451
+ /// same value handed to `EntitlementsService.configure(userId:)`, so
452
+ /// preferring it is what makes `validate` and `entitlements/list`
453
+ /// agree on the subject — including in the purchases-without-core
454
+ /// shape, where they previously disagreed.
455
+ /// 2. The `Identity` snapshot — always well-defined even before any
456
+ /// `configure(...)`, and always prefixed.
457
+ ///
458
+ /// Deliberately does NOT gate on `isCoreConfigured`: there is never a
459
+ /// reason to reach past a well-defined prefixed identity for a weaker one.
460
+ ///
461
+ /// **Known residual exposure.** The anonymous form is
462
+ /// `"$SKAnonymousID:" + DeviceID.get()`, so the device UUID is still
463
+ /// recoverable from the stored subject by stripping the prefix. This
464
+ /// method stops the id from being written *naked* and makes the two
465
+ /// endpoints agree; it does not make the device id unrecoverable. That
466
+ /// needs an opaque derivation (per-install random, or a one-way hash),
467
+ /// which re-keys every existing anonymous install and so must ship with a
468
+ /// server-side alias/backfill. Pinned by
469
+ /// `BackendSubjectIdTests.test_anonymousSubject_stillEmbedsDeviceId_knownLimitation`.
470
+ internal static func backendSubjectId() -> String {
471
+ let configured = shared.stateQueue.sync { shared.currentAppUserID }
472
+ if let configured, !configured.isEmpty {
473
+ return configured
474
+ }
475
+ let snapshot = Identity.current
476
+ return snapshot.userId ?? snapshot.anonymousId
477
+ }
478
+
245
479
  // MARK: Reads / offerings (typed, async)
246
480
 
247
481
  public static func getCustomerInfo() async throws -> CustomerInfo {
@@ -350,6 +584,7 @@ public final class SwissKnife: NSObject {
350
584
  internal static func _dangerouslyResetConfigForTesting() {
351
585
  shared.stateQueue.sync {
352
586
  shared.configured = false
587
+ shared.coreConfigured = false
353
588
  shared.configuredApiKey = nil
354
589
  shared.configuredServerURL = nil
355
590
  shared.currentAppUserID = nil
@@ -417,13 +652,16 @@ public final class SwissKnife: NSObject {
417
652
  )
418
653
  }
419
654
 
655
+ // Attributes are a CORE concern (they describe the person, not the
656
+ // purchase), so these gate on `isCoreConfigured` — an analytics-only app
657
+ // can call `setEmail(...)` and have it land with the right ids.
420
658
  private static func currentAnonymousIdForAttributes() -> String? {
421
- guard isConfigured else { return nil }
659
+ guard isCoreConfigured else { return nil }
422
660
  return shared.stateQueue.sync { shared.currentAppUserID }
423
661
  }
424
662
 
425
663
  private static func currentExternalUserIdForAttributes() -> String? {
426
- guard isConfigured else { return nil }
664
+ guard isCoreConfigured else { return nil }
427
665
  return shared.stateQueue.sync {
428
666
  shared.currentIsAnonymous ? nil : shared.currentAppUserID
429
667
  }
@@ -34,6 +34,18 @@ var _module = require("./native/module.js");
34
34
 
35
35
  const observers = new Map();
36
36
  let lastSnapshot = null;
37
+
38
+ /**
39
+ * Result of the last `logIn` that actually reached native, so a repeat call
40
+ * with the same subject id can be answered without touching the bridge.
41
+ *
42
+ * Hosts are expected to call `logIn` on every app start and after every
43
+ * auth-state read — that is the correct usage, not a misuse — so the repeat
44
+ * case is the common case, and each one would otherwise cost a bridge hop
45
+ * plus a `/api/sdk/users/identify` round trip that can only ever conclude
46
+ * "nothing to merge".
47
+ */
48
+ let lastLogIn = null;
37
49
  function generateToken() {
38
50
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, c => {
39
51
  const r = Math.random() * 16 | 0;
@@ -77,18 +89,58 @@ const Identity = exports.Identity = {
77
89
  return current;
78
90
  },
79
91
  /**
80
- * Identify this device as a known user. Native posts the
81
- * `(anonymous_id, user_id)` pair to `/api/sdk/users/identify` (the
82
- * Wave 1 bug-fix; pre-Wave-1 Android did NOT post). Resolves once
83
- * the backend ack + post-identify entitlements refresh complete.
92
+ * Bind this device to a subject id.
93
+ *
94
+ * ## `logIn` does NOT mean "the human authenticated"
95
+ *
96
+ * The name is kept for RevenueCat parity, but the contract is narrower and
97
+ * more useful than the name suggests: it means *"from now on, this device's
98
+ * activity belongs to this subject id"*. Nothing about it asserts that a
99
+ * person proved who they are.
100
+ *
101
+ * It is therefore entirely legitimate — and often correct — to call this
102
+ * with an id that belongs to an anonymous subject. An app whose logged-out
103
+ * users are real rows in its own database (a deviceId-keyed row carrying
104
+ * progress and purchases) should pass that row's id here immediately, long
105
+ * before any sign-in. Doing so means the subsequent sign-in has a real
106
+ * previous subject to merge *from*, instead of stranding everything the
107
+ * person did while logged out.
108
+ *
109
+ * ## What happens on the wire
110
+ *
111
+ * Native posts the identifier pair to `/api/sdk/users/identify`, which
112
+ * re-points every row from the previous subject onto this one. That call
113
+ * either succeeds or rejects — a rejection means the device is identified
114
+ * locally but NOT merged server-side, so it must be retried rather than
115
+ * ignored. Resolves once the backend ack and the post-identify entitlements
116
+ * refresh complete.
117
+ *
118
+ * ## Repeat calls are free
119
+ *
120
+ * Calling this again with the id already in effect is a no-op: no bridge
121
+ * hop, no network request. Call it on every app start without a guard.
84
122
  */
85
123
  async logIn(userId) {
124
+ // Cheap no-op: the subject is already in effect for this process. Checked
125
+ // against the cached result AND the last known snapshot so a `logOut` /
126
+ // `reset` / `wipe` in between always forces a real call.
127
+ if (lastLogIn !== null && lastLogIn.userId === userId && lastSnapshot !== null && lastSnapshot.userId === userId && !lastSnapshot.isAnonymous) {
128
+ return lastLogIn.result;
129
+ }
86
130
  const result = await (0, _module.getNativeModule)().identityLogIn(userId);
131
+ // Only cache after native resolved. If the identify POST rejected, the
132
+ // throw propagates and nothing is cached, so the next call retries
133
+ // instead of silently reporting success for a merge that never happened.
134
+ lastLogIn = {
135
+ userId,
136
+ result
137
+ };
87
138
  await snapshotAndNotify("logIn");
88
139
  return result;
89
140
  },
90
141
  /** Revert to anonymous. DeviceID stays stable across logout. */
91
142
  async logOut() {
143
+ lastLogIn = null;
92
144
  await (0, _module.getNativeModule)().identityLogOut();
93
145
  await snapshotAndNotify("logOut");
94
146
  },
@@ -97,6 +149,7 @@ const Identity = exports.Identity = {
97
149
  * "switch test user" UX semantic.
98
150
  */
99
151
  async reset() {
152
+ lastLogIn = null;
100
153
  await (0, _module.getNativeModule)().identityReset();
101
154
  await snapshotAndNotify("reset");
102
155
  },
@@ -105,6 +158,7 @@ const Identity = exports.Identity = {
105
158
  * (Android) DeviceID. GDPR-delete / test-build cleanup.
106
159
  */
107
160
  async wipe() {
161
+ lastLogIn = null;
108
162
  await (0, _module.getNativeModule)().identityWipe();
109
163
  await snapshotAndNotify("wipe");
110
164
  },
@@ -120,6 +174,7 @@ const Identity = exports.Identity = {
120
174
  /** @internal Test seam — reset the cached snapshot + observers. */
121
175
  __resetForTests() {
122
176
  lastSnapshot = null;
177
+ lastLogIn = null;
123
178
  observers.clear();
124
179
  }
125
180
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_module","require","observers","Map","lastSnapshot","generateToken","replace","c","r","Math","random","v","toString","snapshotAndNotify","reason","previous","current","getNativeModule","identityCurrent","size","change","Promise","resolve","then","observer","values","e","console","warn","Identity","exports","logIn","userId","result","identityLogIn","logOut","identityLogOut","reset","identityReset","wipe","identityWipe","addObserver","block","token","set","removeObserver","delete","__resetForTests","clear"],"sourceRoot":"../../src","sources":["identity.ts"],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AA3BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAmB,CAAC;AAE7C,IAAIC,YAAqC,GAAG,IAAI;AAEhD,SAASC,aAAaA,CAAA,EAAW;EAC/B,OAAO,sCAAsC,CAACC,OAAO,CAAC,OAAO,EAAGC,CAAC,IAAK;IACpE,MAAMC,CAAC,GAAIC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAI,CAAC;IAClC,MAAMC,CAAC,GAAGJ,CAAC,KAAK,GAAG,GAAGC,CAAC,GAAIA,CAAC,GAAG,GAAG,GAAI,GAAG;IACzC,OAAOG,CAAC,CA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A,CAAA,EAAkB;IAC5B,MAAM,IAAAlB,uBAAe,EAAC,CAAC,CAACmB,cAAc,CAAC,CAAC;IACxC,MAAMvB,iBAAiB,CAAC,QAAQ,CAAC;EACnC,CAAC;EAED;AACF;AACA;AACA;EACE,MAAMwB,KAAKA,CAAA,EAAkB;IAC3B,MAAM,IAAApB,uBAAe,EAAC,CAAC,CAACqB,aAAa,CAAC,CAAC;IACvC,MAAMzB,iBAAiB,CAAC,OAAO,CAAC;EAClC,CAAC;EAED;AACF;AACA;AACA;EACE,MAAM0B,IAAIA,CAAA,EAAkB;IAC1B,MAAM,IAAAtB,uBAAe,EAAC,CAAC,CAACuB,YAAY,CAAC,CAAC;IACtC,MAAM3B,iBAAiB,CAAC,MAAM,CAAC;EACjC,CAAC;EAED;EACA4B,WAAWA,CAACC,KAAe,EAAU;IACnC,MAAMC,KAAK,GAAGtC,aAAa,CAAC,CAAC;IAC7BH,SAAS,CAAC0C,GAAG,CAACD,KAAK,EAAED,KAAK,CAAC;IAC3B,OAAOC,KAAK;EACd,CAAC;EAEDE,cAAcA,CAACF,KAAa,EAAQ;IAClCzC,SAAS,CAAC4C,MAAM,CAACH,KAAK,CAAC;EACzB,CAAC;EAED;EACAI,eAAeA,CAAA,EAAS;IACtB3C,YAAY,GAAG,IAAI;IACnBF,SAAS,CAAC8C,KAAK,CAAC,CAAC;EACnB;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_module","require","observers","Map","lastSnapshot","lastLogIn","generateToken","replace","c","r","Math","random","v","toString","snapshotAndNotify","reason","previous","current","getNativeModule","identityCurrent","size","change","Promise","resolve","then","observer","values","e","console","warn","Identity","exports","logIn","userId","isAnonymous","result","identityLogIn","logOut","identityLogOut","reset","identityReset","wipe","identityWipe","addObserver","block","token","set","removeObserver","delete","__resetForTests","clear"],"sourceRoot":"../../src","sources":["identity.ts"],"mappings":";;;;;;AA2BA,IAAAA,OAAA,GAAAC,OAAA;AA3BA;AACA;AACA;AACA;AACA;AACA;AAC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I;IAChB,MAAM,IAAAa,uBAAe,EAAC,CAAC,CAACsB,aAAa,CAAC,CAAC;IACvC,MAAM1B,iBAAiB,CAAC,OAAO,CAAC;EAClC,CAAC;EAED;AACF;AACA;AACA;EACE,MAAM2B,IAAIA,CAAA,EAAkB;IAC1BpC,SAAS,GAAG,IAAI;IAChB,MAAM,IAAAa,uBAAe,EAAC,CAAC,CAACwB,YAAY,CAAC,CAAC;IACtC,MAAM5B,iBAAiB,CAAC,MAAM,CAAC;EACjC,CAAC;EAED;EACA6B,WAAWA,CAACC,KAAe,EAAU;IACnC,MAAMC,KAAK,GAAGvC,aAAa,CAAC,CAAC;IAC7BJ,SAAS,CAAC4C,GAAG,CAACD,KAAK,EAAED,KAAK,CAAC;IAC3B,OAAOC,KAAK;EACd,CAAC;EAEDE,cAAcA,CAACF,KAAa,EAAQ;IAClC3C,SAAS,CAAC8C,MAAM,CAACH,KAAK,CAAC;EACzB,CAAC;EAED;EACAI,eAAeA,CAAA,EAAS;IACtB7C,YAAY,GAAG,IAAI;IACnBC,SAAS,GAAG,IAAI;IAChBH,SAAS,CAACgD,KAAK,CAAC,CAAC;EACnB;AACF,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["CUSTOMER_INFO_UPDATED_EVENT","exports"],"sourceRoot":"../../../src","sources":["native/spec.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;;AAkBA;AACO,MAAMA,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,+BAA+B;;AAE1E;AACA;AACA;;AA+IA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["CUSTOMER_INFO_UPDATED_EVENT","exports"],"sourceRoot":"../../../src","sources":["native/spec.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAaA;AACA;;AAkBA;AACO,MAAMA,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,+BAA+B;;AAE1E;AACA;AACA;;AA6KA;AACA","ignoreList":[]}
@@ -13,6 +13,32 @@ var _types = require("./types.js");
13
13
 
14
14
  let configured = false;
15
15
  let configuredApiKey = null;
16
+ let coreConfigured = false;
17
+
18
+ /**
19
+ * Read a boolean off the native module without ever letting a missing native
20
+ * module escape as an exception.
21
+ *
22
+ * `getNativeModule()` THROWS when the module is not linked (Expo Go, a bare RN
23
+ * app that skipped `pod install` / a Gradle sync, web) — precisely the state a
24
+ * developer is in while wiring the SDK up, and precisely when they are most
25
+ * likely to be calling one of these accessors to find out what is wrong. A
26
+ * boolean accessor rejecting with "native module is not linked" is a worse
27
+ * answer than `false`: an unlinked module cannot have configured anything, so
28
+ * `false` is not merely safe, it is correct.
29
+ *
30
+ * The `.catch` covers the adjacent case where the module IS linked but predates
31
+ * the method (JS upgraded without rebuilding the app) — same reasoning, same
32
+ * answer. Mirrors the tolerance `Analytics.init` already applies to
33
+ * `configureObservability`.
34
+ */
35
+ function nativeBoolean(read) {
36
+ try {
37
+ return Promise.resolve(read((0, _module.getNativeModule)())).catch(() => false);
38
+ } catch {
39
+ return Promise.resolve(false);
40
+ }
41
+ }
16
42
 
17
43
  // Maps a caller's listener fn to its native subscription so we can remove it.
18
44
  const customerInfoSubscriptions = new Map();
@@ -55,13 +81,78 @@ class Purchases {
55
81
  // Fire-and-forget: native configure resolves async but RC's configure is sync.
56
82
  void native.configure(nativeOptions);
57
83
  configured = true;
84
+ coreConfigured = true;
85
+ configuredApiKey = options.apiKey;
86
+ }
87
+
88
+ /**
89
+ * Configure everything EXCEPT the store: ingest, `Identity`, `Attribution`,
90
+ * subscriber attributes.
91
+ *
92
+ * Use this when another library already owns in-app purchases. `configure`
93
+ * starts a `StoreKit.Transaction.updates` observer on iOS (whose handler
94
+ * calls `transaction.finish()`) and builds a `BillingClient` on Android —
95
+ * both of which contend with an incumbent IAP SDK. `configureCore` creates
96
+ * neither, and registers no install as a side effect.
97
+ *
98
+ * Analytics-only apps don't even need this: `Analytics.init(...)` already
99
+ * wires core natively. Reach for `configureCore` when you want to pass an
100
+ * `appUserID`, an attribution configuration, or a log level up front.
101
+ */
102
+ static configureCore(options) {
103
+ if (coreConfigured && configuredApiKey === options.apiKey) return;
104
+ const native = (0, _module.getNativeModule)();
105
+ const nativeOptions = {
106
+ apiKey: options.apiKey,
107
+ appUserID: options.appUserID ?? null,
108
+ proxyURL: options.proxyURL ?? null,
109
+ diagnosticsEnabled: options.diagnosticsEnabled ?? false,
110
+ autoPromptATT: options.autoPromptATT,
111
+ // Forwarded but inert on this path — core never auto-registers an
112
+ // install. Kept on the payload so the same options object can be handed
113
+ // to `configure` later without surprises.
114
+ sendInstallOnFirstLaunch: options.sendInstallOnFirstLaunch,
115
+ logLevel: options.logLevel
116
+ };
117
+ void native.configureCore(nativeOptions);
118
+ coreConfigured = true;
58
119
  configuredApiKey = options.apiKey;
59
120
  }
60
121
 
61
- /** Whether the SDK has been configured. Delegates to native. */
122
+ /**
123
+ * Whether the PURCHASE engine has been configured — i.e. whether the store
124
+ * APIs (`getOfferings`, `purchasePackage`, `restorePurchases`, …) can work.
125
+ *
126
+ * **Native is the source of truth.** This does not consult the JS-side
127
+ * "configure was called" flag: a brownfield app can configure the SDK from
128
+ * native code, and `Purchases.configure` itself is fire-and-forget, so the
129
+ * JS flag is a request, not a fact.
130
+ *
131
+ * Never throws and never rejects. Resolves `false` when the native module is
132
+ * not linked — see {@link nativeBoolean}. Exactly the same failure semantics
133
+ * as {@link isCoreConfigured}; the two differ only in which native flag they
134
+ * report.
135
+ */
62
136
  static isConfigured() {
63
- if (!configured) return Promise.resolve(false);
64
- return (0, _module.getNativeModule)().isConfigured();
137
+ return nativeBoolean(native => native.isConfigured());
138
+ }
139
+
140
+ /**
141
+ * Whether the CORE (ingest / Identity / Attribution / attributes) is
142
+ * configured. True after `configure`, `configureCore`, or `Analytics.init`.
143
+ *
144
+ * **Native is the source of truth**, and here that is load-bearing rather
145
+ * than merely principled: `Analytics.init` wires core natively via
146
+ * `configureObservability` and touches no JS configure flag, so an
147
+ * analytics-only app has core configured while every JS flag reads false.
148
+ * Short-circuiting on JS state would report `false` in the single most
149
+ * common core-only integration.
150
+ *
151
+ * Never throws and never rejects. Resolves `false` when the native module is
152
+ * not linked — see {@link nativeBoolean}.
153
+ */
154
+ static isCoreConfigured() {
155
+ return nativeBoolean(native => native.isCoreConfigured());
65
156
  }
66
157
 
67
158
  /** Latest CustomerInfo (entitlements + subscriptions), computed server-side. */
@@ -183,6 +274,7 @@ class Purchases {
183
274
  /** @internal Test seam: reset singleton state between tests. */
184
275
  static __resetForTests() {
185
276
  configured = false;
277
+ coreConfigured = false;
186
278
  configuredApiKey = null;
187
279
  customerInfoSubscriptions.clear();
188
280
  }