@peektravel/app-utilities 0.1.6 → 0.2.2

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
@@ -25,6 +25,7 @@ var jwt__namespace = /*#__PURE__*/_interopNamespace(jwt);
25
25
 
26
26
  // src/internal/gateway-endpoints.ts
27
27
  var SALES_ENDPOINT = "sales";
28
+ var V2_EXTENDABLE_SLUG = "peek_backoffice_api-v1";
28
29
 
29
30
  // src/internal/account-users/account-user-converter.ts
30
31
  var ACTIVE_STATUS = "ACTIVE";
@@ -1841,14 +1842,19 @@ var GraphQLClient = class {
1841
1842
  throw new RateLimitError();
1842
1843
  }
1843
1844
  endpoint(endpointName) {
1844
- return `${this.options.baseUrl}/${this.options.appId}/${endpointName}`;
1845
+ const { baseUrl, appId, endpointPathPrefix } = this.options;
1846
+ const prefix = endpointPathPrefix ? `${endpointPathPrefix}/` : "";
1847
+ return `${baseUrl}/${appId}/${prefix}${endpointName}`;
1845
1848
  }
1846
1849
  buildHeaders() {
1847
- return {
1850
+ const headers = {
1848
1851
  "X-Peek-Auth": `Bearer ${this.options.getToken()}`,
1849
- "pk-api-key": this.options.gatewayKey,
1850
1852
  "Content-Type": "application/json"
1851
1853
  };
1854
+ if (this.options.gatewayKey) {
1855
+ headers["pk-api-key"] = this.options.gatewayKey;
1856
+ }
1857
+ return headers;
1852
1858
  }
1853
1859
  };
1854
1860
 
@@ -2908,6 +2914,7 @@ var noopLogger = {
2908
2914
 
2909
2915
  // src/peek-access-service.ts
2910
2916
  var DEFAULT_BASE_URL = "https://apps.peekapis.com/backoffice-gql";
2917
+ var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
2911
2918
  var DEFAULT_TOKEN_TTL_SECONDS = 3600;
2912
2919
  var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
2913
2920
  var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
@@ -2926,11 +2933,12 @@ var PeekAccessService = class {
2926
2933
  bookingService;
2927
2934
  reviewService;
2928
2935
  constructor(config) {
2936
+ const isV2 = config.mode === "v2";
2929
2937
  requireNonEmpty(config.installId, "installId");
2930
2938
  requireNonEmpty(config.jwtSecret, "jwtSecret");
2931
2939
  requireNonEmpty(config.issuer, "issuer");
2932
2940
  requireNonEmpty(config.appId, "appId");
2933
- requireNonEmpty(config.gatewayKey, "gatewayKey");
2941
+ if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
2934
2942
  const logger = config.logger ?? noopLogger;
2935
2943
  const tokens = new TokenManager({
2936
2944
  secret: config.jwtSecret,
@@ -2939,14 +2947,16 @@ var PeekAccessService = class {
2939
2947
  ttlSeconds: config.tokenTtlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS,
2940
2948
  leewaySeconds: config.tokenRefreshLeewaySeconds ?? DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS
2941
2949
  });
2950
+ const defaultBaseUrl = isV2 ? DEFAULT_V2_BASE_URL : DEFAULT_BASE_URL;
2942
2951
  this.client = new GraphQLClient({
2943
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
2952
+ baseUrl: config.baseUrl ?? defaultBaseUrl,
2944
2953
  appId: config.appId,
2945
2954
  gatewayKey: config.gatewayKey,
2946
2955
  getToken: () => tokens.getToken(),
2947
2956
  retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
2948
2957
  logger,
2949
- fetchFn: config.fetch ?? globalThis.fetch
2958
+ fetchFn: config.fetch ?? globalThis.fetch,
2959
+ endpointPathPrefix: isV2 ? V2_EXTENDABLE_SLUG : void 0
2950
2960
  });
2951
2961
  this.productServiceOptions = {
2952
2962
  itemOptionsPageSize: config.itemOptionsPageSize