@fabrika/provider-zerops 0.9.0-dev.1 → 0.9.0-dev.11

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 (180) hide show
  1. package/package.json +17 -14
  2. package/sandbox/Dockerfile +16 -0
  3. package/sandbox/bin/postgres-auth.sh +38 -0
  4. package/sandbox/bin/reset.sh +12 -0
  5. package/sandbox/bin/run-build.sh +35 -0
  6. package/sandbox/bin/run-launcher.sh +18 -0
  7. package/sandbox/bin/start-launcher.sh +25 -0
  8. package/sandbox/bin/stop.sh +47 -0
  9. package/sandbox/init.sh +61 -0
  10. package/src/api/client.ts +15 -1
  11. package/src/api/errors.ts +7 -3
  12. package/src/api/readers.ts +29 -0
  13. package/src/api/types.ts +52 -0
  14. package/src/api.ts +2 -0
  15. package/src/cli.ts +11 -0
  16. package/src/collaborators.ts +0 -14
  17. package/src/compile.ts +1 -1
  18. package/src/control.ts +159 -92
  19. package/src/execution.ts +45 -195
  20. package/src/index.ts +2 -0
  21. package/src/installation/admin.ts +1 -1
  22. package/src/installation/deploy-options.ts +10 -2
  23. package/src/installation/deploy.ts +241 -81
  24. package/src/installation/generated/platform-console-schema.ts +3 -0
  25. package/src/installation/generated/platform-proxy-manifest.ts +1 -1
  26. package/src/installation/guide.md +53 -19
  27. package/src/installation/hosts.ts +1 -7
  28. package/src/installation/index.ts +20 -16
  29. package/src/installation/init-options.ts +2 -1
  30. package/src/installation/install-environment.ts +47 -108
  31. package/src/installation/install-options.ts +3 -1
  32. package/src/installation/install-secrets.ts +24 -68
  33. package/src/installation/install.ts +9 -4
  34. package/src/installation/plain-credentials.ts +91 -0
  35. package/src/installation/sidecar.ts +5 -26
  36. package/src/installation/templates/README.md +13 -12
  37. package/src/installation/templates/platform.yml +3 -0
  38. package/src/installation/topology/setups.ts +17 -4
  39. package/src/installation/topology/topology.ts +33 -23
  40. package/src/installation/upgrade-options.ts +2 -2
  41. package/src/managed-env.ts +1 -174
  42. package/src/manifest.ts +14 -17
  43. package/src/namespace/claims.ts +60 -1
  44. package/src/namespace/codec.ts +17 -0
  45. package/src/namespace/errors.ts +22 -1
  46. package/src/namespace/manifest.ts +36 -23
  47. package/src/namespace/provisioning.ts +88 -114
  48. package/src/namespace/proxy-attempt.ts +14 -2
  49. package/src/namespace/proxy-reads.ts +28 -23
  50. package/src/namespace/proxy-secrets.ts +18 -5
  51. package/src/namespace/sandbox-host.ts +212 -0
  52. package/src/namespace/subdomain.ts +113 -0
  53. package/src/namespace/topology.ts +1 -1
  54. package/src/namespace/types.ts +13 -0
  55. package/src/namespace/update.ts +1 -0
  56. package/src/namespace-cli.ts +152 -0
  57. package/src/plain-credentials.ts +90 -0
  58. package/src/plan.ts +1 -6
  59. package/src/provider.ts +88 -166
  60. package/src/proxy-manifest-carrier.ts +39 -0
  61. package/src/sandbox/base-image.ts +100 -0
  62. package/src/sandbox/constants.ts +44 -0
  63. package/src/sandbox/deploy.ts +471 -0
  64. package/src/sandbox/dev-artifact.ts +206 -0
  65. package/src/sandbox/lifecycle.ts +204 -0
  66. package/src/sandbox/scripts.ts +26 -0
  67. package/src/sandbox-host.ts +28 -0
  68. package/src/source/port.ts +5 -0
  69. package/src/types.ts +6 -2
  70. package/src/zbox/client.ts +259 -0
  71. package/src/zbox/errors.ts +45 -0
  72. package/src/zbox/index.ts +22 -0
  73. package/src/zbox/types.ts +165 -0
  74. package/types/src/api/client.d.ts +5 -0
  75. package/types/src/api/errors.d.ts +26 -0
  76. package/types/src/api/polling.d.ts +41 -0
  77. package/types/src/api/readers.d.ts +1115 -0
  78. package/types/src/api/service-env-limit.d.ts +17 -0
  79. package/types/src/api/service-env-response.d.ts +23 -0
  80. package/types/src/api/types.d.ts +687 -0
  81. package/types/src/api.d.ts +6 -0
  82. package/types/src/authoring.d.ts +9 -0
  83. package/types/src/cli-args.d.ts +19 -0
  84. package/types/src/cli.d.ts +13 -0
  85. package/types/src/collaborators.d.ts +16 -0
  86. package/types/src/compile.d.ts +91 -0
  87. package/types/src/control.d.ts +51 -0
  88. package/types/src/database-budget.d.ts +38 -0
  89. package/types/src/descriptor.d.ts +28 -0
  90. package/types/src/execution.d.ts +114 -0
  91. package/types/src/exposure.d.ts +47 -0
  92. package/types/src/index.d.ts +31 -0
  93. package/types/src/installation/admin-options.d.ts +24 -0
  94. package/types/src/installation/admin.d.ts +35 -0
  95. package/types/src/installation/checker-release.d.ts +12 -0
  96. package/types/src/installation/deploy-options.d.ts +42 -0
  97. package/types/src/installation/deploy.d.ts +136 -0
  98. package/types/src/installation/generated/platform-console-schema.d.ts +2 -0
  99. package/types/src/installation/generated/platform-proxy-manifest.d.ts +2 -0
  100. package/types/src/installation/hosts.d.ts +34 -0
  101. package/types/src/installation/index.d.ts +7 -0
  102. package/types/src/installation/init-options.d.ts +38 -0
  103. package/types/src/installation/init.d.ts +60 -0
  104. package/types/src/installation/install-collaborators.d.ts +24 -0
  105. package/types/src/installation/install-environment.d.ts +63 -0
  106. package/types/src/installation/install-options.d.ts +49 -0
  107. package/types/src/installation/install-project.d.ts +13 -0
  108. package/types/src/installation/install-provisioning.d.ts +58 -0
  109. package/types/src/installation/install-secrets.d.ts +17 -0
  110. package/types/src/installation/install-token.d.ts +10 -0
  111. package/types/src/installation/install.d.ts +23 -0
  112. package/types/src/installation/installation-source.d.ts +8 -0
  113. package/types/src/installation/log.d.ts +44 -0
  114. package/types/src/installation/machine-key.d.ts +19 -0
  115. package/types/src/installation/placement-options.d.ts +11 -0
  116. package/types/src/installation/plain-credentials.d.ts +20 -0
  117. package/types/src/installation/platform-archive.d.ts +7 -0
  118. package/types/src/installation/platform-source.d.ts +8 -0
  119. package/types/src/installation/platform-upload.d.ts +3 -0
  120. package/types/src/installation/sidecar.d.ts +49 -0
  121. package/types/src/installation/source-options.d.ts +1 -0
  122. package/types/src/installation/topology/artifacts.d.ts +8 -0
  123. package/types/src/installation/topology/index.d.ts +5 -0
  124. package/types/src/installation/topology/installation-schemas.d.ts +2242 -0
  125. package/types/src/installation/topology/invariants.d.ts +23 -0
  126. package/types/src/installation/topology/setups.d.ts +59 -0
  127. package/types/src/installation/topology/topology.d.ts +153 -0
  128. package/types/src/installation/topology/validate.d.ts +11 -0
  129. package/types/src/installation/upgrade-options.d.ts +26 -0
  130. package/types/src/installation/upgrade-output.d.ts +6 -0
  131. package/types/src/installation/upgrade.d.ts +88 -0
  132. package/types/src/managed-env.d.ts +24 -0
  133. package/types/src/manifest.d.ts +199 -0
  134. package/types/src/namespace/claims.d.ts +16 -0
  135. package/types/src/namespace/codec.d.ts +352 -0
  136. package/types/src/namespace/constants.d.ts +25 -0
  137. package/types/src/namespace/errors.d.ts +25 -0
  138. package/types/src/namespace/manifest.d.ts +4 -0
  139. package/types/src/namespace/operator.d.ts +12 -0
  140. package/types/src/namespace/provisioning.d.ts +4 -0
  141. package/types/src/namespace/proxy-attempt.d.ts +39 -0
  142. package/types/src/namespace/proxy-reads.d.ts +27 -0
  143. package/types/src/namespace/proxy-secrets.d.ts +8 -0
  144. package/types/src/namespace/proxy-source.d.ts +74 -0
  145. package/types/src/namespace/sandbox-host.d.ts +23 -0
  146. package/types/src/namespace/subdomain.d.ts +43 -0
  147. package/types/src/namespace/topology.d.ts +9 -0
  148. package/types/src/namespace/types.d.ts +111 -0
  149. package/types/src/namespace/update.d.ts +6 -0
  150. package/types/src/namespace/validation.d.ts +12 -0
  151. package/types/src/namespace-cli.d.ts +2 -0
  152. package/types/src/namespace.d.ts +9 -0
  153. package/types/src/plain-credentials.d.ts +7 -0
  154. package/types/src/plan.d.ts +11 -0
  155. package/types/src/provider.d.ts +60 -0
  156. package/types/src/proxy-manifest-carrier.d.ts +37 -0
  157. package/types/src/sandbox/base-image.d.ts +28 -0
  158. package/types/src/sandbox/constants.d.ts +30 -0
  159. package/types/src/sandbox/deploy.d.ts +75 -0
  160. package/types/src/sandbox/dev-artifact.d.ts +51 -0
  161. package/types/src/sandbox/lifecycle.d.ts +27 -0
  162. package/types/src/sandbox/scripts.d.ts +11 -0
  163. package/types/src/sandbox-host.d.ts +16 -0
  164. package/types/src/schema.generated.d.ts +376 -0
  165. package/types/src/service-names.d.ts +4 -0
  166. package/types/src/service-references.d.ts +13 -0
  167. package/types/src/source/constants.d.ts +6 -0
  168. package/types/src/source/port.d.ts +65 -0
  169. package/types/src/source/types.d.ts +4 -0
  170. package/types/src/source/validation.d.ts +19 -0
  171. package/types/src/source.d.ts +2 -0
  172. package/types/src/types.d.ts +125 -0
  173. package/types/src/version-attempt.d.ts +8 -0
  174. package/types/src/zbox/client.d.ts +2 -0
  175. package/types/src/zbox/errors.d.ts +25 -0
  176. package/types/src/zbox/index.d.ts +3 -0
  177. package/types/src/zbox/types.d.ts +433 -0
  178. package/src/installation/mcp.ts +0 -102
  179. package/src/installation/proxy-manifest.ts +0 -214
  180. package/src/installation/secrets.ts +0 -78
