@appweaver/client 1.0.23 → 1.0.24

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 (117) hide show
  1. package/cjs/package.json +3 -0
  2. package/{weaver-client.js → cjs/weaver-client.js} +1 -1
  3. package/esm/angular/index.d.ts +1 -0
  4. package/esm/angular/index.js +1 -0
  5. package/esm/clients/angular-client.d.ts +26 -0
  6. package/esm/clients/angular-client.js +53 -0
  7. package/esm/clients/base-client-interface.d.ts +86 -0
  8. package/esm/clients/base-client-interface.js +1 -0
  9. package/esm/clients/base-client.d.ts +216 -0
  10. package/esm/clients/base-client.js +242 -0
  11. package/esm/clients/fetch-client.d.ts +6 -0
  12. package/esm/clients/fetch-client.js +6 -0
  13. package/esm/clients/index.d.ts +4 -0
  14. package/esm/clients/index.js +4 -0
  15. package/esm/clients/modules/account-client.d.ts +69 -0
  16. package/esm/clients/modules/account-client.js +107 -0
  17. package/esm/clients/modules/auth-client.d.ts +56 -0
  18. package/esm/clients/modules/auth-client.js +74 -0
  19. package/esm/clients/modules/base-module.d.ts +17 -0
  20. package/esm/clients/modules/base-module.js +49 -0
  21. package/esm/clients/modules/files-client.d.ts +27 -0
  22. package/esm/clients/modules/files-client.js +42 -0
  23. package/esm/clients/modules/health-client.d.ts +25 -0
  24. package/esm/clients/modules/health-client.js +30 -0
  25. package/esm/clients/modules/index.d.ts +6 -0
  26. package/esm/clients/modules/index.js +6 -0
  27. package/esm/clients/modules/resource-client.d.ts +90 -0
  28. package/esm/clients/modules/resource-client.js +173 -0
  29. package/esm/clients/responses/file-data-response.d.ts +78 -0
  30. package/esm/clients/responses/file-data-response.js +105 -0
  31. package/esm/clients/responses/index.d.ts +1 -0
  32. package/esm/clients/responses/index.js +1 -0
  33. package/esm/commands/generate-command.d.ts +3 -0
  34. package/esm/commands/generate-command.js +122 -0
  35. package/esm/commands/index.d.ts +1 -0
  36. package/esm/commands/index.js +1 -0
  37. package/esm/constants.d.ts +67 -0
  38. package/esm/constants.js +94 -0
  39. package/esm/errors/client-error.d.ts +6 -0
  40. package/esm/errors/client-error.js +11 -0
  41. package/esm/errors/index.d.ts +1 -0
  42. package/esm/errors/index.js +1 -0
  43. package/esm/generators/generate-client.d.ts +16 -0
  44. package/esm/generators/generate-client.js +399 -0
  45. package/esm/generators/generate-types.d.ts +9 -0
  46. package/esm/generators/generate-types.js +486 -0
  47. package/esm/generators/index.d.ts +2 -0
  48. package/esm/generators/index.js +2 -0
  49. package/esm/index.d.ts +2 -0
  50. package/esm/index.js +2 -0
  51. package/esm/package.json +3 -0
  52. package/esm/types/index.d.ts +1 -0
  53. package/esm/types/index.js +1 -0
  54. package/esm/types/routes.d.ts +15 -0
  55. package/esm/types/routes.js +1 -0
  56. package/esm/utils/index.d.ts +1 -0
  57. package/esm/utils/index.js +1 -0
  58. package/esm/utils/schema-util.d.ts +3 -0
  59. package/esm/utils/schema-util.js +39 -0
  60. package/package.json +29 -5
  61. /package/{angular → cjs/angular}/index.d.ts +0 -0
  62. /package/{angular → cjs/angular}/index.js +0 -0
  63. /package/{clients → cjs/clients}/angular-client.d.ts +0 -0
  64. /package/{clients → cjs/clients}/angular-client.js +0 -0
  65. /package/{clients → cjs/clients}/base-client-interface.d.ts +0 -0
  66. /package/{clients → cjs/clients}/base-client-interface.js +0 -0
  67. /package/{clients → cjs/clients}/base-client.d.ts +0 -0
  68. /package/{clients → cjs/clients}/base-client.js +0 -0
  69. /package/{clients → cjs/clients}/fetch-client.d.ts +0 -0
  70. /package/{clients → cjs/clients}/fetch-client.js +0 -0
  71. /package/{clients → cjs/clients}/index.d.ts +0 -0
  72. /package/{clients → cjs/clients}/index.js +0 -0
  73. /package/{clients → cjs/clients}/modules/account-client.d.ts +0 -0
  74. /package/{clients → cjs/clients}/modules/account-client.js +0 -0
  75. /package/{clients → cjs/clients}/modules/auth-client.d.ts +0 -0
  76. /package/{clients → cjs/clients}/modules/auth-client.js +0 -0
  77. /package/{clients → cjs/clients}/modules/base-module.d.ts +0 -0
  78. /package/{clients → cjs/clients}/modules/base-module.js +0 -0
  79. /package/{clients → cjs/clients}/modules/files-client.d.ts +0 -0
  80. /package/{clients → cjs/clients}/modules/files-client.js +0 -0
  81. /package/{clients → cjs/clients}/modules/health-client.d.ts +0 -0
  82. /package/{clients → cjs/clients}/modules/health-client.js +0 -0
  83. /package/{clients → cjs/clients}/modules/index.d.ts +0 -0
  84. /package/{clients → cjs/clients}/modules/index.js +0 -0
  85. /package/{clients → cjs/clients}/modules/resource-client.d.ts +0 -0
  86. /package/{clients → cjs/clients}/modules/resource-client.js +0 -0
  87. /package/{clients → cjs/clients}/responses/file-data-response.d.ts +0 -0
  88. /package/{clients → cjs/clients}/responses/file-data-response.js +0 -0
  89. /package/{clients → cjs/clients}/responses/index.d.ts +0 -0
  90. /package/{clients → cjs/clients}/responses/index.js +0 -0
  91. /package/{commands → cjs/commands}/generate-command.d.ts +0 -0
  92. /package/{commands → cjs/commands}/generate-command.js +0 -0
  93. /package/{commands → cjs/commands}/index.d.ts +0 -0
  94. /package/{commands → cjs/commands}/index.js +0 -0
  95. /package/{constants.d.ts → cjs/constants.d.ts} +0 -0
  96. /package/{constants.js → cjs/constants.js} +0 -0
  97. /package/{errors → cjs/errors}/client-error.d.ts +0 -0
  98. /package/{errors → cjs/errors}/client-error.js +0 -0
  99. /package/{errors → cjs/errors}/index.d.ts +0 -0
  100. /package/{errors → cjs/errors}/index.js +0 -0
  101. /package/{generators → cjs/generators}/generate-client.d.ts +0 -0
  102. /package/{generators → cjs/generators}/generate-client.js +0 -0
  103. /package/{generators → cjs/generators}/generate-types.d.ts +0 -0
  104. /package/{generators → cjs/generators}/generate-types.js +0 -0
  105. /package/{generators → cjs/generators}/index.d.ts +0 -0
  106. /package/{generators → cjs/generators}/index.js +0 -0
  107. /package/{index.d.ts → cjs/index.d.ts} +0 -0
  108. /package/{index.js → cjs/index.js} +0 -0
  109. /package/{types → cjs/types}/index.d.ts +0 -0
  110. /package/{types → cjs/types}/index.js +0 -0
  111. /package/{types → cjs/types}/routes.d.ts +0 -0
  112. /package/{types → cjs/types}/routes.js +0 -0
  113. /package/{utils → cjs/utils}/index.d.ts +0 -0
  114. /package/{utils → cjs/utils}/index.js +0 -0
  115. /package/{utils → cjs/utils}/schema-util.d.ts +0 -0
  116. /package/{utils → cjs/utils}/schema-util.js +0 -0
  117. /package/{weaver-client.d.ts → cjs/weaver-client.d.ts} +0 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -8,7 +8,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const commander_1 = require("commander");
