@peektravel/app-utilities 0.1.6 → 0.2.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.cjs +16 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -5
- package/dist/index.d.ts +17 -5
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -23,8 +23,8 @@ interface GraphQLClientOptions {
|
|
|
23
23
|
baseUrl: string;
|
|
24
24
|
/** Peek app ID, used in the endpoint path. */
|
|
25
25
|
appId: string;
|
|
26
|
-
/** API gateway key sent as the `pk-api-key` header. */
|
|
27
|
-
gatewayKey
|
|
26
|
+
/** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
|
|
27
|
+
gatewayKey?: string;
|
|
28
28
|
/** Supplies a valid bearer token for each request. */
|
|
29
29
|
getToken: () => string;
|
|
30
30
|
/** Backoff delays (ms) applied on successive HTTP 429 responses. */
|
|
@@ -33,6 +33,11 @@ interface GraphQLClientOptions {
|
|
|
33
33
|
logger: Logger;
|
|
34
34
|
/** `fetch` implementation to use. */
|
|
35
35
|
fetchFn: typeof fetch;
|
|
36
|
+
/**
|
|
37
|
+
* Optional fixed path segment inserted between `appId` and the endpoint name.
|
|
38
|
+
* Used in v2 mode: `baseUrl/appId/endpointPathPrefix/endpointName`.
|
|
39
|
+
*/
|
|
40
|
+
endpointPathPrefix?: string;
|
|
36
41
|
}
|
|
37
42
|
declare class GraphQLClient {
|
|
38
43
|
private readonly options;
|
|
@@ -1199,9 +1204,16 @@ interface PeekAccessServiceConfig {
|
|
|
1199
1204
|
issuer: string;
|
|
1200
1205
|
/** Peek app ID, used in the gateway endpoint path. */
|
|
1201
1206
|
appId: string;
|
|
1202
|
-
/** API gateway key, sent as the `pk-api-key` header. */
|
|
1203
|
-
gatewayKey
|
|
1204
|
-
/**
|
|
1207
|
+
/** API gateway key, sent as the `pk-api-key` header. Required in v1 mode; not used in v2. */
|
|
1208
|
+
gatewayKey?: string;
|
|
1209
|
+
/**
|
|
1210
|
+
* Gateway mode. `"v2"` routes through the app-registry installations API
|
|
1211
|
+
* (`baseUrl/appId/peek_backoffice_api-v1/endpointName`) and defaults to the
|
|
1212
|
+
* app-registry sandbox base URL. `"v1"` (default) uses the standard backoffice
|
|
1213
|
+
* GraphQL gateway.
|
|
1214
|
+
*/
|
|
1215
|
+
mode?: "v2";
|
|
1216
|
+
/** Override the gateway base URL. Default: Peek production gateway (v1) or app-registry sandbox (v2). */
|
|
1205
1217
|
baseUrl?: string;
|
|
1206
1218
|
/** JWT lifetime in seconds. Default: 3600. */
|
|
1207
1219
|
tokenTtlSeconds?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ interface GraphQLClientOptions {
|
|
|
23
23
|
baseUrl: string;
|
|
24
24
|
/** Peek app ID, used in the endpoint path. */
|
|
25
25
|
appId: string;
|
|
26
|
-
/** API gateway key sent as the `pk-api-key` header. */
|
|
27
|
-
gatewayKey
|
|
26
|
+
/** API gateway key sent as the `pk-api-key` header. Omitted from headers when absent (v2 mode). */
|
|
27
|
+
gatewayKey?: string;
|
|
28
28
|
/** Supplies a valid bearer token for each request. */
|
|
29
29
|
getToken: () => string;
|
|
30
30
|
/** Backoff delays (ms) applied on successive HTTP 429 responses. */
|
|
@@ -33,6 +33,11 @@ interface GraphQLClientOptions {
|
|
|
33
33
|
logger: Logger;
|
|
34
34
|
/** `fetch` implementation to use. */
|
|
35
35
|
fetchFn: typeof fetch;
|
|
36
|
+
/**
|
|
37
|
+
* Optional fixed path segment inserted between `appId` and the endpoint name.
|
|
38
|
+
* Used in v2 mode: `baseUrl/appId/endpointPathPrefix/endpointName`.
|
|
39
|
+
*/
|
|
40
|
+
endpointPathPrefix?: string;
|
|
36
41
|
}
|
|
37
42
|
declare class GraphQLClient {
|
|
38
43
|
private readonly options;
|
|
@@ -1199,9 +1204,16 @@ interface PeekAccessServiceConfig {
|
|
|
1199
1204
|
issuer: string;
|
|
1200
1205
|
/** Peek app ID, used in the gateway endpoint path. */
|
|
1201
1206
|
appId: string;
|
|
1202
|
-
/** API gateway key, sent as the `pk-api-key` header. */
|
|
1203
|
-
gatewayKey
|
|
1204
|
-
/**
|
|
1207
|
+
/** API gateway key, sent as the `pk-api-key` header. Required in v1 mode; not used in v2. */
|
|
1208
|
+
gatewayKey?: string;
|
|
1209
|
+
/**
|
|
1210
|
+
* Gateway mode. `"v2"` routes through the app-registry installations API
|
|
1211
|
+
* (`baseUrl/appId/peek_backoffice_api-v1/endpointName`) and defaults to the
|
|
1212
|
+
* app-registry sandbox base URL. `"v1"` (default) uses the standard backoffice
|
|
1213
|
+
* GraphQL gateway.
|
|
1214
|
+
*/
|
|
1215
|
+
mode?: "v2";
|
|
1216
|
+
/** Override the gateway base URL. Default: Peek production gateway (v1) or app-registry sandbox (v2). */
|
|
1205
1217
|
baseUrl?: string;
|
|
1206
1218
|
/** JWT lifetime in seconds. Default: 3600. */
|
|
1207
1219
|
tokenTtlSeconds?: number;
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import * as jwt from 'jsonwebtoken';
|
|
|
3
3
|
|
|
4
4
|
// src/internal/gateway-endpoints.ts
|
|
5
5
|
var SALES_ENDPOINT = "sales";
|
|
6
|
+
var V2_EXTENDABLE_SLUG = "peek_backoffice_api-v1";
|
|
6
7
|
|
|
7
8
|
// src/internal/account-users/account-user-converter.ts
|
|
8
9
|
var ACTIVE_STATUS = "ACTIVE";
|
|
@@ -1819,14 +1820,19 @@ var GraphQLClient = class {
|
|
|
1819
1820
|
throw new RateLimitError();
|
|
1820
1821
|
}
|
|
1821
1822
|
endpoint(endpointName) {
|
|
1822
|
-
|
|
1823
|
+
const { baseUrl, appId, endpointPathPrefix } = this.options;
|
|
1824
|
+
const prefix = endpointPathPrefix ? `${endpointPathPrefix}/` : "";
|
|
1825
|
+
return `${baseUrl}/${appId}/${prefix}${endpointName}`;
|
|
1823
1826
|
}
|
|
1824
1827
|
buildHeaders() {
|
|
1825
|
-
|
|
1828
|
+
const headers = {
|
|
1826
1829
|
"X-Peek-Auth": `Bearer ${this.options.getToken()}`,
|
|
1827
|
-
"pk-api-key": this.options.gatewayKey,
|
|
1828
1830
|
"Content-Type": "application/json"
|
|
1829
1831
|
};
|
|
1832
|
+
if (this.options.gatewayKey) {
|
|
1833
|
+
headers["pk-api-key"] = this.options.gatewayKey;
|
|
1834
|
+
}
|
|
1835
|
+
return headers;
|
|
1830
1836
|
}
|
|
1831
1837
|
};
|
|
1832
1838
|
|
|
@@ -2886,6 +2892,7 @@ var noopLogger = {
|
|
|
2886
2892
|
|
|
2887
2893
|
// src/peek-access-service.ts
|
|
2888
2894
|
var DEFAULT_BASE_URL = "https://apps.peekapis.com/backoffice-gql";
|
|
2895
|
+
var DEFAULT_V2_BASE_URL = "https://app-registry.peeklabs.com/installations-api";
|
|
2889
2896
|
var DEFAULT_TOKEN_TTL_SECONDS = 3600;
|
|
2890
2897
|
var DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS = 60;
|
|
2891
2898
|
var DEFAULT_RETRY_DELAYS_MS = [1e3, 2e3, 4e3];
|
|
@@ -2904,11 +2911,12 @@ var PeekAccessService = class {
|
|
|
2904
2911
|
bookingService;
|
|
2905
2912
|
reviewService;
|
|
2906
2913
|
constructor(config) {
|
|
2914
|
+
const isV2 = config.mode === "v2";
|
|
2907
2915
|
requireNonEmpty(config.installId, "installId");
|
|
2908
2916
|
requireNonEmpty(config.jwtSecret, "jwtSecret");
|
|
2909
2917
|
requireNonEmpty(config.issuer, "issuer");
|
|
2910
2918
|
requireNonEmpty(config.appId, "appId");
|
|
2911
|
-
requireNonEmpty(config.gatewayKey, "gatewayKey");
|
|
2919
|
+
if (!isV2) requireNonEmpty(config.gatewayKey ?? "", "gatewayKey");
|
|
2912
2920
|
const logger = config.logger ?? noopLogger;
|
|
2913
2921
|
const tokens = new TokenManager({
|
|
2914
2922
|
secret: config.jwtSecret,
|
|
@@ -2917,14 +2925,16 @@ var PeekAccessService = class {
|
|
|
2917
2925
|
ttlSeconds: config.tokenTtlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS,
|
|
2918
2926
|
leewaySeconds: config.tokenRefreshLeewaySeconds ?? DEFAULT_TOKEN_REFRESH_LEEWAY_SECONDS
|
|
2919
2927
|
});
|
|
2928
|
+
const defaultBaseUrl = isV2 ? DEFAULT_V2_BASE_URL : DEFAULT_BASE_URL;
|
|
2920
2929
|
this.client = new GraphQLClient({
|
|
2921
|
-
baseUrl: config.baseUrl ??
|
|
2930
|
+
baseUrl: config.baseUrl ?? defaultBaseUrl,
|
|
2922
2931
|
appId: config.appId,
|
|
2923
2932
|
gatewayKey: config.gatewayKey,
|
|
2924
2933
|
getToken: () => tokens.getToken(),
|
|
2925
2934
|
retryDelaysMs: config.retryDelaysMs ?? DEFAULT_RETRY_DELAYS_MS,
|
|
2926
2935
|
logger,
|
|
2927
|
-
fetchFn: config.fetch ?? globalThis.fetch
|
|
2936
|
+
fetchFn: config.fetch ?? globalThis.fetch,
|
|
2937
|
+
endpointPathPrefix: isV2 ? V2_EXTENDABLE_SLUG : void 0
|
|
2928
2938
|
});
|
|
2929
2939
|
this.productServiceOptions = {
|
|
2930
2940
|
itemOptionsPageSize: config.itemOptionsPageSize
|