@alienplatform/sdk 1.14.1 → 2.0.1

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 (160) hide show
  1. package/dist/dist.js +371 -275
  2. package/dist/index.d.ts +22 -28
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -14356
  5. package/dist/native.d.ts +26 -0
  6. package/dist/native.d.ts.map +1 -0
  7. package/dist/native.js +2 -0
  8. package/dist/worker-runtime/channel.d.ts +25 -0
  9. package/dist/worker-runtime/channel.d.ts.map +1 -0
  10. package/dist/worker-runtime/errors.d.ts +79 -0
  11. package/dist/worker-runtime/errors.d.ts.map +1 -0
  12. package/dist/worker-runtime/event-loop.d.ts +43 -0
  13. package/dist/worker-runtime/event-loop.d.ts.map +1 -0
  14. package/dist/{generated → worker-runtime/generated}/control.d.ts +15 -15
  15. package/dist/worker-runtime/generated/control.d.ts.map +1 -0
  16. package/dist/worker-runtime/generated/google/protobuf/duration.d.ts.map +1 -0
  17. package/dist/worker-runtime/generated/google/protobuf/timestamp.d.ts.map +1 -0
  18. package/dist/{generated → worker-runtime/generated}/wait_until.d.ts +29 -29
  19. package/dist/worker-runtime/generated/wait_until.d.ts.map +1 -0
  20. package/dist/worker-runtime/grpc-utils.d.ts +23 -0
  21. package/dist/worker-runtime/grpc-utils.d.ts.map +1 -0
  22. package/dist/worker-runtime/index.d.ts +33 -0
  23. package/dist/worker-runtime/index.d.ts.map +1 -0
  24. package/dist/{src.js → worker-runtime/index.js} +9370 -4035
  25. package/dist/worker-runtime/registry.d.ts +169 -0
  26. package/dist/worker-runtime/registry.d.ts.map +1 -0
  27. package/dist/worker-runtime/service-definitions.d.ts +12 -0
  28. package/dist/worker-runtime/service-definitions.d.ts.map +1 -0
  29. package/dist/worker-runtime/wait-until-manager.d.ts +34 -0
  30. package/dist/worker-runtime/wait-until-manager.d.ts.map +1 -0
  31. package/package.json +18 -38
  32. package/.turbo/turbo-build.log +0 -30
  33. package/AGENTS.md +0 -70
  34. package/dist/bearerTokenAuthenticationPolicy.js +0 -3028
  35. package/dist/bindings/artifact-registry.d.ts +0 -88
  36. package/dist/bindings/artifact-registry.d.ts.map +0 -1
  37. package/dist/bindings/build.d.ts +0 -67
  38. package/dist/bindings/build.d.ts.map +0 -1
  39. package/dist/bindings/index.d.ts +0 -13
  40. package/dist/bindings/index.d.ts.map +0 -1
  41. package/dist/bindings/kv.d.ts +0 -113
  42. package/dist/bindings/kv.d.ts.map +0 -1
  43. package/dist/bindings/postgres.d.ts +0 -90
  44. package/dist/bindings/postgres.d.ts.map +0 -1
  45. package/dist/bindings/postgres.test.d.ts +0 -2
  46. package/dist/bindings/postgres.test.d.ts.map +0 -1
  47. package/dist/bindings/queue.d.ts +0 -81
  48. package/dist/bindings/queue.d.ts.map +0 -1
  49. package/dist/bindings/service-account.d.ts +0 -46
  50. package/dist/bindings/service-account.d.ts.map +0 -1
  51. package/dist/bindings/storage.d.ts +0 -164
  52. package/dist/bindings/storage.d.ts.map +0 -1
  53. package/dist/bindings/vault.d.ts +0 -65
  54. package/dist/bindings/vault.d.ts.map +0 -1
  55. package/dist/bindings/worker.d.ts +0 -72
  56. package/dist/bindings/worker.d.ts.map +0 -1
  57. package/dist/channel.d.ts +0 -39
  58. package/dist/channel.d.ts.map +0 -1
  59. package/dist/checksum.js +0 -6176
  60. package/dist/commands/client.d.ts +0 -47
  61. package/dist/commands/client.d.ts.map +0 -1
  62. package/dist/commands/errors.d.ts +0 -198
  63. package/dist/commands/errors.d.ts.map +0 -1
  64. package/dist/commands/index.d.ts +0 -23
  65. package/dist/commands/index.d.ts.map +0 -1
  66. package/dist/commands/index.js +0 -387
  67. package/dist/commands/types.d.ts +0 -40
  68. package/dist/commands/types.d.ts.map +0 -1
  69. package/dist/commands.d.ts +0 -55
  70. package/dist/commands.d.ts.map +0 -1
  71. package/dist/context.d.ts +0 -182
  72. package/dist/context.d.ts.map +0 -1
  73. package/dist/dist-cjs.js +0 -15258
  74. package/dist/dist2.js +0 -1239
  75. package/dist/errors.d.ts +0 -359
  76. package/dist/errors.d.ts.map +0 -1
  77. package/dist/es5.js +0 -1720
  78. package/dist/esm.js +0 -18068
  79. package/dist/esm2.js +0 -3166
  80. package/dist/event-streams.js +0 -770
  81. package/dist/events.d.ts +0 -163
  82. package/dist/events.d.ts.map +0 -1
  83. package/dist/generated/artifact_registry.d.ts +0 -302
  84. package/dist/generated/artifact_registry.d.ts.map +0 -1
  85. package/dist/generated/build.d.ts +0 -184
  86. package/dist/generated/build.d.ts.map +0 -1
  87. package/dist/generated/container.d.ts +0 -101
  88. package/dist/generated/container.d.ts.map +0 -1
  89. package/dist/generated/control.d.ts.map +0 -1
  90. package/dist/generated/google/protobuf/duration.d.ts.map +0 -1
  91. package/dist/generated/google/protobuf/timestamp.d.ts.map +0 -1
  92. package/dist/generated/kv.d.ts +0 -182
  93. package/dist/generated/kv.d.ts.map +0 -1
  94. package/dist/generated/queue.d.ts +0 -127
  95. package/dist/generated/queue.d.ts.map +0 -1
  96. package/dist/generated/service_account.d.ts +0 -112
  97. package/dist/generated/service_account.d.ts.map +0 -1
  98. package/dist/generated/storage.d.ts +0 -784
  99. package/dist/generated/storage.d.ts.map +0 -1
  100. package/dist/generated/vault.d.ts +0 -107
  101. package/dist/generated/vault.d.ts.map +0 -1
  102. package/dist/generated/wait_until.d.ts.map +0 -1
  103. package/dist/generated/worker.d.ts +0 -107
  104. package/dist/generated/worker.d.ts.map +0 -1
  105. package/dist/global.d.ts +0 -208
  106. package/dist/global.d.ts.map +0 -1
  107. package/dist/grpc-utils.d.ts +0 -25
  108. package/dist/grpc-utils.d.ts.map +0 -1
  109. package/dist/jws.js +0 -611
  110. package/dist/open.js +0 -461
  111. package/dist/rolldown-runtime.js +0 -44
  112. package/dist/src2.js +0 -114032
  113. package/dist/types.d.ts +0 -337
  114. package/dist/types.d.ts.map +0 -1
  115. package/dist/wait-until.d.ts +0 -115
  116. package/dist/wait-until.d.ts.map +0 -1
  117. package/scripts/generate-proto.sh +0 -46
  118. package/src/bindings/AGENTS.md +0 -105
  119. package/src/bindings/artifact-registry.ts +0 -317
  120. package/src/bindings/build.ts +0 -195
  121. package/src/bindings/index.ts +0 -13
  122. package/src/bindings/kv.ts +0 -240
  123. package/src/bindings/postgres.test.ts +0 -17
  124. package/src/bindings/postgres.ts +0 -446
  125. package/src/bindings/queue.ts +0 -191
  126. package/src/bindings/service-account.ts +0 -113
  127. package/src/bindings/storage.ts +0 -536
  128. package/src/bindings/vault.ts +0 -133
  129. package/src/bindings/worker.ts +0 -164
  130. package/src/channel.ts +0 -102
  131. package/src/commands/client.ts +0 -446
  132. package/src/commands/errors.ts +0 -126
  133. package/src/commands/index.ts +0 -41
  134. package/src/commands/types.ts +0 -52
  135. package/src/commands.ts +0 -76
  136. package/src/context.ts +0 -368
  137. package/src/errors.ts +0 -280
  138. package/src/events.ts +0 -511
  139. package/src/generated/artifact_registry.ts +0 -2096
  140. package/src/generated/build.ts +0 -1311
  141. package/src/generated/container.ts +0 -503
  142. package/src/generated/control.ts +0 -2018
  143. package/src/generated/google/protobuf/duration.ts +0 -196
  144. package/src/generated/google/protobuf/timestamp.ts +0 -226
  145. package/src/generated/kv.ts +0 -1169
  146. package/src/generated/queue.ts +0 -753
  147. package/src/generated/service_account.ts +0 -814
  148. package/src/generated/storage.ts +0 -3820
  149. package/src/generated/vault.ts +0 -543
  150. package/src/generated/wait_until.ts +0 -829
  151. package/src/generated/worker.ts +0 -759
  152. package/src/global.ts +0 -287
  153. package/src/grpc-utils.ts +0 -159
  154. package/src/index.ts +0 -160
  155. package/src/types.ts +0 -397
  156. package/src/wait-until.ts +0 -273
  157. package/tsconfig.json +0 -8
  158. package/tsdown.config.ts +0 -17
  159. /package/dist/{generated → worker-runtime/generated}/google/protobuf/duration.d.ts +0 -0
  160. /package/dist/{generated → worker-runtime/generated}/google/protobuf/timestamp.d.ts +0 -0
