gomarketme-react-native 1.0.7 → 1.0.9

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
@@ -31,45 +31,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
31
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
32
  });
33
33
  };
34
- 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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
36
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
62
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
63
36
  };
64
37
  Object.defineProperty(exports, "__esModule", { value: true });
65
- var react_native_1 = require("react-native");
66
- var react_native_device_info_1 = __importDefault(require("react-native-device-info"));
67
- var RNLocalize = __importStar(require("react-native-localize"));
68
- var async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
69
- var react_native_iap_1 = __importDefault(require("react-native-iap"));
70
- var axios_1 = __importDefault(require("axios"));
71
- var GoMarketMe = /** @class */ (function () {
72
- function GoMarketMe() {
38
+ const react_native_1 = require("react-native");
39
+ const react_native_device_info_1 = __importDefault(require("react-native-device-info"));
40
+ const RNLocalize = __importStar(require("react-native-localize"));
41
+ const async_storage_1 = __importDefault(require("@react-native-async-storage/async-storage"));
42
+ const react_native_iap_1 = __importDefault(require("react-native-iap"));
43
+ const axios_1 = __importDefault(require("axios"));
44
+ class GoMarketMe {
45
+ constructor() {
73
46
  this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
74
47
  this.affiliateCampaignCode = '';
75
48
  this.deviceId = '';
@@ -77,433 +50,231 @@ var GoMarketMe = /** @class */ (function () {
77
50
  this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
78
51
  this.eventUrl = 'https://api.gomarketme.net/v1/event';
79
52
  }
80
- GoMarketMe.getInstance = function () {
53
+ static getInstance() {
81
54
  if (!GoMarketMe.instance) {
82
55
  GoMarketMe.instance = new GoMarketMe();
83
56
  }
84
57
  return GoMarketMe.instance;
85
- };
86
- GoMarketMe.prototype.initialize = function (apiKey) {
87
- return __awaiter(this, void 0, void 0, function () {
88
- var isSDKInitialized, systemInfo, e_1;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0:
92
- _a.trys.push([0, 7, , 8]);
93
- return [4 /*yield*/, this.isSDKInitialized()];
94
- case 1:
95
- isSDKInitialized = _a.sent();
96
- if (!!isSDKInitialized) return [3 /*break*/, 3];
97
- return [4 /*yield*/, this.postSDKInitialization(apiKey)];
98
- case 2:
99
- _a.sent();
100
- _a.label = 3;
101
- case 3: return [4 /*yield*/, this.getSystemInfo()];
102
- case 4:
103
- systemInfo = _a.sent();
104
- return [4 /*yield*/, this.postSystemInfo(systemInfo, apiKey)];
105
- case 5:
106
- _a.sent();
107
- return [4 /*yield*/, this.addListener(apiKey)];
108
- case 6:
109
- _a.sent();
110
- return [3 /*break*/, 8];
111
- case 7:
112
- e_1 = _a.sent();
113
- console.error('Error initializing GoMarketMe:', e_1);
114
- return [3 /*break*/, 8];
115
- case 8: return [2 /*return*/];
58
+ }
59
+ initialize(apiKey) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ const isSDKInitialized = yield this.isSDKInitialized();
63
+ if (!isSDKInitialized) {
64
+ yield this.postSDKInitialization(apiKey);
116
65
  }
117
- });
118
- });
119
- };
120
- GoMarketMe.prototype.addListener = function (apiKey) {
121
- return __awaiter(this, void 0, void 0, function () {
122
- var _this = this;
123
- return __generator(this, function (_a) {
124
- react_native_iap_1.default.purchaseUpdatedListener(function (purchase) { return __awaiter(_this, void 0, void 0, function () {
125
- var productIds;
126
- return __generator(this, function (_a) {
127
- switch (_a.label) {
128
- case 0:
129
- if (!(this.affiliateCampaignCode != '')) return [3 /*break*/, 3];
130
- return [4 /*yield*/, this.fetchPurchases([purchase], apiKey)];
131
- case 1:
132
- productIds = _a.sent();
133
- return [4 /*yield*/, this.fetchPurchaseProducts(productIds, apiKey)];
134
- case 2:
135
- _a.sent();
136
- _a.label = 3;
137
- case 3: return [2 /*return*/];
138
- }
139
- });
140
- }); });
141
- return [2 /*return*/];
142
- });
66
+ const systemInfo = yield this.getSystemInfo();
67
+ yield this.postSystemInfo(systemInfo, apiKey);
68
+ yield this.addListener(apiKey);
69
+ }
70
+ catch (e) {
71
+ console.error('Error initializing GoMarketMe:', e);
72
+ }
143
73
  });
144
- };
145
- GoMarketMe.prototype.getSystemInfo = function () {
146
- return __awaiter(this, void 0, void 0, function () {
147
- var deviceData, _a, _b, devicePixelRatio, windowData;
148
- var _c;
149
- return __generator(this, function (_d) {
150
- switch (_d.label) {
151
- case 0:
152
- _b = (_a = react_native_1.Platform).select;
153
- _c = {};
154
- return [4 /*yield*/, this.readIosDeviceInfo()];
155
- case 1:
156
- _c.ios = _d.sent();
157
- return [4 /*yield*/, this.readAndroidDeviceInfo()];
158
- case 2:
159
- deviceData = _b.apply(_a, [(_c.android = _d.sent(),
160
- _c)]);
161
- devicePixelRatio = react_native_1.PixelRatio.get();
162
- windowData = {
163
- devicePixelRatio: devicePixelRatio,
164
- width: react_native_1.Dimensions.get('window').width * devicePixelRatio,
165
- height: react_native_1.Dimensions.get('window').height * devicePixelRatio,
166
- };
167
- return [2 /*return*/, {
168
- device_info: deviceData,
169
- window_info: windowData,
170
- time_zone_code: this.getTimeZoneCode(),
171
- language_code: this.getLanguageCode(),
172
- }];
74
+ }
75
+ addListener(apiKey) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ react_native_iap_1.default.purchaseUpdatedListener((purchase) => __awaiter(this, void 0, void 0, function* () {
78
+ if (this.affiliateCampaignCode) {
79
+ const productIds = yield this.fetchPurchases([purchase], apiKey);
80
+ yield this.fetchPurchaseProducts(productIds, apiKey);
173
81
  }
174
- });
82
+ }));
175
83
  });
176
- };
177
- GoMarketMe.prototype.postSDKInitialization = function (apiKey) {
178
- return __awaiter(this, void 0, void 0, function () {
179
- var response, e_2;
180
- return __generator(this, function (_a) {
181
- switch (_a.label) {
182
- case 0:
183
- _a.trys.push([0, 5, , 6]);
184
- return [4 /*yield*/, axios_1.default.post(this.sdkInitializationUrl, {}, {
185
- headers: {
186
- 'Content-Type': 'application/json',
187
- 'x-api-key': apiKey,
188
- },
189
- })];
190
- case 1:
191
- response = _a.sent();
192
- if (!(response.status === 200)) return [3 /*break*/, 3];
193
- return [4 /*yield*/, this.markSDKAsInitialized()];
194
- case 2:
195
- _a.sent();
196
- return [3 /*break*/, 4];
197
- case 3:
198
- console.error('Failed to mark SDK as Initialized. Status code:', response.status);
199
- _a.label = 4;
200
- case 4: return [3 /*break*/, 6];
201
- case 5:
202
- e_2 = _a.sent();
203
- console.error('Error sending SDK information to server:', e_2);
204
- return [3 /*break*/, 6];
205
- case 6: return [2 /*return*/];
206
- }
84
+ }
85
+ getSystemInfo() {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ const deviceData = react_native_1.Platform.select({
88
+ ios: yield this.readIosDeviceInfo(),
89
+ android: yield this.readAndroidDeviceInfo(),
207
90
  });
91
+ const devicePixelRatio = react_native_1.PixelRatio.get();
92
+ const windowData = {
93
+ devicePixelRatio,
94
+ width: react_native_1.Dimensions.get('window').width * devicePixelRatio,
95
+ height: react_native_1.Dimensions.get('window').height * devicePixelRatio,
96
+ };
97
+ return {
98
+ device_info: deviceData,
99
+ window_info: windowData,
100
+ time_zone_code: this.getTimeZoneCode(),
101
+ language_code: this.getLanguageCode(),
102
+ };
208
103
  });
209
- };
210
- GoMarketMe.prototype.postSystemInfo = function (systemInfo, apiKey) {
211
- return __awaiter(this, void 0, void 0, function () {
212
- var response, responseData, e_3;
213
- return __generator(this, function (_a) {
214
- switch (_a.label) {
215
- case 0:
216
- _a.trys.push([0, 2, , 3]);
217
- return [4 /*yield*/, axios_1.default.post(this.systemInfoUrl, systemInfo, {
218
- headers: {
219
- 'Content-Type': 'application/json',
220
- 'x-api-key': apiKey,
221
- },
222
- })];
223
- case 1:
224
- response = _a.sent();
225
- if (response.status === 200) {
226
- responseData = response.data;
227
- if (responseData.affiliate_campaign_code) {
228
- this.affiliateCampaignCode = responseData.affiliate_campaign_code;
229
- }
230
- if (responseData.device_id) {
231
- this.deviceId = responseData.device_id;
232
- }
233
- }
234
- else {
235
- console.error('Failed to send system info. Status code:', response.status);
236
- }
237
- return [3 /*break*/, 3];
238
- case 2:
239
- e_3 = _a.sent();
240
- console.error('Error sending system info to server:', e_3);
241
- return [3 /*break*/, 3];
242
- case 3: return [2 /*return*/];
104
+ }
105
+ postSDKInitialization(apiKey) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ try {
108
+ const response = yield axios_1.default.post(this.sdkInitializationUrl, {}, {
109
+ headers: {
110
+ 'Content-Type': 'application/json',
111
+ 'x-api-key': apiKey,
112
+ },
113
+ });
114
+ if (response.status === 200) {
115
+ yield this.markSDKAsInitialized();
243
116
  }
244
- });
245
- });
246
- };
247
- GoMarketMe.prototype.readAndroidDeviceInfo = function () {
248
- return __awaiter(this, void 0, void 0, function () {
249
- var _a;
250
- return __generator(this, function (_b) {
251
- switch (_b.label) {
252
- case 0:
253
- _a = {};
254
- return [4 /*yield*/, react_native_device_info_1.default.getAndroidId()];
255
- case 1:
256
- _a.deviceId = _b.sent();
257
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
258
- case 2:
259
- _a._deviceId = _b.sent();
260
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
261
- case 3:
262
- _a.systemName = _b.sent();
263
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
264
- case 4:
265
- _a.systemVersion = _b.sent();
266
- return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
267
- case 5:
268
- _a.brand = _b.sent();
269
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
270
- case 6:
271
- _a.model = _b.sent();
272
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
273
- case 7:
274
- _a.manufacturer = _b.sent();
275
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
276
- case 8:
277
- _a.isEmulator = _b.sent();
278
- return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
279
- case 9: return [2 /*return*/, (_a.uniqueId = _b.sent(),
280
- _a)];
117
+ else {
118
+ console.error('Failed to mark SDK as Initialized. Status code:', response.status);
281
119
  }
282
- });
120
+ }
121
+ catch (e) {
122
+ console.error('Error sending SDK information to server:', e);
123
+ }
283
124
  });
284
- };
285
- GoMarketMe.prototype.readIosDeviceInfo = function () {
286
- return __awaiter(this, void 0, void 0, function () {
287
- var info;
288
- var _a;
289
- return __generator(this, function (_b) {
290
- switch (_b.label) {
291
- case 0:
292
- _a = {};
293
- return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
294
- case 1:
295
- _a.deviceId = _b.sent();
296
- return [4 /*yield*/, react_native_device_info_1.default.getDeviceId()];
297
- case 2:
298
- _a._deviceId = _b.sent();
299
- return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
300
- case 3:
301
- _a.systemName = _b.sent();
302
- return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
303
- case 4:
304
- _a.systemVersion = _b.sent();
305
- return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
306
- case 5:
307
- _a.brand = _b.sent();
308
- return [4 /*yield*/, react_native_device_info_1.default.getModel()];
309
- case 6:
310
- _a.model = _b.sent();
311
- return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
312
- case 7:
313
- _a.manufacturer = _b.sent();
314
- return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
315
- case 8:
316
- _a.isEmulator = _b.sent();
317
- return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
318
- case 9:
319
- info = (_a.uniqueId = _b.sent(),
320
- _a);
321
- return [2 /*return*/];
125
+ }
126
+ postSystemInfo(systemInfo, apiKey) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ try {
129
+ const response = yield axios_1.default.post(this.systemInfoUrl, systemInfo, {
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ 'x-api-key': apiKey,
133
+ },
134
+ });
135
+ if (response.status === 200) {
136
+ const responseData = response.data;
137
+ this.affiliateCampaignCode = responseData.affiliate_campaign_code || this.affiliateCampaignCode;
138
+ this.deviceId = responseData.device_id || this.deviceId;
322
139
  }
323
- });
140
+ else {
141
+ console.error('Failed to send system info. Status code:', response.status);
142
+ }
143
+ }
144
+ catch (e) {
145
+ console.error('Error sending system info to server:', e);
146
+ }
147
+ });
148
+ }
149
+ readAndroidDeviceInfo() {
150
+ return __awaiter(this, void 0, void 0, function* () {
151
+ return {
152
+ deviceId: yield react_native_device_info_1.default.getAndroidId(),
153
+ systemName: yield react_native_device_info_1.default.getSystemName(),
154
+ systemVersion: yield react_native_device_info_1.default.getSystemVersion(),
155
+ brand: yield react_native_device_info_1.default.getBrand(),
156
+ model: yield react_native_device_info_1.default.getModel(),
157
+ manufacturer: yield react_native_device_info_1.default.getManufacturer(),
158
+ isEmulator: yield react_native_device_info_1.default.isEmulator(),
159
+ uniqueId: yield react_native_device_info_1.default.getUniqueId(),
160
+ };
324
161
  });
325
- };
326
- GoMarketMe.prototype.getTimeZoneCode = function () {
327
- // Convert the time zone to GMT format (e.g., "GMT+2")
328
- var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
329
- var date = new Date();
330
- var timezoneOffset = date.getTimezoneOffset(); // in minutes
331
- var absOffset = Math.abs(timezoneOffset);
332
- var hours = Math.floor(absOffset / 60);
333
- var minutes = absOffset % 60;
334
- var sign = timezoneOffset > 0 ? '-' : '+';
335
- return "GMT".concat(sign).concat(String(hours).padStart(2, '0'), ":").concat(String(minutes).padStart(2, '0')); // Return GMT format
336
- };
337
- GoMarketMe.prototype.getLanguageCode = function () {
338
- var locales = RNLocalize.getLocales();
162
+ }
163
+ readIosDeviceInfo() {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ return {
166
+ deviceId: yield react_native_device_info_1.default.getUniqueId(),
167
+ systemName: yield react_native_device_info_1.default.getSystemName(),
168
+ systemVersion: yield react_native_device_info_1.default.getSystemVersion(),
169
+ brand: yield react_native_device_info_1.default.getBrand(),
170
+ model: yield react_native_device_info_1.default.getModel(),
171
+ manufacturer: yield react_native_device_info_1.default.getManufacturer(),
172
+ isEmulator: yield react_native_device_info_1.default.isEmulator(),
173
+ uniqueId: yield react_native_device_info_1.default.getUniqueId(),
174
+ };
175
+ });
176
+ }
177
+ getTimeZoneCode() {
178
+ const timezoneOffset = new Date().getTimezoneOffset();
179
+ const absOffset = Math.abs(timezoneOffset);
180
+ const hours = Math.floor(absOffset / 60);
181
+ const minutes = absOffset % 60;
182
+ const sign = timezoneOffset > 0 ? '-' : '+';
183
+ return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
184
+ }
185
+ getLanguageCode() {
186
+ const locales = RNLocalize.getLocales();
339
187
  return locales.length > 0 ? locales[0].languageTag : 'en-US';
340
- };
341
- GoMarketMe.prototype.fetchPurchases = function (purchaseDetailsList, apiKey) {
342
- return __awaiter(this, void 0, void 0, function () {
343
- var productIds, _i, purchaseDetailsList_1, purchase;
344
- return __generator(this, function (_a) {
345
- switch (_a.label) {
346
- case 0:
347
- productIds = [];
348
- _i = 0, purchaseDetailsList_1 = purchaseDetailsList;
349
- _a.label = 1;
350
- case 1:
351
- if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 4];
352
- purchase = purchaseDetailsList_1[_i];
353
- if (!purchase.transactionReceipt) return [3 /*break*/, 3];
354
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey)];
355
- case 2:
356
- _a.sent();
357
- if (purchase.productId && !productIds.includes(purchase.productId)) {
358
- productIds.push(purchase.productId);
359
- }
360
- _a.label = 3;
361
- case 3:
362
- _i++;
363
- return [3 /*break*/, 1];
364
- case 4: return [2 /*return*/, productIds];
188
+ }
189
+ fetchPurchases(purchaseDetailsList, apiKey) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const productIds = [];
192
+ for (const purchase of purchaseDetailsList) {
193
+ if (purchase.transactionReceipt) {
194
+ yield this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey);
195
+ if (purchase.productId && !productIds.includes(purchase.productId)) {
196
+ productIds.push(purchase.productId);
197
+ }
365
198
  }
366
- });
199
+ }
200
+ return productIds;
367
201
  });
