gomarketme-react-native 1.1.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- 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;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -39,380 +39,383 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.SaleDistribution = exports.Affiliate = exports.Campaign = exports.GoMarketMeAffiliateMarketingData = void 0;
42
43
  var react_native_1 = require("react-native");
43
44
  var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
44
45
  var get_user_locale_1 = __importDefault(require("get-user-locale"));
45
46
  var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
46
- var react_native_iap_1 = __importDefault(require("react-native-iap"));
47
47
  var axios_1 = __importDefault(require("axios"));
48
+ var react_native_iap_1 = require("react-native-iap");
49
+ var GoMarketMeAffiliateMarketingData = /** @class */ (function () {
50
+ function GoMarketMeAffiliateMarketingData(campaign, affiliate, saleDistribution, affiliateCampaignCode, deviceId, offerCode) {
51
+ this.campaign = campaign;
52
+ this.affiliate = affiliate;
53
+ this.saleDistribution = saleDistribution;
54
+ this.affiliateCampaignCode = affiliateCampaignCode;
55
+ this.deviceId = deviceId;
56
+ this.offerCode = offerCode;
57
+ }
58
+ GoMarketMeAffiliateMarketingData.fromJson = function (json) {
59
+ if (!json || Object.keys(json).length === 0)
60
+ return null;
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);
62
+ };
63
+ return GoMarketMeAffiliateMarketingData;
64
+ }());
65
+ exports.GoMarketMeAffiliateMarketingData = GoMarketMeAffiliateMarketingData;
66
+ var Campaign = /** @class */ (function () {
67
+ function Campaign(id, name, status, type, publicLinkUrl) {
68
+ this.id = id;
69
+ this.name = name;
70
+ this.status = status;
71
+ this.type = type;
72
+ this.publicLinkUrl = publicLinkUrl;
73
+ }
74
+ Campaign.fromJson = function (json) {
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);
76
+ };
77
+ return Campaign;
78
+ }());
79
+ exports.Campaign = Campaign;
80
+ var Affiliate = /** @class */ (function () {
81
+ function Affiliate(id, firstName, lastName, countryCode, instagramAccount, tiktokAccount, xAccount) {
82
+ this.id = id;
83
+ this.firstName = firstName;
84
+ this.lastName = lastName;
85
+ this.countryCode = countryCode;
86
+ this.instagramAccount = instagramAccount;
87
+ this.tiktokAccount = tiktokAccount;
88
+ this.xAccount = xAccount;
89
+ }
90
+ Affiliate.fromJson = function (json) {
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) || '');
92
+ };
93
+ return Affiliate;
94
+ }());
95
+ exports.Affiliate = Affiliate;
96
+ var SaleDistribution = /** @class */ (function () {
97
+ function SaleDistribution(platformPercentage, affiliatePercentage) {
98
+ this.platformPercentage = platformPercentage;
99
+ this.affiliatePercentage = affiliatePercentage;
100
+ }
101
+ SaleDistribution.fromJson = function (json) {
102
+ return new SaleDistribution((json === null || json === void 0 ? void 0 : json.platform_percentage) || '', (json === null || json === void 0 ? void 0 : json.affiliate_percentage) || '');
103
+ };
104
+ return SaleDistribution;
105
+ }());
106
+ exports.SaleDistribution = SaleDistribution;
48
107
  var GoMarketMe = /** @class */ (function () {
49
108
  function GoMarketMe() {
109
+ this.sdkType = 'ReactNative';
110
+ this.sdkVersion = '4.0.0';
50
111
  this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
51
- this.affiliateCampaignCode = '';
52
- this.deviceId = '';
53
- this.sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
54
- this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
55
- this.eventUrl = 'https://api.gomarketme.net/v1/event';
56
- this.getTimeZone = function () {
57
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
58
- };
112
+ this.sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
113
+ this.systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
114
+ this.eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
115
+ this._affiliateCampaignCode = '';
116
+ this._deviceId = '';
117
+ this._packageName = '';
59
118
  }
60
119
  GoMarketMe.getInstance = function () {
61
- if (!GoMarketMe.instance) {
120
+ if (!GoMarketMe.instance)
62
121
  GoMarketMe.instance = new GoMarketMe();
63
- }
64
122
  return GoMarketMe.instance;
65
123
  };
66
124
  GoMarketMe.prototype.initialize = function (apiKey) {
67
125
  return __awaiter(this, void 0, void 0, function () {
68
- var isSDKInitialized, systemInfo, e_1;
69
- return __generator(this, function (_a) {
70
- switch (_a.label) {
126
+ var isSDKInitialized, systemInfo, _a, e_1;
127
+ return __generator(this, function (_b) {
128
+ switch (_b.label) {
71
129
  case 0:
72
- _a.trys.push([0, 7, , 8]);
73
- return [4 /*yield*/, this.isSDKInitialized()];
130
+ _b.trys.push([0, 7, , 8]);
131
+ return [4 /*yield*/, this._isSDKInitialized()];
74
132
  case 1:
75
- isSDKInitialized = _a.sent();
133
+ isSDKInitialized = _b.sent();
76
134
  if (!!isSDKInitialized) return [3 /*break*/, 3];
77
- return [4 /*yield*/, this.postSDKInitialization(apiKey)];
135
+ return [4 /*yield*/, this._postSDKInitialization(apiKey)];
78
136
  case 2:
79
- _a.sent();
80
- _a.label = 3;
81
- case 3: return [4 /*yield*/, this.getSystemInfo()];
137
+ _b.sent();
138
+ _b.label = 3;
139
+ case 3:
140
+ this._packageName = react_native_device_info_1.default.getBundleId();
141
+ return [4 /*yield*/, this._getSystemInfo()];
82
142
  case 4:
83
- systemInfo = _a.sent();
84
- return [4 /*yield*/, this.postSystemInfo(systemInfo, apiKey)];
143
+ systemInfo = _b.sent();
144
+ _a = this;
145
+ return [4 /*yield*/, this._postSystemInfo(systemInfo, apiKey)];
85
146
  case 5:
86
- _a.sent();
87
- return [4 /*yield*/, this.addListener(apiKey)];
147
+ _a.affiliateMarketingData = _b.sent();
148
+ return [4 /*yield*/, this._addListeners(apiKey)];
88
149
  case 6:
89
- _a.sent();
150
+ _b.sent();
151
+ this._fetchExistingPurchases(apiKey).catch(function (e) {
152
+ console.log('Error in background purchase fetch:', e);
153
+ });
90
154
  return [3 /*break*/, 8];
91
155
  case 7:
92
- e_1 = _a.sent();
93
- console.error('Error initializing GoMarketMe:', e_1);
156
+ e_1 = _b.sent();
157
+ console.log('Error initializing GoMarketMe:', e_1);
94
158
  return [3 /*break*/, 8];
95
159
  case 8: return [2 /*return*/];
96
160
  }
97
161
  });
98
162
  });
99
163
  };
100
- 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) {
101
175
  return __awaiter(this, void 0, void 0, function () {
102
176
  var _this = this;
103
177
  return __generator(this, function (_a) {
104
- react_native_iap_1.default.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
105
- var productIds;
106
- return __generator(this, function (_a) {
107
- switch (_a.label) {
108
- case 0:
109
- if (!(this.affiliateCampaignCode != '')) return [3 /*break*/, 3];
110
- return [4 /*yield*/, this.fetchPurchases([purchase], apiKey)];
111
- case 1:
112
- productIds = _a.sent();
113
- return [4 /*yield*/, this.fetchPurchaseProducts(productIds, apiKey)];
114
- case 2:
115
- _a.sent();
116
- _a.label = 3;
117
- case 3: return [2 /*return*/];
118
- }
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;
181
+ return __generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0:
184
+ _a.trys.push([0, 2, , 3]);
185
+ return [4 /*yield*/, this._fetchConsolidatedPurchases([purchase], apiKey)];
186
+ case 1:
187
+ _a.sent();
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*/];
194
+ }
195
+ });
196
+ }); });
197
+ }
198
+ if (!this._purchaseErrorUnsub) {
199
+ this._purchaseErrorUnsub = (0, react_native_iap_1.purchaseErrorListener)(function (error) {
200
+ console.log('purchaseErrorListener:', error);
119
201
  });
120
- }); });
202
+ }
121
203
  return [2 /*return*/];
