@reventlessdev/reventless-local 3.0.0-alpha.219 → 3.0.0-alpha.221
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/package.json +11 -11
- package/src/LocalPlatformRegistry.res +189 -0
- package/src/LocalPlatformRegistry.res.mjs +162 -0
- package/src/LocalSeedTarget.res +177 -0
- package/src/LocalSeedTarget.res.mjs +172 -0
- package/src/Platform.res +13 -0
- package/src/Platform.res.mjs +11 -0
- package/src/adapter/Auth/Auth_GraphqlContext.res +75 -7
- package/src/adapter/Auth/Auth_GraphqlContext.res.mjs +38 -1
- package/src/adapter/Auth/LocalAuth.res +11 -26
- package/src/adapter/Auth/LocalAuth.res.mjs +5 -8
- package/src/adapter/BackendState.res +15 -0
- package/src/adapter/BackendState.res.mjs +29 -0
- package/src/adapter/PlatformGraphQL_Server.res +9 -4
- package/src/reset/LocalSeedReset.res +38 -16
- package/src/reset/LocalSeedReset.res.mjs +49 -21
- package/tests/LocalPlatformRegistryTest.res +143 -0
- package/tests/LocalPlatformRegistryTest.res.mjs +152 -0
- package/tests/adapter/LocalAuthLoginTest.res +44 -0
- package/tests/adapter/LocalAuthLoginTest.res.mjs +32 -0
- package/tests/adapter/RequireGroupRefusalTest.res +107 -0
- package/tests/adapter/RequireGroupRefusalTest.res.mjs +130 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
4
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
|
+
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
6
|
+
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
7
|
+
import * as Auth_GraphqlContext$ReventlessLocal from "../../src/adapter/Auth/Auth_GraphqlContext.res.mjs";
|
|
8
|
+
|
|
9
|
+
function identity(groups) {
|
|
10
|
+
return {
|
|
11
|
+
userId: "u-1",
|
|
12
|
+
username: "u",
|
|
13
|
+
groups: groups,
|
|
14
|
+
provider: "InMemory"
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function context(groups, authenticated) {
|
|
19
|
+
return {
|
|
20
|
+
identity: identity(groups),
|
|
21
|
+
authenticated: authenticated
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function ok(_root, _args, _ctx) {
|
|
26
|
+
return "ran";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function describeRefusal(e) {
|
|
30
|
+
let js = Stdlib_JsExn.fromException(e);
|
|
31
|
+
if (js === undefined) {
|
|
32
|
+
return [
|
|
33
|
+
"not a JavaScript error",
|
|
34
|
+
""
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
let js$1 = Primitive_option.valFromOption(js);
|
|
38
|
+
return [
|
|
39
|
+
Stdlib_Option.getOr(Stdlib_JsExn.message(js$1), ""),
|
|
40
|
+
js$1.extensions.code
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function refusalOf(groups, authenticated) {
|
|
45
|
+
let guarded = Auth_GraphqlContext$ReventlessLocal.requireGroup("Admin", ok);
|
|
46
|
+
try {
|
|
47
|
+
return {
|
|
48
|
+
TAG: "Ok",
|
|
49
|
+
_0: await guarded(null, null, context(groups, authenticated))
|
|
50
|
+
};
|
|
51
|
+
} catch (raw_e) {
|
|
52
|
+
let e = Primitive_exceptions.internalToException(raw_e);
|
|
53
|
+
return {
|
|
54
|
+
TAG: "Error",
|
|
55
|
+
_0: describeRefusal(e)
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
globalThis.describe("requireGroup", () => {
|
|
61
|
+
globalThis.test("runs the resolver for a caller holding the group", async () => {
|
|
62
|
+
let outcome = await refusalOf(["Admin"], true);
|
|
63
|
+
globalThis.expect(outcome).toEqual({
|
|
64
|
+
TAG: "Ok",
|
|
65
|
+
_0: "ran"
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
globalThis.test("refuses an identified caller without the group as FORBIDDEN", async () => {
|
|
69
|
+
let outcome = await refusalOf(["Shopper"], true);
|
|
70
|
+
globalThis.expect(outcome).toEqual({
|
|
71
|
+
TAG: "Error",
|
|
72
|
+
_0: [
|
|
73
|
+
"Forbidden: requires group \"Admin\"",
|
|
74
|
+
"FORBIDDEN"
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
globalThis.test("refuses a caller it could not identify as UNAUTHORIZED", async () => {
|
|
79
|
+
let outcome = await refusalOf([], false);
|
|
80
|
+
globalThis.expect(outcome).toEqual({
|
|
81
|
+
TAG: "Error",
|
|
82
|
+
_0: [
|
|
83
|
+
"Unauthorized: requires group \"Admin\"",
|
|
84
|
+
"UNAUTHORIZED"
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
globalThis.test("reads a context missing the outcome as unidentified", async () => {
|
|
89
|
+
let guarded = Auth_GraphqlContext$ReventlessLocal.requireGroup("Admin", ok);
|
|
90
|
+
let legacyContext = {
|
|
91
|
+
identity: identity(["Shopper"])
|
|
92
|
+
};
|
|
93
|
+
let code;
|
|
94
|
+
try {
|
|
95
|
+
await guarded(null, null, legacyContext);
|
|
96
|
+
code = "no refusal";
|
|
97
|
+
} catch (raw_e) {
|
|
98
|
+
let e = Primitive_exceptions.internalToException(raw_e);
|
|
99
|
+
code = describeRefusal(e)[1];
|
|
100
|
+
}
|
|
101
|
+
globalThis.expect(code).toBe("UNAUTHORIZED");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
globalThis.describe("isAuthenticated", () => {
|
|
106
|
+
globalThis.test("a verified caller is authenticated", () => {
|
|
107
|
+
globalThis.expect(Auth_GraphqlContext$ReventlessLocal.isAuthenticated({
|
|
108
|
+
TAG: "Authenticated",
|
|
109
|
+
_0: identity([])
|
|
110
|
+
})).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
globalThis.test("a rejected token is not", () => {
|
|
113
|
+
globalThis.expect(Auth_GraphqlContext$ReventlessLocal.isAuthenticated({
|
|
114
|
+
TAG: "AuthError",
|
|
115
|
+
_0: "Invalid bearer token"
|
|
116
|
+
})).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
globalThis.test("nor is an anonymous caller", () => {
|
|
119
|
+
globalThis.expect(Auth_GraphqlContext$ReventlessLocal.isAuthenticated("Anonymous")).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
identity,
|
|
125
|
+
context,
|
|
126
|
+
ok,
|
|
127
|
+
describeRefusal,
|
|
128
|
+
refusalOf,
|
|
129
|
+
}
|
|
130
|
+
/* Not a pure module */
|