@wildo-ai/platform-config-lib 1.1.13 → 1.1.15
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/dist/esm/bootstrap/application-scheduled-jobs.contracts.d.ts +187 -0
- package/dist/esm/bootstrap/application-scheduled-jobs.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/application-scheduled-jobs.contracts.js +250 -0
- package/dist/esm/bootstrap/application-scheduled-jobs.contracts.js.map +1 -0
- package/dist/esm/bootstrap/minion-database-queue-confinement.contracts.d.ts +41 -0
- package/dist/esm/bootstrap/minion-database-queue-confinement.contracts.d.ts.map +1 -0
- package/dist/esm/bootstrap/minion-database-queue-confinement.contracts.js +53 -0
- package/dist/esm/bootstrap/minion-database-queue-confinement.contracts.js.map +1 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +12 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +12 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts +64 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js +49 -0
- package/dist/esm/bootstrap/postgresql-owed-grants.contracts.js.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts +23 -2
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.js +23 -4
- package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts +14 -0
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.js +24 -0
- package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-management/approval-seal-verifier.d.ts +72 -2
- package/dist/esm/key-management/approval-seal-verifier.d.ts.map +1 -1
- package/dist/esm/key-management/approval-seal-verifier.js +102 -0
- package/dist/esm/key-management/approval-seal-verifier.js.map +1 -1
- package/dist/esm/pnpm-settings/application-pnpm-settings.d.ts +1 -1
- package/dist/esm/pnpm-settings/application-pnpm-settings.js +1 -1
- package/dist/esm/pnpm-settings/application-pnpm-settings.js.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +12 -1
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/hosted-infra-env-config.js +8 -1
- package/dist/esm/project-config/hosted-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +1 -0
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +23 -0
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +68 -5
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.d.ts +7 -3
- package/dist/esm/project-config/shared/csp-defaults.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-defaults.js +10 -4
- package/dist/esm/project-config/shared/csp-defaults.js.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.d.ts +52 -6
- package/dist/esm/project-config/shared/environment.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/environment.schemas.js +80 -6
- package/dist/esm/project-config/shared/environment.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +8 -0
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* # Running one of an application's scheduled jobs NOW (#4006)
|
|
4
|
+
*
|
|
5
|
+
* A scheduled job runs at its next tick. A developer, or the finalization verifier, who needs what a job writes (a
|
|
6
|
+
* recurring todo's occurrences, written hourly by `todosRecurringOccurrences.run_recurring_generation`) would otherwise
|
|
7
|
+
* wait up to an hour. The crontabs manager already has a manual trigger, but only apps-manager may call it, so the door is
|
|
8
|
+
* an apps-manager ADMIN route behind `PLATFORM_ADMIN_SECRET`, and the CLI verb is `wildo local jobs run <selector>`.
|
|
9
|
+
*
|
|
10
|
+
* Decided by practice: a "run this scheduled job now" door is standard (`kubectl create job --from=cronjob/<name>`,
|
|
11
|
+
* Laravel's `schedule:test`, the Run button on Vercel cron jobs). It runs the job's ordinary execution once and does not
|
|
12
|
+
* change its schedule.
|
|
13
|
+
*
|
|
14
|
+
* ## Who owns a job
|
|
15
|
+
*
|
|
16
|
+
* The crontabs manager keys every job on the application's platform id (the `wildoapplication` ROW id, which is what
|
|
17
|
+
* `cronjobs.applicationId` holds) as the first segment of its `jobId`:
|
|
18
|
+
*
|
|
19
|
+
* | kind | `jobId` | selector |
|
|
20
|
+
* |---|---|---|
|
|
21
|
+
* | resource cron operation | `<applicationId>:<resourceType>:<operationId>:<variantKey>` | `<resourceType>.<operationId>:<variantKey>` |
|
|
22
|
+
* | custom batch | `<applicationId>:batch:<batchRef>` | `batch:<batchRef>` |
|
|
23
|
+
* | minion tick | `<applicationId>:minion-tick:<minionName>:<variantKey>` | `minion-tick:<minionName>:<variantKey>` |
|
|
24
|
+
*
|
|
25
|
+
* (`buildJobId` in the crontabs manager's `application-jobs-sync.crontab.controller.ts` is the producer.) So ownership is
|
|
26
|
+
* the prefix `<applicationId>:`, and apps-manager refuses to trigger a job outside it
|
|
27
|
+
* ({@link ApplicationScheduledJobRunRefusal.NOT_OWNED_BY_APPLICATION}): the admin route names ONE application, and a job of
|
|
28
|
+
* another must not be reachable through it.
|
|
29
|
+
*
|
|
30
|
+
* The SELECTOR is the application-relative name a person types. Nobody builds `<applicationId>:…` by hand: the CLI
|
|
31
|
+
* resolves a selector against the listing ({@link resolveApplicationScheduledJobSelector}) and sends the `jobId` the
|
|
32
|
+
* listing named.
|
|
33
|
+
*/
|
|
34
|
+
/** What kind of schedule a job is, read from the shape of its `jobId`. */
|
|
35
|
+
export declare enum ApplicationScheduledJobKind {
|
|
36
|
+
/** A resource operation declared with a cron schedule: `<app>:<resourceType>:<operationId>:<variantKey>`. */
|
|
37
|
+
RESOURCE_OPERATION = "resource_operation",
|
|
38
|
+
/** A custom batch the application registered: `<app>:batch:<batchRef>`. */
|
|
39
|
+
BATCH = "batch",
|
|
40
|
+
/** A minion's periodic tick: `<app>:minion-tick:<minionName>:<variantKey>`. */
|
|
41
|
+
MINION_TICK = "minion_tick",
|
|
42
|
+
/**
|
|
43
|
+
* A job of this application whose remainder fits none of the shapes above. Listed and runnable by its exact selector
|
|
44
|
+
* (the remainder after `<applicationId>:`) rather than hidden: a new job shape in the crontabs manager must not make a
|
|
45
|
+
* job disappear from the listing.
|
|
46
|
+
*/
|
|
47
|
+
UNRECOGNIZED = "unrecognized"
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The reserved second segments of a job id. ONE source for the producer (the crontabs manager's `buildJobId`, which
|
|
51
|
+
* builds through the functions below) and the parser ({@link parseApplicationScheduledJobId}), so the two cannot drift:
|
|
52
|
+
* ownership and the selector both depend on this format.
|
|
53
|
+
*/
|
|
54
|
+
export declare enum ApplicationScheduledJobSegment {
|
|
55
|
+
/** A custom batch: `<app>:batch:<batchRef>`. */
|
|
56
|
+
BATCH = "batch",
|
|
57
|
+
/** A minion's tick: `<app>:minion-tick:<minionName>:<variantKey>`. Reserved, so it cannot collide with a resource type. */
|
|
58
|
+
MINION_TICK = "minion-tick"
|
|
59
|
+
}
|
|
60
|
+
/** The id of an application's custom batch job. */
|
|
61
|
+
export declare function buildApplicationBatchJobId(applicationId: string, batchRef: string): string;
|
|
62
|
+
/** The id of a minion's tick job. */
|
|
63
|
+
export declare function buildApplicationMinionTickJobId(applicationId: string, minionName: string, variantKey: string): string;
|
|
64
|
+
/** The id of a resource operation declared with a cron schedule. */
|
|
65
|
+
export declare function buildApplicationResourceOperationJobId(applicationId: string, resourceType: string, operationId: string, variantKey: string): string;
|
|
66
|
+
/** Why apps-manager refuses to run a scheduled job. Sent as `code` on the refusal, which survives the client sanitizer. */
|
|
67
|
+
export declare enum ApplicationScheduledJobRunRefusal {
|
|
68
|
+
/** The `jobId` does not start with the named application's `<applicationId>:`: it is another application's job, or none. */
|
|
69
|
+
NOT_OWNED_BY_APPLICATION = "scheduled_job_not_owned_by_application",
|
|
70
|
+
/**
|
|
71
|
+
* The job is this application's by its id, and the crontabs manager's store holds no such job: it is not scheduled now
|
|
72
|
+
* (typically the backend stopped declaring it after the listing was read). Nothing ran.
|
|
73
|
+
*/
|
|
74
|
+
UNKNOWN_TO_SCHEDULER = "scheduled_job_unknown_to_scheduler"
|
|
75
|
+
}
|
|
76
|
+
/** The admin path that lists an application's scheduled jobs. */
|
|
77
|
+
export declare function buildAdminApplicationScheduledJobsPath(appSlug: string): string;
|
|
78
|
+
/** The admin path that runs one of an application's scheduled jobs now. The `jobId` travels in the body: it contains `:`. */
|
|
79
|
+
export declare function buildAdminApplicationScheduledJobRunPath(appSlug: string): string;
|
|
80
|
+
export declare const ApplicationScheduledJobSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
81
|
+
resourceType: z.ZodString;
|
|
82
|
+
operationId: z.ZodString;
|
|
83
|
+
variantKey: z.ZodString;
|
|
84
|
+
jobId: z.ZodString;
|
|
85
|
+
selector: z.ZodString;
|
|
86
|
+
armed: z.ZodBoolean;
|
|
87
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.RESOURCE_OPERATION>;
|
|
88
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
89
|
+
batchRef: z.ZodString;
|
|
90
|
+
jobId: z.ZodString;
|
|
91
|
+
selector: z.ZodString;
|
|
92
|
+
armed: z.ZodBoolean;
|
|
93
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.BATCH>;
|
|
94
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
95
|
+
minionName: z.ZodString;
|
|
96
|
+
variantKey: z.ZodString;
|
|
97
|
+
jobId: z.ZodString;
|
|
98
|
+
selector: z.ZodString;
|
|
99
|
+
armed: z.ZodBoolean;
|
|
100
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.MINION_TICK>;
|
|
101
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
102
|
+
jobId: z.ZodString;
|
|
103
|
+
selector: z.ZodString;
|
|
104
|
+
armed: z.ZodBoolean;
|
|
105
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.UNRECOGNIZED>;
|
|
106
|
+
}, z.core.$strict>], "kind">;
|
|
107
|
+
export type ApplicationScheduledJob = z.infer<typeof ApplicationScheduledJobSchema>;
|
|
108
|
+
/** The answer of `GET /admin/apps/:appSlug/scheduled-jobs`. */
|
|
109
|
+
export declare const ApplicationScheduledJobsResponseSchema: z.ZodObject<{
|
|
110
|
+
appSlug: z.ZodString;
|
|
111
|
+
applicationId: z.ZodString;
|
|
112
|
+
platformScheduledTotal: z.ZodNumber;
|
|
113
|
+
schedulerRunning: z.ZodBoolean;
|
|
114
|
+
jobs: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
115
|
+
resourceType: z.ZodString;
|
|
116
|
+
operationId: z.ZodString;
|
|
117
|
+
variantKey: z.ZodString;
|
|
118
|
+
jobId: z.ZodString;
|
|
119
|
+
selector: z.ZodString;
|
|
120
|
+
armed: z.ZodBoolean;
|
|
121
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.RESOURCE_OPERATION>;
|
|
122
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
123
|
+
batchRef: z.ZodString;
|
|
124
|
+
jobId: z.ZodString;
|
|
125
|
+
selector: z.ZodString;
|
|
126
|
+
armed: z.ZodBoolean;
|
|
127
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.BATCH>;
|
|
128
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
129
|
+
minionName: z.ZodString;
|
|
130
|
+
variantKey: z.ZodString;
|
|
131
|
+
jobId: z.ZodString;
|
|
132
|
+
selector: z.ZodString;
|
|
133
|
+
armed: z.ZodBoolean;
|
|
134
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.MINION_TICK>;
|
|
135
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
136
|
+
jobId: z.ZodString;
|
|
137
|
+
selector: z.ZodString;
|
|
138
|
+
armed: z.ZodBoolean;
|
|
139
|
+
kind: z.ZodLiteral<ApplicationScheduledJobKind.UNRECOGNIZED>;
|
|
140
|
+
}, z.core.$strict>], "kind">>;
|
|
141
|
+
}, z.core.$strict>;
|
|
142
|
+
export type ApplicationScheduledJobsResponse = z.infer<typeof ApplicationScheduledJobsResponseSchema>;
|
|
143
|
+
export declare const ApplicationScheduledJobRunRequestSchema: z.ZodObject<{
|
|
144
|
+
jobId: z.ZodString;
|
|
145
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
146
|
+
}, z.core.$strict>;
|
|
147
|
+
export type ApplicationScheduledJobRunRequest = z.input<typeof ApplicationScheduledJobRunRequestSchema>;
|
|
148
|
+
/** The answer of `POST /admin/apps/:appSlug/scheduled-jobs/run`. */
|
|
149
|
+
export declare const ApplicationScheduledJobRunResponseSchema: z.ZodObject<{
|
|
150
|
+
appSlug: z.ZodString;
|
|
151
|
+
applicationId: z.ZodString;
|
|
152
|
+
jobId: z.ZodString;
|
|
153
|
+
selector: z.ZodString;
|
|
154
|
+
triggeredAt: z.ZodISODateTime;
|
|
155
|
+
}, z.core.$strict>;
|
|
156
|
+
export type ApplicationScheduledJobRunResponse = z.infer<typeof ApplicationScheduledJobRunResponseSchema>;
|
|
157
|
+
/** Whether `jobId` is one of this application's jobs: it carries the application's prefix and something after it. */
|
|
158
|
+
export declare function applicationOwnsScheduledJobId(applicationId: string, jobId: string): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Read one of this application's jobs from its `jobId`, or `null` when the job is not this application's.
|
|
161
|
+
*
|
|
162
|
+
* The batch segment is checked BEFORE the resource-operation shape, mirroring the producer: `buildJobId` writes
|
|
163
|
+
* `<app>:batch:<ref>` for any job with a `batchRef`, and a batch ref may itself contain `:`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function parseApplicationScheduledJobId(applicationId: string, jobId: string, armed: boolean): ApplicationScheduledJob | null;
|
|
166
|
+
/** How a selector resolved against a listing. */
|
|
167
|
+
export declare enum ApplicationScheduledJobSelectorResolution {
|
|
168
|
+
/** Exactly one job matches. */
|
|
169
|
+
RESOLVED = "resolved",
|
|
170
|
+
/** No job matches. `candidates` is the whole listing, so the caller can show what exists. */
|
|
171
|
+
NOT_FOUND = "not_found",
|
|
172
|
+
/** Several jobs match (a resource operation scheduled under several variants, named without one). */
|
|
173
|
+
AMBIGUOUS = "ambiguous"
|
|
174
|
+
}
|
|
175
|
+
export type ApplicationScheduledJobSelectorResult = {
|
|
176
|
+
resolution: ApplicationScheduledJobSelectorResolution.RESOLVED;
|
|
177
|
+
job: ApplicationScheduledJob;
|
|
178
|
+
} | {
|
|
179
|
+
resolution: ApplicationScheduledJobSelectorResolution.NOT_FOUND;
|
|
180
|
+
candidates: ApplicationScheduledJob[];
|
|
181
|
+
} | {
|
|
182
|
+
resolution: ApplicationScheduledJobSelectorResolution.AMBIGUOUS;
|
|
183
|
+
matches: ApplicationScheduledJob[];
|
|
184
|
+
};
|
|
185
|
+
/** Resolve what a person typed to exactly one job of the listing, or say why it cannot be. */
|
|
186
|
+
export declare function resolveApplicationScheduledJobSelector(jobs: readonly ApplicationScheduledJob[], selector: string): ApplicationScheduledJobSelectorResult;
|
|
187
|
+
//# sourceMappingURL=application-scheduled-jobs.contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-scheduled-jobs.contracts.d.ts","sourceRoot":"","sources":["../../../src/bootstrap/application-scheduled-jobs.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,0EAA0E;AAC1E,oBAAY,2BAA2B;IACrC,6GAA6G;IAC7G,kBAAkB,uBAAuB;IACzC,2EAA2E;IAC3E,KAAK,UAAU;IACf,+EAA+E;IAC/E,WAAW,gBAAgB;IAC3B;;;;OAIG;IACH,YAAY,iBAAiB;CAC9B;AAED;;;;GAIG;AACH,oBAAY,8BAA8B;IACxC,gDAAgD;IAChD,KAAK,UAAU;IACf,2HAA2H;IAC3H,WAAW,gBAAgB;CAC5B;AAKD,mDAAmD;AACnD,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1F;AAED,qCAAqC;AACrC,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAErH;AAED,oEAAoE;AACpE,wBAAgB,sCAAsC,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEnJ;AAED,2HAA2H;AAC3H,oBAAY,iCAAiC;IAC3C,4HAA4H;IAC5H,wBAAwB,2CAA2C;IACnE;;;OAGG;IACH,oBAAoB,uCAAuC;CAC5D;AAED,iEAAiE;AACjE,wBAAgB,sCAAsC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,6HAA6H;AAC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U,EAAE,uBAAuB,EAAE,CAAA;CAAE,GAC1G;IAAE,UAAU,EAAE,yCAAyC,CAAC,SAAS,CAAC;IAAC,OAAO,EAAE,uBAAuB,EAAE,CAAA;CAAE,CAAC;AAqB5G,8FAA8F;AAC9F,wBAAgB,sCAAsC,CAAC,IAAI,EAAE,SAAS,uBAAuB,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,qCAAqC,CAMxJ"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* # Running one of an application's scheduled jobs NOW (#4006)
|
|
4
|
+
*
|
|
5
|
+
* A scheduled job runs at its next tick. A developer, or the finalization verifier, who needs what a job writes (a
|
|
6
|
+
* recurring todo's occurrences, written hourly by `todosRecurringOccurrences.run_recurring_generation`) would otherwise
|
|
7
|
+
* wait up to an hour. The crontabs manager already has a manual trigger, but only apps-manager may call it, so the door is
|
|
8
|
+
* an apps-manager ADMIN route behind `PLATFORM_ADMIN_SECRET`, and the CLI verb is `wildo local jobs run <selector>`.
|
|
9
|
+
*
|
|
10
|
+
* Decided by practice: a "run this scheduled job now" door is standard (`kubectl create job --from=cronjob/<name>`,
|
|
11
|
+
* Laravel's `schedule:test`, the Run button on Vercel cron jobs). It runs the job's ordinary execution once and does not
|
|
12
|
+
* change its schedule.
|
|
13
|
+
*
|
|
14
|
+
* ## Who owns a job
|
|
15
|
+
*
|
|
16
|
+
* The crontabs manager keys every job on the application's platform id (the `wildoapplication` ROW id, which is what
|
|
17
|
+
* `cronjobs.applicationId` holds) as the first segment of its `jobId`:
|
|
18
|
+
*
|
|
19
|
+
* | kind | `jobId` | selector |
|
|
20
|
+
* |---|---|---|
|
|
21
|
+
* | resource cron operation | `<applicationId>:<resourceType>:<operationId>:<variantKey>` | `<resourceType>.<operationId>:<variantKey>` |
|
|
22
|
+
* | custom batch | `<applicationId>:batch:<batchRef>` | `batch:<batchRef>` |
|
|
23
|
+
* | minion tick | `<applicationId>:minion-tick:<minionName>:<variantKey>` | `minion-tick:<minionName>:<variantKey>` |
|
|
24
|
+
*
|
|
25
|
+
* (`buildJobId` in the crontabs manager's `application-jobs-sync.crontab.controller.ts` is the producer.) So ownership is
|
|
26
|
+
* the prefix `<applicationId>:`, and apps-manager refuses to trigger a job outside it
|
|
27
|
+
* ({@link ApplicationScheduledJobRunRefusal.NOT_OWNED_BY_APPLICATION}): the admin route names ONE application, and a job of
|
|
28
|
+
* another must not be reachable through it.
|
|
29
|
+
*
|
|
30
|
+
* The SELECTOR is the application-relative name a person types. Nobody builds `<applicationId>:…` by hand: the CLI
|
|
31
|
+
* resolves a selector against the listing ({@link resolveApplicationScheduledJobSelector}) and sends the `jobId` the
|
|
32
|
+
* listing named.
|
|
33
|
+
*/
|
|
34
|
+
/** What kind of schedule a job is, read from the shape of its `jobId`. */
|
|
35
|
+
export var ApplicationScheduledJobKind;
|
|
36
|
+
(function (ApplicationScheduledJobKind) {
|
|
37
|
+
/** A resource operation declared with a cron schedule: `<app>:<resourceType>:<operationId>:<variantKey>`. */
|
|
38
|
+
ApplicationScheduledJobKind["RESOURCE_OPERATION"] = "resource_operation";
|
|
39
|
+
/** A custom batch the application registered: `<app>:batch:<batchRef>`. */
|
|
40
|
+
ApplicationScheduledJobKind["BATCH"] = "batch";
|
|
41
|
+
/** A minion's periodic tick: `<app>:minion-tick:<minionName>:<variantKey>`. */
|
|
42
|
+
ApplicationScheduledJobKind["MINION_TICK"] = "minion_tick";
|
|
43
|
+
/**
|
|
44
|
+
* A job of this application whose remainder fits none of the shapes above. Listed and runnable by its exact selector
|
|
45
|
+
* (the remainder after `<applicationId>:`) rather than hidden: a new job shape in the crontabs manager must not make a
|
|
46
|
+
* job disappear from the listing.
|
|
47
|
+
*/
|
|
48
|
+
ApplicationScheduledJobKind["UNRECOGNIZED"] = "unrecognized";
|
|
49
|
+
})(ApplicationScheduledJobKind || (ApplicationScheduledJobKind = {}));
|
|
50
|
+
/**
|
|
51
|
+
* The reserved second segments of a job id. ONE source for the producer (the crontabs manager's `buildJobId`, which
|
|
52
|
+
* builds through the functions below) and the parser ({@link parseApplicationScheduledJobId}), so the two cannot drift:
|
|
53
|
+
* ownership and the selector both depend on this format.
|
|
54
|
+
*/
|
|
55
|
+
export var ApplicationScheduledJobSegment;
|
|
56
|
+
(function (ApplicationScheduledJobSegment) {
|
|
57
|
+
/** A custom batch: `<app>:batch:<batchRef>`. */
|
|
58
|
+
ApplicationScheduledJobSegment["BATCH"] = "batch";
|
|
59
|
+
/** A minion's tick: `<app>:minion-tick:<minionName>:<variantKey>`. Reserved, so it cannot collide with a resource type. */
|
|
60
|
+
ApplicationScheduledJobSegment["MINION_TICK"] = "minion-tick";
|
|
61
|
+
})(ApplicationScheduledJobSegment || (ApplicationScheduledJobSegment = {}));
|
|
62
|
+
const BATCH_JOB_SEGMENT = ApplicationScheduledJobSegment.BATCH;
|
|
63
|
+
const MINION_TICK_JOB_SEGMENT = ApplicationScheduledJobSegment.MINION_TICK;
|
|
64
|
+
/** The id of an application's custom batch job. */
|
|
65
|
+
export function buildApplicationBatchJobId(applicationId, batchRef) {
|
|
66
|
+
return `${applicationId}:${BATCH_JOB_SEGMENT}:${batchRef}`;
|
|
67
|
+
}
|
|
68
|
+
/** The id of a minion's tick job. */
|
|
69
|
+
export function buildApplicationMinionTickJobId(applicationId, minionName, variantKey) {
|
|
70
|
+
return `${applicationId}:${MINION_TICK_JOB_SEGMENT}:${minionName}:${variantKey}`;
|
|
71
|
+
}
|
|
72
|
+
/** The id of a resource operation declared with a cron schedule. */
|
|
73
|
+
export function buildApplicationResourceOperationJobId(applicationId, resourceType, operationId, variantKey) {
|
|
74
|
+
return `${applicationId}:${resourceType}:${operationId}:${variantKey}`;
|
|
75
|
+
}
|
|
76
|
+
/** Why apps-manager refuses to run a scheduled job. Sent as `code` on the refusal, which survives the client sanitizer. */
|
|
77
|
+
export var ApplicationScheduledJobRunRefusal;
|
|
78
|
+
(function (ApplicationScheduledJobRunRefusal) {
|
|
79
|
+
/** The `jobId` does not start with the named application's `<applicationId>:`: it is another application's job, or none. */
|
|
80
|
+
ApplicationScheduledJobRunRefusal["NOT_OWNED_BY_APPLICATION"] = "scheduled_job_not_owned_by_application";
|
|
81
|
+
/**
|
|
82
|
+
* The job is this application's by its id, and the crontabs manager's store holds no such job: it is not scheduled now
|
|
83
|
+
* (typically the backend stopped declaring it after the listing was read). Nothing ran.
|
|
84
|
+
*/
|
|
85
|
+
ApplicationScheduledJobRunRefusal["UNKNOWN_TO_SCHEDULER"] = "scheduled_job_unknown_to_scheduler";
|
|
86
|
+
})(ApplicationScheduledJobRunRefusal || (ApplicationScheduledJobRunRefusal = {}));
|
|
87
|
+
/** The admin path that lists an application's scheduled jobs. */
|
|
88
|
+
export function buildAdminApplicationScheduledJobsPath(appSlug) {
|
|
89
|
+
return `/admin/apps/${encodeURIComponent(appSlug)}/scheduled-jobs`;
|
|
90
|
+
}
|
|
91
|
+
/** The admin path that runs one of an application's scheduled jobs now. The `jobId` travels in the body: it contains `:`. */
|
|
92
|
+
export function buildAdminApplicationScheduledJobRunPath(appSlug) {
|
|
93
|
+
return `${buildAdminApplicationScheduledJobsPath(appSlug)}/run`;
|
|
94
|
+
}
|
|
95
|
+
const ScheduledJobCommonShape = {
|
|
96
|
+
/** The crontabs manager's id, `<applicationId>:…`. */
|
|
97
|
+
jobId: z.string().min(1),
|
|
98
|
+
/** The application-relative name a person types (see the table above). */
|
|
99
|
+
selector: z.string().min(1),
|
|
100
|
+
/** Whether the crontabs replica that answered has the job armed (a standby replica holds jobs it does not arm). */
|
|
101
|
+
armed: z.boolean(),
|
|
102
|
+
};
|
|
103
|
+
export const ApplicationScheduledJobSchema = z.discriminatedUnion('kind', [
|
|
104
|
+
z.strictObject({
|
|
105
|
+
kind: z.literal(ApplicationScheduledJobKind.RESOURCE_OPERATION),
|
|
106
|
+
...ScheduledJobCommonShape,
|
|
107
|
+
resourceType: z.string().min(1),
|
|
108
|
+
operationId: z.string().min(1),
|
|
109
|
+
variantKey: z.string().min(1),
|
|
110
|
+
}),
|
|
111
|
+
z.strictObject({
|
|
112
|
+
kind: z.literal(ApplicationScheduledJobKind.BATCH),
|
|
113
|
+
...ScheduledJobCommonShape,
|
|
114
|
+
batchRef: z.string().min(1),
|
|
115
|
+
}),
|
|
116
|
+
z.strictObject({
|
|
117
|
+
kind: z.literal(ApplicationScheduledJobKind.MINION_TICK),
|
|
118
|
+
...ScheduledJobCommonShape,
|
|
119
|
+
minionName: z.string().min(1),
|
|
120
|
+
variantKey: z.string().min(1),
|
|
121
|
+
}),
|
|
122
|
+
z.strictObject({
|
|
123
|
+
kind: z.literal(ApplicationScheduledJobKind.UNRECOGNIZED),
|
|
124
|
+
...ScheduledJobCommonShape,
|
|
125
|
+
}),
|
|
126
|
+
]);
|
|
127
|
+
/** The answer of `GET /admin/apps/:appSlug/scheduled-jobs`. */
|
|
128
|
+
export const ApplicationScheduledJobsResponseSchema = z.strictObject({
|
|
129
|
+
appSlug: z.string().min(1),
|
|
130
|
+
/** The application's platform id: the prefix of every `jobId` below. */
|
|
131
|
+
applicationId: z.string().min(1),
|
|
132
|
+
/**
|
|
133
|
+
* POSITIVE CONTROL beside an empty `jobs`: how many jobs the crontabs manager holds for EVERY application. Zero jobs for
|
|
134
|
+
* this application beside a platform total of zero says the scheduler holds nothing at all (it has not loaded, or no
|
|
135
|
+
* application has booted), not that this application declares nothing.
|
|
136
|
+
*/
|
|
137
|
+
platformScheduledTotal: z.number().int().min(0),
|
|
138
|
+
/** Whether the scheduler is running on the replica that answered. */
|
|
139
|
+
schedulerRunning: z.boolean(),
|
|
140
|
+
jobs: z.array(ApplicationScheduledJobSchema),
|
|
141
|
+
});
|
|
142
|
+
export const ApplicationScheduledJobRunRequestSchema = z.strictObject({
|
|
143
|
+
/** The crontabs manager's id, exactly as the listing named it. Must belong to the application in the path. */
|
|
144
|
+
jobId: z.string().min(1),
|
|
145
|
+
/** Why, in the operator's words. Optional; recorded on the audit row. */
|
|
146
|
+
reason: z.string().trim().min(1).max(1000).optional(),
|
|
147
|
+
});
|
|
148
|
+
/** The answer of `POST /admin/apps/:appSlug/scheduled-jobs/run`. */
|
|
149
|
+
export const ApplicationScheduledJobRunResponseSchema = z.strictObject({
|
|
150
|
+
appSlug: z.string().min(1),
|
|
151
|
+
applicationId: z.string().min(1),
|
|
152
|
+
jobId: z.string().min(1),
|
|
153
|
+
selector: z.string().min(1),
|
|
154
|
+
/**
|
|
155
|
+
* When the crontabs manager accepted the trigger (ISO 8601). Accepting is not finishing: the occurrence is delivered to
|
|
156
|
+
* the application backend and runs there, asynchronously, exactly as a scheduled tick does.
|
|
157
|
+
*/
|
|
158
|
+
triggeredAt: z.iso.datetime({ offset: true }),
|
|
159
|
+
});
|
|
160
|
+
/** The prefix every job of one application carries. */
|
|
161
|
+
function applicationJobIdPrefix(applicationId) {
|
|
162
|
+
return `${applicationId}:`;
|
|
163
|
+
}
|
|
164
|
+
/** Whether `jobId` is one of this application's jobs: it carries the application's prefix and something after it. */
|
|
165
|
+
export function applicationOwnsScheduledJobId(applicationId, jobId) {
|
|
166
|
+
const prefix = applicationJobIdPrefix(applicationId);
|
|
167
|
+
return applicationId.length > 0 && jobId.startsWith(prefix) && jobId.length > prefix.length;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Read one of this application's jobs from its `jobId`, or `null` when the job is not this application's.
|
|
171
|
+
*
|
|
172
|
+
* The batch segment is checked BEFORE the resource-operation shape, mirroring the producer: `buildJobId` writes
|
|
173
|
+
* `<app>:batch:<ref>` for any job with a `batchRef`, and a batch ref may itself contain `:`.
|
|
174
|
+
*/
|
|
175
|
+
export function parseApplicationScheduledJobId(applicationId, jobId, armed) {
|
|
176
|
+
if (!applicationOwnsScheduledJobId(applicationId, jobId))
|
|
177
|
+
return null;
|
|
178
|
+
const remainder = jobId.slice(applicationJobIdPrefix(applicationId).length);
|
|
179
|
+
const segments = remainder.split(':');
|
|
180
|
+
if (segments[0] === BATCH_JOB_SEGMENT && segments.length >= 2) {
|
|
181
|
+
const batchRef = segments.slice(1).join(':');
|
|
182
|
+
if (batchRef.length > 0) {
|
|
183
|
+
return { kind: ApplicationScheduledJobKind.BATCH, jobId, selector: `${BATCH_JOB_SEGMENT}:${batchRef}`, armed, batchRef };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const [first, second, third] = segments;
|
|
187
|
+
const threeSegments = segments.length === 3 && Boolean(first) && Boolean(second) && Boolean(third);
|
|
188
|
+
if (threeSegments && first === MINION_TICK_JOB_SEGMENT) {
|
|
189
|
+
return {
|
|
190
|
+
kind: ApplicationScheduledJobKind.MINION_TICK,
|
|
191
|
+
jobId,
|
|
192
|
+
selector: `${MINION_TICK_JOB_SEGMENT}:${second}:${third}`,
|
|
193
|
+
armed,
|
|
194
|
+
minionName: second,
|
|
195
|
+
variantKey: third,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
if (threeSegments && first !== BATCH_JOB_SEGMENT) {
|
|
199
|
+
return {
|
|
200
|
+
kind: ApplicationScheduledJobKind.RESOURCE_OPERATION,
|
|
201
|
+
jobId,
|
|
202
|
+
selector: `${first}.${second}:${third}`,
|
|
203
|
+
armed,
|
|
204
|
+
resourceType: first,
|
|
205
|
+
operationId: second,
|
|
206
|
+
variantKey: third,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return { kind: ApplicationScheduledJobKind.UNRECOGNIZED, jobId, selector: remainder, armed };
|
|
210
|
+
}
|
|
211
|
+
/** How a selector resolved against a listing. */
|
|
212
|
+
export var ApplicationScheduledJobSelectorResolution;
|
|
213
|
+
(function (ApplicationScheduledJobSelectorResolution) {
|
|
214
|
+
/** Exactly one job matches. */
|
|
215
|
+
ApplicationScheduledJobSelectorResolution["RESOLVED"] = "resolved";
|
|
216
|
+
/** No job matches. `candidates` is the whole listing, so the caller can show what exists. */
|
|
217
|
+
ApplicationScheduledJobSelectorResolution["NOT_FOUND"] = "not_found";
|
|
218
|
+
/** Several jobs match (a resource operation scheduled under several variants, named without one). */
|
|
219
|
+
ApplicationScheduledJobSelectorResolution["AMBIGUOUS"] = "ambiguous";
|
|
220
|
+
})(ApplicationScheduledJobSelectorResolution || (ApplicationScheduledJobSelectorResolution = {}));
|
|
221
|
+
/**
|
|
222
|
+
* Whether `job` answers `selector`. A job's full selector always matches. The variant may be left out: `<resourceType>.<op>`
|
|
223
|
+
* matches that operation under every variant, and `minion-tick:<name>` that minion's tick, so the common case (one
|
|
224
|
+
* variant, usually `default`) needs no variant typed. Matching is exact otherwise: no case folding and no prefix guessing,
|
|
225
|
+
* so a selector never runs a job other than the one named.
|
|
226
|
+
*/
|
|
227
|
+
function jobAnswersSelector(job, selector) {
|
|
228
|
+
if (job.selector === selector)
|
|
229
|
+
return true;
|
|
230
|
+
switch (job.kind) {
|
|
231
|
+
case ApplicationScheduledJobKind.RESOURCE_OPERATION:
|
|
232
|
+
return selector === `${job.resourceType}.${job.operationId}`;
|
|
233
|
+
case ApplicationScheduledJobKind.MINION_TICK:
|
|
234
|
+
return selector === `${MINION_TICK_JOB_SEGMENT}:${job.minionName}`;
|
|
235
|
+
case ApplicationScheduledJobKind.BATCH:
|
|
236
|
+
case ApplicationScheduledJobKind.UNRECOGNIZED:
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/** Resolve what a person typed to exactly one job of the listing, or say why it cannot be. */
|
|
241
|
+
export function resolveApplicationScheduledJobSelector(jobs, selector) {
|
|
242
|
+
const wanted = selector.trim();
|
|
243
|
+
const matches = jobs.filter((job) => jobAnswersSelector(job, wanted));
|
|
244
|
+
if (matches.length === 1)
|
|
245
|
+
return { resolution: ApplicationScheduledJobSelectorResolution.RESOLVED, job: matches[0] };
|
|
246
|
+
if (matches.length === 0)
|
|
247
|
+
return { resolution: ApplicationScheduledJobSelectorResolution.NOT_FOUND, candidates: [...jobs] };
|
|
248
|
+
return { resolution: ApplicationScheduledJobSelectorResolution.AMBIGUOUS, matches };
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=application-scheduled-jobs.contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"application-scheduled-jobs.contracts.js","sourceRoot":"","sources":["../../../src/bootstrap/application-scheduled-jobs.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,0EAA0E;AAC1E,MAAM,CAAN,IAAY,2BAaX;AAbD,WAAY,2BAA2B;IACrC,6GAA6G;IAC7G,wEAAyC,CAAA;IACzC,2EAA2E;IAC3E,8CAAe,CAAA;IACf,+EAA+E;IAC/E,0DAA2B,CAAA;IAC3B;;;;OAIG;IACH,4DAA6B,CAAA;AAC/B,CAAC,EAbW,2BAA2B,KAA3B,2BAA2B,QAatC;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,8BAKX;AALD,WAAY,8BAA8B;IACxC,gDAAgD;IAChD,iDAAe,CAAA;IACf,2HAA2H;IAC3H,6DAA2B,CAAA;AAC7B,CAAC,EALW,8BAA8B,KAA9B,8BAA8B,QAKzC;AAED,MAAM,iBAAiB,GAAG,8BAA8B,CAAC,KAAK,CAAC;AAC/D,MAAM,uBAAuB,GAAG,8BAA8B,CAAC,WAAW,CAAC;AAE3E,mDAAmD;AACnD,MAAM,UAAU,0BAA0B,CAAC,aAAqB,EAAE,QAAgB;IAChF,OAAO,GAAG,aAAa,IAAI,iBAAiB,IAAI,QAAQ,EAAE,CAAC;AAC7D,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,+BAA+B,CAAC,aAAqB,EAAE,UAAkB,EAAE,UAAkB;IAC3G,OAAO,GAAG,aAAa,IAAI,uBAAuB,IAAI,UAAU,IAAI,UAAU,EAAE,CAAC;AACnF,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,sCAAsC,CAAC,aAAqB,EAAE,YAAoB,EAAE,WAAmB,EAAE,UAAkB;I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AAC,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,yCAAyC,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACrH,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,yCAAyC,CAAC,SAAS,EAAE,UAAU,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;IAC5H,OAAO,EAAE,UAAU,EAAE,yCAAyC,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;AACtF,CAAC","sourcesContent":["import { z } from 'zod';\n\n/**\n * # Running one of an application's scheduled jobs NOW (#4006)\n *\n * A scheduled job runs at its next tick. A developer, or the finalization verifier, who needs what a job writes (a\n * recurring todo's occurrences, written hourly by `todosRecurringOccurrences.run_recurring_generation`) would otherwise\n * wait up to an hour. The crontabs manager already has a manual trigger, but only apps-manager may call it, so the door is\n * an apps-manager ADMIN route behind `PLATFORM_ADMIN_SECRET`, and the CLI verb is `wildo local jobs run <selector>`.\n *\n * Decided by practice: a \"run this scheduled job now\" door is standard (`kubectl create job --from=cronjob/<name>`,\n * Laravel's `schedule:test`, the Run button on Vercel cron jobs). It runs the job's ordinary execution once and does not\n * change its schedule.\n *\n * ## Who owns a job\n *\n * The crontabs manager keys every job on the application's platform id (the `wildoapplication` ROW id, which is what\n * `cronjobs.applicationId` holds) as the first segment of its `jobId`:\n *\n * | kind | `jobId` | selector |\n * |---|---|---|\n * | resource cron operation | `<applicationId>:<resourceType>:<operationId>:<variantKey>` | `<resourceType>.<operationId>:<variantKey>` |\n * | custom batch | `<applicationId>:batch:<batchRef>` | `batch:<batchRef>` |\n * | minion tick | `<applicationId>:minion-tick:<minionName>:<variantKey>` | `minion-tick:<minionName>:<variantKey>` |\n *\n * (`buildJobId` in the crontabs manager's `application-jobs-sync.crontab.controller.ts` is the producer.) So ownership is\n * the prefix `<applicationId>:`, and apps-manager refuses to trigger a job outside it\n * ({@link ApplicationScheduledJobRunRefusal.NOT_OWNED_BY_APPLICATION}): the admin route names ONE application, and a job of\n * another must not be reachable through it.\n *\n * The SELECTOR is the application-relative name a person types. Nobody builds `<applicationId>:…` by hand: the CLI\n * resolves a selector against the listing ({@link resolveApplicationScheduledJobSelector}) and sends the `jobId` the\n * listing named.\n */\n\n/** What kind of schedule a job is, read from the shape of its `jobId`. */\nexport enum ApplicationScheduledJobKind {\n /** A resource operation declared with a cron schedule: `<app>:<resourceType>:<operationId>:<variantKey>`. */\n RESOURCE_OPERATION = 'resource_operation',\n /** A custom batch the application registered: `<app>:batch:<batchRef>`. */\n BATCH = 'batch',\n /** A minion's periodic tick: `<app>:minion-tick:<minionName>:<variantKey>`. */\n MINION_TICK = 'minion_tick',\n /**\n * A job of this application whose remainder fits none of the shapes above. Listed and runnable by its exact selector\n * (the remainder after `<applicationId>:`) rather than hidden: a new job shape in the crontabs manager must not make a\n * job disappear from the listing.\n */\n UNRECOGNIZED = 'unrecognized',\n}\n\n/**\n * The reserved second segments of a job id. ONE source for the producer (the crontabs manager's `buildJobId`, which\n * builds through the functions below) and the parser ({@link parseApplicationScheduledJobId}), so the two cannot drift:\n * ownership and the selector both depend on this format.\n */\nexport enum ApplicationScheduledJobSegment {\n /** A custom batch: `<app>:batch:<batchRef>`. */\n BATCH = 'batch',\n /** A minion's tick: `<app>:minion-tick:<minionName>:<variantKey>`. Reserved, so it cannot collide with a resource type. */\n MINION_TICK = 'minion-tick',\n}\n\nconst BATCH_JOB_SEGMENT = ApplicationScheduledJobSegment.BATCH;\nconst MINION_TICK_JOB_SEGMENT = ApplicationScheduledJobSegment.MINION_TICK;\n\n/** The id of an application's custom batch job. */\nexport function buildApplicationBatchJobId(applicationId: string, batchRef: string): string {\n return `${applicationId}:${BATCH_JOB_SEGMENT}:${batchRef}`;\n}\n\n/** The id of a minion's tick job. */\nexport function buildApplicationMinionTickJobId(applicationId: string, minionName: string, variantKey: string): string {\n return `${applicationId}:${MINION_TICK_JOB_SEGMENT}:${minionName}:${variantKey}`;\n}\n\n/** The id of a resource operation declared with a cron schedule. */\nexport function buildApplicationResourceOperationJobId(applicationId: string, resourceType: string, operationId: string, variantKey: string): string {\n return `${applicationId}:${resourceType}:${operationId}:${variantKey}`;\n}\n\n/** Why apps-manager refuses to run a scheduled job. Sent as `code` on the refusal, which survives the client sanitizer. */\nexport enum ApplicationScheduledJobRunRefusal {\n /** The `jobId` does not start with the named application's `<applicationId>:`: it is another application's job, or none. */\n NOT_OWNED_BY_APPLICATION = 'scheduled_job_not_owned_by_application',\n /**\n * The job is this application's by its id, and the crontabs manager's store holds no such job: it is not scheduled now\n * (typically the backend stopped declaring it after the listing was read). Nothing ran.\n */\n UNKNOWN_TO_SCHEDULER = 'scheduled_job_unknown_to_scheduler',\n}\n\n/** The admin path that lists an application's scheduled jobs. */\nexport function buildAdminApplicationScheduledJobsPath(appSlug: string): string {\n return `/admin/apps/${encodeURIComponent(appSlug)}/scheduled-jobs`;\n}\n\n/** The admin path that runs one of an application's scheduled jobs now. The `jobId` travels in the body: it contains `:`. */\nexport function buildAdminApplicationScheduledJobRunPath(appSlug: string): string {\n return `${buildAdminApplicationScheduledJobsPath(appSlug)}/run`;\n}\n\nconst ScheduledJobCommonShape = {\n /** The crontabs manager's id, `<applicationId>:…`. */\n jobId: z.string().min(1),\n /** The application-relative name a person types (see the table above). */\n selector: z.string().min(1),\n /** Whether the crontabs replica that answered has the job armed (a standby replica holds jobs it does not arm). */\n armed: z.boolean(),\n};\n\nexport const ApplicationScheduledJobSchema = z.discriminatedUnion('kind', [\n z.strictObject({\n kind: z.literal(ApplicationScheduledJobKind.RESOURCE_OPERATION),\n ...ScheduledJobCommonShape,\n resourceType: z.string().min(1),\n operationId: z.string().min(1),\n variantKey: z.string().min(1),\n }),\n z.strictObject({\n kind: z.literal(ApplicationScheduledJobKind.BATCH),\n ...ScheduledJobCommonShape,\n batchRef: z.string().min(1),\n }),\n z.strictObject({\n kind: z.literal(ApplicationScheduledJobKind.MINION_TICK),\n ...ScheduledJobCommonShape,\n minionName: z.string().min(1),\n variantKey: z.string().min(1),\n }),\n z.strictObject({\n kind: z.literal(ApplicationScheduledJobKind.UNRECOGNIZED),\n ...ScheduledJobCommonShape,\n }),\n]);\nexport type ApplicationScheduledJob = z.infer<typeof ApplicationScheduledJobSchema>;\n\n/** The answer of `GET /admin/apps/:appSlug/scheduled-jobs`. */\nexport const ApplicationScheduledJobsResponseSchema = z.strictObject({\n appSlug: z.string().min(1),\n /** The application's platform id: the prefix of every `jobId` below. */\n applicationId: z.string().min(1),\n /**\n * POSITIVE CONTROL beside an empty `jobs`: how many jobs the crontabs manager holds for EVERY application. Zero jobs for\n * this application beside a platform total of zero says the scheduler holds nothing at all (it has not loaded, or no\n * application has booted), not that this application declares nothing.\n */\n platformScheduledTotal: z.number().int().min(0),\n /** Whether the scheduler is running on the replica that answered. */\n schedulerRunning: z.boolean(),\n jobs: z.array(ApplicationScheduledJobSchema),\n});\nexport type ApplicationScheduledJobsResponse = z.infer<typeof ApplicationScheduledJobsResponseSchema>;\n\nexport const ApplicationScheduledJobRunRequestSchema = z.strictObject({\n /** The crontabs manager's id, exactly as the listing named it. Must belong to the application in the path. */\n jobId: z.string().min(1),\n /** Why, in the operator's words. Optional; recorded on the audit row. */\n reason: z.string().trim().min(1).max(1000).optional(),\n});\nexport type ApplicationScheduledJobRunRequest = z.input<typeof ApplicationScheduledJobRunRequestSchema>;\n\n/** The answer of `POST /admin/apps/:appSlug/scheduled-jobs/run`. */\nexport const ApplicationScheduledJobRunResponseSchema = z.strictObject({\n appSlug: z.string().min(1),\n applicationId: z.string().min(1),\n jobId: z.string().min(1),\n selector: z.string().min(1),\n /**\n * When the crontabs manager accepted the trigger (ISO 8601). Accepting is not finishing: the occurrence is delivered to\n * the application backend and runs there, asynchronously, exactly as a scheduled tick does.\n */\n triggeredAt: z.iso.datetime({ offset: true }),\n});\nexport type ApplicationScheduledJobRunResponse = z.infer<typeof ApplicationScheduledJobRunResponseSchema>;\n\n/** The prefix every job of one application carries. */\nfunction applicationJobIdPrefix(applicationId: string): string {\n return `${applicationId}:`;\n}\n\n/** Whether `jobId` is one of this application's jobs: it carries the application's prefix and something after it. */\nexport function applicationOwnsScheduledJobId(applicationId: string, jobId: string): boolean {\n const prefix = applicationJobIdPrefix(applicationId);\n return applicationId.length > 0 && jobId.startsWith(prefix) && jobId.length > prefix.length;\n}\n\n/**\n * Read one of this application's jobs from its `jobId`, or `null` when the job is not this application's.\n *\n * The batch segment is checked BEFORE the resource-operation shape, mirroring the producer: `buildJobId` writes\n * `<app>:batch:<ref>` for any job with a `batchRef`, and a batch ref may itself contain `:`.\n */\nexport function parseApplicationScheduledJobId(applicationId: string, jobId: string, armed: boolean): ApplicationScheduledJob | null {\n if (!applicationOwnsScheduledJobId(applicationId, jobId)) return null;\n const remainder = jobId.slice(applicationJobIdPrefix(applicationId).length);\n const segments = remainder.split(':');\n\n if (segments[0] === BATCH_JOB_SEGMENT && segments.length >= 2) {\n const batchRef = segments.slice(1).join(':');\n if (batchRef.length > 0) {\n return { kind: ApplicationScheduledJobKind.BATCH, jobId, selector: `${BATCH_JOB_SEGMENT}:${batchRef}`, armed, batchRef };\n }\n }\n\n const [first, second, third] = segments;\n const threeSegments = segments.length === 3 && Boolean(first) && Boolean(second) && Boolean(third);\n\n if (threeSegments && first === MINION_TICK_JOB_SEGMENT) {\n return {\n kind: ApplicationScheduledJobKind.MINION_TICK,\n jobId,\n selector: `${MINION_TICK_JOB_SEGMENT}:${second}:${third}`,\n armed,\n minionName: second,\n variantKey: third,\n };\n }\n\n if (threeSegments && first !== BATCH_JOB_SEGMENT) {\n return {\n kind: ApplicationScheduledJobKind.RESOURCE_OPERATION,\n jobId,\n selector: `${first}.${second}:${third}`,\n armed,\n resourceType: first,\n operationId: second,\n variantKey: third,\n };\n }\n\n return { kind: ApplicationScheduledJobKind.UNRECOGNIZED, jobId, selector: remainder, armed };\n}\n\n/** How a selector resolved against a listing. */\nexport enum ApplicationScheduledJobSelectorResolution {\n /** Exactly one job matches. */\n RESOLVED = 'resolved',\n /** No job matches. `candidates` is the whole listing, so the caller can show what exists. */\n NOT_FOUND = 'not_found',\n /** Several jobs match (a resource operation scheduled under several variants, named without one). */\n AMBIGUOUS = 'ambiguous',\n}\n\nexport type ApplicationScheduledJobSelectorResult =\n | { resolution: ApplicationScheduledJobSelectorResolution.RESOLVED; job: ApplicationScheduledJob }\n | { resolution: ApplicationScheduledJobSelectorResolution.NOT_FOUND; candidates: ApplicationScheduledJob[] }\n | { resolution: ApplicationScheduledJobSelectorResolution.AMBIGUOUS; matches: ApplicationScheduledJob[] };\n\n/**\n * Whether `job` answers `selector`. A job's full selector always matches. The variant may be left out: `<resourceType>.<op>`\n * matches that operation under every variant, and `minion-tick:<name>` that minion's tick, so the common case (one\n * variant, usually `default`) needs no variant typed. Matching is exact otherwise: no case folding and no prefix guessing,\n * so a selector never runs a job other than the one named.\n */\nfunction jobAnswersSelector(job: ApplicationScheduledJob, selector: string): boolean {\n if (job.selector === selector) return true;\n switch (job.kind) {\n case ApplicationScheduledJobKind.RESOURCE_OPERATION:\n return selector === `${job.resourceType}.${job.operationId}`;\n case ApplicationScheduledJobKind.MINION_TICK:\n return selector === `${MINION_TICK_JOB_SEGMENT}:${job.minionName}`;\n case ApplicationScheduledJobKind.BATCH:\n case ApplicationScheduledJobKind.UNRECOGNIZED:\n return false;\n }\n}\n\n/** Resolve what a person typed to exactly one job of the listing, or say why it cannot be. */\nexport function resolveApplicationScheduledJobSelector(jobs: readonly ApplicationScheduledJob[], selector: string): ApplicationScheduledJobSelectorResult {\n const wanted = selector.trim();\n const matches = jobs.filter((job) => jobAnswersSelector(job, wanted));\n if (matches.length === 1) return { resolution: ApplicationScheduledJobSelectorResolution.RESOLVED, job: matches[0] };\n if (matches.length === 0) return { resolution: ApplicationScheduledJobSelectorResolution.NOT_FOUND, candidates: [...jobs] };\n return { resolution: ApplicationScheduledJobSelectorResolution.AMBIGUOUS, matches };\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which rows of the DATABASE queue a minion may reach (#2303).
|
|
3
|
+
*
|
|
4
|
+
* Under the `small` service profile the application's processes share the queue kept in its own database
|
|
5
|
+
* (`QueueAdapterType.DATABASE`, the `queueMessages` resource). A minion's PostgreSQL role then needs that table, and a
|
|
6
|
+
* plain table grant would let it read and delete every queued job of its application, where its RabbitMQ credential
|
|
7
|
+
* reads only its own queues (`buildMinionConsumeRegex` in `@wildo-ai/platform-infra-providers`'s RabbitMQ module). This
|
|
8
|
+
* derives the same confinement as rows: its tick queue, the queues under it, and its own reply queues. Applied as a
|
|
9
|
+
* PostgreSQL row-level security policy through the owed-grants contract (`postgresql-owed-grants.contracts.ts`).
|
|
10
|
+
*
|
|
11
|
+
* The names come from the builders the runtime itself uses (`buildMinionTickQueueName`, `buildReplyQueueNamePrefix`,
|
|
12
|
+
* {@link buildRuntimePrincipalQueueSegment}), so the policy and the queue names cannot drift.
|
|
13
|
+
*
|
|
14
|
+
* MongoDB has no row-level security, so a MongoDB application's minions get nothing here, and the `small` profile refuses
|
|
15
|
+
* them (`describeMinionsRefusedByEnvironmentServiceProfile`).
|
|
16
|
+
*/
|
|
17
|
+
import { type ResourceType } from '@wildo-ai/saas-models';
|
|
18
|
+
import { type PostgresOwedRowMatchRule } from './postgresql-owed-grants.contracts';
|
|
19
|
+
/**
|
|
20
|
+
* The resource type of the DATABASE queue's table, in the platform's vocabulary. The engine declares it as
|
|
21
|
+
* `BackendResourceType.QUEUE_MESSAGES` in `@wildo-ai/saas-backend-lib`, which this package cannot import; a test there
|
|
22
|
+
* holds the two equal.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DATABASE_QUEUE_MESSAGES_RESOURCE_TYPE: ResourceType;
|
|
25
|
+
/** The field of a queue message naming its queue (`QueueMessageRow.queueName`; held equal by the same test). */
|
|
26
|
+
export declare const DATABASE_QUEUE_NAME_FIELD = "queueName";
|
|
27
|
+
/** The queue rows one minion may reach: a resource type, the field the policy reads, and the rules. */
|
|
28
|
+
export interface MinionDatabaseQueueConfinement {
|
|
29
|
+
readonly resourceType: ResourceType;
|
|
30
|
+
readonly field: string;
|
|
31
|
+
readonly rowsReachable: readonly PostgresOwedRowMatchRule[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The DATABASE queue rows a minion may lease, settle and delete. Inserting is not confined (see
|
|
35
|
+
* `PostgresRowConfinedTableGrant`): a minion publishes work anywhere in its application, as its broker credential may.
|
|
36
|
+
*
|
|
37
|
+
* Refuses a minion name that sanitises to nothing: its reply segment would be absent, and the reply prefix without a
|
|
38
|
+
* segment is the backend's, which prefixes every runtime's replies.
|
|
39
|
+
*/
|
|
40
|
+
export declare function deriveMinionDatabaseQueueConfinement(wildoApplicationId: string, minionName: string): MinionDatabaseQueueConfinement;
|
|
41
|
+
//# sourceMappingURL=minion-database-queue-confinement.contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minion-database-queue-confinement.contracts.d.ts","sourceRoot":"","sources":["../../../src/bootstrap/minion-database-queue-confinement.contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAwB,KAAK,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAGzG;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,EAAE,YAA8B,CAAC;AAEnF,gHAAgH;AAChH,eAAO,MAAM,yBAAyB,cAAc,CAAC;AAErD,uGAAuG;AACvG,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,EAAE,SAAS,wBAAwB,EAAE,CAAC;CAC7D;AAED;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAAC,kBAAkB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,8BAA8B,CAmBnI"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which rows of the DATABASE queue a minion may reach (#2303).
|
|
3
|
+
*
|
|
4
|
+
* Under the `small` service profile the application's processes share the queue kept in its own database
|
|
5
|
+
* (`QueueAdapterType.DATABASE`, the `queueMessages` resource). A minion's PostgreSQL role then needs that table, and a
|
|
6
|
+
* plain table grant would let it read and delete every queued job of its application, where its RabbitMQ credential
|
|
7
|
+
* reads only its own queues (`buildMinionConsumeRegex` in `@wildo-ai/platform-infra-providers`'s RabbitMQ module). This
|
|
8
|
+
* derives the same confinement as rows: its tick queue, the queues under it, and its own reply queues. Applied as a
|
|
9
|
+
* PostgreSQL row-level security policy through the owed-grants contract (`postgresql-owed-grants.contracts.ts`).
|
|
10
|
+
*
|
|
11
|
+
* The names come from the builders the runtime itself uses (`buildMinionTickQueueName`, `buildReplyQueueNamePrefix`,
|
|
12
|
+
* {@link buildRuntimePrincipalQueueSegment}), so the policy and the queue names cannot drift.
|
|
13
|
+
*
|
|
14
|
+
* MongoDB has no row-level security, so a MongoDB application's minions get nothing here, and the `small` profile refuses
|
|
15
|
+
* them (`describeMinionsRefusedByEnvironmentServiceProfile`).
|
|
16
|
+
*/
|
|
17
|
+
import { QueueNamingUtils } from '@wildo-ai/saas-models';
|
|
18
|
+
import { PostgresOwedRowMatch } from './postgresql-owed-grants.contracts.js';
|
|
19
|
+
import { ApplicationRuntimePrincipalKind, buildRuntimePrincipalQueueSegment } from './runtime-principal.contracts.js';
|
|
20
|
+
/**
|
|
21
|
+
* The resource type of the DATABASE queue's table, in the platform's vocabulary. The engine declares it as
|
|
22
|
+
* `BackendResourceType.QUEUE_MESSAGES` in `@wildo-ai/saas-backend-lib`, which this package cannot import; a test there
|
|
23
|
+
* holds the two equal.
|
|
24
|
+
*/
|
|
25
|
+
export const DATABASE_QUEUE_MESSAGES_RESOURCE_TYPE = 'queueMessages';
|
|
26
|
+
/** The field of a queue message naming its queue (`QueueMessageRow.queueName`; held equal by the same test). */
|
|
27
|
+
export const DATABASE_QUEUE_NAME_FIELD = 'queueName';
|
|
28
|
+
/**
|
|
29
|
+
* The DATABASE queue rows a minion may lease, settle and delete. Inserting is not confined (see
|
|
30
|
+
* `PostgresRowConfinedTableGrant`): a minion publishes work anywhere in its application, as its broker credential may.
|
|
31
|
+
*
|
|
32
|
+
* Refuses a minion name that sanitises to nothing: its reply segment would be absent, and the reply prefix without a
|
|
33
|
+
* segment is the backend's, which prefixes every runtime's replies.
|
|
34
|
+
*/
|
|
35
|
+
export function deriveMinionDatabaseQueueConfinement(wildoApplicationId, minionName) {
|
|
36
|
+
const replySegment = buildRuntimePrincipalQueueSegment(ApplicationRuntimePrincipalKind.MINION, minionName);
|
|
37
|
+
if (!wildoApplicationId || !replySegment) {
|
|
38
|
+
throw new Error(`Cannot confine minion "${minionName}" of application "${wildoApplicationId}" to its own queues: `
|
|
39
|
+
+ 'its application id or its queue segment is empty, and a confinement built from either would reach other runtimes\' rows.');
|
|
40
|
+
}
|
|
41
|
+
const tickQueue = QueueNamingUtils.buildMinionTickQueueName(wildoApplicationId, minionName);
|
|
42
|
+
return {
|
|
43
|
+
resourceType: DATABASE_QUEUE_MESSAGES_RESOURCE_TYPE,
|
|
44
|
+
field: DATABASE_QUEUE_NAME_FIELD,
|
|
45
|
+
rowsReachable: [
|
|
46
|
+
{ kind: PostgresOwedRowMatch.EXACT, value: tickQueue },
|
|
47
|
+
// The broker regex admits `<tick>(\..*)?`: the tick queue's own sub-queues (a dead-letter or delay queue).
|
|
48
|
+
{ kind: PostgresOwedRowMatch.PREFIX, value: `${tickQueue}.` },
|
|
49
|
+
{ kind: PostgresOwedRowMatch.PREFIX, value: QueueNamingUtils.buildReplyQueueNamePrefix(wildoApplicationId, replySegment) },
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=minion-database-queue-confinement.contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"minion-database-queue-confinement.contracts.js","sourceRoot":"","sources":["../../../src/bootstrap/minion-database-queue-confinement.contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,gBAAgB,EAAqB,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,oBAAoB,EAAiC,MAAM,oCAAoC,CAAC;AACzG,OAAO,EAAE,+BAA+B,EAAE,iCAAiC,EAAE,MAAM,+BAA+B,CAAC;AAEnH;;;;GAIG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAiB,eAAe,CAAC;AAEnF,gHAAgH;AAChH,MAAM,CAAC,MAAM,yBAAyB,GAAG,WAAW,CAAC;AASrD;;;;;;GAMG;AACH,MAAM,UAAU,oCAAoC,CAAC,kBAA0B,EAAE,UAAkB;IACjG,MAAM,YAAY,GAAG,iCAAiC,CAAC,+BAA+B,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3G,IAAI,CAAC,kBAAkB,IAAI,CAAC,YAAY,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,qBAAqB,kBAAkB,uBAAuB;cAChG,0HAA0H,CAC7H,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,gBAAgB,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,UAAU,CAAC,CAAC;IAC5F,OAAO;QACL,YAAY,EAAE,qCAAqC;QACnD,KAAK,EAAE,yBAAyB;QAChC,aAAa,EAAE;YACb,EAAE,IAAI,EAAE,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;YACtD,2GAA2G;YAC3G,EAAE,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,GAAG,EAAE;YAC7D,EAAE,IAAI,EAAE,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,yBAAyB,CAAC,kBAAkB,EAAE,YAAY,CAAC,EAAE;SAC3H;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Which rows of the DATABASE queue a minion may reach (#2303).\n *\n * Under the `small` service profile the application's processes share the queue kept in its own database\n * (`QueueAdapterType.DATABASE`, the `queueMessages` resource). A minion's PostgreSQL role then needs that table, and a\n * plain table grant would let it read and delete every queued job of its application, where its RabbitMQ credential\n * reads only its own queues (`buildMinionConsumeRegex` in `@wildo-ai/platform-infra-providers`'s RabbitMQ module). This\n * derives the same confinement as rows: its tick queue, the queues under it, and its own reply queues. Applied as a\n * PostgreSQL row-level security policy through the owed-grants contract (`postgresql-owed-grants.contracts.ts`).\n *\n * The names come from the builders the runtime itself uses (`buildMinionTickQueueName`, `buildReplyQueueNamePrefix`,\n * {@link buildRuntimePrincipalQueueSegment}), so the policy and the queue names cannot drift.\n *\n * MongoDB has no row-level security, so a MongoDB application's minions get nothing here, and the `small` profile refuses\n * them (`describeMinionsRefusedByEnvironmentServiceProfile`).\n */\nimport { QueueNamingUtils, type ResourceType } from '@wildo-ai/saas-models';\n\nimport { PostgresOwedRowMatch, type PostgresOwedRowMatchRule } from './postgresql-owed-grants.contracts';\nimport { ApplicationRuntimePrincipalKind, buildRuntimePrincipalQueueSegment } from './runtime-principal.contracts';\n\n/**\n * The resource type of the DATABASE queue's table, in the platform's vocabulary. The engine declares it as\n * `BackendResourceType.QUEUE_MESSAGES` in `@wildo-ai/saas-backend-lib`, which this package cannot import; a test there\n * holds the two equal.\n */\nexport const DATABASE_QUEUE_MESSAGES_RESOURCE_TYPE: ResourceType = 'queueMessages';\n\n/** The field of a queue message naming its queue (`QueueMessageRow.queueName`; held equal by the same test). */\nexport const DATABASE_QUEUE_NAME_FIELD = 'queueName';\n\n/** The queue rows one minion may reach: a resource type, the field the policy reads, and the rules. */\nexport interface MinionDatabaseQueueConfinement {\n readonly resourceType: ResourceType;\n readonly field: string;\n readonly rowsReachable: readonly PostgresOwedRowMatchRule[];\n}\n\n/**\n * The DATABASE queue rows a minion may lease, settle and delete. Inserting is not confined (see\n * `PostgresRowConfinedTableGrant`): a minion publishes work anywhere in its application, as its broker credential may.\n *\n * Refuses a minion name that sanitises to nothing: its reply segment would be absent, and the reply prefix without a\n * segment is the backend's, which prefixes every runtime's replies.\n */\nexport function deriveMinionDatabaseQueueConfinement(wildoApplicationId: string, minionName: string): MinionDatabaseQueueConfinement {\n const replySegment = buildRuntimePrincipalQueueSegment(ApplicationRuntimePrincipalKind.MINION, minionName);\n if (!wildoApplicationId || !replySegment) {\n throw new Error(\n `Cannot confine minion \"${minionName}\" of application \"${wildoApplicationId}\" to its own queues: `\n + 'its application id or its queue segment is empty, and a confinement built from either would reach other runtimes\\' rows.',\n );\n }\n const tickQueue = QueueNamingUtils.buildMinionTickQueueName(wildoApplicationId, minionName);\n return {\n resourceType: DATABASE_QUEUE_MESSAGES_RESOURCE_TYPE,\n field: DATABASE_QUEUE_NAME_FIELD,\n rowsReachable: [\n { kind: PostgresOwedRowMatch.EXACT, value: tickQueue },\n // The broker regex admits `<tick>(\\..*)?`: the tick queue's own sub-queues (a dead-letter or delay queue).\n { kind: PostgresOwedRowMatch.PREFIX, value: `${tickQueue}.` },\n { kind: PostgresOwedRowMatch.PREFIX, value: QueueNamingUtils.buildReplyQueueNamePrefix(wildoApplicationId, replySegment) },\n ],\n };\n}\n"]}
|
|
@@ -56,6 +56,18 @@ export declare enum PlatformInfrastructureEnvKey {
|
|
|
56
56
|
RABBITMQ_VHOST = "RABBITMQ_VHOST",
|
|
57
57
|
RABBITMQ_ADMIN_USERNAME = "RABBITMQ_ADMIN_USERNAME",
|
|
58
58
|
RABBITMQ_ADMIN_PASSWORD = "RABBITMQ_ADMIN_PASSWORD",
|
|
59
|
+
/**
|
|
60
|
+
* The environment's service profile (`EnvironmentServiceProfile`), as the PLATFORM services read it (#2303 slice D).
|
|
61
|
+
* apps-manager derives from it whether the platform runs a message broker
|
|
62
|
+
* (`environmentServiceProfileRunsMessageBroker`), so under a profile whose queue lives in each application's database
|
|
63
|
+
* it initializes no RabbitMQ admin client and mints no vhost or credentials. Absent ⇒ FULL; emitted only when not the
|
|
64
|
+
* default.
|
|
65
|
+
*
|
|
66
|
+
* A key of its own, not the application backend's `ENVIRONMENT_SERVICE_PROFILE`: platform services boot through the
|
|
67
|
+
* engine's `StartApplicationBackendService`, whose APPLICATION refusals (a Layer-2 audit trail, MongoDB search, a
|
|
68
|
+
* required scan, all keyed on that key) describe what an application may declare, not what a platform service runs.
|
|
69
|
+
*/
|
|
70
|
+
PLATFORM_ENVIRONMENT_SERVICE_PROFILE = "PLATFORM_ENVIRONMENT_SERVICE_PROFILE",
|
|
59
71
|
STORAGE_PROVIDER = "STORAGE_PROVIDER",
|
|
60
72
|
/**
|
|
61
73
|
* S3-compatible endpoint **hostname** (NOT a URL); see the matching
|