@opexa/portal-sdk 0.59.133 → 0.59.134

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.
package/dist/index.cjs CHANGED
@@ -4864,6 +4864,18 @@ var AccountService = class {
4864
4864
  };
4865
4865
  }
4866
4866
  };
4867
+
4868
+ // src/utils/call-if-fn.ts
4869
+ function isFunction(value) {
4870
+ return typeof value === "function";
4871
+ }
4872
+ function callIfFn(value, ...args) {
4873
+ if (isFunction(value)) {
4874
+ return value(...args);
4875
+ } else {
4876
+ return value;
4877
+ }
4878
+ }
4867
4879
  var thumbmark_instance;
4868
4880
  async function getFingerPrint() {
4869
4881
  if (typeof window === "undefined") return null;
@@ -4949,7 +4961,7 @@ var AuthService = class {
4949
4961
  return await this.graphqlClient.request(GENERATE_OUTBOUND_SINGLE_SIGN_ON_REDIRECT_URL_MUTATION, variables);
4950
4962
  }
4951
4963
  get headers() {
4952
- const headers = new Headers(this.options.headers);
4964
+ const headers = new Headers(callIfFn(this.options).headers);
4953
4965
  headers.append("Accept", "application/json, text/plain");
4954
4966
  headers.append("Content-Type", "application/json");
4955
4967
  return headers;
@@ -5282,18 +5294,6 @@ var AuthService = class {
5282
5294
  }
5283
5295
  };
5284
5296
 
5285
- // src/utils/call-if-fn.ts
5286
- function isFunction(value) {
5287
- return typeof value === "function";
5288
- }
5289
- function callIfFn(value, ...args) {
5290
- if (isFunction(value)) {
5291
- return value(...args);
5292
- } else {
5293
- return value;
5294
- }
5295
- }
5296
-
5297
5297
  // src/services/cms-portal.service.ts
5298
5298
  var CmsPortalService = class {
5299
5299
  config;
@@ -5481,16 +5481,16 @@ var CmsPortalService = class {
5481
5481
  async getJson(path, params) {
5482
5482
  const config = callIfFn(this.config);
5483
5483
  const fetch_ = config.fetch ?? fetch;
5484
+ const headers = new Headers(config.headers);
5485
+ headers.set("Accept", "application/json");
5486
+ headers.set("Content-Type", "application/json");
5487
+ headers.set("Site-ID", config.site);
5488
+ headers.set("Platform-ID", config.platform);
5484
5489
  const req = new Request(
5485
5490
  `${config.url}${path}?${params?.toString() ?? ""}`,
5486
5491
  {
5487
5492
  method: "GET",
5488
- headers: {
5489
- Accept: "application/json",
5490
- "Content-Type": "application/json",
5491
- "Site-ID": config.site,
5492
- "Platform-ID": config.platform
5493
- }
5493
+ headers
5494
5494
  }
5495
5495
  );
5496
5496
  try {
@@ -11060,7 +11060,12 @@ var Sdk = class {
11060
11060
  url: cmsPortalUrl,
11061
11061
  site,
11062
11062
  platform: sitePlatform,
11063
- fetch: this.getFetch()
11063
+ fetch: this.getFetch(),
11064
+ headers: {
11065
+ ...this._testHeader && {
11066
+ Test: this._testHeader
11067
+ }
11068
+ }
11064
11069
  }));
11065
11070
  this._fetch = config.fetch ?? null;
11066
11071
  this._middleware = config.middleware ?? ((req) => req);
@@ -11070,6 +11075,7 @@ var Sdk = class {
11070
11075
  this.authMiddleware,
11071
11076
  this.fingerprintMiddleware,
11072
11077
  this.miscMiddleware,
11078
+ this.testHeaderMiddleware,
11073
11079
  this.middleware
11074
11080
  ],
11075
11081
  fetch: this.getFetch(),
@@ -11102,6 +11108,7 @@ var Sdk = class {
11102
11108
  middlewares: [
11103
11109
  this.fingerprintMiddleware,
11104
11110
  this.miscMiddleware,
11111
+ this.testHeaderMiddleware,
11105
11112
  this.middleware,
11106
11113
  this.publicRequestMiddleware
11107
11114
  ],
@@ -11130,15 +11137,18 @@ var Sdk = class {
11130
11137
  `${authUrl}/graphql`,
11131
11138
  graphqlClientConfig
11132
11139
  ),
11133
- fetchOptions: {
11140
+ fetchOptions: () => ({
11134
11141
  headers: {
11135
11142
  Role: "MEMBER",
11136
11143
  "Platform-Code": platform,
11137
11144
  ...!production && {
11138
11145
  "Test-Pass": ""
11146
+ },
11147
+ ...this._testHeader && {
11148
+ Test: this._testHeader
11139
11149
  }
11140
11150
  }
11141
- }
11151
+ })
11142
11152
  });
11143
11153
  const sessionManager = config.sessionStorage === "cookie" ? new SessionManagerCookie({
11144
11154
  logger,
@@ -11178,6 +11188,7 @@ var Sdk = class {
11178
11188
  }
11179
11189
  _fetch = null;
11180
11190
  _middleware;
11191
+ _testHeader = null;
11181
11192
  /**
11182
11193
  * @deprecated use `setFetch` instead
11183
11194
  */
@@ -11205,6 +11216,16 @@ var Sdk = class {
11205
11216
  get middleware() {
11206
11217
  return this._middleware;
11207
11218
  }
11219
+ /**
11220
+ * Sets a header value appended to all outgoing requests (GraphQL, auth
11221
+ * REST, and CMS portal REST). Pass `null` to remove it.
11222
+ */
11223
+ setTestHeader(value) {
11224
+ this._testHeader = value;
11225
+ }
11226
+ get testHeader() {
11227
+ return this._testHeader;
11228
+ }
11208
11229
  initMarketDomain() {
11209
11230
  if (typeof window === "undefined") return;
11210
11231
  const searchParams = new URLSearchParams(window.location.search);
@@ -11353,6 +11374,14 @@ var Sdk = class {
11353
11374
  return request;
11354
11375
  };
11355
11376
  }
11377
+ get testHeaderMiddleware() {
11378
+ return (request) => {
11379
+ if (this._testHeader) {
11380
+ request.headers.set("Test", this._testHeader);
11381
+ }
11382
+ return request;
11383
+ };
11384
+ }
11356
11385
  get publicRequestMiddleware() {
11357
11386
  return (request) => {
11358
11387
  request.headers.delete("Authorization");