122
204
  });
123
205
  });
124
206
  };
125
- GoMarketMe.prototype.getSystemInfo = function () {
207
+ GoMarketMe.prototype._getSystemInfo = function () {
126
208
  return __awaiter(this, void 0, void 0, function () {
127
- var deviceData, _a, _b, devicePixelRatio, dimension, windowData;
128
- var _c;
129
- return __generator(this, function (_d) {
130
- switch (_d.label) {
209
+ var deviceData, _a, devicePixelRatio, dimension;
210
+ var _b;
211
+ return __generator(this, function (_c) {
212
+ switch (_c.label) {
131
213
  case 0:
132
- _b = (_a = react_native_1.Platform).select;
133
- _c = {};
134
- return [4 /*yield*/, this.readIosDeviceInfo()];
214
+ if (!(react_native_1.Platform.OS === 'ios')) return [3 /*break*/, 2];
215
+ return [4 /*yield*/, this._readIosDeviceInfo()];
135
216
  case 1:
136
- _c.ios = _d.sent();
137
- return [4 /*yield*/, this.readAndroidDeviceInfo()];
138
- case 2:
139
- deviceData = _b.apply(_a, [(_c.android = _d.sent(),
140
- _c)]);
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'] || '';
141
226
  devicePixelRatio = react_native_1.PixelRatio.get();
142
227
  dimension = react_native_1.Dimensions.get('window');
143
- windowData = {
144
- devicePixelRatio: devicePixelRatio,
145
- width: dimension.width * devicePixelRatio,
146
- 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
147
240
  };
148
- return [2 /*return*/, {
149
- device_info: deviceData,
150
- window_info: windowData,
151
- time_zone: this.getTimeZone(),
152
- language_code: this.getLanguageCode(),
153
- }];
241
+ return [4 /*yield*/, this._isProduction()];
242
+ case 5: return [2 /*return*/, (_b.is_production = _c.sent(),
243
+ _b)];
154
244
  }
155
245
  });
156
246
  });
157
247
  };
158
- GoMarketMe.prototype.postSDKInitialization = function (apiKey) {
248
+ GoMarketMe.prototype._postSDKInitialization = function (apiKey) {
159
249
  return __awaiter(this, void 0, void 0, function () {
160
- var response, e_2;
250
+ var res, e_3;
161
251
  return __generator(this, function (_a) {
162
252
  switch (_a.label) {
163
253
  case 0:
164
- _a.trys.push([0, 5, , 6]);
254
+ _a.trys.push([0, 4, , 5]);
165
255
  return [4 /*yield*/, axios_1.default.post(this.sdkInitializationUrl, {}, {
166
- headers: {
167
- 'Content-Type': 'application/json',
168
- 'x-api-key': apiKey,
169
- },
256
+ headers: { 'x-api-key': apiKey },
170
257
  })];
171
258
  case 1:
172
- response = _a.sent();
173
- if (!(response.status === 200)) return [3 /*break*/, 3];
174
- return [4 /*yield*/, this.markSDKAsInitialized()];
259
+ res = _a.sent();
260
+ if (!(res.status === 200)) return [3 /*break*/, 3];
261
+ return [4 /*yield*/, this._markSDKAsInitialized()];
175
262
  case 2:
176
263
  _a.sent();
177
- return [3 /*break*/, 4];
178
- case 3:
179
- console.error('Failed to mark SDK as Initialized. Status code:', response.status);
180
- _a.label = 4;
181
- case 4: return [3 /*break*/, 6];
182
- case 5:
183
- e_2 = _a.sent();
184
- console.error('Error sending SDK information to server:', e_2);
185
- return [3 /*break*/, 6];
186
- 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*/];
187
271
  }
188
272
  });
189
273
  });
190
274
  };
191
- GoMarketMe.prototype.postSystemInfo = function (systemInfo, apiKey) {
275
+ GoMarketMe.prototype._postSystemInfo = function (data, apiKey) {
192
276
  return __awaiter(this, void 0, void 0, function () {
193
- var response, responseData, e_3;
277
+ var res, obj, e_4;
194
278
  return __generator(this, function (_a) {
195
279
  switch (_a.label) {
196
280
  case 0:
197
281
  _a.trys.push([0, 2, , 3]);
198
- return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, systemInfo, {
199
- headers: {
200
- 'Content-Type': 'application/json',
201
- 'x-api-key': apiKey,
202
- },
282
+ return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, data, {
283
+ headers: { 'x-api-key': apiKey },
203
284
  })];
204
285
  case 1:
205
- response = _a.sent();
206
- if (response.status === 200) {
207
- responseData = response.data;
208
- if (responseData.affiliate_campaign_code) {
209
- this.affiliateCampaignCode = responseData.affiliate_campaign_code;
210
- }
211
- if (responseData.device_id) {
212
- this.deviceId = responseData.device_id;
213
- }
214
- }
215
- else {
216
- console.error('Failed to send system info. Status code:', response.status);
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];
217
292
  }
218
293
  return [3 /*break*/, 3];
219
294
  case 2:
220
- e_3 = _a.sent();
221
- console.error('Error sending system info to server:', e_3);
295
+ e_4 = _a.sent();
296
+ console.log('Error posting system info:', e_4);
222
297
  return [3 /*break*/, 3];
223
- case 3: return [2 /*return*/];
298
+ case 3: return [2 /*return*/, null];
224
299
  }
225
300
  });
226
301
  });
227
302
  };
228
- GoMarketMe.prototype.readAndroidDeviceInfo = function () {
303
+ GoMarketMe.prototype._readAndroidDeviceInfo = function () {
229
304
  return __awaiter(this, void 0, void 0, function () {
230
- var androidId, uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
231
- return __generator(this, function (_a) {
232
- switch (_a.label) {
233
- 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()];
234
311
  case 1:
235
- androidId = _a.sent();
236
- return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
237
- case 2:
238
- uniqueId = _a.sent();
239
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
240
- case 3:
241
- deviceId = _a.sent();
242
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
243
- case 4:
244
- systemName = _a.sent();
245
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
246
- case 5:
247
- systemVersion = _a.sent();
312
+ _a.deviceId = _b.sent();
248
313
  return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
249
- case 6:
250
- brand = _a.sent();
251
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
252
- case 7:
253
- model = _a.sent();
254
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
255
- case 8:
256
- manufacturer = _a.sent();
257
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
258
- case 9:
259
- isEmulator = _a.sent();
260
- return [2 /*return*/, {
261
- deviceId: androidId,
262
- _deviceId: deviceId,
263
- _uniqueId: uniqueId,
264
- systemName: systemName,
265
- systemVersion: systemVersion,
266
- brand: brand,
267
- model: model,
268
- manufacturer: manufacturer,
269
- isEmulator: isEmulator
270
- }];
271
- }
272
- });
273
- });
274
- };
275
- GoMarketMe.prototype.readIosDeviceInfo = function () {
276
- return __awaiter(this, void 0, void 0, function () {
277
- var uniqueId, deviceId, systemName, systemVersion, brand, model, manufacturer, isEmulator;
278
- return __generator(this, function (_a) {
279
- switch (_a.label) {
280
- case 0: return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
281
- case 1:
282
- uniqueId = _a.sent();
283
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
284
314
  case 2:
285
- deviceId = _a.sent();
286
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
315
+ _a.brand = _b.sent();
316
+ return [4 /*yield*/, react_native_device_info_1.default.getModel()];
287
317
  case 3:
288
- systemName = _a.sent();
289
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
318
+ _a.model = _b.sent();
319
+ return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
290
320
  case 4:
291
- systemVersion = _a.sent();
292
- return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
321
+ _a.manufacturer = _b.sent();
322
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
293
323
  case 5:
294
- brand = _a.sent();
295
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
296
- case 6:
297
- model = _a.sent();
298
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
299
- case 7:
300
- manufacturer = _a.sent();
301
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
302
- case 8:
303
- isEmulator = _a.sent();
304
- return [2 /*return*/, {
305
- deviceId: uniqueId,
306
- _deviceId: deviceId,
307
- systemName: systemName,
308
- systemVersion: systemVersion,
309
- brand: brand,
310
- model: model,
311
- manufacturer: manufacturer,
312
- isEmulator: isEmulator
313
- }];
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)];
314
328
  }
315
329
  });
316
330
  });
317
331
  };
318
- GoMarketMe.prototype.getLanguageCode = function () {
319
- return (0, get_user_locale_1.default)();
320
- };
321
- GoMarketMe.prototype.fetchPurchases = function (purchaseDetailsList, apiKey) {
332
+ GoMarketMe.prototype._readIosDeviceInfo = function () {
322
333
  return __awaiter(this, void 0, void 0, function () {
323
- var productIds, _i, purchaseDetailsList_1, purchase;
324
- return __generator(this, function (_a) {
325
- switch (_a.label) {
334
+ var _a;
335
+ return __generator(this, function (_b) {
336
+ switch (_b.label) {
326
337
  case 0:
327
- productIds = [];
328
- _i = 0, purchaseDetailsList_1 = purchaseDetailsList;
329
- _a.label = 1;
338
+ _a = {};
339
+ return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
330
340
  case 1:
331
- if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 4];
332
- purchase = purchaseDetailsList_1[_i];
333
- if (!purchase.transactionReceipt) return [3 /*break*/, 3];
334
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey)];
341
+ _a.deviceId = _b.sent();
342
+ return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
335
343
  case 2:
336
- _a.sent();
337
- if (purchase.productId && !productIds.includes(purchase.productId)) {
338
- productIds.push(purchase.productId);
339
- }
340
- _a.label = 3;
344
+ _a.brand = _b.sent();
345
+ return [4 /*yield*/, react_native_device_info_1.default.getModel()];
341
346
  case 3:
342
- _i++;
343
- return [3 /*break*/, 1];
344
- case 4: return [2 /*return*/, productIds];
347
+ _a.model = _b.sent();
348
+ return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
349
+ case 4:
350
+ _a.manufacturer = _b.sent();
351
+ return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
352
+ case 5:
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)];
345
357
  }
346
358
  });
347
359
  });
348
360
  };
