@app-swiss-knife/react-native-sdk 0.1.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 (218) hide show
  1. package/README.md +182 -0
  2. package/SwissKnifePurchases.podspec +40 -0
  3. package/android/build.gradle +89 -0
  4. package/android/gradle.properties +3 -0
  5. package/android/src/main/AndroidManifest.xml +26 -0
  6. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +216 -0
  7. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingPackage.kt +17 -0
  8. package/android/src/main/java/com/swissknife/purchases/Conversions.kt +15 -0
  9. package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +371 -0
  10. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +497 -0
  11. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesPackage.kt +25 -0
  12. package/android/vendor/GENERATED.md +10 -0
  13. package/android/vendor/java/com/appswissknife/SwissKnife.kt +533 -0
  14. package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +326 -0
  15. package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +296 -0
  16. package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +503 -0
  17. package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +188 -0
  18. package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +204 -0
  19. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +447 -0
  20. package/android/vendor/java/com/appswissknife/context/AppLifecycle.kt +120 -0
  21. package/android/vendor/java/com/appswissknife/context/Clock.kt +70 -0
  22. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +138 -0
  23. package/android/vendor/java/com/appswissknife/context/IDs.kt +55 -0
  24. package/android/vendor/java/com/appswissknife/context/Reachability.kt +145 -0
  25. package/android/vendor/java/com/appswissknife/context/Session.kt +192 -0
  26. package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +945 -0
  27. package/android/vendor/java/com/appswissknife/crashreporting/SKScreenshot.kt +201 -0
  28. package/android/vendor/java/com/appswissknife/device/DeviceID.kt +172 -0
  29. package/android/vendor/java/com/appswissknife/diagnostics/SKLog.kt +97 -0
  30. package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +495 -0
  31. package/android/vendor/java/com/appswissknife/identity/Identity.kt +522 -0
  32. package/android/vendor/java/com/appswissknife/models/CustomerInfo.kt +67 -0
  33. package/android/vendor/java/com/appswissknife/models/Enums.kt +35 -0
  34. package/android/vendor/java/com/appswissknife/models/Offerings.kt +80 -0
  35. package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +89 -0
  36. package/android/vendor/java/com/appswissknife/models/StoreTransaction.kt +17 -0
  37. package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +507 -0
  38. package/android/vendor/java/com/appswissknife/net/ExponentialBackoff.kt +69 -0
  39. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +582 -0
  40. package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +320 -0
  41. package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +219 -0
  42. package/android/vendor/java/com/appswissknife/performance/SKFrameTracker.kt +94 -0
  43. package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +428 -0
  44. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +560 -0
  45. package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +100 -0
  46. package/android/vendor/java/com/appswissknife/purchases/PriceEnrichmentProvider.kt +36 -0
  47. package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +120 -0
  48. package/android/vendor/res/xml/swissknife_data_extraction_rules.xml +20 -0
  49. package/ios/SwissKnifeCrashReporting.m +32 -0
  50. package/ios/SwissKnifeCrashReporting.swift +186 -0
  51. package/ios/SwissKnifeJSON.swift +347 -0
  52. package/ios/SwissKnifePurchases.m +124 -0
  53. package/ios/SwissKnifePurchases.swift +523 -0
  54. package/ios/vendor/GENERATED.md +10 -0
  55. package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +488 -0
  56. package/ios/vendor/SwissKnifeiOS/AttributesClient.swift +460 -0
  57. package/ios/vendor/SwissKnifeiOS/Attribution/Attribution.swift +307 -0
  58. package/ios/vendor/SwissKnifeiOS/Attribution/AttributionNetwork.swift +92 -0
  59. package/ios/vendor/SwissKnifeiOS/Attribution/AttributionState.swift +141 -0
  60. package/ios/vendor/SwissKnifeiOS/Context/AppLifecycle.swift +130 -0
  61. package/ios/vendor/SwissKnifeiOS/Context/Clock.swift +100 -0
  62. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +190 -0
  63. package/ios/vendor/SwissKnifeiOS/Context/IDs.swift +64 -0
  64. package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +121 -0
  65. package/ios/vendor/SwissKnifeiOS/Context/Session.swift +223 -0
  66. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +1287 -0
  67. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKScreenshot.swift +175 -0
  68. package/ios/vendor/SwissKnifeiOS/DeviceID.swift +161 -0
  69. package/ios/vendor/SwissKnifeiOS/Diagnostics/SKLog.swift +128 -0
  70. package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +323 -0
  71. package/ios/vendor/SwissKnifeiOS/Identity/IdentityNetwork.swift +70 -0
  72. package/ios/vendor/SwissKnifeiOS/Net/BackendHttpClient.swift +329 -0
  73. package/ios/vendor/SwissKnifeiOS/Net/ExponentialBackoff.swift +87 -0
  74. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +681 -0
  75. package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +409 -0
  76. package/ios/vendor/SwissKnifeiOS/Performance/SKFrameTracker.swift +89 -0
  77. package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +440 -0
  78. package/ios/vendor/SwissKnifeiOS/Performance/SKURLSessionDelegate.swift +87 -0
  79. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +646 -0
  80. package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +458 -0
  81. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +374 -0
  82. package/ios/vendor/SwissKnifeiOS/SwissKnife+Analytics.swift +46 -0
  83. package/ios/vendor/SwissKnifeiOS/SwissKnife+DeviceID.swift +30 -0
  84. package/ios/vendor/SwissKnifeiOS/SwissKnife+Session.swift +47 -0
  85. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +417 -0
  86. package/ios/vendor/SwissKnifeiOS/Types.swift +496 -0
  87. package/lib/commonjs/attribution.js +55 -0
  88. package/lib/commonjs/attribution.js.map +1 -0
  89. package/lib/commonjs/identity.js +126 -0
  90. package/lib/commonjs/identity.js.map +1 -0
  91. package/lib/commonjs/index.js +118 -0
  92. package/lib/commonjs/index.js.map +1 -0
  93. package/lib/commonjs/modules/analytics.js +646 -0
  94. package/lib/commonjs/modules/analytics.js.map +1 -0
  95. package/lib/commonjs/modules/attachments.js +169 -0
  96. package/lib/commonjs/modules/attachments.js.map +1 -0
  97. package/lib/commonjs/modules/crash-reporting.js +1327 -0
  98. package/lib/commonjs/modules/crash-reporting.js.map +1 -0
  99. package/lib/commonjs/modules/ids.js +50 -0
  100. package/lib/commonjs/modules/ids.js.map +1 -0
  101. package/lib/commonjs/modules/log.js +59 -0
  102. package/lib/commonjs/modules/log.js.map +1 -0
  103. package/lib/commonjs/modules/offline-store.js +44 -0
  104. package/lib/commonjs/modules/offline-store.js.map +1 -0
  105. package/lib/commonjs/modules/performance.js +494 -0
  106. package/lib/commonjs/modules/performance.js.map +1 -0
  107. package/lib/commonjs/native/module.js +41 -0
  108. package/lib/commonjs/native/module.js.map +1 -0
  109. package/lib/commonjs/native/spec.js +26 -0
  110. package/lib/commonjs/native/spec.js.map +1 -0
  111. package/lib/commonjs/package.json +1 -0
  112. package/lib/commonjs/purchases.js +194 -0
  113. package/lib/commonjs/purchases.js.map +1 -0
  114. package/lib/commonjs/types.js +236 -0
  115. package/lib/commonjs/types.js.map +1 -0
  116. package/lib/module/attribution.js +51 -0
  117. package/lib/module/attribution.js.map +1 -0
  118. package/lib/module/identity.js +122 -0
  119. package/lib/module/identity.js.map +1 -0
  120. package/lib/module/index.js +36 -0
  121. package/lib/module/index.js.map +1 -0
  122. package/lib/module/modules/analytics.js +642 -0
  123. package/lib/module/modules/analytics.js.map +1 -0
  124. package/lib/module/modules/attachments.js +162 -0
  125. package/lib/module/modules/attachments.js.map +1 -0
  126. package/lib/module/modules/crash-reporting.js +1320 -0
  127. package/lib/module/modules/crash-reporting.js.map +1 -0
  128. package/lib/module/modules/ids.js +44 -0
  129. package/lib/module/modules/ids.js.map +1 -0
  130. package/lib/module/modules/log.js +54 -0
  131. package/lib/module/modules/log.js.map +1 -0
  132. package/lib/module/modules/offline-store.js +39 -0
  133. package/lib/module/modules/offline-store.js.map +1 -0
  134. package/lib/module/modules/performance.js +491 -0
  135. package/lib/module/modules/performance.js.map +1 -0
  136. package/lib/module/native/module.js +34 -0
  137. package/lib/module/native/module.js.map +1 -0
  138. package/lib/module/native/spec.js +22 -0
  139. package/lib/module/native/spec.js.map +1 -0
  140. package/lib/module/package.json +1 -0
  141. package/lib/module/purchases.js +187 -0
  142. package/lib/module/purchases.js.map +1 -0
  143. package/lib/module/types.js +230 -0
  144. package/lib/module/types.js.map +1 -0
  145. package/lib/typescript/commonjs/attribution.d.ts +24 -0
  146. package/lib/typescript/commonjs/attribution.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/identity.d.ts +37 -0
  148. package/lib/typescript/commonjs/identity.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/index.d.ts +15 -0
  150. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/modules/analytics.d.ts +127 -0
  152. package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/modules/attachments.d.ts +50 -0
  154. package/lib/typescript/commonjs/modules/attachments.d.ts.map +1 -0
  155. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +175 -0
  156. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -0
  157. package/lib/typescript/commonjs/modules/ids.d.ts +17 -0
  158. package/lib/typescript/commonjs/modules/ids.d.ts.map +1 -0
  159. package/lib/typescript/commonjs/modules/log.d.ts +12 -0
  160. package/lib/typescript/commonjs/modules/log.d.ts.map +1 -0
  161. package/lib/typescript/commonjs/modules/offline-store.d.ts +9 -0
  162. package/lib/typescript/commonjs/modules/offline-store.d.ts.map +1 -0
  163. package/lib/typescript/commonjs/modules/performance.d.ts +75 -0
  164. package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/native/module.d.ts +6 -0
  166. package/lib/typescript/commonjs/native/module.d.ts.map +1 -0
  167. package/lib/typescript/commonjs/native/spec.d.ts +119 -0
  168. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -0
  169. package/lib/typescript/commonjs/package.json +1 -0
  170. package/lib/typescript/commonjs/purchases.d.ts +68 -0
  171. package/lib/typescript/commonjs/purchases.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/types.d.ts +384 -0
  173. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  174. package/lib/typescript/module/attribution.d.ts +24 -0
  175. package/lib/typescript/module/attribution.d.ts.map +1 -0
  176. package/lib/typescript/module/identity.d.ts +37 -0
  177. package/lib/typescript/module/identity.d.ts.map +1 -0
  178. package/lib/typescript/module/index.d.ts +15 -0
  179. package/lib/typescript/module/index.d.ts.map +1 -0
  180. package/lib/typescript/module/modules/analytics.d.ts +127 -0
  181. package/lib/typescript/module/modules/analytics.d.ts.map +1 -0
  182. package/lib/typescript/module/modules/attachments.d.ts +50 -0
  183. package/lib/typescript/module/modules/attachments.d.ts.map +1 -0
  184. package/lib/typescript/module/modules/crash-reporting.d.ts +175 -0
  185. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -0
  186. package/lib/typescript/module/modules/ids.d.ts +17 -0
  187. package/lib/typescript/module/modules/ids.d.ts.map +1 -0
  188. package/lib/typescript/module/modules/log.d.ts +12 -0
  189. package/lib/typescript/module/modules/log.d.ts.map +1 -0
  190. package/lib/typescript/module/modules/offline-store.d.ts +9 -0
  191. package/lib/typescript/module/modules/offline-store.d.ts.map +1 -0
  192. package/lib/typescript/module/modules/performance.d.ts +75 -0
  193. package/lib/typescript/module/modules/performance.d.ts.map +1 -0
  194. package/lib/typescript/module/native/module.d.ts +6 -0
  195. package/lib/typescript/module/native/module.d.ts.map +1 -0
  196. package/lib/typescript/module/native/spec.d.ts +119 -0
  197. package/lib/typescript/module/native/spec.d.ts.map +1 -0
  198. package/lib/typescript/module/package.json +1 -0
  199. package/lib/typescript/module/purchases.d.ts +68 -0
  200. package/lib/typescript/module/purchases.d.ts.map +1 -0
  201. package/lib/typescript/module/types.d.ts +384 -0
  202. package/lib/typescript/module/types.d.ts.map +1 -0
  203. package/package.json +115 -0
  204. package/react-native.config.js +23 -0
  205. package/src/attribution.ts +56 -0
  206. package/src/identity.ts +133 -0
  207. package/src/index.ts +54 -0
  208. package/src/modules/analytics.ts +689 -0
  209. package/src/modules/attachments.ts +222 -0
  210. package/src/modules/crash-reporting.ts +1577 -0
  211. package/src/modules/ids.ts +41 -0
  212. package/src/modules/log.ts +56 -0
  213. package/src/modules/offline-store.ts +51 -0
  214. package/src/modules/performance.ts +589 -0
  215. package/src/native/module.ts +47 -0
  216. package/src/native/spec.ts +183 -0
  217. package/src/purchases.ts +214 -0
  218. package/src/types.ts +470 -0
