@peektravel/app-utilities 0.2.2 → 0.2.4
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.cjs +215 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +444 -329
- package/dist/index.d.ts +444 -329
- package/dist/index.js +214 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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";
|
|
@@ -180,6 +182,8 @@ var AvailabilityService = class {
|
|
|
180
182
|
};
|
|
181
183
|
|
|
182
184
|
// src/models/product.ts
|
|
185
|
+
var ACTIVITY_PRODUCT_TYPE = "ACTIVITY";
|
|
186
|
+
var RENTAL_PRODUCT_TYPE = "RENTAL";
|
|
183
187
|
var ADD_ON_PRODUCT_TYPE = "ADD-ON";
|
|
184
188
|
|
|
185
189
|
// src/internal/bookings/booking-converter.ts
|
|
@@ -2701,6 +2705,21 @@ var ProductService = class {
|
|
|
2701
2705
|
]);
|
|
2702
2706
|
return [...fromActivities(activities), ...fromItemOptionNodes(itemOptionNodes)];
|
|
2703
2707
|
}
|
|
2708
|
+
/** Returns products with type {@link ACTIVITY_PRODUCT_TYPE}. */
|
|
2709
|
+
async getAllActivities() {
|
|
2710
|
+
const activities = await this.fetchActivities();
|
|
2711
|
+
return fromActivities(activities).filter((p) => p.type === ACTIVITY_PRODUCT_TYPE);
|
|
2712
|
+
}
|
|
2713
|
+
/** Returns products with type {@link RENTAL_PRODUCT_TYPE}. */
|
|
2714
|
+
async getAllRentals() {
|
|
2715
|
+
const activities = await this.fetchActivities();
|
|
2716
|
+
return fromActivities(activities).filter((p) => p.type === RENTAL_PRODUCT_TYPE);
|
|
2717
|
+
}
|
|
2718
|
+
/** Returns only add-on products. */
|
|
2719
|
+
async getAllAddons() {
|
|
2720
|
+
const nodes = await this.fetchAllItemOptionNodes();
|
|
2721
|
+
return fromItemOptionNodes(nodes);
|
|
2722
|
+
}
|
|
2704
2723
|
async fetchActivities() {
|
|
2705
2724
|
const body = await this.client.request(
|
|
2706
2725
|
SALES_ENDPOINT,
|
|
@@ -2896,9 +2915,11 @@ var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
|
|
|
2896
2915
|
var DEFAULT_TOKEN_TTL_SECONDS = 3600;
|
|
2897
2916
|
var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
|
|
2898
2917
|
var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
|
|
2918
|
+
var PEEK_TOKEN_ISSUER = "app_registry_v2";
|
|
2899
2919
|
var PeekAccessService = class {
|
|
2900
2920
|
client;
|
|
2901
2921
|
productServiceOptions;
|
|
2922
|
+
jwtSecret;
|
|
2902
2923
|
productService;
|
|
2903
2924
|
accountUserService;
|
|
2904
2925
|
resourcePoolService;
|
|
@@ -2917,6 +2938,7 @@ var PeekAccessService = class {
|
|
|
2917
2938
|
requireNonEmpty(config.issuer, "issuer");
|
|
2918
2939
|
requireNonEmpty(config.appId, "appId");
|
|
2919
2940
|
if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
|
|
2941
|
+
this.jwtSecret = config.jwtSecret;
|
|
2920
2942
|
const logger = config.logger ?? noopLogger;
|
|
2921
2943
|
const tokens = new TokenManager({
|
|
2922
2944
|
secret: config.jwtSecret,
|
|
@@ -2940,6 +2962,41 @@ var PeekAccessService = class {
|
|
|
2940
2962
|
itemOptionsPageSize: config.itemOptionsPageSize
|
|
2941
2963
|
};
|
|
2942
2964
|
}
|
|
2965
|
+
/**
|
|
2966
|
+
* Verifies a Peek auth token issued by the app registry and returns the
|
|
2967
|
+
* decoded claims.
|
|
2968
|
+
*
|
|
2969
|
+
* Validates the HMAC signature (using this service's `jwtSecret`), the token
|
|
2970
|
+
* expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
|
|
2971
|
+
* from the `jsonwebtoken` library on any failure — callers should catch to
|
|
2972
|
+
* distinguish error kinds:
|
|
2973
|
+
*
|
|
2974
|
+
* - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
|
|
2975
|
+
* malformed
|
|
2976
|
+
* - `TokenExpiredError` — past `exp`
|
|
2977
|
+
* - `NotBeforeError` — before `nbf`
|
|
2978
|
+
*
|
|
2979
|
+
* @throws {JsonWebTokenError} signature invalid or token malformed
|
|
2980
|
+
* @throws {TokenExpiredError} token has expired
|
|
2981
|
+
* @throws {NotBeforeError} token not yet valid
|
|
2982
|
+
*/
|
|
2983
|
+
verifyPeekAuthToken(token) {
|
|
2984
|
+
const payload = jwt.verify(token, this.jwtSecret, {
|
|
2985
|
+
issuer: PEEK_TOKEN_ISSUER
|
|
2986
|
+
});
|
|
2987
|
+
const { user: u } = payload;
|
|
2988
|
+
return {
|
|
2989
|
+
installId: payload.sub,
|
|
2990
|
+
displayVersion: payload.display_version,
|
|
2991
|
+
user: {
|
|
2992
|
+
email: u.email,
|
|
2993
|
+
id: u.id,
|
|
2994
|
+
isAdmin: u.is_admin,
|
|
2995
|
+
locale: u.locale,
|
|
2996
|
+
name: u.name
|
|
2997
|
+
}
|
|
2998
|
+
};
|
|
2999
|
+
}
|
|
2943
3000
|
/**
|
|
2944
3001
|
* Returns the {@link ProductService} for this install, bound to the shared
|
|
2945
3002
|
* authenticated transport. The instance is created lazily and reused.
|
|
@@ -3059,6 +3116,161 @@ var PeekAccessService = class {
|
|
|
3059
3116
|
}
|
|
3060
3117
|
return this.reviewService;
|
|
3061
3118
|
}
|
|
3119
|
+
// ─── Product short-forms ─────────────────────────────────────────────────
|
|
3120
|
+
/** All products (activities + add-ons). Delegates to {@link ProductService.getAllProducts}. */
|
|
3121
|
+
getAllProducts() {
|
|
3122
|
+
return this.getProductService().getAllProducts();
|
|
3123
|
+
}
|
|
3124
|
+
/** All activity products (excludes add-ons). Delegates to {@link ProductService.getAllActivities}. */
|
|
3125
|
+
getAllActivities() {
|
|
3126
|
+
return this.getProductService().getAllActivities();
|
|
3127
|
+
}
|
|
3128
|
+
/** All rental products. Delegates to {@link ProductService.getAllRentals}. */
|
|
3129
|
+
getAllRentals() {
|
|
3130
|
+
return this.getProductService().getAllRentals();
|
|
3131
|
+
}
|
|
3132
|
+
/** All add-on products. Delegates to {@link ProductService.getAllAddons}. */
|
|
3133
|
+
getAllAddons() {
|
|
3134
|
+
return this.getProductService().getAllAddons();
|
|
3135
|
+
}
|
|
3136
|
+
// ─── Account-user short-forms ─────────────────────────────────────────────
|
|
3137
|
+
/** All active account users. Delegates to {@link AccountUserService.getAll}. */
|
|
3138
|
+
getAllAccountUsers() {
|
|
3139
|
+
return this.getAccountUserService().getAll();
|
|
3140
|
+
}
|
|
3141
|
+
/** Account user by id, or null. Delegates to {@link AccountUserService.getById}. */
|
|
3142
|
+
getAccountUserById(userId) {
|
|
3143
|
+
return this.getAccountUserService().getById(userId);
|
|
3144
|
+
}
|
|
3145
|
+
// ─── Resource-pool short-forms ────────────────────────────────────────────
|
|
3146
|
+
/** All resource pools. Delegates to {@link ResourcePoolService.getAll}. */
|
|
3147
|
+
getAllResourcePools(mode) {
|
|
3148
|
+
return this.getResourcePoolService().getAll(mode);
|
|
3149
|
+
}
|
|
3150
|
+
// ─── Timeslot short-forms ─────────────────────────────────────────────────
|
|
3151
|
+
/** Timeslots for an activity on a given date. Delegates to {@link TimeslotService.getForDay}. */
|
|
3152
|
+
getTimeslotsForDay(productId, date, filter) {
|
|
3153
|
+
return this.getTimeslotService().getForDay(productId, date, filter);
|
|
3154
|
+
}
|
|
3155
|
+
/** Single timeslot by id. Delegates to {@link TimeslotService.getById}. */
|
|
3156
|
+
getTimeslotById(timeslotId) {
|
|
3157
|
+
return this.getTimeslotService().getById(timeslotId);
|
|
3158
|
+
}
|
|
3159
|
+
/** Set timeslot status. Delegates to {@link TimeslotService.setAvailability}. */
|
|
3160
|
+
setTimeslotAvailability(timeslotId, status) {
|
|
3161
|
+
return this.getTimeslotService().setAvailability(timeslotId, status);
|
|
3162
|
+
}
|
|
3163
|
+
/** Set timeslot manifest notes. Delegates to {@link TimeslotService.setNotes}. */
|
|
3164
|
+
setTimeslotNotes(timeslotId, manifestNotes) {
|
|
3165
|
+
return this.getTimeslotService().setNotes(timeslotId, manifestNotes);
|
|
3166
|
+
}
|
|
3167
|
+
/** Assign or unassign guides on timeslots. Delegates to {@link TimeslotService.assignGuide}. */
|
|
3168
|
+
assignTimeslotGuide(assignment) {
|
|
3169
|
+
return this.getTimeslotService().assignGuide(assignment);
|
|
3170
|
+
}
|
|
3171
|
+
// ─── Reseller short-forms ─────────────────────────────────────────────────
|
|
3172
|
+
/** All reseller channels. Delegates to {@link ResellerService.getAllChannels}. */
|
|
3173
|
+
getAllChannels(agentsPerChannel) {
|
|
3174
|
+
return this.getResellerService().getAllChannels(agentsPerChannel);
|
|
3175
|
+
}
|
|
3176
|
+
// ─── Promo-code short-forms ───────────────────────────────────────────────
|
|
3177
|
+
/** All promo codes. Delegates to {@link PromoCodeService.getAll}. */
|
|
3178
|
+
getAllPromoCodes() {
|
|
3179
|
+
return this.getPromoCodeService().getAll();
|
|
3180
|
+
}
|
|
3181
|
+
/** Create a promo code. Delegates to {@link PromoCodeService.create}. */
|
|
3182
|
+
createPromoCode(input) {
|
|
3183
|
+
return this.getPromoCodeService().create(input);
|
|
3184
|
+
}
|
|
3185
|
+
// ─── Daily-note short-forms ───────────────────────────────────────────────
|
|
3186
|
+
/** Today's daily note. Delegates to {@link DailyNoteService.getToday}. */
|
|
3187
|
+
getDailyNoteToday() {
|
|
3188
|
+
return this.getDailyNoteService().getToday();
|
|
3189
|
+
}
|
|
3190
|
+
/** Update today's daily note. Delegates to {@link DailyNoteService.update}. */
|
|
3191
|
+
updateDailyNote(note) {
|
|
3192
|
+
return this.getDailyNoteService().update(note);
|
|
3193
|
+
}
|
|
3194
|
+
// ─── Availability short-forms ─────────────────────────────────────────────
|
|
3195
|
+
/** Availability times for an activity. Delegates to {@link AvailabilityService.getAvailabilityTimes}. */
|
|
3196
|
+
getAvailabilityTimes(query) {
|
|
3197
|
+
return this.getAvailabilityService().getAvailabilityTimes(query);
|
|
3198
|
+
}
|
|
3199
|
+
// ─── Membership short-forms ───────────────────────────────────────────────
|
|
3200
|
+
/** All memberships. Delegates to {@link MembershipService.getAll}. */
|
|
3201
|
+
getAllMemberships() {
|
|
3202
|
+
return this.getMembershipService().getAll();
|
|
3203
|
+
}
|
|
3204
|
+
/** Purchase a membership. Delegates to {@link MembershipService.purchase}. */
|
|
3205
|
+
purchaseMembership(input) {
|
|
3206
|
+
return this.getMembershipService().purchase(input);
|
|
3207
|
+
}
|
|
3208
|
+
// ─── Booking short-forms ──────────────────────────────────────────────────
|
|
3209
|
+
/** Booking by id. Delegates to {@link BookingService.getById}. */
|
|
3210
|
+
getBookingById(bookingId, options) {
|
|
3211
|
+
return this.getBookingService().getById(bookingId, options);
|
|
3212
|
+
}
|
|
3213
|
+
/** Bookings by time range. Delegates to {@link BookingService.searchByTimeRange}. */
|
|
3214
|
+
searchBookingsByTimeRange(input) {
|
|
3215
|
+
return this.getBookingService().searchByTimeRange(input);
|
|
3216
|
+
}
|
|
3217
|
+
/** Bookings on a timeslot. Delegates to {@link BookingService.searchByTimeslot}. */
|
|
3218
|
+
searchBookingsByTimeslot(timeslotId, options) {
|
|
3219
|
+
return this.getBookingService().searchByTimeslot(timeslotId, options);
|
|
3220
|
+
}
|
|
3221
|
+
/** Guests on a booking. Delegates to {@link BookingService.getGuests}. */
|
|
3222
|
+
getBookingGuests(bookingId) {
|
|
3223
|
+
return this.getBookingService().getGuests(bookingId);
|
|
3224
|
+
}
|
|
3225
|
+
/** Payments on file for a booking. Delegates to {@link BookingService.getPaymentsOnFile}. */
|
|
3226
|
+
getBookingPaymentsOnFile(bookingId) {
|
|
3227
|
+
return this.getBookingService().getPaymentsOnFile(bookingId);
|
|
3228
|
+
}
|
|
3229
|
+
/** Append or overwrite operator notes. Delegates to {@link BookingService.appendNote}. */
|
|
3230
|
+
appendBookingNote(bookingId, note, mode) {
|
|
3231
|
+
return this.getBookingService().appendNote(bookingId, note, mode);
|
|
3232
|
+
}
|
|
3233
|
+
/** Set booking check-in status. Delegates to {@link BookingService.setCheckinStatus}. */
|
|
3234
|
+
setBookingCheckinStatus(bookingId, checkedIn) {
|
|
3235
|
+
return this.getBookingService().setCheckinStatus(bookingId, checkedIn);
|
|
3236
|
+
}
|
|
3237
|
+
/** Cancel a booking. Delegates to {@link BookingService.cancel}. */
|
|
3238
|
+
cancelBooking(bookingId, notes) {
|
|
3239
|
+
return this.getBookingService().cancel(bookingId, notes);
|
|
3240
|
+
}
|
|
3241
|
+
/** Charge a booking. Delegates to {@link BookingService.makePayment}. */
|
|
3242
|
+
makeBookingPayment(input) {
|
|
3243
|
+
return this.getBookingService().makePayment(input);
|
|
3244
|
+
}
|
|
3245
|
+
/** Refund a booking payment. Delegates to {@link BookingService.refund}. */
|
|
3246
|
+
refundBooking(input) {
|
|
3247
|
+
return this.getBookingService().refund(input);
|
|
3248
|
+
}
|
|
3249
|
+
/** Create an invoice link. Delegates to {@link BookingService.createInvoiceLink}. */
|
|
3250
|
+
createBookingInvoiceLink(bookingId) {
|
|
3251
|
+
return this.getBookingService().createInvoiceLink(bookingId);
|
|
3252
|
+
}
|
|
3253
|
+
/** List add-ons on a booking. Delegates to {@link BookingService.listAddons}. */
|
|
3254
|
+
listBookingAddons(bookingId) {
|
|
3255
|
+
return this.getBookingService().listAddons(bookingId);
|
|
3256
|
+
}
|
|
3257
|
+
/** Add an add-on to a booking. Delegates to {@link BookingService.addAddon}. */
|
|
3258
|
+
addBookingAddon(bookingId, input) {
|
|
3259
|
+
return this.getBookingService().addAddon(bookingId, input);
|
|
3260
|
+
}
|
|
3261
|
+
/** Remove an add-on from a booking. Delegates to {@link BookingService.removeAddon}. */
|
|
3262
|
+
removeBookingAddon(bookingId, input) {
|
|
3263
|
+
return this.getBookingService().removeAddon(bookingId, input);
|
|
3264
|
+
}
|
|
3265
|
+
/** Create a booking. Delegates to {@link BookingService.create}. */
|
|
3266
|
+
createBooking(input) {
|
|
3267
|
+
return this.getBookingService().create(input);
|
|
3268
|
+
}
|
|
3269
|
+
// ─── Review short-forms ───────────────────────────────────────────────────
|
|
3270
|
+
/** Reviews for an activity. Delegates to {@link ReviewService.getReviews}. */
|
|
3271
|
+
getReviews(productId, reviewCount, reviewOffset) {
|
|
3272
|
+
return this.getReviewService().getReviews(productId, reviewCount, reviewOffset);
|
|
3273
|
+
}
|
|
3062
3274
|
};
|
|
3063
3275
|
function requireNonEmpty(value, name) {
|
|
3064
3276
|
if (!value) {
|
|
@@ -3151,6 +3363,6 @@ function extractWaiverNode(payload) {
|
|
|
3151
3363
|
return record;
|
|
3152
3364
|
}
|
|
3153
3365
|
|
|
3154
|
-
export { ADD_ON_PRODUCT_TYPE, AccountUserService, AdminAccountRequiredError, AvailabilityService, BookingService, DailyNoteService, MembershipService, PeekAccessService, PeekGraphQLError, ProductService, PromoCodeService, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, noopLogger, parseBookingWebhook, parseWaiverWebhook };
|
|
3366
|
+
export { ACTIVITY_PRODUCT_TYPE, ADD_ON_PRODUCT_TYPE, AccountUserService, AdminAccountRequiredError, AvailabilityService, BookingService, DailyNoteService, MembershipService, PeekAccessService, PeekGraphQLError, ProductService, PromoCodeService, RENTAL_PRODUCT_TYPE, RateLimitError, ResellerService, ResourcePoolService, ReviewService, TimeslotService, noopLogger, parseBookingWebhook, parseWaiverWebhook };
|
|
3155
3367
|
//# sourceMappingURL=index.js.map
|
|
3156
3368
|
//# sourceMappingURL=index.js.map
|