@peektravel/app-utilities 1.0.0 → 1.1.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/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
+ import jwt from 'jsonwebtoken';
2
+
1
3
  /**
2
4
  * A platform's tiny map of **API endpoint key → relative path** (the "slug"
3
5
  * inserted between the install's base API URL and the endpoint's own path).
@@ -1266,21 +1268,36 @@ interface InvoiceLinkResult {
1266
1268
  }
1267
1269
 
1268
1270
  /**
1269
- * Clean, public data models for a booking's add-ons.
1271
+ * A monetary value as returned by the Peek gateway, shared across services and
1272
+ * resources (booking add-ons, availability prices, …).
1270
1273
  *
1271
- * These are the only add-on shapes a consumer sees. The detailed per-option
1272
- * model used to build add/cancel mutations (refids, reservation statuses) is
1273
- * an internal implementation detail and is intentionally not exported.
1274
+ * `amount` is intentionally a **string** (e.g. `"50.00"`), never a number — the
1275
+ * gateway returns stringly-typed money to avoid floating-point precision loss.
1274
1276
  */
1275
- /** Money amount for an add-on line, as returned by the gateway. */
1276
- interface BookingAddonMoney {
1277
- /** Numeric amount as a string (e.g. `"10.00"`). */
1277
+ interface Money {
1278
+ /** Numeric amount as a decimal string (e.g. `"50.00"`). */
1278
1279
  amount: string;
1279
- /** ISO currency code (e.g. `"USD"`). */
1280
+ /** ISO 4217 currency code (e.g. `"USD"`). */
1280
1281
  currency: string;
1281
- /** Human-formatted amount (e.g. `"$10.00"`). */
1282
+ /** Human-formatted amount (e.g. `"$50.00"`). */
1282
1283
  formatted: string;
1283
1284
  }
1285
+
1286
+ /**
1287
+ * Clean, public data models for a booking's add-ons.
1288
+ *
1289
+ * These are the only add-on shapes a consumer sees. The detailed per-option
1290
+ * model used to build add/cancel mutations (refids, reservation statuses) is
1291
+ * an internal implementation detail and is intentionally not exported.
1292
+ */
1293
+
1294
+ /**
1295
+ * Money amount for an add-on line, as returned by the gateway.
1296
+ *
1297
+ * @deprecated Use the shared {@link Money} model instead. Retained as an alias
1298
+ * for backwards compatibility.
1299
+ */
1300
+ type BookingAddonMoney = Money;
1284
1301
  /** A single add-on option with the quantity attached to the booking. */
1285
1302
  interface BookingAddonOption {
1286
1303
  /** The item option id (`itemOptionSnapshot.id`). */
@@ -1297,7 +1314,7 @@ interface BookingAddon {
1297
1314
  /** The add-on item name (`itemSnapshot.name`). */
1298
1315
  addonName: string;
1299
1316
  /** The booking line-item total for this add-on, when present. */
1300
- total: BookingAddonMoney | null;
1317
+ total: Money | null;
1301
1318
  /** Live options on this add-on, combined by option id with a count. */
1302
1319
  addonOptions: BookingAddonOption[];
1303
1320
  }
@@ -1658,6 +1675,7 @@ interface PurchasedMembership {
1658
1675
  * a given activity and date, each carrying its per-resource-option availability
1659
1676
  * so callers can decide whether a requested party fits.
1660
1677
  */
1678
+
1661
1679
  /**
1662
1680
  * A single bookable availability time slot for an activity.
1663
1681
  *
@@ -1677,6 +1695,15 @@ interface AvailabilityTime {
1677
1695
  duration: Duration;
1678
1696
  /** Availability status reported by Peek (e.g. open/closed/sold-out). */
1679
1697
  status: string;
1698
+ /**
1699
+ * Minimum number of tickets required to book this slot.
1700
+ *
1701
+ * Normalized: a raw value of `0` (no minimum) is reported as `1`, so callers
1702
+ * can always treat it as the smallest bookable party size.
1703
+ */
1704
+ minimumTicketsRequired: number;
1705
+ /** Per-ticket price for the slot, when reported by Peek. */
1706
+ price: Money | null;
1680
1707
  /**
1681
1708
  * Remaining availability broken down per resource option. One entry per
1682
1709
  * resource option offered for the slot.
@@ -3207,14 +3234,20 @@ interface InstallWebhook {
3207
3234
  * Verifies an install-status webhook token and merges it with the delivered
3208
3235
  * JSON body into one flat {@link InstallWebhook}.
3209
3236
  *
3210
- * The **JSON body** is the source of the event data — `installId`, `accountId`,
3237
+ * `installId` is **always the token `sub`**. The body `install_id` never sets
3238
+ * it: when the body carries a non-empty `install_id` that is not equal to `sub`,
3239
+ * this throws {@link InstallWebhookError} (`reason: "install_id_mismatch"`); a
3240
+ * body without `install_id` parses normally. A verified token with no `sub`
3241
+ * throws {@link InstallWebhookError} (`reason: "missing_subject"`).
3242
+ *
3243
+ * The **JSON body** is the source of the other event data — `accountId`,
3211
3244
  * `accountName`, `platform`, `isTest`, `timezone`, `apiUrl`, `status`,
3212
- * `displayVersion`, and `user`. The **verified token** authenticates the whole
3213
- * delivery and is the **fallback** for the fields it also carries (`installId`,
3214
- * `accountId`, `status`, `displayVersion`, `user`) when the body omits them. A
3215
- * missing or malformed body degrades the body-only fields (`accountName`,
3216
- * `platform`, `isTest`, `timezone`, `apiUrl`) to `""`/`null`/`false` and leans
3217
- * on the token for the rest; it never throws.
3245
+ * `displayVersion`, and `user`. The **verified token** is the **fallback** for
3246
+ * the fields it also carries (`accountId`, `status`, `displayVersion`, `user`)
3247
+ * when the body omits them. A missing or malformed body degrades the body-only
3248
+ * fields (`accountName`, `platform`, `isTest`, `timezone`, `apiUrl`) to
3249
+ * `""`/`null`/`false` and leans on the token for the rest; it does not throw
3250
+ * for that.
3218
3251
  *
3219
3252
  * Signature verification is strict: the HMAC signature (with `secret`), the
3220
3253
  * token expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience are
@@ -3226,6 +3259,11 @@ interface InstallWebhook {
3226
3259
  * - `TokenExpiredError` — past `exp`
3227
3260
  * - `NotBeforeError` — before `nbf`
3228
3261
  *
3262
+ * A validly signed token that does not match the body throws
3263
+ * {@link InstallWebhookError} (see above). It extends `JsonWebTokenError`, so
3264
+ * an `instanceof JsonWebTokenError` check also matches it. Treat every throw as
3265
+ * a rejected delivery (respond `401`).
3266
+ *
3229
3267
  * An unrecognised `status` or `platform` maps to `null` (with the wire status
3230
3268
  * preserved on {@link InstallWebhook.rawStatus}) rather than being coerced —
3231
3269
  * Peek treats any 2xx as delivered and does not redeliver, so handle a `null`
@@ -3250,6 +3288,8 @@ interface InstallWebhook {
3250
3288
  * @throws {JsonWebTokenError} signature invalid or token malformed
3251
3289
  * @throws {TokenExpiredError} token has expired
3252
3290
  * @throws {NotBeforeError} token not yet valid
3291
+ * @throws {InstallWebhookError} token has no `sub`, or the body `install_id`
3292
+ * is not equal to it
3253
3293
  */
3254
3294
  declare function parseInstallWebhook(token: string, body: unknown, secret: string): InstallWebhook;
3255
3295
  /**
@@ -3284,6 +3324,17 @@ declare function parseInstallWebhook(token: string, body: unknown, secret: strin
3284
3324
  */
3285
3325
  declare function verifyInstallWebhook(token: string, secret: string): InstallWebhookClaims;
3286
3326
 
3327
+ /**
3328
+ * Typed errors thrown by the package. Each mirrors a failure mode of the Peek
3329
+ * GraphQL gateway (or the CNG REST gateway) so callers can branch on the error
3330
+ * type rather than parsing messages.
3331
+ *
3332
+ * `AdminAccountRequiredError` and `RateLimitError` are shared by all gateways.
3333
+ * `PeekGraphQLError` is Peek-only; `CngApiError` and `CngPermissionError` are
3334
+ * CNG-only; `AcmeApiError` is ACME-only. `InstallWebhookError` is thrown by
3335
+ * `parseInstallWebhook` and extends `jsonwebtoken`'s `JsonWebTokenError`.
3336
+ */
3337
+
3287
3338
  /**
3288
3339
  * Thrown when the gateway responds with HTTP 418, indicating the install is not
3289
3340
  * permitted to perform the request because an admin account is required.
@@ -3398,5 +3449,20 @@ declare class AcmeApiError extends Error {
3398
3449
  readonly body: unknown;
3399
3450
  constructor(statusCode: number, body: unknown, message?: string);
3400
3451
  }
3452
+ /** Why {@link InstallWebhookError} was thrown. */
3453
+ type InstallWebhookErrorReason = "install_id_mismatch" | "missing_subject";
3454
+ /**
3455
+ * Thrown by `parseInstallWebhook` when the token signature is valid but the
3456
+ * delivery does not name one install: the token has no `sub`, or the body
3457
+ * `install_id` is present and is not equal to the token `sub`. The cause is on
3458
+ * {@link InstallWebhookError.reason}. It extends `JsonWebTokenError` from
3459
+ * `jsonwebtoken`, so a handler that already treats `JsonWebTokenError` as a
3460
+ * failed token check (respond `401`) handles it with no change.
3461
+ */
3462
+ declare class InstallWebhookError extends jwt.JsonWebTokenError {
3463
+ /** Why the delivery was rejected. */
3464
+ readonly reason: InstallWebhookErrorReason;
3465
+ constructor(reason: InstallWebhookErrorReason);
3466
+ }
3401
3467
 
3402
- 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, CngPermissionError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestion, type CustomQuestionAnswer, type CustomQuestionAnswerInput, type CustomQuestionOption, CustomQuestionService, 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, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type MetaData, type MetaDataBarcodeType, type MetaDataDurationUnit, type MetaDataValue, type MetaDataVolumeUnit, type MetaDataWeightUnit, 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, type ProductReviewSummary, 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 SetMetaDataAttachmentInput, type SetMetaDataGuestInput, type SetMetaDataResult, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
3468
+ 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, CngPermissionError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestion, type CustomQuestionAnswer, type CustomQuestionAnswerInput, type CustomQuestionOption, CustomQuestionService, 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, InstallWebhookError, type InstallWebhookErrorReason, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type MetaData, type MetaDataBarcodeType, type MetaDataDurationUnit, type MetaDataValue, type MetaDataVolumeUnit, type MetaDataWeightUnit, type Money, 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, type ProductReviewSummary, 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 SetMetaDataAttachmentInput, type SetMetaDataGuestInput, type SetMetaDataResult, 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
@@ -1,3 +1,5 @@
1
+ import jwt from 'jsonwebtoken';
2
+
1
3
  /**
2
4
  * A platform's tiny map of **API endpoint key → relative path** (the "slug"
3
5
  * inserted between the install's base API URL and the endpoint's own path).
@@ -1266,21 +1268,36 @@ interface InvoiceLinkResult {
1266
1268
  }
1267
1269
 
1268
1270
  /**
1269
- * Clean, public data models for a booking's add-ons.
1271
+ * A monetary value as returned by the Peek gateway, shared across services and
1272
+ * resources (booking add-ons, availability prices, …).
1270
1273
  *
1271
- * These are the only add-on shapes a consumer sees. The detailed per-option
1272
- * model used to build add/cancel mutations (refids, reservation statuses) is
1273
- * an internal implementation detail and is intentionally not exported.
1274
+ * `amount` is intentionally a **string** (e.g. `"50.00"`), never a number — the
1275
+ * gateway returns stringly-typed money to avoid floating-point precision loss.
1274
1276
  */
1275
- /** Money amount for an add-on line, as returned by the gateway. */
1276
- interface BookingAddonMoney {
1277
- /** Numeric amount as a string (e.g. `"10.00"`). */
1277
+ interface Money {
1278
+ /** Numeric amount as a decimal string (e.g. `"50.00"`). */
1278
1279
  amount: string;
1279
- /** ISO currency code (e.g. `"USD"`). */
1280
+ /** ISO 4217 currency code (e.g. `"USD"`). */
1280
1281
  currency: string;
1281
- /** Human-formatted amount (e.g. `"$10.00"`). */
1282
+ /** Human-formatted amount (e.g. `"$50.00"`). */
1282
1283
  formatted: string;
1283
1284
  }
1285
+
1286
+ /**
1287
+ * Clean, public data models for a booking's add-ons.
1288
+ *
1289
+ * These are the only add-on shapes a consumer sees. The detailed per-option
1290
+ * model used to build add/cancel mutations (refids, reservation statuses) is
1291
+ * an internal implementation detail and is intentionally not exported.
1292
+ */
1293
+
1294
+ /**
1295
+ * Money amount for an add-on line, as returned by the gateway.
1296
+ *
1297
+ * @deprecated Use the shared {@link Money} model instead. Retained as an alias
1298
+ * for backwards compatibility.
1299
+ */
1300
+ type BookingAddonMoney = Money;
1284
1301
  /** A single add-on option with the quantity attached to the booking. */
1285
1302
  interface BookingAddonOption {
1286
1303
  /** The item option id (`itemOptionSnapshot.id`). */
@@ -1297,7 +1314,7 @@ interface BookingAddon {
1297
1314
  /** The add-on item name (`itemSnapshot.name`). */
1298
1315
  addonName: string;
1299
1316
  /** The booking line-item total for this add-on, when present. */
1300
- total: BookingAddonMoney | null;
1317
+ total: Money | null;
1301
1318
  /** Live options on this add-on, combined by option id with a count. */
1302
1319
  addonOptions: BookingAddonOption[];
1303
1320
  }
@@ -1658,6 +1675,7 @@ interface PurchasedMembership {
1658
1675
  * a given activity and date, each carrying its per-resource-option availability
1659
1676
  * so callers can decide whether a requested party fits.
1660
1677
  */
1678
+
1661
1679
  /**
1662
1680
  * A single bookable availability time slot for an activity.
1663
1681
  *
@@ -1677,6 +1695,15 @@ interface AvailabilityTime {
1677
1695
  duration: Duration;
1678
1696
  /** Availability status reported by Peek (e.g. open/closed/sold-out). */
1679
1697
  status: string;
1698
+ /**
1699
+ * Minimum number of tickets required to book this slot.
1700
+ *
1701
+ * Normalized: a raw value of `0` (no minimum) is reported as `1`, so callers
1702
+ * can always treat it as the smallest bookable party size.
1703
+ */
1704
+ minimumTicketsRequired: number;
1705
+ /** Per-ticket price for the slot, when reported by Peek. */
1706
+ price: Money | null;
1680
1707
  /**
1681
1708
  * Remaining availability broken down per resource option. One entry per
1682
1709
  * resource option offered for the slot.
@@ -3207,14 +3234,20 @@ interface InstallWebhook {
3207
3234
  * Verifies an install-status webhook token and merges it with the delivered
3208
3235
  * JSON body into one flat {@link InstallWebhook}.
3209
3236
  *
3210
- * The **JSON body** is the source of the event data — `installId`, `accountId`,
3237
+ * `installId` is **always the token `sub`**. The body `install_id` never sets
3238
+ * it: when the body carries a non-empty `install_id` that is not equal to `sub`,
3239
+ * this throws {@link InstallWebhookError} (`reason: "install_id_mismatch"`); a
3240
+ * body without `install_id` parses normally. A verified token with no `sub`
3241
+ * throws {@link InstallWebhookError} (`reason: "missing_subject"`).
3242
+ *
3243
+ * The **JSON body** is the source of the other event data — `accountId`,
3211
3244
  * `accountName`, `platform`, `isTest`, `timezone`, `apiUrl`, `status`,
3212
- * `displayVersion`, and `user`. The **verified token** authenticates the whole
3213
- * delivery and is the **fallback** for the fields it also carries (`installId`,
3214
- * `accountId`, `status`, `displayVersion`, `user`) when the body omits them. A
3215
- * missing or malformed body degrades the body-only fields (`accountName`,
3216
- * `platform`, `isTest`, `timezone`, `apiUrl`) to `""`/`null`/`false` and leans
3217
- * on the token for the rest; it never throws.
3245
+ * `displayVersion`, and `user`. The **verified token** is the **fallback** for
3246
+ * the fields it also carries (`accountId`, `status`, `displayVersion`, `user`)
3247
+ * when the body omits them. A missing or malformed body degrades the body-only
3248
+ * fields (`accountName`, `platform`, `isTest`, `timezone`, `apiUrl`) to
3249
+ * `""`/`null`/`false` and leans on the token for the rest; it does not throw
3250
+ * for that.
3218
3251
  *
3219
3252
  * Signature verification is strict: the HMAC signature (with `secret`), the
3220
3253
  * token expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience are
@@ -3226,6 +3259,11 @@ interface InstallWebhook {
3226
3259
  * - `TokenExpiredError` — past `exp`
3227
3260
  * - `NotBeforeError` — before `nbf`
3228
3261
  *
3262
+ * A validly signed token that does not match the body throws
3263
+ * {@link InstallWebhookError} (see above). It extends `JsonWebTokenError`, so
3264
+ * an `instanceof JsonWebTokenError` check also matches it. Treat every throw as
3265
+ * a rejected delivery (respond `401`).
3266
+ *
3229
3267
  * An unrecognised `status` or `platform` maps to `null` (with the wire status
3230
3268
  * preserved on {@link InstallWebhook.rawStatus}) rather than being coerced —
3231
3269
  * Peek treats any 2xx as delivered and does not redeliver, so handle a `null`
@@ -3250,6 +3288,8 @@ interface InstallWebhook {
3250
3288
  * @throws {JsonWebTokenError} signature invalid or token malformed
3251
3289
  * @throws {TokenExpiredError} token has expired
3252
3290
  * @throws {NotBeforeError} token not yet valid
3291
+ * @throws {InstallWebhookError} token has no `sub`, or the body `install_id`
3292
+ * is not equal to it
3253
3293
  */
3254
3294
  declare function parseInstallWebhook(token: string, body: unknown, secret: string): InstallWebhook;
3255
3295
  /**
@@ -3284,6 +3324,17 @@ declare function parseInstallWebhook(token: string, body: unknown, secret: strin
3284
3324
  */
3285
3325
  declare function verifyInstallWebhook(token: string, secret: string): InstallWebhookClaims;
3286
3326
 
3327
+ /**
3328
+ * Typed errors thrown by the package. Each mirrors a failure mode of the Peek
3329
+ * GraphQL gateway (or the CNG REST gateway) so callers can branch on the error
3330
+ * type rather than parsing messages.
3331
+ *
3332
+ * `AdminAccountRequiredError` and `RateLimitError` are shared by all gateways.
3333
+ * `PeekGraphQLError` is Peek-only; `CngApiError` and `CngPermissionError` are
3334
+ * CNG-only; `AcmeApiError` is ACME-only. `InstallWebhookError` is thrown by
3335
+ * `parseInstallWebhook` and extends `jsonwebtoken`'s `JsonWebTokenError`.
3336
+ */
3337
+
3287
3338
  /**
3288
3339
  * Thrown when the gateway responds with HTTP 418, indicating the install is not
3289
3340
  * permitted to perform the request because an admin account is required.
@@ -3398,5 +3449,20 @@ declare class AcmeApiError extends Error {
3398
3449
  readonly body: unknown;
3399
3450
  constructor(statusCode: number, body: unknown, message?: string);
3400
3451
  }
3452
+ /** Why {@link InstallWebhookError} was thrown. */
3453
+ type InstallWebhookErrorReason = "install_id_mismatch" | "missing_subject";
3454
+ /**
3455
+ * Thrown by `parseInstallWebhook` when the token signature is valid but the
3456
+ * delivery does not name one install: the token has no `sub`, or the body
3457
+ * `install_id` is present and is not equal to the token `sub`. The cause is on
3458
+ * {@link InstallWebhookError.reason}. It extends `JsonWebTokenError` from
3459
+ * `jsonwebtoken`, so a handler that already treats `JsonWebTokenError` as a
3460
+ * failed token check (respond `401`) handles it with no change.
3461
+ */
3462
+ declare class InstallWebhookError extends jwt.JsonWebTokenError {
3463
+ /** Why the delivery was rejected. */
3464
+ readonly reason: InstallWebhookErrorReason;
3465
+ constructor(reason: InstallWebhookErrorReason);
3466
+ }
3401
3467
 
3402
- 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, CngPermissionError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestion, type CustomQuestionAnswer, type CustomQuestionAnswerInput, type CustomQuestionOption, CustomQuestionService, 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, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type MetaData, type MetaDataBarcodeType, type MetaDataDurationUnit, type MetaDataValue, type MetaDataVolumeUnit, type MetaDataWeightUnit, 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, type ProductReviewSummary, 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 SetMetaDataAttachmentInput, type SetMetaDataGuestInput, type SetMetaDataResult, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateEngineInput, type UpdateTimeslotResult, type UpsertOverridesInput, type UpsertOverridesResult, type Waiver, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
3468
+ 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, CngPermissionError, CngProductService, type CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreateEngineInput, type CreatePromoCodeInput, type CreatedBooking, type CreatedPricingEngine, type CreatedPromoCode, type CustomQuestion, type CustomQuestionAnswer, type CustomQuestionAnswerInput, type CustomQuestionOption, CustomQuestionService, 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, InstallWebhookError, type InstallWebhookErrorReason, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type MetaData, type MetaDataBarcodeType, type MetaDataDurationUnit, type MetaDataValue, type MetaDataVolumeUnit, type MetaDataWeightUnit, type Money, 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, type ProductReviewSummary, 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 SetMetaDataAttachmentInput, type SetMetaDataGuestInput, type SetMetaDataResult, 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.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import * as jwt from 'jsonwebtoken';
3
+ import jwt__default from 'jsonwebtoken';
3
4
 
4
5
  // src/internal/api-endpoints.ts
5
6
  var ApiEndpoints = class {
@@ -169,6 +170,12 @@ var AVAILABILITY_TIMES_QUERY = `
169
170
  }
170
171
  }
171
172
  status
173
+ minimumTicketsRequired
174
+ price {
175
+ amount
176
+ currency
177
+ formatted
178
+ }
172
179
  availability {
173
180
  qty
174
181
  taken
@@ -178,6 +185,24 @@ var AVAILABILITY_TIMES_QUERY = `
178
185
  }
179
186
  `;
180
187
 
188
+ // src/internal/peek/availability/availability-converter.ts
189
+ var DEFAULT_MINIMUM_TICKETS = 1;
190
+ function toAvailabilityTime(node) {
191
+ const rawMinimum = node.minimumTicketsRequired;
192
+ const minimumTicketsRequired = typeof rawMinimum === "number" && rawMinimum > 0 ? rawMinimum : DEFAULT_MINIMUM_TICKETS;
193
+ return {
194
+ id: node.id,
195
+ time: node.time,
196
+ from: node.from,
197
+ end: node.end,
198
+ duration: node.duration,
199
+ status: node.status,
200
+ minimumTicketsRequired,
201
+ price: node.price ?? null,
202
+ availability: node.availability ?? []
203
+ };
204
+ }
205
+
181
206
  // src/internal/peek/availability/availability-service.ts
182
207
  var AvailabilityService = class {
183
208
  constructor(client) {
@@ -195,7 +220,7 @@ var AvailabilityService = class {
195
220
  date: query.date
196
221
  }
197
222
  );
198
- return body.data?.availabilityTimes ?? [];
223
+ return (body.data?.availabilityTimes ?? []).map(toAvailabilityTime);
199
224
  }
200
225
  };
201
226
 
@@ -203,8 +228,6 @@ var AvailabilityService = class {
203
228
  function resolveAccessOptions(options) {
204
229
  return { fullCustomerAccess: options?.fullCustomerAccess ?? false };
205
230
  }
206
-
207
- // src/errors.ts
208
231
  var FORBIDDEN_STATUS = 403;
209
232
  var PERMISSION_MESSAGE_PREFIX = "CNG request forbidden: the app is missing the required permission";
210
233
  var PERMISSION_MESSAGE_UNKNOWN = "CNG request forbidden: the app is missing a required permission";
@@ -304,6 +327,21 @@ var AcmeApiError = class extends Error {
304
327
  this.body = body;
305
328
  }
306
329
  };
330
+ var INSTALL_WEBHOOK_INSTALL_ID_MISMATCH = "install_id_mismatch";
331
+ var INSTALL_WEBHOOK_MISSING_SUBJECT = "missing_subject";
332
+ var INSTALL_WEBHOOK_MESSAGES = {
333
+ [INSTALL_WEBHOOK_INSTALL_ID_MISMATCH]: "Install webhook body install_id does not match the token subject",
334
+ [INSTALL_WEBHOOK_MISSING_SUBJECT]: "Install webhook token has no subject (install id)"
335
+ };
336
+ var InstallWebhookError = class extends jwt__default.JsonWebTokenError {
337
+ /** Why the delivery was rejected. */
338
+ reason;
339
+ constructor(reason) {
340
+ super(INSTALL_WEBHOOK_MESSAGES[reason]);
341
+ this.name = "InstallWebhookError";
342
+ this.reason = reason;
343
+ }
344
+ };
307
345
 
308
346
  // src/models/peek/product.ts
309
347
  var ACTIVITY_PRODUCT_TYPE = "ACTIVITY";
@@ -2769,7 +2807,7 @@ async function requestWithRetry(http, url, init, label, onResponse) {
2769
2807
  // src/internal/sdk-headers.ts
2770
2808
  var SDK_HEADER_NAME = "x-peek-sdk";
2771
2809
  var SDK_PLATFORM = "js";
2772
- var SDK_VERSION = "1.0.0";
2810
+ var SDK_VERSION = "1.1.0";
2773
2811
  var SDK_HEADER_VALUE = `${SDK_PLATFORM}-${SDK_VERSION}`;
2774
2812
 
2775
2813
  // src/internal/peek/graphql-client.ts
@@ -5259,10 +5297,11 @@ function toPeekPlatform(raw) {
5259
5297
  function parseInstallWebhook(token, body, secret) {
5260
5298
  const payload = verifyPeekJwt(token, secret);
5261
5299
  const parsed = extractInstallWebhookBody(body);
5300
+ const installId = resolveInstallId(payload.sub, parsed.install_id);
5262
5301
  const account = parsed.account ?? {};
5263
5302
  const rawStatus = parsed.status || payload.status || "";
5264
5303
  return {
5265
- installId: parsed.install_id || payload.sub || "",
5304
+ installId,
5266
5305
  accountId: account.id || payload.account?.id || "",
5267
5306
  accountName: account.name || "",
5268
5307
  platform: toPeekPlatform(account.platform || ""),
@@ -5275,6 +5314,14 @@ function parseInstallWebhook(token, body, secret) {
5275
5314
  user: resolveInstallUser(parsed.modified_by, payload.user)
5276
5315
  };
5277
5316
  }
5317
+ function resolveInstallId(rawSubject, bodyInstallId) {
5318
+ const tokenSubject = cleanTokenString(rawSubject);
5319
+ if (tokenSubject === null) throw new InstallWebhookError(INSTALL_WEBHOOK_MISSING_SUBJECT);
5320
+ if (bodyInstallId && bodyInstallId !== tokenSubject) {
5321
+ throw new InstallWebhookError(INSTALL_WEBHOOK_INSTALL_ID_MISMATCH);
5322
+ }
5323
+ return tokenSubject;
5324
+ }
5278
5325
  function resolveInstallUser(bodyUser, tokenUser) {
5279
5326
  if (cleanTokenString(bodyUser?.id) !== null) return mapPeekTokenUser(bodyUser);
5280
5327
  return mapPeekTokenUser(tokenUser);
@@ -5290,6 +5337,6 @@ function verifyInstallWebhook(token, secret) {
5290
5337
  };
5291
5338
  }
5292
5339
 
5293
- export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngPermissionError, CngProductService, CustomQuestionService, DailyNoteService, INSTALL_STATUSES, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
5340
+ export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AcmeAccessService, AcmeApiError, AcmeProductService, AdminAccountRequiredError, AvailabilityService, BookingService, CngAccessService, CngApiError, CngPermissionError, CngProductService, CustomQuestionService, DailyNoteService, INSTALL_STATUSES, InstallWebhookError, MembershipService, PeekAccessService, PeekGraphQLError, PeekHttpError, PiiAccessDisabledError, PricingService, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
5294
5341
  //# sourceMappingURL=index.js.map
5295
5342
  //# sourceMappingURL=index.js.map