@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.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var crypto = require('crypto');
|
|
4
3
|
var jwt = require('jsonwebtoken');
|
|
4
|
+
var crypto = require('crypto');
|
|
5
5
|
|
|
6
6
|
function _interopNamespace(e) {
|
|
7
7
|
if (e && e.__esModule) return e;
|
|
@@ -23,6 +23,8 @@ function _interopNamespace(e) {
|
|
|
23
23
|
|
|
24
24
|
var jwt__namespace = /*#__PURE__*/_interopNamespace(jwt);
|
|
25
25
|
|
|
26
|
+
// src/peek-access-service.ts
|
|
27
|
+
|
|
26
28
|
// src/internal/gateway-endpoints.ts
|
|
27
29
|
var SALES_ENDPOINT = "sales";
|
|
28
30
|
var V2_EXTENDABLE_SLUG = "peek_backoffice_api-v1";
|
|
@@ -202,6 +204,8 @@ var AvailabilityService = class {
|
|
|
202
204
|
};
|
|
203
205
|
|
|
204
206
|
// src/models/product.ts
|
|
207
|
+
var ACTIVITY_PRODUCT_TYPE = "ACTIVITY";
|
|
208
|
+
var RENTAL_PRODUCT_TYPE = "RENTAL";
|
|
205
209
|
var ADD_ON_PRODUCT_TYPE = "ADD-ON";
|
|
206
210
|
|
|
207
211
|
// src/internal/bookings/booking-converter.ts
|
|
@@ -2723,6 +2727,21 @@ var ProductService = class {
|
|
|
2723
2727
|
]);
|
|
2724
2728
|
return [...fromActivities(activities), ...fromItemOptionNodes(itemOptionNodes)];
|
|
2725
2729
|
}
|
|
2730
|
+
/** Returns products with type {@link ACTIVITY_PRODUCT_TYPE}. */
|
|
2731
|
+
async getAllActivities() {
|
|
2732
|
+
const activities = await this.fetchActivities();
|
|
2733
|
+
return fromActivities(activities).filter((p) => p.type === ACTIVITY_PRODUCT_TYPE);
|
|
2734
|
+
}
|
|
2735
|
+
/** Returns products with type {@link RENTAL_PRODUCT_TYPE}. */
|
|
2736
|
+
async getAllRentals() {
|
|
2737
|
+
const activities = await this.fetchActivities();
|
|
2738
|
+
return fromActivities(activities).filter((p) => p.type === RENTAL_PRODUCT_TYPE);
|
|
2739
|
+
}
|
|
2740
|
+
/** Returns only add-on products. */
|
|
2741
|
+
async getAllAddons() {
|
|
2742
|
+
const nodes = await this.fetchAllItemOptionNodes();
|
|
2743
|
+
return fromItemOptionNodes(nodes);
|
|
2744
|
+
}
|
|
2726
2745
|
async fetchActivities() {
|
|
2727
2746
|
const body = await this.client.request(
|
|
2728
2747
|
SALES_ENDPOINT,
|
|
@@ -2918,9 +2937,11 @@ var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
|
|
|
2918
2937
|
var DEFAULT_TOKEN_TTL_SECONDS = 3600;
|
|
2919
2938
|
var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
|
|
2920
2939
|
var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
|
|
2940
|
+
var PEEK_TOKEN_ISSUER = "app_registry_v2";
|
|
2921
2941
|
var PeekAccessService = class {
|
|
2922
2942
|
client;
|
|
2923
2943
|
productServiceOptions;
|
|
2944
|
+
jwtSecret;
|
|
2924
2945
|
productService;
|
|
2925
2946
|
accountUserService;
|
|
2926
2947
|
resourcePoolService;
|
|
@@ -2939,6 +2960,7 @@ var PeekAccessService = class {
|
|
|
2939
2960
|
requireNonEmpty(config.issuer, "issuer");
|
|
2940
2961
|
requireNonEmpty(config.appId, "appId");
|
|
2941
2962
|
if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
|
|
2963
|
+
this.jwtSecret = config.jwtSecret;
|
|
2942
2964
|
const logger = config.logger ?? noopLogger;
|
|
2943
2965
|
const tokens = new TokenManager({
|
|
2944
2966
|
secret: config.jwtSecret,
|
|
@@ -2962,6 +2984,41 @@ var PeekAccessService = class {
|
|
|
2962
2984
|
itemOptionsPageSize: config.itemOptionsPageSize
|
|
2963
2985
|
};
|
|
2964
2986
|
}
|
|
2987
|
+
/**
|
|
2988
|
+
* Verifies a Peek auth token issued by the app registry and returns the
|
|
2989
|
+
* decoded claims.
|
|
2990
|
+
*
|
|
2991
|
+
* Validates the HMAC signature (using this service's `jwtSecret`), the token
|
|
2992
|
+
* expiry, the `"app_registry_v2"` issuer, and the `"Joken"` audience. Throws
|
|
2993
|
+
* from the `jsonwebtoken` library on any failure — callers should catch to
|
|
2994
|
+
* distinguish error kinds:
|
|
2995
|
+
*
|
|
2996
|
+
* - `JsonWebTokenError` — signature invalid, wrong issuer/audience, or token
|
|
2997
|
+
* malformed
|
|
2998
|
+
* - `TokenExpiredError` — past `exp`
|
|
2999
|
+
* - `NotBeforeError` — before `nbf`
|
|
3000
|
+
*
|
|
3001
|
+
* @throws {JsonWebTokenError} signature invalid or token malformed
|
|
3002
|
+
* @throws {TokenExpiredError} token has expired
|
|
3003
|
+
* @throws {NotBeforeError} token not yet valid
|
|
3004
|
+
*/
|
|
3005
|
+
verifyPeekAuthToken(token) {
|
|
3006
|
+
const payload = jwt__namespace.verify(token, this.jwtSecret, {
|
|
3007
|
+
issuer: PEEK_TOKEN_ISSUER
|
|
3008
|
+
});
|
|
3009
|
+
const { user: u } = payload;
|
|
3010
|
+
return {
|
|
3011
|
+
installId: payload.sub,
|
|
3012
|
+
displayVersion: payload.display_version,
|
|
3013
|
+
user: {
|
|
3014
|
+
email: u.email,
|
|
3015
|
+
id: u.id,
|
|
3016
|
+
isAdmin: u.is_admin,
|
|
3017
|
+
locale: u.locale,
|
|
3018
|
+
name: u.name
|
|
3019
|
+
}
|
|
3020
|
+
};
|
|
3021
|
+
}
|
|
2965
3022
|
/**
|
|
2966
3023
|
* Returns the {@link ProductService} for this install, bound to the shared
|
|
2967
3024
|
* authenticated transport. The instance is created lazily and reused.
|
|
@@ -3081,6 +3138,161 @@ var PeekAccessService = class {
|
|
|
3081
3138
|
}
|
|
3082
3139
|
return this.reviewService;
|
|
3083
3140
|
}
|
|
3141
|
+
// ─── Product short-forms ─────────────────────────────────────────────────
|
|
3142
|
+
/** All products (activities + add-ons). Delegates to {@link ProductService.getAllProducts}. */
|
|
3143
|
+
getAllProducts() {
|
|
3144
|
+
return this.getProductService().getAllProducts();
|
|
3145
|
+
}
|
|
3146
|
+
/** All activity products (excludes add-ons). Delegates to {@link ProductService.getAllActivities}. */
|
|
3147
|
+
getAllActivities() {
|
|
3148
|
+
return this.getProductService().getAllActivities();
|
|
3149
|
+
}
|
|
3150
|
+
/** All rental products. Delegates to {@link ProductService.getAllRentals}. */
|
|
3151
|
+
getAllRentals() {
|
|
3152
|
+
return this.getProductService().getAllRentals();
|
|
3153
|
+
}
|
|
3154
|
+
/** All add-on products. Delegates to {@link ProductService.getAllAddons}. */
|
|
3155
|
+
getAllAddons() {
|
|
3156
|
+
return this.getProductService().getAllAddons();
|
|
3157
|
+
}
|
|
3158
|
+
// ─── Account-user short-forms ─────────────────────────────────────────────
|
|
3159
|
+
/** All active account users. Delegates to {@link AccountUserService.getAll}. */
|
|
3160
|
+
getAllAccountUsers() {
|
|
3161
|
+
return this.getAccountUserService().getAll();
|
|
3162
|
+
}
|
|
3163
|
+
/** Account user by id, or null. Delegates to {@link AccountUserService.getById}. */
|
|
3164
|
+
getAccountUserById(userId) {
|
|
3165
|
+
return this.getAccountUserService().getById(userId);
|
|
3166
|
+
}
|
|
3167
|
+
// ─── Resource-pool short-forms ────────────────────────────────────────────
|
|
3168
|
+
/** All resource pools. Delegates to {@link ResourcePoolService.getAll}. */
|
|
3169
|
+
getAllResourcePools(mode) {
|
|
3170
|
+
return this.getResourcePoolService().getAll(mode);
|
|
3171
|
+
}
|
|
3172
|
+
// ─── Timeslot short-forms ─────────────────────────────────────────────────
|
|
3173
|
+
/** Timeslots for an activity on a given date. Delegates to {@link TimeslotService.getForDay}. */
|
|
3174
|
+
getTimeslotsForDay(productId, date, filter) {
|
|
3175
|
+
return this.getTimeslotService().getForDay(productId, date, filter);
|
|
3176
|
+
}
|
|
3177
|
+
/** Single timeslot by id. Delegates to {@link TimeslotService.getById}. */
|
|
3178
|
+
getTimeslotById(timeslotId) {
|
|
3179
|
+
return this.getTimeslotService().getById(timeslotId);
|
|
3180
|
+
}
|
|
3181
|
+
/** Set timeslot status. Delegates to {@link TimeslotService.setAvailability}. */
|
|
3182
|
+
setTimeslotAvailability(timeslotId, status) {
|
|
3183
|
+
return this.getTimeslotService().setAvailability(timeslotId, status);
|
|
3184
|
+
}
|
|
3185
|
+
/** Set timeslot manifest notes. Delegates to {@link TimeslotService.setNotes}. */
|
|
3186
|
+
setTimeslotNotes(timeslotId, manifestNotes) {
|
|
3187
|
+
return this.getTimeslotService().setNotes(timeslotId, manifestNotes);
|
|
3188
|
+
}
|
|
3189
|
+
/** Assign or unassign guides on timeslots. Delegates to {@link TimeslotService.assignGuide}. */
|
|
3190
|
+
assignTimeslotGuide(assignment) {
|
|
3191
|
+
return this.getTimeslotService().assignGuide(assignment);
|
|
3192
|
+
}
|
|
3193
|
+
// ─── Reseller short-forms ─────────────────────────────────────────────────
|
|
3194
|
+
/** All reseller channels. Delegates to {@link ResellerService.getAllChannels}. */
|
|
3195
|
+
getAllChannels(agentsPerChannel) {
|
|
3196
|
+
return this.getResellerService().getAllChannels(agentsPerChannel);
|
|
3197
|
+
}
|
|
3198
|
+
// ─── Promo-code short-forms ───────────────────────────────────────────────
|
|
3199
|
+
/** All promo codes. Delegates to {@link PromoCodeService.getAll}. */
|
|
3200
|
+
getAllPromoCodes() {
|
|
3201
|
+
return this.getPromoCodeService().getAll();
|
|
3202
|
+
}
|
|
3203
|
+
/** Create a promo code. Delegates to {@link PromoCodeService.create}. */
|
|
3204
|
+
createPromoCode(input) {
|
|
3205
|
+
return this.getPromoCodeService().create(input);
|
|
3206
|
+
}
|
|
3207
|
+
// ─── Daily-note short-forms ───────────────────────────────────────────────
|
|
3208
|
+
/** Today's daily note. Delegates to {@link DailyNoteService.getToday}. */
|
|
3209
|
+
getDailyNoteToday() {
|
|
3210
|
+
return this.getDailyNoteService().getToday();
|
|
3211
|
+
}
|
|
3212
|
+
/** Update today's daily note. Delegates to {@link DailyNoteService.update}. */
|
|
3213
|
+
updateDailyNote(note) {
|
|
3214
|
+
return this.getDailyNoteService().update(note);
|
|
3215
|
+
}
|
|
3216
|
+
// ─── Availability short-forms ─────────────────────────────────────────────
|
|
3217
|
+
/** Availability times for an activity. Delegates to {@link AvailabilityService.getAvailabilityTimes}. */
|
|
3218
|
+
getAvailabilityTimes(query) {
|
|
3219
|
+
return this.getAvailabilityService().getAvailabilityTimes(query);
|
|
3220
|
+
}
|
|
3221
|
+
// ─── Membership short-forms ───────────────────────────────────────────────
|
|
3222
|
+
/** All memberships. Delegates to {@link MembershipService.getAll}. */
|
|
3223
|
+
getAllMemberships() {
|
|
3224
|
+
return this.getMembershipService().getAll();
|
|
3225
|
+
}
|
|
3226
|
+
/** Purchase a membership. Delegates to {@link MembershipService.purchase}. */
|
|
3227
|
+
purchaseMembership(input) {
|
|
3228
|
+
return this.getMembershipService().purchase(input);
|
|
3229
|
+
}
|
|
3230
|
+
// ─── Booking short-forms ──────────────────────────────────────────────────
|
|
3231
|
+
/** Booking by id. Delegates to {@link BookingService.getById}. */
|
|
3232
|
+
getBookingById(bookingId, options) {
|
|
3233
|
+
return this.getBookingService().getById(bookingId, options);
|
|
3234
|
+
}
|
|
3235
|
+
/** Bookings by time range. Delegates to {@link BookingService.searchByTimeRange}. */
|
|
3236
|
+
searchBookingsByTimeRange(input) {
|
|
3237
|
+
return this.getBookingService().searchByTimeRange(input);
|
|
3238
|
+
}
|
|
3239
|
+
/** Bookings on a timeslot. Delegates to {@link BookingService.searchByTimeslot}. */
|
|
3240
|
+
searchBookingsByTimeslot(timeslotId, options) {
|
|
3241
|
+
return this.getBookingService().searchByTimeslot(timeslotId, options);
|
|
3242
|
+
}
|
|
3243
|
+
/** Guests on a booking. Delegates to {@link BookingService.getGuests}. */
|
|
3244
|
+
getBookingGuests(bookingId) {
|
|
3245
|
+
return this.getBookingService().getGuests(bookingId);
|
|
3246
|
+
}
|
|
3247
|
+
/** Payments on file for a booking. Delegates to {@link BookingService.getPaymentsOnFile}. */
|
|
3248
|
+
getBookingPaymentsOnFile(bookingId) {
|
|
3249
|
+
return this.getBookingService().getPaymentsOnFile(bookingId);
|
|
3250
|
+
}
|
|
3251
|
+
/** Append or overwrite operator notes. Delegates to {@link BookingService.appendNote}. */
|
|
3252
|
+
appendBookingNote(bookingId, note, mode) {
|
|
3253
|
+
return this.getBookingService().appendNote(bookingId, note, mode);
|
|
3254
|
+
}
|
|
3255
|
+
/** Set booking check-in status. Delegates to {@link BookingService.setCheckinStatus}. */
|
|
3256
|
+
setBookingCheckinStatus(bookingId, checkedIn) {
|
|
3257
|
+
return this.getBookingService().setCheckinStatus(bookingId, checkedIn);
|
|
3258
|
+
}
|
|
3259
|
+
/** Cancel a booking. Delegates to {@link BookingService.cancel}. */
|
|
3260
|
+
cancelBooking(bookingId, notes) {
|
|
3261
|
+
return this.getBookingService().cancel(bookingId, notes);
|
|
3262
|
+
}
|
|
3263
|
+
/** Charge a booking. Delegates to {@link BookingService.makePayment}. */
|
|
3264
|
+
makeBookingPayment(input) {
|
|
3265
|
+
return this.getBookingService().makePayment(input);
|
|
3266
|
+
}
|
|
3267
|
+
/** Refund a booking payment. Delegates to {@link BookingService.refund}. */
|
|
3268
|
+
refundBooking(input) {
|
|
3269
|
+
return this.getBookingService().refund(input);
|
|
3270
|
+
}
|
|
3271
|
+
/** Create an invoice link. Delegates to {@link BookingService.createInvoiceLink}. */
|
|
3272
|
+
createBookingInvoiceLink(bookingId) {
|
|
3273
|
+
return this.getBookingService().createInvoiceLink(bookingId);
|
|
3274
|
+
}
|
|
3275
|
+
/** List add-ons on a booking. Delegates to {@link BookingService.listAddons}. */
|
|
3276
|
+
listBookingAddons(bookingId) {
|
|
3277
|
+
return this.getBookingService().listAddons(bookingId);
|
|
3278
|
+
}
|
|
3279
|
+
/** Add an add-on to a booking. Delegates to {@link BookingService.addAddon}. */
|
|
3280
|
+
addBookingAddon(bookingId, input) {
|
|
3281
|
+
return this.getBookingService().addAddon(bookingId, input);
|
|
3282
|
+
}
|
|
3283
|
+
/** Remove an add-on from a booking. Delegates to {@link BookingService.removeAddon}. */
|
|
3284
|
+
removeBookingAddon(bookingId, input) {
|
|
3285
|
+
return this.getBookingService().removeAddon(bookingId, input);
|
|
3286
|
+
}
|
|
3287
|
+
/** Create a booking. Delegates to {@link BookingService.create}. */
|
|
3288
|
+
createBooking(input) {
|
|
3289
|
+
return this.getBookingService().create(input);
|
|
3290
|
+
}
|
|
3291
|
+
// ─── Review short-forms ───────────────────────────────────────────────────
|
|
3292
|
+
/** Reviews for an activity. Delegates to {@link ReviewService.getReviews}. */
|
|
3293
|
+
getReviews(productId, reviewCount, reviewOffset) {
|
|
3294
|
+
return this.getReviewService().getReviews(productId, reviewCount, reviewOffset);
|
|
3295
|
+
}
|
|
3084
3296
|
};
|
|
3085
3297
|
function requireNonEmpty(value, name) {
|
|
3086
3298
|
if (!value) {
|
|
@@ -3173,6 +3385,7 @@ function extractWaiverNode(payload) {
|
|
|
3173
3385
|
return record;
|
|
3174
3386
|
}
|
|
3175
3387
|
|
|
3388
|
+
exports.ACTIVITY_PRODUCT_TYPE = ACTIVITY_PRODUCT_TYPE;
|
|
3176
3389
|
exports.ADD_ON_PRODUCT_TYPE = ADD_ON_PRODUCT_TYPE;
|
|
3177
3390
|
exports.AccountUserService = AccountUserService;
|
|
3178
3391
|
exports.AdminAccountRequiredError = AdminAccountRequiredError;
|
|
@@ -3184,6 +3397,7 @@ exports.PeekAccessService = PeekAccessService;
|
|
|
3184
3397
|
exports.PeekGraphQLError = PeekGraphQLError;
|
|
3185
3398
|
exports.ProductService = ProductService;
|
|
3186
3399
|
exports.PromoCodeService = PromoCodeService;
|
|
3400
|
+
exports.RENTAL_PRODUCT_TYPE = RENTAL_PRODUCT_TYPE;
|
|
3187
3401
|
exports.RateLimitError = RateLimitError;
|
|
3188
3402
|
exports.ResellerService = ResellerService;
|
|
3189
3403
|
exports.ResourcePoolService = ResourcePoolService;
|