@prisma/composer-prisma-cloud 0.2.0-dev.1 → 0.2.0-dev.10
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/control.d.mts.map +1 -0
- package/dist/control.mjs +1 -1
- package/dist/control.mjs.map +1 -1
- package/dist/cron/index.d.mts.map +1 -0
- package/dist/cron/scheduler-entrypoint.mjs +15 -11
- package/dist/cron/scheduler-entrypoint.mjs.map +1 -1
- package/dist/email/email-entrypoint.mjs +19738 -0
- package/dist/email/email-entrypoint.mjs.map +1 -0
- package/dist/email/email-service.mjs +566 -0
- package/dist/email/email-service.mjs.map +1 -0
- package/dist/email/index.d.mts +282 -0
- package/dist/email/index.d.mts.map +1 -0
- package/dist/email/index.mjs +653 -0
- package/dist/email/index.mjs.map +1 -0
- package/dist/email/testing.d.mts +22 -0
- package/dist/email/testing.d.mts.map +1 -0
- package/dist/email/testing.mjs +1321 -0
- package/dist/email/testing.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/{prisma-next-DlU01kXJ-2sP5mQb6.mjs → prisma-next-BvBwGCIt-CSauMX4l.mjs} +19 -3
- package/dist/prisma-next-BvBwGCIt-CSauMX4l.mjs.map +1 -0
- package/dist/prisma-next.d.mts +14 -5
- package/dist/prisma-next.d.mts.map +1 -0
- package/dist/prisma-next.mjs +1 -1
- package/dist/serializer-Cx5slrV4-xJfH6EWS.d.mts.map +1 -0
- package/dist/storage/index.d.mts.map +1 -0
- package/dist/storage/storage-entrypoint.mjs +15 -11
- package/dist/storage/storage-entrypoint.mjs.map +1 -1
- package/dist/storage/testing.d.mts.map +1 -0
- package/dist/streams/index.d.mts.map +1 -0
- package/dist/streams/streams-entrypoint.mjs +15 -11
- package/dist/streams/streams-entrypoint.mjs.map +1 -1
- package/dist/streams/testing.d.mts.map +1 -0
- package/dist/testing.d.mts.map +1 -0
- package/package.json +27 -20
- package/src/exports/control.ts +1 -0
- package/src/exports/cron.ts +1 -0
- package/src/exports/email-testing.ts +1 -0
- package/src/exports/email.ts +1 -0
- package/src/exports/index.ts +1 -0
- package/src/exports/prisma-next.ts +1 -0
- package/src/exports/storage-testing.ts +1 -0
- package/src/exports/storage.ts +1 -0
- package/src/exports/streams-testing.ts +1 -0
- package/src/exports/streams.ts +1 -0
- package/src/exports/testing.ts +1 -0
- package/dist/prisma-next-DlU01kXJ-2sP5mQb6.mjs.map +0 -1
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
import { dependency, hydrateSecrets, hydrateSync, module, number, param, paramNeed, resource, secret, service, string } from "@prisma/composer";
|
|
2
|
+
import { assertDefined } from "@prisma/composer/assertions";
|
|
3
|
+
import { blindCast } from "@prisma/composer/casts";
|
|
4
|
+
import { RPC_PEER_KEY, contract, makeClient, perBindingToken, rpc } from "@prisma/composer/service-rpc";
|
|
5
|
+
import { type } from "arktype";
|
|
6
|
+
import node from "@prisma/composer/node";
|
|
7
|
+
blindCast(Symbol.for("prisma:prisma-cloud-secret-source"));
|
|
8
|
+
/**
|
|
9
|
+
* Walks a node's own params, then each dependency input's connection params —
|
|
10
|
+
* the same enumeration order `configOf` uses, but carrying the raw
|
|
11
|
+
* `ConfigParam` (with its `serialize`/`deserialize`) instead of a pure-data
|
|
12
|
+
* projection.
|
|
13
|
+
*/
|
|
14
|
+
function paramEntries(node) {
|
|
15
|
+
const entries = [];
|
|
16
|
+
for (const [input, value] of Object.entries(node.inputs)) {
|
|
17
|
+
if (typeof value !== "object" || value === null) continue;
|
|
18
|
+
const params = blindCast(value).connection.params;
|
|
19
|
+
for (const [name, param] of Object.entries(params)) entries.push({
|
|
20
|
+
owner: { input },
|
|
21
|
+
name,
|
|
22
|
+
param
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
for (const [name, param] of Object.entries(node.params)) entries.push({
|
|
26
|
+
owner: "service",
|
|
27
|
+
name,
|
|
28
|
+
param
|
|
29
|
+
});
|
|
30
|
+
return entries;
|
|
31
|
+
}
|
|
32
|
+
const configKey = (address, d) => {
|
|
33
|
+
const segments = address.split(".").filter((s) => s.length > 0);
|
|
34
|
+
const owner = d.owner === "service" ? [] : [d.owner.input];
|
|
35
|
+
return [
|
|
36
|
+
"COMPOSER",
|
|
37
|
+
...segments,
|
|
38
|
+
...owner,
|
|
39
|
+
d.name
|
|
40
|
+
].join("_").toUpperCase();
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Typed value → its stored string. Service-own literals are JSON-encoded; a
|
|
44
|
+
* dependency-input value is a provisioning ref at deploy (and a resolved
|
|
45
|
+
* string at boot) and passes through untouched — LANDMINE: JSON-encoding it
|
|
46
|
+
* would break the ordering edge Alchemy resolves through it.
|
|
47
|
+
*/
|
|
48
|
+
function encode(owner, value) {
|
|
49
|
+
return owner === "service" ? JSON.stringify(value) : blindCast(value);
|
|
50
|
+
}
|
|
51
|
+
/** Reverses `encode`: JSON-parse a service-own value, take a dependency-input value raw. */
|
|
52
|
+
function decode(owner, raw) {
|
|
53
|
+
return owner === "service" ? JSON.parse(raw) : raw;
|
|
54
|
+
}
|
|
55
|
+
const PARAM_POINTER_PREFIX = "@composer-param-pointer:";
|
|
56
|
+
/** True iff `raw` is a param pointer row (as opposed to a JSON-encoded literal). */
|
|
57
|
+
const isParamPointerRow = (raw) => raw.startsWith(PARAM_POINTER_PREFIX);
|
|
58
|
+
/** Reverses `encodeParamPointer`: the platform var NAME a pointer row points to. */
|
|
59
|
+
const decodeParamPointer = (raw) => raw.slice(24);
|
|
60
|
+
function coerce(raw, d, key) {
|
|
61
|
+
if (!(raw !== void 0 && raw !== "")) {
|
|
62
|
+
if (d.param.default !== void 0) return d.param.default;
|
|
63
|
+
if (d.param.optional === true) return void 0;
|
|
64
|
+
throw new Error(`missing required config param "${d.name}" (env ${key})`);
|
|
65
|
+
}
|
|
66
|
+
if (d.owner === "service" && isParamPointerRow(raw)) return coerceEnvSourcedParam(raw, d, key);
|
|
67
|
+
try {
|
|
68
|
+
return standardValidateSync(d.param.schema, decode(d.owner, raw));
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
71
|
+
throw new Error(`invalid value for config param "${d.name}" (env ${key}): ${message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Boot resolution for an env-sourced param: double-lookup (pointer → platform
|
|
76
|
+
* var), then the param's own schema on the raw string — no JSON decode, and
|
|
77
|
+
* no redaction (it's config, not a secret). An UNSET platform var is a loud
|
|
78
|
+
* boot failure naming both the param and the platform var; an EMPTY string is
|
|
79
|
+
* not special-cased here — it reaches the schema like any other value, so it
|
|
80
|
+
* passes iff the schema accepts it (deliberately unlike a literal param's own
|
|
81
|
+
* ""-means-absent rule, and unlike a secret's non-empty requirement).
|
|
82
|
+
*/
|
|
83
|
+
function coerceEnvSourcedParam(raw, d, key) {
|
|
84
|
+
const platformVar = decodeParamPointer(raw);
|
|
85
|
+
const value = process.env[platformVar];
|
|
86
|
+
if (value === void 0) throw new Error(`env-sourced config param "${d.name}" (env ${key} → ${platformVar}) is unset: the platform variable "${platformVar}" was not injected — the deploy did not provision it.`);
|
|
87
|
+
try {
|
|
88
|
+
return standardValidateSync(d.param.schema, value);
|
|
89
|
+
} catch (cause) {
|
|
90
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
91
|
+
throw new Error(`invalid value for env-sourced config param "${d.name}" (env ${key} → ${platformVar}): ${message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Boot: read each declared param from env by its key, reverse the param's own
|
|
96
|
+
* serialization (missing/invalid fails loudly), assemble the typed Config.
|
|
97
|
+
* Secrets ride a separate channel (deserializeSecrets), not this one.
|
|
98
|
+
*/
|
|
99
|
+
const deserialize = (node, address) => {
|
|
100
|
+
const service = {};
|
|
101
|
+
const inputs = {};
|
|
102
|
+
for (const d of paramEntries(node)) {
|
|
103
|
+
const key = configKey(address, d);
|
|
104
|
+
const value = coerce(process.env[key], d, key);
|
|
105
|
+
if (d.owner === "service") service[d.name] = value;
|
|
106
|
+
else {
|
|
107
|
+
let bucket = inputs[d.owner.input];
|
|
108
|
+
if (bucket === void 0) {
|
|
109
|
+
bucket = {};
|
|
110
|
+
inputs[d.owner.input] = bucket;
|
|
111
|
+
}
|
|
112
|
+
bucket[d.name] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
service,
|
|
117
|
+
inputs
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* run()'s setup step: write the resolved config to the environment under
|
|
122
|
+
* address-free keys (configKey("", d) + each serialize suffix), which load()
|
|
123
|
+
* reads back with no address. Uses env, not a module variable, because a
|
|
124
|
+
* framework may fork worker processes that inherit env but not memory.
|
|
125
|
+
* Writes only these keys; nothing else is touched.
|
|
126
|
+
*/
|
|
127
|
+
const stash = (node, config) => {
|
|
128
|
+
for (const d of paramEntries(node)) {
|
|
129
|
+
const value = d.owner === "service" ? config.service[d.name] : config.inputs[d.owner.input]?.[d.name];
|
|
130
|
+
if (value === void 0) continue;
|
|
131
|
+
process.env[configKey("", d)] = encode(d.owner, value);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
/** The pointer-row key for a secret slot: COMPOSER_<addr>_<slot> (secrets are service-level). */
|
|
135
|
+
const secretKey = (address, slot) => configKey(address, {
|
|
136
|
+
owner: "service",
|
|
137
|
+
name: slot
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* Boot: resolve every secret slot to its value by double-lookup — read the
|
|
141
|
+
* pointer key (the platform NAME), then read that platform var. A missing
|
|
142
|
+
* pointer or a missing/empty platform value is a loud failure naming both keys.
|
|
143
|
+
* Returns a plain Record for core's `hydrateSecrets` to box.
|
|
144
|
+
*/
|
|
145
|
+
const deserializeSecrets = (node, address) => {
|
|
146
|
+
const values = {};
|
|
147
|
+
for (const slot of Object.keys(node.secretSlots)) {
|
|
148
|
+
const key = secretKey(address, slot);
|
|
149
|
+
const name = process.env[key];
|
|
150
|
+
if (name === void 0 || name === "") throw new Error(`missing secret pointer for slot "${slot}" (env ${key}) — the deploy did not write it.`);
|
|
151
|
+
const value = process.env[name];
|
|
152
|
+
if (value === void 0 || value === "") throw new Error(`secret "${slot}" is not provisioned (env ${key} → ${name}): the platform var "${name}" is unset or empty.`);
|
|
153
|
+
values[slot] = value;
|
|
154
|
+
}
|
|
155
|
+
return values;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* run()'s setup step for secrets: re-emit each slot's pointer NAME under its
|
|
159
|
+
* address-free key, so the address-free `deserializeSecrets` double-looks-up
|
|
160
|
+
* identically. Never the value — the value stays only in the platform var.
|
|
161
|
+
*/
|
|
162
|
+
const stashSecrets = (node, address) => {
|
|
163
|
+
for (const slot of Object.keys(node.secretSlots)) {
|
|
164
|
+
const name = process.env[secretKey(address, slot)];
|
|
165
|
+
if (name === void 0) continue;
|
|
166
|
+
process.env[secretKey("", slot)] = name;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Boot: for each reserved provider param, read its address-scoped row through
|
|
171
|
+
* the same `coerce` a declared param uses (JSON-decode, schema-validate), and
|
|
172
|
+
* re-emit it address-free — `stash`'s counterpart for this separate
|
|
173
|
+
* declaration space. A param is declared optional here unconditionally: an
|
|
174
|
+
* absent row means "never provisioned" (local dev, tests, a provider with no
|
|
175
|
+
* registered value for this deploy), never a boot failure, so nothing is
|
|
176
|
+
* stashed and the runtime reader that owns this slot falls back to its own
|
|
177
|
+
* pass-through behavior.
|
|
178
|
+
*/
|
|
179
|
+
function stashProviderParams(entries, address) {
|
|
180
|
+
for (const entry of entries) {
|
|
181
|
+
const d = {
|
|
182
|
+
owner: "service",
|
|
183
|
+
name: entry.name,
|
|
184
|
+
param: {
|
|
185
|
+
schema: entry.schema,
|
|
186
|
+
optional: true
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const key = configKey(address, d);
|
|
190
|
+
const value = coerce(process.env[key], d, key);
|
|
191
|
+
if (value === void 0) continue;
|
|
192
|
+
process.env[configKey("", d)] = encode("service", value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** The framework-resolved origin row: COMPOSER_<addr>_ORIGIN. Written per
|
|
196
|
+
* compute service at serialize — the service's own provisioned endpoint URL,
|
|
197
|
+
* riding the reserved-provider-param machinery (`origin-key.ts`'s
|
|
198
|
+
* `ORIGIN_PARAM`); never a declared param, never in config(). A harness with
|
|
199
|
+
* no deploy behind it supplies it by setting `COMPOSER_ORIGIN` to the
|
|
200
|
+
* JSON-encoded origin URL — exactly how the existing entrypoint tests supply
|
|
201
|
+
* their other `COMPOSER_*` rows. */
|
|
202
|
+
const ORIGIN_KEY_NAME = "ORIGIN";
|
|
203
|
+
/**
|
|
204
|
+
* Reads this service's origin back out of the address-free stash
|
|
205
|
+
* `stashProviderParams` wrote for the ORIGIN entry. `COMPOSER_ORIGIN` unset is
|
|
206
|
+
* a loud failure — a deployed environment always writes it, so an unset row
|
|
207
|
+
* means either a local harness that hasn't supplied it or a boot() called
|
|
208
|
+
* before run().
|
|
209
|
+
*/
|
|
210
|
+
function readOrigin() {
|
|
211
|
+
const d = {
|
|
212
|
+
owner: "service",
|
|
213
|
+
name: ORIGIN_KEY_NAME,
|
|
214
|
+
param: {
|
|
215
|
+
schema: type("string"),
|
|
216
|
+
optional: true
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
const key = configKey("", d);
|
|
220
|
+
const value = coerce(process.env[key], d, key);
|
|
221
|
+
if (value === void 0) throw new Error("this service's origin is not available (env COMPOSER_ORIGIN is unset) — a deployed environment writes it automatically; a local harness must supply it like any other config value (set COMPOSER_ORIGIN to the JSON-encoded origin URL).");
|
|
222
|
+
return blindCast(value);
|
|
223
|
+
}
|
|
224
|
+
/** Synchronous Standard Schema validation — see the matching note in core's `config.ts`. */
|
|
225
|
+
function standardValidateSync(schema, value) {
|
|
226
|
+
const result = schema["~standard"].validate(value);
|
|
227
|
+
if (result instanceof Promise) throw new Error("config param schema validation must be synchronous — async Standard Schema validators are not supported for config params");
|
|
228
|
+
if (result.issues !== void 0) throw new Error(`config param validation failed: ${result.issues.map((issue) => issue.message).join("; ")}`);
|
|
229
|
+
return result.value;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#region ../../1-prisma-cloud/1-extensions/target/dist/provisioned-edges-B_XS1Mz-.mjs
|
|
233
|
+
/**
|
|
234
|
+
* The service's own origin as a reserved provider param (ADR-0031): the ONE
|
|
235
|
+
* brand and the ONE entry — shared by control.ts (which registers the
|
|
236
|
+
* deploy-side value function that resolves the provisioned service's
|
|
237
|
+
* `endpointDomain` — see its `selfOriginValue`) and compute.ts (which
|
|
238
|
+
* validates and stashes the row at boot through the generic
|
|
239
|
+
* `stashProviderParams` loop), so writer and reader cannot drift.
|
|
240
|
+
*
|
|
241
|
+
* Unlike the key-minting brands (`service-keys.ts`, `streams-keys.ts`) this
|
|
242
|
+
* brand has no provisioner and no consumer edges: the value derives from the
|
|
243
|
+
* service's OWN provisioned attributes, so control.ts registers it as a
|
|
244
|
+
* service-derived provider param (`descriptors/shared.ts`'s
|
|
245
|
+
* `ServiceProviderParam`) and the descriptor writes it for EVERY compute
|
|
246
|
+
* service, exposing or not.
|
|
247
|
+
*
|
|
248
|
+
* This module is reachable from the RUNTIME/authoring side — it must never
|
|
249
|
+
* import `@internal/lowering` or `effect`, or those tokens leak into a user
|
|
250
|
+
* service's bundle (the deploy-side value function lives in control.ts, the
|
|
251
|
+
* control-plane-only entry).
|
|
252
|
+
*/
|
|
253
|
+
/** ADR-0031's brand for the service's own origin — control.ts registers the deploy-side value function under this. */
|
|
254
|
+
const SELF_ORIGIN = Symbol.for("prisma:self-origin");
|
|
255
|
+
/**
|
|
256
|
+
* The reserved provider param for the origin row: the var name is `ORIGIN`,
|
|
257
|
+
* derived through `configKey` at both ends (`configKey(address, …)` at
|
|
258
|
+
* deploy, `configKey('', …)` — `COMPOSER_ORIGIN` — at boot, where
|
|
259
|
+
* `readOrigin` reads it back). `brand` is `SELF_ORIGIN` — control.ts looks
|
|
260
|
+
* its deploy-side value function up by this field.
|
|
261
|
+
*/
|
|
262
|
+
const ORIGIN_PARAM = {
|
|
263
|
+
name: ORIGIN_KEY_NAME,
|
|
264
|
+
schema: type("string"),
|
|
265
|
+
brand: SELF_ORIGIN
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* RPC's reserved provider param (ADR-0030/ADR-0031): the declaration —
|
|
269
|
+
* name + schema + brand — for the accepted-keys set a provider stores, shared
|
|
270
|
+
* by `control.ts` (which registers the deploy-side `value(refs)` that mints
|
|
271
|
+
* and aggregates it — see its `rpcAcceptedKeysValue`) and `compute.ts` (which
|
|
272
|
+
* validates and stashes it at boot), so writer and reader cannot drift.
|
|
273
|
+
* Finding the edges themselves is `provisioned-edges.ts`'s generic,
|
|
274
|
+
* brand-blind scan — RPC is not special-cased anywhere in this target.
|
|
275
|
+
*
|
|
276
|
+
* This module is reachable from the RUNTIME/authoring side — it must never
|
|
277
|
+
* import `@internal/lowering` or `effect`, or those tokens leak into a user
|
|
278
|
+
* service's bundle (the deploy-side `value(refs)` lives in control.ts, the
|
|
279
|
+
* control-plane-only entry).
|
|
280
|
+
*/
|
|
281
|
+
/**
|
|
282
|
+
* The reserved provider param for RPC's accepted-keys set: the var name is
|
|
283
|
+
* `RPC_ACCEPTED_KEYS`, derived through `configKey` at both ends
|
|
284
|
+
* (`configKey(address, …)` at deploy, `configKey('', …)` at boot — the
|
|
285
|
+
* address-free form is `@internal/service-rpc`'s `RPC_ACCEPTED_KEYS_ENV`). `brand` is
|
|
286
|
+
* `RPC_PEER_KEY`, the same brand `perBindingToken()`'s need carries — control.ts
|
|
287
|
+
* looks its `value(refs)` up by this field.
|
|
288
|
+
*/
|
|
289
|
+
const RPC_ACCEPTED_KEYS_PARAM = {
|
|
290
|
+
name: "RPC_ACCEPTED_KEYS",
|
|
291
|
+
schema: type("string[]"),
|
|
292
|
+
brand: RPC_PEER_KEY
|
|
293
|
+
};
|
|
294
|
+
/** ADR-0031's need brand for the streams module's bearer key — control.ts registers the provisioner under this. */
|
|
295
|
+
const STREAMS_API_KEY = Symbol.for("prisma:streams/api-key");
|
|
296
|
+
/**
|
|
297
|
+
* The reserved provider param for the streams bearer key: the var name is
|
|
298
|
+
* `STREAMS_API_KEY`. `brand` is `STREAMS_API_KEY` itself (the same symbol
|
|
299
|
+
* `streamsApiKeyNeed()`'s need carries) — control.ts looks its `value(refs)`
|
|
300
|
+
* up by this field.
|
|
301
|
+
*/
|
|
302
|
+
const STREAMS_API_KEY_PARAM = {
|
|
303
|
+
name: "STREAMS_API_KEY",
|
|
304
|
+
schema: type("string"),
|
|
305
|
+
brand: STREAMS_API_KEY
|
|
306
|
+
};
|
|
307
|
+
configKey("", {
|
|
308
|
+
owner: "service",
|
|
309
|
+
name: STREAMS_API_KEY_PARAM.name
|
|
310
|
+
});
|
|
311
|
+
/**
|
|
312
|
+
* The list of provider-side reserved params the boot path validates and
|
|
313
|
+
* stashes (ADR-0031): every brand's `{name, schema, brand}` declaration,
|
|
314
|
+
* collected from that brand's own module (`service-keys.ts`,
|
|
315
|
+
* `streams-keys.ts`, `origin-key.ts`) so `compute.ts` names no brand itself.
|
|
316
|
+
*
|
|
317
|
+
* This list exists separately from `control.ts`'s deploy-side registry
|
|
318
|
+
* (`PROVIDER_PARAMS`) because `control.ts` is deploy-only code — it imports
|
|
319
|
+
* `@internal/lowering` and `effect` to mint values — and a booted service
|
|
320
|
+
* must never import it. This module is reachable from a user service's
|
|
321
|
+
* bundle through `compute.ts`, so it must never import `@internal/lowering`,
|
|
322
|
+
* `effect`, `alchemy`, or `control.ts`.
|
|
323
|
+
*
|
|
324
|
+
* This is the single source of which reserved provider params exist:
|
|
325
|
+
* control.ts builds `PROVIDER_PARAMS` by mapping over this list and looking
|
|
326
|
+
* up each entry's deploy-side value function (edge-derived `value(refs)` or
|
|
327
|
+
* service-derived `valueForService(provisioned, address)`) by its `brand`,
|
|
328
|
+
* throwing at module load if one is missing. Adding a brand means adding its
|
|
329
|
+
* entry here, plus its deploy-side value function in control.ts — a brand
|
|
330
|
+
* registered for deploy but absent here is no longer expressible, because
|
|
331
|
+
* deploy no longer names its own param set independently.
|
|
332
|
+
*/
|
|
333
|
+
const RESERVED_PROVIDER_PARAMS = [
|
|
334
|
+
RPC_ACCEPTED_KEYS_PARAM,
|
|
335
|
+
STREAMS_API_KEY_PARAM,
|
|
336
|
+
ORIGIN_PARAM
|
|
337
|
+
];
|
|
338
|
+
blindCast(Symbol.for("prisma:prisma-cloud-param-source"));
|
|
339
|
+
Object.freeze({
|
|
340
|
+
kind: "s3",
|
|
341
|
+
__cmp: {
|
|
342
|
+
url: "",
|
|
343
|
+
bucket: "",
|
|
344
|
+
accessKeyId: "",
|
|
345
|
+
secretAccessKey: ""
|
|
346
|
+
},
|
|
347
|
+
satisfies: (required) => required.kind === "s3"
|
|
348
|
+
});
|
|
349
|
+
const reservedParams = { port: number({ default: 3e3 }) };
|
|
350
|
+
/**
|
|
351
|
+
* A Prisma Compute service — declarations only (deps + params + build + the
|
|
352
|
+
* ports it exposes), no descriptor. `params` merges with the reserved
|
|
353
|
+
* `ReservedParams` (`port`); a user param whose name collides with a reserved
|
|
354
|
+
* one fails at authoring, the same way a colliding dependency name does.
|
|
355
|
+
*
|
|
356
|
+
* · run(address, boot) — the process controller: deserialize the platform
|
|
357
|
+
* environment (keyed off `address`, the extension's ONE env read) into a
|
|
358
|
+
* typed Config, re-emit it under address-free process-local stash keys,
|
|
359
|
+
* then call boot() to start the app's entry.
|
|
360
|
+
* · load() / config() — called from inside the app's entry: read the stash;
|
|
361
|
+
* load() hydrates + memoizes the deps, config() returns the typed params.
|
|
362
|
+
* Separate accessors so a dep and a param never share a namespace (ADR-0021).
|
|
363
|
+
* · origin() — this service's platform-assigned public origin, read from the
|
|
364
|
+
* stash `run()` populates; memoized per process.
|
|
365
|
+
*
|
|
366
|
+
* The underlying node carries `extension: '@prisma/composer-prisma-cloud'` —
|
|
367
|
+
* the control-plane registry key `prisma-composer deploy` resolves through the
|
|
368
|
+
* app's `prisma-composer.config.ts` (ADR-0017). This module loads nothing at
|
|
369
|
+
* deploy time; nodes are pure data until run() or load() is called.
|
|
370
|
+
*/
|
|
371
|
+
var ComputeService = class {
|
|
372
|
+
#resolved;
|
|
373
|
+
#loadedDeps;
|
|
374
|
+
#loadedParams;
|
|
375
|
+
#loadedSecrets;
|
|
376
|
+
#origin;
|
|
377
|
+
constructor(node) {
|
|
378
|
+
Object.assign(this, node);
|
|
379
|
+
}
|
|
380
|
+
#processConfig() {
|
|
381
|
+
if (this.#resolved === void 0) this.#resolved = deserialize(this, "");
|
|
382
|
+
return this.#resolved;
|
|
383
|
+
}
|
|
384
|
+
async run(address, boot) {
|
|
385
|
+
const config = deserialize(this, address);
|
|
386
|
+
stash(this, config);
|
|
387
|
+
stashProviderParams(RESERVED_PROVIDER_PARAMS, address);
|
|
388
|
+
stashSecrets(this, address);
|
|
389
|
+
const port = config.service["port"];
|
|
390
|
+
if (typeof port === "number") process.env["PORT"] = String(port);
|
|
391
|
+
return boot();
|
|
392
|
+
}
|
|
393
|
+
load() {
|
|
394
|
+
if (this.#loadedDeps === void 0) this.#loadedDeps = blindCast(hydrateSync(this, this.#processConfig()));
|
|
395
|
+
return this.#loadedDeps;
|
|
396
|
+
}
|
|
397
|
+
config() {
|
|
398
|
+
if (this.#loadedParams === void 0) this.#loadedParams = blindCast(this.#processConfig().service);
|
|
399
|
+
return this.#loadedParams;
|
|
400
|
+
}
|
|
401
|
+
secrets() {
|
|
402
|
+
if (this.#loadedSecrets === void 0) this.#loadedSecrets = blindCast(hydrateSecrets(this, deserializeSecrets(this, "")));
|
|
403
|
+
return this.#loadedSecrets;
|
|
404
|
+
}
|
|
405
|
+
/** This service's platform-assigned public origin — read from the stash
|
|
406
|
+
* run() populates and memoized per process. Throws if called before run()
|
|
407
|
+
* has stashed it (readOrigin's pinned message). */
|
|
408
|
+
origin() {
|
|
409
|
+
this.#origin ??= readOrigin();
|
|
410
|
+
return this.#origin;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
const compute = (def) => {
|
|
414
|
+
const userParams = def.params ?? blindCast({});
|
|
415
|
+
for (const reserved of Object.keys(reservedParams)) {
|
|
416
|
+
if (reserved in def.deps) throw new Error(`compute(): dependency "${reserved}" collides with the reserved service param of the same name — rename the dependency.`);
|
|
417
|
+
if (reserved in userParams) throw new Error(`compute(): param "${reserved}" collides with the reserved service param of the same name — rename the param.`);
|
|
418
|
+
}
|
|
419
|
+
for (const name of Object.keys(userParams)) if (name.toUpperCase() === "ORIGIN") throw new Error(`compute(): param "${name}" collides with the framework-written origin row — rename the param.`);
|
|
420
|
+
for (const name of Object.keys(def.secrets ?? {})) if (name.toUpperCase() === "ORIGIN") throw new Error(`compute(): secret "${name}" collides with the framework-written origin row — rename the secret.`);
|
|
421
|
+
const params = blindCast({
|
|
422
|
+
...userParams,
|
|
423
|
+
...reservedParams
|
|
424
|
+
});
|
|
425
|
+
const instance = new ComputeService(service({
|
|
426
|
+
name: def.name,
|
|
427
|
+
extension: "@prisma/composer-prisma-cloud",
|
|
428
|
+
type: "compute",
|
|
429
|
+
inputs: def.deps,
|
|
430
|
+
params,
|
|
431
|
+
...def.secrets !== void 0 ? { secrets: def.secrets } : {},
|
|
432
|
+
build: def.build,
|
|
433
|
+
...def.expose !== void 0 ? { expose: def.expose } : {}
|
|
434
|
+
}));
|
|
435
|
+
Object.freeze(instance);
|
|
436
|
+
return instance;
|
|
437
|
+
};
|
|
438
|
+
/**
|
|
439
|
+
* The contract a Postgres provides — and the contract its consumers require.
|
|
440
|
+
* `satisfies` compares KIND, not identity: an extension module can be duplicated
|
|
441
|
+
* across a workspace (same rationale as the Symbol.for node brand), and every
|
|
442
|
+
* duplicate's contract must still satisfy. `__cmp` is the connection config a
|
|
443
|
+
* postgres offers; core never inspects it.
|
|
444
|
+
*/
|
|
445
|
+
const postgresContract = Object.freeze({
|
|
446
|
+
kind: "postgres",
|
|
447
|
+
__cmp: { url: "" },
|
|
448
|
+
satisfies: (required) => required.kind === "postgres"
|
|
449
|
+
});
|
|
450
|
+
function postgres(opts) {
|
|
451
|
+
if (opts?.name !== void 0) return resource({
|
|
452
|
+
name: opts.name,
|
|
453
|
+
extension: "@prisma/composer-prisma-cloud",
|
|
454
|
+
provides: postgresContract
|
|
455
|
+
});
|
|
456
|
+
return dependency({
|
|
457
|
+
type: "postgres",
|
|
458
|
+
connection: {
|
|
459
|
+
params: { url: string() },
|
|
460
|
+
hydrate: (v) => v
|
|
461
|
+
},
|
|
462
|
+
required: postgresContract
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
Object.freeze({
|
|
466
|
+
kind: "credentials",
|
|
467
|
+
__cmp: {
|
|
468
|
+
accessKeyId: "",
|
|
469
|
+
secretAccessKey: ""
|
|
470
|
+
},
|
|
471
|
+
satisfies: (required) => required.kind === "credentials"
|
|
472
|
+
});
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region ../../1-prisma-cloud/2-shared-modules/email/dist/email-service-DD1VF_64.mjs
|
|
475
|
+
/**
|
|
476
|
+
* Identity helper that infers `T` with literal keys and each entry's own
|
|
477
|
+
* data type — the `defineSchedule` pattern
|
|
478
|
+
* (`packages/1-prisma-cloud/2-shared-modules/cron/src/schedule.ts`).
|
|
479
|
+
* Performs no validation and no transformation.
|
|
480
|
+
*/
|
|
481
|
+
function defineTemplates(defs) {
|
|
482
|
+
return defs;
|
|
483
|
+
}
|
|
484
|
+
const emailStatus = type("'stored'|'queued'|'sent'|'failed'");
|
|
485
|
+
const emailSendContract = contract({ send: rpc({
|
|
486
|
+
input: type({
|
|
487
|
+
templateId: "string",
|
|
488
|
+
to: "1<=string[]<=50",
|
|
489
|
+
"cc?": "string[]",
|
|
490
|
+
"bcc?": "string[]",
|
|
491
|
+
"replyTo?": "string",
|
|
492
|
+
subject: "string",
|
|
493
|
+
html: "string",
|
|
494
|
+
"text?": "string",
|
|
495
|
+
idempotencyKey: "1<=string<=256"
|
|
496
|
+
}),
|
|
497
|
+
output: type({
|
|
498
|
+
id: "string",
|
|
499
|
+
status: emailStatus,
|
|
500
|
+
"error?": "string"
|
|
501
|
+
})
|
|
502
|
+
}) });
|
|
503
|
+
const emailRecord = type({
|
|
504
|
+
id: "string",
|
|
505
|
+
templateId: "string",
|
|
506
|
+
to: "string[]",
|
|
507
|
+
cc: "string[]",
|
|
508
|
+
bcc: "string[]",
|
|
509
|
+
replyTo: "string | null",
|
|
510
|
+
from: "string",
|
|
511
|
+
subject: "string",
|
|
512
|
+
html: "string",
|
|
513
|
+
text: "string | null",
|
|
514
|
+
status: emailStatus,
|
|
515
|
+
providerMessageId: "string | null",
|
|
516
|
+
error: "string | null",
|
|
517
|
+
attempts: "number",
|
|
518
|
+
createdAt: "string",
|
|
519
|
+
updatedAt: "string"
|
|
520
|
+
});
|
|
521
|
+
const emailOutboxContract = contract({
|
|
522
|
+
getEmail: rpc({
|
|
523
|
+
input: type({ id: "string" }),
|
|
524
|
+
output: type({ email: emailRecord.or("null") })
|
|
525
|
+
}),
|
|
526
|
+
listEmails: rpc({
|
|
527
|
+
input: type({
|
|
528
|
+
"to?": "string",
|
|
529
|
+
"templateId?": "string",
|
|
530
|
+
"status?": emailStatus,
|
|
531
|
+
"cursor?": "string",
|
|
532
|
+
"limit?": "1<=number.integer<=200"
|
|
533
|
+
}),
|
|
534
|
+
output: type({
|
|
535
|
+
emails: emailRecord.array(),
|
|
536
|
+
"nextCursor?": "string"
|
|
537
|
+
})
|
|
538
|
+
})
|
|
539
|
+
});
|
|
540
|
+
/**
|
|
541
|
+
* A consumer's dependency on the `send` port: one method per declared
|
|
542
|
+
* template, each validating its own `data`, rendering, and calling the
|
|
543
|
+
* generic `send` op. Connection params and hydration reuse `rpc()`'s exactly
|
|
544
|
+
* — same `url`/`serviceKey` binding, built the same way `rpc(emailSendContract)`
|
|
545
|
+
* would be, then wrapped.
|
|
546
|
+
*/
|
|
547
|
+
function emailSender(templates) {
|
|
548
|
+
return dependency({
|
|
549
|
+
type: "rpc",
|
|
550
|
+
connection: {
|
|
551
|
+
params: {
|
|
552
|
+
url: string(),
|
|
553
|
+
serviceKey: string({
|
|
554
|
+
optional: true,
|
|
555
|
+
provision: perBindingToken()
|
|
556
|
+
})
|
|
557
|
+
},
|
|
558
|
+
hydrate: ({ url, serviceKey }) => {
|
|
559
|
+
const client = makeClient(emailSendContract, url, { serviceKey });
|
|
560
|
+
const sender = {};
|
|
561
|
+
for (const templateId of Object.keys(templates)) {
|
|
562
|
+
const def = templates[templateId];
|
|
563
|
+
assertDefined(def, `email.${templateId}(): unreachable — key came from Object.keys(templates).`);
|
|
564
|
+
sender[templateId] = async (input) => {
|
|
565
|
+
const validated = def.data(input.data);
|
|
566
|
+
if (validated instanceof type.errors) throw new Error(`email.${templateId}(): data does not match the template schema: ${validated.summary}`);
|
|
567
|
+
const rendered = await def.render(validated);
|
|
568
|
+
const to = Array.isArray(input.to) ? [...input.to] : [input.to];
|
|
569
|
+
if (to.length === 0) throw new Error(`email.${templateId}(): "to" must contain at least one recipient.`);
|
|
570
|
+
const idempotencyKey = input.idempotencyKey ?? crypto.randomUUID();
|
|
571
|
+
return client.send({
|
|
572
|
+
templateId,
|
|
573
|
+
to,
|
|
574
|
+
...input.cc !== void 0 ? { cc: [...input.cc] } : {},
|
|
575
|
+
...input.bcc !== void 0 ? { bcc: [...input.bcc] } : {},
|
|
576
|
+
...input.replyTo !== void 0 ? { replyTo: input.replyTo } : {},
|
|
577
|
+
...rendered,
|
|
578
|
+
idempotencyKey
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
return blindCast(sender);
|
|
583
|
+
}
|
|
584
|
+
},
|
|
585
|
+
required: emailSendContract
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* The email compute service (spec §"Service definition"): a Postgres `db`
|
|
590
|
+
* dependency, the `deliveryMode`/`deliveryUrl`/`from` params, the
|
|
591
|
+
* `deliveryCredential` secret, and the two exposed ports (`send`, `outbox`).
|
|
592
|
+
* Build/entry mechanics copied from storage's service file
|
|
593
|
+
* (`storage/src/storage-service.ts`), not re-derived: `build.module` points
|
|
594
|
+
* at this file's own built output so the deploy bootstrap can re-import it
|
|
595
|
+
* as `main` and call `main.run(address, boot)`; `entry` resolves the
|
|
596
|
+
* sibling entrypoint pass in the same dist directory.
|
|
597
|
+
*/
|
|
598
|
+
const deliveryModeSchema = type("'resend'|'smtp'|'none'");
|
|
599
|
+
function emailService(opts) {
|
|
600
|
+
return compute({
|
|
601
|
+
name: "email",
|
|
602
|
+
deps: { db: postgres() },
|
|
603
|
+
params: {
|
|
604
|
+
deliveryMode: param(deliveryModeSchema),
|
|
605
|
+
deliveryUrl: string({ default: opts?.deliveryUrl ?? "https://api.resend.com" }),
|
|
606
|
+
from: string()
|
|
607
|
+
},
|
|
608
|
+
secrets: { deliveryCredential: secret() },
|
|
609
|
+
expose: {
|
|
610
|
+
send: emailSendContract,
|
|
611
|
+
outbox: emailOutboxContract
|
|
612
|
+
},
|
|
613
|
+
build: node({
|
|
614
|
+
module: new URL("./email-service.mjs", import.meta.url).href,
|
|
615
|
+
entry: "./email-entrypoint.mjs"
|
|
616
|
+
})
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
emailService();
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region ../../1-prisma-cloud/2-shared-modules/email/dist/index.mjs
|
|
622
|
+
function email(opts) {
|
|
623
|
+
return module(opts?.name ?? "email", {
|
|
624
|
+
params: {
|
|
625
|
+
deliveryMode: paramNeed(),
|
|
626
|
+
from: paramNeed()
|
|
627
|
+
},
|
|
628
|
+
secrets: { deliveryCredential: secret() },
|
|
629
|
+
expose: {
|
|
630
|
+
send: emailSendContract,
|
|
631
|
+
outbox: emailOutboxContract
|
|
632
|
+
}
|
|
633
|
+
}, ({ params, secrets, provision }) => {
|
|
634
|
+
const db = provision(postgres({ name: "db" }), { id: "db" });
|
|
635
|
+
const service = provision(emailService(opts?.deliveryUrl !== void 0 ? { deliveryUrl: opts.deliveryUrl } : {}), {
|
|
636
|
+
id: "service",
|
|
637
|
+
deps: { db },
|
|
638
|
+
params: {
|
|
639
|
+
deliveryMode: params.deliveryMode,
|
|
640
|
+
from: params.from
|
|
641
|
+
},
|
|
642
|
+
secrets: { deliveryCredential: secrets.deliveryCredential }
|
|
643
|
+
});
|
|
644
|
+
return {
|
|
645
|
+
send: service.send,
|
|
646
|
+
outbox: service.outbox
|
|
647
|
+
};
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
//#endregion
|
|
651
|
+
export { defineTemplates, email, emailOutboxContract, emailSendContract, emailSender, emailService };
|
|
652
|
+
|
|
653
|
+
//# sourceMappingURL=index.mjs.map
|