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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
222
|
-
console.
|
|
223
|
-
yield storeInsertAffiliateIdentifier({ link: referringLink });
|
|
224
|
+
catch (error) {
|
|
225
|
+
console.error("[Insert Affiliate] Error:", error);
|
|
224
226
|
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
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
|
@@ -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
|
-
|
|
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."
|