@lango-project/lango-client 0.2.0 → 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.
Files changed (232) hide show
  1. package/LICENSE +1 -0
  2. package/NOTICE +5 -1
  3. package/README.md +571 -855
  4. package/cli/.lango/localization.mjs +108 -0
  5. package/{dist/node → cli}/.lango/runtime.mjs +112 -19
  6. package/cli/.lango/vendor/i18next.LICENSE +21 -0
  7. package/cli/.lango/vendor/i18next.mjs +2434 -0
  8. package/cli/create.mjs +62 -0
  9. package/cli/create.mjs.map +1 -0
  10. package/dist/.lango/localization.mjs +108 -0
  11. package/dist/.lango/runtime.mjs +112 -19
  12. package/dist/.lango/vendor/i18next.LICENSE +21 -0
  13. package/dist/.lango/vendor/i18next.mjs +2434 -0
  14. package/dist/accordion.mjs +277 -0
  15. package/dist/accordion.mjs.map +1 -0
  16. package/dist/activities.mjs +185 -0
  17. package/dist/activities.mjs.map +1 -0
  18. package/dist/app.mjs +636 -0
  19. package/dist/app.mjs.map +1 -0
  20. package/dist/boot.mjs +24 -0
  21. package/dist/boot.mjs.map +1 -0
  22. package/dist/bootstrap-LICENSE +21 -0
  23. package/dist/bootstrap.min.css +6 -0
  24. package/dist/bootstrap.min.css.map +1 -0
  25. package/dist/button.mjs +77 -0
  26. package/dist/button.mjs.map +1 -0
  27. package/dist/chip.mjs +134 -0
  28. package/dist/chip.mjs.map +1 -0
  29. package/dist/client.css +95 -0
  30. package/dist/collections.mjs +77 -0
  31. package/dist/collections.mjs.map +1 -0
  32. package/dist/combo_box.mjs +408 -0
  33. package/dist/combo_box.mjs.map +1 -0
  34. package/dist/content.mjs +123 -0
  35. package/dist/content.mjs.map +1 -0
  36. package/dist/control.mjs +139 -0
  37. package/dist/control.mjs.map +1 -0
  38. package/dist/date_input.mjs +242 -0
  39. package/dist/date_input.mjs.map +1 -0
  40. package/dist/error_reporter.mjs +136 -0
  41. package/dist/error_reporter.mjs.map +1 -0
  42. package/dist/fields.mjs +454 -0
  43. package/dist/fields.mjs.map +1 -0
  44. package/dist/file_input.mjs +227 -0
  45. package/dist/file_input.mjs.map +1 -0
  46. package/dist/form.mjs +272 -0
  47. package/dist/form.mjs.map +1 -0
  48. package/dist/heartbeat.mjs +167 -254
  49. package/dist/heartbeat.mjs.map +1 -1
  50. package/dist/index.html +18 -0
  51. package/dist/indicators.mjs +127 -0
  52. package/dist/indicators.mjs.map +1 -0
  53. package/dist/input_changes.mjs +58 -0
  54. package/dist/input_changes.mjs.map +1 -0
  55. package/dist/input_group.mjs +38 -0
  56. package/dist/input_group.mjs.map +1 -0
  57. package/dist/layouts.mjs +195 -0
  58. package/dist/layouts.mjs.map +1 -0
  59. package/dist/library.mjs +130 -775
  60. package/dist/library.mjs.map +1 -1
  61. package/dist/longpoll.mjs +254 -0
  62. package/dist/longpoll.mjs.map +1 -0
  63. package/dist/main.mjs +138 -0
  64. package/dist/main.mjs.map +1 -0
  65. package/dist/markdown.mjs +61 -0
  66. package/dist/markdown.mjs.map +1 -0
  67. package/dist/menus.mjs +468 -0
  68. package/dist/menus.mjs.map +1 -0
  69. package/dist/navigation.mjs +260 -410
  70. package/dist/navigation.mjs.map +1 -1
  71. package/dist/numeric_input.mjs +181 -0
  72. package/dist/numeric_input.mjs.map +1 -0
  73. package/dist/otp_input.mjs +113 -0
  74. package/dist/otp_input.mjs.map +1 -0
  75. package/dist/presentations.mjs +852 -0
  76. package/dist/presentations.mjs.map +1 -0
  77. package/dist/renderer.mjs +293 -0
  78. package/dist/renderer.mjs.map +1 -0
  79. package/dist/rich_content.mjs +99 -0
  80. package/dist/rich_content.mjs.map +1 -0
  81. package/dist/tables.mjs +369 -0
  82. package/dist/tables.mjs.map +1 -0
  83. package/dist/tabs.mjs +205 -0
  84. package/dist/tabs.mjs.map +1 -0
  85. package/dist/templates.mjs +46 -0
  86. package/dist/templates.mjs.map +1 -0
  87. package/dist/vendor/DOMPurify-LICENSE +202 -0
  88. package/dist/vendor/dompurify.mjs +2540 -0
  89. package/dist/vendor/flatpickr-LICENSE.md +21 -0
  90. package/dist/vendor/flatpickr.min.css +13 -0
  91. package/dist/vendor/flatpickr.mjs +2340 -0
  92. package/dist/vendor/flatpickr.mjs.map +7 -0
  93. package/dist/vendor/marked-LICENSE.md +44 -0
  94. package/dist/vendor/marked.esm.js.map +7 -0
  95. package/dist/vendor/marked.mjs +85 -0
  96. package/dist/vendor/purify.es.mjs.map +1 -0
  97. package/dist/widgets.mjs +197 -0
  98. package/dist/widgets.mjs.map +1 -0
  99. package/docs/implementation.md +42 -0
  100. package/package.json +26 -40
  101. package/src/accordion.lango +198 -0
  102. package/src/activities.lango +132 -0
  103. package/src/app.lango +508 -0
  104. package/src/boot.lango +12 -0
  105. package/src/button.lango +49 -0
  106. package/src/chip.lango +94 -0
  107. package/src/collections.lango +46 -0
  108. package/src/combo_box.lango +298 -0
  109. package/src/content.lango +75 -0
  110. package/src/control.lango +100 -0
  111. package/src/create.lango +42 -0
  112. package/src/date_input.lango +215 -0
  113. package/src/error_reporter.lango +95 -0
  114. package/src/fields.lango +327 -0
  115. package/src/file_input.lango +175 -0
  116. package/src/form.lango +195 -0
  117. package/src/heartbeat.lango +136 -199
  118. package/src/indicators.lango +94 -0
  119. package/src/input_changes.lango +33 -0
  120. package/src/input_group.lango +22 -0
  121. package/src/layouts.lango +137 -0
  122. package/src/library.lango +194 -571
  123. package/src/longpoll.lango +187 -0
  124. package/src/main.lango +109 -0
  125. package/src/markdown.lango +48 -0
  126. package/src/menus.lango +336 -0
  127. package/src/navigation.lango +209 -299
  128. package/src/numeric_input.lango +131 -0
  129. package/src/otp_input.lango +83 -0
  130. package/src/presentations.lango +617 -0
  131. package/src/renderer.lango +288 -0
  132. package/src/rich_content.lango +66 -0
  133. package/src/tables.lango +271 -0
  134. package/src/tabs.lango +144 -0
  135. package/src/templates.lango +29 -0
  136. package/src/widgets.lango +141 -0
  137. package/web/client.css +95 -0
  138. package/web/index.html +18 -0
  139. package/dist/application.mjs +0 -429
  140. package/dist/application.mjs.map +0 -1
  141. package/dist/coordinator.mjs +0 -91
  142. package/dist/coordinator.mjs.map +0 -1
  143. package/dist/demo.mjs +0 -110
  144. package/dist/demo.mjs.map +0 -1
  145. package/dist/demo_controls.mjs +0 -59
  146. package/dist/demo_controls.mjs.map +0 -1
  147. package/dist/errors.mjs +0 -201
  148. package/dist/errors.mjs.map +0 -1
  149. package/dist/form_state.mjs +0 -266
  150. package/dist/form_state.mjs.map +0 -1
  151. package/dist/inheritance.mjs +0 -240
  152. package/dist/inheritance.mjs.map +0 -1
  153. package/dist/input_values.mjs +0 -65
  154. package/dist/input_values.mjs.map +0 -1
  155. package/dist/node/.lango/xmldom/conventions.js +0 -429
  156. package/dist/node/.lango/xmldom/dom-parser.js +0 -591
  157. package/dist/node/.lango/xmldom/dom.js +0 -3759
  158. package/dist/node/.lango/xmldom/entities.js +0 -2171
  159. package/dist/node/.lango/xmldom/errors.js +0 -205
  160. package/dist/node/.lango/xmldom/grammar.js +0 -559
  161. package/dist/node/.lango/xmldom/index.js +0 -41
  162. package/dist/node/.lango/xmldom/package.json +0 -1
  163. package/dist/node/.lango/xmldom/sax.js +0 -983
  164. package/dist/node/.lango/xmldom.LICENSE.md +0 -8
  165. package/dist/node/browser_host.mjs +0 -351
  166. package/dist/node/browser_host.mjs.map +0 -1
  167. package/dist/node/create_app.mjs +0 -118
  168. package/dist/node/create_app.mjs.map +0 -1
  169. package/dist/presentation.mjs +0 -89
  170. package/dist/presentation.mjs.map +0 -1
  171. package/dist/protocol.mjs +0 -706
  172. package/dist/protocol.mjs.map +0 -1
  173. package/dist/session.mjs +0 -431
  174. package/dist/session.mjs.map +0 -1
  175. package/dist/tokens.mjs +0 -298
  176. package/dist/tokens.mjs.map +0 -1
  177. package/examples/contacts.lango +0 -302
  178. package/examples/contacts_flow.lango +0 -174
  179. package/examples/contacts_store.lango +0 -109
  180. package/examples/contacts_store_test.lango +0 -65
  181. package/examples/demo.css +0 -72
  182. package/examples/demo_test.lango +0 -356
  183. package/examples/index.html +0 -28
  184. package/examples/pages.lango +0 -180
  185. package/examples/server.lango +0 -189
  186. package/examples/worker.lango +0 -142
  187. package/src/application.lango +0 -327
  188. package/src/browser_host.lango +0 -276
  189. package/src/coordinator.lango +0 -57
  190. package/src/demo.lango +0 -110
  191. package/src/demo_controls.lango +0 -53
  192. package/src/errors.lango +0 -149
  193. package/src/errors_test.lango +0 -157
  194. package/src/form_state.lango +0 -168
  195. package/src/heartbeat_test.lango +0 -479
  196. package/src/inheritance.lango +0 -167
  197. package/src/input_values.lango +0 -37
  198. package/src/logout_test.lango +0 -564
  199. package/src/navigation_test.lango +0 -556
  200. package/src/presentation.lango +0 -55
  201. package/src/protocol.lango +0 -787
  202. package/src/renderer_test.lango +0 -1986
  203. package/src/session.lango +0 -313
  204. package/src/session_test.lango +0 -455
  205. package/src/tabs_test.lango +0 -216
  206. package/src/tokens.lango +0 -215
  207. package/template/.vscode/extensions.json +0 -3
  208. package/template/.vscode/settings.json +0 -9
  209. package/template/README.md +0 -40
  210. package/template/gitignore +0 -4
  211. package/template/package.json +0 -22
  212. package/template/public/app.css +0 -4
  213. package/template/public/index.html +0 -24
  214. package/template/src/client.lango +0 -78
  215. package/template/src/pages.lango +0 -55
  216. package/template/src/server.lango +0 -24
  217. package/template/src/worker.lango +0 -77
  218. package/template/test/app.lango +0 -9
  219. package/tools/create_app.lango +0 -88
  220. package/tools/create_app_test.lango +0 -43
  221. package/tools/starter_test.lango +0 -227
  222. /package/{dist/node → cli}/.lango/bignumber.mjs +0 -0
  223. /package/{dist → cli}/.lango/xmldom/conventions.js +0 -0
  224. /package/{dist → cli}/.lango/xmldom/dom-parser.js +0 -0
  225. /package/{dist → cli}/.lango/xmldom/dom.js +0 -0
  226. /package/{dist → cli}/.lango/xmldom/entities.js +0 -0
  227. /package/{dist → cli}/.lango/xmldom/errors.js +0 -0
  228. /package/{dist → cli}/.lango/xmldom/grammar.js +0 -0
  229. /package/{dist → cli}/.lango/xmldom/index.js +0 -0
  230. /package/{dist → cli}/.lango/xmldom/package.json +0 -0
  231. /package/{dist → cli}/.lango/xmldom/sax.js +0 -0
  232. /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
