zudello-chat-sdk 0.1.1

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 (116) hide show
  1. package/README.md +325 -0
  2. package/dist/cjs/client.js +124 -0
  3. package/dist/cjs/client.js.map +1 -0
  4. package/dist/cjs/constants.js +578 -0
  5. package/dist/cjs/constants.js.map +1 -0
  6. package/dist/cjs/errors.js +195 -0
  7. package/dist/cjs/errors.js.map +1 -0
  8. package/dist/cjs/http/client.js +218 -0
  9. package/dist/cjs/http/client.js.map +1 -0
  10. package/dist/cjs/index.js +80 -0
  11. package/dist/cjs/index.js.map +1 -0
  12. package/dist/cjs/modules/approvals.js +90 -0
  13. package/dist/cjs/modules/approvals.js.map +1 -0
  14. package/dist/cjs/modules/automation.js +110 -0
  15. package/dist/cjs/modules/automation.js.map +1 -0
  16. package/dist/cjs/modules/config.js +264 -0
  17. package/dist/cjs/modules/config.js.map +1 -0
  18. package/dist/cjs/modules/datasets.js +103 -0
  19. package/dist/cjs/modules/datasets.js.map +1 -0
  20. package/dist/cjs/modules/exports.js +126 -0
  21. package/dist/cjs/modules/exports.js.map +1 -0
  22. package/dist/cjs/modules/inboxes.js +99 -0
  23. package/dist/cjs/modules/inboxes.js.map +1 -0
  24. package/dist/cjs/modules/models.js +105 -0
  25. package/dist/cjs/modules/models.js.map +1 -0
  26. package/dist/cjs/modules/org.js +335 -0
  27. package/dist/cjs/modules/org.js.map +1 -0
  28. package/dist/cjs/modules/quick-actions.js +71 -0
  29. package/dist/cjs/modules/quick-actions.js.map +1 -0
  30. package/dist/cjs/modules/resources.js +236 -0
  31. package/dist/cjs/modules/resources.js.map +1 -0
  32. package/dist/cjs/modules/search.js +188 -0
  33. package/dist/cjs/modules/search.js.map +1 -0
  34. package/dist/cjs/modules/sentences.js +155 -0
  35. package/dist/cjs/modules/sentences.js.map +1 -0
  36. package/dist/cjs/modules/users.js +120 -0
  37. package/dist/cjs/modules/users.js.map +1 -0
  38. package/dist/cjs/types.js +8 -0
  39. package/dist/cjs/types.js.map +1 -0
  40. package/dist/esm/client.js +120 -0
  41. package/dist/esm/client.js.map +1 -0
  42. package/dist/esm/constants.js +565 -0
  43. package/dist/esm/constants.js.map +1 -0
  44. package/dist/esm/errors.js +183 -0
  45. package/dist/esm/errors.js.map +1 -0
  46. package/dist/esm/http/client.js +214 -0
  47. package/dist/esm/http/client.js.map +1 -0
  48. package/dist/esm/index.js +49 -0
  49. package/dist/esm/index.js.map +1 -0
  50. package/dist/esm/modules/approvals.js +86 -0
  51. package/dist/esm/modules/approvals.js.map +1 -0
  52. package/dist/esm/modules/automation.js +106 -0
  53. package/dist/esm/modules/automation.js.map +1 -0
  54. package/dist/esm/modules/config.js +260 -0
  55. package/dist/esm/modules/config.js.map +1 -0
  56. package/dist/esm/modules/datasets.js +99 -0
  57. package/dist/esm/modules/datasets.js.map +1 -0
  58. package/dist/esm/modules/exports.js +122 -0
  59. package/dist/esm/modules/exports.js.map +1 -0
  60. package/dist/esm/modules/inboxes.js +95 -0
  61. package/dist/esm/modules/inboxes.js.map +1 -0
  62. package/dist/esm/modules/models.js +101 -0
  63. package/dist/esm/modules/models.js.map +1 -0
  64. package/dist/esm/modules/org.js +331 -0
  65. package/dist/esm/modules/org.js.map +1 -0
  66. package/dist/esm/modules/quick-actions.js +67 -0
  67. package/dist/esm/modules/quick-actions.js.map +1 -0
  68. package/dist/esm/modules/resources.js +232 -0
  69. package/dist/esm/modules/resources.js.map +1 -0
  70. package/dist/esm/modules/search.js +184 -0
  71. package/dist/esm/modules/search.js.map +1 -0
  72. package/dist/esm/modules/sentences.js +151 -0
  73. package/dist/esm/modules/sentences.js.map +1 -0
  74. package/dist/esm/modules/users.js +116 -0
  75. package/dist/esm/modules/users.js.map +1 -0
  76. package/dist/esm/types.js +7 -0
  77. package/dist/esm/types.js.map +1 -0
  78. package/dist/types/client.d.ts +105 -0
  79. package/dist/types/client.d.ts.map +1 -0
  80. package/dist/types/constants.d.ts +505 -0
  81. package/dist/types/constants.d.ts.map +1 -0
  82. package/dist/types/errors.d.ts +143 -0
  83. package/dist/types/errors.d.ts.map +1 -0
  84. package/dist/types/http/client.d.ts +42 -0
  85. package/dist/types/http/client.d.ts.map +1 -0
  86. package/dist/types/index.d.ts +37 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/modules/approvals.d.ts +62 -0
  89. package/dist/types/modules/approvals.d.ts.map +1 -0
  90. package/dist/types/modules/automation.d.ts +79 -0
  91. package/dist/types/modules/automation.d.ts.map +1 -0
  92. package/dist/types/modules/config.d.ts +173 -0
  93. package/dist/types/modules/config.d.ts.map +1 -0
  94. package/dist/types/modules/datasets.d.ts +55 -0
  95. package/dist/types/modules/datasets.d.ts.map +1 -0
  96. package/dist/types/modules/exports.d.ts +76 -0
  97. package/dist/types/modules/exports.d.ts.map +1 -0
  98. package/dist/types/modules/inboxes.d.ts +91 -0
  99. package/dist/types/modules/inboxes.d.ts.map +1 -0
  100. package/dist/types/modules/models.d.ts +91 -0
  101. package/dist/types/modules/models.d.ts.map +1 -0
  102. package/dist/types/modules/org.d.ts +122 -0
  103. package/dist/types/modules/org.d.ts.map +1 -0
  104. package/dist/types/modules/quick-actions.d.ts +58 -0
  105. package/dist/types/modules/quick-actions.d.ts.map +1 -0
  106. package/dist/types/modules/resources.d.ts +111 -0
  107. package/dist/types/modules/resources.d.ts.map +1 -0
  108. package/dist/types/modules/search.d.ts +72 -0
  109. package/dist/types/modules/search.d.ts.map +1 -0
  110. package/dist/types/modules/sentences.d.ts +105 -0
  111. package/dist/types/modules/sentences.d.ts.map +1 -0
  112. package/dist/types/modules/users.d.ts +65 -0
  113. package/dist/types/modules/users.d.ts.map +1 -0
  114. package/dist/types/types.d.ts +2056 -0
  115. package/dist/types/types.d.ts.map +1 -0
  116. package/package.json +67 -0
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ /**
3
+ * Zudello SDK Error Classes
4
+ *
5
+ * Typed error classes for different failure scenarios.
6
+ * Always wrap API calls in try/catch and handle these errors appropriately.
7
+ *
8
+ * @example
9
+ * import {
10
+ * ZudelloClient,
11
+ * ZudelloAuthenticationError,
12
+ * ZudelloValidationError,
13
+ * ZudelloAPIError
14
+ * } from 'zudello-chat-sdk';
15
+ *
16
+ * try {
17
+ * const result = await client.search({ model: 'Transaction' });
18
+ * } catch (error) {
19
+ * if (error instanceof ZudelloAuthenticationError) {
20
+ * console.log('Token expired or invalid');
21
+ * } else if (error instanceof ZudelloValidationError) {
22
+ * console.log('Invalid request:', error.message);
23
+ * } else if (error instanceof ZudelloAPIError) {
24
+ * console.log('API error:', error.statusCode, error.message);
25
+ * }
26
+ * }
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ZudelloRateLimitError = exports.ZudelloNetworkError = exports.ZudelloAPIError = exports.ZudelloValidationError = exports.ZudelloNotFoundError = exports.ZudelloPermissionError = exports.ZudelloAuthenticationError = exports.ZudelloConfigurationError = exports.ZudelloError = void 0;
30
+ /**
31
+ * Base error class for all Zudello SDK errors.
32
+ */
33
+ class ZudelloError extends Error {
34
+ constructor(message) {
35
+ super(message);
36
+ this.name = 'ZudelloError';
37
+ // Maintains proper stack trace for where error was thrown
38
+ if (Error.captureStackTrace) {
39
+ Error.captureStackTrace(this, this.constructor);
40
+ }
41
+ }
42
+ }
43
+ exports.ZudelloError = ZudelloError;
44
+ /**
45
+ * Thrown when SDK configuration is missing or invalid.
46
+ *
47
+ * Common causes:
48
+ * - Missing required environment variables (ZUDELLO_TOKEN, ZUDELLO_CLUSTER_URL, etc.)
49
+ * - Invalid configuration options passed to ZudelloClient constructor
50
+ *
51
+ * @example
52
+ * // This will throw if ZUDELLO_TOKEN env var is not set
53
+ * const client = new ZudelloClient();
54
+ */
55
+ class ZudelloConfigurationError extends ZudelloError {
56
+ /** The configuration key that is missing or invalid */
57
+ configKey;
58
+ constructor(message, configKey) {
59
+ super(message);
60
+ this.name = 'ZudelloConfigurationError';
61
+ this.configKey = configKey;
62
+ }
63
+ }
64
+ exports.ZudelloConfigurationError = ZudelloConfigurationError;
65
+ /**
66
+ * Thrown when authentication fails (401 responses).
67
+ *
68
+ * Common causes:
69
+ * - Expired token
70
+ * - Invalid token format
71
+ * - Token revoked
72
+ *
73
+ * Recovery: Obtain a new token and reinitialize the client.
74
+ */
75
+ class ZudelloAuthenticationError extends ZudelloError {
76
+ constructor(message = 'Authentication failed - check your token') {
77
+ super(message);
78
+ this.name = 'ZudelloAuthenticationError';
79
+ }
80
+ }
81
+ exports.ZudelloAuthenticationError = ZudelloAuthenticationError;
82
+ /**
83
+ * Thrown when the user lacks permission for the requested operation (403 responses).
84
+ *
85
+ * Common causes:
86
+ * - User doesn't have access to the requested resource
87
+ * - User doesn't have permission for the operation (e.g., write when only read allowed)
88
+ * - Resource belongs to a different organization/team
89
+ */
90
+ class ZudelloPermissionError extends ZudelloError {
91
+ constructor(message = 'Access denied - insufficient permissions') {
92
+ super(message);
93
+ this.name = 'ZudelloPermissionError';
94
+ }
95
+ }
96
+ exports.ZudelloPermissionError = ZudelloPermissionError;
97
+ /**
98
+ * Thrown when the requested resource is not found (404 responses).
99
+ *
100
+ * Common causes:
101
+ * - Invalid UUID
102
+ * - Resource has been deleted
103
+ * - Resource belongs to a different team
104
+ */
105
+ class ZudelloNotFoundError extends ZudelloError {
106
+ /** The UUID or identifier that was not found */
107
+ resourceId;
108
+ constructor(message, resourceId) {
109
+ super(message);
110
+ this.name = 'ZudelloNotFoundError';
111
+ this.resourceId = resourceId;
112
+ }
113
+ }
114
+ exports.ZudelloNotFoundError = ZudelloNotFoundError;
115
+ /**
116
+ * Thrown when request validation fails.
117
+ *
118
+ * Common causes:
119
+ * - Invalid model name
120
+ * - Invalid filter syntax
121
+ * - Missing required fields
122
+ * - Invalid field values
123
+ *
124
+ * Check the `details` property for specific validation errors.
125
+ */
126
+ class ZudelloValidationError extends ZudelloError {
127
+ /** Detailed validation error information */
128
+ details;
129
+ /** The field(s) that failed validation */
130
+ fields;
131
+ constructor(message, details, fields) {
132
+ super(message);
133
+ this.name = 'ZudelloValidationError';
134
+ this.details = details;
135
+ this.fields = fields;
136
+ }
137
+ }
138
+ exports.ZudelloValidationError = ZudelloValidationError;
139
+ /**
140
+ * Thrown when the API returns an error response.
141
+ *
142
+ * This is a general API error for non-specific failures.
143
+ * Check `statusCode` and `responseBody` for details.
144
+ */
145
+ class ZudelloAPIError extends ZudelloError {
146
+ /** HTTP status code from the API */
147
+ statusCode;
148
+ /** Raw response body from the API */
149
+ responseBody;
150
+ /** Parsed error details if available */
151
+ errorDetails;
152
+ constructor(message, statusCode, responseBody, errorDetails) {
153
+ super(message);
154
+ this.name = 'ZudelloAPIError';
155
+ this.statusCode = statusCode;
156
+ this.responseBody = responseBody;
157
+ this.errorDetails = errorDetails;
158
+ }
159
+ }
160
+ exports.ZudelloAPIError = ZudelloAPIError;
161
+ /**
162
+ * Thrown when a network error occurs (connection failed, timeout, etc.).
163
+ *
164
+ * These are typically transient errors that may succeed on retry.
165
+ * The SDK has built-in retry logic, so this error means all retries failed.
166
+ */
167
+ class ZudelloNetworkError extends ZudelloError {
168
+ /** The underlying error that caused the network failure */
169
+ cause;
170
+ constructor(message, cause) {
171
+ super(message);
172
+ this.name = 'ZudelloNetworkError';
173
+ this.cause = cause;
174
+ }
175
+ }
176
+ exports.ZudelloNetworkError = ZudelloNetworkError;
177
+ /**
178
+ * Thrown when the API rate limit is exceeded.
179
+ *
180
+ * The SDK has built-in rate limit handling with backoff,
181
+ * so this error means the rate limit persisted after retries.
182
+ *
183
+ * Check `retryAfter` for when to retry (if provided by the API).
184
+ */
185
+ class ZudelloRateLimitError extends ZudelloError {
186
+ /** Seconds to wait before retrying (if provided by API) */
187
+ retryAfter;
188
+ constructor(message = 'Rate limit exceeded', retryAfter) {
189
+ super(message);
190
+ this.name = 'ZudelloRateLimitError';
191
+ this.retryAfter = retryAfter;
192
+ }
193
+ }
194
+ exports.ZudelloRateLimitError = ZudelloRateLimitError;
195
+ //# sourceMappingUR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BAAsB,SAAQ,YAAY;IACrD,2DAA2D;IAC3C,UAAU,CAAU;IAEpC,YAAY,UAAkB,qBAAqB,EAAE,UAAmB;QACtE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AATD,sDASC"}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ /**
3
+ * HTTP Client for Zudello API
4
+ *
5
+ * Handles all HTTP communication including authentication, retries, and error handling.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.HttpClient = void 0;
9
+ const errors_1 = require("../errors");
10
+ // ============================================================================
11
+ // HttpClient
12
+ // ============================================================================
13
+ /**
14
+ * Low-level HTTP client for Zudello API requests.
15
+ *
16
+ * Handles authentication, retries, and error mapping.
17
+ */
18
+ class HttpClient {
19
+ config;
20
+ constructor(config) {
21
+ this.config = this.resolveConfig(config);
22
+ }
23
+ // ==========================================================================
24
+ // Configuration
25
+ // ==========================================================================
26
+ resolveConfig(config) {
27
+ const token = config?.token ?? process.env.ZUDELLO_TOKEN;
28
+ const organizationId = config?.organizationId ?? process.env.ZUDELLO_ORG_ID;
29
+ const teamId = config?.teamId ?? process.env.ZUDELLO_TEAM_ID;
30
+ const clusterUrl = config?.clusterUrl ?? process.env.ZUDELLO_CLUSTER_URL;
31
+ const authApiBase = config?.authApiBase ?? process.env.ZUDELLO_AUTH_API_BASE;
32
+ // Validate required fields
33
+ if (!token) {
34
+ throw new errors_1.ZudelloConfigurationError('Missing required configuration: token. Set ZUDELLO_TOKEN environment variable or pass token in config.', 'token');
35
+ }
36
+ if (!organizationId) {
37
+ throw new errors_1.ZudelloConfigurationError('Missing required configuration: organizationId. Set ZUDELLO_ORG_ID environment variable or pass organizationId in config.', 'organizationId');
38
+ }
39
+ if (!teamId) {
40
+ throw new errors_1.ZudelloConfigurationError('Missing required configuration: teamId. Set ZUDELLO_TEAM_ID environment variable or pass teamId in config.', 'teamId');
41
+ }
42
+ if (!clusterUrl) {
43
+ throw new errors_1.ZudelloConfigurationError('Missing required configuration: clusterUrl. Set ZUDELLO_CLUSTER_URL environment variable or pass clusterUrl in config.', 'clusterUrl');
44
+ }
45
+ if (!authApiBase) {
46
+ throw new errors_1.ZudelloConfigurationError('Missing required configuration: authApiBase. Set ZUDELLO_AUTH_API_BASE environment variable or pass authApiBase in config.', 'authApiBase');
47
+ }
48
+ return {
49
+ token,
50
+ organizationId,
51
+ teamId,
52
+ clusterUrl: clusterUrl.replace(/^https?:\/\//, ''), // Remove protocol if present
53
+ authApiBase,
54
+ userId: config?.userId ?? process.env.ZUDELLO_USER_ID,
55
+ userEmail: config?.userEmail ?? process.env.ZUDELLO_USER_EMAIL,
56
+ maxRetries: config?.maxRetries ?? 3,
57
+ retryDelay: config?.retryDelay ?? 1000,
58
+ timeout: config?.timeout ?? 30000,
59
+ };
60
+ }
61
+ get apiBase() {
62
+ return `https://${this.config.clusterUrl}`;
63
+ }
64
+ get headers() {
65
+ const headers = new Headers();
66
+ headers.set('Content-Type', 'application/json');
67
+ headers.set('Authorization', `Bearer ${this.config.token}`);
68
+ headers.set('x-organization', this.config.organizationId);
69
+ headers.set('x-team', this.config.teamId);
70
+ return headers;
71
+ }
72
+ // ==========================================================================
73
+ // HTTP Layer with Retry
74
+ // ==========================================================================
75
+ /**
76
+ * Make a request to the team-data API.
77
+ */
78
+ async request(method, endpoint, body, retryCount = 0) {
79
+ const url = `${this.apiBase}${endpoint}`;
80
+ const controller = new AbortController();
81
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
82
+ try {
83
+ const response = await fetch(url, {
84
+ method,
85
+ headers: this.headers,
86
+ body: body ? JSON.stringify(body) : undefined,
87
+ signal: controller.signal,
88
+ });
89
+ // Handle specific error status codes
90
+ if (!response.ok) {
91
+ return this.handleErrorResponse(response, method, endpoint, body, retryCount, false);
92
+ }
93
+ // Parse JSON response with error handling
94
+ try {
95
+ return await response.json();
96
+ }
97
+ catch {
98
+ const text = await response.text().catch(() => 'Unable to read response');
99
+ throw new errors_1.ZudelloAPIError(`Invalid JSON response from API`, response.status, text);
100
+ }
101
+ }
102
+ catch (error) {
103
+ // Handle timeout specifically
104
+ if (error instanceof Error && error.name === 'AbortError') {
105
+ return this.handleNetworkError(new Error(`Request timeout after ${this.config.timeout}ms`), method, endpoint, body, retryCount, false);
106
+ }
107
+ return this.handleNetworkError(error, method, endpoint, body, retryCount, false);
108
+ }
109
+ finally {
110
+ clearTimeout(timeoutId);
111
+ }
112
+ }
113
+ /**
114
+ * Make a request to the authentication API (for organisation-level operations).
115
+ */
116
+ async authRequest(method, endpoint, body, retryCount = 0) {
117
+ const url = `${this.config.authApiBase}${endpoint}`;
118
+ const controller = new AbortController();
119
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
120
+ try {
121
+ const response = await fetch(url, {
122
+ method,
123
+ headers: this.headers,
124
+ body: body ? JSON.stringify(body) : undefined,
125
+ signal: controller.signal,
126
+ });
127
+ // Handle specific error status codes
128
+ if (!response.ok) {
129
+ return this.handleErrorResponse(response, method, endpoint, body, retryCount, true);
130
+ }
131
+ // Parse JSON response with error handling
132
+ try {
133
+ return await response.json();
134
+ }
135
+ catch {
136
+ const text = await response.text().catch(() => 'Unable to read response');
137
+ throw new errors_1.ZudelloAPIError(`Invalid JSON response from API`, response.status, text);
138
+ }
139
+ }
140
+ catch (error) {
141
+ // Handle timeout specifically
142
+ if (error instanceof Error && error.name === 'AbortError') {
143
+ return this.handleNetworkError(new Error(`Request timeout after ${this.config.timeout}ms`), method, endpoint, body, retryCount, true);
144
+ }
145
+ return this.handleNetworkError(error, method, endpoint, body, retryCount, true);
146
+ }
147
+ finally {
148
+ clearTimeout(timeoutId);
149
+ }
150
+ }
151
+ async handleErrorResponse(response, method, endpoint, body, retryCount, isAuth) {
152
+ const errorText = await response.text().catch(() => 'Unknown error');
153
+ // Parse error details if possible
154
+ let errorDetails;
155
+ try {
156
+ errorDetails = JSON.parse(errorText);
157
+ }
158
+ catch {
159
+ // Not JSON, use raw text
160
+ }
161
+ switch (response.status) {
162
+ case 401:
163
+ throw new errors_1.ZudelloAuthenticationError('Authentication failed - token may be expired or invalid');
164
+ case 403:
165
+ throw new errors_1.ZudelloPermissionError(isAuth
166
+ ? 'Access forbidden - organisation admin or Zudello staff privileges required'
167
+ : `Access denied: ${errorDetails?.message || 'Insufficient permissions'}`);
168
+ case 404:
169
+ throw new errors_1.ZudelloNotFoundError(`Resource not found: ${errorDetails?.message || endpoint}`, endpoint);
170
+ case 422:
171
+ throw new errors_1.ZudelloValidationError(`Validation failed: ${errorDetails?.message || errorText}`, errorDetails);
172
+ case 429: {
173
+ const retryAfter = parseInt(response.headers.get('Retry-After') || '60', 10);
174
+ if (retryCount < this.config.maxRetries) {
175
+ await this.sleep(retryAfter * 1000);
176
+ return isAuth
177
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
178
+ : this.request(method, endpoint, body, retryCount + 1);
179
+ }
180
+ throw new errors_1.ZudelloRateLimitError('Rate limit exceeded', retryAfter);
181
+ }
182
+ default:
183
+ // Retry on 5xx errors
184
+ if (response.status >= 500 && retryCount < this.config.maxRetries) {
185
+ await this.sleep(this.config.retryDelay * Math.pow(2, retryCount));
186
+ return isAuth
187
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
188
+ : this.request(method, endpoint, body, retryCount + 1);
189
+ }
190
+ throw new errors_1.ZudelloAPIError(`API error (${response.status}): ${errorDetails?.message || response.statusText}`, response.status, errorText, errorDetails);
191
+ }
192
+ }
193
+ async handleNetworkError(error, method, endpoint, body, retryCount, isAuth) {
194
+ // Re-throw Zudello errors
195
+ if (error instanceof errors_1.ZudelloConfigurationError ||
196
+ error instanceof errors_1.ZudelloAuthenticationError ||
197
+ error instanceof errors_1.ZudelloPermissionError ||
198
+ error instanceof errors_1.ZudelloNotFoundError ||
199
+ error instanceof errors_1.ZudelloValidationError ||
200
+ error instanceof errors_1.ZudelloAPIError ||
201
+ error instanceof errors_1.ZudelloRateLimitError) {
202
+ throw error;
203
+ }
204
+ // Network errors - retry
205
+ if (retryCount < this.config.maxRetries) {
206
+ await this.sleep(this.config.retryDelay * Math.pow(2, retryCount));
207
+ return isAuth
208
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
209
+ : this.request(method, endpoint, body, retryCount + 1);
210
+ }
211
+ throw new errors_1.ZudelloNetworkError(`Network error: ${error.message}`, error);
212
+ }
213
+ sleep(ms) {
214
+ return new Promise(resolve => setTimeout(resolve, ms));
215
+ }
216
+ }
217
+ exports.HttpClient = HttpClient;
218
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/http/client.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,sCASmB;AAqBnB,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E;;;;GAIG;AACH,MAAa,UAAU;IACZ,MAAM,CAAiB;IAEhC,YAAY,MAA4B;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,6EAA6E;IAC7E,gBAAgB;IAChB,6EAA6E;IAErE,aAAa,CAAC,MAA4B;QAChD,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;QACzD,MAAM,cAAc,GAAG,MAAM,EAAE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;QAC5E,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;QAC7D,MAAM,UAAU,GAAG,MAAM,EAAE,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC;QACzE,MAAM,WAAW,GAAG,MAAM,EAAE,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;QAE7E,2B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KAAK,YAAY,6BAAoB;YACrC,KAAK,YAAY,+BAAsB;YACvC,KAAK,YAAY,wBAAe;YAChC,KAAK,YAAY,8BAAqB,EAAE,CAAC;YAC3C,MAAM,KAAK,CAAC;QACd,CAAC;QAED,yBAAyB;QACzB,IAAI,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;YACxC,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;YACnE,OAAO,MAAM;gBACX,CAAC,CAAC,IAAI,CAAC,WAAW,CAAI,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,CAAC,CAAC;gBAC7D,CAAC,CAAC,IAAI,CAAC,OAAO,CAAI,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,IAAI,4BAAmB,CAC3B,kBAAmB,KAAe,CAAC,OAAO,EAAE,EAC5C,KAAc,CACf,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AA7RD,gCA6RC"}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ /**
3
+ * Zudello Chat SDK
4
+ *
5
+ * TypeScript SDK for the Zudello API, designed for AI agent code execution in E2B sandboxes.
6
+ *
7
+ * @example
8
+ * import { ZudelloClient, MODELS, MODULES, SUBMODULES } from 'zudello-chat-sdk';
9
+ *
10
+ * // Zero-config: reads from environment variables
11
+ * const client = new ZudelloClient();
12
+ *
13
+ * // Search for pending invoices
14
+ * const invoices = await client.search.query({
15
+ * model: MODELS.Transaction,
16
+ * module: MODULES.PURCHASING,
17
+ * submodule: SUBMODULES.INVOICE,
18
+ * filter: { status: 'REVIEW', total__gt: 1000 }
19
+ * });
20
+ *
21
+ * // Auto-pagination with async iterators
22
+ * for await (const invoice of client.search.list({ model: 'Transaction', module: 'PURCHASING' })) {
23
+ * console.log(invoice.document_number);
24
+ * }
25
+ *
26
+ * // Create resources
27
+ * await client.resources.create({ model: 'Supplier', data: { trading_name: 'ACME' } });
28
+ *
29
+ * // Organisation-level admin (requires privileges)
30
+ * const users = await client.org.listUsers();
31
+ *
32
+ * @packageDocumentation
33
+ */
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.ZudelloRateLimitError = exports.ZudelloNetworkError = exports.ZudelloAPIError = exports.ZudelloValidationError = exports.ZudelloNotFoundError = exports.ZudelloPermissionError = exports.ZudelloAuthenticationError = exports.ZudelloConfigurationError = exports.ZudelloError = exports.createValidatedModelSchema = exports.getCombinationsForModel = exports.getModelsForModule = exports.getValidSubmodulesForModel = exports.getValidModulesForModel = exports.isValidCombination = exports.isValidStatusKey = exports.isValidSubmodule = exports.isValidModule = exports.isValidModel = exports.zudelloStatusKeySchema = exports.zudelloSubmoduleSchema = exports.zudelloModuleSchema = exports.zudelloModelSchema = exports.ZUDELLO_MODEL_COMBINATIONS = exports.ZUDELLO_STATUS_KEYS = exports.ZUDELLO_SUBMODULES = exports.ZUDELLO_MODULES = exports.ZUDELLO_MODELS = exports.STATUS_KEYS = exports.SUBMODULES = exports.MODULES = exports.MODELS = exports.ZudelloClient = void 0;
36
+ // Main client
37
+ var client_1 = require("./client");
38
+ Object.defineProperty(exports, "ZudelloClient", { enumerable: true, get: function () { return client_1.ZudelloClient; } });
39
+ // Constants for type-safe usage
40
+ var constants_1 = require("./constants");
41
+ // Legacy object constants (backward compatible)
42
+ Object.defineProperty(exports, "MODELS", { enumerable: true, get: function () { return constants_1.MODELS; } });
43
+ Object.defineProperty(exports, "MODULES", { enumerable: true, get: function () { return constants_1.MODULES; } });
44
+ Object.defineProperty(exports, "SUBMODULES", { enumerable: true, get: function () { return constants_1.SUBMODULES; } });
45
+ Object.defineProperty(exports, "STATUS_KEYS", { enumerable: true, get: function () { return constants_1.STATUS_KEYS; } });
46
+ // Array constants (for Zod enum compatibility)
47
+ Object.defineProperty(exports, "ZUDELLO_MODELS", { enumerable: true, get: function () { return constants_1.ZUDELLO_MODELS; } });
48
+ Object.defineProperty(exports, "ZUDELLO_MODULES", { enumerable: true, get: function () { return constants_1.ZUDELLO_MODULES; } });
49
+ Object.defineProperty(exports, "ZUDELLO_SUBMODULES", { enumerable: true, get: function () { return constants_1.ZUDELLO_SUBMODULES; } });
50
+ Object.defineProperty(exports, "ZUDELLO_STATUS_KEYS", { enumerable: true, get: function () { return constants_1.ZUDELLO_STATUS_KEYS; } });
51
+ // Model combinations
52
+ Object.defineProperty(exports, "ZUDELLO_MODEL_COMBINATIONS", { enumerable: true, get: function () { return constants_1.ZUDELLO_MODEL_COMBINATIONS; } });
53
+ // Zod schemas
54
+ Object.defineProperty(exports, "zudelloModelSchema", { enumerable: true, get: function () { return constants_1.zudelloModelSchema; } });
55
+ Object.defineProperty(exports, "zudelloModuleSchema", { enumerable: true, get: function () { return constants_1.zudelloModuleSchema; } });
56
+ Object.defineProperty(exports, "zudelloSubmoduleSchema", { enumerable: true, get: function () { return constants_1.zudelloSubmoduleSchema; } });
57
+ Object.defineProperty(exports, "zudelloStatusKeySchema", { enumerable: true, get: function () { return constants_1.zudelloStatusKeySchema; } });
58
+ // Validation functions
59
+ Object.defineProperty(exports, "isValidModel", { enumerable: true, get: function () { return constants_1.isValidModel; } });
60
+ Object.defineProperty(exports, "isValidModule", { enumerable: true, get: function () { return constants_1.isValidModule; } });
61
+ Object.defineProperty(exports, "isValidSubmodule", { enumerable: true, get: function () { return constants_1.isValidSubmodule; } });
62
+ Object.defineProperty(exports, "isValidStatusKey", { enumerable: true, get: function () { return constants_1.isValidStatusKey; } });
63
+ Object.defineProperty(exports, "isValidCombination", { enumerable: true, get: function () { return constants_1.isValidCombination; } });
64
+ Object.defineProperty(exports, "getValidModulesForModel", { enumerable: true, get: function () { return constants_1.getValidModulesForModel; } });
65
+ Object.defineProperty(exports, "getValidSubmodulesForModel", { enumerable: true, get: function () { return constants_1.getValidSubmodulesForModel; } });
66
+ Object.defineProperty(exports, "getModelsForModule", { enumerable: true, get: function () { return constants_1.getModelsForModule; } });
67
+ Object.defineProperty(exports, "getCombinationsForModel", { enumerable: true, get: function () { return constants_1.getCombinationsForModel; } });
68
+ Object.defineProperty(exports, "createValidatedModelSchema", { enumerable: true, get: function () { return constants_1.createValidatedModelSchema; } });
69
+ // Error classes
70
+ var errors_1 = require("./errors");
71
+ Object.defineProperty(exports, "ZudelloError", { enumerable: true, get: function () { return errors_1.ZudelloError; } });
72
+ Object.defineProperty(exports, "ZudelloConfigurationError", { enumerable: true, get: function () { return errors_1.ZudelloConfigurationError; } });
73
+ Object.defineProperty(exports, "ZudelloAuthenticationError", { enumerable: true, get: function () { return errors_1.ZudelloAuthenticationError; } });
74
+ Object.defineProperty(exports, "ZudelloPermissionError", { enumerable: true, get: function () { return errors_1.ZudelloPermissionError; } });
75
+ Object.defineProperty(exports, "ZudelloNotFoundError", { enumerable: true, get: function () { return errors_1.ZudelloNotFoundError; } });
76
+ Object.defineProperty(exports, "ZudelloValidationError", { enumerable: true, get: function () { return errors_1.ZudelloValidationError; } });
77
+ Object.defineProperty(exports, "ZudelloAPIError", { enumerable: true, get: function () { return errors_1.ZudelloAPIError; } });
78
+ Object.defineProperty(exports, "ZudelloNetworkError", { enumerable: true, get: function () { return errors_1.ZudelloNetworkError; } });
79
+ Object.defineProperty(exports, "ZudelloRateLimitError", { enumerable: true, get: function () { return errors_1.ZudelloRateLimitError; } });
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;;;AAEH,cAAc;AACd,mCAAyC;AAAhC,uGAAA,aAAa,OAAA;AAEtB,gCAAgC;AAChC,yCAmCqB;AAlCnB,gDAAgD;AAChD,mGAAA,MAAM,OAAA;AACN,oGAAA,OAAO,OAAA;AACP,uGAAA,UAAU,OAAA;AACV,wGAAA,WAAW,OAAA;AACX,+CAA+C;AAC/C,2GAAA,cAAc,OAAA;AACd,4GAAA,eAAe,OAAA;AACf,+GAAA,kBAAkB,OAAA;AAClB,gHAAA,mBAAmB,OAAA;AACnB,qBAAqB;AACrB,uHAAA,0BAA0B,OAAA;AAC1B,cAAc;AACd,+GAAA,kBAAkB,OAAA;AAClB,gHAAA,mBAAmB,OAAA;AACnB,mHAAA,sBAAsB,OAAA;AACtB,mHAAA,sBAAsB,OAAA;AACtB,uBAAuB;AACvB,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AACb,6GAAA,gBAAgB,OAAA;AAChB,6GAAA,gBAAgB,OAAA;AAChB,+GAAA,kBAAkB,OAAA;AAClB,oHAAA,uBAAuB,OAAA;AACvB,uHAAA,0BAA0B,OAAA;AAC1B,+GAAA,kBAAkB,OAAA;AAClB,oHAAA,uBAAuB,OAAA;AACvB,uHAAA,0BAA0B,OAAA;AAS5B,gBAAgB;AAChB,mCAUkB;AAThB,sGAAA,YAAY,OAAA;AACZ,mHAAA,yBAAyB,OAAA;AACzB,oHAAA,0BAA0B,OAAA;AAC1B,gHAAA,sBAAsB,OAAA;AACtB,8GAAA,oBAAoB,OAAA;AACpB,gHAAA,sBAAsB,OAAA;AACtB,yGAAA,eAAe,OAAA;AACf,6GAAA,mBAAmB,OAAA;AACnB,+GAAA,qBAAqB,OAAA"}
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * Approvals Module
4
+ *
5
+ * Methods for managing approval workflows and bulk approval operations.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ApprovalsModule = void 0;
9
+ /**
10
+ * Approval workflow operations for Zudello.
11
+ */
12
+ class ApprovalsModule {
13
+ http;
14
+ constructor(http) {
15
+ this.http = http;
16
+ }
17
+ /**
18
+ * Bulk approve or reject milestones.
19
+ *
20
+ * @example
21
+ * const result = await client.approvals.bulkApproveMilestones([
22
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-1', status: 'APPROVED' },
23
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-2', status: 'APPROVED' },
24
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-3', status: 'REJECTED', reason: 'Invalid amount' }
25
+ * ]);
26
+ */
27
+ async bulkApproveMilestones(items) {
28
+ const response = await this.http.request('POST', '/team-data/v1/approval/milestones/bulk', { items });
29
+ if (response.success === false) {
30
+ return { success: false, error: response.message || response.error || 'Bulk approval failed' };
31
+ }
32
+ return { success: true, data: response };
33
+ }
34
+ /**
35
+ * Bulk send approval reminders.
36
+ *
37
+ * @example
38
+ * await client.approvals.bulkSendReminders(['inv-uuid-1', 'inv-uuid-2']);
39
+ */
40
+ async bulkSendReminders(resourceUuids) {
41
+ const response = await this.http.request('POST', '/team-data/v1/approval/reminders/bulk', { resource_uuids: resourceUuids });
42
+ if (response.success === false) {
43
+ return { success: false, error: response.message || response.error || 'Failed to send reminders' };
44
+ }
45
+ return { success: true };
46
+ }
47
+ /**
48
+ * Get approval flows for a resource.
49
+ *
50
+ * @param model - The model name (e.g., 'Transaction')
51
+ * @param uuid - The resource UUID
52
+ */
53
+ async getFlows(model, uuid) {
54
+ const response = await this.http.request('GET', `/team-data/v1/approval/flows?model=${encodeURIComponent(model)}&uuid=${encodeURIComponent(uuid)}`);
55
+ if (response.success === false) {
56
+ return { success: false, error: response.message || response.error || 'Failed to get approval flows' };
57
+ }
58
+ return { success: true, data: response.data ?? [] };
59
+ }
60
+ /**
61
+ * Get user groups for the team.
62
+ *
63
+ * @example
64
+ * const groups = await client.approvals.getUserGroups({ userGroupType: 'APPROVAL' });
65
+ */
66
+ async getUserGroups(options = {}) {
67
+ const params = new URLSearchParams();
68
+ if (options.status)
69
+ params.set('status', options.status);
70
+ if (options.userGroupType)
71
+ params.set('user_group_type', options.userGroupType);
72
+ if (options.search)
73
+ params.set('search', options.search);
74
+ if (options.includeMemberIds)
75
+ params.set('include_member_ids', 'true');
76
+ if (options.limit)
77
+ params.set('limit', String(options.limit));
78
+ if (options.offset)
79
+ params.set('offset', String(options.offset));
80
+ if (options.namePattern)
81
+ params.set('name_pattern', options.namePattern);
82
+ const response = await this.http.request('GET', `/team-data/v1/user-groups/?${params.toString()}`);
83
+ if (response.success === false) {
84
+ return { success: false, error: response.message || response.error || 'Failed to get user groups' };
85
+ }
86
+ return { success: true, data: response.data ?? [] };
87
+ }
88
+ }
89
+ exports.ApprovalsModule = ApprovalsModule;
90
+ //# sourceMappingURL=approvals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approvals.js","sourceRoot":"","sources":["../../../src/modules/approvals.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH;;GAEG;AACH,MAAa,eAAe;IACG;IAA7B,YAA6B,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAEjD;;;;;;;;;OASG;IACH,KAAK,CAAC,qBAAqB,CACzB,KAAqB;QAErB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACtC,MAAM,EACN,wCAAwC,EACxC,EAAE,KAAK,EAAE,CACV,CAAC;QACF,IAAI,QAAQ,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC/B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,IAAI,QAAQ,CAAC,KAAK,IAAI,sBAAsB,EAAE,CAAC;QACjG,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CACrB,aAAuB;QAEvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,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