349
- GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
361
+ GoMarketMe.prototype._fetchConsolidatedPurchases = function (purchases, apiKey) {
350
362
  return __awaiter(this, void 0, void 0, function () {
351
- var products, _i, products_1, product, products_3, _a, products_2, product, e_4;
363
+ var _i, purchases_1, purchase, receipt, data, pid, products, _a, products_1, p, e_5;
352
364
  return __generator(this, function (_b) {
353
365
  switch (_b.label) {
354
366
  case 0:
355
- _b.trys.push([0, 15, , 16]);
356
- return [4 /*yield*/, react_native_iap_1.default.getProducts(productIds)];
367
+ _i = 0, purchases_1 = purchases;
368
+ _b.label = 1;
357
369
  case 1:
358
- products = _b.sent();
359
- if (!(products.length > 0)) return [3 /*break*/, 6];
360
- _i = 0, products_1 = products;
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];
375
+ data = this._serializePurchaseDetails(purchase);
376
+ data.products = [];
377
+ pid = data.productID || '';
378
+ if (!pid) return [3 /*break*/, 5];
361
379
  _b.label = 2;
362
380
  case 2:
363
- if (!(_i < products_1.length)) return [3 /*break*/, 5];
364
- product = products_1[_i];
365
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
381
+ _b.trys.push([2, 4, , 5]);
382
+ return [4 /*yield*/, (0, react_native_iap_1.fetchProducts)({ skus: [pid] })];
366
383
  case 3:
367
- _b.sent();
368
- _b.label = 4;
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
+ }
390
+ }
391
+ return [3 /*break*/, 5];
369
392
  case 4:
370
- _i++;
371
- return [3 /*break*/, 2];
372
- case 5: return [3 /*break*/, 14];
373
- case 6: return [4 /*yield*/, react_native_iap_1.default.getSubscriptions(productIds)];
374
- case 7:
375
- products_3 = _b.sent();
376
- if (!(products_3.length > 0)) return [3 /*break*/, 12];
377
- _a = 0, products_2 = products_3;
378
- _b.label = 8;
379
- case 8:
380
- if (!(_a < products_2.length)) return [3 /*break*/, 11];
381
- product = products_2[_a];
382
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeSubscriptionDetails(product)), 'product', apiKey)];
383
- case 9:
384
- _b.sent();
385
- _b.label = 10;
386
- case 10:
387
- _a++;
388
- return [3 /*break*/, 8];
389
- case 11: return [3 /*break*/, 14];
390
- case 12: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
391
- case 13:
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)];
397
+ case 6:
392
398
  _b.sent();
