@alienplatform/bindings 1.0.0 → 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.
Files changed (56) hide show
  1. package/LICENSE.md +105 -0
  2. package/README.md +59 -0
  3. package/dist/errors.d.ts +56 -0
  4. package/dist/errors.d.ts.map +1 -0
  5. package/dist/factories.d.ts +26 -0
  6. package/dist/factories.d.ts.map +1 -0
  7. package/dist/index.d.ts +19 -1768
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +23 -44772
  10. package/dist/loader.d.ts +171 -0
  11. package/dist/loader.d.ts.map +1 -0
  12. package/dist/loader.js +3712 -0
  13. package/dist/native.d.ts +41 -0
  14. package/dist/native.d.ts.map +1 -0
  15. package/dist/native.js +46 -0
  16. package/dist/types.d.ts +150 -0
  17. package/dist/types.d.ts.map +1 -0
  18. package/package.json +39 -21
  19. package/AGENTS.md +0 -70
  20. package/dist/index.js.map +0 -1
  21. package/scripts/generate-proto.sh +0 -46
  22. package/src/bindings/AGENTS.md +0 -105
  23. package/src/bindings/artifact-registry.ts +0 -314
  24. package/src/bindings/build.ts +0 -195
  25. package/src/bindings/function.ts +0 -164
  26. package/src/bindings/index.ts +0 -12
  27. package/src/bindings/kv.ts +0 -240
  28. package/src/bindings/queue.ts +0 -191
  29. package/src/bindings/service-account.ts +0 -113
  30. package/src/bindings/storage.ts +0 -535
  31. package/src/bindings/vault.ts +0 -133
  32. package/src/channel.ts +0 -94
  33. package/src/commands.ts +0 -76
  34. package/src/context.ts +0 -368
  35. package/src/errors.ts +0 -259
  36. package/src/events.ts +0 -463
  37. package/src/generated/artifact_registry.ts +0 -1934
  38. package/src/generated/build.ts +0 -1263
  39. package/src/generated/container.ts +0 -485
  40. package/src/generated/control.ts +0 -1574
  41. package/src/generated/function.ts +0 -741
  42. package/src/generated/google/protobuf/duration.ts +0 -196
  43. package/src/generated/google/protobuf/timestamp.ts +0 -225
  44. package/src/generated/kv.ts +0 -1137
  45. package/src/generated/queue.ts +0 -729
  46. package/src/generated/service_account.ts +0 -766
  47. package/src/generated/storage.ts +0 -3653
  48. package/src/generated/vault.ts +0 -519
  49. package/src/generated/wait_until.ts +0 -781
  50. package/src/global.ts +0 -316
  51. package/src/grpc-utils.ts +0 -159
  52. package/src/index.ts +0 -156
  53. package/src/types.ts +0 -384
  54. package/src/wait-until.ts +0 -257
  55. package/tsconfig.json +0 -8
  56. package/tsdown.config.ts +0 -14
