@global.engg/switcher-lib 0.1.42 → 0.1.44

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.
@@ -78,6 +78,9 @@
78
78
  EngagePlusWebBaseURL: 'https://app-engage.shiprocket.in/'
79
79
  };
80
80
  this.DOMAIN = 'https://app.shiprocket.in';
81
+ this.HANDOFF_COOKIE = 'sr_handoff';
82
+ this.HANDOFF_COOKIE_DOMAIN = 'shiprocket.in';
83
+ this.HANDOFF_COOKIE_MAX_AGE = 60;
81
84
  this.userData = JSON.parse(localStorage.getItem('ngStorage-USER') || localStorage.getItem('_userData') || '{}');
82
85
  this.isDesktop = false;
83
86
  this.appSwitchList = [
@@ -184,11 +187,22 @@
184
187
  // }, 500); // 500ms delay
185
188
  this.executeAppSwitch(app, kyc_status, windowRef);
186
189
  };
190
+ AppSwitcherService.prototype.setHandoffCookie = function (targetUrl) {
191
+ var token = this.userData.token;
192
+ if (!token) {
193
+ return;
194
+ }
195
+ var host = new URL(targetUrl, window.location.href).host;
196
+ var value = encodeURIComponent(host + '|' + token);
197
+ document.cookie = this.HANDOFF_COOKIE + "=" + value + "; Domain=." + this.HANDOFF_COOKIE_DOMAIN + "; Path=/; Max-Age=" + this.HANDOFF_COOKIE_MAX_AGE + "; Secure; SameSite=Lax";
198
+ };
187
199
  AppSwitcherService.prototype.executeAppSwitch = function (app, kyc_status, windowRef) {
188
200
  var _this = this;
189
201
  var _a, _b, _c;
190
202
  if (this.userData.allow_engage && app === 'engage') {
191
- windowRef.open(this.SR_CONSTANTS.EngageWebBaseUrl + "gate-keeper?token=" + this.userData.token, '_blank');
203
+ var targetUrl = this.SR_CONSTANTS.EngageWebBaseUrl + "gate-keeper";
204
+ this.setHandoffCookie(targetUrl);
205
+ windowRef.open(targetUrl, '_blank');
192
206
  }
193
207
  else if (app === 'checkout') {
194
208
  if (this.userData.is_admin) {
@@ -205,10 +219,14 @@
205
219
  // }
206
220
  }
207
221
  else if (this.userData.allow_fbs && app === 'fullfilment') {
208
- windowRef.open(this.SR_CONSTANTS.SrfWebBaseUrl + "login?token=" + this.userData.token, '_blank');
222
+ var targetUrl = this.SR_CONSTANTS.SrfWebBaseUrl + "login";
223
+ this.setHandoffCookie(targetUrl);
224
+ windowRef.open(targetUrl, '_blank');
209
225
  }
210
226
  else if (!this.userData.allow_fbs && app === 'fullfilment') {
211
- windowRef.open(this.SR_CONSTANTS.FulfillmentWebBaseUrl + "?utm_source=panel&utm_medium=app_switcher&utm_campaign=SR-Panel-non-srf-switcher&token=" + this.userData.token, '_blank');
227
+ var targetUrl = this.SR_CONSTANTS.FulfillmentWebBaseUrl + "?utm_source=panel&utm_medium=app_switcher&utm_campaign=SR-Panel-non-srf-switcher";
228
+ this.setHandoffCookie(targetUrl);
229
+ windowRef.open(targetUrl, '_blank');
212
230
  }
213
231
  else if (app === 'rocketbox') {
214
232
  if (this.userData.is_admin) {
@@ -216,9 +234,8 @@
216
234
  }
217
235
  if (this.userData.allow_rb_panel || this.userData.is_rb_user) {
218
236
  // Use setTimeout for window.location.href redirects
219
- var access_token = this.userData.token;
220
- // https://app-cargo.shiprocket.in/auth/confirm?next=/client/dashboard#access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vYXBpdjIuc2hpcHJvY2tldC5jby92MS9hdXRoL2xvZ2luIiwiaWF0IjoxNzcwNjI0ODQ2LCJleHAiOjE3NzE0ODg4NDYsIm5iZiI6MTc3MDYyNDg0NiwianRpIjoiMFFEc2NvTHFHQ0VIUGVESSIsInN1YiI6MjUyMDgsInBydiI6IjA1YmI2NjBmNjdjYWM3NDVmN2IzZGExZWVmMTk3MTk1YTIxMWU2ZDkiLCJjaWQiOjI1MTQ5fQ.3wMPidc7CaIkRhfAsPU9a61HsM-S5Ni_3eJ_kisWKKU&expires_in=36000&token_type=Bearer&source=sr
221
- var url_1 = "https://app-cargo.shiprocket.in/auth/confirm?next=/client/dashboard#access_token=" + access_token + "&expires_in=36000&token_type=Bearer&source=sr";
237
+ var url_1 = "https://app-cargo.shiprocket.in/auth/confirm?next=/client/dashboard#expires_in=36000&token_type=Bearer&source=sr";
238
+ this.setHandoffCookie(url_1);
222
239
  setTimeout(function () {
223
240
  window.open(url_1, '_blank');
224
241
  }, 500);
@@ -232,7 +249,9 @@
232
249
  else if (((_a = this.userData) === null || _a === void 0 ? void 0 : _a.allow_sr_convert) &&
233
250
  !((_b = this.userData) === null || _b === void 0 ? void 0 : _b.allow_engage) &&
234
251
  app === 'sr_convert') {
235
- windowRef.open(this.SR_CONSTANTS.WigzoWebBaseUrl + "/" + this.userData.token, '_blank');
252
+ var targetUrl = "" + this.SR_CONSTANTS.WigzoWebBaseUrl;
253
+ this.setHandoffCookie(targetUrl);
254
+ windowRef.open(targetUrl, '_blank');
236
255
  }
237
256
  else if (app === 'sr_genie') {
238
257
  windowRef.open("https://ai-test.kartrocket.com/login?token=" + this.userData.token, '_blank');
@@ -271,14 +290,18 @@
271
290
  }
272
291
  else if (app === 'creditScore') {
273
292
  if ((_c = this.userData) === null || _c === void 0 ? void 0 : _c.is_crif_enabled) {
274
- windowRef.open("https://capital-web.shiprocket.in/crif-home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=crif_credit_score&utm_term=app_switcher_click&authToken=" + this.userData.token, '_blank');
293
+ var targetUrl = "https://capital-web.shiprocket.in/crif-home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=crif_credit_score&utm_term=app_switcher_click";
294
+ this.setHandoffCookie(targetUrl);
295
+ windowRef.open(targetUrl, '_blank');
275
296
  }
276
297
  else {
277
298
  windowRef.open("https://www.shiprocket.in/capital/", '_blank');
278
299
  }
279
300
  }
280
301
  else if (app === 'capital') {
281
- windowRef.open("https://capital-web.shiprocket.in/home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=capital&utm_term=flexi_business_loan&authToken=" + this.userData.token, '_blank');
302
+ var targetUrl = "https://capital-web.shiprocket.in/home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=capital&utm_term=flexi_business_loan";
303
+ this.setHandoffCookie(targetUrl);
304
+ windowRef.open(targetUrl, '_blank');
282
305
  }
283
306
  else if (app === 'marketing') {
284
307
  // Use setTimeout for window.location.href redirects
@@ -288,7 +311,9 @@
288
311
  }
289
312
  else if (app === 'whatsapp_solutions') {
290
313
  if (this.userData.allow_engage) {
291
- windowRef.open(this.SR_CONSTANTS.EngageWebBaseUrl + "gate-keeper?token=" + this.userData.token, '_blank');
314
+ var targetUrl = this.SR_CONSTANTS.EngageWebBaseUrl + "gate-keeper";
315
+ this.setHandoffCookie(targetUrl);
316
+ windowRef.open(targetUrl, '_blank');
292
317
  }
293
318
  else {
294
319
  windowRef.open("https://app-engage.shiprocket.in/auth/register", '_blank');
@@ -326,7 +351,9 @@
326
351
  }, 500);
327
352
  }
328
353
  else if (app === 'instant_deliveries') {
329
- windowRef.open(this.SR_CONSTANTS.QuickWebBaseUrl + "gate-keeper?token=" + this.userData.token, '_blank');
354
+ var targetUrl = this.SR_CONSTANTS.QuickWebBaseUrl + "gate-keeper";
355
+ this.setHandoffCookie(targetUrl);
356
+ windowRef.open(targetUrl, '_blank');
330
357
  return;
331
358
  }
332
359
  else if (app === 'warehousing') {
@@ -774,7 +801,6 @@
774
801
  SwitcherComponent.prototype.openModal = function (param) {
775
802
  var _this = this;
776
803
  var _a, _b, _c, _d, _e;
777
- console.log("testing log only");
778
804
  if (param == 'mobile') {
779
805
  (_b = (_a = this.windowRef.nativeWindow) === null || _a === void 0 ? void 0 : _a.Moengage) === null || _b === void 0 ? void 0 : _b.track_event("bottom_navigation_clicked", { "company_id": this.company_id, "button_name": 'Switcher', "bu_name": "Domestic" });
780
806
  }