@reventlessdev/reventless-seed-aws 1.0.0-alpha.4 → 1.0.0-alpha.6
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/CHANGELOG.md +15 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.sourcedirs.json +1 -0
- package/lib/bs/compiler-info.json +2 -2
- package/lib/bs/src/ReventlessSeedAws.ast +0 -0
- package/lib/bs/src/ReventlessSeedAws.cmi +0 -0
- package/lib/bs/src/ReventlessSeedAws.cmj +0 -0
- package/lib/bs/src/ReventlessSeedAws.cmt +0 -0
- package/lib/bs/src/ReventlessSeedAws.res +131 -75
- package/lib/bs/src/ReventlessSeedAws.res.mjs +63 -30
- package/lib/bs/src/ReventlessSeedAws_Reset.ast +0 -0
- package/lib/bs/src/ReventlessSeedAws_Reset.cmi +0 -0
- package/lib/bs/src/ReventlessSeedAws_Reset.cmt +0 -0
- package/lib/bs/src/ReventlessSeedAws_Reset.res +8 -15
- package/lib/bs/tests/EndpointResolutionTest.ast +0 -0
- package/lib/bs/tests/EndpointResolutionTest.cmi +0 -0
- package/lib/bs/tests/EndpointResolutionTest.cmj +0 -0
- package/lib/bs/tests/EndpointResolutionTest.cmt +0 -0
- package/lib/bs/tests/EndpointResolutionTest.res +180 -0
- package/lib/bs/tests/EndpointResolutionTest.res.mjs +208 -0
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/EndpointResolutionTest.ast +0 -0
- package/lib/ocaml/EndpointResolutionTest.cmi +0 -0
- package/lib/ocaml/EndpointResolutionTest.cmj +0 -0
- package/lib/ocaml/EndpointResolutionTest.cmt +0 -0
- package/lib/ocaml/EndpointResolutionTest.res +180 -0
- package/lib/ocaml/ReventlessSeedAws.ast +0 -0
- package/lib/ocaml/ReventlessSeedAws.cmi +0 -0
- package/lib/ocaml/ReventlessSeedAws.cmj +0 -0
- package/lib/ocaml/ReventlessSeedAws.cmt +0 -0
- package/lib/ocaml/ReventlessSeedAws.res +131 -75
- package/lib/ocaml/ReventlessSeedAws_Reset.ast +0 -0
- package/lib/ocaml/ReventlessSeedAws_Reset.cmi +0 -0
- package/lib/ocaml/ReventlessSeedAws_Reset.cmt +0 -0
- package/lib/ocaml/ReventlessSeedAws_Reset.res +8 -15
- package/package.json +6 -4
- package/rescript.json +8 -1
- package/src/ReventlessSeedAws.res +131 -75
- package/src/ReventlessSeedAws.res.mjs +63 -30
- package/src/ReventlessSeedAws_Reset.res +8 -15
- package/tests/EndpointResolutionTest.res +180 -0
- package/tests/EndpointResolutionTest.res.mjs +208 -0
|
@@ -19,6 +19,20 @@ function asString(json) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
function asStringDict(json) {
|
|
23
|
+
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
24
|
+
return Object.fromEntries(Stdlib_Array.filterMap(Object.entries(json), param => {
|
|
25
|
+
let k = param[0];
|
|
26
|
+
return Stdlib_Option.map(asString(param[1]), s => [
|
|
27
|
+
k,
|
|
28
|
+
s
|
|
29
|
+
]);
|
|
30
|
+
}));
|
|
31
|
+
} else {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
function envForBackend(backend) {
|
|
23
37
|
if (backend === undefined) {
|
|
24
38
|
return;
|
|
@@ -152,34 +166,39 @@ function resolveField(envKey, fromSource, human) {
|
|
|
152
166
|
};
|
|
153
167
|
}
|
|
154
168
|
|
|
155
|
-
|
|
156
|
-
let
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
169
|
+
function optionalField(envKey, fromSource) {
|
|
170
|
+
let v = Seed_Prompt$ReventlessSeed.envValue(envKey);
|
|
171
|
+
if (v !== undefined) {
|
|
172
|
+
return v;
|
|
173
|
+
} else {
|
|
174
|
+
return Stdlib_Option.getOr(fromSource, "");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function endpointsFrom(stack, source) {
|
|
179
|
+
if (source.TAG === "HostShellConfig") {
|
|
180
|
+
let cfg = source._0;
|
|
160
181
|
let fromCfg = key => Stdlib_Option.flatMap(field(cfg, key), asString);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
region,
|
|
169
|
-
clientId
|
|
170
|
-
];
|
|
182
|
+
return {
|
|
183
|
+
graphql: resolveField("REVENTLESS_GRAPHQL_ENDPOINT", fromCfg("apiEndpoint"), "apiEndpoint"),
|
|
184
|
+
uploadEndpoint: optionalField("REVENTLESS_UPLOAD_ENDPOINT", fromCfg("uploadEndpoint")),
|
|
185
|
+
uploadEndpoints: Stdlib_Option.mapOr(field(cfg, "uploadEndpoints"), {}, asStringDict),
|
|
186
|
+
cognitoRegion: resolveField("AWS_REGION", fromCfg("region"), "region"),
|
|
187
|
+
cognitoClientId: resolveField("COGNITO_CLIENT_ID", fromCfg("cognitoClientId"), "cognitoClientId")
|
|
188
|
+
};
|
|
171
189
|
}
|
|
190
|
+
let outputs = source._0;
|
|
172
191
|
let out = key => Stdlib_Option.flatMap(field(outputs, key), asString);
|
|
173
192
|
let match = Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_GRAPHQL_ENDPOINT");
|
|
174
193
|
let match$1 = out("domainMergedApiEndpoint");
|
|
175
194
|
let match$2 = out("domainApiEndpoint");
|
|
176
|
-
let
|
|
195
|
+
let tmp;
|
|
177
196
|
if (match !== undefined) {
|
|
178
|
-
|
|
197
|
+
tmp = match;
|
|
179
198
|
} else if (match$1 !== undefined) {
|
|
180
|
-
|
|
199
|
+
tmp = match$1;
|
|
181
200
|
} else if (match$2 !== undefined) {
|
|
182
|
-
|
|
201
|
+
tmp = match$2;
|
|
183
202
|
} else {
|
|
184
203
|
throw {
|
|
185
204
|
RE_EXN_ID: Seed$ReventlessSeed.Failed,
|
|
@@ -187,15 +206,26 @@ async function resolveEndpoints(projectDir, backend, stack) {
|
|
|
187
206
|
Error: new Error()
|
|
188
207
|
};
|
|
189
208
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
209
|
+
return {
|
|
210
|
+
graphql: tmp,
|
|
211
|
+
uploadEndpoint: optionalField("REVENTLESS_UPLOAD_ENDPOINT", undefined),
|
|
212
|
+
uploadEndpoints: Stdlib_Option.mapOr(field(outputs, "uploadEndpoints"), {}, asStringDict),
|
|
213
|
+
cognitoRegion: resolveField("AWS_REGION", out("cognitoRegion"), "cognitoRegion"),
|
|
214
|
+
cognitoClientId: resolveField("COGNITO_CLIENT_ID", out("cognitoUserPoolClientId"), "cognitoUserPoolClientId")
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function resolveEndpoints(projectDir, backend, stack) {
|
|
219
|
+
let outputs = stackOutputs(projectDir, backend, stack);
|
|
220
|
+
let hostShellUrl = Stdlib_Option.flatMap(field(outputs, "hostShellUrl"), asString);
|
|
221
|
+
let source = hostShellUrl !== undefined ? ({
|
|
222
|
+
TAG: "HostShellConfig",
|
|
223
|
+
_0: await fetchConfig(hostShellUrl)
|
|
224
|
+
}) : ({
|
|
225
|
+
TAG: "StackOutputs",
|
|
226
|
+
_0: outputs
|
|
227
|
+
});
|
|
228
|
+
return endpointsFrom(stack, source);
|
|
199
229
|
}
|
|
200
230
|
|
|
201
231
|
function cognito(region, clientId) {
|
|
@@ -282,14 +312,15 @@ function connect($staropt$star, stack, backend, param) {
|
|
|
282
312
|
let url = Seed_Prompt$ReventlessSeed.envValue("SEED_PULUMI_BACKEND");
|
|
283
313
|
let backend$1 = url !== undefined ? url : backend;
|
|
284
314
|
let stackName = await resolveStack(projectDir, backend$1, stack);
|
|
285
|
-
let
|
|
286
|
-
return await Seed_Connect$ReventlessSeed.make(stackName,
|
|
315
|
+
let eps = await resolveEndpoints(projectDir, backend$1, stackName);
|
|
316
|
+
return await Seed_Connect$ReventlessSeed.make(stackName, eps.graphql, eps.uploadEndpoint, eps.uploadEndpoints, cognito(eps.cognitoRegion, eps.cognitoClientId), undefined);
|
|
287
317
|
};
|
|
288
318
|
}
|
|
289
319
|
|
|
290
320
|
export {
|
|
291
321
|
field,
|
|
292
322
|
asString,
|
|
323
|
+
asStringDict,
|
|
293
324
|
envForBackend,
|
|
294
325
|
pulumi,
|
|
295
326
|
deployedStacks,
|
|
@@ -298,6 +329,8 @@ export {
|
|
|
298
329
|
resolveStack,
|
|
299
330
|
fetchConfig,
|
|
300
331
|
resolveField,
|
|
332
|
+
optionalField,
|
|
333
|
+
endpointsFrom,
|
|
301
334
|
resolveEndpoints,
|
|
302
335
|
cognito,
|
|
303
336
|
connect,
|
|
@@ -48,14 +48,7 @@ module Ddb = AwsSdk.DynamoDb
|
|
|
48
48
|
module Rgt = AwsSdk.ResourceGroupsTaggingApi
|
|
49
49
|
module S3 = AwsSdk.S3
|
|
50
50
|
|
|
51
|
-
@scope("process") @val external exit: int => unit = "exit"
|
|
52
|
-
@scope("process") @val external processEnv: dict<string> = "env"
|
|
53
|
-
@module("node:fs") external readFileSync: (string, string) => string = "readFileSync"
|
|
54
51
|
|
|
55
|
-
type stream
|
|
56
|
-
@scope("process") @val external stdin: stream = "stdin"
|
|
57
|
-
// `process.stdin.isTTY` is `true` interactively and `undefined` under a pipe/CI.
|
|
58
|
-
@get external isTTY: stream => option<bool> = "isTTY"
|
|
59
52
|
|
|
60
53
|
// The Pulumi project name, which the framework stamps as `reventless:platform` on
|
|
61
54
|
// every resource (`Plugin.res`: `platformName = getProjectName()`). Discovery
|
|
@@ -66,7 +59,7 @@ type stream
|
|
|
66
59
|
// the target project's Pulumi.yaml — the same dir the pulumi subprocess uses.
|
|
67
60
|
let projectName = (~projectDir: string): string => {
|
|
68
61
|
let path = `${projectDir}/Pulumi.yaml`
|
|
69
|
-
let raw = try readFileSync(path
|
|
62
|
+
let raw = try NodeFs.readFileSync(path) catch {
|
|
70
63
|
| _ => throw(Seed.Failed(`could not read ${path} to scope the wipe to this Pulumi project.`))
|
|
71
64
|
}
|
|
72
65
|
switch raw
|
|
@@ -561,7 +554,7 @@ let run = (~stack=?, ~backend=?, ~targets: array<target>, ()): unit => {
|
|
|
561
554
|
),
|
|
562
555
|
)
|
|
563
556
|
}
|
|
564
|
-
|
|
557
|
+
NodeProcess.env->Dict.set("AWS_REGION", region)
|
|
565
558
|
|
|
566
559
|
// Discover + count each target, scoped to its own project via the platform
|
|
567
560
|
// tag so a same-named stack from another project is never touched.
|
|
@@ -597,7 +590,7 @@ let run = (~stack=?, ~backend=?, ~targets: array<target>, ()): unit => {
|
|
|
597
590
|
Seed.Prompt.close()
|
|
598
591
|
Console.log("")
|
|
599
592
|
Console.log(`Nothing to reset — the selected scope already reads empty in ${region}.`)
|
|
600
|
-
exit(0)
|
|
593
|
+
NodeProcess.exit(0)
|
|
601
594
|
}
|
|
602
595
|
|
|
603
596
|
// Confirmation. Interactively, re-typing the exact stack name IS the
|
|
@@ -606,7 +599,7 @@ let run = (~stack=?, ~backend=?, ~targets: array<target>, ()): unit => {
|
|
|
606
599
|
// TTY (CI/scripts) there is nothing to type into, so
|
|
607
600
|
// REVENTLESS_WIPE_CONFIRM=<stack> is the equivalent opt-in. Dry-run is the
|
|
608
601
|
// default either way.
|
|
609
|
-
let interactive = stdin->isTTY->Option.getOr(false)
|
|
602
|
+
let interactive = NodeProcess.stdin->NodeProcess.isTTY->Option.getOr(false)
|
|
610
603
|
let confirmed = if interactive {
|
|
611
604
|
let typed = await Seed.Prompt.ask(
|
|
612
605
|
`About to permanently empty ${total->Int.toString} item(s)/object(s) across the selected scope of "${stack}". ` ++
|
|
@@ -624,7 +617,7 @@ let run = (~stack=?, ~backend=?, ~targets: array<target>, ()): unit => {
|
|
|
624
617
|
? "Dry run — nothing was deleted."
|
|
625
618
|
: `Dry run — nothing was deleted. Set REVENTLESS_WIPE_CONFIRM=${stack} to empty this scope non-interactively.`,
|
|
626
619
|
)
|
|
627
|
-
exit(0)
|
|
620
|
+
NodeProcess.exit(0)
|
|
628
621
|
}
|
|
629
622
|
|
|
630
623
|
for i in 0 to resolvedList->Array.length - 1 {
|
|
@@ -681,19 +674,19 @@ let run = (~stack=?, ~backend=?, ~targets: array<target>, ()): unit => {
|
|
|
681
674
|
|
|
682
675
|
Console.log("")
|
|
683
676
|
Console.log(`Reset complete — the selected scope of "${stack}" reads empty and is re-seedable.`)
|
|
684
|
-
exit(0)
|
|
677
|
+
NodeProcess.exit(0)
|
|
685
678
|
} catch {
|
|
686
679
|
| Seed.Failed(message) =>
|
|
687
680
|
Seed.Prompt.close()
|
|
688
681
|
Console.error("")
|
|
689
682
|
Console.error(`Reset aborted — ${message}`)
|
|
690
|
-
exit(1)
|
|
683
|
+
NodeProcess.exit(1)
|
|
691
684
|
| exn =>
|
|
692
685
|
Seed.Prompt.close()
|
|
693
686
|
Console.error("")
|
|
694
687
|
Console.error("Reset aborted with an unexpected error:")
|
|
695
688
|
Console.error(exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"))
|
|
696
|
-
exit(1)
|
|
689
|
+
NodeProcess.exit(1)
|
|
697
690
|
}
|
|
698
691
|
}
|
|
699
692
|
go()->ignore
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Which document `resolveEndpoints` reads, and what each arm takes from it.
|
|
2
|
+
//
|
|
3
|
+
// `endpointsFrom` is the pure half of `resolveEndpoints`; the impure half is a
|
|
4
|
+
// `pulumi stack output` subprocess and a `config.json` fetch, and the decision
|
|
5
|
+
// these tests pin is in neither. The defect they lock out: **neither arm read
|
|
6
|
+
// `uploadEndpoints`**, so a platform that publishes a presign endpoint per
|
|
7
|
+
// declared store resolved "" and the seeder reported it as serving no uploads.
|
|
8
|
+
// The stack-outputs arm is the one that matters — a platform deploying no host
|
|
9
|
+
// shell publishes no `hostShellUrl` by construction, so it takes that arm, and
|
|
10
|
+
// the per-store endpoint is its only way to reach the store.
|
|
11
|
+
|
|
12
|
+
open JestGlobals
|
|
13
|
+
open ReventlessSeed
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
// Every value read here has an env override, and an ambient one in the runner's
|
|
17
|
+
// environment (AWS_REGION is routinely set) would silently stand in for the
|
|
18
|
+
// document under test. An empty string reads as unset.
|
|
19
|
+
let clearOverrides = () =>
|
|
20
|
+
[
|
|
21
|
+
"REVENTLESS_GRAPHQL_ENDPOINT",
|
|
22
|
+
"REVENTLESS_UPLOAD_ENDPOINT",
|
|
23
|
+
"AWS_REGION",
|
|
24
|
+
"COGNITO_CLIENT_ID",
|
|
25
|
+
"SEED_SKIP_UPLOADS",
|
|
26
|
+
]->Array.forEach(k => NodeProcess.env->Dict.set(k, ""))
|
|
27
|
+
|
|
28
|
+
let obj = entries => JSON.Encode.object(entries->Dict.fromArray)
|
|
29
|
+
let str = JSON.Encode.string
|
|
30
|
+
|
|
31
|
+
// A host shell's config.json and the stack outputs of a platform that serves no
|
|
32
|
+
// shell — the two documents the two arms read, minus the upload keys each test
|
|
33
|
+
// supplies.
|
|
34
|
+
let config = (~extra: array<(string, JSON.t)>) =>
|
|
35
|
+
obj(
|
|
36
|
+
Array.concat(
|
|
37
|
+
[
|
|
38
|
+
("apiEndpoint", str("https://api.example/graphql")),
|
|
39
|
+
("region", str("eu-west-1")),
|
|
40
|
+
("cognitoClientId", str("client-abc")),
|
|
41
|
+
],
|
|
42
|
+
extra,
|
|
43
|
+
),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
let outputs = (~extra: array<(string, JSON.t)>) =>
|
|
47
|
+
obj(
|
|
48
|
+
Array.concat(
|
|
49
|
+
[
|
|
50
|
+
("domainApiEndpoint", str("https://domain.example/graphql")),
|
|
51
|
+
("cognitoRegion", str("eu-west-1")),
|
|
52
|
+
("cognitoUserPoolClientId", str("client-abc")),
|
|
53
|
+
],
|
|
54
|
+
extra,
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
let storeEndpoints = obj([("Catalog.productImages", str("https://presign.example/"))])
|
|
59
|
+
|
|
60
|
+
describe("endpointsFrom — host shell arm", () => {
|
|
61
|
+
beforeEach(clearOverrides)
|
|
62
|
+
|
|
63
|
+
testSync("reads the legacy single service and the per-store map together", () => {
|
|
64
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
65
|
+
~stack="alpha",
|
|
66
|
+
HostShellConfig(
|
|
67
|
+
config(
|
|
68
|
+
~extra=[
|
|
69
|
+
("uploadEndpoint", str("https://legacy.example/")),
|
|
70
|
+
("uploadEndpoints", storeEndpoints),
|
|
71
|
+
],
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
expect(eps.uploadEndpoint)->toBe("https://legacy.example/")
|
|
76
|
+
expect(eps.uploadEndpoints)->toEqual(
|
|
77
|
+
Dict.fromArray([("Catalog.productImages", "https://presign.example/")]),
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
// A shell fronting only declared stores writes no singular key. That used to
|
|
82
|
+
// fail the whole run before a command was sent ("deployment is missing
|
|
83
|
+
// uploadEndpoint"), which is a harder failure than the one this plan fixes.
|
|
84
|
+
testSync("a shell publishing only per-store endpoints resolves an empty legacy service", () => {
|
|
85
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
86
|
+
~stack="alpha",
|
|
87
|
+
HostShellConfig(config(~extra=[("uploadEndpoints", storeEndpoints)])),
|
|
88
|
+
)
|
|
89
|
+
expect(eps.uploadEndpoint)->toBe("")
|
|
90
|
+
expect(eps.uploadEndpoints->Dict.keysToArray)->toEqual(["Catalog.productImages"])
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
testSync("REVENTLESS_UPLOAD_ENDPOINT overrides the legacy service and leaves the map alone", () => {
|
|
94
|
+
NodeProcess.env->Dict.set("REVENTLESS_UPLOAD_ENDPOINT", "https://override.example/")
|
|
95
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
96
|
+
~stack="alpha",
|
|
97
|
+
HostShellConfig(
|
|
98
|
+
config(
|
|
99
|
+
~extra=[
|
|
100
|
+
("uploadEndpoint", str("https://legacy.example/")),
|
|
101
|
+
("uploadEndpoints", storeEndpoints),
|
|
102
|
+
],
|
|
103
|
+
),
|
|
104
|
+
),
|
|
105
|
+
)
|
|
106
|
+
expect(eps.uploadEndpoint)->toBe("https://override.example/")
|
|
107
|
+
expect(eps.uploadEndpoints->Dict.get("Catalog.productImages"))->toEqual(
|
|
108
|
+
Some("https://presign.example/"),
|
|
109
|
+
)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
describe("endpointsFrom — stack outputs arm", () => {
|
|
114
|
+
beforeEach(clearOverrides)
|
|
115
|
+
|
|
116
|
+
// The lookup that was missing entirely: this arm had no upload source but the
|
|
117
|
+
// env var, so a `PlatformOwned` deployment resolved "" whatever it published.
|
|
118
|
+
testSync("reads the uploadEndpoints stack output", () => {
|
|
119
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
120
|
+
~stack="pr-verify",
|
|
121
|
+
StackOutputs(outputs(~extra=[("uploadEndpoints", storeEndpoints)])),
|
|
122
|
+
)
|
|
123
|
+
expect(eps.uploadEndpoints)->toEqual(
|
|
124
|
+
Dict.fromArray([("Catalog.productImages", "https://presign.example/")]),
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// Declaring no store is a legitimate deployment, not a broken one — it stays a
|
|
129
|
+
// no-op at the data set rather than failing the run.
|
|
130
|
+
testSync("a deployment declaring no store resolves an empty map without failing", () => {
|
|
131
|
+
let eps = ReventlessSeedAws.endpointsFrom(~stack="pr-verify", StackOutputs(outputs(~extra=[])))
|
|
132
|
+
expect(eps.uploadEndpoint)->toBe("")
|
|
133
|
+
expect(eps.uploadEndpoints->Dict.keysToArray)->toEqual([])
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
testSync("prefers the merged API endpoint over the per-plugin one", () => {
|
|
137
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
138
|
+
~stack="pr-verify",
|
|
139
|
+
StackOutputs(outputs(~extra=[("domainMergedApiEndpoint", str("https://merged.example/"))])),
|
|
140
|
+
)
|
|
141
|
+
expect(eps.graphql)->toBe("https://merged.example/")
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
testSync("fails naming both keys when the stack exports neither API endpoint", () =>
|
|
145
|
+
switch ReventlessSeedAws.endpointsFrom(
|
|
146
|
+
~stack="pr-verify",
|
|
147
|
+
StackOutputs(obj([("cognitoRegion", str("eu-west-1"))])),
|
|
148
|
+
) {
|
|
149
|
+
| _ => fail("expected endpointsFrom to fail")
|
|
150
|
+
| exception Seed.Failed(msg) =>
|
|
151
|
+
expect(msg)->toContain("domainMergedApiEndpoint")
|
|
152
|
+
expect(msg)->toContain("domainApiEndpoint")
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
describe("endpointsFrom — malformed uploadEndpoints", () => {
|
|
158
|
+
beforeEach(clearOverrides)
|
|
159
|
+
|
|
160
|
+
// One bad member should not cost the run every endpoint it could have used.
|
|
161
|
+
testSync("drops a non-string member rather than the whole map", () => {
|
|
162
|
+
let eps = ReventlessSeedAws.endpointsFrom(
|
|
163
|
+
~stack="pr-verify",
|
|
164
|
+
StackOutputs(
|
|
165
|
+
outputs(
|
|
166
|
+
~extra=[
|
|
167
|
+
(
|
|
168
|
+
"uploadEndpoints",
|
|
169
|
+
obj([
|
|
170
|
+
("Catalog.productImages", str("https://presign.example/")),
|
|
171
|
+
("Catalog.broken", JSON.Encode.int(7)),
|
|
172
|
+
]),
|
|
173
|
+
),
|
|
174
|
+
],
|
|
175
|
+
),
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
expect(eps.uploadEndpoints->Dict.keysToArray)->toEqual(["Catalog.productImages"])
|
|
179
|
+
})
|
|
180
|
+
})
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as JestGlobals from "@reventlessdev/rescript-jest/src/JestGlobals.res.mjs";
|
|
4
|
+
import * as ReventlessSeedAws from "../src/ReventlessSeedAws.res.mjs";
|
|
5
|
+
import * as Seed$ReventlessSeed from "@reventlessdev/reventless-seed/src/Seed.res.mjs";
|
|
6
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
7
|
+
|
|
8
|
+
function clearOverrides() {
|
|
9
|
+
[
|
|
10
|
+
"REVENTLESS_GRAPHQL_ENDPOINT",
|
|
11
|
+
"REVENTLESS_UPLOAD_ENDPOINT",
|
|
12
|
+
"AWS_REGION",
|
|
13
|
+
"COGNITO_CLIENT_ID",
|
|
14
|
+
"SEED_SKIP_UPLOADS"
|
|
15
|
+
].forEach(k => {
|
|
16
|
+
process.env[k] = "";
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function obj(entries) {
|
|
21
|
+
return Object.fromEntries(entries);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function str(prim) {
|
|
25
|
+
return prim;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function config(extra) {
|
|
29
|
+
return Object.fromEntries([
|
|
30
|
+
[
|
|
31
|
+
"apiEndpoint",
|
|
32
|
+
"https://api.example/graphql"
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"region",
|
|
36
|
+
"eu-west-1"
|
|
37
|
+
],
|
|
38
|
+
[
|
|
39
|
+
"cognitoClientId",
|
|
40
|
+
"client-abc"
|
|
41
|
+
]
|
|
42
|
+
].concat(extra));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function outputs(extra) {
|
|
46
|
+
return Object.fromEntries([
|
|
47
|
+
[
|
|
48
|
+
"domainApiEndpoint",
|
|
49
|
+
"https://domain.example/graphql"
|
|
50
|
+
],
|
|
51
|
+
[
|
|
52
|
+
"cognitoRegion",
|
|
53
|
+
"eu-west-1"
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"cognitoUserPoolClientId",
|
|
57
|
+
"client-abc"
|
|
58
|
+
]
|
|
59
|
+
].concat(extra));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let storeEndpoints = Object.fromEntries([[
|
|
63
|
+
"Catalog.productImages",
|
|
64
|
+
"https://presign.example/"
|
|
65
|
+
]]);
|
|
66
|
+
|
|
67
|
+
globalThis.describe("endpointsFrom — host shell arm", () => {
|
|
68
|
+
globalThis.beforeEach(clearOverrides);
|
|
69
|
+
globalThis.test("reads the legacy single service and the per-store map together", () => {
|
|
70
|
+
let eps = ReventlessSeedAws.endpointsFrom("alpha", {
|
|
71
|
+
TAG: "HostShellConfig",
|
|
72
|
+
_0: config([
|
|
73
|
+
[
|
|
74
|
+
"uploadEndpoint",
|
|
75
|
+
"https://legacy.example/"
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"uploadEndpoints",
|
|
79
|
+
storeEndpoints
|
|
80
|
+
]
|
|
81
|
+
])
|
|
82
|
+
});
|
|
83
|
+
globalThis.expect(eps.uploadEndpoint).toBe("https://legacy.example/");
|
|
84
|
+
globalThis.expect(eps.uploadEndpoints).toEqual(Object.fromEntries([[
|
|
85
|
+
"Catalog.productImages",
|
|
86
|
+
"https://presign.example/"
|
|
87
|
+
]]));
|
|
88
|
+
});
|
|
89
|
+
globalThis.test("a shell publishing only per-store endpoints resolves an empty legacy service", () => {
|
|
90
|
+
let eps = ReventlessSeedAws.endpointsFrom("alpha", {
|
|
91
|
+
TAG: "HostShellConfig",
|
|
92
|
+
_0: config([[
|
|
93
|
+
"uploadEndpoints",
|
|
94
|
+
storeEndpoints
|
|
95
|
+
]])
|
|
96
|
+
});
|
|
97
|
+
globalThis.expect(eps.uploadEndpoint).toBe("");
|
|
98
|
+
globalThis.expect(Object.keys(eps.uploadEndpoints)).toEqual(["Catalog.productImages"]);
|
|
99
|
+
});
|
|
100
|
+
globalThis.test("REVENTLESS_UPLOAD_ENDPOINT overrides the legacy service and leaves the map alone", () => {
|
|
101
|
+
process.env["REVENTLESS_UPLOAD_ENDPOINT"] = "https://override.example/";
|
|
102
|
+
let eps = ReventlessSeedAws.endpointsFrom("alpha", {
|
|
103
|
+
TAG: "HostShellConfig",
|
|
104
|
+
_0: config([
|
|
105
|
+
[
|
|
106
|
+
"uploadEndpoint",
|
|
107
|
+
"https://legacy.example/"
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"uploadEndpoints",
|
|
111
|
+
storeEndpoints
|
|
112
|
+
]
|
|
113
|
+
])
|
|
114
|
+
});
|
|
115
|
+
globalThis.expect(eps.uploadEndpoint).toBe("https://override.example/");
|
|
116
|
+
globalThis.expect(eps.uploadEndpoints["Catalog.productImages"]).toEqual("https://presign.example/");
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
globalThis.describe("endpointsFrom — stack outputs arm", () => {
|
|
121
|
+
globalThis.beforeEach(clearOverrides);
|
|
122
|
+
globalThis.test("reads the uploadEndpoints stack output", () => {
|
|
123
|
+
let eps = ReventlessSeedAws.endpointsFrom("pr-verify", {
|
|
124
|
+
TAG: "StackOutputs",
|
|
125
|
+
_0: outputs([[
|
|
126
|
+
"uploadEndpoints",
|
|
127
|
+
storeEndpoints
|
|
128
|
+
]])
|
|
129
|
+
});
|
|
130
|
+
globalThis.expect(eps.uploadEndpoints).toEqual(Object.fromEntries([[
|
|
131
|
+
"Catalog.productImages",
|
|
132
|
+
"https://presign.example/"
|
|
133
|
+
]]));
|
|
134
|
+
});
|
|
135
|
+
globalThis.test("a deployment declaring no store resolves an empty map without failing", () => {
|
|
136
|
+
let eps = ReventlessSeedAws.endpointsFrom("pr-verify", {
|
|
137
|
+
TAG: "StackOutputs",
|
|
138
|
+
_0: outputs([])
|
|
139
|
+
});
|
|
140
|
+
globalThis.expect(eps.uploadEndpoint).toBe("");
|
|
141
|
+
globalThis.expect(Object.keys(eps.uploadEndpoints)).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
globalThis.test("prefers the merged API endpoint over the per-plugin one", () => {
|
|
144
|
+
let eps = ReventlessSeedAws.endpointsFrom("pr-verify", {
|
|
145
|
+
TAG: "StackOutputs",
|
|
146
|
+
_0: outputs([[
|
|
147
|
+
"domainMergedApiEndpoint",
|
|
148
|
+
"https://merged.example/"
|
|
149
|
+
]])
|
|
150
|
+
});
|
|
151
|
+
globalThis.expect(eps.graphql).toBe("https://merged.example/");
|
|
152
|
+
});
|
|
153
|
+
globalThis.test("fails naming both keys when the stack exports neither API endpoint", () => {
|
|
154
|
+
let val;
|
|
155
|
+
try {
|
|
156
|
+
val = ReventlessSeedAws.endpointsFrom("pr-verify", {
|
|
157
|
+
TAG: "StackOutputs",
|
|
158
|
+
_0: Object.fromEntries([[
|
|
159
|
+
"cognitoRegion",
|
|
160
|
+
"eu-west-1"
|
|
161
|
+
]])
|
|
162
|
+
});
|
|
163
|
+
} catch (raw_msg) {
|
|
164
|
+
let msg = Primitive_exceptions.internalToException(raw_msg);
|
|
165
|
+
if (msg.RE_EXN_ID === Seed$ReventlessSeed.Failed) {
|
|
166
|
+
let msg$1 = msg._1;
|
|
167
|
+
globalThis.expect(msg$1).toContain("domainMergedApiEndpoint");
|
|
168
|
+
globalThis.expect(msg$1).toContain("domainApiEndpoint");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
throw msg;
|
|
172
|
+
}
|
|
173
|
+
JestGlobals.fail("expected endpointsFrom to fail");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
globalThis.describe("endpointsFrom — malformed uploadEndpoints", () => {
|
|
178
|
+
globalThis.beforeEach(clearOverrides);
|
|
179
|
+
globalThis.test("drops a non-string member rather than the whole map", () => {
|
|
180
|
+
let eps = ReventlessSeedAws.endpointsFrom("pr-verify", {
|
|
181
|
+
TAG: "StackOutputs",
|
|
182
|
+
_0: outputs([[
|
|
183
|
+
"uploadEndpoints",
|
|
184
|
+
Object.fromEntries([
|
|
185
|
+
[
|
|
186
|
+
"Catalog.productImages",
|
|
187
|
+
"https://presign.example/"
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
"Catalog.broken",
|
|
191
|
+
7
|
|
192
|
+
]
|
|
193
|
+
])
|
|
194
|
+
]])
|
|
195
|
+
});
|
|
196
|
+
globalThis.expect(Object.keys(eps.uploadEndpoints)).toEqual(["Catalog.productImages"]);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
export {
|
|
201
|
+
clearOverrides,
|
|
202
|
+
obj,
|
|
203
|
+
str,
|
|
204
|
+
config,
|
|
205
|
+
outputs,
|
|
206
|
+
storeEndpoints,
|
|
207
|
+
}
|
|
208
|
+
/* storeEndpoints Not a pure module */
|