@peektravel/app-utilities 0.7.1 → 0.7.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.d.cts CHANGED
@@ -19,10 +19,20 @@ interface GraphQLBody<T> {
19
19
  errors?: unknown[];
20
20
  }
21
21
  interface GraphQLClientOptions {
22
- /** Base URL of the backoffice GraphQL gateway (no trailing slash). */
23
- baseUrl: string;
24
- /** Peek app ID, used in the endpoint path. */
25
- appId: string;
22
+ /**
23
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
24
+ * is the **sole request URL** — every GraphQL call POSTs to it unmodified, and
25
+ * `baseUrl`/`appId`/`endpointPathPrefix`/`endpointName` are ignored for URL
26
+ * construction. Takes precedence over `baseUrl`.
27
+ */
28
+ apiUrl?: string;
29
+ /**
30
+ * Base URL of the backoffice GraphQL gateway (no trailing slash). Used only
31
+ * when `apiUrl` is not set; the URL is `baseUrl/appId/[prefix/]endpointName`.
32
+ */
33
+ baseUrl?: string;
34
+ /** Peek app ID, used in the endpoint path (legacy `baseUrl` mode only). */
35
+ appId?: string;
26
36
  /** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
27
37
  gatewayKey?: string;
28
38
  /** Supplies a valid bearer token for each request. */
@@ -1536,9 +1546,29 @@ interface BaseAccessServiceConfig {
1536
1546
  jwtSecret: string;
1537
1547
  /** JWT issuer — the app name / app ID. */
1538
1548
  issuer: string;
1539
- /** App ID, used in the gateway endpoint path. */
1540
- appId: string;
1541
- /** Override the gateway base URL. Default: per-service. */
1549
+ /**
1550
+ * The install's **app endpoint URL** — persist the install webhook's `apiUrl`
1551
+ * and pass it here. When set it is used **as given**: for Peek it is the sole
1552
+ * request URL (every call POSTs to it); for CNG/ACME it is the base and the
1553
+ * REST path is appended. No app-id/gateway segment is inserted, so `appId` is
1554
+ * not required. This is the forward-looking way to target an install — prefer
1555
+ * it over `baseUrl`/`appId`, which are deprecated (the hardcoded base-URL
1556
+ * fallbacks will be removed and a URL will become required in a future release).
1557
+ */
1558
+ apiUrl?: string;
1559
+ /**
1560
+ * App ID, inserted into the gateway endpoint path.
1561
+ *
1562
+ * @deprecated Required only in the legacy `baseUrl` mode. Prefer `apiUrl` (the
1563
+ * install's app endpoint), which needs no app-id segment.
1564
+ */
1565
+ appId?: string;
1566
+ /**
1567
+ * Override the gateway base URL. Default: per-service.
1568
+ *
1569
+ * @deprecated Prefer `apiUrl` (the install's app endpoint, used as given). The
1570
+ * hardcoded per-service default will be removed and a URL will become required.
1571
+ */
1542
1572
  baseUrl?: string;
1543
1573
  /** JWT lifetime in seconds. Default: 3600. */
1544
1574
  tokenTtlSeconds?: number;
@@ -2090,12 +2120,22 @@ declare class PeekAccessService {
2090
2120
  }
2091
2121
 
2092
2122
  interface RestClientOptions$1 {
2093
- /** Base URL of the backoffice gateway (no trailing slash). */
2094
- baseUrl: string;
2095
- /** App ID, used in the endpoint path. */
2096
- appId: string;
2097
- /** Fixed extendable slug inserted between `appId` and the REST path. */
2098
- extendableSlug: string;
2123
+ /**
2124
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
2125
+ * is the **base URL** and only the REST path is appended (`apiUrl/path`) —
2126
+ * `baseUrl`/`appId`/`extendableSlug` are ignored. Takes precedence over
2127
+ * `baseUrl`.
2128
+ */
2129
+ apiUrl?: string;
2130
+ /**
2131
+ * Base URL of the backoffice gateway (no trailing slash). Used only when
2132
+ * `apiUrl` is not set; the URL is `baseUrl/appId/extendableSlug/path`.
2133
+ */
2134
+ baseUrl?: string;
2135
+ /** App ID, used in the endpoint path (legacy `baseUrl` mode only). */
2136
+ appId?: string;
2137
+ /** Fixed extendable slug inserted between `appId` and the REST path (legacy mode). */
2138
+ extendableSlug?: string;
2099
2139
  /** Supplies a valid bearer token for each request. */
2100
2140
  getToken: () => string;
2101
2141
  /** Backoff delays (ms) applied on successive HTTP 429 responses. */
@@ -2217,12 +2257,22 @@ declare class CngAccessService {
2217
2257
  }
2218
2258
 
2219
2259
  interface RestClientOptions {
2220
- /** Base URL of the backoffice gateway (no trailing slash). */
2221
- baseUrl: string;
2222
- /** App ID, used in the endpoint path. */
2223
- appId: string;
2224
- /** Fixed extendable slug inserted between `appId` and the REST path. */
2225
- extendableSlug: string;
2260
+ /**
2261
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
2262
+ * is the **base URL** and only the REST path is appended (`apiUrl/path`) —
2263
+ * `baseUrl`/`appId`/`extendableSlug` are ignored. Takes precedence over
2264
+ * `baseUrl`.
2265
+ */
2266
+ apiUrl?: string;
2267
+ /**
2268
+ * Base URL of the backoffice gateway (no trailing slash). Used only when
2269
+ * `apiUrl` is not set; the URL is `baseUrl/appId/extendableSlug/path`.
2270
+ */
2271
+ baseUrl?: string;
2272
+ /** App ID, used in the endpoint path (legacy `baseUrl` mode only). */
2273
+ appId?: string;
2274
+ /** Fixed extendable slug inserted between `appId` and the REST path (legacy mode). */
2275
+ extendableSlug?: string;
2226
2276
  /** Supplies a valid bearer token for each request. */
2227
2277
  getToken: () => string;
2228
2278
  /** Backoff delays (ms) applied on successive HTTP 429 responses. */
@@ -2341,6 +2391,52 @@ declare class AcmeAccessService {
2341
2391
  getAllActivities(): Promise<AcmeActivity[]>;
2342
2392
  }
2343
2393
 
2394
+ /**
2395
+ * Factory that turns a persisted install (or a parsed install webhook) into the
2396
+ * right access service for its platform, wired to the install's own app
2397
+ * endpoint.
2398
+ *
2399
+ * The install webhook is the only source of an install's `platform` and `apiUrl`
2400
+ * (see `src/models/peek/install.ts`), and those two facts are exactly what's
2401
+ * needed to target it: `platform` picks the service class, and `apiUrl` is used
2402
+ * **as given** as that service's endpoint. This helper encodes that mapping so a
2403
+ * consumer that persisted an install can construct its client in one call
2404
+ * instead of switching on the platform and hand-wiring the URL.
2405
+ */
2406
+
2407
+ /**
2408
+ * The per-install facts needed to build an access service — a structural subset
2409
+ * of {@link InstallWebhook}, so a persisted install record (or the webhook event
2410
+ * itself) satisfies it directly.
2411
+ */
2412
+ interface InstallAccessTarget {
2413
+ /** Which platform serves the install (the install webhook's `platform`). */
2414
+ platform: PeekPlatform | null;
2415
+ /** The install's app endpoint URL (the install webhook's `apiUrl`), used as given. */
2416
+ apiUrl: string;
2417
+ /** The install id (the install webhook's `installId`) — becomes the JWT subject. */
2418
+ installId: string;
2419
+ }
2420
+ /**
2421
+ * The per-app credentials/options shared by every access service — everything
2422
+ * except the per-install `installId`/`apiUrl` (supplied by the target) and the
2423
+ * deprecated `appId`/`baseUrl`/`mode` URL controls (superseded by `apiUrl`).
2424
+ * `gatewayKey` is accepted for Peek and ignored by CNG/ACME.
2425
+ */
2426
+ type InstallAccessConfig = Omit<PeekAccessServiceConfig, "installId" | "apiUrl" | "appId" | "baseUrl" | "mode">;
2427
+ /** The union of access services this factory can return, narrowed by `platform`. */
2428
+ type InstallAccessService = PeekAccessService | CngAccessService | AcmeAccessService;
2429
+ /**
2430
+ * Builds the access service for `install.platform`, using `install.apiUrl` as
2431
+ * the service's endpoint. Narrow the return by `install.platform` (or
2432
+ * `instanceof`) to reach a platform-specific surface.
2433
+ *
2434
+ * @throws {Error} when `install.platform` is `null` or unrecognised — an install
2435
+ * with an unknown platform has no service to route to, and silently defaulting
2436
+ * would point it at the wrong gateway.
2437
+ */
2438
+ declare function createAccessServiceForInstall(install: InstallAccessTarget, config: InstallAccessConfig): InstallAccessService;
2439
+
2344
2440
  /**
2345
2441
  * Public webhook surface for bookings.
2346
2442
  *
@@ -2432,16 +2528,24 @@ declare function parseWaiverWebhook(payload: unknown, options?: AccessOptions):
2432
2528
  * POSTs when an app is installed, uninstalled, or updated.
2433
2529
  *
2434
2530
  * That delivery carries two things at once: a **signed `app_registry_v2` JWT**
2435
- * (the security boundary) and a plain **JSON body** (the enrichment channel).
2531
+ * (the security boundary) and a plain **JSON body** (the event payload).
2436
2532
  * `parseInstallWebhook` verifies the JWT and merges both into this shape, so a
2437
2533
  * consumer sees one clean, flat, JSON-safe record instead of two differently
2438
- * shaped payloads. The verified JWT is authoritative for the fields it carries
2439
- * (`installId`, `accountId`, `status`, `displayVersion`, `user`); the JSON body
2440
- * is the only source of `accountName`, `platform`, and `isTest`.
2441
- *
2442
- * It is also the single origin of the account id in the whole system: no
2443
- * GraphQL read returns it, so whatever a consumer persists from this event is
2444
- * all it will ever have.
2534
+ * shaped payloads. The **JSON body is the source of the event data** — it
2535
+ * carries every field below; the verified JWT authenticates the delivery and
2536
+ * acts as the **fallback** for the fields it also happens to carry (`installId`,
2537
+ * `accountId`, `status`, `displayVersion`, `user`) when the body omits them.
2538
+ *
2539
+ * It is also the single origin of the account id (and the `apiUrl`/`timezone`)
2540
+ * in the whole system: no GraphQL read returns them, so whatever a consumer
2541
+ * persists from this event is all it will ever have.
2542
+ *
2543
+ * **Every install event is a full snapshot — upsert by `installId`.** An
2544
+ * `update_installed` event carries the *same complete record* as the original
2545
+ * `installed` event, so treat each delivery as an upsert keyed by `installId`
2546
+ * and overwrite the stored fields with the incoming ones. This is how the
2547
+ * registry pushes changes — e.g. a new `apiUrl` — so a consumer that only reads
2548
+ * the first `installed` event and ignores later updates will keep stale data.
2445
2549
  */
2446
2550
 
2447
2551
  /**
@@ -2460,9 +2564,10 @@ type InstallStatus = (typeof INSTALL_STATUSES)[number];
2460
2564
  * returns is the shape a consumer persists and later rehydrates. There is
2461
2565
  * deliberately no nested identity object and no second representation.
2462
2566
  *
2463
- * Fields sourced from the **verified JWT** (`installId`, `accountId`, `status`,
2464
- * `rawStatus`, `displayVersion`, `user`) are trustworthy; the enrichment fields
2465
- * (`accountName`, `platform`, `isTest`) come from the unauthenticated JSON body.
2567
+ * Every field is read from the **JSON body** first, falling back to the
2568
+ * **verified JWT** for the fields it also carries (`installId`, `accountId`,
2569
+ * `status`, `displayVersion`, `user`). The delivery is authenticated as a whole
2570
+ * by the JWT signature, so the body is trusted within a verified request.
2466
2571
  */
2467
2572
  interface InstallWebhook {
2468
2573
  /** Install ID — Peek-assigned UUID. Also the JWT subject (`sub`). */
@@ -2490,6 +2595,31 @@ interface InstallWebhook {
2490
2595
  platform: PeekPlatform | null;
2491
2596
  /** Whether this is a test account. Defaults to `false` when not reported. */
2492
2597
  isTest: boolean;
2598
+ /**
2599
+ * The account's IANA timezone (e.g. `"America/New_York"`), or `""` when the
2600
+ * body omits it.
2601
+ *
2602
+ * **Persist this per install.** It has no source other than this event, and
2603
+ * downstream date/time handling for the install (scheduling, day boundaries,
2604
+ * display) needs the account's own timezone rather than the server's.
2605
+ */
2606
+ timezone: string;
2607
+ /**
2608
+ * The **app endpoint URL** the registry serves this install from (the body's
2609
+ * `api.url`), or `""` when the body omits it.
2610
+ *
2611
+ * Use it **as given** as the base URL for this install's API calls — do not
2612
+ * decompose it or append your own app id. The registry may tag traffic with an
2613
+ * app id in the path; that is the registry's concern and opaque to callers, so
2614
+ * hit the URL unmodified.
2615
+ *
2616
+ * **Persist this per install, and refresh it on every install event.** It is
2617
+ * install-specific, has no source other than this webhook, and the registry
2618
+ * can change it: an `update_installed` event redelivers the full record with a
2619
+ * (possibly new) `apiUrl`, so re-key by `installId` and overwrite the stored
2620
+ * URL whenever an event arrives.
2621
+ */
2622
+ apiUrl: string;
2493
2623
  /**
2494
2624
  * The lifecycle status, or `null` when the registry sent a status this
2495
2625
  * version of the package does not know. Handle `null` explicitly — treating
@@ -2502,7 +2632,8 @@ interface InstallWebhook {
2502
2632
  displayVersion: string;
2503
2633
  /**
2504
2634
  * The user that triggered the event, or `null` for system-initiated events
2505
- * (install lifecycle changes are often system-initiated). From the JWT.
2635
+ * (install lifecycle changes are often system-initiated). Read from the body's
2636
+ * `modified_by`, falling back to the JWT's `user`.
2506
2637
  */
2507
2638
  user: PeekAuthTokenUser | null;
2508
2639
  }
@@ -2511,12 +2642,14 @@ interface InstallWebhook {
2511
2642
  * Verifies an install-status webhook token and merges it with the delivered
2512
2643
  * JSON body into one flat {@link InstallWebhook}.
2513
2644
  *
2514
- * The **verified token** is the authoritative source of `installId`,
2515
- * `accountId`, `status`, `displayVersion`, and `user`. The **JSON body** — which
2516
- * is not signed and so is trusted only for fields the token cannot carry —
2517
- * supplies `accountName`, `platform`, and `isTest`. A missing or malformed body
2518
- * degrades those three to `""`/`null`/`false`; it never overrides an
2519
- * authenticated field and never throws.
2645
+ * The **JSON body** is the source of the event data — `installId`, `accountId`,
2646
+ * `accountName`, `platform`, `isTest`, `timezone`, `apiUrl`, `status`,
2647
+ * `displayVersion`, and `user`. The **verified token** authenticates the whole
2648
+ * delivery and is the **fallback** for the fields it also carries (`installId`,
2649
+ * `accountId`, `status`, `displayVersion`, `user`) when the body omits them. A
2650
+ * missing or malformed body degrades the body-only fields (`accountName`,
2651
+ * `platform`, `isTest`, `timezone`, `apiUrl`) to `""`/`null`/`false` and leans
2652
+ * on the token for the rest; it never throws.
2520
2653
  *
2521
2654
  * Signature verification is strict: the HMAC signature (with `secret`), the
2522
2655
  * token expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience are
@@ -2697,4 +2830,4 @@ declare class AcmeApiError extends Error {
2697
2830
  constructor(statusCode: number, body: unknown, message?: string);
2698
2831
  }
2699
2832
 
2700
- export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, type AccessOptions, type AccountUser, AccountUserService, type AccountUserServiceOptions, AcmeAccessService, type AcmeAccessServiceConfig, type AcmeActivity, type AcmeActivityTicket, AcmeApiError, AcmeProductService, type Activity, type ActivityOverrides, type ActivityTicket, type AddAddonInput, AdminAccountRequiredError, type Agent, type AssignGuideResult, type AssignedActivity, type AssignedResource, type Availability, AvailabilityService, type AvailabilityTime, type AvailabilityTimesQuery, type Booking, type BookingAddon, type BookingAddonMoney, type BookingAddonOption, type BookingAddons, type BookingAddonsMutationResult, type BookingPaymentsOnFile, type BookingReadOptions, type BookingSearchBy, BookingService, type BookingServiceOptions, type BookingTimeRangeSearch, type CancelBookingResult, type Channel, type ClearOverridesInput, CngAccessService, type CngAccessServiceConfig, CngApiError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, INSTALL_STATUSES, type InstallStatus, type InstallWebhook, type InstallWebhookAccount, type InstallWebhookClaims, InvalidPeekTokenError, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, type PeekAuthTokenClaims, type PeekAuthTokenUser, PeekGraphQLError, PeekHttpError, type PeekPlatform, PiiAccessDisabledError, type Price, type PricingActivityContext, type PricingEngine, type PricingMoney, type PricingNamedRef, type PricingOverride, type PricingOverrideFilter, PricingService, type Product, type ProductMeetingLocation, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RENTAL_PRODUCT_TYPE, RateLimitError, type RefundInput, type RefundResult, ResellerService, type ResolvedOverride, type ResolvedPricingOverride, type ResolvedResourceOption, type Resource, type ResourceOptionOverride, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
2833
+ export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, type AccessOptions, type AccountUser, AccountUserService, type AccountUserServiceOptions, AcmeAccessService, type AcmeAccessServiceConfig, type AcmeActivity, type AcmeActivityTicket, AcmeApiError, AcmeProductService, type Activity, type ActivityOverrides, type ActivityTicket, type AddAddonInput, AdminAccountRequiredError, type Agent, type AssignGuideResult, type AssignedActivity, type AssignedResource, type Availability, AvailabilityService, type AvailabilityTime, type AvailabilityTimesQuery, type Booking, type BookingAddon, type BookingAddonMoney, type BookingAddonOption, type BookingAddons, type BookingAddonsMutationResult, type BookingPaymentsOnFile, type BookingReadOptions, type BookingSearchBy, BookingService, type BookingServiceOptions, type BookingTimeRangeSearch, type CancelBookingResult, type Channel, type ClearOverridesInput, CngAccessService, type CngAccessServiceConfig, CngApiError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, INSTALL_STATUSES, type InstallAccessConfig, type InstallAccessService, type InstallAccessTarget, type InstallStatus, type InstallWebhook, type InstallWebhookAccount, type InstallWebhookClaims, InvalidPeekTokenError, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, type PeekAuthTokenClaims, type PeekAuthTokenUser, PeekGraphQLError, PeekHttpError, type PeekPlatform, PiiAccessDisabledError, type Price, type PricingActivityContext, type PricingEngine, type PricingMoney, type PricingNamedRef, type PricingOverride, type PricingOverrideFilter, PricingService, type Product, type ProductMeetingLocation, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RENTAL_PRODUCT_TYPE, RateLimitError, type RefundInput, type RefundResult, ResellerService, type ResolvedOverride, type ResolvedPricingOverride, type ResolvedResourceOption, type Resource, type ResourceOptionOverride, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
package/dist/index.d.ts CHANGED
@@ -19,10 +19,20 @@ interface GraphQLBody<T> {
19
19
  errors?: unknown[];
20
20
  }
21
21
  interface GraphQLClientOptions {
22
- /** Base URL of the backoffice GraphQL gateway (no trailing slash). */
23
- baseUrl: string;
24
- /** Peek app ID, used in the endpoint path. */
25
- appId: string;
22
+ /**
23
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
24
+ * is the **sole request URL** — every GraphQL call POSTs to it unmodified, and
25
+ * `baseUrl`/`appId`/`endpointPathPrefix`/`endpointName` are ignored for URL
26
+ * construction. Takes precedence over `baseUrl`.
27
+ */
28
+ apiUrl?: string;
29
+ /**
30
+ * Base URL of the backoffice GraphQL gateway (no trailing slash). Used only
31
+ * when `apiUrl` is not set; the URL is `baseUrl/appId/[prefix/]endpointName`.
32
+ */
33
+ baseUrl?: string;
34
+ /** Peek app ID, used in the endpoint path (legacy `baseUrl` mode only). */
35
+ appId?: string;
26
36
  /** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
27
37
  gatewayKey?: string;
28
38
  /** Supplies a valid bearer token for each request. */
@@ -1536,9 +1546,29 @@ interface BaseAccessServiceConfig {
1536
1546
  jwtSecret: string;
1537
1547
  /** JWT issuer — the app name / app ID. */
1538
1548
  issuer: string;
1539
- /** App ID, used in the gateway endpoint path. */
1540
- appId: string;
1541
- /** Override the gateway base URL. Default: per-service. */
1549
+ /**
1550
+ * The install's **app endpoint URL** — persist the install webhook's `apiUrl`
1551
+ * and pass it here. When set it is used **as given**: for Peek it is the sole
1552
+ * request URL (every call POSTs to it); for CNG/ACME it is the base and the
1553
+ * REST path is appended. No app-id/gateway segment is inserted, so `appId` is
1554
+ * not required. This is the forward-looking way to target an install — prefer
1555
+ * it over `baseUrl`/`appId`, which are deprecated (the hardcoded base-URL
1556
+ * fallbacks will be removed and a URL will become required in a future release).
1557
+ */
1558
+ apiUrl?: string;
1559
+ /**
1560
+ * App ID, inserted into the gateway endpoint path.
1561
+ *
1562
+ * @deprecated Required only in the legacy `baseUrl` mode. Prefer `apiUrl` (the
1563
+ * install's app endpoint), which needs no app-id segment.
1564
+ */
1565
+ appId?: string;
1566
+ /**
1567
+ * Override the gateway base URL. Default: per-service.
1568
+ *
1569
+ * @deprecated Prefer `apiUrl` (the install's app endpoint, used as given). The
1570
+ * hardcoded per-service default will be removed and a URL will become required.
1571
+ */
1542
1572
  baseUrl?: string;
1543
1573
  /** JWT lifetime in seconds. Default: 3600. */
1544
1574
  tokenTtlSeconds?: number;
@@ -2090,12 +2120,22 @@ declare class PeekAccessService {
2090
2120
  }
2091
2121
 
2092
2122
  interface RestClientOptions$1 {
2093
- /** Base URL of the backoffice gateway (no trailing slash). */
2094
- baseUrl: string;
2095
- /** App ID, used in the endpoint path. */
2096
- appId: string;
2097
- /** Fixed extendable slug inserted between `appId` and the REST path. */
2098
- extendableSlug: string;
2123
+ /**
2124
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
2125
+ * is the **base URL** and only the REST path is appended (`apiUrl/path`) —
2126
+ * `baseUrl`/`appId`/`extendableSlug` are ignored. Takes precedence over
2127
+ * `baseUrl`.
2128
+ */
2129
+ apiUrl?: string;
2130
+ /**
2131
+ * Base URL of the backoffice gateway (no trailing slash). Used only when
2132
+ * `apiUrl` is not set; the URL is `baseUrl/appId/extendableSlug/path`.
2133
+ */
2134
+ baseUrl?: string;
2135
+ /** App ID, used in the endpoint path (legacy `baseUrl` mode only). */
2136
+ appId?: string;
2137
+ /** Fixed extendable slug inserted between `appId` and the REST path (legacy mode). */
2138
+ extendableSlug?: string;
2099
2139
  /** Supplies a valid bearer token for each request. */
2100
2140
  getToken: () => string;
2101
2141
  /** Backoff delays (ms) applied on successive HTTP 429 responses. */
@@ -2217,12 +2257,22 @@ declare class CngAccessService {
2217
2257
  }
2218
2258
 
2219
2259
  interface RestClientOptions {
2220
- /** Base URL of the backoffice gateway (no trailing slash). */
2221
- baseUrl: string;
2222
- /** App ID, used in the endpoint path. */
2223
- appId: string;
2224
- /** Fixed extendable slug inserted between `appId` and the REST path. */
2225
- extendableSlug: string;
2260
+ /**
2261
+ * The install's app endpoint URL (the install webhook's `apiUrl`). When set it
2262
+ * is the **base URL** and only the REST path is appended (`apiUrl/path`) —
2263
+ * `baseUrl`/`appId`/`extendableSlug` are ignored. Takes precedence over
2264
+ * `baseUrl`.
2265
+ */
2266
+ apiUrl?: string;
2267
+ /**
2268
+ * Base URL of the backoffice gateway (no trailing slash). Used only when
2269
+ * `apiUrl` is not set; the URL is `baseUrl/appId/extendableSlug/path`.
2270
+ */
2271
+ baseUrl?: string;
2272
+ /** App ID, used in the endpoint path (legacy `baseUrl` mode only). */
2273
+ appId?: string;
2274
+ /** Fixed extendable slug inserted between `appId` and the REST path (legacy mode). */
2275
+ extendableSlug?: string;
2226
2276
  /** Supplies a valid bearer token for each request. */
2227
2277
  getToken: () => string;
2228
2278
  /** Backoff delays (ms) applied on successive HTTP 429 responses. */
@@ -2341,6 +2391,52 @@ declare class AcmeAccessService {
2341
2391
  getAllActivities(): Promise<AcmeActivity[]>;
2342
2392
  }
2343
2393
 
2394
+ /**
2395
+ * Factory that turns a persisted install (or a parsed install webhook) into the
2396
+ * right access service for its platform, wired to the install's own app
2397
+ * endpoint.
2398
+ *
2399
+ * The install webhook is the only source of an install's `platform` and `apiUrl`
2400
+ * (see `src/models/peek/install.ts`), and those two facts are exactly what's
2401
+ * needed to target it: `platform` picks the service class, and `apiUrl` is used
2402
+ * **as given** as that service's endpoint. This helper encodes that mapping so a
2403
+ * consumer that persisted an install can construct its client in one call
2404
+ * instead of switching on the platform and hand-wiring the URL.
2405
+ */
2406
+
2407
+ /**
2408
+ * The per-install facts needed to build an access service — a structural subset
2409
+ * of {@link InstallWebhook}, so a persisted install record (or the webhook event
2410
+ * itself) satisfies it directly.
2411
+ */
2412
+ interface InstallAccessTarget {
2413
+ /** Which platform serves the install (the install webhook's `platform`). */
2414
+ platform: PeekPlatform | null;
2415
+ /** The install's app endpoint URL (the install webhook's `apiUrl`), used as given. */
2416
+ apiUrl: string;
2417
+ /** The install id (the install webhook's `installId`) — becomes the JWT subject. */
2418
+ installId: string;
2419
+ }
2420
+ /**
2421
+ * The per-app credentials/options shared by every access service — everything
2422
+ * except the per-install `installId`/`apiUrl` (supplied by the target) and the
2423
+ * deprecated `appId`/`baseUrl`/`mode` URL controls (superseded by `apiUrl`).
2424
+ * `gatewayKey` is accepted for Peek and ignored by CNG/ACME.
2425
+ */
2426
+ type InstallAccessConfig = Omit<PeekAccessServiceConfig, "installId" | "apiUrl" | "appId" | "baseUrl" | "mode">;
2427
+ /** The union of access services this factory can return, narrowed by `platform`. */
2428
+ type InstallAccessService = PeekAccessService | CngAccessService | AcmeAccessService;
2429
+ /**
2430
+ * Builds the access service for `install.platform`, using `install.apiUrl` as
2431
+ * the service's endpoint. Narrow the return by `install.platform` (or
2432
+ * `instanceof`) to reach a platform-specific surface.
2433
+ *
2434
+ * @throws {Error} when `install.platform` is `null` or unrecognised — an install
2435
+ * with an unknown platform has no service to route to, and silently defaulting
2436
+ * would point it at the wrong gateway.
2437
+ */
2438
+ declare function createAccessServiceForInstall(install: InstallAccessTarget, config: InstallAccessConfig): InstallAccessService;
2439
+
2344
2440
  /**
2345
2441
  * Public webhook surface for bookings.
2346
2442
  *
@@ -2432,16 +2528,24 @@ declare function parseWaiverWebhook(payload: unknown, options?: AccessOptions):
2432
2528
  * POSTs when an app is installed, uninstalled, or updated.
2433
2529
  *
2434
2530
  * That delivery carries two things at once: a **signed `app_registry_v2` JWT**
2435
- * (the security boundary) and a plain **JSON body** (the enrichment channel).
2531
+ * (the security boundary) and a plain **JSON body** (the event payload).
2436
2532
  * `parseInstallWebhook` verifies the JWT and merges both into this shape, so a
2437
2533
  * consumer sees one clean, flat, JSON-safe record instead of two differently
2438
- * shaped payloads. The verified JWT is authoritative for the fields it carries
2439
- * (`installId`, `accountId`, `status`, `displayVersion`, `user`); the JSON body
2440
- * is the only source of `accountName`, `platform`, and `isTest`.
2441
- *
2442
- * It is also the single origin of the account id in the whole system: no
2443
- * GraphQL read returns it, so whatever a consumer persists from this event is
2444
- * all it will ever have.
2534
+ * shaped payloads. The **JSON body is the source of the event data** — it
2535
+ * carries every field below; the verified JWT authenticates the delivery and
2536
+ * acts as the **fallback** for the fields it also happens to carry (`installId`,
2537
+ * `accountId`, `status`, `displayVersion`, `user`) when the body omits them.
2538
+ *
2539
+ * It is also the single origin of the account id (and the `apiUrl`/`timezone`)
2540
+ * in the whole system: no GraphQL read returns them, so whatever a consumer
2541
+ * persists from this event is all it will ever have.
2542
+ *
2543
+ * **Every install event is a full snapshot — upsert by `installId`.** An
2544
+ * `update_installed` event carries the *same complete record* as the original
2545
+ * `installed` event, so treat each delivery as an upsert keyed by `installId`
2546
+ * and overwrite the stored fields with the incoming ones. This is how the
2547
+ * registry pushes changes — e.g. a new `apiUrl` — so a consumer that only reads
2548
+ * the first `installed` event and ignores later updates will keep stale data.
2445
2549
  */
2446
2550
 
2447
2551
  /**
@@ -2460,9 +2564,10 @@ type InstallStatus = (typeof INSTALL_STATUSES)[number];
2460
2564
  * returns is the shape a consumer persists and later rehydrates. There is
2461
2565
  * deliberately no nested identity object and no second representation.
2462
2566
  *
2463
- * Fields sourced from the **verified JWT** (`installId`, `accountId`, `status`,
2464
- * `rawStatus`, `displayVersion`, `user`) are trustworthy; the enrichment fields
2465
- * (`accountName`, `platform`, `isTest`) come from the unauthenticated JSON body.
2567
+ * Every field is read from the **JSON body** first, falling back to the
2568
+ * **verified JWT** for the fields it also carries (`installId`, `accountId`,
2569
+ * `status`, `displayVersion`, `user`). The delivery is authenticated as a whole
2570
+ * by the JWT signature, so the body is trusted within a verified request.
2466
2571
  */
2467
2572
  interface InstallWebhook {
2468
2573
  /** Install ID — Peek-assigned UUID. Also the JWT subject (`sub`). */
@@ -2490,6 +2595,31 @@ interface InstallWebhook {
2490
2595
  platform: PeekPlatform | null;
2491
2596
  /** Whether this is a test account. Defaults to `false` when not reported. */
2492
2597
  isTest: boolean;
2598
+ /**
2599
+ * The account's IANA timezone (e.g. `"America/New_York"`), or `""` when the
2600
+ * body omits it.
2601
+ *
2602
+ * **Persist this per install.** It has no source other than this event, and
2603
+ * downstream date/time handling for the install (scheduling, day boundaries,
2604
+ * display) needs the account's own timezone rather than the server's.
2605
+ */
2606
+ timezone: string;
2607
+ /**
2608
+ * The **app endpoint URL** the registry serves this install from (the body's
2609
+ * `api.url`), or `""` when the body omits it.
2610
+ *
2611
+ * Use it **as given** as the base URL for this install's API calls — do not
2612
+ * decompose it or append your own app id. The registry may tag traffic with an
2613
+ * app id in the path; that is the registry's concern and opaque to callers, so
2614
+ * hit the URL unmodified.
2615
+ *
2616
+ * **Persist this per install, and refresh it on every install event.** It is
2617
+ * install-specific, has no source other than this webhook, and the registry
2618
+ * can change it: an `update_installed` event redelivers the full record with a
2619
+ * (possibly new) `apiUrl`, so re-key by `installId` and overwrite the stored
2620
+ * URL whenever an event arrives.
2621
+ */
2622
+ apiUrl: string;
2493
2623
  /**
2494
2624
  * The lifecycle status, or `null` when the registry sent a status this
2495
2625
  * version of the package does not know. Handle `null` explicitly — treating
@@ -2502,7 +2632,8 @@ interface InstallWebhook {
2502
2632
  displayVersion: string;
2503
2633
  /**
2504
2634
  * The user that triggered the event, or `null` for system-initiated events
2505
- * (install lifecycle changes are often system-initiated). From the JWT.
2635
+ * (install lifecycle changes are often system-initiated). Read from the body's
2636
+ * `modified_by`, falling back to the JWT's `user`.
2506
2637
  */
2507
2638
  user: PeekAuthTokenUser | null;
2508
2639
  }
@@ -2511,12 +2642,14 @@ interface InstallWebhook {
2511
2642
  * Verifies an install-status webhook token and merges it with the delivered
2512
2643
  * JSON body into one flat {@link InstallWebhook}.
2513
2644
  *
2514
- * The **verified token** is the authoritative source of `installId`,
2515
- * `accountId`, `status`, `displayVersion`, and `user`. The **JSON body** — which
2516
- * is not signed and so is trusted only for fields the token cannot carry —
2517
- * supplies `accountName`, `platform`, and `isTest`. A missing or malformed body
2518
- * degrades those three to `""`/`null`/`false`; it never overrides an
2519
- * authenticated field and never throws.
2645
+ * The **JSON body** is the source of the event data — `installId`, `accountId`,
2646
+ * `accountName`, `platform`, `isTest`, `timezone`, `apiUrl`, `status`,
2647
+ * `displayVersion`, and `user`. The **verified token** authenticates the whole
2648
+ * delivery and is the **fallback** for the fields it also carries (`installId`,
2649
+ * `accountId`, `status`, `displayVersion`, `user`) when the body omits them. A
2650
+ * missing or malformed body degrades the body-only fields (`accountName`,
2651
+ * `platform`, `isTest`, `timezone`, `apiUrl`) to `""`/`null`/`false` and leans
2652
+ * on the token for the rest; it never throws.
2520
2653
  *
2521
2654
  * Signature verification is strict: the HMAC signature (with `secret`), the
2522
2655
  * token expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience are
@@ -2697,4 +2830,4 @@ declare class AcmeApiError extends Error {
2697
2830
  constructor(statusCode: number, body: unknown, message?: string);
2698
2831
  }
2699
2832
 
2700
- export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, type AccessOptions, type AccountUser, AccountUserService, type AccountUserServiceOptions, AcmeAccessService, type AcmeAccessServiceConfig, type AcmeActivity, type AcmeActivityTicket, AcmeApiError, AcmeProductService, type Activity, type ActivityOverrides, type ActivityTicket, type AddAddonInput, AdminAccountRequiredError, type Agent, type AssignGuideResult, type AssignedActivity, type AssignedResource, type Availability, AvailabilityService, type AvailabilityTime, type AvailabilityTimesQuery, type Booking, type BookingAddon, type BookingAddonMoney, type BookingAddonOption, type BookingAddons, type BookingAddonsMutationResult, type BookingPaymentsOnFile, type BookingReadOptions, type BookingSearchBy, BookingService, type BookingServiceOptions, type BookingTimeRangeSearch, type CancelBookingResult, type Channel, type ClearOverridesInput, CngAccessService, type CngAccessServiceConfig, CngApiError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, INSTALL_STATUSES, type InstallStatus, type InstallWebhook, type InstallWebhookAccount, type InstallWebhookClaims, InvalidPeekTokenError, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, type PeekAuthTokenClaims, type PeekAuthTokenUser, PeekGraphQLError, PeekHttpError, type PeekPlatform, PiiAccessDisabledError, type Price, type PricingActivityContext, type PricingEngine, type PricingMoney, type PricingNamedRef, type PricingOverride, type PricingOverrideFilter, PricingService, type Product, type ProductMeetingLocation, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RENTAL_PRODUCT_TYPE, RateLimitError, type RefundInput, type RefundResult, ResellerService, type ResolvedOverride, type ResolvedPricingOverride, type ResolvedResourceOption, type Resource, type ResourceOptionOverride, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
2833
+ export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, type AccessOptions, type AccountUser, AccountUserService, type AccountUserServiceOptions, AcmeAccessService, type AcmeAccessServiceConfig, type AcmeActivity, type AcmeActivityTicket, AcmeApiError, AcmeProductService, type Activity, type ActivityOverrides, type ActivityTicket, type AddAddonInput, AdminAccountRequiredError, type Agent, type AssignGuideResult, type AssignedActivity, type AssignedResource, type Availability, AvailabilityService, type AvailabilityTime, type AvailabilityTimesQuery, type Booking, type BookingAddon, type BookingAddonMoney, type BookingAddonOption, type BookingAddons, type BookingAddonsMutationResult, type BookingPaymentsOnFile, type BookingReadOptions, type BookingSearchBy, BookingService, type BookingServiceOptions, type BookingTimeRangeSearch, type CancelBookingResult, type Channel, type ClearOverridesInput, CngAccessService, type CngAccessServiceConfig, CngApiError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, INSTALL_STATUSES, type InstallAccessConfig, type InstallAccessService, type InstallAccessTarget, type InstallStatus, type InstallWebhook, type InstallWebhookAccount, type InstallWebhookClaims, InvalidPeekTokenError, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, type PeekAuthTokenClaims, type PeekAuthTokenUser, PeekGraphQLError, PeekHttpError, type PeekPlatform, PiiAccessDisabledError, type Price, type PricingActivityContext, type PricingEngine, type PricingMoney, type PricingNamedRef, type PricingOverride, type PricingOverrideFilter, PricingService, type Product, type ProductMeetingLocation, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RENTAL_PRODUCT_TYPE, RateLimitError, type RefundInput, type RefundResult, ResellerService, type ResolvedOverride, type ResolvedPricingOverride, type ResolvedResourceOption, type Resource, type ResourceOptionOverride, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };