@posiwise/common-services 0.2.25 → 0.2.26

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.
@@ -323,8 +323,14 @@ class BaseHttpService {
323
323
  this.getConfig();
324
324
  this.toast = injector.get(CustomToastService);
325
325
  }
326
+ buildUrl(url) {
327
+ // Collapse any run of 2+ slashes (arises when baseUrl ends with '/'
328
+ // and the caller path also starts with '/', sometimes twice) down to
329
+ // one, while preserving the '://' of an absolute URL scheme.
330
+ return `${this.baseUrl}${url}`.replace(/([^:]\/)\/+/g, '$1');
331
+ }
326
332
  get(url) {
327
- return this.http.get(`${this.baseUrl}${url}`).pipe(catchError(error => {
333
+ return this.http.get(this.buildUrl(url)).pipe(catchError(error => {
328
334
  this.handleError(error);
329
335
  return throwError(() => new HttpErrorResponse(error));
330
336
  }));
@@ -338,31 +344,31 @@ class BaseHttpService {
338
344
  delete params[k];
339
345
  }
340
346
  }
341
- return this.http.get(`${this.baseUrl}${url}`, { params }).pipe(catchError(error => {
347
+ return this.http.get(this.buildUrl(url), { params }).pipe(catchError(error => {
342
348
  this.handleError(error);
343
349
  return throwError(() => new HttpErrorResponse(error));
344
350
  }));
345
351
  }
346
352
  post(url, params = {}) {
347
- return this.http.post(`${this.baseUrl}${url}`, params).pipe(catchError(error => {
353
+ return this.http.post(this.buildUrl(url), params).pipe(catchError(error => {
348
354
  this.handleError(error);
349
355
  return throwError(() => new HttpErrorResponse(error));
350
356
  }));
351
357
  }
352
358
  put(url, params = {}) {
353
- return this.http.put(`${this.baseUrl}${url}`, params).pipe(catchError(error => {
359
+ return this.http.put(this.buildUrl(url), params).pipe(catchError(error => {
354
360
  this.handleError(error);
355
361
  return throwError(() => new HttpErrorResponse(error));
356
362
  }));
357
363
  }
358
364
  patch(url, params = {}) {
359
- return this.http.patch(`${this.baseUrl}${url}`, params).pipe(catchError(error => {
365
+ return this.http.patch(this.buildUrl(url), params).pipe(catchError(error => {
360
366
  this.handleError(error);
361
367
  return throwError(() => new HttpErrorResponse(error));
362
368
  }));
363
369
  }
364
370
  delete(url, option = {}) {
365
- return this.http.delete(`${this.baseUrl}${url}`, option).pipe(catchError(error => {
371
+ return this.http.delete(this.buildUrl(url), option).pipe(catchError(error => {
366
372
  this.handleError(error);
367
373
  return throwError(() => new HttpErrorResponse(error));
368
374
  }));
@@ -371,7 +377,7 @@ class BaseHttpService {
371
377
  const formData = new FormData();
372
378
  formData.append(param, file);
373
379
  const headers = new HttpHeaders({ enctype: 'multipart/form-data' });
374
- return this.http.put(`${this.baseUrl}${url}`, formData, { headers }).pipe(catchError(error => {
380
+ return this.http.put(this.buildUrl(url), formData, { headers }).pipe(catchError(error => {
375
381
  this.handleError(error);
376
382
  return throwError(() => new HttpErrorResponse(error));
377
383
  }));
@@ -385,7 +391,7 @@ class BaseHttpService {
385
391
  }
386
392
  }
387
393
  const headers = new HttpHeaders({ enctype: 'multipart/form-data' });
388
- return this.http.post(`${this.baseUrl}${url}`, formData, { headers }).pipe(catchError(error => {
394
+ return this.http.post(this.buildUrl(url), formData, { headers }).pipe(catchError(error => {
389
395
  this.handleError(error);
390
396
  return throwError(() => new HttpErrorResponse(error));
391
397
  }));
@@ -698,11 +704,11 @@ class SecureTokenStorageService {
698
704
  }
699
705
  return null;
700
706
  }
701
- /**
702
- * Delete cookie
703
- */
707
+ // Attributes MUST mirror setSecureCookie — browsers require matching
708
+ // Secure + SameSite for the delete to take effect on HTTPS.
704
709
  deleteCookie(name) {
705
- this.document.cookie = `${name}=; Path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
710
+ const isSecure = this.document.location.protocol === 'https:';
711
+ this.document.cookie = `${name}=; Path=/; ${isSecure ? 'Secure; ' : ''}SameSite=Strict; expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
706
712
  }
707
713
  /**
708
714
  * Initialize tokens from storage on service startup
@@ -2249,11 +2255,17 @@ class AhoyService {
2249
2255
  this.ahoy = '/ahoy';
2250
2256
  this.toast = injector.get(CustomToastService);
2251
2257
  }
2258
+ // AhoyService does not extend BaseHttpService, so it needs its own
2259
+ // slash normalization: the micro-service base URL ends with '/' and the
2260
+ // path segments below start with '/', producing '/main-api/v1//versions'.
2261
+ buildUrl(url) {
2262
+ return url.replace(/([^:]\/)\/+/g, '$1');
2263
+ }
2252
2264
  getAhoyEvents(params, service, paging) {
2253
2265
  const baseUrl = HelperService.getBaseUrlMicroService(service);
2254
2266
  const page = HelperService.getPagingParams(paging);
2255
2267
  return this.http
2256
- .get(`${baseUrl}${this.ahoy}/events`, {
2268
+ .get(this.buildUrl(`${baseUrl}${this.ahoy}/events`), {
2257
2269
  params: { ...page, ...params }
2258
2270
  })
2259
2271
  .pipe(catchError(error => {
@@ -2265,7 +2277,7 @@ class AhoyService {
2265
2277
  const baseUrl = HelperService.getBaseUrlMicroService(service);
2266
2278
  const page = HelperService.getPagingParams(paging);
2267
2279
  return this.http
2268
- .get(`${baseUrl}${this.ahoy}/messages`, {
2280
+ .get(this.buildUrl(`${baseUrl}${this.ahoy}/messages`), {
2269
2281
  params: { ...page, ...params }
2270
2282
  })
2271
2283
  .pipe(catchError(error => {
@@ -2277,7 +2289,7 @@ class AhoyService {
2277
2289
  const baseUrl = HelperService.getBaseUrlMicroService(service);
2278
2290
  const page = HelperService.getPagingParams(paging);
2279
2291
  return this.http
2280
- .get(`${baseUrl}${this.ahoy}/visits`, {
2292
+ .get(this.buildUrl(`${baseUrl}${this.ahoy}/visits`), {
2281
2293
  params: { ...page, ...params }
2282
2294
  })
2283
2295
  .pipe(catchError(error => {
@@ -2289,7 +2301,7 @@ class AhoyService {
2289
2301
  const baseUrl = HelperService.getBaseUrlMicroService(service);
2290
2302
  const page = HelperService.getPagingParams(paging);
2291
2303
  return this.http
2292
- .get(`${baseUrl}/versions/get_all`, {
2304
+ .get(this.buildUrl(`${baseUrl}/versions/get_all`), {
2293
2305
  params: { ...page, ...params }
2294
2306
  })
2295
2307
  .pipe(catchError(error => {
@@ -2301,7 +2313,7 @@ class AhoyService {
2301
2313
  const baseUrl = HelperService.getBaseUrlMicroService(service);
2302
2314
  const page = HelperService.getPagingParams(paging);
2303
2315
  return this.http
2304
- .get(`${baseUrl}/events/get_all`, {
2316
+ .get(this.buildUrl(`${baseUrl}/events/get_all`), {
2305
2317
  params: { ...page, ...params }
2306
2318
  })
2307
2319
  .pipe(catchError(error => {
@@ -2368,7 +2380,7 @@ class CommonService {
2368
2380
  return this.api.put(`${NEWSLETTER_SUBSCRIPTION_PATH}/${newsletterId}/toggle`, param);
2369
2381
  }
2370
2382
  unsubscribeNewsletter(token) {
2371
- return this.api.get(`/${NEWSLETTER_UNSUBSCRIBE_PATH}?token=${token}`);
2383
+ return this.api.get(`${NEWSLETTER_UNSUBSCRIBE_PATH}?token=${token}`);
2372
2384
  }
2373
2385
  // FAQ
2374
2386
  getFaq(params) {