gomarketme-react-native 2.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,443 +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 * as RNIap from 'react-native-iap';
6
- import axios from 'axios';
7
- export class GoMarketMeAffiliateMarketingData {
8
- campaign: Campaign;
9
- affiliate: Affiliate;
10
- saleDistribution: SaleDistribution;
11
- affiliateCampaignCode: string;
12
- deviceId: string;
13
- offerCode?: string;
14
-
15
- constructor(
16
- campaign: Campaign,
17
- affiliate: Affiliate,
18
- saleDistribution: SaleDistribution,
19
- affiliateCampaignCode: string,
20
- deviceId: string,
21
- offerCode?: string
22
- ) {
23
- this.campaign = campaign;
24
- this.affiliate = affiliate;
25
- this.saleDistribution = saleDistribution;
26
- this.affiliateCampaignCode = affiliateCampaignCode;
27
- this.deviceId = deviceId;
28
- this.offerCode = offerCode;
29
- }
30
-
31
- static fromJson(json: Record<string, any>): GoMarketMeAffiliateMarketingData | null {
32
- // Check if the json is an empty object
33
- if (Object.keys(json).length === 0) {
34
- return null; // Return null or undefined, depending on your preference
35
- }
36
-
37
- return new GoMarketMeAffiliateMarketingData(
38
- Campaign.fromJson(json.campaign),
39
- Affiliate.fromJson(json.affiliate),
40
- SaleDistribution.fromJson(json.sale_distribution),
41
- json.affiliate_campaign_code || '',
42
- json.device_id || '',
43
- json.offer_code
44
- );
45
- }
46
- }
47
-
48
- export class Campaign {
49
- id: string;
50
- name: string;
51
- status: string;
52
- type: string;
53
- publicLinkUrl?: string;
54
-
55
- constructor(id: string, name: string, status: string, type: string, publicLinkUrl?: string) {
56
- this.id = id;
57
- this.name = name;
58
- this.status = status;
59
- this.type = type;
60
- this.publicLinkUrl = publicLinkUrl;
61
- }
62
-
63
- static fromJson(json: Record<string, any>): Campaign {
64
- return new Campaign(
65
- json.id || '',
66
- json.name || '',
67
- json.status || '',
68
- json.type || '',
69
- json.public_link_url
70
- );
71
- }
72
- }
73
-
74
- export class Affiliate {
75
- id: string;
76
- firstName: string;
77
- lastName: string;
78
- countryCode: string;
79
- instagramAccount: string;
80
- tiktokAccount: string;
81
- xAccount: string;
82
-
83
- constructor(
84
- id: string,
85
- firstName: string,
86
- lastName: string,
87
- countryCode: string,
88
- instagramAccount: string,
89
- tiktokAccount: string,
90
- xAccount: string
91
- ) {
92
- this.id = id;
93
- this.firstName = firstName;
94
- this.lastName = lastName;
95
- this.countryCode = countryCode;
96
- this.instagramAccount = instagramAccount;
97
- this.tiktokAccount = tiktokAccount;
98
- this.xAccount = xAccount;
99
- }
100
-
101
- static fromJson(json: Record<string, any>): Affiliate {
102
- return new Affiliate(
103
- json.id || '',
104
- json.first_name || '',
105
- json.last_name || '',
106
- json.country_code || '',
107
- json.instagram_account || '',
108
- json.tiktok_account || '',
109
- json.x_account || ''
110
- );
111
- }
112
- }
113
-
114
- export class SaleDistribution {
115
- platformPercentage: string;
116
- affiliatePercentage: string;
117
-
118
- constructor(platformPercentage: string, affiliatePercentage: string) {
119
- this.platformPercentage = platformPercentage;
120
- this.affiliatePercentage = affiliatePercentage;
121
- }
122
-
123
- static fromJson(json: Record<string, any>): SaleDistribution {
124
- return new SaleDistribution(
125
- json.platform_percentage || '',
126
- json.affiliate_percentage || ''
127
- );
128
- }
129
- }
130
-
131
- class GoMarketMe {
132
- private static instance: GoMarketMe;
133
- private sdkType = 'ReactNative';
134
- private sdkVersion = '2.0.0';
135
- private sdkInitializedKey = 'GOMARKETME_SDK_INITIALIZED';
136
- private sdkInitializationUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/sdk-initialization';
137
- private systemInfoUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/mobile/system-info';
138
- private eventUrl = 'https://4v9008q1a5.execute-api.us-west-2.amazonaws.com/prod/v1/event';
139
- private _affiliateCampaignCode = '';
140
- private _deviceId = '';
141
- private _packageName = ''
142
- public affiliateMarketingData?: GoMarketMeAffiliateMarketingData | null;
143
-
144
- private constructor() { }
145
-
146
- public static getInstance(): GoMarketMe {
147
- if (!GoMarketMe.instance) {
148
- GoMarketMe.instance = new GoMarketMe();
149
- }
150
- return GoMarketMe.instance;
151
- }
152
-
153
- public async initialize(apiKey: string): Promise<void> {
154
- try {
155
- const isSDKInitialized = await this._isSDKInitialized();
156
- if (!isSDKInitialized) {
157
- await this._postSDKInitialization(apiKey);
158
- }
159
- this._packageName = DeviceInfo.getBundleId();
160
- const systemInfo = await this._getSystemInfo();
161
- this.affiliateMarketingData = await this._postSystemInfo(systemInfo, apiKey);
162
- await this._addListener(apiKey);
163
- } catch (e) {
164
- console.log('Error initializing GoMarketMe:', e);
165
- }
166
- }
167
-
168
- private async _addListener(apiKey: string): Promise<void> {
169
- try {
170
- RNIap.purchaseUpdatedListener(async (purchase: RNIap.Purchase) => {
171
- await this._fetchConsolidatedPurchases([purchase], apiKey);
172
- });
173
-
174
- RNIap.purchaseErrorListener((error) => {
175
- console.log('Purchase error:', error);
176
- });
177
- } catch (e) {
178
- console.log('Error setting up IAP listeners:', e);
179
- }
180
- }
181
-
182
- private async _getSystemInfo(): Promise<any> {
183
- const deviceData = Platform.select({
184
- ios: await this._readIosDeviceInfo(),
185
- android: await this._readAndroidDeviceInfo(),
186
- });
187
-
188
- this._deviceId = deviceData['deviceId'];
189
-
190
- const devicePixelRatio = PixelRatio.get();
191
- const dimension = Dimensions.get('window');
192
-
193
- const windowData = {
194
- devicePixelRatio: devicePixelRatio,
195
- width: dimension.width * devicePixelRatio,
196
- height: dimension.height * devicePixelRatio,
197
- };
198
-
199
- return {
200
- device_info: deviceData,
201
- window_info: windowData,
202
- time_zone: this._getTimeZone(),
203
- language_code: this._getLanguageCode(),
204
- };
205
- }
206
-
207
- private async _postSDKInitialization(apiKey: string): Promise<void> {
208
- try {
209
- const response = await axios.post(this.sdkInitializationUrl, {}, {
210
- headers: {
211
- 'Content-Type': 'application/json',
212
- 'x-api-key': apiKey,
213
- },
214
- });
215
- if (response.status === 200) {
216
- await this._markSDKAsInitialized();
217
- } else {
218
- console.log('Failed to mark SDK as Initialized. Status code:', response.status);
219
- }
220
- } catch (e) {
221
- console.log('Error sending SDK information to server:', e);
222
- }
223
- }
224
-
225
- private async _postSystemInfo(data: any, apiKey: string): Promise<GoMarketMeAffiliateMarketingData | null> {
226
- let output: GoMarketMeAffiliateMarketingData | null = null;
227
- try {
228
- data['sdk_type'] = this.sdkType;
229
- data['sdk_version'] = this.sdkVersion;
230
- data['package_name'] = this._packageName;
231
- const response = await axios.post(this.systemInfoUrl, data, {
232
- headers: {
233
- 'Content-Type': 'application/json',
234
- 'x-api-key': apiKey,
235
- },
236
- });
237
- if (response.status === 200) {
238
- output = GoMarketMeAffiliateMarketingData.fromJson(response.data);
239
- if (output != null) {
240
- this._affiliateCampaignCode = output.affiliateCampaignCode;
241
- }
242
- } else {
243
- console.log('Failed to send system info. Status code:', response.status);
244
- }
245
- } catch (e) {
246
- console.log('Error sending system info to server:', e);
247
- }
248
- return output;
249
- }
250
-
251
- private async _readAndroidDeviceInfo(): Promise<any> {
252
-
253
- let androidId = await DeviceInfo.getAndroidId();
254
- let uniqueId = await DeviceInfo.getUniqueId();
255
- let deviceId = await DeviceInfo.getDeviceId(); // model
256
- let systemName = await DeviceInfo.getSystemName();
257
- let systemVersion = await DeviceInfo.getSystemVersion()
258
- let brand = await DeviceInfo.getBrand();
259
- let model = await DeviceInfo.getModel();
260
- let manufacturer = await DeviceInfo.getManufacturer();
261
- let isEmulator = await DeviceInfo.isEmulator();
262
-
263
- return {
264
- deviceId: androidId,
265
- _deviceId: deviceId,
266
- _uniqueId: uniqueId,
267
- systemName: systemName,
268
- systemVersion: systemVersion,
269
- brand: brand,
270
- model: model,
271
- manufacturer: manufacturer,
272
- isEmulator: isEmulator
273
- };
274
- }
275
-
276
- private async _readIosDeviceInfo(): Promise<any> {
277
-
278
- let uniqueId = await DeviceInfo.getUniqueId();
279
- let deviceId = await DeviceInfo.getDeviceId(); // model
280
- let systemName = await DeviceInfo.getSystemName();
281
- let systemVersion = await DeviceInfo.getSystemVersion()
282
- let brand = await DeviceInfo.getBrand();
283
- let model = await DeviceInfo.getModel();
284
- let manufacturer = await DeviceInfo.getManufacturer();
285
- let isEmulator = await DeviceInfo.isEmulator();
286
-
287
- return {
288
- deviceId: uniqueId,
289
- _deviceId: deviceId,
290
- systemName: systemName,
291
- systemVersion: systemVersion,
292
- brand: brand,
293
- model: model,
294
- manufacturer: manufacturer,
295
- isEmulator: isEmulator
296
- };
297
- }
298
-
299
- private _getTimeZone = (): string => {
300
- return Intl.DateTimeFormat().resolvedOptions().timeZone;
301
- };
302
-
303
- private _getLanguageCode(): string {
304
- return getUserLocale();
305
- }
306
-
307
- private async _fetchConsolidatedPurchases(purchaseDetailsList: RNIap.Purchase[], apiKey: string): Promise<void> {
308
- for (const purchase of purchaseDetailsList) {
309
- if (purchase.transactionReceipt) {
310
- var data = this._serializePurchaseDetails(purchase);
311
- data['products'] = []
312
- if (data.productID != '') {
313
- const products = await RNIap.getProducts({ skus: [data.productID] })
314
- if (products.length > 0) {
315
- for (const product0 of products) {
316
- data['products'].push(this._serializeProductDetails(product0))
317
- }
318
- }
319
- else {
320
- const products = await RNIap.getSubscriptions({ skus: [data.productID] });
321
- if (products.length > 0) {
322
- for (const product0 of products) {
323
- data['products'].push(this._serializeSubscriptionDetails(product0))
324
- }
325
- }
326
- }
327
- }
328
- await this._sendEventToServer(JSON.stringify(data), 'purchase', apiKey);
329
- }
330
- }
331
- }
332
-
333
- private async _sendEventToServer(body: string, eventType: string, apiKey: string): Promise<void> {
334
- try {
335
- const response = await axios.post(this.eventUrl, body, {
336
- headers: {
337
- 'Content-Type': 'application/json',
338
- 'x-affiliate-campaign-code': this._affiliateCampaignCode,
339
- 'x-device-id': this._deviceId,
340
- 'x-event-type': eventType,
341
- 'x-product-type': Platform.OS,
342
- 'x-source-name': Platform.OS === 'android' ? 'google_play' : 'app_store',
343
- 'x-api-key': apiKey,
344
- },
345
- });
346
- if (response.status === 200) {
347
- console.log(`${eventType} sent successfully`);
348
- } else {
349
- console.log(`Failed to send ${eventType}. Status code:`, response.status);
350
- }
351
- } catch (e) {
352
- console.log(`Error sending ${eventType} to server:`, e);
353
- }
354
- }
355
-
356
- private _serializePurchaseDetails(purchase: RNIap.Purchase): any {
357
- return {
358
- packageName: this._packageName,
359
- productID: purchase.productId,
360
- purchaseID: purchase.transactionId || '',
361
- transactionDate: purchase.transactionDate || '',
362
- status: Platform.select({
363
- ios: (purchase as any).transactionStateIOS, // Removed non-existent properties
364
- android: (purchase as any).purchaseStateAndroid,
365
- }),
366
- verificationData: {
367
- localVerificationData: purchase.transactionReceipt,
368
- serverVerificationData: purchase.transactionReceipt,
369
- source: Platform.OS === 'android' ? 'google_play' : 'app_store',
370
- },
371
- pendingCompletePurchase: '',
372
- error: {},
373
- hashCode: '',
374
- _purchase: purchase
375
- };
376
- }
377
-
378
- private _serializeProductDetails(product: RNIap.Product): any {
379
- return {
380
- packageName: this._packageName,
381
- productID: product.productId,
382
- productTitle: product.title,
383
- productDescription: product.description,
384
- productPrice: product.localizedPrice,
385
- productRawPrice: product.price,
386
- productCurrencySymbol: product.localizedPrice.replace('product.price', ''),
387
- productCurrencyCode: product.currency,
388
- hashCode: '',
389
- _product: product
390
- };
391
- }
392
-
393
- private _serializeSubscriptionDetails(subscription: RNIap.Subscription): any {
394
- let output: any = {
395
- productID: subscription.productId,
396
- productTitle: subscription.title,
397
- productDescription: subscription.description,
398
- hashCode: '',
399
- };
400
-
401
- if (Platform.OS === 'ios') {
402
- const subscriptionIOS = subscription as RNIap.SubscriptionIOS;
403
- output.productPrice = subscriptionIOS.localizedPrice;
404
- output.productRawPrice = subscriptionIOS.price;
405
- output.productCurrencyCode = subscriptionIOS.currency;
406
- output._subscription = subscriptionIOS;
407
- } else if (Platform.OS === 'android') {
408
- const subscriptionAndroid = subscription as RNIap.SubscriptionAndroid;
409
- if (subscriptionAndroid.subscriptionOfferDetails?.length) {
410
- const offerDetails = subscriptionAndroid.subscriptionOfferDetails[0];
411
- const priceAmountMicros = parseInt(offerDetails.pricingPhases.pricingPhaseList[0].priceAmountMicros, 10) || 0;
412
- output.productPrice = offerDetails.pricingPhases.pricingPhaseList[0].formattedPrice;
413
- output.productRawPrice = String(priceAmountMicros / 1_000_000);
414
- output.productCurrencyCode = offerDetails.pricingPhases.pricingPhaseList[0].priceCurrencyCode;
415
- }
416
- output._subscription = subscriptionAndroid;
417
- }
418
-
419
- return output;
420
- }
421
-
422
- private async _markSDKAsInitialized(): Promise<boolean> {
423
- try {
424
- await AsyncStorage.setItem(this.sdkInitializedKey, 'true');
425
- return true;
426
- } catch (e) {
427
- console.log('Failed to save SDK initialization:', e);
428
- return false;
429
- }
430
- }
431
-
432
- private async _isSDKInitialized(): Promise<boolean> {
433
- try {
434
- const value = await AsyncStorage.getItem(this.sdkInitializedKey);
435
- return value === 'true';
436
- } catch (e) {
437
- console.log('Failed to load SDK initialization:', e);
438
- return false;
439
- }
440
- }
441
- }
442
-
443
- 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
- }