@appweaver/client 1.0.22 → 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/angular/index.d.ts +1 -0
  2. package/cjs/angular/index.js +17 -0
  3. package/{clients → cjs/clients}/angular-client.d.ts +7 -1
  4. package/{clients → cjs/clients}/base-client-interface.d.ts +18 -3
  5. package/{clients → cjs/clients}/index.d.ts +0 -1
  6. package/{clients → cjs/clients}/index.js +0 -1
  7. package/{generators → cjs/generators}/generate-client.js +2 -1
  8. package/cjs/package.json +3 -0
  9. package/{weaver-client.js → cjs/weaver-client.js} +1 -1
  10. package/esm/angular/index.d.ts +1 -0
  11. package/esm/angular/index.js +1 -0
  12. package/esm/clients/angular-client.d.ts +26 -0
  13. package/esm/clients/angular-client.js +53 -0
  14. package/esm/clients/base-client-interface.d.ts +86 -0
  15. package/esm/clients/base-client-interface.js +1 -0
  16. package/esm/clients/base-client.d.ts +216 -0
  17. package/esm/clients/base-client.js +242 -0
  18. package/esm/clients/fetch-client.d.ts +6 -0
  19. package/esm/clients/fetch-client.js +6 -0
  20. package/esm/clients/index.d.ts +4 -0
  21. package/esm/clients/index.js +4 -0
  22. package/esm/clients/modules/account-client.d.ts +69 -0
  23. package/esm/clients/modules/account-client.js +107 -0
  24. package/esm/clients/modules/auth-client.d.ts +56 -0
  25. package/esm/clients/modules/auth-client.js +74 -0
  26. package/esm/clients/modules/base-module.d.ts +17 -0
  27. package/esm/clients/modules/base-module.js +49 -0
  28. package/esm/clients/modules/files-client.d.ts +27 -0
  29. package/esm/clients/modules/files-client.js +42 -0
  30. package/esm/clients/modules/health-client.d.ts +25 -0
  31. package/esm/clients/modules/health-client.js +30 -0
  32. package/esm/clients/modules/index.d.ts +6 -0
  33. package/esm/clients/modules/index.js +6 -0
  34. package/esm/clients/modules/resource-client.d.ts +90 -0
  35. package/esm/clients/modules/resource-client.js +173 -0
  36. package/esm/clients/responses/file-data-response.d.ts +78 -0
  37. package/esm/clients/responses/file-data-response.js +105 -0
  38. package/esm/clients/responses/index.d.ts +1 -0
  39. package/esm/clients/responses/index.js +1 -0
  40. package/esm/commands/generate-command.d.ts +3 -0
  41. package/esm/commands/generate-command.js +122 -0
  42. package/esm/commands/index.d.ts +1 -0
  43. package/esm/commands/index.js +1 -0
  44. package/esm/constants.d.ts +67 -0
  45. package/esm/constants.js +94 -0
  46. package/esm/errors/client-error.d.ts +6 -0
  47. package/esm/errors/client-error.js +11 -0
  48. package/esm/errors/index.d.ts +1 -0
  49. package/esm/errors/index.js +1 -0
  50. package/esm/generators/generate-client.d.ts +16 -0
  51. package/esm/generators/generate-client.js +399 -0
  52. package/esm/generators/generate-types.d.ts +9 -0
  53. package/esm/generators/generate-types.js +486 -0
  54. package/esm/generators/index.d.ts +2 -0
  55. package/esm/generators/index.js +2 -0
  56. package/esm/index.d.ts +2 -0
  57. package/esm/index.js +2 -0
  58. package/esm/package.json +3 -0
  59. package/esm/types/index.d.ts +1 -0
  60. package/esm/types/index.js +1 -0
  61. package/esm/types/routes.d.ts +15 -0
  62. package/esm/types/routes.js +1 -0
  63. package/esm/utils/index.d.ts +1 -0
  64. package/esm/utils/index.js +1 -0
  65. package/esm/utils/schema-util.d.ts +3 -0
  66. package/esm/utils/schema-util.js +39 -0
  67. package/package.json +39 -7
  68. /package/{clients → cjs/clients}/angular-client.js +0 -0
  69. /package/{clients → cjs/clients}/base-client-interface.js +0 -0
  70. /package/{clients → cjs/clients}/base-client.d.ts +0 -0
  71. /package/{clients → cjs/clients}/base-client.js +0 -0
  72. /package/{clients → cjs/clients}/fetch-client.d.ts +0 -0
  73. /package/{clients → cjs/clients}/fetch-client.js +0 -0
  74. /package/{clients → cjs/clients}/modules/account-client.d.ts +0 -0
  75. /package/{clients → cjs/clients}/modules/account-client.js +0 -0
  76. /package/{clients → cjs/clients}/modules/auth-client.d.ts +0 -0
  77. /package/{clients → cjs/clients}/modules/auth-client.js +0 -0
  78. /package/{clients → cjs/clients}/modules/base-module.d.ts +0 -0
  79. /package/{clients → cjs/clients}/modules/base-module.js +0 -0
  80. /package/{clients → cjs/clients}/modules/files-client.d.ts +0 -0
  81. /package/{clients → cjs/clients}/modules/files-client.js +0 -0
  82. /package/{clients → cjs/clients}/modules/health-client.d.ts +0 -0
  83. /package/{clients → cjs/clients}/modules/health-client.js +0 -0
  84. /package/{clients → cjs/clients}/modules/index.d.ts +0 -0
  85. /package/{clients → cjs/clients}/modules/index.js +0 -0
  86. /package/{clients → cjs/clients}/modules/resource-client.d.ts +0 -0
  87. /package/{clients → cjs/clients}/modules/resource-client.js +0 -0
  88. /package/{clients → cjs/clients}/responses/file-data-response.d.ts +0 -0
  89. /package/{clients → cjs/clients}/responses/file-data-response.js +0 -0
  90. /package/{clients → cjs/clients}/responses/index.d.ts +0 -0
  91. /package/{clients → cjs/clients}/responses/index.js +0 -0
  92. /package/{commands → cjs/commands}/generate-command.d.ts +0 -0
  93. /package/{commands → cjs/commands}/generate-command.js +0 -0
  94. /package/{commands → cjs/commands}/index.d.ts +0 -0
  95. /package/{commands → cjs/commands}/index.js +0 -0
  96. /package/{constants.d.ts → cjs/constants.d.ts} +0 -0
  97. /package/{constants.js → cjs/constants.js} +0 -0
  98. /package/{errors → cjs/errors}/client-error.d.ts +0 -0
  99. /package/{errors → cjs/errors}/client-error.js +0 -0
  100. /package/{errors → cjs/errors}/index.d.ts +0 -0
  101. /package/{errors → cjs/errors}/index.js +0 -0
  102. /package/{generators → cjs/generators}/generate-client.d.ts +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,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
