@app-swiss-knife/react-native-sdk 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +100 -47
  2. package/SwissKnifePurchases.podspec +8 -5
  3. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  4. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
  5. package/ios/SwissKnifeCrashReporting.swift +59 -18
  6. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  7. package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +1 -1
  8. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +24 -0
  9. package/ios/vendor/SwissKnifeiOS/DeviceID.swift +22 -1
  10. package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +49 -0
  11. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +14 -0
  12. package/lib/commonjs/attributes.js +103 -0
  13. package/lib/commonjs/attributes.js.map +1 -0
  14. package/lib/commonjs/index.js +31 -2
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/internal/config.js +237 -0
  17. package/lib/commonjs/internal/config.js.map +1 -0
  18. package/lib/commonjs/purchases.js +152 -209
  19. package/lib/commonjs/purchases.js.map +1 -1
  20. package/lib/commonjs/swiss-knife.js +115 -0
  21. package/lib/commonjs/swiss-knife.js.map +1 -0
  22. package/lib/commonjs/types.js +11 -0
  23. package/lib/commonjs/types.js.map +1 -1
  24. package/lib/module/attributes.js +100 -0
  25. package/lib/module/attributes.js.map +1 -0
  26. package/lib/module/index.js +19 -2
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/internal/config.js +225 -0
  29. package/lib/module/internal/config.js.map +1 -0
  30. package/lib/module/purchases.js +132 -198
  31. package/lib/module/purchases.js.map +1 -1
  32. package/lib/module/swiss-knife.js +112 -0
  33. package/lib/module/swiss-knife.js.map +1 -0
  34. package/lib/module/types.js +11 -0
  35. package/lib/module/types.js.map +1 -1
  36. package/lib/typescript/commonjs/attributes.d.ts +41 -0
  37. package/lib/typescript/commonjs/attributes.d.ts.map +1 -0
  38. package/lib/typescript/commonjs/index.d.ts +2 -0
  39. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  40. package/lib/typescript/commonjs/internal/config.d.ts +121 -0
  41. package/lib/typescript/commonjs/internal/config.d.ts.map +1 -0
  42. package/lib/typescript/commonjs/purchases.d.ts +47 -91
  43. package/lib/typescript/commonjs/purchases.d.ts.map +1 -1
  44. package/lib/typescript/commonjs/swiss-knife.d.ts +56 -0
  45. package/lib/typescript/commonjs/swiss-knife.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/types.d.ts +13 -0
  47. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  48. package/lib/typescript/module/attributes.d.ts +41 -0
  49. package/lib/typescript/module/attributes.d.ts.map +1 -0
  50. package/lib/typescript/module/index.d.ts +2 -0
  51. package/lib/typescript/module/index.d.ts.map +1 -1
  52. package/lib/typescript/module/internal/config.d.ts +121 -0
  53. package/lib/typescript/module/internal/config.d.ts.map +1 -0
  54. package/lib/typescript/module/purchases.d.ts +47 -91
  55. package/lib/typescript/module/purchases.d.ts.map +1 -1
  56. package/lib/typescript/module/swiss-knife.d.ts +56 -0
  57. package/lib/typescript/module/swiss-knife.d.ts.map +1 -0
  58. package/lib/typescript/module/types.d.ts +13 -0
  59. package/lib/typescript/module/types.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/attributes.ts +97 -0
  62. package/src/index.ts +19 -2
  63. package/src/internal/config.ts +233 -0
  64. package/src/purchases.ts +142 -213
  65. package/src/swiss-knife.ts +134 -0
  66. package/src/types.ts +14 -0
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Attributes = void 0;
7
+ var _module = require("./native/module.js");
8
+ var _config = require("./internal/config.js");
9
+ // packages/react-native-sdk/src/attributes.ts
10
+ //
11
+ // Subscriber attributes as a peer namespace, alongside `Identity`,
12
+ // `Attribution`, `Analytics`, `CrashReporting` and `Performance`.
13
+ //
14
+ // ## Why this is not on `Purchases`
15
+ //
16
+ // Attributes describe the *person*, not the purchase. They are the only path to
17
+ // `POST /api/sdk/users/attributes` → `app_users.properties`, which is what the
18
+ // dashboard person card renders — and an app with no in-app purchases at all
19
+ // still wants that card filled in. Reaching it through an object named
20
+ // `Purchases` is a false statement about what the call does, and in practice it
21
+ // is the single hardest surface in this SDK to find: "which call fills the
22
+ // person card?" was the question that cost our integrators the most time.
23
+ //
24
+ // It also disagreed with the guard. These five have been gated on
25
+ // `throwIfCoreNotConfigured` — *not* the purchase guard — since the
26
+ // core/purchases split, precisely because a `configureCore` app (another
27
+ // library owns the store) must still be able to set them. A method that works
28
+ // without the store had no business living on the store namespace.
29
+ //
30
+ // ## Method naming
31
+ //
32
+ // `set` rather than `setAttributes`: `Attributes.setAttributes({...})` stutters,
33
+ // and the namespace already says what is being set. The four reserved keys keep
34
+ // their `setX` spelling — `Attributes.setEmail(...)` reads correctly, does not
35
+ // stutter, and matches the native spelling on both platforms
36
+ // (`SwissKnife.setEmail` on iOS, the `setEmail` bridge method on Android), so
37
+ // there is one name to learn across all three SDKs. Dropping the prefix
38
+ // (`Attributes.email(...)`) would read as a getter.
39
+ //
40
+ // The RC-compatible spellings on `Purchases` are the *same function objects* as
41
+ // these — see `src/internal/config.ts` for why that matters and
42
+ // `src/namespaces.test.ts` for the assertion.
43
+
44
+ /**
45
+ * Set arbitrary subscriber attributes. `null` clears an attribute.
46
+ *
47
+ * Works after `SwissKnife.configure`, `SwissKnife.configureCore`, or
48
+ * `Analytics.init` — the store does not have to be ours, and does not have to
49
+ * exist.
50
+ */
51
+ async function set(attributes) {
52
+ await (0, _config.throwIfCoreNotConfigured)();
53
+ return (0, _module.getNativeModule)().setAttributes(attributes);
54
+ }
55
+
56
+ /** Reserved attribute: email. `null` clears it. */
57
+ async function setEmail(email) {
58
+ await (0, _config.throwIfCoreNotConfigured)();
59
+ return (0, _module.getNativeModule)().setEmail(email);
60
+ }
61
+
62
+ /** Reserved attribute: display name. `null` clears it. */
63
+ async function setDisplayName(displayName) {
64
+ await (0, _config.throwIfCoreNotConfigured)();
65
+ return (0, _module.getNativeModule)().setDisplayName(displayName);
66
+ }
67
+
68
+ /** Reserved attribute: phone number. `null` clears it. */
69
+ async function setPhoneNumber(phoneNumber) {
70
+ await (0, _config.throwIfCoreNotConfigured)();
71
+ return (0, _module.getNativeModule)().setPhoneNumber(phoneNumber);
72
+ }
73
+
74
+ /** Reserved attribute: push token. `null` clears it. */
75
+ async function setPushToken(pushToken) {
76
+ await (0, _config.throwIfCoreNotConfigured)();
77
+ return (0, _module.getNativeModule)().setPushToken(pushToken);
78
+ }
79
+
80
+ /**
81
+ * Subscriber attributes — the data behind the dashboard person card.
82
+ *
83
+ * ```ts
84
+ * import { Attributes } from "@app-swiss-knife/react-native-sdk";
85
+ *
86
+ * await Attributes.setEmail("ann@example.com");
87
+ * await Attributes.setDisplayName("Ann");
88
+ * await Attributes.set({ plan: "gold", cohort: "2026-08" });
89
+ * await Attributes.set({ cohort: null }); // clear
90
+ * ```
91
+ *
92
+ * Every method requires core to be configured and rejects with
93
+ * `UninitializedPurchasesError` otherwise. None of them touch StoreKit or Play
94
+ * Billing.
95
+ */
96
+ const Attributes = exports.Attributes = {
97
+ set,
98
+ setEmail,
99
+ setDisplayName,
100
+ setPhoneNumber,
101
+ setPushToken
102
+ };
103
+ //# sourceMappingURL=attributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_module","require","_config","set","attributes","throwIfCoreNotConfigured","getNativeModule","setAttributes","setEmail","email","setDisplayName","displayName","setPhoneNumber","phoneNumber","setPushToken","pushToken","Attributes","exports"],"sourceRoot":"../../src","sources":["attributes.ts"],"mappings":";;;;;;AAmCA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD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 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  Purchases: true,
8
+ SwissKnife: true,
9
+ Attributes: true,
8
10
  Identity: true,
