gomarketme-react-native 1.0.11 → 1.0.12
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/package.json +8 -8
- package/src/index.tsx +7 -9
- package/dist/index.js +0 -475
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gomarketme-react-native",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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,19 +17,19 @@
|
|
|
17
17
|
"author": "GoMarketMe",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@react-native-async-storage/async-storage": "^
|
|
21
|
-
"axios": "^
|
|
22
|
-
"react-native": "^0.
|
|
23
|
-
"react-native-
|
|
24
|
-
"react-native-iap": "^12.15.6",
|
|
20
|
+
"@react-native-async-storage/async-storage": "^1.15.6",
|
|
21
|
+
"axios": "^0.21.1",
|
|
22
|
+
"react-native-device-info": "^8.0.1",
|
|
23
|
+
"react-native-iap": "^7.0.0",
|
|
25
24
|
"react-native-localize": "^3.2.1"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/node": "^15.12.5",
|
|
29
28
|
"@types/react-native": "^0.64.12",
|
|
30
|
-
"typescript": "^4.
|
|
29
|
+
"typescript": "^4.3.5"
|
|
31
30
|
},
|
|
32
31
|
"peerDependencies": {
|
|
33
|
-
"react": "*"
|
|
32
|
+
"react": "*",
|
|
33
|
+
"react-native": "*"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Platform, Dimensions, PixelRatio } from 'react-native';
|
|
2
2
|
import DeviceInfo from 'react-native-device-info';
|
|
3
3
|
import * as RNLocalize from 'react-native-localize';
|
|
4
|
-
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
5
4
|
import InAppPurchase, { Purchase, Product } from 'react-native-iap';
|
|
6
5
|
import axios from 'axios';
|
|
7
6
|
|
|
@@ -25,7 +24,7 @@ class GoMarketMe {
|
|
|
25
24
|
|
|
26
25
|
public async initialize(apiKey: string): Promise<void> {
|
|
27
26
|
try {
|
|
28
|
-
const isSDKInitialized =
|
|
27
|
+
const isSDKInitialized = this.isSDKInitialized();
|
|
29
28
|
if (!isSDKInitialized) {
|
|
30
29
|
await this.postSDKInitialization(apiKey);
|
|
31
30
|
}
|
|
@@ -77,7 +76,7 @@ class GoMarketMe {
|
|
|
77
76
|
},
|
|
78
77
|
});
|
|
79
78
|
if (response.status === 200) {
|
|
80
|
-
|
|
79
|
+
this.markSDKAsInitialized();
|
|
81
80
|
} else {
|
|
82
81
|
console.error('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
83
82
|
}
|
|
@@ -161,7 +160,7 @@ class GoMarketMe {
|
|
|
161
160
|
|
|
162
161
|
private async fetchPurchaseProducts(productIds: string[], apiKey: string): Promise<void> {
|
|
163
162
|
try {
|
|
164
|
-
const products = await InAppPurchase.getProducts(
|
|
163
|
+
const products = await InAppPurchase.getProducts(productIds);
|
|
165
164
|
if (products.length > 0) {
|
|
166
165
|
for (const product of products) {
|
|
167
166
|
await this.sendEventToServer(JSON.stringify(this.serializeProductDetails(product)), 'product', apiKey);
|
|
@@ -220,13 +219,12 @@ class GoMarketMe {
|
|
|
220
219
|
};
|
|
221
220
|
}
|
|
222
221
|
|
|
223
|
-
private
|
|
224
|
-
|
|
225
|
-
return value === 'true';
|
|
222
|
+
private isSDKInitialized(): boolean {
|
|
223
|
+
return false;
|
|
226
224
|
}
|
|
227
225
|
|
|
228
|
-
private
|
|
229
|
-
|
|
226
|
+
private markSDKAsInitialized(): boolean {
|
|
227
|
+
return true;
|
|
230
228
|
}
|
|
231
229
|
}
|
|
232
230
|
|
package/dist/index.js
DELETED
|
@@ -1,475 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
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
|
-
};
|
|
61
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
62
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
63
|
-
};
|
|
64
|
-
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() {
|
|
73
|
-
this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
74
|
-
this.affiliateCampaignCode = '';
|
|
75
|
-
this.deviceId = '';
|
|
76
|
-
this.sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
|
|
77
|
-
this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
|
|
78
|
-
this.eventUrl = 'https://api.gomarketme.net/v1/event';
|
|
79
|
-
}
|
|
80
|
-
GoMarketMe.getInstance = function () {
|
|
81
|
-
if (!GoMarketMe.instance) {
|
|
82
|
-
GoMarketMe.instance = new GoMarketMe();
|
|
83
|
-
}
|
|
84
|
-
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*/];
|
|
116
|
-
}
|
|
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
|
-
});
|
|
143
|
-
});
|
|
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
|
-
}];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
});
|
|
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
|
-
}
|
|
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*/];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
});
|
|
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
|
-
});
|
|
276
|
-
});
|
|
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
|
-
});
|
|
311
|
-
});
|
|
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();
|
|
323
|
-
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
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];
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
});
|
|
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*/];
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
});
|
|
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*/];
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
};
|
|
427
|
-
GoMarketMe.prototype.serializePurchaseDetails = function (purchase) {
|
|
428
|
-
return {
|
|
429
|
-
productID: purchase.productId,
|
|
430
|
-
purchaseID: purchase.transactionId || '',
|
|
431
|
-
transactionDate: purchase.transactionDate || '',
|
|
432
|
-
status: react_native_1.Platform.select({
|
|
433
|
-
ios: purchase.transactionStateIOS,
|
|
434
|
-
android: purchase.purchaseStateAndroid,
|
|
435
|
-
}),
|
|
436
|
-
verificationData: {
|
|
437
|
-
localVerificationData: purchase.transactionReceipt,
|
|
438
|
-
},
|
|
439
|
-
};
|
|
440
|
-
};
|
|
441
|
-
GoMarketMe.prototype.serializeProductDetails = function (product) {
|
|
442
|
-
return {
|
|
443
|
-
productID: product.productId,
|
|
444
|
-
productTitle: product.title,
|
|
445
|
-
productPrice: product.price,
|
|
446
|
-
};
|
|
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
|
-
});
|
|
459
|
-
});
|
|
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
|
-
});
|
|
471
|
-
});
|
|
472
|
-
};
|
|
473
|
-
return GoMarketMe;
|
|
474
|
-
}());
|
|
475
|
-
exports.default = GoMarketMe.getInstance();
|