368
- };
369
- GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
370
- return __awaiter(this, void 0, void 0, function () {
371
- var products, _i, products_1, product, e_4;
372
- return __generator(this, function (_a) {
373
- switch (_a.label) {
374
- case 0:
375
- _a.trys.push([0, 9, , 10]);
376
- return [4 /*yield*/, react_native_iap_1.default.getProducts({ skus: productIds })];
377
- case 1:
378
- products = _a.sent();
379
- if (!(products.length > 0)) return [3 /*break*/, 6];
380
- _i = 0, products_1 = products;
381
- _a.label = 2;
382
- case 2:
383
- if (!(_i < products_1.length)) return [3 /*break*/, 5];
384
- product = products_1[_i];
385
- return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
386
- case 3:
387
- _a.sent();
388
- _a.label = 4;
389
- case 4:
390
- _i++;
391
- return [3 /*break*/, 2];
392
- case 5: return [3 /*break*/, 8];
393
- case 6: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
394
- case 7:
395
- _a.sent();
396
- _a.label = 8;
397
- case 8: return [3 /*break*/, 10];
398
- case 9:
399
- e_4 = _a.sent();
400
- console.error('Error fetching products:', e_4);
401
- return [3 /*break*/, 10];
402
- case 10: return [2 /*return*/];
202
+ }
203
+ fetchPurchaseProducts(productIds, apiKey) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ try {
206
+ const products = yield react_native_iap_1.default.getProducts({ skus: productIds });
207
+ if (products.length > 0) {
208
+ for (const product of products) {
209
+ yield this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey);
210
+ }
403
211
  }
404
- });
212
+ else {
213
+ yield this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey);
214
+ }
215
+ }
216
+ catch (e) {
217
+ console.error('Error fetching products:', e);
218
+ }
405
219
  });
