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,183 @@
1
+ /**
2
+ * Zudello SDK Error Classes
3
+ *
4
+ * Typed error classes for different failure scenarios.
5
+ * Always wrap API calls in try/catch and handle these errors appropriately.
6
+ *
7
+ * @example
8
+ * import {
9
+ * ZudelloClient,
10
+ * ZudelloAuthenticationError,
11
+ * ZudelloValidationError,
12
+ * ZudelloAPIError
13
+ * } from 'zudello-chat-sdk';
14
+ *
15
+ * try {
16
+ * const result = await client.search({ model: 'Transaction' });
17
+ * } catch (error) {
18
+ * if (error instanceof ZudelloAuthenticationError) {
19
+ * console.log('Token expired or invalid');
20
+ * } else if (error instanceof ZudelloValidationError) {
21
+ * console.log('Invalid request:', error.message);
22
+ * } else if (error instanceof ZudelloAPIError) {
23
+ * console.log('API error:', error.statusCode, error.message);
24
+ * }
25
+ * }
26
+ */
27
+ /**
28
+ * Base error class for all Zudello SDK errors.
29
+ */
30
+ export class ZudelloError extends Error {
31
+ constructor(message) {
32
+ super(message);
33
+ this.name = 'ZudelloError';
34
+ // Maintains proper stack trace for where error was thrown
35
+ if (Error.captureStackTrace) {
36
+ Error.captureStackTrace(this, this.constructor);
37
+ }
38
+ }
39
+ }
40
+ /**
41
+ * Thrown when SDK configuration is missing or invalid.
42
+ *
43
+ * Common causes:
44
+ * - Missing required environment variables (ZUDELLO_TOKEN, ZUDELLO_CLUSTER_URL, etc.)
45
+ * - Invalid configuration options passed to ZudelloClient constructor
46
+ *
47
+ * @example
48
+ * // This will throw if ZUDELLO_TOKEN env var is not set
49
+ * const client = new ZudelloClient();
50
+ */
51
+ export class ZudelloConfigurationError extends ZudelloError {
52
+ /** The configuration key that is missing or invalid */
53
+ configKey;
54
+ constructor(message, configKey) {
55
+ super(message);
56
+ this.name = 'ZudelloConfigurationError';
57
+ this.configKey = configKey;
58
+ }
59
+ }
60
+ /**
61
+ * Thrown when authentication fails (401 responses).
62
+ *
63
+ * Common causes:
64
+ * - Expired token
65
+ * - Invalid token format
66
+ * - Token revoked
67
+ *
68
+ * Recovery: Obtain a new token and reinitialize the client.
69
+ */
70
+ export class ZudelloAuthenticationError extends ZudelloError {
71
+ constructor(message = 'Authentication failed - check your token') {
72
+ super(message);
73
+ this.name = 'ZudelloAuthenticationError';
74
+ }
75
+ }
76
+ /**
77
+ * Thrown when the user lacks permission for the requested operation (403 responses).
78
+ *
79
+ * Common causes:
80
+ * - User doesn't have access to the requested resource
81
+ * - User doesn't have permission for the operation (e.g., write when only read allowed)
82
+ * - Resource belongs to a different organization/team
83
+ */
84
+ export class ZudelloPermissionError extends ZudelloError {
85
+ constructor(message = 'Access denied - insufficient permissions') {
86
+ super(message);
87
+ this.name = 'ZudelloPermissionError';
88
+ }
89
+ }
90
+ /**
91
+ * Thrown when the requested resource is not found (404 responses).
92
+ *
93
+ * Common causes:
94
+ * - Invalid UUID
95
+ * - Resource has been deleted
96
+ * - Resource belongs to a different team
97
+ */
98
+ export class ZudelloNotFoundError extends ZudelloError {
99
+ /** The UUID or identifier that was not found */
100
+ resourceId;
101
+ constructor(message, resourceId) {
102
+ super(message);
103
+ this.name = 'ZudelloNotFoundError';
104
+ this.resourceId = resourceId;
105
+ }
106
+ }
107
+ /**
108
+ * Thrown when request validation fails.
109
+ *
110
+ * Common causes:
111
+ * - Invalid model name
112
+ * - Invalid filter syntax
113
+ * - Missing required fields
114
+ * - Invalid field values
115
+ *
116
+ * Check the `details` property for specific validation errors.
117
+ */
118
+ export class ZudelloValidationError extends ZudelloError {
119
+ /** Detailed validation error information */
120
+ details;
121
+ /** The field(s) that failed validation */
122
+ fields;
123
+ constructor(message, details, fields) {
124
+ super(message);
125
+ this.name = 'ZudelloValidationError';
126
+ this.details = details;
127
+ this.fields = fields;
128
+ }
129
+ }
130
+ /**
131
+ * Thrown when the API returns an error response.
132
+ *
133
+ * This is a general API error for non-specific failures.
134
+ * Check `statusCode` and `responseBody` for details.
135
+ */
136
+ export class ZudelloAPIError extends ZudelloError {
137
+ /** HTTP status code from the API */
138
+ statusCode;
139
+ /** Raw response body from the API */
140
+ responseBody;
141
+ /** Parsed error details if available */
142
+ errorDetails;
143
+ constructor(message, statusCode, responseBody, errorDetails) {
144
+ super(message);
145
+ this.name = 'ZudelloAPIError';
146
+ this.statusCode = statusCode;
147
+ this.responseBody = responseBody;
148
+ this.errorDetails = errorDetails;
149
+ }
150
+ }
151
+ /**
152
+ * Thrown when a network error occurs (connection failed, timeout, etc.).
153
+ *
154
+ * These are typically transient errors that may succeed on retry.
155
+ * The SDK has built-in retry logic, so this error means all retries failed.
156
+ */
157
+ export class ZudelloNetworkError extends ZudelloError {
158
+ /** The underlying error that caused the network failure */
159
+ cause;
160
+ constructor(message, cause) {
161
+ super(message);
162
+ this.name = 'ZudelloNetworkError';
163
+ this.cause = cause;
164
+ }
165
+ }
166
+ /**
167
+ * Thrown when the API rate limit is exceeded.
168
+ *
169
+ * The SDK has built-in rate limit handling with backoff,
170
+ * so this error means the rate limit persisted after retries.
171
+ *
172
+ * Check `retryAfter` for when to retry (if provided by the API).
173
+ */
174
+ export class ZudelloRateLimitError extends ZudelloError {
175
+ /** Seconds to wait before retrying (if provided by API) */
176
+ retryAfter;
177
+ constructor(message = 'Rate limit exceeded', retryAfter) {
178
+ super(message);
179
+ this.name = 'ZudelloRateLimitError';
180
+ this.retryAfter = retryAfter;
181
+ }
182
+ }
183
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,0DAA0D;QAC1D,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,yBAA0B,SAAQ,YAAY;IACzD,uDAAuD;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,oCAAoC;IACpB,UAAU,CAAS;IACnC,qCAAqC;IACrB,YAAY,CAAU;IACtC,wCAAwC;IACxB,YAAY,CAA2B;IAEvD,YACE,OAAe,EACf,UAAkB,EAClB,YAAqB,EACrB,YAAsC;QAEtC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,YAAY;IACnD,2DAA2D;IAC3C,KAAK,CAAS;IAE9B,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAsB,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"}
@@ -0,0 +1,214 @@
1
+ /**
2
+ * HTTP Client for Zudello API
3
+ *
4
+ * Handles all HTTP communication including authentication, retries, and error handling.
5
+ */
6
+ import { ZudelloConfigurationError, ZudelloAuthenticationError, ZudelloPermissionError, ZudelloNotFoundError, ZudelloValidationError, ZudelloAPIError, ZudelloNetworkError, ZudelloRateLimitError, } from '../errors';
7
+ // ============================================================================
8
+ // HttpClient
9
+ // ============================================================================
10
+ /**
11
+ * Low-level HTTP client for Zudello API requests.
12
+ *
13
+ * Handles authentication, retries, and error mapping.
14
+ */
15
+ export class HttpClient {
16
+ config;
17
+ constructor(config) {
18
+ this.config = this.resolveConfig(config);
19
+ }
20
+ // ==========================================================================
21
+ // Configuration
22
+ // ==========================================================================
23
+ resolveConfig(config) {
24
+ const token = config?.token ?? process.env.ZUDELLO_TOKEN;
25
+ const organizationId = config?.organizationId ?? process.env.ZUDELLO_ORG_ID;
26
+ const teamId = config?.teamId ?? process.env.ZUDELLO_TEAM_ID;
27
+ const clusterUrl = config?.clusterUrl ?? process.env.ZUDELLO_CLUSTER_URL;
28
+ const authApiBase = config?.authApiBase ?? process.env.ZUDELLO_AUTH_API_BASE;
29
+ // Validate required fields
30
+ if (!token) {
31
+ throw new ZudelloConfigurationError('Missing required configuration: token. Set ZUDELLO_TOKEN environment variable or pass token in config.', 'token');
32
+ }
33
+ if (!organizationId) {
34
+ throw new ZudelloConfigurationError('Missing required configuration: organizationId. Set ZUDELLO_ORG_ID environment variable or pass organizationId in config.', 'organizationId');
35
+ }
36
+ if (!teamId) {
37
+ throw new ZudelloConfigurationError('Missing required configuration: teamId. Set ZUDELLO_TEAM_ID environment variable or pass teamId in config.', 'teamId');
38
+ }
39
+ if (!clusterUrl) {
40
+ throw new ZudelloConfigurationError('Missing required configuration: clusterUrl. Set ZUDELLO_CLUSTER_URL environment variable or pass clusterUrl in config.', 'clusterUrl');
41
+ }
42
+ if (!authApiBase) {
43
+ throw new ZudelloConfigurationError('Missing required configuration: authApiBase. Set ZUDELLO_AUTH_API_BASE environment variable or pass authApiBase in config.', 'authApiBase');
44
+ }
45
+ return {
46
+ token,
47
+ organizationId,
48
+ teamId,
49
+ clusterUrl: clusterUrl.replace(/^https?:\/\//, ''), // Remove protocol if present
50
+ authApiBase,
51
+ userId: config?.userId ?? process.env.ZUDELLO_USER_ID,
52
+ userEmail: config?.userEmail ?? process.env.ZUDELLO_USER_EMAIL,
53
+ maxRetries: config?.maxRetries ?? 3,
54
+ retryDelay: config?.retryDelay ?? 1000,
55
+ timeout: config?.timeout ?? 30000,
56
+ };
57
+ }
58
+ get apiBase() {
59
+ return `https://${this.config.clusterUrl}`;
60
+ }
61
+ get headers() {
62
+ const headers = new Headers();
63
+ headers.set('Content-Type', 'application/json');
64
+ headers.set('Authorization', `Bearer ${this.config.token}`);
65
+ headers.set('x-organization', this.config.organizationId);
66
+ headers.set('x-team', this.config.teamId);
67
+ return headers;
68
+ }
69
+ // ==========================================================================
70
+ // HTTP Layer with Retry
71
+ // ==========================================================================
72
+ /**
73
+ * Make a request to the team-data API.
74
+ */
75
+ async request(method, endpoint, body, retryCount = 0) {
76
+ const url = `${this.apiBase}${endpoint}`;
77
+ const controller = new AbortController();
78
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
79
+ try {
80
+ const response = await fetch(url, {
81
+ method,
82
+ headers: this.headers,
83
+ body: body ? JSON.stringify(body) : undefined,
84
+ signal: controller.signal,
85
+ });
86
+ // Handle specific error status codes
87
+ if (!response.ok) {
88
+ return this.handleErrorResponse(response, method, endpoint, body, retryCount, false);
89
+ }
90
+ // Parse JSON response with error handling
91
+ try {
92
+ return await response.json();
93
+ }
94
+ catch {
95
+ const text = await response.text().catch(() => 'Unable to read response');
96
+ throw new ZudelloAPIError(`Invalid JSON response from API`, response.status, text);
97
+ }
98
+ }
99
+ catch (error) {
100
+ // Handle timeout specifically
101
+ if (error instanceof Error && error.name === 'AbortError') {
102
+ return this.handleNetworkError(new Error(`Request timeout after ${this.config.timeout}ms`), method, endpoint, body, retryCount, false);
103
+ }
104
+ return this.handleNetworkError(error, method, endpoint, body, retryCount, false);
105
+ }
106
+ finally {
107
+ clearTimeout(timeoutId);
108
+ }
109
+ }
110
+ /**
111
+ * Make a request to the authentication API (for organisation-level operations).
112
+ */
113
+ async authRequest(method, endpoint, body, retryCount = 0) {
114
+ const url = `${this.config.authApiBase}${endpoint}`;
115
+ const controller = new AbortController();
116
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
117
+ try {
118
+ const response = await fetch(url, {
119
+ method,
120
+ headers: this.headers,
121
+ body: body ? JSON.stringify(body) : undefined,
122
+ signal: controller.signal,
123
+ });
124
+ // Handle specific error status codes
125
+ if (!response.ok) {
126
+ return this.handleErrorResponse(response, method, endpoint, body, retryCount, true);
127
+ }
128
+ // Parse JSON response with error handling
129
+ try {
130
+ return await response.json();
131
+ }
132
+ catch {
133
+ const text = await response.text().catch(() => 'Unable to read response');
134
+ throw new ZudelloAPIError(`Invalid JSON response from API`, response.status, text);
135
+ }
136
+ }
137
+ catch (error) {
138
+ // Handle timeout specifically
139
+ if (error instanceof Error && error.name === 'AbortError') {
140
+ return this.handleNetworkError(new Error(`Request timeout after ${this.config.timeout}ms`), method, endpoint, body, retryCount, true);
141
+ }
142
+ return this.handleNetworkError(error, method, endpoint, body, retryCount, true);
143
+ }
144
+ finally {
145
+ clearTimeout(timeoutId);
146
+ }
147
+ }
148
+ async handleErrorResponse(response, method, endpoint, body, retryCount, isAuth) {
149
+ const errorText = await response.text().catch(() => 'Unknown error');
150
+ // Parse error details if possible
151
+ let errorDetails;
152
+ try {
153
+ errorDetails = JSON.parse(errorText);
154
+ }
155
+ catch {
156
+ // Not JSON, use raw text
157
+ }
158
+ switch (response.status) {
159
+ case 401:
160
+ throw new ZudelloAuthenticationError('Authentication failed - token may be expired or invalid');
161
+ case 403:
162
+ throw new ZudelloPermissionError(isAuth
163
+ ? 'Access forbidden - organisation admin or Zudello staff privileges required'
164
+ : `Access denied: ${errorDetails?.message || 'Insufficient permissions'}`);
165
+ case 404:
166
+ throw new ZudelloNotFoundError(`Resource not found: ${errorDetails?.message || endpoint}`, endpoint);
167
+ case 422:
168
+ throw new ZudelloValidationError(`Validation failed: ${errorDetails?.message || errorText}`, errorDetails);
169
+ case 429: {
170
+ const retryAfter = parseInt(response.headers.get('Retry-After') || '60', 10);
171
+ if (retryCount < this.config.maxRetries) {
172
+ await this.sleep(retryAfter * 1000);
173
+ return isAuth
174
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
175
+ : this.request(method, endpoint, body, retryCount + 1);
176
+ }
177
+ throw new ZudelloRateLimitError('Rate limit exceeded', retryAfter);
178
+ }
179
+ default:
180
+ // Retry on 5xx errors
181
+ if (response.status >= 500 && retryCount < this.config.maxRetries) {
182
+ await this.sleep(this.config.retryDelay * Math.pow(2, retryCount));
183
+ return isAuth
184
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
185
+ : this.request(method, endpoint, body, retryCount + 1);
186
+ }
187
+ throw new ZudelloAPIError(`API error (${response.status}): ${errorDetails?.message || response.statusText}`, response.status, errorText, errorDetails);
188
+ }
189
+ }
190
+ async handleNetworkError(error, method, endpoint, body, retryCount, isAuth) {
191
+ // Re-throw Zudello errors
192
+ if (error instanceof ZudelloConfigurationError ||
193
+ error instanceof ZudelloAuthenticationError ||
194
+ error instanceof ZudelloPermissionError ||
195
+ error instanceof ZudelloNotFoundError ||
196
+ error instanceof ZudelloValidationError ||
197
+ error instanceof ZudelloAPIError ||
198
+ error instanceof ZudelloRateLimitError) {
199
+ throw error;
200
+ }
201
+ // Network errors - retry
202
+ if (retryCount < this.config.maxRetries) {
203
+ await this.sleep(this.config.retryDelay * Math.pow(2, retryCount));
204
+ return isAuth
205
+ ? this.authRequest(method, endpoint, body, retryCount + 1)
206
+ : this.request(method, endpoint, body, retryCount + 1);
207
+ }
208
+ throw new ZudelloNetworkError(`Network error: ${error.message}`, error);
209
+ }
210
+ sleep(ms) {
211
+ return new Promise(resolve => setTimeout(resolve, ms));
212
+ }
213
+ }
214
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,WAAW,CAAC;AAqBnB,+EAA+E;AAC/E,aAAa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AAI,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,MAAM,IAAI,mBAAmB,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"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Zudello Chat SDK
3
+ *
4
+ * TypeScript SDK for the Zudello API, designed for AI agent code execution in E2B sandboxes.
5
+ *
6
+ * @example
7
+ * import { ZudelloClient, MODELS, MODULES, SUBMODULES } from 'zudello-chat-sdk';
8
+ *
9
+ * // Zero-config: reads from environment variables
10
+ * const client = new ZudelloClient();
11
+ *
12
+ * // Search for pending invoices
13
+ * const invoices = await client.search.query({
14
+ * model: MODELS.Transaction,
15
+ * module: MODULES.PURCHASING,
16
+ * submodule: SUBMODULES.INVOICE,
17
+ * filter: { status: 'REVIEW', total__gt: 1000 }
18
+ * });
19
+ *
20
+ * // Auto-pagination with async iterators
21
+ * for await (const invoice of client.search.list({ model: 'Transaction', module: 'PURCHASING' })) {
22
+ * console.log(invoice.document_number);
23
+ * }
24
+ *
25
+ * // Create resources
26
+ * await client.resources.create({ model: 'Supplier', data: { trading_name: 'ACME' } });
27
+ *
28
+ * // Organisation-level admin (requires privileges)
29
+ * const users = await client.org.listUsers();
30
+ *
31
+ * @packageDocumentation
32
+ */
33
+ // Main client
34
+ export { ZudelloClient } from './client';
35
+ // Constants for type-safe usage
36
+ export {
37
+ // Legacy object constants (backward compatible)
38
+ MODELS, MODULES, SUBMODULES, STATUS_KEYS,
39
+ // Array constants (for Zod enum compatibility)
40
+ ZUDELLO_MODELS, ZUDELLO_MODULES, ZUDELLO_SUBMODULES, ZUDELLO_STATUS_KEYS,
41
+ // Model combinations
42
+ ZUDELLO_MODEL_COMBINATIONS,
43
+ // Zod schemas
44
+ zudelloModelSchema, zudelloModuleSchema, zudelloSubmoduleSchema, zudelloStatusKeySchema,
45
+ // Validation functions
46
+ isValidModel, isValidModule, isValidSubmodule, isValidStatusKey, isValidCombination, getValidModulesForModel, getValidSubmodulesForModel, getModelsForModule, getCombinationsForModel, createValidatedModelSchema, } from './constants';
47
+ // Error classes
48
+ export { ZudelloError, ZudelloConfigurationError, ZudelloAuthenticationError, ZudelloPermissionError, ZudelloNotFoundError, ZudelloValidationError, ZudelloAPIError, ZudelloNetworkError, ZudelloRateLimitError, } from './errors';
49
+ //# 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,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,gCAAgC;AAChC,OAAO;AACL,gDAAgD;AAChD,MAAM,EACN,OAAO,EACP,UAAU,EACV,WAAW;AACX,+CAA+C;AAC/C,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,mBAAmB;AACnB,qBAAqB;AACrB,0BAA0B;AAC1B,cAAc;AACd,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB;AACtB,uBAAuB;AACvB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,EACvB,0BAA0B,GAO3B,MAAM,aAAa,CAAC;AAErB,gBAAgB;AAChB,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,UAAU,CAAC"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Approvals Module
3
+ *
4
+ * Methods for managing approval workflows and bulk approval operations.
5
+ */
6
+ /**
7
+ * Approval workflow operations for Zudello.
8
+ */
9
+ export class ApprovalsModule {
10
+ http;
11
+ constructor(http) {
12
+ this.http = http;
13
+ }
14
+ /**
15
+ * Bulk approve or reject milestones.
16
+ *
17
+ * @example
18
+ * const result = await client.approvals.bulkApproveMilestones([
19
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-1', status: 'APPROVED' },
20
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-2', status: 'APPROVED' },
21
+ * { resource_model: 'Transaction', resource_uuid: 'inv-uuid-3', status: 'REJECTED', reason: 'Invalid amount' }
22
+ * ]);
23
+ */
24
+ async bulkApproveMilestones(items) {
25
+ const response = await this.http.request('POST', '/team-data/v1/approval/milestones/bulk', { items });
26
+ if (response.success === false) {
27
+ return { success: false, error: response.message || response.error || 'Bulk approval failed' };
28
+ }
29
+ return { success: true, data: response };
30
+ }
31
+ /**
32
+ * Bulk send approval reminders.
33
+ *
34
+ * @example
35
+ * await client.approvals.bulkSendReminders(['inv-uuid-1', 'inv-uuid-2']);
36
+ */
37
+ async bulkSendReminders(resourceUuids) {
38
+ const response = await this.http.request('POST', '/team-data/v1/approval/reminders/bulk', { resource_uuids: resourceUuids });
39
+ if (response.success === false) {
40
+ return { success: false, error: response.message || response.error || 'Failed to send reminders' };
41
+ }
42
+ return { success: true };
43
+ }
44
+ /**
45
+ * Get approval flows for a resource.
46
+ *
47
+ * @param model - The model name (e.g., 'Transaction')
48
+ * @param uuid - The resource UUID
49
+ */
50
+ async getFlows(model, uuid) {
51
+ const response = await this.http.request('GET', `/team-data/v1/approval/flows?model=${encodeURIComponent(model)}&uuid=${encodeURIComponent(uuid)}`);
52
+ if (response.success === false) {
53
+ return { success: false, error: response.message || response.error || 'Failed to get approval flows' };
54
+ }
55
+ return { success: true, data: response.data ?? [] };
56
+ }
57
+ /**
58
+ * Get user groups for the team.
59
+ *
60
+ * @example
61
+ * const groups = await client.approvals.getUserGroups({ userGroupType: 'APPROVAL' });
62
+ */
63
+ async getUserGroups(options = {}) {
64
+ const params = new URLSearchParams();
65
+ if (options.status)
66
+ params.set('status', options.status);
67
+ if (options.userGroupType)
68
+ params.set('user_group_type', options.userGroupType);
69
+ if (options.search)
70
+ params.set('search', options.search);
71
+ if (options.includeMemberIds)
72
+ params.set('include_member_ids', 'true');
73
+ if (options.limit)
74
+ params.set('limit', String(options.limit));
75
+ if (options.offset)
76
+ params.set('offset', String(options.offset));
77
+ if (options.namePattern)
78
+ params.set('name_pattern', options.namePattern);
79
+ const response = await this.http.request('GET', `/team-data/v1/user-groups/?${params.toString()}`);
80
+ if (response.success === false) {
81
+ return { success: false, error: response.message || response.error || 'Failed to get user groups' };
82
+ }
83
+ return { success: true, data: response.data ?? [] };
84
+ }
85
+ }
86
+ //# 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,MAAM,OAAO,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,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E,OAAO,CAAC,aAAa,CAAC,CAAC;QAChF,IAAI,OAAO,CAAC,MAAM;YAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QACzD,IAAI,OAAO,CAAC,gBAAgB;YAAE,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;QACvE,IAAI,OAAO,CAAC,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAC9D,IAAI,OAAO,CAAC,MAAM;YAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,WAAW;YAAE,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;QAEzE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CACtC,KAAK,EACL,8BAA8B,MAAM,CAAC,QAAQ,EAAE,EAAE,CAClD,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,2BAA2B,EAAE,CAAC;QACtG,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;IACtD,CAAC;CACF"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Automation Module
3
+ *
4
+ * Methods for managing Zudello automation scripts, triggers, and execution logs.
5
+ */
6
+ /**
7
+ * Automation operations for Zudello.
8
+ */
9
+ export class AutomationModule {
10
+ http;
11
+ constructor(http) {
12
+ this.http = http;
13
+ }
14
+ /**
15
+ * Get a script by UUID.
16
+ */
17
+ async getScript(scriptUuid) {
18
+ const response = await this.http.request('GET', `/team-data/v1/scripts/${scriptUuid}`);
19
+ return { success: true, data: response.data };
20
+ }
21
+ /**
22
+ * List all scripts.
23
+ */
24
+ async listScripts() {
25
+ const response = await this.http.request('GET', '/team-data/v1/scripts/');
26
+ return { success: true, data: response.data ?? [] };
27
+ }
28
+ /**
29
+ * Get a trigger by UUID.
30
+ */
31
+ async getTrigger(triggerUuid) {
32
+ const response = await this.http.request('GET', `/team-data/v1/triggers/${triggerUuid}`);
33
+ return { success: true, data: response.data };
34
+ }
35
+ /**
36
+ * List triggers.
37
+ */
38
+ async listTriggers(options = {}) {
39
+ const params = new URLSearchParams();
40
+ if (options.type)
41
+ params.set('type', options.type);
42
+ if (options.module)
43
+ params.set('module', options.module);
44
+ if (options.enabled !== undefined)
45
+ params.set('enabled', String(options.enabled));
46
+ const response = await this.http.request('GET', `/team-data/v1/triggers/?${params.toString()}`);
47
+ return { success: true, data: response.data ?? [] };
48
+ }
49
+ /**
50
+ * Get automation logs.
51
+ */
52
+ async getLogs(options = {}) {
53
+ const params = new URLSearchParams();
54
+ if (options.triggerUuid)
55
+ params.set('trigger_uuid', options.triggerUuid);
56
+ if (options.status)
57
+ params.set('status', options.status);
58
+ if (options.startDate)
59
+ params.set('start_date', options.startDate);
60
+ if (options.endDate)
61
+ params.set('end_date', options.endDate);
62
+ if (options.page)
63
+ params.set('page', String(options.page));
64
+ if (options.perPage)
65
+ params.set('per_page', String(options.perPage));
66
+ const response = await this.http.request('GET', `/team-data/v1/automation/logs?${params.toString()}`);
67
+ return { success: true, data: response.data ?? [] };
68
+ }
69
+ /**
70
+ * Get run logs (execution details).
71
+ */
72
+ async getRunLogs(runUuid) {
73
+ const response = await this.http.request('GET', `/team-data/v1/automation/runs/${runUuid}/logs`);
74
+ return { success: true, data: response.data ?? [] };
75
+ }
76
+ /**
77
+ * Get run log content (actual log text).
78
+ */
79
+ async getRunLogContent(runUuid) {
80
+ const response = await this.http.request('GET', `/team-data/v1/automation/runs/${runUuid}/logs/content`);
81
+ return { success: true, data: response.data };
82
+ }
83
+ /**
84
+ * Search execution runs.
85
+ */
86
+ async searchRuns(options = {}) {
87
+ const params = new URLSearchParams();
88
+ if (options.triggerUuid)
89
+ params.set('trigger_uuid', options.triggerUuid);
90
+ if (options.status)
91
+ params.set('status', options.status);
92
+ if (options.startDate)
93
+ params.set('start_date', options.startDate);
94
+ if (options.endDate)
95
+ params.set('end_date', options.endDate);
96
+ if (options.errorContains)
97
+ params.set('error_contains', options.errorContains);
98
+ if (options.page)
99
+ params.set('page', String(options.page));
100
+ if (options.perPage)
101
+ params.set('per_page', String(options.perPage));
102
+ const response = await this.http.request('GET', `/team-data/v1/automation/runs/search?${params.toString()}`);
103
+ return { success: true, data: response.data ?? [] };
104
+ }
105
+ }
106
+ //# sourceMappingURL=automation.js.map