@@ -0,0 +1,165 @@
1
+ import { z } from 'zod'
2
+
3
+ // Each schema reads only the fields the provider uses; Box adds fields freely and they are ignored.
4
+
5
+ const nullableString = z
6
+ .string()
7
+ .nullish()
8
+ .transform((value) => value ?? null)
9
+
10
+ export const zboxOperationSchema = z.object({
11
+ id: z.string().min(1),
12
+ sandboxId: nullableString,
13
+ kind: z.string().min(1),
14
+ status: z.enum(['PENDING', 'RUNNING', 'FINISHED', 'FAILED']),
15
+ error: nullableString,
16
+ })
17
+ export type ZboxOperation = z.infer<typeof zboxOperationSchema>
18
+
19
+ export const zboxSandboxSchema = z.object({
20
+ id: z.string().min(1),
21
+ name: nullableString,
22
+ status: z.enum(['CREATING', 'RUNNING', 'PARKING', 'PARKED', 'WAKING', 'FORKING', 'RESTORING', 'FAILED', 'TERMINATED', 'ARCHIVED']),
23
+ baseDigest: z.string(),
24
+ hosts: z.array(
25
+ z.object({
26
+ port: z.number().int(),
27
+ access: z.string(),
28
+ url: z.string(),
29
+ }),
30
+ ),
31
+ policyGeneration: z.number().int(),
32
+ })
33
+ export type ZboxSandbox = z.infer<typeof zboxSandboxSchema>
34
+
35
+ export const zboxSandboxListSchema = z.object({ items: z.array(zboxSandboxSchema) })
36
+
37
+ export const zboxSpawnSchema = z.object({ operation: zboxOperationSchema, sandboxes: z.array(zboxSandboxSchema) })
38
+
39
+ export const zboxWorkspaceSchema = z.object({ version: z.string() })
40
+ export type ZboxWorkspace = z.infer<typeof zboxWorkspaceSchema>
41
+
42
+ export const zboxBaseSchema = z.object({
43
+ digest: z.string().min(1),
44
+ name: nullableString,
45
+ imageRef: z.string(),
46
+ status: z.enum(['PULLING', 'FLATTENING', 'READY', 'FAILED', 'DELETED']),
47
+ })
48
+ export type ZboxBase = z.infer<typeof zboxBaseSchema>
49
+
50
+ export const zboxBaseListSchema = z.object({ items: z.array(zboxBaseSchema) })
51
+
52
+ export const zboxExecResultSchema = z.object({
53
+ stdout: z.string(),
54
+ stderr: z.string(),
55
+ exitCode: z
56
+ .number()
57
+ .int()
58
+ .nullish()
59
+ .transform((value) => value ?? null),
60
+ timedOut: z.boolean(),
61
+ stdoutTruncated: z.boolean(),
62
+ stderrTruncated: z.boolean(),
63
+ })
64
+ export type ZboxExecResult = z.infer<typeof zboxExecResultSchema>
65
+
66
+ export const zboxSessionSchema = z.object({
67
+ id: z.string().min(1),
68
+ status: z.enum(['OPEN', 'CLOSED', 'FAILED']),
69
+ exitCode: z
70
+ .number()
71
+ .int()
72
+ .nullish()
73
+ .transform((value) => value ?? null),
74
+ hasOutput: z.boolean(),
75
+ })
76
+ export type ZboxSession = z.infer<typeof zboxSessionSchema>
77
+
78
+ export const zboxSuccessSchema = z.object({ success: z.literal(true) })
79
+
80
+ export type ZboxNetworkMode = 'AIRGAPPED' | 'PROJECT' | 'INTERNET' | 'PROJECT_INTERNET'
81
+ export type ZboxPortAccess = 'PROJECT' | 'MEMBERS' | 'TICKET' | 'TOKEN' | 'PUBLIC'
82
+
83
+ export interface ZboxIngressPort {
84
+ port: number
85
+ access: ZboxPortAccess
86
+ wakeOnRequest: boolean
87
+ }
88
+
89
+ /** No `env`: a credential reaches a sandbox only in the root-only file a deploy writes through the file API. */
90
+ export interface ZboxLaunch {
91
+ entrypoint?: string[]
92
+ cmd?: string[]
93
+ workingDir?: string
94
+ }
95
+
96
+ export interface ZboxCreateSandboxInput {
97
+ name: string
98
+ baseDigest: string
99
+ cpus: number
100
+ memoryBytes: number
101
+ /** Box refuses a create whose disk does not fit the workspace's data volume, and its default can exceed a small one. */
102
+ diskBytes: number
103
+ networkMode: ZboxNetworkMode
104
+ launch: ZboxLaunch
105
+ ports: ZboxIngressPort[]
106
+ /** Reused on a retry so Box answers the first create instead of making a second sandbox. */
107
+ idempotencyKey: string
108
+ }
109
+
110
+ /** No `env`, for the same reason as `ZboxLaunch`. */
111
+ export interface ZboxExecInput {
112
+ command: string[]
113
+ workingDir?: string
114
+ timeoutSeconds?: number
115
+ }
116
+
117
+ export interface ZboxProcessInput {
118
+ command: string[]
119
+ workingDir?: string
120
+ }
121
+
122
+ export type ZboxBody = Uint8Array<ArrayBuffer> | ReadableStream<Uint8Array>
123
+
124
+ export type ZboxFetch = (
125
+ input: string,
126
+ init: { method: string; headers: Record<string, string>; body?: string | ZboxBody; signal: AbortSignal },
127
+ ) => Promise<Response>
128
+
129
+ export interface ZboxClientOptions {
130
+ /** The API origin; requests go to `<baseUrl>/api/rest/…`. */
131
+ baseUrl: string
132
+ /** The Workspace API key, sent as `Authorization: Bearer`. Never logged. */
133
+ apiKey: string
134
+ fetch?: ZboxFetch
135
+ /** Generates the `Idempotency-Key` of a call whose caller supplied none. */
136
+ idempotencyKey?: () => string
137
+ }
138
+
139
+ export interface ZboxAwaitOptions {
140
+ signal?: AbortSignal
141
+ /** Milliseconds from now after which waiting gives up. */
142
+ deadlineMs: number
143
+ }
144
+
145
+ export interface ZboxClient {
146
+ getWorkspace(signal?: AbortSignal): Promise<ZboxWorkspace>
147
+ pullBase(input: { imageRef: string; name: string }, signal?: AbortSignal): Promise<ZboxOperation>
148
+ buildBase(input: { context: ZboxBody; name: string }, signal?: AbortSignal): Promise<ZboxOperation>
149
+ listBases(signal?: AbortSignal): Promise<ZboxBase[]>
150
+ getOperation(id: string, waitSeconds: number, signal?: AbortSignal): Promise<ZboxOperation>
151
+ awaitOperation(operation: ZboxOperation, options: ZboxAwaitOptions): Promise<ZboxOperation>
152
+ createSandbox(input: ZboxCreateSandboxInput, signal?: AbortSignal): Promise<{ operation: ZboxOperation; sandbox: ZboxSandbox }>
153
+ getSandbox(id: string, signal?: AbortSignal): Promise<ZboxSandbox>
154
+ findSandboxByName(name: string, signal?: AbortSignal): Promise<ZboxSandbox | null>
155
+ deleteSandbox(id: string, idempotencyKey: string, signal?: AbortSignal): Promise<void>
156
+ park(id: string, input: { memory: boolean }, signal?: AbortSignal): Promise<ZboxOperation>
157
+ wake(id: string, signal?: AbortSignal): Promise<ZboxOperation>
158
+ exec(id: string, input: ZboxExecInput, signal?: AbortSignal): Promise<ZboxExecResult>
159
+ startProcess(id: string, input: ZboxProcessInput, signal?: AbortSignal): Promise<ZboxSession>
160
+ getSession(id: string, signal?: AbortSignal): Promise<ZboxSession>
161
+ sessionOutput(id: string, signal?: AbortSignal): Promise<Uint8Array>
162
+ /** `mode` is the octal file mode (Box defaults to 0644). */
163
+ putFile(id: string, path: string, body: ZboxBody, options?: { mode?: string; signal?: AbortSignal }): Promise<void>
164
+ getFile(id: string, path: string, signal?: AbortSignal): Promise<Uint8Array | null>
165
+ }
@@ -0,0 +1,5 @@
1
+ import type { ZeropsApi, ZeropsApiOptions } from './types';
2
+ /** Base URL of the Zerops public REST API. */
3
+ export declare const ZEROPS_API_BASE = "https://api.app-prg1.zerops.io/api/rest/public";
4
+ /** Build the real client. Every request carries the bearer and the run's signal. */
5
+ export declare const createZeropsApi: (options: ZeropsApiOptions) => ZeropsApi;
@@ -0,0 +1,26 @@
1
+ export declare const isAppVersionNotFoundResponse: (value: unknown) => boolean;
2
+ /**
3
+ * A non-2xx answer from the Zerops API. `code` is the platform's own error identifier, so a caller can
4
+ * branch on `userDataDuplicateKey` rather than matching a prose message.
5
+ */
6
+ export declare class ZeropsApiError extends Error {
7
+ readonly status: number;
8
+ readonly code: string;
9
+ /** The codes of an `errorList` answer's entries: the platform reports several refusals of one request there. */
10
+ readonly listedCodes: readonly string[];
11
+ constructor(message: string, status: number, code: string, listedCodes?: readonly string[]);
12
+ }
13
+ /**
14
+ * The platform's code for "this service publishes no HTTP port", the answer `enableSubdomainAccess` gives
15
+ * before a service's first deploy. Exported so a caller can say what is missing instead of relaying prose.
16
+ */
17
+ export declare const ZEROPS_SERVICE_NOT_HTTP = "serviceStackIsNotHttp";
18
+ /**
19
+ * Turn a non-2xx response into a `ZeropsApiError`. Zerops answers with `{ error: { code, message, meta } }`
20
+ * (the envelope observed live; the OpenAPI `Error` schema shows the inner `{ code, message }`).
21
+ *
22
+ * `redactDetail` drops the server's MESSAGE, which a validation error can fill with the value it
23
+ * rejected. The CODE is a fixed identifier and is kept either way — without it nothing downstream can
24
+ * tell a duplicate key from a missing service.
25
+ */
26
+ export declare const apiError: (label: string, status: number, body: unknown, redactDetail: boolean) => ZeropsApiError;
@@ -0,0 +1,41 @@
1
+ import type { Sleeper } from '../collaborators';
2
+ import { type ZeropsApi, type ZeropsProcess } from './types';
3
+ /**
4
+ * Poll ONE process to completion.
5
+ *
6
+ * The same loop `deployPlatformService` (`installation/deploy.ts`) runs over `/app-version`, run over `/process`
7
+ * instead: read, decide ONLY on a status this build knows to be terminal, sleep, and give up on a deadline
8
+ * of our own rather than on a coincidence. Returns the finished process so a caller can read
9
+ * `actionName`/`appVersionId` off it.
10
+ *
11
+ * Anything outside `ZEROPS_PROCESS_TERMINAL` means "keep waiting", including a status this build has never
12
+ * seen — which is why an unpublished vocabulary (see that constant) can cost a timeout and never a false
13
+ * success. A non-`FINISHED` terminal status throws, naming the status and nothing else.
14
+ */
15
+ export declare const waitForProcess: (input: {
16
+ api: Pick<ZeropsApi, "getProcess">;
17
+ processId: string;
18
+ sleep: Sleeper;
19
+ signal: AbortSignal;
20
+ /** What to call this process in a failure or timeout message. Defaults to its id. */
21
+ label?: string;
22
+ intervalMs?: number;
23
+ attempts?: number;
24
+ }) => Promise<ZeropsProcess>;
25
+ /**
26
+ * `enableSubdomainAccess`, repeated while the service does not yet publish an HTTP port.
27
+ *
28
+ * Live-verified: right after a service's first app version reads ACTIVE the platform still answers
29
+ * `serviceStackIsNotHttp`, and a minute later the same call is accepted. The ports lag ACTIVE, so that
30
+ * answer means "not yet" for a bounded window. Past it the last refusal is rethrown unchanged, so a caller
31
+ * still names the missing port. Any other failure is rethrown at once. The 2xx still proves nothing: the
32
+ * caller decides by reading `subdomainAccess` back.
33
+ */
34
+ export declare const enableSubdomainAccessWhenHttp: (input: {
35
+ api: Pick<ZeropsApi, "enableSubdomainAccess">;
36
+ serviceId: string;
37
+ sleep: Sleeper;
38
+ signal: AbortSignal;
39
+ intervalMs?: number;
40
+ attempts?: number;
41
+ }) => Promise<void>;