@reventlessdev/reventless-seed 1.0.0-alpha.5 → 1.0.0-alpha.7
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 -1
- package/lib/bs/ReventlessSeed.cmi +0 -0
- package/lib/bs/ReventlessSeed.cmt +0 -0
- package/lib/bs/ReventlessSeed.mlmap +1 -1
- package/lib/bs/compiler-info.json +2 -2
- package/lib/bs/src/Seed-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed.ast +0 -0
- package/lib/bs/src/Seed.res +4 -5
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Client.ast +0 -0
- package/lib/bs/src/Seed_Client.res +4 -0
- package/lib/bs/src/Seed_Client.res.mjs +5 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Connect.ast +0 -0
- package/lib/bs/src/Seed_Connect.res +13 -49
- package/lib/bs/src/Seed_Connect.res.mjs +5 -26
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Prompt.ast +0 -0
- package/lib/bs/src/Seed_Prompt.res +10 -20
- package/lib/bs/src/Seed_Prompt.res.mjs +1 -1
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Runner.ast +0 -0
- package/lib/bs/src/Seed_Runner.res +5 -7
- package/lib/bs/src/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Upload.ast +0 -0
- package/lib/bs/src/Seed_Upload.res +39 -100
- package/lib/bs/src/Seed_Upload.res.mjs +61 -93
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_RandomTest.ast +0 -0
- package/lib/bs/tests/Seed_RandomTest.res +160 -0
- package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
- package/lib/ocaml/.compiler.log +2 -2
- package/lib/ocaml/ReventlessSeed.cmi +0 -0
- package/lib/ocaml/ReventlessSeed.cmt +0 -0
- package/lib/ocaml/ReventlessSeed.mlmap +1 -1
- package/lib/ocaml/Seed-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed.ast +0 -0
- package/lib/ocaml/Seed.res +4 -5
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Client-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Client.ast +0 -0
- package/lib/ocaml/Seed_Client.res +4 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Connect-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Connect.ast +0 -0
- package/lib/ocaml/Seed_Connect.res +13 -49
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Prompt.ast +0 -0
- package/lib/ocaml/Seed_Prompt.res +10 -20
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_RandomTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_RandomTest.ast +0 -0
- package/lib/ocaml/Seed_RandomTest.res +160 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Runner.ast +0 -0
- package/lib/ocaml/Seed_Runner.res +5 -7
- package/lib/ocaml/Seed_Types-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Upload-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Upload.ast +0 -0
- package/lib/ocaml/Seed_Upload.res +39 -100
- package/package.json +5 -2
- package/rescript.json +1 -0
- package/src/Seed.res +4 -5
- package/src/Seed_Client.res +4 -0
- package/src/Seed_Client.res.mjs +5 -0
- package/src/Seed_Connect.res +13 -49
- package/src/Seed_Connect.res.mjs +5 -26
- package/src/Seed_Prompt.res +10 -20
- package/src/Seed_Prompt.res.mjs +1 -1
- package/src/Seed_Runner.res +5 -7
- package/src/Seed_Upload.res +39 -100
- package/src/Seed_Upload.res.mjs +61 -93
- package/tests/Seed_RandomTest.res +160 -0
- package/tests/Seed_RandomTest.res.mjs +208 -0
- package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/UploadEndpointResolutionTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/UploadEndpointResolutionTest.ast +0 -0
- package/lib/bs/tests/UploadEndpointResolutionTest.res +0 -101
- package/lib/bs/tests/UploadEndpointResolutionTest.res.mjs +0 -59
- package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/UploadEndpointResolutionTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/UploadEndpointResolutionTest.ast +0 -0
- package/lib/ocaml/UploadEndpointResolutionTest.res +0 -101
- package/tests/UploadEndpointResolutionTest.res +0 -101
- package/tests/UploadEndpointResolutionTest.res.mjs +0 -59
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
open Seed_Types
|
|
4
4
|
|
|
5
|
-
@scope("process") @val external exit: int => unit = "exit"
|
|
6
|
-
@scope("process") @val external env: dict<string> = "env"
|
|
7
5
|
|
|
8
6
|
let envOr = (key: string, fallback: string): string =>
|
|
9
|
-
env->Dict.get(key)->Option.getOr(fallback)
|
|
7
|
+
NodeProcess.env->Dict.get(key)->Option.getOr(fallback)
|
|
10
8
|
|
|
11
9
|
/** One line of progress per phase, so a slow run never looks hung. */
|
|
12
10
|
let report = (line: string): unit => Console.log(` ${line}`)
|
|
@@ -127,7 +125,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
127
125
|
// Exit cleanly: HTTP keep-alive sockets (and, on the interactive path, the
|
|
128
126
|
// readline/stdin handle) can otherwise keep the event loop alive so the CLI
|
|
129
127
|
// appears to hang after a successful run.
|
|
130
|
-
exit(0)
|
|
128
|
+
NodeProcess.exit(0)
|
|
131
129
|
} catch {
|
|
132
130
|
| Failed(message) =>
|
|
133
131
|
Console.error("")
|
|
@@ -135,7 +133,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
135
133
|
Console.error("fresh store once the cause below is fixed.")
|
|
136
134
|
Console.error("")
|
|
137
135
|
Console.error(message)
|
|
138
|
-
exit(1)
|
|
136
|
+
NodeProcess.exit(1)
|
|
139
137
|
| exn =>
|
|
140
138
|
Console.error("")
|
|
141
139
|
Console.error("Seeding aborted with an unexpected error:")
|
|
@@ -143,7 +141,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
143
141
|
Console.error(
|
|
144
142
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"),
|
|
145
143
|
)
|
|
146
|
-
exit(1)
|
|
144
|
+
NodeProcess.exit(1)
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
/**
|
|
@@ -172,7 +170,7 @@ let abortStartup = (message: string): unit => {
|
|
|
172
170
|
Console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.")
|
|
173
171
|
Console.error("")
|
|
174
172
|
Console.error(message)
|
|
175
|
-
exit(1)
|
|
173
|
+
NodeProcess.exit(1)
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
/**
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
// Seed-time asset upload against the framework's
|
|
1
|
+
// Seed-time asset upload against the framework's upload contract (route B).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// stores and the UI renders.
|
|
3
|
+
// Minting is a GraphQL mutation on the domain API — `Upload_Presign(store, fileName,
|
|
4
|
+
// contentType)` — authenticated by the same bearer the seed already uses for commands
|
|
5
|
+
// (no separate endpoint, no anonymous surface). `uploadAsset` issues it through the
|
|
6
|
+
// shared `Seed_Client`, then PUTs the bytes to the returned `uploadUrl` and resolves
|
|
7
|
+
// `Ok(storageRef)` — the same `/{prefix}/{key}` ref a command stores and the UI renders.
|
|
8
8
|
//
|
|
9
|
-
// The seed runs under Node, so
|
|
10
|
-
// absolute URL against the
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
// `uploadAsset` is the transport and takes a resolved endpoint. *Which* endpoint
|
|
15
|
-
// an asset uses — a deployment now publishes one per declared store — is
|
|
16
|
-
// `endpointFor` below, kept separate so the decision is testable without a
|
|
17
|
-
// running presign service.
|
|
9
|
+
// The seed runs under Node, so a relative `uploadUrl` (the local dev server returns a
|
|
10
|
+
// same-origin `/{prefix}/{key}`) is resolved to an absolute URL against the client's
|
|
11
|
+
// endpoint origin before the PUT; AWS returns an absolute presigned S3 URL (used as-is).
|
|
12
|
+
// The PUT itself is unauthenticated — presigned on AWS, open on the local route.
|
|
18
13
|
|
|
19
14
|
type fetchInit = {method: string, headers: dict<string>, body: string}
|
|
20
15
|
type response
|
|
21
16
|
|
|
22
17
|
@val external fetch: (string, fetchInit) => promise<response> = "fetch"
|
|
23
|
-
@send external responseJson: response => promise<JSON.t> = "json"
|
|
24
18
|
@send external responseText: response => promise<string> = "text"
|
|
25
19
|
@get external responseOk: response => bool = "ok"
|
|
26
20
|
@get external responseStatus: response => int = "status"
|
|
27
21
|
|
|
28
|
-
// Resolve a possibly-relative URL against a base (WHATWG URL semantics: an
|
|
29
|
-
//
|
|
22
|
+
// Resolve a possibly-relative URL against a base (WHATWG URL semantics: an absolute
|
|
23
|
+
// `input` ignores `base`, a relative one is resolved against it).
|
|
30
24
|
type url
|
|
31
25
|
@new external makeUrl: (string, string) => url = "URL"
|
|
32
26
|
@get external urlHref: url => string = "href"
|
|
@@ -43,105 +37,50 @@ let asString = (json: JSON.t): option<string> =>
|
|
|
43
37
|
| _ => None
|
|
44
38
|
}
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* declares a store with a matching endpoint → that store's endpoint
|
|
50
|
-
* declares a store with no matching endpoint → the legacy single service
|
|
51
|
-
* declares no store → the legacy single service
|
|
52
|
-
* neither available → `None`
|
|
53
|
-
*
|
|
54
|
-
* `store` is the qualified `{plugin}.{store}` the platform keys its per-store
|
|
55
|
-
* presign endpoints by. The two middle rows are what keep a deployment predating
|
|
56
|
-
* per-store endpoints — and the local dev server, which serves one upload route
|
|
57
|
-
* — working unchanged.
|
|
58
|
-
*
|
|
59
|
-
* These are the same four rows the AutoUI renderer resolves an upload field by.
|
|
60
|
-
* Resolving one declaration by two different rules is how an asset lands in
|
|
61
|
-
* another plugin's bucket with a 2xx and a plausible-looking ref, so a missing
|
|
62
|
-
* key falls back to the legacy service rather than to some other store.
|
|
63
|
-
*/
|
|
64
|
-
let endpointFor = (
|
|
65
|
-
~store: option<string>=?,
|
|
66
|
-
~uploadEndpoint: string,
|
|
67
|
-
~uploadEndpoints: dict<string>,
|
|
68
|
-
): option<string> => {
|
|
69
|
-
let legacy = uploadEndpoint == "" ? None : Some(uploadEndpoint)
|
|
70
|
-
switch store {
|
|
71
|
-
| Some(s) => uploadEndpoints->Dict.get(s)->Option.orElse(legacy)
|
|
72
|
-
| None => legacy
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Why `endpointFor` resolved nothing — the message a data set reports when its
|
|
78
|
-
* upload phase skips.
|
|
79
|
-
*
|
|
80
|
-
* "no upload endpoint" states a fact about the *deployment*; when the deployment
|
|
81
|
-
* publishes endpoints the caller could not match, the fact is about the *client*
|
|
82
|
-
* and that phrasing sends a reader to the bucket, the presign service and the
|
|
83
|
-
* IAM policy, all of which are correct. So the three cases are distinguished and
|
|
84
|
-
* the unmatched one names both the store it wanted and the keys it saw.
|
|
85
|
-
*/
|
|
86
|
-
let unresolvedReason = (~store: option<string>=?, ~uploadEndpoints: dict<string>): string => {
|
|
87
|
-
let available = uploadEndpoints->Dict.keysToArray
|
|
88
|
-
switch (Seed_Prompt.envValue("SEED_SKIP_UPLOADS"), store, available) {
|
|
89
|
-
| (Some(_), _, _) => "SEED_SKIP_UPLOADS is set"
|
|
90
|
-
| (None, _, []) => "this deployment publishes no upload endpoint"
|
|
91
|
-
| (None, Some(s), keys) =>
|
|
92
|
-
`this deployment publishes upload endpoints for ${keys->Array.join(", ")}, none for "${s}"`
|
|
93
|
-
| (None, None, keys) =>
|
|
94
|
-
`this deployment publishes only per-store upload endpoints (${keys->Array.join(
|
|
95
|
-
", ",
|
|
96
|
-
)}) and this upload names no store`
|
|
97
|
-
}
|
|
98
|
-
}
|
|
40
|
+
// Whether this run should skip uploads entirely. `SEED_SKIP_UPLOADS` seeds domain data
|
|
41
|
+
// fast, or skips a broken/absent upload path without editing the data set.
|
|
42
|
+
let uploadsSkipped = (): bool => Seed_Prompt.envValue("SEED_SKIP_UPLOADS")->Option.isSome
|
|
99
43
|
|
|
100
|
-
// A `fetch` that reports an unreachable endpoint as `Error` instead of throwing
|
|
101
|
-
// so the two-step upload can thread failures without exceptions.
|
|
44
|
+
// A `fetch` that reports an unreachable endpoint as `Error` instead of throwing.
|
|
102
45
|
let tryFetch = async (url: string, init: fetchInit): result<response, string> =>
|
|
103
46
|
try Ok(await fetch(url, init)) catch {
|
|
104
47
|
| _ => Error(`cannot reach ${url}`)
|
|
105
48
|
}
|
|
106
49
|
|
|
107
50
|
/**
|
|
108
|
-
* Uploads `bytes` under `fileName`/`contentType`
|
|
51
|
+
* Uploads `bytes` under `fileName`/`contentType` into `store` (the qualified
|
|
52
|
+
* `{plugin}.{store}` the asset's field declares, e.g. `"Catalog.productImages"`) and
|
|
109
53
|
* resolves `Ok(storageRef)` (the stored `/{prefix}/{key}` ref), or `Error(msg)`
|
|
110
|
-
* describing the step that failed.
|
|
111
|
-
*
|
|
112
|
-
* the PUT itself is unauthenticated — presigned on AWS, open locally).
|
|
54
|
+
* describing the step that failed. Mints through the domain API's `Upload_Presign`
|
|
55
|
+
* mutation on `client`, then PUTs the bytes to the returned `uploadUrl`.
|
|
113
56
|
*/
|
|
114
57
|
let uploadAsset = async (
|
|
115
|
-
~
|
|
58
|
+
~client: Seed_Client.t,
|
|
59
|
+
~store: string,
|
|
116
60
|
~bytes: string,
|
|
117
61
|
~fileName: string,
|
|
118
62
|
~contentType: string,
|
|
119
|
-
~authToken: option<string>=?,
|
|
120
63
|
): result<string, string> => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
let
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
64
|
+
// GraphQL string literals: JSON-quote the argument values (JSON string escaping is a
|
|
65
|
+
// superset-safe subset of GraphQL's for these ASCII-ish inputs).
|
|
66
|
+
let q = s => JSON.stringify(JSON.Encode.string(s))
|
|
67
|
+
let query = `mutation { r: Upload_Presign(store: ${q(store)}, fileName: ${q(fileName)}, contentType: ${q(contentType)}) { uploadUrl storageRef } }`
|
|
68
|
+
|
|
69
|
+
let presign = try Ok(await Seed_Client.gql(client, ~query, ~label="Upload_Presign")) catch {
|
|
70
|
+
| Seed_Types.Failed(m) => Error(m)
|
|
71
|
+
| _ => Error("Upload_Presign: unexpected error")
|
|
72
|
+
}
|
|
131
73
|
|
|
132
|
-
switch
|
|
133
|
-
| Error(m) => Error(`presign: ${m}
|
|
134
|
-
| Ok(
|
|
135
|
-
let
|
|
136
|
-
Error(`presign failed with HTTP ${(presignRes->responseStatus)->Int.toString}: ${detail}`)
|
|
137
|
-
| Ok(presignRes) =>
|
|
138
|
-
let json = await presignRes->responseJson
|
|
74
|
+
switch presign {
|
|
75
|
+
| Error(m) => Error(`presign: ${m}`)
|
|
76
|
+
| Ok(data) =>
|
|
77
|
+
let r = data->field("r")->Option.getOr(JSON.Encode.null)
|
|
139
78
|
switch (
|
|
140
|
-
|
|
141
|
-
|
|
79
|
+
r->field("uploadUrl")->Option.flatMap(asString),
|
|
80
|
+
r->field("storageRef")->Option.flatMap(asString),
|
|
142
81
|
) {
|
|
143
82
|
| (Some(uploadUrl), Some(storageRef)) =>
|
|
144
|
-
let putUrl = urlHref(makeUrl(uploadUrl,
|
|
83
|
+
let putUrl = urlHref(makeUrl(uploadUrl, Seed_Client.endpoint(client)))
|
|
145
84
|
switch await tryFetch(
|
|
146
85
|
putUrl,
|
|
147
86
|
{method: "PUT", headers: Dict.fromArray([("content-type", contentType)]), body: bytes},
|
|
@@ -152,7 +91,7 @@ let uploadAsset = async (
|
|
|
152
91
|
let detail = await putRes->responseText
|
|
153
92
|
Error(`upload PUT failed with HTTP ${(putRes->responseStatus)->Int.toString}: ${detail}`)
|
|
154
93
|
}
|
|
155
|
-
| _ => Error("
|
|
94
|
+
| _ => Error("Upload_Presign response missing uploadUrl/storageRef")
|
|
156
95
|
}
|
|
157
96
|
}
|
|
158
97
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reventlessdev/reventless-seed",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.7",
|
|
4
4
|
"description": "Reusable harness for seeding a Reventless platform through its public GraphQL command API",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@reventlessdev/rescript-node": "2.0.0-alpha.0"
|
|
8
|
+
},
|
|
6
9
|
"devDependencies": {
|
|
7
10
|
"rescript": "12.3.0",
|
|
8
|
-
"@reventlessdev/rescript-jest": "1.0.0-alpha.
|
|
11
|
+
"@reventlessdev/rescript-jest": "1.0.0-alpha.10"
|
|
9
12
|
},
|
|
10
13
|
"peerDependencies": {
|
|
11
14
|
"rescript": "12.3.0"
|
package/rescript.json
CHANGED
package/src/Seed.res
CHANGED
|
@@ -14,13 +14,12 @@ module Connect = Seed_Connect
|
|
|
14
14
|
|
|
15
15
|
exception Failed = Seed_Types.Failed
|
|
16
16
|
|
|
17
|
-
// A live target a data set seeds against: an authenticated client,
|
|
18
|
-
//
|
|
19
|
-
//
|
|
17
|
+
// A live target a data set seeds against: an authenticated client, whether uploads
|
|
18
|
+
// are skipped this run, and a label. Uploads mint through the domain API's
|
|
19
|
+
// `Upload_Presign` mutation on the client (route B), so no upload endpoint is carried.
|
|
20
20
|
type connection = Seed_Connect.connection = {
|
|
21
21
|
client: Seed_Client.t,
|
|
22
|
-
|
|
23
|
-
uploadEndpoints: dict<string>,
|
|
22
|
+
uploadsSkipped: bool,
|
|
24
23
|
label: string,
|
|
25
24
|
}
|
|
26
25
|
|
package/src/Seed_Client.res
CHANGED
|
@@ -43,6 +43,10 @@ let make = (~config: config): t => {config, token: None}
|
|
|
43
43
|
Seed.Upload) can authenticate side-channel requests with the same identity. */
|
|
44
44
|
let currentToken = (t: t): option<string> => t.token
|
|
45
45
|
|
|
46
|
+
/** The GraphQL endpoint this client targets — so `Seed.Upload` can resolve a
|
|
47
|
+
relative presigned `uploadUrl` against the same origin. */
|
|
48
|
+
let endpoint = (t: t): string => t.config.endpoint
|
|
49
|
+
|
|
46
50
|
/** Injects a bearer obtained out-of-band (e.g. a Cognito id token), instead of
|
|
47
51
|
minting one via `login`. Provider-agnostic: the harness only cares that the
|
|
48
52
|
token is a valid bearer for `endpoint`. */
|
package/src/Seed_Client.res.mjs
CHANGED
|
@@ -21,6 +21,10 @@ function currentToken(t) {
|
|
|
21
21
|
return t.token;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function endpoint(t) {
|
|
25
|
+
return t.config.endpoint;
|
|
26
|
+
}
|
|
27
|
+
|
|
24
28
|
function useToken(t, token) {
|
|
25
29
|
t.token = token;
|
|
26
30
|
}
|
|
@@ -266,6 +270,7 @@ export {
|
|
|
266
270
|
sleep,
|
|
267
271
|
make,
|
|
268
272
|
currentToken,
|
|
273
|
+
endpoint,
|
|
269
274
|
useToken,
|
|
270
275
|
field,
|
|
271
276
|
asString,
|
package/src/Seed_Connect.res
CHANGED
|
@@ -9,15 +9,13 @@
|
|
|
9
9
|
|
|
10
10
|
open Seed_Types
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// for the resolution between them.
|
|
12
|
+
// Under route B the client mints uploads through the domain API's `Upload_Presign`
|
|
13
|
+
// mutation (authenticated by the same bearer as commands), so a connection needs no
|
|
14
|
+
// upload endpoint — just the authenticated client and whether uploads are skipped this
|
|
15
|
+
// run (`SEED_SKIP_UPLOADS`). Which store an asset uploads into is the caller's `~store`.
|
|
17
16
|
type connection = {
|
|
18
17
|
client: Seed_Client.t,
|
|
19
|
-
|
|
20
|
-
uploadEndpoints: dict<string>,
|
|
18
|
+
uploadsSkipped: bool,
|
|
21
19
|
label: string,
|
|
22
20
|
}
|
|
23
21
|
|
|
@@ -29,48 +27,20 @@ type connection = {
|
|
|
29
27
|
let make = async (
|
|
30
28
|
~label: string,
|
|
31
29
|
~endpoint: string,
|
|
32
|
-
~uploadEndpoint: string,
|
|
33
|
-
~uploadEndpoints: dict<string>=Dict.make(),
|
|
34
30
|
~login: (~username: string, ~password: string) => promise<string>,
|
|
35
31
|
~localDefaults: bool=false,
|
|
36
32
|
): connection => {
|
|
37
|
-
// `SEED_SKIP_UPLOADS` forces the
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
// knob: an empty `REVENTLESS_UPLOAD_ENDPOINT` env reads as "unset" (falls back
|
|
42
|
-
// to discovery), so this is the reliable way to disable uploads — which means
|
|
43
|
-
// it has to clear the per-store map too, or a declared store keeps uploading
|
|
44
|
-
// through it.
|
|
45
|
-
let skip = Seed_Prompt.envValue("SEED_SKIP_UPLOADS")->Option.isSome
|
|
46
|
-
let uploadEndpoint = skip ? "" : uploadEndpoint
|
|
47
|
-
let uploadEndpoints = skip ? Dict.make() : uploadEndpoints
|
|
33
|
+
// `SEED_SKIP_UPLOADS` forces the upload phase to no-op — seed domain data fast, or
|
|
34
|
+
// skip a broken/absent upload path without editing the data set. The data set reads
|
|
35
|
+
// `connection.uploadsSkipped` and reports the skip.
|
|
36
|
+
let uploadsSkipped = Seed_Upload.uploadsSkipped()
|
|
48
37
|
let (username, password) = await Seed_Prompt.credentials(~localDefaults)
|
|
49
38
|
let token = await login(~username, ~password)
|
|
50
39
|
let client = Seed_Client.make(~config={endpoint: endpoint})
|
|
51
40
|
client->Seed_Client.useToken(token)
|
|
52
|
-
{client,
|
|
41
|
+
{client, uploadsSkipped, label}
|
|
53
42
|
}
|
|
54
43
|
|
|
55
|
-
/**
|
|
56
|
-
* The endpoint an asset destined for `store` uploads through, or the reason
|
|
57
|
-
* there is none — the message to report when the upload phase skips.
|
|
58
|
-
*
|
|
59
|
-
* `store` is the qualified `{plugin}.{store}` the asset's field declares, e.g.
|
|
60
|
-
* `"Catalog.productImages"`. Resolution is `Seed_Upload.endpointFor`; naming a
|
|
61
|
-
* store the deployment does not serve falls back to the legacy single service
|
|
62
|
-
* rather than to another store's endpoint.
|
|
63
|
-
*/
|
|
64
|
-
let uploadEndpointFor = (c: connection, ~store: string): result<string, string> =>
|
|
65
|
-
switch Seed_Upload.endpointFor(
|
|
66
|
-
~store,
|
|
67
|
-
~uploadEndpoint=c.uploadEndpoint,
|
|
68
|
-
~uploadEndpoints=c.uploadEndpoints,
|
|
69
|
-
) {
|
|
70
|
-
| Some(endpoint) => Ok(endpoint)
|
|
71
|
-
| None => Error(Seed_Upload.unresolvedReason(~store, ~uploadEndpoints=c.uploadEndpoints))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
44
|
/**
|
|
75
45
|
* A login function backed by an HTTP login endpoint (the local dev
|
|
76
46
|
* `/__inmemory/login` shape: POST `{username, password}` → `{token}`). Reuses
|
|
@@ -98,24 +68,18 @@ let envOr = (key: string, fallback: string): string =>
|
|
|
98
68
|
* defaults baked in and overridable per endpoint (arg, then env var, then
|
|
99
69
|
* default). Empty input at the credential prompt falls back to `admin`/`admin`.
|
|
100
70
|
*
|
|
101
|
-
* No
|
|
102
|
-
*
|
|
103
|
-
* "declares a store with no matching endpoint" row.
|
|
71
|
+
* No upload endpoint: uploads mint through the domain API's `Upload_Presign` mutation
|
|
72
|
+
* on the same `graphql` endpoint, with the store passed per asset.
|
|
104
73
|
*/
|
|
105
|
-
let local = (~graphql=?, ~
|
|
74
|
+
let local = (~graphql=?, ~login=?, ()): (unit => promise<connection>) => {
|
|
106
75
|
let endpoint =
|
|
107
76
|
graphql->Option.getOr(envOr("REVENTLESS_GRAPHQL_ENDPOINT", "http://localhost:4000/graphql"))
|
|
108
|
-
let uploadEndpoint =
|
|
109
|
-
upload->Option.getOr(
|
|
110
|
-
envOr("REVENTLESS_UPLOAD_ENDPOINT", "http://localhost:4000/__inmemory/upload"),
|
|
111
|
-
)
|
|
112
77
|
let loginEndpoint =
|
|
113
78
|
login->Option.getOr(envOr("REVENTLESS_LOGIN_ENDPOINT", "http://localhost:4000/__inmemory/login"))
|
|
114
79
|
() =>
|
|
115
80
|
make(
|
|
116
81
|
~label="local",
|
|
117
82
|
~endpoint,
|
|
118
|
-
~uploadEndpoint,
|
|
119
83
|
~login=viaLoginEndpoint(~loginEndpoint),
|
|
120
84
|
~localDefaults=true,
|
|
121
85
|
)
|
package/src/Seed_Connect.res.mjs
CHANGED
|
@@ -6,12 +6,9 @@ import * as Seed_Client$ReventlessSeed from "./Seed_Client.res.mjs";
|
|
|
6
6
|
import * as Seed_Prompt$ReventlessSeed from "./Seed_Prompt.res.mjs";
|
|
7
7
|
import * as Seed_Upload$ReventlessSeed from "./Seed_Upload.res.mjs";
|
|
8
8
|
|
|
9
|
-
async function make(label, endpoint,
|
|
10
|
-
let uploadEndpoints = uploadEndpointsOpt !== undefined ? uploadEndpointsOpt : ({});
|
|
9
|
+
async function make(label, endpoint, login, localDefaultsOpt) {
|
|
11
10
|
let localDefaults = localDefaultsOpt !== undefined ? localDefaultsOpt : false;
|
|
12
|
-
let
|
|
13
|
-
let uploadEndpoint$1 = skip ? "" : uploadEndpoint;
|
|
14
|
-
let uploadEndpoints$1 = skip ? ({}) : uploadEndpoints;
|
|
11
|
+
let uploadsSkipped = Seed_Upload$ReventlessSeed.uploadsSkipped();
|
|
15
12
|
let match = await Seed_Prompt$ReventlessSeed.credentials(localDefaults);
|
|
16
13
|
let token = await login(match[0], match[1]);
|
|
17
14
|
let client = Seed_Client$ReventlessSeed.make({
|
|
@@ -20,27 +17,11 @@ async function make(label, endpoint, uploadEndpoint, uploadEndpointsOpt, login,
|
|
|
20
17
|
Seed_Client$ReventlessSeed.useToken(client, token);
|
|
21
18
|
return {
|
|
22
19
|
client: client,
|
|
23
|
-
|
|
24
|
-
uploadEndpoints: uploadEndpoints$1,
|
|
20
|
+
uploadsSkipped: uploadsSkipped,
|
|
25
21
|
label: label
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
function uploadEndpointFor(c, store) {
|
|
30
|
-
let endpoint = Seed_Upload$ReventlessSeed.endpointFor(store, c.uploadEndpoint, c.uploadEndpoints);
|
|
31
|
-
if (endpoint !== undefined) {
|
|
32
|
-
return {
|
|
33
|
-
TAG: "Ok",
|
|
34
|
-
_0: endpoint
|
|
35
|
-
};
|
|
36
|
-
} else {
|
|
37
|
-
return {
|
|
38
|
-
TAG: "Error",
|
|
39
|
-
_0: Seed_Upload$ReventlessSeed.unresolvedReason(store, c.uploadEndpoints)
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
25
|
function viaLoginEndpoint(loginEndpoint) {
|
|
45
26
|
return async (username, password) => {
|
|
46
27
|
let client = Seed_Client$ReventlessSeed.make({
|
|
@@ -66,16 +47,14 @@ function envOr(key, fallback) {
|
|
|
66
47
|
return Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue(key), fallback);
|
|
67
48
|
}
|
|
68
49
|
|
|
69
|
-
function local(graphql,
|
|
50
|
+
function local(graphql, login, param) {
|
|
70
51
|
let endpoint = Stdlib_Option.getOr(graphql, Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_GRAPHQL_ENDPOINT"), "http://localhost:4000/graphql"));
|
|
71
|
-
let uploadEndpoint = Stdlib_Option.getOr(upload, Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_UPLOAD_ENDPOINT"), "http://localhost:4000/__inmemory/upload"));
|
|
72
52
|
let loginEndpoint = Stdlib_Option.getOr(login, Stdlib_Option.getOr(Seed_Prompt$ReventlessSeed.envValue("REVENTLESS_LOGIN_ENDPOINT"), "http://localhost:4000/__inmemory/login"));
|
|
73
|
-
return () => make("local", endpoint,
|
|
53
|
+
return () => make("local", endpoint, viaLoginEndpoint(loginEndpoint), true);
|
|
74
54
|
}
|
|
75
55
|
|
|
76
56
|
export {
|
|
77
57
|
make,
|
|
78
|
-
uploadEndpointFor,
|
|
79
58
|
viaLoginEndpoint,
|
|
80
59
|
envOr,
|
|
81
60
|
local,
|
package/src/Seed_Prompt.res
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// One shared readline interface for every interactive prompt in a seed run.
|
|
2
2
|
//
|
|
3
3
|
// The reason this module exists: creating and closing a fresh `readline`
|
|
4
|
-
// interface per prompt leaves stdin paused after the first `close`, so the
|
|
4
|
+
// interface per prompt leaves NodeProcess.stdin paused after the first `close`, so the
|
|
5
5
|
// second prompt (password after username) never fires and the run hangs. A
|
|
6
6
|
// single interface, created lazily and closed exactly once, avoids that — and a
|
|
7
7
|
// `muted` gate on its output lets password entry reuse the same interface
|
|
@@ -14,18 +14,8 @@ open Seed_Types
|
|
|
14
14
|
|
|
15
15
|
// ── Node bindings ─────────────────────────────────────────────────────────────
|
|
16
16
|
|
|
17
|
-
type stream
|
|
18
|
-
@val @scope("process") external stdin: stream = "stdin"
|
|
19
|
-
@val @scope("process") external stdout: stream = "stdout"
|
|
20
|
-
@send external writeStream: (stream, string) => unit = "write"
|
|
21
|
-
@get external isTTY: stream => bool = "isTTY"
|
|
22
|
-
@send external pauseStream: stream => unit = "pause"
|
|
23
|
-
@send external unrefStream: stream => unit = "unref"
|
|
24
|
-
|
|
25
|
-
@scope("process") @val external processEnv: dict<string> = "env"
|
|
26
|
-
|
|
27
17
|
type rl
|
|
28
|
-
type rlOptions = {input: stream, output: stream, terminal?: bool}
|
|
18
|
+
type rlOptions = {input: NodeProcess.stream, output: NodeProcess.stream, terminal?: bool}
|
|
29
19
|
@module("node:readline") external createInterface: rlOptions => rl = "createInterface"
|
|
30
20
|
@send external question: (rl, string, string => unit) => unit = "question"
|
|
31
21
|
@send external closeRl: rl => unit = "close"
|
|
@@ -42,10 +32,10 @@ let iface = (): rl =>
|
|
|
42
32
|
switch rlRef.contents {
|
|
43
33
|
| Some(rl) => rl
|
|
44
34
|
| None =>
|
|
45
|
-
let rl = createInterface({input: stdin, output: stdout, terminal: true})
|
|
35
|
+
let rl = createInterface({input: NodeProcess.stdin, output: NodeProcess.stdout, terminal: true})
|
|
46
36
|
rl->setWriteToOutput(s =>
|
|
47
37
|
if !muted.contents {
|
|
48
|
-
stdout->
|
|
38
|
+
NodeProcess.stdout->NodeProcess.write(s)
|
|
49
39
|
}
|
|
50
40
|
)
|
|
51
41
|
rlRef := Some(rl)
|
|
@@ -58,23 +48,23 @@ let close = (): unit =>
|
|
|
58
48
|
rl->closeRl
|
|
59
49
|
rlRef := None
|
|
60
50
|
// Closing the interface is not enough: a terminal-mode readline leaves
|
|
61
|
-
// stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
51
|
+
// NodeProcess.stdin resumed and reffed, which keeps the event loop alive so the CLI
|
|
62
52
|
// never exits after seeding. Release it explicitly.
|
|
63
|
-
stdin->
|
|
64
|
-
stdin->
|
|
53
|
+
NodeProcess.stdin->NodeProcess.pause
|
|
54
|
+
NodeProcess.stdin->NodeProcess.unref
|
|
65
55
|
| None => ()
|
|
66
56
|
}
|
|
67
57
|
|
|
68
58
|
// ── Env + TTY ─────────────────────────────────────────────────────────────────
|
|
69
59
|
|
|
70
60
|
let envValue = (key: string): option<string> =>
|
|
71
|
-
switch
|
|
61
|
+
switch NodeProcess.env->Dict.get(key) {
|
|
72
62
|
| Some(v) if v->String.trim != "" => Some(v->String.trim)
|
|
73
63
|
| _ => None
|
|
74
64
|
}
|
|
75
65
|
|
|
76
66
|
let requireTty = (): unit =>
|
|
77
|
-
if !(stdin->isTTY) {
|
|
67
|
+
if !(NodeProcess.stdin->NodeProcess.isTTY->Option.getOr(false)) {
|
|
78
68
|
throw(
|
|
79
69
|
Failed(
|
|
80
70
|
"no TTY for an interactive prompt — set the documented SEED_* / REVENTLESS_DEMO_* " ++
|
|
@@ -101,7 +91,7 @@ let askHidden = (query: string): promise<string> =>
|
|
|
101
91
|
let rl = iface()
|
|
102
92
|
rl->question(query, answer => {
|
|
103
93
|
muted := false
|
|
104
|
-
stdout->
|
|
94
|
+
NodeProcess.stdout->NodeProcess.write("\n")
|
|
105
95
|
resolve(answer)
|
|
106
96
|
})
|
|
107
97
|
muted := true
|
package/src/Seed_Prompt.res.mjs
CHANGED
package/src/Seed_Runner.res
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
open Seed_Types
|
|
4
4
|
|
|
5
|
-
@scope("process") @val external exit: int => unit = "exit"
|
|
6
|
-
@scope("process") @val external env: dict<string> = "env"
|
|
7
5
|
|
|
8
6
|
let envOr = (key: string, fallback: string): string =>
|
|
9
|
-
env->Dict.get(key)->Option.getOr(fallback)
|
|
7
|
+
NodeProcess.env->Dict.get(key)->Option.getOr(fallback)
|
|
10
8
|
|
|
11
9
|
/** One line of progress per phase, so a slow run never looks hung. */
|
|
12
10
|
let report = (line: string): unit => Console.log(` ${line}`)
|
|
@@ -127,7 +125,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
127
125
|
// Exit cleanly: HTTP keep-alive sockets (and, on the interactive path, the
|
|
128
126
|
// readline/stdin handle) can otherwise keep the event loop alive so the CLI
|
|
129
127
|
// appears to hang after a successful run.
|
|
130
|
-
exit(0)
|
|
128
|
+
NodeProcess.exit(0)
|
|
131
129
|
} catch {
|
|
132
130
|
| Failed(message) =>
|
|
133
131
|
Console.error("")
|
|
@@ -135,7 +133,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
135
133
|
Console.error("fresh store once the cause below is fixed.")
|
|
136
134
|
Console.error("")
|
|
137
135
|
Console.error(message)
|
|
138
|
-
exit(1)
|
|
136
|
+
NodeProcess.exit(1)
|
|
139
137
|
| exn =>
|
|
140
138
|
Console.error("")
|
|
141
139
|
Console.error("Seeding aborted with an unexpected error:")
|
|
@@ -143,7 +141,7 @@ let run = async (main: unit => promise<unit>): unit =>
|
|
|
143
141
|
Console.error(
|
|
144
142
|
exn->JsExn.fromException->Option.flatMap(JsExn.message)->Option.getOr("unknown"),
|
|
145
143
|
)
|
|
146
|
-
exit(1)
|
|
144
|
+
NodeProcess.exit(1)
|
|
147
145
|
}
|
|
148
146
|
|
|
149
147
|
/**
|
|
@@ -172,7 +170,7 @@ let abortStartup = (message: string): unit => {
|
|
|
172
170
|
Console.error("Seeding did not start — nothing was written. Fix the cause below and re-run.")
|
|
173
171
|
Console.error("")
|
|
174
172
|
Console.error(message)
|
|
175
|
-
exit(1)
|
|
173
|
+
NodeProcess.exit(1)
|
|
176
174
|
}
|
|
177
175
|
|
|
178
176
|
/**
|