@sparkvault/sdk-js 14.2.2 → 14.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -6
- package/dist/index.cjs +1679 -1109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +21 -5
- package/dist/index.mjs +1679 -1109
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/client.d.ts +18 -4
- package/dist/products/help-desk/form-attachments.d.ts +1 -0
- package/dist/products/help-desk/form.d.ts +20 -1
- package/dist/products/help-desk/types.d.ts +3 -1
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/dist/ui/modal-shell.d.ts +41 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9689,33 +9689,71 @@ function getStyles(options) {
|
|
|
9689
9689
|
}
|
|
9690
9690
|
|
|
9691
9691
|
/**
|
|
9692
|
-
* Modal shell shared by the SDK's widgets (identity and
|
|
9692
|
+
* Modal shell shared by the SDK's widgets (identity, upload and the help desk
|
|
9693
|
+
* form).
|
|
9693
9694
|
*
|
|
9694
|
-
* One dialog behaviour for
|
|
9695
|
-
*
|
|
9696
|
-
*
|
|
9697
|
-
*
|
|
9698
|
-
*
|
|
9699
|
-
*
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9695
|
+
* One dialog behaviour for all of them: an overlay labelled as a modal dialog;
|
|
9696
|
+
* a page scroll lock held for as long as any shell is open (and the page's own
|
|
9697
|
+
* overflow given back when the last one closes); focus moved into the dialog
|
|
9698
|
+
* on open and returned to whatever had it on close; and every listener
|
|
9699
|
+
* removed on teardown. Each widget builds its own header, body and footer
|
|
9700
|
+
* inside `modal`.
|
|
9701
|
+
*
|
|
9702
|
+
* The backdrop dismisses only a press and release both on it. A browser sends
|
|
9703
|
+
* `click` to the nearest common ancestor of the press and the release, so a
|
|
9704
|
+
* text selection dragged out of the dialog and released over the backdrop
|
|
9705
|
+
* clicks the overlay, and that is no dismissal.
|
|
9706
|
+
*
|
|
9707
|
+
* Open shells stack, and the keyboard belongs to the one opened last that is
|
|
9708
|
+
* still in the page, so a dialog opened over another (Identity's sign-in over
|
|
9709
|
+
* the help desk form) answers alone, and a shell whose overlay the host
|
|
9710
|
+
* removed without destroy() answers nothing. A dialog of the host's own that
|
|
9711
|
+
* holds focus (an `onAuthRequired` sign-in opened over the form) keeps the
|
|
9712
|
+
* keyboard too. Escape dismisses the shell, unless the key ends an IME
|
|
9713
|
+
* composition or another handler already took it (`defaultPrevented`). Tab
|
|
9714
|
+
* and Shift+Tab stay inside it, wrapping from its last control to its first
|
|
9715
|
+
* and back, as the WAI-ARIA dialog pattern asks; Escape still leaves, so it is
|
|
9716
|
+
* no keyboard trap.
|
|
9717
|
+
*/
|
|
9718
|
+
/** What Tab can reach inside a dialog, before the rendered check. */
|
|
9719
|
+
const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]):not([type=hidden]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
9720
|
+
/** A dialog of any making: focus inside one that is no shell's leaves the keyboard to it. */
|
|
9721
|
+
const ANY_DIALOG = '[aria-modal="true"], [role="dialog"], [role="alertdialog"], dialog[open]';
|
|
9722
|
+
/** Shells currently open, the one opened last on top, and the page overflow the first of them replaced. */
|
|
9723
|
+
const openShells = [];
|
|
9703
9724
|
let pageOverflow = '';
|
|
9704
|
-
|
|
9705
|
-
|
|
9725
|
+
/** The shell opened last whose overlay is still in the page. */
|
|
9726
|
+
function topShell() {
|
|
9727
|
+
for (let index = openShells.length - 1; index >= 0; index -= 1) {
|
|
9728
|
+
if (openShells[index].overlay.isConnected)
|
|
9729
|
+
return openShells[index];
|
|
9730
|
+
}
|
|
9731
|
+
return undefined;
|
|
9732
|
+
}
|
|
9733
|
+
/**
|
|
9734
|
+
* Whether a keydown is an IME's. Safari ends a composition before the keydown
|
|
9735
|
+
* that ends it, so that keydown reads `isComposing` false and only its
|
|
9736
|
+
* (deprecated) `keyCode`, the IME's 229, tells it apart.
|
|
9737
|
+
*/
|
|
9738
|
+
function composing(event) {
|
|
9739
|
+
return event.isComposing || event.keyCode === 229;
|
|
9740
|
+
}
|
|
9741
|
+
function pushShell(shell) {
|
|
9742
|
+
if (openShells.length === 0) {
|
|
9706
9743
|
pageOverflow = document.body.style.overflow;
|
|
9707
9744
|
document.body.style.overflow = 'hidden';
|
|
9708
9745
|
}
|
|
9709
|
-
openShells
|
|
9746
|
+
openShells.push(shell);
|
|
9710
9747
|
}
|
|
9711
|
-
function
|
|
9712
|
-
openShells
|
|
9713
|
-
if (openShells === 0) {
|
|
9748
|
+
function removeShell(shell) {
|
|
9749
|
+
openShells.splice(openShells.indexOf(shell), 1);
|
|
9750
|
+
if (openShells.length === 0) {
|
|
9714
9751
|
document.body.style.overflow = pageOverflow;
|
|
9715
9752
|
}
|
|
9716
9753
|
}
|
|
9717
9754
|
class ModalShell {
|
|
9718
9755
|
constructor(options) {
|
|
9756
|
+
this.pressOnBackdrop = false;
|
|
9719
9757
|
this.open = true;
|
|
9720
9758
|
this.opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
9721
9759
|
this.overlay = document.createElement('div');
|
|
@@ -9730,18 +9768,33 @@ class ModalShell {
|
|
|
9730
9768
|
this.modal.className = `${options.classPrefix}-modal`;
|
|
9731
9769
|
this.modal.tabIndex = -1;
|
|
9732
9770
|
this.overlay.appendChild(this.modal);
|
|
9771
|
+
this.onOverlayPointerDown = (event) => {
|
|
9772
|
+
this.pressOnBackdrop = event.target === this.overlay;
|
|
9773
|
+
};
|
|
9733
9774
|
this.onOverlayClick = (event) => {
|
|
9734
|
-
|
|
9775
|
+
const dismiss = event.target === this.overlay && this.pressOnBackdrop;
|
|
9776
|
+
this.pressOnBackdrop = false;
|
|
9777
|
+
if (dismiss)
|
|
9735
9778
|
options.onDismiss();
|
|
9736
9779
|
};
|
|
9737
9780
|
this.onKeydown = (event) => {
|
|
9738
|
-
if (
|
|
9781
|
+
if (!this.ownsKeyboard())
|
|
9782
|
+
return;
|
|
9783
|
+
if (event.key === 'Escape') {
|
|
9784
|
+
if (composing(event) || event.defaultPrevented)
|
|
9785
|
+
return;
|
|
9786
|
+
event.preventDefault();
|
|
9739
9787
|
options.onDismiss();
|
|
9788
|
+
}
|
|
9789
|
+
else if (event.key === 'Tab' && !event.defaultPrevented) {
|
|
9790
|
+
this.keepFocusInside(event);
|
|
9791
|
+
}
|
|
9740
9792
|
};
|
|
9793
|
+
this.overlay.addEventListener('pointerdown', this.onOverlayPointerDown);
|
|
9741
9794
|
this.overlay.addEventListener('click', this.onOverlayClick);
|
|
9742
9795
|
document.addEventListener('keydown', this.onKeydown);
|
|
9743
9796
|
document.body.appendChild(this.overlay);
|
|
9744
|
-
|
|
9797
|
+
pushShell(this);
|
|
9745
9798
|
this.modal.focus({ preventScroll: true });
|
|
9746
9799
|
}
|
|
9747
9800
|
/** Remove the dialog, release the scroll lock, and return focus to the opener. */
|
|
@@ -9750,13 +9803,59 @@ class ModalShell {
|
|
|
9750
9803
|
return;
|
|
9751
9804
|
this.open = false;
|
|
9752
9805
|
document.removeEventListener('keydown', this.onKeydown);
|
|
9806
|
+
this.overlay.removeEventListener('pointerdown', this.onOverlayPointerDown);
|
|
9753
9807
|
this.overlay.removeEventListener('click', this.onOverlayClick);
|
|
9754
9808
|
this.overlay.remove();
|
|
9755
|
-
|
|
9809
|
+
removeShell(this);
|
|
9756
9810
|
if (this.opener?.isConnected) {
|
|
9757
9811
|
this.opener.focus({ preventScroll: true });
|
|
9758
9812
|
}
|
|
9759
9813
|
}
|
|
9814
|
+
/**
|
|
9815
|
+
* Whether this shell answers the keyboard: it is the top shell still in the
|
|
9816
|
+
* page, and focus is not inside a dialog of the host's own, which the shell
|
|
9817
|
+
* stack does not know of. Focus in another shell is the stack's to settle.
|
|
9818
|
+
*/
|
|
9819
|
+
ownsKeyboard() {
|
|
9820
|
+
if (topShell() !== this)
|
|
9821
|
+
return false;
|
|
9822
|
+
const hostDialog = document.activeElement?.closest(ANY_DIALOG);
|
|
9823
|
+
return !hostDialog || openShells.some((shell) => shell.overlay.contains(hostDialog));
|
|
9824
|
+
}
|
|
9825
|
+
/**
|
|
9826
|
+
* Wrap Tab from the dialog's last rendered control to its first, and
|
|
9827
|
+
* Shift+Tab from its first (or from anything before it, the dialog itself
|
|
9828
|
+
* included) to its last. Focus that has left the dialog comes back to its
|
|
9829
|
+
* first control. A step a widget hides (`hidden`) renders no box, so its
|
|
9830
|
+
* controls are never reached.
|
|
9831
|
+
*/
|
|
9832
|
+
keepFocusInside(event) {
|
|
9833
|
+
const controls = Array.from(this.modal.querySelectorAll(FOCUSABLE))
|
|
9834
|
+
.filter((element) => element.getClientRects().length > 0);
|
|
9835
|
+
const active = document.activeElement;
|
|
9836
|
+
if (controls.length === 0) {
|
|
9837
|
+
event.preventDefault();
|
|
9838
|
+
this.modal.focus({ preventScroll: true });
|
|
9839
|
+
return;
|
|
9840
|
+
}
|
|
9841
|
+
const first = controls[0];
|
|
9842
|
+
const last = controls[controls.length - 1];
|
|
9843
|
+
if (!active || !this.modal.contains(active)) {
|
|
9844
|
+
event.preventDefault();
|
|
9845
|
+
first.focus();
|
|
9846
|
+
return;
|
|
9847
|
+
}
|
|
9848
|
+
const beforeFirst = active === first || (first.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_PRECEDING) !== 0;
|
|
9849
|
+
const afterLast = active === last || ((last.compareDocumentPosition(active) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0 && !last.contains(active));
|
|
9850
|
+
if (event.shiftKey && beforeFirst) {
|
|
9851
|
+
event.preventDefault();
|
|
9852
|
+
last.focus();
|
|
9853
|
+
}
|
|
9854
|
+
else if (!event.shiftKey && afterLast) {
|
|
9855
|
+
event.preventDefault();
|
|
9856
|
+
first.focus();
|
|
9857
|
+
}
|
|
9858
|
+
}
|
|
9760
9859
|
}
|
|
9761
9860
|
|
|
9762
9861
|
/**
|
|
@@ -14936,6 +15035,18 @@ function requestNumber(value) {
|
|
|
14936
15035
|
function validToken(value) {
|
|
14937
15036
|
return typeof value === 'string' && SESSION_TOKEN.test(value);
|
|
14938
15037
|
}
|
|
15038
|
+
/** A session answer's lifetime: whole seconds from its landing, more than none. */
|
|
15039
|
+
function validLifetime(value) {
|
|
15040
|
+
return Number.isSafeInteger(value) && value > 0;
|
|
15041
|
+
}
|
|
15042
|
+
/**
|
|
15043
|
+
* When a session whose answer lands now ends, in seconds on this device's
|
|
15044
|
+
* clock: its `ttl_seconds` from now. Core's `expires_at` is never compared
|
|
15045
|
+
* with the device clock, which may run apart from Core's.
|
|
15046
|
+
*/
|
|
15047
|
+
function landedDeadline(session) {
|
|
15048
|
+
return Date.now() / 1000 + session.ttl_seconds;
|
|
15049
|
+
}
|
|
14939
15050
|
/** A stale result cannot be rendered as, or mistaken for a failure of, the new customer. */
|
|
14940
15051
|
function sessionChanged() {
|
|
14941
15052
|
return new SparkVaultError('The help desk session changed before this request completed. Reload for the current customer; reconcile any pending write before retrying.', 'HELP_DESK_SESSION_CHANGED', 409, undefined, null, 'HELP_DESK_SESSION_CHANGED');
|
|
@@ -14952,6 +15063,12 @@ class HelpDeskClient {
|
|
|
14952
15063
|
this.renewedTokens = new Set();
|
|
14953
15064
|
this.authorityRevision = 0;
|
|
14954
15065
|
this.listeners = new Set();
|
|
15066
|
+
/**
|
|
15067
|
+
* When the installed session ends on this device's clock, in seconds: set
|
|
15068
|
+
* from `ttl_seconds` as an answer lands from Core. Null for a session whose
|
|
15069
|
+
* landing this client did not see (setSession), which ends at Core's 401.
|
|
15070
|
+
*/
|
|
15071
|
+
this.deadline = null;
|
|
14955
15072
|
this.token = null;
|
|
14956
15073
|
this.revision = 0;
|
|
14957
15074
|
this.desk = Object.freeze({ ...desk, branding: Object.freeze({ ...desk.branding }), identity: desk.identity ? Object.freeze({ ...desk.identity }) : null,
|
|
@@ -14990,19 +15107,23 @@ class HelpDeskClient {
|
|
|
14990
15107
|
return new HelpDeskClient(data, http, new IngotsModule(customerConfig, http), options.getSessionToken, assertionProvider);
|
|
14991
15108
|
}
|
|
14992
15109
|
/**
|
|
14993
|
-
* Install a customer session answer
|
|
14994
|
-
*
|
|
14995
|
-
*
|
|
15110
|
+
* Install a customer session answer the host holds, such as one restored
|
|
15111
|
+
* from its own storage. Its landing time is unknown, so this client sets it
|
|
15112
|
+
* no deadline of its own: it lasts until Core answers 401, which clears it.
|
|
15113
|
+
* A company provider verifies restored sessions again before use. Null
|
|
15114
|
+
* stays signed out until refreshSession() or authenticate() explicitly
|
|
15115
|
+
* resumes the provider.
|
|
14996
15116
|
*/
|
|
14997
15117
|
setSession(session) {
|
|
14998
|
-
this.installSession(session);
|
|
15118
|
+
this.installSession(session, null);
|
|
14999
15119
|
}
|
|
15000
|
-
installSession(session) {
|
|
15001
|
-
if (session !== null && (!validToken(session?.token) || !Number.isFinite(session.expires_at)
|
|
15002
|
-
throw new ValidationError('session must be a
|
|
15120
|
+
installSession(session, deadline) {
|
|
15121
|
+
if (session !== null && (!validToken(session?.token) || !Number.isFinite(session.expires_at))) {
|
|
15122
|
+
throw new ValidationError('session must be a help desk session answer', { field: 'session' });
|
|
15003
15123
|
}
|
|
15004
15124
|
const installed = session ? { ...session, customer: { ...session.customer } } : null;
|
|
15005
15125
|
this.session = installed;
|
|
15126
|
+
this.deadline = installed ? deadline : null;
|
|
15006
15127
|
this.authentication = null;
|
|
15007
15128
|
this.verifiedRequesterId = null;
|
|
15008
15129
|
this.provedSession = false;
|
|
@@ -15024,6 +15145,7 @@ class HelpDeskClient {
|
|
|
15024
15145
|
/** Explicitly refresh the host-managed session, for example after a backend handoff. */
|
|
15025
15146
|
async refreshSession() {
|
|
15026
15147
|
this.session = undefined;
|
|
15148
|
+
this.deadline = null;
|
|
15027
15149
|
this.authentication = null;
|
|
15028
15150
|
this.verifiedRequesterId = null;
|
|
15029
15151
|
this.provedSession = false;
|
|
@@ -15042,12 +15164,12 @@ class HelpDeskClient {
|
|
|
15042
15164
|
if (this.desk.auth_mode === 'external_unavailable')
|
|
15043
15165
|
throw new SparkVaultError('Company-session authentication is unavailable.', 'HELP_DESK_EXTERNAL_UNAVAILABLE', 503);
|
|
15044
15166
|
if (this.assertionProvider && this.desk.auth_mode === 'external_sso' &&
|
|
15045
|
-
(this.session === undefined || (this.session && (!this.provedSession || (this.verifiedRequesterId !== null && this.
|
|
15167
|
+
(this.session === undefined || (this.session && (!this.provedSession || (this.verifiedRequesterId !== null && this.deadline !== null && this.deadline <= Date.now() / 1000 + RENEW_BEFORE_SECONDS))))) {
|
|
15046
15168
|
await this.authenticate();
|
|
15047
15169
|
return this.session?.token ?? null;
|
|
15048
15170
|
}
|
|
15049
15171
|
if (this.session !== undefined) {
|
|
15050
|
-
if (this.session && this.
|
|
15172
|
+
if (this.session && this.deadline !== null && this.deadline <= Date.now() / 1000)
|
|
15051
15173
|
this.clearSession();
|
|
15052
15174
|
return this.session?.token ?? null;
|
|
15053
15175
|
}
|
|
@@ -15116,16 +15238,22 @@ class HelpDeskClient {
|
|
|
15116
15238
|
const session = await this.send('POST', path, body, undefined, false);
|
|
15117
15239
|
if (revision !== this.revision)
|
|
15118
15240
|
throw new AuthenticationError('The help desk session changed during sign-in. Try again.');
|
|
15119
|
-
|
|
15241
|
+
if (!validLifetime(session?.ttl_seconds))
|
|
15242
|
+
throw new SparkVaultError('The help desk returned an invalid session.', 'HELP_DESK_INVALID_RESPONSE');
|
|
15243
|
+
const installed = this.installSession(session, landedDeadline(session));
|
|
15120
15244
|
if (this.session !== installed || this.token !== session.token)
|
|
15121
15245
|
throw sessionChanged();
|
|
15122
15246
|
this.provedSession = true;
|
|
15123
15247
|
return session;
|
|
15124
15248
|
}
|
|
15125
|
-
/**
|
|
15249
|
+
/**
|
|
15250
|
+
* A public, short-lived challenge from the help desk's own Entropy service.
|
|
15251
|
+
* Core refuses a nonce past its `expires_at` on its own clock, so this
|
|
15252
|
+
* device's clock never judges it.
|
|
15253
|
+
*/
|
|
15126
15254
|
async startExternalChallenge() {
|
|
15127
15255
|
const challenge = await this.send('POST', apiPath `/v1/hd/desks/${this.desk.desk_id}/auth/external/challenge`, undefined, undefined, false);
|
|
15128
|
-
if (!EXTERNAL_NONCE.test(challenge?.nonce) || !EXTERNAL_NONCE.test(challenge?.verifier) || !Number.isFinite(challenge.expires_at)
|
|
15256
|
+
if (!EXTERNAL_NONCE.test(challenge?.nonce) || !EXTERNAL_NONCE.test(challenge?.verifier) || !Number.isFinite(challenge.expires_at)) {
|
|
15129
15257
|
throw new SparkVaultError('The help desk returned an invalid support challenge.', 'HELP_DESK_INVALID_RESPONSE');
|
|
15130
15258
|
}
|
|
15131
15259
|
return challenge;
|
|
@@ -15178,17 +15306,20 @@ class HelpDeskClient {
|
|
|
15178
15306
|
this.authentication = null; }).catch(() => undefined);
|
|
15179
15307
|
return operation;
|
|
15180
15308
|
}
|
|
15309
|
+
/** Install a company session answer that just landed from Core, timed from its `ttl_seconds`. */
|
|
15181
15310
|
acceptExternalSession(session, automatic = false) {
|
|
15182
|
-
if (!validToken(session?.token) || !Number.isFinite(session.expires_at) || session.
|
|
15311
|
+
if (!validToken(session?.token) || !Number.isFinite(session.expires_at) || !validLifetime(session.ttl_seconds) ||
|
|
15183
15312
|
!isResourceIdOf('requester', session.customer?.requester_id)) {
|
|
15184
15313
|
throw new SparkVaultError('The help desk returned an invalid company session.', 'HELP_DESK_INVALID_RESPONSE');
|
|
15185
15314
|
}
|
|
15315
|
+
const deadline = landedDeadline(session);
|
|
15186
15316
|
const previous = this.verifiedRequesterId;
|
|
15187
15317
|
const sameCustomer = previous !== null && previous === session.customer.requester_id;
|
|
15188
15318
|
if (sameCustomer && this.token)
|
|
15189
15319
|
this.renewedTokens.add(this.token);
|
|
15190
15320
|
const installed = { ...session, customer: { ...session.customer } };
|
|
15191
15321
|
this.session = installed;
|
|
15322
|
+
this.deadline = deadline;
|
|
15192
15323
|
this.verifiedRequesterId = session.customer.requester_id;
|
|
15193
15324
|
this.provedSession = true;
|
|
15194
15325
|
this.rememberToken(session.token, sameCustomer ? 'renew' : 'external', true, {
|
|
@@ -15295,645 +15426,70 @@ class HelpDeskClient {
|
|
|
15295
15426
|
}
|
|
15296
15427
|
}
|
|
15297
15428
|
|
|
15298
|
-
/** Scoped styles for the optional inline help desk form. */
|
|
15299
|
-
function injectHelpDeskFormStyles() {
|
|
15300
|
-
if (document.getElementById('sparkvault-help-desk-styles'))
|
|
15301
|
-
return;
|
|
15302
|
-
const style = document.createElement('style');
|
|
15303
|
-
style.id = 'sparkvault-help-desk-styles';
|
|
15304
|
-
style.textContent = `
|
|
15305
|
-
.svhd-overlay{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:${DS.modalOverlay};overflow:auto}
|
|
15306
|
-
.svhd-blur{backdrop-filter:blur(5px)}
|
|
15307
|
-
.svhd-modal{width:100%;max-width:36rem;max-height:calc(100dvh - 32px);overflow:auto;border-radius:12px;background:${DS.white};box-shadow:${DS.shadowPopover}}
|
|
15308
|
-
.svhd-modal-header{display:flex;justify-content:flex-end;padding:12px 16px 0}
|
|
15309
|
-
.svhd-modal-close{border:0;border-radius:4px;background:transparent;color:${DS.slate600};cursor:pointer;font:600 14px/1.5 system-ui,sans-serif;padding:6px 8px}
|
|
15310
|
-
.svhd-modal-close:hover{color:${DS.slate900}}
|
|
15311
|
-
.svhd-modal-close:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
15312
|
-
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
15313
|
-
.svhd-container{box-sizing:border-box;max-width:36rem;border:1px solid ${DS.slate200};border-radius:12px;background:${DS.white};color:${DS.slate900};font:400 15px/1.5 system-ui,sans-serif;padding:24px}
|
|
15314
|
-
.svhd-container *{box-sizing:border-box}
|
|
15315
|
-
.svhd-container h2{font-size:22px;line-height:1.25;margin:0 0 20px}
|
|
15316
|
-
.svhd-form{display:grid;gap:16px}
|
|
15317
|
-
.svhd-field{display:grid;gap:6px}
|
|
15318
|
-
.svhd-label{font-weight:600}
|
|
15319
|
-
.svhd-input{width:100%;border:1px solid ${DS.slate300};border-radius:6px;padding:10px 12px;color:${DS.slate900};background:${DS.white};font:inherit}
|
|
15320
|
-
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
15321
|
-
.svhd-input:disabled{background:${DS.slate50}}
|
|
15322
|
-
.svhd-description{min-height:140px;resize:vertical}
|
|
15323
|
-
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
15324
|
-
.svhd-auth[hidden],.svhd-field[hidden],.svhd-status[hidden],.svhd-link[hidden]{display:none}
|
|
15325
|
-
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
15326
|
-
.svhd-button{border:0;border-radius:6px;padding:10px 16px;font:600 15px/1.5 system-ui,sans-serif;background:${DS.action};color:${DS.white};cursor:pointer}
|
|
15327
|
-
.svhd-button:hover{background:${DS.actionHover}}
|
|
15328
|
-
.svhd-button:disabled{opacity:.6;cursor:default}
|
|
15329
|
-
.svhd-secondary{background:transparent;color:${DS.slate600};padding:10px 4px}
|
|
15330
|
-
.svhd-secondary:hover{background:transparent;color:${DS.slate900}}
|
|
15331
|
-
.svhd-status{margin:0;color:${DS.slate600}}
|
|
15332
|
-
.svhd-error{color:${DS.error}}
|
|
15333
|
-
.svhd-link{color:${DS.action};text-decoration:underline}
|
|
15334
|
-
.svhd-attachments[hidden],.svhd-attachments [hidden]{display:none}
|
|
15335
|
-
.svhd-file-hint{font-size:13px;color:${DS.slate600};margin:0}
|
|
15336
|
-
.svhd-file-list{display:grid;gap:12px;list-style:none;padding:0;margin:0}
|
|
15337
|
-
.svhd-file{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:4px 10px;align-items:center;border:1px solid ${DS.slate200};border-radius:6px;padding:10px}
|
|
15338
|
-
.svhd-file-name{font-weight:600;overflow-wrap:anywhere;grid-column:1/-1}
|
|
15339
|
-
.svhd-file [role=status]{grid-column:1/-1;font-size:13px}
|
|
15340
|
-
.svhd-file progress{width:100%;min-width:0;accent-color:${DS.action}}
|
|
15341
|
-
.svhd-file .svhd-button{font-size:13px;padding:6px}
|
|
15342
|
-
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
15343
|
-
`;
|
|
15344
|
-
document.head.appendChild(style);
|
|
15345
|
-
}
|
|
15346
|
-
|
|
15347
15429
|
/**
|
|
15348
|
-
* The
|
|
15349
|
-
*
|
|
15350
|
-
* before they send) and every runtime that saves a stored name to a device
|
|
15351
|
-
* (Forge's Content-Disposition, the web console's download, the x.sv reveal
|
|
15352
|
-
* page, the mobile share sheet). A download saves under the file's current
|
|
15353
|
-
* name by this rule, or under SAVED_FILENAME_FALLBACK when it has none.
|
|
15354
|
-
*
|
|
15355
|
-
* UNSAFE characters are never stored, and are replaced in any name saved to a
|
|
15356
|
-
* device: path separators, control characters (C0, DEL and C1), and the
|
|
15357
|
-
* invisible bidirectional controls that make a name display a different
|
|
15358
|
-
* extension than it has (`invoice<U+202E>fdp.exe` shows as `invoiceexe.pdf`).
|
|
15359
|
-
*
|
|
15360
|
-
* NON-PORTABLE characters (`: * ? " < > |`) are refused by the file systems a
|
|
15361
|
-
* name is saved to, so they are never stored either. A saved name keeps them:
|
|
15362
|
-
* a stored name cannot hold one, and Forge carries a name's exact text in the
|
|
15363
|
-
* RFC 5987 `filename*` parameter.
|
|
15430
|
+
* The products that send an organization's mail from a platform mail domain,
|
|
15431
|
+
* and the labels under those domains the platform keeps for itself.
|
|
15364
15432
|
*
|
|
15365
|
-
*
|
|
15366
|
-
*
|
|
15367
|
-
|
|
15368
|
-
|
|
15369
|
-
|
|
15370
|
-
* Control characters (C0, DEL and C1) and the invisible bidirectional text
|
|
15371
|
-
* controls, as the body of a character class: text holding one displays as
|
|
15372
|
-
* other text than it holds.
|
|
15373
|
-
*/
|
|
15374
|
-
const CONTROL_AND_BIDI_CHARACTERS = String.raw`\p{Cc}\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069`;
|
|
15375
|
-
|
|
15376
|
-
/** Path separators, control characters and bidirectional text controls. */
|
|
15377
|
-
const UNSAFE_FILENAME_CHARACTERS = new RegExp(String.raw`[\\/${CONTROL_AND_BIDI_CHARACTERS}]`, 'u');
|
|
15378
|
-
|
|
15379
|
-
/** Characters the file systems a name is saved to refuse. */
|
|
15380
|
-
const NON_PORTABLE_FILENAME_CHARACTERS = /[:*?"<>|]/;
|
|
15381
|
-
|
|
15382
|
-
/**
|
|
15383
|
-
* A character a save drops from a name's end. Windows drops trailing dots and
|
|
15384
|
-
* spaces from a name it saves ("page.html." is saved as "page.html"); any
|
|
15385
|
-
* other trailing white space is dropped alike, so a name never hides the
|
|
15386
|
-
* extension a saved copy could open as.
|
|
15387
|
-
*/
|
|
15388
|
-
const DROPPED_TRAILING_CHARACTER = /[\s.]/u;
|
|
15389
|
-
|
|
15390
|
-
/**
|
|
15391
|
-
* `name` without the trailing dots and white space a save drops: "page.html."
|
|
15392
|
-
* and "page.html " are "page.html", "notes. ." is "notes", and a name of only
|
|
15393
|
-
* dots and white space is ''. shownExtension and lastExtension read the
|
|
15394
|
-
* extension in front of them, and Forge completes a saved name after them
|
|
15395
|
-
* (./media-type-node.js withMediaTypeExtension: "notes." under text/plain
|
|
15396
|
-
* saves as "notes.txt").
|
|
15433
|
+
* Each product sends an organization's mail from `{handle}.{domain}`, the
|
|
15434
|
+
* organization's own host under the product's mail domain, or from a domain
|
|
15435
|
+
* the organization verified once it is ready for what the product uses it
|
|
15436
|
+
* for. Core and the console read these facts here, so no surface names a
|
|
15437
|
+
* product's domain, capabilities or From address its own way.
|
|
15397
15438
|
*
|
|
15398
|
-
*
|
|
15399
|
-
* @returns {string}
|
|
15439
|
+
* BROWSER-SAFE: imports only ./platform-domains.js, which imports nothing.
|
|
15400
15440
|
*/
|
|
15401
|
-
function trimDroppedTrailing(name) {
|
|
15402
|
-
let end = name.length;
|
|
15403
|
-
while (end > 0 && DROPPED_TRAILING_CHARACTER.test(name[end - 1])) end -= 1;
|
|
15404
|
-
return name.slice(0, end);
|
|
15405
|
-
}
|
|
15406
15441
|
|
|
15407
|
-
/**
|
|
15408
|
-
* Invisible characters (Unicode's Default_Ignorable_Code_Point): the joiners,
|
|
15409
|
-
* variation selectors, tags and bidirectional controls, which display as
|
|
15410
|
-
* nothing, and the Hangul fillers, which display as blank space. None shows
|
|
15411
|
-
* in a name, and a save keeps several (`Invoice.pdf<U+034F>` saves as itself
|
|
15412
|
-
* in Chromium and Firefox, and shows as `Invoice.pdf`).
|
|
15413
|
-
*/
|
|
15414
|
-
const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
|
|
15415
15442
|
|
|
15416
15443
|
/**
|
|
15417
|
-
*
|
|
15418
|
-
* (
|
|
15419
|
-
*
|
|
15420
|
-
*
|
|
15421
|
-
*
|
|
15422
|
-
*
|
|
15423
|
-
*
|
|
15424
|
-
* @returns {string}
|
|
15444
|
+
* Each product that sends an organization's mail from a platform mail domain:
|
|
15445
|
+
* its key (also its tiered-product key and the suffix of its SES tenant's
|
|
15446
|
+
* name), the domain (one SES identity, whose {handle}.{domain} subdomain is
|
|
15447
|
+
* each organization's address), what it uses an organization's own domain
|
|
15448
|
+
* for, what a domain needs ready before the product may select it, and the
|
|
15449
|
+
* fixed local part it writes from (null when it varies: a help desk team
|
|
15450
|
+
* writes from its alias). Every descriptor and array frozen.
|
|
15425
15451
|
*/
|
|
15426
|
-
|
|
15427
|
-
|
|
15428
|
-
|
|
15429
|
-
|
|
15430
|
-
|
|
15431
|
-
|
|
15432
|
-
|
|
15433
|
-
|
|
15434
|
-
|
|
15452
|
+
const MAIL_PRODUCTS = Object.freeze({
|
|
15453
|
+
help_desk: Object.freeze({
|
|
15454
|
+
key: 'help_desk',
|
|
15455
|
+
domain: SPARKVAULT_HELP_DESK_DOMAIN,
|
|
15456
|
+
capabilities: Object.freeze(['web', 'sending', 'receiving']),
|
|
15457
|
+
selectable: Object.freeze(['sending', 'web']),
|
|
15458
|
+
fromLocalPart: null
|
|
15459
|
+
}),
|
|
15460
|
+
notify: Object.freeze({
|
|
15461
|
+
key: 'notify',
|
|
15462
|
+
domain: SPARKVAULT_NOTIFY_SEND_DOMAIN,
|
|
15463
|
+
capabilities: Object.freeze(['sending']),
|
|
15464
|
+
selectable: Object.freeze(['sending']),
|
|
15465
|
+
fromLocalPart: 'notify'
|
|
15466
|
+
})
|
|
15435
15467
|
});
|
|
15436
15468
|
|
|
15437
|
-
/**
|
|
15438
|
-
|
|
15439
|
-
* shows nothing once saved (nameAsShown), every character in it a dot, white
|
|
15440
|
-
* space or an invisible character (`...` and ` . `, and `..<U+034F>` and
|
|
15441
|
-
* `.<U+200B>.`, which show as `..`). No such name is stored
|
|
15442
|
-
* (storableFilenameProblem), and a file that has one saves under the
|
|
15443
|
-
* fallback name (savedFilename).
|
|
15444
|
-
*
|
|
15445
|
-
* @param {string} name
|
|
15446
|
-
* @returns {boolean}
|
|
15447
|
-
*/
|
|
15448
|
-
function isOnlyDotsOrSpaces(name) {
|
|
15449
|
-
return name !== '' && nameAsShown(name) === '';
|
|
15450
|
-
}
|
|
15469
|
+
/** Every mail product's key, in MAIL_PRODUCTS order: the order every product-by-product decision runs in. */
|
|
15470
|
+
const MAIL_PRODUCT_KEYS = Object.freeze(Object.keys(MAIL_PRODUCTS));
|
|
15451
15471
|
|
|
15452
15472
|
/**
|
|
15453
|
-
*
|
|
15454
|
-
*
|
|
15473
|
+
* GENERATED by infra/scripts/generate-organization-name-unicode.mjs from
|
|
15474
|
+
* Unicode 18.0.0 (confusables.txt, UnicodeData.txt, DerivedBidiClass.txt,
|
|
15475
|
+
* BidiBrackets.txt, DerivedAge.txt, DerivedNormalizationProps.txt). Do not
|
|
15476
|
+
* edit: rerun the generator.
|
|
15455
15477
|
*
|
|
15456
|
-
* @
|
|
15457
|
-
*
|
|
15458
|
-
|
|
15459
|
-
|
|
15460
|
-
|
|
15461
|
-
|
|
15462
|
-
if (isOnlyDotsOrSpaces(name)) return FILENAME_PROBLEMS.ONLY_DOTS_OR_SPACES;
|
|
15463
|
-
return null;
|
|
15464
|
-
}
|
|
15465
|
-
|
|
15466
|
-
/** The longest name an ingot stores, in UTF-16 code units. */
|
|
15467
|
-
const INGOT_NAME_MAX = 255;
|
|
15468
|
-
|
|
15469
|
-
/**
|
|
15470
|
-
* A run of the white space Firefox reads in a name it saves: the space
|
|
15471
|
-
* separators and U+FEFF, and the line and paragraph separators, which it
|
|
15472
|
-
* drops wherever they stand and which end no run.
|
|
15478
|
+
* The Unicode data @sparkvault/app-sdk/organization-name reads a text with.
|
|
15479
|
+
* Code points are hexadecimal, separated by spaces; `first-last` is a range.
|
|
15480
|
+
* The rule reads a text in NFC, so neither list names a character NFC
|
|
15481
|
+
* replaces on every engine the rule runs on (Unicode 15.1 or older).
|
|
15482
|
+
*
|
|
15483
|
+
* BROWSER-SAFE: data only, no imports.
|
|
15473
15484
|
*/
|
|
15474
|
-
const WHITE_SPACE_RUN = /[\p{Zs}\uFEFF\u2028\u2029]+/gu;
|
|
15475
15485
|
|
|
15476
|
-
/** A run whose first space is an ideographic space (U+3000), the one space Firefox keeps. */
|
|
15477
|
-
const RUN_FIREFOX_KEEPS = /^[\u2028\u2029]*\u3000/;
|
|
15478
15486
|
|
|
15479
15487
|
/**
|
|
15480
|
-
*
|
|
15481
|
-
*
|
|
15482
|
-
*
|
|
15483
|
-
*
|
|
15484
|
-
*
|
|
15485
|
-
* follows the last dot. So a run there is dropped whole unless it starts with
|
|
15486
|
-
* an ideographic space: `evil.ex e` saves as `evil.exe`, `evil.ex<U+3000>e`
|
|
15487
|
-
* as itself, `evil.ex <U+3000>e` as `evil.exe`. Closing up the whole name
|
|
15488
|
-
* moves no dot, so what follows its last dot is what Firefox saves there.
|
|
15489
|
-
*
|
|
15490
|
-
* @param {string} name
|
|
15491
|
-
* @returns {string}
|
|
15492
|
-
*/
|
|
15493
|
-
function closeUpSpaces(name) {
|
|
15494
|
-
return name.replace(WHITE_SPACE_RUN, (run) => (RUN_FIREFOX_KEEPS.test(run) ? '\u3000' : ''));
|
|
15495
|
-
}
|
|
15496
|
-
|
|
15497
|
-
/**
|
|
15498
|
-
* The extension `name` shows, its spaces kept, lowercase and without its dot:
|
|
15499
|
-
* what follows the last dot of what the name shows once saved (nameAsShown:
|
|
15500
|
-
* read past its invisible characters, without the trailing dots and white
|
|
15501
|
-
* space a save drops). "invoice.note.html" and "page.html." show 'html',
|
|
15502
|
-
* "logs.tar.gz" 'gz', ".html" 'html' (Windows reads a leading dot's
|
|
15503
|
-
* extension), "Invoice.pdf (1)" 'pdf (1)', and a name with no dot ''. It is
|
|
15504
|
-
* what Chromium's copy shows, since Chromium saves a name as sent:
|
|
15505
|
-
* "Invoice.pdf<U+034F>" shows 'pdf', and a character that draws as blank
|
|
15506
|
-
* space or as another letter yet is no invisible character stays in it
|
|
15507
|
-
* ("Invoice.pdf<U+2800>", a braille blank, shows 'pdf<U+2800>';
|
|
15508
|
-
* "Invoice.<U+0440>df", a Cyrillic er, '<U+0440>df'). Only whether a saved
|
|
15509
|
-
* name is completed reads it, by where its first word ends
|
|
15510
|
-
* (./media-type-node.js withMediaTypeExtension), since completion ends a name
|
|
15511
|
-
* in its type's own extension, which holds no space for Firefox to close up;
|
|
15512
|
-
* every rule about what a name makes a file reads lastExtension.
|
|
15513
|
-
*
|
|
15514
|
-
* @param {string} name
|
|
15515
|
-
* @returns {string}
|
|
15516
|
-
*/
|
|
15517
|
-
function shownExtension(name) {
|
|
15518
|
-
const shown = nameAsShown(name);
|
|
15519
|
-
const dot = shown.lastIndexOf('.');
|
|
15520
|
-
return dot === -1 ? '' : shown.slice(dot + 1).toLowerCase();
|
|
15521
|
-
}
|
|
15522
|
-
|
|
15523
|
-
/**
|
|
15524
|
-
* The extension a saved copy of `name` opens as, lowercase and without its
|
|
15525
|
-
* dot: the one it shows (shownExtension) once its spaces are closed up as
|
|
15526
|
-
* Firefox, the browser that changes a saved name most, closes them
|
|
15527
|
-
* (closeUpSpaces). "evil.ex e", "evil.ex<U+00A0>e" and "evil. exe" open as
|
|
15528
|
-
* 'exe', "Scan. pdf" as 'pdf', "Invoice.pdf (1)" as 'pdf(1)' and "Acme Inc.
|
|
15529
|
-
* Contract" as 'contract', though Chromium saves each as sent. Every rule
|
|
15530
|
-
* about what a name makes a file (a refused extension, an inline
|
|
15531
|
-
* disposition, the type Core stores for an untyped upload, the type Forge
|
|
15532
|
-
* serves a download under: ./media-type-node.js) reads this, never
|
|
15533
|
-
* splitExtension.
|
|
15534
|
-
*
|
|
15535
|
-
* @param {string} name
|
|
15536
|
-
* @returns {string}
|
|
15537
|
-
*/
|
|
15538
|
-
function lastExtension(name) {
|
|
15539
|
-
// Closed up before its invisible characters are read past: Firefox counts
|
|
15540
|
-
// U+FEFF, one of them, as white space (`evil.ex<U+FEFF><U+3000>e` saves as
|
|
15541
|
-
// `evil.exe`).
|
|
15542
|
-
return shownExtension(closeUpSpaces(name));
|
|
15543
|
-
}
|
|
15544
|
-
|
|
15545
|
-
/**
|
|
15546
|
-
* What a help-desk attachment may be named and what its first bytes may not
|
|
15547
|
-
* be: the one list of the files a ticket accepts, beside the one list of
|
|
15548
|
-
* extensions Forge never completes a saved name with.
|
|
15549
|
-
*
|
|
15550
|
-
* Both sides of a ticket upload files: a customer through the portal, an
|
|
15551
|
-
* operator through the console, and a customer's mail client through SES. The
|
|
15552
|
-
* server never reads the plaintext of an uploaded ingot, so the policy splits
|
|
15553
|
-
* by where the bytes are: the NAME rule runs on the server at initiate and in
|
|
15554
|
-
* the browser before an upload starts; the SNIFF rule runs wherever the bytes
|
|
15555
|
-
* are at hand — in the browser over the file's first slice, and on the server
|
|
15556
|
-
* over an inbound email's parts. The type a ticket stores a file under, which
|
|
15557
|
-
* the MIME registry decides, is server-only: ./attachment-policy-node.js.
|
|
15558
|
-
*
|
|
15559
|
-
* Built on the platform's one filename grammar (filename.js): nothing here
|
|
15560
|
-
* spells a second version of it.
|
|
15561
|
-
*
|
|
15562
|
-
* BROWSER-SAFE: reads any Uint8Array (a Node Buffer is one).
|
|
15563
|
-
*/
|
|
15564
|
-
|
|
15565
|
-
|
|
15566
|
-
/**
|
|
15567
|
-
* The files a ticket accepts, by kind: each kind keyed by the word every
|
|
15568
|
-
* surface names it with (./attachment-check.js ACCEPTED_ATTACHMENTS_COPY), and
|
|
15569
|
-
* listing the extensions a name may end in, lowercase and without the dot, as
|
|
15570
|
-
* lastExtension reads the one a saved copy opens as. A ticket takes no other
|
|
15571
|
-
* file: a name of no extension, an archive, a page, a Markdown document, a
|
|
15572
|
-
* drawing, a legacy or macro-enabled Office document, a message, and every
|
|
15573
|
-
* program, script, installer, shortcut and certificate are refused, whatever
|
|
15574
|
-
* their bytes say.
|
|
15575
|
-
* attachment-policy.test.js gives each kind the reason the program a desktop
|
|
15576
|
-
* opens it with runs no code from it, and holds that none of them, nor any
|
|
15577
|
-
* extension the registry lists beside one for its type, is one of
|
|
15578
|
-
* REFUSED_EXTENSIONS or one Outlook blocks.
|
|
15579
|
-
*/
|
|
15580
|
-
const ACCEPTED_ATTACHMENT_KINDS = Object.freeze({
|
|
15581
|
-
images: Object.freeze(['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif', 'bmp', 'tif', 'tiff', 'avif']),
|
|
15582
|
-
documents: Object.freeze(['pdf', 'docx', 'xlsx', 'pptx', 'txt', 'csv', 'tsv', 'log', 'json']),
|
|
15583
|
-
recordings: Object.freeze(['mp4', 'mov', 'webm', 'm4a', 'mp3', 'wav'])
|
|
15584
|
-
});
|
|
15585
|
-
|
|
15586
|
-
/** Every extension a ticket's file may end in: ACCEPTED_ATTACHMENT_KINDS's, in its order. */
|
|
15587
|
-
const ACCEPTED_ATTACHMENT_EXTENSIONS = Object.freeze(Object.values(ACCEPTED_ATTACHMENT_KINDS).flat());
|
|
15588
|
-
|
|
15589
|
-
const ACCEPTED_EXTENSION_SET = new Set(ACCEPTED_ATTACHMENT_EXTENSIONS);
|
|
15590
|
-
|
|
15591
|
-
/**
|
|
15592
|
-
* The extensions Forge never completes a saved name with (lowercase, no dot):
|
|
15593
|
-
* a vault download's name that shows no extension the MIME registry knows is
|
|
15594
|
-
* completed with its type's registered one only when that is none of these
|
|
15595
|
-
* (./media-type-node.js withMediaTypeExtension), so no download saves as a
|
|
15596
|
-
* program, a script, a page or any file a desktop acts on when it is opened.
|
|
15597
|
-
* That completion is all that reads the list: a ticket takes only the
|
|
15598
|
-
* extensions it accepts (ACCEPTED_ATTACHMENT_EXTENSIONS), none of them one of
|
|
15599
|
-
* these. Every extension Outlook blocks as an attachment is one, held to
|
|
15600
|
-
* Microsoft's list by attachment-policy.test.js. The list is ordered by kind.
|
|
15601
|
-
*/
|
|
15602
|
-
const REFUSED_EXTENSIONS = Object.freeze([
|
|
15603
|
-
'exe', 'dll', 'scr', 'com', 'pif', 'cpl', 'msc', 'bat', 'cmd',
|
|
15604
|
-
'ps1', 'ps1xml', 'ps2', 'ps2xml', 'psc1', 'psc2', 'psd1', 'psdm1', 'pssc', 'cdxml',
|
|
15605
|
-
'msh', 'msh1', 'msh2', 'mshxml', 'msh1xml', 'msh2xml',
|
|
15606
|
-
'vb', 'vbs', 'vbe', 'js', 'jse', 'ws', 'wsf', 'wsh', 'wsc', 'sct',
|
|
15607
|
-
'msi', 'msp', 'mst', 'msu', 'cab', 'diagcab', 'inf', 'jar', 'hta', 'htc', 'reg',
|
|
15608
|
-
'lnk', 'url', 'website', 'shb', 'shs', 'scf', 'xnk', 'grp', 'library-ms', 'search-ms',
|
|
15609
|
-
'settingcontent-ms', 'appcontent-ms', 'theme', 'wsb', 'gadget', 'osd', 'bgi', 'udl', 'ins', 'isp',
|
|
15610
|
-
'webpnp', 'printerexport',
|
|
15611
|
-
'iso', 'img', 'vhd', 'vhdx', 'dmg', 'app',
|
|
15612
|
-
'sh', 'bash', 'zsh', 'ksh', 'csh', 'tcl', 'py', 'pyc', 'pyo', 'pyw', 'pyz', 'pyzw', 'pl', 'rb',
|
|
15613
|
-
'php', 'phtml', 'asp', 'aspx',
|
|
15614
|
-
'html', 'htm', 'xhtml', 'shtml', 'shtm', 'xht', 'xhtm', 'mht', 'mhtml', 'svg', 'svgz', 'xml', 'xsl', 'xslt',
|
|
15615
|
-
'rdf', 'xul',
|
|
15616
|
-
'docm', 'dotm', 'xlsm', 'xltm', 'xlam', 'pptm', 'potm', 'ppam', 'sldm', 'ppsm', 'xlsb', 'xla', 'xlm', 'xll',
|
|
15617
|
-
'application', 'appref-ms', 'xbap', 'appinstaller', 'appx', 'appxbundle', 'msix', 'msixbundle',
|
|
15618
|
-
'chm', 'its', 'hlp', 'cnt', 'hpj',
|
|
15619
|
-
'mdb', 'adp', 'ade', 'mag', 'mad', 'maf', 'mam', 'maq', 'mar', 'mas', 'mat', 'mav', 'maw', 'mda', 'mde',
|
|
15620
|
-
'mdt', 'mdw', 'mdz',
|
|
15621
|
-
'prf', 'ops', 'pst',
|
|
15622
|
-
'fxp', 'prg', 'bas', 'vbp', 'vsmacros', 'vsw', 'pcd', 'plg',
|
|
15623
|
-
'cer', 'der', 'crt', 'cert', 'pem', 'p12', 'pfx', 'pkcs12', 'p7b', 'p7c', 'p7r', 'spc',
|
|
15624
|
-
'jnlp', 'class', 'air', 'crx', 'xpi', 'oxt', 'vbox-extpack',
|
|
15625
|
-
'apk', 'pkg', 'mpkg', 'deb', 'udeb', 'rpm', 'run',
|
|
15626
|
-
'asx', 'wax', 'wvx', 'wmx', 'wmd',
|
|
15627
|
-
'mau', 'mcf', 'tmp'
|
|
15628
|
-
]);
|
|
15629
|
-
|
|
15630
|
-
/**
|
|
15631
|
-
* Why a name or a head slice is refused, as the two refusal functions report
|
|
15632
|
-
* it. REFUSED_EXTENSION: the extension the name's saved copy opens as is none
|
|
15633
|
-
* a ticket accepts, or the name shows none.
|
|
15634
|
-
*/
|
|
15635
|
-
const ATTACHMENT_REFUSALS = Object.freeze({
|
|
15636
|
-
EMPTY: 'empty',
|
|
15637
|
-
TOO_LONG: 'too_long',
|
|
15638
|
-
UNSAFE_NAME: 'unsafe_name',
|
|
15639
|
-
REFUSED_EXTENSION: 'refused_extension',
|
|
15640
|
-
EXECUTABLE: 'executable',
|
|
15641
|
-
SCRIPT: 'script',
|
|
15642
|
-
MARKUP: 'markup'
|
|
15643
|
-
});
|
|
15644
|
-
|
|
15645
|
-
/** How many leading bytes the sniff reads; a caller slices `file.slice(0, ATTACHMENT_SNIFF_BYTES)`. */
|
|
15646
|
-
const ATTACHMENT_SNIFF_BYTES = 4096;
|
|
15647
|
-
|
|
15648
|
-
new Set(REFUSED_EXTENSIONS);
|
|
15649
|
-
|
|
15650
|
-
/** Leading byte sequences of code a desktop would run. */
|
|
15651
|
-
const EXECUTABLE_SIGNATURES = Object.freeze([
|
|
15652
|
-
[0x4d, 0x5a], // MZ: Windows PE
|
|
15653
|
-
[0x7f, 0x45, 0x4c, 0x46], // ELF
|
|
15654
|
-
[0xfe, 0xed, 0xfa, 0xce], // Mach-O 32-bit
|
|
15655
|
-
[0xfe, 0xed, 0xfa, 0xcf], // Mach-O 64-bit
|
|
15656
|
-
[0xce, 0xfa, 0xed, 0xfe], // Mach-O 32-bit, reversed
|
|
15657
|
-
[0xcf, 0xfa, 0xed, 0xfe], // Mach-O 64-bit, reversed
|
|
15658
|
-
[0xca, 0xfe, 0xba, 0xbe], // Mach-O universal / Java class
|
|
15659
|
-
[0xbe, 0xba, 0xfe, 0xca] // Mach-O universal, reversed
|
|
15660
|
-
]);
|
|
15661
|
-
|
|
15662
|
-
const SHEBANG = Object.freeze([0x23, 0x21]);
|
|
15663
|
-
|
|
15664
|
-
/**
|
|
15665
|
-
* A ZIP local file header's signature (`PK\x03\x04`): the first bytes of
|
|
15666
|
-
* every Office Open XML package (.docx, .xlsx, .pptx), the only ZIP a ticket
|
|
15667
|
-
* takes. Its parts are XML by definition, and a package whose ZIP stores them
|
|
15668
|
-
* uncompressed, as common web exporters write one, shows its first part's
|
|
15669
|
-
* `<?xml` declaration in the first kilobyte; no browser reads a file that
|
|
15670
|
-
* opens with this signature as a page.
|
|
15671
|
-
*/
|
|
15672
|
-
const ZIP_LOCAL_FILE_SIGNATURE = Object.freeze([0x50, 0x4b, 0x03, 0x04]);
|
|
15673
|
-
|
|
15674
|
-
/** Document openers a browser would run as a page; matched case-insensitively in the first kilobyte. */
|
|
15675
|
-
const MARKUP_OPENERS = Object.freeze(['<?xml', '<!doctype html', '<html', '<script', '<svg']);
|
|
15676
|
-
const MARKUP_WINDOW = 1024;
|
|
15677
|
-
|
|
15678
|
-
function startsWith(bytes, prefix) {
|
|
15679
|
-
return bytes.length >= prefix.length && prefix.every((byte, index) => bytes[index] === byte);
|
|
15680
|
-
}
|
|
15681
|
-
|
|
15682
|
-
/**
|
|
15683
|
-
* What stops `name` from naming a ticket attachment, or null when nothing does.
|
|
15684
|
-
* Its extension is the one a saved copy opens as (lastExtension), and a ticket
|
|
15685
|
-
* takes it only when that is one it accepts (ACCEPTED_ATTACHMENT_EXTENSIONS),
|
|
15686
|
-
* so a name of no extension is refused, and neither a SparkVault document's
|
|
15687
|
-
* two-part extension ("invoice.note.html"), trailing dots or spaces
|
|
15688
|
-
* ("page.html."), an invisible character ("evil.ex<U+034F>e") nor a space
|
|
15689
|
-
* Firefox closes up ("evil.ex e", which Firefox saves as "evil.exe") passes
|
|
15690
|
-
* for an accepted one; a name that opens as one is taken however it is
|
|
15691
|
-
* written ("Photo.JPG", "report.pdf.", "Scan. pdf").
|
|
15692
|
-
*
|
|
15693
|
-
* @param {unknown} name
|
|
15694
|
-
* @returns {string|null} One of ATTACHMENT_REFUSALS, or null
|
|
15695
|
-
*/
|
|
15696
|
-
function attachmentNameRefusal(name) {
|
|
15697
|
-
if (typeof name !== 'string' || name.length === 0) return ATTACHMENT_REFUSALS.EMPTY;
|
|
15698
|
-
if (name.length > INGOT_NAME_MAX) return ATTACHMENT_REFUSALS.TOO_LONG;
|
|
15699
|
-
if (storableFilenameProblem(name) !== null) return ATTACHMENT_REFUSALS.UNSAFE_NAME;
|
|
15700
|
-
if (!ACCEPTED_EXTENSION_SET.has(lastExtension(name))) return ATTACHMENT_REFUSALS.REFUSED_EXTENSION;
|
|
15701
|
-
return null;
|
|
15702
|
-
}
|
|
15703
|
-
|
|
15704
|
-
/**
|
|
15705
|
-
* What the first bytes of a file say it is that no ticket may carry, or null
|
|
15706
|
-
* when they say nothing of the kind: a program, a script, or markup a browser
|
|
15707
|
-
* would run as a page, which a ZIP package's head is never read for
|
|
15708
|
-
* (ZIP_LOCAL_FILE_SIGNATURE). Reads at most ATTACHMENT_SNIFF_BYTES.
|
|
15709
|
-
*
|
|
15710
|
-
* @param {Uint8Array} headBytes
|
|
15711
|
-
* @returns {string|null} One of ATTACHMENT_REFUSALS, or null
|
|
15712
|
-
*/
|
|
15713
|
-
function attachmentSniffRefusal(headBytes) {
|
|
15714
|
-
const bytes = headBytes.subarray(0, ATTACHMENT_SNIFF_BYTES);
|
|
15715
|
-
if (EXECUTABLE_SIGNATURES.some((signature) => startsWith(bytes, signature))) return ATTACHMENT_REFUSALS.EXECUTABLE;
|
|
15716
|
-
if (startsWith(bytes, SHEBANG)) return ATTACHMENT_REFUSALS.SCRIPT;
|
|
15717
|
-
if (startsWith(bytes, ZIP_LOCAL_FILE_SIGNATURE)) return null;
|
|
15718
|
-
// Latin-1 decoding keeps one byte per character, so a UTF-8 or Latin-1
|
|
15719
|
-
// document's ASCII markup reads the same; a BOM or leading whitespace is
|
|
15720
|
-
// skipped by searching the window instead of anchoring at offset 0.
|
|
15721
|
-
const text = String.fromCharCode(...bytes.subarray(0, MARKUP_WINDOW)).toLowerCase();
|
|
15722
|
-
if (MARKUP_OPENERS.some((opener) => text.includes(opener))) return ATTACHMENT_REFUSALS.MARKUP;
|
|
15723
|
-
return null;
|
|
15724
|
-
}
|
|
15725
|
-
|
|
15726
|
-
/**
|
|
15727
|
-
* A byte count as people read it: "500 B", "1 KB", "1.5 MB", "5 GB", in
|
|
15728
|
-
* binary units (1 KB = 1024 B) up to TB, with at most `decimals` decimal
|
|
15729
|
-
* places and no trailing zeros. The one size formatter every surface writes
|
|
15730
|
-
* sizes with; a runtime that cannot import app-sdk runs a generated mirror of
|
|
15731
|
-
* it (module-mirrors).
|
|
15732
|
-
*
|
|
15733
|
-
* A count that is missing, not a finite number, zero or negative reads
|
|
15734
|
-
* "0 B"; a count past the largest unit is written in TB.
|
|
15735
|
-
*
|
|
15736
|
-
* BROWSER-SAFE: data only, no imports.
|
|
15737
|
-
*/
|
|
15738
|
-
|
|
15739
|
-
const UNITS = Object.freeze(['B', 'KB', 'MB', 'GB', 'TB']);
|
|
15740
|
-
const STEP = 1024;
|
|
15741
|
-
|
|
15742
|
-
/**
|
|
15743
|
-
* @param {number|null|undefined} bytes
|
|
15744
|
-
* @param {number} [decimals=1] - The most decimal places shown
|
|
15745
|
-
* @returns {string}
|
|
15746
|
-
*/
|
|
15747
|
-
function formatBytes(bytes, decimals = 1) {
|
|
15748
|
-
if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes <= 0) return `0 ${UNITS[0]}`;
|
|
15749
|
-
const unit = Math.min(Math.max(Math.floor(Math.log(bytes) / Math.log(STEP)), 0), UNITS.length - 1);
|
|
15750
|
-
return `${parseFloat((bytes / STEP ** unit).toFixed(decimals))} ${UNITS[unit]}`;
|
|
15751
|
-
}
|
|
15752
|
-
|
|
15753
|
-
/**
|
|
15754
|
-
* What stops a file from joining a message, decided in the browser before any
|
|
15755
|
-
* upload starts: the one check the portal's editor and the console's
|
|
15756
|
-
* composer run. The server never reads an uploaded file's plaintext, so the
|
|
15757
|
-
* check on a file's first bytes can only run here, over the file itself; the
|
|
15758
|
-
* name rule runs here and again on the server when the upload is initiated.
|
|
15759
|
-
* Both are the platform's one attachment policy (./attachment-policy.js);
|
|
15760
|
-
* this adds only what no upload can take: an empty file, one past the most
|
|
15761
|
-
* its uploader may attach (a customer ./help-desk-contract.js
|
|
15762
|
-
* CUSTOMER_ATTACHMENT_MAX_BYTES, an operator MAX_ATTACHMENT_BYTES), and one
|
|
15763
|
-
* the browser can no longer read (changed or moved on disk after it was
|
|
15764
|
-
* picked). Beside the check, the sentence each refusal reads, and the one
|
|
15765
|
-
* phrase that names the files a ticket accepts.
|
|
15766
|
-
*
|
|
15767
|
-
* BROWSER-SAFE: reads the file it is handed through the Blob API, which
|
|
15768
|
-
* Node's File has too.
|
|
15769
|
-
*/
|
|
15770
|
-
|
|
15771
|
-
|
|
15772
|
-
/** The files refused beyond the policy's. */
|
|
15773
|
-
const FILE_REFUSALS = Object.freeze({ EMPTY_FILE: 'empty_file', TOO_LARGE: 'too_large', UNREADABLE: 'unreadable' });
|
|
15774
|
-
|
|
15775
|
-
/** The first bytes of `file`, or null when the browser cannot read them. */
|
|
15776
|
-
async function headOf(file) {
|
|
15777
|
-
try {
|
|
15778
|
-
return new Uint8Array(await file.slice(0, ATTACHMENT_SNIFF_BYTES).arrayBuffer());
|
|
15779
|
-
} catch {
|
|
15780
|
-
return null;
|
|
15781
|
-
}
|
|
15782
|
-
}
|
|
15783
|
-
|
|
15784
|
-
/** A ceiling a file is held to: a positive whole number of bytes, or a TypeError. */
|
|
15785
|
-
function assertCeiling(maxBytes) {
|
|
15786
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) throw new TypeError('A file is held to a ceiling of a positive whole number of bytes');
|
|
15787
|
-
}
|
|
15788
|
-
|
|
15789
|
-
/**
|
|
15790
|
-
* Why `file` cannot be attached, or null when it may be: its name first, then
|
|
15791
|
-
* its size against `maxBytes`, then its first bytes.
|
|
15792
|
-
*
|
|
15793
|
-
* @param {File} file
|
|
15794
|
-
* @param {number} maxBytes - The most its uploader may attach: a customer
|
|
15795
|
-
* CUSTOMER_ATTACHMENT_MAX_BYTES, an operator MAX_ATTACHMENT_BYTES
|
|
15796
|
-
* @returns {Promise<string|null>} One of ATTACHMENT_REFUSALS or FILE_REFUSALS, or null
|
|
15797
|
-
* @throws {TypeError} For a ceiling that is not a positive whole number of bytes
|
|
15798
|
-
*/
|
|
15799
|
-
async function attachmentRefusal(file, maxBytes) {
|
|
15800
|
-
assertCeiling(maxBytes);
|
|
15801
|
-
const byName = attachmentNameRefusal(file.name);
|
|
15802
|
-
if (byName) return byName;
|
|
15803
|
-
if (file.size === 0) return FILE_REFUSALS.EMPTY_FILE;
|
|
15804
|
-
if (file.size > maxBytes) return FILE_REFUSALS.TOO_LARGE;
|
|
15805
|
-
const head = await headOf(file);
|
|
15806
|
-
return head ? attachmentSniffRefusal(head) : FILE_REFUSALS.UNREADABLE;
|
|
15807
|
-
}
|
|
15808
|
-
|
|
15809
|
-
/**
|
|
15810
|
-
* The words naming every kind of file a ticket accepts with its extensions,
|
|
15811
|
-
* the last kind joined by "and": `images (.jpg, .jpeg, ...), documents
|
|
15812
|
-
* (.pdf, ...) and recordings (.mp4, ...)`.
|
|
15813
|
-
*
|
|
15814
|
-
* @param {Readonly<Record<string, readonly string[]>>} kinds - ACCEPTED_ATTACHMENT_KINDS
|
|
15815
|
-
* @returns {string}
|
|
15816
|
-
*/
|
|
15817
|
-
function acceptedKindsCopy(kinds) {
|
|
15818
|
-
const named = Object.entries(kinds).map(([kind, extensions]) => {
|
|
15819
|
-
const listed = extensions.map((extension) => `.${extension}`).join(', ');
|
|
15820
|
-
return `${kind} (${listed})`;
|
|
15821
|
-
});
|
|
15822
|
-
return `${named.slice(0, -1).join(', ')} and ${named.at(-1)}`;
|
|
15823
|
-
}
|
|
15824
|
-
|
|
15825
|
-
/**
|
|
15826
|
-
* The files a ticket accepts, in the one phrase every surface names them by,
|
|
15827
|
-
* built from the policy's own list (ACCEPTED_ATTACHMENT_KINDS): the sentence
|
|
15828
|
-
* refusing any other file reads it, and so do the API reference
|
|
15829
|
-
* (apps/api/openapi/overlay.mjs) and the help desk's page on the site
|
|
15830
|
-
* (apps/www/_data/helpDeskAttachments.js).
|
|
15831
|
-
*/
|
|
15832
|
-
const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
15833
|
-
|
|
15834
|
-
const REFUSAL_COPY = Object.freeze({
|
|
15835
|
-
[ATTACHMENT_REFUSALS.EMPTY]: 'This file has no name.',
|
|
15836
|
-
[ATTACHMENT_REFUSALS.TOO_LONG]: "This file's name is too long. Rename it and try again.",
|
|
15837
|
-
[ATTACHMENT_REFUSALS.UNSAFE_NAME]: "This file's name can't be used. Rename it and try again.",
|
|
15838
|
-
[ATTACHMENT_REFUSALS.REFUSED_EXTENSION]: `Files of this type can't be attached. You can attach ${ACCEPTED_ATTACHMENTS_COPY}.`,
|
|
15839
|
-
[ATTACHMENT_REFUSALS.EXECUTABLE]: "This file is a program, and programs can't be attached.",
|
|
15840
|
-
[ATTACHMENT_REFUSALS.SCRIPT]: "This file is a script, and scripts can't be attached.",
|
|
15841
|
-
[ATTACHMENT_REFUSALS.MARKUP]: "This file holds web page markup, which can't be attached.",
|
|
15842
|
-
[FILE_REFUSALS.EMPTY_FILE]: 'This file is empty.',
|
|
15843
|
-
[FILE_REFUSALS.UNREADABLE]: "This file couldn't be read. Remove it and pick it again."
|
|
15844
|
-
});
|
|
15845
|
-
|
|
15846
|
-
/**
|
|
15847
|
-
* The sentence a person reads for a file larger than `maxBytes`, the ceiling
|
|
15848
|
-
* it was held to: the browser's check's (FILE_REFUSALS.TOO_LARGE), and the
|
|
15849
|
-
* server's, which names its own (`details.max_bytes` of a 413).
|
|
15850
|
-
*
|
|
15851
|
-
* @param {number} maxBytes
|
|
15852
|
-
* @returns {string}
|
|
15853
|
-
*/
|
|
15854
|
-
function tooLargeCopy(maxBytes) {
|
|
15855
|
-
assertCeiling(maxBytes);
|
|
15856
|
-
return `This file is larger than ${formatBytes(maxBytes)}.`;
|
|
15857
|
-
}
|
|
15858
|
-
|
|
15859
|
-
/**
|
|
15860
|
-
* The sentence a person reads for a refusal.
|
|
15861
|
-
*
|
|
15862
|
-
* @param {string} refusal - One of ATTACHMENT_REFUSALS or FILE_REFUSALS
|
|
15863
|
-
* @param {number} maxBytes - The ceiling attachmentRefusal held the file to
|
|
15864
|
-
* @returns {string}
|
|
15865
|
-
* @throws {TypeError} For a ceiling that is not a positive whole number of bytes
|
|
15866
|
-
*/
|
|
15867
|
-
function refusalCopy(refusal, maxBytes) {
|
|
15868
|
-
assertCeiling(maxBytes);
|
|
15869
|
-
if (refusal === FILE_REFUSALS.TOO_LARGE) return tooLargeCopy(maxBytes);
|
|
15870
|
-
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
15871
|
-
}
|
|
15872
|
-
|
|
15873
|
-
/**
|
|
15874
|
-
* The products that send an organization's mail from a platform mail domain,
|
|
15875
|
-
* and the labels under those domains the platform keeps for itself.
|
|
15876
|
-
*
|
|
15877
|
-
* Each product sends an organization's mail from `{handle}.{domain}`, the
|
|
15878
|
-
* organization's own host under the product's mail domain, or from a domain
|
|
15879
|
-
* the organization verified once it is ready for what the product uses it
|
|
15880
|
-
* for. Core and the console read these facts here, so no surface names a
|
|
15881
|
-
* product's domain, capabilities or From address its own way.
|
|
15882
|
-
*
|
|
15883
|
-
* BROWSER-SAFE: imports only ./platform-domains.js, which imports nothing.
|
|
15884
|
-
*/
|
|
15885
|
-
|
|
15886
|
-
|
|
15887
|
-
/**
|
|
15888
|
-
* Each product that sends an organization's mail from a platform mail domain:
|
|
15889
|
-
* its key (also its tiered-product key and the suffix of its SES tenant's
|
|
15890
|
-
* name), the domain (one SES identity, whose {handle}.{domain} subdomain is
|
|
15891
|
-
* each organization's address), what it uses an organization's own domain
|
|
15892
|
-
* for, what a domain needs ready before the product may select it, and the
|
|
15893
|
-
* fixed local part it writes from (null when it varies: a help desk team
|
|
15894
|
-
* writes from its alias). Every descriptor and array frozen.
|
|
15895
|
-
*/
|
|
15896
|
-
const MAIL_PRODUCTS = Object.freeze({
|
|
15897
|
-
help_desk: Object.freeze({
|
|
15898
|
-
key: 'help_desk',
|
|
15899
|
-
domain: SPARKVAULT_HELP_DESK_DOMAIN,
|
|
15900
|
-
capabilities: Object.freeze(['web', 'sending', 'receiving']),
|
|
15901
|
-
selectable: Object.freeze(['sending', 'web']),
|
|
15902
|
-
fromLocalPart: null
|
|
15903
|
-
}),
|
|
15904
|
-
notify: Object.freeze({
|
|
15905
|
-
key: 'notify',
|
|
15906
|
-
domain: SPARKVAULT_NOTIFY_SEND_DOMAIN,
|
|
15907
|
-
capabilities: Object.freeze(['sending']),
|
|
15908
|
-
selectable: Object.freeze(['sending']),
|
|
15909
|
-
fromLocalPart: 'notify'
|
|
15910
|
-
})
|
|
15911
|
-
});
|
|
15912
|
-
|
|
15913
|
-
/** Every mail product's key, in MAIL_PRODUCTS order: the order every product-by-product decision runs in. */
|
|
15914
|
-
const MAIL_PRODUCT_KEYS = Object.freeze(Object.keys(MAIL_PRODUCTS));
|
|
15915
|
-
|
|
15916
|
-
/**
|
|
15917
|
-
* GENERATED by infra/scripts/generate-organization-name-unicode.mjs from
|
|
15918
|
-
* Unicode 18.0.0 (confusables.txt, UnicodeData.txt, DerivedBidiClass.txt,
|
|
15919
|
-
* BidiBrackets.txt, DerivedAge.txt, DerivedNormalizationProps.txt). Do not
|
|
15920
|
-
* edit: rerun the generator.
|
|
15921
|
-
*
|
|
15922
|
-
* The Unicode data @sparkvault/app-sdk/organization-name reads a text with.
|
|
15923
|
-
* Code points are hexadecimal, separated by spaces; `first-last` is a range.
|
|
15924
|
-
* The rule reads a text in NFC, so neither list names a character NFC
|
|
15925
|
-
* replaces on every engine the rule runs on (Unicode 15.1 or older).
|
|
15926
|
-
*
|
|
15927
|
-
* BROWSER-SAFE: data only, no imports.
|
|
15928
|
-
*/
|
|
15929
|
-
|
|
15930
|
-
|
|
15931
|
-
/**
|
|
15932
|
-
* The Latin letters a character reads as, keyed by its reading: one group of
|
|
15933
|
-
* letters per position, positions joined by '.' ('uv' is one letter, u or v;
|
|
15934
|
-
* 'p.a' is two). A character NFKD already reads correctly on every engine the
|
|
15935
|
-
* rule runs on is left out, as are the ASCII letters, which read as
|
|
15936
|
-
* themselves.
|
|
15488
|
+
* The Latin letters a character reads as, keyed by its reading: one group of
|
|
15489
|
+
* letters per position, positions joined by '.' ('uv' is one letter, u or v;
|
|
15490
|
+
* 'p.a' is two). A character NFKD already reads correctly on every engine the
|
|
15491
|
+
* rule runs on is left out, as are the ASCII letters, which read as
|
|
15492
|
+
* themselves.
|
|
15937
15493
|
*/
|
|
15938
15494
|
const LETTER_READINGS = {
|
|
15939
15495
|
'a':
|
|
@@ -16246,450 +15802,1131 @@ const LETTER_READINGS = {
|
|
|
16246
15802
|
};
|
|
16247
15803
|
|
|
16248
15804
|
/**
|
|
16249
|
-
* The characters that read as letters but that a reader may also pass over: a
|
|
16250
|
-
* mark, drawn on the character before it; a superscript or subscript form,
|
|
16251
|
-
* drawn small beside a word's letters; a character whose letters are a
|
|
16252
|
-
* resemblance only (confusable with a character that is no ASCII letter, or
|
|
16253
|
-
* with ASCII letters beside another character), and every hand-listed
|
|
16254
|
-
* lookalike and character confusable with one, which a reader may take for
|
|
16255
|
-
* the shape it is drawn as; a digit, punctuation mark or symbol that passes
|
|
16256
|
-
* for a letter, or a letter UTS #39 makes confusable with one, which a reader
|
|
16257
|
-
* may take for what it is drawn as; a bare vertical stroke (the vertical
|
|
16258
|
-
* line, l, I, 1 and every character confusable with them), which a reader
|
|
16259
|
-
* takes for a separator as readily as for a letter; and a character whose
|
|
16260
|
-
* canonical decomposition a reader may pass over part by part (U+00CC, an I
|
|
16261
|
-
* and a grave accent; a Hangul syllable of a bare stroke and jamo that read
|
|
16262
|
-
* as no letter). Each is listed whether its reading is in LETTER_READINGS,
|
|
16263
|
-
* comes from NFKD or is its own ASCII letter; a character that reads as no
|
|
16264
|
-
* letter is passed over anyway.
|
|
15805
|
+
* The characters that read as letters but that a reader may also pass over: a
|
|
15806
|
+
* mark, drawn on the character before it; a superscript or subscript form,
|
|
15807
|
+
* drawn small beside a word's letters; a character whose letters are a
|
|
15808
|
+
* resemblance only (confusable with a character that is no ASCII letter, or
|
|
15809
|
+
* with ASCII letters beside another character), and every hand-listed
|
|
15810
|
+
* lookalike and character confusable with one, which a reader may take for
|
|
15811
|
+
* the shape it is drawn as; a digit, punctuation mark or symbol that passes
|
|
15812
|
+
* for a letter, or a letter UTS #39 makes confusable with one, which a reader
|
|
15813
|
+
* may take for what it is drawn as; a bare vertical stroke (the vertical
|
|
15814
|
+
* line, l, I, 1 and every character confusable with them), which a reader
|
|
15815
|
+
* takes for a separator as readily as for a letter; and a character whose
|
|
15816
|
+
* canonical decomposition a reader may pass over part by part (U+00CC, an I
|
|
15817
|
+
* and a grave accent; a Hangul syllable of a bare stroke and jamo that read
|
|
15818
|
+
* as no letter). Each is listed whether its reading is in LETTER_READINGS,
|
|
15819
|
+
* comes from NFKD or is its own ASCII letter; a character that reads as no
|
|
15820
|
+
* letter is passed over anyway.
|
|
15821
|
+
*/
|
|
15822
|
+
const OPTIONAL_LETTERS =
|
|
15823
|
+
'21 24 25 2b 30 31 34 35 37 40 49 6c 7c a1-a3 a5 aa ae b5 b9 ba bc-be cc-cf d7 128 12a 12c 12e ' +
|
|
15824
|
+
'130 138 13a 13c 13e 140 142 190 196 197 19a 1bc 1c0 1c1 1c3 1cf 208 20a 245 25b 26b 26d 26e ' +
|
|
15825
|
+
'276 279-27b 28a 2a4 2a7 2a8 2b0-2b5 2b7 2b8 2e0-2e3 363-36f 376 377 37b 37d 38a 393 399 39b ' +
|
|
15826
|
+
'3aa 3ad 3b2 3b5 3ba 3bc 3c0 3c4 3d0 3d6 3f0 3f5 3fd 403 404 406 407 40d 413 414 418 419 41b ' +
|
|
15827
|
+
'426 42f 432 434 438-43a 43d 43f 442 446 44a 44b 44f 454 45c 45d 48a 48b 490 492 494 49b 49f ' +
|
|
15828
|
+
'4a3 4a7 4ad 4c0 4c5 4c8 4ca 4cf 4e2-4e5 4f6 4f9 4fa 4fe 50d 510-513 520 521 525 52e 52f 547 ' +
|
|
15829
|
+
'548 554 577 57a 586 58c 5c0 5d5 5df 5e7 5e9 5f0 5f1 609 60a 622 623 625 627 661 665 667 668 ' +
|
|
15830
|
+
'66a 672 673 675 6f1 6f5 6f7 6f8 7c0 7ca 964-966 9e6 a66 ae6 b66 be6 c02 c66 c82 ce6 d02 d5f ' +
|
|
15831
|
+
'd66 d82 e04 e14 e15 e20 e22 e23 e26 e40 e41 e50 e8d ed0 1040 104a 104b 10a0 111b 111d 112b ' +
|
|
15832
|
+
'112c 1135 1141-1146 1148-114b 114d 1157 1162 1164 1166 1168 116b 116c 1170 1171 1174 1175 1180 ' +
|
|
15833
|
+
'1181 1185 1188 118a 118c 1190 1192 1194 1197-119d 11a1 11a7 11d5 11e2 11e6 11ec 11ed 11ef 11f1 ' +
|
|
15834
|
+
'11f2 11f4 1223 1260 13b1 13cb 13ce 13f0 13f8 13fb 13fc 1429 1431 143a-143d 144e 1457-145a 1467 ' +
|
|
15835
|
+
'1468 1476 1477 147a 147b 147e-1481 1486-1488 1498 1499 14a5 14ae 14af 14b6 14b7 14f0 14fa 14fb ' +
|
|
15836
|
+
'150e 1511 1515 1519 151a 1521 1522 152f 1530 1540 1575 157f 1581 1583 1584 1586 1591 1598 15b6 ' +
|
|
15837
|
+
'15e9 1609 166d 166e 1673 16c1 16c5 16d0 16ed 172a 17e0 18e8 1a80 1a90 1abf 1acc-1ace 1bea 1bec ' +
|
|
15838
|
+
'1c84 1d0b 1d0e 1d14 1d19 1d28 1d29 1d2c-1d2e 1d30 1d31 1d33-1d3a 1d3c 1d3e-1d43 1d45 1d47-1d49 ' +
|
|
15839
|
+
'1d4b 1d4d 1d4f-1d53 1d56-1d58 1d5a 1d5b 1d5d 1d5e 1d62-1d68 1d78 1d7a 1d7f 1d9c 1d9d 1da0-1da2 ' +
|
|
15840
|
+
'1da4-1db1 1db3 1db5-1db9 1dbb-1dbd 1dbf 1dca 1dd3-1dd8 1dda-1de9 1deb-1dee 1df0-1df4 1e2c 1e2e ' +
|
|
15841
|
+
'1e37 1e39 1e3b 1e3d 1ec8 1eca 1f10-1f15 1f38-1f3f 1f72 1fd8-1fda 2016 2020 2030 2031 203c 2048 ' +
|
|
15842
|
+
'2049 2052 2070 2071 2074 2075 2077 207a 207f-2081 2084 2085 2087 208a 2090-2093 2095-209f 20a1 ' +
|
|
15843
|
+
'20a4-20a6 20a8 20a9 20ab-20ae 20b1 20b3 20b4 20b6 20b8-20ba 20bd 20c1 2100 2101 2103 2105-2107 ' +
|
|
15844
|
+
'2109 2110 2111 2113 2116 2117 2120-2122 212e 213b 213c 213e 2150-2153 2155-215b 215d-217f 2183 ' +
|
|
15845
|
+
'2184 2189 218a 21bf 2205 2214 221a 221e 2223-2226 2228-222a 2296 229d 22a4 22c1-22c3 22f4 22ff ' +
|
|
15846
|
+
'2300 2361 2365 236c 2373 2374 2376-2378 237a 237f 239c 239f 23a2 23a5 23aa 23ae 23e8 23fd 2460 ' +
|
|
15847
|
+
'2463 2464 2466 2469-2474 2477 2478 247a 247d-2488 248b 248c 248e 2491-24ea 2502 2503 2573 2795 ' +
|
|
15848
|
+
'27d9 292b 292c 2963 296e 29b1-29b4 29e2 2a22-2a28 2a2f-2a31 2a40-2a45 2a52 2a5b 2a5d 2a62 2a63 ' +
|
|
15849
|
+
'2aee-2af1 2c6d 2c79 2c7c 2c7d 2c83 2c84 2c88 2c89 2c8f 2c92 2c95 2c9b 2ca1 2ca7 2cc0 2cd1 2ce8 ' +
|
|
15850
|
+
'2d00 2d37 2d4a 2d4f 2d51 2de1-2de3 2de6 2de8-2df0 2df2 2df4 2df6 2df7 2dfa 2dfb 2e36 2e37 2e85 ' +
|
|
15851
|
+
'2f01 2f0f 2f11 2f19 2f1b 2f59 3007 3012 3036 3072-3074 30a2 30a4 30ba 30e0 30ec 310e 3125 3129 ' +
|
|
15852
|
+
'3150 3152 3154 3156 3159 315a 315e 315f 3162 3163 3171 3178 3179 3182-3184 3188 3189 318b 318c ' +
|
|
15853
|
+
'318e 31d1 3207 3215 321d 321e 3250 3251 3254 3255 3257 325a 325b 325e 325f 3267 3275 327d 327e ' +
|
|
15854
|
+
'32b2 32b5-32c0 32c3 32c4 32c6 32c9-32d1 32f0 32f9 3300-3305 330a 330b 3315 3318-331a 331f 3320 ' +
|
|
15855
|
+
'332a 332d 332e 333d 3343 3344 3350 3355 3356 3358 3359 335c 335d 335f 3362-336d 3370-337a ' +
|
|
15856
|
+
'3380-33e0 33e3 33e4 33e6 33e9-33f4 33f7 33f8 33fa 33fd-33ff 4e02 4e28 4ebb 51e0 5200 5342 5369 ' +
|
|
15857
|
+
'53b6 5c3a 723f a00e a017 a018 a024 a072 a0f4 a224 a235 a263 a2d6 a2ea a2eb a317 a31a a34f a3dd ' +
|
|
15858
|
+
'a407 a490 a492 a493 a4a4 a4a6 a4c4 a4c5 a4db a4e5 a4f2 a4f5 a516 a56f a613 a650 a651 a674-a679 ' +
|
|
15859
|
+
'a67b a68d a69c a69d a6a1 a6ce a728-a72b a73f a742 a75a a75c a75d a768 a769 a772 a774-a776 a781 ' +
|
|
15860
|
+
'a792 a793 a79d a7ae a7b5 a7da a7dc a7e2 a7f1-a7f4 a7f8 a7f9 a7fe a830 a8ce a8cf a96b a976 a977 ' +
|
|
15861
|
+
'aa5d ab41 ab42 ab5d-ab5f ab62 ab68 ab6c ab70-ab72 ab7a-ab7c ab8b ab90 ab9b ab9e aba2 abae abb2 ' +
|
|
15862
|
+
'abb6 ac1c-ac30 ac32-ac37 ac54-ac68 ac6a-ac6f ac8c-aca0 aca2-aca7 acc4-acd8 acda-acdf ad18-ad2c ' +
|
|
15863
|
+
'ad2e-ad48 ad4a-ad4f ada4-adb8 adba-add4 add6-addb ae14-ae28 ae2a-ae44 ae46-ae4b ae68-ae7c ' +
|
|
15864
|
+
'ae7e-ae83 aea0-aeb4 aeb6-aebb aed8-aeec aeee-aef3 af10-af24 af26-af2b af64-af78 af7a-af94 ' +
|
|
15865
|
+
'af96-af9b aff0-b004 b006-b020 b022-b027 b060-b074 b076-b090 b092-b097 b0b4-b0c8 b0ca-b0cf ' +
|
|
15866
|
+
'b0ec-b100 b102-b107 b124-b138 b13a-b13f b15c-b170 b172-b177 b1b0-b1c4 b1c6-b1e0 b1e2-b1e7 ' +
|
|
15867
|
+
'b23c-b250 b252-b26c b26e-b273 b2ac-b2c0 b2c2-b2dc b2de-b2e3 b300-b314 b316-b31b b338-b34c ' +
|
|
15868
|
+
'b34e-b353 b370-b384 b386-b38b b3a8-b3bc b3be-b3c3 b3fc-b410 b412-b42c b42e-b433 b488-b49c ' +
|
|
15869
|
+
'b49e-b4b8 b4ba-b4bf b4f8-b50c b50e-b528 b52a-b52f b54c-b560 b562-b567 b584-b598 b59a-b59f ' +
|
|
15870
|
+
'b5bc-b5d0 b5d2-b5d7 b5f4-b608 b60a-b60f b648-b65c b65e-b678 b67a-b67f b6d4-b6e8 b6ea-b704 ' +
|
|
15871
|
+
'b706-b70b b744-b758 b75a-b774 b776-b77b b798-b7ac b7ae-b7b3 b7d0-b7e4 b7e6-b7eb b808-b81c ' +
|
|
15872
|
+
'b81e-b823 b840-b854 b856-b85b b894-b8a8 b8aa-b8c4 b8c6-b8cb b920-b934 b936-b950 b952-b957 ' +
|
|
15873
|
+
'b990-b9a4 b9a6-b9c0 b9c2-b9c7 b9e4-b9f8 b9fa-b9ff ba1c-ba30 ba32-ba37 ba54-ba68 ba6a-ba6f ' +
|
|
15874
|
+
'ba8c-baa0 baa2-baa7 bae0-baf4 baf6-bb10 bb12-bb17 bb6c-bb80 bb82-bb9c bb9e-bba3 bbdc-bbf0 ' +
|
|
15875
|
+
'bbf2-bc0c bc0e-bc13 bc30-bc44 bc46-bc4b bc68-bc7c bc7e-bc83 bca0-bcb4 bcb6-bcbb bcd8-bcec ' +
|
|
15876
|
+
'bcee-bcf3 bd2c-bd40 bd42-bd5c bd5e-bd63 bdb8-bdcc bdce-bde8 bdea-bdef be28-be3c be3e-be58 ' +
|
|
15877
|
+
'be5a-be5f be7c-be90 be92-be97 beb4-bec8 beca-becf beec-bf00 bf02-bf07 bf24-bf38 bf3a-bf3f ' +
|
|
15878
|
+
'bf78-bf8c bf8e-bfa8 bfaa-bfaf c004-c018 c01a-c034 c036-c03b c074-c088 c08a-c0a4 c0a6-c0ab ' +
|
|
15879
|
+
'c0c8-c0dc c0de-c0e3 c100-c114 c116-c11b c138-c14c c14e-c153 c170-c184 c186-c18b c1c4-c1d8 ' +
|
|
15880
|
+
'c1da-c1f4 c1f6-c1fb c250-c264 c266-c280 c282-c287 c2c0-c2d4 c2d6-c2f0 c2f2-c2f7 c314-c328 ' +
|
|
15881
|
+
'c32a-c32f c34c-c360 c362-c367 c384-c398 c39a-c39f c3bc-c3d0 c3d2-c3d7 c410-c424 c426-c440 ' +
|
|
15882
|
+
'c442-c447 c49c-c4b0 c4b2-c4cc c4ce-c4d3 c50c-c520 c522-c53c c53e-c543 c7ac-c7c0 c7c2-c7c7 ' +
|
|
15883
|
+
'c7e4-c7f8 c7fa-c7ff c81c-c830 c832-c837 c854-c868 c86a-c86f c8a8-c8bc c8be-c8d8 c8da-c8df ' +
|
|
15884
|
+
'c934-c948 c94a-c964 c966-c96b c9a4-c9b8 c9ba-c9d4 c9d6-c9db c9f8-ca0c ca0e-ca13 ca30-ca44 ' +
|
|
15885
|
+
'ca46-ca4b ca68-ca7c ca7e-ca83 caa0-cab4 cab6-cabb caf4-cb08 cb0a-cb24 cb26-cb2b cb80-cb94 ' +
|
|
15886
|
+
'cb96-cbb0 cbb2-cbb7 cbf0-cc04 cc06-cc20 cc22-cc27 cc44-cc58 cc5a-cc5f cc7c-cc90 cc92-cc97 ' +
|
|
15887
|
+
'ccb4-ccc8 ccca-cccf ccec-cd00 cd02-cd07 cd40-cd54 cd56-cd70 cd72-cd77 cdcc-cde0 cde2-cdfc ' +
|
|
15888
|
+
'cdfe-ce03 ce3c-ce50 ce52-ce6c ce6e-ce73 ce90-cea4 cea6-ceab cec8-cedc cede-cee3 cf00-cf14 ' +
|
|
15889
|
+
'cf16-cf1b cf38-cf4c cf4e-cf53 cf8c-cfa0 cfa2-cfbc cfbe-cfc3 d018-d02c d02e-d048 d04a-d04f ' +
|
|
15890
|
+
'd088-d09c d09e-d0b8 d0ba-d0bf d0dc-d0f0 d0f2-d0f7 d114-d128 d12a-d12f d14c-d160 d162-d167 ' +
|
|
15891
|
+
'd184-d198 d19a-d19f d1d8-d1ec d1ee-d208 d20a-d20f d264-d278 d27a-d294 d296-d29b d2d4-d2e8 ' +
|
|
15892
|
+
'd2ea-d304 d306-d30b d328-d33c d33e-d343 d360-d374 d376-d37b d398-d3ac d3ae-d3b3 d3d0-d3e4 ' +
|
|
15893
|
+
'd3e6-d3eb d424-d438 d43a-d454 d456-d45b d4b0-d4c4 d4c6-d4e0 d4e2-d4e7 d520-d534 d536-d550 ' +
|
|
15894
|
+
'd552-d557 d574-d588 d58a-d58f d5ac-d5c0 d5c2-d5c7 d5e4-d5f8 d5fa-d5ff d61c-d630 d632-d637 ' +
|
|
15895
|
+
'd670-d684 d686-d6a0 d6a2-d6a7 d6fc-d710 d712-d72c d72e-d733 d76c-d780 d782-d79c d79e-d7a3 d7b1 ' +
|
|
15896
|
+
'd7b3 d7b6 d7b7 d7bb d7bd-d7c4 d7c6 d7dd d7eb d7f4 fb29 fbea fbeb fc37 fc80 fc88 fccd fd3c fd3d ' +
|
|
15897
|
+
'fdf3 fdfc fe15 fe31 fe57 fe62 fe69-fe6b fe81-fe84 fe87 fe88 fe8d fe8e fef5-fefc ff01 ff04 ff05 ' +
|
|
15898
|
+
'ff0b ff10 ff11 ff14 ff15 ff17 ff20 ff29 ff4c ff5c ff71 ff72 ff91 ff9a ffc3 ffc5 ffc7 ffcb ffce ' +
|
|
15899
|
+
'ffcf ffd5 ffd6 ffdb ffdc ffe0 ffe1 ffe5 ffe6 ffe8 1017e 10182 1018b 1018e 10196-10199 101a0 ' +
|
|
15900
|
+
'1028a 1028d 1029b 102f5 10309 10320 10322 10401 10423 10425 10429 1042a 10443 1044b 1044d ' +
|
|
15901
|
+
'104b0 104bc 104d2 104e4 104fa 1050d-10510 10783-10785 10787-1078d 10790 10792-10796 ' +
|
|
15902
|
+
'10798-1079f 107a2 107a3 107a5-107b0 107b2 107b6 107b7 107b9 107ba 107bd 10926 10c3e 10ca5 ' +
|
|
15903
|
+
'10cfa 10cfc 11047 11048 11055 110c0 110c1 11141 11142 111c5 111c6 11302 113d4 113d5 1144b ' +
|
|
15904
|
+
'1144c 114d0 115c5 11641 11642 118af 118bb 118c6 118ce 118cf 118db 118e0 118e3 118e5 118e6 ' +
|
|
15905
|
+
'118e9 118ec 118ef 118f2 11c41 11c42 11dda 11de0 11de1 16869 16ad1 16ae4 16d63 16d69 16d6a ' +
|
|
15906
|
+
'16e80 16e82 16e8a 16eaa 16ec1 16f07 16f28 16f2d 16f3d 1cc90 1ccd6-1ccf1 1ccf4 1ccf5 1ccf7 ' +
|
|
15907
|
+
'1ce15 1cefc 1d100 1d134 1d1fe 1d202 1d207 1d20b-1d20d 1d212 1d213 1d216 1d21a 1d221 1d22a ' +
|
|
15908
|
+
'1d245 1d262 1d373 1d377 1d408 1d425 1d43c 1d459 1d470 1d48d 1d4c1 1d4d8 1d4f5 1d529 1d540 ' +
|
|
15909
|
+
'1d55d 1d574 1d591 1d5a8 1d5c5 1d5dc 1d5f9 1d610 1d62d 1d644 1d661 1d678 1d695 1d6aa 1d6b0 ' +
|
|
15910
|
+
'1d6b2 1d6c3 1d6c6 1d6cb 1d6cd 1d6d1 1d6d5 1d6dc 1d6de 1d6e1 1d6e4 1d6ea 1d6ec 1d6fd 1d700 ' +
|
|
15911
|
+
'1d705 1d707 1d70b 1d70f 1d716 1d718 1d71b 1d71e 1d724 1d726 1d737 1d73a 1d73f 1d741 1d745 ' +
|
|
15912
|
+
'1d749 1d750 1d752 1d755 1d758 1d75e 1d760 1d771 1d774 1d779 1d77b 1d77f 1d783 1d78a 1d78c ' +
|
|
15913
|
+
'1d78f 1d792 1d798 1d79a 1d7ab 1d7ae 1d7b3 1d7b5 1d7b9 1d7bd 1d7c4 1d7c6 1d7c9 1d7ce 1d7cf ' +
|
|
15914
|
+
'1d7d2 1d7d3 1d7d5 1d7d8 1d7d9 1d7dc 1d7dd 1d7df 1d7e2 1d7e3 1d7e6 1d7e7 1d7e9 1d7ec 1d7ed ' +
|
|
15915
|
+
'1d7f0 1d7f1 1d7f3 1d7f6 1d7f7 1d7fa 1d7fb 1d7fd 1df05 1df08 1df0a 1df12 1df15 1df17 1df19 ' +
|
|
15916
|
+
'1df1c 1df1f-1df23 1df2b 1df2c 1df3b 1df44 1df50 1df57 1df5b 1df5c 1df62 1df63 1df67 ' +
|
|
15917
|
+
'1df6c-1df6e 1dfcd-1dfd7 1dfd9-1dfdd 1dfe0 1dfe1 1dfe4 1dfe5 1dfe8-1dfea 1dfef-1dff2 ' +
|
|
15918
|
+
'1dff5-1dfff 1e030 1e032-1e035 1e038 1e039 1e03c-1e041 1e043 1e044 1e046 1e047 1e049 ' +
|
|
15919
|
+
'1e04c-1e051 1e053-1e056 1e059 1e05a 1e05c-1e05f 1e061 1e062 1e064-1e06d 1e08f 1e140 1e141 ' +
|
|
15920
|
+
'1e145 1e2f0 1e6e9 1e8c7 1ec75 1ec83 1ec86 1ec87 1ec89 1ec9e 1ec9f 1eca2 1eca3 1ecb1 1ecb2 ' +
|
|
15921
|
+
'1ed01 1ed13 1ed31 1ed32 1ed36 1ed37 1ee00 1ee61 1ee62 1ee67-1ee6a 1ee6c-1ee72 1ee74-1ee77 ' +
|
|
15922
|
+
'1ee79-1ee7c 1ee7e 1ee80 1f100-1f102 1f105 1f106 1f108 1f10f-1f12e 1f130-1f16e 1f170-1f198 ' +
|
|
15923
|
+
'1f19a 1f1a5-1f1a7 1f1a9-1f1ac 1f1e6-1f1ff 1f700 1f707 1f708 1f714 1f74c 1f75c 1f768 1f76b ' +
|
|
15924
|
+
'1f76c 1fbf0 1fbf1 1fbf4 1fbf5 1fbf7';
|
|
15925
|
+
|
|
15926
|
+
/**
|
|
15927
|
+
* Each bidirectional class other than L, keyed by its UAX #9 short name: the
|
|
15928
|
+
* code points that hold it. Every other code point is L. The explicit
|
|
15929
|
+
* formatting characters are left out: the rule refuses them before it lays a
|
|
15930
|
+
* text out.
|
|
15931
|
+
*/
|
|
15932
|
+
const BIDI_CLASSES = {
|
|
15933
|
+
AL:
|
|
15934
|
+
'608 60b 60d 61b-64a 66d-66f 671-6d5 6e5-6e6 6ee-6ef 6fa-710 712-72f 74b-7a5 7b1-7bf 860-88f ' +
|
|
15935
|
+
'892-896 8a0-8c9 fb50-fbc2 fbd3-fd3d fd50-fd8f fd92-fdc7 fdf0-fdfc fe70-fefe 10d00-10d23 ' +
|
|
15936
|
+
'10d28-10d2f 10d3a-10d3f 10ec0-10eca 10ed9-10eef 10f30-10f45 10f51-10f6f 1ec70-1ecbf ' +
|
|
15937
|
+
'1ed00-1ed4f 1ee00-1eeef 1eef2-1eeff',
|
|
15938
|
+
AN:
|
|
15939
|
+
'600-605 660-669 66b-66c 6dd 890-891 8e2 10d30-10d39 10d40-10d49 10e60-10e7e',
|
|
15940
|
+
B:
|
|
15941
|
+
'a d 1c-1e 85 2029',
|
|
15942
|
+
BN:
|
|
15943
|
+
'0-8 e-1b 7f-84 86-9f ad 180e 200b-200d 2060-2065 206a-206f fdd0-fdef feff fff0-fff8 ' +
|
|
15944
|
+
'fffe-ffff 1bca0-1bca3 1d173-1d17a 1fffe-1ffff 2fffe-2ffff 3fffe-3ffff 4fffe-4ffff ' +
|
|
15945
|
+
'5fffe-5ffff 6fffe-6ffff 7fffe-7ffff 8fffe-8ffff 9fffe-9ffff afffe-affff bfffe-bffff ' +
|
|
15946
|
+
'cfffe-cffff dfffe-e00ff e01f0-e0fff efffe-effff ffffe-fffff 10fffe-10ffff',
|
|
15947
|
+
CS:
|
|
15948
|
+
'2c 2e-2f 3a a0 60c 202f 2044 fe50 fe52 fe55 ff0c ff0e-ff0f ff1a',
|
|
15949
|
+
EN:
|
|
15950
|
+
'30-39 b2-b3 b9 6f0-6f9 2070 2074-2079 2080-2089 2488-249b ff10-ff19 102e1-102fb 1ccf0-1ccf9 ' +
|
|
15951
|
+
'1d7ce-1d7ff 1f100-1f10a 1fbf0-1fbf9',
|
|
15952
|
+
ES:
|
|
15953
|
+
'2b 2d 207a-207b 208a-208b 2212 fb29 fe62-fe63 ff0b ff0d',
|
|
15954
|
+
ET:
|
|
15955
|
+
'23-25 a2-a5 b0-b1 58f 609-60a 66a 9f2-9f3 9fb af1 bf9 e3f 17db 2030-2034 20a0-20cf 212e 2213 ' +
|
|
15956
|
+
'a838-a839 fe5f fe69-fe6a ff03-ff05 ffe0-ffe1 ffe5-ffe6 11fdd-11fe0 1e2ff',
|
|
15957
|
+
NSM:
|
|
15958
|
+
'300-36f 483-489 591-5bd 5bf 5c1-5c2 5c4-5c5 5c7-5c9 610-61a 64b-65f 670 6d6-6dc 6df-6e4 ' +
|
|
15959
|
+
'6e7-6e8 6ea-6ed 711 730-74a 7a6-7b0 7eb-7f3 7fd 816-819 81b-823 825-827 829-82d 859-85b ' +
|
|
15960
|
+
'897-89f 8ca-8e1 8e3-902 93a 93c 941-948 94d 951-957 962-963 981 9bc 9c1-9c4 9cd 9e2-9e3 9fe ' +
|
|
15961
|
+
'a01-a02 a3c a41-a42 a47-a48 a4b-a4d a51 a70-a71 a75 a81-a82 abc ac1-ac5 ac7-ac8 acd ae2-ae3 ' +
|
|
15962
|
+
'afa-aff b01 b3c b3f b41-b44 b4d b53-b56 b62-b63 b82 bc0 bcd c00 c04 c3c c3e-c40 c46-c48 ' +
|
|
15963
|
+
'c4a-c4d c55-c56 c62-c63 c81 cbc ccc-ccd ce2-ce3 d00-d01 d3b-d3c d41-d44 d4d d62-d63 d81 dca ' +
|
|
15964
|
+
'dd2-dd4 dd6 e31 e34-e3a e47-e4e eb1 eb4-ebc ec8-ece f18-f19 f35 f37 f39 f71-f7e f80-f84 ' +
|
|
15965
|
+
'f86-f87 f8d-f97 f99-fbc fc6 102d-1030 1032-1037 1039-103a 103d-103e 1058-1059 105e-1060 ' +
|
|
15966
|
+
'1071-1074 1082 1085-1086 108d 109d 135d-135f 1712-1714 1732-1733 1752-1753 1772-1773 ' +
|
|
15967
|
+
'17b4-17b5 17b7-17bd 17c6 17c9-17d3 17dd 180b-180d 180f 1885-1886 18a9 1920-1922 1927-1928 ' +
|
|
15968
|
+
'1932 1939-193b 1a17-1a18 1a1b 1a56 1a58-1a5e 1a60 1a62 1a65-1a6c 1a73-1a7c 1a7f 1ab0-1af0 ' +
|
|
15969
|
+
'1b00-1b03 1b34 1b36-1b39 1b6b-1b73 1b80-1b81 1ba2-1ba5 1ba8-1ba9 1bab-1bad 1be6 1be8-1be9 ' +
|
|
15970
|
+
'1bed 1bef-1bf1 1c2c-1c33 1c36-1c37 1cd0-1cd2 1cd4-1ce0 1ce2-1ce8 1ced 1cf4 1cf8-1cf9 ' +
|
|
15971
|
+
'1dc0-1dff 20d0-20f0 2cef-2cf1 2d7f 2de0-2dff 302a-302d 3099-309a a66f-a672 a674-a67d ' +
|
|
15972
|
+
'a69e-a69f a6f0-a6f1 a802 a806 a80b a825-a826 a82c a8c4-a8c5 a8e0-a8f1 a8ff a926-a92d ' +
|
|
15973
|
+
'a947-a951 a980-a982 a9b3 a9b6-a9b9 a9bc-a9bd a9e5 aa29-aa2e aa31-aa32 aa35-aa36 aa43 aa4c ' +
|
|
15974
|
+
'aa7c aab0 aab2-aab4 aab7-aab8 aabe-aabf aac1 aaec-aaed aaf6 abe5 abe8 abed fb1e fe00-fe0f ' +
|
|
15975
|
+
'fe20-fe2f 101fd 102e0 10376-1037a 10a01-10a03 10a05-10a06 10a0c-10a0f 10a38-10a3a 10a3f ' +
|
|
15976
|
+
'10ae5-10ae6 10d24-10d27 10d69-10d6d 10eab-10eac 10ecb-10ecf 10ef0-10eff 10f46-10f50 ' +
|
|
15977
|
+
'10f82-10f85 11001 11038-11046 11070 11073-11074 1107f-11081 110b3-110b6 110b9-110ba 110c2 ' +
|
|
15978
|
+
'11100-11102 11127-1112b 1112d-11134 11173 11180-11181 111b6-111be 111c9-111cc 111cf ' +
|
|
15979
|
+
'1122f-11231 11234 11236-11237 1123e 11241 112df 112e3-112ea 11300-11301 1133b-1133c 11340 ' +
|
|
15980
|
+
'11366-1136c 11370-11374 113bb-113c0 113ce 113d0 113d2 113e1-113e2 11438-1143f 11442-11444 ' +
|
|
15981
|
+
'11446 1145e 114b3-114b8 114ba 114bf-114c0 114c2-114c3 115b2-115b5 115bc-115bd 115bf-115c0 ' +
|
|
15982
|
+
'115dc-115dd 11633-1163a 1163d 1163f-11640 116ab 116ad 116b0-116b5 116b7 1171d 1171f ' +
|
|
15983
|
+
'11722-11725 11727-1172b 1182f-11837 11839-1183a 1193b-1193c 1193e 11943 119d4-119d7 ' +
|
|
15984
|
+
'119da-119db 119e0 11a01-11a06 11a09-11a0a 11a33-11a38 11a3b-11a3e 11a47 11a51-11a56 ' +
|
|
15985
|
+
'11a59-11a5b 11a8a-11a96 11a98-11a99 11b60 11b62-11b64 11b66 11c30-11c36 11c38-11c3d ' +
|
|
15986
|
+
'11c92-11ca7 11caa-11cb0 11cb2-11cb3 11cb5-11cb6 11d31-11d36 11d3a 11d3c-11d3d 11d3f-11d45 ' +
|
|
15987
|
+
'11d47 11d90-11d91 11d95 11d97 11df0 11ef3-11ef4 11f00-11f01 11f36-11f3a 11f40 11f42 11f5a ' +
|
|
15988
|
+
'13440 13447-13455 1611e-16129 1612d-1612f 16af0-16af4 16b30-16b36 16f4f 16f8f-16f92 16fe4 ' +
|
|
15989
|
+
'1bc9d-1bc9e 1cf00-1cf2d 1cf30-1cf46 1d127-1d128 1d167-1d169 1d17b-1d182 1d185-1d18b ' +
|
|
15990
|
+
'1d1aa-1d1ad 1d242-1d244 1d25b-1d25c 1da00-1da36 1da3b-1da6c 1da75 1da84 1da9b-1da9f ' +
|
|
15991
|
+
'1daa1-1daaf 1e000-1e006 1e008-1e018 1e01b-1e021 1e023-1e024 1e026-1e02a 1e08f 1e130-1e136 ' +
|
|
15992
|
+
'1e2ae 1e2ec-1e2ef 1e4ec-1e4ef 1e5ee-1e5ef 1e6e3 1e6e6 1e6ee-1e6ef 1e6f5 1e8d0-1e8d6 ' +
|
|
15993
|
+
'1e944-1e94a e0100-e01ef',
|
|
15994
|
+
ON:
|
|
15995
|
+
'21-22 26-2a 3b-40 5b-60 7b-7e a1 a6-a9 ab-ac ae-af b4 b6-b8 bb-bf d7 f7 2b9-2ba 2c2-2cf ' +
|
|
15996
|
+
'2d2-2df 2e5-2ed 2ef-2ff 374-375 37e 384-385 387 3f6 58a 58d-58e 606-607 60e-60f 6de 6e9 ' +
|
|
15997
|
+
'7f6-7f9 bf3-bf8 bfa c78-c7e f3a-f3d 1390-1399 1400 169b-169c 17f0-17f9 1800-180a 1940 ' +
|
|
15998
|
+
'1944-1945 19de-19ff 1fbd 1fbf-1fc1 1fcd-1fcf 1fdd-1fdf 1fed-1fef 1ffd-1ffe 2010-2027 ' +
|
|
15999
|
+
'2035-2043 2045-205e 207c-207e 208c-208f 2100-2101 2103-2106 2108-2109 2114 2116-2118 ' +
|
|
16000
|
+
'211e-2123 2125 2127 2129 213a-213b 2140-2144 214a-214d 2150-215f 2189-218b 2190-2211 ' +
|
|
16001
|
+
'2214-2335 237b-2394 2396-2429 2440-244a 2460-2487 24ea-26ab 26ad-27ff 2900-2b73 2b76-2bff ' +
|
|
16002
|
+
'2ce5-2cea 2cf9-2cff 2e00-2e5d 2e60-2e63 2e80-2e99 2e9b-2ef3 2f00-2fd5 2ff0-2fff 3001-3004 ' +
|
|
16003
|
+
'3008-3020 3030 3036-3037 303d-303f 309b-309c 30a0 30fb 31c0-31e5 31ef 321d-321e 3250-325f ' +
|
|
16004
|
+
'327c-327e 32b1-32bf 32cc-32cf 3377-337a 33de-33df 33ff 4dc0-4dff a490-a4c6 a60d-a60f a673 ' +
|
|
16005
|
+
'a67e-a67f a700-a721 a788 a828-a82b a874-a877 ab6a-ab6b fbc3-fbd2 fd3e-fd4f fd90-fd91 ' +
|
|
16006
|
+
'fdc8-fdcf fdfd-fdff fe10-fe19 fe30-fe4f fe51 fe54 fe56-fe5e fe60-fe61 fe64-fe66 fe68 fe6b ' +
|
|
16007
|
+
'ff01-ff02 ff06-ff0a ff1b-ff20 ff3b-ff40 ff5b-ff65 ffe2-ffe4 ffe8-ffee fff9-fffd 10101 ' +
|
|
16008
|
+
'10140-1018c 10190-1019c 101a0 1091f 10b39-10b3f 10d6e 10ed0-10ed8 11052-11065 11660-1166c ' +
|
|
16009
|
+
'11fd5-11fdc 11fe1-11ff1 16fe2 1cc00-1ccd5 1ccfa-1ccfc 1cd00-1ceb3 1ceba-1ced0 1ced2-1ced4 ' +
|
|
16010
|
+
'1cedd-1cefd 1d1e9-1d1ea 1d200-1d241 1d245 1d300-1d356 1d6c1 1d6db 1d6fb 1d715 1d735 1d74f ' +
|
|
16011
|
+
'1d76f 1d789 1d7a9 1d7c3 1db00-1db1c 1eef0-1eef1 1f000-1f02b 1f030-1f093 1f0a0-1f0ae ' +
|
|
16012
|
+
'1f0b1-1f0bf 1f0c1-1f0cf 1f0d1-1f0f5 1f10b-1f10f 1f12f 1f16a-1f16f 1f1ad 1f260-1f265 ' +
|
|
16013
|
+
'1f300-1f6d9 1f6dc-1f6ec 1f6f0-1f6fc 1f700-1f7d9 1f7db 1f7e0-1f7eb 1f7f0-1f80b 1f810-1f847 ' +
|
|
16014
|
+
'1f850-1f859 1f860-1f887 1f890-1f8ad 1f8b0-1f8bb 1f8c0-1f8c1 1f8d0-1f8d8 1f900-1fa57 ' +
|
|
16015
|
+
'1fa60-1fa6d 1fa70-1fa7c 1fa80-1fac6 1fac8 1facc-1fadd 1fadf-1faeb 1faef-1fafa 1fb00-1fb92 ' +
|
|
16016
|
+
'1fb94-1fbef 1fbfa',
|
|
16017
|
+
R:
|
|
16018
|
+
'590 5be 5c0 5c3 5c6 5ca-5ff 7c0-7ea 7f4-7f5 7fa-7fc 7fe-815 81a 824 828 82e-858 85c-85f 200f ' +
|
|
16019
|
+
'fb1d fb1f-fb28 fb2a-fb4f 10800-1091e 10920-10a00 10a04 10a07-10a0b 10a10-10a37 10a3b-10a3e ' +
|
|
16020
|
+
'10a40-10ae4 10ae7-10b38 10b40-10cff 10d4a-10d68 10d6f-10e5f 10e7f-10eaa 10ead-10ebf ' +
|
|
16021
|
+
'10f00-10f2f 10f70-10f81 10f86-10fff 1e800-1e8cf 1e8d7-1e943 1e94b-1ec6f 1ecc0-1ecff ' +
|
|
16022
|
+
'1ed50-1edff 1ef00-1efff',
|
|
16023
|
+
S:
|
|
16024
|
+
'9 b 1f',
|
|
16025
|
+
WS:
|
|
16026
|
+
'c 20 1680 2000-200a 2028 205f 3000'
|
|
16027
|
+
};
|
|
16028
|
+
|
|
16029
|
+
/** UAX #9's paired brackets (rule N0), as `opening:closing`. */
|
|
16030
|
+
const BRACKET_PAIRS =
|
|
16031
|
+
'28:29 5b:5d 7b:7d f3a:f3b f3c:f3d 169b:169c 2045:2046 207d:207e 208d:208e 2308:2309 230a:230b ' +
|
|
16032
|
+
'2329:232a 2768:2769 276a:276b 276c:276d 276e:276f 2770:2771 2772:2773 2774:2775 27c5:27c6 ' +
|
|
16033
|
+
'27e6:27e7 27e8:27e9 27ea:27eb 27ec:27ed 27ee:27ef 2983:2984 2985:2986 2987:2988 2989:298a ' +
|
|
16034
|
+
'298b:298c 298d:2990 298f:298e 2991:2992 2993:2994 2995:2996 2997:2998 29d8:29d9 29da:29db ' +
|
|
16035
|
+
'29fc:29fd 2e22:2e23 2e24:2e25 2e26:2e27 2e28:2e29 2e55:2e56 2e57:2e58 2e59:2e5a 2e5b:2e5c ' +
|
|
16036
|
+
'2e62:2e63 3008:3009 300a:300b 300c:300d 300e:300f 3010:3011 3014:3015 3016:3017 3018:3019 ' +
|
|
16037
|
+
'301a:301b fe59:fe5a fe5b:fe5c fe5d:fe5e ff08:ff09 ff3b:ff3d ff5b:ff5d ff5f:ff60 ff62:ff63';
|
|
16038
|
+
|
|
16039
|
+
/**
|
|
16040
|
+
* Whether an organization's name, or any text, reads as SparkVault's own.
|
|
16041
|
+
*
|
|
16042
|
+
* An organization's name is the author a recipient reads on its mail:
|
|
16043
|
+
* Identity's sign-in codes leave the platform's sign-in mailbox under it, and
|
|
16044
|
+
* Notify relays an organization's message from "{name}"
|
|
16045
|
+
* <notify@{handle}.send.sv>. A name that reads as SparkVault or SparkLink
|
|
16046
|
+
* would author that mail as the platform, a name that carries an email
|
|
16047
|
+
* address would author it as whoever that address names, and a name that
|
|
16048
|
+
* reads as a web address would show a link where its author belongs.
|
|
16049
|
+
*
|
|
16050
|
+
* A reader reads letters, not code points, and reads them in the order they
|
|
16051
|
+
* are laid out, so a text is judged the way it is read:
|
|
16052
|
+
* - in each form a surface shows it in: a lone surrogate, a code unit no
|
|
16053
|
+
* other pairs with (a JSON escape such as \ud800 puts one in a string), is
|
|
16054
|
+
* shown as U+FFFD REPLACEMENT CHARACTER where the text is carried as UTF-8
|
|
16055
|
+
* (a From line's encoded-word), and as itself where a JSON answer carries
|
|
16056
|
+
* it (the answer writes the escape \ud800, and a JavaScript client's
|
|
16057
|
+
* JSON.parse restores the surrogate), which the client lays out as the
|
|
16058
|
+
* left-to-right character Unicode classes it as; U+FFFD is a neutral,
|
|
16059
|
+
* which joins the right-to-left run around it, and the surrogate splits
|
|
16060
|
+
* that run, so a text that holds one is read both ways (formsShown);
|
|
16061
|
+
* - in NFC: canonically equivalent texts show alike, so the rule reads one
|
|
16062
|
+
* text for all of them, a precomposed character for the character and marks
|
|
16063
|
+
* it decomposes to (U+00CC, an I with a grave accent, for I and U+0300
|
|
16064
|
+
* COMBINING GRAVE ACCENT) and a Hangul syllable for its jamo, each composed
|
|
16065
|
+
* character a reader may pass over wherever they may pass over its parts;
|
|
16066
|
+
* - each character as the Latin letters it passes for
|
|
16067
|
+
* (./organization-name-unicode.js LETTER_READINGS, derived from Unicode's
|
|
16068
|
+
* confusables, names and compatibility decompositions and a hand list of
|
|
16069
|
+
* lookalikes, the alphabets fancy-text generators substitute for Latin ones
|
|
16070
|
+
* among them; any other character through NFKD), a character at times
|
|
16071
|
+
* reading as either of two letters (U+028B, a v with a hook, is a u or a v),
|
|
16072
|
+
* and i and l as one letter, since a capital I and a small l are one glyph
|
|
16073
|
+
* in most sans-serif faces;
|
|
16074
|
+
* - a character that reads as no letter (a space, punctuation, an invisible
|
|
16075
|
+
* character) passed over, so it never breaks a word; the marks drawn on a
|
|
16076
|
+
* character, each read just before that character or just after it, in any
|
|
16077
|
+
* order, or not at all; and a character a reader may take for a letter or
|
|
16078
|
+
* pass over, read where it stands or not at all (OPTIONAL_LETTERS): a
|
|
16079
|
+
* superscript or subscript form, drawn small beside a word's letters; a
|
|
16080
|
+
* character whose letters are a resemblance only, a fancy-text generator's
|
|
16081
|
+
* letter among them (U+A317 YI SYLLABLE SOT, an s, is drawn as U+00A7
|
|
16082
|
+
* SECTION SIGN); a digit, punctuation mark or symbol that passes for a
|
|
16083
|
+
* letter (`1`, `$`, `+`), or a letter drawn as one; and a bare vertical
|
|
16084
|
+
* stroke (`|`, `l`, `I`), which reads as a separator as readily as an l; so
|
|
16085
|
+
* none of those breaks a word either, and a character breaks one only where
|
|
16086
|
+
* a reader must read it as letters: it is a form of them, or UTS #39 draws
|
|
16087
|
+
* it as Latin letters alone;
|
|
16088
|
+
* - in every order it can be laid out in: as stored, and as the Unicode
|
|
16089
|
+
* bidirectional algorithm (UAX #9) lays it out in a left-to-right and in a
|
|
16090
|
+
* right-to-left paragraph (an inbox in a right-to-left language, or a
|
|
16091
|
+
* client that takes the direction from the text's first letter), where a
|
|
16092
|
+
* right-to-left letter or mark, or an Arabic digit, between Latin words
|
|
16093
|
+
* reverses their order: "Vault", U+05BE HEBREW PUNCTUATION MAQAF, "Spark" is
|
|
16094
|
+
* laid out in a right-to-left paragraph as "Spark", the maqaf, "Vault".
|
|
16095
|
+
* An explicit direction control (holdsDirectionControl, ./display-text.js)
|
|
16096
|
+
* sets the direction of the text after it beyond what this lays out, so a
|
|
16097
|
+
* caller that judges what a reader sees refuses it as well, as
|
|
16098
|
+
* isReservedDisplayText, for any text an organization shows under its name,
|
|
16099
|
+
* and isReservedOrganizationName do. Both also judge a text at every cut of it
|
|
16100
|
+
* as stored, each cut read in this way, since the platform shows a text cut to
|
|
16101
|
+
* fit. The implicit marks are no such control: each is a strong character of
|
|
16102
|
+
* its direction, laid out as a letter of that direction is.
|
|
16103
|
+
*
|
|
16104
|
+
* BROWSER-SAFE: imports only ./display-text.js and
|
|
16105
|
+
* ./organization-name-unicode.js, neither of which imports anything, and needs
|
|
16106
|
+
* String.prototype.isWellFormed and toWellFormed (ES2024: Chrome 111,
|
|
16107
|
+
* Firefox 119, Safari 16.4).
|
|
16108
|
+
*/
|
|
16109
|
+
|
|
16110
|
+
/** The words no organization's name may read as: the platform's brand and its link product. */
|
|
16111
|
+
const RESERVED_BRAND_TOKENS = Object.freeze(['sparkvault', 'sparklink']);
|
|
16112
|
+
|
|
16113
|
+
/** i and l read as one letter. */
|
|
16114
|
+
const foldLetter = (letter) => (letter === 'i' ? 'l' : letter);
|
|
16115
|
+
|
|
16116
|
+
/** The letters of the reserved words, each a bit of a position's mask. */
|
|
16117
|
+
const BRAND_BITS = new Map(
|
|
16118
|
+
[...new Set(Array.from(RESERVED_BRAND_TOKENS.join(''), foldLetter))].map((letter, index) => [letter, 1 << index])
|
|
16119
|
+
);
|
|
16120
|
+
|
|
16121
|
+
/** The brand letters a group of letters can read as, as a mask: 0 for a letter of no reserved word. */
|
|
16122
|
+
function lettersMask(letters) {
|
|
16123
|
+
let mask = 0;
|
|
16124
|
+
for (const letter of letters) mask |= BRAND_BITS.get(foldLetter(letter)) ?? 0;
|
|
16125
|
+
return mask;
|
|
16126
|
+
}
|
|
16127
|
+
|
|
16128
|
+
/** Each reserved word as the masks its letters need. */
|
|
16129
|
+
const TOKEN_MASKS = RESERVED_BRAND_TOKENS.map((token) => Array.from(token, lettersMask));
|
|
16130
|
+
|
|
16131
|
+
/** Each code point a generated list names: hexadecimal, separated by spaces, `first-last` a range. */
|
|
16132
|
+
function* codePointsOf(list) {
|
|
16133
|
+
for (const entry of list.split(' ')) {
|
|
16134
|
+
const [first, last = first] = entry.split('-');
|
|
16135
|
+
for (let codePoint = parseInt(first, 16); codePoint <= parseInt(last, 16); codePoint++) yield codePoint;
|
|
16136
|
+
}
|
|
16137
|
+
}
|
|
16138
|
+
|
|
16139
|
+
/** Each listed character's reading: one mask per letter position. */
|
|
16140
|
+
const LISTED_READINGS = new Map();
|
|
16141
|
+
for (const [reading, list] of Object.entries(LETTER_READINGS)) {
|
|
16142
|
+
const positions = Object.freeze(reading.split('.').map(lettersMask));
|
|
16143
|
+
for (const codePoint of codePointsOf(list)) LISTED_READINGS.set(codePoint, positions);
|
|
16144
|
+
}
|
|
16145
|
+
|
|
16146
|
+
/** The characters whose letters a reader may read or pass over. */
|
|
16147
|
+
new Set(codePointsOf(OPTIONAL_LETTERS));
|
|
16148
|
+
|
|
16149
|
+
/** Every bidirectional class other than L, as sorted [first, last, class] ranges. */
|
|
16150
|
+
Object.entries(BIDI_CLASSES)
|
|
16151
|
+
.flatMap(([bidiClass, list]) => list.split(' ').map((entry) => {
|
|
16152
|
+
const [first, last = first] = entry.split('-');
|
|
16153
|
+
return [parseInt(first, 16), parseInt(last, 16), bidiClass];
|
|
16154
|
+
}))
|
|
16155
|
+
.sort((a, b) => a[0] - b[0]);
|
|
16156
|
+
|
|
16157
|
+
/** Each opening paired bracket's closing bracket, and the reverse (UAX #9 BD16). */
|
|
16158
|
+
const CLOSING_BRACKET = new Map();
|
|
16159
|
+
const OPENING_BRACKET = new Map();
|
|
16160
|
+
for (const pair of BRACKET_PAIRS.split(' ')) {
|
|
16161
|
+
const [opening, closing] = pair.split(':').map((codePoint) => parseInt(codePoint, 16));
|
|
16162
|
+
CLOSING_BRACKET.set(opening, closing);
|
|
16163
|
+
OPENING_BRACKET.set(closing, opening);
|
|
16164
|
+
}
|
|
16165
|
+
|
|
16166
|
+
/**
|
|
16167
|
+
* A reading's progress, as one bit set (a bit-parallel search): for each
|
|
16168
|
+
* reserved word a bit per letter, set while the letters read so far end in the
|
|
16169
|
+
* word spelled up to that letter, the words' bits side by side from
|
|
16170
|
+
* WORD_OFFSETS; and SPELLED, set once any word has been spelled whole. Two
|
|
16171
|
+
* ways of reading a text merge as the union of their bits.
|
|
16172
|
+
*/
|
|
16173
|
+
const WORD_OFFSETS = TOKEN_MASKS.map((_, word) =>
|
|
16174
|
+
TOKEN_MASKS.slice(0, word).reduce((offset, token) => offset + token.length, 0));
|
|
16175
|
+
|
|
16176
|
+
/** Each word's first letter, where a new spelling can start at any letter read. */
|
|
16177
|
+
WORD_OFFSETS.reduce((bits, offset) => bits | (1 << offset), 0);
|
|
16178
|
+
|
|
16179
|
+
/** Each word's last letter. */
|
|
16180
|
+
TOKEN_MASKS.reduce((bits, token, word) => bits | (1 << (WORD_OFFSETS[word] + token.length - 1)), 0);
|
|
16181
|
+
|
|
16182
|
+
1 << TOKEN_MASKS.reduce((count, token) => count + token.length, 0);
|
|
16183
|
+
|
|
16184
|
+
/** For each mask of brand letters, the letters of the words a letter of it can be. */
|
|
16185
|
+
Array.from({ length: 1 << BRAND_BITS.size }, (_, mask) =>
|
|
16186
|
+
TOKEN_MASKS.reduce((bits, token, word) => token.reduce((wordBits, letters, position) =>
|
|
16187
|
+
((letters & mask) === 0 ? wordBits : wordBits | (1 << (WORD_OFFSETS[word] + position))), bits), 0));
|
|
16188
|
+
|
|
16189
|
+
/**
|
|
16190
|
+
* The Secure Help Desk's shared vocabulary: the values Core's help-desk engine
|
|
16191
|
+
* stores and checks, and the console and the customer portal render, defined
|
|
16192
|
+
* once so the three cannot disagree about a status, a label, a limit, a timing
|
|
16193
|
+
* or an event's visibility.
|
|
16194
|
+
*
|
|
16195
|
+
* A ticket is `open`, `waiting_on_customer`, `on_hold` (until a time) or
|
|
16196
|
+
* `closed` (as resolved, a duplicate merged elsewhere, or spam). A customer
|
|
16197
|
+
* never sees those words: customerStatusLabel is the one translation into
|
|
16198
|
+
* theirs. Every timeline event type declares whether a customer may see it;
|
|
16199
|
+
* a customer-facing projection keeps only `public` types (an allowlist, so a
|
|
16200
|
+
* new type is hidden until it says otherwise). The portal's client name and
|
|
16201
|
+
* API prefix, team mail aliases, the attachment ceremony's steps, the
|
|
16202
|
+
* question a customer's new request asks before it is discarded, session,
|
|
16203
|
+
* sign-in code (its length, lifetime, sender, resend wait, countdown and
|
|
16204
|
+
* the code step's words),
|
|
16205
|
+
* merge and pending-attachment timings, hold presets, tag and size limits,
|
|
16206
|
+
* the operator display and desk mode choices and the response-time
|
|
16207
|
+
* histogram's bucket edges live here for the same reason. So do the one rule a tag is stored by
|
|
16208
|
+
* (ticketTag), which Core applies where it stores a tag and the console
|
|
16209
|
+
* applies where one is typed, and the one rule a typed or pasted sign-in
|
|
16210
|
+
* code is read by (helpDeskPinDigits), which every sign-in form applies.
|
|
16211
|
+
*
|
|
16212
|
+
* BROWSER-SAFE: data and pure functions; its imports are the platform's label
|
|
16213
|
+
* rule a tag is built on (./display-text.js), the mail products whose fixed
|
|
16214
|
+
* From local parts no team alias may take (./mail-products.js) and the brand
|
|
16215
|
+
* rule no team alias may read as (./organization-name.js).
|
|
16216
|
+
*/
|
|
16217
|
+
|
|
16218
|
+
|
|
16219
|
+
/**
|
|
16220
|
+
* Mail local parts no team may take as its alias: the role mailboxes RFC 2142
|
|
16221
|
+
* names, the addresses mail systems and their operators keep for themselves,
|
|
16222
|
+
* the platform's own host labels, and the fixed local part every other mail
|
|
16223
|
+
* product writes from (MAIL_PRODUCTS fromLocalPart), so no team writes from
|
|
16224
|
+
* the address Notify writes from on a domain both products use.
|
|
16225
|
+
*/
|
|
16226
|
+
Object.freeze([
|
|
16227
|
+
'abuse', 'postmaster', 'hostmaster', 'webmaster', 'noc', 'security', 'info', 'marketing', 'sales',
|
|
16228
|
+
'admin', 'administrator', 'root', 'mailer-daemon', 'no-reply', 'noreply', 'bounce', 'bounces',
|
|
16229
|
+
'dmarc', 'spf', 'dkim', 'probe',
|
|
16230
|
+
'www', 'api', 'mail', 'smtp', 'mx', 'help', 'sparkvault',
|
|
16231
|
+
...MAIL_PRODUCT_KEYS.map((key) => MAIL_PRODUCTS[key].fromLocalPart).filter((localPart) => localPart !== null)
|
|
16232
|
+
]);
|
|
16233
|
+
|
|
16234
|
+
/** The alias a team's mail goes out under until its admin chooses another. */
|
|
16235
|
+
const DEFAULT_TEAM_ALIAS = 'support';
|
|
16236
|
+
|
|
16237
|
+
/**
|
|
16238
|
+
* What a customer's new request asks before Cancel throws away what they
|
|
16239
|
+
* wrote and the files they added: the portal's New request page and the SDK's
|
|
16240
|
+
* support form ask it in place of their actions row, with Keep editing first,
|
|
16241
|
+
* as the primary button, focused as the question appears, and Discard after
|
|
16242
|
+
* it as the quieter one. Discard sends nothing, forgets the text and cancels
|
|
16243
|
+
* each file's upload, so `note` promises no more than both forms do.
|
|
16244
|
+
*/
|
|
16245
|
+
const DISCARD_REQUEST_COPY = Object.freeze({
|
|
16246
|
+
question: 'Discard this request?',
|
|
16247
|
+
note: 'What you wrote and any files you added will not be sent.',
|
|
16248
|
+
keepEditing: 'Keep editing',
|
|
16249
|
+
discard: 'Discard'
|
|
16250
|
+
});
|
|
16251
|
+
|
|
16252
|
+
/**
|
|
16253
|
+
* What the emailed-code step of a customer's sign-in says, word for word in
|
|
16254
|
+
* the portal's sign-in page and the SDK's support form: the refusal of a code
|
|
16255
|
+
* that is wrong, spent or expired (Core's PIN_INVALID), and the note once a
|
|
16256
|
+
* new code is sent. Neither names who sent the email, so both read right on
|
|
16257
|
+
* the portal and on a company's own site.
|
|
16258
|
+
*/
|
|
16259
|
+
const HELP_DESK_CODE_STEP_COPY = Object.freeze({
|
|
16260
|
+
codeRefused: 'That code is wrong or has expired. Check the newest email, or send a new code.',
|
|
16261
|
+
newCodeSent: 'We sent a new code. Use the newest one.'
|
|
16262
|
+
});
|
|
16263
|
+
|
|
16264
|
+
/** How long an emailed sign-in code stays good, in seconds. */
|
|
16265
|
+
const HELP_DESK_PIN_TTL_SECONDS = 600;
|
|
16266
|
+
|
|
16267
|
+
/** How long an emailed sign-in code stays good, in whole minutes: what the sign-in forms, the code's email and the API reference state. */
|
|
16268
|
+
const HELP_DESK_PIN_TTL_MINUTES = Math.round(HELP_DESK_PIN_TTL_SECONDS / 60);
|
|
16269
|
+
|
|
16270
|
+
/** How many digits an emailed sign-in code has. */
|
|
16271
|
+
const HELP_DESK_PIN_LENGTH = 6;
|
|
16272
|
+
|
|
16273
|
+
/** How long after a code is sent before a sign-in form offers to send another, in seconds. */
|
|
16274
|
+
const HELP_DESK_PIN_RESEND_AFTER_SECONDS = 60;
|
|
16275
|
+
|
|
16276
|
+
/**
|
|
16277
|
+
* The digits of a sign-in code as a person typed or pasted it, at most
|
|
16278
|
+
* HELP_DESK_PIN_LENGTH of them: "123 456" and "Your code: 123-456" both read
|
|
16279
|
+
* "123456", so a code pasted with separators is never cut short.
|
|
16280
|
+
*
|
|
16281
|
+
* @param {unknown} value
|
|
16282
|
+
* @returns {string}
|
|
16283
|
+
*/
|
|
16284
|
+
function helpDeskPinDigits(value) {
|
|
16285
|
+
return String(value).replace(/\D/g, '').slice(0, HELP_DESK_PIN_LENGTH);
|
|
16286
|
+
}
|
|
16287
|
+
|
|
16288
|
+
/**
|
|
16289
|
+
* The address a desk's emailed sign-in codes come from: its default team
|
|
16290
|
+
* alias on the host the desk sends from (the desk lookup's `sending_host`).
|
|
16291
|
+
*
|
|
16292
|
+
* @param {string} sendingHost
|
|
16293
|
+
* @returns {string}
|
|
16294
|
+
*/
|
|
16295
|
+
function helpDeskCodeSender(sendingHost) {
|
|
16296
|
+
return `${DEFAULT_TEAM_ALIAS}@${sendingHost}`;
|
|
16297
|
+
}
|
|
16298
|
+
|
|
16299
|
+
/**
|
|
16300
|
+
* A wait as the sign-in forms count it down before another code may be sent:
|
|
16301
|
+
* whole minutes and two-digit seconds, "0:42", "1:00". A part second rounds
|
|
16302
|
+
* down and a wait past its end reads "0:00".
|
|
16303
|
+
*
|
|
16304
|
+
* @param {number} seconds
|
|
16305
|
+
* @returns {string}
|
|
16306
|
+
*/
|
|
16307
|
+
function helpDeskCountdown(seconds) {
|
|
16308
|
+
const whole = Math.max(0, Math.floor(seconds));
|
|
16309
|
+
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, '0')}`;
|
|
16310
|
+
}
|
|
16311
|
+
|
|
16312
|
+
/**
|
|
16313
|
+
* Why a customer's file is refused by the desk's upload allowance per
|
|
16314
|
+
* customer (`customer_upload_limit_bytes`), as the 402 QUOTA_EXCEEDED that
|
|
16315
|
+
* refuses it names in `details.reason`, so the portal tells it from the
|
|
16316
|
+
* organization's storage being full: the customer's files would pass their
|
|
16317
|
+
* allowance, or the allowance is 0, which turns customer uploads off. A file
|
|
16318
|
+
* an email carried that the allowance refused is listed by the same reason
|
|
16319
|
+
* among the files its message left out (`email.skipped_attachments`).
|
|
16320
|
+
*/
|
|
16321
|
+
const CUSTOMER_UPLOAD_REFUSALS = Object.freeze({
|
|
16322
|
+
ALLOWANCE_REACHED: 'customer_upload_limit',
|
|
16323
|
+
UPLOADS_OFF: 'customer_uploads_off'
|
|
16324
|
+
});
|
|
16325
|
+
|
|
16326
|
+
/** The most attachments one message carries. */
|
|
16327
|
+
const MAX_ATTACHMENTS_PER_MESSAGE = 20;
|
|
16328
|
+
|
|
16329
|
+
/** The largest file a customer uploads through the portal, in bytes. */
|
|
16330
|
+
const CUSTOMER_ATTACHMENT_MAX_BYTES = 25 * 1024 * 1024;
|
|
16331
|
+
|
|
16332
|
+
/** Scoped styles for the optional inline help desk form. */
|
|
16333
|
+
function injectHelpDeskFormStyles() {
|
|
16334
|
+
if (document.getElementById('sparkvault-help-desk-styles'))
|
|
16335
|
+
return;
|
|
16336
|
+
const style = document.createElement('style');
|
|
16337
|
+
style.id = 'sparkvault-help-desk-styles';
|
|
16338
|
+
style.textContent = `
|
|
16339
|
+
.svhd-overlay{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px;background:${DS.modalOverlay};overflow:auto}
|
|
16340
|
+
.svhd-blur{backdrop-filter:blur(5px)}
|
|
16341
|
+
.svhd-modal{width:100%;max-width:36rem;max-height:calc(100dvh - 32px);overflow:auto;border-radius:12px;background:${DS.white};box-shadow:${DS.shadowPopover}}
|
|
16342
|
+
.svhd-modal-header{display:flex;justify-content:flex-end;padding:12px 16px 0}
|
|
16343
|
+
.svhd-modal-close{border:0;border-radius:4px;background:transparent;color:${DS.slate600};cursor:pointer;font:600 14px/1.5 system-ui,sans-serif;padding:6px 8px;min-height:44px}
|
|
16344
|
+
.svhd-modal-close:hover{color:${DS.slate900}}
|
|
16345
|
+
.svhd-modal-close:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
16346
|
+
.svhd-modal .svhd-container{max-width:none;border:0;border-radius:0;padding-top:8px}
|
|
16347
|
+
.svhd-container{box-sizing:border-box;max-width:36rem;border:1px solid ${DS.slate200};border-radius:12px;background:${DS.white};color:${DS.slate900};font:400 15px/1.5 system-ui,sans-serif;padding:24px}
|
|
16348
|
+
.svhd-container *{box-sizing:border-box}
|
|
16349
|
+
.svhd-container h2{font-size:22px;line-height:1.25;margin:0 0 20px}
|
|
16350
|
+
.svhd-form{display:grid;gap:16px}
|
|
16351
|
+
.svhd-field{display:grid;gap:6px}
|
|
16352
|
+
.svhd-label{font-weight:600}
|
|
16353
|
+
.svhd-input{width:100%;border:1px solid ${DS.slate300};border-radius:6px;padding:10px 12px;color:${DS.slate900};background:${DS.white};font:inherit;font-size:16px}
|
|
16354
|
+
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
16355
|
+
.svhd-input:disabled{background:${DS.slate50}}
|
|
16356
|
+
.svhd-description{min-height:140px;resize:vertical}
|
|
16357
|
+
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
16358
|
+
.svhd-form[hidden],.svhd-auth[hidden],.svhd-field[hidden],.svhd-field-error[hidden],.svhd-status[hidden],.svhd-link[hidden],.svhd-actions[hidden],.svhd-confirm[hidden]{display:none}
|
|
16359
|
+
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
16360
|
+
.svhd-button{border:0;border-radius:6px;padding:10px 16px;min-height:44px;font:600 15px/1.5 system-ui,sans-serif;background:${DS.action};color:${DS.white};cursor:pointer}
|
|
16361
|
+
.svhd-button:hover{background:${DS.actionHover}}
|
|
16362
|
+
.svhd-button:disabled{opacity:.6;cursor:default}
|
|
16363
|
+
.svhd-secondary{background:transparent;color:${DS.slate600};padding:10px 4px}
|
|
16364
|
+
.svhd-secondary:hover{background:transparent;color:${DS.slate900}}
|
|
16365
|
+
.svhd-status{margin:0;color:${DS.slate600}}
|
|
16366
|
+
.svhd-error{color:${DS.error}}
|
|
16367
|
+
.svhd-field-error{margin:0;font-size:14px;color:${DS.error}}
|
|
16368
|
+
.svhd-code-links{display:flex;flex-wrap:wrap;gap:4px 16px}
|
|
16369
|
+
.svhd-confirm{display:grid;gap:8px}
|
|
16370
|
+
.svhd-confirm-title{font-weight:600;margin:0}
|
|
16371
|
+
.svhd-done{display:grid;gap:12px}
|
|
16372
|
+
.svhd-done-title{font-size:18px;line-height:1.3;margin:0}
|
|
16373
|
+
.svhd-done-title:focus{outline:none}
|
|
16374
|
+
.svhd-link{display:inline-flex;align-items:center;justify-self:start;min-height:44px;color:${DS.action};text-decoration:underline}
|
|
16375
|
+
.svhd-attachments[hidden],.svhd-attachments [hidden]{display:none}
|
|
16376
|
+
.svhd-file-hint{font-size:13px;color:${DS.slate600};margin:0}
|
|
16377
|
+
.svhd-file-list{display:grid;gap:12px;list-style:none;padding:0;margin:0}
|
|
16378
|
+
.svhd-file{display:grid;grid-template-columns:minmax(0,1fr) auto auto;gap:4px 10px;align-items:center;border:1px solid ${DS.slate200};border-radius:6px;padding:10px}
|
|
16379
|
+
.svhd-file-name{font-weight:600;overflow-wrap:anywhere;grid-column:1/-1}
|
|
16380
|
+
.svhd-file [role=status]{grid-column:1/-1;font-size:13px}
|
|
16381
|
+
.svhd-file progress{width:100%;min-width:0;accent-color:${DS.action}}
|
|
16382
|
+
.svhd-file .svhd-button{font-size:13px;padding:0 12px;min-height:44px}
|
|
16383
|
+
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
16384
|
+
`;
|
|
16385
|
+
document.head.appendChild(style);
|
|
16386
|
+
}
|
|
16387
|
+
|
|
16388
|
+
/**
|
|
16389
|
+
* The one rule for which characters a file name may hold, shared by every
|
|
16390
|
+
* runtime that stores a name (Core refuses them at ingest, and clients check
|
|
16391
|
+
* before they send) and every runtime that saves a stored name to a device
|
|
16392
|
+
* (Forge's Content-Disposition, the web console's download, the x.sv reveal
|
|
16393
|
+
* page, the mobile share sheet). A download saves under the file's current
|
|
16394
|
+
* name by this rule, or under SAVED_FILENAME_FALLBACK when it has none.
|
|
16395
|
+
*
|
|
16396
|
+
* UNSAFE characters are never stored, and are replaced in any name saved to a
|
|
16397
|
+
* device: path separators, control characters (C0, DEL and C1), and the
|
|
16398
|
+
* invisible bidirectional controls that make a name display a different
|
|
16399
|
+
* extension than it has (`invoice<U+202E>fdp.exe` shows as `invoiceexe.pdf`).
|
|
16400
|
+
*
|
|
16401
|
+
* NON-PORTABLE characters (`: * ? " < > |`) are refused by the file systems a
|
|
16402
|
+
* name is saved to, so they are never stored either. A saved name keeps them:
|
|
16403
|
+
* a stored name cannot hold one, and Forge carries a name's exact text in the
|
|
16404
|
+
* RFC 5987 `filename*` parameter.
|
|
16405
|
+
*
|
|
16406
|
+
* Pure and import-free, so a browser, a container and a Lambda load it alike;
|
|
16407
|
+
* sdk-mobile mirrors it at build time (scripts/generate-app-sdk-mirrors.mjs).
|
|
16408
|
+
*/
|
|
16409
|
+
|
|
16410
|
+
/**
|
|
16411
|
+
* Control characters (C0, DEL and C1) and the invisible bidirectional text
|
|
16412
|
+
* controls, as the body of a character class: text holding one displays as
|
|
16413
|
+
* other text than it holds.
|
|
16414
|
+
*/
|
|
16415
|
+
const CONTROL_AND_BIDI_CHARACTERS = String.raw`\p{Cc}\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069`;
|
|
16416
|
+
|
|
16417
|
+
/** Path separators, control characters and bidirectional text controls. */
|
|
16418
|
+
const UNSAFE_FILENAME_CHARACTERS = new RegExp(String.raw`[\\/${CONTROL_AND_BIDI_CHARACTERS}]`, 'u');
|
|
16419
|
+
|
|
16420
|
+
/** Characters the file systems a name is saved to refuse. */
|
|
16421
|
+
const NON_PORTABLE_FILENAME_CHARACTERS = /[:*?"<>|]/;
|
|
16422
|
+
|
|
16423
|
+
/**
|
|
16424
|
+
* A character a save drops from a name's end. Windows drops trailing dots and
|
|
16425
|
+
* spaces from a name it saves ("page.html." is saved as "page.html"); any
|
|
16426
|
+
* other trailing white space is dropped alike, so a name never hides the
|
|
16427
|
+
* extension a saved copy could open as.
|
|
16428
|
+
*/
|
|
16429
|
+
const DROPPED_TRAILING_CHARACTER = /[\s.]/u;
|
|
16430
|
+
|
|
16431
|
+
/**
|
|
16432
|
+
* `name` without the trailing dots and white space a save drops: "page.html."
|
|
16433
|
+
* and "page.html " are "page.html", "notes. ." is "notes", and a name of only
|
|
16434
|
+
* dots and white space is ''. shownExtension and lastExtension read the
|
|
16435
|
+
* extension in front of them, and Forge completes a saved name after them
|
|
16436
|
+
* (./media-type-node.js withMediaTypeExtension: "notes." under text/plain
|
|
16437
|
+
* saves as "notes.txt").
|
|
16438
|
+
*
|
|
16439
|
+
* @param {string} name
|
|
16440
|
+
* @returns {string}
|
|
16441
|
+
*/
|
|
16442
|
+
function trimDroppedTrailing(name) {
|
|
16443
|
+
let end = name.length;
|
|
16444
|
+
while (end > 0 && DROPPED_TRAILING_CHARACTER.test(name[end - 1])) end -= 1;
|
|
16445
|
+
return name.slice(0, end);
|
|
16446
|
+
}
|
|
16447
|
+
|
|
16448
|
+
/**
|
|
16449
|
+
* Invisible characters (Unicode's Default_Ignorable_Code_Point): the joiners,
|
|
16450
|
+
* variation selectors, tags and bidirectional controls, which display as
|
|
16451
|
+
* nothing, and the Hangul fillers, which display as blank space. None shows
|
|
16452
|
+
* in a name, and a save keeps several (`Invoice.pdf<U+034F>` saves as itself
|
|
16453
|
+
* in Chromium and Firefox, and shows as `Invoice.pdf`).
|
|
16454
|
+
*/
|
|
16455
|
+
const INVISIBLE_CHARACTERS = /\p{Default_Ignorable_Code_Point}/gu;
|
|
16456
|
+
|
|
16457
|
+
/**
|
|
16458
|
+
* What `name` shows once saved: the name read past its invisible characters
|
|
16459
|
+
* (INVISIBLE_CHARACTERS), without the trailing dots and white space a save
|
|
16460
|
+
* drops (trimDroppedTrailing). The extension a name shows is read in it
|
|
16461
|
+
* (shownExtension), and a name it leaves nothing of is one of only dots or
|
|
16462
|
+
* spaces (isOnlyDotsOrSpaces).
|
|
16463
|
+
*
|
|
16464
|
+
* @param {string} name
|
|
16465
|
+
* @returns {string}
|
|
16466
|
+
*/
|
|
16467
|
+
function nameAsShown(name) {
|
|
16468
|
+
return trimDroppedTrailing(name.replace(INVISIBLE_CHARACTERS, ''));
|
|
16469
|
+
}
|
|
16470
|
+
|
|
16471
|
+
/** Why a name cannot be stored, as storableFilenameProblem reports it. */
|
|
16472
|
+
const FILENAME_PROBLEMS = Object.freeze({
|
|
16473
|
+
UNSAFE_CHARACTER: 'unsafe_character',
|
|
16474
|
+
NON_PORTABLE_CHARACTER: 'non_portable_character',
|
|
16475
|
+
ONLY_DOTS_OR_SPACES: 'only_dots_or_spaces'
|
|
16476
|
+
});
|
|
16477
|
+
|
|
16478
|
+
/**
|
|
16479
|
+
* Whether `name` is one of only dots or spaces: a name that is not empty yet
|
|
16480
|
+
* shows nothing once saved (nameAsShown), every character in it a dot, white
|
|
16481
|
+
* space or an invisible character (`...` and ` . `, and `..<U+034F>` and
|
|
16482
|
+
* `.<U+200B>.`, which show as `..`). No such name is stored
|
|
16483
|
+
* (storableFilenameProblem), and a file that has one saves under the
|
|
16484
|
+
* fallback name (savedFilename).
|
|
16485
|
+
*
|
|
16486
|
+
* @param {string} name
|
|
16487
|
+
* @returns {boolean}
|
|
16488
|
+
*/
|
|
16489
|
+
function isOnlyDotsOrSpaces(name) {
|
|
16490
|
+
return name !== '' && nameAsShown(name) === '';
|
|
16491
|
+
}
|
|
16492
|
+
|
|
16493
|
+
/**
|
|
16494
|
+
* What stops `name` from being stored as a file name, or null when nothing
|
|
16495
|
+
* does. Length and emptiness are the storing runtime's own limits.
|
|
16496
|
+
*
|
|
16497
|
+
* @param {string} name
|
|
16498
|
+
* @returns {string|null} One of FILENAME_PROBLEMS, or null
|
|
16499
|
+
*/
|
|
16500
|
+
function storableFilenameProblem(name) {
|
|
16501
|
+
if (UNSAFE_FILENAME_CHARACTERS.test(name)) return FILENAME_PROBLEMS.UNSAFE_CHARACTER;
|
|
16502
|
+
if (NON_PORTABLE_FILENAME_CHARACTERS.test(name)) return FILENAME_PROBLEMS.NON_PORTABLE_CHARACTER;
|
|
16503
|
+
if (isOnlyDotsOrSpaces(name)) return FILENAME_PROBLEMS.ONLY_DOTS_OR_SPACES;
|
|
16504
|
+
return null;
|
|
16505
|
+
}
|
|
16506
|
+
|
|
16507
|
+
/** The longest name an ingot stores, in UTF-16 code units. */
|
|
16508
|
+
const INGOT_NAME_MAX = 255;
|
|
16509
|
+
|
|
16510
|
+
/**
|
|
16511
|
+
* A run of the white space Firefox reads in a name it saves: the space
|
|
16512
|
+
* separators and U+FEFF, and the line and paragraph separators, which it
|
|
16513
|
+
* drops wherever they stand and which end no run.
|
|
16514
|
+
*/
|
|
16515
|
+
const WHITE_SPACE_RUN = /[\p{Zs}\uFEFF\u2028\u2029]+/gu;
|
|
16516
|
+
|
|
16517
|
+
/** A run whose first space is an ideographic space (U+3000), the one space Firefox keeps. */
|
|
16518
|
+
const RUN_FIREFOX_KEEPS = /^[\u2028\u2029]*\u3000/;
|
|
16519
|
+
|
|
16520
|
+
/**
|
|
16521
|
+
* `name` with its white space closed up as Firefox closes it in what follows
|
|
16522
|
+
* its last dot, under any type it is handed and in a blob's name alike
|
|
16523
|
+
* (nsExternalHelperAppService::SanitizeFileName): it collapses a run of white
|
|
16524
|
+
* space into the run's first character, an ideographic space kept as it is
|
|
16525
|
+
* and any other made an ASCII space, then strips the ASCII spaces from what
|
|
16526
|
+
* follows the last dot. So a run there is dropped whole unless it starts with
|
|
16527
|
+
* an ideographic space: `evil.ex e` saves as `evil.exe`, `evil.ex<U+3000>e`
|
|
16528
|
+
* as itself, `evil.ex <U+3000>e` as `evil.exe`. Closing up the whole name
|
|
16529
|
+
* moves no dot, so what follows its last dot is what Firefox saves there.
|
|
16530
|
+
*
|
|
16531
|
+
* @param {string} name
|
|
16532
|
+
* @returns {string}
|
|
16533
|
+
*/
|
|
16534
|
+
function closeUpSpaces(name) {
|
|
16535
|
+
return name.replace(WHITE_SPACE_RUN, (run) => (RUN_FIREFOX_KEEPS.test(run) ? '\u3000' : ''));
|
|
16536
|
+
}
|
|
16537
|
+
|
|
16538
|
+
/**
|
|
16539
|
+
* The extension `name` shows, its spaces kept, lowercase and without its dot:
|
|
16540
|
+
* what follows the last dot of what the name shows once saved (nameAsShown:
|
|
16541
|
+
* read past its invisible characters, without the trailing dots and white
|
|
16542
|
+
* space a save drops). "invoice.note.html" and "page.html." show 'html',
|
|
16543
|
+
* "logs.tar.gz" 'gz', ".html" 'html' (Windows reads a leading dot's
|
|
16544
|
+
* extension), "Invoice.pdf (1)" 'pdf (1)', and a name with no dot ''. It is
|
|
16545
|
+
* what Chromium's copy shows, since Chromium saves a name as sent:
|
|
16546
|
+
* "Invoice.pdf<U+034F>" shows 'pdf', and a character that draws as blank
|
|
16547
|
+
* space or as another letter yet is no invisible character stays in it
|
|
16548
|
+
* ("Invoice.pdf<U+2800>", a braille blank, shows 'pdf<U+2800>';
|
|
16549
|
+
* "Invoice.<U+0440>df", a Cyrillic er, '<U+0440>df'). Only whether a saved
|
|
16550
|
+
* name is completed reads it, by where its first word ends
|
|
16551
|
+
* (./media-type-node.js withMediaTypeExtension), since completion ends a name
|
|
16552
|
+
* in its type's own extension, which holds no space for Firefox to close up;
|
|
16553
|
+
* every rule about what a name makes a file reads lastExtension.
|
|
16554
|
+
*
|
|
16555
|
+
* @param {string} name
|
|
16556
|
+
* @returns {string}
|
|
16557
|
+
*/
|
|
16558
|
+
function shownExtension(name) {
|
|
16559
|
+
const shown = nameAsShown(name);
|
|
16560
|
+
const dot = shown.lastIndexOf('.');
|
|
16561
|
+
return dot === -1 ? '' : shown.slice(dot + 1).toLowerCase();
|
|
16562
|
+
}
|
|
16563
|
+
|
|
16564
|
+
/**
|
|
16565
|
+
* The extension a saved copy of `name` opens as, lowercase and without its
|
|
16566
|
+
* dot: the one it shows (shownExtension) once its spaces are closed up as
|
|
16567
|
+
* Firefox, the browser that changes a saved name most, closes them
|
|
16568
|
+
* (closeUpSpaces). "evil.ex e", "evil.ex<U+00A0>e" and "evil. exe" open as
|
|
16569
|
+
* 'exe', "Scan. pdf" as 'pdf', "Invoice.pdf (1)" as 'pdf(1)' and "Acme Inc.
|
|
16570
|
+
* Contract" as 'contract', though Chromium saves each as sent. Every rule
|
|
16571
|
+
* about what a name makes a file (a refused extension, an inline
|
|
16572
|
+
* disposition, the type Core stores for an untyped upload, the type Forge
|
|
16573
|
+
* serves a download under: ./media-type-node.js) reads this, never
|
|
16574
|
+
* splitExtension.
|
|
16575
|
+
*
|
|
16576
|
+
* @param {string} name
|
|
16577
|
+
* @returns {string}
|
|
16578
|
+
*/
|
|
16579
|
+
function lastExtension(name) {
|
|
16580
|
+
// Closed up before its invisible characters are read past: Firefox counts
|
|
16581
|
+
// U+FEFF, one of them, as white space (`evil.ex<U+FEFF><U+3000>e` saves as
|
|
16582
|
+
// `evil.exe`).
|
|
16583
|
+
return shownExtension(closeUpSpaces(name));
|
|
16584
|
+
}
|
|
16585
|
+
|
|
16586
|
+
/**
|
|
16587
|
+
* What a help-desk attachment may be named and what its first bytes may not
|
|
16588
|
+
* be: the one list of the files a ticket accepts, beside the one list of
|
|
16589
|
+
* extensions Forge never completes a saved name with.
|
|
16590
|
+
*
|
|
16591
|
+
* Both sides of a ticket upload files: a customer through the portal, an
|
|
16592
|
+
* operator through the console, and a customer's mail client through SES. The
|
|
16593
|
+
* server never reads the plaintext of an uploaded ingot, so the policy splits
|
|
16594
|
+
* by where the bytes are: the NAME rule runs on the server at initiate and in
|
|
16595
|
+
* the browser before an upload starts; the SNIFF rule runs wherever the bytes
|
|
16596
|
+
* are at hand — in the browser over the file's first slice, and on the server
|
|
16597
|
+
* over an inbound email's parts. The type a ticket stores a file under, which
|
|
16598
|
+
* the MIME registry decides, is server-only: ./attachment-policy-node.js.
|
|
16599
|
+
*
|
|
16600
|
+
* Built on the platform's one filename grammar (filename.js): nothing here
|
|
16601
|
+
* spells a second version of it.
|
|
16602
|
+
*
|
|
16603
|
+
* BROWSER-SAFE: reads any Uint8Array (a Node Buffer is one).
|
|
16265
16604
|
*/
|
|
16266
|
-
|
|
16267
|
-
'21 24 25 2b 30 31 34 35 37 40 49 6c 7c a1-a3 a5 aa ae b5 b9 ba bc-be cc-cf d7 128 12a 12c 12e ' +
|
|
16268
|
-
'130 138 13a 13c 13e 140 142 190 196 197 19a 1bc 1c0 1c1 1c3 1cf 208 20a 245 25b 26b 26d 26e ' +
|
|
16269
|
-
'276 279-27b 28a 2a4 2a7 2a8 2b0-2b5 2b7 2b8 2e0-2e3 363-36f 376 377 37b 37d 38a 393 399 39b ' +
|
|
16270
|
-
'3aa 3ad 3b2 3b5 3ba 3bc 3c0 3c4 3d0 3d6 3f0 3f5 3fd 403 404 406 407 40d 413 414 418 419 41b ' +
|
|
16271
|
-
'426 42f 432 434 438-43a 43d 43f 442 446 44a 44b 44f 454 45c 45d 48a 48b 490 492 494 49b 49f ' +
|
|
16272
|
-
'4a3 4a7 4ad 4c0 4c5 4c8 4ca 4cf 4e2-4e5 4f6 4f9 4fa 4fe 50d 510-513 520 521 525 52e 52f 547 ' +
|
|
16273
|
-
'548 554 577 57a 586 58c 5c0 5d5 5df 5e7 5e9 5f0 5f1 609 60a 622 623 625 627 661 665 667 668 ' +
|
|
16274
|
-
'66a 672 673 675 6f1 6f5 6f7 6f8 7c0 7ca 964-966 9e6 a66 ae6 b66 be6 c02 c66 c82 ce6 d02 d5f ' +
|
|
16275
|
-
'd66 d82 e04 e14 e15 e20 e22 e23 e26 e40 e41 e50 e8d ed0 1040 104a 104b 10a0 111b 111d 112b ' +
|
|
16276
|
-
'112c 1135 1141-1146 1148-114b 114d 1157 1162 1164 1166 1168 116b 116c 1170 1171 1174 1175 1180 ' +
|
|
16277
|
-
'1181 1185 1188 118a 118c 1190 1192 1194 1197-119d 11a1 11a7 11d5 11e2 11e6 11ec 11ed 11ef 11f1 ' +
|
|
16278
|
-
'11f2 11f4 1223 1260 13b1 13cb 13ce 13f0 13f8 13fb 13fc 1429 1431 143a-143d 144e 1457-145a 1467 ' +
|
|
16279
|
-
'1468 1476 1477 147a 147b 147e-1481 1486-1488 1498 1499 14a5 14ae 14af 14b6 14b7 14f0 14fa 14fb ' +
|
|
16280
|
-
'150e 1511 1515 1519 151a 1521 1522 152f 1530 1540 1575 157f 1581 1583 1584 1586 1591 1598 15b6 ' +
|
|
16281
|
-
'15e9 1609 166d 166e 1673 16c1 16c5 16d0 16ed 172a 17e0 18e8 1a80 1a90 1abf 1acc-1ace 1bea 1bec ' +
|
|
16282
|
-
'1c84 1d0b 1d0e 1d14 1d19 1d28 1d29 1d2c-1d2e 1d30 1d31 1d33-1d3a 1d3c 1d3e-1d43 1d45 1d47-1d49 ' +
|
|
16283
|
-
'1d4b 1d4d 1d4f-1d53 1d56-1d58 1d5a 1d5b 1d5d 1d5e 1d62-1d68 1d78 1d7a 1d7f 1d9c 1d9d 1da0-1da2 ' +
|
|
16284
|
-
'1da4-1db1 1db3 1db5-1db9 1dbb-1dbd 1dbf 1dca 1dd3-1dd8 1dda-1de9 1deb-1dee 1df0-1df4 1e2c 1e2e ' +
|
|
16285
|
-
'1e37 1e39 1e3b 1e3d 1ec8 1eca 1f10-1f15 1f38-1f3f 1f72 1fd8-1fda 2016 2020 2030 2031 203c 2048 ' +
|
|
16286
|
-
'2049 2052 2070 2071 2074 2075 2077 207a 207f-2081 2084 2085 2087 208a 2090-2093 2095-209f 20a1 ' +
|
|
16287
|
-
'20a4-20a6 20a8 20a9 20ab-20ae 20b1 20b3 20b4 20b6 20b8-20ba 20bd 20c1 2100 2101 2103 2105-2107 ' +
|
|
16288
|
-
'2109 2110 2111 2113 2116 2117 2120-2122 212e 213b 213c 213e 2150-2153 2155-215b 215d-217f 2183 ' +
|
|
16289
|
-
'2184 2189 218a 21bf 2205 2214 221a 221e 2223-2226 2228-222a 2296 229d 22a4 22c1-22c3 22f4 22ff ' +
|
|
16290
|
-
'2300 2361 2365 236c 2373 2374 2376-2378 237a 237f 239c 239f 23a2 23a5 23aa 23ae 23e8 23fd 2460 ' +
|
|
16291
|
-
'2463 2464 2466 2469-2474 2477 2478 247a 247d-2488 248b 248c 248e 2491-24ea 2502 2503 2573 2795 ' +
|
|
16292
|
-
'27d9 292b 292c 2963 296e 29b1-29b4 29e2 2a22-2a28 2a2f-2a31 2a40-2a45 2a52 2a5b 2a5d 2a62 2a63 ' +
|
|
16293
|
-
'2aee-2af1 2c6d 2c79 2c7c 2c7d 2c83 2c84 2c88 2c89 2c8f 2c92 2c95 2c9b 2ca1 2ca7 2cc0 2cd1 2ce8 ' +
|
|
16294
|
-
'2d00 2d37 2d4a 2d4f 2d51 2de1-2de3 2de6 2de8-2df0 2df2 2df4 2df6 2df7 2dfa 2dfb 2e36 2e37 2e85 ' +
|
|
16295
|
-
'2f01 2f0f 2f11 2f19 2f1b 2f59 3007 3012 3036 3072-3074 30a2 30a4 30ba 30e0 30ec 310e 3125 3129 ' +
|
|
16296
|
-
'3150 3152 3154 3156 3159 315a 315e 315f 3162 3163 3171 3178 3179 3182-3184 3188 3189 318b 318c ' +
|
|
16297
|
-
'318e 31d1 3207 3215 321d 321e 3250 3251 3254 3255 3257 325a 325b 325e 325f 3267 3275 327d 327e ' +
|
|
16298
|
-
'32b2 32b5-32c0 32c3 32c4 32c6 32c9-32d1 32f0 32f9 3300-3305 330a 330b 3315 3318-331a 331f 3320 ' +
|
|
16299
|
-
'332a 332d 332e 333d 3343 3344 3350 3355 3356 3358 3359 335c 335d 335f 3362-336d 3370-337a ' +
|
|
16300
|
-
'3380-33e0 33e3 33e4 33e6 33e9-33f4 33f7 33f8 33fa 33fd-33ff 4e02 4e28 4ebb 51e0 5200 5342 5369 ' +
|
|
16301
|
-
'53b6 5c3a 723f a00e a017 a018 a024 a072 a0f4 a224 a235 a263 a2d6 a2ea a2eb a317 a31a a34f a3dd ' +
|
|
16302
|
-
'a407 a490 a492 a493 a4a4 a4a6 a4c4 a4c5 a4db a4e5 a4f2 a4f5 a516 a56f a613 a650 a651 a674-a679 ' +
|
|
16303
|
-
'a67b a68d a69c a69d a6a1 a6ce a728-a72b a73f a742 a75a a75c a75d a768 a769 a772 a774-a776 a781 ' +
|
|
16304
|
-
'a792 a793 a79d a7ae a7b5 a7da a7dc a7e2 a7f1-a7f4 a7f8 a7f9 a7fe a830 a8ce a8cf a96b a976 a977 ' +
|
|
16305
|
-
'aa5d ab41 ab42 ab5d-ab5f ab62 ab68 ab6c ab70-ab72 ab7a-ab7c ab8b ab90 ab9b ab9e aba2 abae abb2 ' +
|
|
16306
|
-
'abb6 ac1c-ac30 ac32-ac37 ac54-ac68 ac6a-ac6f ac8c-aca0 aca2-aca7 acc4-acd8 acda-acdf ad18-ad2c ' +
|
|
16307
|
-
'ad2e-ad48 ad4a-ad4f ada4-adb8 adba-add4 add6-addb ae14-ae28 ae2a-ae44 ae46-ae4b ae68-ae7c ' +
|
|
16308
|
-
'ae7e-ae83 aea0-aeb4 aeb6-aebb aed8-aeec aeee-aef3 af10-af24 af26-af2b af64-af78 af7a-af94 ' +
|
|
16309
|
-
'af96-af9b aff0-b004 b006-b020 b022-b027 b060-b074 b076-b090 b092-b097 b0b4-b0c8 b0ca-b0cf ' +
|
|
16310
|
-
'b0ec-b100 b102-b107 b124-b138 b13a-b13f b15c-b170 b172-b177 b1b0-b1c4 b1c6-b1e0 b1e2-b1e7 ' +
|
|
16311
|
-
'b23c-b250 b252-b26c b26e-b273 b2ac-b2c0 b2c2-b2dc b2de-b2e3 b300-b314 b316-b31b b338-b34c ' +
|
|
16312
|
-
'b34e-b353 b370-b384 b386-b38b b3a8-b3bc b3be-b3c3 b3fc-b410 b412-b42c b42e-b433 b488-b49c ' +
|
|
16313
|
-
'b49e-b4b8 b4ba-b4bf b4f8-b50c b50e-b528 b52a-b52f b54c-b560 b562-b567 b584-b598 b59a-b59f ' +
|
|
16314
|
-
'b5bc-b5d0 b5d2-b5d7 b5f4-b608 b60a-b60f b648-b65c b65e-b678 b67a-b67f b6d4-b6e8 b6ea-b704 ' +
|
|
16315
|
-
'b706-b70b b744-b758 b75a-b774 b776-b77b b798-b7ac b7ae-b7b3 b7d0-b7e4 b7e6-b7eb b808-b81c ' +
|
|
16316
|
-
'b81e-b823 b840-b854 b856-b85b b894-b8a8 b8aa-b8c4 b8c6-b8cb b920-b934 b936-b950 b952-b957 ' +
|
|
16317
|
-
'b990-b9a4 b9a6-b9c0 b9c2-b9c7 b9e4-b9f8 b9fa-b9ff ba1c-ba30 ba32-ba37 ba54-ba68 ba6a-ba6f ' +
|
|
16318
|
-
'ba8c-baa0 baa2-baa7 bae0-baf4 baf6-bb10 bb12-bb17 bb6c-bb80 bb82-bb9c bb9e-bba3 bbdc-bbf0 ' +
|
|
16319
|
-
'bbf2-bc0c bc0e-bc13 bc30-bc44 bc46-bc4b bc68-bc7c bc7e-bc83 bca0-bcb4 bcb6-bcbb bcd8-bcec ' +
|
|
16320
|
-
'bcee-bcf3 bd2c-bd40 bd42-bd5c bd5e-bd63 bdb8-bdcc bdce-bde8 bdea-bdef be28-be3c be3e-be58 ' +
|
|
16321
|
-
'be5a-be5f be7c-be90 be92-be97 beb4-bec8 beca-becf beec-bf00 bf02-bf07 bf24-bf38 bf3a-bf3f ' +
|
|
16322
|
-
'bf78-bf8c bf8e-bfa8 bfaa-bfaf c004-c018 c01a-c034 c036-c03b c074-c088 c08a-c0a4 c0a6-c0ab ' +
|
|
16323
|
-
'c0c8-c0dc c0de-c0e3 c100-c114 c116-c11b c138-c14c c14e-c153 c170-c184 c186-c18b c1c4-c1d8 ' +
|
|
16324
|
-
'c1da-c1f4 c1f6-c1fb c250-c264 c266-c280 c282-c287 c2c0-c2d4 c2d6-c2f0 c2f2-c2f7 c314-c328 ' +
|
|
16325
|
-
'c32a-c32f c34c-c360 c362-c367 c384-c398 c39a-c39f c3bc-c3d0 c3d2-c3d7 c410-c424 c426-c440 ' +
|
|
16326
|
-
'c442-c447 c49c-c4b0 c4b2-c4cc c4ce-c4d3 c50c-c520 c522-c53c c53e-c543 c7ac-c7c0 c7c2-c7c7 ' +
|
|
16327
|
-
'c7e4-c7f8 c7fa-c7ff c81c-c830 c832-c837 c854-c868 c86a-c86f c8a8-c8bc c8be-c8d8 c8da-c8df ' +
|
|
16328
|
-
'c934-c948 c94a-c964 c966-c96b c9a4-c9b8 c9ba-c9d4 c9d6-c9db c9f8-ca0c ca0e-ca13 ca30-ca44 ' +
|
|
16329
|
-
'ca46-ca4b ca68-ca7c ca7e-ca83 caa0-cab4 cab6-cabb caf4-cb08 cb0a-cb24 cb26-cb2b cb80-cb94 ' +
|
|
16330
|
-
'cb96-cbb0 cbb2-cbb7 cbf0-cc04 cc06-cc20 cc22-cc27 cc44-cc58 cc5a-cc5f cc7c-cc90 cc92-cc97 ' +
|
|
16331
|
-
'ccb4-ccc8 ccca-cccf ccec-cd00 cd02-cd07 cd40-cd54 cd56-cd70 cd72-cd77 cdcc-cde0 cde2-cdfc ' +
|
|
16332
|
-
'cdfe-ce03 ce3c-ce50 ce52-ce6c ce6e-ce73 ce90-cea4 cea6-ceab cec8-cedc cede-cee3 cf00-cf14 ' +
|
|
16333
|
-
'cf16-cf1b cf38-cf4c cf4e-cf53 cf8c-cfa0 cfa2-cfbc cfbe-cfc3 d018-d02c d02e-d048 d04a-d04f ' +
|
|
16334
|
-
'd088-d09c d09e-d0b8 d0ba-d0bf d0dc-d0f0 d0f2-d0f7 d114-d128 d12a-d12f d14c-d160 d162-d167 ' +
|
|
16335
|
-
'd184-d198 d19a-d19f d1d8-d1ec d1ee-d208 d20a-d20f d264-d278 d27a-d294 d296-d29b d2d4-d2e8 ' +
|
|
16336
|
-
'd2ea-d304 d306-d30b d328-d33c d33e-d343 d360-d374 d376-d37b d398-d3ac d3ae-d3b3 d3d0-d3e4 ' +
|
|
16337
|
-
'd3e6-d3eb d424-d438 d43a-d454 d456-d45b d4b0-d4c4 d4c6-d4e0 d4e2-d4e7 d520-d534 d536-d550 ' +
|
|
16338
|
-
'd552-d557 d574-d588 d58a-d58f d5ac-d5c0 d5c2-d5c7 d5e4-d5f8 d5fa-d5ff d61c-d630 d632-d637 ' +
|
|
16339
|
-
'd670-d684 d686-d6a0 d6a2-d6a7 d6fc-d710 d712-d72c d72e-d733 d76c-d780 d782-d79c d79e-d7a3 d7b1 ' +
|
|
16340
|
-
'd7b3 d7b6 d7b7 d7bb d7bd-d7c4 d7c6 d7dd d7eb d7f4 fb29 fbea fbeb fc37 fc80 fc88 fccd fd3c fd3d ' +
|
|
16341
|
-
'fdf3 fdfc fe15 fe31 fe57 fe62 fe69-fe6b fe81-fe84 fe87 fe88 fe8d fe8e fef5-fefc ff01 ff04 ff05 ' +
|
|
16342
|
-
'ff0b ff10 ff11 ff14 ff15 ff17 ff20 ff29 ff4c ff5c ff71 ff72 ff91 ff9a ffc3 ffc5 ffc7 ffcb ffce ' +
|
|
16343
|
-
'ffcf ffd5 ffd6 ffdb ffdc ffe0 ffe1 ffe5 ffe6 ffe8 1017e 10182 1018b 1018e 10196-10199 101a0 ' +
|
|
16344
|
-
'1028a 1028d 1029b 102f5 10309 10320 10322 10401 10423 10425 10429 1042a 10443 1044b 1044d ' +
|
|
16345
|
-
'104b0 104bc 104d2 104e4 104fa 1050d-10510 10783-10785 10787-1078d 10790 10792-10796 ' +
|
|
16346
|
-
'10798-1079f 107a2 107a3 107a5-107b0 107b2 107b6 107b7 107b9 107ba 107bd 10926 10c3e 10ca5 ' +
|
|
16347
|
-
'10cfa 10cfc 11047 11048 11055 110c0 110c1 11141 11142 111c5 111c6 11302 113d4 113d5 1144b ' +
|
|
16348
|
-
'1144c 114d0 115c5 11641 11642 118af 118bb 118c6 118ce 118cf 118db 118e0 118e3 118e5 118e6 ' +
|
|
16349
|
-
'118e9 118ec 118ef 118f2 11c41 11c42 11dda 11de0 11de1 16869 16ad1 16ae4 16d63 16d69 16d6a ' +
|
|
16350
|
-
'16e80 16e82 16e8a 16eaa 16ec1 16f07 16f28 16f2d 16f3d 1cc90 1ccd6-1ccf1 1ccf4 1ccf5 1ccf7 ' +
|
|
16351
|
-
'1ce15 1cefc 1d100 1d134 1d1fe 1d202 1d207 1d20b-1d20d 1d212 1d213 1d216 1d21a 1d221 1d22a ' +
|
|
16352
|
-
'1d245 1d262 1d373 1d377 1d408 1d425 1d43c 1d459 1d470 1d48d 1d4c1 1d4d8 1d4f5 1d529 1d540 ' +
|
|
16353
|
-
'1d55d 1d574 1d591 1d5a8 1d5c5 1d5dc 1d5f9 1d610 1d62d 1d644 1d661 1d678 1d695 1d6aa 1d6b0 ' +
|
|
16354
|
-
'1d6b2 1d6c3 1d6c6 1d6cb 1d6cd 1d6d1 1d6d5 1d6dc 1d6de 1d6e1 1d6e4 1d6ea 1d6ec 1d6fd 1d700 ' +
|
|
16355
|
-
'1d705 1d707 1d70b 1d70f 1d716 1d718 1d71b 1d71e 1d724 1d726 1d737 1d73a 1d73f 1d741 1d745 ' +
|
|
16356
|
-
'1d749 1d750 1d752 1d755 1d758 1d75e 1d760 1d771 1d774 1d779 1d77b 1d77f 1d783 1d78a 1d78c ' +
|
|
16357
|
-
'1d78f 1d792 1d798 1d79a 1d7ab 1d7ae 1d7b3 1d7b5 1d7b9 1d7bd 1d7c4 1d7c6 1d7c9 1d7ce 1d7cf ' +
|
|
16358
|
-
'1d7d2 1d7d3 1d7d5 1d7d8 1d7d9 1d7dc 1d7dd 1d7df 1d7e2 1d7e3 1d7e6 1d7e7 1d7e9 1d7ec 1d7ed ' +
|
|
16359
|
-
'1d7f0 1d7f1 1d7f3 1d7f6 1d7f7 1d7fa 1d7fb 1d7fd 1df05 1df08 1df0a 1df12 1df15 1df17 1df19 ' +
|
|
16360
|
-
'1df1c 1df1f-1df23 1df2b 1df2c 1df3b 1df44 1df50 1df57 1df5b 1df5c 1df62 1df63 1df67 ' +
|
|
16361
|
-
'1df6c-1df6e 1dfcd-1dfd7 1dfd9-1dfdd 1dfe0 1dfe1 1dfe4 1dfe5 1dfe8-1dfea 1dfef-1dff2 ' +
|
|
16362
|
-
'1dff5-1dfff 1e030 1e032-1e035 1e038 1e039 1e03c-1e041 1e043 1e044 1e046 1e047 1e049 ' +
|
|
16363
|
-
'1e04c-1e051 1e053-1e056 1e059 1e05a 1e05c-1e05f 1e061 1e062 1e064-1e06d 1e08f 1e140 1e141 ' +
|
|
16364
|
-
'1e145 1e2f0 1e6e9 1e8c7 1ec75 1ec83 1ec86 1ec87 1ec89 1ec9e 1ec9f 1eca2 1eca3 1ecb1 1ecb2 ' +
|
|
16365
|
-
'1ed01 1ed13 1ed31 1ed32 1ed36 1ed37 1ee00 1ee61 1ee62 1ee67-1ee6a 1ee6c-1ee72 1ee74-1ee77 ' +
|
|
16366
|
-
'1ee79-1ee7c 1ee7e 1ee80 1f100-1f102 1f105 1f106 1f108 1f10f-1f12e 1f130-1f16e 1f170-1f198 ' +
|
|
16367
|
-
'1f19a 1f1a5-1f1a7 1f1a9-1f1ac 1f1e6-1f1ff 1f700 1f707 1f708 1f714 1f74c 1f75c 1f768 1f76b ' +
|
|
16368
|
-
'1f76c 1fbf0 1fbf1 1fbf4 1fbf5 1fbf7';
|
|
16605
|
+
|
|
16369
16606
|
|
|
16370
16607
|
/**
|
|
16371
|
-
*
|
|
16372
|
-
*
|
|
16373
|
-
*
|
|
16374
|
-
*
|
|
16608
|
+
* The files a ticket accepts, by kind: each kind keyed by the word every
|
|
16609
|
+
* surface names it with (./attachment-check.js ACCEPTED_ATTACHMENTS_COPY), and
|
|
16610
|
+
* listing the extensions a name may end in, lowercase and without the dot, as
|
|
16611
|
+
* lastExtension reads the one a saved copy opens as. A ticket takes no other
|
|
16612
|
+
* file: a name of no extension, an archive, a page, a Markdown document, a
|
|
16613
|
+
* drawing, a legacy or macro-enabled Office document, a message, and every
|
|
16614
|
+
* program, script, installer, shortcut and certificate are refused, whatever
|
|
16615
|
+
* their bytes say.
|
|
16616
|
+
* attachment-policy.test.js gives each kind the reason the program a desktop
|
|
16617
|
+
* opens it with runs no code from it, and holds that none of them, nor any
|
|
16618
|
+
* extension the registry lists beside one for its type, is one of
|
|
16619
|
+
* REFUSED_EXTENSIONS or one Outlook blocks.
|
|
16375
16620
|
*/
|
|
16376
|
-
const
|
|
16377
|
-
|
|
16378
|
-
|
|
16379
|
-
|
|
16380
|
-
|
|
16381
|
-
'1ed00-1ed4f 1ee00-1eeef 1eef2-1eeff',
|
|
16382
|
-
AN:
|
|
16383
|
-
'600-605 660-669 66b-66c 6dd 890-891 8e2 10d30-10d39 10d40-10d49 10e60-10e7e',
|
|
16384
|
-
B:
|
|
16385
|
-
'a d 1c-1e 85 2029',
|
|
16386
|
-
BN:
|
|
16387
|
-
'0-8 e-1b 7f-84 86-9f ad 180e 200b-200d 2060-2065 206a-206f fdd0-fdef feff fff0-fff8 ' +
|
|
16388
|
-
'fffe-ffff 1bca0-1bca3 1d173-1d17a 1fffe-1ffff 2fffe-2ffff 3fffe-3ffff 4fffe-4ffff ' +
|
|
16389
|
-
'5fffe-5ffff 6fffe-6ffff 7fffe-7ffff 8fffe-8ffff 9fffe-9ffff afffe-affff bfffe-bffff ' +
|
|
16390
|
-
'cfffe-cffff dfffe-e00ff e01f0-e0fff efffe-effff ffffe-fffff 10fffe-10ffff',
|
|
16391
|
-
CS:
|
|
16392
|
-
'2c 2e-2f 3a a0 60c 202f 2044 fe50 fe52 fe55 ff0c ff0e-ff0f ff1a',
|
|
16393
|
-
EN:
|
|
16394
|
-
'30-39 b2-b3 b9 6f0-6f9 2070 2074-2079 2080-2089 2488-249b ff10-ff19 102e1-102fb 1ccf0-1ccf9 ' +
|
|
16395
|
-
'1d7ce-1d7ff 1f100-1f10a 1fbf0-1fbf9',
|
|
16396
|
-
ES:
|
|
16397
|
-
'2b 2d 207a-207b 208a-208b 2212 fb29 fe62-fe63 ff0b ff0d',
|
|
16398
|
-
ET:
|
|
16399
|
-
'23-25 a2-a5 b0-b1 58f 609-60a 66a 9f2-9f3 9fb af1 bf9 e3f 17db 2030-2034 20a0-20cf 212e 2213 ' +
|
|
16400
|
-
'a838-a839 fe5f fe69-fe6a ff03-ff05 ffe0-ffe1 ffe5-ffe6 11fdd-11fe0 1e2ff',
|
|
16401
|
-
NSM:
|
|
16402
|
-
'300-36f 483-489 591-5bd 5bf 5c1-5c2 5c4-5c5 5c7-5c9 610-61a 64b-65f 670 6d6-6dc 6df-6e4 ' +
|
|
16403
|
-
'6e7-6e8 6ea-6ed 711 730-74a 7a6-7b0 7eb-7f3 7fd 816-819 81b-823 825-827 829-82d 859-85b ' +
|
|
16404
|
-
'897-89f 8ca-8e1 8e3-902 93a 93c 941-948 94d 951-957 962-963 981 9bc 9c1-9c4 9cd 9e2-9e3 9fe ' +
|
|
16405
|
-
'a01-a02 a3c a41-a42 a47-a48 a4b-a4d a51 a70-a71 a75 a81-a82 abc ac1-ac5 ac7-ac8 acd ae2-ae3 ' +
|
|
16406
|
-
'afa-aff b01 b3c b3f b41-b44 b4d b53-b56 b62-b63 b82 bc0 bcd c00 c04 c3c c3e-c40 c46-c48 ' +
|
|
16407
|
-
'c4a-c4d c55-c56 c62-c63 c81 cbc ccc-ccd ce2-ce3 d00-d01 d3b-d3c d41-d44 d4d d62-d63 d81 dca ' +
|
|
16408
|
-
'dd2-dd4 dd6 e31 e34-e3a e47-e4e eb1 eb4-ebc ec8-ece f18-f19 f35 f37 f39 f71-f7e f80-f84 ' +
|
|
16409
|
-
'f86-f87 f8d-f97 f99-fbc fc6 102d-1030 1032-1037 1039-103a 103d-103e 1058-1059 105e-1060 ' +
|
|
16410
|
-
'1071-1074 1082 1085-1086 108d 109d 135d-135f 1712-1714 1732-1733 1752-1753 1772-1773 ' +
|
|
16411
|
-
'17b4-17b5 17b7-17bd 17c6 17c9-17d3 17dd 180b-180d 180f 1885-1886 18a9 1920-1922 1927-1928 ' +
|
|
16412
|
-
'1932 1939-193b 1a17-1a18 1a1b 1a56 1a58-1a5e 1a60 1a62 1a65-1a6c 1a73-1a7c 1a7f 1ab0-1af0 ' +
|
|
16413
|
-
'1b00-1b03 1b34 1b36-1b39 1b6b-1b73 1b80-1b81 1ba2-1ba5 1ba8-1ba9 1bab-1bad 1be6 1be8-1be9 ' +
|
|
16414
|
-
'1bed 1bef-1bf1 1c2c-1c33 1c36-1c37 1cd0-1cd2 1cd4-1ce0 1ce2-1ce8 1ced 1cf4 1cf8-1cf9 ' +
|
|
16415
|
-
'1dc0-1dff 20d0-20f0 2cef-2cf1 2d7f 2de0-2dff 302a-302d 3099-309a a66f-a672 a674-a67d ' +
|
|
16416
|
-
'a69e-a69f a6f0-a6f1 a802 a806 a80b a825-a826 a82c a8c4-a8c5 a8e0-a8f1 a8ff a926-a92d ' +
|
|
16417
|
-
'a947-a951 a980-a982 a9b3 a9b6-a9b9 a9bc-a9bd a9e5 aa29-aa2e aa31-aa32 aa35-aa36 aa43 aa4c ' +
|
|
16418
|
-
'aa7c aab0 aab2-aab4 aab7-aab8 aabe-aabf aac1 aaec-aaed aaf6 abe5 abe8 abed fb1e fe00-fe0f ' +
|
|
16419
|
-
'fe20-fe2f 101fd 102e0 10376-1037a 10a01-10a03 10a05-10a06 10a0c-10a0f 10a38-10a3a 10a3f ' +
|
|
16420
|
-
'10ae5-10ae6 10d24-10d27 10d69-10d6d 10eab-10eac 10ecb-10ecf 10ef0-10eff 10f46-10f50 ' +
|
|
16421
|
-
'10f82-10f85 11001 11038-11046 11070 11073-11074 1107f-11081 110b3-110b6 110b9-110ba 110c2 ' +
|
|
16422
|
-
'11100-11102 11127-1112b 1112d-11134 11173 11180-11181 111b6-111be 111c9-111cc 111cf ' +
|
|
16423
|
-
'1122f-11231 11234 11236-11237 1123e 11241 112df 112e3-112ea 11300-11301 1133b-1133c 11340 ' +
|
|
16424
|
-
'11366-1136c 11370-11374 113bb-113c0 113ce 113d0 113d2 113e1-113e2 11438-1143f 11442-11444 ' +
|
|
16425
|
-
'11446 1145e 114b3-114b8 114ba 114bf-114c0 114c2-114c3 115b2-115b5 115bc-115bd 115bf-115c0 ' +
|
|
16426
|
-
'115dc-115dd 11633-1163a 1163d 1163f-11640 116ab 116ad 116b0-116b5 116b7 1171d 1171f ' +
|
|
16427
|
-
'11722-11725 11727-1172b 1182f-11837 11839-1183a 1193b-1193c 1193e 11943 119d4-119d7 ' +
|
|
16428
|
-
'119da-119db 119e0 11a01-11a06 11a09-11a0a 11a33-11a38 11a3b-11a3e 11a47 11a51-11a56 ' +
|
|
16429
|
-
'11a59-11a5b 11a8a-11a96 11a98-11a99 11b60 11b62-11b64 11b66 11c30-11c36 11c38-11c3d ' +
|
|
16430
|
-
'11c92-11ca7 11caa-11cb0 11cb2-11cb3 11cb5-11cb6 11d31-11d36 11d3a 11d3c-11d3d 11d3f-11d45 ' +
|
|
16431
|
-
'11d47 11d90-11d91 11d95 11d97 11df0 11ef3-11ef4 11f00-11f01 11f36-11f3a 11f40 11f42 11f5a ' +
|
|
16432
|
-
'13440 13447-13455 1611e-16129 1612d-1612f 16af0-16af4 16b30-16b36 16f4f 16f8f-16f92 16fe4 ' +
|
|
16433
|
-
'1bc9d-1bc9e 1cf00-1cf2d 1cf30-1cf46 1d127-1d128 1d167-1d169 1d17b-1d182 1d185-1d18b ' +
|
|
16434
|
-
'1d1aa-1d1ad 1d242-1d244 1d25b-1d25c 1da00-1da36 1da3b-1da6c 1da75 1da84 1da9b-1da9f ' +
|
|
16435
|
-
'1daa1-1daaf 1e000-1e006 1e008-1e018 1e01b-1e021 1e023-1e024 1e026-1e02a 1e08f 1e130-1e136 ' +
|
|
16436
|
-
'1e2ae 1e2ec-1e2ef 1e4ec-1e4ef 1e5ee-1e5ef 1e6e3 1e6e6 1e6ee-1e6ef 1e6f5 1e8d0-1e8d6 ' +
|
|
16437
|
-
'1e944-1e94a e0100-e01ef',
|
|
16438
|
-
ON:
|
|
16439
|
-
'21-22 26-2a 3b-40 5b-60 7b-7e a1 a6-a9 ab-ac ae-af b4 b6-b8 bb-bf d7 f7 2b9-2ba 2c2-2cf ' +
|
|
16440
|
-
'2d2-2df 2e5-2ed 2ef-2ff 374-375 37e 384-385 387 3f6 58a 58d-58e 606-607 60e-60f 6de 6e9 ' +
|
|
16441
|
-
'7f6-7f9 bf3-bf8 bfa c78-c7e f3a-f3d 1390-1399 1400 169b-169c 17f0-17f9 1800-180a 1940 ' +
|
|
16442
|
-
'1944-1945 19de-19ff 1fbd 1fbf-1fc1 1fcd-1fcf 1fdd-1fdf 1fed-1fef 1ffd-1ffe 2010-2027 ' +
|
|
16443
|
-
'2035-2043 2045-205e 207c-207e 208c-208f 2100-2101 2103-2106 2108-2109 2114 2116-2118 ' +
|
|
16444
|
-
'211e-2123 2125 2127 2129 213a-213b 2140-2144 214a-214d 2150-215f 2189-218b 2190-2211 ' +
|
|
16445
|
-
'2214-2335 237b-2394 2396-2429 2440-244a 2460-2487 24ea-26ab 26ad-27ff 2900-2b73 2b76-2bff ' +
|
|
16446
|
-
'2ce5-2cea 2cf9-2cff 2e00-2e5d 2e60-2e63 2e80-2e99 2e9b-2ef3 2f00-2fd5 2ff0-2fff 3001-3004 ' +
|
|
16447
|
-
'3008-3020 3030 3036-3037 303d-303f 309b-309c 30a0 30fb 31c0-31e5 31ef 321d-321e 3250-325f ' +
|
|
16448
|
-
'327c-327e 32b1-32bf 32cc-32cf 3377-337a 33de-33df 33ff 4dc0-4dff a490-a4c6 a60d-a60f a673 ' +
|
|
16449
|
-
'a67e-a67f a700-a721 a788 a828-a82b a874-a877 ab6a-ab6b fbc3-fbd2 fd3e-fd4f fd90-fd91 ' +
|
|
16450
|
-
'fdc8-fdcf fdfd-fdff fe10-fe19 fe30-fe4f fe51 fe54 fe56-fe5e fe60-fe61 fe64-fe66 fe68 fe6b ' +
|
|
16451
|
-
'ff01-ff02 ff06-ff0a ff1b-ff20 ff3b-ff40 ff5b-ff65 ffe2-ffe4 ffe8-ffee fff9-fffd 10101 ' +
|
|
16452
|
-
'10140-1018c 10190-1019c 101a0 1091f 10b39-10b3f 10d6e 10ed0-10ed8 11052-11065 11660-1166c ' +
|
|
16453
|
-
'11fd5-11fdc 11fe1-11ff1 16fe2 1cc00-1ccd5 1ccfa-1ccfc 1cd00-1ceb3 1ceba-1ced0 1ced2-1ced4 ' +
|
|
16454
|
-
'1cedd-1cefd 1d1e9-1d1ea 1d200-1d241 1d245 1d300-1d356 1d6c1 1d6db 1d6fb 1d715 1d735 1d74f ' +
|
|
16455
|
-
'1d76f 1d789 1d7a9 1d7c3 1db00-1db1c 1eef0-1eef1 1f000-1f02b 1f030-1f093 1f0a0-1f0ae ' +
|
|
16456
|
-
'1f0b1-1f0bf 1f0c1-1f0cf 1f0d1-1f0f5 1f10b-1f10f 1f12f 1f16a-1f16f 1f1ad 1f260-1f265 ' +
|
|
16457
|
-
'1f300-1f6d9 1f6dc-1f6ec 1f6f0-1f6fc 1f700-1f7d9 1f7db 1f7e0-1f7eb 1f7f0-1f80b 1f810-1f847 ' +
|
|
16458
|
-
'1f850-1f859 1f860-1f887 1f890-1f8ad 1f8b0-1f8bb 1f8c0-1f8c1 1f8d0-1f8d8 1f900-1fa57 ' +
|
|
16459
|
-
'1fa60-1fa6d 1fa70-1fa7c 1fa80-1fac6 1fac8 1facc-1fadd 1fadf-1faeb 1faef-1fafa 1fb00-1fb92 ' +
|
|
16460
|
-
'1fb94-1fbef 1fbfa',
|
|
16461
|
-
R:
|
|
16462
|
-
'590 5be 5c0 5c3 5c6 5ca-5ff 7c0-7ea 7f4-7f5 7fa-7fc 7fe-815 81a 824 828 82e-858 85c-85f 200f ' +
|
|
16463
|
-
'fb1d fb1f-fb28 fb2a-fb4f 10800-1091e 10920-10a00 10a04 10a07-10a0b 10a10-10a37 10a3b-10a3e ' +
|
|
16464
|
-
'10a40-10ae4 10ae7-10b38 10b40-10cff 10d4a-10d68 10d6f-10e5f 10e7f-10eaa 10ead-10ebf ' +
|
|
16465
|
-
'10f00-10f2f 10f70-10f81 10f86-10fff 1e800-1e8cf 1e8d7-1e943 1e94b-1ec6f 1ecc0-1ecff ' +
|
|
16466
|
-
'1ed50-1edff 1ef00-1efff',
|
|
16467
|
-
S:
|
|
16468
|
-
'9 b 1f',
|
|
16469
|
-
WS:
|
|
16470
|
-
'c 20 1680 2000-200a 2028 205f 3000'
|
|
16471
|
-
};
|
|
16621
|
+
const ACCEPTED_ATTACHMENT_KINDS = Object.freeze({
|
|
16622
|
+
images: Object.freeze(['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif', 'bmp', 'tif', 'tiff', 'avif']),
|
|
16623
|
+
documents: Object.freeze(['pdf', 'docx', 'xlsx', 'pptx', 'txt', 'csv', 'tsv', 'log', 'json']),
|
|
16624
|
+
recordings: Object.freeze(['mp4', 'mov', 'webm', 'm4a', 'mp3', 'wav'])
|
|
16625
|
+
});
|
|
16472
16626
|
|
|
16473
|
-
/**
|
|
16474
|
-
const
|
|
16475
|
-
|
|
16476
|
-
|
|
16477
|
-
'27e6:27e7 27e8:27e9 27ea:27eb 27ec:27ed 27ee:27ef 2983:2984 2985:2986 2987:2988 2989:298a ' +
|
|
16478
|
-
'298b:298c 298d:2990 298f:298e 2991:2992 2993:2994 2995:2996 2997:2998 29d8:29d9 29da:29db ' +
|
|
16479
|
-
'29fc:29fd 2e22:2e23 2e24:2e25 2e26:2e27 2e28:2e29 2e55:2e56 2e57:2e58 2e59:2e5a 2e5b:2e5c ' +
|
|
16480
|
-
'2e62:2e63 3008:3009 300a:300b 300c:300d 300e:300f 3010:3011 3014:3015 3016:3017 3018:3019 ' +
|
|
16481
|
-
'301a:301b fe59:fe5a fe5b:fe5c fe5d:fe5e ff08:ff09 ff3b:ff3d ff5b:ff5d ff5f:ff60 ff62:ff63';
|
|
16627
|
+
/** Every extension a ticket's file may end in: ACCEPTED_ATTACHMENT_KINDS's, in its order. */
|
|
16628
|
+
const ACCEPTED_ATTACHMENT_EXTENSIONS = Object.freeze(Object.values(ACCEPTED_ATTACHMENT_KINDS).flat());
|
|
16629
|
+
|
|
16630
|
+
const ACCEPTED_EXTENSION_SET = new Set(ACCEPTED_ATTACHMENT_EXTENSIONS);
|
|
16482
16631
|
|
|
16483
16632
|
/**
|
|
16484
|
-
*
|
|
16485
|
-
*
|
|
16486
|
-
*
|
|
16487
|
-
*
|
|
16488
|
-
*
|
|
16489
|
-
*
|
|
16490
|
-
*
|
|
16491
|
-
*
|
|
16492
|
-
*
|
|
16493
|
-
*
|
|
16494
|
-
* A reader reads letters, not code points, and reads them in the order they
|
|
16495
|
-
* are laid out, so a text is judged the way it is read:
|
|
16496
|
-
* - in each form a surface shows it in: a lone surrogate, a code unit no
|
|
16497
|
-
* other pairs with (a JSON escape such as \ud800 puts one in a string), is
|
|
16498
|
-
* shown as U+FFFD REPLACEMENT CHARACTER where the text is carried as UTF-8
|
|
16499
|
-
* (a From line's encoded-word), and as itself where a JSON answer carries
|
|
16500
|
-
* it (the answer writes the escape \ud800, and a JavaScript client's
|
|
16501
|
-
* JSON.parse restores the surrogate), which the client lays out as the
|
|
16502
|
-
* left-to-right character Unicode classes it as; U+FFFD is a neutral,
|
|
16503
|
-
* which joins the right-to-left run around it, and the surrogate splits
|
|
16504
|
-
* that run, so a text that holds one is read both ways (formsShown);
|
|
16505
|
-
* - in NFC: canonically equivalent texts show alike, so the rule reads one
|
|
16506
|
-
* text for all of them, a precomposed character for the character and marks
|
|
16507
|
-
* it decomposes to (U+00CC, an I with a grave accent, for I and U+0300
|
|
16508
|
-
* COMBINING GRAVE ACCENT) and a Hangul syllable for its jamo, each composed
|
|
16509
|
-
* character a reader may pass over wherever they may pass over its parts;
|
|
16510
|
-
* - each character as the Latin letters it passes for
|
|
16511
|
-
* (./organization-name-unicode.js LETTER_READINGS, derived from Unicode's
|
|
16512
|
-
* confusables, names and compatibility decompositions and a hand list of
|
|
16513
|
-
* lookalikes, the alphabets fancy-text generators substitute for Latin ones
|
|
16514
|
-
* among them; any other character through NFKD), a character at times
|
|
16515
|
-
* reading as either of two letters (U+028B, a v with a hook, is a u or a v),
|
|
16516
|
-
* and i and l as one letter, since a capital I and a small l are one glyph
|
|
16517
|
-
* in most sans-serif faces;
|
|
16518
|
-
* - a character that reads as no letter (a space, punctuation, an invisible
|
|
16519
|
-
* character) passed over, so it never breaks a word; the marks drawn on a
|
|
16520
|
-
* character, each read just before that character or just after it, in any
|
|
16521
|
-
* order, or not at all; and a character a reader may take for a letter or
|
|
16522
|
-
* pass over, read where it stands or not at all (OPTIONAL_LETTERS): a
|
|
16523
|
-
* superscript or subscript form, drawn small beside a word's letters; a
|
|
16524
|
-
* character whose letters are a resemblance only, a fancy-text generator's
|
|
16525
|
-
* letter among them (U+A317 YI SYLLABLE SOT, an s, is drawn as U+00A7
|
|
16526
|
-
* SECTION SIGN); a digit, punctuation mark or symbol that passes for a
|
|
16527
|
-
* letter (`1`, `$`, `+`), or a letter drawn as one; and a bare vertical
|
|
16528
|
-
* stroke (`|`, `l`, `I`), which reads as a separator as readily as an l; so
|
|
16529
|
-
* none of those breaks a word either, and a character breaks one only where
|
|
16530
|
-
* a reader must read it as letters: it is a form of them, or UTS #39 draws
|
|
16531
|
-
* it as Latin letters alone;
|
|
16532
|
-
* - in every order it can be laid out in: as stored, and as the Unicode
|
|
16533
|
-
* bidirectional algorithm (UAX #9) lays it out in a left-to-right and in a
|
|
16534
|
-
* right-to-left paragraph (an inbox in a right-to-left language, or a
|
|
16535
|
-
* client that takes the direction from the text's first letter), where a
|
|
16536
|
-
* right-to-left letter or mark, or an Arabic digit, between Latin words
|
|
16537
|
-
* reverses their order: "Vault", U+05BE HEBREW PUNCTUATION MAQAF, "Spark" is
|
|
16538
|
-
* laid out in a right-to-left paragraph as "Spark", the maqaf, "Vault".
|
|
16539
|
-
* An explicit direction control (holdsDirectionControl, ./display-text.js)
|
|
16540
|
-
* sets the direction of the text after it beyond what this lays out, so a
|
|
16541
|
-
* caller that judges what a reader sees refuses it as well, as
|
|
16542
|
-
* isReservedDisplayText, for any text an organization shows under its name,
|
|
16543
|
-
* and isReservedOrganizationName do. Both also judge a text at every cut of it
|
|
16544
|
-
* as stored, each cut read in this way, since the platform shows a text cut to
|
|
16545
|
-
* fit. The implicit marks are no such control: each is a strong character of
|
|
16546
|
-
* its direction, laid out as a letter of that direction is.
|
|
16547
|
-
*
|
|
16548
|
-
* BROWSER-SAFE: imports only ./display-text.js and
|
|
16549
|
-
* ./organization-name-unicode.js, neither of which imports anything, and needs
|
|
16550
|
-
* String.prototype.isWellFormed and toWellFormed (ES2024: Chrome 111,
|
|
16551
|
-
* Firefox 119, Safari 16.4).
|
|
16633
|
+
* The extensions Forge never completes a saved name with (lowercase, no dot):
|
|
16634
|
+
* a vault download's name that shows no extension the MIME registry knows is
|
|
16635
|
+
* completed with its type's registered one only when that is none of these
|
|
16636
|
+
* (./media-type-node.js withMediaTypeExtension), so no download saves as a
|
|
16637
|
+
* program, a script, a page or any file a desktop acts on when it is opened.
|
|
16638
|
+
* That completion is all that reads the list: a ticket takes only the
|
|
16639
|
+
* extensions it accepts (ACCEPTED_ATTACHMENT_EXTENSIONS), none of them one of
|
|
16640
|
+
* these. Every extension Outlook blocks as an attachment is one, held to
|
|
16641
|
+
* Microsoft's list by attachment-policy.test.js. The list is ordered by kind.
|
|
16552
16642
|
*/
|
|
16643
|
+
const REFUSED_EXTENSIONS = Object.freeze([
|
|
16644
|
+
'exe', 'dll', 'scr', 'com', 'pif', 'cpl', 'msc', 'bat', 'cmd',
|
|
16645
|
+
'ps1', 'ps1xml', 'ps2', 'ps2xml', 'psc1', 'psc2', 'psd1', 'psdm1', 'pssc', 'cdxml',
|
|
16646
|
+
'msh', 'msh1', 'msh2', 'mshxml', 'msh1xml', 'msh2xml',
|
|
16647
|
+
'vb', 'vbs', 'vbe', 'js', 'jse', 'ws', 'wsf', 'wsh', 'wsc', 'sct',
|
|
16648
|
+
'msi', 'msp', 'mst', 'msu', 'cab', 'diagcab', 'inf', 'jar', 'hta', 'htc', 'reg',
|
|
16649
|
+
'lnk', 'url', 'website', 'shb', 'shs', 'scf', 'xnk', 'grp', 'library-ms', 'search-ms',
|
|
16650
|
+
'settingcontent-ms', 'appcontent-ms', 'theme', 'wsb', 'gadget', 'osd', 'bgi', 'udl', 'ins', 'isp',
|
|
16651
|
+
'webpnp', 'printerexport',
|
|
16652
|
+
'iso', 'img', 'vhd', 'vhdx', 'dmg', 'app',
|
|
16653
|
+
'sh', 'bash', 'zsh', 'ksh', 'csh', 'tcl', 'py', 'pyc', 'pyo', 'pyw', 'pyz', 'pyzw', 'pl', 'rb',
|
|
16654
|
+
'php', 'phtml', 'asp', 'aspx',
|
|
16655
|
+
'html', 'htm', 'xhtml', 'shtml', 'shtm', 'xht', 'xhtm', 'mht', 'mhtml', 'svg', 'svgz', 'xml', 'xsl', 'xslt',
|
|
16656
|
+
'rdf', 'xul',
|
|
16657
|
+
'docm', 'dotm', 'xlsm', 'xltm', 'xlam', 'pptm', 'potm', 'ppam', 'sldm', 'ppsm', 'xlsb', 'xla', 'xlm', 'xll',
|
|
16658
|
+
'application', 'appref-ms', 'xbap', 'appinstaller', 'appx', 'appxbundle', 'msix', 'msixbundle',
|
|
16659
|
+
'chm', 'its', 'hlp', 'cnt', 'hpj',
|
|
16660
|
+
'mdb', 'adp', 'ade', 'mag', 'mad', 'maf', 'mam', 'maq', 'mar', 'mas', 'mat', 'mav', 'maw', 'mda', 'mde',
|
|
16661
|
+
'mdt', 'mdw', 'mdz',
|
|
16662
|
+
'prf', 'ops', 'pst',
|
|
16663
|
+
'fxp', 'prg', 'bas', 'vbp', 'vsmacros', 'vsw', 'pcd', 'plg',
|
|
16664
|
+
'cer', 'der', 'crt', 'cert', 'pem', 'p12', 'pfx', 'pkcs12', 'p7b', 'p7c', 'p7r', 'spc',
|
|
16665
|
+
'jnlp', 'class', 'air', 'crx', 'xpi', 'oxt', 'vbox-extpack',
|
|
16666
|
+
'apk', 'pkg', 'mpkg', 'deb', 'udeb', 'rpm', 'run',
|
|
16667
|
+
'asx', 'wax', 'wvx', 'wmx', 'wmd',
|
|
16668
|
+
'mau', 'mcf', 'tmp'
|
|
16669
|
+
]);
|
|
16553
16670
|
|
|
16554
|
-
/**
|
|
16555
|
-
|
|
16671
|
+
/**
|
|
16672
|
+
* Why a name or a head slice is refused, as the two refusal functions report
|
|
16673
|
+
* it. REFUSED_EXTENSION: the extension the name's saved copy opens as is none
|
|
16674
|
+
* a ticket accepts, or the name shows none.
|
|
16675
|
+
*/
|
|
16676
|
+
const ATTACHMENT_REFUSALS = Object.freeze({
|
|
16677
|
+
EMPTY: 'empty',
|
|
16678
|
+
TOO_LONG: 'too_long',
|
|
16679
|
+
UNSAFE_NAME: 'unsafe_name',
|
|
16680
|
+
REFUSED_EXTENSION: 'refused_extension',
|
|
16681
|
+
EXECUTABLE: 'executable',
|
|
16682
|
+
SCRIPT: 'script',
|
|
16683
|
+
MARKUP: 'markup'
|
|
16684
|
+
});
|
|
16556
16685
|
|
|
16557
|
-
/**
|
|
16558
|
-
const
|
|
16686
|
+
/** How many leading bytes the sniff reads; a caller slices `file.slice(0, ATTACHMENT_SNIFF_BYTES)`. */
|
|
16687
|
+
const ATTACHMENT_SNIFF_BYTES = 4096;
|
|
16559
16688
|
|
|
16560
|
-
|
|
16561
|
-
const BRAND_BITS = new Map(
|
|
16562
|
-
[...new Set(Array.from(RESERVED_BRAND_TOKENS.join(''), foldLetter))].map((letter, index) => [letter, 1 << index])
|
|
16563
|
-
);
|
|
16689
|
+
new Set(REFUSED_EXTENSIONS);
|
|
16564
16690
|
|
|
16565
|
-
/**
|
|
16566
|
-
|
|
16567
|
-
|
|
16568
|
-
|
|
16569
|
-
|
|
16570
|
-
|
|
16691
|
+
/** Leading byte sequences of code a desktop would run. */
|
|
16692
|
+
const EXECUTABLE_SIGNATURES = Object.freeze([
|
|
16693
|
+
[0x4d, 0x5a], // MZ: Windows PE
|
|
16694
|
+
[0x7f, 0x45, 0x4c, 0x46], // ELF
|
|
16695
|
+
[0xfe, 0xed, 0xfa, 0xce], // Mach-O 32-bit
|
|
16696
|
+
[0xfe, 0xed, 0xfa, 0xcf], // Mach-O 64-bit
|
|
16697
|
+
[0xce, 0xfa, 0xed, 0xfe], // Mach-O 32-bit, reversed
|
|
16698
|
+
[0xcf, 0xfa, 0xed, 0xfe], // Mach-O 64-bit, reversed
|
|
16699
|
+
[0xca, 0xfe, 0xba, 0xbe], // Mach-O universal / Java class
|
|
16700
|
+
[0xbe, 0xba, 0xfe, 0xca] // Mach-O universal, reversed
|
|
16701
|
+
]);
|
|
16571
16702
|
|
|
16572
|
-
|
|
16573
|
-
const TOKEN_MASKS = RESERVED_BRAND_TOKENS.map((token) => Array.from(token, lettersMask));
|
|
16703
|
+
const SHEBANG = Object.freeze([0x23, 0x21]);
|
|
16574
16704
|
|
|
16575
|
-
/**
|
|
16576
|
-
|
|
16577
|
-
|
|
16578
|
-
|
|
16579
|
-
|
|
16580
|
-
|
|
16705
|
+
/**
|
|
16706
|
+
* A ZIP local file header's signature (`PK\x03\x04`): the first bytes of
|
|
16707
|
+
* every Office Open XML package (.docx, .xlsx, .pptx), the only ZIP a ticket
|
|
16708
|
+
* takes. Its parts are XML by definition, and a package whose ZIP stores them
|
|
16709
|
+
* uncompressed, as common web exporters write one, shows its first part's
|
|
16710
|
+
* `<?xml` declaration in the first kilobyte; no browser reads a file that
|
|
16711
|
+
* opens with this signature as a page.
|
|
16712
|
+
*/
|
|
16713
|
+
const ZIP_LOCAL_FILE_SIGNATURE = Object.freeze([0x50, 0x4b, 0x03, 0x04]);
|
|
16714
|
+
|
|
16715
|
+
/** Document openers a browser would run as a page; matched case-insensitively in the first kilobyte. */
|
|
16716
|
+
const MARKUP_OPENERS = Object.freeze(['<?xml', '<!doctype html', '<html', '<script', '<svg']);
|
|
16717
|
+
const MARKUP_WINDOW = 1024;
|
|
16718
|
+
|
|
16719
|
+
function startsWith(bytes, prefix) {
|
|
16720
|
+
return bytes.length >= prefix.length && prefix.every((byte, index) => bytes[index] === byte);
|
|
16581
16721
|
}
|
|
16582
16722
|
|
|
16583
|
-
/**
|
|
16584
|
-
|
|
16585
|
-
|
|
16586
|
-
|
|
16587
|
-
|
|
16723
|
+
/**
|
|
16724
|
+
* What stops `name` from naming a ticket attachment, or null when nothing does.
|
|
16725
|
+
* Its extension is the one a saved copy opens as (lastExtension), and a ticket
|
|
16726
|
+
* takes it only when that is one it accepts (ACCEPTED_ATTACHMENT_EXTENSIONS),
|
|
16727
|
+
* so a name of no extension is refused, and neither a SparkVault document's
|
|
16728
|
+
* two-part extension ("invoice.note.html"), trailing dots or spaces
|
|
16729
|
+
* ("page.html."), an invisible character ("evil.ex<U+034F>e") nor a space
|
|
16730
|
+
* Firefox closes up ("evil.ex e", which Firefox saves as "evil.exe") passes
|
|
16731
|
+
* for an accepted one; a name that opens as one is taken however it is
|
|
16732
|
+
* written ("Photo.JPG", "report.pdf.", "Scan. pdf").
|
|
16733
|
+
*
|
|
16734
|
+
* @param {unknown} name
|
|
16735
|
+
* @returns {string|null} One of ATTACHMENT_REFUSALS, or null
|
|
16736
|
+
*/
|
|
16737
|
+
function attachmentNameRefusal(name) {
|
|
16738
|
+
if (typeof name !== 'string' || name.length === 0) return ATTACHMENT_REFUSALS.EMPTY;
|
|
16739
|
+
if (name.length > INGOT_NAME_MAX) return ATTACHMENT_REFUSALS.TOO_LONG;
|
|
16740
|
+
if (storableFilenameProblem(name) !== null) return ATTACHMENT_REFUSALS.UNSAFE_NAME;
|
|
16741
|
+
if (!ACCEPTED_EXTENSION_SET.has(lastExtension(name))) return ATTACHMENT_REFUSALS.REFUSED_EXTENSION;
|
|
16742
|
+
return null;
|
|
16588
16743
|
}
|
|
16589
16744
|
|
|
16590
|
-
/**
|
|
16591
|
-
|
|
16745
|
+
/**
|
|
16746
|
+
* What the first bytes of a file say it is that no ticket may carry, or null
|
|
16747
|
+
* when they say nothing of the kind: a program, a script, or markup a browser
|
|
16748
|
+
* would run as a page, which a ZIP package's head is never read for
|
|
16749
|
+
* (ZIP_LOCAL_FILE_SIGNATURE). Reads at most ATTACHMENT_SNIFF_BYTES.
|
|
16750
|
+
*
|
|
16751
|
+
* @param {Uint8Array} headBytes
|
|
16752
|
+
* @returns {string|null} One of ATTACHMENT_REFUSALS, or null
|
|
16753
|
+
*/
|
|
16754
|
+
function attachmentSniffRefusal(headBytes) {
|
|
16755
|
+
const bytes = headBytes.subarray(0, ATTACHMENT_SNIFF_BYTES);
|
|
16756
|
+
if (EXECUTABLE_SIGNATURES.some((signature) => startsWith(bytes, signature))) return ATTACHMENT_REFUSALS.EXECUTABLE;
|
|
16757
|
+
if (startsWith(bytes, SHEBANG)) return ATTACHMENT_REFUSALS.SCRIPT;
|
|
16758
|
+
if (startsWith(bytes, ZIP_LOCAL_FILE_SIGNATURE)) return null;
|
|
16759
|
+
// Latin-1 decoding keeps one byte per character, so a UTF-8 or Latin-1
|
|
16760
|
+
// document's ASCII markup reads the same; a BOM or leading whitespace is
|
|
16761
|
+
// skipped by searching the window instead of anchoring at offset 0.
|
|
16762
|
+
const text = String.fromCharCode(...bytes.subarray(0, MARKUP_WINDOW)).toLowerCase();
|
|
16763
|
+
if (MARKUP_OPENERS.some((opener) => text.includes(opener))) return ATTACHMENT_REFUSALS.MARKUP;
|
|
16764
|
+
return null;
|
|
16765
|
+
}
|
|
16592
16766
|
|
|
16593
|
-
/**
|
|
16594
|
-
|
|
16595
|
-
|
|
16596
|
-
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16767
|
+
/**
|
|
16768
|
+
* A byte count as people read it: "500 B", "1 KB", "1.5 MB", "5 GB", in
|
|
16769
|
+
* binary units (1 KB = 1024 B) up to TB, with at most `decimals` decimal
|
|
16770
|
+
* places and no trailing zeros. The one size formatter every surface writes
|
|
16771
|
+
* sizes with; a runtime that cannot import app-sdk runs a generated mirror of
|
|
16772
|
+
* it (module-mirrors).
|
|
16773
|
+
*
|
|
16774
|
+
* A count that is missing, not a finite number, zero or negative reads
|
|
16775
|
+
* "0 B"; a count past the largest unit is written in TB.
|
|
16776
|
+
*
|
|
16777
|
+
* BROWSER-SAFE: data only, no imports.
|
|
16778
|
+
*/
|
|
16600
16779
|
|
|
16601
|
-
|
|
16602
|
-
const
|
|
16603
|
-
|
|
16604
|
-
|
|
16605
|
-
|
|
16606
|
-
|
|
16607
|
-
|
|
16780
|
+
const UNITS = Object.freeze(['B', 'KB', 'MB', 'GB', 'TB']);
|
|
16781
|
+
const STEP = 1024;
|
|
16782
|
+
|
|
16783
|
+
/**
|
|
16784
|
+
* @param {number|null|undefined} bytes
|
|
16785
|
+
* @param {number} [decimals=1] - The most decimal places shown
|
|
16786
|
+
* @returns {string}
|
|
16787
|
+
*/
|
|
16788
|
+
function formatBytes(bytes, decimals = 1) {
|
|
16789
|
+
if (typeof bytes !== 'number' || !Number.isFinite(bytes) || bytes <= 0) return `0 ${UNITS[0]}`;
|
|
16790
|
+
const unit = Math.min(Math.max(Math.floor(Math.log(bytes) / Math.log(STEP)), 0), UNITS.length - 1);
|
|
16791
|
+
return `${parseFloat((bytes / STEP ** unit).toFixed(decimals))} ${UNITS[unit]}`;
|
|
16608
16792
|
}
|
|
16609
16793
|
|
|
16610
16794
|
/**
|
|
16611
|
-
*
|
|
16612
|
-
*
|
|
16613
|
-
*
|
|
16614
|
-
*
|
|
16615
|
-
*
|
|
16795
|
+
* What stops a file from joining a message, decided in the browser before any
|
|
16796
|
+
* upload starts: the one check the portal's editor and the console's
|
|
16797
|
+
* composer run. The server never reads an uploaded file's plaintext, so the
|
|
16798
|
+
* check on a file's first bytes can only run here, over the file itself; the
|
|
16799
|
+
* name rule runs here and again on the server when the upload is initiated.
|
|
16800
|
+
* Both are the platform's one attachment policy (./attachment-policy.js);
|
|
16801
|
+
* this adds only what no upload can take: an empty file, one past the most
|
|
16802
|
+
* its uploader may attach (a customer ./help-desk-contract.js
|
|
16803
|
+
* CUSTOMER_ATTACHMENT_MAX_BYTES, an operator MAX_ATTACHMENT_BYTES), and one
|
|
16804
|
+
* the browser can no longer read (changed or moved on disk after it was
|
|
16805
|
+
* picked). Beside the check, the sentence each refusal reads, the one
|
|
16806
|
+
* phrase that names the files a ticket accepts, and what a customer's file
|
|
16807
|
+
* picker states and filters before any file is chosen.
|
|
16808
|
+
*
|
|
16809
|
+
* BROWSER-SAFE: reads the file it is handed through the Blob API, which
|
|
16810
|
+
* Node's File has too.
|
|
16616
16811
|
*/
|
|
16617
|
-
const WORD_OFFSETS = TOKEN_MASKS.map((_, word) =>
|
|
16618
|
-
TOKEN_MASKS.slice(0, word).reduce((offset, token) => offset + token.length, 0));
|
|
16619
16812
|
|
|
16620
|
-
/** Each word's first letter, where a new spelling can start at any letter read. */
|
|
16621
|
-
WORD_OFFSETS.reduce((bits, offset) => bits | (1 << offset), 0);
|
|
16622
16813
|
|
|
16623
|
-
/**
|
|
16624
|
-
|
|
16814
|
+
/** The files refused beyond the policy's. */
|
|
16815
|
+
const FILE_REFUSALS = Object.freeze({ EMPTY_FILE: 'empty_file', TOO_LARGE: 'too_large', UNREADABLE: 'unreadable' });
|
|
16625
16816
|
|
|
16626
|
-
|
|
16817
|
+
/** The first bytes of `file`, or null when the browser cannot read them. */
|
|
16818
|
+
async function headOf(file) {
|
|
16819
|
+
try {
|
|
16820
|
+
return new Uint8Array(await file.slice(0, ATTACHMENT_SNIFF_BYTES).arrayBuffer());
|
|
16821
|
+
} catch {
|
|
16822
|
+
return null;
|
|
16823
|
+
}
|
|
16824
|
+
}
|
|
16627
16825
|
|
|
16628
|
-
/**
|
|
16629
|
-
|
|
16630
|
-
|
|
16631
|
-
|
|
16826
|
+
/** A ceiling a file is held to: a positive whole number of bytes, or a TypeError. */
|
|
16827
|
+
function assertCeiling(maxBytes) {
|
|
16828
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1) throw new TypeError('A file is held to a ceiling of a positive whole number of bytes');
|
|
16829
|
+
}
|
|
16632
16830
|
|
|
16633
16831
|
/**
|
|
16634
|
-
*
|
|
16635
|
-
*
|
|
16636
|
-
* once so the three cannot disagree about a status, a label, a limit, a timing
|
|
16637
|
-
* or an event's visibility.
|
|
16832
|
+
* Why `file` cannot be attached, or null when it may be: its name first, then
|
|
16833
|
+
* its size against `maxBytes`, then its first bytes.
|
|
16638
16834
|
*
|
|
16639
|
-
*
|
|
16640
|
-
*
|
|
16641
|
-
*
|
|
16642
|
-
*
|
|
16643
|
-
* a
|
|
16644
|
-
|
|
16645
|
-
|
|
16646
|
-
|
|
16647
|
-
|
|
16648
|
-
|
|
16649
|
-
|
|
16650
|
-
|
|
16835
|
+
* @param {File} file
|
|
16836
|
+
* @param {number} maxBytes - The most its uploader may attach: a customer
|
|
16837
|
+
* CUSTOMER_ATTACHMENT_MAX_BYTES, an operator MAX_ATTACHMENT_BYTES
|
|
16838
|
+
* @returns {Promise<string|null>} One of ATTACHMENT_REFUSALS or FILE_REFUSALS, or null
|
|
16839
|
+
* @throws {TypeError} For a ceiling that is not a positive whole number of bytes
|
|
16840
|
+
*/
|
|
16841
|
+
async function attachmentRefusal(file, maxBytes) {
|
|
16842
|
+
assertCeiling(maxBytes);
|
|
16843
|
+
const byName = attachmentNameRefusal(file.name);
|
|
16844
|
+
if (byName) return byName;
|
|
16845
|
+
if (file.size === 0) return FILE_REFUSALS.EMPTY_FILE;
|
|
16846
|
+
if (file.size > maxBytes) return FILE_REFUSALS.TOO_LARGE;
|
|
16847
|
+
const head = await headOf(file);
|
|
16848
|
+
return head ? attachmentSniffRefusal(head) : FILE_REFUSALS.UNREADABLE;
|
|
16849
|
+
}
|
|
16850
|
+
|
|
16851
|
+
/**
|
|
16852
|
+
* The words naming every kind of file a ticket accepts with its extensions,
|
|
16853
|
+
* the last kind joined by "and": `images (.jpg, .jpeg, ...), documents
|
|
16854
|
+
* (.pdf, ...) and recordings (.mp4, ...)`.
|
|
16651
16855
|
*
|
|
16652
|
-
*
|
|
16653
|
-
*
|
|
16654
|
-
* From local parts no team alias may take (./mail-products.js) and the brand
|
|
16655
|
-
* rule no team alias may read as (./organization-name.js).
|
|
16856
|
+
* @param {Readonly<Record<string, readonly string[]>>} kinds - ACCEPTED_ATTACHMENT_KINDS
|
|
16857
|
+
* @returns {string}
|
|
16656
16858
|
*/
|
|
16859
|
+
function acceptedKindsCopy(kinds) {
|
|
16860
|
+
const named = Object.entries(kinds).map(([kind, extensions]) => {
|
|
16861
|
+
const listed = extensions.map((extension) => `.${extension}`).join(', ');
|
|
16862
|
+
return `${kind} (${listed})`;
|
|
16863
|
+
});
|
|
16864
|
+
return `${named.slice(0, -1).join(', ')} and ${named.at(-1)}`;
|
|
16865
|
+
}
|
|
16657
16866
|
|
|
16867
|
+
/**
|
|
16868
|
+
* The files a ticket accepts, in the one phrase every surface names them by,
|
|
16869
|
+
* built from the policy's own list (ACCEPTED_ATTACHMENT_KINDS): the sentence
|
|
16870
|
+
* refusing any other file reads it, and so do the API reference
|
|
16871
|
+
* (apps/api/openapi/overlay.mjs) and the help desk's page on the site
|
|
16872
|
+
* (apps/www/_data/helpDeskAttachments.js).
|
|
16873
|
+
*/
|
|
16874
|
+
const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
16658
16875
|
|
|
16659
16876
|
/**
|
|
16660
|
-
*
|
|
16661
|
-
*
|
|
16662
|
-
* the
|
|
16663
|
-
* product writes from (MAIL_PRODUCTS fromLocalPart), so no team writes from
|
|
16664
|
-
* the address Notify writes from on a domain both products use.
|
|
16877
|
+
* What a customer's file picker says before any file is chosen: what to add,
|
|
16878
|
+
* how many files a message takes and how large each may be. The portal's
|
|
16879
|
+
* editor and the SDK's support form show it under their pickers.
|
|
16665
16880
|
*/
|
|
16666
|
-
|
|
16667
|
-
|
|
16668
|
-
'admin', 'administrator', 'root', 'mailer-daemon', 'no-reply', 'noreply', 'bounce', 'bounces',
|
|
16669
|
-
'dmarc', 'spf', 'dkim', 'probe',
|
|
16670
|
-
'www', 'api', 'mail', 'smtp', 'mx', 'help', 'sparkvault',
|
|
16671
|
-
...MAIL_PRODUCT_KEYS.map((key) => MAIL_PRODUCTS[key].fromLocalPart).filter((localPart) => localPart !== null)
|
|
16672
|
-
]);
|
|
16881
|
+
const CUSTOMER_ATTACHMENTS_HINT =
|
|
16882
|
+
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
16673
16883
|
|
|
16674
16884
|
/**
|
|
16675
|
-
*
|
|
16676
|
-
*
|
|
16677
|
-
*
|
|
16678
|
-
*
|
|
16679
|
-
* allowance, or the allowance is 0, which turns customer uploads off. A file
|
|
16680
|
-
* an email carried that the allowance refused is listed by the same reason
|
|
16681
|
-
* among the files its message left out (`email.skipped_attachments`).
|
|
16885
|
+
* A file input's `accept`: every extension a ticket accepts
|
|
16886
|
+
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
16887
|
+
* chooser offers those files first. A filter, never the check: a person can
|
|
16888
|
+
* still pick any file, and attachmentRefusal decides.
|
|
16682
16889
|
*/
|
|
16683
|
-
const
|
|
16684
|
-
|
|
16685
|
-
|
|
16890
|
+
const ATTACHMENT_INPUT_ACCEPT = ACCEPTED_ATTACHMENT_EXTENSIONS.map((extension) => `.${extension}`).join(',');
|
|
16891
|
+
|
|
16892
|
+
const REFUSAL_COPY = Object.freeze({
|
|
16893
|
+
[ATTACHMENT_REFUSALS.EMPTY]: 'This file has no name.',
|
|
16894
|
+
[ATTACHMENT_REFUSALS.TOO_LONG]: "This file's name is too long. Rename it and try again.",
|
|
16895
|
+
[ATTACHMENT_REFUSALS.UNSAFE_NAME]: "This file's name can't be used. Rename it and try again.",
|
|
16896
|
+
[ATTACHMENT_REFUSALS.REFUSED_EXTENSION]: `Files of this type can't be attached. You can attach ${ACCEPTED_ATTACHMENTS_COPY}.`,
|
|
16897
|
+
[ATTACHMENT_REFUSALS.EXECUTABLE]: "This file is a program, and programs can't be attached.",
|
|
16898
|
+
[ATTACHMENT_REFUSALS.SCRIPT]: "This file is a script, and scripts can't be attached.",
|
|
16899
|
+
[ATTACHMENT_REFUSALS.MARKUP]: "This file holds web page markup, which can't be attached.",
|
|
16900
|
+
[FILE_REFUSALS.EMPTY_FILE]: 'This file is empty.',
|
|
16901
|
+
[FILE_REFUSALS.UNREADABLE]: "This file couldn't be read. Remove it and pick it again."
|
|
16686
16902
|
});
|
|
16687
16903
|
|
|
16688
|
-
/**
|
|
16689
|
-
|
|
16904
|
+
/**
|
|
16905
|
+
* The sentence a person reads for a file larger than `maxBytes`, the ceiling
|
|
16906
|
+
* it was held to: the browser's check's (FILE_REFUSALS.TOO_LARGE), and the
|
|
16907
|
+
* server's, which names its own (`details.max_bytes` of a 413).
|
|
16908
|
+
*
|
|
16909
|
+
* @param {number} maxBytes
|
|
16910
|
+
* @returns {string}
|
|
16911
|
+
*/
|
|
16912
|
+
function tooLargeCopy(maxBytes) {
|
|
16913
|
+
assertCeiling(maxBytes);
|
|
16914
|
+
return `This file is larger than ${formatBytes(maxBytes)}.`;
|
|
16915
|
+
}
|
|
16690
16916
|
|
|
16691
|
-
/**
|
|
16692
|
-
|
|
16917
|
+
/**
|
|
16918
|
+
* The sentence a person reads for a refusal.
|
|
16919
|
+
*
|
|
16920
|
+
* @param {string} refusal - One of ATTACHMENT_REFUSALS or FILE_REFUSALS
|
|
16921
|
+
* @param {number} maxBytes - The ceiling attachmentRefusal held the file to
|
|
16922
|
+
* @returns {string}
|
|
16923
|
+
* @throws {TypeError} For a ceiling that is not a positive whole number of bytes
|
|
16924
|
+
*/
|
|
16925
|
+
function refusalCopy(refusal, maxBytes) {
|
|
16926
|
+
assertCeiling(maxBytes);
|
|
16927
|
+
if (refusal === FILE_REFUSALS.TOO_LARGE) return tooLargeCopy(maxBytes);
|
|
16928
|
+
return REFUSAL_COPY[refusal] ?? "This file can't be attached.";
|
|
16929
|
+
}
|
|
16693
16930
|
|
|
16694
16931
|
function createProgress() { return document.createElement('progress'); }
|
|
16695
16932
|
/** A failed mint's quota/size refusal remains a visible file error, never a silently omitted file. */
|
|
@@ -16726,12 +16963,12 @@ function createFormAttachments(client, prefix, context) {
|
|
|
16726
16963
|
input.name = 'attachments';
|
|
16727
16964
|
input.id = label.htmlFor;
|
|
16728
16965
|
input.multiple = true;
|
|
16729
|
-
input.accept =
|
|
16966
|
+
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
16730
16967
|
input.className = 'svhd-input';
|
|
16731
16968
|
const hint = document.createElement('p');
|
|
16732
16969
|
hint.id = `${prefix}-attachment-hint`;
|
|
16733
16970
|
hint.className = 'svhd-file-hint';
|
|
16734
|
-
hint.textContent =
|
|
16971
|
+
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
16735
16972
|
input.setAttribute('aria-describedby', hint.id);
|
|
16736
16973
|
const notice = document.createElement('p');
|
|
16737
16974
|
notice.className = 'svhd-error svhd-file-hint';
|
|
@@ -16942,6 +17179,7 @@ function createFormAttachments(client, prefix, context) {
|
|
|
16942
17179
|
element,
|
|
16943
17180
|
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
16944
17181
|
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
17182
|
+
get hasEntries() { return entries.length > 0; },
|
|
16945
17183
|
get busy() { return entries.some(entry => !!entry.operation); },
|
|
16946
17184
|
async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
|
|
16947
17185
|
lock(value) { locked = value; input.disabled = value || pickingDisabled; entries.forEach(controls); },
|
|
@@ -16979,18 +17217,24 @@ function notify(callback, value) {
|
|
|
16979
17217
|
// The host owns its callback. A confirmed send must never become a retry.
|
|
16980
17218
|
}
|
|
16981
17219
|
}
|
|
16982
|
-
|
|
17220
|
+
/** `https://{host}{path}` on the desk's own host, or null when the host is anything but a bare host name. */
|
|
17221
|
+
function hostedUrl(host, path) {
|
|
16983
17222
|
try {
|
|
16984
17223
|
const url = new URL(`https://${host}`);
|
|
16985
17224
|
if (url.host !== host || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
|
|
16986
17225
|
return null;
|
|
16987
|
-
url.pathname =
|
|
17226
|
+
url.pathname = path;
|
|
16988
17227
|
return url.href;
|
|
16989
17228
|
}
|
|
16990
17229
|
catch {
|
|
16991
17230
|
return null;
|
|
16992
17231
|
}
|
|
16993
17232
|
}
|
|
17233
|
+
/** Whether a field holds text of the customer's own: anything but nothing or what the host prefilled. */
|
|
17234
|
+
function edited(input, prefill) {
|
|
17235
|
+
const text = input.value.trim();
|
|
17236
|
+
return text !== '' && text !== (prefill ?? '').trim();
|
|
17237
|
+
}
|
|
16994
17238
|
function companySignInUrl(value) {
|
|
16995
17239
|
try {
|
|
16996
17240
|
const url = new URL(value ?? '');
|
|
@@ -17004,6 +17248,12 @@ function companySignInUrl(value) {
|
|
|
17004
17248
|
* Inject a ticket form using only the requester's customer API. Authentication
|
|
17005
17249
|
* is the desk's email-code flow or an explicit host-provided customer session.
|
|
17006
17250
|
* Files use the same direct resumable Forge ceremony as the hosted portal.
|
|
17251
|
+
*
|
|
17252
|
+
* A check the form makes itself (an empty subject, a short code) and the
|
|
17253
|
+
* server's refusal of a code read under the field they concern; the status
|
|
17254
|
+
* line carries the flow (a code sent, a send in progress or uncertain, a
|
|
17255
|
+
* changed sign-in, a server error). Closing with unsent work asks first.
|
|
17256
|
+
* A confirmed send replaces the form with its confirmation.
|
|
17007
17257
|
*/
|
|
17008
17258
|
function mountHelpDeskForm(client, options) {
|
|
17009
17259
|
const target = resolveTarget(options.target);
|
|
@@ -17022,6 +17272,30 @@ function mountHelpDeskForm(client, options) {
|
|
|
17022
17272
|
form.noValidate = true;
|
|
17023
17273
|
form.setAttribute('aria-labelledby', heading.id);
|
|
17024
17274
|
shell.body.append(heading, form);
|
|
17275
|
+
// A field's error is an alert only while it shows, so it is announced
|
|
17276
|
+
// even when focus already sits on the field it names.
|
|
17277
|
+
function setFieldError(entry, text) {
|
|
17278
|
+
entry.error.textContent = text;
|
|
17279
|
+
entry.error.setAttribute('role', 'alert');
|
|
17280
|
+
entry.error.hidden = false;
|
|
17281
|
+
entry.input.setAttribute('aria-invalid', 'true');
|
|
17282
|
+
const described = (entry.input.getAttribute('aria-describedby') ?? '').split(' ').filter(Boolean);
|
|
17283
|
+
if (!described.includes(entry.error.id))
|
|
17284
|
+
entry.input.setAttribute('aria-describedby', [...described, entry.error.id].join(' '));
|
|
17285
|
+
}
|
|
17286
|
+
function clearFieldError(entry) {
|
|
17287
|
+
if (entry.error.hidden)
|
|
17288
|
+
return;
|
|
17289
|
+
entry.error.textContent = '';
|
|
17290
|
+
entry.error.removeAttribute('role');
|
|
17291
|
+
entry.error.hidden = true;
|
|
17292
|
+
entry.input.removeAttribute('aria-invalid');
|
|
17293
|
+
const described = (entry.input.getAttribute('aria-describedby') ?? '').split(' ').filter((id) => id !== '' && id !== entry.error.id);
|
|
17294
|
+
if (described.length > 0)
|
|
17295
|
+
entry.input.setAttribute('aria-describedby', described.join(' '));
|
|
17296
|
+
else
|
|
17297
|
+
entry.input.removeAttribute('aria-describedby');
|
|
17298
|
+
}
|
|
17025
17299
|
function field(labelText, name, textarea = false) {
|
|
17026
17300
|
const wrapper = document.createElement('div');
|
|
17027
17301
|
wrapper.className = 'svhd-field';
|
|
@@ -17033,23 +17307,46 @@ function mountHelpDeskForm(client, options) {
|
|
|
17033
17307
|
input.id = label.htmlFor;
|
|
17034
17308
|
input.name = name;
|
|
17035
17309
|
input.className = textarea ? 'svhd-input svhd-description' : 'svhd-input';
|
|
17036
|
-
|
|
17037
|
-
|
|
17310
|
+
const error = document.createElement('p');
|
|
17311
|
+
error.id = `${input.id}-error`;
|
|
17312
|
+
error.className = 'svhd-field-error';
|
|
17313
|
+
error.hidden = true;
|
|
17314
|
+
wrapper.append(label, input, error);
|
|
17315
|
+
const created = { wrapper, input, error };
|
|
17316
|
+
input.addEventListener('input', () => clearFieldError(created));
|
|
17317
|
+
return created;
|
|
17038
17318
|
}
|
|
17039
17319
|
const subject = field('Subject', 'subject');
|
|
17040
17320
|
const description = field('Description', 'description', true);
|
|
17041
17321
|
const email = field('Email address', 'email');
|
|
17042
17322
|
const code = field('Email code', 'code');
|
|
17043
17323
|
const name = field('Your name', 'display_name');
|
|
17324
|
+
const fields = [subject, description, email, code, name];
|
|
17044
17325
|
subject.input.maxLength = 200;
|
|
17045
17326
|
subject.input.value = options.subject ?? '';
|
|
17046
17327
|
description.input.value = options.body ?? '';
|
|
17047
17328
|
email.input.type = 'email';
|
|
17048
17329
|
email.input.autocomplete = 'email';
|
|
17049
17330
|
code.input.inputMode = 'numeric';
|
|
17050
|
-
code.input.maxLength = 6;
|
|
17051
17331
|
code.input.autocomplete = 'one-time-code';
|
|
17052
17332
|
name.input.autocomplete = 'name';
|
|
17333
|
+
const codeHint = document.createElement('p');
|
|
17334
|
+
codeHint.id = `${code.input.id}-hint`;
|
|
17335
|
+
codeHint.className = 'svhd-file-hint';
|
|
17336
|
+
codeHint.textContent = `It works for ${HELP_DESK_PIN_TTL_MINUTES} minutes. Not in your inbox? Look in spam for mail from ${helpDeskCodeSender(client.desk.sending_host)}.`;
|
|
17337
|
+
code.input.setAttribute('aria-describedby', codeHint.id);
|
|
17338
|
+
const resend = document.createElement('button');
|
|
17339
|
+
resend.type = 'button';
|
|
17340
|
+
resend.className = 'svhd-button svhd-secondary';
|
|
17341
|
+
resend.textContent = 'Send a new code';
|
|
17342
|
+
const changeEmail = document.createElement('button');
|
|
17343
|
+
changeEmail.type = 'button';
|
|
17344
|
+
changeEmail.className = 'svhd-button svhd-secondary';
|
|
17345
|
+
changeEmail.textContent = 'Use a different email';
|
|
17346
|
+
const codeLinks = document.createElement('div');
|
|
17347
|
+
codeLinks.className = 'svhd-code-links';
|
|
17348
|
+
codeLinks.append(resend, changeEmail);
|
|
17349
|
+
code.wrapper.append(codeHint, codeLinks);
|
|
17053
17350
|
code.wrapper.hidden = true;
|
|
17054
17351
|
name.wrapper.hidden = true;
|
|
17055
17352
|
const auth = document.createElement('fieldset');
|
|
@@ -17067,14 +17364,9 @@ function mountHelpDeskForm(client, options) {
|
|
|
17067
17364
|
hosted.target = '_blank';
|
|
17068
17365
|
hosted.rel = 'noopener noreferrer';
|
|
17069
17366
|
hosted.hidden = true;
|
|
17070
|
-
const
|
|
17071
|
-
if (
|
|
17072
|
-
hosted.href =
|
|
17073
|
-
const changeEmail = document.createElement('button');
|
|
17074
|
-
changeEmail.type = 'button';
|
|
17075
|
-
changeEmail.className = 'svhd-button svhd-secondary';
|
|
17076
|
-
changeEmail.textContent = 'Use another email';
|
|
17077
|
-
changeEmail.hidden = true;
|
|
17367
|
+
const newRequestUrl = hostedUrl(client.desk.canonical_host, '/requests/new');
|
|
17368
|
+
if (newRequestUrl)
|
|
17369
|
+
hosted.href = newRequestUrl;
|
|
17078
17370
|
const actions = document.createElement('div');
|
|
17079
17371
|
actions.className = 'svhd-actions';
|
|
17080
17372
|
const send = document.createElement('button');
|
|
@@ -17086,8 +17378,33 @@ function mountHelpDeskForm(client, options) {
|
|
|
17086
17378
|
cancel.type = 'button';
|
|
17087
17379
|
cancel.textContent = 'Cancel';
|
|
17088
17380
|
cancel.hidden = !options.onCancel;
|
|
17089
|
-
actions.append(send,
|
|
17090
|
-
|
|
17381
|
+
actions.append(send, cancel);
|
|
17382
|
+
const confirm = document.createElement('div');
|
|
17383
|
+
confirm.className = 'svhd-confirm';
|
|
17384
|
+
confirm.setAttribute('role', 'group');
|
|
17385
|
+
confirm.hidden = true;
|
|
17386
|
+
const confirmTitle = document.createElement('p');
|
|
17387
|
+
confirmTitle.id = `${prefix}-confirm-title`;
|
|
17388
|
+
confirmTitle.className = 'svhd-confirm-title';
|
|
17389
|
+
confirmTitle.textContent = DISCARD_REQUEST_COPY.question;
|
|
17390
|
+
const confirmNote = document.createElement('p');
|
|
17391
|
+
confirmNote.id = `${prefix}-confirm-note`;
|
|
17392
|
+
confirmNote.className = 'svhd-status';
|
|
17393
|
+
confirm.setAttribute('aria-labelledby', confirmTitle.id);
|
|
17394
|
+
confirm.setAttribute('aria-describedby', confirmNote.id);
|
|
17395
|
+
const confirmActions = document.createElement('div');
|
|
17396
|
+
confirmActions.className = 'svhd-actions';
|
|
17397
|
+
const keepEditing = document.createElement('button');
|
|
17398
|
+
keepEditing.type = 'button';
|
|
17399
|
+
keepEditing.className = 'svhd-button';
|
|
17400
|
+
keepEditing.textContent = DISCARD_REQUEST_COPY.keepEditing;
|
|
17401
|
+
const discard = document.createElement('button');
|
|
17402
|
+
discard.type = 'button';
|
|
17403
|
+
discard.className = 'svhd-button svhd-secondary';
|
|
17404
|
+
discard.textContent = DISCARD_REQUEST_COPY.discard;
|
|
17405
|
+
confirmActions.append(keepEditing, discard);
|
|
17406
|
+
confirm.append(confirmTitle, confirmNote, confirmActions);
|
|
17407
|
+
form.append(subject.wrapper, description.wrapper, auth, status, hosted, actions, confirm);
|
|
17091
17408
|
let state = 'editing';
|
|
17092
17409
|
let destroyed = false;
|
|
17093
17410
|
let pending = false;
|
|
@@ -17099,12 +17416,21 @@ function mountHelpDeskForm(client, options) {
|
|
|
17099
17416
|
let focusAfter = null;
|
|
17100
17417
|
let generation = 0;
|
|
17101
17418
|
let challenge = null;
|
|
17419
|
+
// When the emailed code stops working, in milliseconds on this device's
|
|
17420
|
+
// clock from the start's landing: Core's `expires_at`, read against a device
|
|
17421
|
+
// clock set apart from Core's, would misjudge it.
|
|
17422
|
+
let challengeEndsAt = 0;
|
|
17102
17423
|
let draftId = null;
|
|
17103
17424
|
let draftPromise = null;
|
|
17104
17425
|
let uncertainSubmission = null;
|
|
17105
17426
|
let sessionToken = null;
|
|
17106
17427
|
let sessionKnown = false;
|
|
17107
17428
|
let attachments;
|
|
17429
|
+
let submittedCode = null;
|
|
17430
|
+
let resendAt = 0;
|
|
17431
|
+
let resendTimer = null;
|
|
17432
|
+
let confirmReturn = null;
|
|
17433
|
+
let done = null;
|
|
17108
17434
|
function setState(next) {
|
|
17109
17435
|
state = next;
|
|
17110
17436
|
notify(options.onStateChange, next);
|
|
@@ -17115,13 +17441,163 @@ function mountHelpDeskForm(client, options) {
|
|
|
17115
17441
|
status.classList.toggle('svhd-error', isError);
|
|
17116
17442
|
status.setAttribute('role', isError ? 'alert' : 'status');
|
|
17117
17443
|
}
|
|
17444
|
+
function renderResend() {
|
|
17445
|
+
const wait = Math.max(0, Math.ceil((resendAt - Date.now()) / 1000));
|
|
17446
|
+
resend.disabled = pending || completed || wait > 0;
|
|
17447
|
+
resend.textContent = wait > 0 ? `Send a new code in ${helpDeskCountdown(wait)}` : 'Send a new code';
|
|
17448
|
+
if (wait === 0)
|
|
17449
|
+
stopResendCountdown();
|
|
17450
|
+
}
|
|
17451
|
+
function stopResendCountdown() {
|
|
17452
|
+
if (resendTimer !== null)
|
|
17453
|
+
clearInterval(resendTimer);
|
|
17454
|
+
resendTimer = null;
|
|
17455
|
+
}
|
|
17456
|
+
function startResendCountdown() {
|
|
17457
|
+
stopResendCountdown();
|
|
17458
|
+
resendAt = Date.now() + HELP_DESK_PIN_RESEND_AFTER_SECONDS * 1000;
|
|
17459
|
+
resendTimer = setInterval(renderResend, 1000);
|
|
17460
|
+
renderResend();
|
|
17461
|
+
}
|
|
17118
17462
|
function disable(disabled) {
|
|
17119
17463
|
for (const input of [subject.input, description.input, email.input, code.input, name.input, send, cancel, changeEmail])
|
|
17120
17464
|
input.disabled = disabled;
|
|
17465
|
+
renderResend();
|
|
17121
17466
|
attachments?.disablePicking(disabled);
|
|
17122
17467
|
attachments?.lock(completed || uncertainSubmission !== null);
|
|
17123
17468
|
}
|
|
17469
|
+
function clearCode() {
|
|
17470
|
+
code.input.value = '';
|
|
17471
|
+
submittedCode = null;
|
|
17472
|
+
}
|
|
17473
|
+
/** Keep the challenge a start just answered, timing its code and the wait before another from now. */
|
|
17474
|
+
function holdChallenge(next) {
|
|
17475
|
+
challenge = next;
|
|
17476
|
+
challengeEndsAt = Date.now() + HELP_DESK_PIN_TTL_SECONDS * 1000;
|
|
17477
|
+
startResendCountdown();
|
|
17478
|
+
}
|
|
17479
|
+
/** Forget the emailed code's challenge: the code typed for it and the wait before another. */
|
|
17480
|
+
function dropChallenge() {
|
|
17481
|
+
challenge = null;
|
|
17482
|
+
challengeEndsAt = 0;
|
|
17483
|
+
clearCode();
|
|
17484
|
+
clearFieldError(code);
|
|
17485
|
+
stopResendCountdown();
|
|
17486
|
+
resendAt = 0;
|
|
17487
|
+
}
|
|
17488
|
+
function renderConfirmNote() {
|
|
17489
|
+
// Only the ticket write, in flight or unanswered, can have created the
|
|
17490
|
+
// request; the earlier steps (sign-in, files, the draft) create no ticket.
|
|
17491
|
+
confirmNote.textContent = uncertainSubmission !== null
|
|
17492
|
+
? 'We may already have received this request. Closing now loses the way to check it.'
|
|
17493
|
+
: DISCARD_REQUEST_COPY.note;
|
|
17494
|
+
}
|
|
17495
|
+
/** The field of the step in view: the code, name or email the sign-in asks for, else the subject. */
|
|
17496
|
+
function stepField() {
|
|
17497
|
+
const asked = auth.hidden ? undefined : [code, name, email].find((entry) => !entry.wrapper.hidden);
|
|
17498
|
+
return (asked ?? subject).input;
|
|
17499
|
+
}
|
|
17500
|
+
function openConfirm() {
|
|
17501
|
+
// A press on the modal's backdrop leaves focus on the page body, and
|
|
17502
|
+
// Keep editing must never hand focus back outside the dialog.
|
|
17503
|
+
const active = document.activeElement;
|
|
17504
|
+
confirmReturn = active instanceof HTMLElement && shell.container.contains(active) ? active : stepField();
|
|
17505
|
+
renderConfirmNote();
|
|
17506
|
+
actions.hidden = true;
|
|
17507
|
+
confirm.hidden = false;
|
|
17508
|
+
keepEditing.focus();
|
|
17509
|
+
}
|
|
17510
|
+
/**
|
|
17511
|
+
* Move focus where a settled send or resend wants it. While the discard
|
|
17512
|
+
* question shows, focus stays on it and Keep editing goes there instead.
|
|
17513
|
+
*/
|
|
17514
|
+
function focusSettled() {
|
|
17515
|
+
const target = focusAfter;
|
|
17516
|
+
focusAfter = null;
|
|
17517
|
+
if (confirm.hidden) {
|
|
17518
|
+
target?.focus();
|
|
17519
|
+
return;
|
|
17520
|
+
}
|
|
17521
|
+
renderConfirmNote();
|
|
17522
|
+
if (target)
|
|
17523
|
+
confirmReturn = target;
|
|
17524
|
+
}
|
|
17525
|
+
function closeConfirm(restoreFocus) {
|
|
17526
|
+
if (confirm.hidden)
|
|
17527
|
+
return;
|
|
17528
|
+
confirm.hidden = true;
|
|
17529
|
+
actions.hidden = false;
|
|
17530
|
+
const target = confirmReturn;
|
|
17531
|
+
confirmReturn = null;
|
|
17532
|
+
if (restoreFocus && target?.isConnected)
|
|
17533
|
+
target.focus();
|
|
17534
|
+
}
|
|
17535
|
+
/**
|
|
17536
|
+
* Whether closing now would lose something: a send under way or
|
|
17537
|
+
* unanswered, a code step, or text and files of the customer's own. The
|
|
17538
|
+
* silent company sign-in the form runs as it opens (`authenticating`) is
|
|
17539
|
+
* no work of the customer's.
|
|
17540
|
+
*/
|
|
17541
|
+
function holdsUnsentWork() {
|
|
17542
|
+
if (completed)
|
|
17543
|
+
return false;
|
|
17544
|
+
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null
|
|
17545
|
+
|| edited(subject.input, options.subject) || edited(description.input, options.body)
|
|
17546
|
+
|| attachments?.hasEntries === true;
|
|
17547
|
+
}
|
|
17548
|
+
function showDone(ticket, customer) {
|
|
17549
|
+
const section = document.createElement('section');
|
|
17550
|
+
section.className = 'svhd-done';
|
|
17551
|
+
const title = document.createElement('h3');
|
|
17552
|
+
title.id = `${prefix}-done-title`;
|
|
17553
|
+
title.className = 'svhd-done-title';
|
|
17554
|
+
title.tabIndex = -1;
|
|
17555
|
+
title.textContent = `Request #${ticket.number} sent`;
|
|
17556
|
+
section.setAttribute('aria-labelledby', title.id);
|
|
17557
|
+
section.append(title);
|
|
17558
|
+
const requestUrl = Number.isSafeInteger(ticket.number) && ticket.number > 0
|
|
17559
|
+
? hostedUrl(client.desk.canonical_host, `/requests/${ticket.number}`)
|
|
17560
|
+
: null;
|
|
17561
|
+
// GET /me carries email_updates only for a customer whose own mailbox
|
|
17562
|
+
// gets the desk's mail, so the form promises email only on that answer.
|
|
17563
|
+
const next = [
|
|
17564
|
+
...(customer.email_updates === true && customer.email_verified !== false ? [`Replies will be emailed to ${customer.email}.`] : []),
|
|
17565
|
+
...(requestUrl ? ['Follow it and read replies on your request page.'] : []),
|
|
17566
|
+
];
|
|
17567
|
+
if (next.length > 0) {
|
|
17568
|
+
const note = document.createElement('p');
|
|
17569
|
+
note.className = 'svhd-status';
|
|
17570
|
+
note.textContent = next.join(' ');
|
|
17571
|
+
section.append(note);
|
|
17572
|
+
}
|
|
17573
|
+
if (requestUrl) {
|
|
17574
|
+
const link = document.createElement('a');
|
|
17575
|
+
link.className = 'svhd-link';
|
|
17576
|
+
link.href = requestUrl;
|
|
17577
|
+
link.target = '_blank';
|
|
17578
|
+
link.rel = 'noopener noreferrer';
|
|
17579
|
+
link.textContent = 'Open your request in a new tab';
|
|
17580
|
+
section.append(link);
|
|
17581
|
+
}
|
|
17582
|
+
if (options.onCancel) {
|
|
17583
|
+
const close = document.createElement('button');
|
|
17584
|
+
close.type = 'button';
|
|
17585
|
+
close.className = 'svhd-button svhd-secondary';
|
|
17586
|
+
close.textContent = 'Close';
|
|
17587
|
+
close.addEventListener('click', dismiss);
|
|
17588
|
+
section.append(close);
|
|
17589
|
+
}
|
|
17590
|
+
closeConfirm(false);
|
|
17591
|
+
form.hidden = true;
|
|
17592
|
+
form.after(section);
|
|
17593
|
+
done = section;
|
|
17594
|
+
title.focus();
|
|
17595
|
+
}
|
|
17124
17596
|
function clearComposer() {
|
|
17597
|
+
done?.remove();
|
|
17598
|
+
done = null;
|
|
17599
|
+
form.hidden = false;
|
|
17600
|
+
closeConfirm(false);
|
|
17125
17601
|
attachments?.clear(completed || uncertainSubmission !== null);
|
|
17126
17602
|
attachments?.lock(false);
|
|
17127
17603
|
if (attachments)
|
|
@@ -17130,14 +17606,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
17130
17606
|
description.input.value = '';
|
|
17131
17607
|
email.input.value = '';
|
|
17132
17608
|
email.input.readOnly = false;
|
|
17133
|
-
|
|
17134
|
-
code.input.value = '';
|
|
17609
|
+
dropChallenge();
|
|
17135
17610
|
name.input.value = '';
|
|
17611
|
+
for (const entry of fields)
|
|
17612
|
+
clearFieldError(entry);
|
|
17136
17613
|
code.wrapper.hidden = true;
|
|
17137
17614
|
name.wrapper.hidden = true;
|
|
17138
17615
|
auth.hidden = true;
|
|
17139
17616
|
hosted.hidden = true;
|
|
17140
|
-
challenge = null;
|
|
17141
17617
|
draftId = null;
|
|
17142
17618
|
draftPromise = null;
|
|
17143
17619
|
uncertainSubmission = null;
|
|
@@ -17180,7 +17656,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17180
17656
|
description.input.value = '';
|
|
17181
17657
|
name.input.value = '';
|
|
17182
17658
|
email.input.value = '';
|
|
17183
|
-
|
|
17659
|
+
clearCode();
|
|
17184
17660
|
if (attachments)
|
|
17185
17661
|
attachments.element.hidden = true;
|
|
17186
17662
|
return;
|
|
@@ -17249,9 +17725,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
17249
17725
|
email.wrapper.hidden = false;
|
|
17250
17726
|
code.wrapper.hidden = challenge === null;
|
|
17251
17727
|
email.input.readOnly = challenge !== null;
|
|
17252
|
-
changeEmail.hidden = challenge === null;
|
|
17253
17728
|
send.textContent = challenge ? 'Verify and send request' : 'Email me a code';
|
|
17254
|
-
message(challenge ?
|
|
17729
|
+
message(challenge ? `We sent a six-digit code to ${email.input.value.trim()}.` : 'Verify your email to send this request.');
|
|
17255
17730
|
focusAfter = challenge ? code.input : email.input;
|
|
17256
17731
|
}
|
|
17257
17732
|
function showHosted() {
|
|
@@ -17266,7 +17741,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17266
17741
|
: 'Sign in to your account on this website to contact support.');
|
|
17267
17742
|
return;
|
|
17268
17743
|
}
|
|
17269
|
-
hosted.hidden =
|
|
17744
|
+
hosted.hidden = newRequestUrl === null;
|
|
17270
17745
|
message(client.desk.auth_mode === 'identity_unavailable'
|
|
17271
17746
|
? 'This help desk cannot sign you in right now. Try again later.'
|
|
17272
17747
|
: 'This help desk requires sign-in. Open it in a new tab to sign in and submit your request there.');
|
|
@@ -17274,6 +17749,11 @@ function mountHelpDeskForm(client, options) {
|
|
|
17274
17749
|
async function submit() {
|
|
17275
17750
|
if (pending || completed || destroyed)
|
|
17276
17751
|
return;
|
|
17752
|
+
// Sending (Enter in a field, a code's last digit) answers the discard
|
|
17753
|
+
// question: the customer kept going.
|
|
17754
|
+
closeConfirm(false);
|
|
17755
|
+
for (const entry of fields)
|
|
17756
|
+
clearFieldError(entry);
|
|
17277
17757
|
const recoveringSubmission = uncertainSubmission !== null;
|
|
17278
17758
|
const subjectText = uncertainSubmission?.subject ?? subject.input.value.trim();
|
|
17279
17759
|
const body = uncertainSubmission?.body ?? description.input.value;
|
|
@@ -17284,9 +17764,9 @@ function mountHelpDeskForm(client, options) {
|
|
|
17284
17764
|
description.input.value = body;
|
|
17285
17765
|
}
|
|
17286
17766
|
if (!subjectText || subjectText.length > 200 || !body.trim()) {
|
|
17287
|
-
const
|
|
17288
|
-
|
|
17289
|
-
|
|
17767
|
+
const refused = !subjectText || subjectText.length > 200 ? subject : description;
|
|
17768
|
+
setFieldError(refused, !subjectText ? 'Add a subject.' : subjectText.length > 200 ? 'Keep the subject to 200 characters.' : 'Describe what you need help with.');
|
|
17769
|
+
refused.input.focus();
|
|
17290
17770
|
return;
|
|
17291
17771
|
}
|
|
17292
17772
|
const ownGeneration = generation;
|
|
@@ -17335,26 +17815,29 @@ function mountHelpDeskForm(client, options) {
|
|
|
17335
17815
|
showEmail();
|
|
17336
17816
|
return;
|
|
17337
17817
|
}
|
|
17338
|
-
|
|
17818
|
+
const started = await client.startPin(email.input.value.trim());
|
|
17339
17819
|
if (!alive(ownGeneration))
|
|
17340
17820
|
return;
|
|
17821
|
+
holdChallenge(started);
|
|
17341
17822
|
setState('verifying');
|
|
17342
17823
|
showEmail();
|
|
17343
17824
|
return;
|
|
17344
17825
|
}
|
|
17345
|
-
if (Date.now() >=
|
|
17346
|
-
|
|
17347
|
-
code.input.value = '';
|
|
17826
|
+
if (Date.now() >= challengeEndsAt) {
|
|
17827
|
+
dropChallenge();
|
|
17348
17828
|
setState('editing');
|
|
17349
17829
|
showEmail();
|
|
17350
17830
|
message('That code expired. Ask for another code.', true);
|
|
17351
17831
|
return;
|
|
17352
17832
|
}
|
|
17353
|
-
|
|
17354
|
-
|
|
17833
|
+
const pin = helpDeskPinDigits(code.input.value);
|
|
17834
|
+
if (pin.length !== HELP_DESK_PIN_LENGTH) {
|
|
17835
|
+
setFieldError(code, 'Enter the six-digit code from your email.');
|
|
17836
|
+
focusAfter = code.input;
|
|
17837
|
+
return;
|
|
17355
17838
|
}
|
|
17356
17839
|
authenticating = true;
|
|
17357
|
-
const verified = await client.verifyPin({ challengeId: challenge.challenge_id, bindingSecret: challenge.binding_secret, code:
|
|
17840
|
+
const verified = await client.verifyPin({ challengeId: challenge.challenge_id, bindingSecret: challenge.binding_secret, code: pin });
|
|
17358
17841
|
if (!alive(ownGeneration))
|
|
17359
17842
|
return;
|
|
17360
17843
|
token = await client.getSessionToken();
|
|
@@ -17368,8 +17851,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17368
17851
|
authenticating = false;
|
|
17369
17852
|
if (attachments)
|
|
17370
17853
|
attachments.element.hidden = false;
|
|
17371
|
-
|
|
17372
|
-
changeEmail.hidden = true;
|
|
17854
|
+
dropChallenge();
|
|
17373
17855
|
subject.input.value = subjectText;
|
|
17374
17856
|
description.input.value = body;
|
|
17375
17857
|
}
|
|
@@ -17389,7 +17871,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17389
17871
|
name.wrapper.hidden = false;
|
|
17390
17872
|
send.textContent = 'Send request';
|
|
17391
17873
|
setState('editing');
|
|
17392
|
-
|
|
17874
|
+
setFieldError(name, 'Add your name before sending your request.');
|
|
17393
17875
|
focusAfter = name.input;
|
|
17394
17876
|
return;
|
|
17395
17877
|
}
|
|
@@ -17426,8 +17908,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17426
17908
|
setState('success');
|
|
17427
17909
|
if (!alive(ownGeneration))
|
|
17428
17910
|
return;
|
|
17429
|
-
|
|
17430
|
-
send.textContent = 'Request sent';
|
|
17911
|
+
showDone(ticket, customer);
|
|
17431
17912
|
notify(options.onSuccess, ticket);
|
|
17432
17913
|
}
|
|
17433
17914
|
catch (failure) {
|
|
@@ -17457,7 +17938,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
17457
17938
|
draftPromise = null;
|
|
17458
17939
|
attachments?.clear();
|
|
17459
17940
|
}
|
|
17460
|
-
|
|
17941
|
+
if (error instanceof SparkVaultError && error.serviceCode === 'PIN_INVALID') {
|
|
17942
|
+
clearCode();
|
|
17943
|
+
setFieldError(code, HELP_DESK_CODE_STEP_COPY.codeRefused);
|
|
17944
|
+
focusAfter = code.input;
|
|
17945
|
+
}
|
|
17946
|
+
else {
|
|
17947
|
+
message(draftExpired ? 'Your saved draft expired. Your text is kept. Choose your files again before sending.' : error.message, true);
|
|
17948
|
+
}
|
|
17461
17949
|
}
|
|
17462
17950
|
setState(uncertainSubmission ? 'uncertain' : challenge ? 'verifying' : 'editing');
|
|
17463
17951
|
if (!alive(ownGeneration))
|
|
@@ -17470,21 +17958,73 @@ function mountHelpDeskForm(client, options) {
|
|
|
17470
17958
|
authenticating = false;
|
|
17471
17959
|
pending = false;
|
|
17472
17960
|
disable(completed);
|
|
17473
|
-
|
|
17474
|
-
|
|
17961
|
+
focusSettled();
|
|
17962
|
+
}
|
|
17963
|
+
}
|
|
17964
|
+
}
|
|
17965
|
+
/** Send a new code to the address the current one went to, replacing the challenge it answers. */
|
|
17966
|
+
async function resendCode() {
|
|
17967
|
+
if (pending || destroyed || challenge === null)
|
|
17968
|
+
return;
|
|
17969
|
+
closeConfirm(false);
|
|
17970
|
+
const ownGeneration = generation;
|
|
17971
|
+
pending = true;
|
|
17972
|
+
disable(true);
|
|
17973
|
+
clearFieldError(code);
|
|
17974
|
+
try {
|
|
17975
|
+
const next = await client.startPin(email.input.value.trim());
|
|
17976
|
+
if (!alive(ownGeneration))
|
|
17977
|
+
return;
|
|
17978
|
+
holdChallenge(next);
|
|
17979
|
+
clearCode();
|
|
17980
|
+
message(HELP_DESK_CODE_STEP_COPY.newCodeSent);
|
|
17981
|
+
focusAfter = code.input;
|
|
17982
|
+
}
|
|
17983
|
+
catch (failure) {
|
|
17984
|
+
if (!alive(ownGeneration))
|
|
17985
|
+
return;
|
|
17986
|
+
const error = failure instanceof Error ? failure : new Error('A new code could not be sent. Try again.');
|
|
17987
|
+
message(error instanceof SparkVaultError && error.statusCode === 429 ? 'Too many codes have been sent. Try again later.' : error.message, true);
|
|
17988
|
+
notify(options.onError, error);
|
|
17989
|
+
}
|
|
17990
|
+
finally {
|
|
17991
|
+
if (alive(ownGeneration)) {
|
|
17992
|
+
pending = false;
|
|
17993
|
+
disable(completed);
|
|
17994
|
+
focusSettled();
|
|
17475
17995
|
}
|
|
17476
17996
|
}
|
|
17477
17997
|
}
|
|
17998
|
+
/** Take a typed, pasted or autofilled code as its digits, and send it the moment the last one lands. */
|
|
17999
|
+
function takeCode(value) {
|
|
18000
|
+
const digits = helpDeskPinDigits(value);
|
|
18001
|
+
if (code.input.value !== digits)
|
|
18002
|
+
code.input.value = digits;
|
|
18003
|
+
if (digits.length < HELP_DESK_PIN_LENGTH) {
|
|
18004
|
+
submittedCode = null;
|
|
18005
|
+
return;
|
|
18006
|
+
}
|
|
18007
|
+
if (pending || challenge === null || digits === submittedCode)
|
|
18008
|
+
return;
|
|
18009
|
+
submittedCode = digits;
|
|
18010
|
+
void submit();
|
|
18011
|
+
}
|
|
17478
18012
|
const onSubmit = (event) => {
|
|
17479
18013
|
event.preventDefault();
|
|
17480
18014
|
void submit();
|
|
17481
18015
|
};
|
|
17482
|
-
|
|
18016
|
+
/** The Cancel path: remove the form, then tell the host the customer closed it. */
|
|
18017
|
+
function dismiss() {
|
|
18018
|
+
controller.destroy();
|
|
18019
|
+
notify(options.onCancel, undefined);
|
|
18020
|
+
}
|
|
18021
|
+
const controller = {
|
|
17483
18022
|
destroy() {
|
|
17484
18023
|
if (destroyed)
|
|
17485
18024
|
return;
|
|
17486
18025
|
destroyed = true;
|
|
17487
18026
|
generation += 1;
|
|
18027
|
+
stopResendCountdown();
|
|
17488
18028
|
attachments?.destroy(completed || uncertainSubmission !== null);
|
|
17489
18029
|
unsubscribe();
|
|
17490
18030
|
form.removeEventListener('submit', onSubmit);
|
|
@@ -17501,20 +18041,38 @@ function mountHelpDeskForm(client, options) {
|
|
|
17501
18041
|
setState('editing');
|
|
17502
18042
|
},
|
|
17503
18043
|
getState: () => state,
|
|
18044
|
+
requestDismiss() {
|
|
18045
|
+
if (destroyed)
|
|
18046
|
+
return;
|
|
18047
|
+
if (!holdsUnsentWork())
|
|
18048
|
+
dismiss();
|
|
18049
|
+
else if (confirm.hidden)
|
|
18050
|
+
openConfirm();
|
|
18051
|
+
else
|
|
18052
|
+
closeConfirm(true);
|
|
18053
|
+
},
|
|
17504
18054
|
};
|
|
18055
|
+
code.input.addEventListener('input', () => takeCode(code.input.value));
|
|
18056
|
+
code.input.addEventListener('paste', (event) => {
|
|
18057
|
+
const pasted = event.clipboardData?.getData('text');
|
|
18058
|
+
if (typeof pasted !== 'string')
|
|
18059
|
+
return;
|
|
18060
|
+
event.preventDefault();
|
|
18061
|
+
clearFieldError(code);
|
|
18062
|
+
takeCode(pasted);
|
|
18063
|
+
});
|
|
18064
|
+
resend.addEventListener('click', () => { void resendCode(); });
|
|
17505
18065
|
changeEmail.addEventListener('click', () => {
|
|
17506
18066
|
if (pending || destroyed)
|
|
17507
18067
|
return;
|
|
17508
|
-
|
|
17509
|
-
code.input.value = '';
|
|
18068
|
+
dropChallenge();
|
|
17510
18069
|
setState('editing');
|
|
17511
18070
|
showEmail();
|
|
17512
18071
|
email.input.focus();
|
|
17513
18072
|
});
|
|
17514
|
-
cancel.addEventListener('click', () =>
|
|
17515
|
-
|
|
17516
|
-
|
|
17517
|
-
});
|
|
18073
|
+
cancel.addEventListener('click', () => controller.requestDismiss());
|
|
18074
|
+
keepEditing.addEventListener('click', () => closeConfirm(true));
|
|
18075
|
+
discard.addEventListener('click', dismiss);
|
|
17518
18076
|
form.addEventListener('submit', onSubmit);
|
|
17519
18077
|
notify(options.onStateChange, state);
|
|
17520
18078
|
// Native company identity starts as the form opens, never from a Connect,
|
|
@@ -17557,7 +18115,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
17557
18115
|
}
|
|
17558
18116
|
});
|
|
17559
18117
|
}
|
|
17560
|
-
return
|
|
18118
|
+
return controller;
|
|
17561
18119
|
}
|
|
17562
18120
|
|
|
17563
18121
|
let modalSequence = 0;
|
|
@@ -17598,6 +18156,18 @@ function openHelpDeskForm(client, options = {}) {
|
|
|
17598
18156
|
// A host callback must not leave the modal or scroll lock behind.
|
|
17599
18157
|
}
|
|
17600
18158
|
};
|
|
18159
|
+
// Escape, the backdrop and Close ask the form, which closes at once when
|
|
18160
|
+
// nothing is unsent and otherwise asks to discard first; its Cancel path
|
|
18161
|
+
// then reaches `cancel`. A state observer can dismiss while the form mounts,
|
|
18162
|
+
// before it hands back its controller, when nothing has been typed yet.
|
|
18163
|
+
const requestDismiss = () => {
|
|
18164
|
+
if (destroyed)
|
|
18165
|
+
return;
|
|
18166
|
+
if (inner)
|
|
18167
|
+
inner.requestDismiss();
|
|
18168
|
+
else
|
|
18169
|
+
cancel();
|
|
18170
|
+
};
|
|
17601
18171
|
const prefix = `svhd-modal-${++modalSequence}`;
|
|
17602
18172
|
const created = new ModalShell({
|
|
17603
18173
|
overlayId: `${prefix}-overlay`,
|
|
@@ -17605,7 +18175,7 @@ function openHelpDeskForm(client, options = {}) {
|
|
|
17605
18175
|
classPrefix: 'svhd',
|
|
17606
18176
|
titleId: `${prefix}-title`,
|
|
17607
18177
|
backdropBlur: options.backdropBlur !== false,
|
|
17608
|
-
onDismiss:
|
|
18178
|
+
onDismiss: requestDismiss,
|
|
17609
18179
|
});
|
|
17610
18180
|
shell = created;
|
|
17611
18181
|
// A host focus listener can dispatch a dismissal while the shell opens.
|
|
@@ -17625,7 +18195,7 @@ function openHelpDeskForm(client, options = {}) {
|
|
|
17625
18195
|
close.className = 'svhd-modal-close';
|
|
17626
18196
|
close.setAttribute('aria-label', 'Close support form');
|
|
17627
18197
|
close.textContent = 'Close';
|
|
17628
|
-
close.addEventListener('click',
|
|
18198
|
+
close.addEventListener('click', requestDismiss);
|
|
17629
18199
|
header.append(title, close);
|
|
17630
18200
|
const body = document.createElement('div');
|
|
17631
18201
|
shell.modal.append(header, body);
|
|
@@ -21517,7 +22087,7 @@ class SparkVault {
|
|
|
21517
22087
|
}
|
|
21518
22088
|
/** Get the SDK version */
|
|
21519
22089
|
static get version() {
|
|
21520
|
-
return '14.2.
|
|
22090
|
+
return '14.2.3';
|
|
21521
22091
|
}
|
|
21522
22092
|
}
|
|
21523
22093
|
if (typeof window !== 'undefined') {
|