@firela/api-types 0.0.0-canary.ed674c1

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.
Files changed (32) hide show
  1. package/README.md +40 -0
  2. package/dist/generated/core/ApiError.d.ts +11 -0
  3. package/dist/generated/core/ApiError.d.ts.map +1 -0
  4. package/dist/generated/core/ApiError.js +11 -0
  5. package/dist/generated/core/ApiRequestOptions.d.ts +14 -0
  6. package/dist/generated/core/ApiRequestOptions.d.ts.map +1 -0
  7. package/dist/generated/core/ApiRequestOptions.js +1 -0
  8. package/dist/generated/core/ApiResult.d.ts +8 -0
  9. package/dist/generated/core/ApiResult.d.ts.map +1 -0
  10. package/dist/generated/core/ApiResult.js +1 -0
  11. package/dist/generated/core/CancelablePromise.d.ts +27 -0
  12. package/dist/generated/core/CancelablePromise.d.ts.map +1 -0
  13. package/dist/generated/core/CancelablePromise.js +88 -0
  14. package/dist/generated/core/OpenAPI.d.ts +28 -0
  15. package/dist/generated/core/OpenAPI.d.ts.map +1 -0
  16. package/dist/generated/core/OpenAPI.js +29 -0
  17. package/dist/generated/core/request.d.ts +30 -0
  18. package/dist/generated/core/request.d.ts.map +1 -0
  19. package/dist/generated/core/request.js +297 -0
  20. package/dist/generated/index.d.ts +6 -0
  21. package/dist/generated/index.d.ts.map +1 -0
  22. package/dist/generated/index.js +6 -0
  23. package/dist/generated/services.gen.d.ts +11 -0
  24. package/dist/generated/services.gen.d.ts.map +1 -0
  25. package/dist/generated/services.gen.js +16 -0
  26. package/dist/generated/types.gen.d.ts +18 -0
  27. package/dist/generated/types.gen.d.ts.map +1 -0
  28. package/dist/generated/types.gen.js +2 -0
  29. package/dist/index.d.ts +2 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +3 -0
  32. package/package.json +31 -0
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # @firela/api-types
2
+
3
+ TypeScript types and API client generated from OpenAPI specifications.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ npm install @firela/api-types
9
+ ```
10
+
11
+ ## Development
12
+
13
+ ```bash
14
+ # Install dependencies
15
+ npm install
16
+
17
+ # Generate types from OpenAPI spec
18
+ npm run generate
19
+
20
+ # Lint OpenAPI spec
21
+ npm run lint
22
+
23
+ # Build
24
+ npm run build
25
+ ```
26
+
27
+ ## Publishing
28
+
29
+ This package is automatically published to npm via GitHub Actions.
30
+
31
+ ### Canary Releases
32
+
33
+ Every push to main triggers a canary release with version `0.0.0-canary.{short-sha}`.
34
+
35
+ Install the latest canary:
36
+
37
+ ```bash
38
+ npm install @firela/api-types@canary
39
+ ```
40
+ // Trigger publish
@@ -0,0 +1,11 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+ export declare class ApiError extends Error {
4
+ readonly url: string;
5
+ readonly status: number;
6
+ readonly statusText: string;
7
+ readonly body: unknown;
8
+ readonly request: ApiRequestOptions;
9
+ constructor(request: ApiRequestOptions, response: ApiResult, message: string);
10
+ }
11
+ //# sourceMappingURL=ApiError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiError.d.ts","sourceRoot":"","sources":["../../../src/generated/core/ApiError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,qBAAa,QAAS,SAAQ,KAAK;IAClC,SAAgB,GAAG,EAAE,MAAM,CAAC;IAC5B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,IAAI,EAAE,OAAO,CAAC;IAC9B,SAAgB,OAAO,EAAE,iBAAiB,CAAC;gBAE/B,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM;CAU5E"}
@@ -0,0 +1,11 @@
1
+ export class ApiError extends Error {
2
+ constructor(request, response, message) {
3
+ super(message);
4
+ this.name = 'ApiError';
5
+ this.url = response.url;
6
+ this.status = response.status;
7
+ this.statusText = response.statusText;
8
+ this.body = response.body;
9
+ this.request = request;
10
+ }
11
+ }
@@ -0,0 +1,14 @@
1
+ export type ApiRequestOptions = {
2
+ readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
3
+ readonly url: string;
4
+ readonly path?: Record<string, unknown>;
5
+ readonly cookies?: Record<string, unknown>;
6
+ readonly headers?: Record<string, unknown>;
7
+ readonly query?: Record<string, unknown>;
8
+ readonly formData?: Record<string, unknown>;
9
+ readonly body?: any;
10
+ readonly mediaType?: string;
11
+ readonly responseHeader?: string;
12
+ readonly errors?: Record<number, string>;
13
+ };
14
+ //# sourceMappingURL=ApiRequestOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiRequestOptions.d.ts","sourceRoot":"","sources":["../../../src/generated/core/ApiRequestOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IAClF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export type ApiResult<TData = any> = {
2
+ readonly body: TData;
3
+ readonly ok: boolean;
4
+ readonly status: number;
5
+ readonly statusText: string;
6
+ readonly url: string;
7
+ };
8
+ //# sourceMappingURL=ApiResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApiResult.d.ts","sourceRoot":"","sources":["../../../src/generated/core/ApiResult.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,CAAC,KAAK,GAAG,GAAG,IAAI;IACpC,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACrB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ export declare class CancelError extends Error {
2
+ constructor(message: string);
3
+ get isCancelled(): boolean;
4
+ }
5
+ export interface OnCancel {
6
+ readonly isResolved: boolean;
7
+ readonly isRejected: boolean;
8
+ readonly isCancelled: boolean;
9
+ (cancelHandler: () => void): void;
10
+ }
11
+ export declare class CancelablePromise<T> implements Promise<T> {
12
+ private _isResolved;
13
+ private _isRejected;
14
+ private _isCancelled;
15
+ readonly cancelHandlers: (() => void)[];
16
+ readonly promise: Promise<T>;
17
+ private _resolve?;
18
+ private _reject?;
19
+ constructor(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void, onCancel: OnCancel) => void);
20
+ get [Symbol.toStringTag](): string;
21
+ then<TResult1 = T, TResult2 = never>(onFulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null, onRejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
22
+ catch<TResult = never>(onRejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null): Promise<T | TResult>;
23
+ finally(onFinally?: (() => void) | null): Promise<T>;
24
+ cancel(): void;
25
+ get isCancelled(): boolean;
26
+ }
27
+ //# sourceMappingURL=CancelablePromise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CancelablePromise.d.ts","sourceRoot":"","sources":["../../../src/generated/core/CancelablePromise.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;IAK3B,IAAW,WAAW,IAAI,OAAO,CAEhC;CACD;AAED,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAE9B,CAAC,aAAa,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAClC;AAED,qBAAa,iBAAiB,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,YAAY,CAAU;IAC9B,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,OAAO,CAAC,QAAQ,CAAC,CAAsC;IACvD,OAAO,CAAC,OAAO,CAAC,CAA6B;gBAG5C,QAAQ,EAAE,CACT,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5C,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,EAClC,QAAQ,EAAE,QAAQ,KACd,IAAI;IAiDV,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAEM,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,EACzC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,EACrE,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GACzE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAIxB,KAAK,CAAC,OAAO,GAAG,KAAK,EAC3B,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GACvE,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;IAIhB,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC;IAIpD,MAAM,IAAI,IAAI;IAmBrB,IAAW,WAAW,IAAI,OAAO,CAEhC;CACD"}
@@ -0,0 +1,88 @@
1
+ export class CancelError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'CancelError';
5
+ }
6
+ get isCancelled() {
7
+ return true;
8
+ }
9
+ }
10
+ export class CancelablePromise {
11
+ constructor(executor) {
12
+ this._isResolved = false;
13
+ this._isRejected = false;
14
+ this._isCancelled = false;
15
+ this.cancelHandlers = [];
16
+ this.promise = new Promise((resolve, reject) => {
17
+ this._resolve = resolve;
18
+ this._reject = reject;
19
+ const onResolve = (value) => {
20
+ if (this._isResolved || this._isRejected || this._isCancelled) {
21
+ return;
22
+ }
23
+ this._isResolved = true;
24
+ if (this._resolve)
25
+ this._resolve(value);
26
+ };
27
+ const onReject = (reason) => {
28
+ if (this._isResolved || this._isRejected || this._isCancelled) {
29
+ return;
30
+ }
31
+ this._isRejected = true;
32
+ if (this._reject)
33
+ this._reject(reason);
34
+ };
35
+ const onCancel = (cancelHandler) => {
36
+ if (this._isResolved || this._isRejected || this._isCancelled) {
37
+ return;
38
+ }
39
+ this.cancelHandlers.push(cancelHandler);
40
+ };
41
+ Object.defineProperty(onCancel, 'isResolved', {
42
+ get: () => this._isResolved,
43
+ });
44
+ Object.defineProperty(onCancel, 'isRejected', {
45
+ get: () => this._isRejected,
46
+ });
47
+ Object.defineProperty(onCancel, 'isCancelled', {
48
+ get: () => this._isCancelled,
49
+ });
50
+ return executor(onResolve, onReject, onCancel);
51
+ });
52
+ }
53
+ get [Symbol.toStringTag]() {
54
+ return "Cancellable Promise";
55
+ }
56
+ then(onFulfilled, onRejected) {
57
+ return this.promise.then(onFulfilled, onRejected);
58
+ }
59
+ catch(onRejected) {
60
+ return this.promise.catch(onRejected);
61
+ }
62
+ finally(onFinally) {
63
+ return this.promise.finally(onFinally);
64
+ }
65
+ cancel() {
66
+ if (this._isResolved || this._isRejected || this._isCancelled) {
67
+ return;
68
+ }
69
+ this._isCancelled = true;
70
+ if (this.cancelHandlers.length) {
71
+ try {
72
+ for (const cancelHandler of this.cancelHandlers) {
73
+ cancelHandler();
74
+ }
75
+ }
76
+ catch (error) {
77
+ console.warn('Cancellation threw an error', error);
78
+ return;
79
+ }
80
+ }
81
+ this.cancelHandlers.length = 0;
82
+ if (this._reject)
83
+ this._reject(new CancelError('Request aborted'));
84
+ }
85
+ get isCancelled() {
86
+ return this._isCancelled;
87
+ }
88
+ }
@@ -0,0 +1,28 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ type Headers = Record<string, string>;
3
+ type Middleware<T> = (value: T) => T | Promise<T>;
4
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
5
+ export declare class Interceptors<T> {
6
+ _fns: Middleware<T>[];
7
+ constructor();
8
+ eject(fn: Middleware<T>): void;
9
+ use(fn: Middleware<T>): void;
10
+ }
11
+ export type OpenAPIConfig = {
12
+ BASE: string;
13
+ CREDENTIALS: 'include' | 'omit' | 'same-origin';
14
+ ENCODE_PATH?: ((path: string) => string) | undefined;
15
+ HEADERS?: Headers | Resolver<Headers> | undefined;
16
+ PASSWORD?: string | Resolver<string> | undefined;
17
+ TOKEN?: string | Resolver<string> | undefined;
18
+ USERNAME?: string | Resolver<string> | undefined;
19
+ VERSION: string;
20
+ WITH_CREDENTIALS: boolean;
21
+ interceptors: {
22
+ request: Interceptors<RequestInit>;
23
+ response: Interceptors<Response>;
24
+ };
25
+ };
26
+ export declare const OpenAPI: OpenAPIConfig;
27
+ export {};
28
+ //# sourceMappingURL=OpenAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OpenAPI.d.ts","sourceRoot":"","sources":["../../../src/generated/core/OpenAPI.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACtC,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAClD,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAE9D,qBAAa,YAAY,CAAC,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;;IAMtB,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;IAOvB,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;CAGtB;AAED,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,GAAG,MAAM,GAAG,aAAa,CAAC;IAChD,WAAW,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IACrD,OAAO,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACjD,KAAK,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,YAAY,EAAE;QACb,OAAO,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;QACnC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;KACjC,CAAC;CACF,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,aAcrB,CAAC"}
@@ -0,0 +1,29 @@
1
+ export class Interceptors {
2
+ constructor() {
3
+ this._fns = [];
4
+ }
5
+ eject(fn) {
6
+ const index = this._fns.indexOf(fn);
7
+ if (index !== -1) {
8
+ this._fns = [...this._fns.slice(0, index), ...this._fns.slice(index + 1)];
9
+ }
10
+ }
11
+ use(fn) {
12
+ this._fns = [...this._fns, fn];
13
+ }
14
+ }
15
+ export const OpenAPI = {
16
+ BASE: 'http://localhost:3333/api/v1',
17
+ CREDENTIALS: 'include',
18
+ ENCODE_PATH: undefined,
19
+ HEADERS: undefined,
20
+ PASSWORD: undefined,
21
+ TOKEN: undefined,
22
+ USERNAME: undefined,
23
+ VERSION: '1.0.0',
24
+ WITH_CREDENTIALS: false,
25
+ interceptors: {
26
+ request: new Interceptors(),
27
+ response: new Interceptors(),
28
+ },
29
+ };
@@ -0,0 +1,30 @@
1
+ import type { ApiRequestOptions } from './ApiRequestOptions';
2
+ import type { ApiResult } from './ApiResult';
3
+ import { CancelablePromise } from './CancelablePromise';
4
+ import type { OnCancel } from './CancelablePromise';
5
+ import type { OpenAPIConfig } from './OpenAPI';
6
+ export declare const isString: (value: unknown) => value is string;
7
+ export declare const isStringWithValue: (value: unknown) => value is string;
8
+ export declare const isBlob: (value: any) => value is Blob;
9
+ export declare const isFormData: (value: unknown) => value is FormData;
10
+ export declare const base64: (str: string) => string;
11
+ export declare const getQueryString: (params: Record<string, unknown>) => string;
12
+ export declare const getFormData: (options: ApiRequestOptions) => FormData | undefined;
13
+ type Resolver<T> = (options: ApiRequestOptions) => Promise<T>;
14
+ export declare const resolve: <T>(options: ApiRequestOptions, resolver?: T | Resolver<T>) => Promise<T | undefined>;
15
+ export declare const getHeaders: (config: OpenAPIConfig, options: ApiRequestOptions) => Promise<Headers>;
16
+ export declare const getRequestBody: (options: ApiRequestOptions) => unknown;
17
+ export declare const sendRequest: (config: OpenAPIConfig, options: ApiRequestOptions, url: string, body: any, formData: FormData | undefined, headers: Headers, onCancel: OnCancel) => Promise<Response>;
18
+ export declare const getResponseHeader: (response: Response, responseHeader?: string) => string | undefined;
19
+ export declare const getResponseBody: (response: Response) => Promise<unknown>;
20
+ export declare const catchErrorCodes: (options: ApiRequestOptions, result: ApiResult) => void;
21
+ /**
22
+ * Request method
23
+ * @param config The OpenAPI configuration object
24
+ * @param options The request options from the service
25
+ * @returns CancelablePromise<T>
26
+ * @throws ApiError
27
+ */
28
+ export declare const request: <T>(config: OpenAPIConfig, options: ApiRequestOptions) => CancelablePromise<T>;
29
+ export {};
30
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/generated/core/request.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAElD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAE3D,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,OAAO,GAAG,KAAG,KAAK,IAAI,IAE5C,CAAC;AAEF,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QAEpD,CAAC;AAEF,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,KAAG,MAOpC,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,MA0BhE,CAAC;AAkBF,eAAO,MAAM,WAAW,GAAI,SAAS,iBAAiB,KAAG,QAAQ,GAAG,SAyBnE,CAAC;AAEF,KAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AAE9D,eAAO,MAAM,OAAO,GAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAK9G,CAAC;AAEF,eAAO,MAAM,UAAU,GAAU,QAAQ,aAAa,EAAE,SAAS,iBAAiB,KAAG,OAAO,CAAC,OAAO,CAyCnG,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,SAAS,iBAAiB,KAAG,OAW3D,CAAC;AAEF,eAAO,MAAM,WAAW,GACvB,QAAQ,aAAa,EACrB,SAAS,iBAAiB,EAC1B,KAAK,MAAM,EACX,MAAM,GAAG,EACT,UAAU,QAAQ,GAAG,SAAS,EAC9B,SAAS,OAAO,EAChB,UAAU,QAAQ,KAChB,OAAO,CAAC,QAAQ,CAqBlB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,UAAU,QAAQ,EAAE,iBAAiB,MAAM,KAAG,MAAM,GAAG,SAQxF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,UAAU,QAAQ,KAAG,OAAO,CAAC,OAAO,CAqBzE,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,SAAS,iBAAiB,EAAE,QAAQ,SAAS,KAAG,IAiE/E,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,QAAQ,aAAa,EAAE,SAAS,iBAAiB,KAAG,iBAAiB,CAAC,CAAC,CAkCjG,CAAC"}
@@ -0,0 +1,297 @@
1
+ import { ApiError } from './ApiError';
2
+ import { CancelablePromise } from './CancelablePromise';
3
+ export const isString = (value) => {
4
+ return typeof value === 'string';
5
+ };
6
+ export const isStringWithValue = (value) => {
7
+ return isString(value) && value !== '';
8
+ };
9
+ export const isBlob = (value) => {
10
+ return value instanceof Blob;
11
+ };
12
+ export const isFormData = (value) => {
13
+ return value instanceof FormData;
14
+ };
15
+ export const base64 = (str) => {
16
+ try {
17
+ return btoa(str);
18
+ }
19
+ catch (err) {
20
+ // @ts-ignore
21
+ return Buffer.from(str).toString('base64');
22
+ }
23
+ };
24
+ export const getQueryString = (params) => {
25
+ const qs = [];
26
+ const append = (key, value) => {
27
+ qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
28
+ };
29
+ const encodePair = (key, value) => {
30
+ if (value === undefined || value === null) {
31
+ return;
32
+ }
33
+ if (value instanceof Date) {
34
+ append(key, value.toISOString());
35
+ }
36
+ else if (Array.isArray(value)) {
37
+ value.forEach(v => encodePair(key, v));
38
+ }
39
+ else if (typeof value === 'object') {
40
+ Object.entries(value).forEach(([k, v]) => encodePair(`${key}[${k}]`, v));
41
+ }
42
+ else {
43
+ append(key, value);
44
+ }
45
+ };
46
+ Object.entries(params).forEach(([key, value]) => encodePair(key, value));
47
+ return qs.length ? `?${qs.join('&')}` : '';
48
+ };
49
+ const getUrl = (config, options) => {
50
+ const encoder = config.ENCODE_PATH || encodeURI;
51
+ const path = options.url
52
+ .replace('{api-version}', config.VERSION)
53
+ .replace(/{(.*?)}/g, (substring, group) => {
54
+ if (options.path?.hasOwnProperty(group)) {
55
+ return encoder(String(options.path[group]));
56
+ }
57
+ return substring;
58
+ });
59
+ const url = config.BASE + path;
60
+ return options.query ? url + getQueryString(options.query) : url;
61
+ };
62
+ export const getFormData = (options) => {
63
+ if (options.formData) {
64
+ const formData = new FormData();
65
+ const process = (key, value) => {
66
+ if (isString(value) || isBlob(value)) {
67
+ formData.append(key, value);
68
+ }
69
+ else {
70
+ formData.append(key, JSON.stringify(value));
71
+ }
72
+ };
73
+ Object.entries(options.formData)
74
+ .filter(([, value]) => value !== undefined && value !== null)
75
+ .forEach(([key, value]) => {
76
+ if (Array.isArray(value)) {
77
+ value.forEach(v => process(key, v));
78
+ }
79
+ else {
80
+ process(key, value);
81
+ }
82
+ });
83
+ return formData;
84
+ }
85
+ return undefined;
86
+ };
87
+ export const resolve = async (options, resolver) => {
88
+ if (typeof resolver === 'function') {
89
+ return resolver(options);
90
+ }
91
+ return resolver;
92
+ };
93
+ export const getHeaders = async (config, options) => {
94
+ const [token, username, password, additionalHeaders] = await Promise.all([
95
+ resolve(options, config.TOKEN),
96
+ resolve(options, config.USERNAME),
97
+ resolve(options, config.PASSWORD),
98
+ resolve(options, config.HEADERS),
99
+ ]);
100
+ const headers = Object.entries({
101
+ Accept: 'application/json',
102
+ ...additionalHeaders,
103
+ ...options.headers,
104
+ })
105
+ .filter(([, value]) => value !== undefined && value !== null)
106
+ .reduce((headers, [key, value]) => ({
107
+ ...headers,
108
+ [key]: String(value),
109
+ }), {});
110
+ if (isStringWithValue(token)) {
111
+ headers['Authorization'] = `Bearer ${token}`;
112
+ }
113
+ if (isStringWithValue(username) && isStringWithValue(password)) {
114
+ const credentials = base64(`${username}:${password}`);
115
+ headers['Authorization'] = `Basic ${credentials}`;
116
+ }
117
+ if (options.body !== undefined) {
118
+ if (options.mediaType) {
119
+ headers['Content-Type'] = options.mediaType;
120
+ }
121
+ else if (isBlob(options.body)) {
122
+ headers['Content-Type'] = options.body.type || 'application/octet-stream';
123
+ }
124
+ else if (isString(options.body)) {
125
+ headers['Content-Type'] = 'text/plain';
126
+ }
127
+ else if (!isFormData(options.body)) {
128
+ headers['Content-Type'] = 'application/json';
129
+ }
130
+ }
131
+ return new Headers(headers);
132
+ };
133
+ export const getRequestBody = (options) => {
134
+ if (options.body !== undefined) {
135
+ if (options.mediaType?.includes('application/json') || options.mediaType?.includes('+json')) {
136
+ return JSON.stringify(options.body);
137
+ }
138
+ else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
139
+ return options.body;
140
+ }
141
+ else {
142
+ return JSON.stringify(options.body);
143
+ }
144
+ }
145
+ return undefined;
146
+ };
147
+ export const sendRequest = async (config, options, url, body, formData, headers, onCancel) => {
148
+ const controller = new AbortController();
149
+ let request = {
150
+ headers,
151
+ body: body ?? formData,
152
+ method: options.method,
153
+ signal: controller.signal,
154
+ };
155
+ if (config.WITH_CREDENTIALS) {
156
+ request.credentials = config.CREDENTIALS;
157
+ }
158
+ for (const fn of config.interceptors.request._fns) {
159
+ request = await fn(request);
160
+ }
161
+ onCancel(() => controller.abort());
162
+ return await fetch(url, request);
163
+ };
164
+ export const getResponseHeader = (response, responseHeader) => {
165
+ if (responseHeader) {
166
+ const content = response.headers.get(responseHeader);
167
+ if (isString(content)) {
168
+ return content;
169
+ }
170
+ }
171
+ return undefined;
172
+ };
173
+ export const getResponseBody = async (response) => {
174
+ if (response.status !== 204) {
175
+ try {
176
+ const contentType = response.headers.get('Content-Type');
177
+ if (contentType) {
178
+ const binaryTypes = ['application/octet-stream', 'application/pdf', 'application/zip', 'audio/', 'image/', 'video/'];
179
+ if (contentType.includes('application/json') || contentType.includes('+json')) {
180
+ return await response.json();
181
+ }
182
+ else if (binaryTypes.some(type => contentType.includes(type))) {
183
+ return await response.blob();
184
+ }
185
+ else if (contentType.includes('multipart/form-data')) {
186
+ return await response.formData();
187
+ }
188
+ else if (contentType.includes('text/')) {
189
+ return await response.text();
190
+ }
191
+ }
192
+ }
193
+ catch (error) {
194
+ console.error(error);
195
+ }
196
+ }
197
+ return undefined;
198
+ };
199
+ export const catchErrorCodes = (options, result) => {
200
+ const errors = {
201
+ 400: 'Bad Request',
202
+ 401: 'Unauthorized',
203
+ 402: 'Payment Required',
204
+ 403: 'Forbidden',
205
+ 404: 'Not Found',
206
+ 405: 'Method Not Allowed',
207
+ 406: 'Not Acceptable',
208
+ 407: 'Proxy Authentication Required',
209
+ 408: 'Request Timeout',
210
+ 409: 'Conflict',
211
+ 410: 'Gone',
212
+ 411: 'Length Required',
213
+ 412: 'Precondition Failed',
214
+ 413: 'Payload Too Large',
215
+ 414: 'URI Too Long',
216
+ 415: 'Unsupported Media Type',
217
+ 416: 'Range Not Satisfiable',
218
+ 417: 'Expectation Failed',
219
+ 418: 'Im a teapot',
220
+ 421: 'Misdirected Request',
221
+ 422: 'Unprocessable Content',
222
+ 423: 'Locked',
223
+ 424: 'Failed Dependency',
224
+ 425: 'Too Early',
225
+ 426: 'Upgrade Required',
226
+ 428: 'Precondition Required',
227
+ 429: 'Too Many Requests',
228
+ 431: 'Request Header Fields Too Large',
229
+ 451: 'Unavailable For Legal Reasons',
230
+ 500: 'Internal Server Error',
231
+ 501: 'Not Implemented',
232
+ 502: 'Bad Gateway',
233
+ 503: 'Service Unavailable',
234
+ 504: 'Gateway Timeout',
235
+ 505: 'HTTP Version Not Supported',
236
+ 506: 'Variant Also Negotiates',
237
+ 507: 'Insufficient Storage',
238
+ 508: 'Loop Detected',
239
+ 510: 'Not Extended',
240
+ 511: 'Network Authentication Required',
241
+ ...options.errors,
242
+ };
243
+ const error = errors[result.status];
244
+ if (error) {
245
+ throw new ApiError(options, result, error);
246
+ }
247
+ if (!result.ok) {
248
+ const errorStatus = result.status ?? 'unknown';
249
+ const errorStatusText = result.statusText ?? 'unknown';
250
+ const errorBody = (() => {
251
+ try {
252
+ return JSON.stringify(result.body, null, 2);
253
+ }
254
+ catch (e) {
255
+ return undefined;
256
+ }
257
+ })();
258
+ throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
259
+ }
260
+ };
261
+ /**
262
+ * Request method
263
+ * @param config The OpenAPI configuration object
264
+ * @param options The request options from the service
265
+ * @returns CancelablePromise<T>
266
+ * @throws ApiError
267
+ */
268
+ export const request = (config, options) => {
269
+ return new CancelablePromise(async (resolve, reject, onCancel) => {
270
+ try {
271
+ const url = getUrl(config, options);
272
+ const formData = getFormData(options);
273
+ const body = getRequestBody(options);
274
+ const headers = await getHeaders(config, options);
275
+ if (!onCancel.isCancelled) {
276
+ let response = await sendRequest(config, options, url, body, formData, headers, onCancel);
277
+ for (const fn of config.interceptors.response._fns) {
278
+ response = await fn(response);
279
+ }
280
+ const responseBody = await getResponseBody(response);
281
+ const responseHeader = getResponseHeader(response, options.responseHeader);
282
+ const result = {
283
+ url,
284
+ ok: response.ok,
285
+ status: response.status,
286
+ statusText: response.statusText,
287
+ body: responseHeader ?? responseBody,
288
+ };
289
+ catchErrorCodes(options, result);
290
+ resolve(result.body);
291
+ }
292
+ }
293
+ catch (error) {
294
+ reject(error);
295
+ }
296
+ });
297
+ };
@@ -0,0 +1,6 @@
1
+ export { ApiError } from './core/ApiError';
2
+ export { CancelablePromise, CancelError } from './core/CancelablePromise';
3
+ export { OpenAPI, type OpenAPIConfig } from './core/OpenAPI';
4
+ export * from './services.gen';
5
+ export * from './types.gen';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generated/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC7D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export { ApiError } from './core/ApiError';
3
+ export { CancelablePromise, CancelError } from './core/CancelablePromise';
4
+ export { OpenAPI } from './core/OpenAPI';
5
+ export * from './services.gen';
6
+ export * from './types.gen';
@@ -0,0 +1,11 @@
1
+ import type { CancelablePromise } from './core/CancelablePromise';
2
+ import type { GetHealthResponse } from './types.gen';
3
+ export declare class DefaultService {
4
+ /**
5
+ * Health check
6
+ * @returns unknown Service is healthy
7
+ * @throws ApiError
8
+ */
9
+ static getHealth(): CancelablePromise<GetHealthResponse>;
10
+ }
11
+ //# sourceMappingURL=services.gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.gen.d.ts","sourceRoot":"","sources":["../../src/generated/services.gen.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,qBAAa,cAAc;IACvB;;;;OAIG;WACW,SAAS,IAAI,iBAAiB,CAAC,iBAAiB,CAAC;CAOlE"}
@@ -0,0 +1,16 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { OpenAPI } from './core/OpenAPI';
3
+ import { request as __request } from './core/request';
4
+ export class DefaultService {
5
+ /**
6
+ * Health check
7
+ * @returns unknown Service is healthy
8
+ * @throws ApiError
9
+ */
10
+ static getHealth() {
11
+ return __request(OpenAPI, {
12
+ method: 'GET',
13
+ url: '/health'
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ export type GetHealthResponse = {
2
+ status?: string;
3
+ };
4
+ export type $OpenApiTs = {
5
+ '/health': {
6
+ get: {
7
+ res: {
8
+ /**
9
+ * Service is healthy
10
+ */
11
+ 200: {
12
+ status?: string;
13
+ };
14
+ };
15
+ };
16
+ };
17
+ };
18
+ //# sourceMappingURL=types.gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.gen.d.ts","sourceRoot":"","sources":["../../src/generated/types.gen.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,iBAAiB,GAAG;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACrB,SAAS,EAAE;QACP,GAAG,EAAE;YACD,GAAG,EAAE;gBACD;;mBAEG;gBACH,GAAG,EAAE;oBACD,MAAM,CAAC,EAAE,MAAM,CAAC;iBACnB,CAAC;aACL,CAAC;SACL,CAAC;KACL,CAAC;CACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './generated';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // Entry point for @firela/api-types
2
+ // Generated types will be exported from ./generated
3
+ export * from './generated';
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@firela/api-types",
3
+ "version": "0.0.0-canary.ed674c1",
4
+ "description": "TypeScript types generated from OpenAPI specifications",
5
+ "license": "MIT",
6
+ "author": "FireLa Team",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/fire-la/api-specs"
10
+ },
11
+ "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "scripts": {
14
+ "generate": "openapi-ts",
15
+ "build": "tsc",
16
+ "lint": "spectral lint openapi.yaml",
17
+ "prepublishOnly": "npm run generate && npm run build"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "devDependencies": {
26
+ "@hey-api/client-fetch": "^0.4.0",
27
+ "@hey-api/openapi-ts": "^0.45.0",
28
+ "@stoplight/spectral-cli": "^6.11.0",
29
+ "typescript": "^5.3.0"
30
+ }
31
+ }