@fabrika/control-contract 0.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 (3) hide show
  1. package/package.json +30 -0
  2. package/src/index.ts +272 -0
  3. package/src/rpc.ts +142 -0
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@fabrika/control-contract",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/contember/fabrika-platform.git",
8
+ "directory": "packages/control-contract"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "files": [
14
+ "src"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "bun": "./src/index.ts",
19
+ "types": "./src/index.ts",
20
+ "default": "./src/index.ts"
21
+ }
22
+ },
23
+ "scripts": {
24
+ "typecheck": "tsc --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "@fabrika/app": "^0.0.1",
28
+ "@fabrika/provider-contract": "^0.0.1"
29
+ }
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1,272 @@
1
+ import type { JsonValue, ProviderEnvelope } from '@fabrika/provider-contract'
2
+
3
+ export type { JsonValue }
4
+
5
+ /** A plain list response. */
6
+ export interface ListResponse<T> {
7
+ items: T[]
8
+ }
9
+
10
+ /** A keyset-paginated list. */
11
+ export interface CursorList<T> {
12
+ items: T[]
13
+ nextCursor: string | null
14
+ }
15
+
16
+ export type ProviderEnvelopeDto = ProviderEnvelope
17
+
18
+ /** One redacted line of deploy output exposed by the control API. */
19
+ export interface RunLogLine {
20
+ readonly ts: number
21
+ readonly stream: 'stdout' | 'stderr' | 'meta'
22
+ readonly text: string
23
+ }
24
+
25
+ /** Backward-compatible short name for browser consumers. */
26
+ export type LogLine = RunLogLine
27
+
28
+ export interface SetSecretValueRequest {
29
+ value: string
30
+ env?: string | null
31
+ }
32
+
33
+ export interface AppDto {
34
+ id: string
35
+ repoUrl: string
36
+ defaultBranch: string
37
+ workerDir: string | null
38
+ buildCmd: string | null
39
+ configPath: string | null
40
+ githubInstallationId: number | null
41
+ createdAt: number
42
+ }
43
+
44
+ export interface AppOptionalFields {
45
+ defaultBranch?: string
46
+ workerDir?: string | null
47
+ buildCmd?: string | null
48
+ configPath?: string | null
49
+ githubInstallationId?: number | null
50
+ resolveInstallationId?: boolean
51
+ }
52
+
53
+ export interface UpdateAppRequest extends AppOptionalFields {
54
+ repoUrl?: string
55
+ }
56
+
57
+ export interface AppEnvDto {
58
+ appId: string
59
+ env: string
60
+ domain: string | null
61
+ publicOrigin: string | null
62
+ triggerRef: string | null
63
+ namespaceId: string | null
64
+ provider: string
65
+ target: ProviderEnvelopeDto
66
+ artifact: ProviderEnvelopeDto
67
+ createdAt: number
68
+ }
69
+
70
+ export interface PutAppEnvRequest {
71
+ domain?: string | null
72
+ publicOrigin?: string | null
73
+ triggerRef?: string | null
74
+ namespaceId?: string | null
75
+ target: ProviderEnvelopeDto
76
+ artifact: ProviderEnvelopeDto
77
+ }
78
+
79
+ export interface CloudflareTargetEnvelope extends ProviderEnvelopeDto {
80
+ provider: 'cloudflare'
81
+ version: 1
82
+ payload: {
83
+ stateNamespace?: string
84
+ }
85
+ }
86
+
87
+ export interface CloudflareArtifactEnvelope extends ProviderEnvelopeDto {
88
+ provider: 'cloudflare'
89
+ version: 1
90
+ payload: {
91
+ configPath: string
92
+ }
93
+ }
94
+
95
+ export type DeploymentNamespaceState = 'pending' | 'provisioning' | 'ready' | 'failed'
96
+
97
+ export interface DeploymentNamespaceDto {
98
+ id: string
99
+ env: string
100
+ provider: string
101
+ exclusiveAppId: string | null
102
+ target: ProviderEnvelopeDto
103
+ state: DeploymentNamespaceState
104
+ lastError: string | null
105
+ createdAt: number
106
+ }
107
+
108
+ export interface DeploymentNamespaceDetailDto extends DeploymentNamespaceDto {
109
+ presentation: DeploymentNamespacePresentationDto | null
110
+ }
111
+
112
+ export interface CreateDeploymentNamespaceRequest {
113
+ id: string
114
+ env: string
115
+ exclusiveAppId?: string | null
116
+ target: ProviderEnvelopeDto
117
+ }
118
+
119
+ export interface AdoptDeploymentNamespaceRequest {
120
+ env: string
121
+ exclusiveAppId?: string | null
122
+ target: ProviderEnvelopeDto
123
+ }
124
+
125
+ export interface DeploymentNamespaceFactDto {
126
+ readonly label: string
127
+ readonly value: string
128
+ }
129
+
130
+ export interface DeploymentNamespacePresentationDto {
131
+ readonly preset: string
132
+ readonly title: string
133
+ readonly facts: readonly DeploymentNamespaceFactDto[]
134
+ readonly instructions: readonly string[]
135
+ }
136
+
137
+ export interface DeploymentNamespacePresetDto {
138
+ readonly id: string
139
+ readonly label: string
140
+ readonly description: string
141
+ readonly requiresExclusiveApp: boolean
142
+ }
143
+
144
+ export interface DeploymentNamespaceOperatorDto {
145
+ readonly presets: readonly DeploymentNamespacePresetDto[]
146
+ }
147
+
148
+ export interface DeploymentNamespaceListResponse {
149
+ items: DeploymentNamespaceDto[]
150
+ operator: DeploymentNamespaceOperatorDto | null
151
+ }
152
+
153
+ export interface PlanDeploymentNamespaceRequest {
154
+ id: string
155
+ env: string
156
+ preset: string
157
+ exclusiveAppId?: string
158
+ options?: JsonValue
159
+ }
160
+
161
+ export interface PlannedDeploymentNamespaceDto {
162
+ readonly id: string
163
+ readonly env: string
164
+ readonly exclusiveAppId?: string
165
+ readonly target: ProviderEnvelopeDto
166
+ }
167
+
168
+ export interface PlanDeploymentNamespaceResponse {
169
+ readonly namespace: PlannedDeploymentNamespaceDto
170
+ readonly presentation: DeploymentNamespacePresentationDto
171
+ }
172
+
173
+ export interface AppSecretDto {
174
+ appId: string
175
+ env: string | null
176
+ name: string
177
+ valueRef: string
178
+ createdAt: number
179
+ }
180
+
181
+ export interface PutAppSecretRequest {
182
+ name: string
183
+ valueRef: string
184
+ env?: string | null
185
+ }
186
+
187
+ export interface AppVarDto {
188
+ appId: string
189
+ env: string | null
190
+ name: string
191
+ value: string
192
+ createdAt: number
193
+ }
194
+
195
+ export interface PutAppVarRequest {
196
+ name: string
197
+ value: string
198
+ env?: string | null
199
+ }
200
+
201
+ export interface RegisterAppRequest extends AppOptionalFields {
202
+ id: string
203
+ repoUrl: string
204
+ env: string
205
+ domain?: string | null
206
+ publicOrigin?: string | null
207
+ triggerRef?: string | null
208
+ namespaceId?: string | null
209
+ target: ProviderEnvelopeDto
210
+ artifact: ProviderEnvelopeDto
211
+ }
212
+
213
+ export interface RegisterAppResponse {
214
+ app: AppDto
215
+ env: AppEnvDto
216
+ }
217
+
218
+ export type RunTrigger = 'webhook' | 'manual' | 'poll'
219
+ export type RunStatus = 'pending' | 'running' | 'succeeded' | 'failed'
220
+
221
+ export interface RunDto {
222
+ id: string
223
+ appId: string
224
+ env: string
225
+ ref: string
226
+ commitSha: string | null
227
+ trigger: RunTrigger
228
+ status: RunStatus
229
+ exitCode: number | null
230
+ externalRunId: string | null
231
+ logKey: string | null
232
+ createdAt: number
233
+ startedAt: number | null
234
+ finishedAt: number | null
235
+ }
236
+
237
+ export interface TriggerDeployRequest {
238
+ appId: string
239
+ env: string
240
+ ref?: string
241
+ }
242
+
243
+ export interface RunTailResponse {
244
+ lines: RunLogLine[]
245
+ cursor: number
246
+ done: boolean
247
+ status: RunStatus
248
+ }
249
+
250
+ export interface RunLogResponse {
251
+ lines: RunLogLine[]
252
+ status?: RunStatus
253
+ }
254
+
255
+ export type {
256
+ AdoptNamespaceInput,
257
+ AppEnvironmentInput,
258
+ AppIdInput,
259
+ AppNamedValueInput,
260
+ ControlRpcContract,
261
+ CreateAppRequest,
262
+ NamespaceIdInput,
263
+ OkResponse,
264
+ PutAppEnvironmentInput,
265
+ PutAppSecretInput,
266
+ PutAppVarInput,
267
+ RunIdInput,
268
+ RunListInput,
269
+ SecretValueInput,
270
+ SecretValueResponse,
271
+ TailRunInput,
272
+ } from './rpc.js'
package/src/rpc.ts ADDED
@@ -0,0 +1,142 @@
1
+ import type { RpcProcedureContract } from '@fabrika/app'
2
+ import type {
3
+ AdoptDeploymentNamespaceRequest,
4
+ AppDto,
5
+ AppEnvDto,
6
+ AppSecretDto,
7
+ AppVarDto,
8
+ CreateDeploymentNamespaceRequest,
9
+ CursorList,
10
+ DeploymentNamespaceDetailDto,
11
+ DeploymentNamespaceListResponse,
12
+ ListResponse,
13
+ PlanDeploymentNamespaceRequest,
14
+ PlanDeploymentNamespaceResponse,
15
+ PutAppEnvRequest,
16
+ PutAppSecretRequest,
17
+ PutAppVarRequest,
18
+ RegisterAppRequest,
19
+ RegisterAppResponse,
20
+ RunDto,
21
+ RunLogResponse,
22
+ RunTailResponse,
23
+ SetSecretValueRequest,
24
+ TriggerDeployRequest,
25
+ UpdateAppRequest,
26
+ } from './index.js'
27
+
28
+ type RpcProcedure<TInput, TOutput> = RpcProcedureContract<TInput, TOutput>
29
+
30
+ export interface AppIdInput {
31
+ readonly appId: string
32
+ }
33
+
34
+ export interface AppEnvironmentInput extends AppIdInput {
35
+ readonly env: string
36
+ }
37
+
38
+ export interface AppNamedValueInput extends AppIdInput {
39
+ readonly name: string
40
+ readonly env?: string | null
41
+ }
42
+
43
+ export interface CreateAppRequest extends UpdateAppRequest {
44
+ readonly id: string
45
+ readonly repoUrl: string
46
+ }
47
+
48
+ export interface PutAppEnvironmentInput extends AppEnvironmentInput {
49
+ readonly environment: PutAppEnvRequest
50
+ }
51
+
52
+ export interface PutAppSecretInput extends AppIdInput {
53
+ readonly secret: PutAppSecretRequest
54
+ }
55
+
56
+ export interface PutAppVarInput extends AppIdInput {
57
+ readonly variable: PutAppVarRequest
58
+ }
59
+
60
+ export interface SecretValueInput extends AppNamedValueInput {
61
+ readonly value: string
62
+ }
63
+
64
+ export interface SecretValueResponse {
65
+ readonly ok: boolean
66
+ readonly valueRef?: string
67
+ }
68
+
69
+ export interface OkResponse {
70
+ readonly ok: boolean
71
+ }
72
+
73
+ export interface NamespaceIdInput {
74
+ readonly namespaceId: string
75
+ }
76
+
77
+ export interface AdoptNamespaceInput extends NamespaceIdInput {
78
+ readonly namespace: AdoptDeploymentNamespaceRequest
79
+ }
80
+
81
+ export interface RunListInput {
82
+ readonly appId?: string
83
+ readonly env?: string
84
+ readonly before?: string
85
+ readonly limit?: number
86
+ }
87
+
88
+ export interface RunIdInput {
89
+ readonly runId: string
90
+ }
91
+
92
+ export interface TailRunInput extends RunIdInput {
93
+ readonly after?: number
94
+ }
95
+
96
+ /** Portable Delivery control API, implemented alongside the backward-compatible REST transport. */
97
+ export interface ControlRpcContract {
98
+ apps: {
99
+ list: RpcProcedure<void, ListResponse<AppDto>>
100
+ get: RpcProcedure<AppIdInput, AppDto>
101
+ create: RpcProcedure<CreateAppRequest, AppDto>
102
+ update: RpcProcedure<AppIdInput & { app: UpdateAppRequest }, AppDto>
103
+ delete: RpcProcedure<AppIdInput, OkResponse>
104
+ environments: {
105
+ list: RpcProcedure<AppIdInput, ListResponse<AppEnvDto>>
106
+ put: RpcProcedure<PutAppEnvironmentInput, AppEnvDto>
107
+ delete: RpcProcedure<AppEnvironmentInput, OkResponse>
108
+ }
109
+ secrets: {
110
+ list: RpcProcedure<AppIdInput, ListResponse<AppSecretDto>>
111
+ put: RpcProcedure<PutAppSecretInput, AppSecretDto>
112
+ delete: RpcProcedure<AppNamedValueInput, OkResponse>
113
+ }
114
+ variables: {
115
+ list: RpcProcedure<AppIdInput, ListResponse<AppVarDto>>
116
+ put: RpcProcedure<PutAppVarInput, AppVarDto>
117
+ delete: RpcProcedure<AppNamedValueInput, OkResponse>
118
+ }
119
+ }
120
+ vault: {
121
+ set: RpcProcedure<SecretValueInput, SecretValueResponse>
122
+ rotate: RpcProcedure<SecretValueInput, OkResponse>
123
+ delete: RpcProcedure<AppNamedValueInput, OkResponse>
124
+ }
125
+ namespaces: {
126
+ list: RpcProcedure<void, DeploymentNamespaceListResponse>
127
+ get: RpcProcedure<NamespaceIdInput, DeploymentNamespaceDetailDto>
128
+ plan: RpcProcedure<PlanDeploymentNamespaceRequest, PlanDeploymentNamespaceResponse>
129
+ create: RpcProcedure<CreateDeploymentNamespaceRequest, DeploymentNamespaceDetailDto>
130
+ adopt: RpcProcedure<AdoptNamespaceInput, DeploymentNamespaceDetailDto>
131
+ reconcile: RpcProcedure<NamespaceIdInput, DeploymentNamespaceDetailDto>
132
+ }
133
+ runs: {
134
+ list: RpcProcedure<RunListInput, CursorList<RunDto>>
135
+ get: RpcProcedure<RunIdInput, RunDto>
136
+ log: RpcProcedure<RunIdInput, RunLogResponse>
137
+ tail: RpcProcedure<TailRunInput, RunTailResponse>
138
+ cancel: RpcProcedure<RunIdInput, RunDto>
139
+ }
140
+ deploy: RpcProcedure<TriggerDeployRequest, RunDto>
141
+ register: RpcProcedure<RegisterAppRequest, RegisterAppResponse>
142
+ }