@app-swiss-knife/react-native-sdk 0.2.7 → 0.3.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.
- package/README.md +100 -47
- package/SwissKnifePurchases.podspec +8 -5
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
- package/ios/SwissKnifeCrashReporting.swift +59 -18
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +51 -1
- package/ios/vendor/SwissKnifeiOS/DeviceID.swift +22 -1
- package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +105 -7
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +14 -0
- package/lib/commonjs/attributes.js +103 -0
- package/lib/commonjs/attributes.js.map +1 -0
- package/lib/commonjs/index.js +31 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/config.js +237 -0
- package/lib/commonjs/internal/config.js.map +1 -0
- package/lib/commonjs/purchases.js +152 -209
- package/lib/commonjs/purchases.js.map +1 -1
- package/lib/commonjs/swiss-knife.js +115 -0
- package/lib/commonjs/swiss-knife.js.map +1 -0
- package/lib/commonjs/types.js +11 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/attributes.js +100 -0
- package/lib/module/attributes.js.map +1 -0
- package/lib/module/index.js +19 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/config.js +225 -0
- package/lib/module/internal/config.js.map +1 -0
- package/lib/module/purchases.js +132 -198
- package/lib/module/purchases.js.map +1 -1
- package/lib/module/swiss-knife.js +112 -0
- package/lib/module/swiss-knife.js.map +1 -0
- package/lib/module/types.js +11 -0
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/attributes.d.ts +41 -0
- package/lib/typescript/commonjs/attributes.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/config.d.ts +121 -0
- package/lib/typescript/commonjs/internal/config.d.ts.map +1 -0
- package/lib/typescript/commonjs/purchases.d.ts +47 -91
- package/lib/typescript/commonjs/purchases.d.ts.map +1 -1
- package/lib/typescript/commonjs/swiss-knife.d.ts +56 -0
- package/lib/typescript/commonjs/swiss-knife.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +13 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/attributes.d.ts +41 -0
- package/lib/typescript/module/attributes.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/internal/config.d.ts +121 -0
- package/lib/typescript/module/internal/config.d.ts.map +1 -0
- package/lib/typescript/module/purchases.d.ts +47 -91
- package/lib/typescript/module/purchases.d.ts.map +1 -1
- package/lib/typescript/module/swiss-knife.d.ts +56 -0
- package/lib/typescript/module/swiss-knife.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +13 -0
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/attributes.ts +97 -0
- package/src/index.ts +19 -2
- package/src/internal/config.ts +233 -0
- package/src/purchases.ts +142 -213
- package/src/swiss-knife.ts +134 -0
- package/src/types.ts +14 -0
|
@@ -4,94 +4,74 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Purchases = void 0;
|
|
7
|
-
exports
|
|
8
|
-
|
|
7
|
+
Object.defineProperty(exports, "__throwIfCoreNotConfigured", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _config.throwIfCoreNotConfigured;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "__throwIfNotConfigured", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _config.throwIfNotConfigured;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
9
19
|
exports.default = void 0;
|
|
20
|
+
var _attributes = require("./attributes.js");
|
|
10
21
|
var _identity = require("./identity.js");
|
|
22
|
+
var _config = require("./internal/config.js");
|
|
11
23
|
var _module = require("./native/module.js");
|
|
12
24
|
var _spec = require("./native/spec.js");
|
|
13
25
|
var _types = require("./types.js");
|
|
14
26
|
// src/purchases.ts
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
//
|
|
28
|
+
// The RevenueCat-compatible surface. Everything a `react-native-purchases`
|
|
29
|
+
// migration can call, spelled the way RevenueCat spells it.
|
|
30
|
+
//
|
|
31
|
+
// ## What this file is, after the namespace split
|
|
32
|
+
//
|
|
33
|
+
// `Purchases` used to be the whole SDK: the store, both bootstraps, subscriber
|
|
34
|
+
// attributes and the identity aliases, twenty-one statics across four unrelated
|
|
35
|
+
// concerns — while `Identity`, `Attribution`, `Analytics`, `CrashReporting` and
|
|
36
|
+
// `Performance` sat beside it as peer namespaces. Two organising principles at
|
|
37
|
+
// once, and the seams showed: `Purchases.configureCore()` is a call whose entire
|
|
38
|
+
// meaning is "I do not want the store", and an app with no purchases in it set
|
|
39
|
+
// its user data through `Purchases.setAttributes`.
|
|
40
|
+
//
|
|
41
|
+
// The store methods below are the ones that genuinely belong here. The rest are
|
|
42
|
+
// **RC-compatibility aliases**, and they are not going anywhere:
|
|
43
|
+
//
|
|
44
|
+
// - bootstrap → `SwissKnife.configure` / `configureCore` / `isConfigured` /
|
|
45
|
+
// `isCoreConfigured` / `setLogLevel` (src/swiss-knife.ts)
|
|
46
|
+
// - attributes → `Attributes.set` / `setEmail` / `setDisplayName` /
|
|
47
|
+
// `setPhoneNumber` / `setPushToken` (src/attributes.ts)
|
|
48
|
+
// - identity → `Identity.logIn` / `logOut` / `current` (src/identity.ts)
|
|
49
|
+
//
|
|
50
|
+
// ## Why the aliases are not deprecated
|
|
51
|
+
//
|
|
52
|
+
// This class exists so that someone migrating off `react-native-purchases` can
|
|
53
|
+
// keep their call sites. Emitting deprecation warnings at exactly those call
|
|
54
|
+
// sites would punish the users the compatibility surface was built for — the
|
|
55
|
+
// migration would arrive pre-broken, with a console full of warnings for code
|
|
56
|
+
// that is doing the right thing. They are documented as aliases and left alone.
|
|
57
|
+
//
|
|
58
|
+
// The four identity aliases are the exception and keep their `@deprecated` tags,
|
|
59
|
+
// because they are a different case: `Identity` is genuinely the canonical home,
|
|
60
|
+
// and the RC names carry return types (`logOut` resolving a `CustomerInfo`) that
|
|
61
|
+
// misdescribe what the call does in a store-less app.
|
|
62
|
+
//
|
|
63
|
+
// ## Why they cannot drift
|
|
64
|
+
//
|
|
65
|
+
// The aliases are not re-implementations and not one-line wrappers: they are the
|
|
66
|
+
// *same function objects* as the canonical methods, assigned as static fields
|
|
67
|
+
// from the modules that own them. `Purchases.configure === SwissKnife.configure`
|
|
68
|
+
// and `Purchases.setAttributes === Attributes.set` are literally true. There is
|
|
69
|
+
// no second copy of the bootstrap state either — see `src/internal/config.ts`.
|
|
70
|
+
// Pinned by `src/namespaces.test.ts`.
|
|
44
71
|
|
|
45
72
|
// Maps a caller's listener fn to its native subscription so we can remove it.
|
|
46
73
|
const customerInfoSubscriptions = new Map();
|
|
47
74
|
|
|
48
|
-
/**
|
|
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`.
|
|
57
|
-
*/
|
|
58
|
-
function throwIfNotConfigured() {
|
|
59
|
-
if (!configured) {
|
|
60
|
-
throw new _types.UninitializedPurchasesError();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Guard for surfaces that only need CORE — the subscriber-attribute setters.
|
|
66
|
-
*
|
|
67
|
-
* Attributes describe the *person*, not the purchase: natively they land in
|
|
68
|
-
* `AttributesClient` → `POST /api/sdk/users/attributes` → `app_users.properties`,
|
|
69
|
-
* which is what the dashboard person card reads. Neither platform's attributes
|
|
70
|
-
* path touches StoreKit or Play Billing — iOS gates on `SwissKnife.isCoreConfigured`
|
|
71
|
-
* (`SwissKnife.currentAnonymousIdForAttributes`), and Android's `configureCore`
|
|
72
|
-
* wires `AttributesClient` with an `Identity`-snapshot id fallback precisely so a
|
|
73
|
-
* store-less app still resolves ids. Gating these on the purchase flag left an app
|
|
74
|
-
* that uses `configureCore` (because another library owns the store) with **no way
|
|
75
|
-
* at all** to populate the person card.
|
|
76
|
-
*
|
|
77
|
-
* Two-step check, and the second step is load-bearing:
|
|
78
|
-
*
|
|
79
|
-
* 1. The JS flag, set by `configure` / `configureCore`. Free, no bridge hop.
|
|
80
|
-
* 2. Native truth. `Analytics.init(...)` wires core natively via
|
|
81
|
-
* `configureObservability` and touches no JS flag, so an analytics-only app
|
|
82
|
-
* has core configured while every JS flag reads `false` — exactly the case
|
|
83
|
-
* {@link isCoreConfigured} documents. Skipping this step would keep the most
|
|
84
|
-
* common core-only integration broken.
|
|
85
|
-
*
|
|
86
|
-
* Never consults the purchase flag. Strictly more permissive than
|
|
87
|
-
* {@link throwIfNotConfigured}, so no existing caller can break.
|
|
88
|
-
*/
|
|
89
|
-
async function throwIfCoreNotConfigured() {
|
|
90
|
-
if (coreConfigured) return;
|
|
91
|
-
if (await nativeBoolean(native => native.isCoreConfigured())) return;
|
|
92
|
-
throw new _types.UninitializedPurchasesError("Purchases core is not configured. Call Purchases.configure(), " + "Purchases.configureCore(), or Analytics.init() first.");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
75
|
/**
|
|
96
76
|
* The `CustomerInfo` RC's `logOut()` resolves with, for a device that just
|
|
97
77
|
* became anonymous.
|
|
@@ -112,7 +92,7 @@ async function throwIfCoreNotConfigured() {
|
|
|
112
92
|
* operation and must not fail because the store is unreachable.
|
|
113
93
|
*/
|
|
114
94
|
async function customerInfoAfterLogOut() {
|
|
115
|
-
if (await nativeBoolean(native => native.isConfigured())) {
|
|
95
|
+
if (await (0, _config.nativeBoolean)(native => native.isConfigured())) {
|
|
116
96
|
try {
|
|
117
97
|
return await (0, _module.getNativeModule)().getCustomerInfo();
|
|
118
98
|
} catch {
|
|
@@ -153,140 +133,99 @@ function emptyCustomerInfo(subjectId) {
|
|
|
153
133
|
}
|
|
154
134
|
|
|
155
135
|
/**
|
|
156
|
-
* RC-compatible subscriptions SDK entry point. Process-wide singleton
|
|
157
|
-
*
|
|
136
|
+
* RC-compatible subscriptions SDK entry point. Process-wide singleton.
|
|
137
|
+
*
|
|
138
|
+
* New code should bootstrap through {@link SwissKnife} — `SwissKnife.configure(…)`
|
|
139
|
+
* — and reach the store through this class. Code migrating from
|
|
140
|
+
* `react-native-purchases` can keep calling `Purchases.configure(…)`: it is the
|
|
141
|
+
* same function.
|
|
158
142
|
*/
|
|
159
143
|
class Purchases {
|
|
144
|
+
// MARK: - Bootstrap (RC-compatibility aliases for `SwissKnife.*`)
|
|
145
|
+
//
|
|
146
|
+
// Assigned, not wrapped: these ARE `SwissKnife.configure` and friends. The
|
|
147
|
+
// configure state lives in one module (`./internal/config`), so mixing the two
|
|
148
|
+
// spellings in one app is not merely allowed, it is indistinguishable.
|
|
149
|
+
|
|
160
150
|
/**
|
|
161
151
|
* Configure the SDK. Must be called before any other method. Calling again
|
|
162
|
-
* with the same API key is a no-op
|
|
163
|
-
*
|
|
152
|
+
* with the same API key is a no-op; the native layer owns full reconfiguration.
|
|
153
|
+
*
|
|
154
|
+
* RC-compatibility alias for `SwissKnife.configure(...)` — the same function
|
|
155
|
+
* under the name `react-native-purchases` uses. Neither is deprecated.
|
|
164
156
|
*/
|
|
165
|
-
static configure
|
|
166
|
-
if (configured && configuredApiKey === options.apiKey) return;
|
|
167
|
-
const native = (0, _module.getNativeModule)();
|
|
168
|
-
const nativeOptions = {
|
|
169
|
-
apiKey: options.apiKey,
|
|
170
|
-
appUserID: options.appUserID ?? null,
|
|
171
|
-
// proxyURL points the native SDK at the Swiss Knife backend. Without it the
|
|
172
|
-
// native layer falls back to its hardcoded default host (api.swiss-knife.dev),
|
|
173
|
-
// which is unreachable for self-hosted tenants. Forward it so callers can
|
|
174
|
-
// target their own backend (e.g. https://swiss.remneys.com).
|
|
175
|
-
proxyURL: options.proxyURL ?? null,
|
|
176
|
-
// Hardening pass (spec): diagnostics opt-in only — default OFF.
|
|
177
|
-
diagnosticsEnabled: options.diagnosticsEnabled ?? false,
|
|
178
|
-
storeKitVersion: options.storeKitVersion,
|
|
179
|
-
useAmazon: options.useAmazon,
|
|
180
|
-
// iOS ATT — default off (no tracking prompt) unless the host opts in.
|
|
181
|
-
autoPromptATT: options.autoPromptATT,
|
|
182
|
-
sendInstallOnFirstLaunch: options.sendInstallOnFirstLaunch,
|
|
183
|
-
logLevel: options.logLevel
|
|
184
|
-
};
|
|
185
|
-
// Fire-and-forget: native configure resolves async but RC's configure is sync.
|
|
186
|
-
void native.configure(nativeOptions);
|
|
187
|
-
configured = true;
|
|
188
|
-
coreConfigured = true;
|
|
189
|
-
configuredApiKey = options.apiKey;
|
|
190
|
-
}
|
|
157
|
+
static configure = _config.configure;
|
|
191
158
|
|
|
192
159
|
/**
|
|
193
160
|
* Configure everything EXCEPT the store: ingest, `Identity`, `Attribution`,
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* Use this when another library already owns in-app purchases. `configure`
|
|
197
|
-
* starts a `StoreKit.Transaction.updates` observer on iOS (whose handler
|
|
198
|
-
* calls `transaction.finish()`) and builds a `BillingClient` on Android —
|
|
199
|
-
* both of which contend with an incumbent IAP SDK. `configureCore` creates
|
|
200
|
-
* neither, and registers no install as a side effect.
|
|
161
|
+
* `Attributes`. Use it when another library already owns in-app purchases.
|
|
201
162
|
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
163
|
+
* Alias for `SwissKnife.configureCore(...)`, which is the name that actually
|
|
164
|
+
* describes the call — nothing about this method concerns purchases, and it is
|
|
165
|
+
* only spelled `Purchases.configureCore` here so that no existing call site
|
|
166
|
+
* breaks. Prefer the `SwissKnife` spelling in new code.
|
|
205
167
|
*/
|
|
206
|
-
static configureCore
|
|
207
|
-
if (coreConfigured && configuredApiKey === options.apiKey) return;
|
|
208
|
-
const native = (0, _module.getNativeModule)();
|
|
209
|
-
const nativeOptions = {
|
|
210
|
-
apiKey: options.apiKey,
|
|
211
|
-
appUserID: options.appUserID ?? null,
|
|
212
|
-
proxyURL: options.proxyURL ?? null,
|
|
213
|
-
diagnosticsEnabled: options.diagnosticsEnabled ?? false,
|
|
214
|
-
autoPromptATT: options.autoPromptATT,
|
|
215
|
-
// Forwarded but inert on this path — core never auto-registers an
|
|
216
|
-
// install. Kept on the payload so the same options object can be handed
|
|
217
|
-
// to `configure` later without surprises.
|
|
218
|
-
sendInstallOnFirstLaunch: options.sendInstallOnFirstLaunch,
|
|
219
|
-
logLevel: options.logLevel
|
|
220
|
-
};
|
|
221
|
-
void native.configureCore(nativeOptions);
|
|
222
|
-
coreConfigured = true;
|
|
223
|
-
configuredApiKey = options.apiKey;
|
|
224
|
-
}
|
|
168
|
+
static configureCore = _config.configureCore;
|
|
225
169
|
|
|
226
170
|
/**
|
|
227
171
|
* Whether the PURCHASE engine has been configured — i.e. whether the store
|
|
228
|
-
* APIs
|
|
229
|
-
*
|
|
230
|
-
* **Native is the source of truth.** This does not consult the JS-side
|
|
231
|
-
* "configure was called" flag: a brownfield app can configure the SDK from
|
|
232
|
-
* native code, and `Purchases.configure` itself is fire-and-forget, so the
|
|
233
|
-
* JS flag is a request, not a fact.
|
|
172
|
+
* APIs below can work. Native is the source of truth; never throws or rejects.
|
|
234
173
|
*
|
|
235
|
-
*
|
|
236
|
-
* not linked — see {@link nativeBoolean}. Exactly the same failure semantics
|
|
237
|
-
* as {@link isCoreConfigured}; the two differ only in which native flag they
|
|
238
|
-
* report.
|
|
174
|
+
* RC-compatibility alias for `SwissKnife.isConfigured()`.
|
|
239
175
|
*/
|
|
240
|
-
static isConfigured
|
|
241
|
-
return nativeBoolean(native => native.isConfigured());
|
|
242
|
-
}
|
|
176
|
+
static isConfigured = _config.isConfigured;
|
|
243
177
|
|
|
244
178
|
/**
|
|
245
|
-
* Whether the CORE (ingest / Identity / Attribution /
|
|
179
|
+
* Whether the CORE (ingest / Identity / Attribution / Attributes) is
|
|
246
180
|
* configured. True after `configure`, `configureCore`, or `Analytics.init`.
|
|
181
|
+
* Native is the source of truth; never throws or rejects.
|
|
247
182
|
*
|
|
248
|
-
*
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
*
|
|
183
|
+
* Alias for `SwissKnife.isCoreConfigured()`.
|
|
184
|
+
*/
|
|
185
|
+
static isCoreConfigured = _config.isCoreConfigured;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Set the native log level. Process-wide — it governs the store engine, the
|
|
189
|
+
* ingest client, Identity, Attribution and the observability modules alike.
|
|
254
190
|
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
191
|
+
* Alias for `SwissKnife.setLogLevel(...)`, which is where a process-wide
|
|
192
|
+
* setting belongs (and where both native SDKs already put it).
|
|
257
193
|
*/
|
|
258
|
-
static
|
|
259
|
-
|
|
260
|
-
|
|
194
|
+
static setLogLevel = _config.setLogLevel;
|
|
195
|
+
|
|
196
|
+
// MARK: - The store
|
|
197
|
+
//
|
|
198
|
+
// These are the methods that genuinely belong on `Purchases`. All of them are
|
|
199
|
+
// gated on the PURCHASE flag.
|
|
261
200
|
|
|
262
201
|
/** Latest CustomerInfo (entitlements + subscriptions), computed server-side. */
|
|
263
202
|
static async getCustomerInfo() {
|
|
264
|
-
throwIfNotConfigured();
|
|
203
|
+
(0, _config.throwIfNotConfigured)();
|
|
265
204
|
return (0, _module.getNativeModule)().getCustomerInfo();
|
|
266
205
|
}
|
|
267
206
|
|
|
268
207
|
/** Current + all offerings configured for this app. */
|
|
269
208
|
static async getOfferings() {
|
|
270
|
-
throwIfNotConfigured();
|
|
209
|
+
(0, _config.throwIfNotConfigured)();
|
|
271
210
|
return (0, _module.getNativeModule)().getOfferings();
|
|
272
211
|
}
|
|
273
212
|
|
|
274
213
|
/** Purchase a package from an offering. Drives the native store payment sheet. */
|
|
275
214
|
static async purchasePackage(pkg) {
|
|
276
|
-
throwIfNotConfigured();
|
|
215
|
+
(0, _config.throwIfNotConfigured)();
|
|
277
216
|
const offeringId = pkg.presentedOfferingContext?.offeringIdentifier ?? '';
|
|
278
217
|
return (0, _module.getNativeModule)().purchasePackage(pkg.identifier, offeringId);
|
|
279
218
|
}
|
|
280
219
|
|
|
281
220
|
/** Purchase a store product directly by its store SKU. */
|
|
282
221
|
static async purchaseStoreProduct(product) {
|
|
283
|
-
throwIfNotConfigured();
|
|
222
|
+
(0, _config.throwIfNotConfigured)();
|
|
284
223
|
return (0, _module.getNativeModule)().purchaseStoreProduct(product.identifier);
|
|
285
224
|
}
|
|
286
225
|
|
|
287
226
|
/** Restore purchases tied to the underlying store account. */
|
|
288
227
|
static async restorePurchases() {
|
|
289
|
-
throwIfNotConfigured();
|
|
228
|
+
(0, _config.throwIfNotConfigured)();
|
|
290
229
|
return (0, _module.getNativeModule)().restorePurchases();
|
|
291
230
|
}
|
|
292
231
|
|
|
@@ -336,9 +275,20 @@ class Purchases {
|
|
|
336
275
|
// the stale cache and resolved "logged in" without the device ever being
|
|
337
276
|
// re-identified. Routing through `Identity` means one owner for that state.
|
|
338
277
|
//
|
|
278
|
+
// ## Why these four ARE deprecated, when the aliases above are not
|
|
279
|
+
//
|
|
280
|
+
// The bootstrap and attribute aliases are pure renames: same arguments, same
|
|
281
|
+
// return type, same behaviour, and keeping them costs a migrating app nothing.
|
|
282
|
+
// These four are not. `logOut` returns a `CustomerInfo` that is fabricated in
|
|
283
|
+
// a store-less app, `getAppUserID` collapses a three-field snapshot into one
|
|
284
|
+
// string, and `isAnonymous` forces a second round trip to learn what
|
|
285
|
+
// `Identity.current()` already returned. The RC names describe the RC model,
|
|
286
|
+
// not ours, so `Identity.*` is genuinely the better call and not merely the
|
|
287
|
+
// better-organised one. They still work, and will keep working.
|
|
288
|
+
//
|
|
339
289
|
// ## The guard
|
|
340
290
|
//
|
|
341
|
-
// These sit on
|
|
291
|
+
// These sit on `throwIfCoreNotConfigured`, not on the purchase guard.
|
|
342
292
|
// Identity is a core capability — natively both platforms gate it on
|
|
343
293
|
// `isCoreConfigured` — and the single most likely caller of
|
|
344
294
|
// `Purchases.logIn` is an app migrating off RevenueCat that still lets
|
|
@@ -360,7 +310,7 @@ class Purchases {
|
|
|
360
310
|
* is NOT merged server-side and the call must be retried. Repeat calls with
|
|
361
311
|
* the id already in effect are free (no bridge hop, no request).
|
|
362
312
|
*
|
|
363
|
-
* Works after `
|
|
313
|
+
* Works after `SwissKnife.configure`, `SwissKnife.configureCore`, or
|
|
364
314
|
* `Analytics.init` — the store does not have to be ours.
|
|
365
315
|
*
|
|
366
316
|
* @deprecated Wave 1 — prefer `Identity.logIn(userId)`. This alias exists so
|
|
@@ -368,7 +318,7 @@ class Purchases {
|
|
|
368
318
|
* is nothing to gain by keeping it and one less name to learn by dropping it.
|
|
369
319
|
*/
|
|
370
320
|
static async logIn(appUserID) {
|
|
371
|
-
await throwIfCoreNotConfigured();
|
|
321
|
+
await (0, _config.throwIfCoreNotConfigured)();
|
|
372
322
|
return _identity.Identity.logIn(appUserID);
|
|
373
323
|
}
|
|
374
324
|
|
|
@@ -388,7 +338,7 @@ class Purchases {
|
|
|
388
338
|
* return store state.
|
|
389
339
|
*/
|
|
390
340
|
static async logOut() {
|
|
391
|
-
await throwIfCoreNotConfigured();
|
|
341
|
+
await (0, _config.throwIfCoreNotConfigured)();
|
|
392
342
|
await _identity.Identity.logOut();
|
|
393
343
|
return customerInfoAfterLogOut();
|
|
394
344
|
}
|
|
@@ -407,7 +357,7 @@ class Purchases {
|
|
|
407
357
|
* two calls that can interleave.
|
|
408
358
|
*/
|
|
409
359
|
static async getAppUserID() {
|
|
410
|
-
await throwIfCoreNotConfigured();
|
|
360
|
+
await (0, _config.throwIfCoreNotConfigured)();
|
|
411
361
|
const snapshot = await _identity.Identity.current();
|
|
412
362
|
return snapshot.userId ?? snapshot.anonymousId;
|
|
413
363
|
}
|
|
@@ -422,48 +372,43 @@ class Purchases {
|
|
|
422
372
|
* {@link getAppUserID}.
|
|
423
373
|
*/
|
|
424
374
|
static async isAnonymous() {
|
|
425
|
-
await throwIfCoreNotConfigured();
|
|
375
|
+
await (0, _config.throwIfCoreNotConfigured)();
|
|
426
376
|
return (await _identity.Identity.current()).isAnonymous;
|
|
427
377
|
}
|
|
428
378
|
|
|
429
|
-
// Subscriber attributes
|
|
430
|
-
//
|
|
431
|
-
//
|
|
379
|
+
// MARK: - Subscriber attributes (RC-compatibility aliases for `Attributes.*`)
|
|
380
|
+
//
|
|
381
|
+
// CORE, not store: all five are gated on `throwIfCoreNotConfigured`, so they
|
|
382
|
+
// work in an app that only called `configureCore` (another library owns the
|
|
383
|
+
// store) or only `Analytics.init`. That is the tell that they never belonged
|
|
384
|
+
// on this class — an app with no purchases at all still needs them, because
|
|
385
|
+
// they are the only path to the dashboard person card.
|
|
386
|
+
//
|
|
387
|
+
// Assigned, not wrapped: `Purchases.setAttributes === Attributes.set`.
|
|
432
388
|
|
|
433
|
-
/**
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Set arbitrary subscriber attributes. `null` clears an attribute.
|
|
391
|
+
*
|
|
392
|
+
* RC-compatibility alias for `Attributes.set(...)`. Not deprecated.
|
|
393
|
+
*/
|
|
394
|
+
static setAttributes = _attributes.Attributes.set;
|
|
438
395
|
|
|
439
|
-
/** Reserved attribute: email. */
|
|
440
|
-
static
|
|
441
|
-
await throwIfCoreNotConfigured();
|
|
442
|
-
return (0, _module.getNativeModule)().setEmail(email);
|
|
443
|
-
}
|
|
396
|
+
/** Reserved attribute: email. Alias for `Attributes.setEmail(...)`. */
|
|
397
|
+
static setEmail = _attributes.Attributes.setEmail;
|
|
444
398
|
|
|
445
|
-
/** Reserved attribute: display name. */
|
|
446
|
-
static
|
|
447
|
-
await throwIfCoreNotConfigured();
|
|
448
|
-
return (0, _module.getNativeModule)().setDisplayName(displayName);
|
|
449
|
-
}
|
|
399
|
+
/** Reserved attribute: display name. Alias for `Attributes.setDisplayName(...)`. */
|
|
400
|
+
static setDisplayName = _attributes.Attributes.setDisplayName;
|
|
450
401
|
|
|
451
|
-
/** Reserved attribute: phone number. */
|
|
452
|
-
static
|
|
453
|
-
await throwIfCoreNotConfigured();
|
|
454
|
-
return (0, _module.getNativeModule)().setPhoneNumber(phoneNumber);
|
|
455
|
-
}
|
|
402
|
+
/** Reserved attribute: phone number. Alias for `Attributes.setPhoneNumber(...)`. */
|
|
403
|
+
static setPhoneNumber = _attributes.Attributes.setPhoneNumber;
|
|
456
404
|
|
|
457
|
-
/** Reserved attribute: push token. */
|
|
458
|
-
static
|
|
459
|
-
await throwIfCoreNotConfigured();
|
|
460
|
-
return (0, _module.getNativeModule)().setPushToken(pushToken);
|
|
461
|
-
}
|
|
405
|
+
/** Reserved attribute: push token. Alias for `Attributes.setPushToken(...)`. */
|
|
406
|
+
static setPushToken = _attributes.Attributes.setPushToken;
|
|
462
407
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
408
|
+
// MARK: - CustomerInfo listeners
|
|
409
|
+
//
|
|
410
|
+
// Store surface: these fire on purchase, renewal and dashboard grant, so they
|
|
411
|
+
// stay here rather than moving to the root.
|
|
467
412
|
|
|
468
413
|
/** Subscribe to CustomerInfo changes (purchase, renewal, dashboard grant). */
|
|
469
414
|
static addCustomerInfoUpdateListener(listener) {
|
|
@@ -489,9 +434,7 @@ class Purchases {
|
|
|
489
434
|
* short-circuit before reaching the (freshly mocked) bridge.
|
|
490
435
|
*/
|
|
491
436
|
static __resetForTests() {
|
|
492
|
-
|
|
493
|
-
coreConfigured = false;
|
|
494
|
-
configuredApiKey = null;
|
|
437
|
+
(0, _config.resetConfigForTests)();
|
|
495
438
|
customerInfoSubscriptions.clear();
|
|
496
439
|
_identity.Identity.__resetForTests();
|
|
497
440
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["_attributes","require","_identity","_config","_module","_spec","_types","customerInfoSubscriptions","Map","customerInfoAfterLogOut","nativeBoolean","native","isConfigured","getNativeModule","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","configureCore","isCoreConfigured","setLogLevel","throwIfNotConfigured","getOfferings","purchasePackage","pkg","offeringId","presentedOfferingContext","offeringIdentifier","identifier","purchaseStoreProduct","product","restorePurchases","logIn","appUserID","throwIfCoreNotConfigured","logOut","getAppUserID","isAnonymous","setAttributes","Attributes","set","setEmail","setDisplayName","setPhoneNumber","setPushToken","addCustomerInfoUpdateListener","listener","sub","getEventEmitter","addListener","CUSTOMER_INFO_UPDATED_EVENT","event","removeCustomerInfoUpdateListener","get","remove","delete","__resetForTests","resetConfigForTests","clear","exports","_default","default"],"sourceRoot":"../../src","sources":["purchases.ts"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AAWA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AA7DA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AA6BA;AACA,MAAMM,yBAAyB,GAAG,IAAIC,GAAG,CAGvC,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,uBAAuBA,CAAA,EAA0B;EAC9D,IAAI,MAAM,IAAAC,qBAAa,EAAEC,MAAM,IAAKA,MAAM,CAACC,YAAY,CAAC,CAAC,CAAC,EAAE;IAC1D,IAAI;MACF,OAAO,MAAM,IAAAC,uBAAe,EAAC,CAAC,CAACC,eAAe,CAAC,CAAC;IAClD,CAAC,CAAC,MAAM;MACN;IAAA;EAEJ;EACA,MAAMC,QAAQ,GAAG,MAAMC,kBAAQ,CAACC,OAAO,CAAC,CAAC;EACzC,OAAOC,iBAAiB,CAACH,QAAQ,CAACI,MAAM,IA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