@@ -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;;;;;;;;;;;"}
@@ -1,302 +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: "Label"
104
- value: "Full name"
105
- }, {
106
- type: "Text"
107
- name: "fullName"
108
- label: "Full name"
109
- value: record.fullName
110
- validation: {
111
- required: true
112
- maxLength: 100
113
- }
114
- }, {
115
- type: "Label"
116
- value: "Email"
117
- }, {
118
- type: "Text"
119
- name: "email"
120
- label: "Email"
121
- value: record.email
122
- validation: {
123
- required: true
124
- maxLength: 254
125
- pattern: "[^ @]+@[^ @]+[.][^ @]+"
126
- message: "Enter a valid email address."
127
- }
128
- }, {
129
- type: "Select"
130
- name: "country"
131
- label: "Country"
132
- value: record.country
133
- options: [{
134
- value: ""
135
- text: "Not specified"
136
- }, {
137
- value: "tr"
138
- text: "Türkiye"
139
- }, {
140
- value: "gb"
141
- text: "United Kingdom"
142
- }]
143
- }, {
144
- type: "Label"
145
- value: "Receive updates"
146
- }, {
147
- type: "Checkbox"
148
- name: "subscribed"
149
- label: "Receive updates"
150
- value: record.subscribed
151
- }, {
152
- type: "Button"
153
- name: "saveButton"
154
- text: "Save contact"
155
- event: "/app/contacts/save"
156
- validate: true
157
- }, {
158
- type: "Label"
159
- value: "Check before deleting this contact"
160
- }, {
161
- type: "Checkbox"
162
- name: "confirmDelete"
163
- label: "Confirm contact deletion"
164
- trackChanges: false
165
- value: false
166
- }, {
167
- type: "Button"
168
- name: "deleteButton"
169
- text: "Delete contact"
170
- event: "/app/contacts/delete"
171
- enabled: record.version > 0
172
- confirmDirty: true
173
- }, {
174
- type: "Label"
175
- name: "status"
176
- value: "Choose a saved contact or enter a new one."
177
- }]
178
- }
179
-
180
- reply(input)
181
- return new ui/Response(input.formId, input.seqno)
182
-
183
- send(result)
184
- context response
185
- response.send(result.result())
186
- return null
187
-
188
- newContact(input)
189
- result = reply(input)
190
- result.replace("selection", selector(owner(), null))
191
- result.replace("editor", editor(draft()))
192
- return send(result)
193
-
194
- openContact(input)
195
- global store
196
- selected = input.values.selection
197
- result = reply(input)
198
- if !is_string(selected) or selected == ""
199
- result.fieldError("selection", "Choose a contact to open.")
200
- return send(result)
201
- record = store.get(owner(), selected)
202
- if record == null
203
- result.replace("selection", selector(owner(), null))
204
- result.value("editor", {
205
- status: "This contact no longer exists. Choose another contact."
206
- })
207
- return send(result)
208
- result.replace("editor", editor(record))
209
- return send(result)
210
-
211
- identity(input)
212
- context response
213
- record = input.values.editor
214
- if !is_object(record) or is_array(record)
215
- response.status(400).send({
216
- error: "InvalidContact"
217
- })
218
- return null
219
- 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
220
- response.status(400).send({
221
- error: "InvalidContact"
222
- })
223
- return null
224
- return record
225
-
226
- saveContact(input)
227
- global store
228
- context response
229
- record = identity(input)
230
- if record == null
231
- return null
232
- countries = ["tr", "gb", ""]
233
- if !is_string(record.fullName) or !is_string(record.email) or !is_bool(record.subscribed) or (record.country != null and !countries.includes(record.country))
234
- response.status(400).send({
235
- error: "InvalidContact"
236
- })
237
- return null
238
- result = reply(input)
239
- fullName = record.fullName.trim()
240
- email = record.email.trim().toLowerCase()
241
- pattern = new RegExp("^[^ @]+@[^ @]+[.][^ @]+$")
242
- invalid = false
243
- if fullName == "" or fullName.length > 100
244
- result.fieldError(["editor", "fullName"], "Enter a name of up to 100 characters.")
245
- invalid = true
246
- if email.length > 254 or !pattern.test(email)
247
- result.fieldError(["editor", "email"], "Enter a valid email address.")
248
- invalid = true
249
- if invalid
250
- return send(result)
251
- values = {
252
- fullName: fullName
253
- email: email
254
- country: record.country
255
- subscribed: record.subscribed
256
- }
257
- saved = store.save(owner(), record.id, record.version, values)
258
- if saved.outcome != "Saved"
259
- if saved.outcome == "DuplicateEmail"
260
- result.fieldError(["editor", "email"], "Another contact uses this email.")
261
- else
262
- result.value("editor", {
263
- status: "The contact changed or was deleted. Open it again before saving."
264
- })
265
- return send(result)
266
- result.replace("selection", selector(owner(), record.id))
267
- result.value("editor", {
268
- fullName: fullName
269
- email: email
270
- country: record.country
271
- subscribed: record.subscribed
272
- version: saved.version
273
- confirmDelete: false
274
- status: "Contact saved."
275
- })
276
- for values as name: value
277
- result.markClean(["editor", name], value)
278
- result.fieldError(["editor", name], null)
279
- result.setEnabled(["editor", "deleteButton"], true)
280
- return send(result)
281
-
282
- deleteContact(input)
283
- global store
284
- record = identity(input)
285
- if record == null
286
- return null
287
- result = reply(input)
288
- if record.confirmDelete != true
289
- result.fieldError(["editor", "confirmDelete"], "Check the deletion confirmation first.")
290
- return send(result)
291
- outcome = store.deleteRecord(owner(), record.id, record.version)
292
- if outcome != "Deleted"
293
- result.value("editor", {
294
- status: "The contact changed or was deleted. Open it again before deleting."
295
- })
296
- return send(result)
297
- result.replace("selection", selector(owner(), null))
298
- result.replace("editor", editor(draft()))
299
- result.value("editor", {
300
- status: "Contact deleted."
301
- })
302
- return send(result)