@trayai/helix-sdk 0.63.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/CHANGELOG.md +49 -0
- package/LICENSE.md +178 -0
- package/README.md +230 -0
- package/dist/broker/index.d.ts +59 -0
- package/dist/broker/index.js +1 -0
- package/dist/chunk-J5OA4RGR.js +1 -0
- package/dist/chunk-L6J5L3JQ.js +1 -0
- package/dist/chunk-V63DM4MB.js +1 -0
- package/dist/chunk-W5TFZBQD.js +1 -0
- package/dist/index.d.ts +117 -0
- package/dist/index.js +9 -0
- package/dist/internal/index.d.ts +128 -0
- package/dist/internal/index.js +1 -0
- package/dist/sdk-config-B-Vfaig8.d.ts +184 -0
- package/dist/testing/index.d.ts +13 -0
- package/dist/testing/index.js +1 -0
- package/dist/types-BxQmQx3V.d.ts +173 -0
- package/package.json +76 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { H3Event } from 'h3';
|
|
2
|
+
import { KyInstance } from 'ky';
|
|
3
|
+
import { ZodType } from 'zod';
|
|
4
|
+
import { Storage } from 'unstorage';
|
|
5
|
+
|
|
6
|
+
/** Connection + call params supplied by the caller at `.parameters()` time. */
|
|
7
|
+
interface DbCallParameters {
|
|
8
|
+
clusterIdentifier?: string;
|
|
9
|
+
database: string;
|
|
10
|
+
dbUser?: string;
|
|
11
|
+
region: string;
|
|
12
|
+
workgroupName?: string;
|
|
13
|
+
statementName?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Terminal builder returned by `.parameters(params)`. */
|
|
16
|
+
interface SqlBuilder {
|
|
17
|
+
sql(query: string): Promise<string>;
|
|
18
|
+
}
|
|
19
|
+
interface DbClient {
|
|
20
|
+
parameters(params: DbCallParameters): SqlBuilder;
|
|
21
|
+
sql(query: string): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type KeyValueStore = Pick<Storage, "getItem" | "setItem" | "removeItem" | "hasItem">;
|
|
25
|
+
|
|
26
|
+
interface FileMetadata {
|
|
27
|
+
/** Developer-facing path (no project prefix). */
|
|
28
|
+
path: string;
|
|
29
|
+
size: number;
|
|
30
|
+
contentType: string;
|
|
31
|
+
lastModified: Date;
|
|
32
|
+
/**
|
|
33
|
+
* Custom metadata set via `PutOptions.metadata`.
|
|
34
|
+
* **Dev only** — the production backend has no field for this; it's silently
|
|
35
|
+
* dropped in Lambda mode and always comes back empty there.
|
|
36
|
+
*/
|
|
37
|
+
metadata: Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* Content hash. **Dev**: real sha1 of the bytes. **Lambda**: synthesized from
|
|
40
|
+
* size + lastModified — the backend doesn't expose a content hash, so don't
|
|
41
|
+
* treat this as a true integrity check in production.
|
|
42
|
+
*/
|
|
43
|
+
etag: string;
|
|
44
|
+
}
|
|
45
|
+
interface PutOptions {
|
|
46
|
+
contentType?: string;
|
|
47
|
+
metadata?: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
interface SignedUrlOptions {
|
|
50
|
+
expiresIn?: number;
|
|
51
|
+
contentType?: string;
|
|
52
|
+
maxSize?: number;
|
|
53
|
+
}
|
|
54
|
+
interface ListOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Max children fetched from the backend before client-side filtering to files
|
|
57
|
+
* only. Subfolders count against this limit too, so a folder with many
|
|
58
|
+
* subfolders can yield fewer than `limit` files back — this is a backend API
|
|
59
|
+
* limitation (no filtered count), not a bug in `list()`.
|
|
60
|
+
*/
|
|
61
|
+
limit?: number;
|
|
62
|
+
cursor?: string;
|
|
63
|
+
}
|
|
64
|
+
type FileData = Buffer | Uint8Array | ReadableStream | string;
|
|
65
|
+
interface FileSystemClient {
|
|
66
|
+
put(path: string, data: FileData, opts?: PutOptions): Promise<FileMetadata>;
|
|
67
|
+
get(path: string): Promise<{
|
|
68
|
+
data: Buffer;
|
|
69
|
+
metadata: FileMetadata;
|
|
70
|
+
} | null>;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a POST endpoint for direct-to-backend upload — **not** a raw
|
|
73
|
+
* PUT-body URL like S3. The caller must POST `multipart/form-data` with the
|
|
74
|
+
* file part named `fileUploadContentInput` in Lambda mode (dev mode accepts
|
|
75
|
+
* a plain PUT of raw bytes). See spec 09 deviations.
|
|
76
|
+
*/
|
|
77
|
+
getUploadUrl(path: string, opts?: SignedUrlOptions): Promise<{
|
|
78
|
+
url: string;
|
|
79
|
+
expiresAt: Date;
|
|
80
|
+
}>;
|
|
81
|
+
getDownloadUrl(path: string, opts?: SignedUrlOptions): Promise<{
|
|
82
|
+
url: string;
|
|
83
|
+
expiresAt: Date;
|
|
84
|
+
}>;
|
|
85
|
+
/**
|
|
86
|
+
* Lists immediate children of the folder resolved from `prefix` — not a
|
|
87
|
+
* recursive substring-prefix scan. `cursor` is always `null`; the backend
|
|
88
|
+
* has no offset/cursor support, only `limit`. Results are filtered to files
|
|
89
|
+
* only after fetching, so `opts.limit` bounds total children (files +
|
|
90
|
+
* subfolders), not the returned file count — see `ListOptions.limit`.
|
|
91
|
+
*/
|
|
92
|
+
list(prefix?: string, opts?: ListOptions): Promise<{
|
|
93
|
+
files: FileMetadata[];
|
|
94
|
+
cursor: string | null;
|
|
95
|
+
}>;
|
|
96
|
+
delete(path: string): Promise<void>;
|
|
97
|
+
/** Deletes every file under `prefix`'s resolved folder, then the folder itself. */
|
|
98
|
+
deleteMany(prefix: string): Promise<{
|
|
99
|
+
deleted: number;
|
|
100
|
+
}>;
|
|
101
|
+
head(path: string): Promise<FileMetadata | null>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface Logger {
|
|
105
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
106
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
107
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
108
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
109
|
+
}
|
|
110
|
+
interface BrokerCallOptions {
|
|
111
|
+
body?: unknown;
|
|
112
|
+
headers?: Record<string, string>;
|
|
113
|
+
query?: Record<string, string | string[]>;
|
|
114
|
+
timeout?: number;
|
|
115
|
+
}
|
|
116
|
+
interface BrokerCallResult {
|
|
117
|
+
status: number;
|
|
118
|
+
body?: unknown;
|
|
119
|
+
headers: Record<string, string | string[]>;
|
|
120
|
+
}
|
|
121
|
+
interface BrokerAuthedClient {
|
|
122
|
+
get(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
123
|
+
post(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
124
|
+
put(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
125
|
+
patch(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
126
|
+
delete(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
127
|
+
head(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
128
|
+
options(url: string, options?: BrokerCallOptions): Promise<BrokerCallResult>;
|
|
129
|
+
}
|
|
130
|
+
interface HttpClient extends KyInstance {
|
|
131
|
+
authed(alias: string): BrokerAuthedClient;
|
|
132
|
+
}
|
|
133
|
+
interface TrayContext<T = Record<string, unknown>> {
|
|
134
|
+
input: T;
|
|
135
|
+
method: string;
|
|
136
|
+
path: string;
|
|
137
|
+
headers: Record<string, string | undefined>;
|
|
138
|
+
http: HttpClient;
|
|
139
|
+
db(alias: string): DbClient;
|
|
140
|
+
kv(): KeyValueStore;
|
|
141
|
+
files(): FileSystemClient;
|
|
142
|
+
log: Logger;
|
|
143
|
+
config: Record<string, unknown>;
|
|
144
|
+
status(code: number): void;
|
|
145
|
+
error(code: number, message: string): never;
|
|
146
|
+
state: Record<string, unknown>;
|
|
147
|
+
request: H3Event;
|
|
148
|
+
executionId: string;
|
|
149
|
+
deploymentId: string | null;
|
|
150
|
+
userId: string | null;
|
|
151
|
+
/**
|
|
152
|
+
* Minimal user identity context (spec 15). Production currently carries
|
|
153
|
+
* only the user ID (invocation payload root in lambda; x-tray-user-id
|
|
154
|
+
* header in dev) — richer fields (email, name, groups, roles) arrive with
|
|
155
|
+
* the full identity feature. Null when no user is known.
|
|
156
|
+
*/
|
|
157
|
+
identity: {
|
|
158
|
+
user: {
|
|
159
|
+
id: string;
|
|
160
|
+
};
|
|
161
|
+
} | null;
|
|
162
|
+
traceId: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Sentinel type — skip input validation when only output validation is desired */
|
|
166
|
+
type UnvalidatedInput = Record<string, unknown>;
|
|
167
|
+
interface DefineFunctionOptions<TInput extends ZodType | undefined = undefined, TOutput extends ZodType | undefined = undefined> {
|
|
168
|
+
input?: TInput;
|
|
169
|
+
output?: TOutput;
|
|
170
|
+
}
|
|
171
|
+
type FunctionHandler<T = Record<string, unknown>> = (ctx: TrayContext<T>) => Promise<unknown>;
|
|
172
|
+
|
|
173
|
+
export type { DbCallParameters as D, FileSystemClient as F, HttpClient as H, KeyValueStore as K, Logger as L, SqlBuilder as S, TrayContext as T, UnvalidatedInput as U, DbClient as a, DefineFunctionOptions as b, FunctionHandler as c };
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trayai/helix-sdk",
|
|
3
|
+
"version": "0.63.0",
|
|
4
|
+
"description": "Helix SDK runtime — defineFunction, ctx, defineConfig, authed HTTP",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "trayio",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"LICENSE.md"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./testing": {
|
|
25
|
+
"import": "./dist/testing/index.js",
|
|
26
|
+
"types": "./dist/testing/index.d.ts"
|
|
27
|
+
},
|
|
28
|
+
"./broker": {
|
|
29
|
+
"import": "./dist/broker/index.js",
|
|
30
|
+
"types": "./dist/broker/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./internal": {
|
|
33
|
+
"tray-internal": {
|
|
34
|
+
"types": "./dist/internal/index.d.ts",
|
|
35
|
+
"import": "./dist/internal/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=24.18.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@opentelemetry/api": "^1.9.1",
|
|
45
|
+
"@opentelemetry/api-logs": "0.220.0",
|
|
46
|
+
"@opentelemetry/core": "^2.7.1",
|
|
47
|
+
"@opentelemetry/exporter-logs-otlp-proto": "0.220.0",
|
|
48
|
+
"@opentelemetry/exporter-trace-otlp-proto": "0.220.0",
|
|
49
|
+
"@opentelemetry/resources": "^2.7.1",
|
|
50
|
+
"@opentelemetry/sdk-logs": "0.220.0",
|
|
51
|
+
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
52
|
+
"@opentelemetry/sdk-trace-node": "^2.7.1",
|
|
53
|
+
"c12": "^3.3.4",
|
|
54
|
+
"chokidar": "^5.0.0",
|
|
55
|
+
"h3": "^1.15.11",
|
|
56
|
+
"ky": "^1.8.1",
|
|
57
|
+
"unstorage": "^1.17.5",
|
|
58
|
+
"zod": "^3.24.4"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^18.0.0",
|
|
62
|
+
"eslint": "^9.39.4",
|
|
63
|
+
"tsup": "^8.4.0",
|
|
64
|
+
"typescript": "^5.7.0",
|
|
65
|
+
"typescript-eslint": "^8.60.0",
|
|
66
|
+
"vitest": "^4.1.4"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "tsup",
|
|
70
|
+
"dev": "tsup --watch",
|
|
71
|
+
"test": "vitest run",
|
|
72
|
+
"test:watch": "vitest",
|
|
73
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
74
|
+
"lint": "tsc --noEmit && eslint ."
|
|
75
|
+
}
|
|
76
|
+
}
|