gomarketme-react-native 4.0.0 → 4.0.1

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/.yarnrc.yml DELETED
@@ -1,5 +0,0 @@
1
- nmHoistingLimits: workspaces
2
-
3
- nodeLinker: node-modules
4
-
5
- yarnPath: .yarn/releases/yarn-4.3.1-git.20240705.hash-35167b2.cjs
package/lefthook.yml DELETED
@@ -1,35 +0,0 @@
1
- # EXAMPLE USAGE:
2
- #
3
- # Refer for explanation to following link:
4
- # https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
5
- #
6
- # pre-push:
7
- # commands:
8
- # packages-audit:
9
- # tags: frontend security
10
- # run: yarn audit
11
- # gems-audit:
12
- # tags: backend security
13
- # run: bundle audit
14
- #
15
- # pre-commit:
16
- # parallel: true
17
- # commands:
18
- # eslint:
19
- # glob: "*.{js,ts,jsx,tsx}"
20
- # run: yarn eslint {staged_files}
21
- # rubocop:
22
- # tags: backend style
23
- # glob: "*.rb"
24
- # exclude: '(^|/)(application|routes)\.rb$'
25
- # run: bundle exec rubocop --force-exclusion {all_files}
26
- # govet:
27
- # tags: backend style
28
- # files: git ls-files -m
29
- # glob: "*.go"
30
- # run: go vet {files}
31
- # scripts:
32
- # "hello.js":
33
- # runner: node
34
- # "any.go":
35
- # runner: go run
package/src/index.tsx DELETED
@@ -1,392 +0,0 @@
1
- import { Platform, Dimensions, PixelRatio } from 'react-native';
2
- import DeviceInfo from 'react-native-device-info';
3
- import getUserLocale from 'get-user-locale';
4
- import AsyncStorage from '@react-native-async-storage/async-storage';
5
- import axios from 'axios';
6
-
7
- import {
8
- type Purchase,
9
- type PurchaseError,
10
- purchaseUpdatedListener,
11
- purchaseErrorListener,
12
- fetchProducts,
13
- ProductCommon,
14
- PurchaseCommon,
15
- getAvailablePurchases,
16
- } from 'react-native-iap';
17
-
18
- export class GoMarketMeAffiliateMarketingData {
19
- campaign: Campaign;
20
- affiliate: Affiliate;
21
- saleDistribution: SaleDistribution;
22
- affiliateCampaignCode: string;
23
- deviceId: string;
24
- offerCode?: string;
25
-
26
- constructor(
27
- campaign: Campaign,
28
- affiliate: Affiliate,
29
- saleDistribution: SaleDistribution,
30
- affiliateCampaignCode: string,
31
- deviceId: string,
32
- offerCode?: string
33
- ) {
34
- this.campaign = campaign;
35
- this.affiliate = affiliate;
36
- this.saleDistribution = saleDistribution;
37
- this.affiliateCampaignCode = affiliateCampaignCode;
38
- this.deviceId = deviceId;
39
- this.offerCode = offerCode;
40
- }
41
-
42
- static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null {
43
- if (!json || Object.keys(json).length === 0) return null;
44
- return new GoMarketMeAffiliateMarketingData(
45
- Campaign.fromJson(json.campaign),
46
- Affiliate.fromJson(json.affiliate),
47
- SaleDistribution.fromJson(json.sale_distribution),
48
- json.affiliate_campaign_code || '',
49
- json.device_id || '',
50
- json.offer_code
51
- );
52
- }
53
- }
54
-
55
- export class Campaign {
56
- id: string;
57
- name: string;
58
- status: string;
59
- type: string;
60
- publicLinkUrl?: string;
61
-
62
- constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string) {
63
- this.id = id;
64
- this.name = name;
65
- this.status = status;
66
- this.type = type;
67
- this.publicLinkUrl = publicLinkUrl;
68
- }
69
-
70
- static fromJson(json: Record<string, any>): Campaign {
71
- return new Campaign(
72
- json?.id || '',
73
- json?.name || '',
74
- json?.status || '',
75
- json?.type || '',
76
- json?.public_link_url
77
- );
78
- }
79
- }
80
-
81
- export class Affiliate {
82
- id: string;
83
- firstName: string;
84
- lastName: string;
85
- countryCode: string;
86
- instagramAccount: string;
87
- tiktokAccount: string;
88
- xAccount: string;
89
-
90
- constructor(
91
- id: string,
92
- firstName: string,
93
- lastName: string,
94
- countryCode: string,
95
- instagramAccount: string,
96
- tiktokAccount: string,
97
- xAccount: string
98
- ) {
99
- this.id = id;
100
- this.firstName = firstName;
101
- this.lastName = lastName;
102
- this.countryCode = countryCode;
103
- this.instagramAccount = instagramAccount;
104
- this.tiktokAccount = tiktokAccount;
105
- this.xAccount = xAccount;
106
- }
107
-
108
- static fromJson(json: Record<string, any>): Affiliate {
109
- return new Affiliate(
110
- json?.id || '',
111
- json?.first_name || '',
112
- json?.last_name || '',
113
- json?.country_code || '',
114
- json?.instagram_account || '',
115
- json?.tiktok_account || '',
116
- json?.x_account || ''
117
- );
118
- }
119
- }
120
-
121
- export class SaleDistribution {
122
- platformPercentage: string;
123
- affiliatePercentage: string;
124
-
125
- constructor(platformPercentage: string, affiliatePercentage: string) {
126
- this.platformPercentage = platformPercentage;
127
- this.affiliatePercentage = affiliatePercentage;
128
- }
129
-
130
- static fromJson(json: Record<string, any>): SaleDistribution {
131
- return new SaleDistribution(json?.platform_percentage || '', json?.affiliate_percentage || '');
132
- }
133
- }
134
-
135
- class GoMarketMe {
136
- private static instance: GoMarketMe;
137
- private sdkType = 'ReactNative';
138
- private sdkVersion = '4.0.0';
139
- private sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
140
- private sdkInitializationUrl =
141
- 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
142
- private systemInfoUrl =
143
- 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
144
- private eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
145
- private _affiliateCampaignCode = '';
146
- private _deviceId = '';
147
- private _packageName = '';
148
- private _purchaseUpdateUnsub?: ReturnType<typeof purchaseUpdatedListener>;
149
- private _purchaseErrorUnsub?: ReturnType<typeof purchaseErrorListener>;
150
- public affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
151
-
152
- private constructor() { }
153
-
154
- public static getInstance(): GoMarketMe {
155
- if (!GoMarketMe.instance) GoMarketMe.instance = new GoMarketMe();
156
- return GoMarketMe.instance;
157
- }
158
-
159
- public async initialize(apiKey: string): Promise<void> {
160
- try {
161
- const isSDKInitialized = await this._isSDKInitialized();
162
- if (!isSDKInitialized) await this._postSDKInitialization(apiKey);
163
- this._packageName = DeviceInfo.getBundleId();
164
- const systemInfo = await this._getSystemInfo();
165
- this.affiliateMarketingData = await this._postSystemInfo(systemInfo, apiKey);
166
- await this._addListeners(apiKey);
167
- this._fetchExistingPurchases(apiKey).catch(e => {
168
- console.log('Error in background purchase fetch:', e);
169
- });
170
- } catch (e) {
171
- console.log('Error initializing GoMarketMe:', e);
172
- }
173
- }
174
-
175
- public removeListeners(): void {
176
- try {
177
- this._purchaseUpdateUnsub?.remove?.();
178
- this._purchaseErrorUnsub?.remove?.();
179
- } catch (e) {
180
- console.log('Error removing listeners:', e);
181
- }
182
- }
183
-
184
- private async _addListeners(apiKey: string): Promise<void> {
185
- if (!this._purchaseUpdateUnsub) {
186
- this._purchaseUpdateUnsub = purchaseUpdatedListener(async (purchase: Purchase) => {
187
- try {
188
- await this._fetchConsolidatedPurchases([purchase], apiKey);
189
- } catch (e) {
190
- console.log('purchaseUpdated error:', e);
191
- }
192
- });
193
- }
194
-
195
- if (!this._purchaseErrorUnsub) {
196
- this._purchaseErrorUnsub = purchaseErrorListener((error: PurchaseError) => {
197
- console.log('purchaseErrorListener:', error);
198
- });
199
- }
200
- }
201
-
202
- private async _getSystemInfo(): Promise<any> {
203
- const deviceData =
204
- Platform.OS === 'ios'
205
- ? await this._readIosDeviceInfo()
206
- : await this._readAndroidDeviceInfo();
207
-
208
- this._deviceId = deviceData['deviceId'] || '';
209
-
210
- const devicePixelRatio = PixelRatio.get();
211
- const dimension = Dimensions.get('window');
212
-
213
- return {
214
- device_info: deviceData,
215
- window_info: {
216
- devicePixelRatio,
217
- width: dimension.width * devicePixelRatio,
218
- height: dimension.height * devicePixelRatio,
219
- },
220
- time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
221
- language_code: getUserLocale(),
222
- sdk_type: this.sdkType,
223
- sdk_version: this.sdkVersion,
224
- package_name: this._packageName,
225
- is_production: await this._isProduction()
226
- };
227
- }
228
-
229
- private async _postSDKInitialization(apiKey: string): Promise<void> {
230
- try {
231
- const res = await axios.post(this.sdkInitializationUrl, {}, {
232
- headers: { 'x-api-key': apiKey },
233
- });
234
- if (res.status === 200) await this._markSDKAsInitialized();
235
- } catch (e) {
236
- console.log('Error posting SDK initialization:', e);
237
- }
238
- }
239
-
240
- private async _postSystemInfo(data: any, apiKey: string) {
241
- try {
242
- const res = await axios.post(this.systemInfoUrl, data, {
243
- headers: { 'x-api-key': apiKey },
244
- });
245
- if (res.status === 200) {
246
- const obj = GoMarketMeAffiliateMarketingData.fromJson(res.data);
247
- if (obj) this._affiliateCampaignCode = obj.affiliateCampaignCode;
248
- return obj;
249
- }
250
- } catch (e) {
251
- console.log('Error posting system info:', e);
252
- }
253
- return null;
254
- }
255
-
256
- private async _readAndroidDeviceInfo() {
257
- return {
258
- deviceId: await DeviceInfo.getAndroidId(),
259
- brand: await DeviceInfo.getBrand(),
260
- model: await DeviceInfo.getModel(),
261
- manufacturer: await DeviceInfo.getManufacturer(),
262
- systemName: await DeviceInfo.getSystemName(),
263
- systemVersion: await DeviceInfo.getSystemVersion(),
264
- };
265
- }
266
-
267
- private async _readIosDeviceInfo() {
268
- return {
269
- deviceId: await DeviceInfo.getUniqueId(),
270
- brand: await DeviceInfo.getBrand(),
271
- model: await DeviceInfo.getModel(),
272
- manufacturer: await DeviceInfo.getManufacturer(),
273
- systemName: await DeviceInfo.getSystemName(),
274
- systemVersion: await DeviceInfo.getSystemVersion(),
275
- };
276
- }
277
-
278
- private async _fetchConsolidatedPurchases(purchases: Purchase[], apiKey: string) {
279
- for (const purchase of purchases) {
280
- const receipt = purchase.purchaseToken;
281
- if (!receipt) continue;
282
-
283
- const data: any = this._serializePurchaseDetails(purchase);
284
- data.products = [];
285
-
286
- const pid = data.productID || '';
287
- if (pid) {
288
- try {
289
- const products = await fetchProducts({ skus: [pid] });
290
- if (products && products.length) {
291
- for (const p of products) {
292
- data.products.push(this._serializeProductDetails(p));
293
- }
294
- }
295
- } catch (e) {
296
- console.warn('Error fetching products:', e);
297
- }
298
- }
299
-
300
- await this._sendEventToServer(JSON.stringify(data), 'purchase_product', apiKey);
301
- }
302
- }
303
-
304
- private async _sendEventToServer(body: string, eventType: string, apiKey: string) {
305
- try {
306
- await axios.post(this.eventUrl, body, {
307
- headers: {
308
- 'x-affiliate-campaign-code': this._affiliateCampaignCode,
309
- 'x-device-id': this._deviceId,
310
- 'x-event-type': eventType,
311
- 'x-product-type': Platform.OS,
312
- 'x-source-name': Platform.OS === 'android' ? 'google_play' : 'app_store',
313
- 'x-api-key': apiKey,
314
- },
315
- });
316
- console.log(`${eventType} sent successfully`);
317
- } catch (e) {
318
- console.log(`Error sending ${eventType}:`, e);
319
- }
320
- }
321
-
322
- private _serializePurchaseDetails(purchase: PurchaseCommon) {
323
- return {
324
- packageName: this._packageName,
325
- productID: purchase.productId,
326
- purchaseID: purchase.id,
327
- transactionDate: purchase.transactionDate,
328
- verificationData: {
329
- localVerificationData: purchase.purchaseToken,
330
- source: Platform.OS === 'android' ? 'google_play' : 'app_store',
331
- },
332
- };
333
- }
334
-
335
- private _serializeProductDetails(product: ProductCommon) {
336
- return {
337
- packageName: this._packageName,
338
- productID: product.id,
339
- productTitle: product.title,
340
- productDescription: product.description,
341
- productPrice: product.displayPrice,
342
- productRawPrice: product.price || '',
343
- productCurrencyCode: product.currency,
344
- };
345
- }
346
-
347
- private async _markSDKAsInitialized() {
348
- await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
349
- }
350
-
351
- private async _isSDKInitialized() {
352
- const val = await AsyncStorage.getItem(this.sdkInitializedKey);
353
- return val === 'true';
354
- }
355
-
356
- private async _isProduction(): Promise<boolean> {
357
- if (__DEV__) return false;
358
-
359
- try {
360
- const installer = await DeviceInfo.getInstallerPackageName();
361
-
362
- if (
363
- installer === 'com.android.vending' ||
364
- installer === 'com.amazon.venezia'
365
- ) {
366
- return true;
367
- }
368
-
369
- if (installer == null && !__DEV__) {
370
- return true;
371
- }
372
-
373
- return false;
374
- } catch (error) {
375
- console.warn('Error determining production status:', error);
376
- return false;
377
- }
378
- }
379
-
380
- private async _fetchExistingPurchases(apiKey: string): Promise<void> {
381
- try {
382
- const purchases = await getAvailablePurchases();
383
- if (purchases && purchases.length > 0) {
384
- await this._fetchConsolidatedPurchases(purchases, apiKey);
385
- }
386
- } catch (e) {
387
- console.log('Error fetching existing purchases on app open:', e);
388
- }
389
- }
390
- }
391
-
392
- export default GoMarketMe.getInstance();
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES5",
4
- "module": "commonjs",
5
- "lib": ["es6", "dom"],
6
- "allowJs": true,
7
- "jsx": "react",
8
- "declaration": true,
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "moduleResolution": "node",
14
- "outDir": "./dist",
15
- "rootDir": "./src"
16
- },
17
- "include": ["src/**/*.ts", "src/**/*.tsx"],
18
- "exclude": ["node_modules", "dist", "**/__tests__/*"]
19
- }