@seatmap-fyi/api-client 0.1.0-alpha.2 → 0.1.0-alpha.28

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.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./generated.js";
2
- export { Configuration, type ConfigurationParameters, } from "./configuration.js";
3
- export { ApiError } from "./errors/api-error.js";
2
+ export { Configuration, type ConfigurationParameters } from "./configuration.js";
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./generated.js";
2
- export { Configuration, } from "./configuration.js";
3
- export { ApiError } from "./errors/api-error.js";
2
+ export { Configuration } from "./configuration.js";
@@ -1,2 +1,14 @@
1
+ import type { AxiosRequestConfig } from "axios";
1
2
  import type { Configuration } from "./configuration.js";
2
- export declare function createApiFetcher(configuration: Configuration): typeof globalThis.fetch;
3
+ /**
4
+ * @method prepareRequestOptions
5
+ * @description Applies instance-scoped transport settings, the SDK write contract and optional body compression.
6
+ * @async
7
+ * @param {Configuration} configuration
8
+ * @param {string | undefined} basePath
9
+ * @param {AxiosRequestConfig | undefined} options
10
+ * @param {string} method
11
+ * @param {unknown} [body]
12
+ * @returns {Promise<AxiosRequestConfig<unknown>>}
13
+ */
14
+ export declare function prepareRequestOptions(configuration: Configuration, basePath: string | undefined, options: AxiosRequestConfig | undefined, method: string, body?: unknown): Promise<AxiosRequestConfig<unknown>>;
package/dist/transport.js CHANGED
@@ -1,71 +1,49 @@
1
- import { ApiError } from "./errors/api-error.js";
1
+ import { mergeConfig } from "axios";
2
+ const clientContract = "20";
2
3
  const requestCompressionThreshold = 64 * 1024;
3
- export function createApiFetcher(configuration) {
4
- const baseUrl = new URL(configuration.basePath);
5
- return async (input, options) => {
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;
51
- }
52
- };
53
- }
54
- function normalizeHeaders(source) {
55
- let entries;
56
- if (source instanceof Headers) {
57
- entries = source.entries();
4
+ /**
5
+ * @method prepareRequestOptions
6
+ * @description Applies instance-scoped transport settings, the SDK write contract and optional body compression.
7
+ * @async
8
+ * @param {Configuration} configuration
9
+ * @param {string | undefined} basePath
10
+ * @param {AxiosRequestConfig | undefined} options
11
+ * @param {string} method
12
+ * @param {unknown} [body]
13
+ * @returns {Promise<AxiosRequestConfig<unknown>>}
14
+ */
15
+ export async function prepareRequestOptions(configuration, basePath, options, method, body) {
16
+ const prepared = mergeConfig(configuration.baseOptions ?? {}, options ?? {});
17
+ const headers = { ...prepared.headers };
18
+ if (!["GET", "HEAD", "OPTIONS"].includes(method)) {
19
+ headers["X-Seatmap-Contract"] = clientContract;
20
+ }
21
+ const configuredBasePath = basePath ?? configuration.basePath;
22
+ if (configuredBasePath !== undefined) {
23
+ prepared.baseURL = configuredBasePath;
24
+ }
25
+ if (body === undefined &&
26
+ !["GET", "HEAD", "OPTIONS"].includes(method) &&
27
+ !Object.keys(headers).some((name) => name.toLowerCase() === "content-type")) {
28
+ headers["Content-Type"] = "application/json";
58
29
  }
59
- else if (Array.isArray(source)) {
60
- entries = source;
30
+ prepared.headers = headers;
31
+ if (prepared.validateStatus === undefined) {
32
+ prepared.validateStatus = (status) => (status >= 200 && status < 300) || status === 304;
61
33
  }
62
- else {
63
- entries = Object.entries(source);
34
+ if (!configuration.compressRequests ||
35
+ body === undefined ||
36
+ (typeof Blob !== "undefined" && body instanceof Blob) ||
37
+ body instanceof ArrayBuffer ||
38
+ ArrayBuffer.isView(body) ||
39
+ Object.keys(headers).some((name) => name.toLowerCase() === "content-encoding")) {
40
+ return prepared;
64
41
  }
65
- const headers = new Headers();
66
- // Caller headers replace differently cased generated defaults instead of being combined.
67
- for (const [name, value] of entries) {
68
- headers.set(name, value);
42
+ const serialized = JSON.stringify(options?.data ?? body);
43
+ if (serialized.length < requestCompressionThreshold || typeof CompressionStream === "undefined") {
44
+ return prepared;
69
45
  }
70
- return headers;
46
+ prepared.data = await new Response(new Blob([serialized]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
47
+ headers["Content-Encoding"] = "gzip";
48
+ return prepared;
71
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seatmap-fyi/api-client",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.28",
4
4
  "license": "UNLICENSED",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -18,5 +18,8 @@
18
18
  },
19
19
  "publishConfig": {
20
20
  "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "axios": "1.20.0"
21
24
  }
22
25
  }
@@ -1,5 +0,0 @@
1
- export declare class ApiError extends Error {
2
- readonly status: number;
3
- readonly response: Response;
4
- constructor(response: Response);
5
- }
@@ -1,10 +0,0 @@
1
- export class ApiError extends Error {
2
- status;
3
- response;
4
- constructor(response) {
5
- super(`API request failed with HTTP ${response.status}.`);
6
- this.name = "ApiError";
7
- this.status = response.status;
8
- this.response = response;
9
- }
10
- }