@seatmap-fyi/api-client 0.1.0-alpha.1 → 0.1.0-alpha.3

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.
@@ -1,9 +1,16 @@
1
1
  export interface ConfigurationParameters {
2
2
  readonly basePath: string;
3
3
  readonly fetchApi?: typeof globalThis.fetch;
4
+ readonly credentials?: RequestCredentials;
5
+ readonly compressRequests?: boolean;
6
+ readonly mapError?: (cause: unknown) => Promise<Error>;
4
7
  }
5
8
  export declare class Configuration {
6
9
  readonly basePath: string;
7
10
  readonly fetchApi: typeof globalThis.fetch;
11
+ readonly credentials: RequestCredentials | undefined;
12
+ readonly compressRequests: boolean;
13
+ readonly mapError: ConfigurationParameters["mapError"];
14
+ csrfToken: string | undefined;
8
15
  constructor(parameters: ConfigurationParameters);
9
16
  }
@@ -1,8 +1,15 @@
1
1
  export class Configuration {
2
2
  basePath;
3
3
  fetchApi;
4
+ credentials;
5
+ compressRequests;
6
+ mapError;
7
+ csrfToken;
4
8
  constructor(parameters) {
5
9
  this.basePath = parameters.basePath;
6
10
  this.fetchApi = parameters.fetchApi ?? globalThis.fetch;
11
+ this.credentials = parameters.credentials;
12
+ this.compressRequests = parameters.compressRequests ?? false;
13
+ this.mapError = parameters.mapError;
7
14
  }
8
15
  }
@@ -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,68 @@
1
1
  import { ApiError } from "./errors/api-error.js";
2
+ const clientContract = "1";
3
+ const requestCompressionThreshold = 64 * 1024;
2
4
  export function createApiFetcher(configuration) {
3
5
  const baseUrl = new URL(configuration.basePath);
4
6
  return async (input, options) => {
5
- const requestOptions = options?.headers === undefined
6
- ? options
7
- : { ...options, headers: normalizeHeaders(options.headers) };
8
- const response = await configuration.fetchApi(typeof input === "string" ? new URL(input, baseUrl) : input, requestOptions);
9
- if (!response.ok && response.status !== 304) {
10
- throw new ApiError(response);
7
+ const request = input instanceof Request ? input : undefined;
8
+ const headers = normalizeHeaders(options?.headers ?? request?.headers ?? {});
9
+ const method = (options?.method ?? request?.method ?? "GET").toUpperCase();
10
+ if (!["GET", "HEAD", "OPTIONS"].includes(method)) {
11
+ headers.set("X-Seatmap-Contract", clientContract);
12
+ if (configuration.csrfToken) {
13
+ headers.set("X-CSRF-Token", configuration.csrfToken);
14
+ }
15
+ }
16
+ let body = options?.body;
17
+ if (configuration.compressRequests &&
18
+ typeof body === "string" &&
19
+ body.length >= requestCompressionThreshold &&
20
+ !headers.has("Content-Encoding") &&
21
+ typeof CompressionStream !== "undefined") {
22
+ body = await new Response(new Blob([body]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
23
+ headers.set("Content-Encoding", "gzip");
24
+ }
25
+ try {
26
+ const response = await configuration.fetchApi(typeof input === "string" ? new URL(input, baseUrl) : input, {
27
+ ...options,
28
+ ...(body !== undefined ? { body } : {}),
29
+ headers,
30
+ ...(configuration.credentials
31
+ ? { credentials: configuration.credentials }
32
+ : {}),
33
+ });
34
+ if (response.status === 401) {
35
+ configuration.csrfToken = undefined;
36
+ }
37
+ if (!response.ok && response.status !== 304) {
38
+ throw new ApiError(response);
39
+ }
40
+ return response;
41
+ }
42
+ catch (cause) {
43
+ if (cause instanceof Error && cause.name === "AbortError") {
44
+ throw cause;
45
+ }
46
+ if (configuration.mapError) {
47
+ throw await configuration.mapError(cause);
48
+ }
49
+ throw cause;
11
50
  }
12
- return response;
13
51
  };
14
52
  }
15
53
  function normalizeHeaders(source) {
54
+ let entries;
16
55
  if (source instanceof Headers) {
17
- return source;
56
+ entries = source.entries();
57
+ }
58
+ else if (Array.isArray(source)) {
59
+ entries = source;
60
+ }
61
+ else {
62
+ entries = Object.entries(source);
18
63
  }
19
- const entries = Array.isArray(source) ? source : Object.entries(source);
20
64
  const headers = new Headers();
21
- // Native Headers construction combines differently cased duplicates instead of replacing them.
65
+ // Caller headers replace differently cased generated defaults instead of being combined.
22
66
  for (const [name, value] of entries) {
23
67
  headers.set(name, value);
24
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seatmap-fyi/api-client",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.3",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,