package/src/types.ts ADDED
@@ -0,0 +1,470 @@
1
+ // packages/react-native-sdk/src/types.ts
2
+ //
3
+ // Phase 7 of the RC rip-and-replace: own TypeScript type definitions that
4
+ // REPLACE the previous star-export of `@revenuecat/purchases-typescript-internal`.
5
+ // Shape mirrors RC's public API (same field names, same semantics) per the
6
+ // user-locked decision in the Phase 7 plan, so consumers of this SDK keep
7
+ // working without any source change.
8
+ //
9
+ // Why mirror RC names?
10
+ // - The public JS surface (`Purchases.configure`, `Purchases.getCustomerInfo`,
11
+ // etc.) MUST stay byte-compatible with `react-native-purchases`. The native
12
+ // bridges in `ios/SwissKnifePurchases.swift` and
13
+ // `android/.../SwissKnifePurchasesModule.kt` JSON-encode our Swift/Kotlin
14
+ // types (defined in `packages/swiss-knife-{ios,android}`) into payloads
15
+ // that match these TS shapes. One contract on both sides of the bridge.
16
+ //
17
+ // What's gone:
18
+ // - The dep on `@revenuecat/purchases-typescript-internal` — removed from
19
+ // package.json. No more PHC-licensed code ships in the SDK.
20
+ //
21
+ // What's preserved:
22
+ // - Re-exported names (`PurchasesEntitlementInfo`, `PurchasesOfferings`,
23
+ // `MakePurchaseResult`, …) so existing callers `import { Foo } from
24
+ // '@app-swiss-knife/react-native-sdk'` still compile unchanged.
25
+ // - The string-numeric `PURCHASES_ERROR_CODE` values RC uses ("0", "1", "10")
26
+ // — that's what the native bridge `reject(...)` callsite emits, so the JS
27
+ // mapper has to keep matching.
28
+
29
+ // MARK: - Value enums (must remain runtime objects, not type-only)
30
+ //
31
+ // RC's TS package exposes these as TS `enum` declarations, which means callers
32
+ // can use them as runtime values (`if (lvl === LOG_LEVEL.DEBUG) …`). We
33
+ // preserve that shape with `as const` objects so consumers don't see a behavior
34
+ // change.
35
+
36
+ /**
37
+ * SDK log level. String values match `RC.LogLevel` so the native bridge keeps
38
+ * parsing the same vocabulary on iOS and Android.
39
+ */
40
+ export const LOG_LEVEL = {
41
+ VERBOSE: "VERBOSE",
42
+ DEBUG: "DEBUG",
43
+ INFO: "INFO",
44
+ WARN: "WARN",
45
+ ERROR: "ERROR",
46
+ } as const;
47
+ export type LOG_LEVEL = (typeof LOG_LEVEL)[keyof typeof LOG_LEVEL];
48
+
49
+ /** Subscription package shape — same names as RC's `PACKAGE_TYPE`. */
50
+ export const PACKAGE_TYPE = {
51
+ UNKNOWN: "UNKNOWN",
52
+ CUSTOM: "CUSTOM",
53
+ LIFETIME: "LIFETIME",
54
+ ANNUAL: "ANNUAL",
55
+ SIX_MONTH: "SIX_MONTH",
56
+ THREE_MONTH: "THREE_MONTH",
57
+ TWO_MONTH: "TWO_MONTH",
58
+ MONTHLY: "MONTHLY",
59
+ WEEKLY: "WEEKLY",
60
+ } as const;
61
+ export type PACKAGE_TYPE = (typeof PACKAGE_TYPE)[keyof typeof PACKAGE_TYPE];
62
+
63
+ /**
64
+ * StoreKit version selection on iOS. We only support StoreKit 2 in Phase 5+,
65
+ * but the enum stays for source compatibility — `configure({ storeKitVersion:
66
+ * STOREKIT_VERSION.STOREKIT_2 })` is a no-op now.
67
+ */
68
+ export const STOREKIT_VERSION = {
69
+ DEFAULT: "DEFAULT",
70
+ STOREKIT_1: "STOREKIT_1",
71
+ STOREKIT_2: "STOREKIT_2",
72
+ } as const;
73
+ export type STOREKIT_VERSION = (typeof STOREKIT_VERSION)[keyof typeof STOREKIT_VERSION];
74
+
75
+ /** JWS / signed-response verification status. RC parity. */
76
+ export const VERIFICATION_RESULT = {
77
+ NOT_REQUESTED: "NOT_REQUESTED",
78
+ VERIFIED: "VERIFIED",
79
+ FAILED: "FAILED",
80
+ VERIFIED_ON_DEVICE: "VERIFIED_ON_DEVICE",
81
+ } as const;
82
+ export type VERIFICATION_RESULT = (typeof VERIFICATION_RESULT)[keyof typeof VERIFICATION_RESULT];
83
+
84
+ /**
85
+ * Public error-code catalog. Values are string-numeric ("0", "1", "10", …)
86
+ * so they match what RC's TS package previously emitted. The native bridges
87
+ * `reject(code, ...)` with these stringified numeric codes and the JS mapper
88
+ * picks them up by string compare — DO NOT renumber.
89
+ *
90
+ * Code → name mapping is the RC catalog the platform-native sealed classes
91
+ * already mirror (see `PurchasesError.kt`/`Types.swift`). New codes go at the
92
+ * end, never reorder.
93
+ */
94
+ export const PURCHASES_ERROR_CODE = {
95
+ UNKNOWN_ERROR: "0",
96
+ PURCHASE_CANCELLED_ERROR: "1",
97
+ STORE_PROBLEM_ERROR: "2",
98
+ PURCHASE_NOT_ALLOWED_ERROR: "3",
99
+ PURCHASE_INVALID_ERROR: "4",
100
+ PRODUCT_NOT_AVAILABLE_FOR_PURCHASE_ERROR: "5",
101
+ PRODUCT_ALREADY_PURCHASED_ERROR: "6",
102
+ RECEIPT_ALREADY_IN_USE_ERROR: "7",
103
+ INVALID_RECEIPT_ERROR: "8",
104
+ MISSING_RECEIPT_FILE_ERROR: "9",
105
+ NETWORK_ERROR: "10",
106
+ INVALID_CREDENTIALS_ERROR: "11",
107
+ UNEXPECTED_BACKEND_RESPONSE_ERROR: "12",
108
+ RECEIPT_IN_USE_BY_OTHER_SUBSCRIBER_ERROR: "13",
109
+ INVALID_APP_USER_ID_ERROR: "14",
110
+ OPERATION_ALREADY_IN_PROGRESS_ERROR: "15",
111
+ UNKNOWN_BACKEND_ERROR: "16",
112
+ INVALID_APPLE_SUBSCRIPTION_KEY_ERROR: "17",
113
+ INELIGIBLE_ERROR: "18",
114
+ INSUFFICIENT_PERMISSIONS_ERROR: "19",
115
+ PAYMENT_PENDING_ERROR: "20",
116
+ INVALID_SUBSCRIBER_ATTRIBUTES_ERROR: "21",
117
+ LOG_OUT_ANONYMOUS_USER_ERROR: "22",
118
+ CONFIGURATION_ERROR: "23",
119
+ UNSUPPORTED_ERROR: "24",
120
+ EMPTY_SUBSCRIBER_ATTRIBUTES_ERROR: "25",
121
+ CUSTOMER_INFO_ERROR: "28",
122
+ } as const;
123
+ export type PURCHASES_ERROR_CODE =
124
+ (typeof PURCHASES_ERROR_CODE)[keyof typeof PURCHASES_ERROR_CODE];
125
+
126
+ // MARK: - Errors thrown / referenced by the Purchases class
127
+
128
+ /**
129
+ * Thrown by `Purchases.<method>()` when called before `Purchases.configure(...)`.
130
+ * Matches the name + shape of RC's `UninitializedPurchasesError` so callers
131
+ * catching by class name keep working.
132
+ */
133
+ export class UninitializedPurchasesError extends Error {
134
+ constructor(
135
+ message: string = "Purchases is not configured. Call Purchases.configure() first.",
136
+ ) {
137
+ super(message);
138
+ this.name = "UninitializedPurchasesError";
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Thrown when an API is called on an unsupported platform (e.g. web). Kept
144
+ * for source compatibility with RC.
145
+ */
146
+ export class UnsupportedPlatformError extends Error {
147
+ constructor(
148
+ message: string = "This method is not supported on the current platform.",
149
+ ) {
150
+ super(message);
151
+ this.name = "UnsupportedPlatformError";
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Plain-object error contract used on callback args and rejected promises.
157
+ * NOT an Error subclass — RC surfaces this as a value, not something thrown
158
+ * as a JS Error. Promise rejections from the native bridge come through as
159
+ * `Error` objects whose `code` and `message` fields match this shape.
160
+ */
161
+ export interface PurchasesError {
162
+ code: PURCHASES_ERROR_CODE;
163
+ message: string;
164
+ underlyingErrorMessage?: string;
165
+ readableErrorCode?: string;
166
+ }
167
+
168
+ // MARK: - Customer / Entitlement domain
169
+
170
+ /**
171
+ * Per-entitlement state. Field names match RC's `PurchasesEntitlementInfo`
172
+ * 1:1; populated by the native bridge from our own `EntitlementInfo` Swift /
173
+ * Kotlin types (see `packages/swiss-knife-{ios,android}`).
174
+ *
175
+ * Dates are ISO-8601 strings on the wire — JS doesn't get a native `Date`
176
+ * across the RN bridge.
177
+ */
178
+ export interface PurchasesEntitlementInfo {
179
+ identifier: string;
180
+ isActive: boolean;
181
+ willRenew: boolean;
182
+ latestPurchaseDate: string;
183
+ /** ms-since-epoch convenience field; some RC consumers grep for `_millis`. */
184
+ latestPurchaseDateMillis: number;
185
+ originalPurchaseDate: string | null;
186
+ originalPurchaseDateMillis: number | null;
187
+ expirationDate: string | null;
188
+ expirationDateMillis: number | null;
189
+ productIdentifier: string;
190
+ productPlanIdentifier: string | null;
191
+ isSandbox: boolean;
192
+ unsubscribeDetectedAt: string | null;
193
+ unsubscribeDetectedAtMillis: number | null;
194
+ billingIssueDetectedAt: string | null;
195
+ billingIssueDetectedAtMillis: number | null;
196
+ periodType: "NORMAL" | "INTRO" | "TRIAL" | "PREPAID";
197
+ store:
198
+ | "APP_STORE"
199
+ | "MAC_APP_STORE"
200
+ | "PLAY_STORE"
201
+ | "STRIPE"
202
+ | "PROMOTIONAL"
203
+ | "AMAZON"
204
+ | "RUSTORE"
205
+ | "UNKNOWN_STORE";
206
+ ownershipType: "PURCHASED" | "FAMILY_SHARED" | "UNKNOWN";
207
+ verification: VERIFICATION_RESULT;
208
+ }
209
+
210
+ /** All entitlements the user has ever owned + the currently-active subset. */
211
+ export interface PurchasesEntitlementInfos {
212
+ all: { [key: string]: PurchasesEntitlementInfo };
213
+ active: { [key: string]: PurchasesEntitlementInfo };
214
+ verification: VERIFICATION_RESULT;
215
+ }
216
+
217
+ /** Subscription-only state per product (renewal status, period, etc.). */
218
+ export interface PurchasesSubscriptionInfo {
219
+ productIdentifier: string;
220
+ purchaseDate: string | null;
221
+ originalPurchaseDate: string | null;
222
+ expiresDate: string | null;
223
+ store: PurchasesEntitlementInfo["store"];
224
+ unsubscribeDetectedAt: string | null;
225
+ isSandbox: boolean;
226
+ billingIssuesDetectedAt: string | null;
227
+ gracePeriodExpiresDate: string | null;
228
+ ownershipType: PurchasesEntitlementInfo["ownershipType"];
229
+ periodType: PurchasesEntitlementInfo["periodType"];
230
+ refundedAt: string | null;
231
+ storeTransactionId: string | null;
232
+ isActive: boolean;
233
+ willRenew: boolean;
234
+ }
235
+
236
+ /** One non-subscription IAP transaction (consumable/non-consumable). */
237
+ export interface PurchasesStoreTransaction {
238
+ productIdentifier: string;
239
+ revenueCatId: string;
240
+ purchaseDate: string;
241
+ /** Raw store transaction id (App Store `transactionIdentifier` or Play `orderId`). */
242
+ storeTransactionId: string;
243
+ }
244
+
245
+ /**
246
+ * Top-level user-level state, populated from our own `CustomerInfo` types on
247
+ * the native side. Field names track RC's `CustomerInfo` shape.
248
+ */
249
+ export interface CustomerInfo {
250
+ entitlements: PurchasesEntitlementInfos;
251
+ /** Active entitlement identifiers — convenience accessor. */
252
+ activeSubscriptions: string[];
253
+ allPurchasedProductIdentifiers: string[];
254
+ /** Product id → most recent purchase date (ISO-8601). */
255
+ allPurchaseDates: { [key: string]: string | null };
256
+ /** Per-product subscription info, keyed by product id. */
257
+ subscriptionsByProductIdentifier: { [key: string]: PurchasesSubscriptionInfo };
258
+ /** Non-subscription IAPs (consumables, one-time non-consumables). */
259
+ nonSubscriptionTransactions: PurchasesStoreTransaction[];
260
+ firstSeen: string;
261
+ /** ms-since-epoch convenience field. */
262
+ firstSeenMillis: number;
263
+ originalAppUserId: string;
264
+ requestDate: string;
265
+ requestDateMillis: number;
266
+ latestExpirationDate: string | null;
267
+ latestExpirationDateMillis: number | null;
268
+ originalPurchaseDate: string | null;
269
+ originalPurchaseDateMillis: number | null;
270
+ originalApplicationVersion: string | null;
271
+ managementURL: string | null;
272
+ }
273
+
274
+ // MARK: - Products / packages / offerings
275
+
276
+ /** Localized price + currency on a store product. Mirror of RC's `PurchasesStoreProductPrice`. */
277
+ export interface PurchasesStoreProductPrice {
278
+ /** Pre-formatted, localized price string from the store. */
279
+ formatted: string;
280
+ /** Numeric amount in the smallest unit of the currency. */
281
+ amountMicros: number;
282
+ /** ISO-4217 currency code. */
283
+ currencyCode: string;
284
+ }
285
+
286
+ /** Subscription period on a store product. */
287
+ export interface PurchasesSubscriptionPeriod {
288
+ unit: "DAY" | "WEEK" | "MONTH" | "YEAR";
289
+ value: number;
290
+ }
291
+
292
+ /** Intro / promotional offer on a store product. */
293
+ export interface PurchasesStoreProductDiscount {
294
+ identifier: string | null;
295
+ price: number;
296
+ priceString: string;
297
+ cycles: number;
298
+ period: PurchasesSubscriptionPeriod;
299
+ periodUnit: PurchasesSubscriptionPeriod["unit"];
300
+ periodNumberOfUnits: number;
301
+ }
302
+
303
+ /** One store product (subscription or non-subscription). */
304
+ export interface PurchasesStoreProduct {
305
+ identifier: string;
306
+ title: string;
307
+ description: string;
308
+ priceString: string;
309
+ price: number;
310
+ currencyCode: string;
311
+ productCategory: "SUBSCRIPTION" | "NON_SUBSCRIPTION";
312
+ productType:
313
+ | "AUTO_RENEWABLE_SUBSCRIPTION"
314
+ | "NON_RENEWABLE_SUBSCRIPTION"
315
+ | "NON_CONSUMABLE"
316
+ | "CONSUMABLE"
317
+ | "UNKNOWN";
318
+ subscriptionPeriod: string | null;
319
+ defaultOption: string | null;
320
+ subscriptionOptions: unknown[] | null;
321
+ presentedOfferingContext: PresentedOfferingContext | null;
322
+ introPrice: PurchasesStoreProductDiscount | null;
323
+ discounts: PurchasesStoreProductDiscount[] | null;
324
+ pricePerWeek: PurchasesStoreProductPrice | null;
325
+ pricePerMonth: PurchasesStoreProductPrice | null;
326
+ pricePerYear: PurchasesStoreProductPrice | null;
327
+ pricePerWeekString: string | null;
328
+ pricePerMonthString: string | null;
329
+ pricePerYearString: string | null;
330
+ }
331
+
332
+ /**
333
+ * The offering / package / target context surfaced when a package is presented.
334
+ * `targetingContext` is RC-server-driven A/B test metadata; preserved for parity.
335
+ */
336
+ export interface PresentedOfferingContext {
337
+ offeringIdentifier: string;
338
+ placementIdentifier: string | null;
339
+ targetingContext: { revision: number; ruleId: string } | null;
340
+ }
341
+
342
+ /** A purchasable package inside an offering. */
343
+ export interface PurchasesPackage {
344
+ identifier: string;
345
+ packageType: PACKAGE_TYPE;
346
+ product: PurchasesStoreProduct;
347
+ presentedOfferingContext: PresentedOfferingContext;
348
+ /** RC legacy: same as `presentedOfferingContext.offeringIdentifier`. */
349
+ offeringIdentifier: string;
350
+ }
351
+
352
+ /** A named group of packages — a paywall variant. */
353
+ export interface PurchasesOffering {
354
+ identifier: string;
355
+ serverDescription: string;
356
+ metadata: { [key: string]: unknown };
357
+ availablePackages: PurchasesPackage[];
358
+ lifetime: PurchasesPackage | null;
359
+ annual: PurchasesPackage | null;
360
+ sixMonth: PurchasesPackage | null;
361
+ threeMonth: PurchasesPackage | null;
362
+ twoMonth: PurchasesPackage | null;
363
+ monthly: PurchasesPackage | null;
364
+ weekly: PurchasesPackage | null;
365
+ paywall: unknown | null;
366
+ paywallComponents: unknown | null;
367
+ }
368
+
369
+ /** Top-level offerings container. */
370
+ export interface PurchasesOfferings {
371
+ all: { [key: string]: PurchasesOffering };
372
+ current: PurchasesOffering | null;
373
+ }
374
+
375
+ // MARK: - Public-method result types
376
+
377
+ /** Returned by `Purchases.logIn(appUserID)`. */
378
+ export interface LogInResult {
379
+ customerInfo: CustomerInfo;
380
+ /** Whether the backend treated this as a brand-new user record. */
381
+ created: boolean;
382
+ }
383
+
384
+ // MARK: - Identity (Wave 1)
385
+
386
+ /**
387
+ * Immutable snapshot of the current identity. Mirrors
388
+ * `SwissKnife.Identity.Snapshot` (iOS) and
389
+ * `com.appswissknife.identity.Identity.Snapshot` (Android).
390
+ *
391
+ * The `anonymousId` carries the unified `$SKAnonymousID:` prefix as of
392
+ * Wave 1 (was `$RCAnonymousID:` on Android pre-Wave-1).
393
+ */
394
+ export interface IdentitySnapshot {
395
+ anonymousId: string;
396
+ userId: string | null;
397
+ isAnonymous: boolean;
398
+ }
399
+
400
+ /** Delivered to `Identity.addObserver` callbacks on every transition. */
401
+ export interface IdentityChange {
402
+ previous: IdentitySnapshot;
403
+ current: IdentitySnapshot;
404
+ }
405
+
406
+ // MARK: - Attribution (Wave 2)
407
+
408
+ /**
409
+ * Resolved attribution for the install. Mirrors
410
+ * `SwissKnife.Attribution.ResolvedAttribution` (iOS) and
411
+ * `Attribution.ResolvedAttribution` (Android).
412
+ */
413
+ export interface ResolvedAttribution {
414
+ /** One of `"advertising_id" | "referrer" | "fingerprint" | "organic"`. */
415
+ method: string;
416
+ /** Backend campaign id when the install matched a campaign; `null` otherwise. */
417
+ campaignId: string | null;
418
+ /** Epoch milliseconds when the SDK persisted the resolution. */
419
+ resolvedAt: number;
420
+ }
421
+
422
+ /** Returned by `Purchases.purchasePackage(...)` / `purchaseStoreProduct(...)`. */
423
+ export interface MakePurchaseResult {
424
+ productIdentifier: string;
425
+ customerInfo: CustomerInfo;
426
+ transaction: PurchasesStoreTransaction | null;
427
+ }
428
+
429
+ // MARK: - Configuration
430
+
431
+ /** Options accepted by `Purchases.configure(...)`. Mirror of `PurchasesConfiguration`. */
432
+ export interface PurchasesConfiguration {
433
+ apiKey: string;
434
+ appUserID?: string | null;
435
+ /** Override the backend host — primarily used in our own configuration to point at our backend rather than RC's. */
436
+ proxyURL?: string | null;
437
+ /** Whether to phone home diagnostics. DEFAULTS TO FALSE in our SDK. */
438
+ diagnosticsEnabled?: boolean;
439
+ storeKitVersion?: STOREKIT_VERSION;
440
+ /**
441
+ * iOS App Tracking Transparency. When `true`, the SDK shows the system ATT
442
+ * prompt on first launch (requires `NSUserTrackingUsageDescription` in
443
+ * Info.plist). **Defaults to `false`** — the SDK never prompts for tracking
444
+ * unless you opt in. iOS-only; ignored on Android.
445
+ */
446
+ autoPromptATT?: boolean;
447
+ /**
448
+ * Register an organic install on first launch (no IDFA, no prompt) so
449
+ * attribution still resolves without ATT. Default `true`. iOS-only.
450
+ */
451
+ sendInstallOnFirstLaunch?: boolean;
452
+ /** Reserved for the Amazon flavor — ignored on iOS / Play Android. */
453
+ useAmazon?: boolean;
454
+ /** Reserved for the legacy bridge; ignored. */
455
+ usesStoreKit2IfAvailable?: boolean;
456
+ /** RC-shim — kept so configs the consumer copied from RC docs still compile. */
457
+ userDefaultsSuiteName?: string;
458
+ shouldShowInAppMessagesAutomatically?: boolean;
459
+ entitlementVerificationMode?: string;
460
+ pendingTransactionsForPrepaidPlansEnabled?: boolean;
461
+ }
462
+
463
+ // MARK: - Event listeners
464
+
465
+ /**
466
+ * Callback signature for `Purchases.addCustomerInfoUpdateListener(fn)`. Fires
467
+ * on every CustomerInfo refresh (post-purchase, post-restore, dashboard-grant
468
+ * silent-push, etc.).
469
+ */
470
+ export type CustomerInfoUpdateListener = (customerInfo: CustomerInfo) => void;