@peektravel/app-utilities 0.2.2 → 0.2.3

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
@@ -1184,15 +1184,28 @@ declare class PromoCodeService {
1184
1184
  create(input: CreatePromoCodeInput): Promise<CreatedPromoCode>;
1185
1185
  }
1186
1186
 
1187
- /**
1188
- * Authenticated root entry point to the Peek backoffice GraphQL gateway.
1189
- *
1190
- * Configure one instance per install with everything needed to authenticate and
1191
- * reach the gateway. The access service owns the shared, authenticated
1192
- * transport (it mints and caches tokens on demand) and hands out per-resource
1193
- * service objects e.g. {@link PeekAccessService.getProductService} — that
1194
- * carry the resource-specific business logic.
1195
- */
1187
+ /** User context embedded in a Peek auth token. */
1188
+ interface PeekAuthTokenUser {
1189
+ /** User's email address. */
1190
+ email: string;
1191
+ /** User's Peek account ID */
1192
+ id: string;
1193
+ /** Whether the user has admin privileges. */
1194
+ isAdmin: boolean;
1195
+ /** User's locale (e.g. `"en"`). */
1196
+ locale: string;
1197
+ /** User's display name. */
1198
+ name: string;
1199
+ }
1200
+ /** Claims returned by {@link PeekAccessService.verifyPeekAuthToken}. */
1201
+ interface PeekAuthTokenClaims {
1202
+ /** Install ID — the JWT subject (`sub`). Peek-assigned UUID. */
1203
+ installId: string;
1204
+ /** App display version at time of issuance. */
1205
+ displayVersion: string;
1206
+ /** Authenticated user context. */
1207
+ user: PeekAuthTokenUser;
1208
+ }
1196
1209
 
1197
1210
  /** Configuration for a {@link PeekAccessService} instance. */
