@peektravel/app-utilities 0.6.1 → 0.7.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.js CHANGED
@@ -2039,8 +2039,13 @@ var GraphQLClient = class {
2039
2039
  };
2040
2040
  var PEEK_TOKEN_ISSUER = "app_registry_v2";
2041
2041
  var PEEK_TOKEN_AUDIENCE = "Joken";
2042
+ var BEARER_PREFIX = "bearer ";
2043
+ function stripBearer(token) {
2044
+ const trimmed = token.trim();
2045
+ return trimmed.toLowerCase().startsWith(BEARER_PREFIX) ? trimmed.slice(BEARER_PREFIX.length).trim() : trimmed;
2046
+ }
2042
2047
  function verifyPeekJwt(token, secret) {
2043
- return jwt.verify(token, secret, {
2048
+ return jwt.verify(stripBearer(token), secret, {
2044
2049
  issuer: PEEK_TOKEN_ISSUER,
2045
2050
  audience: PEEK_TOKEN_AUDIENCE
2046
2051
  });
@@ -3564,9 +3569,10 @@ var PeekAccessService = class {
3564
3569
  * decoded claims.
3565
3570
  *
3566
3571
  * Validates the HMAC signature (using this service's `jwtSecret`), the token
3567
- * expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
3568
- * from the `jsonwebtoken` library on any failure — callers should catch to
3569
- * distinguish error kinds:
3572
+ * expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Pass the
3573
+ * raw `x-peek-auth` request header value — a leading `Bearer ` prefix, if
3574
+ * present, is stripped for you. Throws from the `jsonwebtoken` library on any
3575
+ * failure — callers should catch to distinguish error kinds:
3570
3576
  *
3571
3577
  * - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
3572
3578
  * malformed
@@ -4249,18 +4255,6 @@ function extractWaiverNode(payload) {
4249
4255
  return record;
4250
4256
  }
4251
4257
 
4252
- // src/internal/peek/installs/install-webhook.ts
4253
- function verifyInstallWebhook(token, secret) {
4254
- const payload = verifyPeekJwt(token, secret);
4255
- return {
4256
- installId: payload.sub ?? "",
4257
- account: { id: payload.account?.id ?? "" },
4258
- status: payload.status ?? "",
4259
- displayVersion: payload.display_version ?? "",
4260
- user: payload.user ? mapPeekTokenUser(payload.user) : null
4261
- };
4262
- }
4263
-
4264
4258
  // src/models/peek/auth-token.ts
4265
4259
  var PEEK_PLATFORMS = ["peek", "cng", "acme"];
4266
4260
 
@@ -4272,50 +4266,53 @@ var INSTALL_STATUSES = [
4272
4266
  ];
4273
4267
 
4274
4268
  // src/internal/peek/installs/install-converter.ts
4269
+ function extractInstallWebhookBody(payload) {
4270
+ let body = payload;
4271
+ if (typeof body === "string") {
4272
+ try {
4273
+ body = JSON.parse(body);
4274
+ } catch {
4275
+ return {};
4276
+ }
4277
+ }
4278
+ if (!body || typeof body !== "object") return {};
4279
+ return body;
4280
+ }
4275
4281
  function toInstallStatus(raw) {
4276
4282
  return INSTALL_STATUSES.includes(raw) ? raw : null;
4277
4283
  }
4278
4284
  function toPeekPlatform(raw) {
4279
4285
  return PEEK_PLATFORMS.includes(raw) ? raw : null;
4280
4286
  }
4281
- function fromInstallIdentityNode(node) {
4282
- const data = node ?? {};
4283
- const account = data.account ?? {};
4287
+
4288
+ // src/internal/peek/installs/install-webhook.ts
4289
+ function parseInstallWebhook(token, body, secret) {
4290
+ const payload = verifyPeekJwt(token, secret);
4291
+ const account = extractInstallWebhookBody(body).account ?? {};
4292
+ const rawStatus = payload.status ?? "";
4284
4293
  return {
4285
- installId: data.install_id || "",
4286
- accountId: account.id || "",
4294
+ installId: payload.sub ?? "",
4295
+ accountId: payload.account?.id ?? "",
4287
4296
  accountName: account.name || "",
4288
4297
  platform: toPeekPlatform(account.platform || ""),
4289
- isTest: Boolean(account.is_test)
4290
- };
4291
- }
4292
- function fromInstallEventNode(node) {
4293
- const rawStatus = node?.status || "";
4294
- return {
4298
+ isTest: Boolean(account.is_test),
4295
4299
  status: toInstallStatus(rawStatus),
4296
4300
  rawStatus,
4297
- displayVersion: node?.display_version || "",
4298
- identity: fromInstallIdentityNode(node)
4301
+ displayVersion: payload.display_version ?? "",
4302
+ user: payload.user ? mapPeekTokenUser(payload.user) : null
4299
4303
  };
4300
4304
  }
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;
4305
+ function verifyInstallWebhook(token, secret) {
4306
+ const payload = verifyPeekJwt(token, secret);
4307
+ return {
4308
+ installId: payload.sub ?? "",
4309
+ account: { id: payload.account?.id ?? "" },
4310
+ status: payload.status ?? "",
4311
+ displayVersion: payload.display_version ?? "",
4312
+ user: payload.user ? mapPeekTokenUser(payload.user) : null
4313
+ };
4317
4314
  }
4318
4315
 
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 };
4316
+ 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, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
4320
4317
  //# sourceMappingURL=index.js.map
4321
4318
  //# sourceMappingURL=index.js.map