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