@peektravel/app-utilities 0.1.5 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/index.cjs +103 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -6
- package/dist/index.d.ts +98 -6
- package/dist/index.js +102 -7
- package/dist/index.js.map +1 -1
- package/docs/webhooks.md +141 -0
- package/llms.txt +18 -0
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -23,8 +23,8 @@ interface GraphQLClientOptions {
|
|
|
23
23
|
baseUrl: string;
|
|
24
24
|
/** Peek app ID, used in the endpoint path. */
|
|
25
25
|
appId: string;
|
|
26
|
-
/** API gateway key sent as the `pk-api-key` header. */
|
|
27
|
-
gatewayKey
|
|
26
|
+
/** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
|
|
27
|
+
gatewayKey?: string;
|
|
28
28
|
/** Supplies a valid bearer token for each request. */
|
|
29
29
|
getToken: () => string;
|
|
30
30
|
/** Backoff delays (ms) applied on successive HTTP 429 responses. */
|
|
@@ -33,6 +33,11 @@ interface GraphQLClientOptions {
|
|
|
33
33
|
logger: Logger;
|
|
34
34
|
/** `fetch` implementation to use. */
|
|
35
35
|
fetchFn: typeof fetch;
|
|
36
|
+
/**
|
|
37
|
+
* Optional fixed path segment inserted between `appId` and the endpoint name.
|
|
38
|
+
* Used in v2 mode: `baseUrl/appId/endpointPathPrefix/endpointName`.
|
|
39
|
+
*/
|
|
40
|
+
endpointPathPrefix?: string;
|
|
36
41
|
}
|
|
37
42
|
declare class GraphQLClient {
|
|
38
43
|
private readonly options;
|
|
@@ -1199,9 +1204,16 @@ interface PeekAccessServiceConfig {
|
|
|
1199
1204
|
issuer: string;
|
|
1200
1205
|
/** Peek app ID, used in the gateway endpoint path. */
|
|
1201
1206
|
appId: string;
|
|
1202
|
-
/** API gateway key, sent as the `pk-api-key` header. */
|
|
1203
|
-
gatewayKey
|
|
1204
|
-
/**
|
|
1207
|
+
/** API gateway key, sent as the `pk-api-key` header. Required in v1 mode; not used in v2. */
|
|
1208
|
+
gatewayKey?: string;
|
|
1209
|
+
/**
|
|
1210
|
+
* Gateway mode. `"v2"` routes through the app-registry installations API
|
|
1211
|
+
* (`baseUrl/appId/peek_backoffice_api-v1/endpointName`) and defaults to the
|
|
1212
|
+
* app-registry sandbox base URL. `"v1"` (default) uses the standard backoffice
|
|
1213
|
+
* GraphQL gateway.
|
|
1214
|
+
*/
|
|
1215
|
+
mode?: "v2";
|
|
1216
|
+
/** Override the gateway base URL. Default: Peek production gateway (v1) or app-registry sandbox (v2). */
|
|
1205
1217
|
baseUrl?: string;
|
|
1206
1218
|
/** JWT lifetime in seconds. Default: 3600. */
|
|
1207
1219
|
tokenTtlSeconds?: number;
|
|
@@ -1316,6 +1328,86 @@ declare class PeekAccessService {
|
|
|
1316
1328
|
getReviewService(): ReviewService;
|
|
1317
1329
|
}
|
|
1318
1330
|
|
|
1331
|
+
/**
|
|
1332
|
+
* Public webhook surface for bookings.
|
|
1333
|
+
*
|
|
1334
|
+
* A Peek "backoffice" booking webhook's payload shape is defined by a GraphQL
|
|
1335
|
+
* field selection registered with the hook. That registration happens once, in
|
|
1336
|
+
* an external system (the App Store `broadcast_to_url` config) — not from
|
|
1337
|
+
* consumer code — so this package registers nothing at runtime. It owns the two
|
|
1338
|
+
* pieces that must agree:
|
|
1339
|
+
*
|
|
1340
|
+
* - {@link BOOKING_WEBHOOK_GQL_QUERY} — the canonical selection to paste into
|
|
1341
|
+
* that external config. A setup-time artifact surfaced through
|
|
1342
|
+
* `docs/webhooks.md` and pinned by a drift-guard test; **internal**, not part
|
|
1343
|
+
* of the runtime public API.
|
|
1344
|
+
* - {@link parseBookingWebhook} — the only runtime export; turns a delivered
|
|
1345
|
+
* payload into a clean {@link Booking} using the very same converter as the
|
|
1346
|
+
* read path.
|
|
1347
|
+
*
|
|
1348
|
+
* Parsing an inbound webhook needs no auth, no network, and no client — it is a
|
|
1349
|
+
* pure transform — so it is exported as a standalone function rather than a
|
|
1350
|
+
* method on `PeekAccessService` (the receiver may not hold gateway credentials).
|
|
1351
|
+
*/
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Parses a delivered booking webhook payload into a clean {@link Booking}.
|
|
1355
|
+
*
|
|
1356
|
+
* Accepts the raw request body — either the `{ booking: … }` envelope or a bare
|
|
1357
|
+
* booking node, and a JSON string is parsed first. Which optional field groups
|
|
1358
|
+
* are present is auto-detected from the payload, so there is nothing to keep in
|
|
1359
|
+
* sync with the registered query.
|
|
1360
|
+
*/
|
|
1361
|
+
declare function parseBookingWebhook(payload: unknown): Booking;
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* The clean data model for a signed Peek Pro waiver (liability agreement),
|
|
1365
|
+
* delivered by the waiver webhook.
|
|
1366
|
+
*/
|
|
1367
|
+
/** A signed waiver. */
|
|
1368
|
+
interface Waiver {
|
|
1369
|
+
/** Id of the agreement template that was signed. */
|
|
1370
|
+
templateId: string;
|
|
1371
|
+
/** Id of the booking the waiver is attached to. */
|
|
1372
|
+
bookingId: string;
|
|
1373
|
+
/** URL of the signed waiver document. */
|
|
1374
|
+
fileUrl: string;
|
|
1375
|
+
/** When the waiver was signed (ISO datetime). */
|
|
1376
|
+
signedAt: string;
|
|
1377
|
+
/** Whether a guardian signed on the participant's behalf. */
|
|
1378
|
+
isSignedByGuardian: boolean;
|
|
1379
|
+
/** Participant name captured on the waiver, if any. */
|
|
1380
|
+
guestName: string | null;
|
|
1381
|
+
/** Whether the participant opted in to marketing. */
|
|
1382
|
+
isOptinMarketing: boolean;
|
|
1383
|
+
/** Whether the participant opted in to SMS. */
|
|
1384
|
+
isOptinSms: boolean;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Public webhook surface for waivers.
|
|
1389
|
+
*
|
|
1390
|
+
* Unlike bookings, a waiver webhook needs **no GraphQL registration query** —
|
|
1391
|
+
* Peek delivers a fixed payload (the App Store `waiver_webhook_data` output
|
|
1392
|
+
* format, with `output_fields_gql_query` left null), so there is nothing to
|
|
1393
|
+
* register beyond subscribing to the `agreement_signature_created` event. The
|
|
1394
|
+
* package's only job is to parse the delivered payload into a clean
|
|
1395
|
+
* {@link Waiver}.
|
|
1396
|
+
*
|
|
1397
|
+
* Like the booking parser, this is a pure transform — no auth, no network, no
|
|
1398
|
+
* client — so it is a standalone function rather than a method on
|
|
1399
|
+
* `PeekAccessService` (the receiver may not hold gateway credentials).
|
|
1400
|
+
*/
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* Parses a delivered waiver webhook payload into a clean {@link Waiver}.
|
|
1404
|
+
*
|
|
1405
|
+
* Accepts the raw request body — either the `{ waiver: … }` envelope or a bare
|
|
1406
|
+
* waiver node, and a JSON string is parsed first. Never throws on malformed
|
|
1407
|
+
* input: a missing/garbled body yields a {@link Waiver} with empty fields.
|
|
1408
|
+
*/
|
|
1409
|
+
declare function parseWaiverWebhook(payload: unknown): Waiver;
|
|
1410
|
+
|
|
1319
1411
|
/**
|
|
1320
1412
|
* Typed errors thrown by the package. Each mirrors a failure mode of the Peek
|
|
1321
1413
|
* GraphQL gateway so callers can branch on the error type rather than parsing
|
|
@@ -1349,4 +1441,4 @@ declare class PeekGraphQLError extends Error {
|
|
|
1349
1441
|
constructor(graphqlErrors: unknown[], message?: string);
|
|
1350
1442
|
}
|
|
1351
1443
|
|
|
1352
|
-
export { ADD_ON_PRODUCT_TYPE, type AccountUser, AccountUserService, type AccountUserServiceOptions, 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 CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreatePromoCodeInput, type CreatedBooking, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, PeekGraphQLError, type Price, type Product, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RateLimitError, type RefundInput, type RefundResult, ResellerService, type Resource, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateTimeslotResult, noopLogger };
|
|
1444
|
+
export { ADD_ON_PRODUCT_TYPE, type AccountUser, AccountUserService, type AccountUserServiceOptions, 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 CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreatePromoCodeInput, type CreatedBooking, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, PeekGraphQLError, type Price, type Product, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RateLimitError, type RefundInput, type RefundResult, ResellerService, type Resource, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateTimeslotResult, type Waiver, noopLogger, parseBookingWebhook, parseWaiverWebhook };
|
package/dist/index.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ interface GraphQLClientOptions {
|
|
|
23
23
|
baseUrl: string;
|
|
24
24
|
/** Peek app ID, used in the endpoint path. */
|
|
25
25
|
appId: string;
|
|
26
|
-
/** API gateway key sent as the `pk-api-key` header. */
|
|
27
|
-
gatewayKey
|
|
26
|
+
/** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
|
|
27
|
+
gatewayKey?: string;
|
|
28
28
|
/** Supplies a valid bearer token for each request. */
|
|
29
29
|
getToken: () => string;
|
|
30
30
|
/** Backoff delays (ms) applied on successive HTTP 429 responses. */
|
|
@@ -33,6 +33,11 @@ interface GraphQLClientOptions {
|
|
|
33
33
|
logger: Logger;
|
|
34
34
|
/** `fetch` implementation to use. */
|
|
35
35
|
fetchFn: typeof fetch;
|
|
36
|
+
/**
|
|
37
|
+
* Optional fixed path segment inserted between `appId` and the endpoint name.
|
|
38
|
+
* Used in v2 mode: `baseUrl/appId/endpointPathPrefix/endpointName`.
|
|
39
|
+
*/
|
|
40
|
+
endpointPathPrefix?: string;
|
|
36
41
|
}
|
|
37
42
|
declare class GraphQLClient {
|
|
38
43
|
private readonly options;
|
|
@@ -1199,9 +1204,16 @@ interface PeekAccessServiceConfig {
|
|
|
1199
1204
|
issuer: string;
|
|
1200
1205
|
/** Peek app ID, used in the gateway endpoint path. */
|
|
1201
1206
|
appId: string;
|
|
1202
|
-
/** API gateway key, sent as the `pk-api-key` header. */
|
|
1203
|
-
gatewayKey
|
|
1204
|
-
/**
|
|
1207
|
+
/** API gateway key, sent as the `pk-api-key` header. Required in v1 mode; not used in v2. */
|
|
1208
|
+
gatewayKey?: string;
|
|
1209
|
+
/**
|
|
1210
|
+
* Gateway mode. `"v2"` routes through the app-registry installations API
|
|
1211
|
+
* (`baseUrl/appId/peek_backoffice_api-v1/endpointName`) and defaults to the
|
|
1212
|
+
* app-registry sandbox base URL. `"v1"` (default) uses the standard backoffice
|
|
1213
|
+
* GraphQL gateway.
|
|
1214
|
+
*/
|
|
1215
|
+
mode?: "v2";
|
|
1216
|
+
/** Override the gateway base URL. Default: Peek production gateway (v1) or app-registry sandbox (v2). */
|
|
1205
1217
|
baseUrl?: string;
|
|
1206
1218
|
/** JWT lifetime in seconds. Default: 3600. */
|
|
1207
1219
|
tokenTtlSeconds?: number;
|
|
@@ -1316,6 +1328,86 @@ declare class PeekAccessService {
|
|
|
1316
1328
|
getReviewService(): ReviewService;
|
|
1317
1329
|
}
|
|
1318
1330
|
|
|
1331
|
+
/**
|
|
1332
|
+
* Public webhook surface for bookings.
|
|
1333
|
+
*
|
|
1334
|
+
* A Peek "backoffice" booking webhook's payload shape is defined by a GraphQL
|
|
1335
|
+
* field selection registered with the hook. That registration happens once, in
|
|
1336
|
+
* an external system (the App Store `broadcast_to_url` config) — not from
|
|
1337
|
+
* consumer code — so this package registers nothing at runtime. It owns the two
|
|
1338
|
+
* pieces that must agree:
|
|
1339
|
+
*
|
|
1340
|
+
* - {@link BOOKING_WEBHOOK_GQL_QUERY} — the canonical selection to paste into
|
|
1341
|
+
* that external config. A setup-time artifact surfaced through
|
|
1342
|
+
* `docs/webhooks.md` and pinned by a drift-guard test; **internal**, not part
|
|
1343
|
+
* of the runtime public API.
|
|
1344
|
+
* - {@link parseBookingWebhook} — the only runtime export; turns a delivered
|
|
1345
|
+
* payload into a clean {@link Booking} using the very same converter as the
|
|
1346
|
+
* read path.
|
|
1347
|
+
*
|
|
1348
|
+
* Parsing an inbound webhook needs no auth, no network, and no client — it is a
|
|
1349
|
+
* pure transform — so it is exported as a standalone function rather than a
|
|
1350
|
+
* method on `PeekAccessService` (the receiver may not hold gateway credentials).
|
|
1351
|
+
*/
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Parses a delivered booking webhook payload into a clean {@link Booking}.
|
|
1355
|
+
*
|
|
1356
|
+
* Accepts the raw request body — either the `{ booking: … }` envelope or a bare
|
|
1357
|
+
* booking node, and a JSON string is parsed first. Which optional field groups
|
|
1358
|
+
* are present is auto-detected from the payload, so there is nothing to keep in
|
|
1359
|
+
* sync with the registered query.
|
|
1360
|
+
*/
|
|
1361
|
+
declare function parseBookingWebhook(payload: unknown): Booking;
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* The clean data model for a signed Peek Pro waiver (liability agreement),
|
|
1365
|
+
* delivered by the waiver webhook.
|
|
1366
|
+
*/
|
|
1367
|
+
/** A signed waiver. */
|
|
1368
|
+
interface Waiver {
|
|
1369
|
+
/** Id of the agreement template that was signed. */
|
|
1370
|
+
templateId: string;
|
|
1371
|
+
/** Id of the booking the waiver is attached to. */
|
|
1372
|
+
bookingId: string;
|
|
1373
|
+
/** URL of the signed waiver document. */
|
|
1374
|
+
fileUrl: string;
|
|
1375
|
+
/** When the waiver was signed (ISO datetime). */
|
|
1376
|
+
signedAt: string;
|
|
1377
|
+
/** Whether a guardian signed on the participant's behalf. */
|
|
1378
|
+
isSignedByGuardian: boolean;
|
|
1379
|
+
/** Participant name captured on the waiver, if any. */
|
|
1380
|
+
guestName: string | null;
|
|
1381
|
+
/** Whether the participant opted in to marketing. */
|
|
1382
|
+
isOptinMarketing: boolean;
|
|
1383
|
+
/** Whether the participant opted in to SMS. */
|
|
1384
|
+
isOptinSms: boolean;
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
/**
|
|
1388
|
+
* Public webhook surface for waivers.
|
|
1389
|
+
*
|
|
1390
|
+
* Unlike bookings, a waiver webhook needs **no GraphQL registration query** —
|
|
1391
|
+
* Peek delivers a fixed payload (the App Store `waiver_webhook_data` output
|
|
1392
|
+
* format, with `output_fields_gql_query` left null), so there is nothing to
|
|
1393
|
+
* register beyond subscribing to the `agreement_signature_created` event. The
|
|
1394
|
+
* package's only job is to parse the delivered payload into a clean
|
|
1395
|
+
* {@link Waiver}.
|
|
1396
|
+
*
|
|
1397
|
+
* Like the booking parser, this is a pure transform — no auth, no network, no
|
|
1398
|
+
* client — so it is a standalone function rather than a method on
|
|
1399
|
+
* `PeekAccessService` (the receiver may not hold gateway credentials).
|
|
1400
|
+
*/
|
|
1401
|
+
|
|
1402
|
+
/**
|
|
1403
|
+
* Parses a delivered waiver webhook payload into a clean {@link Waiver}.
|
|
1404
|
+
*
|
|
1405
|
+
* Accepts the raw request body — either the `{ waiver: … }` envelope or a bare
|
|
1406
|
+
* waiver node, and a JSON string is parsed first. Never throws on malformed
|
|
1407
|
+
* input: a missing/garbled body yields a {@link Waiver} with empty fields.
|
|
1408
|
+
*/
|
|
1409
|
+
declare function parseWaiverWebhook(payload: unknown): Waiver;
|
|
1410
|
+
|
|
1319
1411
|
/**
|
|
1320
1412
|
* Typed errors thrown by the package. Each mirrors a failure mode of the Peek
|
|
1321
1413
|
* GraphQL gateway so callers can branch on the error type rather than parsing
|
|
@@ -1349,4 +1441,4 @@ declare class PeekGraphQLError extends Error {
|
|
|
1349
1441
|
constructor(graphqlErrors: unknown[], message?: string);
|
|
1350
1442
|
}
|
|
1351
1443
|
|
|
1352
|
-
export { ADD_ON_PRODUCT_TYPE, type AccountUser, AccountUserService, type AccountUserServiceOptions, 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 CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreatePromoCodeInput, type CreatedBooking, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, PeekGraphQLError, type Price, type Product, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RateLimitError, type RefundInput, type RefundResult, ResellerService, type Resource, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateTimeslotResult, noopLogger };
|
|
1444
|
+
export { ADD_ON_PRODUCT_TYPE, type AccountUser, AccountUserService, type AccountUserServiceOptions, 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 CreateBookingGuest, type CreateBookingInput, type CreateBookingTicket, type CreatePromoCodeInput, type CreatedBooking, type CreatedPromoCode, type CustomQuestionAnswer, type DailyNote, DailyNoteService, type Duration, type Guest, type GuestMetadata, type Guide, type GuideAssignment, type InvoiceLinkResult, type Logger, type MakePaymentInput, type MakePaymentResult, type Membership, type MembershipPurchaseInput, MembershipService, type NoteMode, type Payment, type PaymentSource, PeekAccessService, type PeekAccessServiceConfig, PeekGraphQLError, type Price, type Product, ProductService, type ProductServiceOptions, type ProductTicket, type PromoCode, type PromoCodeFixedAmount, PromoCodeService, type PromoCodeServiceOptions, type PurchasedMembership, RateLimitError, type RefundInput, type RefundResult, ResellerService, type Resource, type ResourceOptionQuantity, type ResourcePool, type ResourcePoolAccountUser, type ResourcePoolAssignment, type ResourcePoolMode, ResourcePoolService, type Review, ReviewService, type Ticket, type Timeslot, type TimeslotFilter, TimeslotService, type UpdateTimeslotResult, type Waiver, noopLogger, parseBookingWebhook, parseWaiverWebhook };
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as jwt from 'jsonwebtoken';
|
|
|
3
3
|
|
|
4
4
|
// src/internal/gateway-endpoints.ts
|
|
5
5
|
var SALES_ENDPOINT = "sales";
|
|
6
|
+
var V2_EXTENDABLE_SLUG = "peek_backoffice_api-v1";
|
|
6
7
|
|
|
7
8
|
// src/internal/account-users/account-user-converter.ts
|
|
8
9
|
var ACTIVE_STATUS = "ACTIVE";
|
|
@@ -1819,14 +1820,19 @@ var GraphQLClient = class {
|
|
|
1819
1820
|
throw new RateLimitError();
|
|
1820
1821
|
}
|
|
1821
1822
|
endpoint(endpointName) {
|
|
1822
|
-
|
|
1823
|
+
const { baseUrl, appId, endpointPathPrefix } = this.options;
|
|
1824
|
+
const prefix = endpointPathPrefix ? `${endpointPathPrefix}/` : "";
|
|
1825
|
+
return `${baseUrl}/${appId}/${prefix}${endpointName}`;
|
|
1823
1826
|
}
|
|
1824
1827
|
buildHeaders() {
|
|
1825
|
-
|
|
1828
|
+
const headers = {
|
|
1826
1829
|
"X-Peek-Auth": `Bearer ${this.options.getToken()}`,
|
|
1827
|
-
"pk-api-key": this.options.gatewayKey,
|
|
1828
1830
|
"Content-Type": "application/json"
|
|
1829
1831
|
};
|
|
1832
|
+
if (this.options.gatewayKey) {
|
|
1833
|
+
headers["pk-api-key"] = this.options.gatewayKey;
|
|
1834
|
+
}
|
|
1835
|
+
return headers;
|
|
1830
1836
|
}
|
|
1831
1837
|
};
|
|
1832
1838
|
|
|
@@ -2886,6 +2892,7 @@ var noopLogger = {
|
|
|
2886
2892
|
|
|
2887
2893
|
// src/peek-access-service.ts
|
|
2888
2894
|
var DEFAULT_BASE_URL = "https://apps.peekapis.com/backoffice-gql";
|
|
2895
|
+
var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
|
|
2889
2896
|
var DEFAULT_TOKEN_TTL_SECONDS = 3600;
|
|
2890
2897
|
var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
|
|
2891
2898
|
var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
|
|
@@ -2904,11 +2911,12 @@ var PeekAccessService = class {
|
|
|
2904
2911
|
bookingService;
|
|
2905
2912
|
reviewService;
|
|
2906
2913
|
constructor(config) {
|
|
2914
|
+
const isV2 = config.mode === "v2";
|
|
2907
2915
|
requireNonEmpty(config.installId, "installId");
|
|
2908
2916
|
requireNonEmpty(config.jwtSecret, "jwtSecret");
|
|
2909
2917
|
requireNonEmpty(config.issuer, "issuer");
|
|
2910
2918
|
requireNonEmpty(config.appId, "appId");
|
|
2911
|
-
requireNonEmpty(config.gatewayKey, "gatewayKey");
|
|
2919
|
+
if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
|
|
2912
2920
|
const logger = config.logger ?? noopLogger;
|
|
2913
2921
|
const tokens = new TokenManager({
|
|
2914
2922
|
secret: config.jwtSecret,
|
|
@@ -2917,14 +2925,16 @@ var PeekAccessService = class {
|
|
|
2917
2925
|
ttlSeconds: config.tokenTtlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS,
|
|
2918
2926
|
leewaySeconds: config.tokenRefreshLeewaySeconds ?? DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS
|
|
2919
2927
|
});
|
|
2928
|
+
const defaultBaseUrl = isV2 ? DEFAULT_V2_BASE_URL : DEFAULT_BASE_URL;
|
|
2920
2929
|
this.client = new GraphQLClient({
|
|
2921
|
-
baseUrl: config.baseUrl ??
|
|
2930
|
+
baseUrl: config.baseUrl ?? defaultBaseUrl,
|
|
2922
2931
|
appId: config.appId,
|
|
2923
2932
|
gatewayKey: config.gatewayKey,
|
|
2924
2933
|
getToken: () => tokens.getToken(),
|
|
2925
2934
|
retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
|
|
2926
2935
|
logger,
|
|
2927
|
-
fetchFn: config.fetch ?? globalThis.fetch
|
|
2936
|
+
fetchFn: config.fetch ?? globalThis.fetch,
|
|
2937
|
+
endpointPathPrefix: isV2 ? V2_EXTENDABLE_SLUG : void 0
|
|
2928
2938
|
});
|
|
2929
2939
|
this.productServiceOptions = {
|
|
2930
2940
|
itemOptionsPageSize: config.itemOptionsPageSize
|
|
@@ -3056,6 +3066,91 @@ function requireNonEmpty(value, name) {
|
|
|
3056
3066
|
}
|
|
3057
3067
|
}
|
|
3058
3068
|
|
|
3059
|
-
|
|
3069
|
+
// src/internal/bookings/booking-webhook.ts
|
|
3070
|
+
var PAYLOAD_BOOKING_KEY = "booking";
|
|
3071
|
+
var VALUE_OPEN_TOKEN = "value {";
|
|
3072
|
+
var PRICE_BREAKDOWN_KEYS = [
|
|
3073
|
+
"convenienceFee",
|
|
3074
|
+
"deposit",
|
|
3075
|
+
"discount",
|
|
3076
|
+
"discountedPrice",
|
|
3077
|
+
"fees",
|
|
3078
|
+
"flatPartnerFee",
|
|
3079
|
+
"price",
|
|
3080
|
+
"retailPrice",
|
|
3081
|
+
"taxes"
|
|
3082
|
+
];
|
|
3083
|
+
buildMaximalWebhookQuery();
|
|
3084
|
+
function buildMaximalWebhookQuery() {
|
|
3085
|
+
const fields = bookingQueryFields.replace(
|
|
3086
|
+
VALUE_OPEN_TOKEN,
|
|
3087
|
+
`${VALUE_OPEN_TOKEN} ${PRICE_BREAKDOWN_FIELDS}`
|
|
3088
|
+
);
|
|
3089
|
+
return `{ ${fields} ${bookingGuestsFields} }`.replace(/\s+/g, " ").trim();
|
|
3090
|
+
}
|
|
3091
|
+
function parseBookingWebhook(payload) {
|
|
3092
|
+
const node = extractBookingNode(payload);
|
|
3093
|
+
return fromBookingNode(node, hasGuests(node), hasPriceBreakdown(node));
|
|
3094
|
+
}
|
|
3095
|
+
function extractBookingNode(payload) {
|
|
3096
|
+
let body = payload;
|
|
3097
|
+
if (typeof body === "string") {
|
|
3098
|
+
try {
|
|
3099
|
+
body = JSON.parse(body);
|
|
3100
|
+
} catch {
|
|
3101
|
+
return {};
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
if (!body || typeof body !== "object") return {};
|
|
3105
|
+
const record = body;
|
|
3106
|
+
const inner = record[PAYLOAD_BOOKING_KEY];
|
|
3107
|
+
if (inner && typeof inner === "object") return inner;
|
|
3108
|
+
return record;
|
|
3109
|
+
}
|
|
3110
|
+
function hasGuests(node) {
|
|
3111
|
+
return Array.isArray(node.bookingGuests);
|
|
3112
|
+
}
|
|
3113
|
+
function hasPriceBreakdown(node) {
|
|
3114
|
+
const value = node.value;
|
|
3115
|
+
if (!value) return false;
|
|
3116
|
+
return PRICE_BREAKDOWN_KEYS.some((key) => key in value);
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
// src/internal/waivers/waiver-webhook.ts
|
|
3120
|
+
var PAYLOAD_WAIVER_KEY = "waiver";
|
|
3121
|
+
function parseWaiverWebhook(payload) {
|
|
3122
|
+
return fromWaiverNode(extractWaiverNode(payload));
|
|
3123
|
+
}
|
|
3124
|
+
function fromWaiverNode(node) {
|
|
3125
|
+
const data = node ?? {};
|
|
3126
|
+
const waiverData = data.waiver_data ?? {};
|
|
3127
|
+
return {
|
|
3128
|
+
templateId: data.agreement_template_id || "",
|
|
3129
|
+
bookingId: data.booking_id || "",
|
|
3130
|
+
fileUrl: data.file_url || "",
|
|
3131
|
+
signedAt: data.signed_at || "",
|
|
3132
|
+
isSignedByGuardian: Boolean(data.signed_by_guardian),
|
|
3133
|
+
guestName: waiverData.participant_name || null,
|
|
3134
|
+
isOptinMarketing: Boolean(waiverData.participant_optin_marketing),
|
|
3135
|
+
isOptinSms: Boolean(waiverData.participant_optin_sms)
|
|
3136
|
+
};
|
|
3137
|
+
}
|
|
3138
|
+
function extractWaiverNode(payload) {
|
|
3139
|
+
let body = payload;
|
|
3140
|
+
if (typeof body === "string") {
|
|
3141
|
+
try {
|
|
3142
|
+
body = JSON.parse(body);
|
|
3143
|
+
} catch {
|
|
3144
|
+
return {};
|
|
3145
|
+
}
|
|
3146
|
+
}
|
|
3147
|
+
if (!body || typeof body !== "object") return {};
|
|
3148
|
+
const record = body;
|
|
3149
|
+
const inner = record[PAYLOAD_WAIVER_KEY];
|
|
3150
|
+
if (inner && typeof inner === "object") return inner;
|
|
3151
|
+
return record;
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
export { ADD_ON_PRODUCT_TYPE, AccountUserService, AdminAccountRequiredError, AvailabilityService, BookingService, DailyNoteService, MembershipService, PeekAccessService, PeekGraphQLError, ProductService, PromoCodeService, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, noopLogger, parseBookingWebhook, parseWaiverWebhook };
|
|
3060
3155
|
//# sourceMappingURL=index.js.map
|
|
3061
3156
|
//# sourceMappingURL=index.js.map
|