@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.
- package/README.md +329 -0
- package/dist/console.d.ts +34 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +9 -0
- package/dist/console.js.map +1 -0
- package/dist/context.d.ts +65 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +9 -0
- package/dist/context.js.map +1 -0
- package/dist/database-errors.d.ts +197 -0
- package/dist/database-errors.d.ts.map +1 -0
- package/dist/database-errors.js +258 -0
- package/dist/database-errors.js.map +1 -0
- package/dist/databases.d.ts +165 -0
- package/dist/databases.d.ts.map +1 -0
- package/dist/databases.js +31 -0
- package/dist/databases.js.map +1 -0
- package/dist/errors.d.ts +244 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +316 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +57 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +9 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +377 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +99 -0
- package/dist/index.js.map +1 -0
- package/dist/secret-errors.d.ts +128 -0
- package/dist/secret-errors.d.ts.map +1 -0
- package/dist/secret-errors.js +172 -0
- package/dist/secret-errors.js.map +1 -0
- package/dist/secrets.d.ts +50 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +27 -0
- package/dist/secrets.js.map +1 -0
- package/dist/volumes.d.ts +276 -0
- package/dist/volumes.d.ts.map +1 -0
- package/dist/volumes.js +9 -0
- package/dist/volumes.js.map +1 -0
- package/package.json +40 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ketrics SDK - Secret Error Classes
|
|
4
|
+
*
|
|
5
|
+
* Provides typed errors for secret operations in tenant applications.
|
|
6
|
+
*
|
|
7
|
+
* Error Hierarchy:
|
|
8
|
+
* - SecretError (base)
|
|
9
|
+
* - SecretNotFoundError
|
|
10
|
+
* - SecretAccessDeniedError
|
|
11
|
+
* - SecretDecryptionError
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.SecretDecryptionError = exports.SecretAccessDeniedError = exports.SecretNotFoundError = exports.SecretError = void 0;
|
|
15
|
+
exports.isSecretError = isSecretError;
|
|
16
|
+
exports.isSecretErrorType = isSecretErrorType;
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Base Error Class
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Base error class for all Secret errors
|
|
22
|
+
*
|
|
23
|
+
* All Secret errors extend this class and include:
|
|
24
|
+
* - secretCode: The secret code that caused the error
|
|
25
|
+
* - operation: The operation that failed
|
|
26
|
+
* - timestamp: When the error occurred
|
|
27
|
+
*/
|
|
28
|
+
class SecretError extends Error {
|
|
29
|
+
constructor(message, secretCode, operation) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = this.constructor.name;
|
|
32
|
+
this.secretCode = secretCode;
|
|
33
|
+
this.operation = operation;
|
|
34
|
+
this.timestamp = new Date();
|
|
35
|
+
// Maintains proper stack trace for where error was thrown
|
|
36
|
+
if (Error.captureStackTrace) {
|
|
37
|
+
Error.captureStackTrace(this, this.constructor);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Serialize error for logging
|
|
42
|
+
*/
|
|
43
|
+
toJSON() {
|
|
44
|
+
return {
|
|
45
|
+
name: this.name,
|
|
46
|
+
message: this.message,
|
|
47
|
+
secretCode: this.secretCode,
|
|
48
|
+
operation: this.operation,
|
|
49
|
+
timestamp: this.timestamp.toISOString(),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.SecretError = SecretError;
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Specific Error Classes
|
|
56
|
+
// ============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* Error thrown when a secret is not found
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* try {
|
|
63
|
+
* const secret = await ketrics.Secret.get('unknown-secret');
|
|
64
|
+
* } catch (error) {
|
|
65
|
+
* if (error instanceof ketrics.SecretNotFoundError) {
|
|
66
|
+
* console.log(`Secret '${error.secretCode}' not found`);
|
|
67
|
+
* }
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
class SecretNotFoundError extends SecretError {
|
|
72
|
+
constructor(secretCode) {
|
|
73
|
+
super(`Secret '${secretCode}' not found. Verify the secret code is correct and the secret exists.`, secretCode, 'get');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.SecretNotFoundError = SecretNotFoundError;
|
|
77
|
+
/**
|
|
78
|
+
* Error thrown when application does not have access to a secret
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* try {
|
|
83
|
+
* const secret = await ketrics.Secret.get('restricted-secret');
|
|
84
|
+
* } catch (error) {
|
|
85
|
+
* if (error instanceof ketrics.SecretAccessDeniedError) {
|
|
86
|
+
* console.log(`No access to secret '${error.secretCode}'`);
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
class SecretAccessDeniedError extends SecretError {
|
|
92
|
+
constructor(secretCode) {
|
|
93
|
+
super(`Access denied to secret '${secretCode}'. The application does not have an access grant for this secret.`, secretCode, 'get');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.SecretAccessDeniedError = SecretAccessDeniedError;
|
|
97
|
+
/**
|
|
98
|
+
* Error thrown when secret decryption fails
|
|
99
|
+
*
|
|
100
|
+
* This typically indicates a KMS key issue or corrupted data.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* try {
|
|
105
|
+
* const secret = await ketrics.Secret.get('encrypted-secret');
|
|
106
|
+
* } catch (error) {
|
|
107
|
+
* if (error instanceof ketrics.SecretDecryptionError) {
|
|
108
|
+
* console.log(`Failed to decrypt secret: ${error.reason}`);
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
class SecretDecryptionError extends SecretError {
|
|
114
|
+
constructor(secretCode, reason) {
|
|
115
|
+
super(`Failed to decrypt secret '${secretCode}': ${reason}`, secretCode, 'decrypt');
|
|
116
|
+
this.reason = reason;
|
|
117
|
+
}
|
|
118
|
+
toJSON() {
|
|
119
|
+
return {
|
|
120
|
+
...super.toJSON(),
|
|
121
|
+
reason: this.reason,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.SecretDecryptionError = SecretDecryptionError;
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Type Guards
|
|
128
|
+
// ============================================================================
|
|
129
|
+
/**
|
|
130
|
+
* Type guard to check if an error is a SecretError
|
|
131
|
+
*
|
|
132
|
+
* @param error - The error to check
|
|
133
|
+
* @returns True if the error is a SecretError
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* try {
|
|
138
|
+
* const secret = await ketrics.Secret.get('my-secret');
|
|
139
|
+
* } catch (error) {
|
|
140
|
+
* if (isSecretError(error)) {
|
|
141
|
+
* console.log(`Secret error: ${error.secretCode}`);
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
function isSecretError(error) {
|
|
147
|
+
return error instanceof SecretError;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Type guard to check if an error is a specific SecretError type
|
|
151
|
+
*
|
|
152
|
+
* @param error - The error to check
|
|
153
|
+
* @param errorClass - The error class to check against
|
|
154
|
+
* @returns True if the error is an instance of the specified class
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* try {
|
|
159
|
+
* const secret = await ketrics.Secret.get('my-secret');
|
|
160
|
+
* } catch (error) {
|
|
161
|
+
* if (isSecretErrorType(error, SecretNotFoundError)) {
|
|
162
|
+
* console.log('Secret not found');
|
|
163
|
+
* } else if (isSecretErrorType(error, SecretAccessDeniedError)) {
|
|
164
|
+
* console.log('Access denied');
|
|
165
|
+
* }
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
function isSecretErrorType(error, errorClass) {
|
|
170
|
+
return error instanceof errorClass;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=secret-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secret-errors.js","sourceRoot":"","sources":["../src/secret-errors.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AAiKH,sCAEC;AAsBD,8CAKC;AA5LD,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;GAOG;AACH,MAAsB,WAAY,SAAQ,KAAK;IAU7C,YAAY,OAAe,EAAE,UAAkB,EAAE,SAAiB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAE5B,0DAA0D;QAC1D,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;YAC5B,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,E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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ketrics SDK - Secret Interfaces
|
|
3
|
+
*
|
|
4
|
+
* Provides type definitions for accessing encrypted secrets
|
|
5
|
+
* from tenant applications.
|
|
6
|
+
*
|
|
7
|
+
* Usage in tenant code:
|
|
8
|
+
* ```typescript
|
|
9
|
+
* // Get a secret value
|
|
10
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
11
|
+
* console.log('API Key retrieved');
|
|
12
|
+
*
|
|
13
|
+
* // Check if a secret exists
|
|
14
|
+
* if (await ketrics.Secret.exists('optional-api-key')) {
|
|
15
|
+
* const key = await ketrics.Secret.get('optional-api-key');
|
|
16
|
+
* // Use the key
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Error Handling:
|
|
21
|
+
* - Secret.get() throws SecretNotFoundError if secret doesn't exist
|
|
22
|
+
* - Secret.get() throws SecretAccessDeniedError if no access grant
|
|
23
|
+
* - Secret.get() throws SecretDecryptionError if decryption fails
|
|
24
|
+
*/
|
|
25
|
+
/**
|
|
26
|
+
* Secret Interface
|
|
27
|
+
*
|
|
28
|
+
* Static interface for retrieving secret values.
|
|
29
|
+
* Secrets are encrypted at rest using tenant-specific KMS keys.
|
|
30
|
+
*/
|
|
31
|
+
export interface ISecret {
|
|
32
|
+
/**
|
|
33
|
+
* Get a secret value by code
|
|
34
|
+
*
|
|
35
|
+
* @param secretCode - Secret code (e.g., "api-key", "db-password")
|
|
36
|
+
* @returns The decrypted secret value
|
|
37
|
+
* @throws SecretNotFoundError if secret doesn't exist
|
|
38
|
+
* @throws SecretAccessDeniedError if application has no access grant
|
|
39
|
+
* @throws SecretDecryptionError if decryption fails
|
|
40
|
+
*/
|
|
41
|
+
get(secretCode: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Check if a secret exists and is accessible
|
|
44
|
+
*
|
|
45
|
+
* @param secretCode - Secret code to check
|
|
46
|
+
* @returns True if secret exists and is accessible
|
|
47
|
+
*/
|
|
48
|
+
exists(secretCode: string): Promise<boolean>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAMH;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;;;OAQG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzC;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9C"}
|
package/dist/secrets.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ketrics SDK - Secret Interfaces
|
|
4
|
+
*
|
|
5
|
+
* Provides type definitions for accessing encrypted secrets
|
|
6
|
+
* from tenant applications.
|
|
7
|
+
*
|
|
8
|
+
* Usage in tenant code:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Get a secret value
|
|
11
|
+
* const apiKey = await ketrics.Secret.get('stripe-api-key');
|
|
12
|
+
* console.log('API Key retrieved');
|
|
13
|
+
*
|
|
14
|
+
* // Check if a secret exists
|
|
15
|
+
* if (await ketrics.Secret.exists('optional-api-key')) {
|
|
16
|
+
* const key = await ketrics.Secret.get('optional-api-key');
|
|
17
|
+
* // Use the key
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Error Handling:
|
|
22
|
+
* - Secret.get() throws SecretNotFoundError if secret doesn't exist
|
|
23
|
+
* - Secret.get() throws SecretAccessDeniedError if no access grant
|
|
24
|
+
* - Secret.get() throws SecretDecryptionError if decryption fails
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
//# sourceMappingURL=secrets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ketrics SDK - Volume Interfaces and Types
|
|
3
|
+
*
|
|
4
|
+
* Provides type definitions for S3-backed volume storage
|
|
5
|
+
* accessible from tenant applications.
|
|
6
|
+
*/
|
|
7
|
+
import { Readable } from 'stream';
|
|
8
|
+
/**
|
|
9
|
+
* Content types for put operations
|
|
10
|
+
*/
|
|
11
|
+
export type PutContent = string | Buffer | Readable;
|
|
12
|
+
/**
|
|
13
|
+
* File content returned from get operation
|
|
14
|
+
*/
|
|
15
|
+
export interface FileContent {
|
|
16
|
+
/** File content as Buffer */
|
|
17
|
+
content: Buffer;
|
|
18
|
+
/** MIME type of the file */
|
|
19
|
+
contentType: string;
|
|
20
|
+
/** Size in bytes */
|
|
21
|
+
contentLength: number;
|
|
22
|
+
/** Last modification date */
|
|
23
|
+
lastModified: Date;
|
|
24
|
+
/** Entity tag (hash of content) */
|
|
25
|
+
etag: string;
|
|
26
|
+
/** Custom metadata if present */
|
|
27
|
+
metadata?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* File metadata without content
|
|
31
|
+
*/
|
|
32
|
+
export interface FileMetadata {
|
|
33
|
+
/** Relative path within volume */
|
|
34
|
+
key: string;
|
|
35
|
+
/** Size in bytes */
|
|
36
|
+
size: number;
|
|
37
|
+
/** MIME type */
|
|
38
|
+
contentType: string;
|
|
39
|
+
/** Last modification date */
|
|
40
|
+
lastModified: Date;
|
|
41
|
+
/** Entity tag */
|
|
42
|
+
etag: string;
|
|
43
|
+
/** Custom metadata if present */
|
|
44
|
+
metadata?: Record<string, string>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* File info in list results
|
|
48
|
+
*/
|
|
49
|
+
export interface FileInfo {
|
|
50
|
+
/** Relative path within volume */
|
|
51
|
+
key: string;
|
|
52
|
+
/** Size in bytes */
|
|
53
|
+
size: number;
|
|
54
|
+
/** Last modification date */
|
|
55
|
+
lastModified: Date;
|
|
56
|
+
/** Entity tag */
|
|
57
|
+
etag: string;
|
|
58
|
+
/** MIME type (optional) */
|
|
59
|
+
contentType?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for put operation
|
|
63
|
+
*/
|
|
64
|
+
export interface PutOptions {
|
|
65
|
+
/** MIME type (auto-detected if not provided) */
|
|
66
|
+
contentType?: string;
|
|
67
|
+
/** Custom metadata to store with object */
|
|
68
|
+
metadata?: Record<string, string>;
|
|
69
|
+
/** Only create if file doesn't exist */
|
|
70
|
+
ifNotExists?: boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Result of put operation
|
|
74
|
+
*/
|
|
75
|
+
export interface PutResult {
|
|
76
|
+
/** Relative path (user-facing) */
|
|
77
|
+
key: string;
|
|
78
|
+
/** Entity tag */
|
|
79
|
+
etag: string;
|
|
80
|
+
/** Version ID (if versioning enabled) */
|
|
81
|
+
versionId?: string;
|
|
82
|
+
/** Size in bytes */
|
|
83
|
+
size: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Result of delete operation
|
|
87
|
+
*/
|
|
88
|
+
export interface DeleteResult {
|
|
89
|
+
/** Deleted file key */
|
|
90
|
+
key: string;
|
|
91
|
+
/** Whether delete succeeded */
|
|
92
|
+
deleted: boolean;
|
|
93
|
+
/** Version ID (if versioning enabled) */
|
|
94
|
+
versionId?: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Delete error info for batch operations
|
|
98
|
+
*/
|
|
99
|
+
export interface DeleteError {
|
|
100
|
+
/** File key that failed */
|
|
101
|
+
key: string;
|
|
102
|
+
/** Error code */
|
|
103
|
+
code: string;
|
|
104
|
+
/** Error message */
|
|
105
|
+
message: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Result of deleteByPrefix operation
|
|
109
|
+
*/
|
|
110
|
+
export interface DeleteByPrefixResult {
|
|
111
|
+
/** Prefix that was deleted */
|
|
112
|
+
prefix: string;
|
|
113
|
+
/** Number of objects deleted */
|
|
114
|
+
deletedCount: number;
|
|
115
|
+
/** Keys of deleted objects */
|
|
116
|
+
deletedKeys: string[];
|
|
117
|
+
/** Any errors that occurred */
|
|
118
|
+
errors?: DeleteError[];
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Options for list operation
|
|
122
|
+
*/
|
|
123
|
+
export interface ListOptions {
|
|
124
|
+
/** Filter by key prefix */
|
|
125
|
+
prefix?: string;
|
|
126
|
+
/** Maximum items to return (default: 1000, max: 1000) */
|
|
127
|
+
maxResults?: number;
|
|
128
|
+
/** Pagination token from previous response */
|
|
129
|
+
continuationToken?: string;
|
|
130
|
+
/** Delimiter for hierarchical listing (e.g., '/') */
|
|
131
|
+
delimiter?: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Result of list operation
|
|
135
|
+
*/
|
|
136
|
+
export interface ListResult {
|
|
137
|
+
/** Array of file info objects */
|
|
138
|
+
files: FileInfo[];
|
|
139
|
+
/** Folder prefixes (only present when delimiter is specified) */
|
|
140
|
+
folders?: string[];
|
|
141
|
+
/** Whether more results are available */
|
|
142
|
+
isTruncated: boolean;
|
|
143
|
+
/** Token for fetching next page */
|
|
144
|
+
continuationToken?: string;
|
|
145
|
+
/** Number of files returned */
|
|
146
|
+
count: number;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Options for copy operation
|
|
150
|
+
*/
|
|
151
|
+
export interface CopyOptions {
|
|
152
|
+
/** Only copy if destination doesn't exist */
|
|
153
|
+
ifNotExists?: boolean;
|
|
154
|
+
/** Replace metadata on copy */
|
|
155
|
+
metadata?: Record<string, string>;
|
|
156
|
+
/** Metadata directive: COPY or REPLACE */
|
|
157
|
+
metadataDirective?: 'COPY' | 'REPLACE';
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Result of copy operation
|
|
161
|
+
*/
|
|
162
|
+
export interface CopyResult {
|
|
163
|
+
/** Source file key */
|
|
164
|
+
sourceKey: string;
|
|
165
|
+
/** Destination file key */
|
|
166
|
+
destinationKey: string;
|
|
167
|
+
/** Entity tag of copied object */
|
|
168
|
+
etag: string;
|
|
169
|
+
/** Last modified date of copy */
|
|
170
|
+
lastModified: Date;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Options for move operation
|
|
174
|
+
*/
|
|
175
|
+
export interface MoveOptions {
|
|
176
|
+
/** Only move if destination doesn't exist */
|
|
177
|
+
ifNotExists?: boolean;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Result of move operation
|
|
181
|
+
*/
|
|
182
|
+
export interface MoveResult {
|
|
183
|
+
/** Source file key */
|
|
184
|
+
sourceKey: string;
|
|
185
|
+
/** Destination file key */
|
|
186
|
+
destinationKey: string;
|
|
187
|
+
/** Entity tag of moved object */
|
|
188
|
+
etag: string;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Options for download URL generation
|
|
192
|
+
*/
|
|
193
|
+
export interface DownloadUrlOptions {
|
|
194
|
+
/** Seconds until expiration (default: 3600, max: 86400) */
|
|
195
|
+
expiresIn?: number;
|
|
196
|
+
/** Override response content type */
|
|
197
|
+
responseContentType?: string;
|
|
198
|
+
/** Content-Disposition header (e.g., 'attachment; filename="report.pdf"') */
|
|
199
|
+
responseContentDisposition?: string;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Options for upload URL generation
|
|
203
|
+
*/
|
|
204
|
+
export interface UploadUrlOptions {
|
|
205
|
+
/** Seconds until expiration (default: 3600, max: 86400) */
|
|
206
|
+
expiresIn?: number;
|
|
207
|
+
/** Required content type for upload */
|
|
208
|
+
contentType?: string;
|
|
209
|
+
/** Maximum upload size in bytes */
|
|
210
|
+
maxSize?: number;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Presigned URL result
|
|
214
|
+
*/
|
|
215
|
+
export interface PresignedUrl {
|
|
216
|
+
/** The presigned URL */
|
|
217
|
+
url: string;
|
|
218
|
+
/** Expiration timestamp */
|
|
219
|
+
expiresAt: Date;
|
|
220
|
+
/** HTTP method for the URL */
|
|
221
|
+
method: 'GET' | 'PUT';
|
|
222
|
+
/** Additional fields for POST-based uploads */
|
|
223
|
+
fields?: Record<string, string>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Volume Interface
|
|
227
|
+
*
|
|
228
|
+
* Interface for a connected volume with file operations.
|
|
229
|
+
* Use Volume.connect() to obtain an instance.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const volume = await Volume.connect('uploads');
|
|
234
|
+
*
|
|
235
|
+
* // Read operations
|
|
236
|
+
* const file = await volume.get('documents/report.pdf');
|
|
237
|
+
* const exists = await volume.exists('config.json');
|
|
238
|
+
* const meta = await volume.getMetadata('image.png');
|
|
239
|
+
*
|
|
240
|
+
* // Write operations
|
|
241
|
+
* await volume.put('data/output.json', JSON.stringify(data));
|
|
242
|
+
*
|
|
243
|
+
* // Delete operations
|
|
244
|
+
* await volume.delete('temp/file.txt');
|
|
245
|
+
* await volume.deleteByPrefix('temp/');
|
|
246
|
+
*
|
|
247
|
+
* // List operations
|
|
248
|
+
* const files = await volume.list({ prefix: 'documents/' });
|
|
249
|
+
*
|
|
250
|
+
* // File management
|
|
251
|
+
* await volume.copy('source.pdf', 'backup/source.pdf');
|
|
252
|
+
* await volume.move('temp/upload.pdf', 'final/document.pdf');
|
|
253
|
+
*
|
|
254
|
+
* // URL generation
|
|
255
|
+
* const downloadUrl = await volume.generateDownloadUrl('report.pdf');
|
|
256
|
+
* const uploadUrl = await volume.generateUploadUrl('uploads/new-file.pdf');
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export interface IVolume {
|
|
260
|
+
/** Volume code (read-only) */
|
|
261
|
+
readonly code: string;
|
|
262
|
+
/** Granted permissions (read-only) */
|
|
263
|
+
readonly permissions: ReadonlySet<string>;
|
|
264
|
+
get(key: string): Promise<FileContent>;
|
|
265
|
+
exists(key: string): Promise<boolean>;
|
|
266
|
+
getMetadata(key: string): Promise<FileMetadata>;
|
|
267
|
+
put(key: string, content: PutContent, options?: PutOptions): Promise<PutResult>;
|
|
268
|
+
delete(key: string): Promise<DeleteResult>;
|
|
269
|
+
deleteByPrefix(prefix: string): Promise<DeleteByPrefixResult>;
|
|
270
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
271
|
+
copy(sourceKey: string, destinationKey: string, options?: CopyOptions): Promise<CopyResult>;
|
|
272
|
+
move(sourceKey: string, destinationKey: string, options?: MoveOptions): Promise<MoveResult>;
|
|
273
|
+
generateDownloadUrl(key: string, options?: DownloadUrlOptions): Promise<PresignedUrl>;
|
|
274
|
+
generateUploadUrl(key: string, options?: UploadUrlOptions): Promise<PresignedUrl>;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=volumes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volumes.d.ts","sourceRoot":"","sources":["../src/volumes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAMlC;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAMpD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,6BAA6B;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,6BAA6B;IAC7B,YAAY,EAAE,IAAI,CAAC;IACnB,mCAAmC;IACnC,IAAI,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,gBAAgB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACnF"}
|
package/dist/volumes.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Ketrics SDK - Volume Interfaces and Types
|
|
4
|
+
*
|
|
5
|
+
* Provides type definitions for S3-backed volume storage
|
|
6
|
+
* accessible from tenant applications.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=volumes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"volumes.js","sourceRoot":"","sources":["../src/volumes.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ketrics/sdk-backend",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Ketrics SDK for backend tenant application code (VM sandbox)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"clean": "rm -rf dist"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ketrics",
|
|
17
|
+
"sdk",
|
|
18
|
+
"typescript",
|
|
19
|
+
"types",
|
|
20
|
+
"tenant",
|
|
21
|
+
"saas"
|
|
22
|
+
],
|
|
23
|
+
"author": "Ketrics",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/ketrics/cl-ketrics-mvp.git",
|
|
28
|
+
"directory": "ketrics-sdk-backend"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^24.10.2",
|
|
32
|
+
"typescript": "^5.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@types/node": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|