package/src/types.ts DELETED
@@ -1,384 +0,0 @@
1
- /**
2
- * Common types for the Alien bindings SDK.
3
- */
4
-
5
- // Re-export build types from core
6
- export type { BuildStatus, ComputeType } from "@alienplatform/core"
7
-
8
- /**
9
- * Branded type for binding names.
10
- */
11
- export type BindingName = string & { readonly __brand: unique symbol }
12
-
13
- // ============================================================================
14
- // Storage Types
15
- // ============================================================================
16
-
17
- /**
18
- * Options for storage get operations.
19
- */
20
- export interface StorageGetOptions {
21
- /** Range start offset in bytes */
22
- rangeStart?: number
23
- /** Range end offset in bytes */
24
- rangeEnd?: number
25
- /** If-Match header value (ETag) */
26
- ifMatch?: string
27
- /** If-None-Match header value (ETag) */
28
- ifNoneMatch?: string
29
- /** If-Modified-Since timestamp */
30
- ifModifiedSince?: Date
31
- /** If-Unmodified-Since timestamp */
32
- ifUnmodifiedSince?: Date
33
- }
34
-
35
- /**
36
- * Options for storage put operations.
37
- */
38
- export interface StoragePutOptions {
39
- /** Content type of the object */
40
- contentType?: string
41
- /** Custom metadata */
42
- metadata?: Record<string, string>
43
- /** Only write if the object doesn't already exist */
44
- ifNotExists?: boolean
45
- }
46
-
47
- /**
48
- * Object metadata from storage.
49
- */
50
- export interface StorageObjectMeta {
51
- /** Full path of the object */
52
- location: string
53
- /** Last modified timestamp */
54
- lastModified?: Date
55
- /** Object size in bytes */
56
- size: number
57
- /** ETag (entity tag) for the object */
58
- etag?: string
59
- /** Object version */
60
- version?: string
61
- }
62
-
63
- /**
64
- * Result of a storage get operation.
65
- */
66
- export interface StorageGetResult {
67
- /** Object metadata */
68
- meta: StorageObjectMeta
69
- /** Object data as bytes */
70
- data: Uint8Array
71
- }
72
-
73
- /**
74
- * Result of a storage list operation with delimiter.
75
- */
76
- export interface StorageListResult {
77
- /** Common prefixes (directories) */
78
- commonPrefixes: string[]
79
- /** Object metadata entries */
80
- objects: StorageObjectMeta[]
81
- }
82
-
83
- /**
84
- * Options for signed URL generation.
85
- */
86
- export interface SignedUrlOptions {
87
- /** Operation type: get (download), put (upload), or delete */
88
- operation: "get" | "put" | "delete"
89
- /** URL expiration duration in seconds */
90
- expiresInSeconds?: number
91
- /** Content type for put operations */
92
- contentType?: string
93
- }
94
-
95
- /**
96
- * Result of signed URL generation.
97
- */
98
- export interface SignedUrlResult {
99
- /** The signed URL */
100
- url: string
101
- /** URL expiration timestamp */
102
- expiresAt?: Date
103
- }
104
-
105
- // ============================================================================
106
- // KV Types
107
- // ============================================================================
108
-
109
- /**
110
- * Options for KV put operations.
111
- */
112
- export interface KvPutOptions {
113
- /** Time-to-live in milliseconds */
114
- ttlMs?: number
115
- /** Only write if the key doesn't exist */
116
- ifNotExists?: boolean
117
- }
118
-
119
- /**
120
- * Result of a KV scan operation.
121
- */
122
- export interface KvScanResult {
123
- /** Key-value pairs */
124
- items: Array<{ key: string; value: Uint8Array }>
125
- /** Cursor for next page */
126
- nextCursor?: string
127
- }
128
-
129
- // ============================================================================
130
- // Queue Types
131
- // ============================================================================
132
-
133
- /**
134
- * A message received from a queue via the Queue binding.
135
- * (Not to be confused with QueueMessage from @alienplatform/core which is used for event handlers)
136
- */
137
- export interface ReceivedQueueMessage<T = unknown> {
138
- /** Message payload */
139
- payload: T
140
- /** Receipt handle for acknowledgment */
141
- receiptHandle: string
142
- }
143
-
144
- // ============================================================================
145
- // Build Types
146
- // ============================================================================
147
-
148
- // BuildStatus and ComputeType are re-exported from @alienplatform/core above
149
-
150
- /**
151
- * Configuration for starting a build via the Build binding.
152
- * (SDK-specific - different from BuildConfig in core which is for resource definition)
153
- */
154
- export interface BuildStartConfig {
155
- /** Build script to execute */
156
- script: string
157
- /** Environment variables */
158
- environment?: Record<string, string>
159
- /** Compute type */
160
- computeType?: import("@alienplatform/core").ComputeType
161
- /** Timeout in seconds */
162
- timeoutSeconds?: number
163
- /** Monitoring configuration */
164
- monitoring?: {
165
- endpoint: string
166
- headers?: Record<string, string>
167
- logsUri?: string
168
- tlsEnabled?: boolean
169
- tlsVerify?: boolean
170
- }
171
- }
172
-
173
- /**
174
- * Information about a build execution.
175
- */
176
- export interface BuildExecution {
177
- /** Build execution ID */
178
- id: string
179
- /** Current status */
180
- status: import("@alienplatform/core").BuildStatus
181
- /** Start timestamp */
182
- startTime?: Date
183
- /** End timestamp */
184
- endTime?: Date
185
- }
186
-
187
- // ============================================================================
188
- // Artifact Registry Types
189
- // ============================================================================
190
-
191
- /**
192
- * Permission levels for artifact registry access.
193
- */
194
- export type ArtifactRegistryPermissions = "pull" | "push-pull"
195
-
196
- /**
197
- * Information about a repository.
198
- */
199
- export interface RepositoryInfo {
200
- /** Repository name */
201
- name: string
202
- /** Repository URI */
203
- uri: string
204
- /** Creation timestamp */
205
- createdAt?: Date
206
- }
207
-
208
- /**
209
- * Credentials for repository access.
210
- */
211
- export interface ArtifactRegistryCredentials {
212
- /** Username for authentication */
213
- username: string
214
- /** Password/token for authentication */
215
- password: string
216
- /** Credential expiration timestamp */
217
- expiresAt?: Date
218
- }
219
-
220
- /**
221
- * Types of compute services that can have cross-account access.
222
- */
223
- export type ComputeServiceType = "function"
224
-
225
- /**
226
- * AWS-specific cross-account access configuration.
227
- */
228
- export interface AwsCrossAccountAccess {
229
- /** AWS account IDs that should have access */
230
- accountIds: string[]
231
- /** Types of compute services that should have access */
232
- allowedServiceTypes: ComputeServiceType[]
233
- /** Specific IAM role ARNs to grant access to */
234
- roleArns: string[]
235
- }
236
-
237
- /**
238
- * GCP-specific cross-account access configuration.
239
- */
240
- export interface GcpCrossAccountAccess {
241
- /** GCP project numbers that should have access */
242
- projectNumbers: string[]
243
- /** Types of compute services that should have access */
244
- allowedServiceTypes: ComputeServiceType[]
245
- /** Additional service account emails to grant access to */
246
- serviceAccountEmails: string[]
247
- }
248
-
249
- /**
250
- * Cross-account access configuration (discriminated union).
251
- */
252
- export type CrossAccountAccess =
253
- | { type: "aws"; aws: AwsCrossAccountAccess }
254
- | { type: "gcp"; gcp: GcpCrossAccountAccess }
255
-
256
- /**
257
- * Current cross-account access permissions.
258
- */
259
- export interface CrossAccountPermissions {
260
- /** Platform-specific access configuration */
261
- access: CrossAccountAccess
262
- /** Timestamp when permissions were last updated (ISO8601 format) */
263
- lastUpdated?: string
264
- }
265
-
266
- // ============================================================================
267
- // Function Types
268
- // ============================================================================
269
-
270
- /**
271
- * Request for function invocation.
272
- */
273
- export interface FunctionInvokeRequest {
274
- /** Target function identifier */
275
- targetFunction: string
276
- /** HTTP method */
277
- method: string
278
- /** Request path */
279
- path: string
280
- /** Request headers */
281
- headers?: Record<string, string>
282
- /** Request body */
283
- body?: Uint8Array
284
- /** Timeout in milliseconds */
285
- timeoutMs?: number
286
- }
287
-
288
- /**
289
- * Response from function invocation.
290
- */
291
- export interface FunctionInvokeResponse {
292
- /** HTTP status code */
293
- status: number
294
- /** Response headers */
295
- headers: Record<string, string>
296
- /** Response body */
297
- body: Uint8Array
298
- }
299
-
300
- // ============================================================================
301
- // Service Account Types
302
- // ============================================================================
303
-
304
- /**
305
- * AWS service account information.
306
- */
307
- export interface AwsServiceAccountInfo {
308
- platform: "aws"
309
- roleName: string
310
- roleArn: string
311
- }
312
-
313
- /**
314
- * GCP service account information.
315
- */
316
- export interface GcpServiceAccountInfo {
317
- platform: "gcp"
318
- email: string
319
- uniqueId: string
320
- }
321
-
322
- /**
323
- * Azure service account information.
324
- */
325
- export interface AzureServiceAccountInfo {
326
- platform: "azure"
327
- clientId: string
328
- resourceId: string
329
- principalId: string
330
- }
331
-
332
- /**
333
- * Platform-specific service account information.
334
- */
335
- export type ServiceAccountInfo =
336
- | AwsServiceAccountInfo
337
- | GcpServiceAccountInfo
338
- | AzureServiceAccountInfo
339
-
340
- /**
341
- * Request for service account impersonation.
342
- */
343
- export interface ImpersonationRequest {
344
- /** Session name for AWS */
345
- sessionName?: string
346
- /** Duration in seconds */
347
- durationSeconds?: number
348
- /** OAuth scopes for GCP */
349
- scopes?: string[]
350
- }
351
-
352
- // ============================================================================
353
- // Configuration Types
354
- // ============================================================================
355
-
356
- /**
357
- * Configuration for connecting to the Alien bindings server.
358
- */
359
- export interface AlienBindingsConfig {
360
- /** gRPC server address */
361
- grpcAddress?: string
362
- }
363
-
364
- /**
365
- * Interface for the bindings provider.
366
- */
367
- export interface AlienBindingsProvider {
368
- /** Get a storage binding */
369
- storage(name: string): import("./bindings/storage.js").Storage
370
- /** Get a KV binding */
371
- kv(name: string): import("./bindings/kv.js").Kv
372
- /** Get a queue binding */
373
- queue(name: string): import("./bindings/queue.js").Queue
374
- /** Get a vault binding */
375
- vault(name: string): import("./bindings/vault.js").Vault
376
- /** Get a build binding */
377
- build(name: string): import("./bindings/build.js").Build
378
- /** Get an artifact registry binding */
379
- artifactRegistry(name: string): import("./bindings/artifact-registry.js").ArtifactRegistry
380
- /** Get a function binding */
381
- func(name: string): import("./bindings/function.js").FunctionBinding
382
- /** Get a service account binding */
383
- serviceAccount(name: string): import("./bindings/service-account.js").ServiceAccount
384
- }
package/src/wait-until.ts DELETED
@@ -1,257 +0,0 @@
1
- /**
2
- * WaitUntil functionality for background task management.
3
- *
4
- * Allows functions to continue running after the response has been sent.
5
- */
6
-
7
- import { type Channel, createClient } from "nice-grpc"
8
- import {
9
- type WaitUntilServiceClient as GeneratedClient,
10
- WaitUntilServiceDefinition,
11
- } from "./generated/wait_until.js"
12
- import { wrapGrpcCall } from "./grpc-utils.js"
13
-
14
- /**
15
- * Task tracker for managing background tasks.
16
- */
17
- export interface TaskTracker {
18
- /** Unique task ID */
19
- id: string
20
- /** Task promise */
21
- promise: Promise<unknown>
22
- /** When the task was registered */
23
- registeredAt: Date
24
- /** Whether the task has completed */
25
- completed: boolean
26
- /** Error if the task failed */
27
- error?: Error
28
- }
29
-
30
- // Internal storage for tracked tasks
31
- const tasks: Map<string, TaskTracker> = new Map()
32
- let taskIdCounter = 0
33
-
34
- /**
35
- * WaitUntil manager for coordinating background tasks with the runtime.
36
- *
37
- * @internal
38
- */
39
- export class WaitUntilManager {
40
- private readonly client: GeneratedClient
41
- private readonly applicationId: string
42
-
43
- constructor(channel: Channel, applicationId: string) {
44
- this.client = createClient(WaitUntilServiceDefinition, channel)
45
- this.applicationId = applicationId
46
- }
47
-
48
- /**
49
- * Register a background task.
50
- *
51
- * @param promise - The promise to track
52
- * @param description - Optional task description for debugging
53
- * @returns Task tracker
54
- */
55
- async register(promise: Promise<unknown>, description?: string): Promise<TaskTracker> {
56
- const id = `task-${++taskIdCounter}`
57
- const registeredAt = new Date()
58
-
59
- const tracker: TaskTracker = {
60
- id,
61
- promise,
62
- registeredAt,
63
- completed: false,
64
- }
65
-
66
- tasks.set(id, tracker)
67
-
68
- // Notify the runtime about the new task
69
- await wrapGrpcCall(
70
- "WaitUntilService",
71
- "NotifyTaskRegistered",
72
- async () => {
73
- await this.client.notifyTaskRegistered({
74
- applicationId: this.applicationId,
75
- taskDescription: description,
76
- })
77
- },
78
- {},
79
- )
80
-
81
- // Track completion
82
- promise
83
- .then(() => {
84
- tracker.completed = true
85
- })
86
- .catch(error => {
87
- tracker.completed = true
88
- tracker.error = error instanceof Error ? error : new Error(String(error))
89
- })
90
-
91
- return tracker
92
- }
93
-
94
- /**
95
- * Wait for all background tasks to complete.
96
- *
97
- * Called during drain to ensure all tasks finish before shutdown.
98
- */
99
- async waitForAll(): Promise<void> {
100
- const pending = Array.from(tasks.values())
101
- .filter(t => !t.completed)
102
- .map(t => t.promise.catch(() => {}))
103
-
104
- await Promise.all(pending)
105
- }
106
-
107
- /**
108
- * Get the current task count.
109
- */
110
- async getTaskCount(): Promise<number> {
111
- return await wrapGrpcCall(
112
- "WaitUntilService",
113
- "GetTaskCount",
114
- async () => {
115
- const response = await this.client.getTaskCount({
116
- applicationId: this.applicationId,
117
- })
118
- return response.taskCount
119
- },
120
- {},
121
- )
122
- }
123
-
124
- /**
125
- * Wait for a drain signal from the runtime.
126
- *
127
- * This blocks until the runtime signals that it's time to drain.
128
- */
129
- async waitForDrainSignal(): Promise<{
130
- shouldDrain: boolean
131
- drainReason: string
132
- }> {
133
- return await wrapGrpcCall(
134
- "WaitUntilService",
135
- "WaitForDrainSignal",
136
- async () => {
137
- const response = await this.client.waitForDrainSignal({
138
- applicationId: this.applicationId,
139
- timeout: undefined,
140
- })
141
- return {
142
- shouldDrain: response.shouldDrain,
143
- drainReason: response.drainReason,
144
- }
145
- },
146
- {},
147
- )
148
- }
149
-
150
- /**
151
- * Notify the runtime that drain is complete.
152
- *
153
- * @param tasksDrained - Number of tasks that were drained
154
- * @param success - Whether all tasks completed successfully
155
- * @param errorMessage - Optional error message if draining failed
156
- */
157
- async notifyDrainComplete(
158
- tasksDrained: number,
159
- success: boolean,
160
- errorMessage?: string,
161
- ): Promise<void> {
162
- await wrapGrpcCall(
163
- "WaitUntilService",
164
- "NotifyDrainComplete",
165
- async () => {
166
- await this.client.notifyDrainComplete({
167
- applicationId: this.applicationId,
168
- tasksDrained,
169
- success,
170
- errorMessage,
171
- })
172
- },
173
- {},
174
- )
175
- }
176
-
177
- /**
178
- * Get all tracked tasks.
179
- */
180
- getTasks(): Map<string, TaskTracker> {
181
- return tasks
182
- }
183
-
184
- /**
185
- * Clear all completed tasks.
186
- */
187
- clearCompleted(): void {
188
- for (const [id, tracker] of tasks) {
189
- if (tracker.completed) {
190
- tasks.delete(id)
191
- }
192
- }
193
- }
194
- }
195
-
196
- // Global wait-until manager instance
197
- let globalManager: WaitUntilManager | undefined
198
-
199
- /**
200
- * Initialize the global wait-until manager.
201
- *
202
- * @internal
203
- */
204
- export function initWaitUntilManager(channel: Channel, applicationId: string): WaitUntilManager {
205
- globalManager = new WaitUntilManager(channel, applicationId)
206
- return globalManager
207
- }
208
-
209
- /**
210
- * Get the global wait-until manager.
211
- *
212
- * @internal
213
- */
214
- export function getWaitUntilManager(): WaitUntilManager | undefined {
215
- return globalManager
216
- }
217
-
218
- /**
219
- * Register a background task to continue after the response.
220
- *
221
- * This allows your function to return a response while continuing
222
- * to do work in the background. The runtime will wait for all
223
- * registered tasks to complete before shutting down.
224
- *
225
- * @param promise - The promise to track
226
- *
227
- * @example
228
- * ```typescript
229
- * import { waitUntil } from "@alienplatform/bindings"
230
- *
231
- * export default {
232
- * async fetch(request: Request): Promise<Response> {
233
- * const data = await request.json()
234
- *
235
- * // Start background work
236
- * waitUntil(sendAnalytics(data))
237
- * waitUntil(updateCache(data))
238
- *
239
- * // Return immediately
240
- * return Response.json({ status: "accepted" })
241
- * }
242
- * }
243
- * ```
244
- */
245
- export function waitUntil(promise: Promise<unknown>): void {
246
- if (!globalManager) {
247
- // If no manager, just track locally
248
- promise.catch(error => {
249
- console.error("Background task failed:", error)
250
- })
251
- return
252
- }
253
-
254
- globalManager.register(promise).catch(error => {
255
- console.error("Failed to register background task:", error)
256
- })
257
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "@alienplatform/typescript-config/base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src"
6
- },
7
- "include": ["src/**/*"]
8
- }
package/tsdown.config.ts DELETED
@@ -1,14 +0,0 @@
1
- import { defineConfig } from "tsdown"
2
-
3
- export default defineConfig({
4
- entry: ["src/index.ts"],
5
- dts: {
6
- sourcemap: true,
7
- },
8
- hash: false,
9
- ignoreWatch: ".turbo",
10
- // Bundle all dependencies so the package is self-contained.
11
- // This allows bun build --compile to work without needing
12
- // transitive dependencies installed in the user's project.
13
- noExternal: [/.*/],
14
- })