@sparkvault/sdk-js 16.8.0 → 16.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1110 -649
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +1110 -649
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/support-styles.d.ts +6 -1
- package/dist/products/help-desk/types.d.ts +4 -0
- package/dist/sparkvault.js +1 -1
- package/dist/sparkvault.js.map +1 -1
- package/package.json +1 -1
- package/dist/products/help-desk/form-attachments.d.ts +0 -38
- package/dist/products/help-desk/form-composer.d.ts +0 -38
- package/dist/products/help-desk/icons.d.ts +0 -21
package/dist/index.mjs
CHANGED
|
@@ -14404,11 +14404,12 @@ const DEFAULT_QUEUE_ALIAS = 'support';
|
|
|
14404
14404
|
|
|
14405
14405
|
/**
|
|
14406
14406
|
* What a customer's new request asks before Cancel throws away what they
|
|
14407
|
-
* wrote and the files they added: the
|
|
14408
|
-
*
|
|
14409
|
-
* as the primary button, focused as the
|
|
14410
|
-
* it as the quieter one. Discard sends
|
|
14411
|
-
* each file's upload, so `note`
|
|
14407
|
+
* wrote and the files they added: the SDK's support form, wherever it is
|
|
14408
|
+
* drawn (the portal's New request page among them), asks it in place of its
|
|
14409
|
+
* actions row, with Keep editing first, as the primary button, focused as the
|
|
14410
|
+
* question appears, and Discard after it as the quieter one. Discard sends
|
|
14411
|
+
* nothing, forgets the text and cancels each file's upload, so `note`
|
|
14412
|
+
* promises no more than the form does.
|
|
14412
14413
|
*/
|
|
14413
14414
|
const DISCARD_REQUEST_COPY = Object.freeze({
|
|
14414
14415
|
question: 'Discard this request?',
|
|
@@ -18283,7 +18284,7 @@ function injectHelpDeskFormStyles() {
|
|
|
18283
18284
|
.svhd-input:focus-visible,.svhd-button:focus-visible,.svhd-link:focus-visible{outline:3px solid ${DS.action};outline-offset:2px}
|
|
18284
18285
|
.svhd-input:disabled{background:${DS.slate50}}
|
|
18285
18286
|
.svhd-auth{display:grid;gap:16px;border:0;padding:0;margin:0}
|
|
18286
|
-
.svhd-form[hidden],.svhd-step[hidden],.svhd-auth[hidden],.svhd-field[hidden],.svhd-field-error[hidden],.svhd-status[hidden],.svhd-link[hidden],.svhd-actions[hidden],.svhd-confirm[hidden],.svhd-widget-account[hidden],.svhd-text-button[hidden]
|
|
18287
|
+
.svhd-form[hidden],.svhd-step[hidden],.svhd-auth[hidden],.svhd-field[hidden],.svhd-field-error[hidden],.svhd-status[hidden],.svhd-link[hidden],.svhd-actions[hidden],.svhd-confirm[hidden],.svhd-widget-account[hidden],.svhd-text-button[hidden]{display:none}
|
|
18287
18288
|
.svhd-actions{display:flex;align-items:center;gap:12px;flex-wrap:wrap}
|
|
18288
18289
|
.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}
|
|
18289
18290
|
.svhd-button:hover{background:${DS.actionHover}}
|
|
@@ -18318,41 +18319,54 @@ function injectHelpDeskFormStyles() {
|
|
|
18318
18319
|
.svhd-recap-label{display:block;color:${DS.slate600};font-size:12px;font-weight:600;line-height:1.4}
|
|
18319
18320
|
.svhd-recap-text{display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;margin:0;color:${DS.slate900};font-size:14px;line-height:1.5;overflow-wrap:anywhere}
|
|
18320
18321
|
.svhd-recap .svhd-text-button{flex:none}
|
|
18321
|
-
/* The frame is the field: its ring shows wherever focus is inside it, and the text inside draws none of its own. */
|
|
18322
|
-
.svhd-composer{position:relative;display:flex;flex-direction:column;min-width:0;border:1px solid ${DS.slate300};border-radius:6px;background:${DS.white}}
|
|
18323
|
-
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:3px solid ${DS.action};outline-offset:2px}
|
|
18324
|
-
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:3px solid ${DS.action};outline-offset:2px}}
|
|
18325
|
-
.svhd-composer-dragging{border-style:dashed;border-color:${DS.action}}
|
|
18326
|
-
.svhd-composer-input{display:block;width:100%;min-height:140px;resize:vertical;border:0;border-radius:6px 6px 0 0;padding:10px 12px;background:transparent;color:${DS.slate900};font:inherit;font-size:16px}
|
|
18327
|
-
.svhd-composer-input:focus,.svhd-composer-input:focus-visible{outline:none}
|
|
18328
|
-
.svhd-composer-input:disabled{background:${DS.slate50}}
|
|
18329
|
-
.svhd-composer-drop{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;margin:0;padding:12px;border-radius:5px;background:${DS.actionBg};color:${DS.action};font-weight:600;text-align:center;pointer-events:none}
|
|
18330
|
-
.svhd-composer-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:0 12px;padding:0 8px 0 4px;border-top:1px solid ${DS.slate200}}
|
|
18331
|
-
.svhd-composer-attach{display:inline-flex;align-items:center;gap:6px;min-height:44px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:${DS.slate600};font:600 14px/1.4 system-ui,sans-serif;cursor:pointer}
|
|
18332
|
-
.svhd-composer-attach:hover{background:${DS.slate100};color:${DS.slate900}}
|
|
18333
|
-
.svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
18334
|
-
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
18335
|
-
.svhd-composer-hint{flex:1 1 160px;min-width:0;margin:0;padding:6px 0;font-size:12px;line-height:1.4;color:${DS.slate600}}
|
|
18336
|
-
.svhd-composer-notice{margin:0;font-size:14px}
|
|
18337
|
-
.svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${DS.slate200}}
|
|
18338
|
-
.svhd-attachment-chips:empty{display:none}
|
|
18339
|
-
.svhd-attachment-chip{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;flex:0 1 280px;min-width:0;max-width:100%;padding:0 0 8px 10px;border:1px solid ${DS.slate200};border-radius:6px;background:${DS.slate50};font-size:13px;line-height:1.4}
|
|
18340
|
-
.svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${DS.slate900}}
|
|
18341
|
-
.svhd-attachment-status{grid-column:1;padding-right:8px;color:${DS.slate600};font-size:12px;overflow-wrap:anywhere}
|
|
18342
|
-
.svhd-attachment-status.svhd-error{color:${DS.error}}
|
|
18343
|
-
.svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${DS.action}}
|
|
18344
|
-
.svhd-attachment-chip .svhd-attachment-remove{display:grid;place-items:center;width:44px;height:44px;min-height:44px;padding:0;border:0;border-radius:6px;background:transparent;color:${DS.slate600};cursor:pointer}
|
|
18345
|
-
.svhd-attachment-remove:hover{background:${DS.slate200};color:${DS.slate900}}
|
|
18346
|
-
.svhd-attachment-chip .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
18347
|
-
.svhd-attachment-chip .svhd-attachment-retry{grid-column:2;min-height:44px;padding:0 10px;border:0;border-radius:6px;background:transparent;color:${DS.action};font:600 13px/1.4 system-ui,sans-serif;text-decoration:underline;cursor:pointer}
|
|
18348
|
-
.svhd-composer button:focus-visible{outline:3px solid ${DS.action};outline-offset:-3px}
|
|
18349
|
-
.svhd-attachment-remove:disabled,.svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
18350
18322
|
.svhd-live{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
|
|
18351
18323
|
.svhd-footer{margin-top:20px;font-size:12px;color:${DS.slate500}}
|
|
18352
18324
|
`;
|
|
18353
18325
|
document.head.appendChild(style);
|
|
18354
18326
|
}
|
|
18355
18327
|
|
|
18328
|
+
/**
|
|
18329
|
+
* The steps an attachment's upload shows (ATTACHMENT_CEREMONY_STEPS, the help
|
|
18330
|
+
* desk's one wording), each in the state the transfer has actually reached:
|
|
18331
|
+
* the one reading the console's composer and the portal's editor draw.
|
|
18332
|
+
* Nothing here runs on a clock: a step completes only when the transfer
|
|
18333
|
+
* reports what it names, so the same report always shows the same steps.
|
|
18334
|
+
*
|
|
18335
|
+
* - "Sending" runs while the upload starts and its bytes go out, and
|
|
18336
|
+
* completes once every byte has been accepted.
|
|
18337
|
+
* - "Encrypted as it arrives" runs while bytes flow: the vault encrypts each
|
|
18338
|
+
* one on arrival, so it completes with the last of them.
|
|
18339
|
+
* - "Stored" runs from the last byte until the server confirms the file is
|
|
18340
|
+
* stored, which also completes "Integrity verified": the server confirms a
|
|
18341
|
+
* file only once it holds every byte of the size the upload declared, each
|
|
18342
|
+
* chunk under an authentication tag, and the transfer has checked the
|
|
18343
|
+
* offsets it reported along the way. A transfer whose bytes all arrived
|
|
18344
|
+
* while the vault was still saving (`received`: the SDK throws
|
|
18345
|
+
* RECEIVED_STILL_SAVING from ./transfer-retry.js for it) shows the file
|
|
18346
|
+
* stored and the check still to come. Both clients attach such a file as it
|
|
18347
|
+
* is, and the server, which alone learns when the file is stored, refuses a
|
|
18348
|
+
* message sent before then in its own words.
|
|
18349
|
+
*
|
|
18350
|
+
* BROWSER-SAFE: pure data, no Node built-ins.
|
|
18351
|
+
*/
|
|
18352
|
+
|
|
18353
|
+
|
|
18354
|
+
/** A step's state. */
|
|
18355
|
+
const CEREMONY_STEP_STATUS = Object.freeze({ PENDING: 'pending', ACTIVE: 'active', COMPLETE: 'complete' });
|
|
18356
|
+
|
|
18357
|
+
const { PENDING, ACTIVE, COMPLETE } = CEREMONY_STEP_STATUS;
|
|
18358
|
+
|
|
18359
|
+
/**
|
|
18360
|
+
* How much of the file has gone out, as a whole percentage.
|
|
18361
|
+
*
|
|
18362
|
+
* @param {{ bytesSent: number, bytesTotal: number }} transfer
|
|
18363
|
+
* @returns {number}
|
|
18364
|
+
*/
|
|
18365
|
+
function sentPercent({ bytesSent, bytesTotal }) {
|
|
18366
|
+
if (!(bytesTotal > 0)) return 0;
|
|
18367
|
+
return Math.min(100, Math.floor((bytesSent / bytesTotal) * 100));
|
|
18368
|
+
}
|
|
18369
|
+
|
|
18356
18370
|
/**
|
|
18357
18371
|
* The one rule for which characters a file name may hold, shared by every
|
|
18358
18372
|
* runtime that stores a name (Core refuses them at ingest, and clients check
|
|
@@ -18761,8 +18775,9 @@ function formatBytes(bytes, decimals = 1) {
|
|
|
18761
18775
|
|
|
18762
18776
|
/**
|
|
18763
18777
|
* What stops a file from joining a message, decided in the browser before any
|
|
18764
|
-
* upload starts: the one check the
|
|
18765
|
-
*
|
|
18778
|
+
* upload starts: the one check the help desk composer (./help-desk-composer.js,
|
|
18779
|
+
* the SDK's ticket form and the portal's reply) and the console's composer
|
|
18780
|
+
* run. The server never reads an uploaded file's plaintext, so the
|
|
18766
18781
|
* check on a file's first bytes can only run here, over the file itself; the
|
|
18767
18782
|
* name rule runs here and again on the server when the upload is initiated.
|
|
18768
18783
|
* Both are the platform's one attachment policy (./attachment-policy.js);
|
|
@@ -18834,17 +18849,19 @@ function acceptedKindsCopy(kinds) {
|
|
|
18834
18849
|
|
|
18835
18850
|
/**
|
|
18836
18851
|
* The files a ticket accepts, in the one phrase every surface names them by,
|
|
18837
|
-
* built from the policy's own list (ACCEPTED_ATTACHMENT_KINDS): the
|
|
18838
|
-
*
|
|
18852
|
+
* built from the policy's own list (ACCEPTED_ATTACHMENT_KINDS): the help desk
|
|
18853
|
+
* composer's (?) tip reads it, and so do the API reference
|
|
18839
18854
|
* (apps/api/openapi/overlay.mjs) and the help desk's page on the site
|
|
18840
|
-
* (apps/www/_data/helpDeskAttachments.js).
|
|
18855
|
+
* (apps/www/_data/helpDeskAttachments.js). A refused file's sentence names
|
|
18856
|
+
* only that its type can't be attached.
|
|
18841
18857
|
*/
|
|
18842
18858
|
const ACCEPTED_ATTACHMENTS_COPY = acceptedKindsCopy(ACCEPTED_ATTACHMENT_KINDS);
|
|
18843
18859
|
|
|
18844
18860
|
/**
|
|
18845
18861
|
* What a customer's file picker says before any file is chosen: what to add,
|
|
18846
|
-
* how many files a message takes and how large each may be. The
|
|
18847
|
-
*
|
|
18862
|
+
* how many files a message takes and how large each may be. The help desk
|
|
18863
|
+
* composer's (?) tip after its Attach button says it, and it describes
|
|
18864
|
+
* Attach.
|
|
18848
18865
|
*/
|
|
18849
18866
|
const CUSTOMER_ATTACHMENTS_HINT =
|
|
18850
18867
|
`Add screenshots, documents or recordings. Up to ${MAX_ATTACHMENTS_PER_MESSAGE} files, ${formatBytes(CUSTOMER_ATTACHMENT_MAX_BYTES)} each.`;
|
|
@@ -18852,12 +18869,25 @@ const CUSTOMER_ATTACHMENTS_HINT =
|
|
|
18852
18869
|
/**
|
|
18853
18870
|
* What a customer reads at a desk that takes no files from its customers
|
|
18854
18871
|
* (the desk lookup's `customer_can_attach_files` is false, the upload refusal
|
|
18855
|
-
* CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF): the
|
|
18856
|
-
*
|
|
18857
|
-
*
|
|
18872
|
+
* CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF): the help desk composer refusing a
|
|
18873
|
+
* file dropped, pasted or uploaded there, and the portal's note on the files
|
|
18874
|
+
* an email left out.
|
|
18858
18875
|
*/
|
|
18859
18876
|
const NO_CUSTOMER_FILES_COPY = "This help desk doesn't take files from customers.";
|
|
18860
18877
|
|
|
18878
|
+
/**
|
|
18879
|
+
* What a customer reads of a file their upload allowance refuses, one
|
|
18880
|
+
* sentence for each reason (CUSTOMER_UPLOAD_REFUSALS) wherever it is said:
|
|
18881
|
+
* the help desk composer's refusal of a file they upload
|
|
18882
|
+
* (./help-desk-composer.js), and the portal's note on the files an email
|
|
18883
|
+
* carried that a request left out. An allowance of 0 turns customer uploads
|
|
18884
|
+
* off, which reads as NO_CUSTOMER_FILES_COPY.
|
|
18885
|
+
*/
|
|
18886
|
+
const CUSTOMER_UPLOAD_REFUSAL_COPY = Object.freeze({
|
|
18887
|
+
[CUSTOMER_UPLOAD_REFUSALS.ALLOWANCE_REACHED]: "You've reached this help desk's upload allowance, so this file can't be added.",
|
|
18888
|
+
[CUSTOMER_UPLOAD_REFUSALS.UPLOADS_OFF]: NO_CUSTOMER_FILES_COPY
|
|
18889
|
+
});
|
|
18890
|
+
|
|
18861
18891
|
/**
|
|
18862
18892
|
* A file input's `accept`: every extension a ticket accepts
|
|
18863
18893
|
* (ACCEPTED_ATTACHMENT_EXTENSIONS), each with its dot, so the system's file
|
|
@@ -18870,7 +18900,7 @@ const REFUSAL_COPY = Object.freeze({
|
|
|
18870
18900
|
[ATTACHMENT_REFUSALS.EMPTY]: 'This file has no name.',
|
|
18871
18901
|
[ATTACHMENT_REFUSALS.TOO_LONG]: "This file's name is too long. Rename it and try again.",
|
|
18872
18902
|
[ATTACHMENT_REFUSALS.UNSAFE_NAME]: "This file's name can't be used. Rename it and try again.",
|
|
18873
|
-
[ATTACHMENT_REFUSALS.REFUSED_EXTENSION]:
|
|
18903
|
+
[ATTACHMENT_REFUSALS.REFUSED_EXTENSION]: "Files of this type can't be attached.",
|
|
18874
18904
|
[ATTACHMENT_REFUSALS.EXECUTABLE]: "This file is a program, and programs can't be attached.",
|
|
18875
18905
|
[ATTACHMENT_REFUSALS.SCRIPT]: "This file is a script, and scripts can't be attached.",
|
|
18876
18906
|
[ATTACHMENT_REFUSALS.MARKUP]: "This file holds web page markup, which can't be attached.",
|
|
@@ -18906,354 +18936,120 @@ function refusalCopy(refusal, maxBytes) {
|
|
|
18906
18936
|
}
|
|
18907
18937
|
|
|
18908
18938
|
/**
|
|
18909
|
-
*
|
|
18910
|
-
*
|
|
18911
|
-
*
|
|
18912
|
-
*
|
|
18939
|
+
* A tenant's brand color and the WCAG contrast rules that decide how it may be
|
|
18940
|
+
* used: the one hex rule the server stores, the console checks and the portal
|
|
18941
|
+
* paints, the one contrast reading the console's readouts, the portal's
|
|
18942
|
+
* accent and the portal's reading of a help center's ground share, and the
|
|
18943
|
+
* one way a readout writes that reading.
|
|
18944
|
+
*
|
|
18945
|
+
* A brand color is tenant-controlled, so it is used only when it is a
|
|
18946
|
+
* six-digit hex color, read case-insensitively and held in lowercase; anything
|
|
18947
|
+
* else (a color name, a CSS function, a value that runs on into more CSS) is
|
|
18948
|
+
* no color at all.
|
|
18949
|
+
*
|
|
18950
|
+
* A brand color can be any lightness, so whatever shows it picks what goes
|
|
18951
|
+
* with it: white or ink as the text on its fill, whichever reads more
|
|
18952
|
+
* strongly (at least 4.2:1 on any fill, as far as two inks reach on a
|
|
18953
|
+
* mid-tone), and the color itself as text only where it reaches 4.5:1 on
|
|
18954
|
+
* both grounds accent text stands on, the white surface and the canvas
|
|
18955
|
+
* tone, ink otherwise. accentProperties says that as the accent
|
|
18956
|
+
* custom properties the customer portal paints with and the console's sample
|
|
18957
|
+
* of it shows, in the design system's own tokens.
|
|
18958
|
+
*
|
|
18959
|
+
* BROWSER-SAFE: data only, no imports.
|
|
18913
18960
|
*/
|
|
18914
|
-
|
|
18915
|
-
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
|
|
18922
|
-
|
|
18923
|
-
|
|
18924
|
-
|
|
18925
|
-
|
|
18926
|
-
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
18930
|
-
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18961
|
+
|
|
18962
|
+
const HEX_COLOR = /^#[0-9a-f]{6}$/;
|
|
18963
|
+
|
|
18964
|
+
/** WCAG AA's floor for normal-size text. */
|
|
18965
|
+
const AA_TEXT_CONTRAST = 4.5;
|
|
18966
|
+
|
|
18967
|
+
/**
|
|
18968
|
+
* The canvas tone, the design system's `--canvas` (`--color-slate-50`): the
|
|
18969
|
+
* page ground the customer portal (its pages and a customer's own messages)
|
|
18970
|
+
* and the knowledge base's default theme set accent text on, beside the white
|
|
18971
|
+
* surface. The design system publishes its tokens only as CSS, which this
|
|
18972
|
+
* import-free module cannot read, so the value is mirrored here once, and
|
|
18973
|
+
* tests/brand-color.test.js holds it to packages/design-system/tokens/colors.css.
|
|
18974
|
+
*/
|
|
18975
|
+
const CANVAS_COLOR = '#f7fafb';
|
|
18976
|
+
|
|
18977
|
+
/**
|
|
18978
|
+
* The ink, the design system's `--ink` (`--color-slate-900`): the dark text a
|
|
18979
|
+
* pairing paints on a fill and in place of a color too light to stand as
|
|
18980
|
+
* text. Mirrored here once for the same reason as CANVAS_COLOR, and held to
|
|
18981
|
+
* packages/design-system/tokens/colors.css by tests/brand-color.test.js.
|
|
18982
|
+
*/
|
|
18983
|
+
const INK_COLOR = '#0d1a20';
|
|
18984
|
+
|
|
18985
|
+
/** Relative luminance (WCAG 2) of an sRGB color's red, green and blue channels, each from 0 to 1. */
|
|
18986
|
+
function channelLuminance(channels) {
|
|
18987
|
+
const [red, green, blue] = channels.map((channel) => (channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4));
|
|
18988
|
+
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
18940
18989
|
}
|
|
18941
18990
|
|
|
18942
|
-
/**
|
|
18943
|
-
function
|
|
18944
|
-
|
|
18945
|
-
notice.className = 'svhd-composer-notice svhd-error';
|
|
18946
|
-
notice.hidden = true;
|
|
18947
|
-
return notice;
|
|
18991
|
+
/** Relative luminance (WCAG 2) of a validated `#rrggbb` color. */
|
|
18992
|
+
function relativeLuminance(color) {
|
|
18993
|
+
return channelLuminance([1, 3, 5].map((offset) => Number.parseInt(color.slice(offset, offset + 2), 16) / 255));
|
|
18948
18994
|
}
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
/**
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
18966
|
-
|
|
18967
|
-
|
|
18968
|
-
|
|
18969
|
-
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
|
|
18974
|
-
|
|
18975
|
-
|
|
18976
|
-
|
|
18977
|
-
|
|
18978
|
-
|
|
18979
|
-
/**
|
|
18980
|
-
*
|
|
18981
|
-
*
|
|
18982
|
-
*
|
|
18983
|
-
|
|
18984
|
-
|
|
18985
|
-
|
|
18986
|
-
|
|
18987
|
-
|
|
18988
|
-
|
|
18989
|
-
|
|
18990
|
-
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
|
|
18995
|
-
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
|
|
19002
|
-
|
|
19003
|
-
|
|
19004
|
-
|
|
19005
|
-
|
|
19006
|
-
|
|
19007
|
-
const notice = createNotice();
|
|
19008
|
-
const list = document.createElement('ul');
|
|
19009
|
-
list.className = 'svhd-attachment-chips';
|
|
19010
|
-
list.setAttribute('aria-label', 'Attached files');
|
|
19011
|
-
let entries = [];
|
|
19012
|
-
let revision = 0;
|
|
19013
|
-
let locked = false;
|
|
19014
|
-
let pickingDisabled = false;
|
|
19015
|
-
let destroyed = false;
|
|
19016
|
-
const current = (entry, ownRevision) => !destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
19017
|
-
function syncPicking() {
|
|
19018
|
-
attach.disabled = locked || pickingDisabled;
|
|
19019
|
-
input.disabled = locked || pickingDisabled;
|
|
19020
|
-
}
|
|
19021
|
-
function controls(entry) {
|
|
19022
|
-
entry.remove.disabled = locked;
|
|
19023
|
-
entry.retry.disabled = locked || !!entry.operation;
|
|
19024
|
-
}
|
|
19025
|
-
function update(entry, state, text) {
|
|
19026
|
-
entry.state = state;
|
|
19027
|
-
entry.row.dataset.state = state;
|
|
19028
|
-
entry.status.textContent = text;
|
|
19029
|
-
entry.status.classList.toggle('svhd-error', state === 'failed');
|
|
19030
|
-
entry.progress.hidden = state !== 'uploading';
|
|
19031
|
-
entry.retry.hidden = !(entry.retryable && (state === 'failed' || state === 'received'));
|
|
19032
|
-
entry.retry.textContent = state === 'received' ? 'Check upload' : 'Retry';
|
|
19033
|
-
entry.retry.setAttribute('aria-label', `${state === 'received' ? 'Check upload' : 'Retry'} ${entry.file.name}`);
|
|
19034
|
-
controls(entry);
|
|
19035
|
-
}
|
|
19036
|
-
async function cancel(entry, id = entry.attachmentId, owner = entry.context) {
|
|
19037
|
-
if (!id || !owner)
|
|
19038
|
-
return;
|
|
19039
|
-
try {
|
|
19040
|
-
await client.cancelDraftAttachment(owner.draftId, id, { expectedSessionToken: owner.expectedSessionToken });
|
|
19041
|
-
}
|
|
19042
|
-
catch {
|
|
19043
|
-
// A switched/signed-out customer cannot cancel as the new account.
|
|
19044
|
-
// Failed cleanup is left to the server's pending-upload reaper.
|
|
19045
|
-
}
|
|
19046
|
-
}
|
|
19047
|
-
function run(entry) {
|
|
19048
|
-
if (entry.operation)
|
|
19049
|
-
return entry.operation;
|
|
19050
|
-
const ownRevision = revision;
|
|
19051
|
-
const controller = new AbortController();
|
|
19052
|
-
entry.controller = controller;
|
|
19053
|
-
const stillCurrent = () => current(entry, ownRevision) && entry.controller === controller;
|
|
19054
|
-
let operation;
|
|
19055
|
-
operation = (async () => {
|
|
19056
|
-
try {
|
|
19057
|
-
update(entry, 'checking', 'Checking file');
|
|
19058
|
-
const refusal = await attachmentRefusal(entry.file, CUSTOMER_ATTACHMENT_MAX_BYTES);
|
|
19059
|
-
if (!stillCurrent())
|
|
19060
|
-
return;
|
|
19061
|
-
if (refusal) {
|
|
19062
|
-
entry.retryable = false;
|
|
19063
|
-
update(entry, 'failed', refusalCopy(refusal, CUSTOMER_ATTACHMENT_MAX_BYTES));
|
|
19064
|
-
return;
|
|
19065
|
-
}
|
|
19066
|
-
const owner = await context();
|
|
19067
|
-
if (!stillCurrent())
|
|
19068
|
-
return;
|
|
19069
|
-
if (!owner) {
|
|
19070
|
-
update(entry, 'queued', 'Uploads when you send your request.');
|
|
19071
|
-
return;
|
|
19072
|
-
}
|
|
19073
|
-
const options = {
|
|
19074
|
-
signal: controller.signal,
|
|
19075
|
-
onProgress: (sent, total) => {
|
|
19076
|
-
if (!stillCurrent())
|
|
19077
|
-
return;
|
|
19078
|
-
const percentage = total > 0 ? Math.max(0, Math.min(100, Math.round(sent / total * 100))) : 0;
|
|
19079
|
-
entry.progress.value = percentage;
|
|
19080
|
-
entry.status.textContent = percentage === 100 ? 'Verifying stored file' : `Uploading ${percentage}%`;
|
|
19081
|
-
},
|
|
19082
|
-
};
|
|
19083
|
-
// Resume the same receipt/session after a lost answer or delayed
|
|
19084
|
-
// publication; never mint another upload for received bytes.
|
|
19085
|
-
if (entry.sessionUrl && entry.attachmentId) {
|
|
19086
|
-
entry.context = owner;
|
|
19087
|
-
update(entry, 'uploading', 'Checking upload');
|
|
19088
|
-
await client.resumeAttachment({ sessionUrl: entry.sessionUrl }, entry.file, options);
|
|
19089
|
-
}
|
|
19090
|
-
else {
|
|
19091
|
-
if (entry.attachmentId)
|
|
19092
|
-
await cancel(entry);
|
|
19093
|
-
if (!stillCurrent())
|
|
19094
|
-
return;
|
|
19095
|
-
entry.attachmentId = undefined;
|
|
19096
|
-
entry.context = owner;
|
|
19097
|
-
update(entry, 'starting', 'Starting upload');
|
|
19098
|
-
const upload = await client.initiateDraftAttachment(owner.draftId, { name: entry.file.name, size: entry.file.size }, { expectedSessionToken: owner.expectedSessionToken });
|
|
19099
|
-
if (!stillCurrent()) {
|
|
19100
|
-
await cancel(entry, upload.attachment_id, owner);
|
|
19101
|
-
return;
|
|
19102
|
-
}
|
|
19103
|
-
if (!isResourceIdOf('attachment', upload.attachment_id))
|
|
19104
|
-
throw new SparkVaultError('Invalid attachment answer.', 'HELP_DESK_INVALID_RESPONSE');
|
|
19105
|
-
entry.attachmentId = upload.attachment_id;
|
|
19106
|
-
if (Number.isSafeInteger(upload.max_bytes) && upload.max_bytes > 0 && entry.file.size > upload.max_bytes) {
|
|
19107
|
-
throw new SparkVaultError('The file is too large.', 'HELP_DESK_ATTACHMENT_TOO_LARGE', 413, { max_bytes: upload.max_bytes });
|
|
19108
|
-
}
|
|
19109
|
-
update(entry, 'uploading', 'Uploading 0%');
|
|
19110
|
-
await client.sendAttachment(upload.forge_url, entry.file, {
|
|
19111
|
-
...options,
|
|
19112
|
-
onSessionCreated: (session) => { if (stillCurrent())
|
|
19113
|
-
entry.sessionUrl = session.sessionUrl; },
|
|
19114
|
-
});
|
|
19115
|
-
}
|
|
19116
|
-
if (!stillCurrent())
|
|
19117
|
-
return;
|
|
19118
|
-
entry.progress.value = 100;
|
|
19119
|
-
entry.retryable = false;
|
|
19120
|
-
update(entry, 'complete', 'Attached');
|
|
19121
|
-
}
|
|
19122
|
-
catch (error) {
|
|
19123
|
-
if (!stillCurrent())
|
|
19124
|
-
return;
|
|
19125
|
-
const code = error instanceof SparkVaultError ? error.code : error?.code;
|
|
19126
|
-
if (code === RECEIVED_STILL_SAVING) {
|
|
19127
|
-
entry.retryable = !!entry.sessionUrl;
|
|
19128
|
-
update(entry, 'received', 'File received. Waiting for storage confirmation.');
|
|
19129
|
-
return;
|
|
19130
|
-
}
|
|
19131
|
-
if (code === 'session_gone')
|
|
19132
|
-
entry.sessionUrl = undefined;
|
|
19133
|
-
const failure = problem(error);
|
|
19134
|
-
entry.retryable = failure.retryable;
|
|
19135
|
-
update(entry, 'failed', failure.copy);
|
|
19136
|
-
}
|
|
19137
|
-
finally {
|
|
19138
|
-
if (entry.controller === controller)
|
|
19139
|
-
entry.controller = undefined;
|
|
19140
|
-
if (entry.operation === operation)
|
|
19141
|
-
entry.operation = undefined;
|
|
19142
|
-
if (entries.includes(entry))
|
|
19143
|
-
controls(entry);
|
|
19144
|
-
}
|
|
19145
|
-
})();
|
|
19146
|
-
entry.operation = operation;
|
|
19147
|
-
controls(entry);
|
|
19148
|
-
return operation;
|
|
19149
|
-
}
|
|
19150
|
-
function remove(entry) {
|
|
19151
|
-
if (locked)
|
|
19152
|
-
return;
|
|
19153
|
-
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19154
|
-
const refocus = document.activeElement === entry.remove;
|
|
19155
|
-
const index = entries.indexOf(entry);
|
|
19156
|
-
entry.controller?.abort();
|
|
19157
|
-
entries = entries.filter(candidate => candidate !== entry);
|
|
19158
|
-
entry.row.remove();
|
|
19159
|
-
setNotice(notice, null);
|
|
19160
|
-
void cancel(entry);
|
|
19161
|
-
onEntriesChange();
|
|
19162
|
-
if (refocus)
|
|
19163
|
-
(entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
19164
|
-
}
|
|
19165
|
-
function add(files) {
|
|
19166
|
-
if (locked || pickingDisabled || destroyed)
|
|
19167
|
-
return;
|
|
19168
|
-
const incoming = Array.from(files);
|
|
19169
|
-
if (incoming.length === 0)
|
|
19170
|
-
return;
|
|
19171
|
-
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - entries.length);
|
|
19172
|
-
setNotice(notice, incoming.length > room ? `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.` : null);
|
|
19173
|
-
for (const file of incoming.slice(0, room)) {
|
|
19174
|
-
const row = document.createElement('li');
|
|
19175
|
-
row.className = 'svhd-attachment-chip';
|
|
19176
|
-
const filename = document.createElement('span');
|
|
19177
|
-
filename.className = 'svhd-attachment-name';
|
|
19178
|
-
filename.textContent = file.name;
|
|
19179
|
-
filename.title = file.name;
|
|
19180
|
-
const status = document.createElement('span');
|
|
19181
|
-
status.className = 'svhd-attachment-status';
|
|
19182
|
-
status.setAttribute('role', 'status');
|
|
19183
|
-
status.setAttribute('aria-live', 'polite');
|
|
19184
|
-
const progress = document.createElement('progress');
|
|
19185
|
-
progress.className = 'svhd-attachment-progress';
|
|
19186
|
-
progress.max = 100;
|
|
19187
|
-
progress.value = 0;
|
|
19188
|
-
progress.hidden = true;
|
|
19189
|
-
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
19190
|
-
const removeButton = document.createElement('button');
|
|
19191
|
-
removeButton.type = 'button';
|
|
19192
|
-
removeButton.className = 'svhd-attachment-remove';
|
|
19193
|
-
removeButton.setAttribute('aria-label', `Remove ${file.name}`);
|
|
19194
|
-
removeButton.append(helpDeskIcon('close'));
|
|
19195
|
-
const retry = document.createElement('button');
|
|
19196
|
-
retry.type = 'button';
|
|
19197
|
-
retry.className = 'svhd-attachment-retry';
|
|
19198
|
-
retry.hidden = true;
|
|
19199
|
-
const entry = { file, row, status, progress, remove: removeButton, retry, state: 'queued', retryable: false };
|
|
19200
|
-
removeButton.onclick = () => remove(entry);
|
|
19201
|
-
retry.onclick = () => { if (!locked && entry.retryable)
|
|
19202
|
-
void run(entry); };
|
|
19203
|
-
row.append(filename, removeButton, status, retry, progress);
|
|
19204
|
-
list.append(row);
|
|
19205
|
-
entries.push(entry);
|
|
19206
|
-
void run(entry);
|
|
19207
|
-
}
|
|
19208
|
-
if (room > 0)
|
|
19209
|
-
onEntriesChange();
|
|
19210
|
-
}
|
|
19211
|
-
const onChange = () => { if (input.files)
|
|
19212
|
-
add(input.files); input.value = ''; };
|
|
19213
|
-
const onAttach = () => { if (!attach.disabled)
|
|
19214
|
-
input.click(); };
|
|
19215
|
-
input.addEventListener('change', onChange);
|
|
19216
|
-
attach.addEventListener('click', onAttach);
|
|
19217
|
-
function clear(preserveComplete = false) {
|
|
19218
|
-
revision += 1;
|
|
19219
|
-
const previous = entries;
|
|
19220
|
-
entries = [];
|
|
19221
|
-
for (const entry of previous) {
|
|
19222
|
-
entry.controller?.abort();
|
|
19223
|
-
if (!preserveComplete || entry.state !== 'complete')
|
|
19224
|
-
void cancel(entry);
|
|
19225
|
-
}
|
|
19226
|
-
list.replaceChildren();
|
|
19227
|
-
input.value = '';
|
|
19228
|
-
setNotice(notice, null);
|
|
19229
|
-
}
|
|
19230
|
-
return {
|
|
19231
|
-
toolbar,
|
|
19232
|
-
list,
|
|
19233
|
-
notice,
|
|
19234
|
-
get accepting() { return !locked && !pickingDisabled && !destroyed; },
|
|
19235
|
-
get attachmentIds() { return entries.filter(entry => entry.state === 'complete' && entry.attachmentId).map(entry => entry.attachmentId); },
|
|
19236
|
-
get unresolved() { return entries.some(entry => entry.state !== 'complete'); },
|
|
19237
|
-
get hasEntries() { return entries.length > 0; },
|
|
19238
|
-
get names() { return entries.map(entry => entry.file.name); },
|
|
19239
|
-
add,
|
|
19240
|
-
async start() { await Promise.all(entries.map(entry => entry.operation ?? (entry.state === 'queued' ? run(entry) : Promise.resolve()))); },
|
|
19241
|
-
lock(value) { locked = value; syncPicking(); entries.forEach(controls); },
|
|
19242
|
-
disablePicking(value) { pickingDisabled = value; syncPicking(); },
|
|
19243
|
-
renewSession(previousToken, nextToken) {
|
|
19244
|
-
for (const entry of entries) {
|
|
19245
|
-
if (entry.context?.expectedSessionToken === previousToken)
|
|
19246
|
-
entry.context = { ...entry.context, expectedSessionToken: nextToken };
|
|
19247
|
-
}
|
|
19248
|
-
},
|
|
19249
|
-
clear,
|
|
19250
|
-
destroy(preserveComplete = false) {
|
|
19251
|
-
destroyed = true;
|
|
19252
|
-
clear(preserveComplete);
|
|
19253
|
-
input.removeEventListener('change', onChange);
|
|
19254
|
-
attach.removeEventListener('click', onAttach);
|
|
19255
|
-
},
|
|
19256
|
-
};
|
|
18995
|
+
|
|
18996
|
+
/** The contrast ratio of two relative luminances. */
|
|
18997
|
+
function contrastRatio(first, second) {
|
|
18998
|
+
return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
|
|
18999
|
+
}
|
|
19000
|
+
|
|
19001
|
+
/** The relative luminance of the ink a fill's text is weighed in, the real ink rather than pure black. */
|
|
19002
|
+
const INK_LUMINANCE = relativeLuminance(INK_COLOR);
|
|
19003
|
+
|
|
19004
|
+
/** The relative luminances of the grounds accent text stands on: the white surface and the canvas tone. */
|
|
19005
|
+
const TEXT_GROUNDS = Object.freeze([1, relativeLuminance(CANVAS_COLOR)]);
|
|
19006
|
+
|
|
19007
|
+
/** How strongly a color of this luminance reads as text on the ground it reads least on. */
|
|
19008
|
+
function textContrast(luminance) {
|
|
19009
|
+
return Math.min(...TEXT_GROUNDS.map((ground) => contrastRatio(luminance, ground)));
|
|
19010
|
+
}
|
|
19011
|
+
|
|
19012
|
+
/**
|
|
19013
|
+
* A brand color as it may be stored and shown, or null when the value is not
|
|
19014
|
+
* one: a `#rrggbb` hex value, read case-insensitively.
|
|
19015
|
+
*
|
|
19016
|
+
* @param {unknown} value
|
|
19017
|
+
* @returns {string|null} The color in lowercase
|
|
19018
|
+
*/
|
|
19019
|
+
function brandColor(value) {
|
|
19020
|
+
if (typeof value !== 'string') return null;
|
|
19021
|
+
const color = value.toLowerCase();
|
|
19022
|
+
return HEX_COLOR.test(color) ? color : null;
|
|
19023
|
+
}
|
|
19024
|
+
|
|
19025
|
+
/**
|
|
19026
|
+
* What goes with a brand color: the text on its fill (white or ink,
|
|
19027
|
+
* whichever reads more strongly, at least 4.2:1 on any fill) and the ink for
|
|
19028
|
+
* it as text
|
|
19029
|
+
* (the color itself where it reaches AA_TEXT_CONTRAST on both the white
|
|
19030
|
+
* surface and the canvas tone, ink otherwise).
|
|
19031
|
+
*
|
|
19032
|
+
* @param {unknown} value
|
|
19033
|
+
* @returns {{ onAccent: 'white'|'ink', accentInk: 'accent'|'ink', ratio: number }|null} Null when the value is not a brand color; `ratio` is its contrast as text (accentTextContrast)
|
|
19034
|
+
*/
|
|
19035
|
+
function accentPairing(value) {
|
|
19036
|
+
const color = brandColor(value);
|
|
19037
|
+
if (!color) return null;
|
|
19038
|
+
const luminance = relativeLuminance(color);
|
|
19039
|
+
const ratio = textContrast(luminance);
|
|
19040
|
+
return {
|
|
19041
|
+
onAccent: contrastRatio(luminance, 1) >= contrastRatio(luminance, INK_LUMINANCE) ? 'white' : 'ink',
|
|
19042
|
+
accentInk: ratio >= AA_TEXT_CONTRAST ? 'accent' : 'ink',
|
|
19043
|
+
ratio
|
|
19044
|
+
};
|
|
19045
|
+
}
|
|
19046
|
+
|
|
19047
|
+
/** Contrast between a brand fill and the label selected by accentPairing. */
|
|
19048
|
+
function accentFillContrast(value) {
|
|
19049
|
+
const color = brandColor(value);
|
|
19050
|
+
if (!color) return null;
|
|
19051
|
+
const pairing = accentPairing(color);
|
|
19052
|
+
return contrastRatio(relativeLuminance(color), pairing.onAccent === 'white' ? 1 : INK_LUMINANCE);
|
|
19257
19053
|
}
|
|
19258
19054
|
|
|
19259
19055
|
/**
|
|
@@ -19291,7 +19087,7 @@ function createFormAttachments(client, prefix, context, onEntriesChange) {
|
|
|
19291
19087
|
const DROP_FILES_COPY = 'Drop the files to attach them.';
|
|
19292
19088
|
|
|
19293
19089
|
/** What a person reads when a drop held a folder, which is never attached. */
|
|
19294
|
-
const FOLDER_REFUSAL_COPY =
|
|
19090
|
+
const FOLDER_REFUSAL_COPY = "Folders can't be attached. Add the files inside them instead.";
|
|
19295
19091
|
|
|
19296
19092
|
/** The name the clipboard gives every pasted picture, with its extension. */
|
|
19297
19093
|
const CLIPBOARD_IMAGE_NAME = /^image\.(\w+)$/;
|
|
@@ -19416,90 +19212,838 @@ function composerFileEvents({ action, frameHolds, heldNames, dragging, attach, r
|
|
|
19416
19212
|
}
|
|
19417
19213
|
|
|
19418
19214
|
/**
|
|
19419
|
-
*
|
|
19420
|
-
*
|
|
19421
|
-
*
|
|
19422
|
-
*
|
|
19423
|
-
*
|
|
19424
|
-
*
|
|
19425
|
-
|
|
19426
|
-
|
|
19427
|
-
|
|
19428
|
-
|
|
19429
|
-
*
|
|
19430
|
-
*
|
|
19431
|
-
|
|
19432
|
-
|
|
19433
|
-
|
|
19434
|
-
|
|
19435
|
-
|
|
19436
|
-
|
|
19437
|
-
|
|
19438
|
-
|
|
19439
|
-
|
|
19440
|
-
|
|
19441
|
-
|
|
19442
|
-
|
|
19443
|
-
|
|
19444
|
-
|
|
19445
|
-
|
|
19446
|
-
|
|
19447
|
-
|
|
19448
|
-
|
|
19449
|
-
|
|
19450
|
-
|
|
19451
|
-
|
|
19452
|
-
|
|
19453
|
-
|
|
19454
|
-
|
|
19455
|
-
|
|
19456
|
-
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
|
|
19470
|
-
|
|
19471
|
-
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
|
|
19475
|
-
|
|
19476
|
-
|
|
19477
|
-
|
|
19478
|
-
|
|
19479
|
-
|
|
19480
|
-
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
19484
|
-
|
|
19485
|
-
|
|
19486
|
-
|
|
19487
|
-
|
|
19215
|
+
* When an unread Spark expires, as a person reads it on their own clock: the
|
|
19216
|
+
* marketing site's anonymous sender states it on its ready card, and the
|
|
19217
|
+
* console's Create Spark dialog states it before the Spark is made. One
|
|
19218
|
+
* implementation, so both surfaces say the same time the same way.
|
|
19219
|
+
*
|
|
19220
|
+
* BROWSER-SAFE: no imports. It reads the runtime's own locale and time zone.
|
|
19221
|
+
*/
|
|
19222
|
+
|
|
19223
|
+
|
|
19224
|
+
/**
|
|
19225
|
+
* A time of day on the reader's own clock, in the house style where the
|
|
19226
|
+
* reader's locale reads a 12-hour clock with its period last ("4:36pm", on
|
|
19227
|
+
* the hour "5pm"), and as the locale writes it otherwise ("16:36").
|
|
19228
|
+
*
|
|
19229
|
+
* @param {Date} date
|
|
19230
|
+
* @returns {string}
|
|
19231
|
+
*/
|
|
19232
|
+
function clockTime(date) {
|
|
19233
|
+
const clock = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
19234
|
+
const parts = clock.formatToParts(date);
|
|
19235
|
+
const last = parts[parts.length - 1];
|
|
19236
|
+
if (last.type !== 'dayPeriod') return clock.format(date);
|
|
19237
|
+
const part = (type) => parts.find((candidate) => candidate.type === type).value;
|
|
19238
|
+
const minute = part('minute');
|
|
19239
|
+
return `${part('hour')}${minute === '00' ? '' : `:${minute}`}${last.value.replace(/[^\p{L}]/gu, '').toLowerCase()}`;
|
|
19240
|
+
}
|
|
19241
|
+
|
|
19242
|
+
/**
|
|
19243
|
+
* The help desk's bare outline glyphs, drawn by the SDK's support wizard and
|
|
19244
|
+
* ticket form and by the one message composer (./help-desk-composer.js) the
|
|
19245
|
+
* portal's reply shares with them: stroked in `currentColor`, so the
|
|
19246
|
+
* stylesheet that sizes one also colors it, and hidden from assistive
|
|
19247
|
+
* technology, since the control that holds one names it.
|
|
19248
|
+
*
|
|
19249
|
+
* BROWSER-SAFE: builds each glyph through the page's `document`.
|
|
19250
|
+
*/
|
|
19251
|
+
|
|
19252
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
19253
|
+
|
|
19254
|
+
const PATHS = Object.freeze({
|
|
19255
|
+
back: 'm14.5 6-6 6 6 6',
|
|
19256
|
+
close: 'm6 6 12 12M18 6 6 18',
|
|
19257
|
+
external: 'M14 4h6v6m0-6L10 14M11 5H5a1 1 0 0 0-1 1v13a1 1 0 0 0 1 1h13a1 1 0 0 0 1-1v-6',
|
|
19258
|
+
check: 'm5 12 4 4L19 6',
|
|
19259
|
+
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
19260
|
+
chevron: 'm9 6 6 6-6 6',
|
|
19261
|
+
thumbUp: 'M7 10v11H3V10Zm0 1 5-8c2 0 3 1 2 4l-1 3h6a2 2 0 0 1 2 2l-2 7a2 2 0 0 1-2 2H7',
|
|
19262
|
+
thumbDown: 'M7 14V3H3v11Zm0-1 5 8c2 0 3-1 2-4l-1-3h6a2 2 0 0 0 2-2l-2-7a2 2 0 0 0-2-2H7',
|
|
19263
|
+
paperclip: 'm21 11-8.6 8.6a5.5 5.5 0 0 1-7.8-7.8l8.6-8.6a3.7 3.7 0 0 1 5.2 5.2l-8.6 8.6a1.8 1.8 0 0 1-2.6-2.6L15 6.6',
|
|
19264
|
+
info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-10v5m0-8h.01'
|
|
19265
|
+
});
|
|
19266
|
+
|
|
19267
|
+
/**
|
|
19268
|
+
* One glyph as an SVG element.
|
|
19269
|
+
*
|
|
19270
|
+
* @param {string} name - One of the glyphs' names (help-desk-icons.d.ts HelpDeskIconName)
|
|
19271
|
+
* @returns {SVGSVGElement}
|
|
19272
|
+
* @throws {TypeError} For a name no glyph has
|
|
19273
|
+
*/
|
|
19274
|
+
function helpDeskIcon(name) {
|
|
19275
|
+
if (!Object.hasOwn(PATHS, name)) throw new TypeError('No help desk icon has this name.');
|
|
19276
|
+
const svg = document.createElementNS(SVG_NAMESPACE, 'svg');
|
|
19277
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
19278
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
19279
|
+
svg.setAttribute('focusable', 'false');
|
|
19280
|
+
svg.setAttribute('fill', 'none');
|
|
19281
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
19282
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
19283
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
19284
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
19285
|
+
const path = document.createElementNS(SVG_NAMESPACE, 'path');
|
|
19286
|
+
path.setAttribute('d', PATHS[name]);
|
|
19287
|
+
svg.append(path);
|
|
19288
|
+
return svg;
|
|
19289
|
+
}
|
|
19290
|
+
|
|
19291
|
+
/**
|
|
19292
|
+
* The help desk's one message composer, for a customer writing to a help
|
|
19293
|
+
* desk: the SDK's ticket form (the support wizard's request step, and the
|
|
19294
|
+
* inline form) writes a new request in it, and the portal writes a reply on
|
|
19295
|
+
* a request in it. The text sits in one bordered frame with the Attach
|
|
19296
|
+
* button and the attached files inside it, and every file the customer adds
|
|
19297
|
+
* (picked, pasted or dropped) runs through the one attachment pipeline here,
|
|
19298
|
+
* so both surfaces check, upload, resume, refuse and report a file in the
|
|
19299
|
+
* same steps and the same words.
|
|
19300
|
+
*
|
|
19301
|
+
* - **Adding.** A file picked with Attach, pasted into the text (or into a
|
|
19302
|
+
* field the host names, the SDK's summary), or dropped anywhere on the
|
|
19303
|
+
* host's drop zone joins the same list, under the per-message count
|
|
19304
|
+
* (MAX_ATTACHMENTS_PER_MESSAGE; a file the browser's check refused is no
|
|
19305
|
+
* part of it). How a drag, a drop and a paste are answered (a paste or drag
|
|
19306
|
+
* of text stays the browser's, a dropped folder is left out and said so, a
|
|
19307
|
+
* pasted picture is numbered) is @sparkvault/app-sdk/composer-files'
|
|
19308
|
+
* policy, shared with the console's composer. A file brought to a desk that
|
|
19309
|
+
* takes no files from its customers is refused in words
|
|
19310
|
+
* (NO_CUSTOMER_FILES_COPY), and one brought while files cannot join is
|
|
19311
|
+
* never the browser's to open in place of the unsent message.
|
|
19312
|
+
* - **Help.** What a message takes (how many files, how large, which kinds)
|
|
19313
|
+
* waits behind a (?) tip after Attach, a disclosure that closes by its
|
|
19314
|
+
* trigger, by Escape, by its close button, by a press outside it or by
|
|
19315
|
+
* focus leaving it; a refused file's chip names only why it was refused.
|
|
19316
|
+
* - **Uploading.** The browser's check (attachmentRefusal) first, then the
|
|
19317
|
+
* host's transport: its target (the request a reply belongs to, or the
|
|
19318
|
+
* draft a new request uploads to, which may not exist yet: the file then
|
|
19319
|
+
* waits for `start`), the upload's initiation, and the SDK's resumable
|
|
19320
|
+
* transfer. A transfer that failed after its session opened, or whose
|
|
19321
|
+
* bytes all arrived while the vault was still storing them, resumes that
|
|
19322
|
+
* session rather than uploading the file again. A chip's status line, a
|
|
19323
|
+
* polite live region, changes only with the file's step (Checking file,
|
|
19324
|
+
* Starting upload, Uploading, Verifying stored file, Attached, a failure);
|
|
19325
|
+
* the share of bytes sent (sentPercent, floored, so verifying never shows
|
|
19326
|
+
* before the last byte) is its progress bar's, outside that region.
|
|
19327
|
+
* - **Attached.** Only a file the server confirmed stored joins the message
|
|
19328
|
+
* (`attachmentIds`). A file received but still being stored holds the
|
|
19329
|
+
* message back, as Core refuses a message carrying one
|
|
19330
|
+
* (apps/api/src/help-desk/attachments.js validateAttachmentsBelong), until
|
|
19331
|
+
* its Check upload confirms it.
|
|
19332
|
+
* - **Refused.** One sentence for each refusal (uploadProblem), read from the
|
|
19333
|
+
* host's refusal of the upload's initiation (`transport.refusal`, a refusal
|
|
19334
|
+
* it cannot read a fault anyone may try again) or the transfer's own error,
|
|
19335
|
+
* and whether trying again can mend it.
|
|
19336
|
+
*
|
|
19337
|
+
* The composer draws its own stylesheet (one unlayered `<style>` per
|
|
19338
|
+
* document), in the design system's colors with the help desk's accent
|
|
19339
|
+
* (`--hd-accent-ink`) where the host sets one. Its focus ring is the one the
|
|
19340
|
+
* host's fields wear: its color, width and offset are the host's
|
|
19341
|
+
* `--hd-focus`, `--hd-focus-width` and `--hd-focus-offset`, else the SDK's
|
|
19342
|
+
* field ring (Action Blue, 3px, 2px out).
|
|
19343
|
+
*
|
|
19344
|
+
* BROWSER-SAFE: builds its DOM through the page's `document`, and imports
|
|
19345
|
+
* only app-sdk's browser-safe modules.
|
|
19346
|
+
*/
|
|
19347
|
+
|
|
19348
|
+
|
|
19349
|
+
/** The id of the composer's one `<style>` element in a document. */
|
|
19350
|
+
const HELP_DESK_COMPOSER_STYLE_ID = 'sparkvault-help-desk-composer-styles';
|
|
19351
|
+
|
|
19352
|
+
/**
|
|
19353
|
+
* The design-system colors the composer is drawn in, each the value of the
|
|
19354
|
+
* token it names (tests/help-desk-composer.test.js holds them to
|
|
19355
|
+
* packages/design-system/tokens). The canvas tone and the ink are
|
|
19356
|
+
* brand-color.js' mirrors of those tokens.
|
|
19357
|
+
*/
|
|
19358
|
+
const COMPOSER_COLORS = Object.freeze({
|
|
19359
|
+
'--color-white': '#ffffff',
|
|
19360
|
+
'--canvas': CANVAS_COLOR,
|
|
19361
|
+
'--color-slate-100': '#f0f5f7',
|
|
19362
|
+
'--color-slate-200': '#e0e9ed',
|
|
19363
|
+
'--color-slate-300': '#c9d6dc',
|
|
19364
|
+
'--color-slate-600': '#425761',
|
|
19365
|
+
'--ink': INK_COLOR,
|
|
19366
|
+
'--color-action': '#216bde',
|
|
19367
|
+
'--color-action-bg': '#eef4fe',
|
|
19368
|
+
'--color-error': '#b02b27'
|
|
19369
|
+
});
|
|
19370
|
+
|
|
19371
|
+
const C = COMPOSER_COLORS;
|
|
19372
|
+
/** The help desk's accent ink where the host sets one, Action Blue where none does. */
|
|
19373
|
+
const ACCENT_INK = `var(--hd-accent-ink,${C['--color-action']})`;
|
|
19374
|
+
/** The focus ring of the host's fields: the SDK's field ring (`.svhd-input`) where the host sets none. */
|
|
19375
|
+
const FOCUS = `var(--hd-focus,${C['--color-action']})`;
|
|
19376
|
+
const FOCUS_WIDTH = 'var(--hd-focus-width,3px)';
|
|
19377
|
+
const FOCUS_OFFSET = 'var(--hd-focus-offset,2px)';
|
|
19378
|
+
/** A control inside the frame wears the ring within its own hit area. */
|
|
19379
|
+
const INSET_RING = `outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:calc(-1 * ${FOCUS_WIDTH});box-shadow:none`;
|
|
19380
|
+
|
|
19381
|
+
/**
|
|
19382
|
+
* The composer's stylesheet. Every rule but the notice's sits under
|
|
19383
|
+
* `.svhd-composer`, a class deep, so a host's own element and focus rules
|
|
19384
|
+
* never reach into the frame; the notice, which sits under the frame, is
|
|
19385
|
+
* one class of its own.
|
|
19386
|
+
*/
|
|
19387
|
+
const COMPOSER_CSS = `
|
|
19388
|
+
.svhd-composer,.svhd-composer *{box-sizing:border-box}
|
|
19389
|
+
.svhd-composer{position:relative;display:flex;flex-direction:column;min-width:0;border:1px solid ${C['--color-slate-300']};border-radius:6px;background:${C['--color-white']};color:${C['--ink']}}
|
|
19390
|
+
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:${FOCUS_OFFSET}}
|
|
19391
|
+
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:${FOCUS_OFFSET}}}
|
|
19392
|
+
.svhd-composer:has(.svhd-composer-input[aria-invalid=true]){border-color:${C['--color-error']}}
|
|
19393
|
+
.svhd-composer.svhd-composer-dragging{border-style:dashed;border-color:${ACCENT_INK}}
|
|
19394
|
+
.svhd-composer .svhd-composer-input{display:block;width:100%;min-height:140px;margin:0;resize:vertical;border:0;border-radius:6px 6px 0 0;padding:10px 12px;background:transparent;color:${C['--ink']};font-family:inherit;font-size:16px;line-height:1.5}
|
|
19395
|
+
.svhd-composer .svhd-composer-input:focus,.svhd-composer .svhd-composer-input:focus-visible{outline:none;box-shadow:none}
|
|
19396
|
+
.svhd-composer .svhd-composer-input:disabled{background:${C['--canvas']}}
|
|
19397
|
+
.svhd-composer .svhd-composer-drop{position:absolute;inset:0;z-index:1;display:flex;align-items:center;justify-content:center;margin:0;padding:12px;border-radius:5px;background:${C['--color-action-bg']};color:${ACCENT_INK};font-size:15px;font-weight:600;line-height:1.4;text-align:center;pointer-events:none}
|
|
19398
|
+
.svhd-composer .svhd-composer-toolbar{display:flex;align-items:center;flex-wrap:wrap;gap:0 4px;padding:0 4px;border-top:1px solid ${C['--color-slate-200']}}
|
|
19399
|
+
.svhd-composer .svhd-composer-attach{display:inline-flex;align-items:center;gap:6px;min-height:44px;margin:0;padding:0 8px;border:0;border-radius:6px;background:transparent;color:${C['--color-slate-600']};font-family:inherit;font-size:14px;font-weight:600;line-height:1.4;cursor:pointer}
|
|
19400
|
+
.svhd-composer .svhd-composer-attach:hover,.svhd-composer .svhd-composer-help:hover{background:${C['--color-slate-100']};color:${C['--ink']}}
|
|
19401
|
+
.svhd-composer .svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
19402
|
+
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
19403
|
+
.svhd-composer .svhd-composer-help{display:inline-grid;place-items:center;width:44px;height:44px;margin:0;padding:0;border:0;border-radius:6px;background:transparent;color:${C['--color-slate-600']};font-family:inherit;cursor:pointer}
|
|
19404
|
+
.svhd-composer .svhd-composer-help-glyph{display:inline-grid;place-items:center;width:20px;height:20px;border:1px solid currentColor;border-radius:50%;font-size:13px;font-weight:600;line-height:1}
|
|
19405
|
+
.svhd-composer .svhd-composer-help-panel{display:grid;grid-template-columns:minmax(0,1fr) auto;column-gap:8px;align-items:start;flex:1 1 100%;min-width:0;margin:0 0 8px;padding:10px 12px;border:1px solid ${C['--color-slate-200']};border-radius:6px;background:${C['--canvas']};color:${C['--color-slate-600']};font-size:13px;line-height:1.5}
|
|
19406
|
+
.svhd-composer .svhd-composer-help-copy{grid-column:1;min-width:0;overflow-wrap:anywhere}
|
|
19407
|
+
.svhd-composer .svhd-composer-help-copy p{margin:0}
|
|
19408
|
+
.svhd-composer .svhd-composer-help-copy p+p{margin-top:6px}
|
|
19409
|
+
.svhd-composer .svhd-composer-help-close{grid-row:1;grid-column:2;display:grid;place-items:center;width:44px;height:44px;margin:-10px -12px 0 0;padding:0;border:0;border-radius:6px;background:transparent;color:${C['--color-slate-600']};cursor:pointer}
|
|
19410
|
+
.svhd-composer .svhd-composer-help-close:hover,.svhd-composer .svhd-attachment-remove:hover{background:${C['--color-slate-200']};color:${C['--ink']}}
|
|
19411
|
+
.svhd-composer .svhd-composer-help-close svg,.svhd-composer .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
19412
|
+
.svhd-composer .svhd-attachment-chips{display:flex;flex-wrap:wrap;gap:8px;list-style:none;margin:0;padding:8px;border-top:1px solid ${C['--color-slate-200']}}
|
|
19413
|
+
.svhd-composer .svhd-attachment-chips:empty{display:none}
|
|
19414
|
+
.svhd-composer .svhd-attachment-chip{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;align-content:start;flex:0 1 280px;min-width:0;max-width:100%;margin:0;padding:0 0 8px 10px;border:1px solid ${C['--color-slate-200']};border-radius:6px;background:${C['--canvas']};font-size:13px;line-height:1.4}
|
|
19415
|
+
.svhd-composer .svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${C['--ink']}}
|
|
19416
|
+
.svhd-composer .svhd-attachment-status{grid-column:1;padding-right:8px;color:${C['--color-slate-600']};font-size:12px;overflow-wrap:anywhere}
|
|
19417
|
+
.svhd-composer .svhd-attachment-status.svhd-composer-problem{color:${C['--color-error']}}
|
|
19418
|
+
.svhd-composer .svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${ACCENT_INK}}
|
|
19419
|
+
.svhd-composer .svhd-attachment-remove{display:grid;place-items:center;width:44px;height:44px;min-height:44px;margin:0;padding:0;border:0;border-radius:6px;background:transparent;color:${C['--color-slate-600']};cursor:pointer}
|
|
19420
|
+
.svhd-composer .svhd-attachment-retry{grid-column:2;min-height:44px;margin:0;padding:0 10px;border:0;border-radius:6px;background:transparent;color:${ACCENT_INK};font-family:inherit;font-size:13px;font-weight:600;line-height:1.4;text-decoration:underline;cursor:pointer}
|
|
19421
|
+
.svhd-composer .svhd-attachment-remove:disabled,.svhd-composer .svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
19422
|
+
.svhd-composer .svhd-composer-attach:focus-visible,.svhd-composer .svhd-composer-help:focus-visible,.svhd-composer .svhd-composer-help-close:focus-visible,.svhd-composer .svhd-attachment-remove:focus-visible,.svhd-composer .svhd-attachment-retry:focus-visible{${INSET_RING}}
|
|
19423
|
+
.svhd-composer-notice{margin:0;color:${C['--color-error']};font-size:14px;line-height:1.5}
|
|
19424
|
+
.svhd-composer [hidden],.svhd-composer-notice[hidden]{display:none!important}
|
|
19425
|
+
`;
|
|
19426
|
+
|
|
19427
|
+
/** Draw the composer's stylesheet into the page, once. */
|
|
19428
|
+
function injectComposerStyles() {
|
|
19429
|
+
if (document.getElementById(HELP_DESK_COMPOSER_STYLE_ID)) return;
|
|
19430
|
+
const style = document.createElement('style');
|
|
19431
|
+
style.id = HELP_DESK_COMPOSER_STYLE_ID;
|
|
19432
|
+
style.textContent = COMPOSER_CSS;
|
|
19433
|
+
document.head.append(style);
|
|
19434
|
+
}
|
|
19435
|
+
|
|
19436
|
+
/** Where a file stands, as its chip's `data-state` names it. */
|
|
19437
|
+
const FILE_STATE = Object.freeze({
|
|
19438
|
+
/** Waiting for its target: a new request's draft that does not exist yet. */
|
|
19439
|
+
QUEUED: 'queued',
|
|
19440
|
+
CHECKING: 'checking',
|
|
19441
|
+
/** The browser's check refused it; it never reached the server. */
|
|
19442
|
+
REFUSED: 'refused',
|
|
19443
|
+
STARTING: 'starting',
|
|
19444
|
+
UPLOADING: 'uploading',
|
|
19445
|
+
/** Every byte arrived and the vault is still storing it. */
|
|
19446
|
+
RECEIVED: 'received',
|
|
19447
|
+
COMPLETE: 'complete',
|
|
19448
|
+
FAILED: 'failed'
|
|
19449
|
+
});
|
|
19450
|
+
|
|
19451
|
+
const IN_FLIGHT = new Set([FILE_STATE.QUEUED, FILE_STATE.CHECKING, FILE_STATE.STARTING, FILE_STATE.UPLOADING]);
|
|
19452
|
+
|
|
19453
|
+
const QUEUED_COPY = 'Uploads when you send your request.';
|
|
19454
|
+
const LIMIT_COPY = `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.`;
|
|
19455
|
+
const RECEIVED_COPY = 'File received. Waiting for storage confirmation.';
|
|
19456
|
+
const UPLOAD_FAILED_COPY = "This file couldn't be uploaded. Try again or remove it.";
|
|
19457
|
+
const UPLOADING_COPY = 'Uploading';
|
|
19458
|
+
const VERIFYING_COPY = 'Verifying stored file';
|
|
19459
|
+
/** The (?) tip's name, and what it says a message takes. */
|
|
19460
|
+
const HELP_TITLE = 'Attachment limits';
|
|
19461
|
+
const ACCEPTED_KINDS_COPY = `You can attach ${ACCEPTED_ATTACHMENTS_COPY}.`;
|
|
19462
|
+
|
|
19463
|
+
/** What a message's files still need before it can be sent, from the most pressing. */
|
|
19464
|
+
const HOLD_COPY = Object.freeze({
|
|
19465
|
+
uploading: 'Your files are still uploading.',
|
|
19466
|
+
storing: 'A file is still being stored. Check its upload in a moment, or remove it.',
|
|
19467
|
+
retryable: "Remove the files that couldn't be attached, or try them again.",
|
|
19468
|
+
refused: "Remove the files that can't be attached."
|
|
19469
|
+
});
|
|
19470
|
+
|
|
19471
|
+
/** Core's 402s for a company that cannot pay for a transfer now, which funding can mend. */
|
|
19472
|
+
const FUNDING_CODES = new Set(['USAGE_CREDITS_EXHAUSTED', 'USAGE_CREDIT_FUNDING_REVIEW', 'USAGE_CREDITS_REQUIRED']);
|
|
19473
|
+
|
|
19474
|
+
/**
|
|
19475
|
+
* The 409s a next try can get past: a write the server could not settle now
|
|
19476
|
+
* (CONFLICT), and the SDK's own answer for a customer session that changed
|
|
19477
|
+
* under the upload (HELP_DESK_SESSION_CHANGED), which the next try makes
|
|
19478
|
+
* under the session that stands.
|
|
19479
|
+
*/
|
|
19480
|
+
const PASSING_CONFLICTS = new Set(['CONFLICT', 'HELP_DESK_SESSION_CHANGED']);
|
|
19481
|
+
|
|
19482
|
+
/** The transfer's code for a session the server no longer holds: the next try uploads the file afresh. */
|
|
19483
|
+
const SESSION_GONE = 'session_gone';
|
|
19484
|
+
|
|
19485
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
19486
|
+
|
|
19487
|
+
/** A `Retry-After` in milliseconds as the moment it names, in epoch seconds, or null. */
|
|
19488
|
+
const momentAfter = (milliseconds) =>
|
|
19489
|
+
Number.isFinite(milliseconds) && milliseconds >= 0 ? Math.ceil((Date.now() + milliseconds) / 1000) : null;
|
|
19490
|
+
|
|
19491
|
+
/**
|
|
19492
|
+
* The SDK transfer's error as an UploadRefusal: the status and Core code a
|
|
19493
|
+
* refusal it met names (`details.status`, `details.coreCode`), else its own
|
|
19494
|
+
* status (0 for no answer), and its `Retry-After`.
|
|
19495
|
+
*
|
|
19496
|
+
* @param {unknown} error
|
|
19497
|
+
* @returns {import('./help-desk-composer.d.ts').UploadRefusal}
|
|
19498
|
+
*/
|
|
19499
|
+
function transferRefusal(error) {
|
|
19500
|
+
const details = isRecord(error?.details) ? error.details : null;
|
|
19501
|
+
const status = Number.isInteger(details?.status) ? details.status : Number.isInteger(error?.statusCode) ? error.statusCode : 0;
|
|
19502
|
+
return {
|
|
19503
|
+
status,
|
|
19504
|
+
code: typeof details?.coreCode === 'string' ? details.coreCode : null,
|
|
19505
|
+
details,
|
|
19506
|
+
resetsAt: momentAfter(error?.retryAfterMs)
|
|
19507
|
+
};
|
|
19508
|
+
}
|
|
19509
|
+
|
|
19510
|
+
/**
|
|
19511
|
+
* What a customer reads of a file's failed upload, and whether trying it
|
|
19512
|
+
* again can succeed: after a company's funding recovers, a rate limit, a lost
|
|
19513
|
+
* connection, a conflict a next try gets past (PASSING_CONFLICTS), or a fault. A
|
|
19514
|
+
* refusal of the file itself (its size, the customer's upload allowance, the
|
|
19515
|
+
* company's storage, any other final 4xx) stands however often it is tried.
|
|
19516
|
+
* Null, an error neither the host nor the transfer could read, is a fault.
|
|
19517
|
+
*
|
|
19518
|
+
* @param {import('./help-desk-composer.d.ts').UploadRefusal | null} refusal
|
|
19519
|
+
* @param {string | null} organization - The help desk's company, as the desk names it, or null where it names none
|
|
19520
|
+
* @returns {{ copy: string, retryable: boolean }}
|
|
19521
|
+
*/
|
|
19522
|
+
function uploadProblem(refusal, organization) {
|
|
19523
|
+
if (refusal === null) return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19524
|
+
const company = organization || 'This help desk';
|
|
19525
|
+
const { status, code } = refusal;
|
|
19526
|
+
const details = isRecord(refusal.details) ? refusal.details : {};
|
|
19527
|
+
if (status === 402 && FUNDING_CODES.has(code)) {
|
|
19528
|
+
return { copy: `${company} can't take files right now. Try again later.`, retryable: true };
|
|
19529
|
+
}
|
|
19530
|
+
if (status === 429) {
|
|
19531
|
+
const when = Number.isFinite(refusal.resetsAt) ? `at ${clockTime(new Date(refusal.resetsAt * 1000))}` : 'later';
|
|
19532
|
+
return { copy: `Too many uploads for now. Try again ${when}.`, retryable: true };
|
|
19533
|
+
}
|
|
19534
|
+
if (status === 0) return { copy: "This file couldn't be uploaded. Check your connection and try again.", retryable: true };
|
|
19535
|
+
const storageFull = { copy: `${company}'s storage is full, so this file can't be added.`, retryable: false };
|
|
19536
|
+
if (code === 'UPLOAD_POOL_FULL') return storageFull;
|
|
19537
|
+
if (status === 402) {
|
|
19538
|
+
if (typeof details.reason === 'string' && Object.hasOwn(CUSTOMER_UPLOAD_REFUSAL_COPY, details.reason)) {
|
|
19539
|
+
return { copy: CUSTOMER_UPLOAD_REFUSAL_COPY[details.reason], retryable: false };
|
|
19540
|
+
}
|
|
19541
|
+
if (code === 'QUOTA_EXCEEDED' && details.resource === 'storage') return storageFull;
|
|
19542
|
+
return { copy: `${company} can't take files right now.`, retryable: false };
|
|
19543
|
+
}
|
|
19544
|
+
if (status === 413) {
|
|
19545
|
+
const ceiling = details.max_bytes;
|
|
19488
19546
|
return {
|
|
19489
|
-
|
|
19490
|
-
|
|
19491
|
-
clearNotice: () => setNotice(notice, null),
|
|
19492
|
-
destroy() {
|
|
19493
|
-
form.removeEventListener('dragenter', fileEvents.dragOver);
|
|
19494
|
-
form.removeEventListener('dragover', fileEvents.dragOver);
|
|
19495
|
-
form.removeEventListener('dragleave', fileEvents.dragLeave);
|
|
19496
|
-
form.removeEventListener('drop', fileEvents.drop);
|
|
19497
|
-
for (const field of fields) {
|
|
19498
|
-
field.removeEventListener('paste', fileEvents.paste);
|
|
19499
|
-
field.removeEventListener('input', onInput);
|
|
19500
|
-
}
|
|
19501
|
-
},
|
|
19547
|
+
copy: Number.isSafeInteger(ceiling) && ceiling > 0 ? tooLargeCopy(ceiling) : 'This file is larger than this help desk accepts.',
|
|
19548
|
+
retryable: false
|
|
19502
19549
|
};
|
|
19550
|
+
}
|
|
19551
|
+
if (status === 409 && PASSING_CONFLICTS.has(code)) return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19552
|
+
if (status >= 400 && status < 500 && status !== 408) return { copy: "This file can't be attached.", retryable: false };
|
|
19553
|
+
return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19554
|
+
}
|
|
19555
|
+
|
|
19556
|
+
/** A button of the composer's. */
|
|
19557
|
+
function button$1(className, label) {
|
|
19558
|
+
const element = document.createElement('button');
|
|
19559
|
+
element.type = 'button';
|
|
19560
|
+
element.className = className;
|
|
19561
|
+
element.setAttribute('aria-label', label);
|
|
19562
|
+
return element;
|
|
19563
|
+
}
|
|
19564
|
+
|
|
19565
|
+
/**
|
|
19566
|
+
* Frame `options.textarea` as the help desk's message composer.
|
|
19567
|
+
*
|
|
19568
|
+
* @param {import('./help-desk-composer.d.ts').HelpDeskComposerOptions} options
|
|
19569
|
+
* @returns {import('./help-desk-composer.d.ts').HelpDeskComposer}
|
|
19570
|
+
*/
|
|
19571
|
+
function createHelpDeskComposer(options) {
|
|
19572
|
+
const {
|
|
19573
|
+
textarea,
|
|
19574
|
+
transport = null,
|
|
19575
|
+
deskRefusesFiles = false,
|
|
19576
|
+
organization,
|
|
19577
|
+
dropZone = null,
|
|
19578
|
+
pasteFields = [],
|
|
19579
|
+
active = () => true,
|
|
19580
|
+
onFilesChange = () => {},
|
|
19581
|
+
onStateChange = () => {}
|
|
19582
|
+
} = options;
|
|
19583
|
+
injectComposerStyles();
|
|
19584
|
+
|
|
19585
|
+
const frame = document.createElement('div');
|
|
19586
|
+
frame.className = 'svhd-composer';
|
|
19587
|
+
textarea.classList.add('svhd-composer-input');
|
|
19588
|
+
const drop = document.createElement('p');
|
|
19589
|
+
drop.className = 'svhd-composer-drop';
|
|
19590
|
+
drop.textContent = DROP_FILES_COPY;
|
|
19591
|
+
drop.hidden = true;
|
|
19592
|
+
frame.append(textarea, drop);
|
|
19593
|
+
const notice = document.createElement('p');
|
|
19594
|
+
notice.className = 'svhd-composer-notice';
|
|
19595
|
+
notice.hidden = true;
|
|
19596
|
+
const zone = dropZone ?? frame;
|
|
19597
|
+
const fields = [textarea, ...pasteFields];
|
|
19598
|
+
|
|
19599
|
+
// The Attach button, the chooser it opens (a filter that offers the
|
|
19600
|
+
// extensions a request takes first, never the check), and its (?) tip,
|
|
19601
|
+
// whose limits also describe Attach.
|
|
19602
|
+
const input = document.createElement('input');
|
|
19603
|
+
input.type = 'file';
|
|
19604
|
+
input.name = 'attachments';
|
|
19605
|
+
input.multiple = true;
|
|
19606
|
+
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
19607
|
+
input.hidden = true;
|
|
19608
|
+
input.tabIndex = -1;
|
|
19609
|
+
const hint = document.createElement('p');
|
|
19610
|
+
hint.id = `${textarea.id}-attachment-hint`;
|
|
19611
|
+
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
19612
|
+
const kinds = document.createElement('p');
|
|
19613
|
+
kinds.textContent = ACCEPTED_KINDS_COPY;
|
|
19614
|
+
const attach = button$1('svhd-composer-attach', 'Attach files');
|
|
19615
|
+
attach.setAttribute('aria-describedby', hint.id);
|
|
19616
|
+
const attachText = document.createElement('span');
|
|
19617
|
+
attachText.textContent = 'Attach';
|
|
19618
|
+
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
19619
|
+
const helpPanel = document.createElement('div');
|
|
19620
|
+
helpPanel.id = `${textarea.id}-attachment-help`;
|
|
19621
|
+
helpPanel.className = 'svhd-composer-help-panel';
|
|
19622
|
+
helpPanel.setAttribute('role', 'region');
|
|
19623
|
+
helpPanel.setAttribute('aria-label', HELP_TITLE);
|
|
19624
|
+
helpPanel.hidden = true;
|
|
19625
|
+
const helpCopy = document.createElement('div');
|
|
19626
|
+
helpCopy.className = 'svhd-composer-help-copy';
|
|
19627
|
+
helpCopy.append(hint, kinds);
|
|
19628
|
+
const helpClose = button$1('svhd-composer-help-close', 'Close');
|
|
19629
|
+
helpClose.title = 'Close';
|
|
19630
|
+
helpClose.append(helpDeskIcon('close'));
|
|
19631
|
+
helpPanel.append(helpCopy, helpClose);
|
|
19632
|
+
const helpTrigger = button$1('svhd-composer-help', `Help: ${HELP_TITLE}`);
|
|
19633
|
+
helpTrigger.setAttribute('aria-expanded', 'false');
|
|
19634
|
+
helpTrigger.setAttribute('aria-controls', helpPanel.id);
|
|
19635
|
+
const glyph = document.createElement('span');
|
|
19636
|
+
glyph.className = 'svhd-composer-help-glyph';
|
|
19637
|
+
glyph.setAttribute('aria-hidden', 'true');
|
|
19638
|
+
glyph.textContent = '?';
|
|
19639
|
+
helpTrigger.append(glyph);
|
|
19640
|
+
const toolbar = document.createElement('div');
|
|
19641
|
+
toolbar.className = 'svhd-composer-toolbar';
|
|
19642
|
+
toolbar.append(attach, helpTrigger, helpPanel, input);
|
|
19643
|
+
const list = document.createElement('ul');
|
|
19644
|
+
list.className = 'svhd-attachment-chips';
|
|
19645
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
19646
|
+
if (transport) frame.append(toolbar, list);
|
|
19647
|
+
|
|
19648
|
+
let entries = [];
|
|
19649
|
+
// Every clear starts a new revision: an answer for a file of an earlier one is dropped.
|
|
19650
|
+
let revision = 0;
|
|
19651
|
+
let locked = false;
|
|
19652
|
+
let pickingDisabled = false;
|
|
19653
|
+
let destroyed = false;
|
|
19654
|
+
const accepting = () => transport !== null && !locked && !pickingDisabled && !destroyed;
|
|
19655
|
+
const current = (entry, ownRevision) =>
|
|
19656
|
+
!destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
19657
|
+
|
|
19658
|
+
// A refusal of files is an alert only while it shows, as a field's error is.
|
|
19659
|
+
function setNotice(text) {
|
|
19660
|
+
notice.textContent = text ?? '';
|
|
19661
|
+
notice.hidden = text === null;
|
|
19662
|
+
if (text === null) notice.removeAttribute('role');
|
|
19663
|
+
else notice.setAttribute('role', 'alert');
|
|
19664
|
+
}
|
|
19665
|
+
function syncPicking() {
|
|
19666
|
+
attach.disabled = !accepting();
|
|
19667
|
+
input.disabled = !accepting();
|
|
19668
|
+
}
|
|
19669
|
+
function controls(entry) {
|
|
19670
|
+
entry.remove.disabled = locked;
|
|
19671
|
+
entry.retry.disabled = locked || Boolean(entry.operation);
|
|
19672
|
+
}
|
|
19673
|
+
function show(entry, state, text) {
|
|
19674
|
+
entry.state = state;
|
|
19675
|
+
entry.row.dataset.state = state;
|
|
19676
|
+
entry.status.textContent = text;
|
|
19677
|
+
entry.status.classList.toggle('svhd-composer-problem', state === FILE_STATE.FAILED || state === FILE_STATE.REFUSED);
|
|
19678
|
+
entry.progress.hidden = state !== FILE_STATE.UPLOADING;
|
|
19679
|
+
const action = state === FILE_STATE.RECEIVED ? 'Check upload' : 'Retry';
|
|
19680
|
+
entry.retry.hidden = !(entry.retryable && (state === FILE_STATE.FAILED || state === FILE_STATE.RECEIVED));
|
|
19681
|
+
entry.retry.textContent = action;
|
|
19682
|
+
entry.retry.setAttribute('aria-label', `${action} ${entry.file.name}`);
|
|
19683
|
+
controls(entry);
|
|
19684
|
+
if (state === FILE_STATE.COMPLETE) onFilesChange();
|
|
19685
|
+
onStateChange();
|
|
19686
|
+
}
|
|
19687
|
+
/**
|
|
19688
|
+
* Cancel an upload the customer no longer means to send, which gives its
|
|
19689
|
+
* share of their upload allowance back at once. One that does not land (a
|
|
19690
|
+
* signed-out or switched customer cannot cancel as the next one) is the
|
|
19691
|
+
* server's to reap.
|
|
19692
|
+
*/
|
|
19693
|
+
async function cancel(target, attachmentId) {
|
|
19694
|
+
if (target === null || target === undefined || !attachmentId) return;
|
|
19695
|
+
try {
|
|
19696
|
+
await transport.cancel(target, attachmentId);
|
|
19697
|
+
} catch {
|
|
19698
|
+
// As above: the server reaps the upload.
|
|
19699
|
+
}
|
|
19700
|
+
}
|
|
19701
|
+
|
|
19702
|
+
/** One attempt at a file: the browser's check, its target, then a new upload or the resumed one. */
|
|
19703
|
+
function run(entry) {
|
|
19704
|
+
if (entry.operation) return entry.operation;
|
|
19705
|
+
const ownRevision = revision;
|
|
19706
|
+
const controller = new AbortController();
|
|
19707
|
+
entry.controller = controller;
|
|
19708
|
+
const stillCurrent = () => current(entry, ownRevision) && entry.controller === controller;
|
|
19709
|
+
// Which request a failure met: the host's (its target, the initiation) or the transfer's.
|
|
19710
|
+
let request = null;
|
|
19711
|
+
const operation = (async () => {
|
|
19712
|
+
try {
|
|
19713
|
+
show(entry, FILE_STATE.CHECKING, 'Checking file');
|
|
19714
|
+
const refusal = await attachmentRefusal(entry.file, CUSTOMER_ATTACHMENT_MAX_BYTES);
|
|
19715
|
+
if (!stillCurrent()) return;
|
|
19716
|
+
if (refusal) {
|
|
19717
|
+
entry.retryable = false;
|
|
19718
|
+
show(entry, FILE_STATE.REFUSED, refusalCopy(refusal, CUSTOMER_ATTACHMENT_MAX_BYTES));
|
|
19719
|
+
return;
|
|
19720
|
+
}
|
|
19721
|
+
request = 'host';
|
|
19722
|
+
const target = await transport.target();
|
|
19723
|
+
if (!stillCurrent()) return;
|
|
19724
|
+
if (target === null) {
|
|
19725
|
+
show(entry, FILE_STATE.QUEUED, QUEUED_COPY);
|
|
19726
|
+
return;
|
|
19727
|
+
}
|
|
19728
|
+
const transfer = {
|
|
19729
|
+
signal: controller.signal,
|
|
19730
|
+
// The bar takes every step; the status line, a live region, only a change of step.
|
|
19731
|
+
onProgress: (sent, total) => {
|
|
19732
|
+
if (!stillCurrent()) return;
|
|
19733
|
+
const percent = sentPercent({ bytesSent: sent, bytesTotal: total });
|
|
19734
|
+
entry.progress.value = percent;
|
|
19735
|
+
const step = percent === 100 ? VERIFYING_COPY : UPLOADING_COPY;
|
|
19736
|
+
if (entry.status.textContent !== step) entry.status.textContent = step;
|
|
19737
|
+
}
|
|
19738
|
+
};
|
|
19739
|
+
if (entry.sessionUrl && entry.attachmentId) {
|
|
19740
|
+
// The session this file's bytes went to stands: resume it, never upload them twice.
|
|
19741
|
+
entry.target = target;
|
|
19742
|
+
show(entry, FILE_STATE.UPLOADING, 'Checking upload');
|
|
19743
|
+
request = 'transfer';
|
|
19744
|
+
await transport.resume({ sessionUrl: entry.sessionUrl }, entry.file, transfer);
|
|
19745
|
+
} else {
|
|
19746
|
+
// An upload an earlier attempt left on the server is cancelled
|
|
19747
|
+
// first, so it holds none of the allowance this one is decided on.
|
|
19748
|
+
await cancel(entry.target, entry.attachmentId);
|
|
19749
|
+
if (!stillCurrent()) return;
|
|
19750
|
+
entry.attachmentId = null;
|
|
19751
|
+
entry.target = target;
|
|
19752
|
+
show(entry, FILE_STATE.STARTING, 'Starting upload');
|
|
19753
|
+
const upload = await transport.initiate(target, { name: entry.file.name, size: entry.file.size });
|
|
19754
|
+
if (!stillCurrent()) {
|
|
19755
|
+
await cancel(target, upload?.attachment_id);
|
|
19756
|
+
return;
|
|
19757
|
+
}
|
|
19758
|
+
if (!isResourceIdOf('attachment', upload?.attachment_id)) {
|
|
19759
|
+
entry.retryable = true;
|
|
19760
|
+
show(entry, FILE_STATE.FAILED, UPLOAD_FAILED_COPY);
|
|
19761
|
+
return;
|
|
19762
|
+
}
|
|
19763
|
+
entry.attachmentId = upload.attachment_id;
|
|
19764
|
+
if (Number.isSafeInteger(upload.max_bytes) && upload.max_bytes > 0 && entry.file.size > upload.max_bytes) {
|
|
19765
|
+
entry.retryable = false;
|
|
19766
|
+
show(entry, FILE_STATE.FAILED, tooLargeCopy(upload.max_bytes));
|
|
19767
|
+
return;
|
|
19768
|
+
}
|
|
19769
|
+
entry.progress.value = 0;
|
|
19770
|
+
show(entry, FILE_STATE.UPLOADING, UPLOADING_COPY);
|
|
19771
|
+
request = 'transfer';
|
|
19772
|
+
await transport.send(upload.forge_url, entry.file, {
|
|
19773
|
+
...transfer,
|
|
19774
|
+
onSessionCreated: (session) => {
|
|
19775
|
+
if (stillCurrent()) entry.sessionUrl = session.sessionUrl;
|
|
19776
|
+
}
|
|
19777
|
+
});
|
|
19778
|
+
}
|
|
19779
|
+
if (!stillCurrent()) return;
|
|
19780
|
+
entry.progress.value = 100;
|
|
19781
|
+
entry.retryable = false;
|
|
19782
|
+
show(entry, FILE_STATE.COMPLETE, 'Attached');
|
|
19783
|
+
} catch (error) {
|
|
19784
|
+
if (!stillCurrent()) return;
|
|
19785
|
+
if (request === 'transfer' && error?.code === RECEIVED_STILL_SAVING) {
|
|
19786
|
+
entry.retryable = Boolean(entry.sessionUrl);
|
|
19787
|
+
show(entry, FILE_STATE.RECEIVED, RECEIVED_COPY);
|
|
19788
|
+
return;
|
|
19789
|
+
}
|
|
19790
|
+
if (request === 'transfer' && error?.code === SESSION_GONE) {
|
|
19791
|
+
entry.sessionUrl = null;
|
|
19792
|
+
entry.retryable = true;
|
|
19793
|
+
show(entry, FILE_STATE.FAILED, UPLOAD_FAILED_COPY);
|
|
19794
|
+
return;
|
|
19795
|
+
}
|
|
19796
|
+
const problem = uploadProblem(refusalOf(request, error), organization);
|
|
19797
|
+
entry.retryable = problem.retryable;
|
|
19798
|
+
show(entry, FILE_STATE.FAILED, problem.copy);
|
|
19799
|
+
} finally {
|
|
19800
|
+
if (entry.controller === controller) entry.controller = null;
|
|
19801
|
+
if (entry.operation === operation) entry.operation = null;
|
|
19802
|
+
if (entries.includes(entry)) controls(entry);
|
|
19803
|
+
}
|
|
19804
|
+
})();
|
|
19805
|
+
entry.operation = operation;
|
|
19806
|
+
controls(entry);
|
|
19807
|
+
return operation;
|
|
19808
|
+
}
|
|
19809
|
+
|
|
19810
|
+
/**
|
|
19811
|
+
* The refusal a failure names, read by the request it met: the host's
|
|
19812
|
+
* reading of its own refusal, or the transfer's. A host reading that throws
|
|
19813
|
+
* leaves a fault, which the customer may try again, never a stuck chip.
|
|
19814
|
+
*/
|
|
19815
|
+
function refusalOf(request, error) {
|
|
19816
|
+
if (request === 'transfer') return transferRefusal(error);
|
|
19817
|
+
if (request !== 'host') return null;
|
|
19818
|
+
try {
|
|
19819
|
+
return transport.refusal(error);
|
|
19820
|
+
} catch {
|
|
19821
|
+
return null;
|
|
19822
|
+
}
|
|
19823
|
+
}
|
|
19824
|
+
|
|
19825
|
+
function remove(entry) {
|
|
19826
|
+
if (locked) return;
|
|
19827
|
+
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19828
|
+
const refocus = document.activeElement === entry.remove;
|
|
19829
|
+
const index = entries.indexOf(entry);
|
|
19830
|
+
entry.controller?.abort();
|
|
19831
|
+
entries = entries.filter((candidate) => candidate !== entry);
|
|
19832
|
+
entry.row.remove();
|
|
19833
|
+
setNotice(null);
|
|
19834
|
+
void cancel(entry.target, entry.attachmentId);
|
|
19835
|
+
onFilesChange();
|
|
19836
|
+
onStateChange();
|
|
19837
|
+
if (refocus) (entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
19838
|
+
}
|
|
19839
|
+
|
|
19840
|
+
function add(files) {
|
|
19841
|
+
if (!accepting()) return;
|
|
19842
|
+
const incoming = Array.from(files);
|
|
19843
|
+
if (incoming.length === 0) return;
|
|
19844
|
+
const counted = entries.filter((entry) => entry.state !== FILE_STATE.REFUSED).length;
|
|
19845
|
+
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - counted);
|
|
19846
|
+
setNotice(incoming.length > room ? LIMIT_COPY : null);
|
|
19847
|
+
for (const file of incoming.slice(0, room)) {
|
|
19848
|
+
const row = document.createElement('li');
|
|
19849
|
+
row.className = 'svhd-attachment-chip';
|
|
19850
|
+
const name = document.createElement('span');
|
|
19851
|
+
name.className = 'svhd-attachment-name';
|
|
19852
|
+
name.textContent = file.name;
|
|
19853
|
+
name.title = file.name;
|
|
19854
|
+
const status = document.createElement('span');
|
|
19855
|
+
status.className = 'svhd-attachment-status';
|
|
19856
|
+
status.setAttribute('role', 'status');
|
|
19857
|
+
status.setAttribute('aria-live', 'polite');
|
|
19858
|
+
const progress = document.createElement('progress');
|
|
19859
|
+
progress.className = 'svhd-attachment-progress';
|
|
19860
|
+
progress.max = 100;
|
|
19861
|
+
progress.value = 0;
|
|
19862
|
+
progress.hidden = true;
|
|
19863
|
+
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
19864
|
+
const removeButton = button$1('svhd-attachment-remove', `Remove ${file.name}`);
|
|
19865
|
+
removeButton.append(helpDeskIcon('close'));
|
|
19866
|
+
const retry = document.createElement('button');
|
|
19867
|
+
retry.type = 'button';
|
|
19868
|
+
retry.className = 'svhd-attachment-retry';
|
|
19869
|
+
retry.hidden = true;
|
|
19870
|
+
const entry = {
|
|
19871
|
+
file, row, status, progress, remove: removeButton, retry,
|
|
19872
|
+
state: FILE_STATE.QUEUED, retryable: false, controller: null, operation: null,
|
|
19873
|
+
target: null, attachmentId: null, sessionUrl: null
|
|
19874
|
+
};
|
|
19875
|
+
removeButton.addEventListener('click', () => remove(entry));
|
|
19876
|
+
retry.addEventListener('click', () => {
|
|
19877
|
+
if (!locked && entry.retryable) void run(entry);
|
|
19878
|
+
});
|
|
19879
|
+
row.append(name, removeButton, status, retry, progress);
|
|
19880
|
+
list.append(row);
|
|
19881
|
+
entries.push(entry);
|
|
19882
|
+
void run(entry);
|
|
19883
|
+
}
|
|
19884
|
+
if (room > 0) {
|
|
19885
|
+
onFilesChange();
|
|
19886
|
+
onStateChange();
|
|
19887
|
+
}
|
|
19888
|
+
}
|
|
19889
|
+
|
|
19890
|
+
// What a file brought to the host does: join the message, be refused in words, or nothing.
|
|
19891
|
+
function fileAction() {
|
|
19892
|
+
if (!active()) return 'none';
|
|
19893
|
+
if (transport) return accepting() ? 'attach' : 'none';
|
|
19894
|
+
return deskRefusesFiles ? 'refuse' : 'none';
|
|
19895
|
+
}
|
|
19896
|
+
function dragging(value) {
|
|
19897
|
+
frame.classList.toggle('svhd-composer-dragging', value);
|
|
19898
|
+
drop.hidden = !value;
|
|
19899
|
+
}
|
|
19900
|
+
function refuseFiles() {
|
|
19901
|
+
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY) return;
|
|
19902
|
+
setNotice(NO_CUSTOMER_FILES_COPY);
|
|
19903
|
+
}
|
|
19904
|
+
// A dropped folder is left out, and said so beside any refusal the files with it met.
|
|
19905
|
+
function attachBrought(files, folders) {
|
|
19906
|
+
if (files.length > 0) add(files);
|
|
19907
|
+
if (folders > 0) setNotice(files.length > 0 && !notice.hidden ? `${FOLDER_REFUSAL_COPY} ${notice.textContent}` : FOLDER_REFUSAL_COPY);
|
|
19908
|
+
}
|
|
19909
|
+
const fileEvents = composerFileEvents({
|
|
19910
|
+
action: fileAction,
|
|
19911
|
+
frameHolds: (node) => node instanceof Node && frame.contains(node),
|
|
19912
|
+
heldNames: () => entries.map((entry) => entry.file.name),
|
|
19913
|
+
dragging,
|
|
19914
|
+
attach: attachBrought,
|
|
19915
|
+
refuse: refuseFiles
|
|
19916
|
+
});
|
|
19917
|
+
|
|
19918
|
+
// The (?) tip: a disclosure that closes by its trigger, Escape, its close
|
|
19919
|
+
// button (focus back on the trigger), a press outside it, or focus leaving it.
|
|
19920
|
+
const inTip = (node) => node instanceof Node && (helpTrigger.contains(node) || helpPanel.contains(node));
|
|
19921
|
+
function setHelpOpen(open) {
|
|
19922
|
+
helpPanel.hidden = !open;
|
|
19923
|
+
helpTrigger.setAttribute('aria-expanded', String(open));
|
|
19924
|
+
if (open) document.addEventListener('pointerdown', onPressOutsideHelp);
|
|
19925
|
+
else document.removeEventListener('pointerdown', onPressOutsideHelp);
|
|
19926
|
+
}
|
|
19927
|
+
function onPressOutsideHelp(event) {
|
|
19928
|
+
if (!inTip(event.target)) setHelpOpen(false);
|
|
19929
|
+
}
|
|
19930
|
+
const onHelpToggle = () => setHelpOpen(helpPanel.hidden);
|
|
19931
|
+
const onHelpClose = () => {
|
|
19932
|
+
setHelpOpen(false);
|
|
19933
|
+
helpTrigger.focus();
|
|
19934
|
+
};
|
|
19935
|
+
// Escape is the tip's alone while it is open: a dialog the form sits in leaves a handled key alone.
|
|
19936
|
+
const onHelpKey = (event) => {
|
|
19937
|
+
if (event.key !== 'Escape' || helpPanel.hidden) return;
|
|
19938
|
+
event.preventDefault();
|
|
19939
|
+
onHelpClose();
|
|
19940
|
+
};
|
|
19941
|
+
const onHelpFocusOut = (event) => {
|
|
19942
|
+
if (!helpPanel.hidden && event.relatedTarget && !inTip(event.relatedTarget)) setHelpOpen(false);
|
|
19943
|
+
};
|
|
19944
|
+
|
|
19945
|
+
// A desk's refusal of files gives way once the customer writes on.
|
|
19946
|
+
const onInput = () => {
|
|
19947
|
+
if (!transport) setNotice(null);
|
|
19948
|
+
};
|
|
19949
|
+
const onChoose = () => {
|
|
19950
|
+
if (input.files) add(input.files);
|
|
19951
|
+
// The same file can be chosen again after it is removed.
|
|
19952
|
+
input.value = '';
|
|
19953
|
+
};
|
|
19954
|
+
const onAttach = () => {
|
|
19955
|
+
if (!attach.disabled) input.click();
|
|
19956
|
+
};
|
|
19957
|
+
|
|
19958
|
+
zone.addEventListener('dragenter', fileEvents.dragOver);
|
|
19959
|
+
zone.addEventListener('dragover', fileEvents.dragOver);
|
|
19960
|
+
zone.addEventListener('dragleave', fileEvents.dragLeave);
|
|
19961
|
+
zone.addEventListener('drop', fileEvents.drop);
|
|
19962
|
+
for (const field of fields) {
|
|
19963
|
+
field.addEventListener('paste', fileEvents.paste);
|
|
19964
|
+
field.addEventListener('input', onInput);
|
|
19965
|
+
}
|
|
19966
|
+
input.addEventListener('change', onChoose);
|
|
19967
|
+
attach.addEventListener('click', onAttach);
|
|
19968
|
+
helpTrigger.addEventListener('click', onHelpToggle);
|
|
19969
|
+
helpClose.addEventListener('click', onHelpClose);
|
|
19970
|
+
for (const part of [helpTrigger, helpPanel]) {
|
|
19971
|
+
part.addEventListener('keydown', onHelpKey);
|
|
19972
|
+
part.addEventListener('focusout', onHelpFocusOut);
|
|
19973
|
+
}
|
|
19974
|
+
|
|
19975
|
+
function clear(keepAttached = false) {
|
|
19976
|
+
revision += 1;
|
|
19977
|
+
const previous = entries;
|
|
19978
|
+
entries = [];
|
|
19979
|
+
for (const entry of previous) {
|
|
19980
|
+
entry.controller?.abort();
|
|
19981
|
+
if (!keepAttached || entry.state !== FILE_STATE.COMPLETE) void cancel(entry.target, entry.attachmentId);
|
|
19982
|
+
}
|
|
19983
|
+
list.replaceChildren();
|
|
19984
|
+
input.value = '';
|
|
19985
|
+
setNotice(null);
|
|
19986
|
+
}
|
|
19987
|
+
|
|
19988
|
+
return {
|
|
19989
|
+
frame,
|
|
19990
|
+
notice,
|
|
19991
|
+
get hasFiles() {
|
|
19992
|
+
return entries.length > 0;
|
|
19993
|
+
},
|
|
19994
|
+
get attachmentIds() {
|
|
19995
|
+
return entries.filter((entry) => entry.state === FILE_STATE.COMPLETE).map((entry) => entry.attachmentId);
|
|
19996
|
+
},
|
|
19997
|
+
get holdCopy() {
|
|
19998
|
+
if (entries.some((entry) => IN_FLIGHT.has(entry.state))) return HOLD_COPY.uploading;
|
|
19999
|
+
if (entries.some((entry) => entry.state === FILE_STATE.RECEIVED)) return HOLD_COPY.storing;
|
|
20000
|
+
if (entries.some((entry) => entry.state === FILE_STATE.FAILED && entry.retryable)) return HOLD_COPY.retryable;
|
|
20001
|
+
if (entries.some((entry) => entry.state !== FILE_STATE.COMPLETE)) return HOLD_COPY.refused;
|
|
20002
|
+
return null;
|
|
20003
|
+
},
|
|
20004
|
+
async start() {
|
|
20005
|
+
await Promise.all(entries.map((entry) => entry.operation ?? (entry.state === FILE_STATE.QUEUED ? run(entry) : null)));
|
|
20006
|
+
},
|
|
20007
|
+
lock(value) {
|
|
20008
|
+
locked = value;
|
|
20009
|
+
syncPicking();
|
|
20010
|
+
entries.forEach(controls);
|
|
20011
|
+
},
|
|
20012
|
+
disablePicking(value) {
|
|
20013
|
+
pickingDisabled = value;
|
|
20014
|
+
syncPicking();
|
|
20015
|
+
},
|
|
20016
|
+
hideFiles(value) {
|
|
20017
|
+
list.hidden = value;
|
|
20018
|
+
},
|
|
20019
|
+
rebind(rebound) {
|
|
20020
|
+
for (const entry of entries) {
|
|
20021
|
+
if (entry.target !== null) entry.target = rebound(entry.target);
|
|
20022
|
+
}
|
|
20023
|
+
},
|
|
20024
|
+
clear,
|
|
20025
|
+
destroy(keepAttached = false) {
|
|
20026
|
+
destroyed = true;
|
|
20027
|
+
clear(keepAttached);
|
|
20028
|
+
setHelpOpen(false);
|
|
20029
|
+
zone.removeEventListener('dragenter', fileEvents.dragOver);
|
|
20030
|
+
zone.removeEventListener('dragover', fileEvents.dragOver);
|
|
20031
|
+
zone.removeEventListener('dragleave', fileEvents.dragLeave);
|
|
20032
|
+
zone.removeEventListener('drop', fileEvents.drop);
|
|
20033
|
+
for (const field of fields) {
|
|
20034
|
+
field.removeEventListener('paste', fileEvents.paste);
|
|
20035
|
+
field.removeEventListener('input', onInput);
|
|
20036
|
+
}
|
|
20037
|
+
input.removeEventListener('change', onChoose);
|
|
20038
|
+
attach.removeEventListener('click', onAttach);
|
|
20039
|
+
helpTrigger.removeEventListener('click', onHelpToggle);
|
|
20040
|
+
helpClose.removeEventListener('click', onHelpClose);
|
|
20041
|
+
for (const part of [helpTrigger, helpPanel]) {
|
|
20042
|
+
part.removeEventListener('keydown', onHelpKey);
|
|
20043
|
+
part.removeEventListener('focusout', onHelpFocusOut);
|
|
20044
|
+
}
|
|
20045
|
+
}
|
|
20046
|
+
};
|
|
19503
20047
|
}
|
|
19504
20048
|
|
|
19505
20049
|
const TTL_MS = 30 * 60 * 1000;
|
|
@@ -19646,6 +20190,18 @@ function saveFormDraft(deskId, requesterId, value) {
|
|
|
19646
20190
|
}
|
|
19647
20191
|
|
|
19648
20192
|
let formSequence = 0;
|
|
20193
|
+
/**
|
|
20194
|
+
* The desk API's refusal of a file's draft or upload, as the composer reads
|
|
20195
|
+
* it (status 0 for no answer); null for an error the SDK did not build.
|
|
20196
|
+
*/
|
|
20197
|
+
function draftUploadRefusal(error) {
|
|
20198
|
+
if (!(error instanceof SparkVaultError))
|
|
20199
|
+
return null;
|
|
20200
|
+
const details = error.details ?? null;
|
|
20201
|
+
const resetsAt = typeof details?.resets_at === 'number' ? details.resets_at
|
|
20202
|
+
: error.retryAfterMs !== null ? Math.ceil((Date.now() + error.retryAfterMs) / 1000) : null;
|
|
20203
|
+
return { status: error.statusCode ?? 0, code: error.serviceCode ?? error.code, details, resetsAt };
|
|
20204
|
+
}
|
|
19649
20205
|
/** An absent or server-side answer cannot establish that the write was refused. */
|
|
19650
20206
|
function unknownSubmissionOutcome(error) {
|
|
19651
20207
|
// The client can suppress a response after the write was accepted. A new
|
|
@@ -19696,16 +20252,16 @@ function textButton(text, action) {
|
|
|
19696
20252
|
button.addEventListener('click', action);
|
|
19697
20253
|
return button;
|
|
19698
20254
|
}
|
|
19699
|
-
const UNSENT_NOTE_COPY =
|
|
19700
|
-
const SIGN_IN_HELP_COPY =
|
|
20255
|
+
const UNSENT_NOTE_COPY = "Your request hasn't been sent yet. Sign in so we know who to reply to, then we'll send it.";
|
|
20256
|
+
const SIGN_IN_HELP_COPY = "A secure window opens. Sign in with your email, or continue with an account you're already signed in to.";
|
|
19701
20257
|
const SIGNING_IN_COPY = 'Finish signing in using the secure window.';
|
|
19702
20258
|
const SWITCHING_COPY = 'Choose an account in the secure window.';
|
|
19703
|
-
const SIGNED_OUT_COPY = '
|
|
20259
|
+
const SIGNED_OUT_COPY = "You're signed out of support. What you wrote is still here.";
|
|
19704
20260
|
const FILES_AGAIN_COPY = 'Choose your files again before sending.';
|
|
19705
|
-
const SIGN_IN_CANCELLED_COPY =
|
|
20261
|
+
const SIGN_IN_CANCELLED_COPY = "Sign-in was cancelled. Your request is still here and hasn't been sent.";
|
|
19706
20262
|
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19707
20263
|
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
19708
|
-
const WEBSITE_SIGNED_OUT_COPY = '
|
|
20264
|
+
const WEBSITE_SIGNED_OUT_COPY = "You're not signed in to the website. Sign in there, then choose Use website account again.";
|
|
19709
20265
|
const RECOVER_NOTE_COPY = 'Sign in with the same email as before to recover your saved request.';
|
|
19710
20266
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19711
20267
|
function notify$1(callback, value) {
|
|
@@ -19911,26 +20467,42 @@ function mountHelpDeskForm(client, options) {
|
|
|
19911
20467
|
event.preventDefault();
|
|
19912
20468
|
focusAtEnd(description.input);
|
|
19913
20469
|
});
|
|
19914
|
-
|
|
19915
|
-
|
|
19916
|
-
|
|
19917
|
-
|
|
19918
|
-
|
|
19919
|
-
|
|
19920
|
-
|
|
19921
|
-
|
|
19922
|
-
|
|
19923
|
-
|
|
19924
|
-
|
|
19925
|
-
|
|
20470
|
+
// A file uploads to the request's draft, made once the customer is signed
|
|
20471
|
+
// in; until then it waits for the send.
|
|
20472
|
+
const transport = client.desk.customer_can_attach_files && options.attachments !== false
|
|
20473
|
+
? {
|
|
20474
|
+
async target() {
|
|
20475
|
+
const ownGeneration = generation;
|
|
20476
|
+
const token = await tokenFor(ownGeneration);
|
|
20477
|
+
if (!token || !alive(ownGeneration))
|
|
20478
|
+
return null;
|
|
20479
|
+
const id = await ensureDraft(ownGeneration, token);
|
|
20480
|
+
if (!alive(ownGeneration))
|
|
20481
|
+
return null;
|
|
20482
|
+
return { draftId: id, expectedSessionToken: token };
|
|
20483
|
+
},
|
|
20484
|
+
initiate: (upload, file) => client.initiateDraftAttachment(upload.draftId, file, { expectedSessionToken: upload.expectedSessionToken }),
|
|
20485
|
+
cancel: (upload, attachmentId) => client.cancelDraftAttachment(upload.draftId, attachmentId, { expectedSessionToken: upload.expectedSessionToken }),
|
|
20486
|
+
send: (url, file, transfer) => client.sendAttachment(url, file, transfer),
|
|
20487
|
+
resume: (session, file, transfer) => client.resumeAttachment(session, file, transfer),
|
|
20488
|
+
refusal: draftUploadRefusal,
|
|
20489
|
+
}
|
|
20490
|
+
: null;
|
|
20491
|
+
const composer = createHelpDeskComposer({
|
|
20492
|
+
textarea: description.input,
|
|
20493
|
+
transport,
|
|
20494
|
+
deskRefusesFiles: !client.desk.customer_can_attach_files,
|
|
20495
|
+
organization: client.desk.organization_name,
|
|
20496
|
+
dropZone: form,
|
|
20497
|
+
pasteFields: [subject.input],
|
|
20498
|
+
active: () => step === 'details',
|
|
20499
|
+
// What the request carries is saved with it; a file's step is not.
|
|
20500
|
+
onFilesChange: () => {
|
|
20501
|
+
if (composer.hasFiles)
|
|
19926
20502
|
restoredFiles = false;
|
|
19927
20503
|
persistDraft();
|
|
19928
20504
|
syncLeaveGuard();
|
|
19929
|
-
}
|
|
19930
|
-
: undefined;
|
|
19931
|
-
const composer = createComposer({
|
|
19932
|
-
form, summary: subject.input, textarea: description.input, attachments,
|
|
19933
|
-
deskRefusesFiles: !client.desk.customer_can_attach_files, onRequestStep: () => step === 'details',
|
|
20505
|
+
},
|
|
19934
20506
|
});
|
|
19935
20507
|
description.wrapper.classList.add('svhd-composer-field');
|
|
19936
20508
|
description.wrapper.insertBefore(composer.frame, description.error);
|
|
@@ -20071,8 +20643,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20071
20643
|
let websiteSignedOut = false;
|
|
20072
20644
|
// The form is held while the secure window chooses another account: no send is under way.
|
|
20073
20645
|
let switchingAccount = false;
|
|
20646
|
+
/**
|
|
20647
|
+
* Save the request as the form holds it. Never while a sign-in is under
|
|
20648
|
+
* way: a session notification then blanks the fields until the sign-in's
|
|
20649
|
+
* answer confirms its customer, and nothing may save that blank over the
|
|
20650
|
+
* request.
|
|
20651
|
+
*/
|
|
20074
20652
|
function persistDraft() {
|
|
20075
|
-
if (!options.persist || completed || destroyed)
|
|
20653
|
+
if (!options.persist || completed || destroyed || authenticating)
|
|
20076
20654
|
return;
|
|
20077
20655
|
if (!draftOwner) {
|
|
20078
20656
|
// The hidden request is a previous customer's; nothing is saved over it.
|
|
@@ -20082,7 +20660,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20082
20660
|
}
|
|
20083
20661
|
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
20084
20662
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
20085
|
-
uncertain: uncertainSubmission, hadFiles: restoredFiles ||
|
|
20663
|
+
uncertain: uncertainSubmission, hadFiles: restoredFiles || composer.hasFiles,
|
|
20086
20664
|
});
|
|
20087
20665
|
}
|
|
20088
20666
|
function forgetDraft() {
|
|
@@ -20133,7 +20711,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20133
20711
|
*/
|
|
20134
20712
|
function safeComposition() {
|
|
20135
20713
|
return pending || uncertainSubmission !== null || completed ? null
|
|
20136
|
-
: { subject: subject.input.value, body: description.input.value, hadFiles:
|
|
20714
|
+
: { subject: subject.input.value, body: description.input.value, hadFiles: composer.hasFiles };
|
|
20137
20715
|
}
|
|
20138
20716
|
/** What the send button reads while nothing is in flight. */
|
|
20139
20717
|
function idleLabel() {
|
|
@@ -20317,8 +20895,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20317
20895
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
20318
20896
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
20319
20897
|
renderResend();
|
|
20320
|
-
|
|
20321
|
-
|
|
20898
|
+
composer.disablePicking(disabled || recovery !== null);
|
|
20899
|
+
composer.lock(completed || uncertainSubmission !== null);
|
|
20322
20900
|
}
|
|
20323
20901
|
function clearCode() {
|
|
20324
20902
|
code.input.value = '';
|
|
@@ -20397,7 +20975,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20397
20975
|
return false;
|
|
20398
20976
|
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null || step === 'identity'
|
|
20399
20977
|
|| edited(subject.input, filledWith('subject')) || edited(description.input, filledWith('body'))
|
|
20400
|
-
||
|
|
20978
|
+
|| composer.hasFiles;
|
|
20401
20979
|
}
|
|
20402
20980
|
/**
|
|
20403
20981
|
* The field a request the ticket write would refuse is refused under, with
|
|
@@ -20474,11 +21052,9 @@ function mountHelpDeskForm(client, options) {
|
|
|
20474
21052
|
done = null;
|
|
20475
21053
|
form.hidden = false;
|
|
20476
21054
|
closeConfirm(false);
|
|
20477
|
-
|
|
20478
|
-
|
|
20479
|
-
|
|
20480
|
-
attachments.list.hidden = false;
|
|
20481
|
-
composer.clearNotice();
|
|
21055
|
+
composer.clear(completed || uncertainSubmission !== null);
|
|
21056
|
+
composer.lock(false);
|
|
21057
|
+
composer.hideFiles(false);
|
|
20482
21058
|
subject.input.value = '';
|
|
20483
21059
|
description.input.value = '';
|
|
20484
21060
|
email.input.value = '';
|
|
@@ -20517,7 +21093,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20517
21093
|
// and never authenticates one as a side effect of cleanup.
|
|
20518
21094
|
const token = client.verifiedSessionTokenFor(change.requesterId);
|
|
20519
21095
|
if (token && previousToken) {
|
|
20520
|
-
|
|
21096
|
+
composer.rebind((upload) => upload.expectedSessionToken === previousToken ? { ...upload, expectedSessionToken: token } : upload);
|
|
20521
21097
|
sessionToken = token;
|
|
20522
21098
|
}
|
|
20523
21099
|
return;
|
|
@@ -20538,8 +21114,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20538
21114
|
name.input.value = '';
|
|
20539
21115
|
email.input.value = '';
|
|
20540
21116
|
clearCode();
|
|
20541
|
-
|
|
20542
|
-
attachments.list.hidden = true;
|
|
21117
|
+
composer.hideFiles(true);
|
|
20543
21118
|
return;
|
|
20544
21119
|
}
|
|
20545
21120
|
// Preserve the old request before hiding it. The next verified requester
|
|
@@ -20735,8 +21310,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20735
21310
|
sessionToken = token;
|
|
20736
21311
|
sessionKnown = true;
|
|
20737
21312
|
authenticating = false;
|
|
20738
|
-
|
|
20739
|
-
attachments.list.hidden = false;
|
|
21313
|
+
composer.hideFiles(false);
|
|
20740
21314
|
subject.input.value = subjectText;
|
|
20741
21315
|
description.input.value = detailsText;
|
|
20742
21316
|
if (widget && session) {
|
|
@@ -20799,8 +21373,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20799
21373
|
sessionToken = token;
|
|
20800
21374
|
sessionKnown = true;
|
|
20801
21375
|
authenticating = false;
|
|
20802
|
-
|
|
20803
|
-
attachments.list.hidden = false;
|
|
21376
|
+
composer.hideFiles(false);
|
|
20804
21377
|
dropChallenge();
|
|
20805
21378
|
subject.input.value = subjectText;
|
|
20806
21379
|
description.input.value = detailsText;
|
|
@@ -20841,12 +21414,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20841
21414
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
20842
21415
|
return;
|
|
20843
21416
|
}
|
|
20844
|
-
if (!recoveringSubmission &&
|
|
20845
|
-
await
|
|
21417
|
+
if (!recoveringSubmission && transport) {
|
|
21418
|
+
await composer.start();
|
|
20846
21419
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
20847
21420
|
return;
|
|
20848
|
-
|
|
20849
|
-
|
|
21421
|
+
const held = composer.holdCopy;
|
|
21422
|
+
if (held !== null) {
|
|
21423
|
+
message(held, true);
|
|
20850
21424
|
return;
|
|
20851
21425
|
}
|
|
20852
21426
|
}
|
|
@@ -20863,12 +21437,12 @@ function mountHelpDeskForm(client, options) {
|
|
|
20863
21437
|
sourceArticleId = options.sourceArticleId?.();
|
|
20864
21438
|
}
|
|
20865
21439
|
catch { /* Optional context cannot prevent sending. */ }
|
|
20866
|
-
uncertainSubmission = { ticketId: id, subject: subjectText, body, attachments:
|
|
21440
|
+
uncertainSubmission = { ticketId: id, subject: subjectText, body, attachments: composer.attachmentIds,
|
|
20867
21441
|
...(typeof sourceArticleId === 'string' && sourceArticleId.length > 0 && sourceArticleId.length <= 256 &&
|
|
20868
21442
|
!Array.from(sourceArticleId).some(character => character.charCodeAt(0) <= 32 || character === '\\') && { source_article_id: sourceArticleId }) };
|
|
20869
21443
|
}
|
|
20870
21444
|
persistDraft();
|
|
20871
|
-
|
|
21445
|
+
composer.lock(true);
|
|
20872
21446
|
ticketAttempted = true;
|
|
20873
21447
|
const ticket = await client.createTicket({ ...uncertainSubmission, attachments: [...uncertainSubmission.attachments], ...options.assistanceContext?.() }, { expectedSessionToken: token });
|
|
20874
21448
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20903,7 +21477,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20903
21477
|
if (draftExpired) {
|
|
20904
21478
|
draftId = null;
|
|
20905
21479
|
draftPromise = null;
|
|
20906
|
-
|
|
21480
|
+
composer.clear();
|
|
20907
21481
|
}
|
|
20908
21482
|
if (error instanceof SparkVaultError && error.serviceCode === 'PIN_INVALID') {
|
|
20909
21483
|
clearCode();
|
|
@@ -21082,8 +21656,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
21082
21656
|
destroyed = true;
|
|
21083
21657
|
generation += 1;
|
|
21084
21658
|
stopResendCountdown();
|
|
21085
|
-
|
|
21086
|
-
composer.destroy();
|
|
21659
|
+
composer.destroy(completed || uncertainSubmission !== null);
|
|
21087
21660
|
live.destroy();
|
|
21088
21661
|
unsubscribe();
|
|
21089
21662
|
form.removeEventListener('submit', onSubmit);
|
|
@@ -23474,7 +24047,12 @@ function createSupportLauncher(options, open) {
|
|
|
23474
24047
|
};
|
|
23475
24048
|
}
|
|
23476
24049
|
|
|
23477
|
-
/**
|
|
24050
|
+
/**
|
|
24051
|
+
* The support journey's only skin. Customer content stays in the product register.
|
|
24052
|
+
* The panel's focus ring is 2px, 3px out, in the desk's focus color: its width and
|
|
24053
|
+
* offset are the panel's custom properties, which the help desk composer inside
|
|
24054
|
+
* its request form reads, so the composer rings as the fields beside it do.
|
|
24055
|
+
*/
|
|
23478
24056
|
function injectHelpDeskSupportStyles() {
|
|
23479
24057
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
23480
24058
|
return;
|
|
@@ -23482,6 +24060,7 @@ function injectHelpDeskSupportStyles() {
|
|
|
23482
24060
|
style.id = 'sparkvault-help-desk-support-styles';
|
|
23483
24061
|
style.textContent = `
|
|
23484
24062
|
.svhs-panel,.svhs-panel *{box-sizing:border-box}
|
|
24063
|
+
.svhs-panel{--hd-focus-width:2px;--hd-focus-offset:3px}
|
|
23485
24064
|
.svhs-panel{position:fixed;right:calc(var(--svhs-right,24px) + env(safe-area-inset-right,0px));bottom:calc(var(--svhs-bottom,96px) + env(safe-area-inset-bottom,0px));z-index:2147482900;width:408px;height:422px;max-width:calc(100vw - 32px);max-height:calc(100dvh - var(--svhs-bottom,96px) - 24px);display:flex;flex-direction:column;overflow:hidden;border:1px solid ${DS.slate200};border-radius:12px;background:${DS.white};color:${DS.slate900};font:400 15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,'Helvetica Neue',sans-serif;text-align:left;box-shadow:${DS.shadowPopover};transform-origin:bottom right;transition:width 180ms cubic-bezier(.2,0,0,1),height 180ms cubic-bezier(.2,0,0,1)}
|
|
23486
24065
|
.svhs-panel[hidden],.svhs-panel [hidden]{display:none!important}
|
|
23487
24066
|
.svhs-panel[data-stage=results]{height:680px}
|
|
@@ -23493,7 +24072,7 @@ function injectHelpDeskSupportStyles() {
|
|
|
23493
24072
|
.svhs-panel button,.svhs-panel a{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
|
|
23494
24073
|
.svhs-panel button{appearance:none;cursor:pointer;margin:0}
|
|
23495
24074
|
.svhs-panel button:active{transform:translateY(1px)}
|
|
23496
|
-
.svhs-panel button:focus-visible,.svhs-panel a:focus-visible,.svhs-panel input:focus-visible,.svhs-panel textarea:focus-visible{outline:
|
|
24075
|
+
.svhs-panel button:focus-visible,.svhs-panel a:focus-visible,.svhs-panel input:focus-visible,.svhs-panel textarea:focus-visible{outline:var(--hd-focus-width) solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:var(--hd-focus-offset);box-shadow:none}
|
|
23497
24076
|
.svhs-panel svg{display:block;width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;flex:none;pointer-events:none}
|
|
23498
24077
|
.svhs-toolbar{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:60px;flex:none;padding:8px 14px 8px 24px;border-bottom:1px solid ${DS.slate200}}
|
|
23499
24078
|
.svhs-desk-name{font-size:14px;font-weight:600;line-height:1.35;color:${DS.slate600};overflow-wrap:anywhere;min-width:0}
|
|
@@ -23612,10 +24191,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
23612
24191
|
.svhs-contact-target .svhd-auth{gap:14px}
|
|
23613
24192
|
.svhs-contact-target .svhd-text-button{color:var(--hd-accent-ink,${DS.action})}
|
|
23614
24193
|
.svhs-contact-target .svhd-text-button:disabled{color:${DS.slate500}}
|
|
23615
|
-
.svhs-contact-target .svhd-composer:has(.svhd-composer-input:focus-visible){outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}
|
|
23616
|
-
@supports not selector(:has(*)){.svhs-contact-target .svhd-composer:focus-within{outline:2px solid var(--hd-focus,var(--hd-accent-ink,${DS.action}));outline-offset:3px}}
|
|
23617
|
-
.svhs-panel .svhd-composer-input:focus-visible{outline:none}
|
|
23618
|
-
.svhs-panel .svhd-composer button:focus-visible{outline-offset:-2px}
|
|
23619
24194
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23620
24195
|
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23621
24196
|
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
@@ -23874,120 +24449,6 @@ class SupportPhoneHistory {
|
|
|
23874
24449
|
}
|
|
23875
24450
|
}
|
|
23876
24451
|
|
|
23877
|
-
/**
|
|
23878
|
-
* A tenant's brand color and the WCAG contrast rules that decide how it may be
|
|
23879
|
-
* used: the one hex rule the server stores, the console checks and the portal
|
|
23880
|
-
* paints, the one contrast reading the console's readouts and the portal's
|
|
23881
|
-
* accent share, and the one way a readout writes that reading.
|
|
23882
|
-
*
|
|
23883
|
-
* A brand color is tenant-controlled, so it is used only when it is a
|
|
23884
|
-
* six-digit hex color, read case-insensitively and held in lowercase; anything
|
|
23885
|
-
* else (a color name, a CSS function, a value that runs on into more CSS) is
|
|
23886
|
-
* no color at all.
|
|
23887
|
-
*
|
|
23888
|
-
* A brand color can be any lightness, so whatever shows it picks what goes
|
|
23889
|
-
* with it: white or ink as the text on its fill, whichever reads more
|
|
23890
|
-
* strongly (at least 4.2:1 on any fill, as far as two inks reach on a
|
|
23891
|
-
* mid-tone), and the color itself as text only where it reaches 4.5:1 on
|
|
23892
|
-
* both grounds accent text stands on, the white surface and the canvas
|
|
23893
|
-
* tone, ink otherwise. accentProperties says that as the accent
|
|
23894
|
-
* custom properties the customer portal paints with and the console's sample
|
|
23895
|
-
* of it shows, in the design system's own tokens.
|
|
23896
|
-
*
|
|
23897
|
-
* BROWSER-SAFE: data only, no imports.
|
|
23898
|
-
*/
|
|
23899
|
-
|
|
23900
|
-
const HEX_COLOR = /^#[0-9a-f]{6}$/;
|
|
23901
|
-
|
|
23902
|
-
/** WCAG AA's floor for normal-size text. */
|
|
23903
|
-
const AA_TEXT_CONTRAST = 4.5;
|
|
23904
|
-
|
|
23905
|
-
/**
|
|
23906
|
-
* The canvas tone, the design system's `--canvas` (`--color-slate-50`): the
|
|
23907
|
-
* page ground the customer portal (its pages and a customer's own messages)
|
|
23908
|
-
* and the knowledge base's default theme set accent text on, beside the white
|
|
23909
|
-
* surface. The design system publishes its tokens only as CSS, which this
|
|
23910
|
-
* import-free module cannot read, so the value is mirrored here once, and
|
|
23911
|
-
* tests/brand-color.test.js holds it to packages/design-system/tokens/colors.css.
|
|
23912
|
-
*/
|
|
23913
|
-
const CANVAS_COLOR = '#f7fafb';
|
|
23914
|
-
|
|
23915
|
-
/**
|
|
23916
|
-
* The ink, the design system's `--ink` (`--color-slate-900`): the dark text a
|
|
23917
|
-
* pairing paints on a fill and in place of a color too light to stand as
|
|
23918
|
-
* text. Mirrored here once for the same reason as CANVAS_COLOR, and held to
|
|
23919
|
-
* packages/design-system/tokens/colors.css by tests/brand-color.test.js.
|
|
23920
|
-
*/
|
|
23921
|
-
const INK_COLOR = '#0d1a20';
|
|
23922
|
-
|
|
23923
|
-
/** Relative luminance (WCAG 2) of a validated `#rrggbb` color. */
|
|
23924
|
-
function relativeLuminance(color) {
|
|
23925
|
-
const [red, green, blue] = [1, 3, 5].map((offset) => {
|
|
23926
|
-
const channel = Number.parseInt(color.slice(offset, offset + 2), 16) / 255;
|
|
23927
|
-
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
23928
|
-
});
|
|
23929
|
-
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
23930
|
-
}
|
|
23931
|
-
|
|
23932
|
-
/** The contrast ratio of two relative luminances. */
|
|
23933
|
-
function contrastRatio(first, second) {
|
|
23934
|
-
return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
|
|
23935
|
-
}
|
|
23936
|
-
|
|
23937
|
-
/** The relative luminance of the ink a fill's text is weighed in, the real ink rather than pure black. */
|
|
23938
|
-
const INK_LUMINANCE = relativeLuminance(INK_COLOR);
|
|
23939
|
-
|
|
23940
|
-
/** The relative luminances of the grounds accent text stands on: the white surface and the canvas tone. */
|
|
23941
|
-
const TEXT_GROUNDS = Object.freeze([1, relativeLuminance(CANVAS_COLOR)]);
|
|
23942
|
-
|
|
23943
|
-
/** How strongly a color of this luminance reads as text on the ground it reads least on. */
|
|
23944
|
-
function textContrast(luminance) {
|
|
23945
|
-
return Math.min(...TEXT_GROUNDS.map((ground) => contrastRatio(luminance, ground)));
|
|
23946
|
-
}
|
|
23947
|
-
|
|
23948
|
-
/**
|
|
23949
|
-
* A brand color as it may be stored and shown, or null when the value is not
|
|
23950
|
-
* one: a `#rrggbb` hex value, read case-insensitively.
|
|
23951
|
-
*
|
|
23952
|
-
* @param {unknown} value
|
|
23953
|
-
* @returns {string|null} The color in lowercase
|
|
23954
|
-
*/
|
|
23955
|
-
function brandColor(value) {
|
|
23956
|
-
if (typeof value !== 'string') return null;
|
|
23957
|
-
const color = value.toLowerCase();
|
|
23958
|
-
return HEX_COLOR.test(color) ? color : null;
|
|
23959
|
-
}
|
|
23960
|
-
|
|
23961
|
-
/**
|
|
23962
|
-
* What goes with a brand color: the text on its fill (white or ink,
|
|
23963
|
-
* whichever reads more strongly, at least 4.2:1 on any fill) and the ink for
|
|
23964
|
-
* it as text
|
|
23965
|
-
* (the color itself where it reaches AA_TEXT_CONTRAST on both the white
|
|
23966
|
-
* surface and the canvas tone, ink otherwise).
|
|
23967
|
-
*
|
|
23968
|
-
* @param {unknown} value
|
|
23969
|
-
* @returns {{ onAccent: 'white'|'ink', accentInk: 'accent'|'ink', ratio: number }|null} Null when the value is not a brand color; `ratio` is its contrast as text (accentTextContrast)
|
|
23970
|
-
*/
|
|
23971
|
-
function accentPairing(value) {
|
|
23972
|
-
const color = brandColor(value);
|
|
23973
|
-
if (!color) return null;
|
|
23974
|
-
const luminance = relativeLuminance(color);
|
|
23975
|
-
const ratio = textContrast(luminance);
|
|
23976
|
-
return {
|
|
23977
|
-
onAccent: contrastRatio(luminance, 1) >= contrastRatio(luminance, INK_LUMINANCE) ? 'white' : 'ink',
|
|
23978
|
-
accentInk: ratio >= AA_TEXT_CONTRAST ? 'accent' : 'ink',
|
|
23979
|
-
ratio
|
|
23980
|
-
};
|
|
23981
|
-
}
|
|
23982
|
-
|
|
23983
|
-
/** Contrast between a brand fill and the label selected by accentPairing. */
|
|
23984
|
-
function accentFillContrast(value) {
|
|
23985
|
-
const color = brandColor(value);
|
|
23986
|
-
if (!color) return null;
|
|
23987
|
-
const pairing = accentPairing(color);
|
|
23988
|
-
return contrastRatio(relativeLuminance(color), pairing.onAccent === 'white' ? 1 : INK_LUMINANCE);
|
|
23989
|
-
}
|
|
23990
|
-
|
|
23991
24452
|
/** Darken only the narrow range where neither white nor the product ink reaches AA. */
|
|
23992
24453
|
function accessibleFill(color) {
|
|
23993
24454
|
let fill = color;
|
|
@@ -24422,7 +24883,7 @@ class SupportView {
|
|
|
24422
24883
|
continue;
|
|
24423
24884
|
frame.setAttribute('aria-busy', 'false');
|
|
24424
24885
|
status.hidden = false;
|
|
24425
|
-
status.replaceChildren(document.createTextNode(
|
|
24886
|
+
status.replaceChildren(document.createTextNode("This image couldn't be loaded."));
|
|
24426
24887
|
const canonical = httpUrl(this.state?.article?.canonical_url);
|
|
24427
24888
|
if (canonical) {
|
|
24428
24889
|
const link = element('a', '', 'Open the full article');
|
|
@@ -24550,7 +25011,7 @@ class SupportView {
|
|
|
24550
25011
|
this.headings.get('results').textContent = state.busy ? 'Checking for helpful articles…'
|
|
24551
25012
|
: state.kbState === 'locked' ? 'View helpful articles'
|
|
24552
25013
|
: results.length && state.kbState !== 'unavailable' ? 'These articles may help'
|
|
24553
|
-
: '
|
|
25014
|
+
: "Let's get you some help";
|
|
24554
25015
|
const signature = JSON.stringify(results);
|
|
24555
25016
|
if (signature !== this.resultSignature) {
|
|
24556
25017
|
this.resultSignature = signature;
|
|
@@ -24629,12 +25090,12 @@ class SupportView {
|
|
|
24629
25090
|
this.actions.onUnlock?.(); }));
|
|
24630
25091
|
}
|
|
24631
25092
|
else {
|
|
24632
|
-
this.resultStatus.append(element('p', 'svhs-copy',
|
|
25093
|
+
this.resultStatus.append(element('p', 'svhs-copy', "The help center isn't available from this network. You can still contact support below."));
|
|
24633
25094
|
}
|
|
24634
25095
|
}
|
|
24635
25096
|
else if (state.kbState === 'unavailable') {
|
|
24636
25097
|
this.resultStatus.removeAttribute('role');
|
|
24637
|
-
this.resultStatus.append(element('h3', 'svhs-heading',
|
|
25098
|
+
this.resultStatus.append(element('h3', 'svhs-heading', "We couldn't load the help center"), element('p', 'svhs-copy', 'Try again, or send your question to support. Your message is saved here.'));
|
|
24638
25099
|
if (this.actions.onRetry)
|
|
24639
25100
|
this.resultStatus.append(button('svhs-secondary', 'Try again', () => this.actions.onRetry?.()));
|
|
24640
25101
|
}
|
|
@@ -24660,7 +25121,7 @@ class SupportView {
|
|
|
24660
25121
|
this.articleError.hidden = !this.articleError.textContent;
|
|
24661
25122
|
this.articleRetry.hidden = !this.articleError.textContent || Boolean(state.busy) || !this.actions.onRetry;
|
|
24662
25123
|
this.articleContent.hidden = Boolean(state.busy);
|
|
24663
|
-
this.articleTitle.textContent = article?.title || (state.error ?
|
|
25124
|
+
this.articleTitle.textContent = article?.title || (state.error ? "We couldn't load this article" : 'Help article');
|
|
24664
25125
|
const category = state.results?.find((result) => result.id === article?.id)?.category;
|
|
24665
25126
|
this.articleCategory.textContent = category || '';
|
|
24666
25127
|
this.articleCategory.hidden = !category;
|
|
@@ -24769,7 +25230,7 @@ class SupportView {
|
|
|
24769
25230
|
}
|
|
24770
25231
|
renderReceipt(state) {
|
|
24771
25232
|
const receipt = state.receipt;
|
|
24772
|
-
this.receiptCopy.replaceChildren(document.createTextNode(receipt?.email ?
|
|
25233
|
+
this.receiptCopy.replaceChildren(document.createTextNode(receipt?.email ? "Your message has been sent. We'll reply to " : 'Your message has been sent.'));
|
|
24773
25234
|
if (receipt?.email)
|
|
24774
25235
|
this.receiptCopy.append(element('strong', '', receipt.email), document.createTextNode('.'));
|
|
24775
25236
|
this.receiptTicket.textContent = receipt?.ticketNumber !== undefined ? `Ticket #${receipt.ticketNumber}` : '';
|
|
@@ -30540,7 +31001,7 @@ class SparkVault {
|
|
|
30540
31001
|
}
|
|
30541
31002
|
/** Get the SDK version */
|
|
30542
31003
|
static get version() {
|
|
30543
|
-
return '16.
|
|
31004
|
+
return '16.10.0';
|
|
30544
31005
|
}
|
|
30545
31006
|
}
|
|
30546
31007
|
if (typeof window !== 'undefined') {
|