@base316/react 0.1.0 → 0.3.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/CHANGELOG.md +53 -0
- package/README.md +29 -15
- package/dist/index.cjs +4361 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4344 -164
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1176 -0
- package/dist/src/AcceptInvitation.d.ts +27 -0
- package/dist/src/AcceptInvitation.d.ts.map +1 -0
- package/dist/src/ActiveSessions.d.ts +21 -0
- package/dist/src/ActiveSessions.d.ts.map +1 -0
- package/dist/src/ApiKeyManager.d.ts +22 -0
- package/dist/src/ApiKeyManager.d.ts.map +1 -0
- package/dist/src/Chart.d.ts +42 -0
- package/dist/src/Chart.d.ts.map +1 -0
- package/dist/src/DataTable.d.ts +56 -0
- package/dist/src/DataTable.d.ts.map +1 -0
- package/dist/src/DeviceApproval.d.ts +30 -0
- package/dist/src/DeviceApproval.d.ts.map +1 -0
- package/dist/src/ForgotPassword.d.ts +24 -0
- package/dist/src/ForgotPassword.d.ts.map +1 -0
- package/dist/src/Invoices.d.ts.map +1 -1
- package/dist/src/Kanban.d.ts +40 -0
- package/dist/src/Kanban.d.ts.map +1 -0
- package/dist/src/PasskeyManager.d.ts.map +1 -1
- package/dist/src/PayInvoice.d.ts +41 -0
- package/dist/src/PayInvoice.d.ts.map +1 -0
- package/dist/src/PricingTable.d.ts +43 -11
- package/dist/src/PricingTable.d.ts.map +1 -1
- package/dist/src/PrivacyControls.d.ts +28 -0
- package/dist/src/PrivacyControls.d.ts.map +1 -0
- package/dist/src/RecordDetail.d.ts +31 -0
- package/dist/src/RecordDetail.d.ts.map +1 -0
- package/dist/src/RecordForm.d.ts +32 -0
- package/dist/src/RecordForm.d.ts.map +1 -0
- package/dist/src/RelationPicker.d.ts +23 -0
- package/dist/src/RelationPicker.d.ts.map +1 -0
- package/dist/src/ResetPassword.d.ts +24 -0
- package/dist/src/ResetPassword.d.ts.map +1 -0
- package/dist/src/SignIn.d.ts +20 -2
- package/dist/src/SignIn.d.ts.map +1 -1
- package/dist/src/SignUp.d.ts.map +1 -1
- package/dist/src/SubscriptionManager.d.ts.map +1 -1
- package/dist/src/TeamMembers.d.ts +49 -0
- package/dist/src/TeamMembers.d.ts.map +1 -0
- package/dist/src/TwoFactorManager.d.ts +38 -0
- package/dist/src/TwoFactorManager.d.ts.map +1 -0
- package/dist/src/VerifyEmail.d.ts +24 -0
- package/dist/src/VerifyEmail.d.ts.map +1 -0
- package/dist/src/appearance.d.ts +2 -2
- package/dist/src/appearance.d.ts.map +1 -1
- package/dist/src/confirm.d.ts +32 -0
- package/dist/src/confirm.d.ts.map +1 -0
- package/dist/src/fields.d.ts +44 -0
- package/dist/src/fields.d.ts.map +1 -0
- package/dist/src/manifest.d.ts +84 -0
- package/dist/src/manifest.d.ts.map +1 -0
- package/dist/src/provider.d.ts +13 -1
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/test/harness.d.ts +204 -0
- package/dist/src/test/harness.d.ts.map +1 -0
- package/dist/src/test/setup.d.ts +2 -0
- package/dist/src/test/setup.d.ts.map +1 -0
- package/dist/src/useCollection.d.ts +79 -0
- package/dist/src/useCollection.d.ts.map +1 -0
- package/dist/src/usePaymentLink.d.ts +41 -0
- package/dist/src/usePaymentLink.d.ts.map +1 -0
- package/dist/src/usePlans.d.ts +74 -0
- package/dist/src/usePlans.d.ts.map +1 -0
- package/package.json +36 -28
package/dist/index.js
CHANGED
|
@@ -27,13 +27,13 @@ var VARIABLES = {
|
|
|
27
27
|
fontSize: "--b316-font-size",
|
|
28
28
|
spacing: "--b316-spacing"
|
|
29
29
|
};
|
|
30
|
-
function appearanceToStyle(
|
|
31
|
-
if (!
|
|
30
|
+
function appearanceToStyle(appearance2) {
|
|
31
|
+
if (!appearance2) {
|
|
32
32
|
return {};
|
|
33
33
|
}
|
|
34
34
|
const style = {};
|
|
35
35
|
for (const [key, variable] of Object.entries(VARIABLES)) {
|
|
36
|
-
const value =
|
|
36
|
+
const value = appearance2[key];
|
|
37
37
|
if (value !== void 0) {
|
|
38
38
|
style[variable] = value;
|
|
39
39
|
}
|
|
@@ -119,6 +119,18 @@ var STYLESHEET = `
|
|
|
119
119
|
text-decoration: underline;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
/*
|
|
123
|
+
* An armed confirmation: the question and its way out, side by side.
|
|
124
|
+
*
|
|
125
|
+
* Inline rather than a dialog, because a sandboxed iframe does not get dialogs
|
|
126
|
+
* and these components are meant to be embedded in one.
|
|
127
|
+
*/
|
|
128
|
+
.b316-confirm {
|
|
129
|
+
display: inline-flex;
|
|
130
|
+
gap: .4rem;
|
|
131
|
+
align-items: center;
|
|
132
|
+
}
|
|
133
|
+
|
|
122
134
|
.b316-error {
|
|
123
135
|
background: var(--b316-color-danger-bg);
|
|
124
136
|
color: var(--b316-color-danger);
|
|
@@ -138,6 +150,10 @@ var STYLESHEET = `
|
|
|
138
150
|
align-items: stretch;
|
|
139
151
|
}
|
|
140
152
|
|
|
153
|
+
/* Messages above the cards span the row rather than taking a card's column. */
|
|
154
|
+
.b316-plans-error,
|
|
155
|
+
.b316-plans-managed { grid-column: 1 / -1; }
|
|
156
|
+
|
|
141
157
|
.b316-plan {
|
|
142
158
|
display: flex;
|
|
143
159
|
flex-direction: column;
|
|
@@ -227,11 +243,88 @@ var STYLESHEET = `
|
|
|
227
243
|
}
|
|
228
244
|
|
|
229
245
|
.b316-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
|
|
246
|
+
|
|
247
|
+
/* Credential lists. A row is a thing plus the actions on it, and the actions
|
|
248
|
+
stay put as names vary in length, so the eye tracks one column not two. */
|
|
249
|
+
.b316-list { list-style: none; margin: 0; padding: 0; }
|
|
250
|
+
|
|
251
|
+
.b316-list-item {
|
|
252
|
+
display: flex;
|
|
253
|
+
justify-content: space-between;
|
|
254
|
+
align-items: flex-start;
|
|
255
|
+
gap: 16px;
|
|
256
|
+
padding: 12px 0;
|
|
257
|
+
border-top: 1px solid var(--b316-color-border);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.b316-list-item:first-child { border-top: none; }
|
|
261
|
+
|
|
262
|
+
/* Carries a secret shown exactly once, so it has to read as different from the
|
|
263
|
+
rest of the card rather than as another paragraph. */
|
|
264
|
+
.b316-notice {
|
|
265
|
+
border: 1px solid var(--b316-color-border);
|
|
266
|
+
border-radius: var(--b316-radius);
|
|
267
|
+
background: var(--b316-color-subtle, rgba(0,0,0,0.03));
|
|
268
|
+
padding: 12px;
|
|
269
|
+
font-size: 0.93em;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.b316-checkbox {
|
|
273
|
+
display: flex;
|
|
274
|
+
align-items: baseline;
|
|
275
|
+
gap: 8px;
|
|
276
|
+
padding: 4px 0;
|
|
277
|
+
cursor: pointer;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.b316-checkbox input[disabled] { cursor: default; }
|
|
281
|
+
.b316-checkbox.b316-muted { cursor: default; }
|
|
230
282
|
`;
|
|
231
283
|
function cls(base, extra) {
|
|
232
284
|
return extra ? `${base} ${extra}` : base;
|
|
233
285
|
}
|
|
234
286
|
var STYLESHEET_EXTRA = `
|
|
287
|
+
.b316-pay__element { margin-bottom: var(--b316-spacing); min-height: 40px; }
|
|
288
|
+
|
|
289
|
+
.b316-pay__submit {
|
|
290
|
+
width: 100%;
|
|
291
|
+
padding: 11px 14px;
|
|
292
|
+
border: 0;
|
|
293
|
+
border-radius: calc(var(--b316-radius) / 1.6);
|
|
294
|
+
background: var(--b316-color-primary);
|
|
295
|
+
color: #fff;
|
|
296
|
+
font: inherit;
|
|
297
|
+
font-weight: 600;
|
|
298
|
+
cursor: pointer;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.b316-pay__submit[disabled] { opacity: 0.55; cursor: progress; }
|
|
302
|
+
|
|
303
|
+
.b316-pay__error {
|
|
304
|
+
background: var(--b316-color-danger-bg);
|
|
305
|
+
color: var(--b316-color-danger);
|
|
306
|
+
padding: 8px 10px;
|
|
307
|
+
border-radius: calc(var(--b316-radius) / 2);
|
|
308
|
+
font-size: 0.9em;
|
|
309
|
+
margin-bottom: var(--b316-spacing);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
.b316-pay__done {
|
|
313
|
+
background: var(--b316-color-success-bg, #f0fdf4);
|
|
314
|
+
color: var(--b316-color-success);
|
|
315
|
+
padding: 12px 14px;
|
|
316
|
+
border-radius: calc(var(--b316-radius) / 2);
|
|
317
|
+
text-align: center;
|
|
318
|
+
margin: 0;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
.b316-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--b316-color-border); }
|
|
322
|
+
.b316-tab {
|
|
323
|
+
flex: 1; padding: 8px 4px; background: none; border: 0; cursor: pointer;
|
|
324
|
+
font: inherit; font-size: .95em; color: var(--b316-color-muted);
|
|
325
|
+
border-bottom: 2px solid transparent; margin-bottom: -1px;
|
|
326
|
+
}
|
|
327
|
+
.b316-tab-on { color: var(--b316-color-text); border-bottom-color: var(--b316-color-primary); }
|
|
235
328
|
.b316-branding { display: flex; flex-direction: column; gap: 4px; }
|
|
236
329
|
.b316-branding-logo { max-height: 40px; width: auto; align-self: flex-start; }
|
|
237
330
|
.b316-branding-name { font-size: 1.5em; font-weight: 650; letter-spacing: -.01em; }
|
|
@@ -267,12 +360,24 @@ var STYLESHEET_EXTRA = `
|
|
|
267
360
|
.b316-invoice-totals { display: flex; flex-direction: column; gap: 6px; margin-left: auto; min-width: 240px; }
|
|
268
361
|
.b316-invoice-total { font-weight: 650; border-top: 1px solid var(--b316-color-border); padding-top: 6px; }
|
|
269
362
|
|
|
270
|
-
/* Printing emits the invoice alone
|
|
271
|
-
|
|
363
|
+
/* Printing an invoice emits the invoice alone, and printing anything else is
|
|
364
|
+
none of this package's business.
|
|
365
|
+
|
|
366
|
+
This used to start with a bare "body * { visibility: hidden }", which is the
|
|
367
|
+
usual recipe for printing one element \u2014 and it is scoped to the document,
|
|
368
|
+
not to us. The stylesheet is injected into the host page's head the first
|
|
369
|
+
time any Base316 component mounts, so from that moment every print in the
|
|
370
|
+
host application came out blank unless the content happened to sit inside
|
|
371
|
+
.b316-invoice-doc. A customer printing their own page had no way to connect
|
|
372
|
+
it back to us.
|
|
373
|
+
|
|
374
|
+
Scoped to a root the invoice sets on <html> while it is being printed
|
|
375
|
+
instead, so nothing applies unless an invoice asked for it. */
|
|
272
376
|
@media print {
|
|
273
|
-
body * { visibility: hidden; }
|
|
274
|
-
|
|
275
|
-
.b316-invoice-doc {
|
|
377
|
+
[data-b316-printing] body * { visibility: hidden; }
|
|
378
|
+
[data-b316-printing] .b316-invoice-doc,
|
|
379
|
+
[data-b316-printing] .b316-invoice-doc * { visibility: visible; }
|
|
380
|
+
[data-b316-printing] .b316-invoice-doc {
|
|
276
381
|
position: absolute;
|
|
277
382
|
inset: 0 auto auto 0;
|
|
278
383
|
width: 100%;
|
|
@@ -280,6 +385,208 @@ var STYLESHEET_EXTRA = `
|
|
|
280
385
|
}
|
|
281
386
|
.b316-invoice-actions { display: none; }
|
|
282
387
|
}
|
|
388
|
+
|
|
389
|
+
/* --- Collections: tables, forms and detail views ------------------------- */
|
|
390
|
+
|
|
391
|
+
.b316-table-wrap { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
392
|
+
.b316-table-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--b316-spacing); flex-wrap: wrap; }
|
|
393
|
+
.b316-table-actions { display: flex; align-items: center; gap: var(--b316-spacing); }
|
|
394
|
+
|
|
395
|
+
/* The table scrolls inside its own box rather than pushing the page sideways:
|
|
396
|
+
a collection with twenty fields is normal, and a horizontally scrolling page
|
|
397
|
+
makes every other component on it unreachable. */
|
|
398
|
+
.b316-table-scroll { overflow-x: auto; border: 1px solid var(--b316-color-border); border-radius: var(--b316-radius); }
|
|
399
|
+
.b316-table { width: 100%; border-collapse: collapse; font-size: 0.95em; }
|
|
400
|
+
.b316-table th, .b316-table td { padding: 10px 12px; text-align: left; vertical-align: top; white-space: nowrap; }
|
|
401
|
+
.b316-table thead th { background: var(--b316-color-surface-muted, rgba(0,0,0,.03)); font-weight: 600; font-size: 0.87em; color: var(--b316-color-muted); border-bottom: 1px solid var(--b316-color-border); }
|
|
402
|
+
.b316-table tbody tr + tr td { border-top: 1px solid var(--b316-color-border); }
|
|
403
|
+
.b316-row-clickable { cursor: pointer; }
|
|
404
|
+
.b316-row-clickable:hover td { background: var(--b316-color-surface-muted, rgba(0,0,0,.02)); }
|
|
405
|
+
.b316-table-rowactions { text-align: right; white-space: nowrap; }
|
|
406
|
+
.b316-table-more { display: flex; justify-content: center; }
|
|
407
|
+
|
|
408
|
+
.b316-sort { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
|
|
409
|
+
.b316-sort:focus-visible { outline: 2px solid var(--b316-color-primary); outline-offset: 2px; }
|
|
410
|
+
|
|
411
|
+
.b316-empty { padding: calc(var(--b316-spacing) * 2); text-align: center; color: var(--b316-color-muted); }
|
|
412
|
+
|
|
413
|
+
.b316-button-quiet {
|
|
414
|
+
background: none;
|
|
415
|
+
border: 0;
|
|
416
|
+
padding: 4px 6px;
|
|
417
|
+
font: inherit;
|
|
418
|
+
font-size: 0.9em;
|
|
419
|
+
color: var(--b316-color-primary);
|
|
420
|
+
cursor: pointer;
|
|
421
|
+
border-radius: calc(var(--b316-radius) / 2);
|
|
422
|
+
}
|
|
423
|
+
.b316-button-quiet:hover:not([disabled]) { background: var(--b316-color-surface-muted, rgba(0,0,0,.05)); }
|
|
424
|
+
.b316-button-quiet:focus-visible { outline: 2px solid var(--b316-color-primary); outline-offset: 1px; }
|
|
425
|
+
.b316-button-quiet[disabled] { opacity: .55; cursor: not-allowed; }
|
|
426
|
+
.b316-danger { color: var(--b316-color-danger, #b42318); }
|
|
427
|
+
|
|
428
|
+
.b316-chip {
|
|
429
|
+
display: inline-block;
|
|
430
|
+
padding: 2px 8px;
|
|
431
|
+
border-radius: 999px;
|
|
432
|
+
background: var(--b316-color-surface-muted, rgba(0,0,0,.05));
|
|
433
|
+
font-size: 0.87em;
|
|
434
|
+
}
|
|
435
|
+
.b316-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
|
|
436
|
+
|
|
437
|
+
.b316-form { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
438
|
+
.b316-form-title { margin: 0; font-size: 1.05em; }
|
|
439
|
+
.b316-form-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
440
|
+
.b316-field { display: flex; flex-direction: column; gap: 4px; }
|
|
441
|
+
.b316-hint { font-size: 0.82em; color: var(--b316-color-muted); }
|
|
442
|
+
.b316-input-invalid { border-color: var(--b316-color-danger, #b42318); }
|
|
443
|
+
.b316-choices { display: flex; flex-wrap: wrap; gap: 10px; }
|
|
444
|
+
.b316-choice { display: inline-flex; align-items: center; gap: 6px; font-size: 0.95em; }
|
|
445
|
+
.b316-suffixed { display: flex; align-items: center; gap: 8px; }
|
|
446
|
+
.b316-address { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
|
|
447
|
+
|
|
448
|
+
.b316-relation-chosen { display: flex; align-items: center; gap: 8px; }
|
|
449
|
+
.b316-relation-results {
|
|
450
|
+
list-style: none;
|
|
451
|
+
margin: 4px 0 0;
|
|
452
|
+
padding: 4px;
|
|
453
|
+
border: 1px solid var(--b316-color-border);
|
|
454
|
+
border-radius: var(--b316-radius);
|
|
455
|
+
max-height: 220px;
|
|
456
|
+
overflow-y: auto;
|
|
457
|
+
background: var(--b316-color-surface, #fff);
|
|
458
|
+
}
|
|
459
|
+
.b316-relation-result { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; font: inherit; cursor: pointer; border-radius: calc(var(--b316-radius) / 2); }
|
|
460
|
+
.b316-relation-result:hover, .b316-relation-result:focus-visible { background: var(--b316-color-surface-muted, rgba(0,0,0,.05)); outline: none; }
|
|
461
|
+
.b316-relation-empty { padding: 6px 8px; }
|
|
462
|
+
|
|
463
|
+
.b316-detail { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
464
|
+
.b316-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--b316-spacing); }
|
|
465
|
+
.b316-detail-title { margin: 0; font-size: 1.1em; }
|
|
466
|
+
.b316-detail-actions { display: flex; gap: 4px; }
|
|
467
|
+
.b316-detail-fields { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: 8px var(--b316-spacing); margin: 0; }
|
|
468
|
+
.b316-detail-row { display: contents; }
|
|
469
|
+
.b316-detail-fields dd { margin: 0; }
|
|
470
|
+
|
|
471
|
+
/* One column on a narrow screen. A label column of 200px beside a value leaves
|
|
472
|
+
nothing for the value on a phone. */
|
|
473
|
+
/* --- Teams --------------------------------------------------------------- */
|
|
474
|
+
|
|
475
|
+
.b316-team { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
476
|
+
.b316-team-title { margin: 0; font-size: 1em; font-weight: 600; }
|
|
477
|
+
.b316-team-subtitle { margin: 0; font-size: .9em; font-weight: 600; color: var(--b316-color-muted); }
|
|
478
|
+
.b316-team-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
|
|
479
|
+
.b316-team-member { display: flex; align-items: center; justify-content: space-between; gap: var(--b316-spacing); }
|
|
480
|
+
.b316-team-member-side { display: flex; align-items: center; gap: 8px; }
|
|
481
|
+
.b316-team-invite { display: flex; flex-direction: column; gap: 4px; }
|
|
482
|
+
.b316-team-invite-row { display: flex; gap: 8px; }
|
|
483
|
+
.b316-team-invite-row input { flex: 1; }
|
|
484
|
+
/* Selectable and wrapping: this is copied by hand and pasted into an email. */
|
|
485
|
+
.b316-team-link { display: flex; flex-direction: column; gap: 4px; }
|
|
486
|
+
.b316-team-link code { word-break: break-all; user-select: all; padding: 8px; border: 1px solid var(--b316-color-border); border-radius: var(--b316-radius); }
|
|
487
|
+
|
|
488
|
+
.b316-invitation { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
489
|
+
.b316-invitation-actions { display: flex; align-items: center; gap: var(--b316-spacing); }
|
|
490
|
+
|
|
491
|
+
/* --- Sessions, two-factor and the password flows ------------------------- */
|
|
492
|
+
|
|
493
|
+
.b316-sessions { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
494
|
+
.b316-sessions-head { display: flex; align-items: center; justify-content: space-between; gap: var(--b316-spacing); flex-wrap: wrap; }
|
|
495
|
+
.b316-sessions-title, .b316-mfa-title { margin: 0; font-size: 1em; font-weight: 600; }
|
|
496
|
+
.b316-sessions-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
|
|
497
|
+
.b316-session { display: flex; flex-direction: column; gap: 2px; }
|
|
498
|
+
.b316-session-device { display: flex; align-items: center; gap: 6px; font-size: 0.95em; }
|
|
499
|
+
|
|
500
|
+
.b316-device { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
501
|
+
.b316-device-title { margin: 0; font-size: 1em; font-weight: 600; }
|
|
502
|
+
/* What is being granted, listed rather than run together: somebody is deciding
|
|
503
|
+
on this, and a comma-separated line is read as one thing. */
|
|
504
|
+
.b316-device-scopes { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
|
|
505
|
+
.b316-device-scopes li { padding: 2px 8px; border-radius: 999px; font-size: 0.85em; background: var(--b316-color-surface-muted, rgba(0,0,0,.05)); }
|
|
506
|
+
.b316-device-actions { display: flex; gap: 8px; }
|
|
507
|
+
|
|
508
|
+
.b316-privacy { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
509
|
+
.b316-privacy-title { margin: 0; font-size: 1em; font-weight: 600; }
|
|
510
|
+
/* Wraps rather than squeezes: the explanation beside each control is the part
|
|
511
|
+
that matters, and on a narrow screen it belongs above the button. */
|
|
512
|
+
.b316-privacy-row { display: flex; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: 10px; }
|
|
513
|
+
.b316-privacy-row p { margin: 0; }
|
|
514
|
+
.b316-privacy-confirm { display: flex; flex-direction: column; gap: 8px; }
|
|
515
|
+
.b316-privacy-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
516
|
+
|
|
517
|
+
.b316-mfa { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
518
|
+
.b316-mfa-enrol, .b316-mfa-codes, .b316-mfa-on, .b316-mfa-off { display: flex; flex-direction: column; gap: 10px; }
|
|
519
|
+
.b316-mfa-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
520
|
+
/* Selectable and wrapping: this is copied by hand on the device that cannot
|
|
521
|
+
scan its own screen. */
|
|
522
|
+
.b316-mfa-secret code {
|
|
523
|
+
display: block;
|
|
524
|
+
padding: 10px;
|
|
525
|
+
border: 1px solid var(--b316-color-border);
|
|
526
|
+
border-radius: var(--b316-radius);
|
|
527
|
+
font-size: 1.05em;
|
|
528
|
+
letter-spacing: .08em;
|
|
529
|
+
word-break: break-all;
|
|
530
|
+
user-select: all;
|
|
531
|
+
}
|
|
532
|
+
.b316-mfa-uri { font-size: 0.9em; }
|
|
533
|
+
.b316-mfa-code-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
|
|
534
|
+
.b316-mfa-code-list code { user-select: all; }
|
|
535
|
+
|
|
536
|
+
@media (max-width: 560px) {
|
|
537
|
+
.b316-mfa-code-list { grid-template-columns: 1fr; }
|
|
538
|
+
.b316-detail-fields { grid-template-columns: 1fr; }
|
|
539
|
+
.b316-detail-row { display: block; margin-bottom: 10px; }
|
|
540
|
+
.b316-address { grid-template-columns: 1fr; }
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/* --- Board --------------------------------------------------------------- */
|
|
544
|
+
|
|
545
|
+
.b316-board-wrap { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
546
|
+
/* The board scrolls sideways inside itself. Six columns is normal and a page
|
|
547
|
+
that scrolls horizontally puts everything else on it out of reach. */
|
|
548
|
+
.b316-board { display: flex; gap: var(--b316-spacing); overflow-x: auto; align-items: flex-start; padding-bottom: 4px; }
|
|
549
|
+
.b316-board-column {
|
|
550
|
+
flex: 0 0 260px;
|
|
551
|
+
background: var(--b316-color-surface-muted, rgba(0,0,0,.03));
|
|
552
|
+
border: 1px solid transparent;
|
|
553
|
+
border-radius: var(--b316-radius);
|
|
554
|
+
padding: 10px;
|
|
555
|
+
display: flex;
|
|
556
|
+
flex-direction: column;
|
|
557
|
+
gap: 8px;
|
|
558
|
+
}
|
|
559
|
+
.b316-board-over { border-color: var(--b316-color-primary); }
|
|
560
|
+
.b316-board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
561
|
+
.b316-board-title { font-weight: 600; font-size: 0.92em; }
|
|
562
|
+
.b316-board-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
|
|
563
|
+
.b316-board-card {
|
|
564
|
+
background: var(--b316-color-surface, #fff);
|
|
565
|
+
border: 1px solid var(--b316-color-border);
|
|
566
|
+
border-radius: calc(var(--b316-radius) * .8);
|
|
567
|
+
padding: 10px;
|
|
568
|
+
display: flex;
|
|
569
|
+
flex-direction: column;
|
|
570
|
+
gap: 6px;
|
|
571
|
+
font-size: 0.9em;
|
|
572
|
+
}
|
|
573
|
+
.b316-board-card[draggable="true"] { cursor: grab; }
|
|
574
|
+
.b316-board-card-title { font-weight: 600; }
|
|
575
|
+
.b316-board-card-field { display: flex; justify-content: space-between; gap: 8px; }
|
|
576
|
+
.b316-board-move { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
|
|
577
|
+
.b316-board-move select { flex: 1; font-size: 0.9em; padding: 2px 4px; }
|
|
578
|
+
.b316-board-empty { color: var(--b316-color-muted); font-size: 0.87em; padding: 6px 2px; }
|
|
579
|
+
|
|
580
|
+
/* --- Chart --------------------------------------------------------------- */
|
|
581
|
+
|
|
582
|
+
.b316-chart { display: flex; flex-direction: column; gap: var(--b316-spacing); }
|
|
583
|
+
.b316-chart-title { font-weight: 600; font-size: 0.95em; }
|
|
584
|
+
.b316-chart-plot { display: flex; align-items: flex-end; gap: 4px; overflow-x: auto; }
|
|
585
|
+
.b316-chart-col { flex: 1 0 24px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
|
|
586
|
+
.b316-chart-bar { width: 100%; background: var(--b316-color-primary); border-radius: 3px 3px 0 0; min-height: 2px; }
|
|
587
|
+
.b316-chart-label { font-size: 0.7em; color: var(--b316-color-muted); white-space: nowrap; transform: rotate(-45deg); transform-origin: top left; height: 1.6em; }
|
|
588
|
+
.b316-chart-data summary { cursor: pointer; font-size: 0.87em; color: var(--b316-color-muted); }
|
|
589
|
+
.b316-chart-data table { margin-top: 8px; }
|
|
283
590
|
`;
|
|
284
591
|
|
|
285
592
|
// src/provider.tsx
|
|
@@ -308,7 +615,8 @@ function Base316Provider({
|
|
|
308
615
|
baseUrl,
|
|
309
616
|
token: controlledToken,
|
|
310
617
|
onTokenChange,
|
|
311
|
-
appearance,
|
|
618
|
+
appearance: appearance2,
|
|
619
|
+
tenant,
|
|
312
620
|
className,
|
|
313
621
|
children
|
|
314
622
|
}) {
|
|
@@ -337,16 +645,20 @@ function Base316Provider({
|
|
|
337
645
|
}
|
|
338
646
|
setInternalToken(readStoredToken());
|
|
339
647
|
}, [controlled]);
|
|
648
|
+
const tenantKey = tenant ? "organizationId" in tenant ? `id:${tenant.organizationId}` : `ext:${tenant.organizationExternalId}` : null;
|
|
340
649
|
useEffect(() => {
|
|
341
650
|
let cancelled = false;
|
|
342
|
-
client.billing.
|
|
651
|
+
const request = tenantKey ? client.billing.tenantBranding(
|
|
652
|
+
tenantKey.startsWith("id:") ? { organizationId: tenantKey.slice(3) } : { organizationExternalId: tenantKey.slice(4) }
|
|
653
|
+
) : client.billing.branding();
|
|
654
|
+
request.then((result) => {
|
|
343
655
|
if (!cancelled) setBranding(result);
|
|
344
656
|
}).catch(() => {
|
|
345
657
|
});
|
|
346
658
|
return () => {
|
|
347
659
|
cancelled = true;
|
|
348
660
|
};
|
|
349
|
-
}, [client]);
|
|
661
|
+
}, [client, tenantKey]);
|
|
350
662
|
const setToken = useCallback(
|
|
351
663
|
(next) => {
|
|
352
664
|
if (controlled) {
|
|
@@ -406,7 +718,7 @@ function Base316Provider({
|
|
|
406
718
|
colorPrimary: branding.primaryColor,
|
|
407
719
|
colorBackground: branding.backgroundColor
|
|
408
720
|
} : {},
|
|
409
|
-
...
|
|
721
|
+
...appearance2
|
|
410
722
|
}),
|
|
411
723
|
children
|
|
412
724
|
}
|
|
@@ -494,6 +806,9 @@ function Invoices({ className, style }) {
|
|
|
494
806
|
},
|
|
495
807
|
[client, token]
|
|
496
808
|
);
|
|
809
|
+
if (error) {
|
|
810
|
+
return /* @__PURE__ */ jsx3("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx3("div", { className: "b316-error", role: "alert", children: error }) });
|
|
811
|
+
}
|
|
497
812
|
if (sessionLoading || invoices === null) {
|
|
498
813
|
return /* @__PURE__ */ jsx3("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
499
814
|
}
|
|
@@ -504,7 +819,7 @@ function Invoices({ className, style }) {
|
|
|
504
819
|
return /* @__PURE__ */ jsx3("div", { className: cls("b316-card", className), style, children: "No invoices yet." });
|
|
505
820
|
}
|
|
506
821
|
return /* @__PURE__ */ jsxs2("div", { className: cls("b316-card b316-invoices", className), style, children: [
|
|
507
|
-
error ? /* @__PURE__ */ jsx3("div", { className: "b316-error", children: error }) : null,
|
|
822
|
+
error ? /* @__PURE__ */ jsx3("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
508
823
|
/* @__PURE__ */ jsxs2("table", { className: "b316-invoice-table", children: [
|
|
509
824
|
/* @__PURE__ */ jsx3("thead", { children: /* @__PURE__ */ jsxs2("tr", { children: [
|
|
510
825
|
/* @__PURE__ */ jsx3("th", { children: "Invoice" }),
|
|
@@ -545,7 +860,15 @@ function InvoiceView({ invoice, onClose }) {
|
|
|
545
860
|
{
|
|
546
861
|
type: "button",
|
|
547
862
|
className: "b316-button b316-button-secondary",
|
|
548
|
-
onClick: () =>
|
|
863
|
+
onClick: () => {
|
|
864
|
+
const root = document.documentElement;
|
|
865
|
+
root.setAttribute("data-b316-printing", "");
|
|
866
|
+
try {
|
|
867
|
+
window.print();
|
|
868
|
+
} finally {
|
|
869
|
+
root.removeAttribute("data-b316-printing");
|
|
870
|
+
}
|
|
871
|
+
},
|
|
549
872
|
children: "Download PDF"
|
|
550
873
|
}
|
|
551
874
|
)
|
|
@@ -637,6 +960,8 @@ import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
|
637
960
|
function SignIn({
|
|
638
961
|
onSignedIn,
|
|
639
962
|
passkeys = true,
|
|
963
|
+
magicLinkRedirectUrl,
|
|
964
|
+
phone = false,
|
|
640
965
|
className,
|
|
641
966
|
style
|
|
642
967
|
}) {
|
|
@@ -644,10 +969,17 @@ function SignIn({
|
|
|
644
969
|
const [email, setEmail] = useState3("");
|
|
645
970
|
const [password, setPassword] = useState3("");
|
|
646
971
|
const [code, setCode] = useState3("");
|
|
647
|
-
const [
|
|
972
|
+
const [pendingChallenge, setPendingChallenge] = useState3(null);
|
|
973
|
+
const [pendingFactors, setPendingFactors] = useState3([]);
|
|
974
|
+
const [phoneNumber, setPhoneNumber] = useState3("");
|
|
975
|
+
const [phoneChallenge, setPhoneChallenge] = useState3(
|
|
976
|
+
null
|
|
977
|
+
);
|
|
648
978
|
const [error, setError] = useState3(null);
|
|
649
979
|
const [busy, setBusy] = useState3(false);
|
|
650
980
|
const [passkeyReady, setPasskeyReady] = useState3(false);
|
|
981
|
+
const [mode, setMode] = useState3("password");
|
|
982
|
+
const [linkSent, setLinkSent] = useState3(false);
|
|
651
983
|
const abortRef = useRef(null);
|
|
652
984
|
const signInWithPasskey = async (conditional, signal) => {
|
|
653
985
|
if (!conditional) {
|
|
@@ -673,7 +1005,7 @@ function SignIn({
|
|
|
673
1005
|
}
|
|
674
1006
|
};
|
|
675
1007
|
useEffect3(() => {
|
|
676
|
-
if (!passkeys || !isPasskeySupported() ||
|
|
1008
|
+
if (!passkeys || !isPasskeySupported() || pendingChallenge) {
|
|
677
1009
|
return;
|
|
678
1010
|
}
|
|
679
1011
|
setPasskeyReady(true);
|
|
@@ -687,21 +1019,92 @@ function SignIn({
|
|
|
687
1019
|
return () => {
|
|
688
1020
|
controller.abort();
|
|
689
1021
|
};
|
|
690
|
-
}, [passkeys,
|
|
1022
|
+
}, [passkeys, pendingChallenge]);
|
|
1023
|
+
useEffect3(() => {
|
|
1024
|
+
if (typeof window === "undefined") {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
const url = new URL(window.location.href);
|
|
1028
|
+
const token = url.searchParams.get("token");
|
|
1029
|
+
if (!token) {
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
url.searchParams.delete("token");
|
|
1033
|
+
window.history.replaceState({}, "", url.toString());
|
|
1034
|
+
let cancelled = false;
|
|
1035
|
+
void client.auth.magicLink.verify({ token }).then((result) => {
|
|
1036
|
+
if (cancelled) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
setToken(result.token);
|
|
1040
|
+
onSignedIn?.();
|
|
1041
|
+
}).catch(() => {
|
|
1042
|
+
if (!cancelled) {
|
|
1043
|
+
setError("That sign-in link is no longer valid. Ask for a new one.");
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
return () => {
|
|
1047
|
+
cancelled = true;
|
|
1048
|
+
};
|
|
1049
|
+
}, []);
|
|
1050
|
+
async function sendLink() {
|
|
1051
|
+
if (!magicLinkRedirectUrl) {
|
|
1052
|
+
return;
|
|
1053
|
+
}
|
|
1054
|
+
setBusy(true);
|
|
1055
|
+
setError(null);
|
|
1056
|
+
try {
|
|
1057
|
+
await client.auth.magicLink.request({ email, redirectUrl: magicLinkRedirectUrl });
|
|
1058
|
+
setLinkSent(true);
|
|
1059
|
+
} catch (cause) {
|
|
1060
|
+
console.error("[base316] magic link request failed", cause);
|
|
1061
|
+
setError("We could not send that link. Try again.");
|
|
1062
|
+
} finally {
|
|
1063
|
+
setBusy(false);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
691
1066
|
async function submit(event) {
|
|
692
1067
|
event.preventDefault();
|
|
693
1068
|
setBusy(true);
|
|
694
1069
|
setError(null);
|
|
695
1070
|
try {
|
|
696
|
-
if (
|
|
697
|
-
|
|
1071
|
+
if (mode === "magic" && !pendingChallenge) {
|
|
1072
|
+
await sendLink();
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
if (pendingChallenge) {
|
|
1076
|
+
const verified = await client.auth.verifyMfa({
|
|
1077
|
+
challengeToken: pendingChallenge,
|
|
1078
|
+
code
|
|
1079
|
+
});
|
|
698
1080
|
setToken(verified.token);
|
|
699
1081
|
onSignedIn?.();
|
|
700
1082
|
return;
|
|
701
1083
|
}
|
|
1084
|
+
if (mode === "phone") {
|
|
1085
|
+
if (!phoneChallenge) {
|
|
1086
|
+
const started = await client.auth.phone.start({ phone: phoneNumber });
|
|
1087
|
+
setPhoneChallenge({ token: started.challengeToken, hint: started.destinationHint });
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
const signedIn = await client.auth.phone.verify({
|
|
1091
|
+
challengeToken: phoneChallenge.token,
|
|
1092
|
+
code
|
|
1093
|
+
});
|
|
1094
|
+
if (needsSecondFactor(signedIn)) {
|
|
1095
|
+
setPendingChallenge(signedIn.challengeToken);
|
|
1096
|
+
setPendingFactors(signedIn.factors);
|
|
1097
|
+
setCode("");
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
setToken(signedIn.token);
|
|
1101
|
+
onSignedIn?.();
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
702
1104
|
const result = await client.auth.signIn({ email, password });
|
|
703
1105
|
if (needsSecondFactor(result)) {
|
|
704
|
-
|
|
1106
|
+
setPendingChallenge(result.challengeToken);
|
|
1107
|
+
setPendingFactors(result.factors);
|
|
705
1108
|
return;
|
|
706
1109
|
}
|
|
707
1110
|
setToken(result.token);
|
|
@@ -709,15 +1112,72 @@ function SignIn({
|
|
|
709
1112
|
} catch (cause) {
|
|
710
1113
|
console.error("[base316] sign-in failed", cause);
|
|
711
1114
|
setError(
|
|
712
|
-
|
|
1115
|
+
pendingChallenge ? "That code was not accepted." : mode === "phone" ? phoneChallenge ? "That code did not work. Check it, or ask for a new one." : (
|
|
1116
|
+
// Why a text could not be sent is worth saying — a number in the
|
|
1117
|
+
// wrong format, or too many requests — and the server words it
|
|
1118
|
+
// without saying anything about accounts.
|
|
1119
|
+
cause instanceof Error && cause.message ? cause.message : "We could not send a code. Try again."
|
|
1120
|
+
) : "That email and password did not match."
|
|
713
1121
|
);
|
|
714
1122
|
} finally {
|
|
715
1123
|
setBusy(false);
|
|
716
1124
|
}
|
|
717
1125
|
}
|
|
1126
|
+
const magicAvailable = Boolean(magicLinkRedirectUrl) && !pendingChallenge;
|
|
1127
|
+
const tabsShown = (magicAvailable || phone) && !pendingChallenge;
|
|
1128
|
+
const deliveredFactor = pendingFactors.find((factor) => factor.destinationHint);
|
|
1129
|
+
if (linkSent) {
|
|
1130
|
+
return /* @__PURE__ */ jsxs3("div", { className: cls("b316-card", className), style, children: [
|
|
1131
|
+
/* @__PURE__ */ jsx4("div", { style: { fontWeight: 600, marginBottom: 6 }, children: "Check your email" }),
|
|
1132
|
+
/* @__PURE__ */ jsxs3("div", { className: "b316-muted", children: [
|
|
1133
|
+
"If an account exists for ",
|
|
1134
|
+
email,
|
|
1135
|
+
", a sign-in link is on its way. It expires shortly and can be used once."
|
|
1136
|
+
] }),
|
|
1137
|
+
/* @__PURE__ */ jsx4(
|
|
1138
|
+
"button",
|
|
1139
|
+
{
|
|
1140
|
+
type: "button",
|
|
1141
|
+
className: "b316-button b316-button-secondary",
|
|
1142
|
+
style: { marginTop: 16 },
|
|
1143
|
+
onClick: () => setLinkSent(false),
|
|
1144
|
+
children: "Back to sign in"
|
|
1145
|
+
}
|
|
1146
|
+
)
|
|
1147
|
+
] });
|
|
1148
|
+
}
|
|
718
1149
|
return /* @__PURE__ */ jsxs3("form", { onSubmit: submit, className: cls("b316-card", className), style, children: [
|
|
719
|
-
error ? /* @__PURE__ */ jsx4("div", { className: "b316-error", children: error }) : null,
|
|
720
|
-
|
|
1150
|
+
error ? /* @__PURE__ */ jsx4("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
1151
|
+
tabsShown ? /* @__PURE__ */ jsxs3("div", { className: "b316-tabs", children: [
|
|
1152
|
+
/* @__PURE__ */ jsx4(
|
|
1153
|
+
"button",
|
|
1154
|
+
{
|
|
1155
|
+
type: "button",
|
|
1156
|
+
className: cls("b316-tab", mode === "password" ? "b316-tab-on" : void 0),
|
|
1157
|
+
onClick: () => setMode("password"),
|
|
1158
|
+
children: "Password"
|
|
1159
|
+
}
|
|
1160
|
+
),
|
|
1161
|
+
magicAvailable ? /* @__PURE__ */ jsx4(
|
|
1162
|
+
"button",
|
|
1163
|
+
{
|
|
1164
|
+
type: "button",
|
|
1165
|
+
className: cls("b316-tab", mode === "magic" ? "b316-tab-on" : void 0),
|
|
1166
|
+
onClick: () => setMode("magic"),
|
|
1167
|
+
children: "Magic link"
|
|
1168
|
+
}
|
|
1169
|
+
) : null,
|
|
1170
|
+
phone ? /* @__PURE__ */ jsx4(
|
|
1171
|
+
"button",
|
|
1172
|
+
{
|
|
1173
|
+
type: "button",
|
|
1174
|
+
className: cls("b316-tab", mode === "phone" ? "b316-tab-on" : void 0),
|
|
1175
|
+
onClick: () => setMode("phone"),
|
|
1176
|
+
children: "Text message"
|
|
1177
|
+
}
|
|
1178
|
+
) : null
|
|
1179
|
+
] }) : null,
|
|
1180
|
+
pendingChallenge ? /* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
721
1181
|
/* @__PURE__ */ jsx4("label", { className: "b316-label", htmlFor: "b316-code", children: "Authentication code" }),
|
|
722
1182
|
/* @__PURE__ */ jsx4(
|
|
723
1183
|
"input",
|
|
@@ -731,7 +1191,55 @@ function SignIn({
|
|
|
731
1191
|
required: true
|
|
732
1192
|
}
|
|
733
1193
|
),
|
|
734
|
-
/* @__PURE__ */ jsx4("span", { className: "b316-muted", children: "From your authenticator app, or one of your recovery codes." })
|
|
1194
|
+
/* @__PURE__ */ jsx4("span", { className: "b316-muted", children: deliveredFactor ? `We sent a code to ${deliveredFactor.destinationHint}. Enter it, or one of your recovery codes.` : "From your authenticator app, or one of your recovery codes." })
|
|
1195
|
+
] }) : mode === "phone" ? phoneChallenge ? /* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
1196
|
+
/* @__PURE__ */ jsx4("label", { className: "b316-label", htmlFor: "b316-phone-code", children: "Code" }),
|
|
1197
|
+
/* @__PURE__ */ jsx4(
|
|
1198
|
+
"input",
|
|
1199
|
+
{
|
|
1200
|
+
id: "b316-phone-code",
|
|
1201
|
+
className: "b316-input",
|
|
1202
|
+
value: code,
|
|
1203
|
+
onChange: (event) => setCode(event.target.value),
|
|
1204
|
+
autoComplete: "one-time-code",
|
|
1205
|
+
inputMode: "numeric",
|
|
1206
|
+
required: true
|
|
1207
|
+
}
|
|
1208
|
+
),
|
|
1209
|
+
/* @__PURE__ */ jsxs3("span", { className: "b316-muted", children: [
|
|
1210
|
+
"We sent a code to ",
|
|
1211
|
+
phoneChallenge.hint,
|
|
1212
|
+
". It expires in ten minutes.",
|
|
1213
|
+
" ",
|
|
1214
|
+
/* @__PURE__ */ jsx4(
|
|
1215
|
+
"button",
|
|
1216
|
+
{
|
|
1217
|
+
type: "button",
|
|
1218
|
+
className: "b316-button-quiet",
|
|
1219
|
+
onClick: () => {
|
|
1220
|
+
setPhoneChallenge(null);
|
|
1221
|
+
setCode("");
|
|
1222
|
+
},
|
|
1223
|
+
children: "Use a different number"
|
|
1224
|
+
}
|
|
1225
|
+
)
|
|
1226
|
+
] })
|
|
1227
|
+
] }) : /* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
1228
|
+
/* @__PURE__ */ jsx4("label", { className: "b316-label", htmlFor: "b316-phone", children: "Mobile number" }),
|
|
1229
|
+
/* @__PURE__ */ jsx4(
|
|
1230
|
+
"input",
|
|
1231
|
+
{
|
|
1232
|
+
id: "b316-phone",
|
|
1233
|
+
className: "b316-input",
|
|
1234
|
+
type: "tel",
|
|
1235
|
+
value: phoneNumber,
|
|
1236
|
+
onChange: (event) => setPhoneNumber(event.target.value),
|
|
1237
|
+
autoComplete: "tel",
|
|
1238
|
+
placeholder: "+14155550123",
|
|
1239
|
+
required: true
|
|
1240
|
+
}
|
|
1241
|
+
),
|
|
1242
|
+
/* @__PURE__ */ jsx4("span", { className: "b316-muted", children: "Include the country code." })
|
|
735
1243
|
] }) : /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
736
1244
|
/* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
737
1245
|
/* @__PURE__ */ jsx4("label", { className: "b316-label", htmlFor: "b316-email", children: "Email" }),
|
|
@@ -748,7 +1256,7 @@ function SignIn({
|
|
|
748
1256
|
}
|
|
749
1257
|
)
|
|
750
1258
|
] }),
|
|
751
|
-
/* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
1259
|
+
mode === "password" ? /* @__PURE__ */ jsxs3("div", { className: "b316-field", children: [
|
|
752
1260
|
/* @__PURE__ */ jsx4("label", { className: "b316-label", htmlFor: "b316-password", children: "Password" }),
|
|
753
1261
|
/* @__PURE__ */ jsx4(
|
|
754
1262
|
"input",
|
|
@@ -762,10 +1270,10 @@ function SignIn({
|
|
|
762
1270
|
required: true
|
|
763
1271
|
}
|
|
764
1272
|
)
|
|
765
|
-
] })
|
|
1273
|
+
] }) : null
|
|
766
1274
|
] }),
|
|
767
|
-
/* @__PURE__ */ jsx4("button", { className: "b316-button", type: "submit", disabled: busy, children: busy ? "Working\u2026" :
|
|
768
|
-
passkeyReady && !
|
|
1275
|
+
/* @__PURE__ */ jsx4("button", { className: "b316-button", type: "submit", disabled: busy, children: busy ? "Working\u2026" : pendingChallenge ? "Verify" : mode === "magic" ? "Email me a link" : mode === "phone" && !phoneChallenge ? "Text me a code" : "Sign in" }),
|
|
1276
|
+
passkeyReady && !pendingChallenge ? /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
769
1277
|
/* @__PURE__ */ jsx4("div", { className: "b316-muted", style: { textAlign: "center", margin: "10px 0" }, children: "or" }),
|
|
770
1278
|
/* @__PURE__ */ jsx4(
|
|
771
1279
|
"button",
|
|
@@ -817,7 +1325,7 @@ function SignUp({
|
|
|
817
1325
|
}
|
|
818
1326
|
}
|
|
819
1327
|
return /* @__PURE__ */ jsxs4("form", { onSubmit: submit, className: cls("b316-card", className), style, children: [
|
|
820
|
-
error ? /* @__PURE__ */ jsx5("div", { className: "b316-error", children: error }) : null,
|
|
1328
|
+
error ? /* @__PURE__ */ jsx5("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
821
1329
|
/* @__PURE__ */ jsxs4("div", { className: "b316-field", children: [
|
|
822
1330
|
/* @__PURE__ */ jsx5("label", { className: "b316-label", htmlFor: "b316-name", children: "Name" }),
|
|
823
1331
|
/* @__PURE__ */ jsx5(
|
|
@@ -898,19 +1406,86 @@ function UserProfile({ className, style }) {
|
|
|
898
1406
|
|
|
899
1407
|
// src/PasskeyManager.tsx
|
|
900
1408
|
import { isPasskeySupported as isPasskeySupported2 } from "@base316/sdk";
|
|
901
|
-
import { useCallback as useCallback3, useEffect as
|
|
1409
|
+
import { useCallback as useCallback3, useEffect as useEffect5, useState as useState6 } from "react";
|
|
1410
|
+
|
|
1411
|
+
// src/confirm.tsx
|
|
1412
|
+
import { useEffect as useEffect4, useRef as useRef2, useState as useState5 } from "react";
|
|
902
1413
|
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1414
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
1415
|
+
function ConfirmButton({
|
|
1416
|
+
children,
|
|
1417
|
+
confirmLabel,
|
|
1418
|
+
onConfirm,
|
|
1419
|
+
className,
|
|
1420
|
+
disabled,
|
|
1421
|
+
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
1422
|
+
}) {
|
|
1423
|
+
const [armed, setArmed] = useState5(false);
|
|
1424
|
+
const confirmRef = useRef2(null);
|
|
1425
|
+
useEffect4(() => {
|
|
1426
|
+
if (!armed) {
|
|
1427
|
+
return;
|
|
1428
|
+
}
|
|
1429
|
+
confirmRef.current?.focus();
|
|
1430
|
+
const timer = setTimeout(() => setArmed(false), timeoutMs);
|
|
1431
|
+
return () => clearTimeout(timer);
|
|
1432
|
+
}, [armed, timeoutMs]);
|
|
1433
|
+
if (!armed) {
|
|
1434
|
+
return /* @__PURE__ */ jsx7(
|
|
1435
|
+
"button",
|
|
1436
|
+
{
|
|
1437
|
+
type: "button",
|
|
1438
|
+
className,
|
|
1439
|
+
disabled,
|
|
1440
|
+
onClick: () => setArmed(true),
|
|
1441
|
+
children
|
|
1442
|
+
}
|
|
1443
|
+
);
|
|
1444
|
+
}
|
|
1445
|
+
return (
|
|
1446
|
+
// No `role="group"`: both buttons already say what they do, and the
|
|
1447
|
+
// grouping would only repeat the question a screen reader has just read.
|
|
1448
|
+
/* @__PURE__ */ jsxs6("span", { className: "b316-confirm", children: [
|
|
1449
|
+
/* @__PURE__ */ jsx7(
|
|
1450
|
+
"button",
|
|
1451
|
+
{
|
|
1452
|
+
ref: confirmRef,
|
|
1453
|
+
type: "button",
|
|
1454
|
+
className,
|
|
1455
|
+
disabled,
|
|
1456
|
+
onClick: async () => {
|
|
1457
|
+
setArmed(false);
|
|
1458
|
+
await onConfirm();
|
|
1459
|
+
},
|
|
1460
|
+
children: confirmLabel
|
|
1461
|
+
}
|
|
1462
|
+
),
|
|
1463
|
+
/* @__PURE__ */ jsx7(
|
|
1464
|
+
"button",
|
|
1465
|
+
{
|
|
1466
|
+
type: "button",
|
|
1467
|
+
className: "b316-button b316-button-secondary",
|
|
1468
|
+
onClick: () => setArmed(false),
|
|
1469
|
+
children: "Cancel"
|
|
1470
|
+
}
|
|
1471
|
+
)
|
|
1472
|
+
] })
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/PasskeyManager.tsx
|
|
1477
|
+
import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
903
1478
|
function PasskeyManager({
|
|
904
1479
|
className,
|
|
905
1480
|
style,
|
|
906
1481
|
title = "Passkeys"
|
|
907
1482
|
}) {
|
|
908
1483
|
const { client, token, session } = useBase316();
|
|
909
|
-
const [passkeys, setPasskeys] =
|
|
910
|
-
const [busy, setBusy] =
|
|
911
|
-
const [error, setError] =
|
|
912
|
-
const [name, setName] =
|
|
913
|
-
const [supported, setSupported] =
|
|
1484
|
+
const [passkeys, setPasskeys] = useState6(null);
|
|
1485
|
+
const [busy, setBusy] = useState6(false);
|
|
1486
|
+
const [error, setError] = useState6(null);
|
|
1487
|
+
const [name, setName] = useState6("");
|
|
1488
|
+
const [supported, setSupported] = useState6(false);
|
|
914
1489
|
const load = useCallback3(async () => {
|
|
915
1490
|
if (!token) {
|
|
916
1491
|
return;
|
|
@@ -918,11 +1493,13 @@ function PasskeyManager({
|
|
|
918
1493
|
try {
|
|
919
1494
|
const result = await client.auth.passkeys.list(token);
|
|
920
1495
|
setPasskeys(result.data);
|
|
921
|
-
} catch {
|
|
922
|
-
|
|
1496
|
+
} catch (cause) {
|
|
1497
|
+
console.error("[base316] could not list passkeys", cause);
|
|
1498
|
+
setError("Could not load your passkeys. They have not been changed.");
|
|
1499
|
+
setPasskeys(null);
|
|
923
1500
|
}
|
|
924
1501
|
}, [client, token]);
|
|
925
|
-
|
|
1502
|
+
useEffect5(() => {
|
|
926
1503
|
if (!isPasskeySupported2()) {
|
|
927
1504
|
return;
|
|
928
1505
|
}
|
|
@@ -958,30 +1535,30 @@ function PasskeyManager({
|
|
|
958
1535
|
setError(caught instanceof Error ? caught.message : "That did not work.");
|
|
959
1536
|
}
|
|
960
1537
|
};
|
|
961
|
-
return /* @__PURE__ */
|
|
962
|
-
/* @__PURE__ */
|
|
963
|
-
/* @__PURE__ */
|
|
964
|
-
passkeys === null ? /* @__PURE__ */
|
|
965
|
-
/* @__PURE__ */
|
|
966
|
-
/* @__PURE__ */
|
|
967
|
-
/* @__PURE__ */
|
|
1538
|
+
return /* @__PURE__ */ jsxs7("div", { className: cls("b316-card", className), style, children: [
|
|
1539
|
+
/* @__PURE__ */ jsx8("div", { style: { fontWeight: 600, marginBottom: 4 }, children: title }),
|
|
1540
|
+
/* @__PURE__ */ jsx8("div", { className: "b316-muted", style: { marginBottom: 12 }, children: "Sign in with your fingerprint, face or a security key \u2014 nothing to type and nothing to remember." }),
|
|
1541
|
+
passkeys === null ? /* @__PURE__ */ jsx8("div", { className: "b316-muted", children: "Loading\u2026" }) : passkeys.length === 0 ? /* @__PURE__ */ jsx8("div", { className: "b316-muted", children: "No passkeys yet." }) : /* @__PURE__ */ jsx8("ul", { style: { listStyle: "none", margin: 0, padding: 0 }, children: passkeys.map((passkey) => /* @__PURE__ */ jsxs7("li", { className: "b316-row", style: { padding: "8px 0" }, children: [
|
|
1542
|
+
/* @__PURE__ */ jsxs7("div", { children: [
|
|
1543
|
+
/* @__PURE__ */ jsx8("div", { children: passkey.name || "Passkey" }),
|
|
1544
|
+
/* @__PURE__ */ jsxs7("div", { className: "b316-muted", children: [
|
|
968
1545
|
passkey.lastUsedAt ? `Last used ${formatDate(passkey.lastUsedAt)}` : `Added ${formatDate(passkey.createdAt)}`,
|
|
969
1546
|
passkey.backedUp ? "" : " \xB7 this device only"
|
|
970
1547
|
] })
|
|
971
1548
|
] }),
|
|
972
|
-
/* @__PURE__ */
|
|
973
|
-
|
|
1549
|
+
/* @__PURE__ */ jsx8(
|
|
1550
|
+
ConfirmButton,
|
|
974
1551
|
{
|
|
975
|
-
type: "button",
|
|
976
1552
|
className: "b316-button b316-button-secondary",
|
|
977
|
-
|
|
1553
|
+
confirmLabel: `Remove ${passkey.name ?? "this passkey"} for good`,
|
|
1554
|
+
onConfirm: () => remove(passkey.id),
|
|
978
1555
|
children: "Remove"
|
|
979
1556
|
}
|
|
980
1557
|
)
|
|
981
1558
|
] }, passkey.id)) }),
|
|
982
|
-
error ? /* @__PURE__ */
|
|
983
|
-
/* @__PURE__ */
|
|
984
|
-
/* @__PURE__ */
|
|
1559
|
+
error ? /* @__PURE__ */ jsx8("div", { className: "b316-error", role: "alert", style: { marginTop: 12 }, children: error }) : null,
|
|
1560
|
+
/* @__PURE__ */ jsxs7("div", { className: "b316-row", style: { marginTop: 12, gap: 8 }, children: [
|
|
1561
|
+
/* @__PURE__ */ jsx8(
|
|
985
1562
|
"input",
|
|
986
1563
|
{
|
|
987
1564
|
className: "b316-input",
|
|
@@ -990,16 +1567,7 @@ function PasskeyManager({
|
|
|
990
1567
|
onChange: (event) => setName(event.target.value)
|
|
991
1568
|
}
|
|
992
1569
|
),
|
|
993
|
-
/* @__PURE__ */
|
|
994
|
-
"button",
|
|
995
|
-
{
|
|
996
|
-
type: "button",
|
|
997
|
-
className: "b316-button",
|
|
998
|
-
disabled: busy,
|
|
999
|
-
onClick: () => void add(),
|
|
1000
|
-
children: busy ? "Waiting\u2026" : "Add a passkey"
|
|
1001
|
-
}
|
|
1002
|
-
)
|
|
1570
|
+
/* @__PURE__ */ jsx8("button", { type: "button", className: "b316-button", disabled: busy, onClick: () => void add(), children: busy ? "Waiting\u2026" : "Add a passkey" })
|
|
1003
1571
|
] })
|
|
1004
1572
|
] });
|
|
1005
1573
|
}
|
|
@@ -1008,111 +1576,2781 @@ function formatDate(value) {
|
|
|
1008
1576
|
return Number.isNaN(date.getTime()) ? "" : date.toLocaleDateString();
|
|
1009
1577
|
}
|
|
1010
1578
|
|
|
1011
|
-
// src/
|
|
1012
|
-
import { useEffect as
|
|
1013
|
-
import { jsx as
|
|
1014
|
-
function
|
|
1015
|
-
if (
|
|
1016
|
-
|
|
1017
|
-
if (!Number.isFinite(value)) return "Free";
|
|
1018
|
-
try {
|
|
1019
|
-
return new Intl.NumberFormat(void 0, { style: "currency", currency }).format(value);
|
|
1020
|
-
} catch {
|
|
1021
|
-
return `${value} ${currency}`;
|
|
1579
|
+
// src/ActiveSessions.tsx
|
|
1580
|
+
import { useCallback as useCallback4, useEffect as useEffect6, useState as useState7 } from "react";
|
|
1581
|
+
import { jsx as jsx9, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1582
|
+
function describeDevice(userAgent) {
|
|
1583
|
+
if (!userAgent) {
|
|
1584
|
+
return null;
|
|
1022
1585
|
}
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (
|
|
1026
|
-
return
|
|
1586
|
+
const browser = /Edg\//.test(userAgent) ? "Edge" : /OPR\//.test(userAgent) ? "Opera" : /Chrome\//.test(userAgent) ? "Chrome" : /Safari\//.test(userAgent) ? "Safari" : /Firefox\//.test(userAgent) ? "Firefox" : null;
|
|
1587
|
+
const platform = /iPhone|iPad/.test(userAgent) ? "iOS" : /Android/.test(userAgent) ? "Android" : /Mac OS X/.test(userAgent) ? "macOS" : /Windows/.test(userAgent) ? "Windows" : /Linux/.test(userAgent) ? "Linux" : null;
|
|
1588
|
+
if (!browser && !platform) {
|
|
1589
|
+
return userAgent.slice(0, 60);
|
|
1027
1590
|
}
|
|
1028
|
-
|
|
1029
|
-
return plan.intervalCount === 1 ? `per ${unit}` : `every ${plan.intervalCount} ${unit}s`;
|
|
1591
|
+
return [browser, platform].filter(Boolean).join(" on ");
|
|
1030
1592
|
}
|
|
1031
|
-
function
|
|
1593
|
+
function when(value) {
|
|
1594
|
+
const date = new Date(value);
|
|
1595
|
+
return Number.isNaN(date.getTime()) ? "" : date.toLocaleString();
|
|
1596
|
+
}
|
|
1597
|
+
function ActiveSessions({ onRevoked, className, style }) {
|
|
1598
|
+
const { client, token } = useBase316();
|
|
1599
|
+
const [sessions, setSessions] = useState7(null);
|
|
1600
|
+
const [error, setError] = useState7(null);
|
|
1601
|
+
const [busy, setBusy] = useState7(false);
|
|
1602
|
+
const load = useCallback4(() => {
|
|
1603
|
+
if (!token) {
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
client.auth.sessions(token).then((result) => {
|
|
1607
|
+
setSessions(result.data.filter((session) => !session.revokedAt));
|
|
1608
|
+
setError(null);
|
|
1609
|
+
}).catch((cause) => {
|
|
1610
|
+
setError(cause instanceof Error ? cause.message : "Could not load your sessions.");
|
|
1611
|
+
});
|
|
1612
|
+
}, [client, token]);
|
|
1613
|
+
useEffect6(load, [load]);
|
|
1614
|
+
if (!token) {
|
|
1615
|
+
return null;
|
|
1616
|
+
}
|
|
1617
|
+
if (error) {
|
|
1618
|
+
return /* @__PURE__ */ jsx9("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx9("div", { className: "b316-error", role: "alert", children: error }) });
|
|
1619
|
+
}
|
|
1620
|
+
if (!sessions) {
|
|
1621
|
+
return /* @__PURE__ */ jsx9("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
1622
|
+
}
|
|
1623
|
+
async function revokeOthers() {
|
|
1624
|
+
setBusy(true);
|
|
1625
|
+
try {
|
|
1626
|
+
const result = await client.auth.revokeOtherSessions(token);
|
|
1627
|
+
onRevoked?.(result.revoked);
|
|
1628
|
+
load();
|
|
1629
|
+
} catch (cause) {
|
|
1630
|
+
setError(cause instanceof Error ? cause.message : "Could not end those sessions.");
|
|
1631
|
+
} finally {
|
|
1632
|
+
setBusy(false);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
return /* @__PURE__ */ jsxs8("div", { className: cls("b316-card b316-sessions", className), style, children: [
|
|
1636
|
+
/* @__PURE__ */ jsxs8("div", { className: "b316-sessions-head", children: [
|
|
1637
|
+
/* @__PURE__ */ jsx9("h3", { className: "b316-sessions-title", children: "Where you are signed in" }),
|
|
1638
|
+
sessions.length > 1 ? /* @__PURE__ */ jsx9("button", { type: "button", className: "b316-button", disabled: busy, onClick: revokeOthers, children: busy ? "Ending\u2026" : "Sign out other devices" }) : null
|
|
1639
|
+
] }),
|
|
1640
|
+
/* @__PURE__ */ jsx9("ul", { className: "b316-sessions-list", children: sessions.map((session) => /* @__PURE__ */ jsxs8("li", { className: "b316-session", children: [
|
|
1641
|
+
/* @__PURE__ */ jsxs8("div", { className: "b316-session-device", children: [
|
|
1642
|
+
describeDevice(session.userAgent) ?? "Unknown device",
|
|
1643
|
+
session.impersonatedBy ? (
|
|
1644
|
+
// Worth saying loudly: somebody is acting as this account.
|
|
1645
|
+
/* @__PURE__ */ jsx9("span", { className: "b316-chip", children: " Support access" })
|
|
1646
|
+
) : null
|
|
1647
|
+
] }),
|
|
1648
|
+
/* @__PURE__ */ jsxs8("div", { className: "b316-muted", children: [
|
|
1649
|
+
session.ipAddress ? `${session.ipAddress} \xB7 ` : "",
|
|
1650
|
+
"last used ",
|
|
1651
|
+
when(session.lastSeenAt)
|
|
1652
|
+
] })
|
|
1653
|
+
] }, session.id)) }),
|
|
1654
|
+
sessions.length === 0 ? /* @__PURE__ */ jsx9("div", { className: "b316-muted", children: "No active sessions." }) : null
|
|
1655
|
+
] });
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
// src/DeviceApproval.tsx
|
|
1659
|
+
import { useState as useState8 } from "react";
|
|
1660
|
+
import { jsx as jsx10, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1661
|
+
function DeviceApproval({
|
|
1662
|
+
userCode = "",
|
|
1663
|
+
onDecided,
|
|
1664
|
+
className,
|
|
1665
|
+
style
|
|
1666
|
+
}) {
|
|
1667
|
+
const { client, token } = useBase316();
|
|
1668
|
+
const [code, setCode] = useState8(userCode);
|
|
1669
|
+
const [request, setRequest] = useState8(null);
|
|
1670
|
+
const [decided, setDecided] = useState8(null);
|
|
1671
|
+
const [error, setError] = useState8(null);
|
|
1672
|
+
const [busy, setBusy] = useState8(false);
|
|
1673
|
+
if (!token) {
|
|
1674
|
+
return null;
|
|
1675
|
+
}
|
|
1676
|
+
async function lookUp(event) {
|
|
1677
|
+
event.preventDefault();
|
|
1678
|
+
setBusy(true);
|
|
1679
|
+
setError(null);
|
|
1680
|
+
try {
|
|
1681
|
+
setRequest(await client.device.lookup(code));
|
|
1682
|
+
} catch (cause) {
|
|
1683
|
+
setError(cause instanceof Error ? cause.message : "We could not check that code.");
|
|
1684
|
+
} finally {
|
|
1685
|
+
setBusy(false);
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
async function decide(approve) {
|
|
1689
|
+
if (!request) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
setBusy(true);
|
|
1693
|
+
setError(null);
|
|
1694
|
+
try {
|
|
1695
|
+
await client.device.decide(token, { id: request.id, approve });
|
|
1696
|
+
setDecided(approve);
|
|
1697
|
+
onDecided?.(approve);
|
|
1698
|
+
} catch (cause) {
|
|
1699
|
+
setError(cause instanceof Error ? cause.message : "We could not record that.");
|
|
1700
|
+
} finally {
|
|
1701
|
+
setBusy(false);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
if (decided !== null) {
|
|
1705
|
+
return /* @__PURE__ */ jsxs9("div", { className: cls("b316-card b316-device", className), style, children: [
|
|
1706
|
+
/* @__PURE__ */ jsx10("h3", { className: "b316-device-title", children: decided ? "You're all set" : "Not approved" }),
|
|
1707
|
+
/* @__PURE__ */ jsx10("p", { className: "b316-muted", children: decided ? "You can close this page and go back to your device." : "Nothing was granted. You can close this page." })
|
|
1708
|
+
] });
|
|
1709
|
+
}
|
|
1710
|
+
if (request) {
|
|
1711
|
+
return /* @__PURE__ */ jsxs9("div", { className: cls("b316-card b316-device", className), style, children: [
|
|
1712
|
+
/* @__PURE__ */ jsxs9("h3", { className: "b316-device-title", children: [
|
|
1713
|
+
"Sign in to ",
|
|
1714
|
+
request.clientName
|
|
1715
|
+
] }),
|
|
1716
|
+
/* @__PURE__ */ jsxs9("p", { className: "b316-muted", children: [
|
|
1717
|
+
request.clientName,
|
|
1718
|
+
" is asking to sign in as you."
|
|
1719
|
+
] }),
|
|
1720
|
+
request.scopes.length > 0 ? /* @__PURE__ */ jsx10("ul", { className: "b316-device-scopes", children: request.scopes.map((scope) => /* @__PURE__ */ jsx10("li", { children: scope }, scope)) }) : null,
|
|
1721
|
+
error ? /* @__PURE__ */ jsx10("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
1722
|
+
/* @__PURE__ */ jsxs9("div", { className: "b316-device-actions", children: [
|
|
1723
|
+
/* @__PURE__ */ jsx10(
|
|
1724
|
+
"button",
|
|
1725
|
+
{
|
|
1726
|
+
type: "button",
|
|
1727
|
+
className: "b316-button",
|
|
1728
|
+
disabled: busy,
|
|
1729
|
+
onClick: () => decide(true),
|
|
1730
|
+
children: busy ? "Approving\u2026" : "Approve"
|
|
1731
|
+
}
|
|
1732
|
+
),
|
|
1733
|
+
/* @__PURE__ */ jsx10(
|
|
1734
|
+
"button",
|
|
1735
|
+
{
|
|
1736
|
+
type: "button",
|
|
1737
|
+
className: "b316-button b316-button-quiet",
|
|
1738
|
+
disabled: busy,
|
|
1739
|
+
onClick: () => decide(false),
|
|
1740
|
+
children: "Deny"
|
|
1741
|
+
}
|
|
1742
|
+
)
|
|
1743
|
+
] })
|
|
1744
|
+
] });
|
|
1745
|
+
}
|
|
1746
|
+
return /* @__PURE__ */ jsxs9("form", { className: cls("b316-card b316-device", className), style, onSubmit: lookUp, children: [
|
|
1747
|
+
/* @__PURE__ */ jsx10("h3", { className: "b316-device-title", children: "Connect your device" }),
|
|
1748
|
+
/* @__PURE__ */ jsx10("p", { className: "b316-muted", children: "Enter the code shown on your device." }),
|
|
1749
|
+
error ? /* @__PURE__ */ jsx10("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
1750
|
+
/* @__PURE__ */ jsx10(
|
|
1751
|
+
"input",
|
|
1752
|
+
{
|
|
1753
|
+
className: "b316-input",
|
|
1754
|
+
value: code,
|
|
1755
|
+
onChange: (event) => setCode(event.target.value),
|
|
1756
|
+
autoComplete: "off",
|
|
1757
|
+
autoCapitalize: "characters",
|
|
1758
|
+
spellCheck: false,
|
|
1759
|
+
placeholder: "XXXX-XXXX",
|
|
1760
|
+
"aria-label": "Device code"
|
|
1761
|
+
}
|
|
1762
|
+
),
|
|
1763
|
+
/* @__PURE__ */ jsx10("button", { type: "submit", className: "b316-button", disabled: busy || code.trim().length < 4, children: busy ? "Checking\u2026" : "Continue" })
|
|
1764
|
+
] });
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
// src/PrivacyControls.tsx
|
|
1768
|
+
import { useState as useState9 } from "react";
|
|
1769
|
+
import { jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1770
|
+
function PrivacyControls({
|
|
1771
|
+
confirmWord = "DELETE",
|
|
1772
|
+
onErased,
|
|
1773
|
+
className,
|
|
1774
|
+
style
|
|
1775
|
+
}) {
|
|
1776
|
+
const { client, token } = useBase316();
|
|
1777
|
+
const [confirming, setConfirming] = useState9(false);
|
|
1778
|
+
const [typed, setTyped] = useState9("");
|
|
1779
|
+
const [error, setError] = useState9(null);
|
|
1780
|
+
const [busy, setBusy] = useState9(false);
|
|
1781
|
+
if (!token) {
|
|
1782
|
+
return null;
|
|
1783
|
+
}
|
|
1784
|
+
async function download() {
|
|
1785
|
+
setBusy(true);
|
|
1786
|
+
setError(null);
|
|
1787
|
+
try {
|
|
1788
|
+
const data = await client.auth.privacy.export(token);
|
|
1789
|
+
const url = URL.createObjectURL(
|
|
1790
|
+
new Blob([JSON.stringify(data, null, 2)], { type: "application/json" })
|
|
1791
|
+
);
|
|
1792
|
+
const link = document.createElement("a");
|
|
1793
|
+
link.href = url;
|
|
1794
|
+
link.download = "my-data.json";
|
|
1795
|
+
link.click();
|
|
1796
|
+
URL.revokeObjectURL(url);
|
|
1797
|
+
} catch (cause) {
|
|
1798
|
+
setError(cause instanceof Error ? cause.message : "Could not build your export.");
|
|
1799
|
+
} finally {
|
|
1800
|
+
setBusy(false);
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
async function erase() {
|
|
1804
|
+
setBusy(true);
|
|
1805
|
+
setError(null);
|
|
1806
|
+
try {
|
|
1807
|
+
await client.auth.privacy.erase(token);
|
|
1808
|
+
onErased?.();
|
|
1809
|
+
} catch (cause) {
|
|
1810
|
+
setError(cause instanceof Error ? cause.message : "Could not delete your account.");
|
|
1811
|
+
} finally {
|
|
1812
|
+
setBusy(false);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
return /* @__PURE__ */ jsxs10("div", { className: cls("b316-card b316-privacy", className), style, children: [
|
|
1816
|
+
/* @__PURE__ */ jsx11("h3", { className: "b316-privacy-title", children: "Your data" }),
|
|
1817
|
+
error ? /* @__PURE__ */ jsx11("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
1818
|
+
/* @__PURE__ */ jsxs10("div", { className: "b316-privacy-row", children: [
|
|
1819
|
+
/* @__PURE__ */ jsxs10("div", { children: [
|
|
1820
|
+
/* @__PURE__ */ jsx11("p", { children: "Download a copy" }),
|
|
1821
|
+
/* @__PURE__ */ jsx11("p", { className: "b316-muted", children: "Everything we hold about you, as a file. Passwords and security keys are not included \u2014 they are what protect the account rather than anything you can use." })
|
|
1822
|
+
] }),
|
|
1823
|
+
/* @__PURE__ */ jsx11("button", { type: "button", className: "b316-button-quiet", disabled: busy, onClick: download, children: busy ? "Preparing\u2026" : "Download" })
|
|
1824
|
+
] }),
|
|
1825
|
+
/* @__PURE__ */ jsxs10("div", { className: "b316-privacy-row", children: [
|
|
1826
|
+
/* @__PURE__ */ jsxs10("div", { children: [
|
|
1827
|
+
/* @__PURE__ */ jsx11("p", { children: "Delete your account" }),
|
|
1828
|
+
/* @__PURE__ */ jsx11("p", { className: "b316-muted", children: "Permanent. Invoices already raised are kept, because the law requires it; everything that identifies you is removed from them." })
|
|
1829
|
+
] }),
|
|
1830
|
+
confirming ? null : /* @__PURE__ */ jsx11(
|
|
1831
|
+
"button",
|
|
1832
|
+
{
|
|
1833
|
+
type: "button",
|
|
1834
|
+
className: "b316-button-quiet b316-danger",
|
|
1835
|
+
disabled: busy,
|
|
1836
|
+
onClick: () => setConfirming(true),
|
|
1837
|
+
children: "Delete"
|
|
1838
|
+
}
|
|
1839
|
+
)
|
|
1840
|
+
] }),
|
|
1841
|
+
confirming ? /* @__PURE__ */ jsxs10("div", { className: "b316-privacy-confirm", children: [
|
|
1842
|
+
/* @__PURE__ */ jsxs10("label", { className: "b316-label", htmlFor: "b316-privacy-confirm", children: [
|
|
1843
|
+
"Type ",
|
|
1844
|
+
confirmWord,
|
|
1845
|
+
" to confirm"
|
|
1846
|
+
] }),
|
|
1847
|
+
/* @__PURE__ */ jsx11(
|
|
1848
|
+
"input",
|
|
1849
|
+
{
|
|
1850
|
+
id: "b316-privacy-confirm",
|
|
1851
|
+
className: "b316-input",
|
|
1852
|
+
value: typed,
|
|
1853
|
+
autoComplete: "off",
|
|
1854
|
+
onChange: (event) => setTyped(event.target.value)
|
|
1855
|
+
}
|
|
1856
|
+
),
|
|
1857
|
+
/* @__PURE__ */ jsxs10("div", { className: "b316-privacy-actions", children: [
|
|
1858
|
+
/* @__PURE__ */ jsx11(
|
|
1859
|
+
"button",
|
|
1860
|
+
{
|
|
1861
|
+
type: "button",
|
|
1862
|
+
className: "b316-button-quiet",
|
|
1863
|
+
onClick: () => {
|
|
1864
|
+
setConfirming(false);
|
|
1865
|
+
setTyped("");
|
|
1866
|
+
},
|
|
1867
|
+
children: "Cancel"
|
|
1868
|
+
}
|
|
1869
|
+
),
|
|
1870
|
+
/* @__PURE__ */ jsx11(
|
|
1871
|
+
"button",
|
|
1872
|
+
{
|
|
1873
|
+
type: "button",
|
|
1874
|
+
className: "b316-button b316-danger",
|
|
1875
|
+
disabled: busy || typed.trim() !== confirmWord,
|
|
1876
|
+
onClick: erase,
|
|
1877
|
+
children: busy ? "Deleting\u2026" : "Delete my account"
|
|
1878
|
+
}
|
|
1879
|
+
)
|
|
1880
|
+
] })
|
|
1881
|
+
] }) : null
|
|
1882
|
+
] });
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
// src/TwoFactorManager.tsx
|
|
1886
|
+
import { useState as useState10 } from "react";
|
|
1887
|
+
import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1888
|
+
function TwoFactorManager({
|
|
1889
|
+
enabled = false,
|
|
1890
|
+
allowSms = false,
|
|
1891
|
+
onEnabled,
|
|
1892
|
+
onDisabled,
|
|
1893
|
+
className,
|
|
1894
|
+
style
|
|
1895
|
+
}) {
|
|
1896
|
+
const { client, token } = useBase316();
|
|
1897
|
+
const [stage, setStage] = useState10({ name: "idle" });
|
|
1898
|
+
const [on, setOn] = useState10(enabled);
|
|
1899
|
+
const [code, setCode] = useState10("");
|
|
1900
|
+
const [phone, setPhone] = useState10("");
|
|
1901
|
+
const [error, setError] = useState10(null);
|
|
1902
|
+
const [busy, setBusy] = useState10(false);
|
|
1903
|
+
if (!token) {
|
|
1904
|
+
return null;
|
|
1905
|
+
}
|
|
1906
|
+
async function begin() {
|
|
1907
|
+
setBusy(true);
|
|
1908
|
+
setError(null);
|
|
1909
|
+
try {
|
|
1910
|
+
const enrollment = await client.auth.mfa.enroll(token);
|
|
1911
|
+
setStage({ name: "enrolling", ...enrollment });
|
|
1912
|
+
} catch (cause) {
|
|
1913
|
+
setError(cause instanceof Error ? cause.message : "Could not start setup.");
|
|
1914
|
+
} finally {
|
|
1915
|
+
setBusy(false);
|
|
1916
|
+
}
|
|
1917
|
+
}
|
|
1918
|
+
async function beginEmail() {
|
|
1919
|
+
setBusy(true);
|
|
1920
|
+
setError(null);
|
|
1921
|
+
try {
|
|
1922
|
+
const enrollment = await client.auth.mfa.enrollEmail(token);
|
|
1923
|
+
setStage({ name: "enrollingEmail", ...enrollment });
|
|
1924
|
+
} catch (cause) {
|
|
1925
|
+
setError(cause instanceof Error ? cause.message : "Could not send a code.");
|
|
1926
|
+
} finally {
|
|
1927
|
+
setBusy(false);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
async function beginSms() {
|
|
1931
|
+
setBusy(true);
|
|
1932
|
+
setError(null);
|
|
1933
|
+
try {
|
|
1934
|
+
const enrollment = await client.auth.mfa.enrollSms(
|
|
1935
|
+
token,
|
|
1936
|
+
phone.trim() ? { phone: phone.trim() } : {}
|
|
1937
|
+
);
|
|
1938
|
+
setStage({ name: "enrollingEmail", ...enrollment });
|
|
1939
|
+
} catch (cause) {
|
|
1940
|
+
setError(cause instanceof Error ? cause.message : "Could not send a code.");
|
|
1941
|
+
} finally {
|
|
1942
|
+
setBusy(false);
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
async function confirm() {
|
|
1946
|
+
if (stage.name !== "enrolling" && stage.name !== "enrollingEmail") {
|
|
1947
|
+
return;
|
|
1948
|
+
}
|
|
1949
|
+
setBusy(true);
|
|
1950
|
+
setError(null);
|
|
1951
|
+
try {
|
|
1952
|
+
const result = await client.auth.mfa.confirm(token, {
|
|
1953
|
+
factorId: stage.factorId,
|
|
1954
|
+
code: code.trim()
|
|
1955
|
+
});
|
|
1956
|
+
setStage({ name: "saved", recoveryCodes: result.recoveryCodes });
|
|
1957
|
+
setOn(true);
|
|
1958
|
+
setCode("");
|
|
1959
|
+
onEnabled?.();
|
|
1960
|
+
} catch (cause) {
|
|
1961
|
+
setError(cause instanceof Error ? cause.message : "That code did not match.");
|
|
1962
|
+
} finally {
|
|
1963
|
+
setBusy(false);
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
async function disable() {
|
|
1967
|
+
setBusy(true);
|
|
1968
|
+
setError(null);
|
|
1969
|
+
try {
|
|
1970
|
+
await client.auth.mfa.disable(token);
|
|
1971
|
+
setOn(false);
|
|
1972
|
+
setStage({ name: "idle" });
|
|
1973
|
+
onDisabled?.();
|
|
1974
|
+
} catch (cause) {
|
|
1975
|
+
setError(cause instanceof Error ? cause.message : "Could not turn it off.");
|
|
1976
|
+
} finally {
|
|
1977
|
+
setBusy(false);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
return /* @__PURE__ */ jsxs11("div", { className: cls("b316-card b316-mfa", className), style, children: [
|
|
1981
|
+
/* @__PURE__ */ jsx12("h3", { className: "b316-mfa-title", children: "Two-factor authentication" }),
|
|
1982
|
+
error ? /* @__PURE__ */ jsx12("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
1983
|
+
stage.name === "saved" ? /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-codes", children: [
|
|
1984
|
+
/* @__PURE__ */ jsx12("p", { children: "Save these recovery codes somewhere safe. Each one signs you in once if you lose your authenticator, and they are not shown again." }),
|
|
1985
|
+
/* @__PURE__ */ jsx12("ul", { className: "b316-mfa-code-list", children: stage.recoveryCodes.map((recovery) => /* @__PURE__ */ jsx12("li", { children: /* @__PURE__ */ jsx12("code", { children: recovery }) }, recovery)) }),
|
|
1986
|
+
/* @__PURE__ */ jsx12("button", { type: "button", className: "b316-button", onClick: () => setStage({ name: "idle" }), children: "I have saved them" })
|
|
1987
|
+
] }) : stage.name === "smsNumber" ? /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-enrol", children: [
|
|
1988
|
+
/* @__PURE__ */ jsx12("p", { children: "We will text a code to this number now, and each time you sign in." }),
|
|
1989
|
+
/* @__PURE__ */ jsx12("label", { className: "b316-label", htmlFor: "b316-mfa-phone", children: "Mobile number" }),
|
|
1990
|
+
/* @__PURE__ */ jsx12(
|
|
1991
|
+
"input",
|
|
1992
|
+
{
|
|
1993
|
+
id: "b316-mfa-phone",
|
|
1994
|
+
className: "b316-input",
|
|
1995
|
+
type: "tel",
|
|
1996
|
+
autoComplete: "tel",
|
|
1997
|
+
placeholder: "+14155550123",
|
|
1998
|
+
value: phone,
|
|
1999
|
+
onChange: (event) => setPhone(event.target.value)
|
|
2000
|
+
}
|
|
2001
|
+
),
|
|
2002
|
+
/* @__PURE__ */ jsxs11("div", { className: "b316-mfa-actions", children: [
|
|
2003
|
+
/* @__PURE__ */ jsx12(
|
|
2004
|
+
"button",
|
|
2005
|
+
{
|
|
2006
|
+
type: "button",
|
|
2007
|
+
className: "b316-button-quiet",
|
|
2008
|
+
onClick: () => setStage({ name: "idle" }),
|
|
2009
|
+
children: "Cancel"
|
|
2010
|
+
}
|
|
2011
|
+
),
|
|
2012
|
+
/* @__PURE__ */ jsx12("button", { type: "button", className: "b316-button", disabled: busy, onClick: beginSms, children: busy ? "Sending\u2026" : "Send code" })
|
|
2013
|
+
] })
|
|
2014
|
+
] }) : stage.name === "enrollingEmail" ? /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-enrol", children: [
|
|
2015
|
+
/* @__PURE__ */ jsxs11("p", { children: [
|
|
2016
|
+
"We sent a code to ",
|
|
2017
|
+
stage.destinationHint,
|
|
2018
|
+
". Enter it below to turn this on."
|
|
2019
|
+
] }),
|
|
2020
|
+
/* @__PURE__ */ jsx12("label", { className: "b316-label", htmlFor: "b316-mfa-code", children: "Code" }),
|
|
2021
|
+
/* @__PURE__ */ jsx12(
|
|
2022
|
+
"input",
|
|
2023
|
+
{
|
|
2024
|
+
id: "b316-mfa-code",
|
|
2025
|
+
className: "b316-input",
|
|
2026
|
+
inputMode: "numeric",
|
|
2027
|
+
autoComplete: "one-time-code",
|
|
2028
|
+
value: code,
|
|
2029
|
+
onChange: (event) => setCode(event.target.value)
|
|
2030
|
+
}
|
|
2031
|
+
),
|
|
2032
|
+
/* @__PURE__ */ jsxs11("div", { className: "b316-mfa-actions", children: [
|
|
2033
|
+
/* @__PURE__ */ jsx12(
|
|
2034
|
+
"button",
|
|
2035
|
+
{
|
|
2036
|
+
type: "button",
|
|
2037
|
+
className: "b316-button-quiet",
|
|
2038
|
+
onClick: () => setStage({ name: "idle" }),
|
|
2039
|
+
children: "Cancel"
|
|
2040
|
+
}
|
|
2041
|
+
),
|
|
2042
|
+
/* @__PURE__ */ jsx12(
|
|
2043
|
+
"button",
|
|
2044
|
+
{
|
|
2045
|
+
type: "button",
|
|
2046
|
+
className: "b316-button",
|
|
2047
|
+
disabled: busy || !code,
|
|
2048
|
+
onClick: confirm,
|
|
2049
|
+
children: busy ? "Checking\u2026" : "Turn on"
|
|
2050
|
+
}
|
|
2051
|
+
)
|
|
2052
|
+
] })
|
|
2053
|
+
] }) : stage.name === "enrolling" ? /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-enrol", children: [
|
|
2054
|
+
/* @__PURE__ */ jsx12("p", { children: "Add this to your authenticator app, then enter the six-digit code it shows." }),
|
|
2055
|
+
/* @__PURE__ */ jsx12("div", { className: "b316-mfa-secret", children: /* @__PURE__ */ jsx12("code", { children: stage.secret }) }),
|
|
2056
|
+
/* @__PURE__ */ jsx12("a", { className: "b316-mfa-uri", href: stage.uri, children: "Open in an authenticator app" }),
|
|
2057
|
+
/* @__PURE__ */ jsx12("label", { className: "b316-label", htmlFor: "b316-mfa-code", children: "Code" }),
|
|
2058
|
+
/* @__PURE__ */ jsx12(
|
|
2059
|
+
"input",
|
|
2060
|
+
{
|
|
2061
|
+
id: "b316-mfa-code",
|
|
2062
|
+
className: "b316-input",
|
|
2063
|
+
inputMode: "numeric",
|
|
2064
|
+
autoComplete: "one-time-code",
|
|
2065
|
+
value: code,
|
|
2066
|
+
onChange: (event) => setCode(event.target.value)
|
|
2067
|
+
}
|
|
2068
|
+
),
|
|
2069
|
+
/* @__PURE__ */ jsxs11("div", { className: "b316-mfa-actions", children: [
|
|
2070
|
+
/* @__PURE__ */ jsx12(
|
|
2071
|
+
"button",
|
|
2072
|
+
{
|
|
2073
|
+
type: "button",
|
|
2074
|
+
className: "b316-button-quiet",
|
|
2075
|
+
onClick: () => setStage({ name: "idle" }),
|
|
2076
|
+
children: "Cancel"
|
|
2077
|
+
}
|
|
2078
|
+
),
|
|
2079
|
+
/* @__PURE__ */ jsx12(
|
|
2080
|
+
"button",
|
|
2081
|
+
{
|
|
2082
|
+
type: "button",
|
|
2083
|
+
className: "b316-button",
|
|
2084
|
+
disabled: busy || !code,
|
|
2085
|
+
onClick: confirm,
|
|
2086
|
+
children: busy ? "Checking\u2026" : "Turn on"
|
|
2087
|
+
}
|
|
2088
|
+
)
|
|
2089
|
+
] })
|
|
2090
|
+
] }) : on ? /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-on", children: [
|
|
2091
|
+
/* @__PURE__ */ jsx12("p", { className: "b316-muted", children: "On. You will be asked for a code when you sign in." }),
|
|
2092
|
+
/* @__PURE__ */ jsx12(
|
|
2093
|
+
ConfirmButton,
|
|
2094
|
+
{
|
|
2095
|
+
className: "b316-button-quiet b316-danger",
|
|
2096
|
+
disabled: busy,
|
|
2097
|
+
confirmLabel: "Turn off two-factor authentication",
|
|
2098
|
+
onConfirm: disable,
|
|
2099
|
+
children: "Turn off"
|
|
2100
|
+
}
|
|
2101
|
+
)
|
|
2102
|
+
] }) : /* @__PURE__ */ jsxs11("div", { className: "b316-mfa-off", children: [
|
|
2103
|
+
/* @__PURE__ */ jsx12("p", { className: "b316-muted", children: "Off. Turning it on means a code as well as your password, every time you sign in." }),
|
|
2104
|
+
/* @__PURE__ */ jsxs11("div", { className: "b316-mfa-actions", children: [
|
|
2105
|
+
/* @__PURE__ */ jsx12("button", { type: "button", className: "b316-button", disabled: busy, onClick: begin, children: busy ? "Starting\u2026" : "Use an authenticator app" }),
|
|
2106
|
+
/* @__PURE__ */ jsx12(
|
|
2107
|
+
"button",
|
|
2108
|
+
{
|
|
2109
|
+
type: "button",
|
|
2110
|
+
className: "b316-button-quiet",
|
|
2111
|
+
disabled: busy,
|
|
2112
|
+
onClick: beginEmail,
|
|
2113
|
+
children: "Email me a code"
|
|
2114
|
+
}
|
|
2115
|
+
),
|
|
2116
|
+
allowSms ? /* @__PURE__ */ jsx12(
|
|
2117
|
+
"button",
|
|
2118
|
+
{
|
|
2119
|
+
type: "button",
|
|
2120
|
+
className: "b316-button-quiet",
|
|
2121
|
+
disabled: busy,
|
|
2122
|
+
onClick: () => setStage({ name: "smsNumber" }),
|
|
2123
|
+
children: "Text me a code"
|
|
2124
|
+
}
|
|
2125
|
+
) : null
|
|
2126
|
+
] })
|
|
2127
|
+
] })
|
|
2128
|
+
] });
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// src/ForgotPassword.tsx
|
|
2132
|
+
import { useState as useState11 } from "react";
|
|
2133
|
+
import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
2134
|
+
function ForgotPassword({ onSent, signInUrl, className, style }) {
|
|
2135
|
+
const { client } = useBase316();
|
|
2136
|
+
const [email, setEmail] = useState11("");
|
|
2137
|
+
const [sent, setSent] = useState11(false);
|
|
2138
|
+
const [busy, setBusy] = useState11(false);
|
|
2139
|
+
const [error, setError] = useState11(null);
|
|
2140
|
+
async function submit(event) {
|
|
2141
|
+
event.preventDefault();
|
|
2142
|
+
setBusy(true);
|
|
2143
|
+
setError(null);
|
|
2144
|
+
try {
|
|
2145
|
+
await client.auth.requestPasswordReset({ email: email.trim() });
|
|
2146
|
+
setSent(true);
|
|
2147
|
+
onSent?.(email.trim());
|
|
2148
|
+
} catch (cause) {
|
|
2149
|
+
setError(cause instanceof Error ? cause.message : "Could not send the link.");
|
|
2150
|
+
} finally {
|
|
2151
|
+
setBusy(false);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
if (sent) {
|
|
2155
|
+
return /* @__PURE__ */ jsxs12("div", { className: cls("b316-card", className), style, children: [
|
|
2156
|
+
/* @__PURE__ */ jsx13("h3", { className: "b316-form-title", children: "Check your email" }),
|
|
2157
|
+
/* @__PURE__ */ jsxs12("p", { className: "b316-muted", children: [
|
|
2158
|
+
"If there is an account for ",
|
|
2159
|
+
email.trim(),
|
|
2160
|
+
", a link to set a new password is on its way."
|
|
2161
|
+
] }),
|
|
2162
|
+
signInUrl ? /* @__PURE__ */ jsx13("a", { className: "b316-button-link", href: signInUrl, children: "Back to sign in" }) : null
|
|
2163
|
+
] });
|
|
2164
|
+
}
|
|
2165
|
+
return /* @__PURE__ */ jsxs12("form", { className: cls("b316-card b316-form", className), style, onSubmit: submit, children: [
|
|
2166
|
+
/* @__PURE__ */ jsx13("h3", { className: "b316-form-title", children: "Reset your password" }),
|
|
2167
|
+
error ? /* @__PURE__ */ jsx13("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
2168
|
+
/* @__PURE__ */ jsxs12("div", { className: "b316-field", children: [
|
|
2169
|
+
/* @__PURE__ */ jsx13("label", { className: "b316-label", htmlFor: "b316-forgot-email", children: "Email" }),
|
|
2170
|
+
/* @__PURE__ */ jsx13(
|
|
2171
|
+
"input",
|
|
2172
|
+
{
|
|
2173
|
+
id: "b316-forgot-email",
|
|
2174
|
+
className: "b316-input",
|
|
2175
|
+
type: "email",
|
|
2176
|
+
autoComplete: "email",
|
|
2177
|
+
required: true,
|
|
2178
|
+
value: email,
|
|
2179
|
+
onChange: (event) => setEmail(event.target.value)
|
|
2180
|
+
}
|
|
2181
|
+
)
|
|
2182
|
+
] }),
|
|
2183
|
+
/* @__PURE__ */ jsx13("button", { type: "submit", className: "b316-button", disabled: busy || !email, children: busy ? "Sending\u2026" : "Send reset link" }),
|
|
2184
|
+
signInUrl ? /* @__PURE__ */ jsx13("a", { className: "b316-button-link", href: signInUrl, children: "Back to sign in" }) : null
|
|
2185
|
+
] });
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
// src/ResetPassword.tsx
|
|
2189
|
+
import { useEffect as useEffect7, useState as useState12 } from "react";
|
|
2190
|
+
import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2191
|
+
function ResetPassword({
|
|
2192
|
+
token: supplied,
|
|
2193
|
+
onReset,
|
|
2194
|
+
signInUrl,
|
|
2195
|
+
className,
|
|
2196
|
+
style
|
|
2197
|
+
}) {
|
|
2198
|
+
const { client } = useBase316();
|
|
2199
|
+
const [token, setToken] = useState12(supplied ?? null);
|
|
2200
|
+
const [password, setPassword] = useState12("");
|
|
2201
|
+
const [confirmation, setConfirmation] = useState12("");
|
|
2202
|
+
const [done, setDone] = useState12(false);
|
|
2203
|
+
const [busy, setBusy] = useState12(false);
|
|
2204
|
+
const [error, setError] = useState12(null);
|
|
2205
|
+
useEffect7(() => {
|
|
2206
|
+
if (supplied || typeof window === "undefined") {
|
|
2207
|
+
return;
|
|
2208
|
+
}
|
|
2209
|
+
const url = new URL(window.location.href);
|
|
2210
|
+
const found = url.searchParams.get("token");
|
|
2211
|
+
if (!found) {
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
url.searchParams.delete("token");
|
|
2215
|
+
window.history.replaceState({}, "", url.toString());
|
|
2216
|
+
setToken(found);
|
|
2217
|
+
}, [supplied]);
|
|
2218
|
+
async function submit(event) {
|
|
2219
|
+
event.preventDefault();
|
|
2220
|
+
if (password !== confirmation) {
|
|
2221
|
+
setError("Those do not match.");
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
if (!token) {
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
setBusy(true);
|
|
2228
|
+
setError(null);
|
|
2229
|
+
try {
|
|
2230
|
+
await client.auth.completePasswordReset({ token, password });
|
|
2231
|
+
setDone(true);
|
|
2232
|
+
onReset?.();
|
|
2233
|
+
} catch (cause) {
|
|
2234
|
+
setError(cause instanceof Error ? cause.message : "That link is no longer valid.");
|
|
2235
|
+
} finally {
|
|
2236
|
+
setBusy(false);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
if (done) {
|
|
2240
|
+
return /* @__PURE__ */ jsxs13("div", { className: cls("b316-card", className), style, children: [
|
|
2241
|
+
/* @__PURE__ */ jsx14("h3", { className: "b316-form-title", children: "Password changed" }),
|
|
2242
|
+
/* @__PURE__ */ jsx14("p", { className: "b316-muted", children: "You can sign in with your new password." }),
|
|
2243
|
+
signInUrl ? /* @__PURE__ */ jsx14("a", { className: "b316-button-link", href: signInUrl, children: "Sign in" }) : null
|
|
2244
|
+
] });
|
|
2245
|
+
}
|
|
2246
|
+
if (!token) {
|
|
2247
|
+
return /* @__PURE__ */ jsxs13("div", { className: cls("b316-card", className), style, children: [
|
|
2248
|
+
/* @__PURE__ */ jsx14("h3", { className: "b316-form-title", children: "Nothing to reset" }),
|
|
2249
|
+
/* @__PURE__ */ jsx14("p", { className: "b316-muted", children: "This page needs the link from your email. Request a new one if yours has expired." })
|
|
2250
|
+
] });
|
|
2251
|
+
}
|
|
2252
|
+
return /* @__PURE__ */ jsxs13("form", { className: cls("b316-card b316-form", className), style, onSubmit: submit, children: [
|
|
2253
|
+
/* @__PURE__ */ jsx14("h3", { className: "b316-form-title", children: "Choose a new password" }),
|
|
2254
|
+
error ? /* @__PURE__ */ jsx14("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
2255
|
+
/* @__PURE__ */ jsxs13("div", { className: "b316-field", children: [
|
|
2256
|
+
/* @__PURE__ */ jsx14("label", { className: "b316-label", htmlFor: "b316-reset-password", children: "New password" }),
|
|
2257
|
+
/* @__PURE__ */ jsx14(
|
|
2258
|
+
"input",
|
|
2259
|
+
{
|
|
2260
|
+
id: "b316-reset-password",
|
|
2261
|
+
className: "b316-input",
|
|
2262
|
+
type: "password",
|
|
2263
|
+
autoComplete: "new-password",
|
|
2264
|
+
required: true,
|
|
2265
|
+
value: password,
|
|
2266
|
+
onChange: (event) => setPassword(event.target.value)
|
|
2267
|
+
}
|
|
2268
|
+
)
|
|
2269
|
+
] }),
|
|
2270
|
+
/* @__PURE__ */ jsxs13("div", { className: "b316-field", children: [
|
|
2271
|
+
/* @__PURE__ */ jsx14("label", { className: "b316-label", htmlFor: "b316-reset-confirm", children: "Repeat it" }),
|
|
2272
|
+
/* @__PURE__ */ jsx14(
|
|
2273
|
+
"input",
|
|
2274
|
+
{
|
|
2275
|
+
id: "b316-reset-confirm",
|
|
2276
|
+
className: "b316-input",
|
|
2277
|
+
type: "password",
|
|
2278
|
+
autoComplete: "new-password",
|
|
2279
|
+
required: true,
|
|
2280
|
+
value: confirmation,
|
|
2281
|
+
onChange: (event) => setConfirmation(event.target.value)
|
|
2282
|
+
}
|
|
2283
|
+
)
|
|
2284
|
+
] }),
|
|
2285
|
+
/* @__PURE__ */ jsx14("button", { type: "submit", className: "b316-button", disabled: busy || !password, children: busy ? "Saving\u2026" : "Set password" })
|
|
2286
|
+
] });
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
// src/VerifyEmail.tsx
|
|
2290
|
+
import { useEffect as useEffect8, useRef as useRef3, useState as useState13 } from "react";
|
|
2291
|
+
import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
2292
|
+
function VerifyEmail({
|
|
2293
|
+
token: supplied,
|
|
2294
|
+
onVerified,
|
|
2295
|
+
continueUrl,
|
|
2296
|
+
className,
|
|
2297
|
+
style
|
|
2298
|
+
}) {
|
|
2299
|
+
const { client } = useBase316();
|
|
2300
|
+
const [state, setState] = useState13("waiting");
|
|
2301
|
+
const spent = useRef3(false);
|
|
2302
|
+
useEffect8(() => {
|
|
2303
|
+
if (spent.current) {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
let token = supplied ?? null;
|
|
2307
|
+
if (!token && typeof window !== "undefined") {
|
|
2308
|
+
const url = new URL(window.location.href);
|
|
2309
|
+
token = url.searchParams.get("token");
|
|
2310
|
+
if (token) {
|
|
2311
|
+
url.searchParams.delete("token");
|
|
2312
|
+
window.history.replaceState({}, "", url.toString());
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
if (!token) {
|
|
2316
|
+
setState("missing");
|
|
2317
|
+
return;
|
|
2318
|
+
}
|
|
2319
|
+
spent.current = true;
|
|
2320
|
+
setState("verifying");
|
|
2321
|
+
client.auth.verifyEmail({ token }).then(() => {
|
|
2322
|
+
setState("verified");
|
|
2323
|
+
onVerified?.();
|
|
2324
|
+
}).catch(() => {
|
|
2325
|
+
setState("failed");
|
|
2326
|
+
});
|
|
2327
|
+
}, [client, supplied, onVerified]);
|
|
2328
|
+
return /* @__PURE__ */ jsx15("div", { className: cls("b316-card", className), style, children: state === "verified" ? /* @__PURE__ */ jsxs14(Fragment2, { children: [
|
|
2329
|
+
/* @__PURE__ */ jsx15("h3", { className: "b316-form-title", children: "Email confirmed" }),
|
|
2330
|
+
/* @__PURE__ */ jsx15("p", { className: "b316-muted", children: "Thanks \u2014 your address is verified." }),
|
|
2331
|
+
continueUrl ? /* @__PURE__ */ jsx15("a", { className: "b316-button-link", href: continueUrl, children: "Continue" }) : null
|
|
2332
|
+
] }) : state === "failed" ? /* @__PURE__ */ jsxs14(Fragment2, { children: [
|
|
2333
|
+
/* @__PURE__ */ jsx15("h3", { className: "b316-form-title", children: "That link did not work" }),
|
|
2334
|
+
/* @__PURE__ */ jsx15("p", { className: "b316-muted", children: "It may have expired or already been used. Ask for a new one and try again." })
|
|
2335
|
+
] }) : state === "missing" ? /* @__PURE__ */ jsxs14(Fragment2, { children: [
|
|
2336
|
+
/* @__PURE__ */ jsx15("h3", { className: "b316-form-title", children: "Nothing to confirm" }),
|
|
2337
|
+
/* @__PURE__ */ jsx15("p", { className: "b316-muted", children: "This page needs the link from your email." })
|
|
2338
|
+
] }) : /* @__PURE__ */ jsx15("p", { className: "b316-muted", children: "Confirming your email\u2026" }) });
|
|
2339
|
+
}
|
|
2340
|
+
|
|
2341
|
+
// src/TeamMembers.tsx
|
|
2342
|
+
import { useCallback as useCallback5, useEffect as useEffect9, useState as useState14 } from "react";
|
|
2343
|
+
import { Fragment as Fragment3, jsx as jsx16, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2344
|
+
function TeamMembers({
|
|
2345
|
+
organizationId,
|
|
2346
|
+
onInvited,
|
|
2347
|
+
acceptUrl,
|
|
2348
|
+
onLeft,
|
|
2349
|
+
className,
|
|
2350
|
+
style
|
|
2351
|
+
}) {
|
|
2352
|
+
const { client, token, session } = useBase316();
|
|
2353
|
+
const [teams, setTeams] = useState14(null);
|
|
2354
|
+
const [members, setMembers] = useState14(null);
|
|
2355
|
+
const [invitations, setInvitations] = useState14(null);
|
|
2356
|
+
const [email, setEmail] = useState14("");
|
|
2357
|
+
const [busy, setBusy] = useState14(false);
|
|
2358
|
+
const [error, setError] = useState14(null);
|
|
2359
|
+
const [copied, setCopied] = useState14(null);
|
|
2360
|
+
const chosen = organizationId ?? (teams?.length === 1 ? teams[0].id : null);
|
|
2361
|
+
const team = teams?.find((candidate) => candidate.id === chosen) ?? null;
|
|
2362
|
+
const load = useCallback5(() => {
|
|
2363
|
+
if (!token) {
|
|
2364
|
+
return;
|
|
2365
|
+
}
|
|
2366
|
+
client.teams.list(token).then((result) => setTeams(result.data)).catch(
|
|
2367
|
+
(cause) => setError(cause instanceof Error ? cause.message : "Could not load your teams.")
|
|
2368
|
+
);
|
|
2369
|
+
}, [client, token]);
|
|
2370
|
+
useEffect9(load, [load]);
|
|
2371
|
+
useEffect9(() => {
|
|
2372
|
+
if (!token || !chosen) {
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
let cancelled = false;
|
|
2376
|
+
client.teams.members(token, chosen).then((result) => {
|
|
2377
|
+
if (!cancelled) {
|
|
2378
|
+
setMembers(result.data);
|
|
2379
|
+
}
|
|
2380
|
+
}).catch((cause) => {
|
|
2381
|
+
if (!cancelled) {
|
|
2382
|
+
setError(cause instanceof Error ? cause.message : "Could not load the members.");
|
|
2383
|
+
}
|
|
2384
|
+
});
|
|
2385
|
+
client.teams.invitations(token, chosen).then((result) => {
|
|
2386
|
+
if (!cancelled) {
|
|
2387
|
+
setInvitations(result.data);
|
|
2388
|
+
}
|
|
2389
|
+
}).catch(() => {
|
|
2390
|
+
if (!cancelled) {
|
|
2391
|
+
setInvitations(null);
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
return () => {
|
|
2395
|
+
cancelled = true;
|
|
2396
|
+
};
|
|
2397
|
+
}, [client, token, chosen]);
|
|
2398
|
+
if (!token) {
|
|
2399
|
+
return null;
|
|
2400
|
+
}
|
|
2401
|
+
if (!teams) {
|
|
2402
|
+
return /* @__PURE__ */ jsx16("div", { className: cls("b316-card", className), style, children: error ?? "Loading\u2026" });
|
|
2403
|
+
}
|
|
2404
|
+
if (!chosen) {
|
|
2405
|
+
return /* @__PURE__ */ jsx16("div", { className: cls("b316-card", className), style, children: teams.length === 0 ? "You are not in a team yet." : "You are in more than one team. Name which with the organizationId prop." });
|
|
2406
|
+
}
|
|
2407
|
+
const canManage = invitations !== null;
|
|
2408
|
+
async function invite(event) {
|
|
2409
|
+
event.preventDefault();
|
|
2410
|
+
setBusy(true);
|
|
2411
|
+
setError(null);
|
|
2412
|
+
try {
|
|
2413
|
+
const result = await client.teams.invite(token, chosen, {
|
|
2414
|
+
email: email.trim()
|
|
2415
|
+
});
|
|
2416
|
+
const url = acceptUrl ? `${acceptUrl}${acceptUrl.includes("?") ? "&" : "?"}invitation=${encodeURIComponent(result.token)}` : void 0;
|
|
2417
|
+
onInvited?.({ email: email.trim(), token: result.token, url });
|
|
2418
|
+
if (!onInvited) {
|
|
2419
|
+
setCopied(url ?? result.token);
|
|
2420
|
+
}
|
|
2421
|
+
setEmail("");
|
|
2422
|
+
setInvitations((current) => [result.invitation, ...current ?? []]);
|
|
2423
|
+
} catch (cause) {
|
|
2424
|
+
setError(cause instanceof Error ? cause.message : "That invitation could not be sent.");
|
|
2425
|
+
} finally {
|
|
2426
|
+
setBusy(false);
|
|
2427
|
+
}
|
|
2428
|
+
}
|
|
2429
|
+
async function remove(userId) {
|
|
2430
|
+
const leaving = userId === session?.userId;
|
|
2431
|
+
setBusy(true);
|
|
2432
|
+
setError(null);
|
|
2433
|
+
try {
|
|
2434
|
+
await client.teams.removeMember(token, chosen, userId);
|
|
2435
|
+
if (leaving) {
|
|
2436
|
+
onLeft?.();
|
|
2437
|
+
load();
|
|
2438
|
+
} else {
|
|
2439
|
+
setMembers((current) => (current ?? []).filter((member) => member.user.id !== userId));
|
|
2440
|
+
}
|
|
2441
|
+
} catch (cause) {
|
|
2442
|
+
setError(cause instanceof Error ? cause.message : "That did not work.");
|
|
2443
|
+
} finally {
|
|
2444
|
+
setBusy(false);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
async function withdraw(invitationId) {
|
|
2448
|
+
try {
|
|
2449
|
+
await client.teams.revokeInvitation(token, chosen, invitationId);
|
|
2450
|
+
setInvitations((current) => (current ?? []).filter((one) => one.id !== invitationId));
|
|
2451
|
+
} catch (cause) {
|
|
2452
|
+
setError(cause instanceof Error ? cause.message : "That invitation could not be withdrawn.");
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
return /* @__PURE__ */ jsxs15("div", { className: cls("b316-card b316-team", className), style, children: [
|
|
2456
|
+
/* @__PURE__ */ jsx16("h3", { className: "b316-team-title", children: team?.name ?? "Team" }),
|
|
2457
|
+
team?.inherited ? (
|
|
2458
|
+
// Not a member of this team, so not in the list below and with nothing
|
|
2459
|
+
// to leave: access comes from the team that manages it, and ends there.
|
|
2460
|
+
/* @__PURE__ */ jsxs15("div", { className: "b316-muted", children: [
|
|
2461
|
+
"You have access through",
|
|
2462
|
+
" ",
|
|
2463
|
+
teams.find((candidate) => candidate.id === team.via)?.name ?? "the organization that manages this team",
|
|
2464
|
+
"."
|
|
2465
|
+
] })
|
|
2466
|
+
) : null,
|
|
2467
|
+
error ? /* @__PURE__ */ jsx16("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
2468
|
+
/* @__PURE__ */ jsx16("ul", { className: "b316-team-list", children: (members ?? []).map((member) => /* @__PURE__ */ jsxs15("li", { className: "b316-team-member", children: [
|
|
2469
|
+
/* @__PURE__ */ jsxs15("div", { children: [
|
|
2470
|
+
/* @__PURE__ */ jsx16("div", { children: member.user.name ?? member.user.email ?? "Someone" }),
|
|
2471
|
+
/* @__PURE__ */ jsxs15("div", { className: "b316-muted", children: [
|
|
2472
|
+
member.user.email,
|
|
2473
|
+
member.user.id === session?.userId ? " \xB7 you" : ""
|
|
2474
|
+
] })
|
|
2475
|
+
] }),
|
|
2476
|
+
/* @__PURE__ */ jsxs15("div", { className: "b316-team-member-side", children: [
|
|
2477
|
+
/* @__PURE__ */ jsx16("span", { className: "b316-chip", children: member.role.name }),
|
|
2478
|
+
canManage || member.user.id === session?.userId ? /* @__PURE__ */ jsx16(
|
|
2479
|
+
ConfirmButton,
|
|
2480
|
+
{
|
|
2481
|
+
className: "b316-button-quiet b316-danger",
|
|
2482
|
+
disabled: busy,
|
|
2483
|
+
confirmLabel: member.user.id === session?.userId ? "Leave this team" : `Remove ${member.user.name ?? member.user.email ?? "them"}`,
|
|
2484
|
+
onConfirm: () => remove(member.user.id),
|
|
2485
|
+
children: member.user.id === session?.userId ? "Leave" : "Remove"
|
|
2486
|
+
}
|
|
2487
|
+
) : null
|
|
2488
|
+
] })
|
|
2489
|
+
] }, member.id)) }),
|
|
2490
|
+
canManage && (invitations ?? []).length > 0 ? /* @__PURE__ */ jsxs15(Fragment3, { children: [
|
|
2491
|
+
/* @__PURE__ */ jsx16("h4", { className: "b316-team-subtitle", children: "Invited" }),
|
|
2492
|
+
/* @__PURE__ */ jsx16("ul", { className: "b316-team-list", children: (invitations ?? []).map((invitation) => /* @__PURE__ */ jsxs15("li", { className: "b316-team-member", children: [
|
|
2493
|
+
/* @__PURE__ */ jsxs15("div", { children: [
|
|
2494
|
+
/* @__PURE__ */ jsx16("div", { children: invitation.email }),
|
|
2495
|
+
/* @__PURE__ */ jsxs15("div", { className: "b316-muted", children: [
|
|
2496
|
+
invitation.role.name,
|
|
2497
|
+
" \xB7 expires",
|
|
2498
|
+
" ",
|
|
2499
|
+
new Date(invitation.expiresAt).toLocaleDateString()
|
|
2500
|
+
] })
|
|
2501
|
+
] }),
|
|
2502
|
+
/* @__PURE__ */ jsx16(
|
|
2503
|
+
"button",
|
|
2504
|
+
{
|
|
2505
|
+
type: "button",
|
|
2506
|
+
className: "b316-button-quiet",
|
|
2507
|
+
onClick: () => void withdraw(invitation.id),
|
|
2508
|
+
children: "Withdraw"
|
|
2509
|
+
}
|
|
2510
|
+
)
|
|
2511
|
+
] }, invitation.id)) })
|
|
2512
|
+
] }) : null,
|
|
2513
|
+
canManage ? /* @__PURE__ */ jsxs15("form", { className: "b316-team-invite", onSubmit: invite, children: [
|
|
2514
|
+
/* @__PURE__ */ jsx16("label", { className: "b316-label", htmlFor: "b316-invite-email", children: "Invite by email" }),
|
|
2515
|
+
/* @__PURE__ */ jsxs15("div", { className: "b316-team-invite-row", children: [
|
|
2516
|
+
/* @__PURE__ */ jsx16(
|
|
2517
|
+
"input",
|
|
2518
|
+
{
|
|
2519
|
+
id: "b316-invite-email",
|
|
2520
|
+
className: "b316-input",
|
|
2521
|
+
type: "email",
|
|
2522
|
+
required: true,
|
|
2523
|
+
placeholder: "colleague@example.com",
|
|
2524
|
+
value: email,
|
|
2525
|
+
onChange: (event) => setEmail(event.target.value)
|
|
2526
|
+
}
|
|
2527
|
+
),
|
|
2528
|
+
/* @__PURE__ */ jsx16("button", { type: "submit", className: "b316-button", disabled: busy || !email, children: busy ? "Sending\u2026" : "Invite" })
|
|
2529
|
+
] })
|
|
2530
|
+
] }) : null,
|
|
2531
|
+
copied ? /* @__PURE__ */ jsxs15("div", { className: "b316-team-link", children: [
|
|
2532
|
+
/* @__PURE__ */ jsx16("div", { className: "b316-muted", children: "Send them this link. It is shown once and cannot be fetched again." }),
|
|
2533
|
+
/* @__PURE__ */ jsx16("code", { children: copied })
|
|
2534
|
+
] }) : null
|
|
2535
|
+
] });
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
// src/AcceptInvitation.tsx
|
|
2539
|
+
import { useEffect as useEffect10, useState as useState15 } from "react";
|
|
2540
|
+
import { Fragment as Fragment4, jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
2541
|
+
function AcceptInvitation({
|
|
2542
|
+
token: supplied,
|
|
2543
|
+
onAccepted,
|
|
2544
|
+
signUpUrl,
|
|
2545
|
+
signInUrl,
|
|
2546
|
+
className,
|
|
2547
|
+
style
|
|
2548
|
+
}) {
|
|
2549
|
+
const { client, token: session, session: user } = useBase316();
|
|
2550
|
+
const [invitationToken, setInvitationToken] = useState15(supplied ?? null);
|
|
2551
|
+
const [preview, setPreview] = useState15(null);
|
|
2552
|
+
const [state, setState] = useState15("loading");
|
|
2553
|
+
const [error, setError] = useState15(null);
|
|
2554
|
+
const [busy, setBusy] = useState15(false);
|
|
2555
|
+
useEffect10(() => {
|
|
2556
|
+
if (supplied || typeof window === "undefined") {
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
setInvitationToken(new URL(window.location.href).searchParams.get("invitation"));
|
|
2560
|
+
}, [supplied]);
|
|
2561
|
+
useEffect10(() => {
|
|
2562
|
+
if (!invitationToken) {
|
|
2563
|
+
setState(supplied === void 0 ? "loading" : "invalid");
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
let cancelled = false;
|
|
2567
|
+
client.teams.preview(invitationToken).then((result) => {
|
|
2568
|
+
if (!cancelled) {
|
|
2569
|
+
setPreview(result);
|
|
2570
|
+
setState("ready");
|
|
2571
|
+
}
|
|
2572
|
+
}).catch(() => {
|
|
2573
|
+
if (!cancelled) {
|
|
2574
|
+
setState("invalid");
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
return () => {
|
|
2578
|
+
cancelled = true;
|
|
2579
|
+
};
|
|
2580
|
+
}, [client, invitationToken, supplied]);
|
|
2581
|
+
async function accept() {
|
|
2582
|
+
if (!session || !invitationToken) {
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
setBusy(true);
|
|
2586
|
+
setError(null);
|
|
2587
|
+
try {
|
|
2588
|
+
const result = await client.teams.accept(session, invitationToken);
|
|
2589
|
+
setState("accepted");
|
|
2590
|
+
onAccepted?.(result.organizationId);
|
|
2591
|
+
} catch (cause) {
|
|
2592
|
+
setError(cause instanceof Error ? cause.message : "That invitation could not be accepted.");
|
|
2593
|
+
} finally {
|
|
2594
|
+
setBusy(false);
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
if (state === "loading") {
|
|
2598
|
+
return /* @__PURE__ */ jsx17("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
2599
|
+
}
|
|
2600
|
+
if (state === "invalid") {
|
|
2601
|
+
return /* @__PURE__ */ jsxs16("div", { className: cls("b316-card", className), style, children: [
|
|
2602
|
+
/* @__PURE__ */ jsx17("h3", { className: "b316-form-title", children: "That invitation is no longer valid" }),
|
|
2603
|
+
/* @__PURE__ */ jsx17("p", { className: "b316-muted", children: "It may have expired, been withdrawn, or already been used. Ask for a new one." })
|
|
2604
|
+
] });
|
|
2605
|
+
}
|
|
2606
|
+
if (state === "accepted") {
|
|
2607
|
+
return /* @__PURE__ */ jsx17("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsxs16("h3", { className: "b316-form-title", children: [
|
|
2608
|
+
"You have joined ",
|
|
2609
|
+
preview?.organizationName
|
|
2610
|
+
] }) });
|
|
2611
|
+
}
|
|
2612
|
+
const matches = !user || (user.user.email ?? "").toLowerCase() === preview?.email.toLowerCase();
|
|
2613
|
+
return /* @__PURE__ */ jsxs16("div", { className: cls("b316-card b316-invitation", className), style, children: [
|
|
2614
|
+
/* @__PURE__ */ jsxs16("h3", { className: "b316-form-title", children: [
|
|
2615
|
+
"Join ",
|
|
2616
|
+
preview?.organizationName
|
|
2617
|
+
] }),
|
|
2618
|
+
/* @__PURE__ */ jsxs16("p", { className: "b316-muted", children: [
|
|
2619
|
+
"Invited as ",
|
|
2620
|
+
preview?.email,
|
|
2621
|
+
" \xB7 ",
|
|
2622
|
+
preview?.roleName
|
|
2623
|
+
] }),
|
|
2624
|
+
error ? /* @__PURE__ */ jsx17("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
2625
|
+
!session ? /* @__PURE__ */ jsxs16(Fragment4, { children: [
|
|
2626
|
+
/* @__PURE__ */ jsxs16("p", { children: [
|
|
2627
|
+
"Sign in as ",
|
|
2628
|
+
preview?.email,
|
|
2629
|
+
" to accept."
|
|
2630
|
+
] }),
|
|
2631
|
+
/* @__PURE__ */ jsxs16("div", { className: "b316-invitation-actions", children: [
|
|
2632
|
+
signInUrl ? /* @__PURE__ */ jsx17("a", { className: "b316-button", href: signInUrl, children: "Sign in" }) : null,
|
|
2633
|
+
signUpUrl ? /* @__PURE__ */ jsx17("a", { className: "b316-button-link", href: signUpUrl, children: "Create an account" }) : null
|
|
2634
|
+
] })
|
|
2635
|
+
] }) : !matches ? (
|
|
2636
|
+
// Said before they press anything. The server refuses this, but
|
|
2637
|
+
// finding out after a click reads as a broken invitation rather than
|
|
2638
|
+
// as being signed in as the wrong person.
|
|
2639
|
+
/* @__PURE__ */ jsxs16("p", { children: [
|
|
2640
|
+
"You are signed in as ",
|
|
2641
|
+
user?.user.email,
|
|
2642
|
+
". This invitation was sent to ",
|
|
2643
|
+
preview?.email,
|
|
2644
|
+
" \u2014 sign in as that address to accept it."
|
|
2645
|
+
] })
|
|
2646
|
+
) : /* @__PURE__ */ jsx17("button", { type: "button", className: "b316-button", disabled: busy, onClick: accept, children: busy ? "Joining\u2026" : `Join ${preview?.organizationName}` })
|
|
2647
|
+
] });
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// src/PayInvoice.tsx
|
|
2651
|
+
import { useEffect as useEffect11, useRef as useRef4, useState as useState16 } from "react";
|
|
2652
|
+
import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
2653
|
+
var STRIPE_SRC = "https://js.stripe.com/v3/";
|
|
2654
|
+
function loadStripeScript() {
|
|
2655
|
+
if (typeof window === "undefined") {
|
|
2656
|
+
return Promise.reject(new Error("Stripe.js cannot load during server rendering."));
|
|
2657
|
+
}
|
|
2658
|
+
if (window.Stripe) {
|
|
2659
|
+
return Promise.resolve();
|
|
2660
|
+
}
|
|
2661
|
+
return new Promise((resolve, reject) => {
|
|
2662
|
+
const existing = document.querySelector(`script[src="${STRIPE_SRC}"]`);
|
|
2663
|
+
if (existing) {
|
|
2664
|
+
existing.addEventListener("load", () => resolve());
|
|
2665
|
+
existing.addEventListener("error", () => reject(new Error("Stripe.js failed to load.")));
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
const script = document.createElement("script");
|
|
2669
|
+
script.src = STRIPE_SRC;
|
|
2670
|
+
script.async = true;
|
|
2671
|
+
script.onload = () => resolve();
|
|
2672
|
+
script.onerror = () => reject(new Error("Stripe.js failed to load."));
|
|
2673
|
+
document.head.appendChild(script);
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
function PayInvoice({
|
|
2677
|
+
token,
|
|
2678
|
+
environmentId,
|
|
2679
|
+
onPaid,
|
|
2680
|
+
className,
|
|
2681
|
+
style
|
|
2682
|
+
}) {
|
|
2683
|
+
const { client } = useBase316();
|
|
2684
|
+
const mountRef = useRef4(null);
|
|
2685
|
+
const stripeRef = useRef4(null);
|
|
2686
|
+
const elementsRef = useRef4(null);
|
|
2687
|
+
const [ready, setReady] = useState16(false);
|
|
2688
|
+
const [paying, setPaying] = useState16(false);
|
|
2689
|
+
const [done, setDone] = useState16(false);
|
|
2690
|
+
const [error, setError] = useState16(null);
|
|
2691
|
+
useEffect11(() => {
|
|
2692
|
+
let cancelled = false;
|
|
2693
|
+
async function start() {
|
|
2694
|
+
const base = `${client.baseUrl}/pay/${encodeURIComponent(environmentId)}/${encodeURIComponent(token)}`;
|
|
2695
|
+
const response = await fetch(`${base}/intent`, { method: "POST" });
|
|
2696
|
+
if (!response.ok) {
|
|
2697
|
+
throw new Error("This payment link is no longer valid.");
|
|
2698
|
+
}
|
|
2699
|
+
const intent = await response.json();
|
|
2700
|
+
await loadStripeScript();
|
|
2701
|
+
if (cancelled || !window.Stripe || !mountRef.current) {
|
|
2702
|
+
return;
|
|
2703
|
+
}
|
|
2704
|
+
const stripe = window.Stripe(
|
|
2705
|
+
intent.publishableKey,
|
|
2706
|
+
intent.accountId ? { stripeAccount: intent.accountId } : void 0
|
|
2707
|
+
);
|
|
2708
|
+
const elements = stripe.elements({ clientSecret: intent.clientSecret });
|
|
2709
|
+
elements.create("payment").mount(mountRef.current);
|
|
2710
|
+
stripeRef.current = stripe;
|
|
2711
|
+
elementsRef.current = elements;
|
|
2712
|
+
setReady(true);
|
|
2713
|
+
}
|
|
2714
|
+
start().catch((cause) => {
|
|
2715
|
+
if (!cancelled) {
|
|
2716
|
+
setError(cause instanceof Error ? cause.message : "Could not prepare this payment.");
|
|
2717
|
+
}
|
|
2718
|
+
});
|
|
2719
|
+
return () => {
|
|
2720
|
+
cancelled = true;
|
|
2721
|
+
};
|
|
2722
|
+
}, [client, environmentId, token]);
|
|
2723
|
+
const submit = async (event) => {
|
|
2724
|
+
event.preventDefault();
|
|
2725
|
+
if (!stripeRef.current || !elementsRef.current) {
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
setPaying(true);
|
|
2729
|
+
setError(null);
|
|
2730
|
+
const result = await stripeRef.current.confirmPayment({
|
|
2731
|
+
elements: elementsRef.current,
|
|
2732
|
+
confirmParams: { return_url: window.location.href },
|
|
2733
|
+
redirect: "if_required"
|
|
2734
|
+
});
|
|
2735
|
+
if (result.error) {
|
|
2736
|
+
setError(result.error.message ?? "That payment could not be completed.");
|
|
2737
|
+
setPaying(false);
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
setDone(true);
|
|
2741
|
+
onPaid?.();
|
|
2742
|
+
};
|
|
2743
|
+
if (done) {
|
|
2744
|
+
return /* @__PURE__ */ jsx18("div", { className: cls("b316-pay", className), style, children: /* @__PURE__ */ jsx18("p", { className: "b316-pay__done", children: "Paid \u2014 thank you." }) });
|
|
2745
|
+
}
|
|
2746
|
+
return /* @__PURE__ */ jsxs17("form", { className: cls("b316-pay", className), style, onSubmit: submit, children: [
|
|
2747
|
+
error ? /* @__PURE__ */ jsx18("p", { className: "b316-pay__error", role: "alert", children: error }) : null,
|
|
2748
|
+
/* @__PURE__ */ jsx18("div", { ref: mountRef, className: "b316-pay__element" }),
|
|
2749
|
+
/* @__PURE__ */ jsx18("button", { className: "b316-pay__submit", type: "submit", disabled: !ready || paying, children: paying ? "Paying\u2026" : "Pay" })
|
|
2750
|
+
] });
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
// src/usePaymentLink.ts
|
|
2754
|
+
import { useEffect as useEffect12, useRef as useRef5, useState as useState17 } from "react";
|
|
2755
|
+
function usePaymentLink({
|
|
2756
|
+
token,
|
|
2757
|
+
environmentId,
|
|
2758
|
+
intervalMs = 2e3,
|
|
2759
|
+
onPaid
|
|
2760
|
+
}) {
|
|
2761
|
+
const { client } = useBase316();
|
|
2762
|
+
const [status, setStatus] = useState17({ state: "loading" });
|
|
2763
|
+
const onPaidRef = useRef5(onPaid);
|
|
2764
|
+
onPaidRef.current = onPaid;
|
|
2765
|
+
useEffect12(() => {
|
|
2766
|
+
let stopped = false;
|
|
2767
|
+
let timer;
|
|
2768
|
+
const statusUrl = `${client.baseUrl}/pay/${encodeURIComponent(environmentId)}/${encodeURIComponent(token)}/status`;
|
|
2769
|
+
async function check() {
|
|
2770
|
+
try {
|
|
2771
|
+
const response = await fetch(statusUrl, { cache: "no-store" });
|
|
2772
|
+
if (stopped) {
|
|
2773
|
+
return;
|
|
2774
|
+
}
|
|
2775
|
+
if (response.status === 404) {
|
|
2776
|
+
setStatus({ state: "invalid" });
|
|
2777
|
+
return;
|
|
2778
|
+
}
|
|
2779
|
+
if (response.ok) {
|
|
2780
|
+
const body = await response.json();
|
|
2781
|
+
if (stopped) {
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2784
|
+
if (body.state === "settled") {
|
|
2785
|
+
setStatus({ state: "settled", number: body.number });
|
|
2786
|
+
onPaidRef.current?.();
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
setStatus({
|
|
2790
|
+
state: "payable",
|
|
2791
|
+
number: body.number,
|
|
2792
|
+
due: body.due ?? "0",
|
|
2793
|
+
currency: body.currency ?? "USD"
|
|
2794
|
+
});
|
|
2795
|
+
}
|
|
2796
|
+
} catch {
|
|
2797
|
+
}
|
|
2798
|
+
if (!stopped) {
|
|
2799
|
+
timer = setTimeout(check, intervalMs);
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
void check();
|
|
2803
|
+
return () => {
|
|
2804
|
+
stopped = true;
|
|
2805
|
+
if (timer) {
|
|
2806
|
+
clearTimeout(timer);
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2809
|
+
}, [client, environmentId, token, intervalMs]);
|
|
2810
|
+
return status;
|
|
2811
|
+
}
|
|
2812
|
+
|
|
2813
|
+
// src/usePlans.ts
|
|
2814
|
+
import { useCallback as useCallback6, useEffect as useEffect13, useState as useState18 } from "react";
|
|
2815
|
+
var CHECKOUT_STATUSES = /* @__PURE__ */ new Set([402, 409]);
|
|
2816
|
+
function usePlans(options = {}) {
|
|
2817
|
+
const { client, token } = useBase316();
|
|
2818
|
+
const [plans, setPlans] = useState18(null);
|
|
2819
|
+
const [error, setError] = useState18(false);
|
|
2820
|
+
const [busyPlanVersionId, setBusy] = useState18(null);
|
|
2821
|
+
const [lastError, setLastError] = useState18(null);
|
|
2822
|
+
const [ownPlanVersionId, setOwnPlanVersionId] = useState18(null);
|
|
2823
|
+
const [managedBy, setManagedBy] = useState18(null);
|
|
2824
|
+
const [reloadCount, setReloadCount] = useState18(0);
|
|
2825
|
+
const supplied = options.currentPlanVersionId;
|
|
2826
|
+
const discover = supplied === void 0;
|
|
2827
|
+
useEffect13(() => {
|
|
2828
|
+
let cancelled = false;
|
|
2829
|
+
client.billing.plans().then((result) => {
|
|
2830
|
+
if (!cancelled) {
|
|
2831
|
+
setPlans(result.data);
|
|
2832
|
+
}
|
|
2833
|
+
}).catch((cause) => {
|
|
2834
|
+
console.error("[base316] could not load plans", cause);
|
|
2835
|
+
if (!cancelled) {
|
|
2836
|
+
setError(true);
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
return () => {
|
|
2840
|
+
cancelled = true;
|
|
2841
|
+
};
|
|
2842
|
+
}, [client, reloadCount]);
|
|
2843
|
+
useEffect13(() => {
|
|
2844
|
+
if (!token) {
|
|
2845
|
+
return;
|
|
2846
|
+
}
|
|
2847
|
+
let cancelled = false;
|
|
2848
|
+
client.billing.subscription(token).then((result) => {
|
|
2849
|
+
if (!cancelled) {
|
|
2850
|
+
setManagedBy(result.managedBy ?? null);
|
|
2851
|
+
if (discover) {
|
|
2852
|
+
setOwnPlanVersionId(result.subscription?.planVersion.id ?? null);
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
}).catch(() => null);
|
|
2856
|
+
return () => {
|
|
2857
|
+
cancelled = true;
|
|
2858
|
+
};
|
|
2859
|
+
}, [client, token, discover, reloadCount]);
|
|
2860
|
+
const reload = useCallback6(() => {
|
|
2861
|
+
setError(false);
|
|
2862
|
+
setReloadCount((count) => count + 1);
|
|
2863
|
+
}, []);
|
|
2864
|
+
const selectPlan = useCallback6(
|
|
2865
|
+
async (plan) => {
|
|
2866
|
+
setLastError(null);
|
|
2867
|
+
if (managedBy) {
|
|
2868
|
+
const reason = `Your plan is provided by ${managedBy.name ?? "the organization that manages your account"}.`;
|
|
2869
|
+
setLastError(reason);
|
|
2870
|
+
return { status: "failed", reason };
|
|
2871
|
+
}
|
|
2872
|
+
if (!token) {
|
|
2873
|
+
return { status: "needs-sign-in" };
|
|
2874
|
+
}
|
|
2875
|
+
setBusy(plan.planVersionId);
|
|
2876
|
+
const go = (url) => {
|
|
2877
|
+
const navigate = options.navigate ?? true;
|
|
2878
|
+
if (typeof navigate === "function") {
|
|
2879
|
+
navigate(url);
|
|
2880
|
+
} else if (navigate && typeof window !== "undefined") {
|
|
2881
|
+
window.location.assign(url);
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
try {
|
|
2885
|
+
await client.billing.changePlan(token, plan.planVersionId);
|
|
2886
|
+
setOwnPlanVersionId(plan.planVersionId);
|
|
2887
|
+
return { status: "changed", planVersionId: plan.planVersionId };
|
|
2888
|
+
} catch (cause) {
|
|
2889
|
+
const status = cause.status ?? null;
|
|
2890
|
+
if (status === null || !CHECKOUT_STATUSES.has(status)) {
|
|
2891
|
+
const reason = cause instanceof Error ? cause.message : "Could not change plan.";
|
|
2892
|
+
setLastError(reason);
|
|
2893
|
+
return { status: "failed", reason };
|
|
2894
|
+
}
|
|
2895
|
+
try {
|
|
2896
|
+
const session = await client.billing.checkout(token, plan.planVersionId);
|
|
2897
|
+
go(session.url);
|
|
2898
|
+
return { status: "checkout", url: session.url };
|
|
2899
|
+
} catch (checkoutCause) {
|
|
2900
|
+
const reason = checkoutCause instanceof Error ? checkoutCause.message : "Could not start checkout.";
|
|
2901
|
+
setLastError(reason);
|
|
2902
|
+
return { status: "failed", reason };
|
|
2903
|
+
}
|
|
2904
|
+
} finally {
|
|
2905
|
+
setBusy(null);
|
|
2906
|
+
}
|
|
2907
|
+
},
|
|
2908
|
+
[client, token, options.navigate, managedBy]
|
|
2909
|
+
);
|
|
2910
|
+
return {
|
|
2911
|
+
plans,
|
|
2912
|
+
loading: plans === null && !error,
|
|
2913
|
+
error,
|
|
2914
|
+
currentPlanVersionId: discover ? ownPlanVersionId : supplied ?? null,
|
|
2915
|
+
busyPlanVersionId,
|
|
2916
|
+
lastError,
|
|
2917
|
+
signedIn: token !== null,
|
|
2918
|
+
managedBy,
|
|
2919
|
+
selectPlan,
|
|
2920
|
+
reload
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
// src/PricingTable.tsx
|
|
2925
|
+
import { jsx as jsx19, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2926
|
+
function formatAmount(amount, currency) {
|
|
2927
|
+
if (amount === null) return "Free";
|
|
2928
|
+
const value = Number(amount);
|
|
2929
|
+
if (!Number.isFinite(value)) return "Free";
|
|
2930
|
+
try {
|
|
2931
|
+
return new Intl.NumberFormat(void 0, { style: "currency", currency }).format(value);
|
|
2932
|
+
} catch {
|
|
2933
|
+
return `${value} ${currency}`;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
function cadence(plan, amount) {
|
|
2937
|
+
if (amount === null) {
|
|
2938
|
+
return "\xA0";
|
|
2939
|
+
}
|
|
2940
|
+
const unit = plan.interval.toLowerCase();
|
|
2941
|
+
return plan.intervalCount === 1 ? `per ${unit}` : `every ${plan.intervalCount} ${unit}s`;
|
|
2942
|
+
}
|
|
2943
|
+
function PricingTable({
|
|
1032
2944
|
onSelectPlan,
|
|
1033
2945
|
currentPlanVersionId,
|
|
1034
2946
|
featuredPlanKey,
|
|
2947
|
+
signInUrl,
|
|
2948
|
+
className,
|
|
2949
|
+
style
|
|
2950
|
+
}) {
|
|
2951
|
+
const {
|
|
2952
|
+
plans,
|
|
2953
|
+
error,
|
|
2954
|
+
currentPlanVersionId: current,
|
|
2955
|
+
busyPlanVersionId: busy,
|
|
2956
|
+
lastError,
|
|
2957
|
+
signedIn,
|
|
2958
|
+
managedBy,
|
|
2959
|
+
selectPlan
|
|
2960
|
+
} = usePlans({ currentPlanVersionId });
|
|
2961
|
+
async function choose(plan) {
|
|
2962
|
+
if (onSelectPlan) {
|
|
2963
|
+
await onSelectPlan(plan.planVersionId, plan);
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2966
|
+
const outcome = await selectPlan(plan);
|
|
2967
|
+
if (outcome.status === "needs-sign-in" && signInUrl && typeof window !== "undefined") {
|
|
2968
|
+
window.location.assign(signInUrl);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
if (error) {
|
|
2972
|
+
return /* @__PURE__ */ jsx19("div", { className: cls("b316-card", className), style, children: "Plans are unavailable right now." });
|
|
2973
|
+
}
|
|
2974
|
+
if (!plans) {
|
|
2975
|
+
return /* @__PURE__ */ jsx19("div", { className: cls("b316-card", className), style, children: "Loading plans\u2026" });
|
|
2976
|
+
}
|
|
2977
|
+
if (plans.length === 0) {
|
|
2978
|
+
return /* @__PURE__ */ jsx19("div", { className: cls("b316-card", className), style, children: "No plans are published yet." });
|
|
2979
|
+
}
|
|
2980
|
+
const anyTrial = plans.some((plan) => Boolean(plan.trialDays));
|
|
2981
|
+
const anyDescription = plans.some((plan) => Boolean(plan.description));
|
|
2982
|
+
const anyFeatured = plans.some((plan) => plan.key === featuredPlanKey);
|
|
2983
|
+
return /* @__PURE__ */ jsxs18("div", { className: cls("b316-plans", className), style, children: [
|
|
2984
|
+
managedBy ? (
|
|
2985
|
+
// A client company's plan comes from the firm that runs it. The table
|
|
2986
|
+
// still shows what is on offer, with the current plan marked, but
|
|
2987
|
+
// nothing here can be bought: it would grant this account nothing.
|
|
2988
|
+
/* @__PURE__ */ jsxs18("div", { className: "b316-plans-managed b316-muted", children: [
|
|
2989
|
+
"Your plan is provided by ",
|
|
2990
|
+
managedBy.name ?? "the organization that manages your account",
|
|
2991
|
+
". Ask them to change it."
|
|
2992
|
+
] })
|
|
2993
|
+
) : lastError ? /* @__PURE__ */ jsx19("div", { className: "b316-plans-error", role: "alert", children: lastError }) : null,
|
|
2994
|
+
plans.map((plan) => {
|
|
2995
|
+
const base = plan.prices.find((price) => price.featureId === null) ?? plan.prices[0];
|
|
2996
|
+
const isCurrent = current === plan.planVersionId;
|
|
2997
|
+
const featured = featuredPlanKey === plan.key;
|
|
2998
|
+
return /* @__PURE__ */ jsxs18(
|
|
2999
|
+
"div",
|
|
3000
|
+
{
|
|
3001
|
+
className: featured ? "b316-card b316-plan b316-plan-featured" : "b316-card b316-plan",
|
|
3002
|
+
children: [
|
|
3003
|
+
/* @__PURE__ */ jsxs18("div", { className: "b316-plan-head", children: [
|
|
3004
|
+
anyFeatured ? /* @__PURE__ */ jsx19("div", { className: featured ? "b316-plan-badge" : "b316-plan-badge-spacer", children: featured ? "Recommended" : "\xA0" }) : null,
|
|
3005
|
+
/* @__PURE__ */ jsx19("div", { className: "b316-plan-name", children: plan.name }),
|
|
3006
|
+
anyDescription ? /* @__PURE__ */ jsx19("div", { className: "b316-plan-desc", children: plan.description ?? "\xA0" }) : null
|
|
3007
|
+
] }),
|
|
3008
|
+
/* @__PURE__ */ jsxs18("div", { className: "b316-plan-pricing", children: [
|
|
3009
|
+
/* @__PURE__ */ jsx19("div", { className: "b316-plan-price", children: formatAmount(base?.amount ?? null, plan.currency) }),
|
|
3010
|
+
/* @__PURE__ */ jsx19("div", { className: "b316-plan-cadence", children: cadence(plan, base?.amount ?? null) }),
|
|
3011
|
+
anyTrial ? /* @__PURE__ */ jsx19("div", { className: "b316-plan-trial", children: plan.trialDays ? `${plan.trialDays}-day free trial` : "\xA0" }) : null
|
|
3012
|
+
] }),
|
|
3013
|
+
/* @__PURE__ */ jsx19("ul", { className: "b316-plan-features", children: plan.entitlements.filter((entitlement) => entitlement.enabled).map((entitlement) => /* @__PURE__ */ jsxs18("li", { className: "b316-plan-feature", children: [
|
|
3014
|
+
/* @__PURE__ */ jsx19("span", { children: entitlement.featureName }),
|
|
3015
|
+
/* @__PURE__ */ jsx19("span", { className: "b316-plan-feature-value", children: entitlement.limit === null ? "Unlimited" : entitlement.limit })
|
|
3016
|
+
] }, entitlement.featureId)) }),
|
|
3017
|
+
/* @__PURE__ */ jsx19("div", { className: "b316-plan-action", children: /* @__PURE__ */ jsx19(
|
|
3018
|
+
"button",
|
|
3019
|
+
{
|
|
3020
|
+
type: "button",
|
|
3021
|
+
className: isCurrent ? "b316-button b316-button-current" : "b316-button",
|
|
3022
|
+
disabled: isCurrent || managedBy !== null || busy !== null || !signedIn && !signInUrl && !onSelectPlan,
|
|
3023
|
+
onClick: () => {
|
|
3024
|
+
void choose(plan);
|
|
3025
|
+
},
|
|
3026
|
+
children: isCurrent ? "Current plan" : busy === plan.planVersionId ? "Working\u2026" : !signedIn && !signInUrl && !onSelectPlan ? "Sign in to choose" : "Choose"
|
|
3027
|
+
}
|
|
3028
|
+
) })
|
|
3029
|
+
]
|
|
3030
|
+
},
|
|
3031
|
+
plan.id
|
|
3032
|
+
);
|
|
3033
|
+
})
|
|
3034
|
+
] });
|
|
3035
|
+
}
|
|
3036
|
+
|
|
3037
|
+
// src/DataTable.tsx
|
|
3038
|
+
import { specFor as specFor3 } from "@base316/sdk";
|
|
3039
|
+
import { useState as useState22 } from "react";
|
|
3040
|
+
|
|
3041
|
+
// src/fields.tsx
|
|
3042
|
+
import {
|
|
3043
|
+
formatAddress,
|
|
3044
|
+
specFor
|
|
3045
|
+
} from "@base316/sdk";
|
|
3046
|
+
import { jsx as jsx20, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
3047
|
+
function formatNumber(value, fraction = 0) {
|
|
3048
|
+
const number = Number(value);
|
|
3049
|
+
return Number.isFinite(number) ? new Intl.NumberFormat(void 0, {
|
|
3050
|
+
minimumFractionDigits: fraction,
|
|
3051
|
+
maximumFractionDigits: 2
|
|
3052
|
+
}).format(number) : "";
|
|
3053
|
+
}
|
|
3054
|
+
function formatDuration(value) {
|
|
3055
|
+
const total = Number(value);
|
|
3056
|
+
if (!Number.isFinite(total)) {
|
|
3057
|
+
return "";
|
|
3058
|
+
}
|
|
3059
|
+
const hours = Math.floor(total / 3600);
|
|
3060
|
+
const minutes = Math.round(total % 3600 / 60);
|
|
3061
|
+
if (hours === 0) {
|
|
3062
|
+
return `${minutes}m`;
|
|
3063
|
+
}
|
|
3064
|
+
return minutes === 0 ? `${hours}h` : `${hours}h ${minutes}m`;
|
|
3065
|
+
}
|
|
3066
|
+
function FieldCell({ value, field, related }) {
|
|
3067
|
+
if (field.type === "RELATION") {
|
|
3068
|
+
return related?.title ?? (related?.id ? /* @__PURE__ */ jsx20("code", { className: "b316-muted", children: related.id }) : "\u2014");
|
|
3069
|
+
}
|
|
3070
|
+
if (value === null || value === void 0 || value === "") {
|
|
3071
|
+
return /* @__PURE__ */ jsx20("span", { className: "b316-muted", children: "\u2014" });
|
|
3072
|
+
}
|
|
3073
|
+
switch (field.type) {
|
|
3074
|
+
case "BOOLEAN":
|
|
3075
|
+
return value ? "Yes" : "No";
|
|
3076
|
+
case "MONEY":
|
|
3077
|
+
return formatNumber(value, 2);
|
|
3078
|
+
case "PERCENT":
|
|
3079
|
+
return `${formatNumber(value)}%`;
|
|
3080
|
+
case "DURATION":
|
|
3081
|
+
return formatDuration(value);
|
|
3082
|
+
case "RATING": {
|
|
3083
|
+
const stars = Math.round(Number(value));
|
|
3084
|
+
return /* @__PURE__ */ jsxs19("span", { "aria-label": `${stars} out of 5`, children: [
|
|
3085
|
+
"\u2605".repeat(stars),
|
|
3086
|
+
/* @__PURE__ */ jsx20("span", { className: "b316-muted", children: "\u2605".repeat(Math.max(0, 5 - stars)) })
|
|
3087
|
+
] });
|
|
3088
|
+
}
|
|
3089
|
+
case "DATE":
|
|
3090
|
+
return String(value).split("T")[0];
|
|
3091
|
+
case "DATETIME":
|
|
3092
|
+
return new Date(String(value)).toLocaleString();
|
|
3093
|
+
case "SELECT":
|
|
3094
|
+
return /* @__PURE__ */ jsx20("span", { className: "b316-chip", children: String(value) });
|
|
3095
|
+
case "MULTISELECT":
|
|
3096
|
+
return /* @__PURE__ */ jsx20("span", { className: "b316-chips", children: (Array.isArray(value) ? value : [value]).map((item) => /* @__PURE__ */ jsx20("span", { className: "b316-chip", children: String(item) }, String(item))) });
|
|
3097
|
+
case "URL":
|
|
3098
|
+
return /* @__PURE__ */ jsx20("a", { href: String(value), target: "_blank", rel: "noreferrer noopener", children: String(value) });
|
|
3099
|
+
case "EMAIL":
|
|
3100
|
+
return /* @__PURE__ */ jsx20("a", { href: `mailto:${String(value)}`, children: String(value) });
|
|
3101
|
+
case "PHONE":
|
|
3102
|
+
return /* @__PURE__ */ jsx20("a", { href: `tel:${String(value)}`, children: String(value) });
|
|
3103
|
+
case "ADDRESS":
|
|
3104
|
+
return formatAddress(value);
|
|
3105
|
+
case "ATTACHMENT": {
|
|
3106
|
+
const files = Array.isArray(value) ? value : [value];
|
|
3107
|
+
return `${files.length} file${files.length === 1 ? "" : "s"}`;
|
|
3108
|
+
}
|
|
3109
|
+
case "LONGTEXT": {
|
|
3110
|
+
const text = String(value);
|
|
3111
|
+
return text.length > 80 ? `${text.slice(0, 80)}\u2026` : text;
|
|
3112
|
+
}
|
|
3113
|
+
case "JSON":
|
|
3114
|
+
return /* @__PURE__ */ jsx20("code", { className: "b316-muted", children: JSON.stringify(value).slice(0, 60) });
|
|
3115
|
+
default:
|
|
3116
|
+
return String(value);
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
function FieldInput({ value, field, onChange, error, disabled }) {
|
|
3120
|
+
if (specFor(field).computed) {
|
|
3121
|
+
return null;
|
|
3122
|
+
}
|
|
3123
|
+
const id = `b316-field-${field.key}`;
|
|
3124
|
+
const described = error ? `${id}-error` : void 0;
|
|
3125
|
+
const common = {
|
|
3126
|
+
id,
|
|
3127
|
+
disabled,
|
|
3128
|
+
"aria-invalid": error ? true : void 0,
|
|
3129
|
+
"aria-describedby": described,
|
|
3130
|
+
className: error ? "b316-input b316-input-invalid" : "b316-input"
|
|
3131
|
+
};
|
|
3132
|
+
function control() {
|
|
3133
|
+
switch (field.type) {
|
|
3134
|
+
case "LONGTEXT":
|
|
3135
|
+
return /* @__PURE__ */ jsx20(
|
|
3136
|
+
"textarea",
|
|
3137
|
+
{
|
|
3138
|
+
...common,
|
|
3139
|
+
rows: 4,
|
|
3140
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3141
|
+
onChange: (event) => onChange(event.target.value)
|
|
3142
|
+
}
|
|
3143
|
+
);
|
|
3144
|
+
case "BOOLEAN":
|
|
3145
|
+
return /* @__PURE__ */ jsx20(
|
|
3146
|
+
"input",
|
|
3147
|
+
{
|
|
3148
|
+
...common,
|
|
3149
|
+
type: "checkbox",
|
|
3150
|
+
className: "b316-checkbox",
|
|
3151
|
+
checked: Boolean(value),
|
|
3152
|
+
onChange: (event) => onChange(event.target.checked)
|
|
3153
|
+
}
|
|
3154
|
+
);
|
|
3155
|
+
case "SELECT":
|
|
3156
|
+
return /* @__PURE__ */ jsxs19(
|
|
3157
|
+
"select",
|
|
3158
|
+
{
|
|
3159
|
+
...common,
|
|
3160
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3161
|
+
onChange: (event) => onChange(event.target.value === "" ? null : event.target.value),
|
|
3162
|
+
children: [
|
|
3163
|
+
field.required ? null : /* @__PURE__ */ jsx20("option", { value: "", children: "\u2014" }),
|
|
3164
|
+
(field.options ?? []).map((option) => /* @__PURE__ */ jsx20("option", { value: option, children: option }, option))
|
|
3165
|
+
]
|
|
3166
|
+
}
|
|
3167
|
+
);
|
|
3168
|
+
case "MULTISELECT": {
|
|
3169
|
+
const selected = new Set(Array.isArray(value) ? value.map(String) : []);
|
|
3170
|
+
return /* @__PURE__ */ jsx20("div", { className: "b316-choices", children: (field.options ?? []).map((option) => /* @__PURE__ */ jsxs19("label", { className: "b316-choice", children: [
|
|
3171
|
+
/* @__PURE__ */ jsx20(
|
|
3172
|
+
"input",
|
|
3173
|
+
{
|
|
3174
|
+
type: "checkbox",
|
|
3175
|
+
disabled,
|
|
3176
|
+
checked: selected.has(option),
|
|
3177
|
+
onChange: (event) => {
|
|
3178
|
+
const next = new Set(selected);
|
|
3179
|
+
if (event.target.checked) {
|
|
3180
|
+
next.add(option);
|
|
3181
|
+
} else {
|
|
3182
|
+
next.delete(option);
|
|
3183
|
+
}
|
|
3184
|
+
onChange([...next]);
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
),
|
|
3188
|
+
option
|
|
3189
|
+
] }, option)) });
|
|
3190
|
+
}
|
|
3191
|
+
case "NUMBER":
|
|
3192
|
+
case "MONEY":
|
|
3193
|
+
case "PERCENT":
|
|
3194
|
+
return /* @__PURE__ */ jsx20(
|
|
3195
|
+
"input",
|
|
3196
|
+
{
|
|
3197
|
+
...common,
|
|
3198
|
+
type: "number",
|
|
3199
|
+
step: field.type === "NUMBER" ? 1 : 0.01,
|
|
3200
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3201
|
+
onChange: (event) => onChange(event.target.value === "" ? null : Number(event.target.value))
|
|
3202
|
+
}
|
|
3203
|
+
);
|
|
3204
|
+
case "RATING":
|
|
3205
|
+
return /* @__PURE__ */ jsx20(
|
|
3206
|
+
"input",
|
|
3207
|
+
{
|
|
3208
|
+
...common,
|
|
3209
|
+
type: "number",
|
|
3210
|
+
min: 0,
|
|
3211
|
+
max: 5,
|
|
3212
|
+
step: 1,
|
|
3213
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3214
|
+
onChange: (event) => onChange(event.target.value === "" ? null : Number(event.target.value))
|
|
3215
|
+
}
|
|
3216
|
+
);
|
|
3217
|
+
case "DURATION": {
|
|
3218
|
+
const minutes = value === null || value === void 0 ? "" : String(Number(value) / 60);
|
|
3219
|
+
return /* @__PURE__ */ jsxs19("div", { className: "b316-suffixed", children: [
|
|
3220
|
+
/* @__PURE__ */ jsx20(
|
|
3221
|
+
"input",
|
|
3222
|
+
{
|
|
3223
|
+
...common,
|
|
3224
|
+
type: "number",
|
|
3225
|
+
min: 0,
|
|
3226
|
+
value: minutes,
|
|
3227
|
+
onChange: (event) => onChange(event.target.value === "" ? null : Number(event.target.value) * 60)
|
|
3228
|
+
}
|
|
3229
|
+
),
|
|
3230
|
+
/* @__PURE__ */ jsx20("span", { className: "b316-muted", children: "minutes" })
|
|
3231
|
+
] });
|
|
3232
|
+
}
|
|
3233
|
+
case "DATE":
|
|
3234
|
+
return /* @__PURE__ */ jsx20(
|
|
3235
|
+
"input",
|
|
3236
|
+
{
|
|
3237
|
+
...common,
|
|
3238
|
+
type: "date",
|
|
3239
|
+
value: value === null || value === void 0 ? "" : String(value).slice(0, 10),
|
|
3240
|
+
onChange: (event) => onChange(event.target.value === "" ? null : event.target.value)
|
|
3241
|
+
}
|
|
3242
|
+
);
|
|
3243
|
+
case "DATETIME":
|
|
3244
|
+
return /* @__PURE__ */ jsx20(
|
|
3245
|
+
"input",
|
|
3246
|
+
{
|
|
3247
|
+
...common,
|
|
3248
|
+
type: "datetime-local",
|
|
3249
|
+
value: value === null || value === void 0 ? "" : String(value).slice(0, 16),
|
|
3250
|
+
onChange: (event) => onChange(
|
|
3251
|
+
event.target.value === "" ? null : new Date(event.target.value).toISOString()
|
|
3252
|
+
)
|
|
3253
|
+
}
|
|
3254
|
+
);
|
|
3255
|
+
case "ADDRESS": {
|
|
3256
|
+
const address = value ?? {};
|
|
3257
|
+
const part = (key, label) => /* @__PURE__ */ jsx20(
|
|
3258
|
+
"input",
|
|
3259
|
+
{
|
|
3260
|
+
className: "b316-input",
|
|
3261
|
+
disabled,
|
|
3262
|
+
placeholder: label,
|
|
3263
|
+
"aria-label": label,
|
|
3264
|
+
value: address[key] ?? "",
|
|
3265
|
+
onChange: (event) => onChange({ ...address, [key]: event.target.value })
|
|
3266
|
+
},
|
|
3267
|
+
key
|
|
3268
|
+
);
|
|
3269
|
+
return /* @__PURE__ */ jsxs19("div", { className: "b316-address", children: [
|
|
3270
|
+
part("line1", "Address line 1"),
|
|
3271
|
+
part("line2", "Address line 2"),
|
|
3272
|
+
part("city", "City"),
|
|
3273
|
+
part("region", "Region"),
|
|
3274
|
+
part("postalCode", "Postal code"),
|
|
3275
|
+
part("country", "Country")
|
|
3276
|
+
] });
|
|
3277
|
+
}
|
|
3278
|
+
case "EMAIL":
|
|
3279
|
+
return /* @__PURE__ */ jsx20(
|
|
3280
|
+
"input",
|
|
3281
|
+
{
|
|
3282
|
+
...common,
|
|
3283
|
+
type: "email",
|
|
3284
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3285
|
+
onChange: (event) => onChange(event.target.value)
|
|
3286
|
+
}
|
|
3287
|
+
);
|
|
3288
|
+
case "URL":
|
|
3289
|
+
return /* @__PURE__ */ jsx20(
|
|
3290
|
+
"input",
|
|
3291
|
+
{
|
|
3292
|
+
...common,
|
|
3293
|
+
type: "url",
|
|
3294
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3295
|
+
onChange: (event) => onChange(event.target.value)
|
|
3296
|
+
}
|
|
3297
|
+
);
|
|
3298
|
+
case "PHONE":
|
|
3299
|
+
return /* @__PURE__ */ jsx20(
|
|
3300
|
+
"input",
|
|
3301
|
+
{
|
|
3302
|
+
...common,
|
|
3303
|
+
type: "tel",
|
|
3304
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3305
|
+
onChange: (event) => onChange(event.target.value)
|
|
3306
|
+
}
|
|
3307
|
+
);
|
|
3308
|
+
default:
|
|
3309
|
+
return /* @__PURE__ */ jsx20(
|
|
3310
|
+
"input",
|
|
3311
|
+
{
|
|
3312
|
+
...common,
|
|
3313
|
+
type: "text",
|
|
3314
|
+
value: value === null || value === void 0 ? "" : String(value),
|
|
3315
|
+
onChange: (event) => onChange(event.target.value)
|
|
3316
|
+
}
|
|
3317
|
+
);
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
return /* @__PURE__ */ jsxs19("div", { className: "b316-field", children: [
|
|
3321
|
+
/* @__PURE__ */ jsxs19("label", { className: "b316-label", htmlFor: id, children: [
|
|
3322
|
+
field.label,
|
|
3323
|
+
field.required ? /* @__PURE__ */ jsx20("span", { "aria-hidden": "true", children: " *" }) : null
|
|
3324
|
+
] }),
|
|
3325
|
+
control(),
|
|
3326
|
+
field.description ? /* @__PURE__ */ jsx20("div", { className: "b316-hint", children: field.description }) : null,
|
|
3327
|
+
error ? /* @__PURE__ */ jsx20("div", { className: "b316-error", id: described, role: "alert", children: error }) : null
|
|
3328
|
+
] });
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
// src/RecordForm.tsx
|
|
3332
|
+
import { specFor as specFor2 } from "@base316/sdk";
|
|
3333
|
+
import { useEffect as useEffect16, useState as useState21 } from "react";
|
|
3334
|
+
|
|
3335
|
+
// src/RelationPicker.tsx
|
|
3336
|
+
import { useEffect as useEffect14, useRef as useRef6, useState as useState19 } from "react";
|
|
3337
|
+
import { Fragment as Fragment5, jsx as jsx21, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
3338
|
+
function RelationPicker({
|
|
3339
|
+
field,
|
|
3340
|
+
value,
|
|
3341
|
+
onChange,
|
|
3342
|
+
error,
|
|
3343
|
+
disabled,
|
|
3344
|
+
tenant
|
|
3345
|
+
}) {
|
|
3346
|
+
const { client, token } = useBase316();
|
|
3347
|
+
const [query, setQuery] = useState19("");
|
|
3348
|
+
const [results, setResults] = useState19([]);
|
|
3349
|
+
const [chosenTitle, setChosenTitle] = useState19(null);
|
|
3350
|
+
const [open, setOpen] = useState19(false);
|
|
3351
|
+
const id = `b316-field-${field.key}`;
|
|
3352
|
+
const box = useRef6(null);
|
|
3353
|
+
useEffect14(() => {
|
|
3354
|
+
if (!token || !value || !field.relationTo) {
|
|
3355
|
+
setChosenTitle(null);
|
|
3356
|
+
return;
|
|
3357
|
+
}
|
|
3358
|
+
let cancelled = false;
|
|
3359
|
+
client.collections.titles(token, field.relationTo, [value], tenant ? { tenant } : void 0).then((result) => {
|
|
3360
|
+
if (!cancelled) {
|
|
3361
|
+
setChosenTitle(result.titles[value] ?? null);
|
|
3362
|
+
}
|
|
3363
|
+
}).catch(() => null);
|
|
3364
|
+
return () => {
|
|
3365
|
+
cancelled = true;
|
|
3366
|
+
};
|
|
3367
|
+
}, [client, token, value, field.relationTo, tenant]);
|
|
3368
|
+
useEffect14(() => {
|
|
3369
|
+
if (!token || !field.relationTo || !open) {
|
|
3370
|
+
return;
|
|
3371
|
+
}
|
|
3372
|
+
let cancelled = false;
|
|
3373
|
+
const timer = setTimeout(() => {
|
|
3374
|
+
client.collections.list(
|
|
3375
|
+
token,
|
|
3376
|
+
field.relationTo,
|
|
3377
|
+
{ search: query || void 0, limit: 10 },
|
|
3378
|
+
tenant ? { tenant } : void 0
|
|
3379
|
+
).then((page) => {
|
|
3380
|
+
if (!cancelled) {
|
|
3381
|
+
setResults(page.data.map((record) => ({ id: record.id, title: record.title })));
|
|
3382
|
+
}
|
|
3383
|
+
}).catch(() => {
|
|
3384
|
+
if (!cancelled) {
|
|
3385
|
+
setResults([]);
|
|
3386
|
+
}
|
|
3387
|
+
});
|
|
3388
|
+
}, 200);
|
|
3389
|
+
return () => {
|
|
3390
|
+
cancelled = true;
|
|
3391
|
+
clearTimeout(timer);
|
|
3392
|
+
};
|
|
3393
|
+
}, [client, token, field.relationTo, query, open, tenant]);
|
|
3394
|
+
useEffect14(() => {
|
|
3395
|
+
if (!open || typeof document === "undefined") {
|
|
3396
|
+
return;
|
|
3397
|
+
}
|
|
3398
|
+
const onDocumentClick = (event) => {
|
|
3399
|
+
if (box.current && !box.current.contains(event.target)) {
|
|
3400
|
+
setOpen(false);
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
document.addEventListener("mousedown", onDocumentClick);
|
|
3404
|
+
return () => {
|
|
3405
|
+
document.removeEventListener("mousedown", onDocumentClick);
|
|
3406
|
+
};
|
|
3407
|
+
}, [open]);
|
|
3408
|
+
return /* @__PURE__ */ jsxs20("div", { className: "b316-field", ref: box, children: [
|
|
3409
|
+
/* @__PURE__ */ jsxs20("label", { className: "b316-label", htmlFor: id, children: [
|
|
3410
|
+
field.label,
|
|
3411
|
+
field.required ? /* @__PURE__ */ jsx21("span", { "aria-hidden": "true", children: " *" }) : null
|
|
3412
|
+
] }),
|
|
3413
|
+
value && !open ? /* @__PURE__ */ jsxs20("div", { className: "b316-relation-chosen", children: [
|
|
3414
|
+
/* @__PURE__ */ jsx21("span", { children: chosenTitle ?? value }),
|
|
3415
|
+
disabled ? null : /* @__PURE__ */ jsx21(
|
|
3416
|
+
"button",
|
|
3417
|
+
{
|
|
3418
|
+
type: "button",
|
|
3419
|
+
className: "b316-button-quiet",
|
|
3420
|
+
onClick: () => {
|
|
3421
|
+
setQuery("");
|
|
3422
|
+
setOpen(true);
|
|
3423
|
+
},
|
|
3424
|
+
children: "Change"
|
|
3425
|
+
}
|
|
3426
|
+
),
|
|
3427
|
+
disabled || field.required ? null : /* @__PURE__ */ jsx21(
|
|
3428
|
+
"button",
|
|
3429
|
+
{
|
|
3430
|
+
type: "button",
|
|
3431
|
+
className: "b316-button-quiet",
|
|
3432
|
+
onClick: () => onChange(null),
|
|
3433
|
+
"aria-label": `Clear ${field.label}`,
|
|
3434
|
+
children: "Clear"
|
|
3435
|
+
}
|
|
3436
|
+
)
|
|
3437
|
+
] }) : /* @__PURE__ */ jsxs20(Fragment5, { children: [
|
|
3438
|
+
/* @__PURE__ */ jsx21(
|
|
3439
|
+
"input",
|
|
3440
|
+
{
|
|
3441
|
+
id,
|
|
3442
|
+
type: "text",
|
|
3443
|
+
role: "combobox",
|
|
3444
|
+
"aria-expanded": open,
|
|
3445
|
+
"aria-controls": `${id}-results`,
|
|
3446
|
+
"aria-autocomplete": "list",
|
|
3447
|
+
autoComplete: "off",
|
|
3448
|
+
disabled,
|
|
3449
|
+
className: error ? "b316-input b316-input-invalid" : "b316-input",
|
|
3450
|
+
placeholder: `Search ${field.label.toLowerCase()}`,
|
|
3451
|
+
value: query,
|
|
3452
|
+
onFocus: () => setOpen(true),
|
|
3453
|
+
onChange: (event) => {
|
|
3454
|
+
setQuery(event.target.value);
|
|
3455
|
+
setOpen(true);
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3458
|
+
),
|
|
3459
|
+
open ? /* @__PURE__ */ jsx21("ul", { className: "b316-relation-results", id: `${id}-results`, role: "listbox", children: results.length === 0 ? /* @__PURE__ */ jsx21("li", { className: "b316-muted b316-relation-empty", children: "No matches" }) : results.map((result) => /* @__PURE__ */ jsx21("li", { children: /* @__PURE__ */ jsx21(
|
|
3460
|
+
"button",
|
|
3461
|
+
{
|
|
3462
|
+
type: "button",
|
|
3463
|
+
role: "option",
|
|
3464
|
+
"aria-selected": result.id === value,
|
|
3465
|
+
className: "b316-relation-result",
|
|
3466
|
+
onClick: () => {
|
|
3467
|
+
onChange(result.id);
|
|
3468
|
+
setChosenTitle(result.title);
|
|
3469
|
+
setOpen(false);
|
|
3470
|
+
},
|
|
3471
|
+
children: result.title ?? result.id
|
|
3472
|
+
}
|
|
3473
|
+
) }, result.id)) }) : null
|
|
3474
|
+
] }),
|
|
3475
|
+
field.description ? /* @__PURE__ */ jsx21("div", { className: "b316-hint", children: field.description }) : null,
|
|
3476
|
+
error ? /* @__PURE__ */ jsx21("div", { className: "b316-error", role: "alert", children: error }) : null
|
|
3477
|
+
] });
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
// src/useCollection.ts
|
|
3481
|
+
import { useCallback as useCallback7, useEffect as useEffect15, useMemo as useMemo2, useState as useState20 } from "react";
|
|
3482
|
+
function fieldErrorFrom(cause) {
|
|
3483
|
+
const param = cause?.param;
|
|
3484
|
+
const message = cause instanceof Error ? cause.message : "That value was not accepted.";
|
|
3485
|
+
return param ? { [param]: message } : { _: message };
|
|
3486
|
+
}
|
|
3487
|
+
function useCollection(collection, options = {}) {
|
|
3488
|
+
const { client, token } = useBase316();
|
|
3489
|
+
const [schema, setSchema] = useState20(null);
|
|
3490
|
+
const [records, setRecords] = useState20([]);
|
|
3491
|
+
const [error, setError] = useState20(null);
|
|
3492
|
+
const [loading, setLoading] = useState20(true);
|
|
3493
|
+
const [total, setTotal] = useState20(0);
|
|
3494
|
+
const [cursor, setCursor] = useState20(null);
|
|
3495
|
+
const [reloadCount, setReloadCount] = useState20(0);
|
|
3496
|
+
const [search, setSearch] = useState20("");
|
|
3497
|
+
const [filters, setFilters] = useState20([]);
|
|
3498
|
+
const [sort, setSort] = useState20(
|
|
3499
|
+
options.sort ?? null
|
|
3500
|
+
);
|
|
3501
|
+
const [fieldErrors, setFieldErrors] = useState20({});
|
|
3502
|
+
const [saving, setSaving] = useState20(false);
|
|
3503
|
+
const { tenant, limit, recordId } = options;
|
|
3504
|
+
const fixedFilters = JSON.stringify(options.filters ?? []);
|
|
3505
|
+
const scope = useMemo2(() => tenant ? { tenant } : void 0, [tenant]);
|
|
3506
|
+
useEffect15(() => {
|
|
3507
|
+
if (!token) {
|
|
3508
|
+
return;
|
|
3509
|
+
}
|
|
3510
|
+
let cancelled = false;
|
|
3511
|
+
client.collections.schema(token, collection, scope).then((result) => {
|
|
3512
|
+
if (!cancelled) {
|
|
3513
|
+
setSchema(result);
|
|
3514
|
+
}
|
|
3515
|
+
}).catch((cause) => {
|
|
3516
|
+
if (!cancelled) {
|
|
3517
|
+
setError(cause instanceof Error ? cause.message : "This collection is unavailable.");
|
|
3518
|
+
setLoading(false);
|
|
3519
|
+
}
|
|
3520
|
+
});
|
|
3521
|
+
return () => {
|
|
3522
|
+
cancelled = true;
|
|
3523
|
+
};
|
|
3524
|
+
}, [client, token, collection, scope]);
|
|
3525
|
+
useEffect15(() => {
|
|
3526
|
+
if (!token || !schema) {
|
|
3527
|
+
return;
|
|
3528
|
+
}
|
|
3529
|
+
let cancelled = false;
|
|
3530
|
+
setLoading(true);
|
|
3531
|
+
if (recordId) {
|
|
3532
|
+
client.collections.get(token, collection, recordId, scope).then((record) => {
|
|
3533
|
+
if (cancelled) {
|
|
3534
|
+
return;
|
|
3535
|
+
}
|
|
3536
|
+
setRecords([record]);
|
|
3537
|
+
setCursor(null);
|
|
3538
|
+
setTotal(1);
|
|
3539
|
+
setError(null);
|
|
3540
|
+
setLoading(false);
|
|
3541
|
+
}).catch((cause) => {
|
|
3542
|
+
if (!cancelled) {
|
|
3543
|
+
setRecords([]);
|
|
3544
|
+
setTotal(0);
|
|
3545
|
+
setError(cause instanceof Error ? cause.message : "That record is not available.");
|
|
3546
|
+
setLoading(false);
|
|
3547
|
+
}
|
|
3548
|
+
});
|
|
3549
|
+
return () => {
|
|
3550
|
+
cancelled = true;
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
client.collections.list(
|
|
3554
|
+
token,
|
|
3555
|
+
collection,
|
|
3556
|
+
{
|
|
3557
|
+
filters: [...JSON.parse(fixedFilters), ...filters],
|
|
3558
|
+
search: search || void 0,
|
|
3559
|
+
sort: sort ?? void 0,
|
|
3560
|
+
limit
|
|
3561
|
+
},
|
|
3562
|
+
scope
|
|
3563
|
+
).then((page) => {
|
|
3564
|
+
if (cancelled) {
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
setRecords(page.data);
|
|
3568
|
+
setCursor(page.cursor);
|
|
3569
|
+
setTotal(page.total);
|
|
3570
|
+
setError(null);
|
|
3571
|
+
setLoading(false);
|
|
3572
|
+
}).catch((cause) => {
|
|
3573
|
+
if (!cancelled) {
|
|
3574
|
+
setError(cause instanceof Error ? cause.message : "Could not load these records.");
|
|
3575
|
+
setLoading(false);
|
|
3576
|
+
}
|
|
3577
|
+
});
|
|
3578
|
+
return () => {
|
|
3579
|
+
cancelled = true;
|
|
3580
|
+
};
|
|
3581
|
+
}, [
|
|
3582
|
+
client,
|
|
3583
|
+
token,
|
|
3584
|
+
collection,
|
|
3585
|
+
schema,
|
|
3586
|
+
recordId,
|
|
3587
|
+
fixedFilters,
|
|
3588
|
+
filters,
|
|
3589
|
+
search,
|
|
3590
|
+
sort,
|
|
3591
|
+
limit,
|
|
3592
|
+
scope,
|
|
3593
|
+
reloadCount
|
|
3594
|
+
]);
|
|
3595
|
+
const reload = useCallback7(() => {
|
|
3596
|
+
setReloadCount((count) => count + 1);
|
|
3597
|
+
}, []);
|
|
3598
|
+
const loadMore = useCallback7(() => {
|
|
3599
|
+
if (!token || !cursor) {
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
setLoading(true);
|
|
3603
|
+
client.collections.list(
|
|
3604
|
+
token,
|
|
3605
|
+
collection,
|
|
3606
|
+
{
|
|
3607
|
+
filters: [...JSON.parse(fixedFilters), ...filters],
|
|
3608
|
+
search: search || void 0,
|
|
3609
|
+
sort: sort ?? void 0,
|
|
3610
|
+
limit,
|
|
3611
|
+
cursor
|
|
3612
|
+
},
|
|
3613
|
+
scope
|
|
3614
|
+
).then((page) => {
|
|
3615
|
+
setRecords((existing) => [...existing, ...page.data]);
|
|
3616
|
+
setCursor(page.cursor);
|
|
3617
|
+
setLoading(false);
|
|
3618
|
+
}).catch(() => {
|
|
3619
|
+
setLoading(false);
|
|
3620
|
+
});
|
|
3621
|
+
}, [client, token, collection, cursor, fixedFilters, filters, search, sort, limit, scope]);
|
|
3622
|
+
const toggleSort = useCallback7((field) => {
|
|
3623
|
+
setSort((current) => {
|
|
3624
|
+
if (current?.field !== field) {
|
|
3625
|
+
return { field, direction: "asc" };
|
|
3626
|
+
}
|
|
3627
|
+
return current.direction === "asc" ? { field, direction: "desc" } : null;
|
|
3628
|
+
});
|
|
3629
|
+
}, []);
|
|
3630
|
+
const create = useCallback7(
|
|
3631
|
+
async (fields) => {
|
|
3632
|
+
if (!token) {
|
|
3633
|
+
return null;
|
|
3634
|
+
}
|
|
3635
|
+
setSaving(true);
|
|
3636
|
+
setFieldErrors({});
|
|
3637
|
+
try {
|
|
3638
|
+
const record = await client.collections.create(token, collection, fields, scope);
|
|
3639
|
+
reload();
|
|
3640
|
+
return record;
|
|
3641
|
+
} catch (cause) {
|
|
3642
|
+
setFieldErrors(fieldErrorFrom(cause));
|
|
3643
|
+
return null;
|
|
3644
|
+
} finally {
|
|
3645
|
+
setSaving(false);
|
|
3646
|
+
}
|
|
3647
|
+
},
|
|
3648
|
+
[client, token, collection, scope, reload]
|
|
3649
|
+
);
|
|
3650
|
+
const update = useCallback7(
|
|
3651
|
+
async (id, fields) => {
|
|
3652
|
+
if (!token) {
|
|
3653
|
+
return null;
|
|
3654
|
+
}
|
|
3655
|
+
setSaving(true);
|
|
3656
|
+
setFieldErrors({});
|
|
3657
|
+
try {
|
|
3658
|
+
const record = await client.collections.update(token, collection, id, fields, scope);
|
|
3659
|
+
setRecords(
|
|
3660
|
+
(existing) => existing.map((candidate) => candidate.id === id ? record : candidate)
|
|
3661
|
+
);
|
|
3662
|
+
return record;
|
|
3663
|
+
} catch (cause) {
|
|
3664
|
+
setFieldErrors(fieldErrorFrom(cause));
|
|
3665
|
+
return null;
|
|
3666
|
+
} finally {
|
|
3667
|
+
setSaving(false);
|
|
3668
|
+
}
|
|
3669
|
+
},
|
|
3670
|
+
[client, token, collection, scope]
|
|
3671
|
+
);
|
|
3672
|
+
const remove = useCallback7(
|
|
3673
|
+
async (id) => {
|
|
3674
|
+
if (!token) {
|
|
3675
|
+
return false;
|
|
3676
|
+
}
|
|
3677
|
+
setSaving(true);
|
|
3678
|
+
try {
|
|
3679
|
+
await client.collections.remove(token, collection, id, scope);
|
|
3680
|
+
setRecords((existing) => existing.filter((candidate) => candidate.id !== id));
|
|
3681
|
+
setTotal((count) => Math.max(0, count - 1));
|
|
3682
|
+
return true;
|
|
3683
|
+
} catch (cause) {
|
|
3684
|
+
setFieldErrors(fieldErrorFrom(cause));
|
|
3685
|
+
return false;
|
|
3686
|
+
} finally {
|
|
3687
|
+
setSaving(false);
|
|
3688
|
+
}
|
|
3689
|
+
},
|
|
3690
|
+
[client, token, collection, scope]
|
|
3691
|
+
);
|
|
3692
|
+
return {
|
|
3693
|
+
schema,
|
|
3694
|
+
records,
|
|
3695
|
+
loading,
|
|
3696
|
+
error,
|
|
3697
|
+
total,
|
|
3698
|
+
hasMore: cursor !== null,
|
|
3699
|
+
canWrite: schema?.canWrite ?? false,
|
|
3700
|
+
search,
|
|
3701
|
+
setSearch,
|
|
3702
|
+
filters,
|
|
3703
|
+
setFilters,
|
|
3704
|
+
sort,
|
|
3705
|
+
toggleSort,
|
|
3706
|
+
loadMore,
|
|
3707
|
+
reload,
|
|
3708
|
+
fieldErrors,
|
|
3709
|
+
saving,
|
|
3710
|
+
create,
|
|
3711
|
+
update,
|
|
3712
|
+
remove
|
|
3713
|
+
};
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
// src/RecordForm.tsx
|
|
3717
|
+
import { jsx as jsx22, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
3718
|
+
function RecordForm({
|
|
3719
|
+
collection,
|
|
3720
|
+
recordId,
|
|
3721
|
+
tenant,
|
|
3722
|
+
onSaved,
|
|
3723
|
+
onCancel,
|
|
3724
|
+
defaults,
|
|
3725
|
+
className,
|
|
3726
|
+
style
|
|
3727
|
+
}) {
|
|
3728
|
+
const { schema, records, create, update, saving, fieldErrors, error } = useCollection(
|
|
3729
|
+
collection,
|
|
3730
|
+
{
|
|
3731
|
+
tenant,
|
|
3732
|
+
// Fetched by id, not filtered for: `id` is not a schema field, so a filter
|
|
3733
|
+
// naming it is dropped and the form would quietly load the first page and
|
|
3734
|
+
// hope the record was on it.
|
|
3735
|
+
recordId
|
|
3736
|
+
}
|
|
3737
|
+
);
|
|
3738
|
+
const [values, setValues] = useState21(defaults ?? {});
|
|
3739
|
+
const [loaded, setLoaded] = useState21(!recordId);
|
|
3740
|
+
const existing = recordId ? records.find((record) => record.id === recordId) : void 0;
|
|
3741
|
+
useEffect16(() => {
|
|
3742
|
+
if (existing && !loaded) {
|
|
3743
|
+
setValues(existing.fields);
|
|
3744
|
+
setLoaded(true);
|
|
3745
|
+
}
|
|
3746
|
+
}, [existing, loaded]);
|
|
3747
|
+
if (error) {
|
|
3748
|
+
return /* @__PURE__ */ jsx22("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx22("div", { className: "b316-error", role: "alert", children: error }) });
|
|
3749
|
+
}
|
|
3750
|
+
if (!schema || !loaded) {
|
|
3751
|
+
return /* @__PURE__ */ jsx22("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
3752
|
+
}
|
|
3753
|
+
const editable = schema.fields.filter((field) => !specFor2(field).computed);
|
|
3754
|
+
async function submit(event) {
|
|
3755
|
+
event.preventDefault();
|
|
3756
|
+
const saved = recordId ? await update(recordId, values) : await create(values);
|
|
3757
|
+
if (saved) {
|
|
3758
|
+
onSaved?.(saved.id);
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
return /* @__PURE__ */ jsxs21("form", { className: cls("b316-card b316-form", className), style, onSubmit: submit, children: [
|
|
3762
|
+
/* @__PURE__ */ jsx22("h3", { className: "b316-form-title", children: recordId ? `Edit ${schema.name.toLowerCase()}` : `New ${schema.name.toLowerCase()}` }),
|
|
3763
|
+
fieldErrors._ ? /* @__PURE__ */ jsx22("div", { className: "b316-error", role: "alert", children: fieldErrors._ }) : null,
|
|
3764
|
+
editable.map(
|
|
3765
|
+
(field) => field.type === "RELATION" ? /* @__PURE__ */ jsx22(
|
|
3766
|
+
RelationPicker,
|
|
3767
|
+
{
|
|
3768
|
+
field,
|
|
3769
|
+
tenant,
|
|
3770
|
+
disabled: saving,
|
|
3771
|
+
error: fieldErrors[field.key],
|
|
3772
|
+
value: values[field.key] ?? null,
|
|
3773
|
+
onChange: (next) => setValues((current) => ({ ...current, [field.key]: next }))
|
|
3774
|
+
},
|
|
3775
|
+
field.key
|
|
3776
|
+
) : /* @__PURE__ */ jsx22(
|
|
3777
|
+
FieldInput,
|
|
3778
|
+
{
|
|
3779
|
+
field,
|
|
3780
|
+
disabled: saving,
|
|
3781
|
+
error: fieldErrors[field.key],
|
|
3782
|
+
value: values[field.key] ?? null,
|
|
3783
|
+
onChange: (next) => setValues((current) => ({ ...current, [field.key]: next }))
|
|
3784
|
+
},
|
|
3785
|
+
field.key
|
|
3786
|
+
)
|
|
3787
|
+
),
|
|
3788
|
+
/* @__PURE__ */ jsxs21("div", { className: "b316-form-actions", children: [
|
|
3789
|
+
onCancel ? /* @__PURE__ */ jsx22("button", { type: "button", className: "b316-button-quiet", onClick: onCancel, disabled: saving, children: "Cancel" }) : null,
|
|
3790
|
+
/* @__PURE__ */ jsx22("button", { type: "submit", className: "b316-button", disabled: saving, children: saving ? "Saving\u2026" : "Save" })
|
|
3791
|
+
] })
|
|
3792
|
+
] });
|
|
3793
|
+
}
|
|
3794
|
+
|
|
3795
|
+
// src/DataTable.tsx
|
|
3796
|
+
import { jsx as jsx23, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
3797
|
+
function DataTable({
|
|
3798
|
+
collection,
|
|
3799
|
+
columns,
|
|
3800
|
+
renderCell,
|
|
3801
|
+
onSelect,
|
|
3802
|
+
onChanged,
|
|
3803
|
+
hideSearch,
|
|
3804
|
+
readOnly,
|
|
3805
|
+
emptyState,
|
|
3806
|
+
className,
|
|
3807
|
+
style,
|
|
3808
|
+
...options
|
|
3809
|
+
}) {
|
|
3810
|
+
const {
|
|
3811
|
+
schema,
|
|
3812
|
+
records,
|
|
3813
|
+
loading,
|
|
3814
|
+
error,
|
|
3815
|
+
total,
|
|
3816
|
+
hasMore,
|
|
3817
|
+
canWrite,
|
|
3818
|
+
search,
|
|
3819
|
+
setSearch,
|
|
3820
|
+
sort,
|
|
3821
|
+
toggleSort,
|
|
3822
|
+
loadMore,
|
|
3823
|
+
remove
|
|
3824
|
+
} = useCollection(collection, options);
|
|
3825
|
+
const [editing, setEditing] = useState22(null);
|
|
3826
|
+
const [removeFailed, setRemoveFailed] = useState22(null);
|
|
3827
|
+
if (error) {
|
|
3828
|
+
return /* @__PURE__ */ jsx23("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx23("div", { className: "b316-error", role: "alert", children: error }) });
|
|
3829
|
+
}
|
|
3830
|
+
if (!schema) {
|
|
3831
|
+
return /* @__PURE__ */ jsx23("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
3832
|
+
}
|
|
3833
|
+
const shown = columns ? (
|
|
3834
|
+
// Ordered by what was asked for, not by the schema: a caller naming
|
|
3835
|
+
// columns means that order.
|
|
3836
|
+
columns.map((key) => schema.fields.find((field) => field.key === key)).filter((field) => Boolean(field))
|
|
3837
|
+
) : schema.fields;
|
|
3838
|
+
const searchable = schema.fields.some((field) => specFor3(field).capabilities.searchable);
|
|
3839
|
+
const writable = canWrite && !readOnly;
|
|
3840
|
+
return /* @__PURE__ */ jsxs22("div", { className: cls("b316-table-wrap", className), style, children: [
|
|
3841
|
+
removeFailed ? /* @__PURE__ */ jsx23("div", { className: "b316-error", role: "alert", children: removeFailed }) : null,
|
|
3842
|
+
/* @__PURE__ */ jsxs22("div", { className: "b316-table-bar", children: [
|
|
3843
|
+
searchable && !hideSearch ? /* @__PURE__ */ jsx23(
|
|
3844
|
+
"input",
|
|
3845
|
+
{
|
|
3846
|
+
type: "search",
|
|
3847
|
+
className: "b316-input",
|
|
3848
|
+
placeholder: `Search ${schema.namePlural.toLowerCase()}`,
|
|
3849
|
+
"aria-label": `Search ${schema.namePlural}`,
|
|
3850
|
+
value: search,
|
|
3851
|
+
onChange: (event) => setSearch(event.target.value)
|
|
3852
|
+
}
|
|
3853
|
+
) : /* @__PURE__ */ jsx23("span", {}),
|
|
3854
|
+
/* @__PURE__ */ jsxs22("div", { className: "b316-table-actions", children: [
|
|
3855
|
+
/* @__PURE__ */ jsxs22("span", { className: "b316-muted", children: [
|
|
3856
|
+
total,
|
|
3857
|
+
" ",
|
|
3858
|
+
total === 1 ? schema.name.toLowerCase() : schema.namePlural.toLowerCase()
|
|
3859
|
+
] }),
|
|
3860
|
+
writable ? /* @__PURE__ */ jsxs22("button", { type: "button", className: "b316-button", onClick: () => setEditing("new"), children: [
|
|
3861
|
+
"New ",
|
|
3862
|
+
schema.name.toLowerCase()
|
|
3863
|
+
] }) : null
|
|
3864
|
+
] })
|
|
3865
|
+
] }),
|
|
3866
|
+
/* @__PURE__ */ jsx23("div", { className: "b316-table-scroll", children: /* @__PURE__ */ jsxs22("table", { className: "b316-table", children: [
|
|
3867
|
+
/* @__PURE__ */ jsx23("thead", { children: /* @__PURE__ */ jsxs22("tr", { children: [
|
|
3868
|
+
shown.map((field) => {
|
|
3869
|
+
const sortable = specFor3(field).capabilities.sortable;
|
|
3870
|
+
const active = sort?.field === field.key;
|
|
3871
|
+
return /* @__PURE__ */ jsx23("th", { scope: "col", "aria-sort": ariaSort(active, sort?.direction), children: sortable ? /* @__PURE__ */ jsxs22(
|
|
3872
|
+
"button",
|
|
3873
|
+
{
|
|
3874
|
+
type: "button",
|
|
3875
|
+
className: "b316-sort",
|
|
3876
|
+
onClick: () => toggleSort(field.key),
|
|
3877
|
+
children: [
|
|
3878
|
+
field.label,
|
|
3879
|
+
/* @__PURE__ */ jsx23("span", { "aria-hidden": "true", children: active ? sort?.direction === "desc" ? " \u2193" : " \u2191" : " \u2195" })
|
|
3880
|
+
]
|
|
3881
|
+
}
|
|
3882
|
+
) : field.label }, field.key);
|
|
3883
|
+
}),
|
|
3884
|
+
writable ? /* @__PURE__ */ jsx23("th", { scope: "col", className: "b316-table-rowactions" }) : null
|
|
3885
|
+
] }) }),
|
|
3886
|
+
/* @__PURE__ */ jsx23("tbody", { children: records.map((record) => /* @__PURE__ */ jsxs22(
|
|
3887
|
+
"tr",
|
|
3888
|
+
{
|
|
3889
|
+
className: onSelect ? "b316-row-clickable" : void 0,
|
|
3890
|
+
onClick: onSelect ? () => onSelect(record) : void 0,
|
|
3891
|
+
children: [
|
|
3892
|
+
shown.map((field) => /* @__PURE__ */ jsx23("td", { children: renderCell?.(record, field) ?? /* @__PURE__ */ jsx23(
|
|
3893
|
+
FieldCell,
|
|
3894
|
+
{
|
|
3895
|
+
value: record.fields[field.key] ?? null,
|
|
3896
|
+
field,
|
|
3897
|
+
related: record.related[field.key]
|
|
3898
|
+
}
|
|
3899
|
+
) }, field.key)),
|
|
3900
|
+
writable ? /* @__PURE__ */ jsxs22("td", { className: "b316-table-rowactions", children: [
|
|
3901
|
+
/* @__PURE__ */ jsx23(
|
|
3902
|
+
"button",
|
|
3903
|
+
{
|
|
3904
|
+
type: "button",
|
|
3905
|
+
className: "b316-button-quiet",
|
|
3906
|
+
onClick: (event) => {
|
|
3907
|
+
event.stopPropagation();
|
|
3908
|
+
setEditing(record);
|
|
3909
|
+
},
|
|
3910
|
+
children: "Edit"
|
|
3911
|
+
}
|
|
3912
|
+
),
|
|
3913
|
+
/* @__PURE__ */ jsx23(
|
|
3914
|
+
ConfirmButton,
|
|
3915
|
+
{
|
|
3916
|
+
className: "b316-button-quiet b316-danger",
|
|
3917
|
+
confirmLabel: `Delete ${record.title ?? "this record"} for good`,
|
|
3918
|
+
onConfirm: () => remove(record.id).then((ok) => {
|
|
3919
|
+
if (ok) {
|
|
3920
|
+
setRemoveFailed(null);
|
|
3921
|
+
onChanged?.();
|
|
3922
|
+
return;
|
|
3923
|
+
}
|
|
3924
|
+
setRemoveFailed(
|
|
3925
|
+
`${record.title ?? "That record"} could not be deleted. It is still here.`
|
|
3926
|
+
);
|
|
3927
|
+
}),
|
|
3928
|
+
children: "Delete"
|
|
3929
|
+
}
|
|
3930
|
+
)
|
|
3931
|
+
] }) : null
|
|
3932
|
+
]
|
|
3933
|
+
},
|
|
3934
|
+
record.id
|
|
3935
|
+
)) })
|
|
3936
|
+
] }) }),
|
|
3937
|
+
records.length === 0 && !loading ? /* @__PURE__ */ jsx23("div", { className: "b316-empty", children: emptyState ?? `No ${schema.namePlural.toLowerCase()} yet.` }) : null,
|
|
3938
|
+
loading ? /* @__PURE__ */ jsx23("div", { className: "b316-empty", children: "Loading\u2026" }) : null,
|
|
3939
|
+
hasMore ? /* @__PURE__ */ jsx23("div", { className: "b316-table-more", children: /* @__PURE__ */ jsx23("button", { type: "button", className: "b316-button-quiet", onClick: loadMore, disabled: loading, children: "Load more" }) }) : null,
|
|
3940
|
+
editing ? /* @__PURE__ */ jsx23(
|
|
3941
|
+
RecordForm,
|
|
3942
|
+
{
|
|
3943
|
+
collection,
|
|
3944
|
+
recordId: editing === "new" ? void 0 : editing.id,
|
|
3945
|
+
tenant: options.tenant,
|
|
3946
|
+
onSaved: () => {
|
|
3947
|
+
setEditing(null);
|
|
3948
|
+
onChanged?.();
|
|
3949
|
+
},
|
|
3950
|
+
onCancel: () => setEditing(null)
|
|
3951
|
+
}
|
|
3952
|
+
) : null
|
|
3953
|
+
] });
|
|
3954
|
+
}
|
|
3955
|
+
function ariaSort(active, direction) {
|
|
3956
|
+
if (!active) {
|
|
3957
|
+
return void 0;
|
|
3958
|
+
}
|
|
3959
|
+
return direction === "desc" ? "descending" : "ascending";
|
|
3960
|
+
}
|
|
3961
|
+
|
|
3962
|
+
// src/Kanban.tsx
|
|
3963
|
+
import {
|
|
3964
|
+
defaultGroupFieldOf,
|
|
3965
|
+
specFor as specFor4,
|
|
3966
|
+
titleFieldOf
|
|
3967
|
+
} from "@base316/sdk";
|
|
3968
|
+
import { useState as useState23 } from "react";
|
|
3969
|
+
import { jsx as jsx24, jsxs as jsxs23 } from "react/jsx-runtime";
|
|
3970
|
+
function Kanban({
|
|
3971
|
+
collection,
|
|
3972
|
+
groupBy,
|
|
3973
|
+
cardFields,
|
|
3974
|
+
onSelect,
|
|
3975
|
+
emptyState,
|
|
3976
|
+
className,
|
|
3977
|
+
style,
|
|
3978
|
+
...options
|
|
3979
|
+
}) {
|
|
3980
|
+
const { schema, records, loading, error, canWrite, update, total, hasMore, loadMore } = useCollection(collection, {
|
|
3981
|
+
// A board shows everything at once by its nature — a column holding the
|
|
3982
|
+
// first twenty-five of two hundred is misleading rather than partial.
|
|
3983
|
+
limit: options.limit ?? 100,
|
|
3984
|
+
...options
|
|
3985
|
+
});
|
|
3986
|
+
const [dragging, setDragging] = useState23(null);
|
|
3987
|
+
const [over, setOver] = useState23(null);
|
|
3988
|
+
if (error) {
|
|
3989
|
+
return /* @__PURE__ */ jsx24("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx24("div", { className: "b316-error", role: "alert", children: error }) });
|
|
3990
|
+
}
|
|
3991
|
+
if (!schema) {
|
|
3992
|
+
return /* @__PURE__ */ jsx24("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
3993
|
+
}
|
|
3994
|
+
const field = groupBy ? schema.fields.find((candidate) => candidate.key === groupBy) ?? null : defaultGroupFieldOf(schema.fields);
|
|
3995
|
+
if (!field || !specFor4(field).capabilities.groupable) {
|
|
3996
|
+
return /* @__PURE__ */ jsx24("div", { className: cls("b316-card", className), style, children: groupBy ? `"${groupBy}" cannot make columns. A board groups by a choice, a yes/no or a date.` : `${schema.namePlural} have no field to group by. Add a choice field \u2014 a status or a stage \u2014 and this board will use it.` });
|
|
3997
|
+
}
|
|
3998
|
+
const columns = columnsFor(field);
|
|
3999
|
+
const shown = cardFields ? cardFields.map((key) => schema.fields.find((candidate) => candidate.key === key)).filter((candidate) => Boolean(candidate)) : (
|
|
4000
|
+
// The first few fields that are neither the grouping one nor the title.
|
|
4001
|
+
// The grouping field is already the column heading and the title is
|
|
4002
|
+
// already the card heading, so both would be printed twice on every card.
|
|
4003
|
+
schema.fields.filter(
|
|
4004
|
+
(candidate) => candidate.key !== field.key && candidate.key !== titleFieldOf(schema.fields)?.key
|
|
4005
|
+
).slice(0, 3)
|
|
4006
|
+
);
|
|
4007
|
+
async function move(record, value) {
|
|
4008
|
+
if (!canWrite || record.fields[field.key] === value) {
|
|
4009
|
+
return;
|
|
4010
|
+
}
|
|
4011
|
+
await update(record.id, { [field.key]: value });
|
|
4012
|
+
}
|
|
4013
|
+
return /* @__PURE__ */ jsxs23("div", { className: cls("b316-board-wrap", className), style, children: [
|
|
4014
|
+
/* @__PURE__ */ jsx24("div", { className: "b316-board", role: "list", children: columns.map((column) => {
|
|
4015
|
+
const inColumn = records.filter(
|
|
4016
|
+
(record) => String(record.fields[field.key] ?? "") === String(column.value ?? "")
|
|
4017
|
+
);
|
|
4018
|
+
return /* @__PURE__ */ jsxs23(
|
|
4019
|
+
"section",
|
|
4020
|
+
{
|
|
4021
|
+
className: over === String(column.value) ? "b316-board-column b316-board-over" : "b316-board-column",
|
|
4022
|
+
role: "listitem",
|
|
4023
|
+
"aria-label": column.label,
|
|
4024
|
+
onDragOver: (event) => {
|
|
4025
|
+
if (!canWrite || !dragging) {
|
|
4026
|
+
return;
|
|
4027
|
+
}
|
|
4028
|
+
event.preventDefault();
|
|
4029
|
+
setOver(String(column.value));
|
|
4030
|
+
},
|
|
4031
|
+
onDragLeave: () => setOver(null),
|
|
4032
|
+
onDrop: (event) => {
|
|
4033
|
+
event.preventDefault();
|
|
4034
|
+
setOver(null);
|
|
4035
|
+
const record = records.find((candidate) => candidate.id === dragging);
|
|
4036
|
+
if (record) {
|
|
4037
|
+
void move(record, column.value);
|
|
4038
|
+
}
|
|
4039
|
+
setDragging(null);
|
|
4040
|
+
},
|
|
4041
|
+
children: [
|
|
4042
|
+
/* @__PURE__ */ jsxs23("header", { className: "b316-board-head", children: [
|
|
4043
|
+
/* @__PURE__ */ jsx24("span", { className: "b316-board-title", children: column.label }),
|
|
4044
|
+
/* @__PURE__ */ jsx24("span", { className: "b316-muted", children: inColumn.length })
|
|
4045
|
+
] }),
|
|
4046
|
+
/* @__PURE__ */ jsxs23("div", { className: "b316-board-cards", children: [
|
|
4047
|
+
inColumn.map((record) => /* @__PURE__ */ jsxs23(
|
|
4048
|
+
"article",
|
|
4049
|
+
{
|
|
4050
|
+
className: "b316-board-card",
|
|
4051
|
+
draggable: canWrite,
|
|
4052
|
+
onDragStart: () => setDragging(record.id),
|
|
4053
|
+
onDragEnd: () => {
|
|
4054
|
+
setDragging(null);
|
|
4055
|
+
setOver(null);
|
|
4056
|
+
},
|
|
4057
|
+
onClick: onSelect ? () => onSelect(record) : void 0,
|
|
4058
|
+
children: [
|
|
4059
|
+
/* @__PURE__ */ jsx24("div", { className: "b316-board-card-title", children: record.title ?? "Untitled" }),
|
|
4060
|
+
shown.map((candidate) => /* @__PURE__ */ jsxs23("div", { className: "b316-board-card-field", children: [
|
|
4061
|
+
/* @__PURE__ */ jsx24("span", { className: "b316-muted", children: candidate.label }),
|
|
4062
|
+
/* @__PURE__ */ jsx24(
|
|
4063
|
+
FieldCell,
|
|
4064
|
+
{
|
|
4065
|
+
value: record.fields[candidate.key] ?? null,
|
|
4066
|
+
field: candidate,
|
|
4067
|
+
related: record.related[candidate.key]
|
|
4068
|
+
}
|
|
4069
|
+
)
|
|
4070
|
+
] }, candidate.key)),
|
|
4071
|
+
canWrite ? (
|
|
4072
|
+
// Dragging is not reachable by keyboard and is awkward on a
|
|
4073
|
+
// phone. This is the same action by other means, not a
|
|
4074
|
+
// lesser fallback.
|
|
4075
|
+
/* @__PURE__ */ jsxs23("label", { className: "b316-board-move", children: [
|
|
4076
|
+
/* @__PURE__ */ jsx24("span", { className: "b316-muted", children: "Move to" }),
|
|
4077
|
+
/* @__PURE__ */ jsx24(
|
|
4078
|
+
"select",
|
|
4079
|
+
{
|
|
4080
|
+
className: "b316-input",
|
|
4081
|
+
value: String(record.fields[field.key] ?? ""),
|
|
4082
|
+
onClick: (event) => event.stopPropagation(),
|
|
4083
|
+
onChange: (event) => {
|
|
4084
|
+
const chosen = columns.find(
|
|
4085
|
+
(candidate) => String(candidate.value) === event.target.value
|
|
4086
|
+
);
|
|
4087
|
+
void move(record, chosen?.value ?? null);
|
|
4088
|
+
},
|
|
4089
|
+
children: columns.map((candidate) => /* @__PURE__ */ jsx24("option", { value: String(candidate.value), children: candidate.label }, String(candidate.value)))
|
|
4090
|
+
}
|
|
4091
|
+
)
|
|
4092
|
+
] })
|
|
4093
|
+
) : null
|
|
4094
|
+
]
|
|
4095
|
+
},
|
|
4096
|
+
record.id
|
|
4097
|
+
)),
|
|
4098
|
+
inColumn.length === 0 ? /* @__PURE__ */ jsx24("div", { className: "b316-board-empty", children: emptyState ?? "Nothing here" }) : null
|
|
4099
|
+
] })
|
|
4100
|
+
]
|
|
4101
|
+
},
|
|
4102
|
+
String(column.value)
|
|
4103
|
+
);
|
|
4104
|
+
}) }),
|
|
4105
|
+
hasMore ? /* @__PURE__ */ jsx24("div", { className: "b316-table-more", children: /* @__PURE__ */ jsxs23("button", { type: "button", className: "b316-button-quiet", onClick: loadMore, disabled: loading, children: [
|
|
4106
|
+
"Showing ",
|
|
4107
|
+
records.length,
|
|
4108
|
+
" of ",
|
|
4109
|
+
total,
|
|
4110
|
+
" \u2014 load more"
|
|
4111
|
+
] }) }) : null
|
|
4112
|
+
] });
|
|
4113
|
+
}
|
|
4114
|
+
function columnsFor(field) {
|
|
4115
|
+
if (field.type === "BOOLEAN") {
|
|
4116
|
+
return [
|
|
4117
|
+
{ value: true, label: "Yes" },
|
|
4118
|
+
{ value: false, label: "No" }
|
|
4119
|
+
];
|
|
4120
|
+
}
|
|
4121
|
+
const options = (field.options ?? []).map((option) => ({ value: option, label: option }));
|
|
4122
|
+
return [...options, { value: null, label: "None" }];
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
// src/Chart.tsx
|
|
4126
|
+
import {
|
|
4127
|
+
fieldsAggregatableBy,
|
|
4128
|
+
fieldsFor,
|
|
4129
|
+
specFor as specFor5
|
|
4130
|
+
} from "@base316/sdk";
|
|
4131
|
+
import { useMemo as useMemo3 } from "react";
|
|
4132
|
+
import { jsx as jsx25, jsxs as jsxs24 } from "react/jsx-runtime";
|
|
4133
|
+
function Chart({
|
|
4134
|
+
collection,
|
|
4135
|
+
x,
|
|
4136
|
+
y,
|
|
4137
|
+
aggregate = "sum",
|
|
4138
|
+
bucket = "day",
|
|
4139
|
+
title,
|
|
4140
|
+
height = 220,
|
|
4141
|
+
className,
|
|
4142
|
+
style,
|
|
4143
|
+
...options
|
|
4144
|
+
}) {
|
|
4145
|
+
const { schema, records, error, loading } = useCollection(collection, {
|
|
4146
|
+
// A chart of one page is a chart of an arbitrary subset, which is worse
|
|
4147
|
+
// than no chart: it looks like an answer.
|
|
4148
|
+
limit: options.limit ?? 200,
|
|
4149
|
+
...options
|
|
4150
|
+
});
|
|
4151
|
+
const axis = useMemo3(() => {
|
|
4152
|
+
if (!schema) {
|
|
4153
|
+
return null;
|
|
4154
|
+
}
|
|
4155
|
+
const timeFields = fieldsFor(schema.fields, "timeAxis");
|
|
4156
|
+
const chosen = x ? schema.fields.find((field) => field.key === x) ?? null : timeFields[0] ?? null;
|
|
4157
|
+
return chosen && specFor5(chosen).capabilities.timeAxis ? chosen : null;
|
|
4158
|
+
}, [schema, x]);
|
|
4159
|
+
const measure = useMemo3(() => {
|
|
4160
|
+
if (!schema || !y) {
|
|
4161
|
+
return null;
|
|
4162
|
+
}
|
|
4163
|
+
const candidates = fieldsAggregatableBy(schema.fields, aggregate);
|
|
4164
|
+
return candidates.find((field) => field.key === y) ?? null;
|
|
4165
|
+
}, [schema, y, aggregate]);
|
|
4166
|
+
const buckets = useMemo3(
|
|
4167
|
+
() => axis ? bucketise(records, axis, measure, y ? aggregate : "count", bucket) : [],
|
|
4168
|
+
[records, axis, measure, aggregate, bucket, y]
|
|
4169
|
+
);
|
|
4170
|
+
if (error) {
|
|
4171
|
+
return /* @__PURE__ */ jsx25("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx25("div", { className: "b316-error", role: "alert", children: error }) });
|
|
4172
|
+
}
|
|
4173
|
+
if (!schema || loading) {
|
|
4174
|
+
return /* @__PURE__ */ jsx25("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
4175
|
+
}
|
|
4176
|
+
if (!axis) {
|
|
4177
|
+
return /* @__PURE__ */ jsx25("div", { className: cls("b316-card", className), style, children: x ? `"${x}" is not a date, so it cannot be a time axis.` : `${schema.namePlural} have no date field to chart against. Add one and this chart will use it.` });
|
|
4178
|
+
}
|
|
4179
|
+
if (y && !measure) {
|
|
4180
|
+
return /* @__PURE__ */ jsx25("div", { className: cls("b316-card", className), style, children: `"${y}" cannot be ${aggregate === "avg" ? "averaged" : `combined with ${aggregate}`}.` });
|
|
4181
|
+
}
|
|
4182
|
+
const peak = Math.max(...buckets.map((entry) => entry.value), 0);
|
|
4183
|
+
const heading = title ?? `${measure ? `${aggregate} of ${measure.label}` : schema.namePlural} by ${axis.label}`;
|
|
4184
|
+
return /* @__PURE__ */ jsxs24("figure", { className: cls("b316-card b316-chart", className), style, children: [
|
|
4185
|
+
/* @__PURE__ */ jsx25("figcaption", { className: "b316-chart-title", children: heading }),
|
|
4186
|
+
buckets.length === 0 || peak === 0 ? /* @__PURE__ */ jsx25("div", { className: "b316-empty", children: "Nothing to chart yet." }) : /* @__PURE__ */ jsx25("div", { className: "b316-chart-plot", style: { height }, children: buckets.map((entry) => /* @__PURE__ */ jsxs24("div", { className: "b316-chart-col", children: [
|
|
4187
|
+
/* @__PURE__ */ jsx25(
|
|
4188
|
+
"div",
|
|
4189
|
+
{
|
|
4190
|
+
className: "b316-chart-bar",
|
|
4191
|
+
style: { height: `${Math.max(2, entry.value / peak * 100)}%` },
|
|
4192
|
+
title: `${entry.label}: ${format(entry.value)}`
|
|
4193
|
+
}
|
|
4194
|
+
),
|
|
4195
|
+
/* @__PURE__ */ jsx25("span", { className: "b316-chart-label", children: entry.label })
|
|
4196
|
+
] }, entry.key)) }),
|
|
4197
|
+
/* @__PURE__ */ jsxs24("details", { className: "b316-chart-data", children: [
|
|
4198
|
+
/* @__PURE__ */ jsx25("summary", { children: "Values" }),
|
|
4199
|
+
/* @__PURE__ */ jsxs24("table", { className: "b316-table", children: [
|
|
4200
|
+
/* @__PURE__ */ jsx25("thead", { children: /* @__PURE__ */ jsxs24("tr", { children: [
|
|
4201
|
+
/* @__PURE__ */ jsx25("th", { scope: "col", children: axis.label }),
|
|
4202
|
+
/* @__PURE__ */ jsx25("th", { scope: "col", children: measure ? measure.label : "Count" })
|
|
4203
|
+
] }) }),
|
|
4204
|
+
/* @__PURE__ */ jsx25("tbody", { children: buckets.map((entry) => /* @__PURE__ */ jsxs24("tr", { children: [
|
|
4205
|
+
/* @__PURE__ */ jsx25("td", { children: entry.label }),
|
|
4206
|
+
/* @__PURE__ */ jsx25("td", { children: format(entry.value) })
|
|
4207
|
+
] }, entry.key)) })
|
|
4208
|
+
] })
|
|
4209
|
+
] })
|
|
4210
|
+
] });
|
|
4211
|
+
}
|
|
4212
|
+
function format(value) {
|
|
4213
|
+
return new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }).format(value);
|
|
4214
|
+
}
|
|
4215
|
+
function keyFor(date, bucket) {
|
|
4216
|
+
if (bucket === "month") {
|
|
4217
|
+
return `${date.getUTCFullYear()}-${String(date.getUTCMonth() + 1).padStart(2, "0")}`;
|
|
4218
|
+
}
|
|
4219
|
+
if (bucket === "week") {
|
|
4220
|
+
const monday = new Date(date);
|
|
4221
|
+
const offset = (date.getUTCDay() + 6) % 7;
|
|
4222
|
+
monday.setUTCDate(date.getUTCDate() - offset);
|
|
4223
|
+
return monday.toISOString().slice(0, 10);
|
|
4224
|
+
}
|
|
4225
|
+
return date.toISOString().slice(0, 10);
|
|
4226
|
+
}
|
|
4227
|
+
function bucketise(records, axis, measure, aggregate, bucket) {
|
|
4228
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4229
|
+
for (const record of records) {
|
|
4230
|
+
const raw = record.fields[axis.key];
|
|
4231
|
+
if (raw === null || raw === void 0 || raw === "") {
|
|
4232
|
+
continue;
|
|
4233
|
+
}
|
|
4234
|
+
const date = new Date(String(raw));
|
|
4235
|
+
if (Number.isNaN(date.getTime())) {
|
|
4236
|
+
continue;
|
|
4237
|
+
}
|
|
4238
|
+
const key = keyFor(date, bucket);
|
|
4239
|
+
const value = measure ? Number(record.fields[measure.key]) : 1;
|
|
4240
|
+
groups.set(key, [...groups.get(key) ?? [], Number.isFinite(value) ? value : 0]);
|
|
4241
|
+
}
|
|
4242
|
+
return [...groups.entries()].sort(([left], [right]) => left.localeCompare(right)).map(([key, values]) => ({
|
|
4243
|
+
key,
|
|
4244
|
+
label: key,
|
|
4245
|
+
value: combine(values, aggregate)
|
|
4246
|
+
}));
|
|
4247
|
+
}
|
|
4248
|
+
function combine(values, aggregate) {
|
|
4249
|
+
switch (aggregate) {
|
|
4250
|
+
case "count":
|
|
4251
|
+
return values.length;
|
|
4252
|
+
case "avg":
|
|
4253
|
+
return values.length === 0 ? 0 : values.reduce((total, value) => total + value, 0) / values.length;
|
|
4254
|
+
case "min":
|
|
4255
|
+
return values.length === 0 ? 0 : Math.min(...values);
|
|
4256
|
+
case "max":
|
|
4257
|
+
return values.length === 0 ? 0 : Math.max(...values);
|
|
4258
|
+
default:
|
|
4259
|
+
return values.reduce((total, value) => total + value, 0);
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
|
|
4263
|
+
// src/RecordDetail.tsx
|
|
4264
|
+
import { specFor as specFor6 } from "@base316/sdk";
|
|
4265
|
+
import { useState as useState24 } from "react";
|
|
4266
|
+
import { jsx as jsx26, jsxs as jsxs25 } from "react/jsx-runtime";
|
|
4267
|
+
function RecordDetail({
|
|
4268
|
+
collection,
|
|
4269
|
+
recordId,
|
|
4270
|
+
tenant,
|
|
4271
|
+
readOnly,
|
|
4272
|
+
onDeleted,
|
|
4273
|
+
onClose,
|
|
4274
|
+
children,
|
|
1035
4275
|
className,
|
|
1036
4276
|
style
|
|
1037
4277
|
}) {
|
|
1038
|
-
const {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
client.billing.plans().then((result) => {
|
|
1045
|
-
if (!cancelled) setPlans(result.data);
|
|
1046
|
-
}).catch((cause) => {
|
|
1047
|
-
console.error("[base316] could not load plans", cause);
|
|
1048
|
-
if (!cancelled) setError(true);
|
|
1049
|
-
});
|
|
1050
|
-
return () => {
|
|
1051
|
-
cancelled = true;
|
|
1052
|
-
};
|
|
1053
|
-
}, [client]);
|
|
4278
|
+
const { schema, records, canWrite, remove, loading, error } = useCollection(collection, {
|
|
4279
|
+
tenant,
|
|
4280
|
+
recordId
|
|
4281
|
+
});
|
|
4282
|
+
const [editing, setEditing] = useState24(false);
|
|
4283
|
+
const record = records.find((candidate) => candidate.id === recordId);
|
|
1054
4284
|
if (error) {
|
|
1055
|
-
return /* @__PURE__ */
|
|
4285
|
+
return /* @__PURE__ */ jsx26("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx26("div", { className: "b316-error", role: "alert", children: error }) });
|
|
1056
4286
|
}
|
|
1057
|
-
if (!
|
|
1058
|
-
return /* @__PURE__ */
|
|
4287
|
+
if (!schema || loading) {
|
|
4288
|
+
return /* @__PURE__ */ jsx26("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
1059
4289
|
}
|
|
1060
|
-
if (
|
|
1061
|
-
return /* @__PURE__ */
|
|
4290
|
+
if (!record) {
|
|
4291
|
+
return /* @__PURE__ */ jsxs25("div", { className: cls("b316-card", className), style, children: [
|
|
4292
|
+
"That ",
|
|
4293
|
+
schema.name.toLowerCase(),
|
|
4294
|
+
" is not available."
|
|
4295
|
+
] });
|
|
1062
4296
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
return /* @__PURE__ */ jsx8("div", { className: cls("b316-plans", className), style, children: plans.map((plan) => {
|
|
1067
|
-
const base = plan.prices.find((price) => price.featureId === null) ?? plan.prices[0];
|
|
1068
|
-
const current = currentPlanVersionId === plan.planVersionId;
|
|
1069
|
-
const featured = featuredPlanKey === plan.key;
|
|
1070
|
-
return /* @__PURE__ */ jsxs7(
|
|
1071
|
-
"div",
|
|
4297
|
+
if (editing) {
|
|
4298
|
+
return /* @__PURE__ */ jsx26(
|
|
4299
|
+
RecordForm,
|
|
1072
4300
|
{
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
/* @__PURE__ */ jsx8("div", { className: "b316-plan-price", children: formatAmount(base?.amount ?? null, plan.currency) }),
|
|
1082
|
-
/* @__PURE__ */ jsx8("div", { className: "b316-plan-cadence", children: cadence(plan, base?.amount ?? null) }),
|
|
1083
|
-
anyTrial ? /* @__PURE__ */ jsx8("div", { className: "b316-plan-trial", children: plan.trialDays ? `${plan.trialDays}-day free trial` : "\xA0" }) : null
|
|
1084
|
-
] }),
|
|
1085
|
-
/* @__PURE__ */ jsx8("ul", { className: "b316-plan-features", children: plan.entitlements.filter((entitlement) => entitlement.enabled).map((entitlement) => /* @__PURE__ */ jsxs7("li", { className: "b316-plan-feature", children: [
|
|
1086
|
-
/* @__PURE__ */ jsx8("span", { children: entitlement.featureName }),
|
|
1087
|
-
/* @__PURE__ */ jsx8("span", { className: "b316-plan-feature-value", children: entitlement.limit === null ? "Unlimited" : entitlement.limit })
|
|
1088
|
-
] }, entitlement.featureId)) }),
|
|
1089
|
-
/* @__PURE__ */ jsx8("div", { className: "b316-plan-action", children: /* @__PURE__ */ jsx8(
|
|
1090
|
-
"button",
|
|
1091
|
-
{
|
|
1092
|
-
type: "button",
|
|
1093
|
-
className: current ? "b316-button b316-button-current" : "b316-button",
|
|
1094
|
-
disabled: current || busy !== null,
|
|
1095
|
-
onClick: async () => {
|
|
1096
|
-
setBusy(plan.planVersionId);
|
|
1097
|
-
try {
|
|
1098
|
-
await onSelectPlan(plan.planVersionId, plan);
|
|
1099
|
-
} finally {
|
|
1100
|
-
setBusy(null);
|
|
1101
|
-
}
|
|
1102
|
-
},
|
|
1103
|
-
children: current ? "Current plan" : busy === plan.planVersionId ? "Working\u2026" : "Choose"
|
|
1104
|
-
}
|
|
1105
|
-
) })
|
|
1106
|
-
]
|
|
1107
|
-
},
|
|
1108
|
-
plan.id
|
|
4301
|
+
collection,
|
|
4302
|
+
recordId,
|
|
4303
|
+
tenant,
|
|
4304
|
+
className,
|
|
4305
|
+
style,
|
|
4306
|
+
onSaved: () => setEditing(false),
|
|
4307
|
+
onCancel: () => setEditing(false)
|
|
4308
|
+
}
|
|
1109
4309
|
);
|
|
1110
|
-
}
|
|
4310
|
+
}
|
|
4311
|
+
const writable = canWrite && !readOnly;
|
|
4312
|
+
return /* @__PURE__ */ jsxs25("div", { className: cls("b316-card b316-detail", className), style, children: [
|
|
4313
|
+
/* @__PURE__ */ jsxs25("div", { className: "b316-detail-head", children: [
|
|
4314
|
+
/* @__PURE__ */ jsx26("h3", { className: "b316-detail-title", children: record.title ?? schema.name }),
|
|
4315
|
+
/* @__PURE__ */ jsxs25("div", { className: "b316-detail-actions", children: [
|
|
4316
|
+
writable ? /* @__PURE__ */ jsx26("button", { type: "button", className: "b316-button-quiet", onClick: () => setEditing(true), children: "Edit" }) : null,
|
|
4317
|
+
writable ? /* @__PURE__ */ jsx26(
|
|
4318
|
+
ConfirmButton,
|
|
4319
|
+
{
|
|
4320
|
+
className: "b316-button-quiet b316-danger",
|
|
4321
|
+
confirmLabel: `Delete ${record.title ?? "this record"} for good`,
|
|
4322
|
+
onConfirm: async () => {
|
|
4323
|
+
if (await remove(recordId)) {
|
|
4324
|
+
onDeleted?.();
|
|
4325
|
+
}
|
|
4326
|
+
},
|
|
4327
|
+
children: "Delete"
|
|
4328
|
+
}
|
|
4329
|
+
) : null,
|
|
4330
|
+
onClose ? /* @__PURE__ */ jsx26("button", { type: "button", className: "b316-button-quiet", onClick: onClose, children: "Close" }) : null
|
|
4331
|
+
] })
|
|
4332
|
+
] }),
|
|
4333
|
+
/* @__PURE__ */ jsx26("dl", { className: "b316-detail-fields", children: schema.fields.map((field) => /* @__PURE__ */ jsxs25("div", { className: "b316-detail-row", children: [
|
|
4334
|
+
/* @__PURE__ */ jsxs25("dt", { className: "b316-label", children: [
|
|
4335
|
+
field.label,
|
|
4336
|
+
specFor6(field).computed ? /* @__PURE__ */ jsx26("span", { className: "b316-muted", children: " (calculated)" }) : null
|
|
4337
|
+
] }),
|
|
4338
|
+
/* @__PURE__ */ jsx26("dd", { children: /* @__PURE__ */ jsx26(
|
|
4339
|
+
FieldCell,
|
|
4340
|
+
{
|
|
4341
|
+
value: record.fields[field.key] ?? null,
|
|
4342
|
+
field,
|
|
4343
|
+
related: record.related[field.key]
|
|
4344
|
+
}
|
|
4345
|
+
) })
|
|
4346
|
+
] }, field.key)) }),
|
|
4347
|
+
children
|
|
4348
|
+
] });
|
|
1111
4349
|
}
|
|
1112
4350
|
|
|
1113
4351
|
// src/SubscriptionManager.tsx
|
|
1114
|
-
import { useCallback as
|
|
1115
|
-
import { jsx as
|
|
4352
|
+
import { useCallback as useCallback8, useEffect as useEffect17, useState as useState25 } from "react";
|
|
4353
|
+
import { jsx as jsx27, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
1116
4354
|
function statusLabel(status) {
|
|
1117
4355
|
const words = status.toLowerCase().split("_");
|
|
1118
4356
|
return words.map((w, i) => i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : w).join(" ");
|
|
@@ -1122,11 +4360,12 @@ function SubscriptionManager({
|
|
|
1122
4360
|
style
|
|
1123
4361
|
}) {
|
|
1124
4362
|
const { client, token, loading: sessionLoading } = useBase316();
|
|
1125
|
-
const [subscription, setSubscription] =
|
|
1126
|
-
const [loading, setLoading] =
|
|
1127
|
-
const [
|
|
1128
|
-
const [
|
|
1129
|
-
const
|
|
4363
|
+
const [subscription, setSubscription] = useState25(null);
|
|
4364
|
+
const [loading, setLoading] = useState25(true);
|
|
4365
|
+
const [managedBy, setManagedBy] = useState25(null);
|
|
4366
|
+
const [busy, setBusy] = useState25(false);
|
|
4367
|
+
const [error, setError] = useState25(null);
|
|
4368
|
+
const load = useCallback8(async () => {
|
|
1130
4369
|
if (!token) {
|
|
1131
4370
|
setSubscription(null);
|
|
1132
4371
|
setLoading(false);
|
|
@@ -1135,6 +4374,7 @@ function SubscriptionManager({
|
|
|
1135
4374
|
try {
|
|
1136
4375
|
const result = await client.billing.subscription(token);
|
|
1137
4376
|
setSubscription(result.subscription);
|
|
4377
|
+
setManagedBy(result.managedBy ?? null);
|
|
1138
4378
|
} catch (cause) {
|
|
1139
4379
|
console.error("[base316] could not load the subscription", cause);
|
|
1140
4380
|
setError("Could not load your subscription.");
|
|
@@ -1142,32 +4382,39 @@ function SubscriptionManager({
|
|
|
1142
4382
|
setLoading(false);
|
|
1143
4383
|
}
|
|
1144
4384
|
}, [client, token]);
|
|
1145
|
-
|
|
4385
|
+
useEffect17(() => {
|
|
1146
4386
|
void load();
|
|
1147
4387
|
}, [load]);
|
|
1148
4388
|
if (sessionLoading || loading) {
|
|
1149
|
-
return /* @__PURE__ */
|
|
4389
|
+
return /* @__PURE__ */ jsx27("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
1150
4390
|
}
|
|
1151
4391
|
if (!token) {
|
|
1152
|
-
return /* @__PURE__ */
|
|
4392
|
+
return /* @__PURE__ */ jsx27("div", { className: cls("b316-card", className), style, children: "Sign in to manage your subscription." });
|
|
4393
|
+
}
|
|
4394
|
+
if (error) {
|
|
4395
|
+
return /* @__PURE__ */ jsx27("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx27("div", { className: "b316-error", role: "alert", children: error }) });
|
|
1153
4396
|
}
|
|
1154
4397
|
if (!subscription) {
|
|
1155
|
-
return /* @__PURE__ */
|
|
4398
|
+
return /* @__PURE__ */ jsx27("div", { className: cls("b316-card", className), style, children: "You are not subscribed to a plan." });
|
|
1156
4399
|
}
|
|
1157
4400
|
const renews = new Date(subscription.currentPeriodEnd).toLocaleDateString();
|
|
1158
|
-
return /* @__PURE__ */
|
|
1159
|
-
error ? /* @__PURE__ */
|
|
1160
|
-
/* @__PURE__ */
|
|
1161
|
-
/* @__PURE__ */
|
|
4401
|
+
return /* @__PURE__ */ jsxs26("div", { className: cls("b316-card", className), style, children: [
|
|
4402
|
+
error ? /* @__PURE__ */ jsx27("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
4403
|
+
/* @__PURE__ */ jsx27("div", { className: "b316-plan-name", children: subscription.planVersion.plan.name }),
|
|
4404
|
+
/* @__PURE__ */ jsxs26("div", { className: "b316-muted", children: [
|
|
1162
4405
|
statusLabel(subscription.status),
|
|
1163
4406
|
" \xB7 ",
|
|
1164
4407
|
subscription.cancelAtPeriodEnd ? `Ends ${renews}` : `Renews ${renews}`
|
|
1165
4408
|
] }),
|
|
1166
|
-
|
|
4409
|
+
managedBy ? /* @__PURE__ */ jsxs26("p", { className: "b316-muted", children: [
|
|
4410
|
+
"Provided by ",
|
|
4411
|
+
managedBy.name ?? "the organization that manages your account",
|
|
4412
|
+
". Ask them to change or cancel it."
|
|
4413
|
+
] }) : subscription.cancelAtPeriodEnd ? /* @__PURE__ */ jsxs26("p", { className: "b316-muted", children: [
|
|
1167
4414
|
"This subscription will not renew. You keep access until ",
|
|
1168
4415
|
renews,
|
|
1169
4416
|
"."
|
|
1170
|
-
] }) : /* @__PURE__ */
|
|
4417
|
+
] }) : /* @__PURE__ */ jsx27(
|
|
1171
4418
|
"button",
|
|
1172
4419
|
{
|
|
1173
4420
|
type: "button",
|
|
@@ -1192,17 +4439,950 @@ function SubscriptionManager({
|
|
|
1192
4439
|
)
|
|
1193
4440
|
] });
|
|
1194
4441
|
}
|
|
4442
|
+
|
|
4443
|
+
// src/ApiKeyManager.tsx
|
|
4444
|
+
import { useCallback as useCallback9, useEffect as useEffect18, useState as useState26 } from "react";
|
|
4445
|
+
import { jsx as jsx28, jsxs as jsxs27 } from "react/jsx-runtime";
|
|
4446
|
+
function duration(seconds) {
|
|
4447
|
+
if (seconds % 3600 === 0) {
|
|
4448
|
+
return `${seconds / 3600}h`;
|
|
4449
|
+
}
|
|
4450
|
+
if (seconds % 60 === 0) {
|
|
4451
|
+
return `${seconds / 60}m`;
|
|
4452
|
+
}
|
|
4453
|
+
return `${seconds}s`;
|
|
4454
|
+
}
|
|
4455
|
+
function ApiKeyManager({
|
|
4456
|
+
className,
|
|
4457
|
+
style,
|
|
4458
|
+
/** Restrict to one API. Omit to show every one the account can reach. */
|
|
4459
|
+
audience
|
|
4460
|
+
}) {
|
|
4461
|
+
const { client, token, loading: sessionLoading } = useBase316();
|
|
4462
|
+
const [resources, setResources] = useState26([]);
|
|
4463
|
+
const [credentials, setCredentials] = useState26([]);
|
|
4464
|
+
const [loading, setLoading] = useState26(true);
|
|
4465
|
+
const [busy, setBusy] = useState26(false);
|
|
4466
|
+
const [error, setError] = useState26(null);
|
|
4467
|
+
const [creating, setCreating] = useState26(false);
|
|
4468
|
+
const [name, setName] = useState26("");
|
|
4469
|
+
const [chosen, setChosen] = useState26([]);
|
|
4470
|
+
const [resourceId, setResourceId] = useState26(null);
|
|
4471
|
+
const [issued, setIssued] = useState26(null);
|
|
4472
|
+
const load = useCallback9(async () => {
|
|
4473
|
+
if (!token) {
|
|
4474
|
+
setLoading(false);
|
|
4475
|
+
return;
|
|
4476
|
+
}
|
|
4477
|
+
try {
|
|
4478
|
+
const [available, held] = await Promise.all([
|
|
4479
|
+
client.apiCredentials.resources(token),
|
|
4480
|
+
client.apiCredentials.list(token)
|
|
4481
|
+
]);
|
|
4482
|
+
const visible = audience ? available.data.filter((resource2) => resource2.audience === audience) : available.data;
|
|
4483
|
+
setResources(visible);
|
|
4484
|
+
setCredentials(audience ? held.data.filter((item) => item.audience === audience) : held.data);
|
|
4485
|
+
setResourceId((current) => current ?? visible[0]?.id ?? null);
|
|
4486
|
+
} catch (cause) {
|
|
4487
|
+
console.error("[base316] could not load API credentials", cause);
|
|
4488
|
+
setError("Could not load your API keys.");
|
|
4489
|
+
} finally {
|
|
4490
|
+
setLoading(false);
|
|
4491
|
+
}
|
|
4492
|
+
}, [client, token, audience]);
|
|
4493
|
+
useEffect18(() => {
|
|
4494
|
+
void load();
|
|
4495
|
+
}, [load]);
|
|
4496
|
+
if (sessionLoading || loading) {
|
|
4497
|
+
return /* @__PURE__ */ jsx28("div", { className: cls("b316-card", className), style, children: "Loading\u2026" });
|
|
4498
|
+
}
|
|
4499
|
+
if (!token) {
|
|
4500
|
+
return /* @__PURE__ */ jsx28("div", { className: cls("b316-card", className), style, children: "Sign in to manage your API keys." });
|
|
4501
|
+
}
|
|
4502
|
+
if (error) {
|
|
4503
|
+
return /* @__PURE__ */ jsx28("div", { className: cls("b316-card", className), style, children: /* @__PURE__ */ jsx28("div", { className: "b316-error", role: "alert", children: error }) });
|
|
4504
|
+
}
|
|
4505
|
+
if (resources.length === 0) {
|
|
4506
|
+
return /* @__PURE__ */ jsx28("div", { className: cls("b316-card", className), style, children: "There are no APIs available to your account." });
|
|
4507
|
+
}
|
|
4508
|
+
const resource = resources.find((item) => item.id === resourceId) ?? resources[0];
|
|
4509
|
+
const reset = () => {
|
|
4510
|
+
setCreating(false);
|
|
4511
|
+
setName("");
|
|
4512
|
+
setChosen([]);
|
|
4513
|
+
setIssued(null);
|
|
4514
|
+
};
|
|
4515
|
+
return /* @__PURE__ */ jsxs27("div", { className: cls("b316-card", className), style, children: [
|
|
4516
|
+
error ? /* @__PURE__ */ jsx28("div", { className: "b316-error", role: "alert", children: error }) : null,
|
|
4517
|
+
resources.length > 1 ? /* @__PURE__ */ jsx28(
|
|
4518
|
+
"select",
|
|
4519
|
+
{
|
|
4520
|
+
className: "b316-input",
|
|
4521
|
+
value: resource.id,
|
|
4522
|
+
onChange: (event) => setResourceId(event.target.value),
|
|
4523
|
+
style: { marginBottom: 14 },
|
|
4524
|
+
children: resources.map((item) => /* @__PURE__ */ jsx28("option", { value: item.id, children: item.name }, item.id))
|
|
4525
|
+
}
|
|
4526
|
+
) : /* @__PURE__ */ jsx28("div", { className: "b316-plan-name", children: resource.name }),
|
|
4527
|
+
resource.rateLimit ? /* @__PURE__ */ jsxs27("div", { className: "b316-muted", children: [
|
|
4528
|
+
resource.rateLimit.requestsPerWindow,
|
|
4529
|
+
" requests per",
|
|
4530
|
+
" ",
|
|
4531
|
+
duration(resource.rateLimit.windowSeconds),
|
|
4532
|
+
resource.rateLimit.burst > resource.rateLimit.requestsPerWindow ? `, bursting to ${resource.rateLimit.burst}` : null
|
|
4533
|
+
] }) : /* @__PURE__ */ jsx28("div", { className: "b316-muted", children: "No rate limit." }),
|
|
4534
|
+
credentials.length === 0 ? /* @__PURE__ */ jsx28("p", { className: "b316-muted", style: { marginTop: 14 }, children: "You have no API keys yet." }) : /* @__PURE__ */ jsx28("ul", { className: "b316-list", style: { marginTop: 14 }, children: credentials.map((credential) => /* @__PURE__ */ jsxs27("li", { className: "b316-list-item", children: [
|
|
4535
|
+
/* @__PURE__ */ jsxs27("div", { children: [
|
|
4536
|
+
/* @__PURE__ */ jsx28("div", { className: "b316-plan-name", children: credential.name }),
|
|
4537
|
+
/* @__PURE__ */ jsxs27("div", { className: "b316-muted", children: [
|
|
4538
|
+
/* @__PURE__ */ jsx28("code", { children: credential.clientId }),
|
|
4539
|
+
credential.secretLastFour ? ` \xB7 \u2026${credential.secretLastFour}` : null,
|
|
4540
|
+
credential.disabled ? " \xB7 Disabled" : null
|
|
4541
|
+
] }),
|
|
4542
|
+
/* @__PURE__ */ jsx28("div", { className: "b316-muted", children: credential.scopes.join(", ") })
|
|
4543
|
+
] }),
|
|
4544
|
+
/* @__PURE__ */ jsxs27("div", { style: { display: "flex", gap: 8 }, children: [
|
|
4545
|
+
/* @__PURE__ */ jsx28(
|
|
4546
|
+
"button",
|
|
4547
|
+
{
|
|
4548
|
+
type: "button",
|
|
4549
|
+
className: "b316-button b316-button-secondary",
|
|
4550
|
+
disabled: busy,
|
|
4551
|
+
onClick: async () => {
|
|
4552
|
+
setBusy(true);
|
|
4553
|
+
setError(null);
|
|
4554
|
+
try {
|
|
4555
|
+
const rotated = await client.apiCredentials.rotate(
|
|
4556
|
+
token,
|
|
4557
|
+
credential.clientId
|
|
4558
|
+
);
|
|
4559
|
+
setIssued({
|
|
4560
|
+
clientId: credential.clientId,
|
|
4561
|
+
secret: rotated.issuedSecret
|
|
4562
|
+
});
|
|
4563
|
+
await load();
|
|
4564
|
+
} catch (cause) {
|
|
4565
|
+
console.error("[base316] rotate failed", cause);
|
|
4566
|
+
setError("Could not rotate that key.");
|
|
4567
|
+
} finally {
|
|
4568
|
+
setBusy(false);
|
|
4569
|
+
}
|
|
4570
|
+
},
|
|
4571
|
+
children: "Rotate"
|
|
4572
|
+
}
|
|
4573
|
+
),
|
|
4574
|
+
/* @__PURE__ */ jsx28(
|
|
4575
|
+
ConfirmButton,
|
|
4576
|
+
{
|
|
4577
|
+
className: "b316-button b316-button-secondary",
|
|
4578
|
+
disabled: busy,
|
|
4579
|
+
confirmLabel: `Revoke ${credential.name} for good`,
|
|
4580
|
+
onConfirm: async () => {
|
|
4581
|
+
setBusy(true);
|
|
4582
|
+
setError(null);
|
|
4583
|
+
try {
|
|
4584
|
+
await client.apiCredentials.revoke(token, credential.clientId);
|
|
4585
|
+
await load();
|
|
4586
|
+
} catch (cause) {
|
|
4587
|
+
console.error("[base316] revoke failed", cause);
|
|
4588
|
+
setError("Could not revoke that key.");
|
|
4589
|
+
} finally {
|
|
4590
|
+
setBusy(false);
|
|
4591
|
+
}
|
|
4592
|
+
},
|
|
4593
|
+
children: "Revoke"
|
|
4594
|
+
}
|
|
4595
|
+
)
|
|
4596
|
+
] })
|
|
4597
|
+
] }, credential.clientId)) }),
|
|
4598
|
+
issued ? /* @__PURE__ */ jsxs27("div", { className: "b316-notice", style: { marginTop: 14 }, children: [
|
|
4599
|
+
/* @__PURE__ */ jsx28("strong", { children: "Copy this now." }),
|
|
4600
|
+
" It is shown once and cannot be retrieved again.",
|
|
4601
|
+
/* @__PURE__ */ jsx28("div", { style: { marginTop: 8 }, children: /* @__PURE__ */ jsx28("code", { style: { wordBreak: "break-all" }, children: issued.secret }) }),
|
|
4602
|
+
/* @__PURE__ */ jsx28(
|
|
4603
|
+
"button",
|
|
4604
|
+
{
|
|
4605
|
+
type: "button",
|
|
4606
|
+
className: "b316-button b316-button-secondary",
|
|
4607
|
+
style: { marginTop: 10 },
|
|
4608
|
+
onClick: () => {
|
|
4609
|
+
void navigator.clipboard?.writeText(issued.secret).catch(() => {
|
|
4610
|
+
});
|
|
4611
|
+
},
|
|
4612
|
+
children: "Copy"
|
|
4613
|
+
}
|
|
4614
|
+
),
|
|
4615
|
+
/* @__PURE__ */ jsx28(
|
|
4616
|
+
"button",
|
|
4617
|
+
{
|
|
4618
|
+
type: "button",
|
|
4619
|
+
className: "b316-button b316-button-secondary",
|
|
4620
|
+
style: { marginTop: 10, marginLeft: 8 },
|
|
4621
|
+
onClick: reset,
|
|
4622
|
+
children: "Done"
|
|
4623
|
+
}
|
|
4624
|
+
)
|
|
4625
|
+
] }) : null,
|
|
4626
|
+
creating && !issued ? /* @__PURE__ */ jsxs27("div", { style: { marginTop: 14 }, children: [
|
|
4627
|
+
/* @__PURE__ */ jsx28(
|
|
4628
|
+
"input",
|
|
4629
|
+
{
|
|
4630
|
+
className: "b316-input",
|
|
4631
|
+
placeholder: "What is this key for?",
|
|
4632
|
+
value: name,
|
|
4633
|
+
onChange: (event) => setName(event.target.value)
|
|
4634
|
+
}
|
|
4635
|
+
),
|
|
4636
|
+
/* @__PURE__ */ jsxs27("div", { style: { marginTop: 10 }, children: [
|
|
4637
|
+
resource.availableScopes.map((scope) => /* @__PURE__ */ jsxs27("label", { className: "b316-checkbox", children: [
|
|
4638
|
+
/* @__PURE__ */ jsx28(
|
|
4639
|
+
"input",
|
|
4640
|
+
{
|
|
4641
|
+
type: "checkbox",
|
|
4642
|
+
checked: chosen.includes(scope.key),
|
|
4643
|
+
onChange: (event) => setChosen(
|
|
4644
|
+
(current) => event.target.checked ? [...current, scope.key] : current.filter((key) => key !== scope.key)
|
|
4645
|
+
)
|
|
4646
|
+
}
|
|
4647
|
+
),
|
|
4648
|
+
/* @__PURE__ */ jsx28("code", { children: scope.key }),
|
|
4649
|
+
scope.description ? /* @__PURE__ */ jsxs27("span", { className: "b316-muted", children: [
|
|
4650
|
+
" \u2014 ",
|
|
4651
|
+
scope.description
|
|
4652
|
+
] }) : null
|
|
4653
|
+
] }, scope.key)),
|
|
4654
|
+
resource.lockedScopes.map((scope) => /* @__PURE__ */ jsxs27("label", { className: "b316-checkbox b316-muted", children: [
|
|
4655
|
+
/* @__PURE__ */ jsx28("input", { type: "checkbox", disabled: true }),
|
|
4656
|
+
/* @__PURE__ */ jsx28("code", { children: scope.key }),
|
|
4657
|
+
/* @__PURE__ */ jsx28("span", { children: " \u2014 not included in your plan" })
|
|
4658
|
+
] }, scope.key))
|
|
4659
|
+
] }),
|
|
4660
|
+
/* @__PURE__ */ jsx28(
|
|
4661
|
+
"button",
|
|
4662
|
+
{
|
|
4663
|
+
type: "button",
|
|
4664
|
+
className: "b316-button",
|
|
4665
|
+
style: { marginTop: 12 },
|
|
4666
|
+
disabled: busy || !name.trim() || chosen.length === 0,
|
|
4667
|
+
onClick: async () => {
|
|
4668
|
+
setBusy(true);
|
|
4669
|
+
setError(null);
|
|
4670
|
+
try {
|
|
4671
|
+
const created = await client.apiCredentials.create(token, {
|
|
4672
|
+
apiResourceId: resource.id,
|
|
4673
|
+
name: name.trim(),
|
|
4674
|
+
scopes: chosen
|
|
4675
|
+
});
|
|
4676
|
+
if (created.issuedSecret) {
|
|
4677
|
+
setIssued({ clientId: created.clientId, secret: created.issuedSecret });
|
|
4678
|
+
}
|
|
4679
|
+
setCreating(false);
|
|
4680
|
+
setName("");
|
|
4681
|
+
setChosen([]);
|
|
4682
|
+
await load();
|
|
4683
|
+
} catch (cause) {
|
|
4684
|
+
const message = cause instanceof Error ? cause.message : "Could not create that key.";
|
|
4685
|
+
console.error("[base316] create failed", cause);
|
|
4686
|
+
setError(message);
|
|
4687
|
+
} finally {
|
|
4688
|
+
setBusy(false);
|
|
4689
|
+
}
|
|
4690
|
+
},
|
|
4691
|
+
children: "Create key"
|
|
4692
|
+
}
|
|
4693
|
+
),
|
|
4694
|
+
/* @__PURE__ */ jsx28(
|
|
4695
|
+
"button",
|
|
4696
|
+
{
|
|
4697
|
+
type: "button",
|
|
4698
|
+
className: "b316-button b316-button-secondary",
|
|
4699
|
+
style: { marginTop: 12, marginLeft: 8 },
|
|
4700
|
+
onClick: reset,
|
|
4701
|
+
children: "Cancel"
|
|
4702
|
+
}
|
|
4703
|
+
)
|
|
4704
|
+
] }) : null,
|
|
4705
|
+
!creating && !issued ? /* @__PURE__ */ jsx28(
|
|
4706
|
+
"button",
|
|
4707
|
+
{
|
|
4708
|
+
type: "button",
|
|
4709
|
+
className: "b316-button",
|
|
4710
|
+
style: { marginTop: 14 },
|
|
4711
|
+
disabled: resource.availableScopes.length === 0,
|
|
4712
|
+
onClick: () => setCreating(true),
|
|
4713
|
+
children: resource.availableScopes.length === 0 ? "No scopes available on your plan" : "New API key"
|
|
4714
|
+
}
|
|
4715
|
+
) : null
|
|
4716
|
+
] });
|
|
4717
|
+
}
|
|
4718
|
+
|
|
4719
|
+
// src/manifest.ts
|
|
4720
|
+
var appearance = [
|
|
4721
|
+
{ name: "className", summary: "Your own classes on the wrapper.", required: false },
|
|
4722
|
+
{ name: "style", summary: "Inline styles on the wrapper.", required: false }
|
|
4723
|
+
];
|
|
4724
|
+
var MANIFEST = [
|
|
4725
|
+
// --- Setup ---------------------------------------------------------------
|
|
4726
|
+
{
|
|
4727
|
+
name: "Base316Provider",
|
|
4728
|
+
kind: "provider",
|
|
4729
|
+
summary: "Holds the client, the session and the theme. Everything else must be inside it.",
|
|
4730
|
+
useWhen: "Once, around the part of the application that uses any other export here.",
|
|
4731
|
+
requires: [],
|
|
4732
|
+
props: [
|
|
4733
|
+
{ name: "publishableKey", summary: "The environment's publishable key.", required: true },
|
|
4734
|
+
{ name: "baseUrl", summary: "Where the API lives. Defaults to production.", required: false },
|
|
4735
|
+
{
|
|
4736
|
+
name: "token",
|
|
4737
|
+
summary: "Supply to own session storage yourself. Left out, the session is kept in localStorage.",
|
|
4738
|
+
required: false
|
|
4739
|
+
},
|
|
4740
|
+
{
|
|
4741
|
+
name: "onTokenChange",
|
|
4742
|
+
summary: "Called when the session changes. Pair with `token` for an httpOnly cookie.",
|
|
4743
|
+
required: false
|
|
4744
|
+
},
|
|
4745
|
+
{
|
|
4746
|
+
name: "appearance",
|
|
4747
|
+
summary: "Colours, radius and font as tokens. Restyles everything at once.",
|
|
4748
|
+
required: false
|
|
4749
|
+
},
|
|
4750
|
+
{
|
|
4751
|
+
name: "tenant",
|
|
4752
|
+
summary: "White-label everything inside for one tenant \u2014 `{ organizationId }` or `{ organizationExternalId }`. A firm's name, logo and colours on the screens it runs its clients on; its own branding, then its parent's, then the environment's. Change it when the user switches team.",
|
|
4753
|
+
required: false
|
|
4754
|
+
},
|
|
4755
|
+
...appearance
|
|
4756
|
+
],
|
|
4757
|
+
seeAlso: ["useBase316", "useSession"]
|
|
4758
|
+
},
|
|
4759
|
+
{
|
|
4760
|
+
name: "useBase316",
|
|
4761
|
+
kind: "hook",
|
|
4762
|
+
summary: "The client, the session token and the branding, from inside the provider.",
|
|
4763
|
+
useWhen: "Writing a component of your own that needs to call the API directly.",
|
|
4764
|
+
requires: [],
|
|
4765
|
+
props: [],
|
|
4766
|
+
seeAlso: ["Base316Provider"]
|
|
4767
|
+
},
|
|
4768
|
+
{
|
|
4769
|
+
name: "useSession",
|
|
4770
|
+
kind: "hook",
|
|
4771
|
+
summary: "The resolved session, or null. Carries `userId`, `user` (id, email, name, image, and the customer's own declared fields) and `tenants` \u2014 every team this person is in, each with their role.",
|
|
4772
|
+
useWhen: "Deciding what to render for a signed-in versus a signed-out visitor.",
|
|
4773
|
+
requires: [],
|
|
4774
|
+
props: []
|
|
4775
|
+
},
|
|
4776
|
+
// --- Signing in ----------------------------------------------------------
|
|
4777
|
+
{
|
|
4778
|
+
name: "SignIn",
|
|
4779
|
+
kind: "component",
|
|
4780
|
+
summary: "Password, passkey, magic-link and text-message sign-in in one form.",
|
|
4781
|
+
useWhen: "The application renders its own sign-in rather than redirecting to the hosted page.",
|
|
4782
|
+
requires: [],
|
|
4783
|
+
props: [
|
|
4784
|
+
{ name: "onSignedIn", summary: "Called once a session exists.", required: false },
|
|
4785
|
+
{
|
|
4786
|
+
name: "passkeys",
|
|
4787
|
+
summary: "Offer passkeys where supported. On by default.",
|
|
4788
|
+
required: false
|
|
4789
|
+
},
|
|
4790
|
+
{
|
|
4791
|
+
name: "magicLinkRedirectUrl",
|
|
4792
|
+
summary: "Where an emailed link lands, which must be registered on the environment. Without it, magic link is not offered at all.",
|
|
4793
|
+
required: false
|
|
4794
|
+
},
|
|
4795
|
+
{
|
|
4796
|
+
name: "phone",
|
|
4797
|
+
summary: "Offer signing in with a code sent by text message. Needs text messages switched on for the environment, and its own Twilio account in production.",
|
|
4798
|
+
required: false
|
|
4799
|
+
},
|
|
4800
|
+
...appearance
|
|
4801
|
+
],
|
|
4802
|
+
seeAlso: ["SignUp", "ForgotPassword"]
|
|
4803
|
+
},
|
|
4804
|
+
{
|
|
4805
|
+
name: "SignUp",
|
|
4806
|
+
kind: "component",
|
|
4807
|
+
summary: "Create an account with an email and a password.",
|
|
4808
|
+
useWhen: "Alongside SignIn, on a page that registers new users.",
|
|
4809
|
+
requires: [],
|
|
4810
|
+
props: [
|
|
4811
|
+
{ name: "onSignedUp", summary: "Called after the account is created.", required: false },
|
|
4812
|
+
...appearance
|
|
4813
|
+
],
|
|
4814
|
+
seeAlso: ["SignIn", "VerifyEmail"]
|
|
4815
|
+
},
|
|
4816
|
+
{
|
|
4817
|
+
name: "ForgotPassword",
|
|
4818
|
+
kind: "component",
|
|
4819
|
+
summary: "Ask for a reset link by email.",
|
|
4820
|
+
useWhen: "Linked from a sign-in form.",
|
|
4821
|
+
requires: [],
|
|
4822
|
+
props: [
|
|
4823
|
+
{ name: "onSent", summary: "Called with the address after the request.", required: false },
|
|
4824
|
+
{ name: "signInUrl", summary: "Renders a link back to sign-in.", required: false },
|
|
4825
|
+
...appearance
|
|
4826
|
+
],
|
|
4827
|
+
seeAlso: ["ResetPassword"]
|
|
4828
|
+
},
|
|
4829
|
+
{
|
|
4830
|
+
name: "ResetPassword",
|
|
4831
|
+
kind: "component",
|
|
4832
|
+
summary: "Set a new password from an emailed link.",
|
|
4833
|
+
useWhen: "On the page the reset link lands on.",
|
|
4834
|
+
requires: [],
|
|
4835
|
+
props: [
|
|
4836
|
+
{
|
|
4837
|
+
name: "token",
|
|
4838
|
+
summary: "Read from `?token=` when omitted, and removed from the URL.",
|
|
4839
|
+
required: false
|
|
4840
|
+
},
|
|
4841
|
+
{ name: "onReset", summary: "Called once the password is changed.", required: false },
|
|
4842
|
+
{ name: "signInUrl", summary: "Renders a link onward to sign-in.", required: false },
|
|
4843
|
+
...appearance
|
|
4844
|
+
],
|
|
4845
|
+
whenUnmet: "With no token in the URL or props, explains that the link is needed.",
|
|
4846
|
+
seeAlso: ["ForgotPassword"]
|
|
4847
|
+
},
|
|
4848
|
+
{
|
|
4849
|
+
name: "VerifyEmail",
|
|
4850
|
+
kind: "component",
|
|
4851
|
+
summary: "Confirm an address from an emailed link.",
|
|
4852
|
+
useWhen: "On the page the verification link lands on.",
|
|
4853
|
+
requires: [],
|
|
4854
|
+
props: [
|
|
4855
|
+
{
|
|
4856
|
+
name: "token",
|
|
4857
|
+
summary: "Read from `?token=` when omitted, and removed from the URL.",
|
|
4858
|
+
required: false
|
|
4859
|
+
},
|
|
4860
|
+
{ name: "onVerified", summary: "Called once confirmed.", required: false },
|
|
4861
|
+
{ name: "continueUrl", summary: "Renders a link onward.", required: false },
|
|
4862
|
+
...appearance
|
|
4863
|
+
],
|
|
4864
|
+
seeAlso: ["SignUp"]
|
|
4865
|
+
},
|
|
4866
|
+
// --- The account ---------------------------------------------------------
|
|
4867
|
+
{
|
|
4868
|
+
name: "UserProfile",
|
|
4869
|
+
kind: "component",
|
|
4870
|
+
summary: "Name, email and the customer's own declared fields.",
|
|
4871
|
+
useWhen: "An account settings page.",
|
|
4872
|
+
requires: ["session"],
|
|
4873
|
+
props: [],
|
|
4874
|
+
whenUnmet: "Renders nothing without a session.",
|
|
4875
|
+
seeAlso: ["ActiveSessions", "TwoFactorManager", "PasskeyManager"]
|
|
4876
|
+
},
|
|
4877
|
+
{
|
|
4878
|
+
name: "ActiveSessions",
|
|
4879
|
+
kind: "component",
|
|
4880
|
+
summary: "Where the account is signed in, and a button to end the other devices.",
|
|
4881
|
+
useWhen: "A security settings page.",
|
|
4882
|
+
requires: ["session"],
|
|
4883
|
+
props: [
|
|
4884
|
+
{ name: "onRevoked", summary: "Called with the number of sessions ended.", required: false },
|
|
4885
|
+
...appearance
|
|
4886
|
+
],
|
|
4887
|
+
whenUnmet: "Renders nothing without a session.",
|
|
4888
|
+
seeAlso: ["TwoFactorManager"]
|
|
4889
|
+
},
|
|
4890
|
+
{
|
|
4891
|
+
name: "DeviceApproval",
|
|
4892
|
+
kind: "component",
|
|
4893
|
+
summary: "Approve a sign-in that started on a CLI, a TV, or anything with no browser.",
|
|
4894
|
+
useWhen: "You point a device's verification URI at a page in your own app. Put this on that page.",
|
|
4895
|
+
requires: ["session"],
|
|
4896
|
+
props: [
|
|
4897
|
+
{
|
|
4898
|
+
name: "userCode",
|
|
4899
|
+
summary: "The code, when the URL already carries it. Skips the entry step; without it the person types the code.",
|
|
4900
|
+
required: false
|
|
4901
|
+
},
|
|
4902
|
+
{ name: "onDecided", summary: "Called with whether they approved.", required: false },
|
|
4903
|
+
...appearance
|
|
4904
|
+
],
|
|
4905
|
+
whenUnmet: "Renders nothing without a session \u2014 there is nobody to approve as, and collecting a code first would fail at the step that matters.",
|
|
4906
|
+
seeAlso: ["SignIn", "ActiveSessions"]
|
|
4907
|
+
},
|
|
4908
|
+
{
|
|
4909
|
+
name: "PrivacyControls",
|
|
4910
|
+
kind: "component",
|
|
4911
|
+
summary: "Download a copy of everything held about you, or delete your account.",
|
|
4912
|
+
useWhen: "An account settings page. These are the two things a privacy notice promises and most products never build.",
|
|
4913
|
+
requires: ["session"],
|
|
4914
|
+
props: [
|
|
4915
|
+
{
|
|
4916
|
+
name: "confirmWord",
|
|
4917
|
+
summary: "What must be typed to confirm deletion. Defaults to the English word, which is wrong in every other language.",
|
|
4918
|
+
required: false
|
|
4919
|
+
},
|
|
4920
|
+
{
|
|
4921
|
+
name: "onErased",
|
|
4922
|
+
summary: "Called once the account is gone. Sign them out and send them somewhere.",
|
|
4923
|
+
required: false
|
|
4924
|
+
},
|
|
4925
|
+
...appearance
|
|
4926
|
+
],
|
|
4927
|
+
whenUnmet: "Renders nothing without a session.",
|
|
4928
|
+
seeAlso: ["UserProfile", "ActiveSessions"]
|
|
4929
|
+
},
|
|
4930
|
+
{
|
|
4931
|
+
name: "TwoFactorManager",
|
|
4932
|
+
kind: "component",
|
|
4933
|
+
summary: "Turn two-factor authentication on or off, by authenticator app, a code to the inbox or a code by text message.",
|
|
4934
|
+
useWhen: "A security settings page. The app is strongest; the emailed or texted code is the one people who will not install an app actually use.",
|
|
4935
|
+
requires: ["session"],
|
|
4936
|
+
props: [
|
|
4937
|
+
{
|
|
4938
|
+
name: "enabled",
|
|
4939
|
+
summary: "Whether a factor already exists, which decides which side is shown.",
|
|
4940
|
+
required: false
|
|
4941
|
+
},
|
|
4942
|
+
{
|
|
4943
|
+
name: "allowSms",
|
|
4944
|
+
summary: "Offer a code by text message. Off by default: it only works once the environment can send one.",
|
|
4945
|
+
required: false
|
|
4946
|
+
},
|
|
4947
|
+
{ name: "onEnabled", summary: "Called once a factor is confirmed.", required: false },
|
|
4948
|
+
{ name: "onDisabled", summary: "Called once it is removed.", required: false },
|
|
4949
|
+
...appearance
|
|
4950
|
+
],
|
|
4951
|
+
whenUnmet: "Renders nothing without a session.",
|
|
4952
|
+
seeAlso: ["ActiveSessions", "PasskeyManager"]
|
|
4953
|
+
},
|
|
4954
|
+
{
|
|
4955
|
+
name: "PasskeyManager",
|
|
4956
|
+
kind: "component",
|
|
4957
|
+
summary: "Add and remove passkeys.",
|
|
4958
|
+
useWhen: "A security settings page, beside two-factor.",
|
|
4959
|
+
requires: ["session"],
|
|
4960
|
+
props: [{ name: "title", summary: "Heading text.", required: false }, ...appearance],
|
|
4961
|
+
whenUnmet: "Renders nothing without a session.",
|
|
4962
|
+
seeAlso: ["TwoFactorManager"]
|
|
4963
|
+
},
|
|
4964
|
+
{
|
|
4965
|
+
name: "Branding",
|
|
4966
|
+
kind: "component",
|
|
4967
|
+
summary: "The logo, name and tagline \u2014 the environment's, or the tenant's when the provider is given a `tenant`.",
|
|
4968
|
+
useWhen: "Above a sign-in form, so your pages match the hosted ones.",
|
|
4969
|
+
requires: [],
|
|
4970
|
+
props: [
|
|
4971
|
+
{ name: "showTagline", summary: "Include the tagline under the name.", required: false },
|
|
4972
|
+
...appearance
|
|
4973
|
+
]
|
|
4974
|
+
},
|
|
4975
|
+
// --- Teams ---------------------------------------------------------------
|
|
4976
|
+
{
|
|
4977
|
+
name: "TeamMembers",
|
|
4978
|
+
kind: "component",
|
|
4979
|
+
summary: "Who is in a team, who has been invited, and the way in and out. A team reached only through the organization that manages it says so, and offers nothing to leave.",
|
|
4980
|
+
useWhen: "A Team or Members settings page. One component covers the list, the pending invitations, the invite box and leaving.",
|
|
4981
|
+
requires: ["session"],
|
|
4982
|
+
props: [
|
|
4983
|
+
{
|
|
4984
|
+
name: "organizationId",
|
|
4985
|
+
summary: "Which team. Defaults to the only one this person is in; with several it says so rather than guessing.",
|
|
4986
|
+
required: false
|
|
4987
|
+
},
|
|
4988
|
+
{
|
|
4989
|
+
name: "onInvited",
|
|
4990
|
+
summary: "Called with `{ email, token, url }` \u2014 the address invited, the raw token, and the accept URL when `acceptUrl` was given. This is where your application sends the email. Without a handler the link is shown on screen instead, because the token is returned once and cannot be fetched again.",
|
|
4991
|
+
required: false
|
|
4992
|
+
},
|
|
4993
|
+
{
|
|
4994
|
+
name: "acceptUrl",
|
|
4995
|
+
summary: "The page hosting AcceptInvitation. The component appends `?invitation=<token>` and hands the finished link back as `url` on onInvited; without it, onInvited gets the raw token and you build the link yourself.",
|
|
4996
|
+
required: false
|
|
4997
|
+
},
|
|
4998
|
+
{ name: "onLeft", summary: "Called after the viewer leaves the team.", required: false },
|
|
4999
|
+
...appearance
|
|
5000
|
+
],
|
|
5001
|
+
whenUnmet: "Renders nothing without a session. Inviting and removing appear only for somebody whose role grants team.manage.",
|
|
5002
|
+
seeAlso: ["AcceptInvitation"]
|
|
5003
|
+
},
|
|
5004
|
+
{
|
|
5005
|
+
name: "AcceptInvitation",
|
|
5006
|
+
kind: "component",
|
|
5007
|
+
summary: "The other end of an invitation: what it is for, and joining.",
|
|
5008
|
+
useWhen: "On the page an invitation link lands on.",
|
|
5009
|
+
requires: [],
|
|
5010
|
+
props: [
|
|
5011
|
+
{
|
|
5012
|
+
name: "token",
|
|
5013
|
+
summary: "Read from `?invitation=` when omitted.",
|
|
5014
|
+
required: false
|
|
5015
|
+
},
|
|
5016
|
+
{
|
|
5017
|
+
name: "onAccepted",
|
|
5018
|
+
summary: "Called with the organizationId once they have joined.",
|
|
5019
|
+
required: false
|
|
5020
|
+
},
|
|
5021
|
+
{ name: "signUpUrl", summary: "For somebody with no account yet.", required: false },
|
|
5022
|
+
{ name: "signInUrl", summary: "For somebody who has one.", required: false },
|
|
5023
|
+
...appearance
|
|
5024
|
+
],
|
|
5025
|
+
whenUnmet: "Says what the invitation is for without a session, since the point is that they may have no account. Names the address to sign in as when the signed-in one does not match.",
|
|
5026
|
+
seeAlso: ["TeamMembers", "SignUp"]
|
|
5027
|
+
},
|
|
5028
|
+
// --- Money ---------------------------------------------------------------
|
|
5029
|
+
{
|
|
5030
|
+
name: "PricingTable",
|
|
5031
|
+
kind: "component",
|
|
5032
|
+
summary: "The published plans, and completing the purchase.",
|
|
5033
|
+
useWhen: "A pricing page, or an upgrade screen.",
|
|
5034
|
+
requires: ["plans", "paymentAccount"],
|
|
5035
|
+
props: [
|
|
5036
|
+
{
|
|
5037
|
+
name: "onSelectPlan",
|
|
5038
|
+
summary: "Take over what Choose does. Left out, the component changes the plan or starts a checkout itself.",
|
|
5039
|
+
required: false
|
|
5040
|
+
},
|
|
5041
|
+
{
|
|
5042
|
+
name: "currentPlanVersionId",
|
|
5043
|
+
summary: "Marks the current plan. Discovered from the session when omitted.",
|
|
5044
|
+
required: false
|
|
5045
|
+
},
|
|
5046
|
+
{
|
|
5047
|
+
name: "featuredPlanKey",
|
|
5048
|
+
summary: "Which plan to present as the default.",
|
|
5049
|
+
required: false
|
|
5050
|
+
},
|
|
5051
|
+
{
|
|
5052
|
+
name: "signInUrl",
|
|
5053
|
+
summary: "Where a signed-out visitor goes on choosing. Without it the button says so rather than failing.",
|
|
5054
|
+
required: false
|
|
5055
|
+
},
|
|
5056
|
+
...appearance
|
|
5057
|
+
],
|
|
5058
|
+
whenUnmet: "Says plans are unavailable when the catalog is empty.",
|
|
5059
|
+
seeAlso: ["SubscriptionManager", "usePlans"]
|
|
5060
|
+
},
|
|
5061
|
+
{
|
|
5062
|
+
name: "usePlans",
|
|
5063
|
+
kind: "hook",
|
|
5064
|
+
summary: "The plans, the current one, and the prorate-or-checkout branch \u2014 without markup.",
|
|
5065
|
+
useWhen: "You want your own pricing table but not your own billing logic.",
|
|
5066
|
+
requires: ["plans"],
|
|
5067
|
+
props: [],
|
|
5068
|
+
seeAlso: ["PricingTable"]
|
|
5069
|
+
},
|
|
5070
|
+
{
|
|
5071
|
+
name: "SubscriptionManager",
|
|
5072
|
+
kind: "component",
|
|
5073
|
+
summary: "The current plan, its renewal date, and cancelling.",
|
|
5074
|
+
useWhen: "A billing settings page.",
|
|
5075
|
+
requires: ["session"],
|
|
5076
|
+
props: [],
|
|
5077
|
+
whenUnmet: "Renders nothing without a session.",
|
|
5078
|
+
seeAlso: ["PricingTable", "Invoices"]
|
|
5079
|
+
},
|
|
5080
|
+
{
|
|
5081
|
+
name: "Invoices",
|
|
5082
|
+
kind: "component",
|
|
5083
|
+
summary: "The signed-in user's invoices, newest first.",
|
|
5084
|
+
useWhen: "A billing settings page.",
|
|
5085
|
+
requires: ["session"],
|
|
5086
|
+
props: [],
|
|
5087
|
+
whenUnmet: "Renders nothing without a session.",
|
|
5088
|
+
seeAlso: ["SubscriptionManager"]
|
|
5089
|
+
},
|
|
5090
|
+
{
|
|
5091
|
+
name: "PayInvoice",
|
|
5092
|
+
kind: "component",
|
|
5093
|
+
summary: "Pay one invoice from a link, with no account needed.",
|
|
5094
|
+
useWhen: "A page reached from a payment link or a QR code \u2014 a walk-up customer.",
|
|
5095
|
+
requires: ["paymentAccount"],
|
|
5096
|
+
props: [
|
|
5097
|
+
{ name: "token", summary: "The link token, from the URL.", required: false },
|
|
5098
|
+
{ name: "environmentId", summary: "Which environment the link belongs to.", required: false },
|
|
5099
|
+
{ name: "onPaid", summary: "Called once payment succeeds.", required: false },
|
|
5100
|
+
...appearance
|
|
5101
|
+
],
|
|
5102
|
+
seeAlso: ["usePaymentLink"]
|
|
5103
|
+
},
|
|
5104
|
+
{
|
|
5105
|
+
name: "usePaymentLink",
|
|
5106
|
+
kind: "hook",
|
|
5107
|
+
summary: "Watches a payment link and reports when it is paid.",
|
|
5108
|
+
useWhen: "Showing your own waiting screen beside a QR code.",
|
|
5109
|
+
requires: [],
|
|
5110
|
+
props: [],
|
|
5111
|
+
seeAlso: ["PayInvoice"]
|
|
5112
|
+
},
|
|
5113
|
+
{
|
|
5114
|
+
name: "ApiKeyManager",
|
|
5115
|
+
kind: "component",
|
|
5116
|
+
summary: "A customer managing their own API credentials and seeing their rate limits.",
|
|
5117
|
+
useWhen: "A developer-settings page inside your application.",
|
|
5118
|
+
requires: ["session", "apiResource"],
|
|
5119
|
+
props: [
|
|
5120
|
+
{
|
|
5121
|
+
name: "audience",
|
|
5122
|
+
summary: "Limit to one protected API. All of them when omitted.",
|
|
5123
|
+
required: false
|
|
5124
|
+
},
|
|
5125
|
+
...appearance
|
|
5126
|
+
],
|
|
5127
|
+
whenUnmet: "Renders nothing without a session; says so when no API resource is defined."
|
|
5128
|
+
},
|
|
5129
|
+
// --- The application's own data ------------------------------------------
|
|
5130
|
+
{
|
|
5131
|
+
name: "DataTable",
|
|
5132
|
+
kind: "component",
|
|
5133
|
+
summary: "A table of a collection's records, with columns derived from its fields.",
|
|
5134
|
+
useWhen: "Listing records. Reach for Kanban instead to group them by a status, or Chart to count or total them over time.",
|
|
5135
|
+
requires: ["session", "collection"],
|
|
5136
|
+
bindsToCollection: true,
|
|
5137
|
+
props: [
|
|
5138
|
+
{ name: "collection", summary: "The collection key. Required in practice.", required: false },
|
|
5139
|
+
{
|
|
5140
|
+
name: "columns",
|
|
5141
|
+
summary: "Which fields to show, in order. Every field when omitted.",
|
|
5142
|
+
required: false
|
|
5143
|
+
},
|
|
5144
|
+
{ name: "renderCell", summary: "Replace the cell for one field.", required: false },
|
|
5145
|
+
{ name: "onSelect", summary: "Row click. Rows are inert without it.", required: false },
|
|
5146
|
+
{
|
|
5147
|
+
name: "onChanged",
|
|
5148
|
+
summary: "Called after this table creates, edits or deletes a record. The table refreshes itself; use this to refresh anything else on the page bound to the same collection, such as a Chart.",
|
|
5149
|
+
required: false
|
|
5150
|
+
},
|
|
5151
|
+
{ name: "hideSearch", summary: "Hide the search box.", required: false },
|
|
5152
|
+
{
|
|
5153
|
+
name: "readOnly",
|
|
5154
|
+
summary: "Hide New, Edit and Delete even for a writer.",
|
|
5155
|
+
required: false
|
|
5156
|
+
},
|
|
5157
|
+
{ name: "emptyState", summary: "Shown when there is nothing to list.", required: false },
|
|
5158
|
+
...appearance
|
|
5159
|
+
],
|
|
5160
|
+
whenUnmet: "Without the read permission it says which permission is missing, rather than showing an empty table.",
|
|
5161
|
+
seeAlso: ["Kanban", "Chart", "RecordDetail", "RecordForm", "useCollection"]
|
|
5162
|
+
},
|
|
5163
|
+
{
|
|
5164
|
+
name: "Kanban",
|
|
5165
|
+
kind: "component",
|
|
5166
|
+
summary: "A board, grouped by a choice field it finds on its own.",
|
|
5167
|
+
useWhen: "The records move through stages \u2014 a status, a pipeline.",
|
|
5168
|
+
requires: ["session", "collection"],
|
|
5169
|
+
bindsToCollection: true,
|
|
5170
|
+
props: [
|
|
5171
|
+
{ name: "collection", summary: "The collection key. Required in practice.", required: false },
|
|
5172
|
+
{
|
|
5173
|
+
name: "groupBy",
|
|
5174
|
+
summary: "Which field makes the columns. Discovered when omitted.",
|
|
5175
|
+
required: false
|
|
5176
|
+
},
|
|
5177
|
+
{ name: "cardFields", summary: "What to show on a card.", required: false },
|
|
5178
|
+
{ name: "onSelect", summary: "Card click.", required: false },
|
|
5179
|
+
{ name: "emptyState", summary: "Shown in a column with nothing in it.", required: false },
|
|
5180
|
+
...appearance
|
|
5181
|
+
],
|
|
5182
|
+
whenUnmet: "A collection with no groupable field says to add a choice field, rather than drawing one column.",
|
|
5183
|
+
seeAlso: ["DataTable", "Chart"]
|
|
5184
|
+
},
|
|
5185
|
+
{
|
|
5186
|
+
name: "Chart",
|
|
5187
|
+
kind: "component",
|
|
5188
|
+
summary: "Records over time, counted or totalled.",
|
|
5189
|
+
useWhen: "The question is how many or how much, by day, week or month.",
|
|
5190
|
+
requires: ["session", "collection"],
|
|
5191
|
+
bindsToCollection: true,
|
|
5192
|
+
props: [
|
|
5193
|
+
{ name: "collection", summary: "The collection key. Required in practice.", required: false },
|
|
5194
|
+
{ name: "x", summary: "The date field. Discovered when omitted.", required: false },
|
|
5195
|
+
{
|
|
5196
|
+
name: "y",
|
|
5197
|
+
summary: "What to measure. Counts the records when omitted.",
|
|
5198
|
+
required: false
|
|
5199
|
+
},
|
|
5200
|
+
{ name: "aggregate", summary: "sum, avg, min or max. Defaults to sum.", required: false },
|
|
5201
|
+
{ name: "bucket", summary: "day, week or month. Defaults to day.", required: false },
|
|
5202
|
+
{ name: "title", summary: "Overrides the derived caption.", required: false },
|
|
5203
|
+
{ name: "height", summary: "Plot height in pixels.", required: false },
|
|
5204
|
+
...appearance
|
|
5205
|
+
],
|
|
5206
|
+
whenUnmet: "A collection with no date field says so. A field that cannot be summed is refused rather than quietly counted.",
|
|
5207
|
+
seeAlso: ["DataTable", "Kanban"]
|
|
5208
|
+
},
|
|
5209
|
+
{
|
|
5210
|
+
name: "RecordDetail",
|
|
5211
|
+
kind: "component",
|
|
5212
|
+
summary: "One record in full, including the fields a table truncates.",
|
|
5213
|
+
useWhen: "After a row or card is clicked.",
|
|
5214
|
+
requires: ["session", "collection"],
|
|
5215
|
+
bindsToCollection: true,
|
|
5216
|
+
props: [
|
|
5217
|
+
{ name: "collection", summary: "The collection key. Required in practice.", required: false },
|
|
5218
|
+
{ name: "recordId", summary: "Which record. Required in practice.", required: false },
|
|
5219
|
+
{ name: "tenant", summary: "Only when the user is in several.", required: false },
|
|
5220
|
+
{ name: "readOnly", summary: "Hide Edit and Delete.", required: false },
|
|
5221
|
+
{ name: "onDeleted", summary: "Called after deletion.", required: false },
|
|
5222
|
+
{ name: "onClose", summary: "Renders a Close button when given.", required: false },
|
|
5223
|
+
{ name: "children", summary: "Rendered under the fields.", required: false },
|
|
5224
|
+
...appearance
|
|
5225
|
+
],
|
|
5226
|
+
seeAlso: ["DataTable", "RecordForm"]
|
|
5227
|
+
},
|
|
5228
|
+
{
|
|
5229
|
+
name: "RecordForm",
|
|
5230
|
+
kind: "component",
|
|
5231
|
+
summary: "Create or edit a record, with inputs derived from the field types.",
|
|
5232
|
+
useWhen: "Adding a record, or editing one outside the detail view.",
|
|
5233
|
+
requires: ["session", "collection"],
|
|
5234
|
+
bindsToCollection: true,
|
|
5235
|
+
props: [
|
|
5236
|
+
{ name: "collection", summary: "The collection key. Required in practice.", required: false },
|
|
5237
|
+
{ name: "recordId", summary: "Omit to create, supply to edit.", required: false },
|
|
5238
|
+
{ name: "tenant", summary: "Only when the user is in several.", required: false },
|
|
5239
|
+
{
|
|
5240
|
+
name: "onSaved",
|
|
5241
|
+
summary: "Called with the record id. Does not refresh a sibling table \u2014 see the composition rules.",
|
|
5242
|
+
required: false
|
|
5243
|
+
},
|
|
5244
|
+
{ name: "onCancel", summary: "Renders a Cancel button when given.", required: false },
|
|
5245
|
+
{ name: "defaults", summary: "Values to start with. Ignored when editing.", required: false },
|
|
5246
|
+
...appearance
|
|
5247
|
+
],
|
|
5248
|
+
whenUnmet: "Computed fields get no input at all, because the server produces them.",
|
|
5249
|
+
seeAlso: ["RecordDetail", "RelationPicker"]
|
|
5250
|
+
},
|
|
5251
|
+
{
|
|
5252
|
+
name: "RelationPicker",
|
|
5253
|
+
kind: "component",
|
|
5254
|
+
summary: "Choose a record in another collection by typing its name.",
|
|
5255
|
+
useWhen: "Building your own form. RecordForm uses this for relation fields already.",
|
|
5256
|
+
requires: ["session", "collection"],
|
|
5257
|
+
props: [
|
|
5258
|
+
{ name: "field", summary: "The relation field descriptor.", required: true },
|
|
5259
|
+
{ name: "value", summary: "The chosen record id, or null.", required: true },
|
|
5260
|
+
{ name: "onChange", summary: "Called with the new id.", required: true },
|
|
5261
|
+
{ name: "error", summary: "Message shown under the input.", required: false },
|
|
5262
|
+
{ name: "disabled", summary: "Read-only.", required: false },
|
|
5263
|
+
{ name: "tenant", summary: "Only when the user is in several.", required: false }
|
|
5264
|
+
],
|
|
5265
|
+
seeAlso: ["RecordForm"]
|
|
5266
|
+
},
|
|
5267
|
+
{
|
|
5268
|
+
name: "useCollection",
|
|
5269
|
+
kind: "hook",
|
|
5270
|
+
summary: "A collection's schema, records, filters, paging, permissions and writes \u2014 without markup.",
|
|
5271
|
+
useWhen: "You want your own table, board or form but not your own data layer.",
|
|
5272
|
+
requires: ["session", "collection"],
|
|
5273
|
+
bindsToCollection: true,
|
|
5274
|
+
props: [],
|
|
5275
|
+
seeAlso: ["DataTable", "FieldCell", "FieldInput"]
|
|
5276
|
+
},
|
|
5277
|
+
{
|
|
5278
|
+
name: "FieldCell",
|
|
5279
|
+
kind: "component",
|
|
5280
|
+
summary: "One field value, rendered the way the tables render it.",
|
|
5281
|
+
useWhen: "Building your own table over useCollection.",
|
|
5282
|
+
requires: [],
|
|
5283
|
+
props: [
|
|
5284
|
+
{ name: "value", summary: "The stored value.", required: true },
|
|
5285
|
+
{ name: "field", summary: "The field descriptor.", required: true },
|
|
5286
|
+
{ name: "related", summary: "A relation's resolved label.", required: false }
|
|
5287
|
+
],
|
|
5288
|
+
seeAlso: ["FieldInput", "useCollection"]
|
|
5289
|
+
},
|
|
5290
|
+
{
|
|
5291
|
+
name: "FieldInput",
|
|
5292
|
+
kind: "component",
|
|
5293
|
+
summary: "The input for one field, chosen by its type.",
|
|
5294
|
+
useWhen: "Building your own form over useCollection.",
|
|
5295
|
+
requires: [],
|
|
5296
|
+
props: [
|
|
5297
|
+
{ name: "value", summary: "The current value.", required: true },
|
|
5298
|
+
{ name: "field", summary: "The field descriptor.", required: true },
|
|
5299
|
+
{ name: "onChange", summary: "Called with the new value.", required: true },
|
|
5300
|
+
{ name: "error", summary: "Message shown under the input.", required: false },
|
|
5301
|
+
{ name: "disabled", summary: "Read-only.", required: false }
|
|
5302
|
+
],
|
|
5303
|
+
whenUnmet: "Renders nothing for a computed field \u2014 the server produces those.",
|
|
5304
|
+
seeAlso: ["FieldCell", "RecordForm"]
|
|
5305
|
+
}
|
|
5306
|
+
];
|
|
5307
|
+
var COMPOSITION = {
|
|
5308
|
+
rules: [
|
|
5309
|
+
"Everything must be inside Base316Provider. Outside it, hooks throw.",
|
|
5310
|
+
"Most components need a signed-in user. Gate on useSession and render SignIn when there is none \u2014 see `requires: session` on each entry.",
|
|
5311
|
+
"A collection must exist before anything can bind to it. Define one in the dashboard under Collections, or through POST /v1/collections with a secret key.",
|
|
5312
|
+
"No component takes a prop you must supply to make it behave. Naming the subject is different: a collection component needs `collection` and a detail view needs `recordId`, because those say *what* to show rather than patch *how* it works. Everything else has a default.",
|
|
5313
|
+
"Each component bound to a collection holds its own data \u2014 DataTable, Kanban, Chart, RecordForm, RecordDetail, every one. None of them share a cache, so a write in one leaves the others showing what they already had. Put the form inside the table, where New and Edit refresh it; pass `onChanged` to refresh a sibling such as a Chart; or lift `useCollection` and render your own, which is what the hook is for.",
|
|
5314
|
+
"Next.js App Router: put Base316Provider in a Client Component wrapper used by the root layout. Every component here is a Client Component; none of them run on the server."
|
|
5315
|
+
],
|
|
5316
|
+
/** The shape almost every application ends up with. */
|
|
5317
|
+
example: `
|
|
5318
|
+
import { Base316Provider, DataTable, RecordForm, SignIn, useSession } from "@base316/react";
|
|
5319
|
+
|
|
5320
|
+
function Jobs() {
|
|
5321
|
+
const session = useSession();
|
|
5322
|
+
|
|
5323
|
+
// Without this the table renders nothing and looks broken.
|
|
5324
|
+
if (!session) return <SignIn />;
|
|
5325
|
+
|
|
5326
|
+
return (
|
|
5327
|
+
<>
|
|
5328
|
+
<DataTable collection="jobs" onSelect={(record) => console.log(record.id)} />
|
|
5329
|
+
<RecordForm collection="jobs" />
|
|
5330
|
+
</>
|
|
5331
|
+
);
|
|
5332
|
+
}
|
|
5333
|
+
|
|
5334
|
+
export function App() {
|
|
5335
|
+
return (
|
|
5336
|
+
<Base316Provider publishableKey={process.env.NEXT_PUBLIC_BASE316_PUBLISHABLE_KEY!}>
|
|
5337
|
+
<Jobs />
|
|
5338
|
+
</Base316Provider>
|
|
5339
|
+
);
|
|
5340
|
+
}
|
|
5341
|
+
`.trim()
|
|
5342
|
+
};
|
|
5343
|
+
function describeComponent(name) {
|
|
5344
|
+
return MANIFEST.find((entry) => entry.name === name);
|
|
5345
|
+
}
|
|
5346
|
+
function componentsRequiring(requirement) {
|
|
5347
|
+
return MANIFEST.filter((entry) => entry.requires.includes(requirement));
|
|
5348
|
+
}
|
|
1195
5349
|
export {
|
|
5350
|
+
AcceptInvitation,
|
|
5351
|
+
ActiveSessions,
|
|
5352
|
+
ApiKeyManager,
|
|
1196
5353
|
Base316Provider,
|
|
1197
5354
|
Branding,
|
|
5355
|
+
COMPOSITION,
|
|
5356
|
+
Chart,
|
|
5357
|
+
DataTable,
|
|
5358
|
+
DeviceApproval,
|
|
5359
|
+
FieldCell,
|
|
5360
|
+
FieldInput,
|
|
5361
|
+
ForgotPassword,
|
|
1198
5362
|
Invoices,
|
|
5363
|
+
Kanban,
|
|
5364
|
+
MANIFEST,
|
|
1199
5365
|
PasskeyManager,
|
|
5366
|
+
PayInvoice,
|
|
1200
5367
|
PricingTable,
|
|
5368
|
+
PrivacyControls,
|
|
5369
|
+
RecordDetail,
|
|
5370
|
+
RecordForm,
|
|
5371
|
+
RelationPicker,
|
|
5372
|
+
ResetPassword,
|
|
1201
5373
|
SignIn,
|
|
1202
5374
|
SignUp,
|
|
1203
5375
|
SubscriptionManager,
|
|
5376
|
+
TeamMembers,
|
|
5377
|
+
TwoFactorManager,
|
|
1204
5378
|
UserProfile,
|
|
5379
|
+
VerifyEmail,
|
|
5380
|
+
componentsRequiring,
|
|
5381
|
+
describeComponent,
|
|
1205
5382
|
useBase316,
|
|
5383
|
+
useCollection,
|
|
5384
|
+
usePaymentLink,
|
|
5385
|
+
usePlans,
|
|
1206
5386
|
useSession
|
|
1207
5387
|
};
|
|
1208
5388
|
//# sourceMappingURL=index.js.map
|