406
- };
407
- GoMarketMe.prototype.sendEventToServer = function (body, eventType, apiKey) {
408
- return __awaiter(this, void 0, void 0, function () {
409
- var response, e_5;
410
- return __generator(this, function (_a) {
411
- switch (_a.label) {
412
- case 0:
413
- _a.trys.push([0, 2, , 3]);
414
- return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
415
- headers: {
416
- 'Content-Type': 'application/json',
417
- 'x-affiliate-campaign-code': this.affiliateCampaignCode,
418
- 'x-device-id': this.deviceId,
419
- 'x-event-type': eventType,
420
- 'x-product-type': react_native_1.Platform.OS,
421
- 'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
422
- 'x-api-key': apiKey,
423
- },
424
- })];
425
- case 1:
426
- response = _a.sent();
427
- if (response.status === 200) {
428
- console.log("".concat(eventType, " sent successfully"));
429
- }
430
- else {
431
- console.error("Failed to send ".concat(eventType, ". Status code:"), response.status);
432
- }
433
- return [3 /*break*/, 3];
434
- case 2:
435
- e_5 = _a.sent();
436
- console.error("Error sending ".concat(eventType, " to server:"), e_5);
437
- return [3 /*break*/, 3];
438
- case 3: return [2 /*return*/];
220
+ }
221
+ sendEventToServer(body, eventType, apiKey) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ try {
224
+ const response = yield axios_1.default.post(this.eventUrl, body, {
225
+ headers: {
226
+ 'Content-Type': 'application/json',
227
+ 'x-affiliate-campaign-code': this.affiliateCampaignCode,
228
+ 'x-device-id': this.deviceId,
229
+ 'x-event-type': eventType,
230
+ 'x-product-type': react_native_1.Platform.OS,
231
+ 'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
232
+ 'x-api-key': apiKey,
233
+ },
234
+ });
235
+ if (response.status === 200) {
236
+ console.log(`${eventType} sent successfully`);
439
237
  }
440
- });
238
+ else {
239
+ console.error(`Failed to send ${eventType}. Status code:`, response.status);
240
+ }
241
+ }
242
+ catch (e) {
243
+ console.error(`Error sending ${eventType} to server:`, e);
244
+ }
441
245
  });