9
11
  Attribution: true,
10
12
  Analytics: true,
@@ -21,6 +23,12 @@ Object.defineProperty(exports, "Analytics", {
21
23
  return _analytics.Analytics;
22
24
  }
23
25
  });
26
+ Object.defineProperty(exports, "Attributes", {
27
+ enumerable: true,
28
+ get: function () {
29
+ return _attributes.Attributes;
30
+ }
31
+ });
24
32
  Object.defineProperty(exports, "Attribution", {
25
33
  enumerable: true,
26
34
  get: function () {
@@ -69,6 +77,12 @@ Object.defineProperty(exports, "SKRevenue", {
69
77
  return _analytics.SKRevenue;
70
78
  }
71
79
  });
80
+ Object.defineProperty(exports, "SwissKnife", {
81
+ enumerable: true,
82
+ get: function () {
83
+ return _swissKnife.SwissKnife;
84
+ }
85
+ });
72
86
  exports.default = void 0;
73
87
  Object.defineProperty(exports, "parseStackTrace", {
74
88
  enumerable: true,
@@ -77,6 +91,8 @@ Object.defineProperty(exports, "parseStackTrace", {
77
91
  }
78
92
  });
79
93
  var _purchases = _interopRequireDefault(require("./purchases.js"));
94
+ var _swissKnife = require("./swiss-knife.js");
95
+ var _attributes = require("./attributes.js");
80
96
  var _types = require("./types.js");
81
97
  Object.keys(_types).forEach(function (key) {
82
98
  if (key === "default" || key === "__esModule") return;
@@ -98,9 +114,22 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
98
114
  // src/index.ts
99
115
  // Default export mirrors react-native-purchases: `import Purchases from '...'`.
100
116
  var _default = exports.default = _purchases.default; // Named export of the class for `import { Purchases } from '...'`.
117
+ // The SDK root — bootstrap (`configure`, `configureCore`, `isConfigured`,
118
+ // `isCoreConfigured`, `setLogLevel`) plus a handle on every namespace, so
119
+ // `SwissKnife.` lists the whole SDK. Mirrors the native SDKs, which have rooted
120
+ // everything under `SwissKnife` (iOS) / `com.appswissknife.SwissKnife`
121
+ // (Android) all along; JS had no root at all until now.
122
+ //
123
+ // `Purchases.configure` and friends remain — they are the SAME functions, not
124
+ // wrappers, so mixing the spellings shares one bootstrap state.
125
+ // Subscriber attributes as a peer namespace. This is the surface behind the
126
+ // dashboard person card (`POST /api/sdk/users/attributes`), and it needs only
127
+ // core — an app with no in-app purchases still wants it. The RC-compatible
128
+ // `Purchases.setAttributes` / `setEmail` / … aliases are the same functions.
101
129
  // Public type/enum/error surface (CustomerInfo, PurchasesOfferings,
102
- // PURCHASES_ERROR_CODE, LOG_LEVEL, the enums, PurchasesError, etc.) —
103
- // defined in ./types (Phase 7: own definitions, no RC dependency).
130
+ // PURCHASES_ERROR_CODE, LOG_LEVEL, ConfigureOptions, the enums,
131
+ // PurchasesError, etc.) — defined in ./types (Phase 7: own definitions, no RC
132
+ // dependency).
104
133
  // Wave 1 — unified Identity surface. Routes through native
105
134
  // `SwissKnife.Identity` (iOS) / `com.appswissknife.identity.Identity`
106
135
  // (Android). Decoupled from analytics: `Identity.logIn(...)` does NOT
@@ -1 +1 @@
1
- {"version":3,"names":["_purchases","_interopRequireDefault","require","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_identity","_attribution","_analytics","_crashReporting","_performance","e","__esModule","default","_default","Purchases"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAOA,IAAAS,SAAA,GAAAd,OAAA;AAQA,IAAAe,YAAA,GAAAf,OAAA;AAOA,IAAAgB,UAAA,GAAAhB,OAAA;AAEA,IAAAiB,eAAA,GAAAjB,OAAA;AAWA,IAAAkB,YAAA,GAAAlB,OAAA;AAAoD,SAAAD,uBAAAoB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA/CpD;AAGA;AAAA,IAAAG,QAAA,GAAAZ,OAAA,CAAAW,OAAA,GACeE,kBAAS,EAExB;AAGA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA","ignoreList":[]}
1
+ {"version":3,"names":["_purchases","_interopRequireDefault","require","_swissKnife","_attributes","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_identity","_attribution","_analytics","_crashReporting","_performance","e","__esModule","default","_default","Purchases"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAgBA,IAAAC,WAAA,GAAAD,OAAA;AAMA,IAAAE,WAAA,GAAAF,OAAA;AAMA,IAAAG,MAAA,GAAAH,OAAA;AAAAI,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,MAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,MAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AAOA,IAAAS,SAAA,GAAAhB,OAAA;AAQA,IAAAiB,YAAA,GAAAjB,OAAA;AAOA,IAAAkB,UAAA,GAAAlB,OAAA;AAEA,IAAAmB,eAAA,GAAAnB,OAAA;AAWA,IAAAoB,YAAA,GAAApB,OAAA;AAAoD,SAAAD,uBAAAsB,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAhEpD;AAGA;AAAA,IAAAG,QAAA,GAAAZ,OAAA,CAAAW,OAAA,GACeE,kBAAS,EAExB;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA","ignoreList":[]}
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.configure = configure;
7
+ exports.configureCore = configureCore;
8
+ exports.isConfigured = isConfigured;
9
+ exports.isCoreConfigured = isCoreConfigured;
10
+ exports.nativeBoolean = nativeBoolean;
11
+ exports.resetConfigForTests = resetConfigForTests;
12
+ exports.setLogLevel = setLogLevel;
13
+ exports.throwIfCoreNotConfigured = throwIfCoreNotConfigured;
14
+ exports.throwIfNotConfigured = throwIfNotConfigured;
15
+ var _module = require("../native/module.js");
16
+ var _types = require("../types.js");
17
+ // src/internal/config.ts
18
+ //
19
+ // The SDK's bootstrap: the process-wide "have we been configured?" state, the
20
+ // two configure entry points, the two readback flags, the log level, and the
21
+ // guards every public surface is gated on.
22
+ //
23
+ // ## Why this is a module of its own rather than statics on a namespace
24
+ //
25
+ // `SwissKnife.configure(...)` and `Purchases.configure(...)` are one call under
26
+ // two names. If each namespace owned its own copy of `configured` /
27
+ // `coreConfigured`, an app that bootstrapped through one name and then used a
28
+ // surface guarded by the other would be told it had never configured anything —
29
+ // precisely the class of bug a namespace split invites. There is exactly one
30
+ // implementation here, and every public namespace exports a *reference to it*.
31
+ // That makes `SwissKnife.configure === Purchases.configure` literally true (and
32
+ // `Attributes.set === Purchases.setAttributes`, and so on), so the compatibility
33
+ // aliases cannot drift from the canonical methods by construction rather than by
34
+ // diligence. Pinned in `src/namespaces.test.ts`.
35
+ //
36
+ // Nothing in here is part of the published API. It is reachable via the
37
+ // package's `./*` subpath export, as every file under `src/` is; the `internal/`
38
+ // segment is the signal not to.
39
+
40
+ let configured = false;
41
+ let configuredApiKey = null;
42
+ let coreConfigured = false;
43
+
44
+ /**
45
+ * Read a boolean off the native module without ever letting a missing native
46
+ * module escape as an exception.
47
+ *
48
+ * `getNativeModule()` THROWS when the module is not linked (Expo Go, a bare RN
49
+ * app that skipped `pod install` / a Gradle sync, web) — precisely the state a
50
+ * developer is in while wiring the SDK up, and precisely when they are most
51
+ * likely to be calling one of these accessors to find out what is wrong. A
52
+ * boolean accessor rejecting with "native module is not linked" is a worse
53
+ * answer than `false`: an unlinked module cannot have configured anything, so
54
+ * `false` is not merely safe, it is correct.
55
+ *
56
+ * The `.catch` covers the adjacent case where the module IS linked but predates
57
+ * the method (JS upgraded without rebuilding the app) — same reasoning, same
58
+ * answer. Mirrors the tolerance `Analytics.init` already applies to
59
+ * `configureObservability`.
60
+ */
61
+ function nativeBoolean(read) {
62
+ try {
63
+ return Promise.resolve(read((0, _module.getNativeModule)())).catch(() => false);
64
+ } catch {
65
+ return Promise.resolve(false);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * Configure the SDK. Must be called before any other method. Calling again
71
+ * with the same API key is a no-op (matches the common "configure once" guard);
72
+ * the native layer owns full reconfiguration.
73
+ */
74
+ function configure(options) {
75
+ if (configured && configuredApiKey === options.apiKey) return;
76
+ const native = (0, _module.getNativeModule)();
77
+ const nativeOptions = {
78
+ apiKey: options.apiKey,
79
+ appUserID: options.appUserID ?? null,
80
+ // proxyURL points the native SDK at the Swiss Knife backend. Without it the
81
+ // native layer falls back to its hardcoded default host (api.swiss-knife.dev),
82
+ // which is unreachable for self-hosted tenants. Forward it so callers can
83
+ // target their own backend (e.g. https://swiss.remneys.com).
84
+ proxyURL: options.proxyURL ?? null,
85
+ // Hardening pass (spec): diagnostics opt-in only — default OFF.
86
+ diagnosticsEnabled: options.diagnosticsEnabled ?? false,
87
+ storeKitVersion: options.storeKitVersion,
88
+ useAmazon: options.useAmazon,
89
+ // iOS ATT — default off (no tracking prompt) unless the host opts in.
90
+ autoPromptATT: options.autoPromptATT,
91
+ sendInstallOnFirstLaunch: options.sendInstallOnFirstLaunch,
92
+ logLevel: options.logLevel
93
+ };
94
+ // Fire-and-forget: native configure resolves async but RC's configure is sync.
95
+ void native.configure(nativeOptions);
96
+ configured = true;
97
+ coreConfigured = true;
98
+ configuredApiKey = options.apiKey;
99
+ }
100
+
101
+ /**
102
+ * Configure everything EXCEPT the store: ingest, `Identity`, `Attribution`,
103
+ * `Attributes`.
104
+ *
105
+ * Use this when another library already owns in-app purchases. `configure`
106
+ * starts a `StoreKit.Transaction.updates` observer on iOS (whose handler
107
+ * calls `transaction.finish()`) and builds a `BillingClient` on Android —
108
+ * both of which contend with an incumbent IAP SDK. `configureCore` creates
109
+ * neither, and registers no install as a side effect.
110
+ *
111
+ * Analytics-only apps don't even need this: `Analytics.init(...)` already
112
+ * wires core natively. Reach for `configureCore` when you want to pass an
113
+ * `appUserID`, an attribution configuration, or a log level up front.
114
+ */
115
+ function configureCore(options) {
116
+ if (coreConfigured && configuredApiKey === options.apiKey) return;
117
+ const native = (0, _module.getNativeModule)();
118
+ const nativeOptions = {
119
+ apiKey: options.apiKey,
120
+ appUserID: options.appUserID ?? null,
121
+ proxyURL: options.proxyURL ?? null,
122
+ diagnosticsEnabled: options.diagnosticsEnabled ?? false,
123
+ autoPromptATT: options.autoPromptATT,
124
+ // Forwarded but inert on this path — core never auto-registers an
125
+ // install. Kept on the payload so the same options object can be handed
126
+ // to `configure` later without surprises.
127
+ sendInstallOnFirstLaunch: options.sendInstallOnFirstLaunch,
128
+ logLevel: options.logLevel
129
+ };
130
+ void native.configureCore(nativeOptions);
131
+ coreConfigured = true;
132
+ configuredApiKey = options.apiKey;
133
+ }
134
+
135
+ /**
136
+ * Whether the PURCHASE engine has been configured — i.e. whether the store
137
+ * APIs (`getOfferings`, `purchasePackage`, `restorePurchases`, …) can work.
138
+ *
139
+ * **Native is the source of truth.** This does not consult the JS-side
140
+ * "configure was called" flag: a brownfield app can configure the SDK from
141
+ * native code, and `configure` itself is fire-and-forget, so the JS flag is a
142
+ * request, not a fact.
143
+ *
144
+ * Never throws and never rejects. Resolves `false` when the native module is
145
+ * not linked — see {@link nativeBoolean}. Exactly the same failure semantics
146
+ * as {@link isCoreConfigured}; the two differ only in which native flag they
147
+ * report.
148
+ */
149
+ function isConfigured() {
150
+ return nativeBoolean(native => native.isConfigured());
151
+ }
152
+
153
+ /**
154
+ * Whether the CORE (ingest / Identity / Attribution / Attributes) is
155
+ * configured. True after `configure`, `configureCore`, or `Analytics.init`.
156
+ *
157
+ * **Native is the source of truth**, and here that is load-bearing rather
158
+ * than merely principled: `Analytics.init` wires core natively via
159
+ * `configureObservability` and touches no JS configure flag, so an
160
+ * analytics-only app has core configured while every JS flag reads false.
161
+ * Short-circuiting on JS state would report `false` in the single most
162
+ * common core-only integration.
163
+ *
164
+ * Never throws and never rejects. Resolves `false` when the native module is
165
+ * not linked — see {@link nativeBoolean}.
166
+ */
167
+ function isCoreConfigured() {
168
+ return nativeBoolean(native => native.isCoreConfigured());
169
+ }
170
+
171
+ /**
172
+ * Set the native log level. Process-wide: it is read by the store engine, the
173
+ * ingest client, Identity, Attribution and the observability modules alike,
174
+ * which is why it belongs on the SDK root and not on any one namespace.
175
+ *
176
+ * Deliberately ungated — a log level you can only raise *after* a successful
177
+ * configure is useless for debugging a configure that is going wrong. It does
178
+ * still require the native module to be linked, and rejects if it is not.
179
+ */
180
+ function setLogLevel(level) {
181
+ return (0, _module.getNativeModule)().setLogLevel(level);
182
+ }
183
+
184
+ /**
185
+ * Guard for surfaces that genuinely need the PURCHASE engine — `getOfferings`,
186
+ * `purchasePackage`, `restorePurchases` and friends. Checks the JS "configure
187
+ * was called" flag.
188
+ *
189
+ * The RC-parity identity aliases used to sit here too, on the grounds that the
190
+ * legacy native bridge methods they called meant different things on iOS and
191
+ * Android. They now delegate to `Identity` and sit on
192
+ * {@link throwIfCoreNotConfigured} — see the block above `Purchases.logIn`.
193
+ */
194
+ function throwIfNotConfigured() {
195
+ if (!configured) {
196
+ throw new _types.UninitializedPurchasesError();
197
+ }
198
+ }
199
+
200
+ /**
201
+ * Guard for surfaces that only need CORE — the `Attributes` setters.
202
+ *
203
+ * Attributes describe the *person*, not the purchase: natively they land in
204
+ * `AttributesClient` → `POST /api/sdk/users/attributes` → `app_users.properties`,
205
+ * which is what the dashboard person card reads. Neither platform's attributes
206
+ * path touches StoreKit or Play Billing — iOS gates on `SwissKnife.isCoreConfigured`
207
+ * (`SwissKnife.currentAnonymousIdForAttributes`), and Android's `configureCore`
208
+ * wires `AttributesClient` with an `Identity`-snapshot id fallback precisely so a
209
+ * store-less app still resolves ids. Gating these on the purchase flag left an app
210
+ * that uses `configureCore` (because another library owns the store) with **no way
211
+ * at all** to populate the person card.
212
+ *
213
+ * Two-step check, and the second step is load-bearing:
214
+ *
215
+ * 1. The JS flag, set by `configure` / `configureCore`. Free, no bridge hop.
216
+ * 2. Native truth. `Analytics.init(...)` wires core natively via
217
+ * `configureObservability` and touches no JS flag, so an analytics-only app
218
+ * has core configured while every JS flag reads `false` — exactly the case
219
+ * {@link isCoreConfigured} documents. Skipping this step would keep the most
220
+ * common core-only integration broken.
221
+ *
222
+ * Never consults the purchase flag. Strictly more permissive than
223
+ * {@link throwIfNotConfigured}, so no existing caller can break.
224
+ */
225
+ async function throwIfCoreNotConfigured() {
226
+ if (coreConfigured) return;
227
+ if (await nativeBoolean(native => native.isCoreConfigured())) return;
228
+ throw new _types.UninitializedPurchasesError("Swiss Knife core is not configured. Call SwissKnife.configure(), " + "SwissKnife.configureCore(), or Analytics.init() first.");
229
+ }
230
+
231
+ /** @internal Test seam: drop the process-wide configure state. */
232
+ function resetConfigForTests() {
233
+ configured = false;
234
+ coreConfigured = false;
235
+ configuredApiKey = null;
236
+ }
237
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_module","require","_types","configured","configuredApiKey","coreConfigured","nativeBoolean","read","Promise","resolve","getNativeModule","catch","configure","options","apiKey","native","nativeOptions","appUserID","proxyURL","diagnosticsEnabled","storeKitVersion","useAmazon","autoPromptATT","sendInstallOnFirstLaunch","logLevel","configureCore","isConfigured","isCoreConfigured","setLogLevel","level","throwIfNotConfigured","UninitializedPurchasesError","throwIfCoreNotConfigured","resetConfigForTests"],"sourceRoot":"../../../src","sources":["internal/config.ts"],"mappings":";;;;;;;;;;;;;;AAuBA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,IAAIE,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;AACO,SAASC,aAAaA,CAC3BC,IAAmE,EACjD;EAClB,IAAI;IACF,OAA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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,wBAAwBA,CAAA,EAAkB;EAC9D,IAAI3B,cAAc,EAAE;EACpB,IAAI,MAAMC,aAAa,CAAES,MAAM,IAAKA,MAAM,CAACY,gBAAgB,CAAC,CAAC,CAAC,EAAE;EAChE,MAAM,IAAII,kCAA2B,CACnC,mEAAmE,GACjE,wDACJ,CAAC;AACH;;AAEA;AACO,SAASE,mBAAmBA,CAAA,EAAS;EAC1C9B,UAAU,GAAG,KAAK;EAClBE,cAAc,GAAG,KAAK;EACtBD,gBAAgB,GAAG,IAAI;AACzB","ignoreList":[]}