@appweaver/client 1.0.23 → 1.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/package.json +3 -0
- package/{weaver-client.js → cjs/weaver-client.js} +1 -1
- package/esm/angular/index.d.ts +1 -0
- package/esm/angular/index.js +1 -0
- package/esm/clients/angular-client.d.ts +26 -0
- package/esm/clients/angular-client.js +53 -0
- package/esm/clients/base-client-interface.d.ts +86 -0
- package/esm/clients/base-client-interface.js +1 -0
- package/esm/clients/base-client.d.ts +216 -0
- package/esm/clients/base-client.js +242 -0
- package/esm/clients/fetch-client.d.ts +6 -0
- package/esm/clients/fetch-client.js +6 -0
- package/esm/clients/index.d.ts +4 -0
- package/esm/clients/index.js +4 -0
- package/esm/clients/modules/account-client.d.ts +69 -0
- package/esm/clients/modules/account-client.js +107 -0
- package/esm/clients/modules/auth-client.d.ts +56 -0
- package/esm/clients/modules/auth-client.js +74 -0
- package/esm/clients/modules/base-module.d.ts +17 -0
- package/esm/clients/modules/base-module.js +49 -0
- package/esm/clients/modules/files-client.d.ts +27 -0
- package/esm/clients/modules/files-client.js +42 -0
- package/esm/clients/modules/health-client.d.ts +25 -0
- package/esm/clients/modules/health-client.js +30 -0
- package/esm/clients/modules/index.d.ts +6 -0
- package/esm/clients/modules/index.js +6 -0
- package/esm/clients/modules/resource-client.d.ts +90 -0
- package/esm/clients/modules/resource-client.js +173 -0
- package/esm/clients/responses/file-data-response.d.ts +78 -0
- package/esm/clients/responses/file-data-response.js +105 -0
- package/esm/clients/responses/index.d.ts +1 -0
- package/esm/clients/responses/index.js +1 -0
- package/esm/commands/generate-command.d.ts +3 -0
- package/esm/commands/generate-command.js +122 -0
- package/esm/commands/index.d.ts +1 -0
- package/esm/commands/index.js +1 -0
- package/esm/constants.d.ts +67 -0
- package/esm/constants.js +94 -0
- package/esm/errors/client-error.d.ts +6 -0
- package/esm/errors/client-error.js +11 -0
- package/esm/errors/index.d.ts +1 -0
- package/esm/errors/index.js +1 -0
- package/esm/generators/generate-client.d.ts +16 -0
- package/esm/generators/generate-client.js +399 -0
- package/esm/generators/generate-types.d.ts +9 -0
- package/esm/generators/generate-types.js +486 -0
- package/esm/generators/index.d.ts +2 -0
- package/esm/generators/index.js +2 -0
- package/esm/index.d.ts +2 -0
- package/esm/index.js +2 -0
- package/esm/package.json +3 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/routes.d.ts +15 -0
- package/esm/types/routes.js +1 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/schema-util.d.ts +3 -0
- package/esm/utils/schema-util.js +39 -0
- package/package.json +29 -5
- /package/{angular → cjs/angular}/index.d.ts +0 -0
- /package/{angular → cjs/angular}/index.js +0 -0
- /package/{clients → cjs/clients}/angular-client.d.ts +0 -0
- /package/{clients → cjs/clients}/angular-client.js +0 -0
- /package/{clients → cjs/clients}/base-client-interface.d.ts +0 -0
- /package/{clients → cjs/clients}/base-client-interface.js +0 -0
- /package/{clients → cjs/clients}/base-client.d.ts +0 -0
- /package/{clients → cjs/clients}/base-client.js +0 -0
- /package/{clients → cjs/clients}/fetch-client.d.ts +0 -0
- /package/{clients → cjs/clients}/fetch-client.js +0 -0
- /package/{clients → cjs/clients}/index.d.ts +0 -0
- /package/{clients → cjs/clients}/index.js +0 -0
- /package/{clients → cjs/clients}/modules/account-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/account-client.js +0 -0
- /package/{clients → cjs/clients}/modules/auth-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/auth-client.js +0 -0
- /package/{clients → cjs/clients}/modules/base-module.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/base-module.js +0 -0
- /package/{clients → cjs/clients}/modules/files-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/files-client.js +0 -0
- /package/{clients → cjs/clients}/modules/health-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/health-client.js +0 -0
- /package/{clients → cjs/clients}/modules/index.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/index.js +0 -0
- /package/{clients → cjs/clients}/modules/resource-client.d.ts +0 -0
- /package/{clients → cjs/clients}/modules/resource-client.js +0 -0
- /package/{clients → cjs/clients}/responses/file-data-response.d.ts +0 -0
- /package/{clients → cjs/clients}/responses/file-data-response.js +0 -0
- /package/{clients → cjs/clients}/responses/index.d.ts +0 -0
- /package/{clients → cjs/clients}/responses/index.js +0 -0
- /package/{commands → cjs/commands}/generate-command.d.ts +0 -0
- /package/{commands → cjs/commands}/generate-command.js +0 -0
- /package/{commands → cjs/commands}/index.d.ts +0 -0
- /package/{commands → cjs/commands}/index.js +0 -0
- /package/{constants.d.ts → cjs/constants.d.ts} +0 -0
- /package/{constants.js → cjs/constants.js} +0 -0
- /package/{errors → cjs/errors}/client-error.d.ts +0 -0
- /package/{errors → cjs/errors}/client-error.js +0 -0
- /package/{errors → cjs/errors}/index.d.ts +0 -0
- /package/{errors → cjs/errors}/index.js +0 -0
- /package/{generators → cjs/generators}/generate-client.d.ts +0 -0
- /package/{generators → cjs/generators}/generate-client.js +0 -0
- /package/{generators → cjs/generators}/generate-types.d.ts +0 -0
- /package/{generators → cjs/generators}/generate-types.js +0 -0
- /package/{generators → cjs/generators}/index.d.ts +0 -0
- /package/{generators → cjs/generators}/index.js +0 -0
- /package/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/{index.js → cjs/index.js} +0 -0
- /package/{types → cjs/types}/index.d.ts +0 -0
- /package/{types → cjs/types}/index.js +0 -0
- /package/{types → cjs/types}/routes.d.ts +0 -0
- /package/{types → cjs/types}/routes.js +0 -0
- /package/{utils → cjs/utils}/index.d.ts +0 -0
- /package/{utils → cjs/utils}/index.js +0 -0
- /package/{utils → cjs/utils}/schema-util.d.ts +0 -0
- /package/{utils → cjs/utils}/schema-util.js +0 -0
- /package/{weaver-client.d.ts → cjs/weaver-client.d.ts} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseModule } from './base-module.js';
|
|
2
|
+
export class FilesClient extends BaseModule {
|
|
3
|
+
basePath;
|
|
4
|
+
constructor(client, basePath) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.basePath = basePath;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Downloads a publicly accessible file by its path/name.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} fileName - The path or name of the file to retrieve from the public storage.
|
|
12
|
+
* @param {RequestOptions} options - Additional request options.
|
|
13
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
14
|
+
*/
|
|
15
|
+
async public(fileName, options = {}) {
|
|
16
|
+
const { error, response } = await this.sendRequestRaw('get', `${this.basePath}/public/${fileName}`, {
|
|
17
|
+
...options,
|
|
18
|
+
parseAs: 'stream'
|
|
19
|
+
});
|
|
20
|
+
if (error) {
|
|
21
|
+
this.handleError(error, response);
|
|
22
|
+
}
|
|
23
|
+
return this.toFileResponse(response, fileName);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Downloads a protected file by its path/name. Requires the request to be authenticated.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} fileName - The path or name of the file to retrieve from the protected storage.
|
|
29
|
+
* @param {RequestOptions} options - Additional request options.
|
|
30
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
31
|
+
*/
|
|
32
|
+
async protected(fileName, options = {}) {
|
|
33
|
+
const { error, response } = await this.sendRequestRaw('get', `${this.basePath}/protected/${fileName}`, {
|
|
34
|
+
...options,
|
|
35
|
+
parseAs: 'stream'
|
|
36
|
+
});
|
|
37
|
+
if (error) {
|
|
38
|
+
this.handleError(error, response);
|
|
39
|
+
}
|
|
40
|
+
return this.toFileResponse(response, fileName);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseModule, RequestOptions } from './base-module.js';
|
|
2
|
+
import { BaseClientInterface } from '../base-client-interface.js';
|
|
3
|
+
import { HEALTH_OPERATIONS, HEALTH_TYPES } from '../../constants.js';
|
|
4
|
+
export type HealthType = Record<(typeof HEALTH_TYPES)[number], unknown>;
|
|
5
|
+
export type HealthInterface = {
|
|
6
|
+
[K in keyof typeof HEALTH_OPERATIONS]: (...args: any[]) => Promise<any>;
|
|
7
|
+
};
|
|
8
|
+
export declare class HealthClient<Health extends HealthType> extends BaseModule implements HealthInterface {
|
|
9
|
+
readonly basePath: string;
|
|
10
|
+
constructor(client: BaseClientInterface, basePath: string);
|
|
11
|
+
/**
|
|
12
|
+
* Performs a basic health check against the server.
|
|
13
|
+
*
|
|
14
|
+
* @param {RequestOptions} options - Additional request options.
|
|
15
|
+
* @returns The health check response indicating overall server and it's services status.
|
|
16
|
+
*/
|
|
17
|
+
check(options?: RequestOptions): Promise<Health['checkResponse']>;
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether the server is ready to accept traffic (e.g., database connected, migrations applied).
|
|
20
|
+
*
|
|
21
|
+
* @param {RequestOptions} options - Additional request options.
|
|
22
|
+
* @returns The readiness response indicating whether the server is fully operational.
|
|
23
|
+
*/
|
|
24
|
+
ready(options?: RequestOptions): Promise<Health['readyResponse']>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseModule } from './base-module.js';
|
|
2
|
+
export class HealthClient extends BaseModule {
|
|
3
|
+
basePath;
|
|
4
|
+
constructor(client, basePath) {
|
|
5
|
+
super(client);
|
|
6
|
+
this.basePath = basePath;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Performs a basic health check against the server.
|
|
10
|
+
*
|
|
11
|
+
* @param {RequestOptions} options - Additional request options.
|
|
12
|
+
* @returns The health check response indicating overall server and it's services status.
|
|
13
|
+
*/
|
|
14
|
+
async check(options = {}) {
|
|
15
|
+
const { data, error, response } = await this.sendRequestRaw('get', `${this.basePath}/check`, options);
|
|
16
|
+
if (error && response.status !== 503) {
|
|
17
|
+
this.handleError(error, response);
|
|
18
|
+
}
|
|
19
|
+
return data ?? error;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Checks whether the server is ready to accept traffic (e.g., database connected, migrations applied).
|
|
23
|
+
*
|
|
24
|
+
* @param {RequestOptions} options - Additional request options.
|
|
25
|
+
* @returns The readiness response indicating whether the server is fully operational.
|
|
26
|
+
*/
|
|
27
|
+
async ready(options = {}) {
|
|
28
|
+
return this.sendRequest('get', `${this.basePath}/ready`, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
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 { RESOURCE_OPERATIONS, RESOURCE_TYPES } from '../../constants.js';
|
|
5
|
+
export type ResourceType = Record<(typeof RESOURCE_TYPES)[number], unknown>;
|
|
6
|
+
export type ResourceInterface = {
|
|
7
|
+
[K in keyof typeof RESOURCE_OPERATIONS]: (...args: any[]) => Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
export declare class ResourceClient<Resource extends ResourceType> extends BaseModule implements ResourceInterface {
|
|
10
|
+
readonly basePath: string;
|
|
11
|
+
constructor(client: BaseClientInterface, basePath: string);
|
|
12
|
+
/**
|
|
13
|
+
* Fetches a single resource by its numeric ID.
|
|
14
|
+
*
|
|
15
|
+
* @param {number} id - The ID of the resource to retrieve.
|
|
16
|
+
* @param {RequestOptions} options - Additional request options (headers, query params, etc.).
|
|
17
|
+
* @returns The resource record matching the given ID.
|
|
18
|
+
*/
|
|
19
|
+
find(id: number, options?: RequestOptions): Promise<Resource['single']>;
|
|
20
|
+
/**
|
|
21
|
+
* Executes a query against the resource collection.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} request - The query payload (filters, sorting, pagination, etc.).
|
|
24
|
+
* @param {RequestOptions} options - Additional request options.
|
|
25
|
+
* @returns A paginated or filtered list of matching resource records.
|
|
26
|
+
*/
|
|
27
|
+
query(request: Resource['queryRequest'], options?: RequestOptions): Promise<Resource['queryResponse']>;
|
|
28
|
+
/**
|
|
29
|
+
* Runs an aggregation query (e.g., count, sum, avg) against the resource collection.
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} request - The aggregation payload describing the desired computation.
|
|
32
|
+
* @param {RequestOptions} options - Additional request options.
|
|
33
|
+
* @returns The aggregated result for the given query.
|
|
34
|
+
*/
|
|
35
|
+
aggregate(request: Resource['aggregateRequest'], options?: RequestOptions): Promise<Resource['aggregateResponse']>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new resource record.
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} resource - The data for the resource to create.
|
|
40
|
+
* @param {RequestOptions} options - Additional request options.
|
|
41
|
+
* @returns The newly created resource record.
|
|
42
|
+
*/
|
|
43
|
+
create(resource: Resource['create'], options?: RequestOptions): Promise<Resource['single']>;
|
|
44
|
+
/**
|
|
45
|
+
* Updates an existing resource record identified by `id`.
|
|
46
|
+
*
|
|
47
|
+
* @param {Object} resource - The updated field values including the mandatory `id`.
|
|
48
|
+
* @param {RequestOptions} options - Additional request options.
|
|
49
|
+
* @returns The updated resource record.
|
|
50
|
+
*/
|
|
51
|
+
update(resource: Resource['update'] & {
|
|
52
|
+
id: number;
|
|
53
|
+
}, options?: RequestOptions): Promise<Resource['single']>;
|
|
54
|
+
/**
|
|
55
|
+
* Deletes a resource record by its numeric ID.
|
|
56
|
+
*
|
|
57
|
+
* @param {number} id - The ID of the resource to delete.
|
|
58
|
+
* @param {RequestOptions} options - Additional request options.
|
|
59
|
+
* @returns The deleted resource record.
|
|
60
|
+
*/
|
|
61
|
+
delete(id: number, options?: RequestOptions): Promise<Resource['single']>;
|
|
62
|
+
/**
|
|
63
|
+
* Exports resource records as a file (e.g., CSV) and returns a streaming response.
|
|
64
|
+
*
|
|
65
|
+
* @param {Object} request - The export request payload (filters, format, etc.).
|
|
66
|
+
* @param {RequestOptions} options - Additional request options.
|
|
67
|
+
* @returns {@link FileDataResponse} containing the readable stream and file metadata.
|
|
68
|
+
*/
|
|
69
|
+
export(request: Resource['exportRequest'], options?: RequestOptions): Promise<FileDataResponse>;
|
|
70
|
+
/**
|
|
71
|
+
* Uploads one or more files to the resource record.
|
|
72
|
+
*
|
|
73
|
+
* Each entry in `files` maps a field name to a single `File` or an array of `File` objects.
|
|
74
|
+
*
|
|
75
|
+
* @param {number} id - The ID of the resource for which to upload files.
|
|
76
|
+
* @param {Object} files - A map of field names to the file(s) to upload.
|
|
77
|
+
* @param {RequestOptions} options - Additional request options.
|
|
78
|
+
* @returns The updated file metadata for the resource.
|
|
79
|
+
*/
|
|
80
|
+
uploadFiles(id: number, files: Resource['fileUpload'], options?: RequestOptions): Promise<Resource['files']>;
|
|
81
|
+
/**
|
|
82
|
+
* Removes specific files from the resource record.
|
|
83
|
+
*
|
|
84
|
+
* @param {number} id - The ID of the resource for which to delete files.
|
|
85
|
+
* @param {Object} files - The file deletion payload identifying which files to remove.
|
|
86
|
+
* @param {RequestOptions} options - Additional request options.
|
|
87
|
+
* @returns The updated file metadata for the resource after deletion.
|
|
88
|
+
*/
|
|
89
|
+
deleteFiles(id: number, files: Resource['fileDelete'], options?: RequestOptions): Promise<Resource['files']>;
|
|
90
|
+
}
|