442
- };
443
- GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
246
+ }
247
+ serializePurchaseDetails(purchase) {
444
248
  return {
445
249
  productID: purchase.productId,
446
250
  purchaseID: purchase.transactionId || '',
447
251
  transactionDate: purchase.transactionDate || '',
448
252
  status: react_native_1.Platform.select({
449
- ios: purchase.transactionStateIOS, // Removed non-existent properties
253
+ ios: purchase.transactionStateIOS,
450
254
  android: purchase.purchaseStateAndroid,
451
255
  }),
452
256
  verificationData: {
453
257
  localVerificationData: purchase.transactionReceipt,
454
258
  },
455
259
  };
456
- };
457
- GoMarketMe.prototype.serializeProductDetails = function (product) {
260
+ }
261
+ serializeProductDetails(product) {
458
262
  return {
459
263
  productID: product.productId,
460
264
  productTitle: product.title,
461
- productDescription: product.description,
462
265
  productPrice: product.price,
463
- productRawPrice: product.price,
464
- productCurrencyCode: product.currency,
465
266
  };
466
- };
467
- GoMarketMe.prototype.markSDKAsInitialized = function () {
468
- return __awaiter(this, void 0, void 0, function () {
469
- var e_6;
470
- return __generator(this, function (_a) {
471
- switch (_a.label) {
472
- case 0:
473
- _a.trys.push([0, 2, , 3]);
474
- return [4 /*yield*/, async_storage_1.default.setItem(this.sdkInitializedKey, 'true')];
475
- case 1:
476
- _a.sent();
477
- return [2 /*return*/, true];
478
- case 2:
479
- e_6 = _a.sent();
480
- console.error('Failed to save SDK initialization:', e_6);
481
- return [2 /*return*/, false];
482
- case 3: return [2 /*return*/];
483
- }
484
- });
267
+ }
268
+ isSDKInitialized() {
269
+ return __awaiter(this, void 0, void 0, function* () {
270
+ const value = yield async_storage_1.default.getItem(this.sdkInitializedKey);
271
+ return value === 'true';
485
272
  });
486
- };
487
- GoMarketMe.prototype.isSDKInitialized = function () {
488
- return __awaiter(this, void 0, void 0, function () {
489
- var value, e_7;
490
- return __generator(this, function (_a) {
491
- switch (_a.label) {
492
- case 0:
493
- _a.trys.push([0, 2, , 3]);
494
- return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
495
- case 1:
496
- value = _a.sent();
497
- return [2 /*return*/, value === 'true'];
498
- case 2:
499
- e_7 = _a.sent();
500
- console.error('Failed to load SDK initialization:', e_7);
501
- return [2 /*return*/, false];
502
- case 3: return [2 /*return*/];
503
- }
504
- });
273
+ }
274
+ markSDKAsInitialized() {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ yield async_storage_1.default.setItem(this.sdkInitializedKey, 'true');
505
277
  });
506
- };
507
- return GoMarketMe;
508
- }());
278
+ }
279
+ }
509
280
  exports.default = GoMarketMe.getInstance();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gomarketme-react-native",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Affiliate Marketing for React Native-Based iOS and Android Apps.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,6 +17,8 @@
