@lango-project/lango-client 0.4.1 → 0.4.2
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 +26 -0
- package/cli/.lango/runtime.mjs +16 -0
- package/dist/.lango/runtime.mjs +16 -0
- package/dist/accordion.mjs +9 -8
- package/dist/accordion.mjs.map +1 -1
- package/dist/activities.mjs +8 -7
- package/dist/activities.mjs.map +1 -1
- package/dist/app.mjs +465 -50
- package/dist/app.mjs.map +1 -1
- package/dist/boot.mjs +3 -2
- package/dist/boot.mjs.map +1 -1
- package/dist/button.mjs +8 -7
- package/dist/button.mjs.map +1 -1
- package/dist/chip.mjs +5 -4
- package/dist/chip.mjs.map +1 -1
- package/dist/combo_box.mjs +15 -14
- package/dist/combo_box.mjs.map +1 -1
- package/dist/content.mjs +9 -8
- package/dist/content.mjs.map +1 -1
- package/dist/date_input.mjs +3 -2
- package/dist/date_input.mjs.map +1 -1
- package/dist/error_reporter.mjs +6 -5
- package/dist/error_reporter.mjs.map +1 -1
- package/dist/fields.mjs +9 -8
- package/dist/fields.mjs.map +1 -1
- package/dist/file_input.mjs +19 -18
- package/dist/file_input.mjs.map +1 -1
- package/dist/form.mjs +14 -2
- package/dist/form.mjs.map +1 -1
- package/dist/heartbeat.mjs +12 -11
- package/dist/heartbeat.mjs.map +1 -1
- package/dist/input_changes.mjs +5 -4
- package/dist/input_changes.mjs.map +1 -1
- package/dist/longpoll.mjs +12 -11
- package/dist/longpoll.mjs.map +1 -1
- package/dist/main.mjs +35 -18
- package/dist/main.mjs.map +1 -1
- package/dist/menus.mjs +19 -18
- package/dist/menus.mjs.map +1 -1
- package/dist/navigation.mjs +7 -6
- package/dist/navigation.mjs.map +1 -1
- package/dist/numeric_input.mjs +9 -8
- package/dist/numeric_input.mjs.map +1 -1
- package/dist/otp_input.mjs +5 -4
- package/dist/otp_input.mjs.map +1 -1
- package/dist/presentations.mjs +17 -16
- package/dist/presentations.mjs.map +1 -1
- package/dist/renderer.mjs +74 -0
- package/dist/renderer.mjs.map +1 -1
- package/dist/table_scope.mjs +3 -2
- package/dist/table_scope.mjs.map +1 -1
- package/dist/tables.mjs +11 -10
- package/dist/tables.mjs.map +1 -1
- package/dist/tabs.mjs +7 -6
- package/dist/tabs.mjs.map +1 -1
- package/dist/vendor/dompurify.mjs +267 -181
- package/dist/vendor/purify.es.mjs.map +1 -1
- package/dist/widgets.mjs +5 -4
- package/dist/widgets.mjs.map +1 -1
- package/package.json +4 -3
- package/src/app.lango +325 -11
- package/src/form.lango +12 -2
- package/src/heartbeat.lango +2 -2
- package/src/main.lango +15 -0
- package/src/renderer.lango +61 -0
package/src/app.lango
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import js global crypto
|
|
1
2
|
import js global Error
|
|
2
3
|
import js global Object
|
|
3
4
|
import js global Promise
|
|
@@ -20,6 +21,7 @@ export class App(host, renderer)
|
|
|
20
21
|
reporter
|
|
21
22
|
methods
|
|
22
23
|
start()
|
|
24
|
+
acceptEvents(events)
|
|
23
25
|
post(url, input, token)
|
|
24
26
|
saveToken(token)
|
|
25
27
|
clearSavedToken()
|
|
@@ -29,7 +31,20 @@ export class App(host, renderer)
|
|
|
29
31
|
executeDelivery(job)
|
|
30
32
|
checkUrl(url)
|
|
31
33
|
hostUrl()
|
|
32
|
-
request(url, input, token, signal = null, channel = false, opening = false)
|
|
34
|
+
request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)
|
|
35
|
+
sendInput(job, input)
|
|
36
|
+
resumeInput(job, input, challenge)
|
|
37
|
+
needLogin(job, challenge)
|
|
38
|
+
finishLogin(form, userId)
|
|
39
|
+
completeLogin(form)
|
|
40
|
+
beginLoginResponse(form, packet)
|
|
41
|
+
observeAuthentication(form, previous, packet)
|
|
42
|
+
commitAuthentication(source, previous, token, change)
|
|
43
|
+
externalAuthentication(change)
|
|
44
|
+
invalidateForm(form)
|
|
45
|
+
reloadSession()
|
|
46
|
+
cancelLogin(problem = "LoginCancelled")
|
|
47
|
+
loginScopeDisposed(form)
|
|
33
48
|
poll(url, input, token, signal)
|
|
34
49
|
canPoll(form)
|
|
35
50
|
pausePolls(form = null)
|
|
@@ -61,6 +76,18 @@ App(host, renderer)
|
|
|
61
76
|
@pingJob = null
|
|
62
77
|
@resources = []
|
|
63
78
|
@reporter = null
|
|
79
|
+
@login = null
|
|
80
|
+
@committingAuthentication = false
|
|
81
|
+
@authVersion = 0
|
|
82
|
+
@authChanges = []
|
|
83
|
+
@externalStale = false
|
|
84
|
+
@storageChange = null
|
|
85
|
+
try
|
|
86
|
+
@storageChange = @host.storage.getItem("lango.authChange")
|
|
87
|
+
if !is_string(@storageChange) or !@storageChange.startsWith("v1:")
|
|
88
|
+
@storageChange = null
|
|
89
|
+
catch problem
|
|
90
|
+
@storageChange = null
|
|
64
91
|
|
|
65
92
|
App:now()
|
|
66
93
|
if @host.now != null
|
|
@@ -96,8 +123,18 @@ App:error(form, error, code = "UiFailure", name = null)
|
|
|
96
123
|
return null
|
|
97
124
|
|
|
98
125
|
App:saveToken(token)
|
|
126
|
+
if @externalStale
|
|
127
|
+
return false
|
|
99
128
|
try
|
|
100
|
-
@host.storage
|
|
129
|
+
storage = @host.storage
|
|
130
|
+
if storage.getItem != null
|
|
131
|
+
current = storage.getItem("lango.authChange")
|
|
132
|
+
if !@committingAuthentication and is_string(current) and current.startsWith("v1:") and current != @storageChange
|
|
133
|
+
externalAuthentication(current)
|
|
134
|
+
return false
|
|
135
|
+
if @storageChange != null
|
|
136
|
+
storage.setItem("lango.token:${@storageChange}", token)
|
|
137
|
+
storage.setItem("lango.token", token)
|
|
101
138
|
catch error
|
|
102
139
|
return null
|
|
103
140
|
return null
|
|
@@ -105,6 +142,8 @@ App:saveToken(token)
|
|
|
105
142
|
App:clearSavedToken()
|
|
106
143
|
try
|
|
107
144
|
@host.storage.removeItem("lango.token")
|
|
145
|
+
if @storageChange != null
|
|
146
|
+
@host.storage.removeItem("lango.token:${@storageChange}")
|
|
108
147
|
return true
|
|
109
148
|
catch error
|
|
110
149
|
return false
|
|
@@ -115,7 +154,7 @@ App:post(url, input, token)
|
|
|
115
154
|
App:poll(url, input, token, signal)
|
|
116
155
|
return request(url, input, token, signal, true)
|
|
117
156
|
|
|
118
|
-
App:request(url, input, token, signal = null, channel = false, opening = false)
|
|
157
|
+
App:request(url, input, token, signal = null, channel = false, opening = false, recover = false, expected = null)
|
|
119
158
|
target = checkUrl(url)
|
|
120
159
|
headers = {
|
|
121
160
|
"Content-Type": "application/json"
|
|
@@ -125,6 +164,8 @@ App:request(url, input, token, signal = null, channel = false, opening = false)
|
|
|
125
164
|
headers["X-Lango-Screen"] = @host.screen()
|
|
126
165
|
if token != null
|
|
127
166
|
headers.Authorization = "Bearer ${token}"
|
|
167
|
+
if expected != null
|
|
168
|
+
headers["X-Lango-Expected-User"] = to_json(expected)
|
|
128
169
|
options = {
|
|
129
170
|
method: "POST"
|
|
130
171
|
headers: headers
|
|
@@ -134,10 +175,19 @@ App:request(url, input, token, signal = null, channel = false, opening = false)
|
|
|
134
175
|
options.signal = signal
|
|
135
176
|
return chain @host.fetch("${target.pathname}${target.search}", options)
|
|
136
177
|
then(res)
|
|
178
|
+
capture recover
|
|
137
179
|
capture channel
|
|
138
180
|
capture opening
|
|
139
181
|
capture token
|
|
140
182
|
if !res.ok
|
|
183
|
+
if recover and (res.status == 401 or res.status == 403) and res.headers != null and res.headers.get("x-lango-need-login") == "1"
|
|
184
|
+
return chain res.json()
|
|
185
|
+
then(body)
|
|
186
|
+
if !is_object(body) or !is_object(body.needLogin) or (body.error != "LoginRequired" and body.error != "ReauthenticationRequired") or body.needLogin.reason != body.error
|
|
187
|
+
throw "Invalid login challenge"
|
|
188
|
+
return {
|
|
189
|
+
needLogin: body.needLogin
|
|
190
|
+
}
|
|
141
191
|
if opening and res.status == 401 and token != null
|
|
142
192
|
if clearSavedToken()
|
|
143
193
|
throw new Error("Startup HTTP 401: saved token was rejected and cleared. Reload the page to start a new session.")
|
|
@@ -163,6 +213,7 @@ App:request(url, input, token, signal = null, channel = false, opening = false)
|
|
|
163
213
|
if status == null
|
|
164
214
|
status = 200
|
|
165
215
|
return {
|
|
216
|
+
authChange: res.headers.get("x-lango-auth-change")
|
|
166
217
|
status: status
|
|
167
218
|
token: res.headers.get("x-lango-token")
|
|
168
219
|
body: body
|
|
@@ -178,16 +229,29 @@ App:request(url, input, token, signal = null, channel = false, opening = false)
|
|
|
178
229
|
App:start()
|
|
179
230
|
token = null
|
|
180
231
|
try
|
|
181
|
-
|
|
232
|
+
@storageChange = @host.storage.getItem("lango.authChange")
|
|
233
|
+
if !is_string(@storageChange) or !@storageChange.startsWith("v1:")
|
|
234
|
+
@storageChange = null
|
|
235
|
+
token = null
|
|
236
|
+
if @storageChange != null
|
|
237
|
+
token = @host.storage.getItem("lango.token:${@storageChange}")
|
|
238
|
+
if token == null
|
|
239
|
+
token = @host.storage.getItem("lango.token")
|
|
182
240
|
catch error
|
|
183
241
|
token = null
|
|
184
242
|
return chain request("/", {}, token, null, false, true)
|
|
185
243
|
then(packet)
|
|
186
|
-
|
|
244
|
+
acceptEvents(packet.body)
|
|
187
245
|
if @events.clientErrorUrl != null
|
|
188
246
|
@reporter = new ErrorReporter(@this, @events.clientErrorUrl)
|
|
189
247
|
if @events.pingUrl != null
|
|
190
248
|
@heartbeat = new Heartbeat(@this, @host, @events.pingUrl)
|
|
249
|
+
if @externalStale
|
|
250
|
+
if @root == null
|
|
251
|
+
@root = new Form(@this)
|
|
252
|
+
@root.element = @host.mount
|
|
253
|
+
invalidateForm(@root)
|
|
254
|
+
return null
|
|
191
255
|
@root = new Form(@this, null, packet.token)
|
|
192
256
|
@root.element = @host.mount
|
|
193
257
|
@root.setToken(packet.token)
|
|
@@ -196,15 +260,22 @@ App:start()
|
|
|
196
260
|
if @heartbeat != null
|
|
197
261
|
@heartbeat.start()
|
|
198
262
|
return null
|
|
263
|
+
catch(problem)
|
|
264
|
+
if @externalStale
|
|
265
|
+
return null
|
|
266
|
+
throw problem
|
|
199
267
|
|
|
200
268
|
App:send(form, url, owner = null)
|
|
201
269
|
if @disposed or form.disposed
|
|
202
270
|
return Promise/reject("Form is disposed")
|
|
271
|
+
if form.stale or @externalStale
|
|
272
|
+
return Promise/reject("SessionChanged: reload the page")
|
|
203
273
|
pending = new Promise((resolve, reject)
|
|
204
274
|
capture form
|
|
205
275
|
capture url
|
|
206
276
|
capture owner
|
|
207
277
|
@queue.add({
|
|
278
|
+
authVersion: @authVersion
|
|
208
279
|
kind: "send"
|
|
209
280
|
form: form
|
|
210
281
|
url: url
|
|
@@ -221,6 +292,7 @@ App:deliver(form, action, owner, generation)
|
|
|
221
292
|
return Promise/resolve(null)
|
|
222
293
|
deferred = Promise/withResolvers()
|
|
223
294
|
@queue.add({
|
|
295
|
+
authVersion: @authVersion
|
|
224
296
|
kind: "delivery"
|
|
225
297
|
form: form
|
|
226
298
|
action: action
|
|
@@ -237,6 +309,7 @@ App:report(form, url, input, owner)
|
|
|
237
309
|
return Promise/resolve(null)
|
|
238
310
|
deferred = Promise/withResolvers()
|
|
239
311
|
@queue.add({
|
|
312
|
+
authVersion: @authVersion
|
|
240
313
|
kind: "report"
|
|
241
314
|
form: form
|
|
242
315
|
url: url
|
|
@@ -249,7 +322,7 @@ App:report(form, url, input, owner)
|
|
|
249
322
|
return deferred.promise
|
|
250
323
|
|
|
251
324
|
App:canPoll(form)
|
|
252
|
-
if @disposed or form.disposed or @pingJob != null
|
|
325
|
+
if @disposed or form.disposed or form.stale or @externalStale or @pingJob != null or @login != null
|
|
253
326
|
return false
|
|
254
327
|
for @active as job
|
|
255
328
|
if form.related(job.form)
|
|
@@ -271,12 +344,20 @@ App:resumePolls()
|
|
|
271
344
|
return null
|
|
272
345
|
|
|
273
346
|
App:drain()
|
|
274
|
-
if @
|
|
347
|
+
if @disposed
|
|
348
|
+
return null
|
|
349
|
+
if @pingJob != null and @login == null
|
|
275
350
|
if @active.length == 0 and !@pingJob.running
|
|
276
351
|
@pingJob.running = true
|
|
277
352
|
executePing(@pingJob)
|
|
278
353
|
return null
|
|
279
354
|
for @queue.slice() as job
|
|
355
|
+
if job.authVersion != @authVersion or job.form.stale or @externalStale
|
|
356
|
+
@queue.splice(@queue.indexOf(job), 1)
|
|
357
|
+
job.reject("SessionChanged: queued request cancelled")
|
|
358
|
+
continue
|
|
359
|
+
if @login != null and !@login.form.related(job.form)
|
|
360
|
+
continue
|
|
280
361
|
blocked = false
|
|
281
362
|
for @active as running
|
|
282
363
|
if job.form.related(running.form)
|
|
@@ -310,7 +391,9 @@ App:executeDelivery(job)
|
|
|
310
391
|
job.reject(error)
|
|
311
392
|
finally
|
|
312
393
|
capture job
|
|
313
|
-
@active.
|
|
394
|
+
index = @active.indexOf(job)
|
|
395
|
+
if index >= 0
|
|
396
|
+
@active.splice(index, 1)
|
|
314
397
|
drain()
|
|
315
398
|
|
|
316
399
|
App:ping()
|
|
@@ -351,6 +434,8 @@ App:execute(job)
|
|
|
351
434
|
capture job
|
|
352
435
|
if form.disposed
|
|
353
436
|
throw "Form is disposed"
|
|
437
|
+
if form.stale or @externalStale
|
|
438
|
+
throw "SessionChanged: reload the page"
|
|
354
439
|
if job.owner != null and !job.owner.active
|
|
355
440
|
return null
|
|
356
441
|
if job.kind == "report"
|
|
@@ -359,7 +444,7 @@ App:execute(job)
|
|
|
359
444
|
@renderer.waiting(form, true)
|
|
360
445
|
ready = form.prepareValue()
|
|
361
446
|
if ready == null
|
|
362
|
-
return
|
|
447
|
+
return sendInput(job, from_json(to_json(form.getValue())))
|
|
363
448
|
return chain ready
|
|
364
449
|
then(ignored)
|
|
365
450
|
capture form
|
|
@@ -368,15 +453,19 @@ App:execute(job)
|
|
|
368
453
|
throw "Form is disposed"
|
|
369
454
|
if job.owner != null and !job.owner.active
|
|
370
455
|
return null
|
|
371
|
-
return
|
|
456
|
+
return sendInput(job, from_json(to_json(form.getValue())))
|
|
372
457
|
then(packet)
|
|
373
458
|
capture form
|
|
374
459
|
capture job
|
|
460
|
+
if job.authVersion != @authVersion or form.stale or @externalStale
|
|
461
|
+
throw "SessionChanged: response discarded"
|
|
375
462
|
if packet != null and !form.disposed and (job.owner == null or job.owner.active)
|
|
376
463
|
if job.kind == "report"
|
|
377
464
|
form.setToken(packet.token)
|
|
378
465
|
else
|
|
379
466
|
form.handle(packet)
|
|
467
|
+
if form.stale or @externalStale
|
|
468
|
+
throw "SessionChanged: response discarded"
|
|
380
469
|
then(ignored)
|
|
381
470
|
capture job
|
|
382
471
|
job.resolve(null)
|
|
@@ -388,7 +477,9 @@ App:execute(job)
|
|
|
388
477
|
capture form
|
|
389
478
|
if job.kind == "send"
|
|
390
479
|
@renderer.waiting(form, false)
|
|
391
|
-
@active.
|
|
480
|
+
index = @active.indexOf(job)
|
|
481
|
+
if index >= 0
|
|
482
|
+
@active.splice(index, 1)
|
|
392
483
|
drain()
|
|
393
484
|
|
|
394
485
|
App:navigate(url, push = true)
|
|
@@ -449,6 +540,12 @@ App:selectTemplate(path)
|
|
|
449
540
|
|
|
450
541
|
App:command(form, cmd)
|
|
451
542
|
switch cmd.type
|
|
543
|
+
case "loginSatisfied"
|
|
544
|
+
finishLogin(form, cmd.userId)
|
|
545
|
+
case "cancelLogin"
|
|
546
|
+
if @login == null or !@login.form.related(form)
|
|
547
|
+
throw "cancelLogin requires the active login form"
|
|
548
|
+
@login.cancelled = true
|
|
452
549
|
case "values"
|
|
453
550
|
form.setValue(cmd.values)
|
|
454
551
|
case "addRow"
|
|
@@ -525,6 +622,7 @@ App:command(form, cmd)
|
|
|
525
622
|
|
|
526
623
|
App:dispose()
|
|
527
624
|
@disposed = true
|
|
625
|
+
cancelLogin()
|
|
528
626
|
if @heartbeat != null
|
|
529
627
|
@heartbeat.dispose()
|
|
530
628
|
if @reporter != null
|
|
@@ -538,3 +636,219 @@ App:dispose()
|
|
|
538
636
|
release()
|
|
539
637
|
@resources = []
|
|
540
638
|
return null
|
|
639
|
+
|
|
640
|
+
App:sendInput(job, input)
|
|
641
|
+
form = job.form
|
|
642
|
+
recover = @login == null or !@login.form.related(form)
|
|
643
|
+
return chain request(job.url, input, form.token, null, false, false, recover)
|
|
644
|
+
then(packet)
|
|
645
|
+
capture job
|
|
646
|
+
capture input
|
|
647
|
+
if packet.needLogin == null
|
|
648
|
+
return packet
|
|
649
|
+
return resumeInput(job, input, packet.needLogin)
|
|
650
|
+
|
|
651
|
+
App:resumeInput(job, input, challenge)
|
|
652
|
+
return chain needLogin(job, challenge)
|
|
653
|
+
then(identity)
|
|
654
|
+
capture job
|
|
655
|
+
capture input
|
|
656
|
+
form = job.form
|
|
657
|
+
if form.disposed or form.stale or @externalStale or (job.owner != null and !job.owner.active)
|
|
658
|
+
throw "Pending login request is no longer active"
|
|
659
|
+
job.authVersion = @authVersion
|
|
660
|
+
return request(job.url, input, identity.token, null, false, false, false, identity.expected)
|
|
661
|
+
|
|
662
|
+
App:needLogin(job, challenge)
|
|
663
|
+
if @events.needLoginUrl == null
|
|
664
|
+
throw "Login is required but no needLogin event is configured"
|
|
665
|
+
session = @login
|
|
666
|
+
if session != null and session.originalToken != job.form.token
|
|
667
|
+
invalidateForm(job.form)
|
|
668
|
+
throw "SessionChanged: another form is awaiting login"
|
|
669
|
+
if session == null
|
|
670
|
+
deferred = Promise/withResolvers()
|
|
671
|
+
scope = new Form(@this, null, job.form.token)
|
|
672
|
+
session = {
|
|
673
|
+
form: scope
|
|
674
|
+
source: job.form
|
|
675
|
+
promise: deferred.promise
|
|
676
|
+
resolve: deferred.resolve
|
|
677
|
+
reject: deferred.reject
|
|
678
|
+
release: null
|
|
679
|
+
ready: null
|
|
680
|
+
cancelled: false
|
|
681
|
+
change: null
|
|
682
|
+
originalToken: job.form.token
|
|
683
|
+
}
|
|
684
|
+
chain session.promise
|
|
685
|
+
catch(problem)
|
|
686
|
+
return null
|
|
687
|
+
@login = session
|
|
688
|
+
pausePolls()
|
|
689
|
+
try
|
|
690
|
+
cancel = ()
|
|
691
|
+
cancelLogin()
|
|
692
|
+
session.release = @renderer.openLogin(scope, cancel)
|
|
693
|
+
chain post(@events.needLoginUrl, challenge, scope.token)
|
|
694
|
+
then(packet)
|
|
695
|
+
capture session
|
|
696
|
+
if @login == session and !session.form.disposed
|
|
697
|
+
session.form.handle(packet)
|
|
698
|
+
catch(problem)
|
|
699
|
+
capture session
|
|
700
|
+
if @login == session
|
|
701
|
+
cancelLogin(problem)
|
|
702
|
+
catch problem
|
|
703
|
+
cancelLogin(problem)
|
|
704
|
+
return chain session.promise
|
|
705
|
+
then(identity)
|
|
706
|
+
capture challenge
|
|
707
|
+
if challenge.userId != null and identity.userId != challenge.userId
|
|
708
|
+
for @forms.slice() as form
|
|
709
|
+
invalidateForm(form)
|
|
710
|
+
throw "IdentityChanged"
|
|
711
|
+
return {
|
|
712
|
+
token: identity.token
|
|
713
|
+
expected: challenge.userId
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
App:finishLogin(form, userId)
|
|
717
|
+
session = @login
|
|
718
|
+
if session == null or !session.form.related(form) or form.token == null
|
|
719
|
+
throw "loginSatisfied requires an active login form and token"
|
|
720
|
+
if @active.length == 0
|
|
721
|
+
throw "No request is waiting for login"
|
|
722
|
+
session.ready = {
|
|
723
|
+
token: form.token
|
|
724
|
+
userId: userId
|
|
725
|
+
}
|
|
726
|
+
return null
|
|
727
|
+
|
|
728
|
+
App:completeLogin(form)
|
|
729
|
+
session = @login
|
|
730
|
+
if session == null or !session.form.related(form)
|
|
731
|
+
return null
|
|
732
|
+
if session.cancelled
|
|
733
|
+
return cancelLogin()
|
|
734
|
+
if session.ready == null
|
|
735
|
+
return null
|
|
736
|
+
@login = null
|
|
737
|
+
identity = session.ready
|
|
738
|
+
change = session.change
|
|
739
|
+
if !is_string(change) or !change.startsWith("v1:")
|
|
740
|
+
change = "v1:${crypto/randomUUID()}"
|
|
741
|
+
commitAuthentication(session.source, session.originalToken, identity.token, change)
|
|
742
|
+
session.resolve(identity)
|
|
743
|
+
if session.release != null
|
|
744
|
+
release = session.release
|
|
745
|
+
release()
|
|
746
|
+
session.form.dispose()
|
|
747
|
+
drain()
|
|
748
|
+
return null
|
|
749
|
+
|
|
750
|
+
App:cancelLogin(problem = "LoginCancelled")
|
|
751
|
+
session = @login
|
|
752
|
+
if session == null
|
|
753
|
+
return null
|
|
754
|
+
@login = null
|
|
755
|
+
session.reject(problem)
|
|
756
|
+
if session.release != null
|
|
757
|
+
release = session.release
|
|
758
|
+
release()
|
|
759
|
+
session.form.dispose()
|
|
760
|
+
drain()
|
|
761
|
+
return null
|
|
762
|
+
|
|
763
|
+
App:loginScopeDisposed(form)
|
|
764
|
+
if @login != null and (@login.form == form or @login.source == form)
|
|
765
|
+
cancelLogin()
|
|
766
|
+
return null
|
|
767
|
+
|
|
768
|
+
App:acceptEvents(events)
|
|
769
|
+
if !is_object(events) or is_array(events)
|
|
770
|
+
throw "Startup events must be a map"
|
|
771
|
+
if events.needLoginUrl != null
|
|
772
|
+
checkUrl(events.needLoginUrl)
|
|
773
|
+
@events = events
|
|
774
|
+
return null
|
|
775
|
+
|
|
776
|
+
App:beginLoginResponse(form, packet)
|
|
777
|
+
if @login != null and @login.form.related(form)
|
|
778
|
+
@login.change = packet.authChange
|
|
779
|
+
@login.ready = null
|
|
780
|
+
@login.cancelled = false
|
|
781
|
+
return null
|
|
782
|
+
|
|
783
|
+
App:observeAuthentication(form, previous, packet)
|
|
784
|
+
change = packet.authChange
|
|
785
|
+
if @login != null and @login.form.related(form)
|
|
786
|
+
return null
|
|
787
|
+
if is_string(change) and change.startsWith("v1:") and !@authChanges.includes(change)
|
|
788
|
+
commitAuthentication(form, previous, packet.token, change)
|
|
789
|
+
return null
|
|
790
|
+
|
|
791
|
+
App:commitAuthentication(source, previous, token, change)
|
|
792
|
+
if @disposed or @authChanges.includes(change)
|
|
793
|
+
return null
|
|
794
|
+
previousChange = @storageChange
|
|
795
|
+
@storageChange = change
|
|
796
|
+
@authChanges.add(change)
|
|
797
|
+
if @authChanges.length > 64
|
|
798
|
+
@authChanges.shift()
|
|
799
|
+
@authVersion = @authVersion + 1
|
|
800
|
+
@committingAuthentication = true
|
|
801
|
+
for @forms.slice() as form
|
|
802
|
+
if form.disposed or form.stale
|
|
803
|
+
continue
|
|
804
|
+
if form == source or form.token == previous or form.token == token
|
|
805
|
+
form.setToken(token)
|
|
806
|
+
else
|
|
807
|
+
invalidateForm(form)
|
|
808
|
+
@committingAuthentication = false
|
|
809
|
+
try
|
|
810
|
+
@host.storage.setItem("lango.authChange", change)
|
|
811
|
+
if previousChange != null and @host.storage.removeItem != null
|
|
812
|
+
@host.storage.removeItem("lango.token:${previousChange}")
|
|
813
|
+
catch problem
|
|
814
|
+
return null
|
|
815
|
+
return null
|
|
816
|
+
|
|
817
|
+
App:externalAuthentication(change)
|
|
818
|
+
if @disposed or !is_string(change) or !change.startsWith("v1:") or @authChanges.includes(change)
|
|
819
|
+
return null
|
|
820
|
+
@authChanges.add(change)
|
|
821
|
+
if @authChanges.length > 64
|
|
822
|
+
@authChanges.shift()
|
|
823
|
+
@storageChange = change
|
|
824
|
+
@externalStale = true
|
|
825
|
+
@authVersion = @authVersion + 1
|
|
826
|
+
cancelLogin("SessionChanged: authentication changed in another tab")
|
|
827
|
+
if @heartbeat != null
|
|
828
|
+
@heartbeat.dispose()
|
|
829
|
+
if @root == null and @host.mount != null
|
|
830
|
+
@root = new Form(@this)
|
|
831
|
+
@root.element = @host.mount
|
|
832
|
+
for @forms.slice() as form
|
|
833
|
+
invalidateForm(form)
|
|
834
|
+
return null
|
|
835
|
+
|
|
836
|
+
App:invalidateForm(form)
|
|
837
|
+
if form.disposed or form.stale
|
|
838
|
+
return null
|
|
839
|
+
form.stale = true
|
|
840
|
+
form.activity.clear()
|
|
841
|
+
parent = form.parent
|
|
842
|
+
loop while parent != null
|
|
843
|
+
if parent.stale
|
|
844
|
+
return null
|
|
845
|
+
parent = parent.parent
|
|
846
|
+
if @renderer.sessionChanged != null
|
|
847
|
+
@renderer.sessionChanged(form)
|
|
848
|
+
return null
|
|
849
|
+
|
|
850
|
+
App:reloadSession()
|
|
851
|
+
if @host.reload == null
|
|
852
|
+
throw "Reload the page to continue"
|
|
853
|
+
@host.reload()
|
|
854
|
+
return null
|
package/src/form.lango
CHANGED
|
@@ -13,6 +13,7 @@ export class Form(app, parent = null, token = null)
|
|
|
13
13
|
owned
|
|
14
14
|
inheritedNames
|
|
15
15
|
disposed
|
|
16
|
+
stale
|
|
16
17
|
element
|
|
17
18
|
resources
|
|
18
19
|
activity
|
|
@@ -44,6 +45,7 @@ Form(app, parent = null, token = null)
|
|
|
44
45
|
@owned = []
|
|
45
46
|
@inheritedNames = []
|
|
46
47
|
@disposed = false
|
|
48
|
+
@stale = false
|
|
47
49
|
@element = null
|
|
48
50
|
@resources = []
|
|
49
51
|
@activity = new Activities(@this)
|
|
@@ -145,8 +147,9 @@ Form:clearResources()
|
|
|
145
147
|
|
|
146
148
|
Form:setToken(token)
|
|
147
149
|
if token != null
|
|
150
|
+
if @app.saveToken(token) == false
|
|
151
|
+
return @this
|
|
148
152
|
@token = token
|
|
149
|
-
@app.saveToken(token)
|
|
150
153
|
if @app.heartbeat != null
|
|
151
154
|
@app.heartbeat.observe(token)
|
|
152
155
|
return @this
|
|
@@ -155,15 +158,21 @@ Form:send(url)
|
|
|
155
158
|
return @app.send(@this, url)
|
|
156
159
|
|
|
157
160
|
Form:handle(packet)
|
|
158
|
-
if @disposed
|
|
161
|
+
if @disposed or @stale
|
|
159
162
|
return null
|
|
163
|
+
previous = @token
|
|
164
|
+
@app.beginLoginResponse(@this, packet)
|
|
160
165
|
setToken(packet.token)
|
|
166
|
+
if @stale
|
|
167
|
+
return null
|
|
161
168
|
body = packet.body
|
|
162
169
|
if body.view != null
|
|
163
170
|
@app.renderer.show(@this, body.view)
|
|
164
171
|
if body.cmds != null
|
|
165
172
|
for body.cmds as cmd
|
|
166
173
|
@app.command(@this, cmd)
|
|
174
|
+
@app.completeLogin(@this)
|
|
175
|
+
@app.observeAuthentication(@this, previous, packet)
|
|
167
176
|
return null
|
|
168
177
|
|
|
169
178
|
Form:related(other)
|
|
@@ -183,6 +192,7 @@ Form:dispose()
|
|
|
183
192
|
if @disposed
|
|
184
193
|
return null
|
|
185
194
|
@disposed = true
|
|
195
|
+
@app.loginScopeDisposed(@this)
|
|
186
196
|
for @owned.slice() as control
|
|
187
197
|
control.dispose()
|
|
188
198
|
clearResources()
|
package/src/heartbeat.lango
CHANGED
|
@@ -41,7 +41,7 @@ Heartbeat:observe(token)
|
|
|
41
41
|
Heartbeat:live()
|
|
42
42
|
result = []
|
|
43
43
|
for @app.forms as form
|
|
44
|
-
if !form.disposed and form.token != null and !result.includes(form.token)
|
|
44
|
+
if !form.disposed and !form.stale and form.token != null and !result.includes(form.token)
|
|
45
45
|
result.add(form.token)
|
|
46
46
|
return result
|
|
47
47
|
|
|
@@ -152,7 +152,7 @@ Heartbeat:apply(tokens, results)
|
|
|
152
152
|
seen.add(item.previous)
|
|
153
153
|
for results as item
|
|
154
154
|
for @app.forms.slice() as form
|
|
155
|
-
if !form.disposed and form.token == item.previous
|
|
155
|
+
if !form.disposed and !form.stale and form.token == item.previous
|
|
156
156
|
if item.status == 200
|
|
157
157
|
form.setToken(item.token)
|
|
158
158
|
else
|
package/src/main.lango
CHANGED
|
@@ -22,6 +22,7 @@ start()
|
|
|
22
22
|
catch error
|
|
23
23
|
storage = storage
|
|
24
24
|
app = new App({
|
|
25
|
+
reload: reload
|
|
25
26
|
storage: storage
|
|
26
27
|
mount: document/querySelector("#app")
|
|
27
28
|
location: window.location
|
|
@@ -58,6 +59,12 @@ start()
|
|
|
58
59
|
capture app
|
|
59
60
|
if app.reporter != null
|
|
60
61
|
app.reporter.capture("promise", "UnhandledRejection", null, app.root)
|
|
62
|
+
changed = (event)
|
|
63
|
+
capture app
|
|
64
|
+
capture storage
|
|
65
|
+
if event.key == "lango.authChange" and event.storageArea == storage
|
|
66
|
+
app.externalAuthentication(event.newValue)
|
|
67
|
+
window.addEventListener("storage", changed)
|
|
61
68
|
document/addEventListener("click", click)
|
|
62
69
|
window.addEventListener("popstate", pop)
|
|
63
70
|
window.addEventListener("error", windowError)
|
|
@@ -66,10 +73,12 @@ start()
|
|
|
66
73
|
then(ignored)
|
|
67
74
|
capture app
|
|
68
75
|
release = ()
|
|
76
|
+
capture changed
|
|
69
77
|
capture click
|
|
70
78
|
capture pop
|
|
71
79
|
capture windowError
|
|
72
80
|
capture rejection
|
|
81
|
+
window.removeEventListener("storage", changed)
|
|
73
82
|
document/removeEventListener("click", click)
|
|
74
83
|
window.removeEventListener("popstate", pop)
|
|
75
84
|
window.removeEventListener("error", windowError)
|
|
@@ -79,10 +88,12 @@ start()
|
|
|
79
88
|
return app
|
|
80
89
|
catch(error)
|
|
81
90
|
capture app
|
|
91
|
+
capture changed
|
|
82
92
|
capture click
|
|
83
93
|
capture pop
|
|
84
94
|
capture windowError
|
|
85
95
|
capture rejection
|
|
96
|
+
window.removeEventListener("storage", changed)
|
|
86
97
|
document/removeEventListener("click", click)
|
|
87
98
|
window.removeEventListener("popstate", pop)
|
|
88
99
|
window.removeEventListener("error", windowError)
|
|
@@ -116,3 +127,7 @@ screenMode()
|
|
|
116
127
|
if media.matches
|
|
117
128
|
return "wide"
|
|
118
129
|
return "narrow"
|
|
130
|
+
|
|
131
|
+
reload()
|
|
132
|
+
window.location.reload()
|
|
133
|
+
return null
|