+ }
@@ -0,0 +1,6 @@
1
+ import { BaseClient } from './base-client.js';
2
+ export class FetchClient extends BaseClient {
3
+ constructor(config) {
4
+ super(config);
5
+ }
6
+ }
@@ -0,0 +1,4 @@
1
+ export * from './modules/index.js';
2
+ export * from './base-client.js';
3
+ export * from './base-client-interface.js';
4
+ export * from './fetch-client.js';
@@ -0,0 +1,4 @@
1
+ export * from './modules/index.js';
2
+ export * from './base-client.js';
3
+ export * from './base-client-interface.js';
4
+ export * from './fetch-client.js';
@@ -0,0 +1,69 @@
1
+ import { BaseModule, RequestOptions } from './base-module.js';
2
+ import { BaseClientInterface } from '../base-client-interface.js';
3
+ import { ACCOUNT_OPERATIONS, ACCOUNT_TYPES } from '../../constants.js';
4
+ export type AccountType = Record<(typeof ACCOUNT_TYPES)[number], unknown>;
5
+ export type AccountInterface = {
6
+ [K in keyof typeof ACCOUNT_OPERATIONS]: (...args: any[]) => Promise<any>;
7
+ };
8
+ export declare class AccountClient<Account extends AccountType> extends BaseModule implements AccountInterface {
9
+ readonly basePath: string;
10
+ constructor(client: BaseClientInterface, basePath: string);
11
+ /**
12
+ * Sends a verification email to the user's registered email address.
13
+ *
14
+ * @param {Object} request - The payload identifying the account to send the email to.
15
+ * @param {RequestOptions} options - Additional request options.
16
+ * @returns A status response indicating whether the email was dispatched successfully.
17
+ */
18
+ sendVerifyEmail(request: Account['sendEmailVerificationRequest'], options?: RequestOptions): Promise<Account['statusResponse']>;
19
+ /**
20
+ * Verifies a user's email address using a verification token.
21
+ *
22
+ * @param {Object} request - The payload containing the verification token.
23
+ * @param {RequestOptions} options - Additional request options.
24
+ * @returns A status response indicating whether the email was verified successfully.
25
+ */
26
+ verifyEmail(request: Account['emailVerificationRequest'], options?: RequestOptions): Promise<Account['statusResponse']>;
27
+ /**
28
+ * Handles the redirect-based email verification flow by passing the token as a query parameter.
29
+ *
30
+ * Typically used as the target of a link sent in a verification email.
31
+ *
32
+ * @param {string} token - The email verification token from the redirect URL.
33
+ * @param {RequestOptions} options - Additional request options.
34
+ * @returns The server response for the redirect verification (shape depends on the API).
35
+ */
36
+ verifyEmailRedirect(token: string, options?: RequestOptions): Promise<any>;
37
+ /**
38
+ * Sends a password reset email to the user's registered email address.
39
+ *
40
+ * @param {Object} request - The payload identifying the account (e.g., email address).
41
+ * @param {RequestOptions} options - Additional request options.
42
+ * @returns A status response indicating whether the reset email was dispatched successfully.
43
+ */
44
+ sendResetPassword(request: Account['sendResetPasswordRequest'], options?: RequestOptions): Promise<Account['statusResponse']>;
45
+ /**
46
+ * Resets the user's password using a reset token.
47
+ *
48
+ * @param {Object} request - The payload containing the reset token and the new password.
49
+ * @param {RequestOptions} options - Additional request options.
50
+ * @returns A status response indicating whether the password was reset successfully.
51
+ */
52
+ resetPassword(request: Account['resetPasswordRequest'], options?: RequestOptions): Promise<Account['statusResponse']>;
53
+ /**
54
+ * Sends a two-factor authentication (2FA) code to the user (e.g., via SMS or email).
55
+ *
56
+ * @param {Object} request - The payload identifying the account to send the code to.
57
+ * @param {RequestOptions} options - Additional request options.
58
+ * @returns A response confirming the 2FA code was sent.
59
+ */
60
+ send2FACode(request: Account['send2FACodeRequest'], options?: RequestOptions): Promise<Account['send2FAResponse']>;
61
+ /**
62
+ * Verifies a two-factor authentication (2FA) code submitted by the user.
63
+ *
64
+ * @param {Object} request - The payload containing the 2FA code to verify.
65
+ * @param {RequestOptions} options - Additional request options.
66
+ * @returns A response indicating whether the 2FA verification succeeded.
67
+ */
68
+ verify2FACode(request: Account['verify2FARequest'], options?: RequestOptions): Promise<Account['verify2FAResponse']>;
69
+ }
@@ -0,0 +1,107 @@
1
+ import { BaseModule } from './base-module.js';
2
+ export class AccountClient extends BaseModule {
3
+ basePath;
4
+ constructor(client, basePath) {
5
+ super(client);
6
+ this.basePath = basePath;
7
+ }
8
+ /**
9
+ * Sends a verification email to the user's registered email address.
10
+ *
11
+ * @param {Object} request - The payload identifying the account to send the email to.
12
+ * @param {RequestOptions} options - Additional request options.
13
+ * @returns A status response indicating whether the email was dispatched successfully.
14
+ */
15
+ async sendVerifyEmail(request, options = {}) {
16
+ return this.sendRequest('post', `${this.basePath}/send-verify-email`, {
17
+ ...options,
18
+ body: request
19
+ });
20
+ }
21
+ /**
22
+ * Verifies a user's email address using a verification token.
23
+ *
24
+ * @param {Object} request - The payload containing the verification token.
25
+ * @param {RequestOptions} options - Additional request options.
26
+ * @returns A status response indicating whether the email was verified successfully.
27
+ */
28
+ async verifyEmail(request, options = {}) {
29
+ return this.sendRequest('post', `${this.basePath}/verify-email`, {
30
+ ...options,
31
+ body: request
32
+ });
33
+ }
34
+ /**
35
+ * Handles the redirect-based email verification flow by passing the token as a query parameter.
36
+ *
37
+ * Typically used as the target of a link sent in a verification email.
38
+ *
39
+ * @param {string} token - The email verification token from the redirect URL.
40
+ * @param {RequestOptions} options - Additional request options.
41
+ * @returns The server response for the redirect verification (shape depends on the API).
42
+ */
43
+ async verifyEmailRedirect(token, options = {}) {
44
+ return this.sendRequest('get', `${this.basePath}/verify-email-redirect`, {
45
+ ...options,
46
+ params: {
47
+ ...(options.params ?? {}),
48
+ query: {
49
+ ...(options.params?.query ?? {}),
50
+ token
51
+ }
52
+ }
53
+ });
54
+ }
55
+ /**
56
+ * Sends a password reset email to the user's registered email address.
57
+ *
58
+ * @param {Object} request - The payload identifying the account (e.g., email address).
59
+ * @param {RequestOptions} options - Additional request options.
60
+ * @returns A status response indicating whether the reset email was dispatched successfully.
61
+ */
62
+ async sendResetPassword(request, options = {}) {
63
+ return this.sendRequest('post', `${this.basePath}/send-reset-password`, {
64
+ ...options,
65
+ body: request
66
+ });
67
+ }
68
+ /**
69
+ * Resets the user's password using a reset token.
70
+ *
71
+ * @param {Object} request - The payload containing the reset token and the new password.
72
+ * @param {RequestOptions} options - Additional request options.
73
+ * @returns A status response indicating whether the password was reset successfully.
74
+ */
75
+ async resetPassword(request, options = {}) {
76
+ return this.sendRequest('post', `${this.basePath}/reset-password`, {
77
+ ...options,
78
+ body: request
79
+ });
80
+ }
81
+ /**
82
+ * Sends a two-factor authentication (2FA) code to the user (e.g., via SMS or email).
83
+ *
84
+ * @param {Object} request - The payload identifying the account to send the code to.
85
+ * @param {RequestOptions} options - Additional request options.
86
+ * @returns A response confirming the 2FA code was sent.
87
+ */
88
+ async send2FACode(request, options = {}) {
89
+ return this.sendRequest('post', `${this.basePath}/send-2fa-code`, {
90
+ ...options,
91
+ body: request
92
+ });
93
+ }
94
+ /**
95
+ * Verifies a two-factor authentication (2FA) code submitted by the user.
96
+ *
97
+ * @param {Object} request - The payload containing the 2FA code to verify.
98
+ * @param {RequestOptions} options - Additional request options.
99
+ * @returns A response indicating whether the 2FA verification succeeded.
100
+ */
101
+ async verify2FACode(request, options = {}) {
102
+ return this.sendRequest('post', `${this.basePath}/account/verify-2fa-code`, {
103
+ ...options,
104
+ body: request
105
+ });
106
+ }
107
+ }
@@ -0,0 +1,56 @@
1
+ import { BaseModule, RequestOptions } from './base-module.js';
2
+ import { BaseClientInterface } from '../base-client-interface.js';
3
+ import { AUTH_OPERATIONS, AUTH_TYPES } from '../../constants.js';
4
+ export type AuthType = Record<(typeof AUTH_TYPES)[number], unknown>;
5
+ export type AuthInterface = {
6
+ [K in keyof typeof AUTH_OPERATIONS]: (...args: any[]) => Promise<any>;
7
+ };
8
+ export declare class AuthClient<Auth extends AuthType> extends BaseModule implements AuthInterface {
9
+ readonly basePath: string;
10
+ constructor(client: BaseClientInterface, basePath: string);
11
+ /**
12
+ * Authenticates a user with the provided credentials.
13
+ *
14
+ * @param {Object} request - The login payload (e.g., email and password).
15
+ * @param {RequestOptions} options - Additional request options.
16
+ * @returns An authentication response containing tokens and session info.
17
+ */
18
+ login(request: Auth['loginRequest'], options?: RequestOptions): Promise<Auth['authenticationResponse']>;
19
+ /**
20
+ * Logs out the currently authenticated user and invalidates the session.
21
+ *
22
+ * @param {RequestOptions} options - Additional request options.
23
+ * @returns The logout response from the server.
24
+ */
25
+ logout(options?: RequestOptions): Promise<Auth['logoutResponse']>;
26
+ /**
27
+ * Refreshes the current authentication session and issues new tokens.
28
+ *
29
+ * @param {RequestOptions} options - Additional request options.
30
+ * @returns A fresh authentication response with updated tokens.
31
+ */
32
+ refresh(options?: RequestOptions): Promise<Auth['authenticationResponse']>;
33
+ /**
34
+ * Changes the authenticated user's password.
35
+ *
36
+ * @param {Object} request - The change-password payload (e.g., current and new password).
37
+ * @param {RequestOptions} options - Additional request options.
38
+ * @returns An updated authentication response after the password change.
39
+ */
40
+ changePassword(request: Auth['changePasswordRequest'], options?: RequestOptions): Promise<Auth['authenticationResponse']>;
41
+ /**
42
+ * Exchanges a third-party or external token for an application authentication token.
43
+ *
44
+ * @param {Object} request - The token exchange payload (e.g., an OAuth code or external token).
45
+ * @param {RequestOptions} options - Additional request options.
46
+ * @returns An authentication response containing the issued application tokens.
47
+ */
48
+ exchangeToken(request: Auth['exchangeTokenRequest'], options?: RequestOptions): Promise<Auth['authenticationResponse']>;
49
+ /**
50
+ * Retrieves the identity of the currently authenticated user.
51
+ *
52
+ * @param {RequestOptions} options - Additional request options.
53
+ * @returns The identity object for the authenticated user.
54
+ */
55
+ me(options?: RequestOptions): Promise<Auth['identity']>;
56
+ }
@@ -0,0 +1,74 @@
1
+ import { BaseModule } from './base-module.js';
2
+ export class AuthClient extends BaseModule {
3
+ basePath;
4
+ constructor(client, basePath) {
5
+ super(client);
6
+ this.basePath = basePath;
7
+ }
8
+ /**
9
+ * Authenticates a user with the provided credentials.
10
+ *
11
+ * @param {Object} request - The login payload (e.g., email and password).
12
+ * @param {RequestOptions} options - Additional request options.
13
+ * @returns An authentication response containing tokens and session info.
14
+ */
15
+ async login(request, options = {}) {
16
+ return this.sendRequest('post', `${this.basePath}/login`, {
17
+ ...options,
18
+ body: request
19
+ });
20
+ }
21
+ /**
22
+ * Logs out the currently authenticated user and invalidates the session.
23
+ *
24
+ * @param {RequestOptions} options - Additional request options.
25
+ * @returns The logout response from the server.
26
+ */
27
+ async logout(options = {}) {
28
+ return this.sendRequest('post', `${this.basePath}/logout`, options);
29
+ }
30
+ /**
31
+ * Refreshes the current authentication session and issues new tokens.
32
+ *
33
+ * @param {RequestOptions} options - Additional request options.
34
+ * @returns A fresh authentication response with updated tokens.
35
+ */
36
+ async refresh(options = {}) {
37
+ return this.sendRequest('post', `${this.basePath}/refresh`, options);
38
+ }
39
+ /**
40
+ * Changes the authenticated user's password.
41
+ *
42
+ * @param {Object} request - The change-password payload (e.g., current and new password).
43
+ * @param {RequestOptions} options - Additional request options.
44
+ * @returns An updated authentication response after the password change.
45
+ */
46
+ async changePassword(request, options = {}) {
47
+ return this.sendRequest('post', `${this.basePath}/change-password`, {
48
+ ...options,
49
+ body: request
50
+ });
51
+ }
52
+ /**
53
+ * Exchanges a third-party or external token for an application authentication token.
54
+ *
55
+ * @param {Object} request - The token exchange payload (e.g., an OAuth code or external token).
56
+ * @param {RequestOptions} options - Additional request options.
57
+ * @returns An authentication response containing the issued application tokens.
58
+ */
59
+ async exchangeToken(request, options = {}) {
60
+ return this.sendRequest('post', `${this.basePath}/exchange-token`, {
61
+ ...options,
62
+ body: request
63
+ });
64
+ }
65
+ /**
66
+ * Retrieves the identity of the currently authenticated user.
67
+ *
68
+ * @param {RequestOptions} options - Additional request options.
69
+ * @returns The identity object for the authenticated user.
70
+ */
71
+ async me(options = {}) {
72
+ return this.sendRequest('get', `${this.basePath}/me`, options);
73
+ }
74
+ }
@@ -0,0 +1,17 @@
1
+ import { FetchOptions } from 'openapi-fetch';
2
+ import { HttpMethod } from 'openapi-typescript-helpers';
3
+ import { BaseClientInterface, InitParam } from '../base-client-interface.js';
4
+ import { FileDataResponse } from '../responses/index.js';
5
+ export type RequestOptions<T = any> = FetchOptions<T>;
6
+ export declare abstract class BaseModule {
7
+ private readonly _client;
8
+ protected constructor(_client: BaseClientInterface);
9
+ protected sendRequest<Resp = any>(method: HttpMethod, path: string, ...params: InitParam<any>): Promise<Resp>;
10
+ protected sendRequestRaw<Resp = any>(method: HttpMethod, path: string, ...params: InitParam<any>): Promise<{
11
+ data: Resp;
12
+ error: any;
13
+ response: Response;
14
+ }>;
15
+ protected toFileResponse(response: Response, defaultName?: string): FileDataResponse;
16
+ protected handleError(error: any, response: Response): void;
17
+ }
@@ -0,0 +1,49 @@
1
+ import { FileDataResponse } from '../responses/index.js';
2
+ import { ClientError } from '../../errors/index.js';
3
+ export class BaseModule {
4
+ _client;
5
+ constructor(_client) {
6
+ this._client = _client;
7
+ }
8
+ async sendRequest(method, path, ...params) {
9
+ return this._client.sendRequestPromise(method, path, ...params);
10
+ }
11
+ async sendRequestRaw(method, path, ...params) {
12
+ return (await this._client.sendRequestRawPromise(method, path, ...params));
13
+ }
14
+ toFileResponse(response, defaultName = 'unknown') {
15
+ const fileName = response.headers
16
+ .get('Content-Disposition')
17
+ ?.split('filename=')[1]
18
+ ?.replace(/"/g, '') ?? defaultName;
19
+ const length = response.headers.get('Content-Length') ?? '0';
20
+ const maxAge = response.headers
21
+ .get('Cache-Control')
22
+ ?.split('max-age=')[1]
23
+ ?.replace(/"/g, '');
24
+ const matchRangeParts = response.headers
25
+ .get('Content-Range')
26
+ ?.match(/^bytes (\d+)-(\d+)\/(\d+)$/);
27
+ let range = undefined;
28
+ if (matchRangeParts) {
29
+ const [, start, end, total] = matchRangeParts;
30
+ range = {
31
+ start: parseInt(start, 10),
32
+ end: parseInt(end, 10),
33
+ total: parseInt(total, 10)
34
+ };
35
+ }
36
+ return new FileDataResponse({
37
+ fileName,
38
+ stream: response.body,
39
+ type: response.headers.get('Content-Type') ?? '',
40
+ length: parseInt(length, 10),
41
+ range,
42
+ maxAge: maxAge ? parseInt(maxAge, 10) : undefined,
43
+ expiresAt: response.headers.get('Expires') ?? undefined
44
+ });
45
+ }
46
+ handleError(error, response) {
47
+ throw new ClientError(error.message ?? response.statusText ?? 'Unknown error', error.errorCode ?? response.status, response, error);
48
+ }
49
+ }
@@ -0,0 +1,27 @@
1
+ import { BaseModule, RequestOptions } from './base-module.js';
2
+ import { BaseClientInterface } from '../base-client-interface.js';
3
+ import { FileDataResponse } from '../responses/index.js';
4
+ import { FILE_OPERATIONS } from '../../constants.js';
5
+ export type FilesInterface = {
6
+ [K in keyof typeof FILE_OPERATIONS]: (...args: any[]) => Promise<any>;
7
+ };
8
+ export declare class FilesClient extends BaseModule implements FilesInterface {
9
+ readonly basePath: string;
10
+ constructor(client: BaseClientInterface, basePath: string);
11
+ /**
12
+ * Downloads a publicly accessible file by its path/name.
13
+ *
14
+ * @param {string} fileName - The path or name of the file to retrieve from the public storage.
15
+ * @param {RequestOptions} options - Additional request options.
16
+ * @returns {@link FileDataResponse} containing the readable stream and file metadata.
17
+ */
18
+ public(fileName: string, options?: RequestOptions): Promise<FileDataResponse>;
19
+ /**
20
+ * Downloads a protected file by its path/name. Requires the request to be authenticated.
21
+ *
22
+ * @param {string} fileName - The path or name of the file to retrieve from the protected storage.
23
+ * @param {RequestOptions} options - Additional request options.
24
+ * @returns {@link FileDataResponse} containing the readable stream and file metadata.
25
+ */
26
+ protected(fileName: string, options?: RequestOptions): Promise<FileDataResponse>;
27
+ }