insert-affiliate-react-native-sdk 1.2.6 → 1.2.8

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.
@@ -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
  });
@@ -153,6 +153,7 @@ const DeepLinkIapProvider = ({ children, }) => {
153
153
  };
154
154
  function setShortCode(shortCode) {
155
155
  return __awaiter(this, void 0, void 0, function* () {
156
+ console.log("[Insert Affiliate] Setting short code.");
156
157
  generateThenSetUserID();
157
158
  // Validate it is a short code
158
159
  const capitalisedShortCode = shortCode.toUpperCase();
@@ -172,69 +173,64 @@ const DeepLinkIapProvider = ({ children, }) => {
172
173
  }
173
174
  });
174
175
  // MARK: Insert Affiliate Identifier
175
- const setInsertAffiliateIdentifier = (referringLink, completion) => __awaiter(void 0, void 0, void 0, function* () {
176
- console.log("[Insert Affiliate] Setting affiliate identifier.");
177
- try {
178
- generateThenSetUserID();
179
- console.log("[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.");
180
- if (!referringLink) {
181
- console.warn("[Insert Affiliate] Referring link is invalid.");
182
- storeInsertAffiliateIdentifier({ link: referringLink });
183
- completion(null);
184
- return;
185
- }
186
- if (!isInitialized || !companyCode) {
187
- console.error("[Insert Affiliate] SDK is not initialized. Please initialize the SDK with a valid company code.");
188
- completion(null);
189
- return;
190
- }
191
- if (!companyCode || companyCode.trim() === "") {
192
- console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
193
- completion(null);
194
- return;
195
- }
196
- // Check if referring link is already a short code, if so save it and stop here.
197
- if (isShortCode(referringLink)) {
198
- console.log("[Insert Affiliate] Referring link is already a short code.");
199
- storeInsertAffiliateIdentifier({ link: referringLink });
200
- completion(referringLink);
201
- return;
202
- }
203
- // 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
204
- // Encode the referring link
205
- const encodedAffiliateLink = encodeURIComponent(referringLink);
206
- if (!encodedAffiliateLink) {
207
- console.error("[Insert Affiliate] Failed to encode affiliate link.");
208
- storeInsertAffiliateIdentifier({ link: referringLink });
209
- completion(null);
210
- return;
211
- }
212
- // Create the request URL
213
- const urlString = `https://api.insertaffiliate.com/V1/convert-deep-link-to-short-link?companyId=${companyCode}&deepLinkUrl=${encodedAffiliateLink}`;
214
- console.log("[Insert Affiliate] urlString .", urlString);
215
- const response = yield axios_1.default.get(urlString, {
216
- headers: {
217
- "Content-Type": "application/json",
218
- },
219
- });
220
- // Call to the backend for the short code and save the resolse in valid
221
- if (response.status === 200 && response.data.shortLink) {
222
- const shortLink = response.data.shortLink;
223
- console.log("[Insert Affiliate] Short link received:", shortLink);
224
- storeInsertAffiliateIdentifier({ link: shortLink });
225
- completion(shortLink);
176
+ function setInsertAffiliateIdentifier(referringLink) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ console.log("[Insert Affiliate] Setting affiliate identifier.");
179
+ try {
180
+ yield generateThenSetUserID();
181
+ console.log("[Insert Affiliate] Completed generateThenSetUserID within setInsertAffiliateIdentifier.");
182
+ if (!referringLink) {
183
+ console.warn("[Insert Affiliate] Referring link is invalid.");
184
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
185
+ return;
186
+ }
187
+ if (!isInitialized || !companyCode) {
188
+ console.error("[Insert Affiliate] SDK is not initialized. Please initialize the SDK with a valid company code.");
189
+ return;
190
+ }
191
+ if (!companyCode || companyCode.trim() === "") {
192
+ console.error("[Insert Affiliate] Company code is not set. Please initialize the SDK with a valid company code.");
193
+ return;
194
+ }
195
+ // Check if referring link is already a short code, if so save it and stop here.
196
+ if (isShortCode(referringLink)) {
197
+ console.log("[Insert Affiliate] Referring link is already a short code.");
198
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
199
+ return;
200
+ }
201
+ // 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
202
+ // Encode the referring link
203
+ const encodedAffiliateLink = encodeURIComponent(referringLink);
204
+ if (!encodedAffiliateLink) {
205
+ console.error("[Insert Affiliate] Failed to encode affiliate link.");
206
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
207
+ return;
208
+ }
209
+ // Create the request URL
210
+ const urlString = `https://api.insertaffiliate.com/V1/convert-deep-link-to-short-link?companyId=${companyCode}&deepLinkUrl=${encodedAffiliateLink}`;
211
+ console.log("[Insert Affiliate] urlString .", urlString);
212
+ const response = yield axios_1.default.get(urlString, {
213
+ headers: {
214
+ "Content-Type": "application/json",
215
+ },
216
+ });
217
+ // Call to the backend for the short code and save the resolse in valid
218
+ if (response.status === 200 && response.data.shortLink) {
219
+ const shortLink = response.data.shortLink;
220
+ console.log("[Insert Affiliate] Short link received:", shortLink);
221
+ yield storeInsertAffiliateIdentifier({ link: shortLink });
222
+ }
223
+ else {
224
+ console.warn("[Insert Affiliate] Unexpected response format.");
225
+ yield storeInsertAffiliateIdentifier({ link: referringLink });
226
+ }
226
227
  }
227
- else {
228
- console.warn("[Insert Affiliate] Unexpected response format.");
229
- storeInsertAffiliateIdentifier({ link: referringLink });
230
- completion(null);
228
+ catch (error) {
229
+ console.error("[Insert Affiliate] Error:", error);
231
230
  }
232
- }
233
- catch (error) {
234
- console.error("[Insert Affiliate] Error:", error);
235
- completion(null);
236
- }
237
- });
231
+ });
232
+ }
233
+ ;
238
234
  function storeInsertAffiliateIdentifier(_a) {
239
235
  return __awaiter(this, arguments, void 0, function* ({ link }) {
240
236
  console.log(`[Insert Affiliate] Storing affiliate identifier: ${link}`);
@@ -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.6",
3
+ "version": "1.2.8",
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",
@@ -178,6 +178,7 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
178
178
  };
179
179
 
180
180
  async function setShortCode(shortCode: string): Promise<void> {
181
+ console.log("[Insert Affiliate] Setting short code.");
181
182
  generateThenSetUserID();
182
183
 
183
184
  // Validate it is a short code
@@ -200,7 +201,8 @@ const DeepLinkIapProvider: React.FC<T_DEEPLINK_IAP_PROVIDER> = ({
200
201
 
201
202
 
202
203
  // MARK: Insert Affiliate Identifier
203
- const setInsertAffiliateIdentifier = async (referringLink: string) => {
204
+
205
+ async function setInsertAffiliateIdentifier(referringLink: string): Promise<void> {
204
206
  console.log("[Insert Affiliate] Setting affiliate identifier.");
205
207
 
206
208
  try {