@peektravel/app-utilities 0.9.5 → 1.0.0

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/README.md CHANGED
@@ -34,8 +34,8 @@ const peek = new PeekAccessService({
34
34
  installId: 'install-123', // JWT subject
35
35
  jwtSecret: process.env.PEEK_INTERNAL_SECRET!, // signs the JWT
36
36
  issuer: process.env.APP_NAME!, // JWT issuer
37
- appId: process.env.PEEK_APP_ID!, // gateway path segment
38
- gatewayKey: process.env.PEEK_GATEWAY_KEY!, // pk-api-key header
37
+ mode: 'v2', // connection generation — required (see below)
38
+ apiUrl: install.apiUrl, // per-install base URL from the install webhook (persisted)
39
39
  });
40
40
 
41
41
  const products: Product[] = await peek.getProductService().getAllProducts();
@@ -44,6 +44,41 @@ const products: Product[] = await peek.getProductService().getAllProducts();
44
44
  The access service is the authenticated root; each `get<Resource>Service()`
45
45
  returns a (memoized) service that owns that resource's calls.
46
46
 
47
+ ### Connection mode (`v1` / `v2`) — **required**
48
+
49
+ `mode` is a **mandatory** config field — you must choose a connection generation
50
+ explicitly. (It used to be optional, defaulting to `v1`; it is now required so
51
+ that updating the package forces a deliberate choice instead of silently keeping
52
+ the old behaviour.)
53
+
54
+ - **`mode: 'v2'`** — **use this going forward.** The app-registry connection. It
55
+ **requires** the install's `apiUrl` — the per-install base URL delivered on the
56
+ install webhook (`api.url`); the constructor throws without it. Persist that URL
57
+ per install (see [Webhooks](#webhooks)) and pass it as `apiUrl`; no `gatewayKey`
58
+ is needed. If you don't yet have a webhook `apiUrl` (e.g. an older install you
59
+ don't want to uninstall/reinstall just to get one), build one by appending your
60
+ **app slug** to the registry prefix and pass that as the `apiUrl` yourself —
61
+ `https://apps.peek.com/installations-api/<app-slug>` (same shape as the
62
+ webhook's `api.url`; the trailing app-slug segment is required — the prefix
63
+ alone is not a valid URL). Treat it as a transitional bridge and move to the
64
+ webhook URL.
65
+ - **`mode: 'v1'`** — **deprecated; will be removed.** The legacy gateway; needs
66
+ `appId` + `gatewayKey`. If your install relied on the previous default, the
67
+ fastest no-behaviour-change update is to pass `mode: 'v1'` — then plan the
68
+ migration to `v2`.
69
+
70
+ ```ts
71
+ // Legacy v1 (deprecated) — fastest update for an install that used the old default:
72
+ const peek = new PeekAccessService({
73
+ installId: 'install-123',
74
+ jwtSecret: process.env.PEEK_INTERNAL_SECRET!,
75
+ issuer: process.env.APP_NAME!,
76
+ appId: process.env.PEEK_APP_ID!, // gateway path segment
77
+ gatewayKey: process.env.PEEK_GATEWAY_KEY!, // pk-api-key header
78
+ mode: 'v1',
79
+ });
80
+ ```
81
+
47
82
  `getAllProducts()` returns a single flat list of activities **and** add-ons
48
83
  (add-ons tagged with `ADD_ON_PRODUCT_TYPE`), gathering all cursor-paginated
49
84
  add-on pages for you.
@@ -102,7 +137,7 @@ With `fullCustomerAccess` **off** (the default):
102
137
 
103
138
  ```ts
104
139
  const peek = new PeekAccessService({
105
- installId, jwtSecret, issuer, appId, gatewayKey,
140
+ installId, jwtSecret, issuer, mode: 'v2', apiUrl,
106
141
  accessOptions: { fullCustomerAccess: true }, // opt into PII + payment operations
107
142
  });
108
143
  ```
package/dist/index.cjs CHANGED
@@ -2791,7 +2791,7 @@ async function requestWithRetry(http, url, init, label, onResponse) {
2791
2791
  // src/internal/sdk-headers.ts
2792
2792
  var SDK_HEADER_NAME = "x-peek-sdk";
2793
2793
  var SDK_PLATFORM = "js";
2794
- var SDK_VERSION = "0.9.5";
2794
+ var SDK_VERSION = "1.0.0";
2795
2795
  var SDK_HEADER_VALUE = `${SDK_PLATFORM}-${SDK_VERSION}`;
2796
2796
 
2797
2797
  // src/internal/peek/graphql-client.ts
@@ -4434,7 +4434,9 @@ var noopLogger = {
4434
4434
 
4435
4435
  // src/peek-access-service.ts
4436
4436
  var DEFAULT_BASE_URL = "https://apps.peekapis.com/backoffice-gql";
4437
- var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
4437
+ var V2_FALLBACK_URL_PREFIX = "https://apps.peek.com/installations-api";
4438
+ var ERROR_MODE_REQUIRED = `PeekAccessService: "mode" is required and must be "v1" or "v2". Existing installs used the previous default of "v1" \u2014 pass mode: "v1" for the fastest update. Note: "v1" is deprecated and will be removed; migrate to "v2" and pass the install webhook's apiUrl.`;
4439
+ var ERROR_V2_API_URL_REQUIRED = `PeekAccessService: mode "v2" requires an "apiUrl" \u2014 the per-install URL delivered on the install webhook (api.url) and persisted per install. If you do not have one yet, append your app slug to the registry prefix and pass that, e.g. "${V2_FALLBACK_URL_PREFIX}/<app-slug>" (the trailing app-slug segment is required \u2014 the prefix alone is not a valid apiUrl).`;
4438
4440
  var PeekAccessService = class {
4439
4441
  client;
4440
4442
  productServiceOptions;
@@ -4456,19 +4458,24 @@ var PeekAccessService = class {
4456
4458
  customQuestionService;
4457
4459
  constructor(config) {
4458
4460
  const hasApiUrl = !!config.apiUrl;
4461
+ if (config.mode !== "v1" && config.mode !== "v2") {
4462
+ throw new Error(ERROR_MODE_REQUIRED);
4463
+ }
4459
4464
  const isV2 = config.mode === "v2";
4460
4465
  requireNonEmpty(config.installId, "installId", "PeekAccessService");
4461
4466
  requireNonEmpty(config.jwtSecret, "jwtSecret", "PeekAccessService");
4462
4467
  requireNonEmpty(config.issuer, "issuer", "PeekAccessService");
4463
- if (!hasApiUrl) requireNonEmpty(config.appId ?? "", "appId", "PeekAccessService");
4464
- if (!hasApiUrl && !isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey", "PeekAccessService");
4468
+ if (isV2 && !hasApiUrl) throw new Error(ERROR_V2_API_URL_REQUIRED);
4469
+ if (!isV2 && !hasApiUrl) {
4470
+ requireNonEmpty(config.appId ?? "", "appId", "PeekAccessService");
4471
+ requireNonEmpty(config.gatewayKey ?? "", "gatewayKey", "PeekAccessService");
4472
+ }
4465
4473
  this.jwtSecret = config.jwtSecret;
4466
4474
  this.issuer = config.issuer;
4467
4475
  const logger = config.logger ?? noopLogger;
4468
4476
  const tokens = createTokenManager(config);
4469
- const useRegistrySlug = hasApiUrl || isV2;
4470
- const defaultBaseUrl = isV2 ? DEFAULT_V2_BASE_URL : DEFAULT_BASE_URL;
4471
- const baseApiUrl = hasApiUrl ? resolveBaseApiUrl(config.apiUrl, V2_EXTENDABLE_SLUG, "PeekAccessService") : `${config.baseUrl ?? defaultBaseUrl}/${config.appId}`;
4477
+ const useRegistrySlug = hasApiUrl;
4478
+ const baseApiUrl = hasApiUrl ? resolveBaseApiUrl(config.apiUrl, V2_EXTENDABLE_SLUG, "PeekAccessService") : `${config.baseUrl ?? DEFAULT_BASE_URL}/${config.appId}`;
4472
4479
  this.client = new GraphQLClient({
4473
4480
  baseApiUrl,
4474
4481
  endpoints: peekApiEndpoints(useRegistrySlug),
@@ -5133,7 +5140,12 @@ var AcmeAccessService = class {
5133
5140
 
5134
5141
  // src/access-service-factory.ts
5135
5142
  function createAccessServiceForInstall(install, config) {
5136
- const shared = { ...config, installId: install.installId, apiUrl: install.apiUrl };
5143
+ const shared = {
5144
+ ...config,
5145
+ installId: install.installId,
5146
+ apiUrl: install.apiUrl,
5147
+ mode: "v2"
5148
+ };
5137
5149
  switch (install.platform) {
5138
5150
  case "peek":
5139
5151
  return new PeekAccessService(shared);