1198
1211
  interface PeekAccessServiceConfig {
@@ -1258,6 +1271,7 @@ interface PeekAccessServiceConfig {
1258
1271
  declare class PeekAccessService {
1259
1272
  private readonly client;
1260
1273
  private readonly productServiceOptions;
1274
+ private readonly jwtSecret;
1261
1275
  private productService?;
1262
1276
  private accountUserService?;
1263
1277
  private resourcePoolService?;
@@ -1270,6 +1284,25 @@ declare class PeekAccessService {
1270
1284
  private bookingService?;
1271
1285
  private reviewService?;
1272
1286
  constructor(config: PeekAccessServiceConfig);
1287
+ /**
1288
+ * Verifies a Peek auth token issued by the app registry and returns the
1289
+ * decoded claims.
1290
+ *
1291
+ * Validates the HMAC signature (using this service's `jwtSecret`), the token
1292
+ * expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
1293
+ * from the `jsonwebtoken` library on any failure — callers should catch to
1294
+ * distinguish error kinds:
1295
+ *
1296
+ * - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
1297
+ * malformed
1298
+ * - `TokenExpiredError` — past `exp`
1299
+ * - `NotBeforeError` — before `nbf`
1300
+ *
1301
+ * @throws {JsonWebTokenError} signature invalid or token malformed
1302
+ * @throws {TokenExpiredError} token has expired
1303
+ * @throws {NotBeforeError} token not yet valid
1304
+ */
1305
+ verifyPeekAuthToken(token: string): PeekAuthTokenClaims;
1273
1306
  /**
1274
1307
  * Returns the {@link ProductService} for this install, bound to the shared
1275
1308
  * authenticated transport. The instance is created lazily and reused.
@@ -1441,4 +1474,4 @@ declare class PeekGraphQLError extends Error {
1441
1474
  constructor(graphqlErrors: unknown[], message?: string);
1442
1475
  }
1443
1476
 
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 };
1477
+ 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, type PeekAuthTokenClaims, type PeekAuthTokenUser, 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
@@ -1184,15 +1184,28 @@ declare class PromoCodeService {
1184
1184
  create(input: CreatePromoCodeInput): Promise<CreatedPromoCode>;
1185
1185
  }
1186
1186
 
1187
- /**
1188
- * Authenticated root entry point to the Peek backoffice GraphQL gateway.
1189
- *
1190
- * Configure one instance per install with everything needed to authenticate and
1191
- * reach the gateway. The access service owns the shared, authenticated
1192
- * transport (it mints and caches tokens on demand) and hands out per-resource
1193
- * service objects e.g. {@link PeekAccessService.getProductService} — that
1194
- * carry the resource-specific business logic.
1195
- */
1187
+ /** User context embedded in a Peek auth token. */
1188
+ interface PeekAuthTokenUser {
1189
+ /** User's email address. */
1190
+ email: string;
1191
+ /** User's Peek account ID */
1192
+ id: string;
1193
+ /** Whether the user has admin privileges. */
1194
+ isAdmin: boolean;
1195
+ /** User's locale (e.g. `"en"`). */
1196
+ locale: string;
1197
+ /** User's display name. */
1198
+ name: string;
1199
+ }
1200
+ /** Claims returned by {@link PeekAccessService.verifyPeekAuthToken}. */
1201
+ interface PeekAuthTokenClaims {
1202
+ /** Install ID — the JWT subject (`sub`). Peek-assigned UUID. */
1203
+ installId: string;
1204
+ /** App display version at time of issuance. */
1205
+ displayVersion: string;
1206
+ /** Authenticated user context. */
1207
+ user: PeekAuthTokenUser;
1208
+ }
1196
1209
 
1197
1210
  /** Configuration for a {@link PeekAccessService} instance. */
1198
1211
  interface PeekAccessServiceConfig {
@@ -1258,6 +1271,7 @@ interface PeekAccessServiceConfig {
1258
1271
  declare class PeekAccessService {
1259
1272
  private readonly client;
1260
1273
  private readonly productServiceOptions;
1274
+ private readonly jwtSecret;
1261
1275
  private productService?;
1262
1276
  private accountUserService?;
1263
1277
  private resourcePoolService?;
@@ -1270,6 +1284,25 @@ declare class PeekAccessService {
1270
1284
  private bookingService?;
1271
1285
  private reviewService?;
1272
1286
  constructor(config: PeekAccessServiceConfig);
1287
+ /**
1288
+ * Verifies a Peek auth token issued by the app registry and returns the
1289
+ * decoded claims.
1290
+ *
1291
+ * Validates the HMAC signature (using this service's `jwtSecret`), the token
1292
+ * expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
1293
+ * from the `jsonwebtoken` library on any failure — callers should catch to
1294
+ * distinguish error kinds:
1295
+ *
1296
+ * - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
1297
+ * malformed
1298
+ * - `TokenExpiredError` — past `exp`
1299
+ * - `NotBeforeError` — before `nbf`
1300
+ *
1301
+ * @throws {JsonWebTokenError} signature invalid or token malformed
1302
+ * @throws {TokenExpiredError} token has expired
1303
+ * @throws {NotBeforeError} token not yet valid
1304
+ */
1305
+ verifyPeekAuthToken(token: string): PeekAuthTokenClaims;
1273
1306
  /**
1274
1307
  * Returns the {@link ProductService} for this install, bound to the shared
1275
1308
  * authenticated transport. The instance is created lazily and reused.
@@ -1441,4 +1474,4 @@ declare class PeekGraphQLError extends Error {
1441
1474
  constructor(graphqlErrors: unknown[], message?: string);
1442
1475
  }
1443
1476
 
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 };
1477
+ 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, type PeekAuthTokenClaims, type PeekAuthTokenUser, 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
@@ -1,5 +1,7 @@
1
- import { randomUUID } from 'crypto';
2
1
  import * as jwt from 'jsonwebtoken';
2
+ import { randomUUID } from 'crypto';
3
+
4
+ // src/peek-access-service.ts
3
5
 
4
6
  // src/internal/gateway-endpoints.ts
5
7
  var SALES_ENDPOINT = "sales";
@@ -2896,9 +2898,11 @@ var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
2896
2898
  var DEFAULT_TOKEN_TTL_SECONDS = 3600;
2897
2899
  var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
2898
2900
  var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
2901
+ var PEEK_TOKEN_ISSUER = "app_registry_v2";
2899
2902
  var PeekAccessService = class {
2900
2903
  client;
2901
2904
  productServiceOptions;
2905
+ jwtSecret;
2902
2906
  productService;
2903
2907
  accountUserService;
2904
2908
  resourcePoolService;
@@ -2917,6 +2921,7 @@ var PeekAccessService = class {
2917
2921
  requireNonEmpty(config.issuer, "issuer");
2918
2922
  requireNonEmpty(config.appId, "appId");
2919
2923
  if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
2924
+ this.jwtSecret = config.jwtSecret;
2920
2925
  const logger = config.logger ?? noopLogger;
2921
2926
  const tokens = new TokenManager({
2922
2927
  secret: config.jwtSecret,
@@ -2940,6 +2945,41 @@ var PeekAccessService = class {
2940
2945
  itemOptionsPageSize: config.itemOptionsPageSize
2941
2946
  };
2942
2947
  }
2948
+ /**
2949
+ * Verifies a Peek auth token issued by the app registry and returns the
2950
+ * decoded claims.
2951
+ *
2952
+ * Validates the HMAC signature (using this service's `jwtSecret`), the token
2953
+ * expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
2954
+ * from the `jsonwebtoken` library on any failure — callers should catch to
2955
+ * distinguish error kinds:
2956
+ *
2957
+ * - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
2958
+ * malformed
2959
+ * - `TokenExpiredError` — past `exp`
2960
+ * - `NotBeforeError` — before `nbf`
2961
+ *
2962
+ * @throws {JsonWebTokenError} signature invalid or token malformed
2963
+ * @throws {TokenExpiredError} token has expired
2964
+ * @throws {NotBeforeError} token not yet valid
2965
+ */
2966
+ verifyPeekAuthToken(token) {
2967
+ const payload = jwt.verify(token, this.jwtSecret, {
2968
+ issuer: PEEK_TOKEN_ISSUER
2969
+ });
2970
+ const { user: u } = payload;
2971
+ return {
2972
+ installId: payload.sub,
2973
+ displayVersion: payload.display_version,
2974
+ user: {
2975
+ email: u.email,
2976
+ id: u.id,
2977
+ isAdmin: u.is_admin,
2978
+ locale: u.locale,
2979
+ name: u.name
2980
+ }
2981
+ };
2982
+ }
2943
2983
  /**
2944
2984
  * Returns the {@link ProductService} for this install, bound to the shared
2945
2985
  * authenticated transport. The instance is created lazily and reused.