@lango-project/lango-server 0.2.4 → 0.2.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/README.md +23 -5
- package/dist/body_reader.mjs.map +1 -1
- package/dist/builder.mjs.map +1 -1
- package/dist/cli/server.mjs +3 -838
- package/dist/cli/server.mjs.map +1 -1
- package/dist/client_identity.mjs.map +1 -1
- package/dist/database.mjs.map +1 -1
- package/dist/database_action.mjs.map +1 -1
- package/dist/database_options.mjs.map +1 -1
- package/dist/database_scope.mjs.map +1 -1
- package/dist/endpoint.mjs.map +1 -1
- package/dist/error_details.mjs.map +1 -1
- package/dist/execution_failure.mjs.map +1 -1
- package/dist/execution_identity.mjs.map +1 -1
- package/dist/execution_log.mjs.map +1 -1
- package/dist/execution_runtime.mjs.map +1 -1
- package/dist/execution_worker.mjs.map +1 -1
- package/dist/executor.mjs.map +1 -1
- package/dist/group.mjs.map +1 -1
- package/dist/http_failure.mjs.map +1 -1
- package/dist/job_configuration.mjs.map +1 -1
- package/dist/job_context.mjs.map +1 -1
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll_broker.mjs.map +1 -1
- package/dist/longpoll_options.mjs.map +1 -1
- package/dist/longpoll_session.mjs.map +1 -1
- package/dist/middleware.mjs.map +1 -1
- package/dist/module_loader.mjs.map +1 -1
- package/dist/options.mjs.map +1 -1
- package/dist/origin.mjs.map +1 -1
- package/dist/policy.mjs.map +1 -1
- package/dist/postgres_adapter.mjs.map +1 -1
- package/dist/postgres_worker.mjs.map +1 -1
- package/dist/queue_provider.mjs.map +1 -1
- package/dist/request_identity.mjs.map +1 -1
- package/dist/response.mjs +1 -1
- package/dist/response.mjs.map +1 -1
- package/dist/route_info.mjs +5 -1
- package/dist/route_info.mjs.map +1 -1
- package/dist/route_pattern.mjs.map +1 -1
- package/dist/routes.mjs +27 -4
- package/dist/routes.mjs.map +1 -1
- package/dist/runtime.mjs +66 -11
- package/dist/runtime.mjs.map +1 -1
- package/dist/server.mjs +2 -1
- package/dist/server.mjs.map +1 -1
- package/dist/server_context.mjs.map +1 -1
- package/dist/sqlite_adapter.mjs.map +1 -1
- package/dist/static_files.mjs.map +1 -1
- package/dist/token.mjs.map +1 -1
- package/dist/tokens.mjs +4 -1
- package/dist/tokens.mjs.map +1 -1
- package/dist/trace.mjs +6 -1
- package/dist/trace.mjs.map +1 -1
- package/dist/worker.mjs.map +1 -1
- package/docs/browser-sessions.md +96 -0
- package/examples/security/package.json +1 -1
- package/package.json +8 -5
- package/src/response.lango +1 -1
- package/src/route_info.lango +5 -2
- package/src/routes.lango +20 -3
- package/src/runtime.lango +56 -11
- package/src/server.lango +3 -2
- package/src/tokens.lango +4 -0
- package/src/trace.lango +5 -2
- package/dist/cli/.lango/bignumber.mjs +0 -3119
- package/dist/cli/.lango/localization.mjs +0 -108
- package/dist/cli/.lango/runtime.mjs +0 -725
- package/dist/cli/.lango/vendor/i18next.LICENSE +0 -21
- package/dist/cli/.lango/vendor/i18next.mjs +0 -2434
- package/dist/cli/.lango/xmldom/conventions.js +0 -429
- package/dist/cli/.lango/xmldom/dom-parser.js +0 -591
- package/dist/cli/.lango/xmldom/dom.js +0 -3759
- package/dist/cli/.lango/xmldom/entities.js +0 -2171
- package/dist/cli/.lango/xmldom/errors.js +0 -205
- package/dist/cli/.lango/xmldom/grammar.js +0 -559
- package/dist/cli/.lango/xmldom/index.js +0 -41
- package/dist/cli/.lango/xmldom/package.json +0 -1
- package/dist/cli/.lango/xmldom/sax.js +0 -983
- package/dist/cli/.lango/xmldom.LICENSE.md +0 -8
- package/dist/cli/body_reader.mjs +0 -180
- package/dist/cli/body_reader.mjs.map +0 -1
- package/dist/cli/client_identity.mjs +0 -250
- package/dist/cli/client_identity.mjs.map +0 -1
- package/dist/cli/database.mjs +0 -116
- package/dist/cli/database.mjs.map +0 -1
- package/dist/cli/database_options.mjs +0 -83
- package/dist/cli/database_options.mjs.map +0 -1
- package/dist/cli/database_scope.mjs +0 -93
- package/dist/cli/database_scope.mjs.map +0 -1
- package/dist/cli/endpoint.mjs +0 -50
- package/dist/cli/endpoint.mjs.map +0 -1
- package/dist/cli/error_details.mjs +0 -45
- package/dist/cli/error_details.mjs.map +0 -1
- package/dist/cli/longpoll_broker.mjs +0 -215
- package/dist/cli/longpoll_broker.mjs.map +0 -1
- package/dist/cli/longpoll_options.mjs +0 -103
- package/dist/cli/longpoll_options.mjs.map +0 -1
- package/dist/cli/longpoll_session.mjs +0 -136
- package/dist/cli/longpoll_session.mjs.map +0 -1
- package/dist/cli/middleware.mjs +0 -25
- package/dist/cli/middleware.mjs.map +0 -1
- package/dist/cli/options.mjs +0 -214
- package/dist/cli/options.mjs.map +0 -1
- package/dist/cli/origin.mjs +0 -87
- package/dist/cli/origin.mjs.map +0 -1
- package/dist/cli/policy.mjs +0 -121
- package/dist/cli/policy.mjs.map +0 -1
- package/dist/cli/postgres_adapter.mjs +0 -178
- package/dist/cli/postgres_adapter.mjs.map +0 -1
- package/dist/cli/route_pattern.mjs +0 -129
- package/dist/cli/route_pattern.mjs.map +0 -1
- package/dist/cli/routes.mjs +0 -360
- package/dist/cli/routes.mjs.map +0 -1
- package/dist/cli/sqlite_adapter.mjs +0 -163
- package/dist/cli/sqlite_adapter.mjs.map +0 -1
- package/dist/cli/static_files.mjs +0 -224
- package/dist/cli/static_files.mjs.map +0 -1
- package/dist/cli/trace.mjs +0 -53
- package/dist/cli/trace.mjs.map +0 -1
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
hostGlobalCall as __hostGlobalCall,
|
|
4
|
-
bindContexts as __bindContexts,
|
|
5
|
-
fromJson as __fromJson,
|
|
6
|
-
toJson as __toJson,
|
|
7
|
-
isNumber as __isNumber,
|
|
8
|
-
isString as __isString,
|
|
9
|
-
isBool as __isBool,
|
|
10
|
-
isObject as __isObject,
|
|
11
|
-
isArray as __isArray,
|
|
12
|
-
requireBoolean as __requireBoolean,
|
|
13
|
-
normalize as __normalize,
|
|
14
|
-
finite as __finite,
|
|
15
|
-
numericAdd as __numericAdd,
|
|
16
|
-
call as __call,
|
|
17
|
-
boundary as __boundary,
|
|
18
|
-
requireArity as __requireArity,
|
|
19
|
-
withArity as __withArity,
|
|
20
|
-
} from "./.lango/runtime.mjs";
|
|
21
|
-
|
|
22
|
-
export class LongpollSession {
|
|
23
|
-
#broker;
|
|
24
|
-
#route;
|
|
25
|
-
#authorize;
|
|
26
|
-
#body;
|
|
27
|
-
#cancelled;
|
|
28
|
-
#timer;
|
|
29
|
-
#sleep;
|
|
30
|
-
#token;
|
|
31
|
-
#deadline;
|
|
32
|
-
#input;
|
|
33
|
-
#cursor;
|
|
34
|
-
constructor(broker, route, authorize, body) {
|
|
35
|
-
__requireArity(arguments.length, [0, 1, 2, 3], "constructor");
|
|
36
|
-
broker = __boundary(broker);
|
|
37
|
-
route = __boundary(route);
|
|
38
|
-
authorize = __boundary(authorize);
|
|
39
|
-
body = __boundary(body);
|
|
40
|
-
this.#broker = broker;
|
|
41
|
-
this.#route = route;
|
|
42
|
-
this.#authorize = authorize;
|
|
43
|
-
this.#body = body;
|
|
44
|
-
this.#cancelled = false;
|
|
45
|
-
this.#timer = null;
|
|
46
|
-
this.#sleep = null;
|
|
47
|
-
this.#token = null;
|
|
48
|
-
this.#deadline = 0;
|
|
49
|
-
this.#input = null;
|
|
50
|
-
this.#cursor = null;
|
|
51
|
-
}
|
|
52
|
-
cancel() {
|
|
53
|
-
this.#cancelled = true;
|
|
54
|
-
__hostGlobalCall(["clearTimeout"], __normalize(this.#timer));
|
|
55
|
-
if (__requireBoolean(__normalize(this.#sleep) !== null)) {
|
|
56
|
-
__normalize(this.#sleep.resolve(null));
|
|
57
|
-
}
|
|
58
|
-
return null;
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
run() {
|
|
62
|
-
try {
|
|
63
|
-
this.#input = __fromJson(__normalize(this.#body));
|
|
64
|
-
let input = __normalize(this.#input);
|
|
65
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(input))) || __requireBoolean(__isArray(input))) || __requireBoolean(!__requireBoolean(__isString(__normalize(input.key))))) || __requireBoolean(__normalize(input.key) === "")) || __requireBoolean(__normalize(__hostGlobal(["Buffer"]).byteLength(__normalize(input.key))) > 1024))) {
|
|
66
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(failure(400, "InvalidLongpollInput")));
|
|
67
|
-
}
|
|
68
|
-
if (__requireBoolean(__requireBoolean(__normalize(input.cursor) !== null) && __requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(input.cursor)))) || __requireBoolean(input.cursor.length > 512)))) {
|
|
69
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(failure(400, "InvalidLongpollInput")));
|
|
70
|
-
}
|
|
71
|
-
this.#cursor = __normalize(input.cursor);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(failure(400, "InvalidJson")));
|
|
74
|
-
}
|
|
75
|
-
let auth = __normalize(this.#authorize);
|
|
76
|
-
return __call(auth, null, null).then(__withArity(__bindContexts((result) => {
|
|
77
|
-
result = __boundary(result);
|
|
78
|
-
if (__requireBoolean(__normalize(result.status) !== 200)) {
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
this.#token = __normalize(result.authorization);
|
|
82
|
-
this.#deadline = __numericAdd(__normalize(__hostGlobal(["Date"]).now()), __normalize(this.#route.waitTimeoutMs));
|
|
83
|
-
return this.#poll();
|
|
84
|
-
return null;
|
|
85
|
-
}), [0], "closure")).catch(__withArity(__bindContexts((error) => {
|
|
86
|
-
error = __boundary(error);
|
|
87
|
-
return failure(503, "LongpollUnavailable");
|
|
88
|
-
return null;
|
|
89
|
-
}), [0], "closure")).finally(__bindContexts(() => {
|
|
90
|
-
this.cancel();
|
|
91
|
-
return null;
|
|
92
|
-
}));
|
|
93
|
-
return null;
|
|
94
|
-
}
|
|
95
|
-
#poll() {
|
|
96
|
-
if (__requireBoolean(__normalize(this.#cancelled))) {
|
|
97
|
-
return __normalize(__hostGlobal(["Promise"]).resolve(failure(503, "Unavailable")));
|
|
98
|
-
}
|
|
99
|
-
return __normalize(this.#broker.read(__normalize(this.#route.path), __normalize(this.#input.key), __normalize(this.#cursor))).then(__withArity(__bindContexts((batch) => {
|
|
100
|
-
batch = __boundary(batch);
|
|
101
|
-
if (__requireBoolean(__normalize(this.#cancelled))) {
|
|
102
|
-
return failure(503, "Unavailable");
|
|
103
|
-
}
|
|
104
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(batch.resyncRequired)) || __requireBoolean(batch.messages.length > 0)) || __requireBoolean(__normalize(__hostGlobal(["Date"]).now()) >= __normalize(this.#deadline)))) {
|
|
105
|
-
if (__requireBoolean(__normalize(batch.resyncRequired))) {
|
|
106
|
-
batch.fallback = __normalize(this.#route.fallback);
|
|
107
|
-
}
|
|
108
|
-
let auth = __normalize(this.#authorize);
|
|
109
|
-
return __call(auth, __normalize(this.#token), batch);
|
|
110
|
-
}
|
|
111
|
-
this.#cursor = __normalize(batch.cursor);
|
|
112
|
-
this.#sleep = __normalize(__hostGlobal(["Promise"]).withResolvers());
|
|
113
|
-
let sleep = __normalize(this.#sleep);
|
|
114
|
-
let wake = __bindContexts(() => {
|
|
115
|
-
__normalize(sleep.resolve(null));
|
|
116
|
-
return null;
|
|
117
|
-
});
|
|
118
|
-
this.#timer = __hostGlobalCall(["setTimeout"], wake, __normalize(__hostGlobal(["Math"]).min(250, __normalize(__hostGlobal(["Math"]).max(1, __finite(__normalize(this.#deadline) - __normalize(__hostGlobal(["Date"]).now())))))));
|
|
119
|
-
return __normalize(sleep.promise).then(__withArity(__bindContexts((ignored) => {
|
|
120
|
-
ignored = __boundary(ignored);
|
|
121
|
-
return this.#poll();
|
|
122
|
-
return null;
|
|
123
|
-
}), [0], "closure"));
|
|
124
|
-
return null;
|
|
125
|
-
}), [0], "closure"));
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function failure(status, code) {
|
|
130
|
-
__requireArity(arguments.length, [0, 1], "failure");
|
|
131
|
-
status = __boundary(status);
|
|
132
|
-
code = __boundary(code);
|
|
133
|
-
return { status: status, headers: { "content-type": "application/json; charset=utf-8", "cache-control": "no-store" }, body: __toJson({ error: code }) };
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=longpoll_session.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"longpoll_session.mjs","sources":["longpoll_session.lango"],"sourcesContent":["import js global Promise\nimport js global Buffer\nimport js global Date\nimport js global Math\nimport js global setTimeout\nimport js global clearTimeout\n\nexport class LongpollSession(broker, route, authorize, body)\n methods\n run()\n cancel()\n\nLongpollSession(broker, route, authorize, body)\n @broker = broker\n @route = route\n @authorize = authorize\n @body = body\n @cancelled = false\n @timer = null\n @sleep = null\n @token = null\n @deadline = 0\n @input = null\n @cursor = null\n\nLongpollSession:cancel()\n @cancelled = true\n clearTimeout(@timer)\n if @sleep != null\n @sleep.resolve(null)\n return null\n\nLongpollSession:run()\n try\n @input = from_json(@body)\n input = @input\n if !is_object(input) or is_array(input) or !is_string(input.key) or input.key == \"\" or Buffer/byteLength(input.key) > 1024\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n if input.cursor != null and (!is_string(input.cursor) or input.cursor.length > 512)\n return Promise/resolve(failure(400, \"InvalidLongpollInput\"))\n @cursor = input.cursor\n catch error\n return Promise/resolve(failure(400, \"InvalidJson\"))\n auth = @authorize\n return chain auth(null, null)\n then(result)\n if result.status != 200\n return result\n @token = result.authorization\n @deadline = Date/now() + @route.waitTimeoutMs\n return poll()\n catch(error)\n return failure(503, \"LongpollUnavailable\")\n finally\n cancel()\n\nLongpollSession:poll()\n if @cancelled\n return Promise/resolve(failure(503, \"Unavailable\"))\n return chain @broker.read(@route.path, @input.key, @cursor)\n then(batch)\n if @cancelled\n return failure(503, \"Unavailable\")\n if batch.resyncRequired or batch.messages.length > 0 or Date/now() >= @deadline\n if batch.resyncRequired\n batch.fallback = @route.fallback\n auth = @authorize\n return auth(@token, batch)\n @cursor = batch.cursor\n @sleep = Promise/withResolvers()\n sleep = @sleep\n wake = ()\n capture sleep\n sleep.resolve(null)\n @timer = setTimeout(wake, Math/min(250, Math/max(1, @deadline - Date/now())))\n return chain sleep.promise\n then(ignored)\n return poll()\n\nfailure(status, code)\n return {\n status: status\n headers: {\n \"content-type\": \"application/json; charset=utf-8\"\n \"cache-control\": \"no-store\"\n }\n body: to_json({\n error: code\n })\n }\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA;;;;;;;;"}
|
package/dist/cli/middleware.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
isNumber as __isNumber,
|
|
4
|
-
isString as __isString,
|
|
5
|
-
isBool as __isBool,
|
|
6
|
-
isObject as __isObject,
|
|
7
|
-
isArray as __isArray,
|
|
8
|
-
requireBoolean as __requireBoolean,
|
|
9
|
-
normalize as __normalize,
|
|
10
|
-
boundary as __boundary,
|
|
11
|
-
requireArity as __requireArity,
|
|
12
|
-
} from "./.lango/runtime.mjs";
|
|
13
|
-
|
|
14
|
-
export function middlewareName(name) {
|
|
15
|
-
__requireArity(arguments.length, [0], "middlewareName");
|
|
16
|
-
name = __boundary(name);
|
|
17
|
-
let reserved = ["routes", "endpoint", "longpoll", "job", "group", "include", "event", "middleware"];
|
|
18
|
-
let pattern = new (__hostGlobal(["RegExp"]))("^[A-Za-z_][A-Za-z0-9_-]*$");
|
|
19
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(!__requireBoolean(__normalize(pattern.test(name))))) || __requireBoolean(__normalize(reserved.includes(name))))) {
|
|
20
|
-
throw `Invalid or reserved middleware name: ${name}`;
|
|
21
|
-
}
|
|
22
|
-
return name;
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=middleware.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.mjs","sources":["middleware.lango"],"sourcesContent":["import js global RegExp\n\nexport middlewareName(name)\n\nmiddlewareName(name)\n reserved = [\"routes\", \"endpoint\", \"longpoll\", \"job\", \"group\", \"include\", \"event\", \"middleware\"]\n pattern = new RegExp(\"^[A-Za-z_][A-Za-z0-9_-]*$\")\n if !is_string(name) or !pattern.test(name) or reserved.includes(name)\n throw \"Invalid or reserved middleware name: ${name}\"\n return name\n"],"names":[],"mappings":";;;;;;;;;;;;;AAIA;;;;;;;;;;;;"}
|
package/dist/cli/options.mjs
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import { policyRegistry } from "./policy.mjs";
|
|
2
|
-
import { clientOptions } from "./client_identity.mjs";
|
|
3
|
-
import { originOptions } from "./origin.mjs";
|
|
4
|
-
import { redisOptions } from "./longpoll_options.mjs";
|
|
5
|
-
import { databaseOptions } from "./database_options.mjs";
|
|
6
|
-
import { staticOptions } from "./static_files.mjs";
|
|
7
|
-
import * as fs from "node:fs";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import {
|
|
10
|
-
hostGlobal as __hostGlobal,
|
|
11
|
-
hostGlobalCall as __hostGlobalCall,
|
|
12
|
-
xml2obj as __xml2obj,
|
|
13
|
-
fromJson as __fromJson,
|
|
14
|
-
toJson as __toJson,
|
|
15
|
-
isNumber as __isNumber,
|
|
16
|
-
isString as __isString,
|
|
17
|
-
isBool as __isBool,
|
|
18
|
-
isObject as __isObject,
|
|
19
|
-
isArray as __isArray,
|
|
20
|
-
entries as __entries,
|
|
21
|
-
requireBoolean as __requireBoolean,
|
|
22
|
-
normalize as __normalize,
|
|
23
|
-
boundary as __boundary,
|
|
24
|
-
requireArity as __requireArity,
|
|
25
|
-
} from "./.lango/runtime.mjs";
|
|
26
|
-
|
|
27
|
-
export function attributes(tag, allowed) {
|
|
28
|
-
__requireArity(arguments.length, [0, 1], "attributes");
|
|
29
|
-
tag = __boundary(tag);
|
|
30
|
-
allowed = __boundary(allowed);
|
|
31
|
-
for (const [key, value] of __entries(__normalize(tag.attributes()))) {
|
|
32
|
-
if (__requireBoolean(!__requireBoolean(__normalize(allowed.includes(key))))) {
|
|
33
|
-
throw `Unknown ${__normalize(tag.tag())} attribute: ${key}`;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return null;
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function options(root, supplied = null) {
|
|
41
|
-
__requireArity(arguments.length, [0], "options");
|
|
42
|
-
root = __boundary(root);
|
|
43
|
-
supplied = __boundary(supplied);
|
|
44
|
-
let result = { root: __normalize(path.resolve(root)), host: "127.0.0.1", port: 3000, workers: 2, maxQueue: 64, bodyLimit: 2097152, bodyTimeoutMs: 30000, requestTimeoutMs: 30000, eventTimeoutMs: 5000, startupTimeoutMs: 30000, shutdownTimeoutMs: 30000, issuer: "lango-server", audience: "lango-client", ttlSeconds: 900, key: null, keys: { }, activeKeyId: "current", requestEvent: false, database: null, redis: null, static: null, origin: null, client: null, policies: null };
|
|
45
|
-
if (__requireBoolean(supplied !== null)) {
|
|
46
|
-
for (const [key, value] of __entries(supplied)) {
|
|
47
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, key)))) || __requireBoolean(key === "root"))) {
|
|
48
|
-
throw `Unknown server option: ${key}`;
|
|
49
|
-
}
|
|
50
|
-
result[key] = value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(result.host)))) || __requireBoolean(__normalize(result.host) === ""))) {
|
|
54
|
-
throw "Host must be a nonempty string";
|
|
55
|
-
}
|
|
56
|
-
for (const key of ["port", "workers", "maxQueue", "bodyLimit", "bodyTimeoutMs", "requestTimeoutMs", "eventTimeoutMs", "startupTimeoutMs", "shutdownTimeoutMs", "ttlSeconds"]) {
|
|
57
|
-
let value = __normalize(result[key]);
|
|
58
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isNumber(value))) || __requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(value))))) || __requireBoolean(value < 0))) {
|
|
59
|
-
throw `Invalid server option: ${key}`;
|
|
60
|
-
}
|
|
61
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(key !== "port") && __requireBoolean(key !== "maxQueue")) && __requireBoolean(value === 0))) {
|
|
62
|
-
throw `Server option must be positive: ${key}`;
|
|
63
|
-
}
|
|
64
|
-
if (__requireBoolean(__requireBoolean(__normalize(key.endsWith("Ms"))) && __requireBoolean(value > 2147483647))) {
|
|
65
|
-
throw `Timeout exceeds timer limit: ${key}`;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(result.port) > 65535) || __requireBoolean(__normalize(result.workers) > 128)) || __requireBoolean(__normalize(result.ttlSeconds) > 86400))) {
|
|
69
|
-
throw "Server option exceeds supported limit";
|
|
70
|
-
}
|
|
71
|
-
if (__requireBoolean(!__requireBoolean(__isBool(__normalize(result.requestEvent))))) {
|
|
72
|
-
throw "requestEvent must be boolean";
|
|
73
|
-
}
|
|
74
|
-
for (const key of ["issuer", "audience", "activeKeyId"]) {
|
|
75
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(result[key])))) || __requireBoolean(__normalize(result[key]) === ""))) {
|
|
76
|
-
throw `Missing JWT option: ${key}`;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(__normalize(result.keys)))) || __requireBoolean(__isArray(__normalize(result.keys))))) {
|
|
80
|
-
throw "JWT keys must be a map";
|
|
81
|
-
}
|
|
82
|
-
let keys = __normalize(__hostGlobal(["Object"]).assign(__normalize(__hostGlobal(["Object"]).create(null)), __normalize(result.keys)));
|
|
83
|
-
if (__requireBoolean(__normalize(result.key) !== null)) {
|
|
84
|
-
keys[__normalize(result.activeKeyId)] = __normalize(result.key);
|
|
85
|
-
}
|
|
86
|
-
if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(keys, __normalize(result.activeKeyId)))))) {
|
|
87
|
-
throw "JWT signing key is required";
|
|
88
|
-
}
|
|
89
|
-
for (const [id, secret] of __entries(keys)) {
|
|
90
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(secret))) || __requireBoolean(__normalize(secret.length) < 32))) {
|
|
91
|
-
throw "JWT keys must contain at least 32 characters";
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
result.keys = keys;
|
|
95
|
-
result.key = null;
|
|
96
|
-
result.policies = policyRegistry(__normalize(result.policies));
|
|
97
|
-
result.database = databaseOptions(__normalize(result.root), __normalize(result.database), __normalize(result.workers));
|
|
98
|
-
result.redis = redisOptions(__normalize(result.redis));
|
|
99
|
-
result.static = staticOptions(__normalize(result.root), __normalize(result.static));
|
|
100
|
-
result.origin = originOptions(__normalize(result.origin));
|
|
101
|
-
result.client = clientOptions(__normalize(result.client), __normalize(result.database), __normalize(result.origin));
|
|
102
|
-
return result;
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function deployment(directory) {
|
|
107
|
-
__requireArity(arguments.length, [0], "deployment");
|
|
108
|
-
directory = __boundary(directory);
|
|
109
|
-
return options(directory, readDeployment(directory));
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function readDeployment(directory, credentials = true) {
|
|
114
|
-
__requireArity(arguments.length, [0], "readDeployment");
|
|
115
|
-
directory = __boundary(directory);
|
|
116
|
-
credentials = __boundary(credentials);
|
|
117
|
-
let file = __normalize(path.join(directory, "deploy.xml"));
|
|
118
|
-
let root = __xml2obj(__normalize(fs.readFileSync(file, "utf8")));
|
|
119
|
-
if (__requireBoolean(__normalize(root.tag()) !== "deploy")) {
|
|
120
|
-
throw "Expected deploy root";
|
|
121
|
-
}
|
|
122
|
-
attributes(root, []);
|
|
123
|
-
let settings = { };
|
|
124
|
-
let seen = [];
|
|
125
|
-
for (const tag of __normalize(root.children())) {
|
|
126
|
-
let name = __normalize(tag.tag());
|
|
127
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(seen.includes(name))) || __requireBoolean(__requireBoolean(name !== "policies") && __requireBoolean(__normalize(__normalize(tag.children()).length) !== 0))) || __requireBoolean(__normalize(__normalize(tag.innerText()).trim()) !== ""))) {
|
|
128
|
-
throw `Duplicate or nonempty deployment section: ${name}`;
|
|
129
|
-
}
|
|
130
|
-
seen.push(name);
|
|
131
|
-
if (name === "policies") {
|
|
132
|
-
attributes(tag, ["reauthSeconds"]);
|
|
133
|
-
let items = [];
|
|
134
|
-
for (const child of __normalize(tag.children())) {
|
|
135
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(child.tag()) !== "policy") || __requireBoolean(__normalize(__normalize(child.children()).length) !== 0)) || __requireBoolean(__normalize(__normalize(child.innerText()).trim()) !== ""))) {
|
|
136
|
-
throw "Policies may contain only empty policy elements";
|
|
137
|
-
}
|
|
138
|
-
attributes(child, ["name", "reauthSeconds"]);
|
|
139
|
-
items.push(__normalize(child.attributes()));
|
|
140
|
-
}
|
|
141
|
-
settings.policies = { reauthSeconds: __normalize(tag.reauthSeconds), items: items };
|
|
142
|
-
continue;
|
|
143
|
-
} else if (name === "client") {
|
|
144
|
-
attributes(tag, ["maxAgeSeconds"]);
|
|
145
|
-
settings.client = __normalize(tag.attributes());
|
|
146
|
-
continue;
|
|
147
|
-
} else if (name === "origin") {
|
|
148
|
-
attributes(tag, ["url", "urlEnv", "required"]);
|
|
149
|
-
settings.origin = __normalize(tag.attributes());
|
|
150
|
-
continue;
|
|
151
|
-
} else if (name === "static") {
|
|
152
|
-
attributes(tag, ["path", "directory", "index", "fallback", "runtime"]);
|
|
153
|
-
settings.static = __normalize(tag.attributes());
|
|
154
|
-
continue;
|
|
155
|
-
} else if (name === "http") {
|
|
156
|
-
attributes(tag, ["host", "port", "bodyLimit", "bodyTimeoutMs"]);
|
|
157
|
-
} else if (name === "workers") {
|
|
158
|
-
attributes(tag, ["workers", "maxQueue", "requestTimeoutMs", "startupTimeoutMs", "shutdownTimeoutMs"]);
|
|
159
|
-
} else if (name === "events") {
|
|
160
|
-
attributes(tag, ["requestEvent", "eventTimeoutMs"]);
|
|
161
|
-
} else if (name === "redis") {
|
|
162
|
-
attributes(tag, ["connectionEnv", "namespace", "maxPendingPolls"]);
|
|
163
|
-
settings.redis = __normalize(tag.attributes());
|
|
164
|
-
continue;
|
|
165
|
-
} else if (name === "database") {
|
|
166
|
-
attributes(tag, ["type", "file", "connectionEnv", "busyTimeoutMs", "queryTimeoutMs", "connectTimeoutSeconds"]);
|
|
167
|
-
settings.database = __normalize(tag.attributes());
|
|
168
|
-
continue;
|
|
169
|
-
} else if (name === "jwt") {
|
|
170
|
-
attributes(tag, ["issuer", "audience", "ttlSeconds", "keyEnv", "keysFile", "activeKeyId"]);
|
|
171
|
-
if (__requireBoolean(!__requireBoolean(credentials))) {
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
throw `Unknown deployment section: ${name}`;
|
|
176
|
-
}
|
|
177
|
-
for (const [key, value] of __entries(__normalize(tag.attributes()))) {
|
|
178
|
-
if (__requireBoolean(key === "keyEnv")) {
|
|
179
|
-
settings.key = __normalize(__hostGlobal(["process"]).env[value]);
|
|
180
|
-
if (__requireBoolean(__normalize(settings.key) === null)) {
|
|
181
|
-
throw `JWT key environment variable is missing: ${value}`;
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
if (__requireBoolean(key === "keysFile")) {
|
|
185
|
-
settings.keys = __fromJson(__normalize(fs.readFileSync(__normalize(path.resolve(directory, value)), "utf8")));
|
|
186
|
-
} else {
|
|
187
|
-
if (__requireBoolean(contains(["host", "issuer", "audience", "activeKeyId"], key))) {
|
|
188
|
-
settings[key] = value;
|
|
189
|
-
} else {
|
|
190
|
-
if (__requireBoolean(key === "requestEvent")) {
|
|
191
|
-
if (__requireBoolean(__requireBoolean(value !== "true") && __requireBoolean(value !== "false"))) {
|
|
192
|
-
throw "requestEvent must be true or false";
|
|
193
|
-
}
|
|
194
|
-
settings[key] = value === "true";
|
|
195
|
-
} else {
|
|
196
|
-
settings[key] = __hostGlobalCall(["Number"], value);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return settings;
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export function contains(items, value) {
|
|
208
|
-
__requireArity(arguments.length, [0, 1], "contains");
|
|
209
|
-
items = __boundary(items);
|
|
210
|
-
value = __boundary(value);
|
|
211
|
-
return __normalize(items.includes(value));
|
|
212
|
-
return null;
|
|
213
|
-
}
|
|
214
|
-
//# sourceMappingURL=options.mjs.map
|
package/dist/cli/options.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","sources":["options.lango"],"sourcesContent":["import \"./policy\"\n policyRegistry(spec)\nimport \"./client_identity\"\n clientOptions(spec, database, origin)\nimport \"./origin\"\n originOptions(spec)\nimport \"./longpoll_options\"\n redisOptions(spec)\nimport \"./database_options\"\n databaseOptions(root, spec, workers)\nimport \"./static_files\"\n staticOptions(root, spec)\nimport js \"node:fs\" as fs\nimport js \"node:path\" as path\nimport js global Object\nimport js global Number\nimport js global process\n\nexport contains(items, value)\nexport options(root, supplied = null)\nexport deployment(directory)\nexport attributes(tag, allowed)\nexport readDeployment(directory, credentials = true)\n\nattributes(tag, allowed)\n for tag.attributes() as key: value\n if !allowed.includes(key)\n throw \"Unknown ${tag.tag()} attribute: ${key}\"\n return null\n\noptions(root, supplied = null)\n result = {\n root: path/resolve(root)\n host: \"127.0.0.1\"\n port: 3000\n workers: 2\n maxQueue: 64\n bodyLimit: 2097152\n bodyTimeoutMs: 30000\n requestTimeoutMs: 30000\n eventTimeoutMs: 5000\n startupTimeoutMs: 30000\n shutdownTimeoutMs: 30000\n issuer: \"lango-server\"\n audience: \"lango-client\"\n ttlSeconds: 900\n key: null\n keys: {}\n activeKeyId: \"current\"\n requestEvent: false\n database: null\n redis: null\n static: null\n origin: null\n client: null\n policies: null\n }\n if supplied != null\n for supplied as key: value\n if !Object/hasOwn(result, key) or key == \"root\"\n throw \"Unknown server option: ${key}\"\n result[key] = value\n if !is_string(result.host) or result.host == \"\"\n throw \"Host must be a nonempty string\"\n for [\"port\", \"workers\", \"maxQueue\", \"bodyLimit\", \"bodyTimeoutMs\", \"requestTimeoutMs\", \"eventTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\", \"ttlSeconds\"] as key\n value = result[key]\n if !is_number(value) or !Number/isSafeInteger(value) or value < 0\n throw \"Invalid server option: ${key}\"\n if key != \"port\" and key != \"maxQueue\" and value == 0\n throw \"Server option must be positive: ${key}\"\n if key.endsWith(\"Ms\") and value > 2147483647\n throw \"Timeout exceeds timer limit: ${key}\"\n if result.port > 65535 or result.workers > 128 or result.ttlSeconds > 86400\n throw \"Server option exceeds supported limit\"\n if !is_bool(result.requestEvent)\n throw \"requestEvent must be boolean\"\n for [\"issuer\", \"audience\", \"activeKeyId\"] as key\n if !is_string(result[key]) or result[key] == \"\"\n throw \"Missing JWT option: ${key}\"\n if !is_object(result.keys) or is_array(result.keys)\n throw \"JWT keys must be a map\"\n keys = Object/assign(Object/create(null), result.keys)\n if result.key != null\n keys[result.activeKeyId] = result.key\n if !Object/hasOwn(keys, result.activeKeyId)\n throw \"JWT signing key is required\"\n for keys as id: secret\n if !is_string(secret) or secret.length < 32\n throw \"JWT keys must contain at least 32 characters\"\n result.keys = keys\n result.key = null\n result.policies = policyRegistry(result.policies)\n result.database = databaseOptions(result.root, result.database, result.workers)\n result.redis = redisOptions(result.redis)\n result.static = staticOptions(result.root, result.static)\n result.origin = originOptions(result.origin)\n result.client = clientOptions(result.client, result.database, result.origin)\n return result\n\ndeployment(directory)\n return options(directory, readDeployment(directory))\n\nreadDeployment(directory, credentials = true)\n file = path/join(directory, \"deploy.xml\")\n root = xml2obj(fs/readFileSync(file, \"utf8\"))\n if root.tag() != \"deploy\"\n throw \"Expected deploy root\"\n attributes(root, [])\n settings = {}\n seen = []\n for root.children() as tag\n name = tag.tag()\n if seen.includes(name) or (name != \"policies\" and tag.children().length != 0) or tag.innerText().trim() != \"\"\n throw \"Duplicate or nonempty deployment section: ${name}\"\n seen.add(name)\n switch name\n case \"policies\"\n attributes(tag, [\"reauthSeconds\"])\n items = []\n for tag.children() as child\n if child.tag() != \"policy\" or child.children().length != 0 or child.innerText().trim() != \"\"\n throw \"Policies may contain only empty policy elements\"\n attributes(child, [\"name\", \"reauthSeconds\"])\n items.add(child.attributes())\n settings.policies = {\n reauthSeconds: tag.reauthSeconds\n items: items\n }\n continue\n case \"client\"\n attributes(tag, [\"maxAgeSeconds\"])\n settings.client = tag.attributes()\n continue\n case \"origin\"\n attributes(tag, [\"url\", \"urlEnv\", \"required\"])\n settings.origin = tag.attributes()\n continue\n case \"static\"\n attributes(tag, [\"path\", \"directory\", \"index\", \"fallback\", \"runtime\"])\n settings.static = tag.attributes()\n continue\n case \"http\"\n attributes(tag, [\"host\", \"port\", \"bodyLimit\", \"bodyTimeoutMs\"])\n case \"workers\"\n attributes(tag, [\"workers\", \"maxQueue\", \"requestTimeoutMs\", \"startupTimeoutMs\", \"shutdownTimeoutMs\"])\n case \"events\"\n attributes(tag, [\"requestEvent\", \"eventTimeoutMs\"])\n case \"redis\"\n attributes(tag, [\"connectionEnv\", \"namespace\", \"maxPendingPolls\"])\n settings.redis = tag.attributes()\n continue\n case \"database\"\n attributes(tag, [\"type\", \"file\", \"connectionEnv\", \"busyTimeoutMs\", \"queryTimeoutMs\", \"connectTimeoutSeconds\"])\n settings.database = tag.attributes()\n continue\n case \"jwt\"\n attributes(tag, [\"issuer\", \"audience\", \"ttlSeconds\", \"keyEnv\", \"keysFile\", \"activeKeyId\"])\n if !credentials\n continue\n else\n throw \"Unknown deployment section: ${name}\"\n for tag.attributes() as key: value\n if key == \"keyEnv\"\n settings.key = process.env[value]\n if settings.key == null\n throw \"JWT key environment variable is missing: ${value}\"\n else\n if key == \"keysFile\"\n settings.keys = from_json(fs/readFileSync(path/resolve(directory, value), \"utf8\"))\n else\n if contains([\"host\", \"issuer\", \"audience\", \"activeKeyId\"], key)\n settings[key] = value\n else\n if key == \"requestEvent\"\n if value != \"true\" and value != \"false\"\n throw \"requestEvent must be true or false\"\n settings[key] = value == \"true\"\n else\n settings[key] = Number(value)\n return settings\n\ncontains(items, value)\n return items.includes(value)\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA;;;;;;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+EA;;;;;;;;"}
|
package/dist/cli/origin.mjs
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
isNumber as __isNumber,
|
|
4
|
-
isString as __isString,
|
|
5
|
-
isBool as __isBool,
|
|
6
|
-
isObject as __isObject,
|
|
7
|
-
isArray as __isArray,
|
|
8
|
-
requireBoolean as __requireBoolean,
|
|
9
|
-
normalize as __normalize,
|
|
10
|
-
boundary as __boundary,
|
|
11
|
-
requireArity as __requireArity,
|
|
12
|
-
} from "./.lango/runtime.mjs";
|
|
13
|
-
|
|
14
|
-
export function originOptions(spec) {
|
|
15
|
-
__requireArity(arguments.length, [0], "originOptions");
|
|
16
|
-
spec = __boundary(spec);
|
|
17
|
-
let envName;
|
|
18
|
-
if (__requireBoolean(spec === null)) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
22
|
-
throw "Origin configuration must be an object";
|
|
23
|
-
}
|
|
24
|
-
for (const name of __normalize(__hostGlobal(["Object"]).keys(spec))) {
|
|
25
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(name !== "url") && __requireBoolean(name !== "urlEnv")) && __requireBoolean(name !== "required"))) {
|
|
26
|
-
throw `Unknown origin option: ${name}`;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (__requireBoolean(__requireBoolean(__normalize(spec.url) !== null) && __requireBoolean(__normalize(spec.urlEnv) !== null))) {
|
|
30
|
-
throw "Origin requires either url or urlEnv, not both";
|
|
31
|
-
}
|
|
32
|
-
let url = __normalize(spec.url);
|
|
33
|
-
if (__requireBoolean(__normalize(spec.urlEnv) !== null)) {
|
|
34
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(__normalize(spec.urlEnv)))) || __requireBoolean(__normalize(spec.urlEnv) === ""))) {
|
|
35
|
-
throw "Origin urlEnv must name an environment variable";
|
|
36
|
-
}
|
|
37
|
-
envName = __normalize(spec.urlEnv);
|
|
38
|
-
url = __normalize(__hostGlobal(["process"]).env[envName]);
|
|
39
|
-
}
|
|
40
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(url))) || __requireBoolean(url === ""))) {
|
|
41
|
-
throw "Origin URL is required";
|
|
42
|
-
}
|
|
43
|
-
let parsed = null;
|
|
44
|
-
try {
|
|
45
|
-
parsed = new (__hostGlobal(["URL"]))(url);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw "Origin requires an exact HTTP or HTTPS origin";
|
|
48
|
-
}
|
|
49
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(parsed.protocol) !== "https:") && __requireBoolean(__normalize(parsed.protocol) !== "http:")) || __requireBoolean(__normalize(parsed.origin) !== url))) {
|
|
50
|
-
throw "Origin requires an exact HTTP or HTTPS origin without credentials, path, query or fragment";
|
|
51
|
-
}
|
|
52
|
-
let required = __normalize(spec.required);
|
|
53
|
-
if (__requireBoolean(__requireBoolean(required === null) || __requireBoolean(required === "true"))) {
|
|
54
|
-
required = true;
|
|
55
|
-
}
|
|
56
|
-
if (__requireBoolean(required === "false")) {
|
|
57
|
-
required = false;
|
|
58
|
-
}
|
|
59
|
-
if (__requireBoolean(!__requireBoolean(__isBool(required)))) {
|
|
60
|
-
throw "Origin required must be true or false";
|
|
61
|
-
}
|
|
62
|
-
return { url: url, required: required };
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function originAllowed(spec, request) {
|
|
67
|
-
__requireArity(arguments.length, [0, 1], "originAllowed");
|
|
68
|
-
spec = __boundary(spec);
|
|
69
|
-
request = __boundary(request);
|
|
70
|
-
if (__requireBoolean(spec === null)) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
let headers = __normalize(request.headers);
|
|
74
|
-
let value = __normalize(headers.origin);
|
|
75
|
-
if (__requireBoolean(value === null)) {
|
|
76
|
-
if (__requireBoolean(__normalize(spec.required))) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (__requireBoolean(__requireBoolean(value !== null) && __requireBoolean(value !== __normalize(spec.url)))) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
let site = __normalize(headers["sec-fetch-site"]);
|
|
84
|
-
return __requireBoolean(__requireBoolean(site === null) || __requireBoolean(site === "same-origin")) || __requireBoolean(site === "none");
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=origin.mjs.map
|
package/dist/cli/origin.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"origin.mjs","sources":["origin.lango"],"sourcesContent":["import js global Object\nimport js global URL\nimport js global process\n\nexport originOptions(spec)\nexport originAllowed(spec, request)\n\noriginOptions(spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Origin configuration must be an object\"\n for Object/keys(spec) as name\n if name != \"url\" and name != \"urlEnv\" and name != \"required\"\n throw \"Unknown origin option: ${name}\"\n if spec.url != null and spec.urlEnv != null\n throw \"Origin requires either url or urlEnv, not both\"\n url = spec.url\n if spec.urlEnv != null\n if !is_string(spec.urlEnv) or spec.urlEnv == \"\"\n throw \"Origin urlEnv must name an environment variable\"\n envName = spec.urlEnv\n url = process.env[envName]\n if !is_string(url) or url == \"\"\n throw \"Origin URL is required\"\n parsed = null\n try\n parsed = new URL(url)\n catch error\n throw \"Origin requires an exact HTTP or HTTPS origin\"\n if (parsed.protocol != \"https:\" and parsed.protocol != \"http:\") or parsed.origin != url\n throw \"Origin requires an exact HTTP or HTTPS origin without credentials, path, query or fragment\"\n required = spec.required\n if required == null or required == \"true\"\n required = true\n if required == \"false\"\n required = false\n if !is_bool(required)\n throw \"Origin required must be true or false\"\n return {\n url: url\n required: required\n }\n\noriginAllowed(spec, request)\n if spec == null\n return true\n headers = request.headers\n value = headers.origin\n if value == null\n if spec.required\n return false\n if value != null and value != spec.url\n return false\n site = headers[\"sec-fetch-site\"]\n return site == null or site == \"same-origin\" or site == \"none\"\n"],"names":[],"mappings":";;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCA;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/cli/policy.mjs
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
hostGlobalCall as __hostGlobalCall,
|
|
4
|
-
isNumber as __isNumber,
|
|
5
|
-
isString as __isString,
|
|
6
|
-
isBool as __isBool,
|
|
7
|
-
isObject as __isObject,
|
|
8
|
-
isArray as __isArray,
|
|
9
|
-
entries as __entries,
|
|
10
|
-
requireBoolean as __requireBoolean,
|
|
11
|
-
normalize as __normalize,
|
|
12
|
-
boundary as __boundary,
|
|
13
|
-
requireArity as __requireArity,
|
|
14
|
-
} from "./.lango/runtime.mjs";
|
|
15
|
-
|
|
16
|
-
export function policyOptions(spec) {
|
|
17
|
-
__requireArity(arguments.length, [0], "policyOptions");
|
|
18
|
-
spec = __boundary(spec);
|
|
19
|
-
let name = __normalize(spec.policy);
|
|
20
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(name !== null) && __requireBoolean(__normalize(spec.auth) !== null)) && __requireBoolean(name !== __normalize(spec.auth)))) {
|
|
21
|
-
throw "Endpoint policy and legacy auth cannot disagree";
|
|
22
|
-
}
|
|
23
|
-
let legacy = name === null;
|
|
24
|
-
if (__requireBoolean(name === null)) {
|
|
25
|
-
name = __normalize(spec.auth);
|
|
26
|
-
}
|
|
27
|
-
if (__requireBoolean(name === null)) {
|
|
28
|
-
name = "login";
|
|
29
|
-
}
|
|
30
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(__normalize(name.trim()) === "")) || __requireBoolean(__normalize(name.includes(","))))) {
|
|
31
|
-
throw "Endpoint policy must name one permission";
|
|
32
|
-
}
|
|
33
|
-
let seconds = __normalize(spec.reauthSeconds);
|
|
34
|
-
if (__requireBoolean(seconds === null)) {
|
|
35
|
-
seconds = 0;
|
|
36
|
-
}
|
|
37
|
-
if (__requireBoolean(__isString(seconds))) {
|
|
38
|
-
if (__requireBoolean(__normalize(seconds.trim()) === "")) {
|
|
39
|
-
throw "reauthSeconds cannot be empty";
|
|
40
|
-
}
|
|
41
|
-
seconds = __hostGlobalCall(["Number"], seconds);
|
|
42
|
-
}
|
|
43
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Number"]).isSafeInteger(seconds)))) || __requireBoolean(seconds < 0)) || __requireBoolean(seconds > 31536000))) {
|
|
44
|
-
throw "reauthSeconds must be an integer between 0 and 31536000";
|
|
45
|
-
}
|
|
46
|
-
if (__requireBoolean(__requireBoolean(seconds > 0) && __requireBoolean(name === "anonymous"))) {
|
|
47
|
-
throw "Anonymous policy cannot require password freshness";
|
|
48
|
-
}
|
|
49
|
-
return { name: name, reauthSeconds: seconds, explicit: __normalize(spec.reauthSeconds) !== null, legacy: legacy };
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function policyRegistry(spec) {
|
|
54
|
-
__requireArity(arguments.length, [0], "policyRegistry");
|
|
55
|
-
spec = __boundary(spec);
|
|
56
|
-
if (__requireBoolean(spec === null)) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(spec))) || __requireBoolean(__isArray(spec)))) {
|
|
60
|
-
throw "Policies must be a map";
|
|
61
|
-
}
|
|
62
|
-
for (const [key, value] of __entries(spec)) {
|
|
63
|
-
if (__requireBoolean(__requireBoolean(key !== "reauthSeconds") && __requireBoolean(key !== "items"))) {
|
|
64
|
-
throw `Unknown policies option: ${key}`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
let base = policyOptions({ policy: "login", reauthSeconds: __normalize(spec.reauthSeconds) });
|
|
68
|
-
let items = __normalize(spec.items);
|
|
69
|
-
if (__requireBoolean(!__requireBoolean(__isArray(items)))) {
|
|
70
|
-
throw "Policies require an items array";
|
|
71
|
-
}
|
|
72
|
-
let result = __normalize(__hostGlobal(["Object"]).create(null));
|
|
73
|
-
for (const item of items) {
|
|
74
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(item))) || __requireBoolean(__isArray(item)))) {
|
|
75
|
-
throw "Policy must be a map";
|
|
76
|
-
}
|
|
77
|
-
for (const [key, value] of __entries(item)) {
|
|
78
|
-
if (__requireBoolean(__requireBoolean(key !== "name") && __requireBoolean(key !== "reauthSeconds"))) {
|
|
79
|
-
throw `Unknown policy option: ${key}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let name = __normalize(item.name);
|
|
83
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(name))) || __requireBoolean(__normalize(name.trim()) !== name)) || __requireBoolean(name === "")) || __requireBoolean(name === "anonymous")) || __requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(result, name))))) {
|
|
84
|
-
throw "Invalid or duplicate policy name";
|
|
85
|
-
}
|
|
86
|
-
let seconds = __normalize(item.reauthSeconds);
|
|
87
|
-
if (__requireBoolean(seconds === null)) {
|
|
88
|
-
seconds = __normalize(base.reauthSeconds);
|
|
89
|
-
}
|
|
90
|
-
let selected = policyOptions({ policy: name, reauthSeconds: seconds });
|
|
91
|
-
result[name] = __normalize(selected.reauthSeconds);
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function resolvePolicies(routes, registry) {
|
|
98
|
-
__requireArity(arguments.length, [0, 1], "resolvePolicies");
|
|
99
|
-
routes = __boundary(routes);
|
|
100
|
-
registry = __boundary(registry);
|
|
101
|
-
if (__requireBoolean(registry === null)) {
|
|
102
|
-
return routes;
|
|
103
|
-
}
|
|
104
|
-
for (const route of routes) {
|
|
105
|
-
if (__requireBoolean(__normalize(route.policy) !== "anonymous")) {
|
|
106
|
-
if (__requireBoolean(!__requireBoolean(__normalize(__hostGlobal(["Object"]).hasOwn(registry, __normalize(route.policy)))))) {
|
|
107
|
-
throw `Undefined route policy: ${__normalize(route.policy)}`;
|
|
108
|
-
}
|
|
109
|
-
let maximum = __normalize(registry[__normalize(route.policy)]);
|
|
110
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__normalize(route.reauthExplicit)) && __requireBoolean(maximum > 0)) && __requireBoolean(__requireBoolean(__normalize(route.reauthSeconds) === 0) || __requireBoolean(__normalize(route.reauthSeconds) > maximum)))) {
|
|
111
|
-
throw `Route cannot weaken policy freshness: ${__normalize(route.path)}`;
|
|
112
|
-
}
|
|
113
|
-
if (__requireBoolean(!__requireBoolean(__normalize(route.reauthExplicit)))) {
|
|
114
|
-
route.reauthSeconds = maximum;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return routes;
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=policy.mjs.map
|
package/dist/cli/policy.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy.mjs","sources":["policy.lango"],"sourcesContent":["import js global Number\nimport js global Object\n\nexport policyOptions(spec)\nexport policyRegistry(spec)\nexport resolvePolicies(routes, registry)\n\npolicyOptions(spec)\n name = spec.policy\n if name != null and spec.auth != null and name != spec.auth\n throw \"Endpoint policy and legacy auth cannot disagree\"\n legacy = name == null\n if name == null\n name = spec.auth\n if name == null\n name = \"login\"\n if !is_string(name) or name.trim() == \"\" or name.includes(\",\")\n throw \"Endpoint policy must name one permission\"\n seconds = spec.reauthSeconds\n if seconds == null\n seconds = 0\n if is_string(seconds)\n if seconds.trim() == \"\"\n throw \"reauthSeconds cannot be empty\"\n seconds = Number(seconds)\n if !Number/isSafeInteger(seconds) or seconds < 0 or seconds > 31536000\n throw \"reauthSeconds must be an integer between 0 and 31536000\"\n if seconds > 0 and name == \"anonymous\"\n throw \"Anonymous policy cannot require password freshness\"\n return {\n name: name\n reauthSeconds: seconds\n explicit: spec.reauthSeconds != null\n legacy: legacy\n }\n\npolicyRegistry(spec)\n if spec == null\n return null\n if !is_object(spec) or is_array(spec)\n throw \"Policies must be a map\"\n for spec as key: value\n if key != \"reauthSeconds\" and key != \"items\"\n throw \"Unknown policies option: ${key}\"\n base = policyOptions({\n policy: \"login\"\n reauthSeconds: spec.reauthSeconds\n })\n items = spec.items\n if !is_array(items)\n throw \"Policies require an items array\"\n result = Object/create(null)\n for items as item\n if !is_object(item) or is_array(item)\n throw \"Policy must be a map\"\n for item as key: value\n if key != \"name\" and key != \"reauthSeconds\"\n throw \"Unknown policy option: ${key}\"\n name = item.name\n if !is_string(name) or name.trim() != name or name == \"\" or name == \"anonymous\" or Object/hasOwn(result, name)\n throw \"Invalid or duplicate policy name\"\n seconds = item.reauthSeconds\n if seconds == null\n seconds = base.reauthSeconds\n selected = policyOptions({\n policy: name\n reauthSeconds: seconds\n })\n result[name] = selected.reauthSeconds\n return result\n\nresolvePolicies(routes, registry)\n if registry == null\n return routes\n for routes as route\n if route.policy != \"anonymous\"\n if !Object/hasOwn(registry, route.policy)\n throw \"Undefined route policy: ${route.policy}\"\n maximum = registry[route.policy]\n if route.reauthExplicit and maximum > 0 and (route.reauthSeconds == 0 or route.reauthSeconds > maximum)\n throw \"Route cannot weaken policy freshness: ${route.path}\"\n if !route.reauthExplicit\n route.reauthSeconds = maximum\n return routes\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;;;;;;;;;;;;;;;;;;;"}
|