@peektravel/app-utilities 0.7.1 → 0.7.2

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
@@ -2022,7 +2022,8 @@ var GraphQLClient = class {
2022
2022
  );
2023
2023
  }
2024
2024
  endpoint(endpointName) {
2025
- const { baseUrl, appId, endpointPathPrefix } = this.options;
2025
+ const { apiUrl, baseUrl, appId, endpointPathPrefix } = this.options;
2026
+ if (apiUrl) return apiUrl;
2026
2027
  const prefix = endpointPathPrefix ? `${endpointPathPrefix}/` : "";
2027
2028
  return `${baseUrl}/${appId}/${prefix}${endpointName}`;
2028
2029
  }
@@ -3539,25 +3540,27 @@ var PeekAccessService = class {
3539
3540
  bookingService;
3540
3541
  reviewService;
3541
3542
  constructor(config) {
3543
+ const hasApiUrl = !!config.apiUrl;
3542
3544
  const isV2 = config.mode === "v2";
3543
3545
  requireNonEmpty(config.installId, "installId", "PeekAccessService");
3544
3546
  requireNonEmpty(config.jwtSecret, "jwtSecret", "PeekAccessService");
3545
3547
  requireNonEmpty(config.issuer, "issuer", "PeekAccessService");
3546
- requireNonEmpty(config.appId, "appId", "PeekAccessService");
3547
- if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey", "PeekAccessService");
3548
+ if (!hasApiUrl) requireNonEmpty(config.appId ?? "", "appId", "PeekAccessService");
3549
+ if (!hasApiUrl && !isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey", "PeekAccessService");
3548
3550
  this.jwtSecret = config.jwtSecret;
3549
3551
  const logger = config.logger ?? noopLogger;
3550
3552
  const tokens = createTokenManager(config);
3551
3553
  const defaultBaseUrl = isV2 ? DEFAULT_V2_BASE_URL : DEFAULT_BASE_URL;
3552
3554
  this.client = new GraphQLClient({
3553
- baseUrl: config.baseUrl ?? defaultBaseUrl,
3554
- appId: config.appId,
3555
+ apiUrl: config.apiUrl,
3556
+ baseUrl: hasApiUrl ? void 0 : config.baseUrl ?? defaultBaseUrl,
3557
+ appId: hasApiUrl ? void 0 : config.appId,
3555
3558
  gatewayKey: config.gatewayKey,
3556
3559
  getToken: () => tokens.getToken(),
3557
3560
  retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
3558
3561
  logger,
3559
3562
  fetchFn: config.fetch ?? globalThis.fetch,
3560
- endpointPathPrefix: isV2 ? V2_EXTENDABLE_SLUG : void 0
3563
+ endpointPathPrefix: !hasApiUrl && isV2 ? V2_EXTENDABLE_SLUG : void 0
3561
3564
  });
3562
3565
  this.productServiceOptions = {
3563
3566
  itemOptionsPageSize: config.itemOptionsPageSize
@@ -3985,7 +3988,8 @@ var RestClient = class {
3985
3988
  );
3986
3989
  }
3987
3990
  endpoint(path) {
3988
- const { baseUrl, appId, extendableSlug } = this.options;
3991
+ const { apiUrl, baseUrl, appId, extendableSlug } = this.options;
3992
+ if (apiUrl) return `${apiUrl}/${path}`;
3989
3993
  return `${baseUrl}/${appId}/${extendableSlug}/${path}`;
3990
3994
  }
3991
3995
  buildHeaders() {
@@ -4002,15 +4006,17 @@ var CngAccessService = class {
4002
4006
  client;
4003
4007
  productService;
4004
4008
  constructor(config) {
4009
+ const hasApiUrl = !!config.apiUrl;
4005
4010
  requireNonEmpty(config.installId, "installId", "CngAccessService");
4006
4011
  requireNonEmpty(config.jwtSecret, "jwtSecret", "CngAccessService");
4007
4012
  requireNonEmpty(config.issuer, "issuer", "CngAccessService");
4008
- requireNonEmpty(config.appId, "appId", "CngAccessService");
4013
+ if (!hasApiUrl) requireNonEmpty(config.appId ?? "", "appId", "CngAccessService");
4009
4014
  const logger = config.logger ?? noopLogger;
4010
4015
  const tokens = createTokenManager(config);
4011
4016
  this.client = new RestClient({
4012
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL2,
4013
- appId: config.appId,
4017
+ apiUrl: config.apiUrl,
4018
+ baseUrl: hasApiUrl ? void 0 : config.baseUrl ?? DEFAULT_BASE_URL2,
4019
+ appId: hasApiUrl ? void 0 : config.appId,
4014
4020
  extendableSlug: CNG_EXTENDABLE_SLUG,
4015
4021
  getToken: () => tokens.getToken(),
4016
4022
  retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
@@ -4116,7 +4122,8 @@ var RestClient2 = class {
4116
4122
  );
4117
4123
  }
4118
4124
  endpoint(path) {
4119
- const { baseUrl, appId, extendableSlug } = this.options;
4125
+ const { apiUrl, baseUrl, appId, extendableSlug } = this.options;
4126
+ if (apiUrl) return `${apiUrl}/${path}`;
4120
4127
  return `${baseUrl}/${appId}/${extendableSlug}/${path}`;
4121
4128
  }
4122
4129
  buildHeaders() {
@@ -4133,15 +4140,17 @@ var AcmeAccessService = class {
4133
4140
  client;
4134
4141
  productService;
4135
4142
  constructor(config) {
4143
+ const hasApiUrl = !!config.apiUrl;
4136
4144
  requireNonEmpty(config.installId, "installId", "AcmeAccessService");
4137
4145
  requireNonEmpty(config.jwtSecret, "jwtSecret", "AcmeAccessService");
4138
4146
  requireNonEmpty(config.issuer, "issuer", "AcmeAccessService");
4139
- requireNonEmpty(config.appId, "appId", "AcmeAccessService");
4147
+ if (!hasApiUrl) requireNonEmpty(config.appId ?? "", "appId", "AcmeAccessService");
4140
4148
  const logger = config.logger ?? noopLogger;
4141
4149
  const tokens = createTokenManager(config);
4142
4150
  this.client = new RestClient2({
4143
- baseUrl: config.baseUrl ?? DEFAULT_BASE_URL3,
4144
- appId: config.appId,
4151
+ apiUrl: config.apiUrl,
4152
+ baseUrl: hasApiUrl ? void 0 : config.baseUrl ?? DEFAULT_BASE_URL3,
4153
+ appId: hasApiUrl ? void 0 : config.appId,
4145
4154
  extendableSlug: ACME_EXTENDABLE_SLUG,
4146
4155
  getToken: () => tokens.getToken(),
4147
4156
  retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
@@ -4165,6 +4174,23 @@ var AcmeAccessService = class {
4165
4174
  }
4166
4175
  };
4167
4176
 
4177
+ // src/access-service-factory.ts
4178
+ function createAccessServiceForInstall(install, config) {
4179
+ const shared = { ...config, installId: install.installId, apiUrl: install.apiUrl };
4180
+ switch (install.platform) {
4181
+ case "peek":
4182
+ return new PeekAccessService(shared);
4183
+ case "cng":
4184
+ return new CngAccessService(shared);
4185
+ case "acme":
4186
+ return new AcmeAccessService(shared);
4187
+ default:
4188
+ throw new Error(
4189
+ `createAccessServiceForInstall: unknown or missing platform "${install.platform}" for install "${install.installId}"`
4190
+ );
4191
+ }
4192
+ }
4193
+
4168
4194
  // src/internal/peek/bookings/booking-webhook.ts
4169
4195
  var PAYLOAD_BOOKING_KEY = "booking";
4170
4196
  var VALUE_OPEN_TOKEN = "value {";
@@ -4288,20 +4314,27 @@ function toPeekPlatform(raw) {
4288
4314
  // src/internal/peek/installs/install-webhook.ts
4289
4315
  function parseInstallWebhook(token, body, secret) {
4290
4316
  const payload = verifyPeekJwt(token, secret);
4291
- const account = extractInstallWebhookBody(body).account ?? {};
4292
- const rawStatus = payload.status ?? "";
4317
+ const parsed = extractInstallWebhookBody(body);
4318
+ const account = parsed.account ?? {};
4319
+ const rawStatus = parsed.status || payload.status || "";
4293
4320
  return {
4294
- installId: payload.sub ?? "",
4295
- accountId: payload.account?.id ?? "",
4321
+ installId: parsed.install_id || payload.sub || "",
4322
+ accountId: account.id || payload.account?.id || "",
4296
4323
  accountName: account.name || "",
4297
4324
  platform: toPeekPlatform(account.platform || ""),
4298
4325
  isTest: Boolean(account.is_test),
4326
+ timezone: account.timezone || "",
4327
+ apiUrl: parsed.api?.url || "",
4299
4328
  status: toInstallStatus(rawStatus),
4300
4329
  rawStatus,
4301
- displayVersion: payload.display_version ?? "",
4302
- user: payload.user ? mapPeekTokenUser(payload.user) : null
4330
+ displayVersion: parsed.display_version || payload.display_version || "",
4331
+ user: resolveInstallUser(parsed.modified_by, payload.user)
4303
4332
  };
4304
4333
  }
4334
+ function resolveInstallUser(bodyUser, tokenUser) {
4335
+ if (bodyUser?.id) return mapPeekTokenUser(bodyUser);
4336
+ return tokenUser ? mapPeekTokenUser(tokenUser) : null;
4337
+ }
4305
4338
  function verifyInstallWebhook(token, secret) {
4306
4339
  const payload = verifyPeekJwt(token, secret);
4307
4340
  return {
@@ -4313,6 +4346,6 @@ function verifyInstallWebhook(token, secret) {
4313
4346
  };
4314
4347
  }
4315
4348
 
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 };
4349
+ 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, createAccessServiceForInstall, noopLogger, parseBookingWebhook, parseInstallWebhook, parseWaiverWebhook, verifyInstallWebhook };
4317
4350
  //# sourceMappingURL=index.js.map
4318
4351
  //# sourceMappingURL=index.js.map