gomarketme-react-native 1.0.10 → 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 -12
- package/src/index.tsx +7 -9
- package/tsconfig.json +12 -10
- package/dist/index.js +0 -280
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,23 +17,19 @@
|
|
|
17
17
|
"author": "GoMarketMe",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"react-native": "^0.76.1",
|
|
25
|
-
"react-native-device-info": "^14.0.0",
|
|
26
|
-
"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",
|
|
27
24
|
"react-native-localize": "^3.2.1"
|
|
28
25
|
},
|
|
29
26
|
"devDependencies": {
|
|
30
27
|
"@types/node": "^15.12.5",
|
|
31
28
|
"@types/react-native": "^0.64.12",
|
|
32
|
-
"typescript": "^4.
|
|
29
|
+
"typescript": "^4.3.5"
|
|
33
30
|
},
|
|
34
31
|
"peerDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"react": "*"
|
|
32
|
+
"react": "*",
|
|
33
|
+
"react-native": "*"
|
|
38
34
|
}
|
|
39
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/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
|
+
}
|
package/dist/index.js
DELETED
|
@@ -1,280 +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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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() {
|
|
46
|
-
this.sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
|
|
47
|
-
this.affiliateCampaignCode = '';
|
|
48
|
-
this.deviceId = '';
|
|
49
|
-
this.sdkInitializationUrl = 'https://api.gomarketme.net/v1/sdk-initialization';
|
|
50
|
-
this.systemInfoUrl = 'https://api.gomarketme.net/v1/mobile/system-info';
|
|
51
|
-
this.eventUrl = 'https://api.gomarketme.net/v1/event';
|
|
52
|
-
}
|
|
53
|
-
static getInstance() {
|
|
54
|
-
if (!GoMarketMe.instance) {
|
|
55
|
-
GoMarketMe.instance = new GoMarketMe();
|
|
56
|
-
}
|
|
57
|
-
return GoMarketMe.instance;
|
|
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);
|
|
65
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}));
|
|
83
|
-
});
|
|
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(),
|
|
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
|
-
};
|
|
103
|
-
});
|
|
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();
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
console.error('Failed to mark SDK as Initialized. Status code:', response.status);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
console.error('Error sending SDK information to server:', e);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
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;
|
|
139
|
-
}
|
|
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
|
-
};
|
|
161
|
-
});
|
|
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();
|
|
187
|
-
return locales.length > 0 ? locales[0].languageTag : 'en-US';
|
|
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
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return productIds;
|
|
201
|
-
});
|
|
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
|
-
}
|
|
211
|
-
}
|
|
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
|
-
}
|
|
219
|
-
});
|
|
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`);
|
|
237
|
-
}
|
|
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
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
serializePurchaseDetails(purchase) {
|
|
248
|
-
return {
|
|
249
|
-
productID: purchase.productId,
|
|
250
|
-
purchaseID: purchase.transactionId || '',
|
|
251
|
-
transactionDate: purchase.transactionDate || '',
|
|
252
|
-
status: react_native_1.Platform.select({
|
|
253
|
-
ios: purchase.transactionStateIOS,
|
|
254
|
-
android: purchase.purchaseStateAndroid,
|
|
255
|
-
}),
|
|
256
|
-
verificationData: {
|
|
257
|
-
localVerificationData: purchase.transactionReceipt,
|
|
258
|
-
},
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
serializeProductDetails(product) {
|
|
262
|
-
return {
|
|
263
|
-
productID: product.productId,
|
|
264
|
-
productTitle: product.title,
|
|
265
|
-
productPrice: product.price,
|
|
266
|
-
};
|
|
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';
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
markSDKAsInitialized() {
|
|
275
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
-
yield async_storage_1.default.setItem(this.sdkInitializedKey, 'true');
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
exports.default = GoMarketMe.getInstance();
|