@app-swiss-knife/react-native-sdk 0.2.5 → 0.2.7
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.
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +18 -1
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +53 -9
- package/ios/SwissKnifePurchases.swift +16 -1
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/lib/commonjs/purchases.js +195 -32
- package/lib/commonjs/purchases.js.map +1 -1
- package/lib/module/purchases.js +196 -33
- package/lib/module/purchases.js.map +1 -1
- package/lib/typescript/commonjs/purchases.d.ts +65 -13
- package/lib/typescript/commonjs/purchases.d.ts.map +1 -1
- package/lib/typescript/module/purchases.d.ts +65 -13
- package/lib/typescript/module/purchases.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/purchases.ts +196 -33
|
@@ -194,7 +194,24 @@ class SwissKnifePurchasesModule(
|
|
|
194
194
|
)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
// ----- Identity -----
|
|
197
|
+
// ----- Identity (legacy bridge methods — no longer called by our JS) -----
|
|
198
|
+
//
|
|
199
|
+
// `Purchases.logIn` / `logOut` / `getAppUserID` / `isAnonymous` in JS now
|
|
200
|
+
// delegate to the `Identity` module, which uses the `identity*` methods
|
|
201
|
+
// further down. These four stay on the spec because removing a method from
|
|
202
|
+
// the native-module contract breaks any app pinned to an older JS, but they
|
|
203
|
+
// are dead from this package's point of view.
|
|
204
|
+
//
|
|
205
|
+
// Do NOT re-point JS at them. They bottom out in the deprecated
|
|
206
|
+
// `SwissKnife.*` facades, which on THIS platform are not equivalent to the
|
|
207
|
+
// iOS ones: `SwissKnife.logOut` goes straight to the purchases gateway
|
|
208
|
+
// instead of `Identity.logOut`, and `SwissKnife.appUserID` /
|
|
209
|
+
// `SwissKnife.isAnonymous()` read gateway state — whose anonymous id is a
|
|
210
|
+
// fresh random UUID per process, not the DeviceID-derived
|
|
211
|
+
// `$SKAnonymousID:` subject `Identity.current()` reports, and which
|
|
212
|
+
// `Identity.reset()` / `Identity.wipe()` never clear. That split is what
|
|
213
|
+
// `packages/react-native-sdk/src/identity-parity.test.ts` exists to keep out
|
|
214
|
+
// of the JS surface.
|
|
198
215
|
|
|
199
216
|
@ReactMethod
|
|
200
217
|
fun logIn(appUserID: String, promise: Promise) {
|
|
@@ -42,7 +42,7 @@ internal object DeviceContextProvider {
|
|
|
42
42
|
* eventually inject this via `BuildConfig`, but for now keep it in
|
|
43
43
|
* source so we don't have to thread build settings through every test.
|
|
44
44
|
*/
|
|
45
|
-
const val SDK_VERSION: String = "0.2.
|
|
45
|
+
const val SDK_VERSION: String = "0.2.7"
|
|
46
46
|
|
|
47
47
|
private val cacheLock = Any()
|
|
48
48
|
|
|
@@ -47,6 +47,7 @@ import com.appswissknife.StoreTransactionResult
|
|
|
47
47
|
import com.appswissknife.entitlements.EntitlementsRepository
|
|
48
48
|
import com.appswissknife.entitlements.SimpleCustomerInfo
|
|
49
49
|
import com.appswissknife.entitlements.SimpleEntitlementInfos
|
|
50
|
+
import com.appswissknife.identity.Identity
|
|
50
51
|
import com.appswissknife.models.CustomerInfo
|
|
51
52
|
import com.appswissknife.models.LogLevel
|
|
52
53
|
import com.appswissknife.models.Offerings
|
|
@@ -91,12 +92,19 @@ class BillingClientGateway(
|
|
|
91
92
|
@Volatile private var serverUrl: String = ""
|
|
92
93
|
@Volatile private var apiKey: String = ""
|
|
93
94
|
@Volatile private var explicitAppUserId: String? = null
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Last-resort anonymous subject.
|
|
98
|
+
*
|
|
99
|
+
* Used ONLY when [Identity] has no application context yet — i.e. a
|
|
100
|
+
* purchase or entitlement check attempted before `SwissKnife.configure`.
|
|
101
|
+
* It is minted per process and never persisted, so it is not a stable
|
|
102
|
+
* identity and anything keyed on it is unreachable after the process
|
|
103
|
+
* dies. That is precisely why it must not be the normal path; see
|
|
104
|
+
* [getAppUserID].
|
|
105
|
+
*/
|
|
106
|
+
@Volatile private var fallbackAnonymousAppUserId: String =
|
|
107
|
+
"\$SKAnonymousID:${UUID.randomUUID().toString().replace("-", "")}"
|
|
100
108
|
|
|
101
109
|
private val configured = AtomicBoolean(false)
|
|
102
110
|
private val reconnectAttempt = AtomicInteger(0)
|
|
@@ -172,9 +180,39 @@ class BillingClientGateway(
|
|
|
172
180
|
|
|
173
181
|
override fun isConfigured(): Boolean = configured.get()
|
|
174
182
|
|
|
175
|
-
|
|
183
|
+
/**
|
|
184
|
+
* The subject the backend keys purchases and entitlements on.
|
|
185
|
+
*
|
|
186
|
+
* Mirrors iOS `SwissKnife.backendSubjectId()`: an explicit id wins,
|
|
187
|
+
* otherwise the [Identity] snapshot.
|
|
188
|
+
*
|
|
189
|
+
* **Why this is not a random UUID any more.** The anonymous branch used to
|
|
190
|
+
* return `"${'$'}SKAnonymousID:" + UUID.randomUUID()`, minted once per
|
|
191
|
+
* process in a field initializer and never persisted, while
|
|
192
|
+
* `Identity.current()` — and therefore the `/api/sdk/users/identify` POST —
|
|
193
|
+
* reported `"${'$'}SKAnonymousID:" + DeviceID.get(ctx)` from
|
|
194
|
+
* EncryptedSharedPreferences. Android was posting two different subjects for
|
|
195
|
+
* the same anonymous person: one on `validate`/entitlements, another on
|
|
196
|
+
* `identify`. The merge looked for rows under the id it was told about and
|
|
197
|
+
* found none, so an anonymous purchase never followed the user into their
|
|
198
|
+
* account. iOS never had this half of the bug because both paths already
|
|
199
|
+
* went through `backendSubjectId()`.
|
|
200
|
+
*/
|
|
201
|
+
override fun getAppUserID(): String {
|
|
202
|
+
explicitAppUserId?.takeIf { it.isNotEmpty() }?.let { return it }
|
|
203
|
+
val snapshot = Identity.current()
|
|
204
|
+
val fromIdentity = snapshot.userId ?: snapshot.anonymousId
|
|
205
|
+
return fromIdentity.takeIf { it.isNotEmpty() } ?: fallbackAnonymousAppUserId
|
|
206
|
+
}
|
|
176
207
|
|
|
177
|
-
|
|
208
|
+
/**
|
|
209
|
+
* Anonymous iff neither this gateway nor [Identity] holds an explicit user.
|
|
210
|
+
* Consulting Identity too keeps this consistent with [getAppUserID] — a
|
|
211
|
+
* host that identified through `Identity.logIn` directly must not be
|
|
212
|
+
* reported as anonymous while its subject is a real user id.
|
|
213
|
+
*/
|
|
214
|
+
override fun isAnonymous(): Boolean =
|
|
215
|
+
explicitAppUserId == null && Identity.current().userId == null
|
|
178
216
|
|
|
179
217
|
override fun getCustomerInfo(
|
|
180
218
|
onSuccess: (CustomerInfo) -> Unit,
|
|
@@ -342,7 +380,13 @@ class BillingClientGateway(
|
|
|
342
380
|
return
|
|
343
381
|
}
|
|
344
382
|
explicitAppUserId = null
|
|
345
|
-
|
|
383
|
+
// Rotates the pre-configure fallback only. The real post-logout subject
|
|
384
|
+
// comes from `Identity`, whose DeviceID deliberately survives logout so
|
|
385
|
+
// analytics stay continuous for the same physical install — same as iOS,
|
|
386
|
+
// where logOut also returns to the stable device anonymous id rather than
|
|
387
|
+
// inventing a new one.
|
|
388
|
+
fallbackAnonymousAppUserId =
|
|
389
|
+
"\$SKAnonymousID:${UUID.randomUUID().toString().replace("-", "")}"
|
|
346
390
|
val repo = entitlementsRepo
|
|
347
391
|
repo?.invalidate()
|
|
348
392
|
onSuccess(emptyCustomerInfo())
|
|
@@ -246,7 +246,22 @@ class SwissKnifePurchases: RCTEventEmitter {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
// MARK: Identity
|
|
249
|
+
// MARK: Identity (legacy bridge methods — no longer called by our JS)
|
|
250
|
+
//
|
|
251
|
+
// `Purchases.logIn` / `logOut` / `getAppUserID` / `isAnonymous` in JS now
|
|
252
|
+
// delegate to the `Identity` module, which uses the `identity*` methods
|
|
253
|
+
// further down. These four stay on the spec because removing a method from
|
|
254
|
+
// the native-module contract breaks any app pinned to an older JS, but they
|
|
255
|
+
// are dead from this package's point of view.
|
|
256
|
+
//
|
|
257
|
+
// Do NOT re-point JS at them. They bottom out in the deprecated
|
|
258
|
+
// `SwissKnife.*` facades, and those facades are not equivalent across
|
|
259
|
+
// platforms: Android's `SwissKnife.logOut` bypasses `Identity.logOut` for
|
|
260
|
+
// the purchases gateway, and its `appUserID` / `isAnonymous` read gateway
|
|
261
|
+
// state whose anonymous id is a per-process random UUID rather than the
|
|
262
|
+
// DeviceID-derived `$SKAnonymousID:` subject this side reports. That split
|
|
263
|
+
// is what `packages/react-native-sdk/src/identity-parity.test.ts` exists to
|
|
264
|
+
// keep out of the JS surface.
|
|
250
265
|
|
|
251
266
|
@objc(logIn:resolver:rejecter:)
|
|
252
267
|
func logIn(_ appUserID: String,
|
|
@@ -99,7 +99,7 @@ internal enum DeviceContextProvider {
|
|
|
99
99
|
/// Round A baseline. The build pipeline (`swiss-build`) will eventually
|
|
100
100
|
/// inject this via `-D` flag, but for now keep it in source so we don't
|
|
101
101
|
/// have to thread build settings through the SPM Package.swift.
|
|
102
|
-
static let sdkVersionConstant: String = "0.2.
|
|
102
|
+
static let sdkVersionConstant: String = "0.2.7"
|
|
103
103
|
|
|
104
104
|
private static let cacheLock = DispatchQueue(label: "com.swissknife.context.device")
|
|
105
105
|
private static var cached: DeviceContext?
|
|
@@ -7,6 +7,7 @@ exports.Purchases = void 0;
|
|
|
7
7
|
exports.__throwIfCoreNotConfigured = throwIfCoreNotConfigured;
|
|
8
8
|
exports.__throwIfNotConfigured = throwIfNotConfigured;
|
|
9
9
|
exports.default = void 0;
|
|
10
|
+
var _identity = require("./identity.js");
|
|
10
11
|
var _module = require("./native/module.js");
|
|
11
12
|
var _spec = require("./native/spec.js");
|
|
12
13
|
var _types = require("./types.js");
|
|
@@ -45,9 +46,14 @@ function nativeBoolean(read) {
|
|
|
45
46
|
const customerInfoSubscriptions = new Map();
|
|
46
47
|
|
|
47
48
|
/**
|
|
48
|
-
* Guard for surfaces that genuinely need the PURCHASE engine —
|
|
49
|
-
*
|
|
50
|
-
*
|
|
49
|
+
* Guard for surfaces that genuinely need the PURCHASE engine — `getOfferings`,
|
|
50
|
+
* `purchasePackage`, `restorePurchases` and friends. Checks the JS "configure
|
|
51
|
+
* was called" flag.
|
|
52
|
+
*
|
|
53
|
+
* The RC-parity identity aliases used to sit here too, on the grounds that the
|
|
54
|
+
* legacy native bridge methods they called meant different things on iOS and
|
|
55
|
+
* Android. They now delegate to `Identity` and sit on
|
|
56
|
+
* {@link throwIfCoreNotConfigured} — see the block above `logIn`.
|
|
51
57
|
*/
|
|
52
58
|
function throwIfNotConfigured() {
|
|
53
59
|
if (!configured) {
|
|
@@ -86,6 +92,66 @@ async function throwIfCoreNotConfigured() {
|
|
|
86
92
|
throw new _types.UninitializedPurchasesError("Purchases core is not configured. Call Purchases.configure(), " + "Purchases.configureCore(), or Analytics.init() first.");
|
|
87
93
|
}
|
|
88
94
|
|
|
95
|
+
/**
|
|
96
|
+
* The `CustomerInfo` RC's `logOut()` resolves with, for a device that just
|
|
97
|
+
* became anonymous.
|
|
98
|
+
*
|
|
99
|
+
* The store engine is the preferred source, so an app that owns the store
|
|
100
|
+
* keeps getting real post-logout state. Whether it can answer is decided by
|
|
101
|
+
* `isConfigured()` — native truth on both platforms — rather than by trying
|
|
102
|
+
* the read and interpreting the failure, because an *unconfigured* store does
|
|
103
|
+
* not fail the same way on the two platforms: iOS rejects `getCustomerInfo`
|
|
104
|
+
* with `notConfigured`, Android's unconfigured gateway resolves an empty
|
|
105
|
+
* record of its own construction. Discovering the state from the error would
|
|
106
|
+
* hand back two different objects for one situation, in the very module that
|
|
107
|
+
* exists to stop that happening.
|
|
108
|
+
*
|
|
109
|
+
* With no store engine — or with one that cannot answer right now (cold cache
|
|
110
|
+
* plus offline) — the caller gets the entitlement-free record below, built in
|
|
111
|
+
* JS so it is identical on both platforms. Logging out is not a store
|
|
112
|
+
* operation and must not fail because the store is unreachable.
|
|
113
|
+
*/
|
|
114
|
+
async function customerInfoAfterLogOut() {
|
|
115
|
+
if (await nativeBoolean(native => native.isConfigured())) {
|
|
116
|
+
try {
|
|
117
|
+
return await (0, _module.getNativeModule)().getCustomerInfo();
|
|
118
|
+
} catch {
|
|
119
|
+
// Fall through to the empty record.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const snapshot = await _identity.Identity.current();
|
|
123
|
+
return emptyCustomerInfo(snapshot.userId ?? snapshot.anonymousId);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** An entitlement-free `CustomerInfo` for `subjectId`. Mirrors the native
|
|
127
|
+
* `CustomerInfo.empty(originalAppUserId:)` constructors. */
|
|
128
|
+
function emptyCustomerInfo(subjectId) {
|
|
129
|
+
const now = new Date();
|
|
130
|
+
return {
|
|
131
|
+
entitlements: {
|
|
132
|
+
all: {},
|
|
133
|
+
active: {},
|
|
134
|
+
verification: _types.VERIFICATION_RESULT.NOT_REQUESTED
|
|
135
|
+
},
|
|
136
|
+
activeSubscriptions: [],
|
|
137
|
+
allPurchasedProductIdentifiers: [],
|
|
138
|
+
allPurchaseDates: {},
|
|
139
|
+
subscriptionsByProductIdentifier: {},
|
|
140
|
+
nonSubscriptionTransactions: [],
|
|
141
|
+
firstSeen: now.toISOString(),
|
|
142
|
+
firstSeenMillis: now.getTime(),
|
|
143
|
+
originalAppUserId: subjectId,
|
|
144
|
+
requestDate: now.toISOString(),
|
|
145
|
+
requestDateMillis: now.getTime(),
|
|
146
|
+
latestExpirationDate: null,
|
|
147
|
+
latestExpirationDateMillis: null,
|
|
148
|
+
originalPurchaseDate: null,
|
|
149
|
+
originalPurchaseDateMillis: null,
|
|
150
|
+
originalApplicationVersion: null,
|
|
151
|
+
managementURL: null
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
89
155
|
/**
|
|
90
156
|
* RC-compatible subscriptions SDK entry point. Process-wide singleton; call
|
|
91
157
|
* `Purchases.configure(...)` once at app start, then use the static methods.
|
|
@@ -224,51 +290,140 @@ class Purchases {
|
|
|
224
290
|
return (0, _module.getNativeModule)().restorePurchases();
|
|
225
291
|
}
|
|
226
292
|
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
-
//
|
|
232
|
-
//
|
|
233
|
-
//
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
// Identity on
|
|
293
|
+
// MARK: - RC-parity identity aliases
|
|
294
|
+
//
|
|
295
|
+
// ## The guarantee
|
|
296
|
+
//
|
|
297
|
+
// Each of the four aliases below is *exactly* its {@link Identity}
|
|
298
|
+
// counterpart with the RevenueCat name and the RevenueCat return type, on
|
|
299
|
+
// BOTH platforms. There is no per-platform behaviour left in them: they are
|
|
300
|
+
// one-line delegations to `Identity`, which reaches the `identityLogIn` /
|
|
301
|
+
// `identityLogOut` / `identityCurrent` native bridge methods — and those go
|
|
302
|
+
// to the unified native `Identity` (`SwissKnife.Identity` on iOS,
|
|
303
|
+
// `com.appswissknife.identity.Identity` on Android) on both. Concretely, a
|
|
304
|
+
// `Purchases.logIn(...)` POSTs `/api/sdk/users/identify` on iOS AND on
|
|
305
|
+
// Android. Pinned by `identity-parity.test.ts`.
|
|
306
|
+
//
|
|
307
|
+
// ## Why they are written as delegations rather than bridge calls
|
|
308
|
+
//
|
|
309
|
+
// They used to call the legacy `logIn` / `logOut` / `getAppUserID` /
|
|
310
|
+
// `isAnonymous` bridge methods, which bottom out in the *deprecated native
|
|
311
|
+
// facades* — and those facades do NOT agree across platforms:
|
|
312
|
+
//
|
|
313
|
+
// - `logOut`: iOS `SwissKnife.logOut` routes to `Identity.logOut`;
|
|
314
|
+
// Android's routes straight to the purchases `gateway` and only
|
|
315
|
+
// back-syncs Identity's snapshot afterwards.
|
|
316
|
+
// - `getAppUserID`: iOS returns the Identity-synced subject (a stable
|
|
317
|
+
// `$SKAnonymousID:`+DeviceID value when anonymous); Android returns
|
|
318
|
+
// `gateway.getAppUserID()`, whose anonymous form is a fresh random UUID
|
|
319
|
+
// minted per process and unrelated to `Identity.current().anonymousId`.
|
|
320
|
+
// - `isAnonymous`: iOS reads Identity-synced state; Android reads the
|
|
321
|
+
// gateway's, which `Identity.reset()` / `Identity.wipe()` never touch.
|
|
322
|
+
//
|
|
323
|
+
// Delegating in JS makes the RN surface immune to all of that, and it is the
|
|
324
|
+
// only version of the fix that is verifiable from this repo's test suites.
|
|
325
|
+
// The legacy bridge methods stay on the native-module spec (removing them
|
|
326
|
+
// would break the native contract) but nothing in this package calls them
|
|
327
|
+
// any more.
|
|
328
|
+
//
|
|
329
|
+
// ## Second bug this closes
|
|
330
|
+
//
|
|
331
|
+
// `Identity` keeps JS-side caches (`lastSnapshot`, `lastLogIn`) that let a
|
|
332
|
+
// repeat `Identity.logIn(sameId)` skip the bridge. An alias that mutated
|
|
333
|
+
// native identity behind `Identity`'s back left those caches describing a
|
|
334
|
+
// world that no longer existed — after `Identity.logIn("u")` +
|
|
335
|
+
// `Purchases.logOut()`, a following `Identity.logIn("u")` short-circuited on
|
|
336
|
+
// the stale cache and resolved "logged in" without the device ever being
|
|
337
|
+
// re-identified. Routing through `Identity` means one owner for that state.
|
|
338
|
+
//
|
|
339
|
+
// ## The guard
|
|
340
|
+
//
|
|
341
|
+
// These sit on {@link throwIfCoreNotConfigured}, not on the purchase guard.
|
|
342
|
+
// Identity is a core capability — natively both platforms gate it on
|
|
343
|
+
// `isCoreConfigured` — and the single most likely caller of
|
|
344
|
+
// `Purchases.logIn` is an app migrating off RevenueCat that still lets
|
|
345
|
+
// RevenueCat own the store, i.e. one that called `configureCore`. Gating the
|
|
346
|
+
// RC-named alias on the purchase engine would reject exactly that app while
|
|
347
|
+
// the identical `Identity.logIn` call succeeded. The guard is not dropped
|
|
348
|
+
// entirely, because `Identity.current()` before any configure returns a
|
|
349
|
+
// real snapshot on iOS and a `{anonymousId: ""}` placeholder on Android —
|
|
350
|
+
// requiring core is what makes even that case agree.
|
|
238
351
|
|
|
239
352
|
/**
|
|
240
|
-
* Identify the user
|
|
353
|
+
* Identify the user, merging the anonymous subject into `appUserID`
|
|
354
|
+
* server-side.
|
|
355
|
+
*
|
|
356
|
+
* Exactly `Identity.logIn(appUserID)` with the RevenueCat name. On both
|
|
357
|
+
* platforms this POSTs `(anonymous_id, user_id)` to
|
|
358
|
+
* `/api/sdk/users/identify` and resolves once the backend ack and the
|
|
359
|
+
* post-identify entitlements refresh complete; a rejection means the device
|
|
360
|
+
* is NOT merged server-side and the call must be retried. Repeat calls with
|
|
361
|
+
* the id already in effect are free (no bridge hop, no request).
|
|
362
|
+
*
|
|
363
|
+
* Works after `Purchases.configure`, `Purchases.configureCore`, or
|
|
364
|
+
* `Analytics.init` — the store does not have to be ours.
|
|
241
365
|
*
|
|
242
|
-
* @deprecated Wave 1 — prefer `Identity.logIn(userId)`.
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* `Identity.logIn(...)`.
|
|
366
|
+
* @deprecated Wave 1 — prefer `Identity.logIn(userId)`. This alias exists so
|
|
367
|
+
* RevenueCat migrations compile unchanged; it is a pure delegation, so there
|
|
368
|
+
* is nothing to gain by keeping it and one less name to learn by dropping it.
|
|
246
369
|
*/
|
|
247
370
|
static async logIn(appUserID) {
|
|
248
|
-
|
|
249
|
-
return
|
|
371
|
+
await throwIfCoreNotConfigured();
|
|
372
|
+
return _identity.Identity.logIn(appUserID);
|
|
250
373
|
}
|
|
251
374
|
|
|
252
375
|
/**
|
|
253
|
-
* Log out the current user and revert to anonymous.
|
|
376
|
+
* Log out the current user and revert to anonymous. The device id survives,
|
|
377
|
+
* so analytics continuity for the same physical install is preserved.
|
|
254
378
|
*
|
|
255
|
-
*
|
|
379
|
+
* Exactly `Identity.logOut()` with the RevenueCat name, plus RC's
|
|
380
|
+
* `CustomerInfo` return: after the logout lands, the post-logout customer
|
|
381
|
+
* info is read back from the store engine. **When no store engine is
|
|
382
|
+
* configured** (`configureCore`, `Analytics.init`) there is nothing to read,
|
|
383
|
+
* and you get an entitlement-free `CustomerInfo` for the anonymous subject —
|
|
384
|
+
* the same record, built in JS, on both platforms. Do not read that as a
|
|
385
|
+
* store error; if you want real entitlements, call `getCustomerInfo()`.
|
|
386
|
+
*
|
|
387
|
+
* @deprecated Wave 1 — prefer `Identity.logOut()`, which does not pretend to
|
|
388
|
+
* return store state.
|
|
256
389
|
*/
|
|
257
390
|
static async logOut() {
|
|
258
|
-
|
|
259
|
-
|
|
391
|
+
await throwIfCoreNotConfigured();
|
|
392
|
+
await _identity.Identity.logOut();
|
|
393
|
+
return customerInfoAfterLogOut();
|
|
260
394
|
}
|
|
261
395
|
|
|
262
|
-
/**
|
|
396
|
+
/**
|
|
397
|
+
* The current subject id — the identified user id if there is one, else the
|
|
398
|
+
* SDK's anonymous id (`$SKAnonymousID:`-prefixed, stable across launches).
|
|
399
|
+
*
|
|
400
|
+
* Exactly `(await Identity.current()).userId ?? .anonymousId`. Note this is
|
|
401
|
+
* the *Identity* subject on both platforms; on Android the purchase
|
|
402
|
+
* gateway's own anonymous id is a different, per-process value, and this
|
|
403
|
+
* alias deliberately does not report it.
|
|
404
|
+
*
|
|
405
|
+
* @deprecated Wave 1 — prefer `Identity.current()`, which hands back the
|
|
406
|
+
* anonymous id, the user id and `isAnonymous` in one read instead of forcing
|
|
407
|
+
* two calls that can interleave.
|
|
408
|
+
*/
|
|
263
409
|
static async getAppUserID() {
|
|
264
|
-
|
|
265
|
-
|
|
410
|
+
await throwIfCoreNotConfigured();
|
|
411
|
+
const snapshot = await _identity.Identity.current();
|
|
412
|
+
return snapshot.userId ?? snapshot.anonymousId;
|
|
266
413
|
}
|
|
267
414
|
|
|
268
|
-
/**
|
|
415
|
+
/**
|
|
416
|
+
* Whether the current subject is the SDK-generated anonymous id.
|
|
417
|
+
*
|
|
418
|
+
* Exactly `(await Identity.current()).isAnonymous`, so it tracks
|
|
419
|
+
* `Identity.reset()` and `Identity.wipe()` on both platforms.
|
|
420
|
+
*
|
|
421
|
+
* @deprecated Wave 1 — prefer `Identity.current()`; see
|
|
422
|
+
* {@link getAppUserID}.
|
|
423
|
+
*/
|
|
269
424
|
static async isAnonymous() {
|
|
270
|
-
|
|
271
|
-
return (
|
|
425
|
+
await throwIfCoreNotConfigured();
|
|
426
|
+
return (await _identity.Identity.current()).isAnonymous;
|
|
272
427
|
}
|
|
273
428
|
|
|
274
429
|
// Subscriber attributes. CORE, not store — see {@link throwIfCoreNotConfigured}.
|
|
@@ -325,12 +480,20 @@ class Purchases {
|
|
|
325
480
|
}
|
|
326
481
|
}
|
|
327
482
|
|
|
328
|
-
/**
|
|
483
|
+
/**
|
|
484
|
+
* @internal Test seam: reset singleton state between tests.
|
|
485
|
+
*
|
|
486
|
+
* Also resets `Identity`'s caches, because the RC-parity aliases delegate
|
|
487
|
+
* there: without it, a `Purchases.logIn("u")` in one test would leave
|
|
488
|
+
* `Identity`'s `lastLogIn` primed and the next test's identical call would
|
|
489
|
+
* short-circuit before reaching the (freshly mocked) bridge.
|
|
490
|
+
*/
|
|
329
491
|
static __resetForTests() {
|
|
330
492
|
configured = false;
|
|
331
493
|
coreConfigured = false;
|
|
332
494
|
configuredApiKey = null;
|
|
333
495
|
customerInfoSubscriptions.clear();
|
|
496
|
+
_identity.Identity.__resetForTests();
|
|
334
497
|
}
|
|
335
498
|
}
|
|
336
499
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_identity","require","_module","_spec","_types","configured","configuredApiKey","coreConfigured","nativeBoolean","read","Promise","resolve","getNativeModule","catch","customerInfoSubscriptions","Map","throwIfNotConfigured","UninitializedPurchasesError","throwIfCoreNotConfigured","native","isCoreConfigured","customerInfoAfterLogOut","isConfigured","getCustomerInfo","snapshot","Identity","current","emptyCustomerInfo","userId","anonymousId","subjectId","now","Date","entitlements","all","active","verification","VERIFICATION_RESULT","NOT_REQUESTED","activeSubscriptions","allPurchasedProductIdentifiers","allPurchaseDates","subscriptionsByProductIdentifier","nonSubscriptionTransactions","firstSeen","toISOString","firstSeenMillis","getTime","originalAppUserId","requestDate","requestDateMillis","latestExpirationDate","latestExpirationDateMillis","originalPurchaseDate","originalPurchaseDateMillis","originalApplicationVersion","managementURL","Purchases","configure","options","apiKey","nativeOptions","appUserID","proxyURL","diagnosticsEnabled","storeKitVersion","useAmazon","autoPromptATT","sendInstallOnFirstLaunch","logLevel","configureCore","getOfferings","purchasePackage","pkg","offeringId","presentedOfferingContext","offeringIdentifier","identifier","purchaseStoreProduct","product","restorePurchases","logIn","logOut","getAppUserID","isAnonymous","setAttributes","attributes","setEmail","email","setDisplayName","displayName","setPhoneNumber","phoneNumber","setPushToken","pushToken","setLogLevel","level","addCustomerInfoUpdateListener","listener","sub","getEventEmitter","addListener","CUSTOMER_INFO_UPDATED_EVENT","event","set","removeCustomerInfoUpdateListener","get","remove","delete","__resetForTests","clear","exports","_default","default"],"sourceRoot":"../../src","sources":["purchases.ts"],"mappings":";;;;;;;;;AACA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAJA;;AAsBA,IAAII,UAAU,GAAG,KAAK;AACtB,IAAIC,gBAA+B,GAAG,IAAI;AAC1C,IAAIC,cAAc,GAAG,KAAK;;AAE1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,aAAaA,CACpBC,IAAmE,EACjD;EAClB,IAAI;IACF,OAAOC,OAAO,CAACC,OAAO,CAACF,IAAI,CAAC,IAAAG,uBAAe,EAAC,CAAC,CAAC,CAAC,CAACC,KAAK,CAAC,MAAM,KAAK,CAAC;EACpE,CAAC,CAAC,MAAM;IACN,OAAOH,OAAO,CAACC,OAAO,CAAC,KA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