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

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
2
  export { Configuration, type ConfigurationParameters, } from "./configuration.js";
3
- export { ApiError } from "./errors/api-error.js";
package/dist/index.js CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from "./generated.js";
2
2
  export { Configuration, } from "./configuration.js";
3
- export { ApiError } from "./errors/api-error.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,26 +1,50 @@
1
- import { ApiError } from "./errors/api-error.js";
2
- export function createApiFetcher(configuration) {
3
- const baseUrl = new URL(configuration.basePath);
4
- 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);
11
- }
12
- return response;
13
- };
14
- }
15
- function normalizeHeaders(source) {
16
- if (source instanceof Headers) {
17
- return source;
1
+ import { mergeConfig } from "axios";
2
+ const clientContract = "3";
3
+ const requestCompressionThreshold = 64 * 1024;
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";
29
+ }
30
+ prepared.headers = headers;
31
+ if (prepared.validateStatus === undefined) {
32
+ prepared.validateStatus = (status) => (status >= 200 && status < 300) || status === 304;
33
+ }
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;
18
41
  }
19
- const entries = Array.isArray(source) ? source : Object.entries(source);
20
- const headers = new Headers();
21
- // Native Headers construction combines differently cased duplicates instead of replacing them.
22
- for (const [name, value] of entries) {
23
- headers.set(name, value);
42
+ const serialized = JSON.stringify(options?.data ?? body);
43
+ if (serialized.length < requestCompressionThreshold ||
44
+ typeof CompressionStream === "undefined") {
45
+ return prepared;
24
46
  }
25
- return headers;
47
+ prepared.data = await new Response(new Blob([serialized]).stream().pipeThrough(new CompressionStream("gzip"))).arrayBuffer();
48
+ headers["Content-Encoding"] = "gzip";
49
+ return prepared;
26
50
  }
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.11",
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
- }