insert-affiliate-react-native-sdk 1.2.5 → 1.2.7

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.
@@ -12,7 +12,7 @@ type T_DEEPLINK_IAP_CONTEXT = {
12
12
  validatePurchaseWithIapticAPI: (jsonIapPurchase: CustomPurchase, iapticAppId: string, iapticAppName: string, iapticPublicKey: string) => Promise<boolean>;
13
13
  trackEvent: (eventName: string) => Promise<void>;
14
14
  setShortCode: (shortCode: string) => Promise<void>;
15
- setInsertAffiliateIdentifier: (referringLink: string, completion: (shortLink: string | null) => void) => Promise<void>;
15
+ setInsertAffiliateIdentifier: (referringLink: string) => Promise<void>;
16
16
  initialize: (code: string | null) => Promise<void>;
17
17
  isInitialized: boolean;
18
18
  };
@@ -53,7 +53,7 @@ exports.DeepLinkIapContext = (0, react_1.createContext)({
53
53
  validatePurchaseWithIapticAPI: (jsonIapPurchase, iapticAppId, iapticAppName, iapticPublicKey) => __awaiter(void 0, void 0, void 0, function* () { return false; }),
54
54
  trackEvent: (eventName) => __awaiter(void 0, void 0, void 0, function* () { }),
55
55
  setShortCode: (shortCode) => __awaiter(void 0, void 0, void 0, function* () { }),
56
- setInsertAffiliateIdentifier: (referringLink, completion) => __awaiter(void 0, void 0, void 0, function* () { }),
56
+ setInsertAffiliateIdentifier: (referringLink) => __awaiter(void 0, void 0, void 0, function* () { }),
57
57
  initialize: (code) => __awaiter(void 0, void 0, void 0, function* () { }),
58
58
  isInitialized: false
59
59
  });
@@ -172,32 +172,28 @@ const DeepLinkIapProvider = ({ children, }) => {
172
172
  }
173
173
  });
174
174
  // MARK: Insert Affiliate Identifier
