@peektravel/app-utilities 0.6.0 → 0.6.1

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
@@ -1791,13 +1791,18 @@ declare class PricingService {
1791
1791
  private validateResourceOption;
1792
1792
  }
1793
1793
 
1794
+ /**
1795
+ * Every platform this package knows about. Exported as a value (not just a
1796
+ * union) so runtime code can recognise a reported platform without restating
1797
+ * the list. New platforms extend this array.
1798
+ */
1799
+ declare const PEEK_PLATFORMS: readonly ["peek", "cng", "acme"];
1794
1800
  /**
1795
1801
  * Platform that embedded the app for this session. Verification is
1796
1802
  * brand-agnostic — one peek-auth JWT is minted for every platform — so this
1797
1803
  * claim is the single thing that identifies which platform a request came from.
1798
- * New platforms extend this union.
1799
1804
  */
1800
- type PeekPlatform = "peek" | "cng" | "acme";
1805
+ type PeekPlatform = (typeof PEEK_PLATFORMS)[number];
1801
1806
  /** User context embedded in a Peek auth token. */
1802
1807
  interface PeekAuthTokenUser {
1803
1808
  /** User's email address. */
@@ -1929,10 +1934,13 @@ declare class PeekAccessService {
1929
1934
  * malformed
1930
1935
  * - `TokenExpiredError` — past `exp`
1931
1936
  * - `NotBeforeError` — before `nbf`
1937
+ * - `InvalidPeekTokenError` — signature valid but the `user` block is missing
1938
+ * its `id`
1932
1939
  *
1933
1940
  * @throws {JsonWebTokenError} signature invalid or token malformed
1934
1941
  * @throws {TokenExpiredError} token has expired
1935
1942
  * @throws {NotBeforeError} token not yet valid
1943
+ * @throws {InvalidPeekTokenError} verified token has no `user.id`
1936
1944
  */
1937
1945
  verifyPeekAuthToken(token: string): PeekAuthTokenClaims;
1938
1946
  /**
@@ -2440,6 +2448,128 @@ declare function parseWaiverWebhook(payload: unknown, options?: AccessOptions):
2440
2448
  */
2441
2449
  declare function verifyInstallWebhook(token: string, secret: string): InstallWebhookClaims;
2442
2450
 
2451
+ /**
2452
+ * The clean data model for an app-store **install lifecycle event** — the JSON
2453
+ * webhook body Peek's app registry POSTs when an app is installed, uninstalled,
2454
+ * or updated.
2455
+ *
2456
+ * This is the sibling of the signed-JWT channel behind `verifyInstallWebhook`
2457
+ * (see `models/peek/auth-token.ts`). The two carry the same event; this one is
2458
+ * the richer of the pair, because only it reports the account **name**,
2459
+ * **platform**, and **test** flag.
2460
+ *
2461
+ * It is also the single origin of the account id in the whole system: no
2462
+ * GraphQL read and no peek-auth token returns it, so whatever a consumer
2463
+ * persists from this event is all it will ever have.
2464
+ */
2465
+
2466
+ /**
2467
+ * Every install lifecycle status Peek's app registry sends today. Exported so
2468
+ * consumers can validate or enumerate without restating the vocabulary.
2469
+ */
2470
+ declare const INSTALL_STATUSES: readonly ["installed", "uninstalled", "update_installed"];
2471
+ /** Install lifecycle status. */
2472
+ type InstallStatus = (typeof INSTALL_STATUSES)[number];
2473
+ /**
2474
+ * Who an install is — the core account data, in one object.
2475
+ *
2476
+ * Flat and JSON-safe by design: it round-trips through a datastore unchanged,
2477
+ * so the same shape the parser returns is the shape a consumer persists and
2478
+ * later rehydrates. There is deliberately no second representation.
2479
+ */
2480
+ interface InstallIdentity {
2481
+ /** Install ID — Peek-assigned UUID. Also the subject of every peek-auth JWT. */
2482
+ installId: string;
2483
+ /**
2484
+ * Stable Peek account id — the same value Peek calls the **partner ID**.
2485
+ * This event is its only source; it cannot be re-fetched later.
2486
+ */
2487
+ accountId: string;
2488
+ /** Partner display name. */
2489
+ accountName: string;
2490
+ /**
2491
+ * Which Peek platform owns the install, or `null` when the registry reported
2492
+ * a platform this version of the package does not know. `null` means "newer
2493
+ * than this package", **not** "absent" — do not coerce it to a default.
2494
+ *
2495
+ * **Persist and track this per install.** It is not cosmetic: the platform
2496
+ * determines which APIs the install is served by, and therefore which access
2497
+ * service a consumer must construct for it — `PeekAccessService` for `"peek"`,
2498
+ * `CngAccessService` for `"cng"`, `AcmeAccessService` for `"acme"`, each
2499
+ * routed at a different gateway. Two installs of the same app can sit on
2500
+ * different platforms, so this cannot be inferred from app-level config and
2501
+ * has no source other than this event.
2502
+ */
2503
+ platform: PeekPlatform | null;
2504
+ /** Whether this is a test account. Defaults to `false` when not reported. */
2505
+ isTest: boolean;
2506
+ }
2507
+ /** A parsed install lifecycle event: what happened, to which install. */
2508
+ interface InstallEvent {
2509
+ /**
2510
+ * The lifecycle status, or `null` when the registry sent a status this
2511
+ * version of the package does not know. Handle `null` explicitly — treating
2512
+ * it as a no-op silently drops a lifecycle transition.
2513
+ */
2514
+ status: InstallStatus | null;
2515
+ /** The status exactly as delivered, for logging and for the `null` case. */
2516
+ rawStatus: string;
2517
+ /** App display version at the time of the event. */
2518
+ displayVersion: string;
2519
+ /** The install's core account data. */
2520
+ identity: InstallIdentity;
2521
+ }
2522
+
2523
+ /**
2524
+ * Public webhook surface for the **install-event** channel — the JSON body
2525
+ * Peek's app registry POSTs on install, uninstall, and update.
2526
+ *
2527
+ * This is the second of the two install channels. Its sibling,
2528
+ * `verifyInstallWebhook`, receives the same lifecycle event as a signed
2529
+ * `app_registry_v2` JWT; that payload authenticates itself but carries only the
2530
+ * account **id**. This one carries the account's name, platform, and test flag
2531
+ * as well, which makes it the authoritative source of {@link InstallIdentity}.
2532
+ *
2533
+ * Like the booking and waiver parsers, this is a pure transform — no auth, no
2534
+ * network, no client — so it is a standalone function rather than a method on
2535
+ * `PeekAccessService`. The receiver holds no gateway credentials for an install
2536
+ * it has not recorded yet, and an uninstall describes one being torn down.
2537
+ *
2538
+ * **It never throws.** The sender is first-party and the payload contract is
2539
+ * Peek's own, so defending against malformed input would be defending against a
2540
+ * case that does not arise. What the parser does guard is the contract
2541
+ * *growing*: an unrecognised `status` or `platform` surfaces as `null` rather
2542
+ * than being coerced into a known value, so a newer registry can never be
2543
+ * silently mistaken for an older one.
2544
+ */
2545
+
2546
+ /**
2547
+ * Parses a delivered install-event webhook body into a clean
2548
+ * {@link InstallEvent}.
2549
+ *
2550
+ * Accepts the raw request body, or a JSON string, which is parsed first.
2551
+ * Missing fields map to `""`/`false`; an unknown `status` or `platform` maps to
2552
+ * `null` with the wire value preserved on {@link InstallEvent.rawStatus}.
2553
+ *
2554
+ * Handle a `null` `status` explicitly. Peek treats any 2xx as delivered and
2555
+ * will not redeliver, so responding successfully to a status the package does
2556
+ * not recognise silently drops a lifecycle transition:
2557
+ *
2558
+ * ```ts
2559
+ * const event = parseInstallEvent(req.body);
2560
+ * switch (event.status) {
2561
+ * case "installed": return provision(event.identity, event.displayVersion);
2562
+ * case "uninstalled": return deprovision(event.identity);
2563
+ * case "update_installed": return recordVersion(event.identity, event.displayVersion);
2564
+ * default: throw new Error(`unknown install status: ${event.rawStatus}`);
2565
+ * }
2566
+ * ```
2567
+ *
2568
+ * Persist `event.identity` as a unit: it is flat and JSON-safe, and its
2569
+ * `accountId` (the partner ID) has no other source in the system.
2570
+ */
2571
+ declare function parseInstallEvent(payload: unknown): InstallEvent;
2572
+
2443
2573
  /**
2444
2574
  * Typed errors thrown by the package. Each mirrors a failure mode of the Peek
2445
2575
  * GraphQL gateway (or the CNG REST gateway) so callers can branch on the error
@@ -2498,6 +2628,19 @@ declare class PeekHttpError extends Error {
2498
2628
  readonly body: unknown;
2499
2629
  constructor(statusCode: number, url: string, body: unknown, message?: string);
2500
2630
  }
2631
+ /**
2632
+ * Thrown when an `app_registry_v2` token passes signature/issuer/audience
2633
+ * verification but its `user` block is missing a required `id`. The signature is
2634
+ * authentic, so this signals a structurally malformed token from the app
2635
+ * registry rather than a forged one — distinct from the `jsonwebtoken`
2636
+ * `JsonWebTokenError` family. The offending field is preserved on
2637
+ * {@link InvalidPeekTokenError.field}.
2638
+ */
2639
+ declare class InvalidPeekTokenError extends Error {
2640
+ /** The token field that was missing or empty (e.g. `"user.id"`). */
2641
+ readonly field: string;
2642
+ constructor(field: string);
2643
+ }
2501
2644
  /**
2502
2645
  * Thrown when a payment or booking-modification operation is called on an
2503
2646
  * access service that was constructed without `fullCustomerAccess` (PII access
@@ -2538,4 +2681,4 @@ declare class AcmeApiError extends Error {
2538
2681
  constructor(statusCode: number, body: unknown, message?: string);
2539
2682
  }
2540
2683
 
2541
- 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, type InstallWebhookAccount, type InstallWebhookClaims, 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, parseWaiverWebhook, verifyInstallWebhook };
2684
+ 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 InstallEvent, type InstallIdentity, type InstallStatus, 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, parseInstallEvent, parseWaiverWebhook, verifyInstallWebhook };
package/dist/index.d.ts CHANGED
@@ -1791,13 +1791,18 @@ declare class PricingService {
1791
1791
  private validateResourceOption;
1792
1792
  }
1793
1793
 
1794
+ /**
1795
+ * Every platform this package knows about. Exported as a value (not just a
1796
+ * union) so runtime code can recognise a reported platform without restating
1797
+ * the list. New platforms extend this array.
1798
+ */
1799
+ declare const PEEK_PLATFORMS: readonly ["peek", "cng", "acme"];
1794
1800
  /**
1795
1801
  * Platform that embedded the app for this session. Verification is
1796
1802
  * brand-agnostic — one peek-auth JWT is minted for every platform — so this
1797
1803
  * claim is the single thing that identifies which platform a request came from.
1798
- * New platforms extend this union.
1799
1804
  */
1800
- type PeekPlatform = "peek" | "cng" | "acme";
1805
+ type PeekPlatform = (typeof PEEK_PLATFORMS)[number];
1801
1806
  /** User context embedded in a Peek auth token. */
1802
1807
  interface PeekAuthTokenUser {
1803
1808
  /** User's email address. */
@@ -1929,10 +1934,13 @@ declare class PeekAccessService {
1929
1934
  * malformed
1930
1935
  * - `TokenExpiredError` — past `exp`
1931
1936
  * - `NotBeforeError` — before `nbf`
1937
+ * - `InvalidPeekTokenError` — signature valid but the `user` block is missing
1938
+ * its `id`
1932
1939
  *
1933
1940
  * @throws {JsonWebTokenError} signature invalid or token malformed
1934
1941
  * @throws {TokenExpiredError} token has expired
1935
1942
  * @throws {NotBeforeError} token not yet valid
1943
+ * @throws {InvalidPeekTokenError} verified token has no `user.id`
1936
1944
  */
1937
1945
  verifyPeekAuthToken(token: string): PeekAuthTokenClaims;
1938
1946
  /**
@@ -2440,6 +2448,128 @@ declare function parseWaiverWebhook(payload: unknown, options?: AccessOptions):
2440
2448
  */
2441
2449
  declare function verifyInstallWebhook(token: string, secret: string): InstallWebhookClaims;
2442
2450
 
2451
+ /**
2452
+ * The clean data model for an app-store **install lifecycle event** — the JSON
2453
+ * webhook body Peek's app registry POSTs when an app is installed, uninstalled,
2454
+ * or updated.
2455
+ *
2456
+ * This is the sibling of the signed-JWT channel behind `verifyInstallWebhook`
2457
+ * (see `models/peek/auth-token.ts`). The two carry the same event; this one is
2458
+ * the richer of the pair, because only it reports the account **name**,
2459
+ * **platform**, and **test** flag.
2460
+ *
2461
+ * It is also the single origin of the account id in the whole system: no
2462
+ * GraphQL read and no peek-auth token returns it, so whatever a consumer
2463
+ * persists from this event is all it will ever have.
2464
+ */
2465
+
2466
+ /**
2467
+ * Every install lifecycle status Peek's app registry sends today. Exported so
2468
+ * consumers can validate or enumerate without restating the vocabulary.
2469
+ */
2470
+ declare const INSTALL_STATUSES: readonly ["installed", "uninstalled", "update_installed"];
2471
+ /** Install lifecycle status. */
2472
+ type InstallStatus = (typeof INSTALL_STATUSES)[number];
2473
+ /**
2474
+ * Who an install is — the core account data, in one object.
2475
+ *
2476
+ * Flat and JSON-safe by design: it round-trips through a datastore unchanged,
2477
+ * so the same shape the parser returns is the shape a consumer persists and
2478
+ * later rehydrates. There is deliberately no second representation.
2479
+ */
2480
+ interface InstallIdentity {
2481
+ /** Install ID — Peek-assigned UUID. Also the subject of every peek-auth JWT. */
2482
+ installId: string;
2483
+ /**
2484
+ * Stable Peek account id — the same value Peek calls the **partner ID**.
2485
+ * This event is its only source; it cannot be re-fetched later.
2486
+ */
2487
+ accountId: string;
2488
+ /** Partner display name. */
2489
+ accountName: string;
2490
+ /**
2491
+ * Which Peek platform owns the install, or `null` when the registry reported
2492
+ * a platform this version of the package does not know. `null` means "newer
2493
+ * than this package", **not** "absent" — do not coerce it to a default.
2494
+ *
2495
+ * **Persist and track this per install.** It is not cosmetic: the platform
2496
+ * determines which APIs the install is served by, and therefore which access
2497
+ * service a consumer must construct for it — `PeekAccessService` for `"peek"`,
2498
+ * `CngAccessService` for `"cng"`, `AcmeAccessService` for `"acme"`, each
2499
+ * routed at a different gateway. Two installs of the same app can sit on
2500
+ * different platforms, so this cannot be inferred from app-level config and
2501
+ * has no source other than this event.
2502
+ */
2503
+ platform: PeekPlatform | null;
2504
+ /** Whether this is a test account. Defaults to `false` when not reported. */
2505
+ isTest: boolean;
2506
+ }
2507
+ /** A parsed install lifecycle event: what happened, to which install. */
2508
+ interface InstallEvent {
2509
+ /**
2510
+ * The lifecycle status, or `null` when the registry sent a status this
2511
+ * version of the package does not know. Handle `null` explicitly — treating
2512
+ * it as a no-op silently drops a lifecycle transition.
2513
+ */
2514
+ status: InstallStatus | null;
2515
+ /** The status exactly as delivered, for logging and for the `null` case. */
2516
+ rawStatus: string;
2517
+ /** App display version at the time of the event. */
2518
+ displayVersion: string;
2519
+ /** The install's core account data. */
2520
+ identity: InstallIdentity;
2521
+ }
2522
+
2523
+ /**
2524
+ * Public webhook surface for the **install-event** channel — the JSON body
2525
+ * Peek's app registry POSTs on install, uninstall, and update.
2526
+ *
2527
+ * This is the second of the two install channels. Its sibling,
2528
+ * `verifyInstallWebhook`, receives the same lifecycle event as a signed
2529
+ * `app_registry_v2` JWT; that payload authenticates itself but carries only the
2530
+ * account **id**. This one carries the account's name, platform, and test flag
2531
+ * as well, which makes it the authoritative source of {@link InstallIdentity}.
2532
+ *
2533
+ * Like the booking and waiver parsers, this is a pure transform — no auth, no
2534
+ * network, no client — so it is a standalone function rather than a method on
2535
+ * `PeekAccessService`. The receiver holds no gateway credentials for an install
2536
+ * it has not recorded yet, and an uninstall describes one being torn down.
2537
+ *
2538
+ * **It never throws.** The sender is first-party and the payload contract is
2539
+ * Peek's own, so defending against malformed input would be defending against a
2540
+ * case that does not arise. What the parser does guard is the contract
2541
+ * *growing*: an unrecognised `status` or `platform` surfaces as `null` rather
2542
+ * than being coerced into a known value, so a newer registry can never be
2543
+ * silently mistaken for an older one.
2544
+ */
2545
+
2546
+ /**
2547
+ * Parses a delivered install-event webhook body into a clean
2548
+ * {@link InstallEvent}.
2549
+ *
2550
+ * Accepts the raw request body, or a JSON string, which is parsed first.
2551
+ * Missing fields map to `""`/`false`; an unknown `status` or `platform` maps to
2552
+ * `null` with the wire value preserved on {@link InstallEvent.rawStatus}.
2553
+ *
2554
+ * Handle a `null` `status` explicitly. Peek treats any 2xx as delivered and
2555
+ * will not redeliver, so responding successfully to a status the package does
2556
+ * not recognise silently drops a lifecycle transition:
2557
+ *
2558
+ * ```ts
2559
+ * const event = parseInstallEvent(req.body);
2560
+ * switch (event.status) {
2561
+ * case "installed": return provision(event.identity, event.displayVersion);
2562
+ * case "uninstalled": return deprovision(event.identity);
2563
+ * case "update_installed": return recordVersion(event.identity, event.displayVersion);
2564
+ * default: throw new Error(`unknown install status: ${event.rawStatus}`);
2565
+ * }
2566
+ * ```
2567
+ *
2568
+ * Persist `event.identity` as a unit: it is flat and JSON-safe, and its
2569
+ * `accountId` (the partner ID) has no other source in the system.
2570
+ */
2571
+ declare function parseInstallEvent(payload: unknown): InstallEvent;
2572
+
2443
2573
  /**
2444
2574
  * Typed errors thrown by the package. Each mirrors a failure mode of the Peek
2445
2575
  * GraphQL gateway (or the CNG REST gateway) so callers can branch on the error
@@ -2498,6 +2628,19 @@ declare class PeekHttpError extends Error {
2498
2628
  readonly body: unknown;
2499
2629
  constructor(statusCode: number, url: string, body: unknown, message?: string);
2500
2630
  }
2631
+ /**
2632
+ * Thrown when an `app_registry_v2` token passes signature/issuer/audience
2633
+ * verification but its `user` block is missing a required `id`. The signature is
2634
+ * authentic, so this signals a structurally malformed token from the app
2635
+ * registry rather than a forged one — distinct from the `jsonwebtoken`
2636
+ * `JsonWebTokenError` family. The offending field is preserved on
2637
+ * {@link InvalidPeekTokenError.field}.
2638
+ */
2639
+ declare class InvalidPeekTokenError extends Error {
2640
+ /** The token field that was missing or empty (e.g. `"user.id"`). */
2641
+ readonly field: string;
2642
+ constructor(field: string);
2643
+ }
2501
2644
  /**
2502
2645
  * Thrown when a payment or booking-modification operation is called on an
2503
2646
  * access service that was constructed without `fullCustomerAccess` (PII access
@@ -2538,4 +2681,4 @@ declare class AcmeApiError extends Error {
2538
2681
  constructor(statusCode: number, body: unknown, message?: string);
2539
2682
  }
2540
2683
 
2541
- 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, type InstallWebhookAccount, type InstallWebhookClaims, 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, parseWaiverWebhook, verifyInstallWebhook };
2684
+ 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 InstallEvent, type InstallIdentity, type InstallStatus, 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, parseInstallEvent, parseWaiverWebhook, verifyInstallWebhook };
package/dist/index.js CHANGED
@@ -225,6 +225,15 @@ var PeekHttpError = class extends Error {
225
225
  this.body = body;
226
226
  }
227
227
  };
228
+ var InvalidPeekTokenError = class extends Error {
229
+ /** The token field that was missing or empty (e.g. `"user.id"`). */
230
+ field;
231
+ constructor(field) {
232
+ super(`Peek token is missing required field "${field}"`);
233
+ this.name = "InvalidPeekTokenError";
234
+ this.field = field;
235
+ }
236
+ };
228
237
  var PiiAccessDisabledError = class extends Error {
229
238
  /** The name of the operation that was blocked (e.g. `"makePayment"`). */
230
239
  operation;
@@ -2037,6 +2046,9 @@ function verifyPeekJwt(token, secret) {
2037
2046
  });
2038
2047
  }
2039
2048
  function mapPeekTokenUser(u) {
2049
+ if (!u.id) {
2050
+ throw new InvalidPeekTokenError("user.id");
2051
+ }
2040
2052
  return {
2041
2053
  email: u.email,
2042
2054
  id: u.id,
@@ -3560,10 +3572,13 @@ var PeekAccessService = class {
3560
3572
  * malformed
3561
3573
  * - `TokenExpiredError` — past `exp`
3562
3574
  * - `NotBeforeError` — before `nbf`
3575
+ * - `InvalidPeekTokenError` — signature valid but the `user` block is missing
3576
+ * its `id`
3563
3577
  *
3564
3578
  * @throws {JsonWebTokenError} signature invalid or token malformed
3565
3579
  * @throws {TokenExpiredError} token has expired
3566
3580
  * @throws {NotBeforeError} token not yet valid
3581
+ * @throws {InvalidPeekTokenError} verified token has no `user.id`
3567
3582
  */
3568
3583
  verifyPeekAuthToken(token) {
3569
3584
  const payload = verifyPeekJwt(token, this.jwtSecret);
@@ -4246,6 +4261,61 @@ function verifyInstallWebhook(token, secret) {
4246
4261
  };
4247
4262
  }
4248
4263
 
4249
- export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngProductService, DailyNoteService, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, noopLogger, parseBookingWebhook, parseWaiverWebhook, verifyInstallWebhook };
4264
+ // src/models/peek/auth-token.ts
4265
+ var PEEK_PLATFORMS = ["peek", "cng", "acme"];
4266
+
4267
+ // src/models/peek/install.ts
4268
+ var INSTALL_STATUSES = [
4269
+ "installed",
4270
+ "uninstalled",
4271
+ "update_installed"
4272
+ ];
4273
+
4274
+ // src/internal/peek/installs/install-converter.ts
4275
+ function toInstallStatus(raw) {
4276
+ return INSTALL_STATUSES.includes(raw) ? raw : null;
4277
+ }
4278
+ function toPeekPlatform(raw) {
4279
+ return PEEK_PLATFORMS.includes(raw) ? raw : null;
4280
+ }
4281
+ function fromInstallIdentityNode(node) {
4282
+ const data = node ?? {};
4283
+ const account = data.account ?? {};
4284
+ return {
4285
+ installId: data.install_id || "",
4286
+ accountId: account.id || "",
4287
+ accountName: account.name || "",
4288
+ platform: toPeekPlatform(account.platform || ""),
4289
+ isTest: Boolean(account.is_test)
4290
+ };
4291
+ }
4292
+ function fromInstallEventNode(node) {
4293
+ const rawStatus = node?.status || "";
4294
+ return {
4295
+ status: toInstallStatus(rawStatus),
4296
+ rawStatus,
4297
+ displayVersion: node?.display_version || "",
4298
+ identity: fromInstallIdentityNode(node)
4299
+ };
4300
+ }
4301
+
4302
+ // src/internal/peek/installs/install-event.ts
4303
+ function parseInstallEvent(payload) {
4304
+ return fromInstallEventNode(extractInstallEventNode(payload));
4305
+ }
4306
+ function extractInstallEventNode(payload) {
4307
+ let body = payload;
4308
+ if (typeof body === "string") {
4309
+ try {
4310
+ body = JSON.parse(body);
4311
+ } catch {
4312
+ return {};
4313
+ }
4314
+ }
4315
+ if (!body || typeof body !== "object") return {};
4316
+ return body;
4317
+ }
4318
+
4319
+ export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngProductService, DailyNoteService, INSTALL_STATUSES, InvalidPeekTokenError, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, noopLogger, parseBookingWebhook, parseInstallEvent, parseWaiverWebhook, verifyInstallWebhook };
4250
4320
  //# sourceMappingURL=index.js.map
4251
4321
  //# sourceMappingURL=index.js.map