@adapty/core 3.15.0-dev.11e2c53bb5aaf58bf319abd22d240e6936c010b9

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/dist/index.mjs ADDED
@@ -0,0 +1,2937 @@
1
+ //#region src/platform.ts
2
+ var Platform = class Platform {
3
+ static get OS() {
4
+ return Platform._os;
5
+ }
6
+ static set OS(value) {
7
+ Platform._os = value;
8
+ }
9
+ };
10
+ Platform._os = "unknown";
11
+
12
+ //#endregion
13
+ //#region src/types/inputs.ts
14
+ /**
15
+ * Log levels for the SDK
16
+ *
17
+ * @remarks
18
+ * Logging is performed on a native side.
19
+ * So you are expected to watch logs in Xcode or Android Studio.
20
+ */
21
+ const LogLevel = Object.freeze({
22
+ VERBOSE: "verbose",
23
+ ERROR: "error",
24
+ WARN: "warn",
25
+ INFO: "info"
26
+ });
27
+ const FetchPolicy = Object.freeze({
28
+ ReloadRevalidatingCacheData: "reload_revalidating_cache_data",
29
+ ReturnCacheDataElseLoad: "return_cache_data_else_load",
30
+ ReturnCacheDataIfNotExpiredElseLoad: "return_cache_data_if_not_expired_else_load"
31
+ });
32
+ const AdaptyAndroidSubscriptionUpdateReplacementMode = Object.freeze({
33
+ ChargeFullPrice: "charge_full_price",
34
+ Deferred: "deferred",
35
+ WithoutProration: "without_proration",
36
+ ChargeProratedPrice: "charge_prorated_price",
37
+ WithTimeProration: "with_time_proration"
38
+ });
39
+
40
+ //#endregion
41
+ //#region src/logger/console-sink.ts
42
+ function getConsoleForLevel(level) {
43
+ switch (level) {
44
+ case "error": return console.error;
45
+ case "warn": return console.warn;
46
+ case "verbose": return console.debug;
47
+ case "info":
48
+ default: return console.info;
49
+ }
50
+ }
51
+ const consoleLogSink = {
52
+ id: "console",
53
+ handle: (event) => {
54
+ const logger = getConsoleForLevel(event.level);
55
+ logger(event.formatted, event.params);
56
+ }
57
+ };
58
+
59
+ //#endregion
60
+ //#region src/logger/log.ts
61
+ var Log = class Log {
62
+ /**
63
+ * Override the version shown in log messages
64
+ * @internal
65
+ */
66
+ static setVersion(version) {
67
+ this._version = version;
68
+ }
69
+ static formatMessage(message, funcName) {
70
+ const now = new Date().toISOString();
71
+ return `[${now}] [adapty@${this._version}] "${funcName}": ${message}`;
72
+ }
73
+ /** Configure JS logger: replace sinks and/or set default metadata */
74
+ static configure(config) {
75
+ if (config.sinks) {
76
+ for (const sink of this.sinks) sink.destroy?.();
77
+ this.sinks = config.sinks.slice();
78
+ }
79
+ this.defaultMeta = config.defaultMeta;
80
+ }
81
+ /** Register additional sink */
82
+ static addSink(sink) {
83
+ this.sinks.push(sink);
84
+ }
85
+ /** Remove sink by id and call its destroy if present */
86
+ static removeSink(id) {
87
+ const sink = this.sinks.find((sink$1) => sink$1.id === id);
88
+ this.sinks = this.sinks.filter((sink$1) => sink$1.id !== id);
89
+ sink?.destroy?.();
90
+ }
91
+ /** Clear all sinks and destroy them */
92
+ static clearSinks() {
93
+ const prev = this.sinks;
94
+ this.sinks = [];
95
+ for (const sink of prev) sink.destroy?.();
96
+ }
97
+ /**
98
+ * Gets the appropriate log level integer for a log level.
99
+ * @internal
100
+ */
101
+ static getLogLevelInt(logLevel) {
102
+ switch (logLevel) {
103
+ case LogLevel.ERROR: return 0;
104
+ case LogLevel.WARN: return 1;
105
+ case LogLevel.INFO: return 2;
106
+ case LogLevel.VERBOSE: return 3;
107
+ }
108
+ }
109
+ /**
110
+ * Logs a message to the console if the log level is appropriate.
111
+ * Uses lazy evaluation to avoid unnecessary computations.
112
+ * @internal
113
+ */
114
+ static log(logLevel, funcName, message, params) {
115
+ if (!Log.logLevel) return;
116
+ const currentLevel = Log.getLogLevelInt(Log.logLevel);
117
+ const messageLevel = Log.getLogLevelInt(logLevel);
118
+ if (messageLevel <= currentLevel) {
119
+ const resolvedMessage = message();
120
+ const resolvedParams = params ? params() : void 0;
121
+ const mergedParams = this.defaultMeta ? {
122
+ ...this.defaultMeta,
123
+ ...resolvedParams ?? {}
124
+ } : resolvedParams;
125
+ const formatted = Log.formatMessage(resolvedMessage, funcName);
126
+ const event = {
127
+ timestamp: new Date().toISOString(),
128
+ version: this._version,
129
+ level: logLevel,
130
+ funcName,
131
+ message: resolvedMessage,
132
+ params: mergedParams,
133
+ formatted
134
+ };
135
+ for (const sink of this.sinks) {
136
+ if (sink.levels && !sink.levels.includes(logLevel)) continue;
137
+ try {
138
+ sink.handle(event);
139
+ } catch {}
140
+ }
141
+ }
142
+ }
143
+ static info(funcName, message, params) {
144
+ this.log(LogLevel.INFO, funcName, message, params);
145
+ }
146
+ static warn(funcName, message, params) {
147
+ this.log(LogLevel.WARN, funcName, message, params);
148
+ }
149
+ static error(funcName, message, params) {
150
+ this.log(LogLevel.ERROR, funcName, message, params);
151
+ }
152
+ static verbose(funcName, message, params) {
153
+ this.log(LogLevel.VERBOSE, funcName, message, params);
154
+ }
155
+ };
156
+ Log.logLevel = null;
157
+ Log.sinks = [consoleLogSink];
158
+ Log.defaultMeta = void 0;
159
+ Log._version = "unknown";
160
+
161
+ //#endregion
162
+ //#region src/logger/log-scope.ts
163
+ var LogScope = class {
164
+ constructor(args) {
165
+ this.methodName = void 0;
166
+ this.onStart = void 0;
167
+ this.onSuccess = void 0;
168
+ this.onFailed = void 0;
169
+ this.onWait = void 0;
170
+ this.onWaitComplete = void 0;
171
+ this.methodName = args.methodName;
172
+ this.onStart = args.onStart;
173
+ this.onSuccess = args.onSuccess;
174
+ this.onFailed = args.onFailed;
175
+ this.onWait = args.onWait;
176
+ this.onWaitComplete = args.onWaitComplete;
177
+ }
178
+ start(args) {
179
+ this.onStart(args);
180
+ }
181
+ wait(args) {
182
+ this.onWait(args);
183
+ }
184
+ waitComplete(args) {
185
+ this.onWaitComplete(args);
186
+ }
187
+ success(args) {
188
+ this.onSuccess(args);
189
+ }
190
+ failed(args) {
191
+ this.onFailed(args);
192
+ }
193
+ };
194
+
195
+ //#endregion
196
+ //#region src/logger/log-context.ts
197
+ var LogContext = class {
198
+ constructor() {
199
+ this.stack = [];
200
+ }
201
+ createScope(step, args, message) {
202
+ return new LogScope({
203
+ ...args,
204
+ onStart: (payload) => {
205
+ this.stack.push({
206
+ action: step,
207
+ fn: args.methodName,
208
+ payload
209
+ });
210
+ Log.verbose(args.methodName, () => `${message}...`, () => payload());
211
+ },
212
+ onSuccess: (payload) => {
213
+ this.stack.push({
214
+ action: step,
215
+ fn: args.methodName,
216
+ payload,
217
+ done: true
218
+ });
219
+ Log.verbose(args.methodName, () => `${message}: OK`, () => payload());
220
+ },
221
+ onFailed: (payload) => {
222
+ this.stack.push({
223
+ action: step,
224
+ fn: args.methodName,
225
+ payload,
226
+ error: true
227
+ });
228
+ const resolvedStack = this.stack.map((s) => ({
229
+ ...s,
230
+ payload: s.payload()
231
+ }));
232
+ const p = payload();
233
+ p["__stack__"] = resolvedStack;
234
+ Log.error(args.methodName, () => `${message}: FAILED`, () => p);
235
+ },
236
+ onWait: (payload) => {
237
+ this.stack.push({
238
+ action: step,
239
+ fn: args.methodName,
240
+ payload
241
+ });
242
+ Log.verbose(args.methodName, () => `<HOLD> ${message}`, () => payload());
243
+ },
244
+ onWaitComplete: (payload) => {
245
+ this.stack.push({
246
+ action: step,
247
+ fn: args.methodName,
248
+ payload
249
+ });
250
+ Log.verbose(args.methodName, () => `<UNLOCKED> ${message}`, () => payload());
251
+ }
252
+ });
253
+ }
254
+ event(method) {
255
+ return this.createScope("EVENT", method, `Receiving event "${method.methodName}"`);
256
+ }
257
+ call(args) {
258
+ return this.createScope("CALL", args, "Calling method");
259
+ }
260
+ encode(args) {
261
+ return this.createScope("ENCODE", args, "Encoding object");
262
+ }
263
+ bridge(args) {
264
+ return this.createScope("BRIDGE", args, "Calling bridge function");
265
+ }
266
+ decode(args) {
267
+ return this.createScope("DECODE", args, "Decoding string");
268
+ }
269
+ };
270
+
271
+ //#endregion
272
+ //#region src/adapters/defaults.ts
273
+ /**
274
+ * Default platform adapter with unknown OS
275
+ */
276
+ var DefaultPlatformAdapter = class {
277
+ get OS() {
278
+ return Platform.OS;
279
+ }
280
+ set OS(value) {
281
+ Platform.OS = value;
282
+ }
283
+ };
284
+ /**
285
+ * Default SDK metadata adapter
286
+ */
287
+ var DefaultSdkMetadataAdapter = class {
288
+ constructor(sdkName = "unknown", sdkVersion = "0.0.0") {
289
+ this.sdkName = sdkName;
290
+ this.sdkVersion = sdkVersion;
291
+ }
292
+ };
293
+ /**
294
+ * Default logger adapter using the real LogContext implementation
295
+ */
296
+ var DefaultLoggerAdapter = class {
297
+ createContext() {
298
+ return new LogContext();
299
+ }
300
+ };
301
+
302
+ //#endregion
303
+ //#region src/types/error.ts
304
+ const ErrorCode = Object.freeze({
305
+ 0: "unknown",
306
+ 1: "clientInvalid",
307
+ 3: "paymentInvalid",
308
+ 4: "paymentNotAllowed",
309
+ 5: "storeProductNotAvailable",
310
+ 6: "cloudServicePermissionDenied",
311
+ 7: "cloudServiceNetworkConnectionFailed",
312
+ 8: "cloudServiceRevoked",
313
+ 9: "privacyAcknowledgementRequired",
314
+ 10: "unauthorizedRequestData",
315
+ 11: "invalidOfferIdentifier",
316
+ 12: "invalidSignature",
317
+ 13: "missingOfferParams",
318
+ 14: "invalidOfferPrice",
319
+ 20: "adaptyNotInitialized",
320
+ 22: "productNotFound",
321
+ 24: "currentSubscriptionToUpdateNotFoundInHistory",
322
+ 97: "billingServiceTimeout",
323
+ 98: "featureNotSupported",
324
+ 99: "billingServiceDisconnected",
325
+ 102: "billingServiceUnavailable",
326
+ 103: "billingUnavailable",
327
+ 105: "developerError",
328
+ 106: "billingError",
329
+ 107: "itemAlreadyOwned",
330
+ 108: "itemNotOwned",
331
+ 112: "billingNetworkError",
332
+ 1e3: "noProductIDsFound",
333
+ 1002: "productRequestFailed",
334
+ 1003: "cantMakePayments",
335
+ 1004: "noPurchasesToRestore",
336
+ 1005: "cantReadReceipt",
337
+ 1006: "productPurchaseFailed",
338
+ 1010: "refreshReceiptFailed",
339
+ 1011: "receiveRestoredTransactionsFailed",
340
+ 2002: "notActivated",
341
+ 2003: "badRequest",
342
+ 2004: "serverError",
343
+ 2005: "networkFailed",
344
+ 2006: "decodingFailed",
345
+ 2009: "encodingFailed",
346
+ 3e3: "analyticsDisabled",
347
+ 3001: "wrongParam",
348
+ 3005: "activateOnceError",
349
+ 3006: "profileWasChanged",
350
+ 3007: "unsupportedData",
351
+ 3100: "persistingDataError",
352
+ 3101: "fetchTimeoutError",
353
+ 9e3: "operationInterrupted"
354
+ });
355
+ function getErrorCode(error) {
356
+ const errorCode = Object.keys(ErrorCode).find((keyStr) => {
357
+ const key = Number(keyStr);
358
+ return ErrorCode[key] === error;
359
+ });
360
+ if (!errorCode) return void 0;
361
+ return Number(errorCode);
362
+ }
363
+ function getErrorPrompt(code) {
364
+ const prompt = ErrorCode[code];
365
+ if (!prompt) return `Unknown code: ${code}`;
366
+ return prompt;
367
+ }
368
+
369
+ //#endregion
370
+ //#region src/adapty-error.ts
371
+ var AdaptyError = class AdaptyError extends Error {
372
+ constructor(input) {
373
+ super(AdaptyError.getMessage(input));
374
+ this.adaptyCode = void 0;
375
+ this.localizedDescription = void 0;
376
+ this.detail = void 0;
377
+ this.adaptyCode = input.adaptyCode;
378
+ this.localizedDescription = input.message;
379
+ this.detail = input.detail;
380
+ if (AdaptyError.middleware) AdaptyError.middleware(this);
381
+ }
382
+ static set onError(callback) {
383
+ AdaptyError.middleware = callback;
384
+ }
385
+ static failedToDecodeNativeError(message, error) {
386
+ return new AdaptyError({
387
+ adaptyCode: 0,
388
+ message,
389
+ detail: JSON.stringify(error)
390
+ });
391
+ }
392
+ static failedToEncode(message) {
393
+ return new AdaptyError({
394
+ adaptyCode: 2009,
395
+ message
396
+ });
397
+ }
398
+ static failedToDecode(message) {
399
+ return new AdaptyError({
400
+ adaptyCode: 2006,
401
+ message
402
+ });
403
+ }
404
+ static getMessage(input) {
405
+ const code = input.adaptyCode;
406
+ const codeText = ErrorCode[code];
407
+ let message = `#${code} (${codeText}): ${input.message}`;
408
+ if (AdaptyError.prefix) message = `${AdaptyError.prefix} ${message}`;
409
+ return message;
410
+ }
411
+ };
412
+ AdaptyError.prefix = "";
413
+ AdaptyError.middleware = void 0;
414
+
415
+ //#endregion
416
+ //#region src/coders/coder.ts
417
+ var Coder = class {
418
+ constructor(platform = new DefaultPlatformAdapter()) {
419
+ this.platform = void 0;
420
+ this.platform = platform;
421
+ }
422
+ encode(data) {
423
+ return this.encodeWithProperties(data, this.properties);
424
+ }
425
+ decode(data) {
426
+ return this.decodeWithProperties(data, this.properties);
427
+ }
428
+ isType(value, type) {
429
+ switch (type) {
430
+ case "string":
431
+ case "boolean":
432
+ case "number": return typeof value === type;
433
+ case "object": return value !== null && typeof value === "object";
434
+ case "array": return Array.isArray(value);
435
+ }
436
+ }
437
+ getNestedValue(obj, key) {
438
+ const keys = key.split(".");
439
+ let current;
440
+ if (typeof obj === "string") try {
441
+ current = JSON.parse(obj);
442
+ } catch (error) {
443
+ return void 0;
444
+ }
445
+ else current = obj;
446
+ for (let i = 0; i < keys.length; i++) {
447
+ const key$1 = keys[i];
448
+ if (current[key$1] !== void 0) current = current[key$1];
449
+ else return void 0;
450
+ }
451
+ return current;
452
+ }
453
+ assignNestedValue(obj, key, value) {
454
+ const keys = String(key).split(".");
455
+ let currentObj = obj;
456
+ for (let i = 0; i < keys.length - 1; i++) {
457
+ const key$1 = keys[i];
458
+ if (currentObj[key$1] === void 0) currentObj[key$1] = {};
459
+ currentObj = currentObj[key$1];
460
+ }
461
+ currentObj[keys[keys.length - 1]] = value;
462
+ return obj;
463
+ }
464
+ encodeWithProperties(data, properties) {
465
+ const result = {};
466
+ for (const key in data) {
467
+ if (key === "ios" || key === "android") {
468
+ const platformResult = this.encodeWithProperties(data[key], properties[key]);
469
+ Object.assign(result, platformResult);
470
+ continue;
471
+ }
472
+ const property = properties[key];
473
+ if (!property) throw AdaptyError.failedToEncode(`Failed to find encoder for property "${key}"`);
474
+ const converter = property.converter;
475
+ this.assignNestedValue(result, property.key, converter ? converter.encode(data[key]) : data[key]);
476
+ }
477
+ return result;
478
+ }
479
+ decodeWithProperties(data, properties, platform) {
480
+ const result = {};
481
+ for (const key in properties) {
482
+ if (key === "android" || key === "ios") {
483
+ result[key] = this.decodeWithProperties(data, properties[key], key);
484
+ continue;
485
+ }
486
+ const property = properties[key];
487
+ if (!property) throw AdaptyError.failedToDecode(`Failed to find decoder for property "${key}"`);
488
+ const value = this.getNestedValue(data, property.key);
489
+ if (property.required && value === void 0 && (!platform || platform == this.platform.OS)) throw AdaptyError.failedToDecode(`Failed to decode native response, because it is missing required property "${key}"`);
490
+ if (value == null) continue;
491
+ if (!this.isType(value, property.type)) throw AdaptyError.failedToDecode(`Failed to decode native response, because its property "${key}" has invalid type. Expected type: ${property.type}. Received type: ${typeof value}`);
492
+ result[key] = property.converter ? property.converter.decode(value) : value;
493
+ }
494
+ return result;
495
+ }
496
+ };
497
+ var SimpleCoder = class extends Coder {};
498
+
499
+ //#endregion
500
+ //#region src/coders/date.ts
501
+ /**
502
+ * Format: yyyy-MM-dd'T'HH:mm:ss.SSSZ
503
+ * OpenAPI: Output.Date
504
+ */
505
+ var DateCoder = class {
506
+ decode(input) {
507
+ let pureValue = input;
508
+ if (!input.endsWith("Z")) {
509
+ const dateParts = input.split(/[-T:.Z]/);
510
+ const date = new Date(Date.UTC(parseInt(dateParts[0] ?? "0", 10), parseInt(dateParts[1] ?? "0", 10) - 1, parseInt(dateParts[2] ?? "0", 10), parseInt(dateParts[3] ?? "0", 10), parseInt(dateParts[4] ?? "0", 10), parseInt(dateParts[5] ?? "0", 10)));
511
+ pureValue = date.toISOString();
512
+ }
513
+ const parsedValue = Date.parse(pureValue);
514
+ if (isNaN(parsedValue)) throw AdaptyError.failedToDecode(`Failed to decode a date string into JS Date. String value: ${pureValue}`);
515
+ return new Date(parsedValue);
516
+ }
517
+ encode(value) {
518
+ return value.toISOString();
519
+ }
520
+ };
521
+
522
+ //#endregion
523
+ //#region src/coders/adapty-access-level.ts
524
+ var AdaptyAccessLevelCoder = class extends SimpleCoder {
525
+ constructor(..._args) {
526
+ super(..._args);
527
+ this.properties = {
528
+ activatedAt: {
529
+ key: "activated_at",
530
+ required: true,
531
+ type: "string",
532
+ converter: new DateCoder()
533
+ },
534
+ activeIntroductoryOfferType: {
535
+ key: "active_introductory_offer_type",
536
+ required: false,
537
+ type: "string"
538
+ },
539
+ activePromotionalOfferId: {
540
+ key: "active_promotional_offer_id",
541
+ required: false,
542
+ type: "string"
543
+ },
544
+ activePromotionalOfferType: {
545
+ key: "active_promotional_offer_type",
546
+ required: false,
547
+ type: "string"
548
+ },
549
+ billingIssueDetectedAt: {
550
+ key: "billing_issue_detected_at",
551
+ required: false,
552
+ type: "string",
553
+ converter: new DateCoder()
554
+ },
555
+ cancellationReason: {
556
+ key: "cancellation_reason",
557
+ required: false,
558
+ type: "string"
559
+ },
560
+ expiresAt: {
561
+ key: "expires_at",
562
+ required: false,
563
+ type: "string",
564
+ converter: new DateCoder()
565
+ },
566
+ id: {
567
+ key: "id",
568
+ required: true,
569
+ type: "string"
570
+ },
571
+ isActive: {
572
+ key: "is_active",
573
+ required: true,
574
+ type: "boolean"
575
+ },
576
+ isInGracePeriod: {
577
+ key: "is_in_grace_period",
578
+ required: true,
579
+ type: "boolean"
580
+ },
581
+ isLifetime: {
582
+ key: "is_lifetime",
583
+ required: true,
584
+ type: "boolean"
585
+ },
586
+ isRefund: {
587
+ key: "is_refund",
588
+ required: true,
589
+ type: "boolean"
590
+ },
591
+ renewedAt: {
592
+ key: "renewed_at",
593
+ required: false,
594
+ type: "string",
595
+ converter: new DateCoder()
596
+ },
597
+ startsAt: {
598
+ key: "starts_at",
599
+ required: false,
600
+ type: "string",
601
+ converter: new DateCoder()
602
+ },
603
+ store: {
604
+ key: "store",
605
+ required: true,
606
+ type: "string"
607
+ },
608
+ unsubscribedAt: {
609
+ key: "unsubscribed_at",
610
+ required: false,
611
+ type: "string",
612
+ converter: new DateCoder()
613
+ },
614
+ vendorProductId: {
615
+ key: "vendor_product_id",
616
+ required: true,
617
+ type: "string"
618
+ },
619
+ willRenew: {
620
+ key: "will_renew",
621
+ required: true,
622
+ type: "boolean"
623
+ },
624
+ android: { offerId: {
625
+ key: "offer_id",
626
+ required: false,
627
+ type: "string"
628
+ } }
629
+ };
630
+ }
631
+ };
632
+
633
+ //#endregion
634
+ //#region src/coders/adapty-ui-media-cache.ts
635
+ var AdaptyUiMediaCacheCoder = class extends SimpleCoder {
636
+ constructor(..._args) {
637
+ super(..._args);
638
+ this.properties = {
639
+ memoryStorageTotalCostLimit: {
640
+ key: "memory_storage_total_cost_limit",
641
+ required: false,
642
+ type: "number"
643
+ },
644
+ memoryStorageCountLimit: {
645
+ key: "memory_storage_count_limit",
646
+ required: false,
647
+ type: "number"
648
+ },
649
+ diskStorageSizeLimit: {
650
+ key: "disk_storage_size_limit",
651
+ required: false,
652
+ type: "number"
653
+ }
654
+ };
655
+ }
656
+ };
657
+
658
+ //#endregion
659
+ //#region src/coders/adapty-configuration.ts
660
+ var AdaptyConfigurationCoder = class {
661
+ constructor(platform, sdkMetadata) {
662
+ this.platform = platform;
663
+ this.sdkMetadata = sdkMetadata;
664
+ }
665
+ encode(apiKey, params) {
666
+ const config = {
667
+ api_key: apiKey,
668
+ cross_platform_sdk_name: this.sdkMetadata.sdkName,
669
+ cross_platform_sdk_version: this.sdkMetadata.sdkVersion
670
+ };
671
+ if (params.customerUserId) config["customer_user_id"] = params.customerUserId;
672
+ config["observer_mode"] = params.observerMode ?? false;
673
+ config["ip_address_collection_disabled"] = params.ipAddressCollectionDisabled ?? false;
674
+ if (params.logLevel) config["log_level"] = params.logLevel;
675
+ config["server_cluster"] = params.serverCluster ?? "default";
676
+ if (params.backendProxyHost) config["backend_proxy_host"] = params.backendProxyHost;
677
+ if (params.backendProxyPort) config["backend_proxy_port"] = params.backendProxyPort;
678
+ config["activate_ui"] = params.activateUi ?? true;
679
+ const mediaCacheCoder = new AdaptyUiMediaCacheCoder();
680
+ config["media_cache"] = mediaCacheCoder.encode(params.mediaCache ?? {
681
+ memoryStorageTotalCostLimit: 100 * 1024 * 1024,
682
+ memoryStorageCountLimit: 2147483647,
683
+ diskStorageSizeLimit: 100 * 1024 * 1024
684
+ });
685
+ if (this.platform.OS === "ios") {
686
+ config["apple_idfa_collection_disabled"] = params.ios?.idfaCollectionDisabled ?? false;
687
+ if (params.ios?.appAccountToken) config["customer_identity_parameters"] = { app_account_token: params.ios.appAccountToken };
688
+ if (params.ios?.clearDataOnBackup !== void 0) config["clear_data_on_backup"] = params.ios.clearDataOnBackup;
689
+ }
690
+ if (this.platform.OS === "android") {
691
+ config["google_adid_collection_disabled"] = params.android?.adIdCollectionDisabled ?? false;
692
+ config["google_enable_pending_prepaid_plans"] = params.android?.pendingPrepaidPlansEnabled ?? false;
693
+ config["google_local_access_level_allowed"] = params.android?.localAccessLevelAllowed ?? false;
694
+ if (params.android?.obfuscatedAccountId) config["customer_identity_parameters"] = { obfuscated_account_id: params.android.obfuscatedAccountId };
695
+ }
696
+ return config;
697
+ }
698
+ };
699
+
700
+ //#endregion
701
+ //#region src/coders/adapty-subscription-period.ts
702
+ var AdaptySubscriptionPeriodCoder = class extends SimpleCoder {
703
+ constructor(..._args) {
704
+ super(..._args);
705
+ this.properties = {
706
+ unit: {
707
+ key: "unit",
708
+ required: true,
709
+ type: "string"
710
+ },
711
+ numberOfUnits: {
712
+ key: "number_of_units",
713
+ required: true,
714
+ type: "number"
715
+ }
716
+ };
717
+ }
718
+ };
719
+
720
+ //#endregion
721
+ //#region src/coders/adapty-price.ts
722
+ var AdaptyPriceCoder = class extends SimpleCoder {
723
+ constructor(..._args) {
724
+ super(..._args);
725
+ this.properties = {
726
+ amount: {
727
+ key: "amount",
728
+ required: true,
729
+ type: "number"
730
+ },
731
+ currencyCode: {
732
+ key: "currency_code",
733
+ required: false,
734
+ type: "string"
735
+ },
736
+ currencySymbol: {
737
+ key: "currency_symbol",
738
+ required: false,
739
+ type: "string"
740
+ },
741
+ localizedString: {
742
+ key: "localized_string",
743
+ required: false,
744
+ type: "string"
745
+ }
746
+ };
747
+ }
748
+ };
749
+
750
+ //#endregion
751
+ //#region src/coders/adapty-discount-phase.ts
752
+ var AdaptyDiscountPhaseCoder = class extends SimpleCoder {
753
+ constructor(..._args) {
754
+ super(..._args);
755
+ this.properties = {
756
+ localizedNumberOfPeriods: {
757
+ key: "localized_number_of_periods",
758
+ required: false,
759
+ type: "string"
760
+ },
761
+ localizedSubscriptionPeriod: {
762
+ key: "localized_subscription_period",
763
+ required: false,
764
+ type: "string"
765
+ },
766
+ numberOfPeriods: {
767
+ key: "number_of_periods",
768
+ required: true,
769
+ type: "number"
770
+ },
771
+ paymentMode: {
772
+ key: "payment_mode",
773
+ required: true,
774
+ type: "string"
775
+ },
776
+ price: {
777
+ key: "price",
778
+ required: true,
779
+ type: "object",
780
+ converter: new AdaptyPriceCoder()
781
+ },
782
+ subscriptionPeriod: {
783
+ key: "subscription_period",
784
+ required: true,
785
+ type: "object",
786
+ converter: new AdaptySubscriptionPeriodCoder()
787
+ }
788
+ };
789
+ }
790
+ };
791
+
792
+ //#endregion
793
+ //#region src/coders/adapty-identify-params.ts
794
+ var AdaptyIdentifyParamsCoder = class {
795
+ constructor(platform) {
796
+ this.platform = platform;
797
+ }
798
+ encode(params) {
799
+ if (!params) return void 0;
800
+ const result = {};
801
+ if (this.platform.OS === "ios" && params.ios?.appAccountToken) result.app_account_token = params.ios.appAccountToken;
802
+ if (this.platform.OS === "android" && params.android?.obfuscatedAccountId) result.obfuscated_account_id = params.android.obfuscatedAccountId;
803
+ return Object.keys(result).length > 0 ? result : void 0;
804
+ }
805
+ };
806
+
807
+ //#endregion
808
+ //#region src/coders/adapty-installation-details.ts
809
+ var AdaptyInstallationDetailsCoder = class {
810
+ encode(model) {
811
+ const result = {
812
+ install_time: new DateCoder().encode(model.installTime),
813
+ app_launch_count: model.appLaunchCount
814
+ };
815
+ if (model.installId) result.install_id = model.installId;
816
+ if (model.payload) result.payload = model.payload;
817
+ return result;
818
+ }
819
+ decode(json) {
820
+ return {
821
+ installTime: new DateCoder().decode(json.install_time),
822
+ appLaunchCount: json.app_launch_count,
823
+ installId: json.install_id,
824
+ payload: json.payload
825
+ };
826
+ }
827
+ };
828
+
829
+ //#endregion
830
+ //#region src/coders/adapty-installation-status.ts
831
+ var AdaptyInstallationStatusCoder = class {
832
+ encode(model) {
833
+ if (model.status === "determined") {
834
+ const details = {
835
+ install_time: new DateCoder().encode(model.details.installTime),
836
+ app_launch_count: model.details.appLaunchCount
837
+ };
838
+ if (model.details.installId) details.install_id = model.details.installId;
839
+ if (model.details.payload) details.payload = model.details.payload;
840
+ return {
841
+ status: "determined",
842
+ details
843
+ };
844
+ }
845
+ return { status: model.status };
846
+ }
847
+ decode(json) {
848
+ if (json.status === "determined") {
849
+ const details = {
850
+ installTime: new DateCoder().decode(json.details.install_time),
851
+ appLaunchCount: json.details.app_launch_count,
852
+ installId: json.details.install_id,
853
+ payload: json.details.payload
854
+ };
855
+ return {
856
+ status: "determined",
857
+ details
858
+ };
859
+ }
860
+ return { status: json.status };
861
+ }
862
+ };
863
+
864
+ //#endregion
865
+ //#region src/coders/adapty-native-error.ts
866
+ var AdaptyNativeErrorCoder = class extends SimpleCoder {
867
+ constructor(..._args) {
868
+ super(..._args);
869
+ this.type = "error";
870
+ this.properties = {
871
+ adaptyCode: {
872
+ key: "adapty_code",
873
+ required: true,
874
+ type: "number"
875
+ },
876
+ message: {
877
+ key: "message",
878
+ required: true,
879
+ type: "string"
880
+ },
881
+ detail: {
882
+ key: "detail",
883
+ required: false,
884
+ type: "string"
885
+ }
886
+ };
887
+ }
888
+ getError(data) {
889
+ return new AdaptyError({
890
+ adaptyCode: data.adaptyCode,
891
+ message: data.message,
892
+ detail: data.detail
893
+ });
894
+ }
895
+ };
896
+
897
+ //#endregion
898
+ //#region src/coders/adapty-non-subscription.ts
899
+ var AdaptyNonSubscriptionCoder = class extends SimpleCoder {
900
+ constructor(..._args) {
901
+ super(..._args);
902
+ this.properties = {
903
+ isConsumable: {
904
+ key: "is_consumable",
905
+ required: true,
906
+ type: "boolean"
907
+ },
908
+ isRefund: {
909
+ key: "is_refund",
910
+ required: true,
911
+ type: "boolean"
912
+ },
913
+ isSandbox: {
914
+ key: "is_sandbox",
915
+ required: true,
916
+ type: "boolean"
917
+ },
918
+ purchasedAt: {
919
+ key: "purchased_at",
920
+ required: true,
921
+ type: "string",
922
+ converter: new DateCoder()
923
+ },
924
+ purchaseId: {
925
+ key: "purchase_id",
926
+ required: true,
927
+ type: "string"
928
+ },
929
+ store: {
930
+ key: "store",
931
+ required: true,
932
+ type: "string"
933
+ },
934
+ vendorProductId: {
935
+ key: "vendor_product_id",
936
+ required: true,
937
+ type: "string"
938
+ },
939
+ vendorTransactionId: {
940
+ key: "vendor_transaction_id",
941
+ required: false,
942
+ type: "string"
943
+ }
944
+ };
945
+ }
946
+ };
947
+
948
+ //#endregion
949
+ //#region src/coders/adapty-onboarding-builder.ts
950
+ var AdaptyOnboardingBuilderCoder = class extends SimpleCoder {
951
+ constructor(..._args) {
952
+ super(..._args);
953
+ this.properties = { url: {
954
+ key: "config_url",
955
+ required: true,
956
+ type: "string"
957
+ } };
958
+ }
959
+ };
960
+
961
+ //#endregion
962
+ //#region src/coders/json.ts
963
+ var JSONCoder = class {
964
+ decode(input) {
965
+ if (!input) return {};
966
+ return JSON.parse(input);
967
+ }
968
+ encode(value) {
969
+ if (Object.keys(value).length === 0) return "";
970
+ return JSON.stringify(value);
971
+ }
972
+ };
973
+
974
+ //#endregion
975
+ //#region src/coders/adapty-remote-config.ts
976
+ var AdaptyRemoteConfigCoder = class extends Coder {
977
+ constructor(..._args) {
978
+ super(..._args);
979
+ this.properties = {
980
+ data: {
981
+ key: "data",
982
+ required: true,
983
+ type: "string",
984
+ converter: new JSONCoder()
985
+ },
986
+ lang: {
987
+ key: "lang",
988
+ required: true,
989
+ type: "string"
990
+ }
991
+ };
992
+ }
993
+ decode(data) {
994
+ const codablePart = super.decode(data);
995
+ const dataString = JSON.stringify(codablePart.data);
996
+ return {
997
+ ...codablePart,
998
+ dataString: dataString.length < 4 ? "" : dataString
999
+ };
1000
+ }
1001
+ encode(data) {
1002
+ const { dataString,...codablePart } = data;
1003
+ return super.encode(codablePart);
1004
+ }
1005
+ };
1006
+
1007
+ //#endregion
1008
+ //#region src/coders/adapty-placement.ts
1009
+ var AdaptyPlacementCoder = class extends SimpleCoder {
1010
+ constructor(..._args) {
1011
+ super(..._args);
1012
+ this.properties = {
1013
+ abTestName: {
1014
+ key: "ab_test_name",
1015
+ required: true,
1016
+ type: "string"
1017
+ },
1018
+ audienceName: {
1019
+ key: "audience_name",
1020
+ required: true,
1021
+ type: "string"
1022
+ },
1023
+ id: {
1024
+ key: "developer_id",
1025
+ required: true,
1026
+ type: "string"
1027
+ },
1028
+ revision: {
1029
+ key: "revision",
1030
+ required: true,
1031
+ type: "number"
1032
+ },
1033
+ audienceVersionId: {
1034
+ key: "placement_audience_version_id",
1035
+ required: true,
1036
+ type: "string"
1037
+ },
1038
+ isTrackingPurchases: {
1039
+ key: "is_tracking_purchases",
1040
+ required: false,
1041
+ type: "boolean"
1042
+ }
1043
+ };
1044
+ }
1045
+ };
1046
+
1047
+ //#endregion
1048
+ //#region src/coders/adapty-onboarding.ts
1049
+ var AdaptyOnboardingCoder = class extends Coder {
1050
+ constructor(..._args) {
1051
+ super(..._args);
1052
+ this.properties = {
1053
+ placement: {
1054
+ key: "placement",
1055
+ required: true,
1056
+ type: "object",
1057
+ converter: new AdaptyPlacementCoder()
1058
+ },
1059
+ id: {
1060
+ key: "onboarding_id",
1061
+ required: true,
1062
+ type: "string"
1063
+ },
1064
+ name: {
1065
+ key: "onboarding_name",
1066
+ required: true,
1067
+ type: "string"
1068
+ },
1069
+ remoteConfig: {
1070
+ key: "remote_config",
1071
+ required: false,
1072
+ type: "object",
1073
+ converter: new AdaptyRemoteConfigCoder()
1074
+ },
1075
+ variationId: {
1076
+ key: "variation_id",
1077
+ required: true,
1078
+ type: "string"
1079
+ },
1080
+ version: {
1081
+ key: "response_created_at",
1082
+ required: false,
1083
+ type: "number"
1084
+ },
1085
+ onboardingBuilder: {
1086
+ key: "onboarding_builder",
1087
+ required: false,
1088
+ type: "object",
1089
+ converter: new AdaptyOnboardingBuilderCoder()
1090
+ },
1091
+ payloadData: {
1092
+ key: "payload_data",
1093
+ required: false,
1094
+ type: "string"
1095
+ },
1096
+ requestLocale: {
1097
+ key: "request_locale",
1098
+ required: true,
1099
+ type: "string"
1100
+ }
1101
+ };
1102
+ }
1103
+ decode(data) {
1104
+ const codablePart = super.decode(data);
1105
+ return {
1106
+ ...codablePart,
1107
+ hasViewConfiguration: codablePart.onboardingBuilder !== void 0
1108
+ };
1109
+ }
1110
+ encode(data) {
1111
+ const { hasViewConfiguration,...codablePart } = data;
1112
+ return super.encode(codablePart);
1113
+ }
1114
+ };
1115
+
1116
+ //#endregion
1117
+ //#region src/coders/adapty-paywall-builder.ts
1118
+ var AdaptyPaywallBuilderCoder = class extends SimpleCoder {
1119
+ constructor(..._args) {
1120
+ super(..._args);
1121
+ this.properties = {
1122
+ id: {
1123
+ key: "paywall_builder_id",
1124
+ required: true,
1125
+ type: "string"
1126
+ },
1127
+ lang: {
1128
+ key: "lang",
1129
+ required: true,
1130
+ type: "string"
1131
+ }
1132
+ };
1133
+ }
1134
+ };
1135
+
1136
+ //#endregion
1137
+ //#region src/coders/adapty-subscription-offer-identifier.ts
1138
+ var AdaptySubscriptionOfferIdCoder = class extends SimpleCoder {
1139
+ constructor(..._args) {
1140
+ super(..._args);
1141
+ this.properties = {
1142
+ type: {
1143
+ key: "type",
1144
+ required: true,
1145
+ type: "string"
1146
+ },
1147
+ id: {
1148
+ key: "id",
1149
+ required: false,
1150
+ type: "string"
1151
+ }
1152
+ };
1153
+ }
1154
+ };
1155
+
1156
+ //#endregion
1157
+ //#region src/coders/array.ts
1158
+ var ArrayCoder = class {
1159
+ constructor(coderFactory) {
1160
+ this.coderFactory = coderFactory;
1161
+ }
1162
+ decode(input) {
1163
+ const coder = this.coderFactory();
1164
+ return input.map((item) => coder.decode(item));
1165
+ }
1166
+ encode(value) {
1167
+ const coder = this.coderFactory();
1168
+ return value.map((item) => coder.encode(item));
1169
+ }
1170
+ };
1171
+
1172
+ //#endregion
1173
+ //#region src/coders/adapty-subscription-offer.ts
1174
+ var AdaptySubscriptionOfferCoder = class extends SimpleCoder {
1175
+ constructor(..._args) {
1176
+ super(..._args);
1177
+ this.properties = {
1178
+ identifier: {
1179
+ key: "offer_identifier",
1180
+ required: true,
1181
+ type: "object",
1182
+ converter: new AdaptySubscriptionOfferIdCoder()
1183
+ },
1184
+ phases: {
1185
+ key: "phases",
1186
+ required: true,
1187
+ type: "array",
1188
+ converter: new ArrayCoder(() => new AdaptyDiscountPhaseCoder())
1189
+ },
1190
+ android: { offerTags: {
1191
+ key: "offer_tags",
1192
+ required: false,
1193
+ type: "array"
1194
+ } }
1195
+ };
1196
+ }
1197
+ decode(data) {
1198
+ const baseResult = super.decode(data);
1199
+ if (!data.offer_tags) {
1200
+ const { android,...partialData } = baseResult;
1201
+ return partialData;
1202
+ }
1203
+ return baseResult;
1204
+ }
1205
+ };
1206
+
1207
+ //#endregion
1208
+ //#region src/coders/adapty-subscription-details.ts
1209
+ var AdaptySubscriptionDetailsCoder = class extends SimpleCoder {
1210
+ constructor(..._args) {
1211
+ super(..._args);
1212
+ this.properties = {
1213
+ subscriptionPeriod: {
1214
+ key: "period",
1215
+ required: true,
1216
+ type: "object",
1217
+ converter: new AdaptySubscriptionPeriodCoder()
1218
+ },
1219
+ localizedSubscriptionPeriod: {
1220
+ key: "localized_period",
1221
+ required: false,
1222
+ type: "string"
1223
+ },
1224
+ offer: {
1225
+ key: "offer",
1226
+ required: false,
1227
+ type: "object",
1228
+ converter: new AdaptySubscriptionOfferCoder()
1229
+ },
1230
+ ios: { subscriptionGroupIdentifier: {
1231
+ key: "group_identifier",
1232
+ required: false,
1233
+ type: "string"
1234
+ } },
1235
+ android: {
1236
+ basePlanId: {
1237
+ key: "base_plan_id",
1238
+ required: true,
1239
+ type: "string"
1240
+ },
1241
+ renewalType: {
1242
+ key: "renewal_type",
1243
+ required: false,
1244
+ type: "string"
1245
+ }
1246
+ }
1247
+ };
1248
+ }
1249
+ decode(data) {
1250
+ const baseResult = super.decode(data);
1251
+ const propToRemove = data.base_plan_id ? "ios" : "android";
1252
+ const { [propToRemove]: _,...partialData } = baseResult;
1253
+ return partialData;
1254
+ }
1255
+ };
1256
+
1257
+ //#endregion
1258
+ //#region src/coders/adapty-paywall-product.ts
1259
+ var AdaptyPaywallProductCoder = class extends SimpleCoder {
1260
+ constructor(..._args) {
1261
+ super(..._args);
1262
+ this.properties = {
1263
+ vendorProductId: {
1264
+ key: "vendor_product_id",
1265
+ required: true,
1266
+ type: "string"
1267
+ },
1268
+ adaptyId: {
1269
+ key: "adapty_product_id",
1270
+ required: true,
1271
+ type: "string"
1272
+ },
1273
+ paywallProductIndex: {
1274
+ key: "paywall_product_index",
1275
+ required: true,
1276
+ type: "number"
1277
+ },
1278
+ localizedDescription: {
1279
+ key: "localized_description",
1280
+ required: true,
1281
+ type: "string"
1282
+ },
1283
+ localizedTitle: {
1284
+ key: "localized_title",
1285
+ required: true,
1286
+ type: "string"
1287
+ },
1288
+ regionCode: {
1289
+ key: "region_code",
1290
+ required: false,
1291
+ type: "string"
1292
+ },
1293
+ variationId: {
1294
+ key: "paywall_variation_id",
1295
+ required: true,
1296
+ type: "string"
1297
+ },
1298
+ paywallABTestName: {
1299
+ key: "paywall_ab_test_name",
1300
+ required: true,
1301
+ type: "string"
1302
+ },
1303
+ paywallName: {
1304
+ key: "paywall_name",
1305
+ required: true,
1306
+ type: "string"
1307
+ },
1308
+ accessLevelId: {
1309
+ key: "access_level_id",
1310
+ required: true,
1311
+ type: "string"
1312
+ },
1313
+ productType: {
1314
+ key: "product_type",
1315
+ required: true,
1316
+ type: "string"
1317
+ },
1318
+ price: {
1319
+ key: "price",
1320
+ required: false,
1321
+ type: "object",
1322
+ converter: new AdaptyPriceCoder()
1323
+ },
1324
+ webPurchaseUrl: {
1325
+ key: "web_purchase_url",
1326
+ required: false,
1327
+ type: "string"
1328
+ },
1329
+ payloadData: {
1330
+ key: "payload_data",
1331
+ required: false,
1332
+ type: "string"
1333
+ },
1334
+ subscription: {
1335
+ key: "subscription",
1336
+ required: false,
1337
+ type: "object",
1338
+ converter: new AdaptySubscriptionDetailsCoder()
1339
+ },
1340
+ ios: { isFamilyShareable: {
1341
+ key: "is_family_shareable",
1342
+ required: true,
1343
+ type: "boolean"
1344
+ } }
1345
+ };
1346
+ }
1347
+ getInput(data) {
1348
+ return {
1349
+ adapty_product_id: data.adapty_product_id,
1350
+ access_level_id: data.access_level_id,
1351
+ product_type: data.product_type,
1352
+ paywall_product_index: data.paywall_product_index,
1353
+ paywall_ab_test_name: data.paywall_ab_test_name,
1354
+ payload_data: data.payload_data,
1355
+ paywall_name: data.paywall_name,
1356
+ paywall_variation_id: data.paywall_variation_id,
1357
+ subscription_offer_identifier: data.subscription?.offer?.offer_identifier,
1358
+ vendor_product_id: data.vendor_product_id
1359
+ };
1360
+ }
1361
+ };
1362
+
1363
+ //#endregion
1364
+ //#region src/coders/product-reference.ts
1365
+ var ProductReferenceCoder = class extends SimpleCoder {
1366
+ constructor(..._args) {
1367
+ super(..._args);
1368
+ this.properties = {
1369
+ vendorId: {
1370
+ key: "vendor_product_id",
1371
+ required: true,
1372
+ type: "string"
1373
+ },
1374
+ adaptyId: {
1375
+ key: "adapty_product_id",
1376
+ required: true,
1377
+ type: "string"
1378
+ },
1379
+ accessLevelId: {
1380
+ key: "access_level_id",
1381
+ required: true,
1382
+ type: "string"
1383
+ },
1384
+ productType: {
1385
+ key: "product_type",
1386
+ required: true,
1387
+ type: "string"
1388
+ },
1389
+ ios: {
1390
+ promotionalOfferId: {
1391
+ key: "promotional_offer_id",
1392
+ required: false,
1393
+ type: "string"
1394
+ },
1395
+ winBackOfferId: {
1396
+ key: "win_back_offer_id",
1397
+ required: false,
1398
+ type: "string"
1399
+ }
1400
+ },
1401
+ android: {
1402
+ basePlanId: {
1403
+ key: "base_plan_id",
1404
+ required: false,
1405
+ type: "string"
1406
+ },
1407
+ offerId: {
1408
+ key: "offer_id",
1409
+ required: false,
1410
+ type: "string"
1411
+ }
1412
+ }
1413
+ };
1414
+ }
1415
+ };
1416
+
1417
+ //#endregion
1418
+ //#region src/coders/adapty-paywall.ts
1419
+ var AdaptyPaywallCoder = class extends Coder {
1420
+ constructor(..._args) {
1421
+ super(..._args);
1422
+ this.properties = {
1423
+ placement: {
1424
+ key: "placement",
1425
+ required: true,
1426
+ type: "object",
1427
+ converter: new AdaptyPlacementCoder()
1428
+ },
1429
+ id: {
1430
+ key: "paywall_id",
1431
+ required: true,
1432
+ type: "string"
1433
+ },
1434
+ name: {
1435
+ key: "paywall_name",
1436
+ required: true,
1437
+ type: "string"
1438
+ },
1439
+ products: {
1440
+ key: "products",
1441
+ required: true,
1442
+ type: "array",
1443
+ converter: new ArrayCoder(() => new ProductReferenceCoder())
1444
+ },
1445
+ remoteConfig: {
1446
+ key: "remote_config",
1447
+ required: false,
1448
+ type: "object",
1449
+ converter: new AdaptyRemoteConfigCoder()
1450
+ },
1451
+ variationId: {
1452
+ key: "variation_id",
1453
+ required: true,
1454
+ type: "string"
1455
+ },
1456
+ version: {
1457
+ key: "response_created_at",
1458
+ required: false,
1459
+ type: "number"
1460
+ },
1461
+ paywallBuilder: {
1462
+ key: "paywall_builder",
1463
+ required: false,
1464
+ type: "object",
1465
+ converter: new AdaptyPaywallBuilderCoder()
1466
+ },
1467
+ webPurchaseUrl: {
1468
+ key: "web_purchase_url",
1469
+ required: false,
1470
+ type: "string"
1471
+ },
1472
+ payloadData: {
1473
+ key: "payload_data",
1474
+ required: false,
1475
+ type: "string"
1476
+ },
1477
+ requestLocale: {
1478
+ key: "request_locale",
1479
+ required: true,
1480
+ type: "string"
1481
+ }
1482
+ };
1483
+ }
1484
+ decode(data) {
1485
+ const codablePart = super.decode(data);
1486
+ return {
1487
+ ...codablePart,
1488
+ hasViewConfiguration: codablePart.paywallBuilder !== void 0,
1489
+ productIdentifiers: codablePart.products.map((product) => ({
1490
+ vendorProductId: product.vendorId,
1491
+ adaptyProductId: product.adaptyId,
1492
+ basePlanId: product.android?.basePlanId
1493
+ }))
1494
+ };
1495
+ }
1496
+ encode(data) {
1497
+ const { hasViewConfiguration, productIdentifiers,...codablePart } = data;
1498
+ return super.encode(codablePart);
1499
+ }
1500
+ };
1501
+
1502
+ //#endregion
1503
+ //#region src/coders/adapty-profile-parameters.ts
1504
+ var AdaptyProfileParametersCoder = class extends SimpleCoder {
1505
+ constructor(..._args) {
1506
+ super(..._args);
1507
+ this.properties = {
1508
+ firstName: {
1509
+ key: "first_name",
1510
+ required: false,
1511
+ type: "string"
1512
+ },
1513
+ lastName: {
1514
+ key: "last_name",
1515
+ required: false,
1516
+ type: "string"
1517
+ },
1518
+ gender: {
1519
+ key: "gender",
1520
+ required: false,
1521
+ type: "string"
1522
+ },
1523
+ birthday: {
1524
+ key: "birthday",
1525
+ required: false,
1526
+ type: "string"
1527
+ },
1528
+ email: {
1529
+ key: "email",
1530
+ required: false,
1531
+ type: "string"
1532
+ },
1533
+ phoneNumber: {
1534
+ key: "phone_number",
1535
+ required: false,
1536
+ type: "string"
1537
+ },
1538
+ appTrackingTransparencyStatus: {
1539
+ key: "att_status",
1540
+ required: false,
1541
+ type: "number"
1542
+ },
1543
+ codableCustomAttributes: {
1544
+ key: "custom_attributes",
1545
+ required: false,
1546
+ type: "object"
1547
+ },
1548
+ analyticsDisabled: {
1549
+ key: "analytics_disabled",
1550
+ required: false,
1551
+ type: "boolean"
1552
+ }
1553
+ };
1554
+ }
1555
+ };
1556
+
1557
+ //#endregion
1558
+ //#region src/coders/adapty-subscription.ts
1559
+ var AdaptySubscriptionCoder = class extends SimpleCoder {
1560
+ constructor(..._args) {
1561
+ super(..._args);
1562
+ this.properties = {
1563
+ isActive: {
1564
+ key: "is_active",
1565
+ required: true,
1566
+ type: "boolean"
1567
+ },
1568
+ isLifetime: {
1569
+ key: "is_lifetime",
1570
+ required: true,
1571
+ type: "boolean"
1572
+ },
1573
+ vendorProductId: {
1574
+ key: "vendor_product_id",
1575
+ required: true,
1576
+ type: "string"
1577
+ },
1578
+ store: {
1579
+ key: "store",
1580
+ required: true,
1581
+ type: "string"
1582
+ },
1583
+ vendorTransactionId: {
1584
+ key: "vendor_transaction_id",
1585
+ required: true,
1586
+ type: "string"
1587
+ },
1588
+ vendorOriginalTransactionId: {
1589
+ key: "vendor_original_transaction_id",
1590
+ required: true,
1591
+ type: "string"
1592
+ },
1593
+ activatedAt: {
1594
+ key: "activated_at",
1595
+ required: true,
1596
+ type: "string",
1597
+ converter: new DateCoder()
1598
+ },
1599
+ willRenew: {
1600
+ key: "will_renew",
1601
+ required: true,
1602
+ type: "boolean"
1603
+ },
1604
+ isInGracePeriod: {
1605
+ key: "is_in_grace_period",
1606
+ required: true,
1607
+ type: "boolean"
1608
+ },
1609
+ isRefund: {
1610
+ key: "is_refund",
1611
+ required: true,
1612
+ type: "boolean"
1613
+ },
1614
+ isSandbox: {
1615
+ key: "is_sandbox",
1616
+ required: true,
1617
+ type: "boolean"
1618
+ },
1619
+ renewedAt: {
1620
+ key: "renewed_at",
1621
+ required: false,
1622
+ type: "string",
1623
+ converter: new DateCoder()
1624
+ },
1625
+ expiresAt: {
1626
+ key: "expires_at",
1627
+ required: false,
1628
+ type: "string",
1629
+ converter: new DateCoder()
1630
+ },
1631
+ startsAt: {
1632
+ key: "starts_at",
1633
+ required: false,
1634
+ type: "string",
1635
+ converter: new DateCoder()
1636
+ },
1637
+ unsubscribedAt: {
1638
+ key: "unsubscribed_at",
1639
+ required: false,
1640
+ type: "string",
1641
+ converter: new DateCoder()
1642
+ },
1643
+ billingIssueDetectedAt: {
1644
+ key: "billing_issue_detected_at",
1645
+ required: false,
1646
+ type: "string",
1647
+ converter: new DateCoder()
1648
+ },
1649
+ activeIntroductoryOfferType: {
1650
+ key: "active_introductory_offer_type",
1651
+ required: false,
1652
+ type: "string"
1653
+ },
1654
+ activePromotionalOfferType: {
1655
+ key: "active_promotional_offer_type",
1656
+ required: false,
1657
+ type: "string"
1658
+ },
1659
+ activePromotionalOfferId: {
1660
+ key: "active_promotional_offer_id",
1661
+ required: false,
1662
+ type: "string"
1663
+ },
1664
+ cancellationReason: {
1665
+ key: "cancellation_reason",
1666
+ required: false,
1667
+ type: "string"
1668
+ }
1669
+ };
1670
+ }
1671
+ };
1672
+
1673
+ //#endregion
1674
+ //#region src/coders/hashmap.ts
1675
+ var HashmapCoder = class {
1676
+ constructor(coder) {
1677
+ this.coder = void 0;
1678
+ this.coder = coder;
1679
+ }
1680
+ decode(input) {
1681
+ const result = {};
1682
+ Object.keys(input).forEach((key) => {
1683
+ const property = input[key];
1684
+ result[key] = this.coder?.decode(property) ?? property;
1685
+ });
1686
+ return result;
1687
+ }
1688
+ encode(value) {
1689
+ const result = {};
1690
+ Object.keys(value).forEach((key) => {
1691
+ const property = value[key];
1692
+ result[key] = this.coder?.encode(property) ?? property;
1693
+ });
1694
+ return result;
1695
+ }
1696
+ };
1697
+
1698
+ //#endregion
1699
+ //#region src/coders/adapty-profile.ts
1700
+ var AdaptyProfileCoder = class extends SimpleCoder {
1701
+ constructor(..._args) {
1702
+ super(..._args);
1703
+ this.properties = {
1704
+ accessLevels: {
1705
+ key: "paid_access_levels",
1706
+ required: false,
1707
+ type: "object",
1708
+ converter: new HashmapCoder(new AdaptyAccessLevelCoder())
1709
+ },
1710
+ customAttributes: {
1711
+ key: "custom_attributes",
1712
+ required: false,
1713
+ type: "object"
1714
+ },
1715
+ customerUserId: {
1716
+ key: "customer_user_id",
1717
+ required: false,
1718
+ type: "string"
1719
+ },
1720
+ nonSubscriptions: {
1721
+ key: "non_subscriptions",
1722
+ required: false,
1723
+ type: "object",
1724
+ converter: new HashmapCoder(new ArrayCoder(() => new AdaptyNonSubscriptionCoder()))
1725
+ },
1726
+ profileId: {
1727
+ key: "profile_id",
1728
+ required: true,
1729
+ type: "string"
1730
+ },
1731
+ subscriptions: {
1732
+ key: "subscriptions",
1733
+ required: false,
1734
+ type: "object",
1735
+ converter: new HashmapCoder(new AdaptySubscriptionCoder())
1736
+ }
1737
+ };
1738
+ }
1739
+ };
1740
+
1741
+ //#endregion
1742
+ //#region src/coders/adapty-purchase-params.ts
1743
+ function isDeprecatedType(data) {
1744
+ return data && data.android && "oldSubVendorProductId" in data.android && "prorationMode" in data.android;
1745
+ }
1746
+ var AdaptyPurchaseParamsCoder = class {
1747
+ constructor(platform) {
1748
+ this.platform = platform;
1749
+ }
1750
+ encode(data) {
1751
+ if (this.platform.OS !== "android") return {};
1752
+ const purchaseParams = {};
1753
+ if (isDeprecatedType(data)) {
1754
+ if (data.android) {
1755
+ purchaseParams["subscription_update_params"] = {
1756
+ replacement_mode: data.android.prorationMode,
1757
+ old_sub_vendor_product_id: data.android.oldSubVendorProductId
1758
+ };
1759
+ if (data.android.isOfferPersonalized) purchaseParams["is_offer_personalized"] = data.android.isOfferPersonalized;
1760
+ }
1761
+ return purchaseParams;
1762
+ }
1763
+ if (data.android) {
1764
+ if (data.android.subscriptionUpdateParams) purchaseParams["subscription_update_params"] = {
1765
+ replacement_mode: data.android.subscriptionUpdateParams.prorationMode,
1766
+ old_sub_vendor_product_id: data.android.subscriptionUpdateParams.oldSubVendorProductId
1767
+ };
1768
+ if (data.android.isOfferPersonalized !== void 0) purchaseParams["is_offer_personalized"] = data.android.isOfferPersonalized;
1769
+ }
1770
+ return purchaseParams;
1771
+ }
1772
+ };
1773
+
1774
+ //#endregion
1775
+ //#region src/coders/adapty-purchase-result.ts
1776
+ var AdaptyPurchaseResultCoder = class extends SimpleCoder {
1777
+ constructor(..._args) {
1778
+ super(..._args);
1779
+ this.properties = { type: {
1780
+ key: "type",
1781
+ required: true,
1782
+ type: "string"
1783
+ } };
1784
+ }
1785
+ decode(data) {
1786
+ const baseResult = super.decode(data);
1787
+ if (baseResult.type === "success") {
1788
+ if (!data.profile) throw new Error("Profile is required for success type of purchase result");
1789
+ return {
1790
+ ...baseResult,
1791
+ profile: new AdaptyProfileCoder(this.platform).decode(data.profile),
1792
+ ...this.platform.OS === "ios" && data.apple_jws_transaction ? { ios: { jwsTransaction: data.apple_jws_transaction } } : {},
1793
+ ...this.platform.OS === "android" && data.google_purchase_token ? { android: { purchaseToken: data.google_purchase_token } } : {}
1794
+ };
1795
+ }
1796
+ return baseResult;
1797
+ }
1798
+ encode(data) {
1799
+ const { type } = data;
1800
+ if (type === "success") {
1801
+ if (!("profile" in data)) throw new Error("Profile is required for success type of purchase result");
1802
+ return {
1803
+ type: "success",
1804
+ profile: new AdaptyProfileCoder(this.platform).encode(data.profile),
1805
+ ...this.platform.OS === "ios" && data.ios?.jwsTransaction ? { apple_jws_transaction: data.ios.jwsTransaction } : {},
1806
+ ...this.platform.OS === "android" && data.android?.purchaseToken ? { google_purchase_token: data.android.purchaseToken } : {}
1807
+ };
1808
+ }
1809
+ return super.encode({ type });
1810
+ }
1811
+ };
1812
+
1813
+ //#endregion
1814
+ //#region src/coders/adapty-ui-dialog-config.ts
1815
+ var AdaptyUiDialogConfigCoder = class extends SimpleCoder {
1816
+ constructor(..._args) {
1817
+ super(..._args);
1818
+ this.properties = {
1819
+ primaryActionTitle: {
1820
+ key: "default_action_title",
1821
+ required: true,
1822
+ type: "string"
1823
+ },
1824
+ secondaryActionTitle: {
1825
+ key: "secondary_action_title",
1826
+ required: false,
1827
+ type: "string"
1828
+ },
1829
+ title: {
1830
+ key: "title",
1831
+ required: false,
1832
+ type: "string"
1833
+ },
1834
+ content: {
1835
+ key: "content",
1836
+ required: false,
1837
+ type: "string"
1838
+ }
1839
+ };
1840
+ }
1841
+ };
1842
+
1843
+ //#endregion
1844
+ //#region src/coders/adapty-ui-create-onboarding-view-params.ts
1845
+ var AdaptyUICreateOnboardingViewParamsCoder = class {
1846
+ encode(data) {
1847
+ const result = {};
1848
+ if (data.externalUrlsPresentation) result.external_urls_presentation = data.externalUrlsPresentation;
1849
+ return result;
1850
+ }
1851
+ };
1852
+
1853
+ //#endregion
1854
+ //#region src/coders/utils.ts
1855
+ const formatDateUTC = (date) => {
1856
+ const pad = (num, digits = 2) => {
1857
+ const str = num.toString();
1858
+ const paddingLength = digits - str.length;
1859
+ return paddingLength > 0 ? "0".repeat(paddingLength) + str : str;
1860
+ };
1861
+ const year = date.getUTCFullYear();
1862
+ const month = pad(date.getUTCMonth() + 1);
1863
+ const day = pad(date.getUTCDate());
1864
+ const hours = pad(date.getUTCHours());
1865
+ const minutes = pad(date.getUTCMinutes());
1866
+ const seconds = pad(date.getUTCSeconds());
1867
+ const millis = pad(date.getUTCMilliseconds(), 3);
1868
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${millis}Z`;
1869
+ };
1870
+ const colorToHex = {
1871
+ fromARGB(value) {
1872
+ const hex = value.toString(16).padStart(8, "0");
1873
+ return `#${hex.slice(2)}${hex.slice(0, 2)}`;
1874
+ },
1875
+ fromRGBA(value) {
1876
+ return `#${value.toString(16).padStart(8, "0")}`;
1877
+ },
1878
+ fromRGB(value) {
1879
+ return `#${value.toString(16).padStart(6, "0")}ff`;
1880
+ }
1881
+ };
1882
+ const extractBase64Data = (input) => {
1883
+ const commaIndex = input.indexOf(",");
1884
+ if (input.startsWith("data:") && commaIndex !== -1) return input.slice(commaIndex + 1);
1885
+ return input;
1886
+ };
1887
+ const resolveAssetId = (asset, platformOS) => {
1888
+ if ("relativeAssetPath" in asset) return platformOS === "android" ? `${asset.relativeAssetPath}a` : asset.relativeAssetPath;
1889
+ const fileLocation = asset.fileLocation;
1890
+ if (platformOS === "android") return "relativeAssetPath" in fileLocation.android ? `${fileLocation.android.relativeAssetPath}a` : `${fileLocation.android.rawResName}r`;
1891
+ return fileLocation.ios.fileName;
1892
+ };
1893
+
1894
+ //#endregion
1895
+ //#region src/coders/adapty-ui-create-paywall-view-params.ts
1896
+ var AdaptyUICreatePaywallViewParamsCoder = class {
1897
+ constructor(platform) {
1898
+ this.platform = platform;
1899
+ }
1900
+ encode(data) {
1901
+ const result = {};
1902
+ if (data.prefetchProducts !== void 0) result.preload_products = data.prefetchProducts;
1903
+ if (data.loadTimeoutMs !== void 0) result.load_timeout = data.loadTimeoutMs / 1e3;
1904
+ if (data.customTags) result.custom_tags = data.customTags;
1905
+ if (data.customTimers) result.custom_timers = this.encodeCustomTimers(data.customTimers);
1906
+ if (data.customAssets) result.custom_assets = this.encodeCustomAssets(data.customAssets);
1907
+ if (data.productPurchaseParams) result.product_purchase_parameters = this.encodeProductPurchaseParams(data.productPurchaseParams);
1908
+ return result;
1909
+ }
1910
+ encodeCustomTimers(timers) {
1911
+ const result = {};
1912
+ for (const key in timers) if (timers.hasOwnProperty(key)) {
1913
+ const date = timers[key];
1914
+ if (date instanceof Date) result[key] = formatDateUTC(date);
1915
+ }
1916
+ return result;
1917
+ }
1918
+ encodeCustomAssets(assets) {
1919
+ const getAssetId = (asset) => {
1920
+ return resolveAssetId(asset, this.platform.OS) || "";
1921
+ };
1922
+ return Object.entries(assets).map(([id, asset]) => {
1923
+ switch (asset.type) {
1924
+ case "image": return "base64" in asset ? {
1925
+ id,
1926
+ type: "image",
1927
+ value: extractBase64Data(asset.base64)
1928
+ } : {
1929
+ id,
1930
+ type: "image",
1931
+ asset_id: getAssetId(asset)
1932
+ };
1933
+ case "video": return {
1934
+ id,
1935
+ type: "video",
1936
+ asset_id: getAssetId(asset)
1937
+ };
1938
+ case "color":
1939
+ let value;
1940
+ if ("argb" in asset) value = colorToHex.fromARGB(asset.argb);
1941
+ else if ("rgba" in asset) value = colorToHex.fromRGBA(asset.rgba);
1942
+ else if ("rgb" in asset) value = colorToHex.fromRGB(asset.rgb);
1943
+ else return void 0;
1944
+ return {
1945
+ id,
1946
+ type: "color",
1947
+ value
1948
+ };
1949
+ case "linear-gradient":
1950
+ const { values, points = {} } = asset;
1951
+ const { x0 = 0, y0 = 0, x1 = 1, y1 = 0 } = points;
1952
+ const colorStops = values.map(({ p,...colorInput }) => {
1953
+ let color;
1954
+ if ("argb" in colorInput) color = colorToHex.fromARGB(colorInput.argb);
1955
+ else if ("rgba" in colorInput) color = colorToHex.fromRGBA(colorInput.rgba);
1956
+ else if ("rgb" in colorInput) color = colorToHex.fromRGB(colorInput.rgb);
1957
+ else return void 0;
1958
+ return {
1959
+ color,
1960
+ p
1961
+ };
1962
+ }).filter((v) => v !== void 0);
1963
+ if (colorStops.length !== values.length) return void 0;
1964
+ return {
1965
+ id,
1966
+ type: "linear-gradient",
1967
+ values: colorStops,
1968
+ points: {
1969
+ x0,
1970
+ y0,
1971
+ x1,
1972
+ y1
1973
+ }
1974
+ };
1975
+ default: return void 0;
1976
+ }
1977
+ }).filter((item) => item !== void 0);
1978
+ }
1979
+ encodeProductPurchaseParams(params) {
1980
+ if (!params) return {};
1981
+ const purchaseParamsCoder = new AdaptyPurchaseParamsCoder(this.platform);
1982
+ return Object.fromEntries(params.map(({ productId, params: params$1 }) => [productId.adaptyProductId, purchaseParamsCoder.encode(params$1)]));
1983
+ }
1984
+ };
1985
+
1986
+ //#endregion
1987
+ //#region src/coders/adapty-ui-onboarding-meta.ts
1988
+ var AdaptyUiOnboardingMetaCoder = class extends SimpleCoder {
1989
+ constructor(..._args) {
1990
+ super(..._args);
1991
+ this.properties = {
1992
+ onboardingId: {
1993
+ key: "onboarding_id",
1994
+ required: true,
1995
+ type: "string"
1996
+ },
1997
+ screenClientId: {
1998
+ key: "screen_cid",
1999
+ required: true,
2000
+ type: "string"
2001
+ },
2002
+ screenIndex: {
2003
+ key: "screen_index",
2004
+ required: true,
2005
+ type: "number"
2006
+ },
2007
+ totalScreens: {
2008
+ key: "total_screens",
2009
+ required: true,
2010
+ type: "number"
2011
+ }
2012
+ };
2013
+ }
2014
+ };
2015
+
2016
+ //#endregion
2017
+ //#region src/coders/adapty-ui-onboarding-state-params.ts
2018
+ var AdaptyUiOnboardingStateParamsCoder = class extends SimpleCoder {
2019
+ constructor(..._args) {
2020
+ super(..._args);
2021
+ this.properties = {
2022
+ id: {
2023
+ key: "id",
2024
+ required: true,
2025
+ type: "string"
2026
+ },
2027
+ value: {
2028
+ key: "value",
2029
+ required: true,
2030
+ type: "string"
2031
+ },
2032
+ label: {
2033
+ key: "label",
2034
+ required: true,
2035
+ type: "string"
2036
+ }
2037
+ };
2038
+ }
2039
+ };
2040
+
2041
+ //#endregion
2042
+ //#region src/coders/adapty-ui-onboarding-state-updated-action.ts
2043
+ var AdaptyUiOnboardingStateUpdatedActionCoder = class extends SimpleCoder {
2044
+ constructor(..._args) {
2045
+ super(..._args);
2046
+ this.paramCoder = new AdaptyUiOnboardingStateParamsCoder();
2047
+ this.properties = {
2048
+ elementId: {
2049
+ key: "element_id",
2050
+ required: true,
2051
+ type: "string"
2052
+ },
2053
+ elementType: {
2054
+ key: "element_type",
2055
+ required: true,
2056
+ type: "string"
2057
+ }
2058
+ };
2059
+ }
2060
+ decode(data) {
2061
+ const base = super.decode(data);
2062
+ const { elementType } = base;
2063
+ switch (elementType) {
2064
+ case "select": return {
2065
+ ...base,
2066
+ elementType: "select",
2067
+ value: this.paramCoder.decode(data.value)
2068
+ };
2069
+ case "multi_select": return {
2070
+ ...base,
2071
+ elementType: "multi_select",
2072
+ value: Array.isArray(data.value) ? data.value.map((v) => this.paramCoder.decode(v)) : []
2073
+ };
2074
+ case "input": return {
2075
+ ...base,
2076
+ value: data.value
2077
+ };
2078
+ case "date_picker": return {
2079
+ ...base,
2080
+ value: data.value
2081
+ };
2082
+ default: throw new Error(`Unknown element_type: ${elementType}`);
2083
+ }
2084
+ }
2085
+ encode(data) {
2086
+ const base = super.encode(data);
2087
+ const { elementType } = data;
2088
+ switch (elementType) {
2089
+ case "select": return {
2090
+ ...base,
2091
+ element_type: "select",
2092
+ value: this.paramCoder.encode(data.value)
2093
+ };
2094
+ case "multi_select": return {
2095
+ ...base,
2096
+ element_type: "multi_select",
2097
+ value: data.value.map((v) => this.paramCoder.encode(v))
2098
+ };
2099
+ case "input": return {
2100
+ ...base,
2101
+ element_type: "input",
2102
+ value: data.value
2103
+ };
2104
+ case "date_picker": return {
2105
+ ...base,
2106
+ element_type: "date_picker",
2107
+ value: data.value
2108
+ };
2109
+ default: throw new Error(`Unknown elementType: ${elementType}`);
2110
+ }
2111
+ }
2112
+ };
2113
+
2114
+ //#endregion
2115
+ //#region src/coders/bridge-error.ts
2116
+ var BridgeErrorCoder = class extends SimpleCoder {
2117
+ constructor(..._args) {
2118
+ super(..._args);
2119
+ this.type = "error";
2120
+ this.properties = {
2121
+ errorType: {
2122
+ key: "error_type",
2123
+ required: true,
2124
+ type: "string"
2125
+ },
2126
+ name: {
2127
+ key: "name",
2128
+ required: false,
2129
+ type: "string"
2130
+ },
2131
+ type: {
2132
+ key: "type",
2133
+ required: false,
2134
+ type: "string"
2135
+ },
2136
+ underlyingError: {
2137
+ key: "parent_error",
2138
+ required: false,
2139
+ type: "string"
2140
+ },
2141
+ description: {
2142
+ key: "description",
2143
+ required: false,
2144
+ type: "string"
2145
+ }
2146
+ };
2147
+ }
2148
+ getError(data) {
2149
+ switch (data.errorType) {
2150
+ case "missingRequiredArgument": return new AdaptyError({
2151
+ adaptyCode: 3001,
2152
+ message: `Required parameter "${data.name} was not passed to a native module"`
2153
+ });
2154
+ case "typeMismatch": return new AdaptyError({
2155
+ adaptyCode: 3001,
2156
+ message: `Passed parameter "${data.name}" has invalid type. Expected type: ${data.type}"`
2157
+ });
2158
+ case "encodingFailed": return new AdaptyError({
2159
+ adaptyCode: 2009,
2160
+ message: `Bridge layer failed to encode response. Bridge error: ${JSON.stringify(data.underlyingError ?? {})}"`
2161
+ });
2162
+ case "wrongParam":
2163
+ case "WRONG_PARAMETER": return new AdaptyError({
2164
+ adaptyCode: 3001,
2165
+ message: data.name ?? `Wrong parameter. Bridge error: ${JSON.stringify(data.underlyingError ?? {})}"`
2166
+ });
2167
+ case "methodNotImplemented": return new AdaptyError({
2168
+ adaptyCode: 2003,
2169
+ message: "Requested bridge handle not found"
2170
+ });
2171
+ case "unsupportedIosVersion": return new AdaptyError({
2172
+ adaptyCode: 2003,
2173
+ message: "Unsupported iOS version"
2174
+ });
2175
+ case "unexpectedError":
2176
+ default: return new AdaptyError({
2177
+ adaptyCode: 0,
2178
+ message: `Unexpected error occurred: ${JSON.stringify(data.underlyingError ?? {})}`
2179
+ });
2180
+ }
2181
+ }
2182
+ };
2183
+
2184
+ //#endregion
2185
+ //#region src/coders/factory.ts
2186
+ /**
2187
+ * Factory for creating coders with injected dependencies
2188
+ */
2189
+ var CoderFactory = class {
2190
+ constructor(deps) {
2191
+ this.deps = deps;
2192
+ }
2193
+ createAccessLevelCoder() {
2194
+ return new AdaptyAccessLevelCoder(this.deps.platform);
2195
+ }
2196
+ createConfigurationCoder() {
2197
+ return new AdaptyConfigurationCoder(this.deps.platform, this.deps.sdkMetadata);
2198
+ }
2199
+ createDateCoder() {
2200
+ return new DateCoder();
2201
+ }
2202
+ createDiscountPhaseCoder() {
2203
+ return new AdaptyDiscountPhaseCoder(this.deps.platform);
2204
+ }
2205
+ createPurchaseParamsCoder() {
2206
+ return new AdaptyPurchaseParamsCoder(this.deps.platform);
2207
+ }
2208
+ createPurchaseResultCoder() {
2209
+ return new AdaptyPurchaseResultCoder(this.deps.platform);
2210
+ }
2211
+ createIdentifyParamsCoder() {
2212
+ return new AdaptyIdentifyParamsCoder(this.deps.platform);
2213
+ }
2214
+ createInstallationDetailsCoder() {
2215
+ return new AdaptyInstallationDetailsCoder();
2216
+ }
2217
+ createInstallationStatusCoder() {
2218
+ return new AdaptyInstallationStatusCoder();
2219
+ }
2220
+ createJsonCoder() {
2221
+ return new JSONCoder();
2222
+ }
2223
+ createNativeErrorCoder() {
2224
+ return new AdaptyNativeErrorCoder(this.deps.platform);
2225
+ }
2226
+ createNonSubscriptionCoder() {
2227
+ return new AdaptyNonSubscriptionCoder(this.deps.platform);
2228
+ }
2229
+ createOnboardingBuilderCoder() {
2230
+ return new AdaptyOnboardingBuilderCoder(this.deps.platform);
2231
+ }
2232
+ createOnboardingCoder() {
2233
+ return new AdaptyOnboardingCoder(this.deps.platform);
2234
+ }
2235
+ createPaywallBuilderCoder() {
2236
+ return new AdaptyPaywallBuilderCoder(this.deps.platform);
2237
+ }
2238
+ createPaywallCoder() {
2239
+ return new AdaptyPaywallCoder(this.deps.platform);
2240
+ }
2241
+ createPaywallProductCoder() {
2242
+ return new AdaptyPaywallProductCoder(this.deps.platform);
2243
+ }
2244
+ createPlacementCoder() {
2245
+ return new AdaptyPlacementCoder(this.deps.platform);
2246
+ }
2247
+ createPriceCoder() {
2248
+ return new AdaptyPriceCoder(this.deps.platform);
2249
+ }
2250
+ createProductReferenceCoder() {
2251
+ return new ProductReferenceCoder(this.deps.platform);
2252
+ }
2253
+ createProfileCoder() {
2254
+ return new AdaptyProfileCoder(this.deps.platform);
2255
+ }
2256
+ createProfileParametersCoder() {
2257
+ return new AdaptyProfileParametersCoder(this.deps.platform);
2258
+ }
2259
+ createRemoteConfigCoder() {
2260
+ return new AdaptyRemoteConfigCoder(this.deps.platform);
2261
+ }
2262
+ createSubscriptionCoder() {
2263
+ return new AdaptySubscriptionCoder(this.deps.platform);
2264
+ }
2265
+ createSubscriptionDetailsCoder() {
2266
+ return new AdaptySubscriptionDetailsCoder(this.deps.platform);
2267
+ }
2268
+ createSubscriptionOfferCoder() {
2269
+ return new AdaptySubscriptionOfferCoder(this.deps.platform);
2270
+ }
2271
+ createSubscriptionOfferIdCoder() {
2272
+ return new AdaptySubscriptionOfferIdCoder(this.deps.platform);
2273
+ }
2274
+ createSubscriptionPeriodCoder() {
2275
+ return new AdaptySubscriptionPeriodCoder(this.deps.platform);
2276
+ }
2277
+ createUiCreateOnboardingViewParamsCoder() {
2278
+ return new AdaptyUICreateOnboardingViewParamsCoder();
2279
+ }
2280
+ createUiCreatePaywallViewParamsCoder() {
2281
+ return new AdaptyUICreatePaywallViewParamsCoder(this.deps.platform);
2282
+ }
2283
+ createUiDialogConfigCoder() {
2284
+ return new AdaptyUiDialogConfigCoder(this.deps.platform);
2285
+ }
2286
+ createUiMediaCacheCoder() {
2287
+ return new AdaptyUiMediaCacheCoder(this.deps.platform);
2288
+ }
2289
+ createUiOnboardingMetaCoder() {
2290
+ return new AdaptyUiOnboardingMetaCoder(this.deps.platform);
2291
+ }
2292
+ createUiOnboardingStateParamsCoder() {
2293
+ return new AdaptyUiOnboardingStateParamsCoder(this.deps.platform);
2294
+ }
2295
+ createUiOnboardingStateUpdatedActionCoder() {
2296
+ return new AdaptyUiOnboardingStateUpdatedActionCoder(this.deps.platform);
2297
+ }
2298
+ createBridgeErrorCoder() {
2299
+ return new BridgeErrorCoder(this.deps.platform);
2300
+ }
2301
+ createArrayCoder(coderFactory) {
2302
+ return new ArrayCoder(coderFactory);
2303
+ }
2304
+ createPaywallProductArrayCoder() {
2305
+ return new ArrayCoder(() => this.createPaywallProductCoder());
2306
+ }
2307
+ createHashmapCoder(coder) {
2308
+ return new HashmapCoder(coder);
2309
+ }
2310
+ };
2311
+
2312
+ //#endregion
2313
+ //#region src/types/index.ts
2314
+ const VendorStore = Object.freeze({
2315
+ AppStore: "app_store",
2316
+ PlayStore: "play_store",
2317
+ Adapty: "adapty"
2318
+ });
2319
+ const OfferType = Object.freeze({
2320
+ FreeTrial: "free_trial",
2321
+ PayAsYouGo: "pay_as_you_go",
2322
+ PayUpFront: "pay_up_front"
2323
+ });
2324
+ const CancellationReason = Object.freeze({
2325
+ VolountarilyCancelled: "voluntarily_cancelled",
2326
+ BillingError: "billing_error",
2327
+ Refund: "refund",
2328
+ PriceIncrease: "price_increase",
2329
+ ProductWasNotAvailable: "product_was_not_available",
2330
+ Unknown: "unknown"
2331
+ });
2332
+ const Gender = Object.freeze({
2333
+ Female: "f",
2334
+ Male: "m",
2335
+ Other: "o"
2336
+ });
2337
+ const AppTrackingTransparencyStatus = Object.freeze({
2338
+ NotDetermined: 0,
2339
+ Restricted: 1,
2340
+ Denied: 2,
2341
+ Authorized: 3,
2342
+ Unknown: 4
2343
+ });
2344
+ const ProductPeriod = Object.freeze({
2345
+ Day: "day",
2346
+ Week: "week",
2347
+ Month: "month",
2348
+ Year: "year"
2349
+ });
2350
+ const WebPresentation = Object.freeze({
2351
+ BrowserOutApp: "browser_out_app",
2352
+ BrowserInApp: "browser_in_app"
2353
+ });
2354
+ const RefundPreference = Object.freeze({
2355
+ NoPreference: "no_preference",
2356
+ Grant: "grant",
2357
+ Decline: "decline"
2358
+ });
2359
+
2360
+ //#endregion
2361
+ //#region src/types/bridge.ts
2362
+ /**
2363
+ * Valid list of callable bridge handlers
2364
+ * Must be the same as
2365
+ * - iOS RNAConstants.MethodName
2366
+ * @internal
2367
+ */
2368
+ const MethodNames = [
2369
+ "activate",
2370
+ "adapty_ui_activate",
2371
+ "adapty_ui_create_paywall_view",
2372
+ "adapty_ui_dismiss_paywall_view",
2373
+ "adapty_ui_present_paywall_view",
2374
+ "adapty_ui_show_dialog",
2375
+ "adapty_ui_create_onboarding_view",
2376
+ "adapty_ui_dismiss_onboarding_view",
2377
+ "adapty_ui_present_onboarding_view",
2378
+ "create_web_paywall_url",
2379
+ "get_current_installation_status",
2380
+ "is_activated",
2381
+ "get_paywall",
2382
+ "get_paywall_for_default_audience",
2383
+ "get_paywall_products",
2384
+ "get_onboarding",
2385
+ "get_onboarding_for_default_audience",
2386
+ "get_profile",
2387
+ "identify",
2388
+ "log_show_paywall",
2389
+ "logout",
2390
+ "make_purchase",
2391
+ "open_web_paywall",
2392
+ "present_code_redemption_sheet",
2393
+ "report_transaction",
2394
+ "restore_purchases",
2395
+ "set_fallback",
2396
+ "set_integration_identifiers",
2397
+ "set_log_level",
2398
+ "update_attribution_data",
2399
+ "update_collecting_refund_data_consent",
2400
+ "update_profile",
2401
+ "update_refund_preference"
2402
+ ];
2403
+
2404
+ //#endregion
2405
+ //#region src/types/paywall-events.ts
2406
+ const PaywallEventId = {
2407
+ DidAppear: "paywall_view_did_appear",
2408
+ DidDisappear: "paywall_view_did_disappear",
2409
+ DidPerformAction: "paywall_view_did_perform_action",
2410
+ DidSelectProduct: "paywall_view_did_select_product",
2411
+ DidStartPurchase: "paywall_view_did_start_purchase",
2412
+ DidFinishPurchase: "paywall_view_did_finish_purchase",
2413
+ DidFailPurchase: "paywall_view_did_fail_purchase",
2414
+ DidStartRestore: "paywall_view_did_start_restore",
2415
+ DidFinishRestore: "paywall_view_did_finish_restore",
2416
+ DidFailRestore: "paywall_view_did_fail_restore",
2417
+ DidFailRendering: "paywall_view_did_fail_rendering",
2418
+ DidFailLoadingProducts: "paywall_view_did_fail_loading_products",
2419
+ DidFinishWebPaymentNavigation: "paywall_view_did_finish_web_payment_navigation"
2420
+ };
2421
+
2422
+ //#endregion
2423
+ //#region src/types/onboarding-events.ts
2424
+ const OnboardingEventId = {
2425
+ Close: "onboarding_on_close_action",
2426
+ Custom: "onboarding_on_custom_action",
2427
+ Paywall: "onboarding_on_paywall_action",
2428
+ StateUpdated: "onboarding_on_state_updated_action",
2429
+ FinishedLoading: "onboarding_did_finish_loading",
2430
+ Analytics: "onboarding_on_analytics_action",
2431
+ Error: "onboarding_did_fail_with_error"
2432
+ };
2433
+
2434
+ //#endregion
2435
+ //#region src/ui/paywall-event-mapping.ts
2436
+ /**
2437
+ * Resolves native event to handler name based on event data
2438
+ */
2439
+ const NATIVE_EVENT_RESOLVER = {
2440
+ [PaywallEventId.DidPerformAction]: (event) => {
2441
+ if (event.id !== PaywallEventId.DidPerformAction) return null;
2442
+ const actionMap = {
2443
+ close: "onCloseButtonPress",
2444
+ system_back: "onAndroidSystemBack",
2445
+ open_url: "onUrlPress",
2446
+ custom: "onCustomAction"
2447
+ };
2448
+ return actionMap[event.action.type] || null;
2449
+ },
2450
+ [PaywallEventId.DidAppear]: () => "onPaywallShown",
2451
+ [PaywallEventId.DidDisappear]: () => "onPaywallClosed",
2452
+ [PaywallEventId.DidSelectProduct]: () => "onProductSelected",
2453
+ [PaywallEventId.DidStartPurchase]: () => "onPurchaseStarted",
2454
+ [PaywallEventId.DidFinishPurchase]: () => "onPurchaseCompleted",
2455
+ [PaywallEventId.DidFailPurchase]: () => "onPurchaseFailed",
2456
+ [PaywallEventId.DidStartRestore]: () => "onRestoreStarted",
2457
+ [PaywallEventId.DidFinishRestore]: () => "onRestoreCompleted",
2458
+ [PaywallEventId.DidFailRestore]: () => "onRestoreFailed",
2459
+ [PaywallEventId.DidFailRendering]: () => "onRenderingFailed",
2460
+ [PaywallEventId.DidFailLoadingProducts]: () => "onLoadingProductsFailed",
2461
+ [PaywallEventId.DidFinishWebPaymentNavigation]: () => "onWebPaymentNavigationFinished"
2462
+ };
2463
+ /**
2464
+ * Maps handler name to native event name
2465
+ * Used in addListener/addInternalListener to subscribe to correct native event
2466
+ */
2467
+ const HANDLER_TO_NATIVE_EVENT = {
2468
+ onCloseButtonPress: PaywallEventId.DidPerformAction,
2469
+ onAndroidSystemBack: PaywallEventId.DidPerformAction,
2470
+ onUrlPress: PaywallEventId.DidPerformAction,
2471
+ onCustomAction: PaywallEventId.DidPerformAction,
2472
+ onPaywallShown: PaywallEventId.DidAppear,
2473
+ onPaywallClosed: PaywallEventId.DidDisappear,
2474
+ onProductSelected: PaywallEventId.DidSelectProduct,
2475
+ onPurchaseStarted: PaywallEventId.DidStartPurchase,
2476
+ onPurchaseCompleted: PaywallEventId.DidFinishPurchase,
2477
+ onPurchaseFailed: PaywallEventId.DidFailPurchase,
2478
+ onRestoreStarted: PaywallEventId.DidStartRestore,
2479
+ onRestoreCompleted: PaywallEventId.DidFinishRestore,
2480
+ onRestoreFailed: PaywallEventId.DidFailRestore,
2481
+ onRenderingFailed: PaywallEventId.DidFailRendering,
2482
+ onLoadingProductsFailed: PaywallEventId.DidFailLoadingProducts,
2483
+ onWebPaymentNavigationFinished: PaywallEventId.DidFinishWebPaymentNavigation
2484
+ };
2485
+ function extractPaywallCallbackArgs(handlerName, event) {
2486
+ switch (event.id) {
2487
+ case PaywallEventId.DidSelectProduct: return [event.productId];
2488
+ case PaywallEventId.DidStartPurchase: return [event.product];
2489
+ case PaywallEventId.DidFinishPurchase: return [event.purchaseResult, event.product];
2490
+ case PaywallEventId.DidFailPurchase: return [event.error, event.product];
2491
+ case PaywallEventId.DidFinishRestore: return [event.profile];
2492
+ case PaywallEventId.DidFailRestore:
2493
+ case PaywallEventId.DidFailRendering:
2494
+ case PaywallEventId.DidFailLoadingProducts: return [event.error];
2495
+ case PaywallEventId.DidPerformAction:
2496
+ if (handlerName === "onUrlPress" || handlerName === "onCustomAction") return [event.action.value ?? ""];
2497
+ return [];
2498
+ case PaywallEventId.DidFinishWebPaymentNavigation: return [event.product, event.error];
2499
+ case PaywallEventId.DidAppear:
2500
+ case PaywallEventId.DidDisappear:
2501
+ case PaywallEventId.DidStartRestore: return [];
2502
+ }
2503
+ }
2504
+
2505
+ //#endregion
2506
+ //#region src/ui/onboarding-event-mapping.ts
2507
+ const ONBOARDING_EVENT_MAPPINGS = {
2508
+ onboarding_on_close_action: [{ handlerName: "onClose" }],
2509
+ onboarding_on_custom_action: [{ handlerName: "onCustom" }],
2510
+ onboarding_on_paywall_action: [{ handlerName: "onPaywall" }],
2511
+ onboarding_on_state_updated_action: [{ handlerName: "onStateUpdated" }],
2512
+ onboarding_did_finish_loading: [{ handlerName: "onFinishedLoading" }],
2513
+ onboarding_on_analytics_action: [{ handlerName: "onAnalytics" }],
2514
+ onboarding_did_fail_with_error: [{ handlerName: "onError" }]
2515
+ };
2516
+ const HANDLER_TO_EVENT_CONFIG = Object.entries(ONBOARDING_EVENT_MAPPINGS).reduce((acc, [nativeEvent, mappings]) => {
2517
+ mappings.forEach(({ handlerName }) => {
2518
+ acc[handlerName] = {
2519
+ nativeEvent,
2520
+ handlerName
2521
+ };
2522
+ });
2523
+ return acc;
2524
+ }, {});
2525
+ const NATIVE_EVENT_TO_HANDLERS = Object.entries(HANDLER_TO_EVENT_CONFIG).reduce((acc, [handlerName, config]) => {
2526
+ if (!acc[config.nativeEvent]) acc[config.nativeEvent] = [];
2527
+ const handlers = acc[config.nativeEvent];
2528
+ if (handlers) handlers.push(handlerName);
2529
+ return acc;
2530
+ }, {});
2531
+ function extractOnboardingCallbackArgs(_handlerName, event) {
2532
+ switch (event.id) {
2533
+ case OnboardingEventId.Close:
2534
+ case OnboardingEventId.Custom:
2535
+ case OnboardingEventId.Paywall: return [event.actionId, event.meta];
2536
+ case OnboardingEventId.StateUpdated: return [event.action, event.meta];
2537
+ case OnboardingEventId.FinishedLoading: return [event.meta];
2538
+ case OnboardingEventId.Analytics: return [{
2539
+ ...event.event,
2540
+ element_id: event.event.elementId
2541
+ }, event.meta];
2542
+ case OnboardingEventId.Error: return [event.error];
2543
+ }
2544
+ }
2545
+
2546
+ //#endregion
2547
+ //#region src/ui/types.ts
2548
+ const AdaptyUiDialogActionType = Object.freeze({
2549
+ primary: "primary",
2550
+ secondary: "secondary"
2551
+ });
2552
+
2553
+ //#endregion
2554
+ //#region src/coders/parse.ts
2555
+ function parseMethodResult(factory, input, resultType, ctx) {
2556
+ const log = ctx?.decode({ methodName: "parseMethodResult" });
2557
+ log?.start(() => ({ input }));
2558
+ let obj;
2559
+ try {
2560
+ obj = JSON.parse(input);
2561
+ } catch (error) {
2562
+ const adaptyError = AdaptyError.failedToDecode(`Failed to decode native response. JSON.parse raised an error: ${error?.message || ""}`);
2563
+ log?.failed(() => ({ error: adaptyError.message }));
2564
+ throw adaptyError;
2565
+ }
2566
+ if (obj.hasOwnProperty("success")) {
2567
+ if ([
2568
+ "String",
2569
+ "Boolean",
2570
+ "Void",
2571
+ "AdaptyUiView",
2572
+ "AdaptyUiDialogActionType"
2573
+ ].includes(resultType)) return obj.success;
2574
+ const coder = getCoder(factory, resultType, ctx);
2575
+ return coder?.decode(obj.success);
2576
+ } else if (obj.hasOwnProperty("error")) {
2577
+ const coder = getCoder(factory, "AdaptyError", ctx);
2578
+ const errorData = coder?.decode(obj.error);
2579
+ throw coder.getError(errorData);
2580
+ } else {
2581
+ const adaptyError = AdaptyError.failedToDecode(`Failed to decode native response. Response does not have expected "success" or "error" property`);
2582
+ log?.failed(() => ({ error: adaptyError.message }));
2583
+ throw adaptyError;
2584
+ }
2585
+ }
2586
+ function parseCommonEvent(factory, event, input, ctx) {
2587
+ let obj;
2588
+ try {
2589
+ obj = JSON.parse(input);
2590
+ } catch (error) {
2591
+ throw AdaptyError.failedToDecode(`Failed to decode event: ${error?.message}`);
2592
+ }
2593
+ switch (event) {
2594
+ case "did_load_latest_profile": return getCoder(factory, "AdaptyProfile", ctx)?.decode(obj["profile"]);
2595
+ case "on_installation_details_success": return getCoder(factory, "AdaptyInstallationDetails", ctx)?.decode(obj["details"]);
2596
+ case "on_installation_details_fail": return getCoder(factory, "AdaptyError", ctx)?.decode(obj["error"]);
2597
+ default: return null;
2598
+ }
2599
+ }
2600
+ function getCoder(factory, type, ctx) {
2601
+ ctx?.stack;
2602
+ switch (type) {
2603
+ case "AdaptyError": return factory.createNativeErrorCoder();
2604
+ case "AdaptyProfile": return factory.createProfileCoder();
2605
+ case "AdaptyPaywall": return factory.createPaywallCoder();
2606
+ case "AdaptyPaywallProduct": return factory.createPaywallProductCoder();
2607
+ case "AdaptyRemoteConfig": return factory.createRemoteConfigCoder();
2608
+ case "AdaptyPaywallBuilder": return factory.createPaywallBuilderCoder();
2609
+ case "AdaptyOnboarding": return factory.createOnboardingCoder();
2610
+ case "AdaptyPurchaseResult": return factory.createPurchaseResultCoder();
2611
+ case "AdaptyInstallationStatus": return factory.createInstallationStatusCoder();
2612
+ case "AdaptyInstallationDetails": return factory.createInstallationDetailsCoder();
2613
+ case "AdaptyUiOnboardingMeta": return factory.createUiOnboardingMetaCoder();
2614
+ case "AdaptyUiOnboardingStateParams": return factory.createUiOnboardingStateParamsCoder();
2615
+ case "AdaptyUiOnboardingStateUpdatedAction": return factory.createUiOnboardingStateUpdatedActionCoder();
2616
+ case "BridgeError": return factory.createBridgeErrorCoder();
2617
+ case "Array<AdaptyPaywallProduct>": return factory.createPaywallProductArrayCoder();
2618
+ case "String": return null;
2619
+ }
2620
+ throw AdaptyError.failedToDecode(`Failed to decode native response. Response has unexpected "type" property: ${type}`);
2621
+ }
2622
+
2623
+ //#endregion
2624
+ //#region src/coders/parse-paywall.ts
2625
+ function parsePaywallEvent(factory, input, ctx) {
2626
+ let obj;
2627
+ try {
2628
+ obj = JSON.parse(input);
2629
+ } catch (error) {
2630
+ throw AdaptyError.failedToDecode(`Failed to decode event: ${error?.message}`);
2631
+ }
2632
+ const eventId = obj["id"];
2633
+ if (!eventId?.startsWith("paywall_view_")) return null;
2634
+ const viewObj = obj["view"];
2635
+ const view = {
2636
+ id: viewObj["id"],
2637
+ placementId: viewObj["placement_id"],
2638
+ variationId: viewObj["variation_id"]
2639
+ };
2640
+ switch (eventId) {
2641
+ case PaywallEventId.DidAppear: return {
2642
+ id: eventId,
2643
+ view
2644
+ };
2645
+ case PaywallEventId.DidDisappear: return {
2646
+ id: eventId,
2647
+ view
2648
+ };
2649
+ case PaywallEventId.DidPerformAction: {
2650
+ const actionObj = obj["action"];
2651
+ return {
2652
+ id: eventId,
2653
+ view,
2654
+ action: {
2655
+ type: actionObj["type"],
2656
+ value: actionObj["value"]
2657
+ }
2658
+ };
2659
+ }
2660
+ case PaywallEventId.DidSelectProduct: return {
2661
+ id: eventId,
2662
+ view,
2663
+ productId: obj["product_id"] ?? ""
2664
+ };
2665
+ case PaywallEventId.DidStartPurchase: return {
2666
+ id: eventId,
2667
+ view,
2668
+ product: getPaywallCoder(factory, "product", ctx).decode(obj["product"])
2669
+ };
2670
+ case PaywallEventId.DidFinishPurchase: return {
2671
+ id: eventId,
2672
+ view,
2673
+ purchaseResult: getPaywallCoder(factory, "purchaseResult", ctx).decode(obj["purchased_result"]),
2674
+ product: getPaywallCoder(factory, "product", ctx).decode(obj["product"])
2675
+ };
2676
+ case PaywallEventId.DidFailPurchase: {
2677
+ const errorCoder = getPaywallCoder(factory, "error", ctx);
2678
+ const decodedError = errorCoder.decode(obj["error"]);
2679
+ return {
2680
+ id: eventId,
2681
+ view,
2682
+ error: errorCoder.getError(decodedError),
2683
+ product: getPaywallCoder(factory, "product", ctx).decode(obj["product"])
2684
+ };
2685
+ }
2686
+ case PaywallEventId.DidStartRestore: return {
2687
+ id: eventId,
2688
+ view
2689
+ };
2690
+ case PaywallEventId.DidFinishRestore: return {
2691
+ id: eventId,
2692
+ view,
2693
+ profile: getPaywallCoder(factory, "profile", ctx).decode(obj["profile"])
2694
+ };
2695
+ case PaywallEventId.DidFailRestore: {
2696
+ const errorCoder = getPaywallCoder(factory, "error", ctx);
2697
+ const decodedError = errorCoder.decode(obj["error"]);
2698
+ return {
2699
+ id: eventId,
2700
+ view,
2701
+ error: errorCoder.getError(decodedError)
2702
+ };
2703
+ }
2704
+ case PaywallEventId.DidFailRendering: {
2705
+ const errorCoder = getPaywallCoder(factory, "error", ctx);
2706
+ const decodedError = errorCoder.decode(obj["error"]);
2707
+ return {
2708
+ id: eventId,
2709
+ view,
2710
+ error: errorCoder.getError(decodedError)
2711
+ };
2712
+ }
2713
+ case PaywallEventId.DidFailLoadingProducts: {
2714
+ const errorCoder = getPaywallCoder(factory, "error", ctx);
2715
+ const decodedError = errorCoder.decode(obj["error"]);
2716
+ return {
2717
+ id: eventId,
2718
+ view,
2719
+ error: errorCoder.getError(decodedError)
2720
+ };
2721
+ }
2722
+ case PaywallEventId.DidFinishWebPaymentNavigation: return {
2723
+ id: eventId,
2724
+ view,
2725
+ product: obj["product"] ? getPaywallCoder(factory, "product", ctx).decode(obj["product"]) : void 0,
2726
+ error: obj["error"] ? (() => {
2727
+ const errorCoder = getPaywallCoder(factory, "error", ctx);
2728
+ const decodedError = errorCoder.decode(obj["error"]);
2729
+ return errorCoder.getError(decodedError);
2730
+ })() : void 0
2731
+ };
2732
+ default: return null;
2733
+ }
2734
+ }
2735
+ function getPaywallCoder(factory, type, _ctx) {
2736
+ switch (type) {
2737
+ case "product": return factory.createPaywallProductCoder();
2738
+ case "profile": return factory.createProfileCoder();
2739
+ case "purchaseResult": return factory.createPurchaseResultCoder();
2740
+ case "error": return factory.createNativeErrorCoder();
2741
+ }
2742
+ }
2743
+
2744
+ //#endregion
2745
+ //#region src/coders/parse-onboarding.ts
2746
+ function parseOnboardingEvent(factory, input, ctx) {
2747
+ let obj;
2748
+ try {
2749
+ obj = JSON.parse(input);
2750
+ } catch (error) {
2751
+ throw AdaptyError.failedToDecode(`Failed to decode event: ${error?.message}`);
2752
+ }
2753
+ const eventId = obj["id"];
2754
+ if (!eventId?.startsWith("onboarding_")) return null;
2755
+ const viewObj = obj["view"];
2756
+ const view = {
2757
+ id: viewObj["id"],
2758
+ placementId: viewObj["placement_id"],
2759
+ variationId: viewObj["variation_id"]
2760
+ };
2761
+ const decodeMeta = () => getOnboardingCoder(factory, "meta", ctx).decode(obj["meta"]);
2762
+ switch (eventId) {
2763
+ case OnboardingEventId.Close:
2764
+ case OnboardingEventId.Custom:
2765
+ case OnboardingEventId.Paywall: return {
2766
+ id: eventId,
2767
+ view,
2768
+ actionId: obj["action_id"] ?? "",
2769
+ meta: decodeMeta()
2770
+ };
2771
+ case OnboardingEventId.StateUpdated: return {
2772
+ id: eventId,
2773
+ view,
2774
+ action: getOnboardingCoder(factory, "action", ctx).decode(obj["action"]),
2775
+ meta: decodeMeta()
2776
+ };
2777
+ case OnboardingEventId.FinishedLoading: return {
2778
+ id: eventId,
2779
+ view,
2780
+ meta: decodeMeta()
2781
+ };
2782
+ case OnboardingEventId.Analytics: {
2783
+ const eventObj = obj["event"];
2784
+ return {
2785
+ id: eventId,
2786
+ view,
2787
+ event: {
2788
+ name: eventObj["name"],
2789
+ elementId: eventObj["element_id"],
2790
+ reply: eventObj["reply"]
2791
+ },
2792
+ meta: decodeMeta()
2793
+ };
2794
+ }
2795
+ case OnboardingEventId.Error: {
2796
+ const errorCoder = getOnboardingCoder(factory, "error", ctx);
2797
+ const decodedError = errorCoder.decode(obj["error"]);
2798
+ return {
2799
+ id: eventId,
2800
+ view,
2801
+ error: errorCoder.getError(decodedError)
2802
+ };
2803
+ }
2804
+ default: return null;
2805
+ }
2806
+ }
2807
+ function getOnboardingCoder(factory, type, _ctx) {
2808
+ switch (type) {
2809
+ case "meta": return factory.createUiOnboardingMetaCoder();
2810
+ case "action": return factory.createUiOnboardingStateUpdatedActionCoder();
2811
+ case "error": return factory.createNativeErrorCoder();
2812
+ }
2813
+ }
2814
+
2815
+ //#endregion
2816
+ //#region src/utils/generate-id.ts
2817
+ /**
2818
+ * Generates a short unique identifier.
2819
+ * Format: 12 lowercase alphanumeric characters
2820
+ */
2821
+ function generateId() {
2822
+ let id = "";
2823
+ while (id.length < 12) id += Math.random().toString(36).slice(2);
2824
+ return id.slice(0, 12);
2825
+ }
2826
+
2827
+ //#endregion
2828
+ //#region src/utils/compact-object.ts
2829
+ /**
2830
+ * Removes undefined properties from an object, preserving the original type structure
2831
+ * @param obj - Source object with potentially undefined values
2832
+ * @returns Object with undefined values filtered out
2833
+ */
2834
+ function filterUndefined(obj) {
2835
+ return Object.fromEntries(Object.entries(obj).filter(([_, value]) => value !== void 0));
2836
+ }
2837
+
2838
+ //#endregion
2839
+ //#region src/utils/map-values.ts
2840
+ /**
2841
+ * Maps over values of an object, transforming each value using the provided function.
2842
+ *
2843
+ * @param obj - The object to map over
2844
+ * @param fn - Function to transform each value
2845
+ * @returns New object with transformed values
2846
+ */
2847
+ function mapValues(obj, fn) {
2848
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value, key)]));
2849
+ }
2850
+
2851
+ //#endregion
2852
+ //#region src/utils/merge-options.ts
2853
+ /**
2854
+ * Checks if a value is a plain object (not an array, null, Date, etc.)
2855
+ */
2856
+ function isPlainObject(value) {
2857
+ return value !== null && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date) && !(value instanceof RegExp) && Object.prototype.toString.call(value) === "[object Object]";
2858
+ }
2859
+ /**
2860
+ * Deep merge implementation that replaces arrays and merges objects
2861
+ */
2862
+ function deepMerge(target, source, seen = new Set()) {
2863
+ if (source === null || source === void 0) return source;
2864
+ if (target === null || target === void 0) return source;
2865
+ if (Array.isArray(source)) return source;
2866
+ if (Array.isArray(target)) return source;
2867
+ if (isPlainObject(target) && isPlainObject(source)) {
2868
+ if (seen.has(source) || seen.has(target)) throw new Error("Converting circular structure to JSON");
2869
+ seen.add(source);
2870
+ seen.add(target);
2871
+ const result = {};
2872
+ const allKeys = new Set([...Object.keys(target), ...Object.keys(source)]);
2873
+ for (const key of allKeys) {
2874
+ if (key === "__proto__" || key === "constructor" || key === "prototype") continue;
2875
+ if (key in source) if (key in target) {
2876
+ if (seen.has(source[key]) || seen.has(target[key])) throw new Error("Converting circular structure to JSON");
2877
+ result[key] = deepMerge(target[key], source[key], seen);
2878
+ } else {
2879
+ if (seen.has(source[key])) throw new Error("Converting circular structure to JSON");
2880
+ result[key] = source[key];
2881
+ }
2882
+ else {
2883
+ if (seen.has(target[key])) throw new Error("Converting circular structure to JSON");
2884
+ result[key] = target[key];
2885
+ }
2886
+ }
2887
+ seen.delete(source);
2888
+ seen.delete(target);
2889
+ return result;
2890
+ }
2891
+ return source;
2892
+ }
2893
+ /**
2894
+ * Universal method for merging options with defaults
2895
+ * @param options - input options
2896
+ * @param defaults - default values
2897
+ * @returns merged object with TResult type
2898
+ */
2899
+ function mergeOptions(options, defaults) {
2900
+ return deepMerge(defaults, options);
2901
+ }
2902
+
2903
+ //#endregion
2904
+ //#region src/utils/with-error-context.ts
2905
+ function toJSON() {
2906
+ return {
2907
+ message: this.message,
2908
+ name: this.name,
2909
+ stack: this.stack,
2910
+ originalError: this.originalError instanceof Error ? {
2911
+ message: this.originalError.message,
2912
+ name: this.originalError.name
2913
+ } : this.originalError
2914
+ };
2915
+ }
2916
+ /**
2917
+ * Wraps a user-provided callback with error context enrichment.
2918
+ * Catches exceptions and wraps them with source and handler information.
2919
+ */
2920
+ function withErrorContext(callback, handlerName, source) {
2921
+ const wrapped = function(...args) {
2922
+ try {
2923
+ return callback.apply(this, args);
2924
+ } catch (error) {
2925
+ const message = `Unhandled exception in user's handler in ${source}.${handlerName}`;
2926
+ const wrappedError = new Error(message);
2927
+ wrappedError.originalError = error;
2928
+ wrappedError.toJSON = toJSON;
2929
+ throw wrappedError;
2930
+ }
2931
+ };
2932
+ return wrapped;
2933
+ }
2934
+
2935
+ //#endregion
2936
+ export { AdaptyAndroidSubscriptionUpdateReplacementMode, AdaptyError, AdaptyUiDialogActionType, AppTrackingTransparencyStatus, CancellationReason, CoderFactory, DefaultLoggerAdapter, DefaultPlatformAdapter, DefaultSdkMetadataAdapter, ErrorCode, FetchPolicy, Gender, HANDLER_TO_EVENT_CONFIG, HANDLER_TO_NATIVE_EVENT, Log, LogContext, LogLevel, LogScope, MethodNames, NATIVE_EVENT_RESOLVER, NATIVE_EVENT_TO_HANDLERS, ONBOARDING_EVENT_MAPPINGS, OfferType, OnboardingEventId, PaywallEventId, ProductPeriod, RefundPreference, VendorStore, WebPresentation, consoleLogSink, extractOnboardingCallbackArgs, extractPaywallCallbackArgs, filterUndefined, generateId, getErrorCode, getErrorPrompt, mapValues, mergeOptions, parseCommonEvent, parseMethodResult, parseOnboardingEvent, parsePaywallEvent, withErrorContext };
2937
+ //# sourceMappingURL=index.mjs.map