gomarketme-react-native 2.0.0 → 4.0.1

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.js CHANGED
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -32,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
9
  });
33
10
  };
34
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
14
  function verb(n) { return function (v) { return step([n, v]); }; }
38
15
  function step(op) {
39
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -67,8 +44,8 @@ var react_native_1 = require("react-native");
67
44
  var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
68
45
  var get_user_locale_1 = __importDefault(require("get-user-locale"));
69
46
  var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
70
- var RNIap = __importStar(require("react-native-iap"));
71
47
  var axios_1 = __importDefault(require("axios"));
48
+ var react_native_iap_1 = require("react-native-iap");
72
49
  var GoMarketMeAffiliateMarketingData = /** @class */ (function () {
73
50
  function GoMarketMeAffiliateMarketingData(campaign, affiliate, saleDistribution, affiliateCampaignCode, deviceId, offerCode) {
74
51
  this.campaign = campaign;
@@ -79,10 +56,8 @@ var GoMarketMeAffiliateMarketingData = /** @class */ (function () {
79
56
  this.offerCode = offerCode;
80
57
  }
81
58
  GoMarketMeAffiliateMarketingData.fromJson = function (json) {
82
- // Check if the json is an empty object
83
- if (Object.keys(json).length === 0) {
84
- return null; // Return null or undefined, depending on your preference
85
- }
59
+ if (!json || Object.keys(json).length === 0)
60
+ return null;
86
61
  return new GoMarketMeAffiliateMarketingData(Campaign.fromJson(json.campaign), Affiliate.fromJson(json.affiliate), SaleDistribution.fromJson(json.sale_distribution), json.affiliate_campaign_code || '', json.device_id || '', json.offer_code);
87
62
  };
88
63
  return GoMarketMeAffiliateMarketingData;
@@ -97,7 +72,7 @@ var Campaign = /** @class */ (function () {
97
72
  this.publicLinkUrl = publicLinkUrl;
98
73
  }
99
74
  Campaign.fromJson = function (json) {
100
- return new Campaign(json.id || '', json.name || '', json.status || '', json.type || '', json.public_link_url);
75
+ return new Campaign((json === null || json === void 0 ? void 0 : json.id) || '', (json === null || json === void 0 ? void 0 : json.name) || '', (json === null || json === void 0 ? void 0 : json.status) || '', (json === null || json === void 0 ? void 0 : json.type) || '', json === null || json === void 0 ? void 0 : json.public_link_url);
101
76
  };
102
77
  return Campaign;
103
78
  }());
@@ -113,7 +88,7 @@ var Affiliate = /** @class */ (function () {
113
88
  this.xAccount = xAccount;
114
89
  }
115
90
  Affiliate.fromJson = function (json) {
116
- return new Affiliate(json.id || '', json.first_name || '', json.last_name || '', json.country_code || '', json.instagram_account || '', json.tiktok_account || '', json.x_account || '');
91
+ return new Affiliate((json === null || json === void 0 ? void 0 : json.id) || '', (json === null || json === void 0 ? void 0 : json.first_name) || '', (json === null || json === void 0 ? void 0 : json.last_name) || '', (json === null || json === void 0 ? void 0 : json.country_code) || '', (json === null || json === void 0 ? void 0 : json.instagram_account) || '', (json === null || json === void 0 ? void 0 : json.tiktok_account) || '', (json === null || json === void 0 ? void 0 : json.x_account) || '');
117
92
  };
118
93
  return Affiliate;
119
94
  }());
@@ -124,7 +99,7 @@ var SaleDistribution = /** @class */ (function () {
124
99
  this.affiliatePercentage = affiliatePercentage;
125
100
  }
126
101
  SaleDistribution.fromJson = function (json) {
127
- return new SaleDistribution(json.platform_percentage || '', json.affiliate_percentage || '');
102
+ return new SaleDistribution((json === null || json === void 0 ? void 0 : json.platform_percentage) || '', (json === null || json === void 0 ? void 0 : json.affiliate_percentage) || '');
128
103
  };
129
104
  return SaleDistribution;
130
105
  }());
@@ -132,7 +107,7 @@ exports.SaleDistribution = SaleDistribution;
132
107
  var GoMarketMe = /** @class */ (function () {
133
108
  function GoMarketMe() {
134
109
  this.sdkType = 'ReactNative';
135
- this.sdkVersion = '2.0.0';
110
+ this.sdkVersion = '4.0.1';
136
111
  this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
137
112
  this.sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
138
113
  this.systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
@@ -140,14 +115,10 @@ var GoMarketMe = /** @class */ (function () {
140
115
  this._affiliateCampaignCode = '';
141
116
  this._deviceId = '';
142
117
  this._packageName = '';
143
- this._getTimeZone = function () {
144
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
145
- };
146
118
  }
147
119
  GoMarketMe.getInstance = function () {
148
- if (!GoMarketMe.instance) {
120
+ if (!GoMarketMe.instance)
149
121
  GoMarketMe.instance = new GoMarketMe();
150
- }
151
122
  return GoMarketMe.instance;
152
123
  };
153
124
  GoMarketMe.prototype.initialize = function (apiKey) {
@@ -174,9 +145,12 @@ var GoMarketMe = /** @class */ (function () {
174
145
  return [4 /*yield*/, this._postSystemInfo(systemInfo, apiKey)];
175
146
  case 5:
176
147
  _a.affiliateMarketingData = _b.sent();
177
- return [4 /*yield*/, this._addListener(apiKey)];
148
+ return [4 /*yield*/, this._addListeners(apiKey)];
178
149
  case 6:
179
150
  _b.sent();
151
+ this._fetchExistingPurchases(apiKey).catch(function (e) {
152
+ console.log('Error in background purchase fetch:', e);
153
+ });
180
154
  return [3 /*break*/, 8];
181
155
  case 7:
182
156
  e_1 = _b.sent();
@@ -187,27 +161,44 @@ var GoMarketMe = /** @class */ (function () {
187
161
  });
188
162
  });
189
163
  };
190
- GoMarketMe.prototype._addListener = function (apiKey) {
164
+ GoMarketMe.prototype.removeListeners = function () {
165
+ var _a, _b, _c, _d;
166
+ try {
167
+ (_b = (_a = this._purchaseUpdateUnsub) === null || _a === void 0 ? void 0 : _a.remove) === null || _b === void 0 ? void 0 : _b.call(_a);
168
+ (_d = (_c = this._purchaseErrorUnsub) === null || _c === void 0 ? void 0 : _c.remove) === null || _d === void 0 ? void 0 : _d.call(_c);
169
+ }
170
+ catch (e) {
171
+ console.log('Error removing listeners:', e);
172
+ }
173
+ };
174
+ GoMarketMe.prototype._addListeners = function (apiKey) {
191
175
  return __awaiter(this, void 0, void 0, function () {
192
176
  var _this = this;
193
177
  return __generator(this, function (_a) {
194
- try {
195
- RNIap.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
178
+ if (!this._purchaseUpdateUnsub) {
179
+ this._purchaseUpdateUnsub = (0, react_native_iap_1.purchaseUpdatedListener)(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
180
+ var e_2;
196
181
  return __generator(this, function (_a) {
197
182
  switch (_a.label) {
198
- case 0: return [4 /*yield*/, this._fetchConsolidatedPurchases([purchase], apiKey)];
183
+ case 0:
184
+ _a.trys.push([0, 2, , 3]);
185
+ return [4 /*yield*/, this._fetchConsolidatedPurchases([purchase], apiKey)];
199
186
  case 1:
200
187
  _a.sent();
201
- return [2 /*return*/];
188
+ return [3 /*break*/, 3];
189
+ case 2:
190
+ e_2 = _a.sent();
191
+ console.log('purchaseUpdated error:', e_2);
192
+ return [3 /*break*/, 3];
193
+ case 3: return [2 /*return*/];
202
194
  }
203
195
  });
204
196
  }); });
205
- RNIap.purchaseErrorListener(function (error) {
206
- console.log('Purchase error:', error);
207
- });
208
197
  }
209
- catch (e) {
210
- console.log('Error setting up IAP listeners:', e);
198
+ if (!this._purchaseErrorUnsub) {
199
+ this._purchaseErrorUnsub = (0, react_native_iap_1.purchaseErrorListener)(function (error) {
200
+ console.log('purchaseErrorListener:', error);
201
+ });
211
202
  }
212
203
  return [2 /*return*/];
213
204
  });
@@ -215,242 +206,197 @@ var GoMarketMe = /** @class */ (function () {
215
206
  };
216
207
  GoMarketMe.prototype._getSystemInfo = function () {
217
208
  return __awaiter(this, void 0, void 0, function () {
218
- var deviceData, _a, _b, devicePixelRatio, dimension, windowData;
219
- var _c;
220
- return __generator(this, function (_d) {
221
- switch (_d.label) {
209
+ var deviceData, _a, devicePixelRatio, dimension;
210
+ var _b;
211
+ return __generator(this, function (_c) {
212
+ switch (_c.label) {
222
213
  case 0:
223
- _b = (_a = react_native_1.Platform).select;
224
- _c = {};
214
+ if (!(react_native_1.Platform.OS === 'ios')) return [3 /*break*/, 2];
225
215
  return [4 /*yield*/, this._readIosDeviceInfo()];
226
216
  case 1:
227
- _c.ios = _d.sent();
228
- return [4 /*yield*/, this._readAndroidDeviceInfo()];
229
- case 2:
230
- deviceData = _b.apply(_a, [(_c.android = _d.sent(),
231
- _c)]);
232
- this._deviceId = deviceData['deviceId'];
217
+ _a = _c.sent();
218
+ return [3 /*break*/, 4];
219
+ case 2: return [4 /*yield*/, this._readAndroidDeviceInfo()];
220
+ case 3:
221
+ _a = _c.sent();
222
+ _c.label = 4;
223
+ case 4:
224
+ deviceData = _a;
225
+ this._deviceId = deviceData['deviceId'] || '';
233
226
  devicePixelRatio = react_native_1.PixelRatio.get();
234
227
  dimension = react_native_1.Dimensions.get('window');
235
- windowData = {
236
- devicePixelRatio: devicePixelRatio,
237
- width: dimension.width * devicePixelRatio,
238
- height: dimension.height * devicePixelRatio,
228
+ _b = {
229
+ device_info: deviceData,
230
+ window_info: {
231
+ devicePixelRatio: devicePixelRatio,
232
+ width: dimension.width * devicePixelRatio,
233
+ height: dimension.height * devicePixelRatio,
234
+ },
235
+ time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
236
+ language_code: (0, get_user_locale_1.default)(),
237
+ sdk_type: this.sdkType,
238
+ sdk_version: this.sdkVersion,
239
+ package_name: this._packageName
239
240
  };
240
- return [2 /*return*/, {
241
- device_info: deviceData,
242
- window_info: windowData,
243
- time_zone: this._getTimeZone(),
244
- language_code: this._getLanguageCode(),
245
- }];
241
+ return [4 /*yield*/, this._isProduction()];
242
+ case 5: return [2 /*return*/, (_b.is_production = _c.sent(),
243
+ _b)];
246
244
  }
247
245
  });
248
246
  });
249
247
  };
250
248
  GoMarketMe.prototype._postSDKInitialization = function (apiKey) {
251
249
  return __awaiter(this, void 0, void 0, function () {
252
- var response, e_2;
250
+ var res, e_3;
253
251
  return __generator(this, function (_a) {
254
252
  switch (_a.label) {
255
253
  case 0:
256
- _a.trys.push([0, 5, , 6]);
254
+ _a.trys.push([0, 4, , 5]);
257
255
  return [4 /*yield*/, axios_1.default.post(this.sdkInitializationUrl, {}, {
258
- headers: {
259
- 'Content-Type': 'application/json',
260
- 'x-api-key': apiKey,
261
- },
256
+ headers: { 'x-api-key': apiKey },
262
257
  })];
263
258
  case 1:
264
- response = _a.sent();
265
- if (!(response.status === 200)) return [3 /*break*/, 3];
259
+ res = _a.sent();
260
+ if (!(res.status === 200)) return [3 /*break*/, 3];
266
261
  return [4 /*yield*/, this._markSDKAsInitialized()];
267
262
  case 2:
268
263
  _a.sent();
269
- return [3 /*break*/, 4];
270
- case 3:
271
- console.log('Failed to mark SDK as Initialized. Status code:', response.status);
272
- _a.label = 4;
273
- case 4: return [3 /*break*/, 6];
274
- case 5:
275
- e_2 = _a.sent();
276
- console.log('Error sending SDK information to server:', e_2);
277
- return [3 /*break*/, 6];
278
- case 6: return [2 /*return*/];
264
+ _a.label = 3;
265
+ case 3: return [3 /*break*/, 5];
266
+ case 4:
267
+ e_3 = _a.sent();
268
+ console.log('Error posting SDK initialization:', e_3);
269
+ return [3 /*break*/, 5];
270
+ case 5: return [2 /*return*/];
279
271
  }
280
272
  });
281
273
  });
282
274
  };
283
275
  GoMarketMe.prototype._postSystemInfo = function (data, apiKey) {
284
276
  return __awaiter(this, void 0, void 0, function () {
285
- var output, response, e_3;
277
+ var res, obj, e_4;
286
278
  return __generator(this, function (_a) {
287
279
  switch (_a.label) {
288
280
  case 0:
289
- output = null;
290
- _a.label = 1;
291
- case 1:
292
- _a.trys.push([1, 3, , 4]);
293
- data['sdk_type'] = this.sdkType;
294
- data['sdk_version'] = this.sdkVersion;
295
- data['package_name'] = this._packageName;
281
+ _a.trys.push([0, 2, , 3]);
296
282
  return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, data, {
297
- headers: {
298
- 'Content-Type': 'application/json',
299
- 'x-api-key': apiKey,
300
- },
283
+ headers: { 'x-api-key': apiKey },
301
284
  })];
302
- case 2:
303
- response = _a.sent();
304
- if (response.status === 200) {
305
- output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
306
- if (output != null) {
307
- this._affiliateCampaignCode = output.affiliateCampaignCode;
308
- }
309
- }
310
- else {
311
- console.log('Failed to send system info. Status code:', response.status);
285
+ case 1:
286
+ res = _a.sent();
287
+ if (res.status === 200) {
288
+ obj = GoMarketMeAffiliateMarketingData.fromJson(res.data);
289
+ if (obj)
290
+ this._affiliateCampaignCode = obj.affiliateCampaignCode;
291
+ return [2 /*return*/, obj];
312
292
  }
313
- return [3 /*break*/, 4];
314
- case 3:
315
- e_3 = _a.sent();
316
- console.log('Error sending system info to server:', e_3);
317
- return [3 /*break*/, 4];
318
- case 4: return [2 /*return*/, output];
293
+ return [3 /*break*/, 3];
294
+ case 2:
295
+ e_4 = _a.sent();
296
+ console.log('Error posting system info:', e_4);
297
+ return [3 /*break*/, 3];
298
+ case 3: return [2 /*return*/, null];
319
299
  }
320
300
  });
321
301
  });
322
302
  };
323
303
  GoMarketMe.prototype._readAndroidDeviceInfo = function () {
324
304
  return __awaiter(this, void 0, void 0, function () {
325
- var androidId, uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
326
- return __generator(this, function (_a) {
327
- switch (_a.label) {
328
- case 0: return [4 /*yield*/, react_native_device_info_1.default.getAndroidId()];
305
+ var _a;
306
+ return __generator(this, function (_b) {
307
+ switch (_b.label) {
308
+ case 0:
309
+ _a = {};
310
+ return [4 /*yield*/, react_native_device_info_1.default.getAndroidId()];
329
311
  case 1:
330
- androidId = _a.sent();
331
- return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
312
+ _a.deviceId = _b.sent();
313
+ return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
332
314
  case 2:
333
- uniqueId = _a.sent();
334
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
315
+ _a.brand = _b.sent();
316
+ return [4 /*yield*/, react_native_device_info_1.default.getModel()];
335
317
  case 3:
336
- deviceId = _a.sent();
337
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
318
+ _a.model = _b.sent();
319
+ return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
338
320
  case 4:
339
- systemName = _a.sent();
340
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
321
+ _a.manufacturer = _b.sent();
322
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
341
323
  case 5:
342
- systemVersion = _a.sent();
343
- return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
344
- case 6:
345
- brand = _a.sent();
346
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
347
- case 7:
348
- model = _a.sent();
349
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
350
- case 8:
351
- manufacturer = _a.sent();
352
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
353
- case 9:
354
- isEmulator = _a.sent();
355
- return [2 /*return*/, {
356
- deviceId: androidId,
357
- _deviceId: deviceId,
358
- _uniqueId: uniqueId,
359
- systemName: systemName,
360
- systemVersion: systemVersion,
361
- brand: brand,
362
- model: model,
363
- manufacturer: manufacturer,
364
- isEmulator: isEmulator
365
- }];
324
+ _a.systemName = _b.sent();
325
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
326
+ case 6: return [2 /*return*/, (_a.systemVersion = _b.sent(),
327
+ _a)];
366
328
  }
367
329
  });
368
330
  });
369
331
  };
370
332
  GoMarketMe.prototype._readIosDeviceInfo = function () {
371
333
  return __awaiter(this, void 0, void 0, function () {
372
- var uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
373
- return __generator(this, function (_a) {
374
- switch (_a.label) {
375
- case 0: return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
334
+ var _a;
335
+ return __generator(this, function (_b) {
336
+ switch (_b.label) {
337
+ case 0:
338
+ _a = {};
339
+ return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
376
340
  case 1:
377
- uniqueId = _a.sent();
378
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
341
+ _a.deviceId = _b.sent();
342
+ return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
379
343
  case 2:
380
- deviceId = _a.sent();
381
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
344
+ _a.brand = _b.sent();
345
+ return [4 /*yield*/, react_native_device_info_1.default.getModel()];
382
346
  case 3:
383
- systemName = _a.sent();
384
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
347
+ _a.model = _b.sent();
348
+ return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
385
349
  case 4:
386
- systemVersion = _a.sent();
387
- return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
350
+ _a.manufacturer = _b.sent();
351
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
388
352
  case 5:
389
- brand = _a.sent();
390
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
391
- case 6:
392
- model = _a.sent();
393
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
394
- case 7:
395
- manufacturer = _a.sent();
396
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
397
- case 8:
398
- isEmulator = _a.sent();
399
- return [2 /*return*/, {
400
- deviceId: uniqueId,
401
- _deviceId: deviceId,
402
- systemName: systemName,
403
- systemVersion: systemVersion,
404
- brand: brand,
405
- model: model,
406
- manufacturer: manufacturer,
407
- isEmulator: isEmulator
408
- }];
353
+ _a.systemName = _b.sent();
354
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
355
+ case 6: return [2 /*return*/, (_a.systemVersion = _b.sent(),
356
+ _a)];
409
357
  }
410
358
  });
411
359
  });
412
360
  };
413
- GoMarketMe.prototype._getLanguageCode = function () {
414
- return (0, get_user_locale_1.default)();
415
- };
416
- GoMarketMe.prototype._fetchConsolidatedPurchases = function (purchaseDetailsList, apiKey) {
361
+ GoMarketMe.prototype._fetchConsolidatedPurchases = function (purchases, apiKey) {
417
362
  return __awaiter(this, void 0, void 0, function () {
418
- var _i, purchaseDetailsList_1, purchase, data, products, _a, products_1, product0, products_3, _b, products_2, product0;
419
- return __generator(this, function (_c) {
420
- switch (_c.label) {
363
+ var _i, purchases_1, purchase, receipt, data, pid, products, _a, products_1, p, e_5;
364
+ return __generator(this, function (_b) {
365
+ switch (_b.label) {
421
366
  case 0:
422
- _i = 0, purchaseDetailsList_1 = purchaseDetailsList;
423
- _c.label = 1;
367
+ _i = 0, purchases_1 = purchases;
368
+ _b.label = 1;
424
369
  case 1:
425
- if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 8];
426
- purchase = purchaseDetailsList_1[_i];
427
- if (!purchase.transactionReceipt) return [3 /*break*/, 7];
370
+ if (!(_i < purchases_1.length)) return [3 /*break*/, 8];
371
+ purchase = purchases_1[_i];
372
+ receipt = purchase.purchaseToken;
373
+ if (!receipt)
374
+ return [3 /*break*/, 7];
428
375
  data = this._serializePurchaseDetails(purchase);
429
- data['products'] = [];
430
- if (!(data.productID != '')) return [3 /*break*/, 5];
431
- return [4 /*yield*/, RNIap.getProducts({ skus: [data.productID] })];
376
+ data.products = [];
377
+ pid = data.productID || '';
378
+ if (!pid) return [3 /*break*/, 5];
379
+ _b.label = 2;
432
380
  case 2:
433
- products = _c.sent();
434
- if (!(products.length > 0)) return [3 /*break*/, 3];
435
- for (_a = 0, products_1 = products; _a < products_1.length; _a++) {
436
- product0 = products_1[_a];
437
- data['products'].push(this._serializeProductDetails(product0));
381
+ _b.trys.push([2, 4, , 5]);
382
+ return [4 /*yield*/, (0, react_native_iap_1.fetchProducts)({ skus: [pid] })];
383
+ case 3:
384
+ products = _b.sent();
385
+ if (products && products.length) {
386
+ for (_a = 0, products_1 = products; _a < products_1.length; _a++) {
387
+ p = products_1[_a];
388
+ data.products.push(this._serializeProductDetails(p));
389
+ }
438
390
  }
439
391
  return [3 /*break*/, 5];
440
- case 3: return [4 /*yield*/, RNIap.getSubscriptions({ skus: [data.productID] })];
441
392
  case 4:
442
- products_3 = _c.sent();
443
- if (products_3.length > 0) {
444
- for (_b = 0, products_2 = products_3; _b < products_2.length; _b++) {
445
- product0 = products_2[_b];
446
- data['products'].push(this._serializeSubscriptionDetails(product0));
447
- }
448
- }
449
- _c.label = 5;
450
- case 5: return [4 /*yield*/, this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey)];
393
+ e_5 = _b.sent();
394
+ console.warn('Error fetching products:', e_5);
395
+ return [3 /*break*/, 5];
396
+ case 5: return [4 /*yield*/, this._sendEventToServer(JSON.stringify(data), 'purchase_product', apiKey)];
451
397
  case 6:
452
- _c.sent();
453
- _c.label = 7;
398
+ _b.sent();
399
+ _b.label = 7;
454
400
  case 7:
455
401
  _i++;
456
402
  return [3 /*break*/, 1];
@@ -461,14 +407,13 @@ var GoMarketMe = /** @class */ (function () {
461
407
  };
462
408
  GoMarketMe.prototype._sendEventToServer = function (body, eventType, apiKey) {
463
409
  return __awaiter(this, void 0, void 0, function () {
464
- var response, e_4;
410
+ var e_6;
465
411
  return __generator(this, function (_a) {
466
412
  switch (_a.label) {
467
413
  case 0:
468
414
  _a.trys.push([0, 2, , 3]);
469
415
  return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
470
416
  headers: {
471
- 'Content-Type': 'application/json',
472
417
  'x-affiliate-campaign-code': this._affiliateCampaignCode,
473
418
  'x-device-id': this._deviceId,
474
419
  'x-event-type': eventType,
@@ -478,17 +423,12 @@ var GoMarketMe = /** @class */ (function () {
478
423
  },
479
424
  })];
480
425
  case 1:
481
- response = _a.sent();
482
- if (response.status === 200) {
483
- console.log("".concat(eventType, " sent successfully"));
484
- }
485
- else {
486
- console.log("Failed to send ".concat(eventType, ". Status code:"), response.status);
487
- }
426
+ _a.sent();
427
+ console.log("".concat(eventType, " sent successfully"));
488
428
  return [3 /*break*/, 3];
489
429
  case 2:
490
- e_4 = _a.sent();
491
- console.log("Error sending ".concat(eventType, " to server:"), e_4);
430
+ e_6 = _a.sent();
431
+ console.log("Error sending ".concat(eventType, ":"), e_6);
492
432
  return [3 /*break*/, 3];
493
433
  case 3: return [2 /*return*/];
494
434
  }
@@ -499,101 +439,102 @@ var GoMarketMe = /** @class */ (function () {
499
439
  return {
500
440
  packageName: this._packageName,
501
441
  productID: purchase.productId,
502
- purchaseID: purchase.transactionId || '',
503
- transactionDate: purchase.transactionDate || '',
504
- status: react_native_1.Platform.select({
505
- ios: purchase.transactionStateIOS,
506
- android: purchase.purchaseStateAndroid,
507
- }),
442
+ purchaseID: purchase.id,
443
+ transactionDate: purchase.transactionDate,
508
444
  verificationData: {
509
- localVerificationData: purchase.transactionReceipt,
510
- serverVerificationData: purchase.transactionReceipt,
445
+ localVerificationData: purchase.purchaseToken,
511
446
  source: react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
512
447
  },
513
- pendingCompletePurchase: '',
514
- error: {},
515
- hashCode: '',
516
- _purchase: purchase
517
448
  };
518
449
  };
519
450
  GoMarketMe.prototype._serializeProductDetails = function (product) {
520
451
  return {
521
452
  packageName: this._packageName,
522
- productID: product.productId,
453
+ productID: product.id,
523
454
  productTitle: product.title,
524
455
  productDescription: product.description,
525
- productPrice: product.localizedPrice,
526
- productRawPrice: product.price,
527
- productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
456
+ productPrice: product.displayPrice,
457
+ productRawPrice: product.price || '',
528
458
  productCurrencyCode: product.currency,
529
- hashCode: '',
530
- _product: product
531
- };
532
- };
533
- GoMarketMe.prototype._serializeSubscriptionDetails = function (subscription) {
534
- var _a;
535
- var output = {
536
- productID: subscription.productId,
537
- productTitle: subscription.title,
538
- productDescription: subscription.description,
539
- hashCode: '',
540
459
  };
541
- if (react_native_1.Platform.OS === 'ios') {
542
- var subscriptionIOS = subscription;
543
- output.productPrice = subscriptionIOS.localizedPrice;
544
- output.productRawPrice = subscriptionIOS.price;
545
- output.productCurrencyCode = subscriptionIOS.currency;
546
- output._subscription = subscriptionIOS;
547
- }
548
- else if (react_native_1.Platform.OS === 'android') {
549
- var subscriptionAndroid = subscription;
550
- if ((_a = subscriptionAndroid.subscriptionOfferDetails) === null || _a === void 0 ? void 0 : _a.length) {
551
- var offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
552
- var priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
553
- output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
554
- output.productRawPrice = String(priceAmountMicros / 1000000);
555
- output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
556
- }
557
- output._subscription = subscriptionAndroid;
558
- }
559
- return output;
560
460
  };
561
461
  GoMarketMe.prototype._markSDKAsInitialized = function () {
562
462
  return __awaiter(this, void 0, void 0, function () {
563
- var e_5;
564
463
  return __generator(this, function (_a) {
565
464
  switch (_a.label) {
566
- case 0:
567
- _a.trys.push([0, 2, , 3]);
568
- return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
465
+ case 0: return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
569
466
  case 1:
570
467
  _a.sent();
571
- return [2 /*return*/, true];
572
- case 2:
573
- e_5 = _a.sent();
574
- console.log('Failed to save SDK initialization:', e_5);
575
- return [2 /*return*/, false];
576
- case 3: return [2 /*return*/];
468
+ return [2 /*return*/];
577
469
  }
578
470
  });
579
471
  });
580
472
  };
581
473
  GoMarketMe.prototype._isSDKInitialized = function () {
582
474
  return __awaiter(this, void 0, void 0, function () {
583
- var value, e_6;
475
+ var val;
476
+ return __generator(this, function (_a) {
477
+ switch (_a.label) {
478
+ case 0: return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
479
+ case 1:
480
+ val = _a.sent();
481
+ return [2 /*return*/, val === 'true'];
482
+ }
483
+ });
484
+ });
485
+ };
486
+ GoMarketMe.prototype._isProduction = function () {
487
+ return __awaiter(this, void 0, void 0, function () {
488
+ var installer, error_1;
584
489
  return __generator(this, function (_a) {
585
490
  switch (_a.label) {
586
491
  case 0:
587
- _a.trys.push([0, 2, , 3]);
588
- return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
492
+ if (__DEV__)
493
+ return [2 /*return*/, false];
494
+ _a.label = 1;
589
495
  case 1:
590
- value = _a.sent();
591
- return [2 /*return*/, value === 'true'];
496
+ _a.trys.push([1, 3, , 4]);
497
+ return [4 /*yield*/, react_native_device_info_1.default.getInstallerPackageName()];
592
498
  case 2:
593
- e_6 = _a.sent();
594
- console.log('Failed to load SDK initialization:', e_6);
499
+ installer = _a.sent();
500
+ if (installer === 'com.android.vending' ||
501
+ installer === 'com.amazon.venezia') {
502
+ return [2 /*return*/, true];
503
+ }
504
+ if (installer == null && !__DEV__) {
505
+ return [2 /*return*/, true];
506
+ }
595
507
  return [2 /*return*/, false];
596
- case 3: return [2 /*return*/];
508
+ case 3:
509
+ error_1 = _a.sent();
510
+ console.warn('Error determining production status:', error_1);
511
+ return [2 /*return*/, false];
512
+ case 4: return [2 /*return*/];
513
+ }
514
+ });
515
+ });
516
+ };
517
+ GoMarketMe.prototype._fetchExistingPurchases = function (apiKey) {
518
+ return __awaiter(this, void 0, void 0, function () {
519
+ var purchases, e_7;
520
+ return __generator(this, function (_a) {
521
+ switch (_a.label) {
522
+ case 0:
523
+ _a.trys.push([0, 4, , 5]);
524
+ return [4 /*yield*/, (0, react_native_iap_1.getAvailablePurchases)()];
525
+ case 1:
526
+ purchases = _a.sent();
527
+ if (!(purchases && purchases.length > 0)) return [3 /*break*/, 3];
528
+ return [4 /*yield*/, this._fetchConsolidatedPurchases(purchases, apiKey)];
529
+ case 2:
530
+ _a.sent();
531
+ _a.label = 3;
532
+ case 3: return [3 /*break*/, 5];
533
+ case 4:
534
+ e_7 = _a.sent();
535
+ console.log('Error fetching existing purchases on app open:', e_7);
536
+ return [3 /*break*/, 5];
537
+ case 5: return [2 /*return*/];
597
538
  }
598
539
  });
599
540
  });