@global.engg/switcher-lib 0.1.43 → 0.1.45

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.
@@ -158,15 +158,21 @@ class AppSwitcherService {
158
158
  // }, 500); // 500ms delay
159
159
  this.executeAppSwitch(app, kyc_status, windowRef);
160
160
  }
161
- setHandoffCookie() {
162
- const value = this.userData.token;
161
+ setHandoffCookie(targetUrl) {
162
+ const token = this.userData.token;
163
+ if (!token) {
164
+ return;
165
+ }
166
+ const host = new URL(targetUrl, window.location.href).host;
167
+ const value = encodeURIComponent(host + '|' + token);
163
168
  document.cookie = `${this.HANDOFF_COOKIE}=${value}; Domain=.${this.HANDOFF_COOKIE_DOMAIN}; Path=/; Max-Age=${this.HANDOFF_COOKIE_MAX_AGE}; Secure; SameSite=Lax`;
164
169
  }
165
170
  executeAppSwitch(app, kyc_status, windowRef) {
166
171
  var _a, _b, _c;
167
172
  if (this.userData.allow_engage && app === 'engage') {
168
- this.setHandoffCookie();
169
- windowRef.open(`${this.SR_CONSTANTS.EngageWebBaseUrl}gate-keeper`, '_blank');
173
+ const targetUrl = `${this.SR_CONSTANTS.EngageWebBaseUrl}gate-keeper`;
174
+ this.setHandoffCookie(targetUrl);
175
+ windowRef.open(targetUrl, '_blank');
170
176
  }
171
177
  else if (app === 'checkout') {
172
178
  if (this.userData.is_admin) {
@@ -174,6 +180,7 @@ class AppSwitcherService {
174
180
  }
175
181
  let url = `https://fastrr-dashboard.pickrr.com/dashboard?utm_source=sr_dashboard&utm_medium=appswitcher&utm_campaign=appswitcher01&utm_content=appswitcher01&cid=${this.userData.company_id}`;
176
182
  url = `${url}&token=${this.userData.token}`;
183
+ this.setHandoffCookie(url);
177
184
  windowRef.open(url, '_blank');
178
185
  // if ((this.isCheckoutAllowed(this.userData?.company_id) || this.userData.allow_checkout)) {
179
186
  // url = `${url}&token=${this.userData.token}`
@@ -183,12 +190,14 @@ class AppSwitcherService {
183
190
  // }
184
191
  }
185
192
  else if (this.userData.allow_fbs && app === 'fullfilment') {
186
- this.setHandoffCookie();
187
- windowRef.open(`${this.SR_CONSTANTS.SrfWebBaseUrl}login`, '_blank');
193
+ const targetUrl = `${this.SR_CONSTANTS.SrfWebBaseUrl}login`;
194
+ this.setHandoffCookie(targetUrl);
195
+ windowRef.open(targetUrl, '_blank');
188
196
  }
189
197
  else if (!this.userData.allow_fbs && app === 'fullfilment') {
190
- this.setHandoffCookie();
191
- windowRef.open(`${this.SR_CONSTANTS.FulfillmentWebBaseUrl}?utm_source=panel&utm_medium=app_switcher&utm_campaign=SR-Panel-non-srf-switcher`, '_blank');
198
+ const targetUrl = `${this.SR_CONSTANTS.FulfillmentWebBaseUrl}?utm_source=panel&utm_medium=app_switcher&utm_campaign=SR-Panel-non-srf-switcher`;
199
+ this.setHandoffCookie(targetUrl);
200
+ windowRef.open(targetUrl, '_blank');
192
201
  }
193
202
  else if (app === 'rocketbox') {
194
203
  if (this.userData.is_admin) {
@@ -196,26 +205,31 @@ class AppSwitcherService {
196
205
  }
197
206
  if (this.userData.allow_rb_panel || this.userData.is_rb_user) {
198
207
  // Use setTimeout for window.location.href redirects
199
- this.setHandoffCookie();
200
208
  const url = `https://app-cargo.shiprocket.in/auth/confirm?next=/client/dashboard#expires_in=36000&token_type=Bearer&source=sr`;
209
+ this.setHandoffCookie(url);
201
210
  setTimeout(() => {
202
211
  window.open(url, '_blank');
203
212
  }, 500);
204
213
  }
205
214
  else {
215
+ const targetUrl = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
216
+ this.setHandoffCookie(targetUrl);
206
217
  setTimeout(() => {
207
- window.location.href = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
218
+ window.location.href = targetUrl;
208
219
  }, 500);
209
220
  }
210
221
  }
211
222
  else if (((_a = this.userData) === null || _a === void 0 ? void 0 : _a.allow_sr_convert) &&
212
223
  !((_b = this.userData) === null || _b === void 0 ? void 0 : _b.allow_engage) &&
213
224
  app === 'sr_convert') {
214
- this.setHandoffCookie();
215
- windowRef.open(`${this.SR_CONSTANTS.WigzoWebBaseUrl}`, '_blank');
225
+ const targetUrl = `${this.SR_CONSTANTS.WigzoWebBaseUrl}`;
226
+ this.setHandoffCookie(targetUrl);
227
+ windowRef.open(targetUrl, '_blank');
216
228
  }
217
229
  else if (app === 'sr_genie') {
218
- windowRef.open(`https://ai-test.kartrocket.com/login?token=${this.userData.token}`, '_blank');
230
+ const targetUrl = `https://ai-test.kartrocket.com/login?token=${this.userData.token}`;
231
+ this.setHandoffCookie(targetUrl);
232
+ windowRef.open(targetUrl, '_blank');
219
233
  }
220
234
  else if (app === 'one_impression') {
221
235
  // Calling one-impression and redirecting to new tab
@@ -225,10 +239,14 @@ class AppSwitcherService {
225
239
  this.fetchOpenInAppLink();
226
240
  }
227
241
  else if (app === 'wigzo') {
228
- windowRef.open(`https://app.wigzo.com/auth/shiprocket/login/${this.userData.token}`, '_blank');
242
+ const targetUrl = `https://app.wigzo.com/auth/shiprocket/login/${this.userData.token}`;
243
+ this.setHandoffCookie(targetUrl);
244
+ windowRef.open(targetUrl, '_blank');
229
245
  }
230
246
  else if (app === 'omuni') {
231
- windowRef.open(`https://omuni.com/`, '_blank');
247
+ const targetUrl = `https://omuni.com/`;
248
+ this.setHandoffCookie(targetUrl);
249
+ windowRef.open(targetUrl, '_blank');
232
250
  // if (this.userData?.is_omuni2_user == 1) {
233
251
  // this.httpService.get('omuni/switch').subscribe(
234
252
  // (res) => {
@@ -247,85 +265,106 @@ class AppSwitcherService {
247
265
  // }
248
266
  }
249
267
  else if (app === 'trends') {
250
- windowRef.open(`https://trends.shiprocket.in/`, '_blank');
268
+ const targetUrl = `https://trends.shiprocket.in/`;
269
+ this.setHandoffCookie(targetUrl);
270
+ windowRef.open(targetUrl, '_blank');
251
271
  }
252
272
  else if (app === 'creditScore') {
253
273
  if ((_c = this.userData) === null || _c === void 0 ? void 0 : _c.is_crif_enabled) {
254
- this.setHandoffCookie();
255
- 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`, '_blank');
274
+ const 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`;
275
+ this.setHandoffCookie(targetUrl);
276
+ windowRef.open(targetUrl, '_blank');
256
277
  }
257
278
  else {
258
- windowRef.open(`https://www.shiprocket.in/capital/`, '_blank');
279
+ const targetUrl = `https://www.shiprocket.in/capital/`;
280
+ this.setHandoffCookie(targetUrl);
281
+ windowRef.open(targetUrl, '_blank');
259
282
  }
260
283
  }
261
284
  else if (app === 'capital') {
262
- this.setHandoffCookie();
263
- windowRef.open(`https://capital-web.shiprocket.in/home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=capital&utm_term=flexi_business_loan`, '_blank');
285
+ const targetUrl = `https://capital-web.shiprocket.in/home/?utm_source=App-Switcher&utm_medium=Manual-Adhoc&utm_content=capital&utm_term=flexi_business_loan`;
286
+ this.setHandoffCookie(targetUrl);
287
+ windowRef.open(targetUrl, '_blank');
264
288
  }
265
289
  else if (app === 'marketing') {
266
- // Use setTimeout for window.location.href redirects
290
+ const targetUrl = `${this.DOMAIN}/seller/home`;
291
+ this.setHandoffCookie(targetUrl);
267
292
  setTimeout(() => {
268
- window.location.href = `${this.DOMAIN}/seller/home`;
293
+ window.location.href = targetUrl;
269
294
  }, 500);
270
295
  }
271
296
  else if (app === 'whatsapp_solutions') {
272
297
  if (this.userData.allow_engage) {
273
- this.setHandoffCookie();
274
- windowRef.open(`${this.SR_CONSTANTS.EngageWebBaseUrl}gate-keeper`, '_blank');
298
+ const targetUrl = `${this.SR_CONSTANTS.EngageWebBaseUrl}gate-keeper`;
299
+ this.setHandoffCookie(targetUrl);
300
+ windowRef.open(targetUrl, '_blank');
275
301
  }
276
302
  else {
277
- windowRef.open(`https://app-engage.shiprocket.in/auth/register`, '_blank');
303
+ const targetUrl = `https://app-engage.shiprocket.in/auth/register`;
304
+ this.setHandoffCookie(targetUrl);
305
+ windowRef.open(targetUrl, '_blank');
278
306
  }
279
307
  }
280
308
  else if (app === 'internationalParcels') {
281
309
  if (kyc_status == 0 || kyc_status == 1 || kyc_status == 2 || kyc_status == 4) {
282
- // Use setTimeout for window.location.href redirects
310
+ const targetUrl = `${this.DOMAIN}/seller/internationalDashboard/overview`;
311
+ this.setHandoffCookie(targetUrl);
283
312
  setTimeout(() => {
284
- window.location.href = `${this.DOMAIN}/seller/internationalDashboard/overview`;
313
+ window.location.href = targetUrl;
285
314
  }, 500);
286
315
  }
287
316
  else {
317
+ const targetUrl = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
318
+ this.setHandoffCookie(targetUrl);
288
319
  setTimeout(() => {
289
- window.location.href = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
320
+ window.location.href = targetUrl;
290
321
  }, 500);
291
322
  }
292
323
  }
293
324
  else if (app === 'i_rocketbox') {
294
- // Use setTimeout for window.location.href redirects
325
+ const targetUrl = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
326
+ this.setHandoffCookie(targetUrl);
295
327
  setTimeout(() => {
296
- window.location.href = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
328
+ window.location.href = targetUrl;
297
329
  }, 500);
298
330
  }
299
331
  else if (app === 'brand_launch') {
300
- // Use setTimeout for window.location.href redirects
332
+ const targetUrl = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
333
+ this.setHandoffCookie(targetUrl);
301
334
  setTimeout(() => {
302
- window.location.href = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
335
+ window.location.href = targetUrl;
303
336
  }, 500);
304
337
  }
305
338
  else if (app === 'express_parcel') {
306
- // Use setTimeout for window.location.href redirects
339
+ const targetUrl = `${this.DOMAIN}/seller/home`;
340
+ this.setHandoffCookie(targetUrl);
307
341
  setTimeout(() => {
308
- window.location.href = `${this.DOMAIN}/seller/home`;
342
+ window.location.href = targetUrl;
309
343
  }, 500);
310
344
  }
311
345
  else if (app === 'instant_deliveries') {
312
- this.setHandoffCookie();
313
- windowRef.open(`${this.SR_CONSTANTS.QuickWebBaseUrl}gate-keeper`, '_blank');
346
+ const targetUrl = `${this.SR_CONSTANTS.QuickWebBaseUrl}gate-keeper`;
347
+ this.setHandoffCookie(targetUrl);
348
+ windowRef.open(targetUrl, '_blank');
314
349
  return;
315
350
  }
316
351
  else if (app === 'warehousing') {
317
- windowRef.open(`https://fulfillment.shiprocket.in/`, '_blank');
352
+ const targetUrl = `https://fulfillment.shiprocket.in/`;
353
+ this.setHandoffCookie(targetUrl);
354
+ windowRef.open(targetUrl, '_blank');
318
355
  }
319
356
  else if (app == 'srocketbox') {
320
- // Use setTimeout for window.location.href redirects
357
+ const targetUrl = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
358
+ this.setHandoffCookie(targetUrl);
321
359
  setTimeout(() => {
322
- window.location.href = `${this.DOMAIN}/seller/settings/internationalsettings/internationalkyc`;
360
+ window.location.href = targetUrl;
323
361
  }, 500);
324
362
  }
325
363
  else if (app == 'somuni') {
326
- // Use setTimeout for window.location.href redirects
364
+ const targetUrl = `${this.DOMAIN}/seller/home`;
365
+ this.setHandoffCookie(targetUrl);
327
366
  setTimeout(() => {
328
- window.location.href = `${this.DOMAIN}/seller/home`;
367
+ window.location.href = targetUrl;
329
368
  }, 500);
330
369
  }
331
370
  }
@@ -444,6 +483,7 @@ class AppSwitcherService {
444
483
  this._http.get('oneimpression/open-app-redirection_url')
445
484
  .subscribe((res) => {
446
485
  if (res && (res === null || res === void 0 ? void 0 : res.url)) {
486
+ this.setHandoffCookie(res.url);
447
487
  window.open(res === null || res === void 0 ? void 0 : res.url, '_blank');
448
488
  }
449
489
  });
@@ -451,6 +491,7 @@ class AppSwitcherService {
451
491
  fetchOneImpressionLoginLink() {
452
492
  this._http.get(this._getURL() + 'oneimpression/get-login-link').subscribe((res) => {
453
493
  if (res && (res === null || res === void 0 ? void 0 : res.url)) {
494
+ this.setHandoffCookie(res.url);
454
495
  window.open(res === null || res === void 0 ? void 0 : res.url, '_blank');
455
496
  }
456
497
  else if ((res === null || res === void 0 ? void 0 : res.status) == 'fail') {