393
- _b.label = 14;
394
- case 14: return [3 /*break*/, 16];
395
- case 15:
396
- e_4 = _b.sent();
397
- console.error('Error fetching products:', e_4);
398
- return [3 /*break*/, 16];
399
- case 16: return [2 /*return*/];
399
+ _b.label = 7;
400
+ case 7:
401
+ _i++;
402
+ return [3 /*break*/, 1];
403
+ case 8: return [2 /*return*/];
400
404
  }
401
405
  });
402
406
  });
403
407
  };
404
- GoMarketMe.prototype.sendEventToServer = function (body, eventType, apiKey) {
408
+ GoMarketMe.prototype._sendEventToServer = function (body, eventType, apiKey) {
405
409
  return __awaiter(this, void 0, void 0, function () {
406
- var response, e_5;
410
+ var e_6;
407
411
  return __generator(this, function (_a) {
408
412
  switch (_a.label) {
409
413
  case 0:
410
414
  _a.trys.push([0, 2, , 3]);
411
415
  return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
412
416
  headers: {
413
- 'Content-Type': 'application/json',
414
- 'x-affiliate-campaign-code': this.affiliateCampaignCode,
415
- 'x-device-id': this.deviceId,
417
+ 'x-affiliate-campaign-code': this._affiliateCampaignCode,
418
+ 'x-device-id': this._deviceId,
416
419
  'x-event-type': eventType,
417
420
  'x-product-type': react_native_1.Platform.OS,
418
421
  'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
@@ -420,93 +423,118 @@ var GoMarketMe = /** @class */ (function () {
420
423
  },
421
424
  })];
422
425
  case 1:
423
- response = _a.sent();
424
- if (response.status === 200) {
425
- console.log("".concat(eventType, " sent successfully"));
426
- }
427
- else {
428
- console.error("Failed to send ".concat(eventType, ". Status code:"), response.status);
429
- }
426
+ _a.sent();
427
+ console.log("".concat(eventType, " sent successfully"));
430
428
  return [3 /*break*/, 3];
431
429
  case 2:
432
- e_5 = _a.sent();
433
- console.error("Error sending ".concat(eventType, " to server:"), e_5);
430
+ e_6 = _a.sent();
431
+ console.log("Error sending ".concat(eventType, ":"), e_6);
434
432
  return [3 /*break*/, 3];
435
433
  case 3: return [2 /*return*/];
436
434
  }
437
435
  });
438
436
  });
439
437
  };
