@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/README.md +51 -50
- package/dist/index.cjs +43 -46
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +100 -84
- package/dist/index.d.ts +100 -84
- package/dist/index.js +43 -46
- package/dist/index.js.map +1 -1
- package/docs/webhooks.md +107 -128
- package/llms.txt +27 -27
- package/package.json +1 -1
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.
|
|
3568
|
-
*
|
|
3569
|
-
*
|
|
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
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
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:
|
|
4286
|
-
accountId: account
|
|
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:
|
|
4298
|
-
|
|
4301
|
+
displayVersion: payload.display_version ?? "",
|
|
4302
|
+
user: payload.user ? mapPeekTokenUser(payload.user) : null
|
|
4299
4303
|
};
|
|
4300
4304
|
}
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
}
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
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,
|
|
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
|