17
17
  "author": "GoMarketMe",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
+ "@babel/core": "^7.26.0",
21
+ "@babel/preset-env": "^7.26.0",
20
22
  "@react-native-async-storage/async-storage": "^2.0.0",
21
23
  "axios": "^1.7.7",
22
24
  "react-native": "^0.76.1",
@@ -25,6 +27,11 @@
25
27
  "react-native-localize": "^3.2.1"
26
28
  },
27
29
  "devDependencies": {
28
- "typescript": "^5.6.3"
30
+ "@types/node": "^15.12.5",
31
+ "@types/react-native": "^0.64.12",
32
+ "typescript": "^4.9.5"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "*"
29
36
  }
30
37
  }
package/src/index.tsx CHANGED
@@ -39,7 +39,7 @@ class GoMarketMe {
39
39
 
40
40
  private async addListener(apiKey: string): Promise<void> {
41
41
  InAppPurchase.purchaseUpdatedListener(async (purchase: Purchase) => {
42
- if (this.affiliateCampaignCode != '') {
42
+ if (this.affiliateCampaignCode) {
43
43
  const productIds = await this.fetchPurchases([purchase], apiKey);
44
44
  await this.fetchPurchaseProducts(productIds, apiKey);
45
45
  }
@@ -55,7 +55,7 @@ class GoMarketMe {
55
55
  const devicePixelRatio = PixelRatio.get();
56
56
 
57
57
  const windowData = {
58
- devicePixelRatio: devicePixelRatio,
58
+ devicePixelRatio,
59
59
  width: Dimensions.get('window').width * devicePixelRatio,
60
60
  height: Dimensions.get('window').height * devicePixelRatio,
61
61
  };
@@ -96,12 +96,8 @@ class GoMarketMe {
96
96
  });
97
97
  if (response.status === 200) {
98
98
  const responseData = response.data;
99
- if (responseData.affiliate_campaign_code) {
100
- this.affiliateCampaignCode = responseData.affiliate_campaign_code;
101
- }
102
- if (responseData.device_id) {
103
- this.deviceId = responseData.device_id;
104
- }
99
+ this.affiliateCampaignCode = responseData.affiliate_campaign_code || this.affiliateCampaignCode;
100
+ this.deviceId = responseData.device_id || this.deviceId;
105
101
  } else {
106
102
  console.error('Failed to send system info. Status code:', response.status);
107
103
  }
@@ -113,7 +109,6 @@ class GoMarketMe {
113
109
  private async readAndroidDeviceInfo(): Promise<any> {
114
110
  return {
115
111
  deviceId: await DeviceInfo.getAndroidId(),
116
- _deviceId: await DeviceInfo.getDeviceId(),
117
112
  systemName: await DeviceInfo.getSystemName(),
118
113
  systemVersion: await DeviceInfo.getSystemVersion(),
119
114
  brand: await DeviceInfo.getBrand(),
@@ -125,9 +120,8 @@ class GoMarketMe {
125
120
  }
126
121
 
127
122
  private async readIosDeviceInfo(): Promise<any> {
128
- var info = {
123
+ return {
129
124
  deviceId: await DeviceInfo.getUniqueId(),
130
- _deviceId: await DeviceInfo.getDeviceId(),
131
125
  systemName: await DeviceInfo.getSystemName(),
132
126
  systemVersion: await DeviceInfo.getSystemVersion(),
133
127
  brand: await DeviceInfo.getBrand(),
@@ -139,15 +133,12 @@ class GoMarketMe {
139
133
  }
140
134
 
141
135
  private getTimeZoneCode(): string {
142
- // Convert the time zone to GMT format (e.g., "GMT+2")
143
- const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
144
- const date = new Date();
145
- const timezoneOffset = date.getTimezoneOffset(); // in minutes
136
+ const timezoneOffset = new Date().getTimezoneOffset();
146
137
  const absOffset = Math.abs(timezoneOffset);
147
138
  const hours = Math.floor(absOffset / 60);
148
139
  const minutes = absOffset % 60;
149
140
  const sign = timezoneOffset > 0 ? '-' : '+';
150
- return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`; // Return GMT format
141
+ return `GMT${sign}${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}`;
151
142
  }
152
143
 
153
144
  private getLanguageCode(): string {
@@ -212,7 +203,7 @@ class GoMarketMe {
212
203
  purchaseID: purchase.transactionId || '',
213
204
  transactionDate: purchase.transactionDate || '',
214
205
  status: Platform.select({
215
- ios: (purchase as any).transactionStateIOS, // Removed non-existent properties
206
+ ios: (purchase as any).transactionStateIOS,
216
207
  android: (purchase as any).purchaseStateAndroid,
217
208
  }),
218
209
  verificationData: {
@@ -225,31 +216,17 @@ class GoMarketMe {
225
216
  return {
226
217
  productID: product.productId,
227
218
  productTitle: product.title,
228
- productDescription: product.description,
229
219
  productPrice: product.price,
230
- productRawPrice: product.price,
231
- productCurrencyCode: product.currency,
232
220
  };
233
221
  }
234
222
 
235
- private async markSDKAsInitialized(): Promise<boolean> {
236
- try {
237
- await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
238
- return true;
239
- } catch (e) {
240
- console.error('Failed to save SDK initialization:', e);
241
- return false;
242
- }
223
+ private async isSDKInitialized(): Promise<boolean> {
224
+ const value = await AsyncStorage.getItem(this.sdkInitializedKey);
225
+ return value === 'true';
243
226
  }
244
227
 
245
- private async isSDKInitialized(): Promise<boolean> {
246
- try {
247
- const value = await AsyncStorage.getItem(this.sdkInitializedKey);
248
- return value === 'true';
249
- } catch (e) {
250
- console.error('Failed to load SDK initialization:', e);
251
- return false;
252
- }
228
+ private async markSDKAsInitialized(): Promise<void> {
229
+ await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
253
230
  }
254
231
  }
255
232
 
package/tsconfig.json CHANGED
@@ -1,19 +1,17 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "ES5",
4
- "module": "commonjs",
5
- "lib": ["es6", "dom"],
6
- "allowJs": true,
7
- "jsx": "react",
3
+ "outDir": "./dist",
8
4
  "declaration": true,
5
+ "emitDeclarationOnly": false,
6
+ "declarationMap": true,
7
+ "declarationDir": "./dist",
8
+ "allowJs": true,
9
+ "target": "ES6",
10
+ "module": "CommonJS",
9
11
  "strict": true,
10
12
  "esModuleInterop": true,
11
13
  "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "moduleResolution": "node",
14
- "outDir": "./dist",
15
- "rootDir": "./src"
14
+ "forceConsistentCasingInFileNames": true
16
15
  },
17
- "include": ["src/**/*.ts", "src/**/*.tsx"],
18
- "exclude": ["node_modules", "dist", "**/__tests__/*"]
16
+ "include": ["src/**/*"]
19
17
  }