@turinhub/tale-js-sdk 1.3.0

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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -0
  3. package/dist/acl/index.d.ts +295 -0
  4. package/dist/acl/index.js +653 -0
  5. package/dist/acl/types.d.ts +142 -0
  6. package/dist/acl/types.js +1 -0
  7. package/dist/auth/index.d.ts +166 -0
  8. package/dist/auth/index.js +522 -0
  9. package/dist/auth/types.d.ts +127 -0
  10. package/dist/auth/types.js +1 -0
  11. package/dist/cms/file.d.ts +398 -0
  12. package/dist/cms/file.js +800 -0
  13. package/dist/cms/folder.d.ts +128 -0
  14. package/dist/cms/folder.js +294 -0
  15. package/dist/cms/index.d.ts +3 -0
  16. package/dist/cms/index.js +6 -0
  17. package/dist/cms/types.d.ts +157 -0
  18. package/dist/cms/types.js +1 -0
  19. package/dist/common/types.d.ts +91 -0
  20. package/dist/common/types.js +2 -0
  21. package/dist/errors.d.ts +52 -0
  22. package/dist/errors.js +109 -0
  23. package/dist/index.d.ts +13 -0
  24. package/dist/index.js +12 -0
  25. package/dist/rbac/acl.d.ts +152 -0
  26. package/dist/rbac/acl.js +723 -0
  27. package/dist/rbac/index.d.ts +464 -0
  28. package/dist/rbac/index.js +1121 -0
  29. package/dist/rbac/rbac.d.ts +198 -0
  30. package/dist/rbac/rbac.js +984 -0
  31. package/dist/rbac/types.d.ts +125 -0
  32. package/dist/rbac/types.js +1 -0
  33. package/dist/rbac/user-group.d.ts +122 -0
  34. package/dist/rbac/user-group.js +570 -0
  35. package/dist/status.d.ts +40 -0
  36. package/dist/status.js +56 -0
  37. package/dist/task/index.d.ts +163 -0
  38. package/dist/task/index.js +495 -0
  39. package/dist/task/types.d.ts +116 -0
  40. package/dist/task/types.js +1 -0
  41. package/dist/task-type/index.d.ts +92 -0
  42. package/dist/task-type/index.js +256 -0
  43. package/dist/task-type/types.d.ts +54 -0
  44. package/dist/task-type/types.js +1 -0
  45. package/dist/token.d.ts +21 -0
  46. package/dist/token.js +114 -0
  47. package/dist/user/index.d.ts +267 -0
  48. package/dist/user/index.js +786 -0
  49. package/dist/user/types.d.ts +145 -0
  50. package/dist/user/types.js +1 -0
  51. package/dist/user-attribute/index.d.ts +186 -0
  52. package/dist/user-attribute/index.js +615 -0
  53. package/dist/user-attribute/types.d.ts +109 -0
  54. package/dist/user-attribute/types.js +1 -0
  55. package/dist/user-group/index.d.ts +231 -0
  56. package/dist/user-group/index.js +566 -0
  57. package/dist/user-group/types.d.ts +50 -0
  58. package/dist/user-group/types.js +1 -0
  59. package/package.json +50 -0
