@reventlessdev/reventless-seed 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +149 -0
- package/lib/bs/.compiler.log +2 -2
- package/lib/bs/.sourcedirs.json +1 -0
- package/lib/bs/ReventlessSeed.cmi +0 -0
- package/lib/bs/ReventlessSeed.cmt +0 -0
- package/lib/bs/ReventlessSeed.mlmap +6 -0
- 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 +12 -3
- package/lib/bs/src/Seed.res.mjs +3 -0
- 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 +382 -21
- package/lib/bs/src/Seed_Client.res.mjs +332 -24
- 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 +281 -33
- package/lib/bs/src/Seed_Connect.res.mjs +162 -8
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Prompt-ReventlessSeed.cmj +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 +140 -41
- package/lib/bs/src/Seed_Prompt.res.mjs +88 -13
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Random.ast +0 -0
- package/lib/bs/src/Seed_Random.res +4 -2
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Runner-ReventlessSeed.cmj +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 +45 -19
- package/lib/bs/src/Seed_Runner.res.mjs +19 -1
- 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 +43 -43
- package/lib/bs/src/Seed_Upload.res.mjs +65 -69
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/bs/src/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/bs/src/Seed_Users.ast +0 -0
- package/lib/bs/src/Seed_Users.res +92 -0
- package/lib/bs/src/Seed_Users.res.mjs +91 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ClientTest.ast +0 -0
- package/lib/bs/tests/Seed_ClientTest.res +287 -0
- package/lib/bs/tests/Seed_ClientTest.res.mjs +268 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_ConnectTest.ast +0 -0
- package/lib/bs/tests/Seed_ConnectTest.res +64 -0
- package/lib/bs/tests/Seed_ConnectTest.res.mjs +56 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_PromptTest.ast +0 -0
- package/lib/bs/tests/Seed_PromptTest.res +55 -0
- package/lib/bs/tests/Seed_PromptTest.res.mjs +63 -0
- 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 +200 -0
- package/lib/bs/tests/Seed_RandomTest.res.mjs +208 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/bs/tests/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/bs/tests/Seed_UsersTest.ast +0 -0
- package/lib/bs/tests/Seed_UsersTest.res +129 -0
- package/lib/bs/tests/Seed_UsersTest.res.mjs +113 -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 +6 -0
- 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 +12 -3
- 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 +382 -21
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ClientTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ClientTest.ast +0 -0
- package/lib/ocaml/Seed_ClientTest.res +287 -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 +281 -33
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_ConnectTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_ConnectTest.ast +0 -0
- package/lib/ocaml/Seed_ConnectTest.res +64 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Prompt-ReventlessSeed.cmj +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 +140 -41
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_PromptTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_PromptTest.ast +0 -0
- package/lib/ocaml/Seed_PromptTest.res +55 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Random-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Random.ast +0 -0
- package/lib/ocaml/Seed_Random.res +4 -2
- 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 +200 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Runner-ReventlessSeed.cmj +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 +45 -19
- 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 +43 -43
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_Users-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_Users.ast +0 -0
- package/lib/ocaml/Seed_Users.res +92 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmi +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmj +0 -0
- package/lib/ocaml/Seed_UsersTest-ReventlessSeed.cmt +0 -0
- package/lib/ocaml/Seed_UsersTest.ast +0 -0
- package/lib/ocaml/Seed_UsersTest.res +129 -0
- package/package.json +7 -2
- package/rescript.json +9 -1
- package/src/Seed.res +12 -3
- package/src/Seed.res.mjs +3 -0
- package/src/Seed_Client.res +382 -21
- package/src/Seed_Client.res.mjs +332 -24
- package/src/Seed_Connect.res +281 -33
- package/src/Seed_Connect.res.mjs +162 -8
- package/src/Seed_Prompt.res +140 -41
- package/src/Seed_Prompt.res.mjs +88 -13
- package/src/Seed_Random.res +4 -2
- package/src/Seed_Runner.res +45 -19
- package/src/Seed_Runner.res.mjs +19 -1
- package/src/Seed_Upload.res +43 -43
- package/src/Seed_Upload.res.mjs +65 -69
- package/src/Seed_Users.res +92 -0
- package/src/Seed_Users.res.mjs +91 -0
- package/tests/Seed_ClientTest.res +287 -0
- package/tests/Seed_ClientTest.res.mjs +268 -0
- package/tests/Seed_ConnectTest.res +64 -0
- package/tests/Seed_ConnectTest.res.mjs +56 -0
- package/tests/Seed_PromptTest.res +55 -0
- package/tests/Seed_PromptTest.res.mjs +63 -0
- package/tests/Seed_RandomTest.res +200 -0
- package/tests/Seed_RandomTest.res.mjs +208 -0
- package/tests/Seed_UsersTest.res +129 -0
- package/tests/Seed_UsersTest.res.mjs +113 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
3
4
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
4
5
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
6
|
import * as Seed_Types$ReventlessSeed from "./Seed_Types.res.mjs";
|
|
@@ -21,10 +22,107 @@ function currentToken(t) {
|
|
|
21
22
|
return t.token;
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
function endpoint(t) {
|
|
26
|
+
return t.config.endpoint;
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
function useToken(t, token) {
|
|
25
30
|
t.token = token;
|
|
26
31
|
}
|
|
27
32
|
|
|
33
|
+
let availableRolesClaim = "availableRoles";
|
|
34
|
+
|
|
35
|
+
let groupClaimNames = [
|
|
36
|
+
"cognito:groups",
|
|
37
|
+
"groups"
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
let callerIdClaimNames = [
|
|
41
|
+
"sub",
|
|
42
|
+
"userId"
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
function decodeSegment(segment) {
|
|
46
|
+
try {
|
|
47
|
+
return Stdlib_JSON.Decode.object(JSON.parse(Buffer.from(segment, "base64url").toString("utf8")));
|
|
48
|
+
} catch (exn) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isJoseHeader(obj) {
|
|
54
|
+
return Stdlib_Option.isSome(obj["alg"]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function claims(t) {
|
|
58
|
+
return Stdlib_Option.flatMap(t.token, token => Stdlib_Array.reduce(token.split("."), undefined, (found, segment) => {
|
|
59
|
+
if (found !== undefined) {
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
let obj = decodeSegment(segment);
|
|
63
|
+
if (obj !== undefined && Stdlib_Option.isSome(obj["alg"])) {
|
|
64
|
+
return;
|
|
65
|
+
} else {
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function asStrings(value) {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
return Stdlib_Array.filterMap(value, Stdlib_JSON.Decode.string);
|
|
74
|
+
}
|
|
75
|
+
switch (typeof value) {
|
|
76
|
+
case "string" :
|
|
77
|
+
return value.split(",").map(prim => prim.trim()).filter(s => s !== "");
|
|
78
|
+
default:
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function claimStrings(t, name) {
|
|
84
|
+
return Stdlib_Option.flatMap(Stdlib_Option.flatMap(claims(t), c => c[name]), asStrings);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function effectiveGroups(t) {
|
|
88
|
+
return Stdlib_Array.reduce(groupClaimNames, undefined, (found, name) => {
|
|
89
|
+
if (found !== undefined) {
|
|
90
|
+
return found;
|
|
91
|
+
} else {
|
|
92
|
+
return claimStrings(t, name);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function callerId(t) {
|
|
98
|
+
return Stdlib_Array.reduce(callerIdClaimNames, undefined, (found, name) => {
|
|
99
|
+
if (found !== undefined) {
|
|
100
|
+
return found;
|
|
101
|
+
} else {
|
|
102
|
+
return Stdlib_Option.flatMap(Stdlib_Option.flatMap(claims(t), c => c[name]), Stdlib_JSON.Decode.string);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function narrowedFrom(t) {
|
|
108
|
+
let available = claimStrings(t, availableRolesClaim);
|
|
109
|
+
if (available !== undefined && available.length !== 0) {
|
|
110
|
+
return available;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function identitySummary(t) {
|
|
115
|
+
return Stdlib_Option.map(effectiveGroups(t), groups => {
|
|
116
|
+
let held = groups.length === 0 ? "no groups" : groups.join(", ");
|
|
117
|
+
let available = claimStrings(t, availableRolesClaim);
|
|
118
|
+
if (available !== undefined && available.length !== 0) {
|
|
119
|
+
return held + ` — narrowed to this role from ` + available.join(", ");
|
|
120
|
+
} else {
|
|
121
|
+
return held;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
28
126
|
function field(json, key) {
|
|
29
127
|
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
30
128
|
return json[key];
|
|
@@ -94,7 +192,58 @@ async function login(t) {
|
|
|
94
192
|
t.token = Stdlib_Option.flatMap(field(json, "token"), asString);
|
|
95
193
|
}
|
|
96
194
|
|
|
97
|
-
|
|
195
|
+
let transientErrorTypes = [
|
|
196
|
+
"InternalFailure",
|
|
197
|
+
"ServiceUnavailable",
|
|
198
|
+
"ServiceUnavailableError",
|
|
199
|
+
"Throttling",
|
|
200
|
+
"ThrottlingException",
|
|
201
|
+
"TooManyRequestsException",
|
|
202
|
+
"RequestTimeout"
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
function isTransient(errors) {
|
|
206
|
+
let entries = Stdlib_JSON.Decode.array(errors);
|
|
207
|
+
if (entries !== undefined && entries.length !== 0) {
|
|
208
|
+
return entries.every(e => {
|
|
209
|
+
let errorType = nodeString(e, "errorType");
|
|
210
|
+
if (errorType !== undefined) {
|
|
211
|
+
return transientErrorTypes.includes(errorType);
|
|
212
|
+
} else {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
} else {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function isDenied(errors) {
|
|
222
|
+
let entries = Stdlib_JSON.Decode.array(errors);
|
|
223
|
+
if (entries !== undefined) {
|
|
224
|
+
return entries.some(e => {
|
|
225
|
+
let match = nodeString(e, "errorType");
|
|
226
|
+
let match$1 = nodeString(e, "message");
|
|
227
|
+
if (match !== undefined) {
|
|
228
|
+
if (match.includes("Unauthorized")) {
|
|
229
|
+
return true;
|
|
230
|
+
} else if (match$1 !== undefined) {
|
|
231
|
+
return match$1.includes("Not Authorized");
|
|
232
|
+
} else {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
} else if (match$1 !== undefined) {
|
|
236
|
+
return match$1.includes("Not Authorized");
|
|
237
|
+
} else {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function gqlOutcome(t, query, label) {
|
|
98
247
|
let headers = Object.fromEntries([[
|
|
99
248
|
"content-type",
|
|
100
249
|
"application/json"
|
|
@@ -107,30 +256,73 @@ async function gql(t, query, label) {
|
|
|
107
256
|
"query",
|
|
108
257
|
query
|
|
109
258
|
]]));
|
|
110
|
-
let
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
259
|
+
let attempt = async n => {
|
|
260
|
+
let res;
|
|
261
|
+
try {
|
|
262
|
+
res = await fetch(t.config.endpoint, {
|
|
263
|
+
method: "POST",
|
|
264
|
+
headers: headers,
|
|
265
|
+
body: body
|
|
266
|
+
});
|
|
267
|
+
} catch (exn) {
|
|
268
|
+
throw {
|
|
269
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
270
|
+
_1: label + `: cannot reach ` + t.config.endpoint + ` — is the platform running?`,
|
|
271
|
+
Error: new Error()
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
let json = await res.json();
|
|
275
|
+
let errors = field(json, "errors");
|
|
276
|
+
if (errors === undefined) {
|
|
277
|
+
return {
|
|
278
|
+
TAG: "Data",
|
|
279
|
+
_0: Stdlib_Option.getOr(field(json, "data"), null)
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
if (isTransient(errors) && n < 4) {
|
|
283
|
+
await sleep((250 * (1 << (n - 1 | 0)) | 0) + (Math.random() * 250 | 0) | 0);
|
|
284
|
+
return await attempt(n + 1 | 0);
|
|
285
|
+
}
|
|
286
|
+
let tried = n > 1 ? `\n gave up after ` + n.toString() + ` attempts` : "";
|
|
287
|
+
let summary = isDenied(errors) ? identitySummary(t) : undefined;
|
|
288
|
+
let identity = summary !== undefined ? `\n identity: ` + summary : "";
|
|
289
|
+
return {
|
|
290
|
+
TAG: "Errors",
|
|
291
|
+
_0: {
|
|
292
|
+
errors: errors,
|
|
293
|
+
message: label + ` failed\n query: ` + query + `\n response: ` + JSON.stringify(errors) + identity + tried
|
|
294
|
+
}
|
|
122
295
|
};
|
|
296
|
+
};
|
|
297
|
+
return await attempt(1);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function gql(t, query, label) {
|
|
301
|
+
let data = await gqlOutcome(t, query, label);
|
|
302
|
+
if (data.TAG === "Data") {
|
|
303
|
+
return data._0;
|
|
123
304
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
305
|
+
throw {
|
|
306
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
307
|
+
_1: data._0.message,
|
|
308
|
+
Error: new Error()
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function checkAccess(t, query, label) {
|
|
313
|
+
let match = await gqlOutcome(t, query, label);
|
|
314
|
+
if (match.TAG === "Data") {
|
|
315
|
+
return "Granted";
|
|
316
|
+
}
|
|
317
|
+
let match$1 = match._0;
|
|
318
|
+
if (isDenied(match$1.errors)) {
|
|
319
|
+
return "Refused";
|
|
320
|
+
} else {
|
|
321
|
+
return {
|
|
322
|
+
TAG: "Broke",
|
|
323
|
+
_0: match$1.message
|
|
131
324
|
};
|
|
132
325
|
}
|
|
133
|
-
return Stdlib_Option.getOr(field(json, "data"), null);
|
|
134
326
|
}
|
|
135
327
|
|
|
136
328
|
let commandResultSelection = `__typename
|
|
@@ -162,6 +354,68 @@ async function send(t, m, tolerateOpt) {
|
|
|
162
354
|
};
|
|
163
355
|
}
|
|
164
356
|
|
|
357
|
+
let deniedCommandCodes = [
|
|
358
|
+
"Forbidden",
|
|
359
|
+
"Unauthorized",
|
|
360
|
+
"AccessDenied"
|
|
361
|
+
];
|
|
362
|
+
|
|
363
|
+
function isDeniedResult(result) {
|
|
364
|
+
let match = nodeString(result, "errorCode");
|
|
365
|
+
let match$1 = nodeString(result, "errorDetail");
|
|
366
|
+
if (match !== undefined && deniedCommandCodes.includes(match)) {
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
if (match$1 !== undefined) {
|
|
370
|
+
return match$1.toLowerCase().includes("not authorized");
|
|
371
|
+
} else {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async function checkCommandAccess(t, m) {
|
|
377
|
+
let data = await gqlOutcome(t, `mutation { r: ` + m.field + `(` + Seed_Types$ReventlessSeed.renderArgs(m.args) + `) { ` + commandResultSelection + ` } }`, Seed_Types$ReventlessSeed.describe(m));
|
|
378
|
+
if (data.TAG === "Data") {
|
|
379
|
+
if (isDeniedResult(Stdlib_Option.getOr(field(data._0, "r"), null))) {
|
|
380
|
+
return "Refused";
|
|
381
|
+
} else {
|
|
382
|
+
return "Granted";
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
let match = data._0;
|
|
386
|
+
if (isDenied(match.errors)) {
|
|
387
|
+
return "Refused";
|
|
388
|
+
} else {
|
|
389
|
+
return {
|
|
390
|
+
TAG: "Broke",
|
|
391
|
+
_0: match.message
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
async function checkQueryAccess(t, fieldName) {
|
|
397
|
+
let query = `{ ` + fieldName + `(first: 1) { edges { node { id } } } }`;
|
|
398
|
+
let data = await gqlOutcome(t, query, fieldName);
|
|
399
|
+
if (data.TAG === "Data") {
|
|
400
|
+
let match = Stdlib_Option.flatMap(field(data._0, fieldName), c => field(c, "edges"));
|
|
401
|
+
let edges = Array.isArray(match) ? match.length : 0;
|
|
402
|
+
if (edges > 0) {
|
|
403
|
+
return "Granted";
|
|
404
|
+
} else {
|
|
405
|
+
return "Empty";
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
let match$1 = data._0;
|
|
409
|
+
if (isDenied(match$1.errors)) {
|
|
410
|
+
return "Refused";
|
|
411
|
+
} else {
|
|
412
|
+
return {
|
|
413
|
+
TAG: "Broke",
|
|
414
|
+
_0: match$1.message
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
165
419
|
async function sendAll(t, mutations) {
|
|
166
420
|
for (let i = 0, i_finish = mutations.length; i < i_finish; ++i) {
|
|
167
421
|
let m = mutations[i];
|
|
@@ -171,14 +425,16 @@ async function sendAll(t, mutations) {
|
|
|
171
425
|
}
|
|
172
426
|
}
|
|
173
427
|
|
|
174
|
-
async function queryAllNodes(t, fieldName, selection) {
|
|
428
|
+
async function queryAllNodes(t, fieldName, selection, argsOpt) {
|
|
429
|
+
let args = argsOpt !== undefined ? argsOpt : "";
|
|
175
430
|
let nodes = [];
|
|
176
431
|
let after;
|
|
177
432
|
let more = true;
|
|
433
|
+
let extra = args === "" ? "" : `, ` + args;
|
|
178
434
|
while (more) {
|
|
179
435
|
let c = after;
|
|
180
436
|
let cursor = c !== undefined ? `, after: ` + Seed_Types$ReventlessSeed.quote(c) : "";
|
|
181
|
-
let query = `{ ` + fieldName + `(first: 100` + cursor + `) { edges { node { ` + selection + ` } } pageInfo { hasNextPage endCursor } } }`;
|
|
437
|
+
let query = `{ ` + fieldName + `(first: 100` + extra + cursor + `) { edges { node { ` + selection + ` } } pageInfo { hasNextPage endCursor } } }`;
|
|
182
438
|
let data = await gql(t, query, fieldName);
|
|
183
439
|
let connection = Stdlib_Option.getOr(field(data, fieldName), null);
|
|
184
440
|
let match = field(connection, "edges");
|
|
@@ -205,7 +461,30 @@ async function queryAllNodes(t, fieldName, selection) {
|
|
|
205
461
|
}
|
|
206
462
|
|
|
207
463
|
async function countNodes(t, field) {
|
|
208
|
-
return (await queryAllNodes(t, field, "id")).length;
|
|
464
|
+
return (await queryAllNodes(t, field, "id", undefined)).length;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async function queryAllNodesUntil(t, field, selection, argsOpt, satisfied, onTimeout, timeoutMsOpt) {
|
|
468
|
+
let args = argsOpt !== undefined ? argsOpt : "";
|
|
469
|
+
let timeoutMs = timeoutMsOpt !== undefined ? timeoutMsOpt : 60000;
|
|
470
|
+
let deadline = Date.now() + timeoutMs;
|
|
471
|
+
let result;
|
|
472
|
+
while (result === undefined) {
|
|
473
|
+
let nodes = await queryAllNodes(t, field, selection, args);
|
|
474
|
+
if (satisfied(nodes)) {
|
|
475
|
+
result = nodes;
|
|
476
|
+
} else {
|
|
477
|
+
if (Date.now() > deadline) {
|
|
478
|
+
throw {
|
|
479
|
+
RE_EXN_ID: Seed_Types$ReventlessSeed.Failed,
|
|
480
|
+
_1: onTimeout(nodes),
|
|
481
|
+
Error: new Error()
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
await sleep(500);
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
return Stdlib_Option.getOr(result, []);
|
|
209
488
|
}
|
|
210
489
|
|
|
211
490
|
async function waitForIds(t, fieldName, ids, timeoutMsOpt) {
|
|
@@ -240,21 +519,50 @@ async function waitForIds(t, fieldName, ids, timeoutMsOpt) {
|
|
|
240
519
|
return Stdlib_Option.getOr(result, 0);
|
|
241
520
|
}
|
|
242
521
|
|
|
522
|
+
let activeRoleClaim = "activeRole";
|
|
523
|
+
|
|
524
|
+
let attempts = 4;
|
|
525
|
+
|
|
243
526
|
export {
|
|
244
527
|
sleep,
|
|
245
528
|
make,
|
|
246
529
|
currentToken,
|
|
530
|
+
endpoint,
|
|
247
531
|
useToken,
|
|
532
|
+
activeRoleClaim,
|
|
533
|
+
availableRolesClaim,
|
|
534
|
+
groupClaimNames,
|
|
535
|
+
callerIdClaimNames,
|
|
536
|
+
decodeSegment,
|
|
537
|
+
isJoseHeader,
|
|
538
|
+
claims,
|
|
539
|
+
asStrings,
|
|
540
|
+
claimStrings,
|
|
541
|
+
effectiveGroups,
|
|
542
|
+
callerId,
|
|
543
|
+
narrowedFrom,
|
|
544
|
+
identitySummary,
|
|
248
545
|
field,
|
|
249
546
|
asString,
|
|
250
547
|
nodeString,
|
|
251
548
|
login,
|
|
549
|
+
transientErrorTypes,
|
|
550
|
+
isTransient,
|
|
551
|
+
isDenied,
|
|
552
|
+
attempts,
|
|
553
|
+
gqlOutcome,
|
|
252
554
|
gql,
|
|
555
|
+
checkAccess,
|
|
253
556
|
commandResultSelection,
|
|
254
557
|
send,
|
|
558
|
+
deniedCommandCodes,
|
|
559
|
+
isDeniedResult,
|
|
560
|
+
checkCommandAccess,
|
|
561
|
+
checkQueryAccess,
|
|
255
562
|
sendAll,
|
|
256
563
|
queryAllNodes,
|
|
257
564
|
countNodes,
|
|
565
|
+
queryAllNodesUntil,
|
|
258
566
|
waitForIds,
|
|
259
567
|
}
|
|
260
568
|
/* No side effect */
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|