@brimble/contracts 0.0.0-stage → 0.1.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.
@@ -0,0 +1,276 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serviceStateSchema = exports.screenshotSchema = exports.deployStartedSchema = exports.deployStatusSchema = exports.deployNotifySchema = exports.deploySaveSchema = exports.deployCompletedSchema = exports.staleTempSnapshotSchema = exports.staleTempCleanupSchema = exports.proxyClearCacheSchema = exports.processCmdSchema = exports.databaseVolumeDeleteSchema = exports.startStopContainerSchema = exports.deleteHubContainerSchema = exports.killContainerSchema = exports.processCancelSchema = exports.clonePublicRepoSchema = exports.cloneSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const common_1 = require("../common");
6
+ const enums_1 = require("./enums");
7
+ const stringOrNumber = zod_1.z.union([zod_1.z.string(), zod_1.z.number()]);
8
+ /** A log id on the wire: an ObjectId, or `''` which the runner sends when absent. */
9
+ const logIdValue = zod_1.z.union([common_1.objectId, zod_1.z.literal('')]);
10
+ const isoTimestamp = zod_1.z.iso.datetime({ offset: true });
11
+ /**
12
+ * Large mongoose documents are carried on the wire with far more fields than the
13
+ * runner reads. We validate the fields the runner actually consumes and allow the
14
+ * rest through, rather than re-deriving the entire model here.
15
+ */
16
+ const serverRef = zod_1.z
17
+ .object({
18
+ tag: common_1.nonEmptyString,
19
+ id: common_1.objectId.optional(),
20
+ private_ip_address: common_1.ipAddress.optional(),
21
+ ip_address: common_1.ipAddress.optional(),
22
+ })
23
+ .loose();
24
+ const previewRef = zod_1.z
25
+ .object({
26
+ _id: common_1.objectId,
27
+ port: common_1.port.optional(),
28
+ name: common_1.nonEmptyString.optional(),
29
+ branch: common_1.nonEmptyString.optional(),
30
+ })
31
+ .loose();
32
+ const projectRef = zod_1.z
33
+ .object({
34
+ _id: common_1.objectId,
35
+ name: common_1.nonEmptyString,
36
+ serviceType: enums_1.serviceType.optional(),
37
+ })
38
+ .loose();
39
+ const planConfigurationsRef = zod_1.z
40
+ .object({
41
+ deployed_ha: zod_1.z.boolean().optional(),
42
+ build_timeout: zod_1.z.number().int().positive().optional(),
43
+ })
44
+ .loose();
45
+ const buildTargetRef = zod_1.z
46
+ .object({
47
+ slug: common_1.nonEmptyString.optional(),
48
+ adapter: common_1.nonEmptyString.optional(),
49
+ })
50
+ .loose();
51
+ /** `clone` — the full deployment job core enqueues for the runner (core's DeploymentJobPayload). */
52
+ exports.cloneSchema = zod_1.z
53
+ .object({
54
+ logId: common_1.objectId,
55
+ uniqueId: common_1.nonEmptyString,
56
+ commitId: common_1.commitSha.nullable(),
57
+ git: enums_1.gitType,
58
+ repoName: zod_1.z.string(),
59
+ url: zod_1.z.union([common_1.gitRemoteUrl, zod_1.z.literal('n/a')]),
60
+ deploymentUrl: common_1.httpUrl,
61
+ queueName: common_1.nonEmptyString,
62
+ keys: zod_1.z.array(common_1.nonEmptyString),
63
+ previousServerTags: zod_1.z.array(common_1.nonEmptyString),
64
+ planType: enums_1.planType,
65
+ tag: common_1.objectId,
66
+ token: common_1.nonEmptyString,
67
+ activeRunnersCount: zod_1.z.number().int().nonnegative(),
68
+ server: serverRef,
69
+ project: projectRef,
70
+ preview: previewRef.nullable().optional(),
71
+ planConfigurations: planConfigurationsRef,
72
+ buildTarget: buildTargetRef,
73
+ domains: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())),
74
+ configFiles: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())),
75
+ framework: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable(),
76
+ environmentName: common_1.nonEmptyString.nullable(),
77
+ installation_id: stringOrNumber.nullable(),
78
+ csiVolumeId: common_1.nonEmptyString.nullable(),
79
+ commitMsg: zod_1.z.string().nullable(),
80
+ rmqName: common_1.nonEmptyString.optional(),
81
+ branch: common_1.nonEmptyString.optional(),
82
+ author: zod_1.z.string().optional(),
83
+ priority: stringOrNumber.optional(),
84
+ userId: common_1.objectId.optional(),
85
+ cloneEnvironmentId: common_1.objectId.optional(),
86
+ deployVaultToken: common_1.nonEmptyString.optional(),
87
+ gitUsername: common_1.nonEmptyString.optional(),
88
+ commentId: stringOrNumber.optional(),
89
+ envVersion: zod_1.z.number().int().nonnegative().optional(),
90
+ buildEnvVersion: zod_1.z.number().int().nonnegative().optional(),
91
+ startOnly: zod_1.z.boolean().optional(),
92
+ sourceImage: common_1.nonEmptyString.optional(),
93
+ upKeep: zod_1.z.boolean().optional(),
94
+ projectCap: zod_1.z.number().int().positive().optional(),
95
+ jobId: stringOrNumber.optional(),
96
+ })
97
+ .loose();
98
+ /** `clone:public:repo` — environment-clone push to a freshly created repo. */
99
+ exports.clonePublicRepoSchema = zod_1.z.object({
100
+ cloneUrl: common_1.gitRemoteUrl,
101
+ pushUrl: common_1.gitRemoteUrl,
102
+ name: zod_1.z.string().min(1).max(120),
103
+ email: zod_1.z.email().max(254),
104
+ projectId: common_1.objectId.optional(),
105
+ deployVaultToken: common_1.nonEmptyString.optional(),
106
+ gitUsername: common_1.nonEmptyString.optional(),
107
+ activeRunnersCount: zod_1.z.number().int().nonnegative().optional(),
108
+ });
109
+ /** `process:cancel` — cancel an in-flight build by its container key. */
110
+ exports.processCancelSchema = zod_1.z.object({
111
+ key: common_1.nonEmptyString,
112
+ git: enums_1.gitType.optional(),
113
+ });
114
+ /** `container:kill` — tear down live container(s) for a project. */
115
+ exports.killContainerSchema = zod_1.z.object({
116
+ containers: zod_1.z.array(common_1.nonEmptyString),
117
+ name: common_1.nonEmptyString,
118
+ type: common_1.nonEmptyString.optional(),
119
+ projectId: common_1.objectId.optional(),
120
+ projectName: common_1.nonEmptyString.optional(),
121
+ cleanupAllForProject: zod_1.z.boolean().optional(),
122
+ excludeContainer: common_1.nonEmptyString.optional(),
123
+ excludeContainers: zod_1.z.array(common_1.nonEmptyString).optional(),
124
+ drainSeconds: zod_1.z.number().int().nonnegative().optional(),
125
+ });
126
+ /** `container:hub:delete` — remove a project's pushed hub image. */
127
+ exports.deleteHubContainerSchema = zod_1.z.object({
128
+ containerName: common_1.nonEmptyString,
129
+ projectName: common_1.nonEmptyString.optional(),
130
+ });
131
+ /** `container:start` / `container:stop`. Start additionally carries autoscaling intent. */
132
+ exports.startStopContainerSchema = zod_1.z.object({
133
+ containers: zod_1.z.array(common_1.nonEmptyString),
134
+ projectId: common_1.objectId.optional(),
135
+ namespace: common_1.nonEmptyString.optional(),
136
+ teamId: common_1.objectId.optional(),
137
+ ownerId: common_1.objectId.optional(),
138
+ tag: common_1.nonEmptyString.optional(),
139
+ targetCount: zod_1.z.number().int().nonnegative().optional(),
140
+ autoscalingActive: zod_1.z.boolean().optional(),
141
+ });
142
+ /** `database-volume:delete`. */
143
+ exports.databaseVolumeDeleteSchema = zod_1.z.object({
144
+ project: projectRef,
145
+ });
146
+ /** `process:cmd` — run an allowlisted docker verb against a container. */
147
+ exports.processCmdSchema = zod_1.z.object({
148
+ cmd: enums_1.dockerCommand,
149
+ name: common_1.nonEmptyString,
150
+ });
151
+ /** `proxy:clear:cache` — invalidate cached project/preview route. */
152
+ exports.proxyClearCacheSchema = zod_1.z
153
+ .object({
154
+ projectId: common_1.objectId.optional(),
155
+ previewId: common_1.objectId.optional(),
156
+ })
157
+ .refine((value) => Boolean(value.projectId || value.previewId), { message: 'projectId or previewId is required' });
158
+ const staleTempScope = zod_1.z.object({
159
+ scopeId: common_1.objectId,
160
+ liveLogName: common_1.nonEmptyString,
161
+ port: common_1.port.optional(),
162
+ });
163
+ /** `container:cleanup` — remove stale temp containers (mantis StaleTempCleanupPayload). */
164
+ exports.staleTempCleanupSchema = zod_1.z.object({
165
+ runId: common_1.nonEmptyString,
166
+ sentAt: zod_1.z.iso.datetime({ offset: true }),
167
+ mode: enums_1.staleTempMode,
168
+ scopes: zod_1.z.array(staleTempScope),
169
+ });
170
+ /** `container:cleanup:snapshot` — a chunk of the stale-temp snapshot (mantis StaleTempSnapshotChunk). */
171
+ exports.staleTempSnapshotSchema = zod_1.z.object({
172
+ snapshotId: common_1.nonEmptyString,
173
+ snapshotAt: zod_1.z.iso.datetime({ offset: true }),
174
+ mode: enums_1.staleTempMode,
175
+ chunkIndex: zod_1.z.number().int().nonnegative(),
176
+ chunkCount: zod_1.z.number().int().positive(),
177
+ totalCount: zod_1.z.number().int().nonnegative(),
178
+ scopeIds: zod_1.z.array(common_1.objectId),
179
+ });
180
+ const privateDependencyProblem = zod_1.z.object({
181
+ reason: enums_1.privateDependencyReason,
182
+ variable: common_1.nonEmptyString,
183
+ host: zod_1.z.union([common_1.domainName, common_1.ipAddress]),
184
+ port: zod_1.z.string().regex(/^\d{1,5}$/, 'must be a numeric port string'),
185
+ });
186
+ /** `deploy:completed` — runner -> core completion signal. Primary and superseded paths share this string, so most fields are optional. */
187
+ exports.deployCompletedSchema = zod_1.z.object({
188
+ name: common_1.nonEmptyString.optional(),
189
+ status: zod_1.z.boolean().optional(),
190
+ previewId: common_1.objectId.optional(),
191
+ logId: logIdValue.optional(),
192
+ uniqueId: common_1.nonEmptyString.optional(),
193
+ projectId: common_1.objectId.optional(),
194
+ userId: common_1.objectId.optional(),
195
+ teamId: common_1.objectId.optional(),
196
+ isCancelled: zod_1.z.boolean().optional(),
197
+ isSuperseded: zod_1.z.boolean().optional(),
198
+ upKeep: zod_1.z.boolean().optional(),
199
+ privateDependencies: zod_1.z.array(privateDependencyProblem).optional(),
200
+ });
201
+ /** `deploy:save` — runner -> core persistence of a finished deployment record. */
202
+ exports.deploySaveSchema = zod_1.z.object({
203
+ project: projectRef,
204
+ preview: previewRef.nullable().optional(),
205
+ upKeep: zod_1.z.boolean().optional(),
206
+ deployedInCluster: zod_1.z.boolean(),
207
+ replica_ready: zod_1.z.boolean(),
208
+ logId: logIdValue,
209
+ uniqueId: zod_1.z.string(),
210
+ imagePushed: zod_1.z.boolean(),
211
+ sequence: zod_1.z.number().int(),
212
+ sentAt: isoTimestamp,
213
+ rmqName: common_1.nonEmptyString,
214
+ });
215
+ /** `deploy:notify` — runner -> core commit-status / notification fan-out. */
216
+ exports.deployNotifySchema = zod_1.z.object({
217
+ project: projectRef,
218
+ preview: previewRef.nullable().optional(),
219
+ commitId: common_1.commitSha.nullable().optional(),
220
+ installationId: stringOrNumber.nullable().optional(),
221
+ type: enums_1.deployNotifyType,
222
+ url: zod_1.z.object({
223
+ domain: common_1.nonEmptyString.optional(),
224
+ deployment: common_1.httpUrl.optional(),
225
+ }),
226
+ logId: logIdValue.optional(),
227
+ message: zod_1.z.string().nullable().optional(),
228
+ author: zod_1.z.string().optional(),
229
+ commentId: stringOrNumber.optional(),
230
+ });
231
+ /** `deploy:status` — runner -> core live status line. Note the nested `{ event, data }`. */
232
+ exports.deployStatusSchema = zod_1.z.object({
233
+ event: enums_1.deployStatusEvent,
234
+ data: zod_1.z.object({
235
+ id: common_1.objectId,
236
+ status: zod_1.z.boolean(),
237
+ url: common_1.httpUrl.optional(),
238
+ message: zod_1.z.string(),
239
+ teamId: common_1.objectId.optional(),
240
+ userId: common_1.objectId.optional(),
241
+ }),
242
+ });
243
+ /** `deploy:started` — runner -> core start signal with the pending commit status. */
244
+ exports.deployStartedSchema = zod_1.z.object({
245
+ projectId: common_1.objectId,
246
+ logId: logIdValue,
247
+ startTime: isoTimestamp,
248
+ upKeep: zod_1.z.boolean().optional(),
249
+ git: enums_1.gitType,
250
+ commitStatus: zod_1.z.object({
251
+ repo: zod_1.z.string(),
252
+ commitId: common_1.commitSha.nullable().optional(),
253
+ installationId: stringOrNumber.nullable().optional(),
254
+ git: enums_1.gitType,
255
+ payload: zod_1.z.object({
256
+ state: zod_1.z.literal('pending'),
257
+ description: zod_1.z.string(),
258
+ context: zod_1.z.string(),
259
+ target_url: common_1.httpUrl,
260
+ }),
261
+ }),
262
+ });
263
+ /** `screenshot` — runner -> core request to capture a deployed URL. */
264
+ exports.screenshotSchema = zod_1.z.object({
265
+ url: common_1.httpUrl,
266
+ projectId: common_1.objectId,
267
+ upKeep: zod_1.z.boolean(),
268
+ });
269
+ /** `service:state` — runner -> core container-state transition. */
270
+ exports.serviceStateSchema = zod_1.z.object({
271
+ projectId: common_1.objectId,
272
+ uniqueId: common_1.nonEmptyString,
273
+ action: enums_1.serviceStateAction,
274
+ runtime: enums_1.serviceRuntime,
275
+ targetCount: zod_1.z.number().int().nonnegative().optional(),
276
+ });
package/package.json CHANGED
@@ -1,6 +1,22 @@
1
1
  {
2
2
  "name": "@brimble/contracts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Brimble cross-service message contracts (zod schemas) shared between services",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "rm -rf dist && tsc -p .",
12
+ "prepack": "npm run build"
13
+ },
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "zod": "^4.6.7"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "17.0.0",
20
+ "typescript": "^5.9.3"
21
+ }
22
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.