@@ -0,0 +1,142 @@
1
+ import type { CommonOptions } from "../common/types.js";
2
+ /**
3
+ * ACL Record (Access Control List Record)
4
+ * Represents a single access control rule
5
+ */
6
+ export interface AclRecord {
7
+ record_id: string;
8
+ app_id: string;
9
+ template_id?: string;
10
+ subject_type: string;
11
+ subject_id?: string;
12
+ subject_identifier?: string;
13
+ resource_type: string;
14
+ resource_id?: string;
15
+ resource_identifier?: string;
16
+ effect_type: string;
17
+ priority?: number;
18
+ data_scope?: Record<string, unknown>;
19
+ description?: string;
20
+ created_at: string;
21
+ updated_at: string;
22
+ }
23
+ /**
24
+ * Request for creating an ACL record
25
+ */
26
+ export interface CreateAclRecordRequest {
27
+ template_id?: string;
28
+ subject_type: string;
29
+ subject_id?: string;
30
+ subject_identifier?: string;
31
+ resource_type: string;
32
+ resource_id?: string;
33
+ resource_identifier?: string;
34
+ effect_type: string;
35
+ priority?: number;
36
+ data_scope?: Record<string, unknown>;
37
+ description?: string;
38
+ }
39
+ /**
40
+ * Request for updating an ACL record
41
+ */
42
+ export interface UpdateAclRecordRequest {
43
+ template_id?: string;
44
+ effect_type?: string;
45
+ priority?: number;
46
+ data_scope?: Record<string, unknown>;
47
+ description?: string;
48
+ }
49
+ /**
50
+ * Request for listing ACL records
51
+ */
52
+ export interface ListAclRecordsRequest {
53
+ page?: number;
54
+ size?: number;
55
+ sort?: string;
56
+ template_id?: string;
57
+ subject_type?: string;
58
+ subject_id?: string;
59
+ subject_identifier?: string;
60
+ resource_type?: string;
61
+ resource_id?: string;
62
+ resource_identifier?: string;
63
+ }
64
+ /**
65
+ * Batch creation response for ACL records
66
+ */
67
+ export interface AclBatchCreateResponse {
68
+ success_count: number;
69
+ failure_count: number;
70
+ success_records: AclRecord[];
71
+ failures: AclBatchFailure[];
72
+ }
73
+ /**
74
+ * Failure details for batch creation
75
+ */
76
+ export interface AclBatchFailure {
77
+ index: number;
78
+ request: CreateAclRecordRequest;
79
+ error_message: string;
80
+ }
81
+ /**
82
+ * ACL Template
83
+ * Represents a reusable ACL configuration template
84
+ */
85
+ export interface AclTemplate {
86
+ template_id: string;
87
+ app_id: string;
88
+ template_name: string;
89
+ template_code: string;
90
+ subject_type?: string;
91
+ subject_filter?: Record<string, unknown>;
92
+ resource_type?: string;
93
+ resource_filter?: Record<string, unknown>;
94
+ effect_type?: string;
95
+ priority?: number;
96
+ data_scope?: Record<string, unknown>;
97
+ description?: string;
98
+ created_at: string;
99
+ updated_at: string;
100
+ }
101
+ /**
102
+ * Request for creating an ACL template
103
+ */
104
+ export interface CreateAclTemplateRequest {
105
+ template_name: string;
106
+ template_code: string;
107
+ subject_type?: string;
108
+ subject_filter?: Record<string, unknown>;
109
+ resource_type?: string;
110
+ resource_filter?: Record<string, unknown>;
111
+ effect_type?: string;
112
+ priority?: number;
113
+ data_scope?: Record<string, unknown>;
114
+ description?: string;
115
+ }
116
+ /**
117
+ * Request for updating an ACL template
118
+ */
119
+ export interface UpdateAclTemplateRequest {
120
+ template_name?: string;
121
+ subject_filter?: Record<string, unknown>;
122
+ resource_filter?: Record<string, unknown>;
123
+ effect_type?: string;
124
+ priority?: number;
125
+ data_scope?: Record<string, unknown>;
126
+ description?: string;
127
+ }
128
+ /**
129
+ * Request for listing ACL templates
130
+ */
131
+ export interface ListAclTemplatesRequest {
132
+ page?: number;
133
+ size?: number;
134
+ sort?: string;
135
+ resource_type?: string;
136
+ subject_type?: string;
137
+ }
138
+ /**
139
+ * Options for ACL operations
140
+ */
141
+ export interface AclOptions extends CommonOptions {
142
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,166 @@
1
+ import type { LoginRequest, LoginOptions, LoginWithSmsOptions, VerifySmsOptions, AppInfo, AuthUser, UserToken, AuthRole, AuthPrivilege, UserGroup, AuthUserLoginMethod, LoginResponse, LoginJson, SendSmsResponse, SendSmsJson, VerifySmsRequest, SmsLoginResponse, SmsLoginJson } from "./types.js";
2
+ export type { LoginRequest, LoginOptions, LoginWithSmsOptions, VerifySmsOptions, AppInfo, AuthUser, UserToken, AuthRole, AuthPrivilege, UserGroup, AuthUserLoginMethod, LoginResponse, LoginJson, SendSmsResponse, SendSmsJson, VerifySmsRequest, SmsLoginResponse, SmsLoginJson, };
3
+ /**
4
+ * Authenticates a user with username and password.
5
+ *
6
+ * @param credentials - User login credentials
7
+ * @param options - Optional configuration for the login request
8
+ * @returns Promise resolving to login response with user info and token
9
+ * @throws {ConfigurationError} When required environment variables (TALE_BASE_URL, TALE_APP_KEY) are missing
10
+ * @throws {ApiError} When authentication fails or returns invalid response
11
+ * @throws {NetworkError} When network request fails
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { login } from '@tale/client';
16
+ *
17
+ * try {
18
+ * const result = await login({
19
+ * username: 'johndoe',
20
+ * password: 'secure_password_123'
21
+ * });
22
+ * console.log('Login successful:', result.user.username);
23
+ * console.log('User token:', result.token.token);
24
+ * } catch (error) {
25
+ * console.error('Login failed:', error.message);
26
+ * }
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * import { login } from '@tale/client';
32
+ *
33
+ * // Login with include parameters to control what data is returned
34
+ * const result = await login({
35
+ * username: 'johndoe',
36
+ * password: 'secure_password_123'
37
+ * }, {
38
+ * include_rbac: true, // Include roles and privileges (SDK default: false)
39
+ * include_user_groups: true, // Include user groups (SDK default: false)
40
+ * include_login_methods: true, // Include login methods (SDK default: false)
41
+ * include_attributes: true, // Include user attributes (SDK default: false)
42
+ * include_acl: true // Include ACL records (SDK default: false)
43
+ * });
44
+ * ```
45
+ *
46
+ * @note The function requires the following environment variables:
47
+ * - TALE_BASE_URL: Base URL for Tale backend services
48
+ * - TALE_APP_KEY: Application key for authentication
49
+ * @note By default, all include parameters are set to false for better performance.
50
+ * Explicitly set them to true if you need the additional data.
51
+ *
52
+ * @param options.include_rbac Include roles and privileges; default false
53
+ * @param options.include_login_methods Include user login methods; default false
54
+ * @param options.include_user_groups Include user groups; default false
55
+ * @param options.include_attributes Include user attributes; default false
56
+ * @param options.include_acl Include ACL records; default false
57
+ */
58
+ export declare function login(credentials: LoginRequest, options?: LoginOptions): Promise<LoginResponse>;
59
+ /**
60
+ * Validates a user token.
61
+ *
62
+ * @param token - User token to validate
63
+ * @param options - Optional configuration for validation
64
+ * @returns Promise resolving to validation result
65
+ * @throws {ConfigurationError} When required environment variables are missing
66
+ * @throws {ApiError} When validation fails
67
+ * @throws {NetworkError} When network request fails
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { validateToken } from '@tale/client';
72
+ *
73
+ * try {
74
+ * const result = await validateToken('tu_user_token_here');
75
+ * console.log('Token is valid');
76
+ * } catch (error) {
77
+ * console.error('Token validation failed:', error.message);
78
+ * }
79
+ * ```
80
+ */
81
+ export declare function validateToken(token: string, options?: {
82
+ scope?: string;
83
+ baseUrl?: string;
84
+ }): Promise<boolean>;
85
+ /**
86
+ * Initiates SMS login by sending verification code for login or registration.
87
+ *
88
+ * @param phone - Phone number for sending SMS
89
+ * @param options - Optional configuration for the request
90
+ * @returns Promise resolving to SMS sending response
91
+ * @throws {ConfigurationError} When required environment variables are missing
92
+ * @throws {ApiError} When SMS sending fails or returns invalid response
93
+ * @throws {NetworkError} When network request fails
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { loginWithSms } from '@tale/client';
98
+ *
99
+ * try {
100
+ * const result = await loginWithSms('+8613800138000');
101
+ * console.log('SMS sent:', result.sms_id);
102
+ * console.log('Type:', result.type); // 'login' or 'register'
103
+ * } catch (error) {
104
+ * console.error('SMS sending failed:', error.message);
105
+ * }
106
+ * ```
107
+ */
108
+ export declare function loginWithSms(phone: string, options?: LoginWithSmsOptions): Promise<SendSmsResponse>;
109
+ /**
110
+ * Verifies SMS code and authenticates user (login or register).
111
+ *
112
+ * @param request - SMS verification request with sms_id, code, and optional user data
113
+ * @param options - Optional configuration for the request
114
+ * @returns Promise resolving to login response with user info and token
115
+ * @throws {ConfigurationError} When required environment variables are missing
116
+ * @throws {ApiError} When verification fails or returns invalid response
117
+ * @throws {NetworkError} When network request fails
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * import { verifySmsCode } from '@tale/client';
122
+ *
123
+ * try {
124
+ * const result = await verifySmsCode({
125
+ * sms_id: 'uuid-here',
126
+ * sms_type: 'login',
127
+ * verification_code: '123456'
128
+ * });
129
+ * console.log('Login successful:', result.user.user_id);
130
+ * console.log('User token:', result.token.token);
131
+ * } catch (error) {
132
+ * console.error('SMS verification failed:', error.message);
133
+ * }
134
+ * ```
135
+ */
136
+ export declare function verifySmsCode(request: VerifySmsRequest, options?: VerifySmsOptions): Promise<SmsLoginResponse>;
137
+ /**
138
+ * Registers a new user with SMS verification and optional additional information.
139
+ *
140
+ * @param request - Registration request with SMS verification and optional user data
141
+ * @param options - Optional configuration for the request
142
+ * @returns Promise resolving to registration response with user info and token
143
+ * @throws {ConfigurationError} When required environment variables are missing
144
+ * @throws {ApiError} When registration fails or returns invalid response
145
+ * @throws {NetworkError} When network request fails
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * import { registerWithSms } from '@tale/client';
150
+ *
151
+ * try {
152
+ * const result = await registerWithSms({
153
+ * sms_id: 'uuid-here',
154
+ * sms_type: 'register',
155
+ * verification_code: '123456',
156
+ * username: 'newuser',
157
+ * password_encrypted: 'encrypted_password'
158
+ * });
159
+ * console.log('Registration successful:', result.user.user_id);
160
+ * console.log('User token:', result.token.token);
161
+ * } catch (error) {
162
+ * console.error('Registration failed:', error.message);
163
+ * }
164
+ * ```
165
+ */
166
+ export declare function registerWithSms(request: VerifySmsRequest, options?: VerifySmsOptions): Promise<SmsLoginResponse>;