gomarketme-react-native 1.0.9 → 1.0.11
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 +389 -194
- package/package.json +1 -3
- package/tsconfig.json +12 -10
package/dist/index.js
CHANGED
|
@@ -31,18 +31,45 @@ 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;
|
|
36
|
+
return g = { next: verb(0), "throw": verb(1), "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
|
+
};
|
|
34
61
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
63
|
};
|
|
37
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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() {
|
|
46
73
|
this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
47
74
|
this.affiliateCampaignCode = '';
|
|
48
75
|
this.deviceId = '';
|
|
@@ -50,201 +77,354 @@ class GoMarketMe {
|
|
|
50
77
|
this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
|
|
51
78
|
this.eventUrl = 'https://api.gomarketme.net/v1/event';
|
|
52
79
|
}
|
|
53
|
-
|
|
80
|
+
GoMarketMe.getInstance = function () {
|
|
54
81
|
if (!GoMarketMe.instance) {
|
|
55
82
|
GoMarketMe.instance = new GoMarketMe();
|
|
56
83
|
}
|
|
57
84
|
return GoMarketMe.instance;
|
|
58
|
-
}
|
|
59
|
-
initialize(apiKey) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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*/];
|
|
65
116
|
}
|
|
66
|
-
|
|
67
|
-
yield this.postSystemInfo(systemInfo, apiKey);
|
|
68
|
-
yield this.addListener(apiKey);
|
|
69
|
-
}
|
|
70
|
-
catch (e) {
|
|
71
|
-
console.error('Error initializing GoMarketMe:', e);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
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);
|
|
81
|
-
}
|
|
82
|
-
}));
|
|
117
|
+
});
|
|
83
118
|
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return __awaiter(this, void 0, void 0, function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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*/];
|
|
90
142
|
});
|
|
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
|
-
};
|
|
103
143
|
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return __awaiter(this, void 0, void 0, function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
+
}];
|
|
119
173
|
}
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
console.error('Error sending SDK information to server:', e);
|
|
123
|
-
}
|
|
174
|
+
});
|
|
124
175
|
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return __awaiter(this, void 0, void 0, function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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*/];
|
|
139
206
|
}
|
|
140
|
-
|
|
141
|
-
|
|
207
|
+
});
|
|
208
|
+
});
|
|
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
|
+
this.affiliateCampaignCode = responseData.affiliate_campaign_code || this.affiliateCampaignCode;
|
|
228
|
+
this.deviceId = responseData.device_id || this.deviceId;
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
console.error('Failed to send system info. Status code:', response.status);
|
|
232
|
+
}
|
|
233
|
+
return [3 /*break*/, 3];
|
|
234
|
+
case 2:
|
|
235
|
+
e_3 = _a.sent();
|
|
236
|
+
console.error('Error sending system info to server:', e_3);
|
|
237
|
+
return [3 /*break*/, 3];
|
|
238
|
+
case 3: return [2 /*return*/];
|
|
142
239
|
}
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
console.error('Error sending system info to server:', e);
|
|
146
|
-
}
|
|
240
|
+
});
|
|
147
241
|
});
|
|
148
|
-
}
|
|
149
|
-
readAndroidDeviceInfo() {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
242
|
+
};
|
|
243
|
+
GoMarketMe.prototype.readAndroidDeviceInfo = function () {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var _a;
|
|
246
|
+
return __generator(this, function (_b) {
|
|
247
|
+
switch (_b.label) {
|
|
248
|
+
case 0:
|
|
249
|
+
_a = {};
|
|
250
|
+
return [4 /*yield*/, react_native_device_info_1.default.getAndroidId()];
|
|
251
|
+
case 1:
|
|
252
|
+
_a.deviceId = _b.sent();
|
|
253
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
|
|
254
|
+
case 2:
|
|
255
|
+
_a.systemName = _b.sent();
|
|
256
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
|
|
257
|
+
case 3:
|
|
258
|
+
_a.systemVersion = _b.sent();
|
|
259
|
+
return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
|
|
260
|
+
case 4:
|
|
261
|
+
_a.brand = _b.sent();
|
|
262
|
+
return [4 /*yield*/, react_native_device_info_1.default.getModel()];
|
|
263
|
+
case 5:
|
|
264
|
+
_a.model = _b.sent();
|
|
265
|
+
return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
|
|
266
|
+
case 6:
|
|
267
|
+
_a.manufacturer = _b.sent();
|
|
268
|
+
return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
|
|
269
|
+
case 7:
|
|
270
|
+
_a.isEmulator = _b.sent();
|
|
271
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
272
|
+
case 8: return [2 /*return*/, (_a.uniqueId = _b.sent(),
|
|
273
|
+
_a)];
|
|
274
|
+
}
|
|
275
|
+
});
|
|
161
276
|
});
|
|
162
|
-
}
|
|
163
|
-
readIosDeviceInfo() {
|
|
164
|
-
return __awaiter(this, void 0, void 0, function
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
277
|
+
};
|
|
278
|
+
GoMarketMe.prototype.readIosDeviceInfo = function () {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
280
|
+
var _a;
|
|
281
|
+
return __generator(this, function (_b) {
|
|
282
|
+
switch (_b.label) {
|
|
283
|
+
case 0:
|
|
284
|
+
_a = {};
|
|
285
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
286
|
+
case 1:
|
|
287
|
+
_a.deviceId = _b.sent();
|
|
288
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemName()];
|
|
289
|
+
case 2:
|
|
290
|
+
_a.systemName = _b.sent();
|
|
291
|
+
return [4 /*yield*/, react_native_device_info_1.default.getSystemVersion()];
|
|
292
|
+
case 3:
|
|
293
|
+
_a.systemVersion = _b.sent();
|
|
294
|
+
return [4 /*yield*/, react_native_device_info_1.default.getBrand()];
|
|
295
|
+
case 4:
|
|
296
|
+
_a.brand = _b.sent();
|
|
297
|
+
return [4 /*yield*/, react_native_device_info_1.default.getModel()];
|
|
298
|
+
case 5:
|
|
299
|
+
_a.model = _b.sent();
|
|
300
|
+
return [4 /*yield*/, react_native_device_info_1.default.getManufacturer()];
|
|
301
|
+
case 6:
|
|
302
|
+
_a.manufacturer = _b.sent();
|
|
303
|
+
return [4 /*yield*/, react_native_device_info_1.default.isEmulator()];
|
|
304
|
+
case 7:
|
|
305
|
+
_a.isEmulator = _b.sent();
|
|
306
|
+
return [4 /*yield*/, react_native_device_info_1.default.getUniqueId()];
|
|
307
|
+
case 8: return [2 /*return*/, (_a.uniqueId = _b.sent(),
|
|
308
|
+
_a)];
|
|
309
|
+
}
|
|
310
|
+
});
|
|
175
311
|
});
|
|
176
|
-
}
|
|
177
|
-
getTimeZoneCode() {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
getLanguageCode() {
|
|
186
|
-
|
|
312
|
+
};
|
|
313
|
+
GoMarketMe.prototype.getTimeZoneCode = function () {
|
|
314
|
+
var timezoneOffset = new Date().getTimezoneOffset();
|
|
315
|
+
var absOffset = Math.abs(timezoneOffset);
|
|
316
|
+
var hours = Math.floor(absOffset / 60);
|
|
317
|
+
var minutes = absOffset % 60;
|
|
318
|
+
var sign = timezoneOffset > 0 ? '-' : '+';
|
|
319
|
+
return "GMT".concat(sign).concat(String(hours).padStart(2, '0'), ":").concat(String(minutes).padStart(2, '0'));
|
|
320
|
+
};
|
|
321
|
+
GoMarketMe.prototype.getLanguageCode = function () {
|
|
322
|
+
var locales = RNLocalize.getLocales();
|
|
187
323
|
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
188
|
-
}
|
|
189
|
-
fetchPurchases(purchaseDetailsList, apiKey) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
324
|
+
};
|
|
325
|
+
GoMarketMe.prototype.fetchPurchases = function (purchaseDetailsList, apiKey) {
|
|
326
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
327
|
+
var productIds, _i, purchaseDetailsList_1, purchase;
|
|
328
|
+
return __generator(this, function (_a) {
|
|
329
|
+
switch (_a.label) {
|
|
330
|
+
case 0:
|
|
331
|
+
productIds = [];
|
|
332
|
+
_i = 0, purchaseDetailsList_1 = purchaseDetailsList;
|
|
333
|
+
_a.label = 1;
|
|
334
|
+
case 1:
|
|
335
|
+
if (!(_i < purchaseDetailsList_1.length)) return [3 /*break*/, 4];
|
|
336
|
+
purchase = purchaseDetailsList_1[_i];
|
|
337
|
+
if (!purchase.transactionReceipt) return [3 /*break*/, 3];
|
|
338
|
+
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializePurchaseDetails(purchase)), 'purchase', apiKey)];
|
|
339
|
+
case 2:
|
|
340
|
+
_a.sent();
|
|
341
|
+
if (purchase.productId && !productIds.includes(purchase.productId)) {
|
|
342
|
+
productIds.push(purchase.productId);
|
|
343
|
+
}
|
|
344
|
+
_a.label = 3;
|
|
345
|
+
case 3:
|
|
346
|
+
_i++;
|
|
347
|
+
return [3 /*break*/, 1];
|
|
348
|
+
case 4: return [2 /*return*/, productIds];
|
|
198
349
|
}
|
|
199
|
-
}
|
|
200
|
-
return productIds;
|
|
350
|
+
});
|
|
201
351
|
});
|
|
202
|
-
}
|
|
203
|
-
fetchPurchaseProducts(productIds, apiKey) {
|
|
204
|
-
return __awaiter(this, void 0, void 0, function
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
352
|
+
};
|
|
353
|
+
GoMarketMe.prototype.fetchPurchaseProducts = function (productIds, apiKey) {
|
|
354
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
355
|
+
var products, _i, products_1, product, e_4;
|
|
356
|
+
return __generator(this, function (_a) {
|
|
357
|
+
switch (_a.label) {
|
|
358
|
+
case 0:
|
|
359
|
+
_a.trys.push([0, 9, , 10]);
|
|
360
|
+
return [4 /*yield*/, react_native_iap_1.default.getProducts({ skus: productIds })];
|
|
361
|
+
case 1:
|
|
362
|
+
products = _a.sent();
|
|
363
|
+
if (!(products.length > 0)) return [3 /*break*/, 6];
|
|
364
|
+
_i = 0, products_1 = products;
|
|
365
|
+
_a.label = 2;
|
|
366
|
+
case 2:
|
|
367
|
+
if (!(_i < products_1.length)) return [3 /*break*/, 5];
|
|
368
|
+
product = products_1[_i];
|
|
369
|
+
return [4 /*yield*/, this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey)];
|
|
370
|
+
case 3:
|
|
371
|
+
_a.sent();
|
|
372
|
+
_a.label = 4;
|
|
373
|
+
case 4:
|
|
374
|
+
_i++;
|
|
375
|
+
return [3 /*break*/, 2];
|
|
376
|
+
case 5: return [3 /*break*/, 8];
|
|
377
|
+
case 6: return [4 /*yield*/, this.sendEventToServer(JSON.stringify({ notFoundIDs: productIds.join(',') }), 'product', apiKey)];
|
|
378
|
+
case 7:
|
|
379
|
+
_a.sent();
|
|
380
|
+
_a.label = 8;
|
|
381
|
+
case 8: return [3 /*break*/, 10];
|
|
382
|
+
case 9:
|
|
383
|
+
e_4 = _a.sent();
|
|
384
|
+
console.error('Error fetching products:', e_4);
|
|
385
|
+
return [3 /*break*/, 10];
|
|
386
|
+
case 10: return [2 /*return*/];
|
|
214
387
|
}
|
|
215
|
-
}
|
|
216
|
-
catch (e) {
|
|
217
|
-
console.error('Error fetching products:', e);
|
|
218
|
-
}
|
|
388
|
+
});
|
|
219
389
|
});
|
|
220
|
-
}
|
|
221
|
-
sendEventToServer(body, eventType, apiKey) {
|
|
222
|
-
return __awaiter(this, void 0, void 0, function
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
390
|
+
};
|
|
391
|
+
GoMarketMe.prototype.sendEventToServer = function (body, eventType, apiKey) {
|
|
392
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
393
|
+
var response, e_5;
|
|
394
|
+
return __generator(this, function (_a) {
|
|
395
|
+
switch (_a.label) {
|
|
396
|
+
case 0:
|
|
397
|
+
_a.trys.push([0, 2, , 3]);
|
|
398
|
+
return [4 /*yield*/, axios_1.default.post(this.eventUrl, body, {
|
|
399
|
+
headers: {
|
|
400
|
+
'Content-Type': 'application/json',
|
|
401
|
+
'x-affiliate-campaign-code': this.affiliateCampaignCode,
|
|
402
|
+
'x-device-id': this.deviceId,
|
|
403
|
+
'x-event-type': eventType,
|
|
404
|
+
'x-product-type': react_native_1.Platform.OS,
|
|
405
|
+
'x-source-name': react_native_1.Platform.OS === 'android' ? 'google_play' : 'app_store',
|
|
406
|
+
'x-api-key': apiKey,
|
|
407
|
+
},
|
|
408
|
+
})];
|
|
409
|
+
case 1:
|
|
410
|
+
response = _a.sent();
|
|
411
|
+
if (response.status === 200) {
|
|
412
|
+
console.log("".concat(eventType, " sent successfully"));
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
console.error("Failed to send ".concat(eventType, ". Status code:"), response.status);
|
|
416
|
+
}
|
|
417
|
+
return [3 /*break*/, 3];
|
|
418
|
+
case 2:
|
|
419
|
+
e_5 = _a.sent();
|
|
420
|
+
console.error("Error sending ".concat(eventType, " to server:"), e_5);
|
|
421
|
+
return [3 /*break*/, 3];
|
|
422
|
+
case 3: return [2 /*return*/];
|
|
237
423
|
}
|
|
238
|
-
|
|
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
|
-
}
|
|
424
|
+
});
|
|
245
425
|
});
|
|
246
|
-
}
|
|
247
|
-
serializePurchaseDetails(purchase) {
|
|
426
|
+
};
|
|
427
|
+
GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
|
|
248
428
|
return {
|
|
249
429
|
productID: purchase.productId,
|
|
250
430
|
purchaseID: purchase.transactionId || '',
|
|
@@ -257,24 +437,39 @@ class GoMarketMe {
|
|
|
257
437
|
localVerificationData: purchase.transactionReceipt,
|
|
258
438
|
},
|
|
259
439
|
};
|
|
260
|
-
}
|
|
261
|
-
serializeProductDetails(product) {
|
|
440
|
+
};
|
|
441
|
+
GoMarketMe.prototype.serializeProductDetails = function (product) {
|
|
262
442
|
return {
|
|
263
443
|
productID: product.productId,
|
|
264
444
|
productTitle: product.title,
|
|
265
445
|
productPrice: product.price,
|
|
266
446
|
};
|
|
267
|
-
}
|
|
268
|
-
isSDKInitialized() {
|
|
269
|
-
return __awaiter(this, void 0, void 0, function
|
|
270
|
-
|
|
271
|
-
return
|
|
447
|
+
};
|
|
448
|
+
GoMarketMe.prototype.isSDKInitialized = function () {
|
|
449
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
450
|
+
var value;
|
|
451
|
+
return __generator(this, function (_a) {
|
|
452
|
+
switch (_a.label) {
|
|
453
|
+
case 0: return [4 /*yield*/, async_storage_1.default.getItem(this.sdkInitializedKey)];
|
|
454
|
+
case 1:
|
|
455
|
+
value = _a.sent();
|
|
456
|
+
return [2 /*return*/, value === 'true'];
|
|
457
|
+
}
|
|
458
|
+
});
|
|
272
459
|
});
|
|
273
|
-
}
|
|
274
|
-
markSDKAsInitialized() {
|
|
275
|
-
return __awaiter(this, void 0, void 0, function
|
|
276
|
-
|
|
460
|
+
};
|
|
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
|
+
});
|
|
277
471
|
});
|
|
278
|
-
}
|
|
279
|
-
|
|
472
|
+
};
|
|
473
|
+
return GoMarketMe;
|
|
474
|
+
}());
|
|
280
475
|
exports.default = GoMarketMe.getInstance();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gomarketme-react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
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,8 +17,6 @@
|
|
|
17
17
|
"author": "GoMarketMe",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@babel/core": "^7.26.0",
|
|
21
|
-
"@babel/preset-env": "^7.26.0",
|
|
22
20
|
"@react-native-async-storage/async-storage": "^2.0.0",
|
|
23
21
|
"axios": "^1.7.7",
|
|
24
22
|
"react-native": "^0.76.1",
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"declarationDir": "./dist",
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["es6", "dom"],
|
|
8
6
|
"allowJs": true,
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"jsx": "react",
|
|
8
|
+
"declaration": true,
|
|
11
9
|
"strict": true,
|
|
12
10
|
"esModuleInterop": true,
|
|
13
11
|
"skipLibCheck": true,
|
|
14
|
-
"forceConsistentCasingInFileNames": true
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"moduleResolution": "node",
|
|
14
|
+
"outDir": "./dist",
|
|
15
|
+
"rootDir": "./src"
|
|
15
16
|
},
|
|
16
|
-
"include": ["src
|
|
17
|
-
|
|
17
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
18
|
+
"exclude": ["node_modules", "dist", "**/__tests__/*"]
|
|
19
|
+
}
|