10
10
  const commands_1 = require("./commands");
11
- const pkg = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, './package.json'), 'utf8'));
11
+ const pkg = JSON.parse(node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '../package.json'), 'utf8'));
12
12
  const program = new commander_1.Command();
13
13
  program
14
14
  .name('weaver-client')
@@ -0,0 +1 @@
1
+ export * from '../clients/angular-client.js';
@@ -0,0 +1 @@
1
+ export * from '../clients/angular-client.js';
@@ -0,0 +1,26 @@
1
+ import { FetchResponse, MaybeOptionalInit } from 'openapi-fetch';
2
+ import { HttpMethod, MediaType, PathsWithMethod } from 'openapi-typescript-helpers';
3
+ import { Observable } from 'rxjs';
4
+ import { BaseClient, ClientConfig, ClientResult, FetchHandler } from './base-client.js';
5
+ import { ExtendedPaths, InitParam } from './base-client-interface.js';
6
+ import { AccountClient, AccountInterface, AccountType, AuthClient, AuthInterface, AuthType, FilesClient, HealthClient, HealthInterface, HealthType, ResourceClient, ResourceInterface, ResourceType } from './modules/index.js';
7
+ /** Maps a `Promise`-returning type to a concrete RxJS `Observable`. */
8
+ export type PromiseToObservable<T> = T extends Promise<infer R> ? Observable<R> : T;
9
+ /** Maps every `Promise`-returning method of `T` to return a concrete RxJS `Observable`. */
10
+ export type ObservableMethods<T> = {
11
+ [K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => PromiseToObservable<R> : T[K];
12
+ };
13
+ export declare class AngularClient<Paths extends {} = {
14
+ [key: string]: any;
15
+ }> extends BaseClient<Paths, true> {
16
+ constructor(fetch: FetchHandler, config: ClientConfig);
17
+ sendRequest<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Observable<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>>;
18
+ sendRequestRaw<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Observable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>>;
19
+ protected customRequest<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path): (...params: InitParam<Init>) => Observable<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>>;
20
+ protected resourceClient<Resource extends ResourceType, OmitFields extends readonly (keyof ResourceInterface)[] = []>(resourcePath: string): ObservableMethods<ClientResult<ResourceClient<Resource>, ResourceInterface, OmitFields>>;
21
+ protected authClient<Auth extends AuthType, OmitFields extends readonly (keyof AuthInterface)[] = []>(authPath: string): ObservableMethods<ClientResult<AuthClient<Auth>, AuthInterface, OmitFields>>;
22
+ protected accountClient<Account extends AccountType, OmitFields extends readonly (keyof AccountInterface)[] = []>(accountPath: string): ObservableMethods<ClientResult<AccountClient<Account>, AccountInterface, OmitFields>>;
23
+ protected healthClient<Health extends HealthType, OmitFields extends readonly (keyof HealthInterface)[] = []>(healthPath: string): ObservableMethods<ClientResult<HealthClient<Health>, HealthInterface, OmitFields>>;
24
+ protected filesClient<OmitFields extends readonly (keyof HealthInterface)[] = []>(filesPath: string): ObservableMethods<ClientResult<FilesClient, HealthInterface, OmitFields>>;
25
+ private wrapWithObservables;
26
+ }
@@ -0,0 +1,53 @@
1
+ import { from } from 'rxjs';
2
+ import { BaseClient } from './base-client.js';
3
+ export class AngularClient extends BaseClient {
4
+ constructor(fetch, config) {
5
+ super({ ...config, fetch });
6
+ }
7
+ sendRequest(method, url, ...params) {
8
+ return from(super.sendRequestPromise(method, url, ...params));
9
+ }
10
+ sendRequestRaw(method, url, ...params) {
11
+ return from(super.sendRequestRawPromise(method, url, ...params));
12
+ }
13
+ customRequest(method, url) {
14
+ return (...params) => from(super.sendRequestPromise(method, url, ...params));
15
+ }
16
+ resourceClient(resourcePath) {
17
+ const instance = super.resourceClient(resourcePath);
18
+ return this.wrapWithObservables(instance);
19
+ }
20
+ authClient(authPath) {
21
+ const instance = super.authClient(authPath);
22
+ return this.wrapWithObservables(instance);
23
+ }
24
+ accountClient(accountPath) {
25
+ const instance = super.accountClient(accountPath);
26
+ return this.wrapWithObservables(instance);
27
+ }
28
+ healthClient(healthPath) {
29
+ const instance = super.healthClient(healthPath);
30
+ return this.wrapWithObservables(instance);
31
+ }
32
+ filesClient(filesPath) {
33
+ const instance = super.filesClient(filesPath);
34
+ return this.wrapWithObservables(instance);
35
+ }
36
+ wrapWithObservables(instance) {
37
+ const isPromiseLike = (value) => value !== null &&
38
+ (typeof value === 'object' || typeof value === 'function') &&
39
+ typeof value.then === 'function';
40
+ return new Proxy(instance, {
41
+ get(target, prop, receiver) {
42
+ const value = Reflect.get(target, prop, receiver);
43
+ if (typeof value !== 'function') {
44
+ return value;
45
+ }
46
+ return (...args) => {
47
+ const result = value.apply(target, args);
48
+ return isPromiseLike(result) ? from(result) : result;
49
+ };
50
+ }
51
+ });
52
+ }
53
+ }
@@ -0,0 +1,86 @@
1
+ import { FetchResponse, MaybeOptionalInit } from 'openapi-fetch';
2
+ import { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf } from 'openapi-typescript-helpers';
3
+ export type ExtendedPaths<Paths> = Paths & Record<string, Record<HttpMethod, {}>>;
4
+ export type InitParam<Init> = RequiredKeysOf<Init> extends never ? [(Init & {
5
+ [key: string]: unknown;
6
+ })?] : [Init & {
7
+ [key: string]: unknown;
8
+ }];
9
+ /**
10
+ * Minimal structural subset of an RxJS `Observable`.
11
+ *
12
+ * Keeps the base client free of any `rxjs` dependency (runtime and types) while
13
+ * remaining assignable from a real `Observable` — `AngularClient` narrows these
14
+ * return types to concrete RxJS Observables in the `@appweaver/client/angular` entry.
15
+ */
16
+ export interface ObservableLike<T> {
17
+ subscribe(observer?: {
18
+ next?: (value: T) => void;
19
+ error?: (error: any) => void;
20
+ complete?: () => void;
21
+ }): {
22
+ unsubscribe(): void;
23
+ };
24
+ }
25
+ export type ObservableOrPromise<T, B extends boolean> = B extends true ? ObservableLike<T> : Promise<T>;
26
+ export type PromiseToObservable<T> = T extends Promise<infer R> ? ObservableLike<R> : T;
27
+ export type ObservableMethods<T> = {
28
+ [K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => PromiseToObservable<R> : T[K];
29
+ };
30
+ /**
31
+ * Public interface for {@link BaseClient} exposing the three core request methods.
32
+ *
33
+ * @typeParam Paths - The OpenAPI path map generated by `openapi-typescript` for the target API.
34
+ */
35
+ export interface BaseClientInterface<Paths extends {} = {
36
+ [key: string]: any;
37
+ }, UseObservable extends boolean = false> {
38
+ /**
39
+ * Sends an HTTP request and returns the parsed response data.
40
+ *
41
+ * Throws a {@link ClientError} if the server returns an error response, including the
42
+ * error message and status code from the response body when available.
43
+ *
44
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
45
+ * @typeParam Path - A path in `Paths` that supports `Method`.
46
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
47
+ * @param {HttpMethod} method - The HTTP method to use.
48
+ * @param {string} url - The API path to request.
49
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
50
+ * @returns The non-nullable `data` field from the response.
51
+ * @throws {ClientError} When the server returns an error response.
52
+ */
53
+ sendRequest<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): ObservableOrPromise<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>, UseObservable>;
54
+ /**
55
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple.
56
+ *
57
+ * Unlike {@link sendRequest}, this method does **not** throw on error responses — callers
58
+ * receive the full `{ data, error, response }` object and are responsible for handling
59
+ * error cases themselves.
60
+ *
61
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
62
+ * @typeParam Path - A path in `Paths` that supports `Method`.
63
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
64
+ * @param {HttpMethod} method - The HTTP method to use.
65
+ * @param {string} url - The API path to request.
66
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
67
+ * @returns The raw `FetchResponse` containing `data`, `error`, and the native `Response`.
68
+ */
69
+ sendRequestRaw<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): ObservableOrPromise<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>, UseObservable>;
70
+ /**
71
+ * Sends an HTTP request and returns the parsed response data as a Promise.
72
+ *
73
+ * This protected helper always returns a `Promise` and is intended to be called
74
+ * by {@link sendRequest} and overrides in subclasses such as `AngularClient`.
75
+ *
76
+ * @throws {ClientError} When the server returns an error response.
77
+ */
78
+ sendRequestPromise<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Promise<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>>;
79
+ /**
80
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple as a Promise.
81
+ *
82
+ * This protected helper always returns a `Promise` and is intended to be called
83
+ * by {@link sendRequestRaw} and overrides in subclasses such as `AngularClient`.
84
+ */
85
+ sendRequestRawPromise<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Promise<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>>;
86
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,216 @@
1
+ import { Client, FetchResponse, MaybeOptionalInit, Middleware } from 'openapi-fetch';
2
+ import { HttpMethod, MediaType, PathsWithMethod } from 'openapi-typescript-helpers';
3
+ import { BaseClientInterface, ExtendedPaths, InitParam, ObservableMethods, ObservableOrPromise } from './base-client-interface.js';
4
+ import { AccountClient, AccountInterface, AccountType, AuthClient, AuthInterface, AuthType, FilesClient, HealthClient, HealthInterface, HealthType, ResourceClient, ResourceInterface, ResourceType } from './modules/index.js';
5
+ export type ClientResult<TClient, Interface, OmitFields extends readonly (keyof Interface)[]> = [OmitFields[number]] extends [never] ? TClient : Omit<TClient, OmitFields[number]>;
6
+ export type ClientResultMethods<T, B extends boolean> = B extends true ? ObservableMethods<T> : T;
7
+ /**
8
+ * Function type for dynamically resolving authentication values per request.
9
+ *
10
+ * This function receives the outgoing `Request` and can return authentication configuration
11
+ * either synchronously or asynchronously. Used to provide dynamic auth values (e.g., fetching
12
+ * tokens from storage) instead of static strings or objects.
13
+ *
14
+ * @typeParam T - The type of authentication value to return (string, JwtAuthConfig, ApiKeyAuthConfig, or
15
+ * BasicAuthConfig).
16
+ * @param {Request} req - The outgoing HTTP request object.
17
+ * @returns The authentication value, either directly or wrapped in a Promise.
18
+ */
19
+ export type AuthFn<T> = (req: Request) => T | Promise<T>;
20
+ /** Configuration for JWT-based authentication. */
21
+ export type JwtAuthConfig = {
22
+ /** The JWT access token to include in the `Authorization: Bearer` header. */
23
+ accessToken: string;
24
+ /** Optional refresh token for renewing expired access tokens when calling the refresh endpoint. */
25
+ refreshToken?: string;
26
+ };
27
+ /** Configuration for API key authentication. */
28
+ export type ApiKeyAuthConfig = {
29
+ /** The API key value to send in the request header. */
30
+ key: string;
31
+ /** The header name to use for the API key. Defaults to `X-Api-Key`. */
32
+ header?: string;
33
+ };
34
+ /** Configuration for HTTP Basic authentication. */
35
+ export type BasicAuthConfig = {
36
+ /** The username for Basic authentication. */
37
+ username: string;
38
+ /** The password for Basic authentication. */
39
+ password: string;
40
+ };
41
+ /**
42
+ * Authentication configuration for the client. Exactly one auth strategy must be provided.
43
+ *
44
+ * - `jwt` — attaches a `Bearer` token to the `Authorization` header.
45
+ * - `apiKey` — attaches a key to a configurable header (default: `X-Api-Key`).
46
+ * - `basic` — attaches Base64-encoded credentials to the `Authorization` header.
47
+ *
48
+ * Each value may be a static config object, a plain string shorthand, or an async function
49
+ * that receives the outgoing `Request` and returns the auth value dynamically.
50
+ */
51
+ export type AuthConfig = {
52
+ jwt: string | AuthFn<string> | AuthFn<JwtAuthConfig> | JwtAuthConfig;
53
+ } | {
54
+ apiKey: string | AuthFn<string> | AuthFn<ApiKeyAuthConfig> | ApiKeyAuthConfig;
55
+ } | {
56
+ basic: string | AuthFn<string> | AuthFn<BasicAuthConfig> | BasicAuthConfig;
57
+ };
58
+ /**
59
+ * Type definition for a custom fetch handler implementation.
60
+ *
61
+ * This type represents a function that performs HTTP requests and returns a Promise resolving to a Response object.
62
+ * It is intended to be used as a replacement or extension of the default `fetch` function provided by the browser or
63
+ * other runtime environments.
64
+ *
65
+ * @param {RequestInfo} request - The resource that you wish to fetch, either as a string URL or a Request object.
66
+ * @param {RequestInit} [init] - Optional options object containing custom settings for the fetch request, such as
67
+ * method, headers, body, and more.
68
+ * @returns {Promise<Response>} A Promise that resolves to the Response to the request.
69
+ */
70
+ export type FetchHandler = (request: RequestInfo, init?: RequestInit) => Promise<Response>;
71
+ /** Configuration options for {@link FetchClient}. */
72
+ export type ClientConfig = {
73
+ /** The base URL that will be prepended to every request path. */
74
+ baseUrl: string;
75
+ /** Request timeout in milliseconds. Requests that exceed this duration are aborted. */
76
+ timeout?: number;
77
+ /** Additional `openapi-fetch` middlewares applied after the built-in timeout and auth middlewares. */
78
+ middlewares?: Middleware[];
79
+ /** Authentication strategy to attach to every outgoing request. */
80
+ auth?: AuthConfig;
81
+ /** Custom fetch handler implementation for making HTTP requests and transforming responses. */
82
+ fetch?: FetchHandler;
83
+ };
84
+ /**
85
+ * Type-safe HTTP client built on top of `openapi-fetch`.
86
+ *
87
+ * `BaseClient` wires up a base URL, optional request timeout, optional authentication
88
+ * middleware, and any additional custom middlewares into a single reusable client instance.
89
+ * Subclasses expose domain-specific helpers by composing the protected factory methods
90
+ * (`resourceClient`, `authClient`, `accountClient`, `healthClient`, `fileClient`).
91
+ *
92
+ * @typeParam Paths - The OpenAPI path map generated by `openapi-typescript` for the target API.
93
+ * @typeParam UseObservable - Boolean flag indicating whether to return Observables (true) or Promises (false).
94
+ * Defaults to false for Promise-based clients like `FetchClient`. Set to true in `AngularClient` to enable RxJS
95
+ * Observable support.
96
+ */
97
+ export declare abstract class BaseClient<Paths extends {} = {
98
+ [key: string]: any;
99
+ }, UseObservable extends boolean = false> implements BaseClientInterface<Paths, UseObservable> {
100
+ private readonly _config;
101
+ private readonly _client;
102
+ private readonly _modules;
103
+ protected constructor(_config: ClientConfig);
104
+ /**
105
+ * Returns the underlying `openapi-fetch` client instance.
106
+ *
107
+ * Use this when direct access to the raw client is required to call methods
108
+ * not exposed by `FetchClient` directly.
109
+ */
110
+ getClient(): Client<Paths>;
111
+ /**
112
+ * Retrieves the client configuration.
113
+ *
114
+ * @return {ClientConfig} The current client configuration instance.
115
+ */
116
+ getConfig(): ClientConfig;
117
+ /**
118
+ * Sends an HTTP request and returns the parsed response data.
119
+ *
120
+ * Returns a `Promise` by default. In `AngularClient` (where `UseObservable = true`)
121
+ * this method is overridden to return an `Observable` instead.
122
+ *
123
+ * Throws a {@link ClientError} if the server returns an error response, including the
124
+ * error message and status code from the response body when available.
125
+ *
126
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
127
+ * @typeParam Path - A path in `Paths` that supports `Method`.
128
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
129
+ * @param {HttpMethod} method - The HTTP method to use.
130
+ * @param {string} url - The API path to request.
131
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
132
+ * @returns The non-nullable `data` field from the response.
133
+ * @throws {ClientError} When the server returns an error response.
134
+ */
135
+ sendRequest<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): ObservableOrPromise<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>, UseObservable>;
136
+ /**
137
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple.
138
+ *
139
+ * Returns a `Promise` by default. In `AngularClient` (where `UseObservable = true`)
140
+ * this method is overridden to return an `Observable` instead.
141
+ *
142
+ * Unlike {@link sendRequest}, this method does **not** throw on error responses — callers
143
+ * receive the full `{ data, error, response }` object and are responsible for handling
144
+ * error cases themselves.
145
+ *
146
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
147
+ * @typeParam Path - A path in `Paths` that supports `Method`.
148
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
149
+ * @param {HttpMethod} method - The HTTP method to use.
150
+ * @param {string} url - The API path to request.
151
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
152
+ * @returns The raw `FetchResponse` containing `data`, `error`, and the native `Response`.
153
+ */
154
+ sendRequestRaw<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): ObservableOrPromise<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>, UseObservable>;
155
+ /**
156
+ * Sends an HTTP request and returns the parsed response data as a Promise.
157
+ *
158
+ * This protected helper always returns a `Promise` and is intended to be called
159
+ * by {@link sendRequest} and overrides in subclasses such as `AngularClient`.
160
+ *
161
+ * @throws {ClientError} When the server returns an error response.
162
+ */
163
+ sendRequestPromise<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Promise<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>>;
164
+ /**
165
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple as a Promise.
166
+ *
167
+ * This protected helper always returns a `Promise` and is intended to be called
168
+ * by {@link sendRequestRaw} and overrides in subclasses such as `AngularClient`.
169
+ */
170
+ sendRequestRawPromise<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path, ...params: InitParam<Init>): Promise<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>>;
171
+ /**
172
+ * Handles a custom HTTP request based on the provided method, URL, and initialization parameters.
173
+ *
174
+ * @param {Method} method - The HTTP method to be used (e.g., GET, POST).
175
+ * @param {Path} url - The endpoint URL corresponding to the specified method.
176
+ * @return A function that accepts initialization parameters and returns an observable or promise of the fetched data.
177
+ */
178
+ protected customRequest<Method extends HttpMethod, Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<ExtendedPaths<Paths>[Path], Method>>(method: Method, url: Path): (...params: InitParam<Init>) => ObservableOrPromise<NonNullable<FetchResponse<ExtendedPaths<Paths>[Path][Method], Init, MediaType>['data']>, UseObservable>;
179
+ /**
180
+ * Creates and returns a new instance of a ResourceClient for managing a specific resource type.
181
+ *
182
+ * @param {string} resourcePath - The API path or endpoint for the resource.
183
+ * @template Resource - The type of the resource being managed.
184
+ * @template OmitFields - An optional array of resource interface fields to omit.
185
+ * @return {ResourceClient} A ResourceClient instance for interacting with the specified resource.
186
+ */
187
+ protected resourceClient<Resource extends ResourceType, OmitFields extends readonly (keyof ResourceInterface)[] = []>(resourcePath: string): ClientResultMethods<ClientResult<ResourceClient<Resource>, ResourceInterface, OmitFields>, UseObservable>;
188
+ /**
189
+ * Creates and returns an AuthClient instance for managing authentication operations.
190
+ *
191
+ * @param {string} authPath - The authentication path used to configure the AuthClient instance.
192
+ * @return {AuthClient} An instance of AuthClient initialized with the provided authentication path.
193
+ */
194
+ protected authClient<Auth extends AuthType, OmitFields extends readonly (keyof AuthInterface)[] = []>(authPath: string): ClientResultMethods<ClientResult<AuthClient<Auth>, AuthInterface, OmitFields>, UseObservable>;
195
+ /**
196
+ * Creates and returns an AccountClient instance for managing account-related operations.
197
+ *
198
+ * @param {string} accountPath - The path to the account resource.
199
+ * @return {AccountClient} An instance of AccountClient configured with the provided account path.
200
+ */
201
+ protected accountClient<Account extends AccountType, OmitFields extends readonly (keyof AccountInterface)[] = []>(accountPath: string): ClientResultMethods<ClientResult<AccountClient<Account>, AccountInterface, OmitFields>, UseObservable>;
202
+ /**
203
+ * Creates and returns a HealthClient instance for interacting with health-related data.
204
+ *
205
+ * @param {string} healthPath - The path to the health resource endpoint.
206
+ * @return {HealthClient} An instance of HealthClient configured with the provided health path.
207
+ */
208
+ protected healthClient<Health extends HealthType, OmitFields extends readonly (keyof HealthInterface)[] = []>(healthPath: string): ClientResultMethods<ClientResult<HealthClient<Health>, HealthInterface, OmitFields>, UseObservable>;
209
+ /**
210
+ * Creates and returns an instance of `FilesClient` for the specified file path.
211
+ *
212
+ * @param {string} filesPath - The file path used to initialize the `FilesClient`.
213
+ * @return {FilesClient} An instance of FilesClient configured with the provided files' path.
214
+ */
215
+ protected filesClient<OmitFields extends readonly (keyof HealthInterface)[] = []>(filesPath: string): ClientResultMethods<ClientResult<FilesClient, HealthInterface, OmitFields>, UseObservable>;
216
+ }
@@ -0,0 +1,242 @@
1
+ import createClient from 'openapi-fetch';
2
+ import { AccountClient, AuthClient, FilesClient, HealthClient, ResourceClient } from './modules/index.js';
3
+ import { ClientError } from '../errors/index.js';
4
+ /**
5
+ * Type-safe HTTP client built on top of `openapi-fetch`.
6
+ *
7
+ * `BaseClient` wires up a base URL, optional request timeout, optional authentication
8
+ * middleware, and any additional custom middlewares into a single reusable client instance.
9
+ * Subclasses expose domain-specific helpers by composing the protected factory methods
10
+ * (`resourceClient`, `authClient`, `accountClient`, `healthClient`, `fileClient`).
11
+ *
12
+ * @typeParam Paths - The OpenAPI path map generated by `openapi-typescript` for the target API.
13
+ * @typeParam UseObservable - Boolean flag indicating whether to return Observables (true) or Promises (false).
14
+ * Defaults to false for Promise-based clients like `FetchClient`. Set to true in `AngularClient` to enable RxJS
15
+ * Observable support.
16
+ */
17
+ export class BaseClient {
18
+ _config;
19
+ _client;
20
+ _modules = {
21
+ resources: []
22
+ };
23
+ constructor(_config) {
24
+ this._config = _config;
25
+ const { baseUrl, timeout, middlewares, auth, fetch } = _config;
26
+ this._client = createClient({ baseUrl, fetch });
27
+ if (timeout) {
28
+ this._client.use({
29
+ onRequest: async ({ request }) => {
30
+ const timeoutSignal = AbortSignal.timeout(timeout);
31
+ return new Request(request, {
32
+ signal: request.signal
33
+ ? AbortSignal.any([request.signal, timeoutSignal])
34
+ : timeoutSignal
35
+ });
36
+ }
37
+ });
38
+ }
39
+ if (auth) {
40
+ this._client.use({
41
+ onRequest: async ({ request, schemaPath }) => {
42
+ const headers = new Headers(request.headers);
43
+ if ('jwt' in auth) {
44
+ const jwt = typeof auth.jwt === 'function'
45
+ ? await auth.jwt(request)
46
+ : auth.jwt;
47
+ let token;
48
+ if (typeof jwt === 'object') {
49
+ token = jwt.accessToken;
50
+ const refreshPath = `/${this._modules.auth?.basePath}/refresh`.replace(/\/+/g, '/');
51
+ if (schemaPath === refreshPath && jwt.refreshToken) {
52
+ token = jwt.refreshToken;
53
+ }
54
+ }
55
+ else {
56
+ token = jwt;
57
+ }
58
+ headers.set('Authorization', `Bearer ${token}`);
59
+ }
60
+ else if ('basic' in auth) {
61
+ const basic = typeof auth.basic === 'function'
62
+ ? await auth.basic(request)
63
+ : auth.basic;
64
+ const secret = typeof basic === 'string'
65
+ ? basic
66
+ : btoa(`${basic.username}:${basic.password}`);
67
+ headers.set('Authorization', `Basic ${secret}`);
68
+ }
69
+ if ('apiKey' in auth) {
70
+ const apiKey = typeof auth.apiKey === 'function'
71
+ ? await auth.apiKey(request)
72
+ : auth.apiKey;
73
+ const key = typeof apiKey === 'string' ? apiKey : apiKey.key;
74
+ const header = typeof apiKey !== 'string' ? apiKey?.header : undefined;
75
+ headers.set(header ?? 'X-Api-Key', key);
76
+ }
77
+ return new Request(request, {
78
+ headers
79
+ });
80
+ }
81
+ });
82
+ }
83
+ if (middlewares) {
84
+ for (const middleware of middlewares) {
85
+ this._client.use(middleware);
86
+ }
87
+ }
88
+ }
89
+ /**
90
+ * Returns the underlying `openapi-fetch` client instance.
91
+ *
92
+ * Use this when direct access to the raw client is required to call methods
93
+ * not exposed by `FetchClient` directly.
94
+ */
95
+ getClient() {
96
+ return this._client;
97
+ }
98
+ /**
99
+ * Retrieves the client configuration.
100
+ *
101
+ * @return {ClientConfig} The current client configuration instance.
102
+ */
103
+ getConfig() {
104
+ return this._config;
105
+ }
106
+ /**
107
+ * Sends an HTTP request and returns the parsed response data.
108
+ *
109
+ * Returns a `Promise` by default. In `AngularClient` (where `UseObservable = true`)
110
+ * this method is overridden to return an `Observable` instead.
111
+ *
112
+ * Throws a {@link ClientError} if the server returns an error response, including the
113
+ * error message and status code from the response body when available.
114
+ *
115
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
116
+ * @typeParam Path - A path in `Paths` that supports `Method`.
117
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
118
+ * @param {HttpMethod} method - The HTTP method to use.
119
+ * @param {string} url - The API path to request.
120
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
121
+ * @returns The non-nullable `data` field from the response.
122
+ * @throws {ClientError} When the server returns an error response.
123
+ */
124
+ sendRequest(method, url, ...params) {
125
+ return this.sendRequestPromise(method, url, ...params);
126
+ }
127
+ /**
128
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple.
129
+ *
130
+ * Returns a `Promise` by default. In `AngularClient` (where `UseObservable = true`)
131
+ * this method is overridden to return an `Observable` instead.
132
+ *
133
+ * Unlike {@link sendRequest}, this method does **not** throw on error responses — callers
134
+ * receive the full `{ data, error, response }` object and are responsible for handling
135
+ * error cases themselves.
136
+ *
137
+ * @typeParam Method - The HTTP method (e.g. `"get"`, `"post"`).
138
+ * @typeParam Path - A path in `Paths` that supports `Method`.
139
+ * @typeParam Init - The request init inferred from the OpenAPI schema for this operation.
140
+ * @param {HttpMethod} method - The HTTP method to use.
141
+ * @param {string} url - The API path to request.
142
+ * @param {Object} params - Optional request parameters (body, query, headers, etc.) as defined by the schema.
143
+ * @returns The raw `FetchResponse` containing `data`, `error`, and the native `Response`.
144
+ */
145
+ sendRequestRaw(method, url, ...params) {
146
+ return this.sendRequestRawPromise(method, url, ...params);
147
+ }
148
+ /**
149
+ * Sends an HTTP request and returns the parsed response data as a Promise.
150
+ *
151
+ * This protected helper always returns a `Promise` and is intended to be called
152
+ * by {@link sendRequest} and overrides in subclasses such as `AngularClient`.
153
+ *
154
+ * @throws {ClientError} When the server returns an error response.
155
+ */
156
+ async sendRequestPromise(method, url, ...params) {
157
+ const { data, error, response } = await this._client.request(method, url, ...params);
158
+ if (error) {
159
+ const err = error;
160
+ throw new ClientError(err.message ?? response.statusText ?? 'Unknown error', err.errorCode ?? response.status, response, error);
161
+ }
162
+ return data;
163
+ }
164
+ /**
165
+ * Sends an HTTP request and returns the raw `openapi-fetch` response tuple as a Promise.
166
+ *
167
+ * This protected helper always returns a `Promise` and is intended to be called
168
+ * by {@link sendRequestRaw} and overrides in subclasses such as `AngularClient`.
169
+ */
170
+ sendRequestRawPromise(method, url, ...params) {
171
+ return this._client.request(method, url, ...params);
172
+ }
173
+ /**
174
+ * Handles a custom HTTP request based on the provided method, URL, and initialization parameters.
175
+ *
176
+ * @param {Method} method - The HTTP method to be used (e.g., GET, POST).
177
+ * @param {Path} url - The endpoint URL corresponding to the specified method.
178
+ * @return A function that accepts initialization parameters and returns an observable or promise of the fetched data.
179
+ */
180
+ customRequest(method, url) {
181
+ return (...params) => {
182
+ return this.sendRequest(method, url, ...params);
183
+ };
184
+ }
185
+ /**
186
+ * Creates and returns a new instance of a ResourceClient for managing a specific resource type.
187
+ *
188
+ * @param {string} resourcePath - The API path or endpoint for the resource.
189
+ * @template Resource - The type of the resource being managed.
190
+ * @template OmitFields - An optional array of resource interface fields to omit.
191
+ * @return {ResourceClient} A ResourceClient instance for interacting with the specified resource.
192
+ */
193
+ resourceClient(resourcePath) {
194
+ const resource = new ResourceClient(this, resourcePath);
195
+ this._modules.resources.push(resource);
196
+ return resource;
197
+ }
198
+ /**
199
+ * Creates and returns an AuthClient instance for managing authentication operations.
200
+ *
201
+ * @param {string} authPath - The authentication path used to configure the AuthClient instance.
202
+ * @return {AuthClient} An instance of AuthClient initialized with the provided authentication path.
203
+ */
204
+ authClient(authPath) {
205
+ const auth = new AuthClient(this, authPath);
206
+ this._modules.auth = auth;
207
+ return auth;
208
+ }
209
+ /**
210
+ * Creates and returns an AccountClient instance for managing account-related operations.
211
+ *
212
+ * @param {string} accountPath - The path to the account resource.
213
+ * @return {AccountClient} An instance of AccountClient configured with the provided account path.
214
+ */
215
+ accountClient(accountPath) {
216
+ const account = new AccountClient(this, accountPath);
217
+ this._modules.account = account;
218
+ return account;
219
+ }
220
+ /**
221
+ * Creates and returns a HealthClient instance for interacting with health-related data.
222
+ *
223
+ * @param {string} healthPath - The path to the health resource endpoint.
224
+ * @return {HealthClient} An instance of HealthClient configured with the provided health path.
225
+ */
226
+ healthClient(healthPath) {
227
+ const health = new HealthClient(this, healthPath);
228
+ this._modules.health = health;
229
+ return health;
230
+ }
231
+ /**
232
+ * Creates and returns an instance of `FilesClient` for the specified file path.
233
+ *
234
+ * @param {string} filesPath - The file path used to initialize the `FilesClient`.
235
+ * @return {FilesClient} An instance of FilesClient configured with the provided files' path.
236
+ */
237
+ filesClient(filesPath) {
238
+ const files = new FilesClient(this, filesPath);
239
+ this._modules.files = files;
240
+ return files;
241
+ }
242
+ }
@@ -0,0 +1,6 @@
1
+ import { ClientConfig, BaseClient } from './base-client.js';
2
+ export declare class FetchClient<Paths extends {} = {
3
+ [key: string]: any;
4
+ }> extends BaseClient<Paths> {
5
+ constructor(config: ClientConfig);
6
+ }