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

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