@@ -1,191 +0,0 @@
1
- /**
2
- * Queue binding implementation.
3
- *
4
- * Provides message queue operations for async task processing.
5
- */
6
-
7
- import { type Channel, createClient } from "nice-grpc"
8
- import {
9
- type QueueServiceClient as GeneratedQueueServiceClient,
10
- type MessagePayload,
11
- type QueueMessage as QueueMessageProto,
12
- QueueServiceDefinition,
13
- } from "../generated/queue.js"
14
- import { wrapGrpcCall } from "../grpc-utils.js"
15
- import type { ReceivedQueueMessage } from "../types.js"
16
-
17
- /**
18
- * Queue binding for message queue operations.
19
- *
20
- * @example
21
- * ```typescript
22
- * import { queue } from "@alienplatform/sdk"
23
- *
24
- * const tasks = queue("task-queue")
25
- *
26
- * // Send a message (JSON)
27
- * await tasks.send("process-image", { imageId: "123", format: "webp" })
28
- *
29
- * // Receive messages
30
- * const messages = await tasks.receive("process-image", 10)
31
- * for (const msg of messages) {
32
- * await processImage(msg.payload)
33
- * await tasks.ack("process-image", msg.receiptHandle)
34
- * }
35
- * ```
36
- */
37
- export class Queue {
38
- private readonly client: GeneratedQueueServiceClient
39
- private readonly bindingName: string
40
-
41
- constructor(channel: Channel, bindingName: string) {
42
- this.client = createClient(QueueServiceDefinition, channel)
43
- this.bindingName = bindingName
44
- }
45
-
46
- /**
47
- * Send a message to a queue.
48
- *
49
- * @param queueName - Name of the queue
50
- * @param payload - Message payload (object for JSON, string for text)
51
- */
52
- async send(queueName: string, payload: unknown): Promise<void> {
53
- const message = this.toProtoPayload(payload)
54
-
55
- await wrapGrpcCall(
56
- "QueueService",
57
- "Send",
58
- async () => {
59
- await this.client.send({
60
- bindingName: this.bindingName,
61
- queue: queueName,
62
- message,
63
- })
64
- },
65
- { bindingName: this.bindingName },
66
- )
67
- }
68
-
69
- /**
70
- * Send a text message to a queue.
71
- *
72
- * @param queueName - Name of the queue
73
- * @param text - Text message
74
- */
75
- async sendText(queueName: string, text: string): Promise<void> {
76
- await wrapGrpcCall(
77
- "QueueService",
78
- "Send",
79
- async () => {
80
- await this.client.send({
81
- bindingName: this.bindingName,
82
- queue: queueName,
83
- message: { text },
84
- })
85
- },
86
- { bindingName: this.bindingName },
87
- )
88
- }
89
-
90
- /**
91
- * Receive messages from a queue.
92
- *
93
- * @param queueName - Name of the queue
94
- * @param maxMessages - Maximum number of messages to receive (1-10)
95
- * @returns Array of messages with receipt handles
96
- */
97
- async receive<T = unknown>(
98
- queueName: string,
99
- maxMessages = 1,
100
- ): Promise<ReceivedQueueMessage<T>[]> {
101
- return await wrapGrpcCall(
102
- "QueueService",
103
- "Receive",
104
- async () => {
105
- const response = await this.client.receive({
106
- bindingName: this.bindingName,
107
- queue: queueName,
108
- maxMessages: Math.min(Math.max(1, maxMessages), 10),
109
- })
110
- return response.messages.map(msg => this.fromProtoMessage<T>(msg))
111
- },
112
- { bindingName: this.bindingName },
113
- )
114
- }
115
-
116
- /**
117
- * Acknowledge a message (remove it from the queue).
118
- *
119
- * @param queueName - Name of the queue
120
- * @param receiptHandle - Receipt handle from the received message
121
- */
122
- async ack(queueName: string, receiptHandle: string): Promise<void> {
123
- await wrapGrpcCall(
124
- "QueueService",
125
- "Ack",
126
- async () => {
127
- await this.client.ack({
128
- bindingName: this.bindingName,
129
- queue: queueName,
130
- receiptHandle,
131
- })
132
- },
133
- { bindingName: this.bindingName },
134
- )
135
- }
136
-
137
- /**
138
- * Process messages from a queue with automatic acknowledgment.
139
- *
140
- * @param queueName - Name of the queue
141
- * @param handler - Handler function for each message
142
- * @param options - Processing options
143
- *
144
- * @example
145
- * ```typescript
146
- * await tasks.process("image-tasks", async (payload) => {
147
- * await processImage(payload.imageId)
148
- * })
149
- * ```
150
- */
151
- async process<T = unknown>(
152
- queueName: string,
153
- handler: (payload: T) => Promise<void>,
154
- options?: { maxMessages?: number },
155
- ): Promise<void> {
156
- const maxMessages = options?.maxMessages ?? 10
157
-
158
- const messages = await this.receive<T>(queueName, maxMessages)
159
-
160
- for (const message of messages) {
161
- await handler(message.payload)
162
- await this.ack(queueName, message.receiptHandle)
163
- }
164
- }
165
-
166
- // Private helpers
167
-
168
- private toProtoPayload(payload: unknown): MessagePayload {
169
- if (typeof payload === "string") {
170
- return { text: payload }
171
- }
172
- return { json: JSON.stringify(payload) }
173
- }
174
-
175
- private fromProtoMessage<T>(proto: QueueMessageProto): ReceivedQueueMessage<T> {
176
- let payload: unknown
177
-
178
- if (proto.payload?.json) {
179
- payload = JSON.parse(proto.payload.json)
180
- } else if (proto.payload?.text) {
181
- payload = proto.payload.text
182
- } else {
183
- payload = null
184
- }
185
-
186
- return {
187
- payload: payload as T,
188
- receiptHandle: proto.receiptHandle,
189
- }
190
- }
191
- }
@@ -1,113 +0,0 @@
1
- /**
2
- * ServiceAccount binding implementation.
3
- *
4
- * Provides identity and impersonation capabilities.
5
- */
6
-
7
- import { type Channel, createClient } from "nice-grpc"
8
- import {
9
- type ServiceAccountServiceClient as GeneratedClient,
10
- type ServiceAccountInfo as ServiceAccountInfoProto,
11
- ServiceAccountServiceDefinition,
12
- } from "../generated/service_account.js"
13
- import { wrapGrpcCall } from "../grpc-utils.js"
14
- import type { ImpersonationRequest, ServiceAccountInfo } from "../types.js"
15
-
16
- /**
17
- * ServiceAccount binding for identity and impersonation.
18
- *
19
- * @example
20
- * ```typescript
21
- * import { serviceAccount } from "@alienplatform/sdk"
22
- *
23
- * const sa = serviceAccount("deployment-account")
24
- *
25
- * // Get account info
26
- * const info = await sa.getInfo()
27
- * if (info.platform === "aws") {
28
- * console.log("Role ARN:", info.roleArn)
29
- * }
30
- *
31
- * // Impersonate the service account
32
- * const config = await sa.impersonate({ durationSeconds: 3600 })
33
- * ```
34
- */
35
- export class ServiceAccount {
36
- private readonly client: GeneratedClient
37
- private readonly bindingName: string
38
-
39
- constructor(channel: Channel, bindingName: string) {
40
- this.client = createClient(ServiceAccountServiceDefinition, channel)
41
- this.bindingName = bindingName
42
- }
43
-
44
- /**
45
- * Get information about the service account.
46
- *
47
- * @returns Platform-specific service account information
48
- */
49
- async getInfo(): Promise<ServiceAccountInfo> {
50
- return await wrapGrpcCall(
51
- "ServiceAccountService",
52
- "GetInfo",
53
- async () => {
54
- const response = await this.client.getInfo({
55
- bindingName: this.bindingName,
56
- })
57
- return this.fromProtoInfo(response.info!)
58
- },
59
- { bindingName: this.bindingName, bindingType: "ServiceAccount" },
60
- )
61
- }
62
-
63
- /**
64
- * Impersonate the service account.
65
- *
66
- * @param request - Impersonation options
67
- * @returns Client configuration for the impersonated identity
68
- */
69
- async impersonate(request?: ImpersonationRequest): Promise<unknown> {
70
- return await wrapGrpcCall(
71
- "ServiceAccountService",
72
- "Impersonate",
73
- async () => {
74
- const response = await this.client.impersonate({
75
- bindingName: this.bindingName,
76
- sessionName: request?.sessionName,
77
- durationSeconds: request?.durationSeconds,
78
- scopes: request?.scopes ?? [],
79
- })
80
- return JSON.parse(response.clientConfigJson)
81
- },
82
- { bindingName: this.bindingName, bindingType: "ServiceAccount" },
83
- )
84
- }
85
-
86
- // Private helpers
87
-
88
- private fromProtoInfo(proto: ServiceAccountInfoProto): ServiceAccountInfo {
89
- if (proto.aws) {
90
- return {
91
- platform: "aws",
92
- roleName: proto.aws.roleName,
93
- roleArn: proto.aws.roleArn,
94
- }
95
- }
96
- if (proto.gcp) {
97
- return {
98
- platform: "gcp",
99
- email: proto.gcp.email,
100
- uniqueId: proto.gcp.uniqueId,
101
- }
102
- }
103
- if (proto.azure) {
104
- return {
105
- platform: "azure",
106
- clientId: proto.azure.clientId,
107
- resourceId: proto.azure.resourceId,
108
- principalId: proto.azure.principalId,
109
- }
110
- }
111
- throw new Error("Unknown service account platform")
112
- }
113
- }