@lango-project/lango-client 0.2.1 → 0.4.0
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/LICENSE +1 -0
- package/NOTICE +5 -1
- package/README.md +570 -906
- package/cli/.lango/localization.mjs +108 -0
- package/{dist/node → cli}/.lango/runtime.mjs +112 -19
- package/cli/.lango/vendor/i18next.LICENSE +21 -0
- package/cli/.lango/vendor/i18next.mjs +2434 -0
- package/cli/create.mjs +62 -0
- package/cli/create.mjs.map +1 -0
- package/dist/.lango/localization.mjs +108 -0
- package/dist/.lango/runtime.mjs +112 -19
- package/dist/.lango/vendor/i18next.LICENSE +21 -0
- package/dist/.lango/vendor/i18next.mjs +2434 -0
- package/dist/accordion.mjs +277 -0
- package/dist/accordion.mjs.map +1 -0
- package/dist/activities.mjs +185 -0
- package/dist/activities.mjs.map +1 -0
- package/dist/app.mjs +636 -0
- package/dist/app.mjs.map +1 -0
- package/dist/boot.mjs +24 -0
- package/dist/boot.mjs.map +1 -0
- package/dist/bootstrap-LICENSE +21 -0
- package/dist/bootstrap.min.css +6 -0
- package/dist/bootstrap.min.css.map +1 -0
- package/dist/button.mjs +77 -0
- package/dist/button.mjs.map +1 -0
- package/dist/chip.mjs +134 -0
- package/dist/chip.mjs.map +1 -0
- package/dist/client.css +95 -0
- package/dist/collections.mjs +77 -0
- package/dist/collections.mjs.map +1 -0
- package/dist/combo_box.mjs +408 -0
- package/dist/combo_box.mjs.map +1 -0
- package/dist/content.mjs +123 -0
- package/dist/content.mjs.map +1 -0
- package/dist/control.mjs +139 -0
- package/dist/control.mjs.map +1 -0
- package/dist/date_input.mjs +242 -0
- package/dist/date_input.mjs.map +1 -0
- package/dist/error_reporter.mjs +136 -0
- package/dist/error_reporter.mjs.map +1 -0
- package/dist/fields.mjs +454 -0
- package/dist/fields.mjs.map +1 -0
- package/dist/file_input.mjs +227 -0
- package/dist/file_input.mjs.map +1 -0
- package/dist/form.mjs +272 -0
- package/dist/form.mjs.map +1 -0
- package/dist/heartbeat.mjs +167 -254
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/index.html +18 -0
- package/dist/indicators.mjs +127 -0
- package/dist/indicators.mjs.map +1 -0
- package/dist/input_changes.mjs +58 -0
- package/dist/input_changes.mjs.map +1 -0
- package/dist/input_group.mjs +38 -0
- package/dist/input_group.mjs.map +1 -0
- package/dist/layouts.mjs +195 -0
- package/dist/layouts.mjs.map +1 -0
- package/dist/library.mjs +130 -807
- package/dist/library.mjs.map +1 -1
- package/dist/longpoll.mjs +254 -0
- package/dist/longpoll.mjs.map +1 -0
- package/dist/main.mjs +138 -0
- package/dist/main.mjs.map +1 -0
- package/dist/markdown.mjs +61 -0
- package/dist/markdown.mjs.map +1 -0
- package/dist/menus.mjs +468 -0
- package/dist/menus.mjs.map +1 -0
- package/dist/navigation.mjs +260 -410
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +181 -0
- package/dist/numeric_input.mjs.map +1 -0
- package/dist/otp_input.mjs +113 -0
- package/dist/otp_input.mjs.map +1 -0
- package/dist/presentations.mjs +852 -0
- package/dist/presentations.mjs.map +1 -0
- package/dist/renderer.mjs +293 -0
- package/dist/renderer.mjs.map +1 -0
- package/dist/rich_content.mjs +99 -0
- package/dist/rich_content.mjs.map +1 -0
- package/dist/tables.mjs +369 -0
- package/dist/tables.mjs.map +1 -0
- package/dist/tabs.mjs +205 -0
- package/dist/tabs.mjs.map +1 -0
- package/dist/templates.mjs +46 -0
- package/dist/templates.mjs.map +1 -0
- package/dist/vendor/DOMPurify-LICENSE +202 -0
- package/dist/vendor/dompurify.mjs +2540 -0
- package/dist/vendor/flatpickr-LICENSE.md +21 -0
- package/dist/vendor/flatpickr.min.css +13 -0
- package/dist/vendor/flatpickr.mjs +2340 -0
- package/dist/vendor/flatpickr.mjs.map +7 -0
- package/dist/vendor/marked-LICENSE.md +44 -0
- package/dist/vendor/marked.esm.js.map +7 -0
- package/dist/vendor/marked.mjs +85 -0
- package/dist/vendor/purify.es.mjs.map +1 -0
- package/dist/widgets.mjs +197 -0
- package/dist/widgets.mjs.map +1 -0
- package/docs/implementation.md +42 -0
- package/package.json +25 -43
- package/src/accordion.lango +198 -0
- package/src/activities.lango +132 -0
- package/src/app.lango +508 -0
- package/src/boot.lango +12 -0
- package/src/button.lango +49 -0
- package/src/chip.lango +94 -0
- package/src/collections.lango +46 -0
- package/src/combo_box.lango +298 -0
- package/src/content.lango +75 -0
- package/src/control.lango +100 -0
- package/src/create.lango +42 -0
- package/src/date_input.lango +215 -0
- package/src/error_reporter.lango +95 -0
- package/src/fields.lango +327 -0
- package/src/file_input.lango +175 -0
- package/src/form.lango +195 -0
- package/src/heartbeat.lango +136 -199
- package/src/indicators.lango +94 -0
- package/src/input_changes.lango +33 -0
- package/src/input_group.lango +22 -0
- package/src/layouts.lango +137 -0
- package/src/library.lango +194 -599
- package/src/longpoll.lango +187 -0
- package/src/main.lango +109 -0
- package/src/markdown.lango +48 -0
- package/src/menus.lango +336 -0
- package/src/navigation.lango +209 -299
- package/src/numeric_input.lango +131 -0
- package/src/otp_input.lango +83 -0
- package/src/presentations.lango +617 -0
- package/src/renderer.lango +288 -0
- package/src/rich_content.lango +66 -0
- package/src/tables.lango +271 -0
- package/src/tabs.lango +144 -0
- package/src/templates.lango +29 -0
- package/src/widgets.lango +141 -0
- package/web/client.css +95 -0
- package/web/index.html +18 -0
- package/dist/application.mjs +0 -429
- package/dist/application.mjs.map +0 -1
- package/dist/coordinator.mjs +0 -91
- package/dist/coordinator.mjs.map +0 -1
- package/dist/demo.mjs +0 -110
- package/dist/demo.mjs.map +0 -1
- package/dist/demo_controls.mjs +0 -59
- package/dist/demo_controls.mjs.map +0 -1
- package/dist/errors.mjs +0 -201
- package/dist/errors.mjs.map +0 -1
- package/dist/form_state.mjs +0 -266
- package/dist/form_state.mjs.map +0 -1
- package/dist/inheritance.mjs +0 -240
- package/dist/inheritance.mjs.map +0 -1
- package/dist/input_values.mjs +0 -65
- package/dist/input_values.mjs.map +0 -1
- package/dist/node/.lango/xmldom/conventions.js +0 -429
- package/dist/node/.lango/xmldom/dom-parser.js +0 -591
- package/dist/node/.lango/xmldom/dom.js +0 -3759
- package/dist/node/.lango/xmldom/entities.js +0 -2171
- package/dist/node/.lango/xmldom/errors.js +0 -205
- package/dist/node/.lango/xmldom/grammar.js +0 -559
- package/dist/node/.lango/xmldom/index.js +0 -41
- package/dist/node/.lango/xmldom/package.json +0 -1
- package/dist/node/.lango/xmldom/sax.js +0 -983
- package/dist/node/.lango/xmldom.LICENSE.md +0 -8
- package/dist/node/browser_host.mjs +0 -351
- package/dist/node/browser_host.mjs.map +0 -1
- package/dist/node/create_app.mjs +0 -118
- package/dist/node/create_app.mjs.map +0 -1
- package/dist/presentation.mjs +0 -89
- package/dist/presentation.mjs.map +0 -1
- package/dist/protocol.mjs +0 -706
- package/dist/protocol.mjs.map +0 -1
- package/dist/session.mjs +0 -471
- package/dist/session.mjs.map +0 -1
- package/dist/tokens.mjs +0 -298
- package/dist/tokens.mjs.map +0 -1
- package/examples/contacts.lango +0 -293
- package/examples/contacts_flow.lango +0 -174
- package/examples/contacts_store.lango +0 -109
- package/examples/contacts_store_test.lango +0 -65
- package/examples/demo.css +0 -87
- package/examples/demo_test.lango +0 -356
- package/examples/index.html +0 -32
- package/examples/pages.lango +0 -174
- package/examples/server.lango +0 -189
- package/examples/worker.lango +0 -142
- package/src/application.lango +0 -327
- package/src/browser_host.lango +0 -276
- package/src/coordinator.lango +0 -57
- package/src/demo.lango +0 -110
- package/src/demo_controls.lango +0 -53
- package/src/errors.lango +0 -149
- package/src/errors_test.lango +0 -157
- package/src/form_state.lango +0 -168
- package/src/heartbeat_test.lango +0 -479
- package/src/inheritance.lango +0 -167
- package/src/input_values.lango +0 -37
- package/src/logout_test.lango +0 -564
- package/src/navigation_test.lango +0 -556
- package/src/presentation.lango +0 -55
- package/src/protocol.lango +0 -787
- package/src/renderer_test.lango +0 -2047
- package/src/session.lango +0 -343
- package/src/session_test.lango +0 -455
- package/src/tabs_test.lango +0 -216
- package/src/tokens.lango +0 -215
- package/template/.vscode/extensions.json +0 -3
- package/template/.vscode/settings.json +0 -9
- package/template/README.md +0 -44
- package/template/gitignore +0 -4
- package/template/package.json +0 -22
- package/template/public/app.css +0 -10
- package/template/public/index.html +0 -24
- package/template/src/client.lango +0 -78
- package/template/src/pages.lango +0 -55
- package/template/src/server.lango +0 -24
- package/template/src/worker.lango +0 -77
- package/template/test/app.lango +0 -9
- package/tools/browser_runner.lango +0 -32
- package/tools/browser_test.lango +0 -343
- package/tools/create_app.lango +0 -88
- package/tools/create_app_test.lango +0 -43
- package/tools/starter_test.lango +0 -227
- /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
- /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
- /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
- /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
- /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
- /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
- /package/{dist → cli}/.lango/xmldom/index.js +0 -0
- /package/{dist → cli}/.lango/xmldom/package.json +0 -0
- /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
- /package/{dist → cli}/.lango/xmldom.LICENSE.md +0 -0
package/dist/tokens.mjs
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hostGlobal as __hostGlobal,
|
|
3
|
-
hostGlobalCall as __hostGlobalCall,
|
|
4
|
-
contextGet as __contextGet,
|
|
5
|
-
contextSet as __contextSet,
|
|
6
|
-
contextRestore as __contextRestore,
|
|
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
|
-
numericAdd as __numericAdd,
|
|
15
|
-
boundary as __boundary,
|
|
16
|
-
requireArity as __requireArity,
|
|
17
|
-
withArity as __withArity,
|
|
18
|
-
} from "./.lango/runtime.mjs";
|
|
19
|
-
|
|
20
|
-
export class TokenStore {
|
|
21
|
-
#storage;
|
|
22
|
-
#key;
|
|
23
|
-
#latest;
|
|
24
|
-
#ready;
|
|
25
|
-
#initializing;
|
|
26
|
-
#generation;
|
|
27
|
-
constructor(storage = null, key = "lango:last-token") {
|
|
28
|
-
storage = __boundary(storage);
|
|
29
|
-
key = __boundary(key);
|
|
30
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isString(key))) || __requireBoolean(key === ""))) {
|
|
31
|
-
throw "UiTokenStorageKeyRequired";
|
|
32
|
-
}
|
|
33
|
-
this.#storage = storage;
|
|
34
|
-
this.#key = key;
|
|
35
|
-
this.#latest = null;
|
|
36
|
-
this.#ready = __normalize(__hostGlobal(["Promise"]).resolve());
|
|
37
|
-
this.#initializing = false;
|
|
38
|
-
this.#generation = 0;
|
|
39
|
-
if (__requireBoolean(storage !== null)) {
|
|
40
|
-
try {
|
|
41
|
-
let token = __normalize(storage.getItem(key));
|
|
42
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__isString(token)) && __requireBoolean(token !== "")) && __requireBoolean(__normalize(token.length) <= 16384))) {
|
|
43
|
-
this.#latest = token;
|
|
44
|
-
}
|
|
45
|
-
} catch (error) {
|
|
46
|
-
storageUnavailable();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
latest() {
|
|
51
|
-
return __normalize(this.#latest);
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
ready() {
|
|
55
|
-
return __normalize(this.#ready);
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
initializing() {
|
|
59
|
-
return __normalize(this.#initializing);
|
|
60
|
-
return null;
|
|
61
|
-
}
|
|
62
|
-
current(generation) {
|
|
63
|
-
__requireArity(arguments.length, [0], "current");
|
|
64
|
-
generation = __boundary(generation);
|
|
65
|
-
return generation === __normalize(this.#generation);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
initialized(token, generation) {
|
|
69
|
-
__requireArity(arguments.length, [0, 1], "initialized");
|
|
70
|
-
token = __boundary(token);
|
|
71
|
-
generation = __boundary(generation);
|
|
72
|
-
if (__requireBoolean(!__requireBoolean(this.current(generation)))) {
|
|
73
|
-
throw "UiTokenOperationSuperseded";
|
|
74
|
-
}
|
|
75
|
-
if (__requireBoolean(token !== null)) {
|
|
76
|
-
this.save(token);
|
|
77
|
-
}
|
|
78
|
-
this.#initializing = false;
|
|
79
|
-
return token;
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
cancelInitialization() {
|
|
83
|
-
this.#generation = __numericAdd(__normalize(this.#generation), 1);
|
|
84
|
-
this.#initializing = false;
|
|
85
|
-
this.#ready = __normalize(__hostGlobal(["Promise"]).resolve(__normalize(this.#latest)));
|
|
86
|
-
return null;
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
clear() {
|
|
90
|
-
let previous = __normalize(this.#latest);
|
|
91
|
-
this.cancelInitialization();
|
|
92
|
-
this.#latest = null;
|
|
93
|
-
this.#ready = __normalize(__hostGlobal(["Promise"]).resolve());
|
|
94
|
-
if (__requireBoolean(__normalize(this.#storage) !== null)) {
|
|
95
|
-
try {
|
|
96
|
-
let persisted = __normalize(this.#storage.getItem(__normalize(this.#key)));
|
|
97
|
-
if (__requireBoolean(__requireBoolean(previous !== null) && __requireBoolean(persisted === previous))) {
|
|
98
|
-
__normalize(this.#storage.removeItem(__normalize(this.#key)));
|
|
99
|
-
}
|
|
100
|
-
} catch (error) {
|
|
101
|
-
storageUnavailable();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return null;
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
initialize(path, previousToken = null) {
|
|
108
|
-
__requireArity(arguments.length, [0], "initialize");
|
|
109
|
-
path = __boundary(path);
|
|
110
|
-
previousToken = __boundary(previousToken);
|
|
111
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(path))) || __requireBoolean(!__requireBoolean(__normalize(path.startsWith("/"))))) || __requireBoolean(__normalize(path.startsWith("//")))) || __requireBoolean(__normalize(path.includes("\\"))))) {
|
|
112
|
-
throw "UiTokenBootstrapRequiresSameOriginPath";
|
|
113
|
-
}
|
|
114
|
-
this.cancelInitialization();
|
|
115
|
-
let generation = __normalize(this.#generation);
|
|
116
|
-
let headers = { "Content-Type": "application/json" };
|
|
117
|
-
previousToken = this.bootstrapSeed(previousToken);
|
|
118
|
-
if (__requireBoolean(previousToken !== null)) {
|
|
119
|
-
headers.Authorization = `Bearer ${previousToken}`;
|
|
120
|
-
}
|
|
121
|
-
this.#initializing = true;
|
|
122
|
-
let pending = __normalize(__hostGlobal(["fetch"])(path, { method: "POST", headers: headers, body: "{}", cache: "no-store", redirect: "error" }).then(__withArity((response) => {
|
|
123
|
-
response = __boundary(response);
|
|
124
|
-
return initializedToken(this, response, generation);
|
|
125
|
-
return null;
|
|
126
|
-
}, [0], "closure")));
|
|
127
|
-
this.#ready = pending;
|
|
128
|
-
pending.catch(__withArity((error) => {
|
|
129
|
-
error = __boundary(error);
|
|
130
|
-
bootstrapFailed(this, generation);
|
|
131
|
-
return null;
|
|
132
|
-
}, [0], "closure"));
|
|
133
|
-
return pending;
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
bootstrapSeed(previousToken) {
|
|
137
|
-
__requireArity(arguments.length, [0], "bootstrapSeed");
|
|
138
|
-
previousToken = __boundary(previousToken);
|
|
139
|
-
if (__requireBoolean(previousToken !== null)) {
|
|
140
|
-
return previousToken;
|
|
141
|
-
}
|
|
142
|
-
if (__requireBoolean(__normalize(this.#storage) !== null)) {
|
|
143
|
-
try {
|
|
144
|
-
let persisted = __normalize(this.#storage.getItem(__normalize(this.#key)));
|
|
145
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__isString(persisted)) && __requireBoolean(persisted !== "")) && __requireBoolean(__normalize(persisted.length) <= 16384))) {
|
|
146
|
-
return persisted;
|
|
147
|
-
}
|
|
148
|
-
} catch (error) {
|
|
149
|
-
storageUnavailable();
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return __normalize(this.#latest);
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
logout(path) {
|
|
156
|
-
__requireArity(arguments.length, [0], "logout");
|
|
157
|
-
path = __boundary(path);
|
|
158
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(path))) || __requireBoolean(!__requireBoolean(__normalize(path.startsWith("/"))))) || __requireBoolean(__normalize(path.startsWith("//")))) || __requireBoolean(__normalize(path.includes("\\"))))) {
|
|
159
|
-
throw "UiLogoutRequiresSameOriginPath";
|
|
160
|
-
}
|
|
161
|
-
let generation = __normalize(this.#generation);
|
|
162
|
-
let waiting = __normalize(this.#ready);
|
|
163
|
-
let ready = __normalize(waiting.catch(__withArity((error) => {
|
|
164
|
-
error = __boundary(error);
|
|
165
|
-
return null;
|
|
166
|
-
return null;
|
|
167
|
-
}, [0], "closure")));
|
|
168
|
-
return ready.then(() => {
|
|
169
|
-
return this.logoutReady(path, generation);
|
|
170
|
-
return null;
|
|
171
|
-
});
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
logoutReady(path, generation) {
|
|
175
|
-
__requireArity(arguments.length, [0, 1], "logoutReady");
|
|
176
|
-
path = __boundary(path);
|
|
177
|
-
generation = __boundary(generation);
|
|
178
|
-
if (__requireBoolean(!__requireBoolean(this.current(generation)))) {
|
|
179
|
-
throw "UiTokenOperationSuperseded";
|
|
180
|
-
}
|
|
181
|
-
let previous = __normalize(this.#latest);
|
|
182
|
-
if (__requireBoolean(previous === null)) {
|
|
183
|
-
throw "UiLogoutTokenRequired";
|
|
184
|
-
}
|
|
185
|
-
return __hostGlobalCall(["fetch"], path, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${previous}` }, body: "{}", cache: "no-store", redirect: "error" }).then(__withArity((response) => {
|
|
186
|
-
response = __boundary(response);
|
|
187
|
-
return readLogout(this, response, previous, generation);
|
|
188
|
-
return null;
|
|
189
|
-
}, [0], "closure"));
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
loggedOut(previousToken, generation) {
|
|
193
|
-
__requireArity(arguments.length, [0, 1], "loggedOut");
|
|
194
|
-
previousToken = __boundary(previousToken);
|
|
195
|
-
generation = __boundary(generation);
|
|
196
|
-
if (__requireBoolean(!__requireBoolean(this.current(generation)))) {
|
|
197
|
-
throw "UiTokenOperationSuperseded";
|
|
198
|
-
}
|
|
199
|
-
this.clear();
|
|
200
|
-
return previousToken;
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
save(token) {
|
|
204
|
-
__requireArity(arguments.length, [0], "save");
|
|
205
|
-
token = __boundary(token);
|
|
206
|
-
if (__requireBoolean(__requireBoolean(__requireBoolean(!__requireBoolean(__isString(token))) || __requireBoolean(token === "")) || __requireBoolean(__normalize(token.length) > 16384))) {
|
|
207
|
-
throw "UiInvalidToken";
|
|
208
|
-
}
|
|
209
|
-
this.#latest = token;
|
|
210
|
-
if (__requireBoolean(__normalize(this.#storage) !== null)) {
|
|
211
|
-
try {
|
|
212
|
-
__normalize(this.#storage.setItem(__normalize(this.#key), token));
|
|
213
|
-
} catch (error) {
|
|
214
|
-
storageUnavailable();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return null;
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
function initializedToken(store, response, generation) {
|
|
222
|
-
__requireArity(arguments.length, [0, 1, 2], "initializedToken");
|
|
223
|
-
store = __boundary(store);
|
|
224
|
-
response = __boundary(response);
|
|
225
|
-
generation = __boundary(generation);
|
|
226
|
-
let token = __normalize(response.headers.get("X-Lango-Token"));
|
|
227
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__normalize(response.ok))) || __requireBoolean(token === null))) {
|
|
228
|
-
throw "UiTokenBootstrapFailed";
|
|
229
|
-
}
|
|
230
|
-
return __normalize(response.json()).then(__withArity((body) => {
|
|
231
|
-
body = __boundary(body);
|
|
232
|
-
return __normalize(store.initialized(token, generation));
|
|
233
|
-
return null;
|
|
234
|
-
}, [0], "closure"));
|
|
235
|
-
return null;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function bootstrapFailed(store, generation) {
|
|
239
|
-
const __contextScope = [];
|
|
240
|
-
try {
|
|
241
|
-
__requireArity(arguments.length, [0, 1], "bootstrapFailed");
|
|
242
|
-
store = __boundary(store);
|
|
243
|
-
generation = __boundary(generation);
|
|
244
|
-
if (__requireBoolean(!__requireBoolean(__normalize(store.current(generation))))) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
__normalize(__contextGet("log").err("Token bootstrap failed"));
|
|
248
|
-
__normalize(store.initialized(null, generation));
|
|
249
|
-
return null;
|
|
250
|
-
return null;
|
|
251
|
-
} finally {
|
|
252
|
-
__contextRestore(__contextScope);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function readLogout(store, response, previous, generation) {
|
|
257
|
-
__requireArity(arguments.length, [0, 1, 2, 3], "readLogout");
|
|
258
|
-
store = __boundary(store);
|
|
259
|
-
response = __boundary(response);
|
|
260
|
-
previous = __boundary(previous);
|
|
261
|
-
generation = __boundary(generation);
|
|
262
|
-
if (__requireBoolean(!__requireBoolean(__normalize(response.ok)))) {
|
|
263
|
-
throw `UiLogoutHttpError: ${__normalize(response.status)}`;
|
|
264
|
-
}
|
|
265
|
-
return __normalize(response.json()).then(__withArity((body) => {
|
|
266
|
-
body = __boundary(body);
|
|
267
|
-
if (__requireBoolean(__requireBoolean(!__requireBoolean(__isObject(body))) || __requireBoolean(__normalize(body.loggedOut) !== true))) {
|
|
268
|
-
throw "UiInvalidLogoutResponse";
|
|
269
|
-
}
|
|
270
|
-
return __normalize(store.loggedOut(previous, generation));
|
|
271
|
-
return null;
|
|
272
|
-
}, [0], "closure"));
|
|
273
|
-
return null;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
export function browserTokenStore(key = "lango:last-token") {
|
|
277
|
-
key = __boundary(key);
|
|
278
|
-
let storage = null;
|
|
279
|
-
try {
|
|
280
|
-
storage = __normalize(__hostGlobal(["localStorage"]));
|
|
281
|
-
} catch (error) {
|
|
282
|
-
storageUnavailable();
|
|
283
|
-
}
|
|
284
|
-
return new TokenStore(storage, key);
|
|
285
|
-
return null;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function storageUnavailable() {
|
|
289
|
-
const __contextScope = [];
|
|
290
|
-
try {
|
|
291
|
-
__normalize(__contextGet("log").warn("Token persistence is unavailable; this session continues in memory"));
|
|
292
|
-
return null;
|
|
293
|
-
return null;
|
|
294
|
-
} finally {
|
|
295
|
-
__contextRestore(__contextScope);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
//# sourceMappingURL=tokens.mjs.map
|
package/dist/tokens.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.mjs","sources":["tokens.lango"],"sourcesContent":["import js global Promise\nimport js global localStorage\nimport js global fetch\nexport browserTokenStore(key = \"lango:last-token\")\n\n\nexport class TokenStore\n methods\n latest()\n save(token)\n initialize(path, previousToken = null)\n ready()\n initializing()\n initialized(token, generation)\n current(generation)\n cancelInitialization()\n clear()\n logout(path)\n logoutReady(path, generation)\n loggedOut(previousToken, generation)\n bootstrapSeed(previousToken)\n\nTokenStore(storage = null, key = \"lango:last-token\")\n if !is_string(key) or key == \"\"\n throw \"UiTokenStorageKeyRequired\"\n @storage = storage\n @key = key\n @latest = null\n @ready = Promise/resolve()\n @initializing = false\n @generation = 0\n if storage != null\n try\n token = storage.getItem(key)\n if is_string(token) and token != \"\" and token.length <= 16384\n @latest = token\n catch error\n storageUnavailable()\n\nTokenStore:latest()\n return @latest\n\nTokenStore:ready()\n return @ready\n\nTokenStore:initializing()\n return @initializing\n\nTokenStore:current(generation)\n return generation == @generation\n\nTokenStore:initialized(token, generation)\n if !current(generation)\n throw \"UiTokenOperationSuperseded\"\n if token != null\n save(token)\n @initializing = false\n return token\n\nTokenStore:cancelInitialization()\n @generation++\n @initializing = false\n @ready = Promise/resolve(@latest)\n return null\n\nTokenStore:clear()\n previous = @latest\n cancelInitialization()\n @latest = null\n @ready = Promise/resolve()\n if @storage != null\n try\n persisted = @storage.getItem(@key)\n if previous != null and persisted == previous\n @storage.removeItem(@key)\n catch error\n storageUnavailable()\n return null\n\nTokenStore:initialize(path, previousToken = null)\n if !is_string(path) or !path.startsWith(\"/\") or path.startsWith(\"//\") or path.includes(\"\\\\\")\n throw \"UiTokenBootstrapRequiresSameOriginPath\"\n cancelInitialization()\n generation = @generation\n headers = {\n \"Content-Type\": \"application/json\"\n }\n previousToken = bootstrapSeed(previousToken)\n if previousToken != null\n headers.Authorization = \"Bearer ${previousToken}\"\n @initializing = true\n pending = fetch(path, {\n method: \"POST\"\n headers: headers\n body: \"{}\"\n cache: \"no-store\"\n redirect: \"error\"\n }).then((response)\n capture generation\n return initializedToken(@this, response, generation)\n )\n @ready = pending\n pending.catch((error)\n capture generation\n bootstrapFailed(@this, generation)\n )\n return pending\n\nTokenStore:bootstrapSeed(previousToken)\n if previousToken != null\n return previousToken\n if @storage != null\n try\n persisted = @storage.getItem(@key)\n if is_string(persisted) and persisted != \"\" and persisted.length <= 16384\n return persisted\n catch error\n storageUnavailable()\n return @latest\n\ninitializedToken(store, response, generation)\n token = response.headers.get(\"X-Lango-Token\")\n if !response.ok or token == null\n throw \"UiTokenBootstrapFailed\"\n return response.json().then((body)\n capture store\n capture token\n capture generation\n return store.initialized(token, generation)\n )\n\nbootstrapFailed(store, generation)\n context log\n if !store.current(generation)\n return null\n log.err(\"Token bootstrap failed\")\n store.initialized(null, generation)\n return null\n\nTokenStore:logout(path)\n if !is_string(path) or !path.startsWith(\"/\") or path.startsWith(\"//\") or path.includes(\"\\\\\")\n throw \"UiLogoutRequiresSameOriginPath\"\n generation = @generation\n waiting = @ready\n ready = waiting.catch((error)\n return null\n )\n return ready.then(()\n capture path\n capture generation\n return logoutReady(path, generation)\n )\n\nTokenStore:logoutReady(path, generation)\n if !current(generation)\n throw \"UiTokenOperationSuperseded\"\n previous = @latest\n if previous == null\n throw \"UiLogoutTokenRequired\"\n return fetch(path, {\n method: \"POST\"\n headers: {\n \"Content-Type\": \"application/json\"\n Authorization: \"Bearer ${previous}\"\n }\n body: \"{}\"\n cache: \"no-store\"\n redirect: \"error\"\n }).then((response)\n capture previous\n capture generation\n return readLogout(@this, response, previous, generation)\n )\n\nreadLogout(store, response, previous, generation)\n if !response.ok\n throw \"UiLogoutHttpError: ${response.status}\"\n return response.json().then((body)\n capture store\n capture previous\n capture generation\n if !is_object(body) or body.loggedOut != true\n throw \"UiInvalidLogoutResponse\"\n return store.loggedOut(previous, generation)\n )\n\nTokenStore:loggedOut(previousToken, generation)\n if !current(generation)\n throw \"UiTokenOperationSuperseded\"\n clear()\n return previousToken\n\nTokenStore:save(token)\n if !is_string(token) or token == \"\" or token.length > 16384\n throw \"UiInvalidToken\"\n @latest = token\n if @storage != null\n try\n @storage.setItem(@key, token)\n catch error\n storageUnavailable()\n return null\n\nbrowserTokenStore(key = \"lango:last-token\")\n storage = null\n try\n storage = localStorage\n catch error\n storageUnavailable()\n return new TokenStore(storage, key)\n\nstorageUnavailable()\n context log\n log.warn(\"Token persistence is unavailable; this session continues in memory\")\n return null\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA;;;;;;;;;;;;;;;;;AAWA;;;;;;;;;;;;;;;;;;AA2CA;;;;;;;;;;;;;;;;;;;;AA6BA;;;;;;;;;;;;AAQA;;;;;;;;;;;"}
|
package/examples/contacts.lango
DELETED
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
import js "node:path" as path
|
|
2
|
-
import js global crypto
|
|
3
|
-
import js global RegExp
|
|
4
|
-
import js "../../lango-ui/dist/library.mjs" as ui
|
|
5
|
-
import "./contacts_store"
|
|
6
|
-
class ContactsStore
|
|
7
|
-
|
|
8
|
-
export initializeContacts(options)
|
|
9
|
-
export closeContacts()
|
|
10
|
-
export contactsPage(selected)
|
|
11
|
-
export newContact(input)
|
|
12
|
-
export openContact(input)
|
|
13
|
-
export saveContact(input)
|
|
14
|
-
export deleteContact(input)
|
|
15
|
-
|
|
16
|
-
global store = null
|
|
17
|
-
|
|
18
|
-
initializeContacts(options)
|
|
19
|
-
global store
|
|
20
|
-
store = new ContactsStore(path.join(options.stateDir, "contacts.sqlite"))
|
|
21
|
-
|
|
22
|
-
closeContacts()
|
|
23
|
-
global store
|
|
24
|
-
if store != null
|
|
25
|
-
store.close()
|
|
26
|
-
store = null
|
|
27
|
-
|
|
28
|
-
owner()
|
|
29
|
-
context token
|
|
30
|
-
if token == null or !is_string(token.clientId) or token.clientId == ""
|
|
31
|
-
throw "ContactsIdentityRequired"
|
|
32
|
-
return token.clientId
|
|
33
|
-
|
|
34
|
-
contactsPage(selected)
|
|
35
|
-
return {
|
|
36
|
-
type: "Form"
|
|
37
|
-
name: "__content__"
|
|
38
|
-
controls: [{
|
|
39
|
-
type: "Label"
|
|
40
|
-
value: "Contacts"
|
|
41
|
-
}, selector(owner(), null), {
|
|
42
|
-
type: "Button"
|
|
43
|
-
name: "openButton"
|
|
44
|
-
text: "Open selected contact"
|
|
45
|
-
event: "/app/contacts/open"
|
|
46
|
-
confirmDirty: true
|
|
47
|
-
}, {
|
|
48
|
-
type: "Button"
|
|
49
|
-
name: "newButton"
|
|
50
|
-
text: "New contact"
|
|
51
|
-
event: "/app/contacts/new"
|
|
52
|
-
confirmDirty: true
|
|
53
|
-
}, editor(draft())]
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
draft()
|
|
57
|
-
return {
|
|
58
|
-
id: crypto/randomUUID()
|
|
59
|
-
version: 0
|
|
60
|
-
fullName: ""
|
|
61
|
-
email: ""
|
|
62
|
-
country: ""
|
|
63
|
-
subscribed: false
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
selector(client, selected)
|
|
67
|
-
global store
|
|
68
|
-
options = []
|
|
69
|
-
found = false
|
|
70
|
-
for store.list(client) as record
|
|
71
|
-
options.add({
|
|
72
|
-
value: record.id
|
|
73
|
-
text: "${record.fullName} — ${record.email}"
|
|
74
|
-
})
|
|
75
|
-
if record.id == selected
|
|
76
|
-
found = true
|
|
77
|
-
value = null
|
|
78
|
-
if found
|
|
79
|
-
value = selected
|
|
80
|
-
return {
|
|
81
|
-
type: "Select"
|
|
82
|
-
name: "selection"
|
|
83
|
-
label: "Saved contacts"
|
|
84
|
-
trackChanges: false
|
|
85
|
-
value: value
|
|
86
|
-
options: options
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
editor(record)
|
|
90
|
-
return {
|
|
91
|
-
type: "Container"
|
|
92
|
-
name: "editor"
|
|
93
|
-
classes: ["contact-editor"]
|
|
94
|
-
controls: [{
|
|
95
|
-
type: "Value"
|
|
96
|
-
name: "id"
|
|
97
|
-
value: record.id
|
|
98
|
-
}, {
|
|
99
|
-
type: "Value"
|
|
100
|
-
name: "version"
|
|
101
|
-
value: record.version
|
|
102
|
-
}, {
|
|
103
|
-
type: "Text"
|
|
104
|
-
name: "fullName"
|
|
105
|
-
label: "Full name"
|
|
106
|
-
value: record.fullName
|
|
107
|
-
validation: {
|
|
108
|
-
required: true
|
|
109
|
-
maxLength: 100
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
type: "Text"
|
|
113
|
-
name: "email"
|
|
114
|
-
label: "Email"
|
|
115
|
-
value: record.email
|
|
116
|
-
validation: {
|
|
117
|
-
required: true
|
|
118
|
-
maxLength: 254
|
|
119
|
-
pattern: "[^ @]+@[^ @]+[.][^ @]+"
|
|
120
|
-
message: "Enter a valid email address."
|
|
121
|
-
}
|
|
122
|
-
}, {
|
|
123
|
-
type: "Select"
|
|
124
|
-
name: "country"
|
|
125
|
-
label: "Country"
|
|
126
|
-
value: record.country
|
|
127
|
-
options: [{
|
|
128
|
-
value: ""
|
|
129
|
-
text: "Not specified"
|
|
130
|
-
}, {
|
|
131
|
-
value: "tr"
|
|
132
|
-
text: "Türkiye"
|
|
133
|
-
}, {
|
|
134
|
-
value: "gb"
|
|
135
|
-
text: "United Kingdom"
|
|
136
|
-
}]
|
|
137
|
-
}, {
|
|
138
|
-
type: "Checkbox"
|
|
139
|
-
name: "subscribed"
|
|
140
|
-
label: "Receive updates"
|
|
141
|
-
value: record.subscribed
|
|
142
|
-
}, {
|
|
143
|
-
type: "Button"
|
|
144
|
-
name: "saveButton"
|
|
145
|
-
text: "Save contact"
|
|
146
|
-
event: "/app/contacts/save"
|
|
147
|
-
validate: true
|
|
148
|
-
}, {
|
|
149
|
-
type: "Label"
|
|
150
|
-
value: "Check before deleting this contact"
|
|
151
|
-
}, {
|
|
152
|
-
type: "Checkbox"
|
|
153
|
-
name: "confirmDelete"
|
|
154
|
-
label: "Confirm contact deletion"
|
|
155
|
-
trackChanges: false
|
|
156
|
-
value: false
|
|
157
|
-
}, {
|
|
158
|
-
type: "Button"
|
|
159
|
-
name: "deleteButton"
|
|
160
|
-
text: "Delete contact"
|
|
161
|
-
event: "/app/contacts/delete"
|
|
162
|
-
enabled: record.version > 0
|
|
163
|
-
confirmDirty: true
|
|
164
|
-
}, {
|
|
165
|
-
type: "Label"
|
|
166
|
-
name: "status"
|
|
167
|
-
value: "Choose a saved contact or enter a new one."
|
|
168
|
-
}]
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
reply(input)
|
|
172
|
-
return new ui/Response(input.formId, input.seqno)
|
|
173
|
-
|
|
174
|
-
send(result)
|
|
175
|
-
context response
|
|
176
|
-
response.send(result.result())
|
|
177
|
-
return null
|
|
178
|
-
|
|
179
|
-
newContact(input)
|
|
180
|
-
result = reply(input)
|
|
181
|
-
result.replace("selection", selector(owner(), null))
|
|
182
|
-
result.replace("editor", editor(draft()))
|
|
183
|
-
return send(result)
|
|
184
|
-
|
|
185
|
-
openContact(input)
|
|
186
|
-
global store
|
|
187
|
-
selected = input.values.selection
|
|
188
|
-
result = reply(input)
|
|
189
|
-
if !is_string(selected) or selected == ""
|
|
190
|
-
result.fieldError("selection", "Choose a contact to open.")
|
|
191
|
-
return send(result)
|
|
192
|
-
record = store.get(owner(), selected)
|
|
193
|
-
if record == null
|
|
194
|
-
result.replace("selection", selector(owner(), null))
|
|
195
|
-
result.value("editor", {
|
|
196
|
-
status: "This contact no longer exists. Choose another contact."
|
|
197
|
-
})
|
|
198
|
-
return send(result)
|
|
199
|
-
result.replace("editor", editor(record))
|
|
200
|
-
return send(result)
|
|
201
|
-
|
|
202
|
-
identity(input)
|
|
203
|
-
context response
|
|
204
|
-
record = input.values.editor
|
|
205
|
-
if !is_object(record) or is_array(record)
|
|
206
|
-
response.status(400).send({
|
|
207
|
-
error: "InvalidContact"
|
|
208
|
-
})
|
|
209
|
-
return null
|
|
210
|
-
if !is_string(record.id) or record.id == "" or record.id.length > 128 or !is_number(record.version) or record.version < 0 or record.version % 1 != 0 or record.version >= 9007199254740991
|
|
211
|
-
response.status(400).send({
|
|
212
|
-
error: "InvalidContact"
|
|
213
|
-
})
|
|
214
|
-
return null
|
|
215
|
-
return record
|
|
216
|
-
|
|
217
|
-
saveContact(input)
|
|
218
|
-
global store
|
|
219
|
-
context response
|
|
220
|
-
record = identity(input)
|
|
221
|
-
if record == null
|
|
222
|
-
return null
|
|
223
|
-
countries = ["tr", "gb", ""]
|
|
224
|
-
if !is_string(record.fullName) or !is_string(record.email) or !is_bool(record.subscribed) or (record.country != null and !countries.includes(record.country))
|
|
225
|
-
response.status(400).send({
|
|
226
|
-
error: "InvalidContact"
|
|
227
|
-
})
|
|
228
|
-
return null
|
|
229
|
-
result = reply(input)
|
|
230
|
-
fullName = record.fullName.trim()
|
|
231
|
-
email = record.email.trim().toLowerCase()
|
|
232
|
-
pattern = new RegExp("^[^ @]+@[^ @]+[.][^ @]+$")
|
|
233
|
-
invalid = false
|
|
234
|
-
if fullName == "" or fullName.length > 100
|
|
235
|
-
result.fieldError(["editor", "fullName"], "Enter a name of up to 100 characters.")
|
|
236
|
-
invalid = true
|
|
237
|
-
if email.length > 254 or !pattern.test(email)
|
|
238
|
-
result.fieldError(["editor", "email"], "Enter a valid email address.")
|
|
239
|
-
invalid = true
|
|
240
|
-
if invalid
|
|
241
|
-
return send(result)
|
|
242
|
-
values = {
|
|
243
|
-
fullName: fullName
|
|
244
|
-
email: email
|
|
245
|
-
country: record.country
|
|
246
|
-
subscribed: record.subscribed
|
|
247
|
-
}
|
|
248
|
-
saved = store.save(owner(), record.id, record.version, values)
|
|
249
|
-
if saved.outcome != "Saved"
|
|
250
|
-
if saved.outcome == "DuplicateEmail"
|
|
251
|
-
result.fieldError(["editor", "email"], "Another contact uses this email.")
|
|
252
|
-
else
|
|
253
|
-
result.value("editor", {
|
|
254
|
-
status: "The contact changed or was deleted. Open it again before saving."
|
|
255
|
-
})
|
|
256
|
-
return send(result)
|
|
257
|
-
result.replace("selection", selector(owner(), record.id))
|
|
258
|
-
result.value("editor", {
|
|
259
|
-
fullName: fullName
|
|
260
|
-
email: email
|
|
261
|
-
country: record.country
|
|
262
|
-
subscribed: record.subscribed
|
|
263
|
-
version: saved.version
|
|
264
|
-
confirmDelete: false
|
|
265
|
-
status: "Contact saved."
|
|
266
|
-
})
|
|
267
|
-
for values as name: value
|
|
268
|
-
result.markClean(["editor", name], value)
|
|
269
|
-
result.fieldError(["editor", name], null)
|
|
270
|
-
result.setEnabled(["editor", "deleteButton"], true)
|
|
271
|
-
return send(result)
|
|
272
|
-
|
|
273
|
-
deleteContact(input)
|
|
274
|
-
global store
|
|
275
|
-
record = identity(input)
|
|
276
|
-
if record == null
|
|
277
|
-
return null
|
|
278
|
-
result = reply(input)
|
|
279
|
-
if record.confirmDelete != true
|
|
280
|
-
result.fieldError(["editor", "confirmDelete"], "Check the deletion confirmation first.")
|
|
281
|
-
return send(result)
|
|
282
|
-
outcome = store.deleteRecord(owner(), record.id, record.version)
|
|
283
|
-
if outcome != "Deleted"
|
|
284
|
-
result.value("editor", {
|
|
285
|
-
status: "The contact changed or was deleted. Open it again before deleting."
|
|
286
|
-
})
|
|
287
|
-
return send(result)
|
|
288
|
-
result.replace("selection", selector(owner(), null))
|
|
289
|
-
result.replace("editor", editor(draft()))
|
|
290
|
-
result.value("editor", {
|
|
291
|
-
status: "Contact deleted."
|
|
292
|
-
})
|
|
293
|
-
return send(result)
|