440
- GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
438
+ GoMarketMe.prototype._serializePurchaseDetails = function (purchase) {
441
439
  return {
440
+ packageName: this._packageName,
442
441
  productID: purchase.productId,
443
- purchaseID: purchase.transactionId || '',
444
- transactionDate: purchase.transactionDate || '',
445
- status: react_native_1.Platform.select({
446
- ios: purchase.transactionStateIOS,
447
- android: purchase.purchaseStateAndroid,
448
- }),
442
+ purchaseID: purchase.id,
443
+ transactionDate: purchase.transactionDate,
449
444
  verificationData: {
450
- localVerificationData: purchase.transactionReceipt,
445
+ localVerificationData: purchase.purchaseToken,
446
+ source: react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
451
447
  },
452
448
  };
453
449
  };
454
- GoMarketMe.prototype.serializeProductDetails = function (product) {
450
+ GoMarketMe.prototype._serializeProductDetails = function (product) {
455
451
  return {
456
- productID: product.productId,
452
+ packageName: this._packageName,
453
+ productID: product.id,
457
454
  productTitle: product.title,
458
455
  productDescription: product.description,
459
- productPrice: product.price,
460
- productRawPrice: product.price,
456
+ productPrice: product.displayPrice,
457
+ productRawPrice: product.price || '',
461
458
  productCurrencyCode: product.currency,
462
459
  };
463
460
  };
464
- GoMarketMe.prototype.serializeSubscriptionDetails = function (subscription) {
465
- return {
466
- productID: subscription.productId,
467
- productTitle: subscription.title,
468
- productDescription: subscription.description,
469
- productPrice: subscription.price,
470
- productRawPrice: subscription.price,
471
- productCurrencyCode: subscription.currency,
472
- };
461
+ GoMarketMe.prototype._markSDKAsInitialized = function () {
462
+ return __awaiter(this, void 0, void 0, function () {
463
+ return __generator(this, function (_a) {
464
+ switch (_a.label) {
465
+ case 0: return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
466
+ case 1:
467
+ _a.sent();
468
+ return [2 /*return*/];
469
+ }
470
+ });
471
+ });
473
472
  };
474
- GoMarketMe.prototype.markSDKAsInitialized = function () {
473
+ GoMarketMe.prototype._isSDKInitialized = function () {
475
474
  return __awaiter(this, void 0, void 0, function () {
476
- var 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;
477
489
  return __generator(this, function (_a) {
478
490
  switch (_a.label) {
479
491
  case 0:
480
- _a.trys.push([0, 2, , 3]);
481
- return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
492
+ if (__DEV__)
493
+ return [2 /*return*/, false];
494
+ _a.label = 1;
482
495
  case 1:
483
- _a.sent();
484
- return [2 /*return*/, true];
496
+ _a.trys.push([1, 3, , 4]);
497
+ return [4 /*yield*/, react_native_device_info_1.default.getInstallerPackageName()];
485
498
  case 2:
486
- e_6 = _a.sent();
487
- console.error('Failed to save 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
+ }
488
507
  return [2 /*return*/, false];
489
- 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*/];
490
513
  }
491
514
  });
492
515
  });
493
516
  };
494
- GoMarketMe.prototype.isSDKInitialized = function () {
517
+ GoMarketMe.prototype._fetchExistingPurchases = function (apiKey) {
495
518
  return __awaiter(this, void 0, void 0, function () {
496
- var value, e_7;
519
+ var purchases, e_7;
497
520
  return __generator(this, function (_a) {
498
521
  switch (_a.label) {
499
522
  case 0:
500
- _a.trys.push([0, 2, , 3]);
501
- return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
523
+ _a.trys.push([0, 4, , 5]);
524
+ return [4 /*yield*/, (0, react_native_iap_1.getAvailablePurchases)()];
502
525
  case 1:
503
- value = _a.sent();
504
- return [2 /*return*/, value === 'true'];
526
+ purchases = _a.sent();
527
+ if (!(purchases && purchases.length > 0)) return [3 /*break*/, 3];
528
+ return [4 /*yield*/, this._fetchConsolidatedPurchases(purchases, apiKey)];
505
529
  case 2:
530
+ _a.sent();
531
+ _a.label = 3;
532
+ case 3: return [3 /*break*/, 5];
533
+ case 4:
506
534
  e_7 = _a.sent();
507
- console.error('Failed to load SDK initialization:', e_7);
508
- return [2 /*return*/, false];
509
- case 3: return [2 /*return*/];
535
+ console.log('Error fetching existing purchases on app open:', e_7);
536
+ return [3 /*break*/, 5];
537
+ case 5: return [2 /*return*/];
510
538
  }
511
539
  });
512
540
  });