@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,134 @@
1
+ // packages/react-native-sdk/src/swiss-knife.ts
2
+ //
3
+ // The SDK root. Mirror of `SwissKnife` on iOS (`SwissKnifeiOS`, a public final
4
+ // class with `configure` / `configureCore` / `isConfigured` /
5
+ // `isCoreConfigured` / `setLogLevel` statics and `SwissKnife.Identity`,
6
+ // `SwissKnife.Attribution` extensions) and of `com.appswissknife.SwissKnife` on
7
+ // Android.
8
+ //
9
+ // ## Why this exists
10
+ //
11
+ // Until now JS had no root at all. Both bootstraps lived on `Purchases`, which
12
+ // made `Purchases.configureCore()` — a call whose entire meaning is "I do not
13
+ // want the store" — read as a contradiction, and left the SDK running two
14
+ // organising principles at once: a god-object for some concerns, peer
15
+ // namespaces (`Identity`, `Attribution`, `Analytics`, `CrashReporting`,
16
+ // `Performance`) for the rest. The native SDKs never had that problem. This
17
+ // closes the gap in the direction of the two that were already right.
18
+ //
19
+ // ## What belongs here, and what does not
20
+ //
21
+ // Bootstrap and process-wide settings: the two `configure` entry points, the
22
+ // two readback flags, and `setLogLevel`. `setLogLevel` earns its place three
23
+ // ways — it is on the native root on both platforms; it is read by every
24
+ // subsystem (store engine, ingest client, Identity, Attribution, the
25
+ // observability modules), so no single namespace owns it; and it is the one
26
+ // member of the old `Purchases` surface with no configure guard at all, which
27
+ // is the tell that it was never a purchase method.
28
+ //
29
+ // The store surface stays on `Purchases` and is reachable as
30
+ // `SwissKnife.Purchases`. Hoisting `getOfferings` / `purchasePackage` /
31
+ // `restorePurchases` / the CustomerInfo listeners onto the root would recreate
32
+ // the junk drawer at a new address. (iOS does put them on its root; iOS has no
33
+ // RC-compatibility object competing for the name, and we do.)
34
+ //
35
+ // The namespace handles below make the root the one thing you have to know:
36
+ // typing `SwissKnife.` lists the entire SDK. They are the same objects the
37
+ // package exports by name — `SwissKnife.Identity === Identity` — not copies.
38
+
39
+ import {
40
+ configure,
41
+ configureCore,
42
+ isConfigured,
43
+ isCoreConfigured,
44
+ setLogLevel,
45
+ } from "./internal/config";
46
+ import { Attributes } from "./attributes";
47
+ import { Attribution } from "./attribution";
48
+ import { Identity } from "./identity";
49
+ import { Purchases } from "./purchases";
50
+ import { Analytics } from "./modules/analytics";
51
+ import { CrashReporting } from "./modules/crash-reporting";
52
+ import { Performance } from "./modules/performance";
53
+
54
+ /**
55
+ * The shape of {@link SwissKnife}.
56
+ *
57
+ * Written out rather than inferred because `declaration: true` cannot emit an
58
+ * inferred object type whose members reference types their own module does not
59
+ * export (TS4023) — `CrashReporting`'s internals are the case in point. Every
60
+ * member is a `typeof` query on the thing it re-exports, so this stays a
61
+ * restatement of the wiring and can never disagree with it.
62
+ */
63
+ export interface SwissKnifeSDK {
64
+ configure: typeof configure;
65
+ configureCore: typeof configureCore;
66
+ isConfigured: typeof isConfigured;
67
+ isCoreConfigured: typeof isCoreConfigured;
68
+ setLogLevel: typeof setLogLevel;
69
+ Purchases: typeof Purchases;
70
+ Identity: typeof Identity;
71
+ Attributes: typeof Attributes;
72
+ Attribution: typeof Attribution;
73
+ Analytics: typeof Analytics;
74
+ CrashReporting: typeof CrashReporting;
75
+ Performance: typeof Performance;
76
+ /** @internal */
77
+ __resetForTests(): void;
78
+ }
79
+
80
+ /**
81
+ * The Swiss Knife SDK root — bootstrap plus a handle on every namespace.
82
+ *
83
+ * ```ts
84
+ * import { SwissKnife } from "@app-swiss-knife/react-native-sdk";
85
+ *
86
+ * // Full SDK, we own the store:
87
+ * SwissKnife.configure({ apiKey: "sk_live_…", proxyURL: "https://…" });
88
+ *
89
+ * // Another library owns in-app purchases:
90
+ * SwissKnife.configureCore({ apiKey: "sk_live_…", proxyURL: "https://…" });
91
+ *
92
+ * await SwissKnife.Identity.logIn("user_42");
93
+ * await SwissKnife.Attributes.setEmail("ann@example.com");
94
+ * ```
95
+ *
96
+ * `Purchases.configure` / `Purchases.configureCore` are RC-compatibility
97
+ * aliases for the first two and remain fully supported — they are the *same
98
+ * functions*, so an app that mixes the spellings shares one bootstrap state.
99
+ */
100
+ export const SwissKnife: SwissKnifeSDK = {
101
+ // MARK: - Bootstrap
102
+ configure,
103
+ configureCore,
104
+ isConfigured,
105
+ isCoreConfigured,
106
+ setLogLevel,
107
+
108
+ // MARK: - Namespaces
109
+ /** In-app purchases + the RevenueCat-compatible surface. */
110
+ Purchases,
111
+ /** Who this device is. `logIn` / `logOut` / `current` / `reset` / `wipe`. */
112
+ Identity,
113
+ /** Subscriber attributes — the dashboard person card. */
114
+ Attributes,
115
+ /** Install attribution: ATT / IDFA / advertising id / install referrer. */
116
+ Attribution,
117
+ /** Product analytics: `init` / `track` / `identify` / `screen`. */
118
+ Analytics,
119
+ /** Crash + error reporting. */
120
+ CrashReporting,
121
+ /** Performance transactions and spans. */
122
+ Performance,
123
+
124
+ /**
125
+ * @internal Test seam: reset the process-wide configure state and `Identity`'s
126
+ * caches. Identical to `Purchases.__resetForTests()` — it is the same call, so
127
+ * a suite written against either namespace resets the same singletons.
128
+ */
129
+ __resetForTests(): void {
130
+ Purchases.__resetForTests();
131
+ },
132
+ };
133
+
134
+ export default SwissKnife;
package/src/types.ts CHANGED
@@ -469,6 +469,20 @@ export interface PurchasesConfiguration {
469
469
  pendingTransactionsForPrepaidPlansEnabled?: boolean;
470
470
  }
471
471
 
472
+ /**
473
+ * Options accepted by `SwissKnife.configure(...)` / `SwissKnife.configureCore(...)`
474
+ * — and, identically, by their `Purchases.*` RC-compatibility aliases.
475
+ *
476
+ * A name for what the two bootstrap entry points have always taken:
477
+ * `PurchasesConfiguration & { logLevel?: LOG_LEVEL }`. `logLevel` is not part of
478
+ * RevenueCat's `PurchasesConfiguration`, so it cannot go on that interface
479
+ * without breaking the mirror; it is accepted here because setting the log level
480
+ * *after* configure is too late to debug the configure itself.
481
+ */
482
+ export type ConfigureOptions = PurchasesConfiguration & {
483
+ logLevel?: LOG_LEVEL;
484
+ };
485
+
472
486
  // MARK: - Event listeners
473
487
 
474
488
  /**