@ketrics/sdk-backend 0.2.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.
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Ketrics SDK - Volume Error Classes
3
+ *
4
+ * Complete error hierarchy for Volume SDK operations.
5
+ * All errors extend VolumeError for consistent handling.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Volume, VolumeNotFoundError, FileNotFoundError } from '@ketrics/sdk';
10
+ *
11
+ * try {
12
+ * const volume = await Volume.connect('uploads');
13
+ * const file = await volume.get('missing.txt');
14
+ * } catch (error) {
15
+ * if (error instanceof VolumeNotFoundError) {
16
+ * console.log('Volume not found:', error.volumeCode);
17
+ * } else if (error instanceof FileNotFoundError) {
18
+ * console.log('File not found:', error.key);
19
+ * } else if (isVolumeError(error)) {
20
+ * console.log('Volume error:', error.message);
21
+ * }
22
+ * }
23
+ * ```
24
+ */
25
+ /**
26
+ * Volume permission values
27
+ */
28
+ export type VolumePermissionValue = 'ReadObject' | 'CreateObject' | 'UpdateObject' | 'DeleteObject' | 'ListObjects';
29
+ /**
30
+ * Base error class for all Volume SDK errors.
31
+ *
32
+ * Provides consistent properties across all error types.
33
+ * Use the type guards (isVolumeError, isVolumeErrorType) for type-safe error handling.
34
+ */
35
+ export declare abstract class VolumeError extends Error {
36
+ /** Volume code where error occurred */
37
+ readonly volumeCode: string;
38
+ /** Operation that caused the error */
39
+ readonly operation: string;
40
+ /** Timestamp when error occurred */
41
+ readonly timestamp: Date;
42
+ constructor(volumeCode: string, operation: string, message: string);
43
+ /**
44
+ * Convert error to JSON for logging/serialization.
45
+ * Does not include stack trace or internal details.
46
+ */
47
+ toJSON(): Record<string, unknown>;
48
+ }
49
+ /**
50
+ * Thrown when a volume does not exist.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * try {
55
+ * await Volume.connect('nonexistent');
56
+ * } catch (error) {
57
+ * if (error instanceof VolumeNotFoundError) {
58
+ * console.log(`Volume '${error.volumeCode}' not found`);
59
+ * }
60
+ * }
61
+ * ```
62
+ */
63
+ export declare class VolumeNotFoundError extends VolumeError {
64
+ constructor(volumeCode: string);
65
+ }
66
+ /**
67
+ * Thrown when the application does not have an access grant to the volume.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * try {
72
+ * await Volume.connect('restricted');
73
+ * } catch (error) {
74
+ * if (error instanceof VolumeAccessDeniedError) {
75
+ * console.log(`No access to volume '${error.volumeCode}'`);
76
+ * }
77
+ * }
78
+ * ```
79
+ */
80
+ export declare class VolumeAccessDeniedError extends VolumeError {
81
+ constructor(volumeCode: string);
82
+ }
83
+ /**
84
+ * Thrown when an operation requires a permission that was not granted.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * try {
89
+ * await volume.delete('file.txt'); // No DELETE permission
90
+ * } catch (error) {
91
+ * if (error instanceof VolumePermissionDeniedError) {
92
+ * console.log(`Missing permission: ${error.requiredPermission}`);
93
+ * }
94
+ * }
95
+ * ```
96
+ */
97
+ export declare class VolumePermissionDeniedError extends VolumeError {
98
+ /** The permission that was required but not granted */
99
+ readonly requiredPermission: VolumePermissionValue;
100
+ constructor(volumeCode: string, requiredPermission: VolumePermissionValue, operation: string, message?: string);
101
+ toJSON(): Record<string, unknown>;
102
+ }
103
+ /**
104
+ * Thrown when a file does not exist in the volume.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * try {
109
+ * await volume.get('missing.txt');
110
+ * } catch (error) {
111
+ * if (error instanceof FileNotFoundError) {
112
+ * console.log(`File '${error.key}' not found`);
113
+ * }
114
+ * }
115
+ * ```
116
+ */
117
+ export declare class FileNotFoundError extends VolumeError {
118
+ /** The file key that was not found */
119
+ readonly key: string;
120
+ constructor(volumeCode: string, key: string);
121
+ toJSON(): Record<string, unknown>;
122
+ }
123
+ /**
124
+ * Thrown when attempting to create a file that already exists (with ifNotExists option).
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * try {
129
+ * await volume.put('config.json', data, { ifNotExists: true });
130
+ * } catch (error) {
131
+ * if (error instanceof FileAlreadyExistsError) {
132
+ * console.log(`File '${error.key}' already exists`);
133
+ * }
134
+ * }
135
+ * ```
136
+ */
137
+ export declare class FileAlreadyExistsError extends VolumeError {
138
+ /** The file key that already exists */
139
+ readonly key: string;
140
+ constructor(volumeCode: string, key: string);
141
+ toJSON(): Record<string, unknown>;
142
+ }
143
+ /**
144
+ * Thrown when a file path is invalid (e.g., path traversal attempt).
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * try {
149
+ * await volume.get('../../../etc/passwd');
150
+ * } catch (error) {
151
+ * if (error instanceof InvalidPathError) {
152
+ * console.log(`Invalid path: ${error.reason}`);
153
+ * }
154
+ * }
155
+ * ```
156
+ */
157
+ export declare class InvalidPathError extends VolumeError {
158
+ /** The invalid path */
159
+ readonly path: string;
160
+ /** Reason the path is invalid */
161
+ readonly reason: string;
162
+ constructor(path: string, reason: string);
163
+ toJSON(): Record<string, unknown>;
164
+ }
165
+ /**
166
+ * Thrown when a file exceeds the volume's size limit.
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * try {
171
+ * await volume.put('large-file.zip', hugeBuffer);
172
+ * } catch (error) {
173
+ * if (error instanceof FileSizeLimitError) {
174
+ * console.log(`File too large: ${error.size} > ${error.maxSize}`);
175
+ * }
176
+ * }
177
+ * ```
178
+ */
179
+ export declare class FileSizeLimitError extends VolumeError {
180
+ /** The file key */
181
+ readonly key: string;
182
+ /** Actual file size in bytes */
183
+ readonly size: number;
184
+ /** Maximum allowed size in bytes */
185
+ readonly maxSize: number;
186
+ constructor(volumeCode: string, key: string, size: number, maxSize: number);
187
+ toJSON(): Record<string, unknown>;
188
+ }
189
+ /**
190
+ * Thrown when a file's content type is not allowed by the volume.
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * try {
195
+ * await volume.put('script.exe', buffer);
196
+ * } catch (error) {
197
+ * if (error instanceof ContentTypeNotAllowedError) {
198
+ * console.log(`Content type '${error.contentType}' not allowed`);
199
+ * console.log(`Allowed: ${error.allowedTypes.join(', ')}`);
200
+ * }
201
+ * }
202
+ * ```
203
+ */
204
+ export declare class ContentTypeNotAllowedError extends VolumeError {
205
+ /** The file key */
206
+ readonly key: string;
207
+ /** The content type that was rejected */
208
+ readonly contentType: string;
209
+ /** List of allowed content types/extensions */
210
+ readonly allowedTypes: string[];
211
+ constructor(volumeCode: string, key: string, contentType: string, allowedTypes: string[]);
212
+ toJSON(): Record<string, unknown>;
213
+ }
214
+ /**
215
+ * Type guard to check if an error is a VolumeError.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * try {
220
+ * await volume.get('file.txt');
221
+ * } catch (error) {
222
+ * if (isVolumeError(error)) {
223
+ * console.log('Volume error:', error.volumeCode, error.operation);
224
+ * }
225
+ * }
226
+ * ```
227
+ */
228
+ export declare function isVolumeError(error: unknown): error is VolumeError;
229
+ /**
230
+ * Type guard to check if an error is a specific VolumeError type.
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * try {
235
+ * await volume.get('file.txt');
236
+ * } catch (error) {
237
+ * if (isVolumeErrorType(error, FileNotFoundError)) {
238
+ * console.log('File not found:', error.key);
239
+ * }
240
+ * }
241
+ * ```
242
+ */
243
+ export declare function isVolumeErrorType<T extends VolumeError>(error: unknown, errorClass: new (...args: never[]) => T): error is T;
244
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAC7B,YAAY,GACZ,cAAc,GACd,cAAc,GACd,cAAc,GACd,aAAa,CAAC;AAElB;;;;;GAKG;AACH,8BAAsB,WAAY,SAAQ,KAAK;IAC7C,uCAAuC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,M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AAI,EAAE,KAAK,EAAE,KAAK,CAAC,GACtC,KAAK,IAAI,CAAC,CAEZ"}
package/dist/errors.js ADDED
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - Volume Error Classes
4
+ *
5
+ * Complete error hierarchy for Volume SDK operations.
6
+ * All errors extend VolumeError for consistent handling.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { Volume, VolumeNotFoundError, FileNotFoundError } from '@ketrics/sdk';
11
+ *
12
+ * try {
13
+ * const volume = await Volume.connect('uploads');
14
+ * const file = await volume.get('missing.txt');
15
+ * } catch (error) {
16
+ * if (error instanceof VolumeNotFoundError) {
17
+ * console.log('Volume not found:', error.volumeCode);
18
+ * } else if (error instanceof FileNotFoundError) {
19
+ * console.log('File not found:', error.key);
20
+ * } else if (isVolumeError(error)) {
21
+ * console.log('Volume error:', error.message);
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.ContentTypeNotAllowedError = exports.FileSizeLimitError = exports.InvalidPathError = exports.FileAlreadyExistsError = exports.FileNotFoundError = exports.VolumePermissionDeniedError = exports.VolumeAccessDeniedError = exports.VolumeNotFoundError = exports.VolumeError = void 0;
28
+ exports.isVolumeError = isVolumeError;
29
+ exports.isVolumeErrorType = isVolumeErrorType;
30
+ /**
31
+ * Base error class for all Volume SDK errors.
32
+ *
33
+ * Provides consistent properties across all error types.
34
+ * Use the type guards (isVolumeError, isVolumeErrorType) for type-safe error handling.
35
+ */
36
+ class VolumeError extends Error {
37
+ constructor(volumeCode, operation, message) {
38
+ super(message);
39
+ this.name = this.constructor.name;
40
+ this.volumeCode = volumeCode;
41
+ this.operation = operation;
42
+ this.timestamp = new Date();
43
+ // Maintains proper stack trace for where error was thrown
44
+ if (Error.captureStackTrace) {
45
+ Error.captureStackTrace(this, this.constructor);
46
+ }
47
+ }
48
+ /**
49
+ * Convert error to JSON for logging/serialization.
50
+ * Does not include stack trace or internal details.
51
+ */
52
+ toJSON() {
53
+ return {
54
+ name: this.name,
55
+ message: this.message,
56
+ volumeCode: this.volumeCode,
57
+ operation: this.operation,
58
+ timestamp: this.timestamp.toISOString(),
59
+ };
60
+ }
61
+ }
62
+ exports.VolumeError = VolumeError;
63
+ /**
64
+ * Thrown when a volume does not exist.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * try {
69
+ * await Volume.connect('nonexistent');
70
+ * } catch (error) {
71
+ * if (error instanceof VolumeNotFoundError) {
72
+ * console.log(`Volume '${error.volumeCode}' not found`);
73
+ * }
74
+ * }
75
+ * ```
76
+ */
77
+ class VolumeNotFoundError extends VolumeError {
78
+ constructor(volumeCode) {
79
+ super(volumeCode, 'connect', `Volume '${volumeCode}' not found`);
80
+ }
81
+ }
82
+ exports.VolumeNotFoundError = VolumeNotFoundError;
83
+ /**
84
+ * Thrown when the application does not have an access grant to the volume.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * try {
89
+ * await Volume.connect('restricted');
90
+ * } catch (error) {
91
+ * if (error instanceof VolumeAccessDeniedError) {
92
+ * console.log(`No access to volume '${error.volumeCode}'`);
93
+ * }
94
+ * }
95
+ * ```
96
+ */
97
+ class VolumeAccessDeniedError extends VolumeError {
98
+ constructor(volumeCode) {
99
+ super(volumeCode, 'connect', `Application does not have access to volume '${volumeCode}'`);
100
+ }
101
+ }
102
+ exports.VolumeAccessDeniedError = VolumeAccessDeniedError;
103
+ /**
104
+ * Thrown when an operation requires a permission that was not granted.
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * try {
109
+ * await volume.delete('file.txt'); // No DELETE permission
110
+ * } catch (error) {
111
+ * if (error instanceof VolumePermissionDeniedError) {
112
+ * console.log(`Missing permission: ${error.requiredPermission}`);
113
+ * }
114
+ * }
115
+ * ```
116
+ */
117
+ class VolumePermissionDeniedError extends VolumeError {
118
+ constructor(volumeCode, requiredPermission, operation, message) {
119
+ super(volumeCode, operation, message ||
120
+ `Operation '${operation}' requires '${requiredPermission}' permission on volume '${volumeCode}'`);
121
+ this.requiredPermission = requiredPermission;
122
+ }
123
+ toJSON() {
124
+ return {
125
+ ...super.toJSON(),
126
+ requiredPermission: this.requiredPermission,
127
+ };
128
+ }
129
+ }
130
+ exports.VolumePermissionDeniedError = VolumePermissionDeniedError;
131
+ /**
132
+ * Thrown when a file does not exist in the volume.
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * try {
137
+ * await volume.get('missing.txt');
138
+ * } catch (error) {
139
+ * if (error instanceof FileNotFoundError) {
140
+ * console.log(`File '${error.key}' not found`);
141
+ * }
142
+ * }
143
+ * ```
144
+ */
145
+ class FileNotFoundError extends VolumeError {
146
+ constructor(volumeCode, key) {
147
+ super(volumeCode, 'get', `File '${key}' not found in volume '${volumeCode}'`);
148
+ this.key = key;
149
+ }
150
+ toJSON() {
151
+ return {
152
+ ...super.toJSON(),
153
+ key: this.key,
154
+ };
155
+ }
156
+ }
157
+ exports.FileNotFoundError = FileNotFoundError;
158
+ /**
159
+ * Thrown when attempting to create a file that already exists (with ifNotExists option).
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * try {
164
+ * await volume.put('config.json', data, { ifNotExists: true });
165
+ * } catch (error) {
166
+ * if (error instanceof FileAlreadyExistsError) {
167
+ * console.log(`File '${error.key}' already exists`);
168
+ * }
169
+ * }
170
+ * ```
171
+ */
172
+ class FileAlreadyExistsError extends VolumeError {
173
+ constructor(volumeCode, key) {
174
+ super(volumeCode, 'put', `File '${key}' already exists in volume '${volumeCode}'`);
175
+ this.key = key;
176
+ }
177
+ toJSON() {
178
+ return {
179
+ ...super.toJSON(),
180
+ key: this.key,
181
+ };
182
+ }
183
+ }
184
+ exports.FileAlreadyExistsError = FileAlreadyExistsError;
185
+ /**
186
+ * Thrown when a file path is invalid (e.g., path traversal attempt).
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * try {
191
+ * await volume.get('../../../etc/passwd');
192
+ * } catch (error) {
193
+ * if (error instanceof InvalidPathError) {
194
+ * console.log(`Invalid path: ${error.reason}`);
195
+ * }
196
+ * }
197
+ * ```
198
+ */
199
+ class InvalidPathError extends VolumeError {
200
+ constructor(path, reason) {
201
+ super('', 'validate', `Invalid path '${path}': ${reason}`);
202
+ this.path = path;
203
+ this.reason = reason;
204
+ }
205
+ toJSON() {
206
+ return {
207
+ ...super.toJSON(),
208
+ path: this.path,
209
+ reason: this.reason,
210
+ };
211
+ }
212
+ }
213
+ exports.InvalidPathError = InvalidPathError;
214
+ /**
215
+ * Thrown when a file exceeds the volume's size limit.
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * try {
220
+ * await volume.put('large-file.zip', hugeBuffer);
221
+ * } catch (error) {
222
+ * if (error instanceof FileSizeLimitError) {
223
+ * console.log(`File too large: ${error.size} > ${error.maxSize}`);
224
+ * }
225
+ * }
226
+ * ```
227
+ */
228
+ class FileSizeLimitError extends VolumeError {
229
+ constructor(volumeCode, key, size, maxSize) {
230
+ const sizeMB = (size / (1024 * 1024)).toFixed(2);
231
+ const maxMB = (maxSize / (1024 * 1024)).toFixed(2);
232
+ super(volumeCode, 'put', `File '${key}' (${sizeMB}MB) exceeds volume limit (${maxMB}MB)`);
233
+ this.key = key;
234
+ this.size = size;
235
+ this.maxSize = maxSize;
236
+ }
237
+ toJSON() {
238
+ return {
239
+ ...super.toJSON(),
240
+ key: this.key,
241
+ size: this.size,
242
+ maxSize: this.maxSize,
243
+ };
244
+ }
245
+ }
246
+ exports.FileSizeLimitError = FileSizeLimitError;
247
+ /**
248
+ * Thrown when a file's content type is not allowed by the volume.
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * try {
253
+ * await volume.put('script.exe', buffer);
254
+ * } catch (error) {
255
+ * if (error instanceof ContentTypeNotAllowedError) {
256
+ * console.log(`Content type '${error.contentType}' not allowed`);
257
+ * console.log(`Allowed: ${error.allowedTypes.join(', ')}`);
258
+ * }
259
+ * }
260
+ * ```
261
+ */
262
+ class ContentTypeNotAllowedError extends VolumeError {
263
+ constructor(volumeCode, key, contentType, allowedTypes) {
264
+ super(volumeCode, 'put', `Content type '${contentType}' not allowed for volume '${volumeCode}'. Allowed: ${allowedTypes.join(', ')}`);
265
+ this.key = key;
266
+ this.contentType = contentType;
267
+ this.allowedTypes = allowedTypes;
268
+ }
269
+ toJSON() {
270
+ return {
271
+ ...super.toJSON(),
272
+ key: this.key,
273
+ contentType: this.contentType,
274
+ allowedTypes: this.allowedTypes,
275
+ };
276
+ }
277
+ }
278
+ exports.ContentTypeNotAllowedError = ContentTypeNotAllowedError;
279
+ // ============================================================================
280
+ // Type Guards
281
+ // ============================================================================
282
+ /**
283
+ * Type guard to check if an error is a VolumeError.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * try {
288
+ * await volume.get('file.txt');
289
+ * } catch (error) {
290
+ * if (isVolumeError(error)) {
291
+ * console.log('Volume error:', error.volumeCode, error.operation);
292
+ * }
293
+ * }
294
+ * ```
295
+ */
296
+ function isVolumeError(error) {
297
+ return error instanceof VolumeError;
298
+ }
299
+ /**
300
+ * Type guard to check if an error is a specific VolumeError type.
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * try {
305
+ * await volume.get('file.txt');
306
+ * } catch (error) {
307
+ * if (isVolumeErrorType(error, FileNotFoundError)) {
308
+ * console.log('File not found:', error.key);
309
+ * }
310
+ * }
311
+ * ```
312
+ */
313
+ function isVolumeErrorType(error, errorClass) {
314
+ return error instanceof errorClass;
315
+ }
316
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAgWH,sCAEC;AAgBD,8CAKC;AA3WD;;;;;GAKG;AACH,MAAsB,WAAY,SAAQ,KAAK;IAQ7C,YAAY,UAAkB,EAAE,SAAiB,EAAE,OAAe;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAA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AAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,KAAK,CAAC,MAAM,EAAE;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;IACJ,CAAC;CACF;AAhCD,gEAgCC;AAED,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;;;;;;;;;;;;GAaG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,iBAAiB,CAC/B,KAAc,EACd,UAAuC;IAEvC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC"}
package/dist/http.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Ketrics SDK - HTTP Client Interfaces
3
+ *
4
+ * Provides type definitions for making external API requests
5
+ * from tenant applications.
6
+ */
7
+ /**
8
+ * HTTP Request Configuration
9
+ */
10
+ export interface HttpRequestConfig {
11
+ /** Request headers */
12
+ headers?: Record<string, string>;
13
+ /** Request timeout in milliseconds */
14
+ timeout?: number;
15
+ /** Query parameters */
16
+ params?: Record<string, string | number | boolean>;
17
+ /** Maximum redirects to follow */
18
+ maxRedirects?: number;
19
+ }
20
+ /**
21
+ * HTTP Response
22
+ */
23
+ export interface HttpResponse<T = unknown> {
24
+ /** Response data */
25
+ data: T;
26
+ /** HTTP status code */
27
+ status: number;
28
+ /** HTTP status text */
29
+ statusText: string;
30
+ /** Response headers */
31
+ headers: Record<string, string>;
32
+ }
33
+ /**
34
+ * HTTP Client Interface
35
+ *
36
+ * Simple HTTP client for making external API requests.
37
+ * Wraps axios with default timeout and user agent.
38
+ */
39
+ export interface HttpClient {
40
+ /**
41
+ * Send GET request
42
+ */
43
+ get<T = unknown>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
44
+ /**
45
+ * Send POST request
46
+ */
47
+ post<T = unknown>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
48
+ /**
49
+ * Send PUT request
50
+ */
51
+ put<T = unknown>(url: string, data?: unknown, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
52
+ /**
53
+ * Send DELETE request
54
+ */
55
+ delete<T = unknown>(url: string, config?: HttpRequestConfig): Promise<HttpResponse<T>>;
56
+ }
57
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,sCAAsC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;IACnD,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,OAAO;IACvC,oBAAoB;IACpB,IAAI,EAAE,CAAC,CAAC;IACR,uBAAuB;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpF;;OAEG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAErG;;OAEG;IACH,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpG;;OAEG;IACH,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CACxF"}
package/dist/http.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Ketrics SDK - HTTP Client Interfaces
4
+ *
5
+ * Provides type definitions for making external API requests
6
+ * from tenant applications.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}