@seatmap-fyi/api-client 0.1.0-alpha.1 → 0.1.0-alpha.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/configuration.d.ts +9 -0
- package/dist/configuration.js +9 -0
- package/dist/generated.d.ts +3 -0
- package/dist/generated.js +8 -0
- package/dist/transport.js +55 -10
- package/package.json +1 -1
package/dist/configuration.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export interface ConfigurationParameters {
|
|
2
2
|
readonly basePath: string;
|
|
3
3
|
readonly fetchApi?: typeof globalThis.fetch;
|
|
4
|
+
readonly credentials?: RequestCredentials;
|
|
5
|
+
readonly contract?: string;
|
|
6
|
+
readonly compressRequests?: boolean;
|
|
7
|
+
readonly mapError?: (cause: unknown) => Promise<Error>;
|
|
4
8
|
}
|
|
5
9
|
export declare class Configuration {
|
|
6
10
|
readonly basePath: string;
|
|
7
11
|
readonly fetchApi: typeof globalThis.fetch;
|
|
12
|
+
readonly credentials: RequestCredentials | undefined;
|
|
13
|
+
readonly contract: string | undefined;
|
|
14
|
+
readonly compressRequests: boolean;
|
|
15
|
+
readonly mapError: ConfigurationParameters["mapError"];
|
|
16
|
+
csrfToken: string | undefined;
|
|
8
17
|
constructor(parameters: ConfigurationParameters);
|
|
9
18
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
export class Configuration {
|
|
2
2
|
basePath;
|
|
3
3
|
fetchApi;
|
|
4
|
+
credentials;
|
|
5
|
+
contract;
|
|
6
|
+
compressRequests;
|
|
7
|
+
mapError;
|
|
8
|
+
csrfToken;
|
|
4
9
|
constructor(parameters) {
|
|
5
10
|
this.basePath = parameters.basePath;
|
|
6
11
|
this.fetchApi = parameters.fetchApi ?? globalThis.fetch;
|
|
12
|
+
this.credentials = parameters.credentials;
|
|
13
|
+
this.contract = parameters.contract;
|
|
14
|
+
this.compressRequests = parameters.compressRequests ?? false;
|
|
15
|
+
this.mapError = parameters.mapError;
|
|
7
16
|
}
|
|
8
17
|
}
|
package/dist/generated.d.ts
CHANGED
|
@@ -2352,6 +2352,7 @@ export declare class HealthClient {
|
|
|
2352
2352
|
}
|
|
2353
2353
|
export declare class AuthenticationClient {
|
|
2354
2354
|
private readonly fetchApi;
|
|
2355
|
+
private readonly basePath;
|
|
2355
2356
|
constructor(configuration: Configuration);
|
|
2356
2357
|
getIntegrationContext(options?: RequestInit): Promise<AccountContextDto>;
|
|
2357
2358
|
startLogin(params: StartLoginParams, options?: RequestInit): Promise<unknown>;
|
|
@@ -2360,6 +2361,8 @@ export declare class AuthenticationClient {
|
|
|
2360
2361
|
getAuthoringSession(options?: RequestInit): Promise<AuthoringSessionContextDto>;
|
|
2361
2362
|
revokeAuthoringSession(options?: RequestInit): Promise<void>;
|
|
2362
2363
|
getEmbedContext(mapId: string, options?: RequestInit): Promise<EmbedContextDto>;
|
|
2364
|
+
startLoginHref(params: StartLoginParams): string;
|
|
2365
|
+
logoutProviderHref(): string;
|
|
2363
2366
|
}
|
|
2364
2367
|
export declare class MapsClient {
|
|
2365
2368
|
private readonly fetchApi;
|
package/dist/generated.js
CHANGED
|
@@ -64,7 +64,9 @@ export class HealthClient {
|
|
|
64
64
|
}
|
|
65
65
|
export class AuthenticationClient {
|
|
66
66
|
fetchApi;
|
|
67
|
+
basePath;
|
|
67
68
|
constructor(configuration) {
|
|
69
|
+
this.basePath = configuration.basePath;
|
|
68
70
|
this.fetchApi = createApiFetcher(configuration);
|
|
69
71
|
}
|
|
70
72
|
getIntegrationContext(options) {
|
|
@@ -88,6 +90,12 @@ export class AuthenticationClient {
|
|
|
88
90
|
getEmbedContext(mapId, options) {
|
|
89
91
|
return getEmbedContext(mapId, options, this.fetchApi);
|
|
90
92
|
}
|
|
93
|
+
startLoginHref(params) {
|
|
94
|
+
return new URL(getStartLoginUrl(params), this.basePath).href;
|
|
95
|
+
}
|
|
96
|
+
logoutProviderHref() {
|
|
97
|
+
return new URL(getLogoutProviderUrl(), this.basePath).href;
|
|
98
|
+
}
|
|
91
99
|
}
|
|
92
100
|
export class MapsClient {
|
|
93
101
|
fetchApi;
|
package/dist/transport.js
CHANGED
|
@@ -1,24 +1,69 @@
|
|
|
1
1
|
import { ApiError } from "./errors/api-error.js";
|
|
2
|
+
const requestCompressionThreshold = 64 * 1024;
|
|
2
3
|
export function createApiFetcher(configuration) {
|
|
3
4
|
const baseUrl = new URL(configuration.basePath);
|
|
4
5
|
return async (input, options) => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const request = input instanceof Request ? input : undefined;
|
|
7
|
+
const headers = normalizeHeaders(options?.headers ?? request?.headers ?? {});
|
|
8
|
+
const method = (options?.method ?? request?.method ?? "GET").toUpperCase();
|
|
9
|
+
if (!["GET", "HEAD", "OPTIONS"].includes(method)) {
|
|
10
|
+
if (configuration.contract) {
|
|
11
|
+
headers.set("X-Seatmap-Contract", configuration.contract);
|
|
12
|
+
}
|
|
13
|
+
if (configuration.csrfToken) {
|
|
14
|
+
headers.set("X-CSRF-Token", configuration.csrfToken);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let body = options?.body;
|
|
18
|
+
if (configuration.compressRequests &&
|
|
19
|
+
typeof body === "string" &&
|
|
20
|
+
body.length >= requestCompressionThreshold &&
|
|
21
|
+
!headers.has("Content-Encoding") &&
|
|
22
|
+
typeof CompressionStream !== "undefined") {
|
|
23
|
+
body = await new Response(new Blob([body]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
|
|
24
|
+
headers.set("Content-Encoding", "gzip");
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const response = await configuration.fetchApi(typeof input === "string" ? new URL(input, baseUrl) : input, {
|
|
28
|
+
...options,
|
|
29
|
+
...(body !== undefined ? { body } : {}),
|
|
30
|
+
headers,
|
|
31
|
+
...(configuration.credentials
|
|
32
|
+
? { credentials: configuration.credentials }
|
|
33
|
+
: {}),
|
|
34
|
+
});
|
|
35
|
+
if (response.status === 401) {
|
|
36
|
+
configuration.csrfToken = undefined;
|
|
37
|
+
}
|
|
38
|
+
if (!response.ok && response.status !== 304) {
|
|
39
|
+
throw new ApiError(response);
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
catch (cause) {
|
|
44
|
+
if (cause instanceof Error && cause.name === "AbortError") {
|
|
45
|
+
throw cause;
|
|
46
|
+
}
|
|
47
|
+
if (configuration.mapError) {
|
|
48
|
+
throw await configuration.mapError(cause);
|
|
49
|
+
}
|
|
50
|
+
throw cause;
|
|
11
51
|
}
|
|
12
|
-
return response;
|
|
13
52
|
};
|
|
14
53
|
}
|
|
15
54
|
function normalizeHeaders(source) {
|
|
55
|
+
let entries;
|
|
16
56
|
if (source instanceof Headers) {
|
|
17
|
-
|
|
57
|
+
entries = source.entries();
|
|
58
|
+
}
|
|
59
|
+
else if (Array.isArray(source)) {
|
|
60
|
+
entries = source;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
entries = Object.entries(source);
|
|
18
64
|
}
|
|
19
|
-
const entries = Array.isArray(source) ? source : Object.entries(source);
|
|
20
65
|
const headers = new Headers();
|
|
21
|
-
//
|
|
66
|
+
// Caller headers replace differently cased generated defaults instead of being combined.
|
|
22
67
|
for (const [name, value] of entries) {
|
|
23
68
|
headers.set(name, value);
|
|
24
69
|
}
|