175
- const setInsertAffiliateIdentifier = (referringLink, completion) => __awaiter(void 0, void 0, void 0, function* () {
175
+ const setInsertAffiliateIdentifier = (referringLink) => __awaiter(void 0, void 0, void 0, function* () {
176
176
  console.log("[Insert Affiliate] Setting affiliate identifier.");
177
177
  try {
178
- generateThenSetUserID();
178
+ yield generateThenSetUserID();
179
179
  console.log("[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.");
180
180
  if (!referringLink) {
181
181
  console.warn("[Insert Affiliate] Referring link is invalid.");
182
- storeInsertAffiliateIdentifier({ link: referringLink });
183
- completion(null);
182
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
184
183
  return;
185
184
  }
186
185
  if (!isInitialized || !companyCode) {
187
186
  console.error("[Insert Affiliate] SDK is not initialized. Please initialize the SDK with a valid company code.");
188
- completion(null);
189
187
  return;
190
188
  }
191
189
  if (!companyCode || companyCode.trim() === "") {
192
190
  console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
193
- completion(null);
194
191
  return;
195
192
  }
196
193
  // Check if referring link is already a short code, if so save it and stop here.
197
194
  if (isShortCode(referringLink)) {
198
195
  console.log("[Insert Affiliate] Referring link is already a short code.");
199
- storeInsertAffiliateIdentifier({ link: referringLink });
200
- completion(referringLink);
196
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
201
197
  return;
202
198
  }
203
199
  // If the code is not already a short code, encode it raedy to send to our endpoint to return the short code. Save it before making the call in case something goes wrong
@@ -205,8 +201,7 @@ const DeepLinkIapProvider = ({ children, }) => {
205
201
  const encodedAffiliateLink = encodeURIComponent(referringLink);
206
202
  if (!encodedAffiliateLink) {
207
203
  console.error("[Insert Affiliate] Failed to encode affiliate link.");
208
- storeInsertAffiliateIdentifier({ link: referringLink });
209
- completion(null);
204
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
210
205
  return;
211
206
  }
212
207
  // Create the request URL
@@ -221,18 +216,15 @@ const DeepLinkIapProvider = ({ children, }) => {
221
216
  if (response.status === 200 && response.data.shortLink) {
222
217
  const shortLink = response.data.shortLink;
223
218
  console.log("[Insert Affiliate] Short link received:", shortLink);
224
- storeInsertAffiliateIdentifier({ link: shortLink });
225
- completion(shortLink);
219
+ yield storeInsertAffiliateIdentifier({ link: shortLink });
226
220
  }
227
221
  else {
228
222
  console.warn("[Insert Affiliate] Unexpected response format.");
229
- storeInsertAffiliateIdentifier({ link: referringLink });
230
- completion(null);
223
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
231
224
  }
232
225
  }
233
226
  catch (error) {
234
227
  console.error("[Insert Affiliate] Error:", error);
235
- completion(null);
236
228
  }
237
229
  });
238
230
  function storeInsertAffiliateIdentifier(_a) {
@@ -7,7 +7,7 @@ declare const useDeepLinkIapProvider: () => {
7
7
  returnInsertAffiliateIdentifier: () => Promise<string | null>;
8
8
  trackEvent: (eventName: string) => Promise<void>;
9
9
  setShortCode: (shortCode: string) => Promise<void>;
10
- setInsertAffiliateIdentifier: (referringLink: string, completion: (shortLink: string | null) => void) => Promise<void>;
10
+ setInsertAffiliateIdentifier: (referringLink: string) => Promise<void>;
11
11
  initialize: (code: string | null) => Promise<void>;
12
12
  isInitialized: boolean;
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "insert-affiliate-react-native-sdk",
3
- "version": "1.2.5",
3
+ "version": "1.2.7",
4
4
  "description": "A package for connecting with the Insert Affiliate Platform to add app based affiliate marketing.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,10 +24,7 @@ type T_DEEPLINK_IAP_CONTEXT = {
24
24
  ) => Promise<boolean>;
25
25
  trackEvent: (eventName: string) => Promise<void>;
26
26
  setShortCode: (shortCode: string) => Promise<void>;
27
- setInsertAffiliateIdentifier: (
28
- referringLink: string,
29
- completion: (shortLink: string | null) => void
30
- ) => Promise<void>;
27
+ setInsertAffiliateIdentifier: (referringLink: string) => Promise<void>;
31
28
  initialize: (code: string | null) => Promise<void>;
32
29
  isInitialized: boolean;
33
30
  };
@@ -67,10 +64,7 @@ export const DeepLinkIapContext = createContext<T_DEEPLINK_IAP_CONTEXT>({
67
64
  ) => false,
68
65
  trackEvent: async (eventName: string) => {},
69
66
  setShortCode: async (shortCode: string) => {},
70
- setInsertAffiliateIdentifier: async (
71
- referringLink: string,
72
- completion: (shortLink: string | null) => void
73
- ) => {},
67
+ setInsertAffiliateIdentifier: async (referringLink: string) => {},
74
68
  initialize: async (code: string | null) => {},
75
69
  isInitialized: false
76
70
  });
@@ -206,27 +200,22 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
206
200
 
207
201
 
208
202
  // MARK: Insert Affiliate Identifier
209
- const setInsertAffiliateIdentifier = async (
210
- referringLink: string,
211
- completion: (shortLink: string | null) => void
212
- ) => {
203
+ const setInsertAffiliateIdentifier = async (referringLink: string) => {
213
204
  console.log("[Insert Affiliate] Setting affiliate identifier.");
214
205
 
215
206
  try {
216
- generateThenSetUserID();
207
+ await generateThenSetUserID();
217
208
 
218
209
  console.log("[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.");
219
210
 
220
211
  if (!referringLink) {
221
212
  console.warn("[Insert Affiliate] Referring link is invalid.");
222
- storeInsertAffiliateIdentifier({ link: referringLink });
223
- completion(null);
213
+ await storeInsertAffiliateIdentifier({ link: referringLink });
224
214
  return;
225
215
  }
226
216
 
227
217
  if (!isInitialized || !companyCode) {
228
218
  console.error("[Insert Affiliate] SDK is not initialized. Please initialize the SDK with a valid company code.");
229
- completion(null);
230
219
  return;
231
220
  }
232
221
 
@@ -234,15 +223,13 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
234
223
  console.error(
235
224
  "[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code."
236
225
  );
237
- completion(null);
238
226
  return;
239
227
  }
240
228
 
241
229
  // Check if referring link is already a short code, if so save it and stop here.
242
230
  if (isShortCode(referringLink)) {
243
231
  console.log("[Insert Affiliate] Referring link is already a short code.");
244
- storeInsertAffiliateIdentifier({ link: referringLink });
245
- completion(referringLink);
232
+ await storeInsertAffiliateIdentifier({ link: referringLink });
246
233
  return;
247
234
  }
248
235
 
@@ -251,8 +238,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
251
238
  const encodedAffiliateLink = encodeURIComponent(referringLink);
252
239
  if (!encodedAffiliateLink) {
253
240
  console.error("[Insert Affiliate] Failed to encode affiliate link.");
254
- storeInsertAffiliateIdentifier({ link: referringLink });
255
- completion(null);
241
+ await storeInsertAffiliateIdentifier({ link: referringLink });
256
242
  return;
257
243
  }
258
244
 
@@ -269,16 +255,13 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
269
255
  if (response.status === 200 && response.data.shortLink) {
270
256
  const shortLink = response.data.shortLink;
271
257
  console.log("[Insert Affiliate] Short link received:", shortLink);
272
- storeInsertAffiliateIdentifier({ link: shortLink });
273
- completion(shortLink);
258
+ await storeInsertAffiliateIdentifier({ link: shortLink });
274
259
  } else {
275
260
  console.warn("[Insert Affiliate] Unexpected response format.");
276
- storeInsertAffiliateIdentifier({ link: referringLink });
277
- completion(null);
261
+ await storeInsertAffiliateIdentifier({ link: referringLink });
278
262
  }
279
263
  } catch (error) {
280
264
  console.error("[Insert Affiliate] Error:", error);
281
- completion(null);
282
265
  }
283
266
  };
284
267