@alienplatform/sdk 1.14.1 → 2.0.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/dist/dist.js +371 -275
- package/dist/index.d.ts +22 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -14356
- package/dist/native.d.ts +26 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +2 -0
- package/dist/worker-runtime/channel.d.ts +25 -0
- package/dist/worker-runtime/channel.d.ts.map +1 -0
- package/dist/worker-runtime/errors.d.ts +79 -0
- package/dist/worker-runtime/errors.d.ts.map +1 -0
- package/dist/worker-runtime/event-loop.d.ts +43 -0
- package/dist/worker-runtime/event-loop.d.ts.map +1 -0
- package/dist/{generated → worker-runtime/generated}/control.d.ts +15 -15
- package/dist/worker-runtime/generated/control.d.ts.map +1 -0
- package/dist/worker-runtime/generated/google/protobuf/duration.d.ts.map +1 -0
- package/dist/worker-runtime/generated/google/protobuf/timestamp.d.ts.map +1 -0
- package/dist/{generated → worker-runtime/generated}/wait_until.d.ts +29 -29
- package/dist/worker-runtime/generated/wait_until.d.ts.map +1 -0
- package/dist/worker-runtime/grpc-utils.d.ts +23 -0
- package/dist/worker-runtime/grpc-utils.d.ts.map +1 -0
- package/dist/worker-runtime/index.d.ts +33 -0
- package/dist/worker-runtime/index.d.ts.map +1 -0
- package/dist/{src.js → worker-runtime/index.js} +9370 -4035
- package/dist/worker-runtime/registry.d.ts +169 -0
- package/dist/worker-runtime/registry.d.ts.map +1 -0
- package/dist/worker-runtime/service-definitions.d.ts +12 -0
- package/dist/worker-runtime/service-definitions.d.ts.map +1 -0
- package/dist/worker-runtime/wait-until-manager.d.ts +34 -0
- package/dist/worker-runtime/wait-until-manager.d.ts.map +1 -0
- package/package.json +18 -38
- package/.turbo/turbo-build.log +0 -30
- package/AGENTS.md +0 -70
- package/dist/bearerTokenAuthenticationPolicy.js +0 -3028
- package/dist/bindings/artifact-registry.d.ts +0 -88
- package/dist/bindings/artifact-registry.d.ts.map +0 -1
- package/dist/bindings/build.d.ts +0 -67
- package/dist/bindings/build.d.ts.map +0 -1
- package/dist/bindings/index.d.ts +0 -13
- package/dist/bindings/index.d.ts.map +0 -1
- package/dist/bindings/kv.d.ts +0 -113
- package/dist/bindings/kv.d.ts.map +0 -1
- package/dist/bindings/postgres.d.ts +0 -90
- package/dist/bindings/postgres.d.ts.map +0 -1
- package/dist/bindings/postgres.test.d.ts +0 -2
- package/dist/bindings/postgres.test.d.ts.map +0 -1
- package/dist/bindings/queue.d.ts +0 -81
- package/dist/bindings/queue.d.ts.map +0 -1
- package/dist/bindings/service-account.d.ts +0 -46
- package/dist/bindings/service-account.d.ts.map +0 -1
- package/dist/bindings/storage.d.ts +0 -164
- package/dist/bindings/storage.d.ts.map +0 -1
- package/dist/bindings/vault.d.ts +0 -65
- package/dist/bindings/vault.d.ts.map +0 -1
- package/dist/bindings/worker.d.ts +0 -72
- package/dist/bindings/worker.d.ts.map +0 -1
- package/dist/channel.d.ts +0 -39
- package/dist/channel.d.ts.map +0 -1
- package/dist/checksum.js +0 -6176
- package/dist/commands/client.d.ts +0 -47
- package/dist/commands/client.d.ts.map +0 -1
- package/dist/commands/errors.d.ts +0 -198
- package/dist/commands/errors.d.ts.map +0 -1
- package/dist/commands/index.d.ts +0 -23
- package/dist/commands/index.d.ts.map +0 -1
- package/dist/commands/index.js +0 -387
- package/dist/commands/types.d.ts +0 -40
- package/dist/commands/types.d.ts.map +0 -1
- package/dist/commands.d.ts +0 -55
- package/dist/commands.d.ts.map +0 -1
- package/dist/context.d.ts +0 -182
- package/dist/context.d.ts.map +0 -1
- package/dist/dist-cjs.js +0 -15258
- package/dist/dist2.js +0 -1239
- package/dist/errors.d.ts +0 -359
- package/dist/errors.d.ts.map +0 -1
- package/dist/es5.js +0 -1720
- package/dist/esm.js +0 -18068
- package/dist/esm2.js +0 -3166
- package/dist/event-streams.js +0 -770
- package/dist/events.d.ts +0 -163
- package/dist/events.d.ts.map +0 -1
- package/dist/generated/artifact_registry.d.ts +0 -302
- package/dist/generated/artifact_registry.d.ts.map +0 -1
- package/dist/generated/build.d.ts +0 -184
- package/dist/generated/build.d.ts.map +0 -1
- package/dist/generated/container.d.ts +0 -101
- package/dist/generated/container.d.ts.map +0 -1
- package/dist/generated/control.d.ts.map +0 -1
- package/dist/generated/google/protobuf/duration.d.ts.map +0 -1
- package/dist/generated/google/protobuf/timestamp.d.ts.map +0 -1
- package/dist/generated/kv.d.ts +0 -182
- package/dist/generated/kv.d.ts.map +0 -1
- package/dist/generated/queue.d.ts +0 -127
- package/dist/generated/queue.d.ts.map +0 -1
- package/dist/generated/service_account.d.ts +0 -112
- package/dist/generated/service_account.d.ts.map +0 -1
- package/dist/generated/storage.d.ts +0 -784
- package/dist/generated/storage.d.ts.map +0 -1
- package/dist/generated/vault.d.ts +0 -107
- package/dist/generated/vault.d.ts.map +0 -1
- package/dist/generated/wait_until.d.ts.map +0 -1
- package/dist/generated/worker.d.ts +0 -107
- package/dist/generated/worker.d.ts.map +0 -1
- package/dist/global.d.ts +0 -208
- package/dist/global.d.ts.map +0 -1
- package/dist/grpc-utils.d.ts +0 -25
- package/dist/grpc-utils.d.ts.map +0 -1
- package/dist/jws.js +0 -611
- package/dist/open.js +0 -461
- package/dist/rolldown-runtime.js +0 -44
- package/dist/src2.js +0 -114032
- package/dist/types.d.ts +0 -337
- package/dist/types.d.ts.map +0 -1
- package/dist/wait-until.d.ts +0 -115
- package/dist/wait-until.d.ts.map +0 -1
- package/scripts/generate-proto.sh +0 -46
- package/src/bindings/AGENTS.md +0 -105
- package/src/bindings/artifact-registry.ts +0 -317
- package/src/bindings/build.ts +0 -195
- package/src/bindings/index.ts +0 -13
- package/src/bindings/kv.ts +0 -240
- package/src/bindings/postgres.test.ts +0 -17
- package/src/bindings/postgres.ts +0 -446
- package/src/bindings/queue.ts +0 -191
- package/src/bindings/service-account.ts +0 -113
- package/src/bindings/storage.ts +0 -536
- package/src/bindings/vault.ts +0 -133
- package/src/bindings/worker.ts +0 -164
- package/src/channel.ts +0 -102
- package/src/commands/client.ts +0 -446
- package/src/commands/errors.ts +0 -126
- package/src/commands/index.ts +0 -41
- package/src/commands/types.ts +0 -52
- package/src/commands.ts +0 -76
- package/src/context.ts +0 -368
- package/src/errors.ts +0 -280
- package/src/events.ts +0 -511
- package/src/generated/artifact_registry.ts +0 -2096
- package/src/generated/build.ts +0 -1311
- package/src/generated/container.ts +0 -503
- package/src/generated/control.ts +0 -2018
- package/src/generated/google/protobuf/duration.ts +0 -196
- package/src/generated/google/protobuf/timestamp.ts +0 -226
- package/src/generated/kv.ts +0 -1169
- package/src/generated/queue.ts +0 -753
- package/src/generated/service_account.ts +0 -814
- package/src/generated/storage.ts +0 -3820
- package/src/generated/vault.ts +0 -543
- package/src/generated/wait_until.ts +0 -829
- package/src/generated/worker.ts +0 -759
- package/src/global.ts +0 -287
- package/src/grpc-utils.ts +0 -159
- package/src/index.ts +0 -160
- package/src/types.ts +0 -397
- package/src/wait-until.ts +0 -273
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -17
- /package/dist/{generated → worker-runtime/generated}/google/protobuf/duration.d.ts +0 -0
- /package/dist/{generated → worker-runtime/generated}/google/protobuf/timestamp.d.ts +0 -0
package/src/global.ts
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global convenience functions for Alien bindings.
|
|
3
|
-
*
|
|
4
|
-
* These functions use a singleton AlienContext for easy access.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { ArtifactRegistry } from "./bindings/artifact-registry.js"
|
|
8
|
-
import type { Build } from "./bindings/build.js"
|
|
9
|
-
import type { Kv } from "./bindings/kv.js"
|
|
10
|
-
import type { Queue } from "./bindings/queue.js"
|
|
11
|
-
import type { ServiceAccount } from "./bindings/service-account.js"
|
|
12
|
-
import type { Storage } from "./bindings/storage.js"
|
|
13
|
-
import type { Vault } from "./bindings/vault.js"
|
|
14
|
-
import type { WorkerBinding } from "./bindings/worker.js"
|
|
15
|
-
|
|
16
|
-
import { AlienContext } from "./context.js"
|
|
17
|
-
import {
|
|
18
|
-
type CronEvent,
|
|
19
|
-
type QueueMessageEvent,
|
|
20
|
-
type StorageEvent,
|
|
21
|
-
onCronEvent as onCronEventImpl,
|
|
22
|
-
onQueueMessage as onQueueMessageImpl,
|
|
23
|
-
onStorageEvent as onStorageEventImpl,
|
|
24
|
-
} from "./events.js"
|
|
25
|
-
import { waitUntil as waitUntilImpl } from "./wait-until.js"
|
|
26
|
-
|
|
27
|
-
// Lazy-initialized global context
|
|
28
|
-
let globalContext: AlienContext | undefined
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Get or create the global AlienContext.
|
|
32
|
-
*/
|
|
33
|
-
async function getGlobalContext(): Promise<AlienContext> {
|
|
34
|
-
if (!globalContext) {
|
|
35
|
-
globalContext = await AlienContext.fromEnv()
|
|
36
|
-
}
|
|
37
|
-
return globalContext
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ============================================================================
|
|
41
|
-
// Binding Accessors
|
|
42
|
-
// ============================================================================
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Get a storage binding.
|
|
46
|
-
*
|
|
47
|
-
* @param name - Binding name
|
|
48
|
-
* @returns Storage binding instance
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { storage } from "@alienplatform/sdk"
|
|
53
|
-
*
|
|
54
|
-
* const bucket = await storage("my-bucket")
|
|
55
|
-
* await bucket.put("hello.txt", "Hello, World!")
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export async function storage(name: string): Promise<Storage> {
|
|
59
|
-
return (await getGlobalContext()).storage(name)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Get a KV binding.
|
|
64
|
-
*
|
|
65
|
-
* @param name - Binding name
|
|
66
|
-
* @returns KV binding instance
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* import { kv } from "@alienplatform/sdk"
|
|
71
|
-
*
|
|
72
|
-
* const cache = await kv("my-cache")
|
|
73
|
-
* await cache.set("key", "value")
|
|
74
|
-
* const value = await cache.getText("key")
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export async function kv(name: string): Promise<Kv> {
|
|
78
|
-
return (await getGlobalContext()).kv(name)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Get a queue binding.
|
|
83
|
-
*
|
|
84
|
-
* @param name - Binding name
|
|
85
|
-
* @returns Queue binding instance
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* import { queue } from "@alienplatform/sdk"
|
|
90
|
-
*
|
|
91
|
-
* const tasks = await queue("task-queue")
|
|
92
|
-
* await tasks.send("job-type", { jobId: "123" })
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export async function queue(name: string): Promise<Queue> {
|
|
96
|
-
return (await getGlobalContext()).queue(name)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Get a vault binding.
|
|
101
|
-
*
|
|
102
|
-
* @param name - Binding name
|
|
103
|
-
* @returns Vault binding instance
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* import { vault } from "@alienplatform/sdk"
|
|
108
|
-
*
|
|
109
|
-
* const secrets = await vault("app-secrets")
|
|
110
|
-
* const apiKey = await secrets.get("API_KEY")
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
export async function vault(name: string): Promise<Vault> {
|
|
114
|
-
return (await getGlobalContext()).vault(name)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Get a build binding.
|
|
119
|
-
*
|
|
120
|
-
* @param name - Binding name
|
|
121
|
-
* @returns Build binding instance
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* import { build } from "@alienplatform/sdk"
|
|
126
|
-
*
|
|
127
|
-
* const builder = await build("my-builder")
|
|
128
|
-
* const execution = await builder.start({ script: "npm run build" })
|
|
129
|
-
* ```
|
|
130
|
-
*/
|
|
131
|
-
export async function build(name: string): Promise<Build> {
|
|
132
|
-
return (await getGlobalContext()).build(name)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Get an artifact registry binding.
|
|
137
|
-
*
|
|
138
|
-
* @param name - Binding name
|
|
139
|
-
* @returns ArtifactRegistry binding instance
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```typescript
|
|
143
|
-
* import { artifactRegistry } from "@alienplatform/sdk"
|
|
144
|
-
*
|
|
145
|
-
* const registry = await artifactRegistry("my-registry")
|
|
146
|
-
* const repo = await registry.createRepository("my-app")
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export async function artifactRegistry(name: string): Promise<ArtifactRegistry> {
|
|
150
|
-
return (await getGlobalContext()).artifactRegistry(name)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Get a worker binding.
|
|
155
|
-
*
|
|
156
|
-
* @param name - Binding name
|
|
157
|
-
* @returns Worker binding instance
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* import { worker } from "@alienplatform/sdk"
|
|
162
|
-
*
|
|
163
|
-
* const processor = await worker("image-processor")
|
|
164
|
-
* const result = await processor.invokeJson("resize", { width: 800 })
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
export async function worker(name: string): Promise<WorkerBinding> {
|
|
168
|
-
return (await getGlobalContext()).worker(name)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Get a service account binding.
|
|
173
|
-
*
|
|
174
|
-
* @param name - Binding name
|
|
175
|
-
* @returns ServiceAccount binding instance
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```typescript
|
|
179
|
-
* import { serviceAccount } from "@alienplatform/sdk"
|
|
180
|
-
*
|
|
181
|
-
* const sa = await serviceAccount("deployment-account")
|
|
182
|
-
* const info = await sa.getInfo()
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export async function serviceAccount(name: string): Promise<ServiceAccount> {
|
|
186
|
-
return (await getGlobalContext()).serviceAccount(name)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ============================================================================
|
|
190
|
-
// Event Handlers
|
|
191
|
-
// ============================================================================
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Register a storage event handler.
|
|
195
|
-
*
|
|
196
|
-
* @param bucket - Bucket name
|
|
197
|
-
* @param handler - Event handler
|
|
198
|
-
* @param options - Handler options
|
|
199
|
-
* @returns Unsubscribe function
|
|
200
|
-
*
|
|
201
|
-
* @example
|
|
202
|
-
* ```typescript
|
|
203
|
-
* import { onStorageEvent } from "@alienplatform/sdk"
|
|
204
|
-
*
|
|
205
|
-
* onStorageEvent("uploads", async (event) => {
|
|
206
|
-
* console.log("File uploaded:", event.objectKey)
|
|
207
|
-
* })
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
export function onStorageEvent(
|
|
211
|
-
bucket: string,
|
|
212
|
-
handler: (event: StorageEvent) => Promise<void>,
|
|
213
|
-
options?: { prefix?: string },
|
|
214
|
-
): () => void {
|
|
215
|
-
return onStorageEventImpl(bucket, handler, options)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Register a cron event handler.
|
|
220
|
-
*
|
|
221
|
-
* @param schedule - Cron schedule expression
|
|
222
|
-
* @param handler - Event handler
|
|
223
|
-
* @returns Unsubscribe function
|
|
224
|
-
*
|
|
225
|
-
* @example
|
|
226
|
-
* ```typescript
|
|
227
|
-
* import { onCronEvent } from "@alienplatform/sdk"
|
|
228
|
-
*
|
|
229
|
-
* onCronEvent("0 * * * *", async (event) => {
|
|
230
|
-
* console.log("Hourly task running at:", event.timestamp)
|
|
231
|
-
* })
|
|
232
|
-
* ```
|
|
233
|
-
*/
|
|
234
|
-
export function onCronEvent(
|
|
235
|
-
schedule: string,
|
|
236
|
-
handler: (event: CronEvent) => Promise<void>,
|
|
237
|
-
): () => void {
|
|
238
|
-
return onCronEventImpl(schedule, handler)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Register a queue message handler.
|
|
243
|
-
*
|
|
244
|
-
* @param queueName - Queue name
|
|
245
|
-
* @param handler - Message handler
|
|
246
|
-
* @returns Unsubscribe function
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* import { onQueueMessage } from "@alienplatform/sdk"
|
|
251
|
-
*
|
|
252
|
-
* onQueueMessage("tasks", async (message) => {
|
|
253
|
-
* console.log("Processing:", message.payload)
|
|
254
|
-
* })
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
export function onQueueMessage<T = unknown>(
|
|
258
|
-
queueName: string,
|
|
259
|
-
handler: (message: QueueMessageEvent<T>) => Promise<void>,
|
|
260
|
-
): () => void {
|
|
261
|
-
return onQueueMessageImpl(queueName, handler)
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// ============================================================================
|
|
265
|
-
// WaitUntil
|
|
266
|
-
// ============================================================================
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Register a background task to continue after the response.
|
|
270
|
-
*
|
|
271
|
-
* @param promise - The promise to track
|
|
272
|
-
*
|
|
273
|
-
* @example
|
|
274
|
-
* ```typescript
|
|
275
|
-
* import { waitUntil } from "@alienplatform/sdk"
|
|
276
|
-
*
|
|
277
|
-
* export default {
|
|
278
|
-
* async fetch(request: Request): Promise<Response> {
|
|
279
|
-
* waitUntil(sendAnalytics(request))
|
|
280
|
-
* return Response.json({ status: "ok" })
|
|
281
|
-
* }
|
|
282
|
-
* }
|
|
283
|
-
* ```
|
|
284
|
-
*/
|
|
285
|
-
export function waitUntil(promise: Promise<unknown>): void {
|
|
286
|
-
waitUntilImpl(promise)
|
|
287
|
-
}
|
package/src/grpc-utils.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* gRPC utility functions for error handling and type conversion.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AlienError } from "@alienplatform/core"
|
|
6
|
-
import { Status } from "nice-grpc"
|
|
7
|
-
import {
|
|
8
|
-
BindingNotFoundError,
|
|
9
|
-
GrpcCallError,
|
|
10
|
-
KvInvalidKeyError,
|
|
11
|
-
KvInvalidValueError,
|
|
12
|
-
KvKeyNotFoundError,
|
|
13
|
-
SecretNotFoundError,
|
|
14
|
-
StorageObjectExistsError,
|
|
15
|
-
StorageObjectNotFoundError,
|
|
16
|
-
StoragePreconditionError,
|
|
17
|
-
} from "./errors.js"
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Convert a gRPC error to an AlienError with proper chaining.
|
|
21
|
-
*/
|
|
22
|
-
export async function grpcErrorToAlienError(
|
|
23
|
-
error: unknown,
|
|
24
|
-
service: string,
|
|
25
|
-
method: string,
|
|
26
|
-
context?: {
|
|
27
|
-
bindingName?: string
|
|
28
|
-
path?: string
|
|
29
|
-
key?: string
|
|
30
|
-
secretName?: string
|
|
31
|
-
bindingType?: string
|
|
32
|
-
},
|
|
33
|
-
): Promise<AlienError<any>> {
|
|
34
|
-
// Start with the original error wrapped as AlienError
|
|
35
|
-
const baseError = await AlienError.from(error)
|
|
36
|
-
|
|
37
|
-
// Handle nice-grpc errors
|
|
38
|
-
if (error && typeof error === "object" && "code" in error) {
|
|
39
|
-
const grpcError = error as { code: number; details?: string; message?: string }
|
|
40
|
-
const details = grpcError.details ?? grpcError.message ?? "Unknown error"
|
|
41
|
-
const code = grpcError.code
|
|
42
|
-
|
|
43
|
-
// Map specific gRPC status codes to domain errors
|
|
44
|
-
if (code === Status.NOT_FOUND) {
|
|
45
|
-
// Determine the appropriate not-found error based on context
|
|
46
|
-
if (context?.path && context?.bindingName) {
|
|
47
|
-
return baseError.withContext(
|
|
48
|
-
StorageObjectNotFoundError.create({
|
|
49
|
-
bindingName: context.bindingName,
|
|
50
|
-
path: context.path,
|
|
51
|
-
}),
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
if (context?.key && context?.bindingName) {
|
|
55
|
-
return baseError.withContext(
|
|
56
|
-
KvKeyNotFoundError.create({
|
|
57
|
-
bindingName: context.bindingName,
|
|
58
|
-
key: context.key,
|
|
59
|
-
}),
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
if (context?.secretName && context?.bindingName) {
|
|
63
|
-
return baseError.withContext(
|
|
64
|
-
SecretNotFoundError.create({
|
|
65
|
-
bindingName: context.bindingName,
|
|
66
|
-
secretName: context.secretName,
|
|
67
|
-
}),
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
if (context?.bindingName && context?.bindingType) {
|
|
71
|
-
return baseError.withContext(
|
|
72
|
-
BindingNotFoundError.create({
|
|
73
|
-
bindingName: context.bindingName,
|
|
74
|
-
bindingType: context.bindingType,
|
|
75
|
-
}),
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (code === Status.FAILED_PRECONDITION && context?.path && context?.bindingName) {
|
|
81
|
-
return baseError.withContext(
|
|
82
|
-
StoragePreconditionError.create({
|
|
83
|
-
bindingName: context.bindingName,
|
|
84
|
-
path: context.path,
|
|
85
|
-
condition: details,
|
|
86
|
-
}),
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (code === Status.ALREADY_EXISTS && context?.path && context?.bindingName) {
|
|
91
|
-
return baseError.withContext(
|
|
92
|
-
StorageObjectExistsError.create({
|
|
93
|
-
bindingName: context.bindingName,
|
|
94
|
-
path: context.path,
|
|
95
|
-
}),
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (code === Status.INVALID_ARGUMENT) {
|
|
100
|
-
if (context?.key) {
|
|
101
|
-
return baseError.withContext(
|
|
102
|
-
KvInvalidKeyError.create({
|
|
103
|
-
key: context.key,
|
|
104
|
-
reason: details,
|
|
105
|
-
}),
|
|
106
|
-
)
|
|
107
|
-
}
|
|
108
|
-
if (service === "KvService") {
|
|
109
|
-
return baseError.withContext(
|
|
110
|
-
KvInvalidValueError.create({
|
|
111
|
-
reason: details,
|
|
112
|
-
}),
|
|
113
|
-
)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Generic gRPC error
|
|
118
|
-
return baseError.withContext(
|
|
119
|
-
GrpcCallError.create({
|
|
120
|
-
service,
|
|
121
|
-
method,
|
|
122
|
-
grpcCode: Status[code] ?? String(code),
|
|
123
|
-
details,
|
|
124
|
-
}),
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Fallback for non-gRPC errors
|
|
129
|
-
return baseError.withContext(
|
|
130
|
-
GrpcCallError.create({
|
|
131
|
-
service,
|
|
132
|
-
method,
|
|
133
|
-
grpcCode: "UNKNOWN",
|
|
134
|
-
details: error instanceof Error ? error.message : String(error),
|
|
135
|
-
}),
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Wrap an async gRPC call with error handling.
|
|
141
|
-
*/
|
|
142
|
-
export async function wrapGrpcCall<T>(
|
|
143
|
-
service: string,
|
|
144
|
-
method: string,
|
|
145
|
-
call: () => Promise<T>,
|
|
146
|
-
context?: {
|
|
147
|
-
bindingName?: string
|
|
148
|
-
path?: string
|
|
149
|
-
key?: string
|
|
150
|
-
secretName?: string
|
|
151
|
-
bindingType?: string
|
|
152
|
-
},
|
|
153
|
-
): Promise<T> {
|
|
154
|
-
try {
|
|
155
|
-
return await call()
|
|
156
|
-
} catch (error) {
|
|
157
|
-
throw await grpcErrorToAlienError(error, service, method, context)
|
|
158
|
-
}
|
|
159
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @alienplatform/sdk - TypeScript SDK for Alien bindings.
|
|
3
|
-
*
|
|
4
|
-
* This package provides type-safe access to Alien resources including
|
|
5
|
-
* Storage, KV, Queue, Vault, Build, ArtifactRegistry, Worker, and ServiceAccount.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // Global convenience functions (most common usage)
|
|
10
|
-
* import { storage, kv, onStorageEvent, waitUntil } from "@alienplatform/sdk"
|
|
11
|
-
*
|
|
12
|
-
* const bucket = storage("my-bucket")
|
|
13
|
-
* await bucket.put("hello.txt", "Hello, World!")
|
|
14
|
-
*
|
|
15
|
-
* // Or use AlienContext for more control
|
|
16
|
-
* import { AlienContext } from "@alienplatform/sdk"
|
|
17
|
-
*
|
|
18
|
-
* const ctx = AlienContext.fromEnv()
|
|
19
|
-
* const bucket = ctx.storage("my-bucket")
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @packageDocumentation
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Main Entry Point
|
|
27
|
-
// ============================================================================
|
|
28
|
-
|
|
29
|
-
export { AlienContext } from "./context.js"
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// Global Convenience Bindings
|
|
33
|
-
// ============================================================================
|
|
34
|
-
|
|
35
|
-
export {
|
|
36
|
-
// Binding accessors
|
|
37
|
-
storage,
|
|
38
|
-
kv,
|
|
39
|
-
queue,
|
|
40
|
-
vault,
|
|
41
|
-
build,
|
|
42
|
-
artifactRegistry,
|
|
43
|
-
worker,
|
|
44
|
-
serviceAccount,
|
|
45
|
-
// Event handlers
|
|
46
|
-
onStorageEvent,
|
|
47
|
-
onCronEvent,
|
|
48
|
-
onQueueMessage,
|
|
49
|
-
// WaitUntil
|
|
50
|
-
waitUntil,
|
|
51
|
-
} from "./global.js"
|
|
52
|
-
|
|
53
|
-
// Event types - StorageEvent, QueueMessage, ScheduledEvent come from @alienplatform/core
|
|
54
|
-
// CronEvent and QueueMessageEvent are bindings-specific extensions
|
|
55
|
-
export type {
|
|
56
|
-
StorageEvent,
|
|
57
|
-
StorageEventType,
|
|
58
|
-
QueueMessage,
|
|
59
|
-
ScheduledEvent,
|
|
60
|
-
CronEvent,
|
|
61
|
-
QueueMessageEvent,
|
|
62
|
-
} from "./events.js"
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Binding Classes (for advanced usage)
|
|
66
|
-
// ============================================================================
|
|
67
|
-
|
|
68
|
-
export { Storage } from "./bindings/storage.js"
|
|
69
|
-
export { Kv } from "./bindings/kv.js"
|
|
70
|
-
export { Queue } from "./bindings/queue.js"
|
|
71
|
-
export { Vault } from "./bindings/vault.js"
|
|
72
|
-
export { Build } from "./bindings/build.js"
|
|
73
|
-
export { ArtifactRegistry } from "./bindings/artifact-registry.js"
|
|
74
|
-
export { WorkerBinding } from "./bindings/worker.js"
|
|
75
|
-
export { ServiceAccount } from "./bindings/service-account.js"
|
|
76
|
-
|
|
77
|
-
// Postgres is connection-only (no gRPC service): a function that resolves connection
|
|
78
|
-
// details for a linked database, not a channel-backed binding class.
|
|
79
|
-
export { getPostgresConnection, type PostgresConnection } from "./bindings/postgres.js"
|
|
80
|
-
|
|
81
|
-
// ============================================================================
|
|
82
|
-
// Types
|
|
83
|
-
// ============================================================================
|
|
84
|
-
|
|
85
|
-
export type {
|
|
86
|
-
// Storage
|
|
87
|
-
StorageGetOptions,
|
|
88
|
-
StoragePutOptions,
|
|
89
|
-
StorageObjectMeta,
|
|
90
|
-
StorageGetResult,
|
|
91
|
-
StorageListResult,
|
|
92
|
-
SignedUrlOptions,
|
|
93
|
-
SignedUrlResult,
|
|
94
|
-
// KV
|
|
95
|
-
KvPutOptions,
|
|
96
|
-
KvScanResult,
|
|
97
|
-
// Queue
|
|
98
|
-
ReceivedQueueMessage,
|
|
99
|
-
// Build (BuildStatus and ComputeType come from @alienplatform/core)
|
|
100
|
-
BuildStartConfig,
|
|
101
|
-
BuildExecution,
|
|
102
|
-
// Artifact Registry
|
|
103
|
-
ArtifactRegistryPermissions,
|
|
104
|
-
RepositoryInfo,
|
|
105
|
-
ArtifactRegistryCredentials,
|
|
106
|
-
RegistryAuthMethod,
|
|
107
|
-
ComputeServiceType,
|
|
108
|
-
AwsCrossAccountAccess,
|
|
109
|
-
GcpCrossAccountAccess,
|
|
110
|
-
CrossAccountAccess,
|
|
111
|
-
CrossAccountPermissions,
|
|
112
|
-
// Worker
|
|
113
|
-
WorkerInvokeRequest,
|
|
114
|
-
WorkerInvokeResponse,
|
|
115
|
-
// Service Account
|
|
116
|
-
ServiceAccountInfo,
|
|
117
|
-
AwsServiceAccountInfo,
|
|
118
|
-
GcpServiceAccountInfo,
|
|
119
|
-
AzureServiceAccountInfo,
|
|
120
|
-
ImpersonationRequest,
|
|
121
|
-
// Configuration
|
|
122
|
-
AlienBindingsConfig,
|
|
123
|
-
AlienBindingsProvider,
|
|
124
|
-
} from "./types.js"
|
|
125
|
-
|
|
126
|
-
// ============================================================================
|
|
127
|
-
// Errors
|
|
128
|
-
// ============================================================================
|
|
129
|
-
|
|
130
|
-
export {
|
|
131
|
-
GrpcConnectionError,
|
|
132
|
-
GrpcCallError,
|
|
133
|
-
BindingNotFoundError,
|
|
134
|
-
ContextNotInitializedError,
|
|
135
|
-
MissingEnvVarError,
|
|
136
|
-
StorageObjectNotFoundError,
|
|
137
|
-
StoragePreconditionError,
|
|
138
|
-
StorageObjectExistsError,
|
|
139
|
-
KvKeyNotFoundError,
|
|
140
|
-
KvInvalidKeyError,
|
|
141
|
-
KvInvalidValueError,
|
|
142
|
-
SecretNotFoundError,
|
|
143
|
-
QueueOperationError,
|
|
144
|
-
EventHandlerAlreadyRegisteredError,
|
|
145
|
-
CommandAlreadyRegisteredError,
|
|
146
|
-
InvalidBindingConfigError,
|
|
147
|
-
PostgresSecretResolutionError,
|
|
148
|
-
} from "./errors.js"
|
|
149
|
-
|
|
150
|
-
// ============================================================================
|
|
151
|
-
// Commands
|
|
152
|
-
// ============================================================================
|
|
153
|
-
|
|
154
|
-
export { command, runCommand, getCommands, type CommandDefinition } from "./commands.js"
|
|
155
|
-
|
|
156
|
-
// ============================================================================
|
|
157
|
-
// Re-export from core for convenience
|
|
158
|
-
// ============================================================================
|
|
159
|
-
|
|
160
|
-
// Note: BuildStatus, ComputeType are re-exported via types.ts
|