@fabrika/provider-zerops 0.2.0 → 0.3.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.
- package/package.json +18 -5
- package/src/api/client.ts +522 -0
- package/src/api/errors.ts +50 -0
- package/src/api/polling.ts +59 -0
- package/src/api/readers.ts +185 -0
- package/src/api/service-env-response.ts +34 -0
- package/src/api/types.ts +602 -0
- package/src/api.ts +29 -1378
- package/src/authoring.ts +7 -10
- package/src/cli-args.ts +0 -5
- package/src/cli.ts +3 -28
- package/src/collaborators.ts +2 -4
- package/src/compile.ts +3 -1
- package/src/control.ts +203 -450
- package/src/descriptor.ts +135 -0
- package/src/index.ts +23 -127
- package/src/installation/admin-options.ts +128 -0
- package/src/installation/admin.ts +123 -0
- package/src/installation/deploy-options.ts +155 -0
- package/src/installation/deploy.ts +668 -0
- package/src/installation/generated/platform-console-schema.ts +41 -0
- package/src/installation/generated/platform-proxy-manifest.ts +72 -0
- package/src/installation/hosts.ts +117 -0
- package/src/installation/index.ts +366 -0
- package/src/installation/init.ts +521 -0
- package/src/installation/install-collaborators.ts +28 -0
- package/src/installation/install-environment.ts +193 -0
- package/src/installation/install-options.ts +193 -0
- package/src/installation/install-project.ts +201 -0
- package/src/installation/install-provisioning.ts +185 -0
- package/src/installation/install.ts +286 -0
- package/src/installation/installation-source.ts +42 -0
- package/src/installation/log.ts +77 -0
- package/src/installation/machine-key.ts +65 -0
- package/src/installation/manifest.ts +95 -0
- package/src/installation/placement-options.ts +33 -0
- package/src/installation/platform-source.ts +106 -0
- package/src/installation/platform-upload.ts +34 -0
- package/src/installation/proxy-manifest.ts +113 -0
- package/src/installation/secrets.ts +79 -0
- package/src/installation/sidecar.ts +122 -0
- package/src/installation/source-options.ts +12 -0
- package/src/installation/templates/README.md +116 -0
- package/src/installation/templates/fabrika.ref +1 -0
- package/src/installation/templates/gitignore +3 -0
- package/src/installation/templates/platform.yml +144 -0
- package/src/installation/topology/artifacts.ts +141 -0
- package/src/installation/topology/index.ts +13 -0
- package/src/installation/topology/installation-schemas.ts +225 -0
- package/src/installation/topology/invariants.ts +86 -0
- package/src/installation/topology/setups.ts +442 -0
- package/src/installation/topology/topology.ts +501 -0
- package/src/installation/topology/validate.ts +26 -0
- package/src/installation/upgrade-options.ts +108 -0
- package/src/installation/upgrade-output.ts +31 -0
- package/src/installation/upgrade.ts +373 -0
- package/src/managed-env.ts +105 -0
- package/src/manifest.ts +191 -344
- package/src/namespace/claims.ts +77 -0
- package/src/namespace/codec.ts +179 -0
- package/src/namespace/constants.ts +30 -0
- package/src/namespace/errors.ts +60 -0
- package/src/namespace/manifest.ts +28 -0
- package/src/namespace/operator.ts +151 -0
- package/src/namespace/provisioning.ts +482 -0
- package/src/namespace/proxy-attempt.ts +220 -0
- package/src/namespace/proxy-source.ts +22 -0
- package/src/namespace/topology.ts +115 -0
- package/src/namespace/types.ts +114 -0
- package/src/namespace.ts +34 -1271
- package/src/plan.ts +21 -23
- package/src/provider.ts +266 -241
- package/src/source/constants.ts +11 -0
- package/src/source/port.ts +49 -0
- package/src/source/types.ts +4 -0
- package/src/source/validation.ts +72 -0
- package/src/source.ts +2 -1220
- package/src/types.ts +8 -7
- package/src/version-attempt.ts +18 -0
- package/src/codec.ts +0 -108
- package/src/namespace-command.ts +0 -209
- package/src/source-connection.ts +0 -344
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type {
|
|
3
|
+
ZeropsAppVersion,
|
|
4
|
+
ZeropsAppVersionStatus,
|
|
5
|
+
ZeropsImportResult,
|
|
6
|
+
ZeropsIntegrationToken,
|
|
7
|
+
ZeropsLogAccess,
|
|
8
|
+
ZeropsProcess,
|
|
9
|
+
ZeropsProject,
|
|
10
|
+
ZeropsProjectMode,
|
|
11
|
+
ZeropsProjectStatus,
|
|
12
|
+
ZeropsRoleCode,
|
|
13
|
+
ZeropsService,
|
|
14
|
+
ZeropsServiceEnv,
|
|
15
|
+
ZeropsServiceStatus,
|
|
16
|
+
} from './types'
|
|
17
|
+
|
|
18
|
+
/** Zerops sends `null` for an absent optional field; nothing reads one of these as required, so a malformed one reads as absent. */
|
|
19
|
+
const optional = <Schema extends z.ZodTypeAny>(schema: Schema) => schema.optional().catch(undefined)
|
|
20
|
+
|
|
21
|
+
const nonBlankSchema = z.string().refine((value) => value.trim() !== '')
|
|
22
|
+
const idSchema = nonBlankSchema
|
|
23
|
+
|
|
24
|
+
/** Every valid `ZeropsAppVersionStatus`, in pipeline order. */
|
|
25
|
+
const appVersionStatusSchema = z.enum(
|
|
26
|
+
[
|
|
27
|
+
'UPLOADING',
|
|
28
|
+
'WAITING_TO_BUILD',
|
|
29
|
+
'BUILDING',
|
|
30
|
+
'BUILD_FAILED',
|
|
31
|
+
'BUILD_VALIDATION_FAILED',
|
|
32
|
+
'WAITING_TO_DEPLOY',
|
|
33
|
+
'DEPLOYING',
|
|
34
|
+
'DEPLOY_FAILED',
|
|
35
|
+
'PREPARING_RUNTIME',
|
|
36
|
+
'PREPARING_RUNTIME_FAILED',
|
|
37
|
+
'ACTIVE',
|
|
38
|
+
'BACKUP',
|
|
39
|
+
'CANCELLED',
|
|
40
|
+
] satisfies [ZeropsAppVersionStatus, ...ZeropsAppVersionStatus[]],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const projectStatusSchema = z.enum(
|
|
44
|
+
['NEW', 'CREATING', 'ACTIVE', 'DELETING', 'FAILED', 'STOPPING', 'STOPPED', 'STARTING'] satisfies [
|
|
45
|
+
ZeropsProjectStatus,
|
|
46
|
+
...ZeropsProjectStatus[],
|
|
47
|
+
],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const projectModeSchema = z.enum(['LIGHT', 'SERIOUS'] satisfies [ZeropsProjectMode, ...ZeropsProjectMode[]])
|
|
51
|
+
|
|
52
|
+
const serviceStatusSchema = z.enum(
|
|
53
|
+
[
|
|
54
|
+
'NEW',
|
|
55
|
+
'CREATING',
|
|
56
|
+
'ACTIVE',
|
|
57
|
+
'STOPPING',
|
|
58
|
+
'STOPPED',
|
|
59
|
+
'STARTING',
|
|
60
|
+
'RESTARTING',
|
|
61
|
+
'RELOADING',
|
|
62
|
+
'DELETING',
|
|
63
|
+
'DELETED',
|
|
64
|
+
'FAILED',
|
|
65
|
+
'ACTION_FAILED',
|
|
66
|
+
'UPGRADING',
|
|
67
|
+
'READY_TO_DEPLOY',
|
|
68
|
+
'SERVICE_CREATING',
|
|
69
|
+
'SERVICE_ACTIVE',
|
|
70
|
+
'SERVICE_STOPPING',
|
|
71
|
+
'SERVICE_STOPPED',
|
|
72
|
+
'SERVICE_STARTING',
|
|
73
|
+
'SERVICE_RESTARTING',
|
|
74
|
+
'SERVICE_RELOADING',
|
|
75
|
+
'SERVICE_DELETING',
|
|
76
|
+
'SERVICE_DELETED',
|
|
77
|
+
'SERVICE_FAILED',
|
|
78
|
+
'SERVICE_ACTION_FAILED',
|
|
79
|
+
'SERVICE_REPAIRING',
|
|
80
|
+
'SERVICE_CONTAINER_FAILED',
|
|
81
|
+
'SERVICE_MOVING_CONTAINER',
|
|
82
|
+
'SERVICE_UPGRADING',
|
|
83
|
+
'SERVICE_SCALING',
|
|
84
|
+
'SERVICE_REPAIR_FAILED',
|
|
85
|
+
'REPAIRING',
|
|
86
|
+
'CONTAINER_FAILED',
|
|
87
|
+
'MOVING_CONTAINER',
|
|
88
|
+
'SCALING',
|
|
89
|
+
'REPAIR_FAILED',
|
|
90
|
+
] satisfies [ZeropsServiceStatus, ...ZeropsServiceStatus[]],
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
const roleCodeSchema = z.enum(['OWNER', 'ADMIN', 'BASIC_USER', 'READ_ONLY', 'NO_ACCESS'] satisfies [ZeropsRoleCode, ...ZeropsRoleCode[]])
|
|
94
|
+
|
|
95
|
+
// Absent or null reads as absent, but a blank id fails the parse: build-and-deploy must not accept `appVersion: { id: '' }`.
|
|
96
|
+
const nestedIdSchema = z.object({ id: idSchema }).nullish()
|
|
97
|
+
|
|
98
|
+
export const appVersionSchema = z.object({
|
|
99
|
+
id: idSchema,
|
|
100
|
+
// Unknown statuses read as absent: the poll loop keeps waiting rather than guessing an outcome.
|
|
101
|
+
status: optional(appVersionStatusSchema),
|
|
102
|
+
serviceStackId: optional(idSchema),
|
|
103
|
+
projectId: optional(idSchema),
|
|
104
|
+
sequence: optional(z.number()),
|
|
105
|
+
build: optional(z.object({
|
|
106
|
+
startDate: optional(z.string()),
|
|
107
|
+
endDate: optional(z.string()),
|
|
108
|
+
pipelineStart: optional(z.string()),
|
|
109
|
+
pipelineFinish: optional(z.string()),
|
|
110
|
+
pipelineFailed: optional(z.string()),
|
|
111
|
+
})),
|
|
112
|
+
}) satisfies z.ZodType<ZeropsAppVersion, z.ZodTypeDef, unknown>
|
|
113
|
+
|
|
114
|
+
export const processSchema = z.object({
|
|
115
|
+
id: idSchema,
|
|
116
|
+
status: optional(z.string()),
|
|
117
|
+
actionName: optional(z.string()),
|
|
118
|
+
serviceStackId: optional(idSchema),
|
|
119
|
+
appVersion: nestedIdSchema,
|
|
120
|
+
}).transform(({ appVersion, ...process }): ZeropsProcess => ({ ...process, appVersionId: appVersion?.id }))
|
|
121
|
+
|
|
122
|
+
export const serviceSchema = z.object({
|
|
123
|
+
id: idSchema,
|
|
124
|
+
name: z.string(),
|
|
125
|
+
projectId: optional(idSchema),
|
|
126
|
+
status: optional(serviceStatusSchema),
|
|
127
|
+
base: optional(z.string()),
|
|
128
|
+
activeAppVersion: nestedIdSchema,
|
|
129
|
+
subdomainAccess: optional(z.boolean()),
|
|
130
|
+
autoscalingProfileId: optional(z.string()),
|
|
131
|
+
}).transform(({ activeAppVersion, ...service }): ZeropsService => ({ ...service, activeAppVersionId: activeAppVersion?.id }))
|
|
132
|
+
|
|
133
|
+
export const projectSchema = z.object({
|
|
134
|
+
id: idSchema,
|
|
135
|
+
name: z.string(),
|
|
136
|
+
status: optional(projectStatusSchema),
|
|
137
|
+
mode: optional(projectModeSchema),
|
|
138
|
+
description: optional(z.string()),
|
|
139
|
+
tagList: optional(z.array(z.string())),
|
|
140
|
+
}) satisfies z.ZodType<ZeropsProject, z.ZodTypeDef, unknown>
|
|
141
|
+
|
|
142
|
+
export const integrationTokenSchema = z.object({
|
|
143
|
+
id: idSchema,
|
|
144
|
+
name: z.string(),
|
|
145
|
+
token: nonBlankSchema,
|
|
146
|
+
// An unknown role reads as absent, never as a guess.
|
|
147
|
+
projects: z.array(z.object({ projectId: idSchema, roleCode: optional(roleCodeSchema) })),
|
|
148
|
+
roleCode: optional(roleCodeSchema),
|
|
149
|
+
}) satisfies z.ZodType<ZeropsIntegrationToken, z.ZodTypeDef, unknown>
|
|
150
|
+
|
|
151
|
+
export const serviceEnvSchema = z.object({
|
|
152
|
+
id: idSchema,
|
|
153
|
+
key: nonBlankSchema,
|
|
154
|
+
content: z.string(),
|
|
155
|
+
serviceStackId: optional(idSchema),
|
|
156
|
+
type: optional(z.string()),
|
|
157
|
+
sensitive: optional(z.boolean()),
|
|
158
|
+
}) satisfies z.ZodType<ZeropsServiceEnv, z.ZodTypeDef, unknown>
|
|
159
|
+
|
|
160
|
+
export const importResultSchema = z.object({
|
|
161
|
+
projectId: idSchema,
|
|
162
|
+
projectName: optional(z.string()),
|
|
163
|
+
serviceStacks: z.array(z.object({ id: idSchema, name: z.string(), processes: z.array(processSchema) })),
|
|
164
|
+
}).transform(({ serviceStacks, ...result }): ZeropsImportResult => ({ ...result, services: serviceStacks }))
|
|
165
|
+
|
|
166
|
+
export const logAccessSchema = z.object({
|
|
167
|
+
url: z.string(),
|
|
168
|
+
urlPlain: z.string(),
|
|
169
|
+
urlInfo: z.string(),
|
|
170
|
+
urlUi: z.string(),
|
|
171
|
+
accessToken: z.string(),
|
|
172
|
+
expiration: z.string(),
|
|
173
|
+
}) satisfies z.ZodType<ZeropsLogAccess, z.ZodTypeDef, unknown>
|
|
174
|
+
|
|
175
|
+
/** Parse a response, never echoing it: an issue can quote the value it rejected, and these carry credentials. */
|
|
176
|
+
export const readResponse = <Output>(label: string, schema: z.ZodType<Output, z.ZodTypeDef, unknown>, value: unknown): Output => {
|
|
177
|
+
const result = schema.safeParse(value)
|
|
178
|
+
if (!result.success) {
|
|
179
|
+
throw new Error(`zerops: ${label} returned an invalid response`)
|
|
180
|
+
}
|
|
181
|
+
return result.data
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const appVersionListSchema = z.object({ list: z.array(appVersionSchema) })
|
|
185
|
+
export const projectMatchesSchema = z.object({ projects: z.array(projectSchema) })
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { ZeropsServiceEnv } from './types'
|
|
3
|
+
|
|
4
|
+
const invalid = (): never => {
|
|
5
|
+
throw new Error('zerops: invalid service environment response')
|
|
6
|
+
}
|
|
7
|
+
const nonemptySchema = z.string().refine((value) => value.trim() !== '')
|
|
8
|
+
const serviceEnvEntrySchema = z.object({
|
|
9
|
+
id: nonemptySchema,
|
|
10
|
+
key: nonemptySchema,
|
|
11
|
+
content: z.string(),
|
|
12
|
+
serviceStackId: nonemptySchema.optional(),
|
|
13
|
+
type: nonemptySchema.optional(),
|
|
14
|
+
sensitive: z.boolean().optional(),
|
|
15
|
+
}).superRefine((entry, ctx) => {
|
|
16
|
+
if (Object.values(entry).some((value) => value === undefined)) ctx.addIssue({ code: 'custom', message: 'present fields must have values' })
|
|
17
|
+
})
|
|
18
|
+
const serviceEnvResponseSchema = z.object({ items: z.array(serviceEnvEntrySchema) })
|
|
19
|
+
|
|
20
|
+
/** Parse at the raw HTTP boundary, before permissive legacy readers can coerce a malformed field. */
|
|
21
|
+
export function parseServiceEnvResponse(value: unknown, serviceId: string): ZeropsServiceEnv[] {
|
|
22
|
+
const result = serviceEnvResponseSchema.safeParse(value)
|
|
23
|
+
if (!result.success || serviceId.trim() === '') return invalid()
|
|
24
|
+
const ids = new Set<string>()
|
|
25
|
+
const keys = new Set<string>()
|
|
26
|
+
return result.data.items.map((entry) => {
|
|
27
|
+
const { id, key, serviceStackId } = entry
|
|
28
|
+
if (ids.has(id) || keys.has(key)) return invalid()
|
|
29
|
+
ids.add(id)
|
|
30
|
+
keys.add(key)
|
|
31
|
+
if (serviceStackId !== undefined && serviceStackId !== serviceId) return invalid()
|
|
32
|
+
return entry
|
|
33
|
+
})
|
|
34
|
+
}
|