@sparkvault/sdk-js 16.8.0 → 16.9.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 +1107 -649
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1107 -649
- package/dist/index.mjs.map +1 -1
- package/dist/products/help-desk/support-styles.d.ts +6 -1
- 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,117 @@ 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 and the portal's
|
|
18942
|
+
* accent share, and the one way a readout writes that reading.
|
|
18943
|
+
*
|
|
18944
|
+
* A brand color is tenant-controlled, so it is used only when it is a
|
|
18945
|
+
* six-digit hex color, read case-insensitively and held in lowercase; anything
|
|
18946
|
+
* else (a color name, a CSS function, a value that runs on into more CSS) is
|
|
18947
|
+
* no color at all.
|
|
18948
|
+
*
|
|
18949
|
+
* A brand color can be any lightness, so whatever shows it picks what goes
|
|
18950
|
+
* with it: white or ink as the text on its fill, whichever reads more
|
|
18951
|
+
* strongly (at least 4.2:1 on any fill, as far as two inks reach on a
|
|
18952
|
+
* mid-tone), and the color itself as text only where it reaches 4.5:1 on
|
|
18953
|
+
* both grounds accent text stands on, the white surface and the canvas
|
|
18954
|
+
* tone, ink otherwise. accentProperties says that as the accent
|
|
18955
|
+
* custom properties the customer portal paints with and the console's sample
|
|
18956
|
+
* of it shows, in the design system's own tokens.
|
|
18957
|
+
*
|
|
18958
|
+
* BROWSER-SAFE: data only, no imports.
|
|
18913
18959
|
*/
|
|
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
|
-
|
|
18960
|
+
|
|
18961
|
+
const HEX_COLOR = /^#[0-9a-f]{6}$/;
|
|
18962
|
+
|
|
18963
|
+
/** WCAG AA's floor for normal-size text. */
|
|
18964
|
+
const AA_TEXT_CONTRAST = 4.5;
|
|
18965
|
+
|
|
18966
|
+
/**
|
|
18967
|
+
* The canvas tone, the design system's `--canvas` (`--color-slate-50`): the
|
|
18968
|
+
* page ground the customer portal (its pages and a customer's own messages)
|
|
18969
|
+
* and the knowledge base's default theme set accent text on, beside the white
|
|
18970
|
+
* surface. The design system publishes its tokens only as CSS, which this
|
|
18971
|
+
* import-free module cannot read, so the value is mirrored here once, and
|
|
18972
|
+
* tests/brand-color.test.js holds it to packages/design-system/tokens/colors.css.
|
|
18973
|
+
*/
|
|
18974
|
+
const CANVAS_COLOR = '#f7fafb';
|
|
18975
|
+
|
|
18976
|
+
/**
|
|
18977
|
+
* The ink, the design system's `--ink` (`--color-slate-900`): the dark text a
|
|
18978
|
+
* pairing paints on a fill and in place of a color too light to stand as
|
|
18979
|
+
* text. Mirrored here once for the same reason as CANVAS_COLOR, and held to
|
|
18980
|
+
* packages/design-system/tokens/colors.css by tests/brand-color.test.js.
|
|
18981
|
+
*/
|
|
18982
|
+
const INK_COLOR = '#0d1a20';
|
|
18983
|
+
|
|
18984
|
+
/** Relative luminance (WCAG 2) of a validated `#rrggbb` color. */
|
|
18985
|
+
function relativeLuminance(color) {
|
|
18986
|
+
const [red, green, blue] = [1, 3, 5].map((offset) => {
|
|
18987
|
+
const channel = Number.parseInt(color.slice(offset, offset + 2), 16) / 255;
|
|
18988
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
18989
|
+
});
|
|
18990
|
+
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
18940
18991
|
}
|
|
18941
18992
|
|
|
18942
|
-
/**
|
|
18943
|
-
function
|
|
18944
|
-
|
|
18945
|
-
notice.className = 'svhd-composer-notice svhd-error';
|
|
18946
|
-
notice.hidden = true;
|
|
18947
|
-
return notice;
|
|
18993
|
+
/** The contrast ratio of two relative luminances. */
|
|
18994
|
+
function contrastRatio(first, second) {
|
|
18995
|
+
return (Math.max(first, second) + 0.05) / (Math.min(first, second) + 0.05);
|
|
18948
18996
|
}
|
|
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
|
-
function
|
|
18985
|
-
|
|
18986
|
-
|
|
18987
|
-
|
|
18988
|
-
|
|
18989
|
-
|
|
18990
|
-
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
18994
|
-
|
|
18995
|
-
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19001
|
-
|
|
19002
|
-
attachText.textContent = 'Attach';
|
|
19003
|
-
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
19004
|
-
const toolbar = document.createElement('div');
|
|
19005
|
-
toolbar.className = 'svhd-composer-toolbar';
|
|
19006
|
-
toolbar.append(attach, hint, input);
|
|
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
|
-
};
|
|
18997
|
+
|
|
18998
|
+
/** The relative luminance of the ink a fill's text is weighed in, the real ink rather than pure black. */
|
|
18999
|
+
const INK_LUMINANCE = relativeLuminance(INK_COLOR);
|
|
19000
|
+
|
|
19001
|
+
/** The relative luminances of the grounds accent text stands on: the white surface and the canvas tone. */
|
|
19002
|
+
const TEXT_GROUNDS = Object.freeze([1, relativeLuminance(CANVAS_COLOR)]);
|
|
19003
|
+
|
|
19004
|
+
/** How strongly a color of this luminance reads as text on the ground it reads least on. */
|
|
19005
|
+
function textContrast(luminance) {
|
|
19006
|
+
return Math.min(...TEXT_GROUNDS.map((ground) => contrastRatio(luminance, ground)));
|
|
19007
|
+
}
|
|
19008
|
+
|
|
19009
|
+
/**
|
|
19010
|
+
* A brand color as it may be stored and shown, or null when the value is not
|
|
19011
|
+
* one: a `#rrggbb` hex value, read case-insensitively.
|
|
19012
|
+
*
|
|
19013
|
+
* @param {unknown} value
|
|
19014
|
+
* @returns {string|null} The color in lowercase
|
|
19015
|
+
*/
|
|
19016
|
+
function brandColor(value) {
|
|
19017
|
+
if (typeof value !== 'string') return null;
|
|
19018
|
+
const color = value.toLowerCase();
|
|
19019
|
+
return HEX_COLOR.test(color) ? color : null;
|
|
19020
|
+
}
|
|
19021
|
+
|
|
19022
|
+
/**
|
|
19023
|
+
* What goes with a brand color: the text on its fill (white or ink,
|
|
19024
|
+
* whichever reads more strongly, at least 4.2:1 on any fill) and the ink for
|
|
19025
|
+
* it as text
|
|
19026
|
+
* (the color itself where it reaches AA_TEXT_CONTRAST on both the white
|
|
19027
|
+
* surface and the canvas tone, ink otherwise).
|
|
19028
|
+
*
|
|
19029
|
+
* @param {unknown} value
|
|
19030
|
+
* @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)
|
|
19031
|
+
*/
|
|
19032
|
+
function accentPairing(value) {
|
|
19033
|
+
const color = brandColor(value);
|
|
19034
|
+
if (!color) return null;
|
|
19035
|
+
const luminance = relativeLuminance(color);
|
|
19036
|
+
const ratio = textContrast(luminance);
|
|
19037
|
+
return {
|
|
19038
|
+
onAccent: contrastRatio(luminance, 1) >= contrastRatio(luminance, INK_LUMINANCE) ? 'white' : 'ink',
|
|
19039
|
+
accentInk: ratio >= AA_TEXT_CONTRAST ? 'accent' : 'ink',
|
|
19040
|
+
ratio
|
|
19041
|
+
};
|
|
19042
|
+
}
|
|
19043
|
+
|
|
19044
|
+
/** Contrast between a brand fill and the label selected by accentPairing. */
|
|
19045
|
+
function accentFillContrast(value) {
|
|
19046
|
+
const color = brandColor(value);
|
|
19047
|
+
if (!color) return null;
|
|
19048
|
+
const pairing = accentPairing(color);
|
|
19049
|
+
return contrastRatio(relativeLuminance(color), pairing.onAccent === 'white' ? 1 : INK_LUMINANCE);
|
|
19257
19050
|
}
|
|
19258
19051
|
|
|
19259
19052
|
/**
|
|
@@ -19291,7 +19084,7 @@ function createFormAttachments(client, prefix, context, onEntriesChange) {
|
|
|
19291
19084
|
const DROP_FILES_COPY = 'Drop the files to attach them.';
|
|
19292
19085
|
|
|
19293
19086
|
/** What a person reads when a drop held a folder, which is never attached. */
|
|
19294
|
-
const FOLDER_REFUSAL_COPY =
|
|
19087
|
+
const FOLDER_REFUSAL_COPY = "Folders can't be attached. Add the files inside them instead.";
|
|
19295
19088
|
|
|
19296
19089
|
/** The name the clipboard gives every pasted picture, with its extension. */
|
|
19297
19090
|
const CLIPBOARD_IMAGE_NAME = /^image\.(\w+)$/;
|
|
@@ -19416,90 +19209,838 @@ function composerFileEvents({ action, frameHolds, heldNames, dragging, attach, r
|
|
|
19416
19209
|
}
|
|
19417
19210
|
|
|
19418
19211
|
/**
|
|
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
|
-
|
|
19212
|
+
* When an unread Spark expires, as a person reads it on their own clock: the
|
|
19213
|
+
* marketing site's anonymous sender states it on its ready card, and the
|
|
19214
|
+
* console's Create Spark dialog states it before the Spark is made. One
|
|
19215
|
+
* implementation, so both surfaces say the same time the same way.
|
|
19216
|
+
*
|
|
19217
|
+
* BROWSER-SAFE: no imports. It reads the runtime's own locale and time zone.
|
|
19218
|
+
*/
|
|
19219
|
+
|
|
19220
|
+
|
|
19221
|
+
/**
|
|
19222
|
+
* A time of day on the reader's own clock, in the house style where the
|
|
19223
|
+
* reader's locale reads a 12-hour clock with its period last ("4:36pm", on
|
|
19224
|
+
* the hour "5pm"), and as the locale writes it otherwise ("16:36").
|
|
19225
|
+
*
|
|
19226
|
+
* @param {Date} date
|
|
19227
|
+
* @returns {string}
|
|
19228
|
+
*/
|
|
19229
|
+
function clockTime(date) {
|
|
19230
|
+
const clock = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit' });
|
|
19231
|
+
const parts = clock.formatToParts(date);
|
|
19232
|
+
const last = parts[parts.length - 1];
|
|
19233
|
+
if (last.type !== 'dayPeriod') return clock.format(date);
|
|
19234
|
+
const part = (type) => parts.find((candidate) => candidate.type === type).value;
|
|
19235
|
+
const minute = part('minute');
|
|
19236
|
+
return `${part('hour')}${minute === '00' ? '' : `:${minute}`}${last.value.replace(/[^\p{L}]/gu, '').toLowerCase()}`;
|
|
19237
|
+
}
|
|
19238
|
+
|
|
19239
|
+
/**
|
|
19240
|
+
* The help desk's bare outline glyphs, drawn by the SDK's support wizard and
|
|
19241
|
+
* ticket form and by the one message composer (./help-desk-composer.js) the
|
|
19242
|
+
* portal's reply shares with them: stroked in `currentColor`, so the
|
|
19243
|
+
* stylesheet that sizes one also colors it, and hidden from assistive
|
|
19244
|
+
* technology, since the control that holds one names it.
|
|
19245
|
+
*
|
|
19246
|
+
* BROWSER-SAFE: builds each glyph through the page's `document`.
|
|
19247
|
+
*/
|
|
19248
|
+
|
|
19249
|
+
const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
|
|
19250
|
+
|
|
19251
|
+
const PATHS = Object.freeze({
|
|
19252
|
+
back: 'm14.5 6-6 6 6 6',
|
|
19253
|
+
close: 'm6 6 12 12M18 6 6 18',
|
|
19254
|
+
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',
|
|
19255
|
+
check: 'm5 12 4 4L19 6',
|
|
19256
|
+
article: 'M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8Zm0 0v5h5M8 12h8M8 16h6',
|
|
19257
|
+
chevron: 'm9 6 6 6-6 6',
|
|
19258
|
+
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',
|
|
19259
|
+
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',
|
|
19260
|
+
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',
|
|
19261
|
+
info: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-10v5m0-8h.01'
|
|
19262
|
+
});
|
|
19263
|
+
|
|
19264
|
+
/**
|
|
19265
|
+
* One glyph as an SVG element.
|
|
19266
|
+
*
|
|
19267
|
+
* @param {string} name - One of the glyphs' names (help-desk-icons.d.ts HelpDeskIconName)
|
|
19268
|
+
* @returns {SVGSVGElement}
|
|
19269
|
+
* @throws {TypeError} For a name no glyph has
|
|
19270
|
+
*/
|
|
19271
|
+
function helpDeskIcon(name) {
|
|
19272
|
+
if (!Object.hasOwn(PATHS, name)) throw new TypeError('No help desk icon has this name.');
|
|
19273
|
+
const svg = document.createElementNS(SVG_NAMESPACE, 'svg');
|
|
19274
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
19275
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
19276
|
+
svg.setAttribute('focusable', 'false');
|
|
19277
|
+
svg.setAttribute('fill', 'none');
|
|
19278
|
+
svg.setAttribute('stroke', 'currentColor');
|
|
19279
|
+
svg.setAttribute('stroke-width', '1.7');
|
|
19280
|
+
svg.setAttribute('stroke-linecap', 'round');
|
|
19281
|
+
svg.setAttribute('stroke-linejoin', 'round');
|
|
19282
|
+
const path = document.createElementNS(SVG_NAMESPACE, 'path');
|
|
19283
|
+
path.setAttribute('d', PATHS[name]);
|
|
19284
|
+
svg.append(path);
|
|
19285
|
+
return svg;
|
|
19286
|
+
}
|
|
19287
|
+
|
|
19288
|
+
/**
|
|
19289
|
+
* The help desk's one message composer, for a customer writing to a help
|
|
19290
|
+
* desk: the SDK's ticket form (the support wizard's request step, and the
|
|
19291
|
+
* inline form) writes a new request in it, and the portal writes a reply on
|
|
19292
|
+
* a request in it. The text sits in one bordered frame with the Attach
|
|
19293
|
+
* button and the attached files inside it, and every file the customer adds
|
|
19294
|
+
* (picked, pasted or dropped) runs through the one attachment pipeline here,
|
|
19295
|
+
* so both surfaces check, upload, resume, refuse and report a file in the
|
|
19296
|
+
* same steps and the same words.
|
|
19297
|
+
*
|
|
19298
|
+
* - **Adding.** A file picked with Attach, pasted into the text (or into a
|
|
19299
|
+
* field the host names, the SDK's summary), or dropped anywhere on the
|
|
19300
|
+
* host's drop zone joins the same list, under the per-message count
|
|
19301
|
+
* (MAX_ATTACHMENTS_PER_MESSAGE; a file the browser's check refused is no
|
|
19302
|
+
* part of it). How a drag, a drop and a paste are answered (a paste or drag
|
|
19303
|
+
* of text stays the browser's, a dropped folder is left out and said so, a
|
|
19304
|
+
* pasted picture is numbered) is @sparkvault/app-sdk/composer-files'
|
|
19305
|
+
* policy, shared with the console's composer. A file brought to a desk that
|
|
19306
|
+
* takes no files from its customers is refused in words
|
|
19307
|
+
* (NO_CUSTOMER_FILES_COPY), and one brought while files cannot join is
|
|
19308
|
+
* never the browser's to open in place of the unsent message.
|
|
19309
|
+
* - **Help.** What a message takes (how many files, how large, which kinds)
|
|
19310
|
+
* waits behind a (?) tip after Attach, a disclosure that closes by its
|
|
19311
|
+
* trigger, by Escape, by its close button, by a press outside it or by
|
|
19312
|
+
* focus leaving it; a refused file's chip names only why it was refused.
|
|
19313
|
+
* - **Uploading.** The browser's check (attachmentRefusal) first, then the
|
|
19314
|
+
* host's transport: its target (the request a reply belongs to, or the
|
|
19315
|
+
* draft a new request uploads to, which may not exist yet: the file then
|
|
19316
|
+
* waits for `start`), the upload's initiation, and the SDK's resumable
|
|
19317
|
+
* transfer. A transfer that failed after its session opened, or whose
|
|
19318
|
+
* bytes all arrived while the vault was still storing them, resumes that
|
|
19319
|
+
* session rather than uploading the file again. A chip's status line, a
|
|
19320
|
+
* polite live region, changes only with the file's step (Checking file,
|
|
19321
|
+
* Starting upload, Uploading, Verifying stored file, Attached, a failure);
|
|
19322
|
+
* the share of bytes sent (sentPercent, floored, so verifying never shows
|
|
19323
|
+
* before the last byte) is its progress bar's, outside that region.
|
|
19324
|
+
* - **Attached.** Only a file the server confirmed stored joins the message
|
|
19325
|
+
* (`attachmentIds`). A file received but still being stored holds the
|
|
19326
|
+
* message back, as Core refuses a message carrying one
|
|
19327
|
+
* (apps/api/src/help-desk/attachments.js validateAttachmentsBelong), until
|
|
19328
|
+
* its Check upload confirms it.
|
|
19329
|
+
* - **Refused.** One sentence for each refusal (uploadProblem), read from the
|
|
19330
|
+
* host's refusal of the upload's initiation (`transport.refusal`, a refusal
|
|
19331
|
+
* it cannot read a fault anyone may try again) or the transfer's own error,
|
|
19332
|
+
* and whether trying again can mend it.
|
|
19333
|
+
*
|
|
19334
|
+
* The composer draws its own stylesheet (one unlayered `<style>` per
|
|
19335
|
+
* document), in the design system's colors with the help desk's accent
|
|
19336
|
+
* (`--hd-accent-ink`) where the host sets one. Its focus ring is the one the
|
|
19337
|
+
* host's fields wear: its color, width and offset are the host's
|
|
19338
|
+
* `--hd-focus`, `--hd-focus-width` and `--hd-focus-offset`, else the SDK's
|
|
19339
|
+
* field ring (Action Blue, 3px, 2px out).
|
|
19340
|
+
*
|
|
19341
|
+
* BROWSER-SAFE: builds its DOM through the page's `document`, and imports
|
|
19342
|
+
* only app-sdk's browser-safe modules.
|
|
19343
|
+
*/
|
|
19344
|
+
|
|
19345
|
+
|
|
19346
|
+
/** The id of the composer's one `<style>` element in a document. */
|
|
19347
|
+
const HELP_DESK_COMPOSER_STYLE_ID = 'sparkvault-help-desk-composer-styles';
|
|
19348
|
+
|
|
19349
|
+
/**
|
|
19350
|
+
* The design-system colors the composer is drawn in, each the value of the
|
|
19351
|
+
* token it names (tests/help-desk-composer.test.js holds them to
|
|
19352
|
+
* packages/design-system/tokens). The canvas tone and the ink are
|
|
19353
|
+
* brand-color.js' mirrors of those tokens.
|
|
19354
|
+
*/
|
|
19355
|
+
const COMPOSER_COLORS = Object.freeze({
|
|
19356
|
+
'--color-white': '#ffffff',
|
|
19357
|
+
'--canvas': CANVAS_COLOR,
|
|
19358
|
+
'--color-slate-100': '#f0f5f7',
|
|
19359
|
+
'--color-slate-200': '#e0e9ed',
|
|
19360
|
+
'--color-slate-300': '#c9d6dc',
|
|
19361
|
+
'--color-slate-600': '#425761',
|
|
19362
|
+
'--ink': INK_COLOR,
|
|
19363
|
+
'--color-action': '#216bde',
|
|
19364
|
+
'--color-action-bg': '#eef4fe',
|
|
19365
|
+
'--color-error': '#b02b27'
|
|
19366
|
+
});
|
|
19367
|
+
|
|
19368
|
+
const C = COMPOSER_COLORS;
|
|
19369
|
+
/** The help desk's accent ink where the host sets one, Action Blue where none does. */
|
|
19370
|
+
const ACCENT_INK = `var(--hd-accent-ink,${C['--color-action']})`;
|
|
19371
|
+
/** The focus ring of the host's fields: the SDK's field ring (`.svhd-input`) where the host sets none. */
|
|
19372
|
+
const FOCUS = `var(--hd-focus,${C['--color-action']})`;
|
|
19373
|
+
const FOCUS_WIDTH = 'var(--hd-focus-width,3px)';
|
|
19374
|
+
const FOCUS_OFFSET = 'var(--hd-focus-offset,2px)';
|
|
19375
|
+
/** A control inside the frame wears the ring within its own hit area. */
|
|
19376
|
+
const INSET_RING = `outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:calc(-1 * ${FOCUS_WIDTH});box-shadow:none`;
|
|
19377
|
+
|
|
19378
|
+
/**
|
|
19379
|
+
* The composer's stylesheet. Every rule but the notice's sits under
|
|
19380
|
+
* `.svhd-composer`, a class deep, so a host's own element and focus rules
|
|
19381
|
+
* never reach into the frame; the notice, which sits under the frame, is
|
|
19382
|
+
* one class of its own.
|
|
19383
|
+
*/
|
|
19384
|
+
const COMPOSER_CSS = `
|
|
19385
|
+
.svhd-composer,.svhd-composer *{box-sizing:border-box}
|
|
19386
|
+
.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']}}
|
|
19387
|
+
.svhd-composer:has(.svhd-composer-input:focus-visible){outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:${FOCUS_OFFSET}}
|
|
19388
|
+
@supports not selector(:has(*)){.svhd-composer:focus-within{outline:${FOCUS_WIDTH} solid ${FOCUS};outline-offset:${FOCUS_OFFSET}}}
|
|
19389
|
+
.svhd-composer:has(.svhd-composer-input[aria-invalid=true]){border-color:${C['--color-error']}}
|
|
19390
|
+
.svhd-composer.svhd-composer-dragging{border-style:dashed;border-color:${ACCENT_INK}}
|
|
19391
|
+
.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}
|
|
19392
|
+
.svhd-composer .svhd-composer-input:focus,.svhd-composer .svhd-composer-input:focus-visible{outline:none;box-shadow:none}
|
|
19393
|
+
.svhd-composer .svhd-composer-input:disabled{background:${C['--canvas']}}
|
|
19394
|
+
.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}
|
|
19395
|
+
.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']}}
|
|
19396
|
+
.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}
|
|
19397
|
+
.svhd-composer .svhd-composer-attach:hover,.svhd-composer .svhd-composer-help:hover{background:${C['--color-slate-100']};color:${C['--ink']}}
|
|
19398
|
+
.svhd-composer .svhd-composer-attach:disabled{opacity:.6;cursor:default}
|
|
19399
|
+
.svhd-composer .svhd-composer-attach svg{display:block;width:18px;height:18px}
|
|
19400
|
+
.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}
|
|
19401
|
+
.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}
|
|
19402
|
+
.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}
|
|
19403
|
+
.svhd-composer .svhd-composer-help-copy{grid-column:1;min-width:0;overflow-wrap:anywhere}
|
|
19404
|
+
.svhd-composer .svhd-composer-help-copy p{margin:0}
|
|
19405
|
+
.svhd-composer .svhd-composer-help-copy p+p{margin-top:6px}
|
|
19406
|
+
.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}
|
|
19407
|
+
.svhd-composer .svhd-composer-help-close:hover,.svhd-composer .svhd-attachment-remove:hover{background:${C['--color-slate-200']};color:${C['--ink']}}
|
|
19408
|
+
.svhd-composer .svhd-composer-help-close svg,.svhd-composer .svhd-attachment-remove svg{display:block;width:16px;height:16px}
|
|
19409
|
+
.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']}}
|
|
19410
|
+
.svhd-composer .svhd-attachment-chips:empty{display:none}
|
|
19411
|
+
.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}
|
|
19412
|
+
.svhd-composer .svhd-attachment-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600;color:${C['--ink']}}
|
|
19413
|
+
.svhd-composer .svhd-attachment-status{grid-column:1;padding-right:8px;color:${C['--color-slate-600']};font-size:12px;overflow-wrap:anywhere}
|
|
19414
|
+
.svhd-composer .svhd-attachment-status.svhd-composer-problem{color:${C['--color-error']}}
|
|
19415
|
+
.svhd-composer .svhd-attachment-progress{grid-column:1/-1;width:calc(100% - 10px);height:6px;margin-top:6px;accent-color:${ACCENT_INK}}
|
|
19416
|
+
.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}
|
|
19417
|
+
.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}
|
|
19418
|
+
.svhd-composer .svhd-attachment-remove:disabled,.svhd-composer .svhd-attachment-retry:disabled{opacity:.6;cursor:default}
|
|
19419
|
+
.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}}
|
|
19420
|
+
.svhd-composer-notice{margin:0;color:${C['--color-error']};font-size:14px;line-height:1.5}
|
|
19421
|
+
.svhd-composer [hidden],.svhd-composer-notice[hidden]{display:none!important}
|
|
19422
|
+
`;
|
|
19423
|
+
|
|
19424
|
+
/** Draw the composer's stylesheet into the page, once. */
|
|
19425
|
+
function injectComposerStyles() {
|
|
19426
|
+
if (document.getElementById(HELP_DESK_COMPOSER_STYLE_ID)) return;
|
|
19427
|
+
const style = document.createElement('style');
|
|
19428
|
+
style.id = HELP_DESK_COMPOSER_STYLE_ID;
|
|
19429
|
+
style.textContent = COMPOSER_CSS;
|
|
19430
|
+
document.head.append(style);
|
|
19431
|
+
}
|
|
19432
|
+
|
|
19433
|
+
/** Where a file stands, as its chip's `data-state` names it. */
|
|
19434
|
+
const FILE_STATE = Object.freeze({
|
|
19435
|
+
/** Waiting for its target: a new request's draft that does not exist yet. */
|
|
19436
|
+
QUEUED: 'queued',
|
|
19437
|
+
CHECKING: 'checking',
|
|
19438
|
+
/** The browser's check refused it; it never reached the server. */
|
|
19439
|
+
REFUSED: 'refused',
|
|
19440
|
+
STARTING: 'starting',
|
|
19441
|
+
UPLOADING: 'uploading',
|
|
19442
|
+
/** Every byte arrived and the vault is still storing it. */
|
|
19443
|
+
RECEIVED: 'received',
|
|
19444
|
+
COMPLETE: 'complete',
|
|
19445
|
+
FAILED: 'failed'
|
|
19446
|
+
});
|
|
19447
|
+
|
|
19448
|
+
const IN_FLIGHT = new Set([FILE_STATE.QUEUED, FILE_STATE.CHECKING, FILE_STATE.STARTING, FILE_STATE.UPLOADING]);
|
|
19449
|
+
|
|
19450
|
+
const QUEUED_COPY = 'Uploads when you send your request.';
|
|
19451
|
+
const LIMIT_COPY = `You can attach up to ${MAX_ATTACHMENTS_PER_MESSAGE} files. Remove a file before adding another.`;
|
|
19452
|
+
const RECEIVED_COPY = 'File received. Waiting for storage confirmation.';
|
|
19453
|
+
const UPLOAD_FAILED_COPY = "This file couldn't be uploaded. Try again or remove it.";
|
|
19454
|
+
const UPLOADING_COPY = 'Uploading';
|
|
19455
|
+
const VERIFYING_COPY = 'Verifying stored file';
|
|
19456
|
+
/** The (?) tip's name, and what it says a message takes. */
|
|
19457
|
+
const HELP_TITLE = 'Attachment limits';
|
|
19458
|
+
const ACCEPTED_KINDS_COPY = `You can attach ${ACCEPTED_ATTACHMENTS_COPY}.`;
|
|
19459
|
+
|
|
19460
|
+
/** What a message's files still need before it can be sent, from the most pressing. */
|
|
19461
|
+
const HOLD_COPY = Object.freeze({
|
|
19462
|
+
uploading: 'Your files are still uploading.',
|
|
19463
|
+
storing: 'A file is still being stored. Check its upload in a moment, or remove it.',
|
|
19464
|
+
retryable: "Remove the files that couldn't be attached, or try them again.",
|
|
19465
|
+
refused: "Remove the files that can't be attached."
|
|
19466
|
+
});
|
|
19467
|
+
|
|
19468
|
+
/** Core's 402s for a company that cannot pay for a transfer now, which funding can mend. */
|
|
19469
|
+
const FUNDING_CODES = new Set(['USAGE_CREDITS_EXHAUSTED', 'USAGE_CREDIT_FUNDING_REVIEW', 'USAGE_CREDITS_REQUIRED']);
|
|
19470
|
+
|
|
19471
|
+
/**
|
|
19472
|
+
* The 409s a next try can get past: a write the server could not settle now
|
|
19473
|
+
* (CONFLICT), and the SDK's own answer for a customer session that changed
|
|
19474
|
+
* under the upload (HELP_DESK_SESSION_CHANGED), which the next try makes
|
|
19475
|
+
* under the session that stands.
|
|
19476
|
+
*/
|
|
19477
|
+
const PASSING_CONFLICTS = new Set(['CONFLICT', 'HELP_DESK_SESSION_CHANGED']);
|
|
19478
|
+
|
|
19479
|
+
/** The transfer's code for a session the server no longer holds: the next try uploads the file afresh. */
|
|
19480
|
+
const SESSION_GONE = 'session_gone';
|
|
19481
|
+
|
|
19482
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
19483
|
+
|
|
19484
|
+
/** A `Retry-After` in milliseconds as the moment it names, in epoch seconds, or null. */
|
|
19485
|
+
const momentAfter = (milliseconds) =>
|
|
19486
|
+
Number.isFinite(milliseconds) && milliseconds >= 0 ? Math.ceil((Date.now() + milliseconds) / 1000) : null;
|
|
19487
|
+
|
|
19488
|
+
/**
|
|
19489
|
+
* The SDK transfer's error as an UploadRefusal: the status and Core code a
|
|
19490
|
+
* refusal it met names (`details.status`, `details.coreCode`), else its own
|
|
19491
|
+
* status (0 for no answer), and its `Retry-After`.
|
|
19492
|
+
*
|
|
19493
|
+
* @param {unknown} error
|
|
19494
|
+
* @returns {import('./help-desk-composer.d.ts').UploadRefusal}
|
|
19495
|
+
*/
|
|
19496
|
+
function transferRefusal(error) {
|
|
19497
|
+
const details = isRecord(error?.details) ? error.details : null;
|
|
19498
|
+
const status = Number.isInteger(details?.status) ? details.status : Number.isInteger(error?.statusCode) ? error.statusCode : 0;
|
|
19499
|
+
return {
|
|
19500
|
+
status,
|
|
19501
|
+
code: typeof details?.coreCode === 'string' ? details.coreCode : null,
|
|
19502
|
+
details,
|
|
19503
|
+
resetsAt: momentAfter(error?.retryAfterMs)
|
|
19504
|
+
};
|
|
19505
|
+
}
|
|
19506
|
+
|
|
19507
|
+
/**
|
|
19508
|
+
* What a customer reads of a file's failed upload, and whether trying it
|
|
19509
|
+
* again can succeed: after a company's funding recovers, a rate limit, a lost
|
|
19510
|
+
* connection, a conflict a next try gets past (PASSING_CONFLICTS), or a fault. A
|
|
19511
|
+
* refusal of the file itself (its size, the customer's upload allowance, the
|
|
19512
|
+
* company's storage, any other final 4xx) stands however often it is tried.
|
|
19513
|
+
* Null, an error neither the host nor the transfer could read, is a fault.
|
|
19514
|
+
*
|
|
19515
|
+
* @param {import('./help-desk-composer.d.ts').UploadRefusal | null} refusal
|
|
19516
|
+
* @param {string | null} organization - The help desk's company, as the desk names it, or null where it names none
|
|
19517
|
+
* @returns {{ copy: string, retryable: boolean }}
|
|
19518
|
+
*/
|
|
19519
|
+
function uploadProblem(refusal, organization) {
|
|
19520
|
+
if (refusal === null) return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19521
|
+
const company = organization || 'This help desk';
|
|
19522
|
+
const { status, code } = refusal;
|
|
19523
|
+
const details = isRecord(refusal.details) ? refusal.details : {};
|
|
19524
|
+
if (status === 402 && FUNDING_CODES.has(code)) {
|
|
19525
|
+
return { copy: `${company} can't take files right now. Try again later.`, retryable: true };
|
|
19526
|
+
}
|
|
19527
|
+
if (status === 429) {
|
|
19528
|
+
const when = Number.isFinite(refusal.resetsAt) ? `at ${clockTime(new Date(refusal.resetsAt * 1000))}` : 'later';
|
|
19529
|
+
return { copy: `Too many uploads for now. Try again ${when}.`, retryable: true };
|
|
19530
|
+
}
|
|
19531
|
+
if (status === 0) return { copy: "This file couldn't be uploaded. Check your connection and try again.", retryable: true };
|
|
19532
|
+
const storageFull = { copy: `${company}'s storage is full, so this file can't be added.`, retryable: false };
|
|
19533
|
+
if (code === 'UPLOAD_POOL_FULL') return storageFull;
|
|
19534
|
+
if (status === 402) {
|
|
19535
|
+
if (typeof details.reason === 'string' && Object.hasOwn(CUSTOMER_UPLOAD_REFUSAL_COPY, details.reason)) {
|
|
19536
|
+
return { copy: CUSTOMER_UPLOAD_REFUSAL_COPY[details.reason], retryable: false };
|
|
19537
|
+
}
|
|
19538
|
+
if (code === 'QUOTA_EXCEEDED' && details.resource === 'storage') return storageFull;
|
|
19539
|
+
return { copy: `${company} can't take files right now.`, retryable: false };
|
|
19540
|
+
}
|
|
19541
|
+
if (status === 413) {
|
|
19542
|
+
const ceiling = details.max_bytes;
|
|
19488
19543
|
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
|
-
},
|
|
19544
|
+
copy: Number.isSafeInteger(ceiling) && ceiling > 0 ? tooLargeCopy(ceiling) : 'This file is larger than this help desk accepts.',
|
|
19545
|
+
retryable: false
|
|
19502
19546
|
};
|
|
19547
|
+
}
|
|
19548
|
+
if (status === 409 && PASSING_CONFLICTS.has(code)) return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19549
|
+
if (status >= 400 && status < 500 && status !== 408) return { copy: "This file can't be attached.", retryable: false };
|
|
19550
|
+
return { copy: UPLOAD_FAILED_COPY, retryable: true };
|
|
19551
|
+
}
|
|
19552
|
+
|
|
19553
|
+
/** A button of the composer's. */
|
|
19554
|
+
function button$1(className, label) {
|
|
19555
|
+
const element = document.createElement('button');
|
|
19556
|
+
element.type = 'button';
|
|
19557
|
+
element.className = className;
|
|
19558
|
+
element.setAttribute('aria-label', label);
|
|
19559
|
+
return element;
|
|
19560
|
+
}
|
|
19561
|
+
|
|
19562
|
+
/**
|
|
19563
|
+
* Frame `options.textarea` as the help desk's message composer.
|
|
19564
|
+
*
|
|
19565
|
+
* @param {import('./help-desk-composer.d.ts').HelpDeskComposerOptions} options
|
|
19566
|
+
* @returns {import('./help-desk-composer.d.ts').HelpDeskComposer}
|
|
19567
|
+
*/
|
|
19568
|
+
function createHelpDeskComposer(options) {
|
|
19569
|
+
const {
|
|
19570
|
+
textarea,
|
|
19571
|
+
transport = null,
|
|
19572
|
+
deskRefusesFiles = false,
|
|
19573
|
+
organization,
|
|
19574
|
+
dropZone = null,
|
|
19575
|
+
pasteFields = [],
|
|
19576
|
+
active = () => true,
|
|
19577
|
+
onFilesChange = () => {},
|
|
19578
|
+
onStateChange = () => {}
|
|
19579
|
+
} = options;
|
|
19580
|
+
injectComposerStyles();
|
|
19581
|
+
|
|
19582
|
+
const frame = document.createElement('div');
|
|
19583
|
+
frame.className = 'svhd-composer';
|
|
19584
|
+
textarea.classList.add('svhd-composer-input');
|
|
19585
|
+
const drop = document.createElement('p');
|
|
19586
|
+
drop.className = 'svhd-composer-drop';
|
|
19587
|
+
drop.textContent = DROP_FILES_COPY;
|
|
19588
|
+
drop.hidden = true;
|
|
19589
|
+
frame.append(textarea, drop);
|
|
19590
|
+
const notice = document.createElement('p');
|
|
19591
|
+
notice.className = 'svhd-composer-notice';
|
|
19592
|
+
notice.hidden = true;
|
|
19593
|
+
const zone = dropZone ?? frame;
|
|
19594
|
+
const fields = [textarea, ...pasteFields];
|
|
19595
|
+
|
|
19596
|
+
// The Attach button, the chooser it opens (a filter that offers the
|
|
19597
|
+
// extensions a request takes first, never the check), and its (?) tip,
|
|
19598
|
+
// whose limits also describe Attach.
|
|
19599
|
+
const input = document.createElement('input');
|
|
19600
|
+
input.type = 'file';
|
|
19601
|
+
input.name = 'attachments';
|
|
19602
|
+
input.multiple = true;
|
|
19603
|
+
input.accept = ATTACHMENT_INPUT_ACCEPT;
|
|
19604
|
+
input.hidden = true;
|
|
19605
|
+
input.tabIndex = -1;
|
|
19606
|
+
const hint = document.createElement('p');
|
|
19607
|
+
hint.id = `${textarea.id}-attachment-hint`;
|
|
19608
|
+
hint.textContent = CUSTOMER_ATTACHMENTS_HINT;
|
|
19609
|
+
const kinds = document.createElement('p');
|
|
19610
|
+
kinds.textContent = ACCEPTED_KINDS_COPY;
|
|
19611
|
+
const attach = button$1('svhd-composer-attach', 'Attach files');
|
|
19612
|
+
attach.setAttribute('aria-describedby', hint.id);
|
|
19613
|
+
const attachText = document.createElement('span');
|
|
19614
|
+
attachText.textContent = 'Attach';
|
|
19615
|
+
attach.append(helpDeskIcon('paperclip'), attachText);
|
|
19616
|
+
const helpPanel = document.createElement('div');
|
|
19617
|
+
helpPanel.id = `${textarea.id}-attachment-help`;
|
|
19618
|
+
helpPanel.className = 'svhd-composer-help-panel';
|
|
19619
|
+
helpPanel.setAttribute('role', 'region');
|
|
19620
|
+
helpPanel.setAttribute('aria-label', HELP_TITLE);
|
|
19621
|
+
helpPanel.hidden = true;
|
|
19622
|
+
const helpCopy = document.createElement('div');
|
|
19623
|
+
helpCopy.className = 'svhd-composer-help-copy';
|
|
19624
|
+
helpCopy.append(hint, kinds);
|
|
19625
|
+
const helpClose = button$1('svhd-composer-help-close', 'Close');
|
|
19626
|
+
helpClose.title = 'Close';
|
|
19627
|
+
helpClose.append(helpDeskIcon('close'));
|
|
19628
|
+
helpPanel.append(helpCopy, helpClose);
|
|
19629
|
+
const helpTrigger = button$1('svhd-composer-help', `Help: ${HELP_TITLE}`);
|
|
19630
|
+
helpTrigger.setAttribute('aria-expanded', 'false');
|
|
19631
|
+
helpTrigger.setAttribute('aria-controls', helpPanel.id);
|
|
19632
|
+
const glyph = document.createElement('span');
|
|
19633
|
+
glyph.className = 'svhd-composer-help-glyph';
|
|
19634
|
+
glyph.setAttribute('aria-hidden', 'true');
|
|
19635
|
+
glyph.textContent = '?';
|
|
19636
|
+
helpTrigger.append(glyph);
|
|
19637
|
+
const toolbar = document.createElement('div');
|
|
19638
|
+
toolbar.className = 'svhd-composer-toolbar';
|
|
19639
|
+
toolbar.append(attach, helpTrigger, helpPanel, input);
|
|
19640
|
+
const list = document.createElement('ul');
|
|
19641
|
+
list.className = 'svhd-attachment-chips';
|
|
19642
|
+
list.setAttribute('aria-label', 'Attached files');
|
|
19643
|
+
if (transport) frame.append(toolbar, list);
|
|
19644
|
+
|
|
19645
|
+
let entries = [];
|
|
19646
|
+
// Every clear starts a new revision: an answer for a file of an earlier one is dropped.
|
|
19647
|
+
let revision = 0;
|
|
19648
|
+
let locked = false;
|
|
19649
|
+
let pickingDisabled = false;
|
|
19650
|
+
let destroyed = false;
|
|
19651
|
+
const accepting = () => transport !== null && !locked && !pickingDisabled && !destroyed;
|
|
19652
|
+
const current = (entry, ownRevision) =>
|
|
19653
|
+
!destroyed && revision === ownRevision && entries.includes(entry) && !entry.controller?.signal.aborted;
|
|
19654
|
+
|
|
19655
|
+
// A refusal of files is an alert only while it shows, as a field's error is.
|
|
19656
|
+
function setNotice(text) {
|
|
19657
|
+
notice.textContent = text ?? '';
|
|
19658
|
+
notice.hidden = text === null;
|
|
19659
|
+
if (text === null) notice.removeAttribute('role');
|
|
19660
|
+
else notice.setAttribute('role', 'alert');
|
|
19661
|
+
}
|
|
19662
|
+
function syncPicking() {
|
|
19663
|
+
attach.disabled = !accepting();
|
|
19664
|
+
input.disabled = !accepting();
|
|
19665
|
+
}
|
|
19666
|
+
function controls(entry) {
|
|
19667
|
+
entry.remove.disabled = locked;
|
|
19668
|
+
entry.retry.disabled = locked || Boolean(entry.operation);
|
|
19669
|
+
}
|
|
19670
|
+
function show(entry, state, text) {
|
|
19671
|
+
entry.state = state;
|
|
19672
|
+
entry.row.dataset.state = state;
|
|
19673
|
+
entry.status.textContent = text;
|
|
19674
|
+
entry.status.classList.toggle('svhd-composer-problem', state === FILE_STATE.FAILED || state === FILE_STATE.REFUSED);
|
|
19675
|
+
entry.progress.hidden = state !== FILE_STATE.UPLOADING;
|
|
19676
|
+
const action = state === FILE_STATE.RECEIVED ? 'Check upload' : 'Retry';
|
|
19677
|
+
entry.retry.hidden = !(entry.retryable && (state === FILE_STATE.FAILED || state === FILE_STATE.RECEIVED));
|
|
19678
|
+
entry.retry.textContent = action;
|
|
19679
|
+
entry.retry.setAttribute('aria-label', `${action} ${entry.file.name}`);
|
|
19680
|
+
controls(entry);
|
|
19681
|
+
if (state === FILE_STATE.COMPLETE) onFilesChange();
|
|
19682
|
+
onStateChange();
|
|
19683
|
+
}
|
|
19684
|
+
/**
|
|
19685
|
+
* Cancel an upload the customer no longer means to send, which gives its
|
|
19686
|
+
* share of their upload allowance back at once. One that does not land (a
|
|
19687
|
+
* signed-out or switched customer cannot cancel as the next one) is the
|
|
19688
|
+
* server's to reap.
|
|
19689
|
+
*/
|
|
19690
|
+
async function cancel(target, attachmentId) {
|
|
19691
|
+
if (target === null || target === undefined || !attachmentId) return;
|
|
19692
|
+
try {
|
|
19693
|
+
await transport.cancel(target, attachmentId);
|
|
19694
|
+
} catch {
|
|
19695
|
+
// As above: the server reaps the upload.
|
|
19696
|
+
}
|
|
19697
|
+
}
|
|
19698
|
+
|
|
19699
|
+
/** One attempt at a file: the browser's check, its target, then a new upload or the resumed one. */
|
|
19700
|
+
function run(entry) {
|
|
19701
|
+
if (entry.operation) return entry.operation;
|
|
19702
|
+
const ownRevision = revision;
|
|
19703
|
+
const controller = new AbortController();
|
|
19704
|
+
entry.controller = controller;
|
|
19705
|
+
const stillCurrent = () => current(entry, ownRevision) && entry.controller === controller;
|
|
19706
|
+
// Which request a failure met: the host's (its target, the initiation) or the transfer's.
|
|
19707
|
+
let request = null;
|
|
19708
|
+
const operation = (async () => {
|
|
19709
|
+
try {
|
|
19710
|
+
show(entry, FILE_STATE.CHECKING, 'Checking file');
|
|
19711
|
+
const refusal = await attachmentRefusal(entry.file, CUSTOMER_ATTACHMENT_MAX_BYTES);
|
|
19712
|
+
if (!stillCurrent()) return;
|
|
19713
|
+
if (refusal) {
|
|
19714
|
+
entry.retryable = false;
|
|
19715
|
+
show(entry, FILE_STATE.REFUSED, refusalCopy(refusal, CUSTOMER_ATTACHMENT_MAX_BYTES));
|
|
19716
|
+
return;
|
|
19717
|
+
}
|
|
19718
|
+
request = 'host';
|
|
19719
|
+
const target = await transport.target();
|
|
19720
|
+
if (!stillCurrent()) return;
|
|
19721
|
+
if (target === null) {
|
|
19722
|
+
show(entry, FILE_STATE.QUEUED, QUEUED_COPY);
|
|
19723
|
+
return;
|
|
19724
|
+
}
|
|
19725
|
+
const transfer = {
|
|
19726
|
+
signal: controller.signal,
|
|
19727
|
+
// The bar takes every step; the status line, a live region, only a change of step.
|
|
19728
|
+
onProgress: (sent, total) => {
|
|
19729
|
+
if (!stillCurrent()) return;
|
|
19730
|
+
const percent = sentPercent({ bytesSent: sent, bytesTotal: total });
|
|
19731
|
+
entry.progress.value = percent;
|
|
19732
|
+
const step = percent === 100 ? VERIFYING_COPY : UPLOADING_COPY;
|
|
19733
|
+
if (entry.status.textContent !== step) entry.status.textContent = step;
|
|
19734
|
+
}
|
|
19735
|
+
};
|
|
19736
|
+
if (entry.sessionUrl && entry.attachmentId) {
|
|
19737
|
+
// The session this file's bytes went to stands: resume it, never upload them twice.
|
|
19738
|
+
entry.target = target;
|
|
19739
|
+
show(entry, FILE_STATE.UPLOADING, 'Checking upload');
|
|
19740
|
+
request = 'transfer';
|
|
19741
|
+
await transport.resume({ sessionUrl: entry.sessionUrl }, entry.file, transfer);
|
|
19742
|
+
} else {
|
|
19743
|
+
// An upload an earlier attempt left on the server is cancelled
|
|
19744
|
+
// first, so it holds none of the allowance this one is decided on.
|
|
19745
|
+
await cancel(entry.target, entry.attachmentId);
|
|
19746
|
+
if (!stillCurrent()) return;
|
|
19747
|
+
entry.attachmentId = null;
|
|
19748
|
+
entry.target = target;
|
|
19749
|
+
show(entry, FILE_STATE.STARTING, 'Starting upload');
|
|
19750
|
+
const upload = await transport.initiate(target, { name: entry.file.name, size: entry.file.size });
|
|
19751
|
+
if (!stillCurrent()) {
|
|
19752
|
+
await cancel(target, upload?.attachment_id);
|
|
19753
|
+
return;
|
|
19754
|
+
}
|
|
19755
|
+
if (!isResourceIdOf('attachment', upload?.attachment_id)) {
|
|
19756
|
+
entry.retryable = true;
|
|
19757
|
+
show(entry, FILE_STATE.FAILED, UPLOAD_FAILED_COPY);
|
|
19758
|
+
return;
|
|
19759
|
+
}
|
|
19760
|
+
entry.attachmentId = upload.attachment_id;
|
|
19761
|
+
if (Number.isSafeInteger(upload.max_bytes) && upload.max_bytes > 0 && entry.file.size > upload.max_bytes) {
|
|
19762
|
+
entry.retryable = false;
|
|
19763
|
+
show(entry, FILE_STATE.FAILED, tooLargeCopy(upload.max_bytes));
|
|
19764
|
+
return;
|
|
19765
|
+
}
|
|
19766
|
+
entry.progress.value = 0;
|
|
19767
|
+
show(entry, FILE_STATE.UPLOADING, UPLOADING_COPY);
|
|
19768
|
+
request = 'transfer';
|
|
19769
|
+
await transport.send(upload.forge_url, entry.file, {
|
|
19770
|
+
...transfer,
|
|
19771
|
+
onSessionCreated: (session) => {
|
|
19772
|
+
if (stillCurrent()) entry.sessionUrl = session.sessionUrl;
|
|
19773
|
+
}
|
|
19774
|
+
});
|
|
19775
|
+
}
|
|
19776
|
+
if (!stillCurrent()) return;
|
|
19777
|
+
entry.progress.value = 100;
|
|
19778
|
+
entry.retryable = false;
|
|
19779
|
+
show(entry, FILE_STATE.COMPLETE, 'Attached');
|
|
19780
|
+
} catch (error) {
|
|
19781
|
+
if (!stillCurrent()) return;
|
|
19782
|
+
if (request === 'transfer' && error?.code === RECEIVED_STILL_SAVING) {
|
|
19783
|
+
entry.retryable = Boolean(entry.sessionUrl);
|
|
19784
|
+
show(entry, FILE_STATE.RECEIVED, RECEIVED_COPY);
|
|
19785
|
+
return;
|
|
19786
|
+
}
|
|
19787
|
+
if (request === 'transfer' && error?.code === SESSION_GONE) {
|
|
19788
|
+
entry.sessionUrl = null;
|
|
19789
|
+
entry.retryable = true;
|
|
19790
|
+
show(entry, FILE_STATE.FAILED, UPLOAD_FAILED_COPY);
|
|
19791
|
+
return;
|
|
19792
|
+
}
|
|
19793
|
+
const problem = uploadProblem(refusalOf(request, error), organization);
|
|
19794
|
+
entry.retryable = problem.retryable;
|
|
19795
|
+
show(entry, FILE_STATE.FAILED, problem.copy);
|
|
19796
|
+
} finally {
|
|
19797
|
+
if (entry.controller === controller) entry.controller = null;
|
|
19798
|
+
if (entry.operation === operation) entry.operation = null;
|
|
19799
|
+
if (entries.includes(entry)) controls(entry);
|
|
19800
|
+
}
|
|
19801
|
+
})();
|
|
19802
|
+
entry.operation = operation;
|
|
19803
|
+
controls(entry);
|
|
19804
|
+
return operation;
|
|
19805
|
+
}
|
|
19806
|
+
|
|
19807
|
+
/**
|
|
19808
|
+
* The refusal a failure names, read by the request it met: the host's
|
|
19809
|
+
* reading of its own refusal, or the transfer's. A host reading that throws
|
|
19810
|
+
* leaves a fault, which the customer may try again, never a stuck chip.
|
|
19811
|
+
*/
|
|
19812
|
+
function refusalOf(request, error) {
|
|
19813
|
+
if (request === 'transfer') return transferRefusal(error);
|
|
19814
|
+
if (request !== 'host') return null;
|
|
19815
|
+
try {
|
|
19816
|
+
return transport.refusal(error);
|
|
19817
|
+
} catch {
|
|
19818
|
+
return null;
|
|
19819
|
+
}
|
|
19820
|
+
}
|
|
19821
|
+
|
|
19822
|
+
function remove(entry) {
|
|
19823
|
+
if (locked) return;
|
|
19824
|
+
// A keyboard removal keeps focus among the files, else on Attach.
|
|
19825
|
+
const refocus = document.activeElement === entry.remove;
|
|
19826
|
+
const index = entries.indexOf(entry);
|
|
19827
|
+
entry.controller?.abort();
|
|
19828
|
+
entries = entries.filter((candidate) => candidate !== entry);
|
|
19829
|
+
entry.row.remove();
|
|
19830
|
+
setNotice(null);
|
|
19831
|
+
void cancel(entry.target, entry.attachmentId);
|
|
19832
|
+
onFilesChange();
|
|
19833
|
+
onStateChange();
|
|
19834
|
+
if (refocus) (entries[Math.min(index, entries.length - 1)]?.remove ?? attach).focus();
|
|
19835
|
+
}
|
|
19836
|
+
|
|
19837
|
+
function add(files) {
|
|
19838
|
+
if (!accepting()) return;
|
|
19839
|
+
const incoming = Array.from(files);
|
|
19840
|
+
if (incoming.length === 0) return;
|
|
19841
|
+
const counted = entries.filter((entry) => entry.state !== FILE_STATE.REFUSED).length;
|
|
19842
|
+
const room = Math.max(0, MAX_ATTACHMENTS_PER_MESSAGE - counted);
|
|
19843
|
+
setNotice(incoming.length > room ? LIMIT_COPY : null);
|
|
19844
|
+
for (const file of incoming.slice(0, room)) {
|
|
19845
|
+
const row = document.createElement('li');
|
|
19846
|
+
row.className = 'svhd-attachment-chip';
|
|
19847
|
+
const name = document.createElement('span');
|
|
19848
|
+
name.className = 'svhd-attachment-name';
|
|
19849
|
+
name.textContent = file.name;
|
|
19850
|
+
name.title = file.name;
|
|
19851
|
+
const status = document.createElement('span');
|
|
19852
|
+
status.className = 'svhd-attachment-status';
|
|
19853
|
+
status.setAttribute('role', 'status');
|
|
19854
|
+
status.setAttribute('aria-live', 'polite');
|
|
19855
|
+
const progress = document.createElement('progress');
|
|
19856
|
+
progress.className = 'svhd-attachment-progress';
|
|
19857
|
+
progress.max = 100;
|
|
19858
|
+
progress.value = 0;
|
|
19859
|
+
progress.hidden = true;
|
|
19860
|
+
progress.setAttribute('aria-label', `Upload progress for ${file.name}`);
|
|
19861
|
+
const removeButton = button$1('svhd-attachment-remove', `Remove ${file.name}`);
|
|
19862
|
+
removeButton.append(helpDeskIcon('close'));
|
|
19863
|
+
const retry = document.createElement('button');
|
|
19864
|
+
retry.type = 'button';
|
|
19865
|
+
retry.className = 'svhd-attachment-retry';
|
|
19866
|
+
retry.hidden = true;
|
|
19867
|
+
const entry = {
|
|
19868
|
+
file, row, status, progress, remove: removeButton, retry,
|
|
19869
|
+
state: FILE_STATE.QUEUED, retryable: false, controller: null, operation: null,
|
|
19870
|
+
target: null, attachmentId: null, sessionUrl: null
|
|
19871
|
+
};
|
|
19872
|
+
removeButton.addEventListener('click', () => remove(entry));
|
|
19873
|
+
retry.addEventListener('click', () => {
|
|
19874
|
+
if (!locked && entry.retryable) void run(entry);
|
|
19875
|
+
});
|
|
19876
|
+
row.append(name, removeButton, status, retry, progress);
|
|
19877
|
+
list.append(row);
|
|
19878
|
+
entries.push(entry);
|
|
19879
|
+
void run(entry);
|
|
19880
|
+
}
|
|
19881
|
+
if (room > 0) {
|
|
19882
|
+
onFilesChange();
|
|
19883
|
+
onStateChange();
|
|
19884
|
+
}
|
|
19885
|
+
}
|
|
19886
|
+
|
|
19887
|
+
// What a file brought to the host does: join the message, be refused in words, or nothing.
|
|
19888
|
+
function fileAction() {
|
|
19889
|
+
if (!active()) return 'none';
|
|
19890
|
+
if (transport) return accepting() ? 'attach' : 'none';
|
|
19891
|
+
return deskRefusesFiles ? 'refuse' : 'none';
|
|
19892
|
+
}
|
|
19893
|
+
function dragging(value) {
|
|
19894
|
+
frame.classList.toggle('svhd-composer-dragging', value);
|
|
19895
|
+
drop.hidden = !value;
|
|
19896
|
+
}
|
|
19897
|
+
function refuseFiles() {
|
|
19898
|
+
if (!notice.hidden && notice.textContent === NO_CUSTOMER_FILES_COPY) return;
|
|
19899
|
+
setNotice(NO_CUSTOMER_FILES_COPY);
|
|
19900
|
+
}
|
|
19901
|
+
// A dropped folder is left out, and said so beside any refusal the files with it met.
|
|
19902
|
+
function attachBrought(files, folders) {
|
|
19903
|
+
if (files.length > 0) add(files);
|
|
19904
|
+
if (folders > 0) setNotice(files.length > 0 && !notice.hidden ? `${FOLDER_REFUSAL_COPY} ${notice.textContent}` : FOLDER_REFUSAL_COPY);
|
|
19905
|
+
}
|
|
19906
|
+
const fileEvents = composerFileEvents({
|
|
19907
|
+
action: fileAction,
|
|
19908
|
+
frameHolds: (node) => node instanceof Node && frame.contains(node),
|
|
19909
|
+
heldNames: () => entries.map((entry) => entry.file.name),
|
|
19910
|
+
dragging,
|
|
19911
|
+
attach: attachBrought,
|
|
19912
|
+
refuse: refuseFiles
|
|
19913
|
+
});
|
|
19914
|
+
|
|
19915
|
+
// The (?) tip: a disclosure that closes by its trigger, Escape, its close
|
|
19916
|
+
// button (focus back on the trigger), a press outside it, or focus leaving it.
|
|
19917
|
+
const inTip = (node) => node instanceof Node && (helpTrigger.contains(node) || helpPanel.contains(node));
|
|
19918
|
+
function setHelpOpen(open) {
|
|
19919
|
+
helpPanel.hidden = !open;
|
|
19920
|
+
helpTrigger.setAttribute('aria-expanded', String(open));
|
|
19921
|
+
if (open) document.addEventListener('pointerdown', onPressOutsideHelp);
|
|
19922
|
+
else document.removeEventListener('pointerdown', onPressOutsideHelp);
|
|
19923
|
+
}
|
|
19924
|
+
function onPressOutsideHelp(event) {
|
|
19925
|
+
if (!inTip(event.target)) setHelpOpen(false);
|
|
19926
|
+
}
|
|
19927
|
+
const onHelpToggle = () => setHelpOpen(helpPanel.hidden);
|
|
19928
|
+
const onHelpClose = () => {
|
|
19929
|
+
setHelpOpen(false);
|
|
19930
|
+
helpTrigger.focus();
|
|
19931
|
+
};
|
|
19932
|
+
// Escape is the tip's alone while it is open: a dialog the form sits in leaves a handled key alone.
|
|
19933
|
+
const onHelpKey = (event) => {
|
|
19934
|
+
if (event.key !== 'Escape' || helpPanel.hidden) return;
|
|
19935
|
+
event.preventDefault();
|
|
19936
|
+
onHelpClose();
|
|
19937
|
+
};
|
|
19938
|
+
const onHelpFocusOut = (event) => {
|
|
19939
|
+
if (!helpPanel.hidden && event.relatedTarget && !inTip(event.relatedTarget)) setHelpOpen(false);
|
|
19940
|
+
};
|
|
19941
|
+
|
|
19942
|
+
// A desk's refusal of files gives way once the customer writes on.
|
|
19943
|
+
const onInput = () => {
|
|
19944
|
+
if (!transport) setNotice(null);
|
|
19945
|
+
};
|
|
19946
|
+
const onChoose = () => {
|
|
19947
|
+
if (input.files) add(input.files);
|
|
19948
|
+
// The same file can be chosen again after it is removed.
|
|
19949
|
+
input.value = '';
|
|
19950
|
+
};
|
|
19951
|
+
const onAttach = () => {
|
|
19952
|
+
if (!attach.disabled) input.click();
|
|
19953
|
+
};
|
|
19954
|
+
|
|
19955
|
+
zone.addEventListener('dragenter', fileEvents.dragOver);
|
|
19956
|
+
zone.addEventListener('dragover', fileEvents.dragOver);
|
|
19957
|
+
zone.addEventListener('dragleave', fileEvents.dragLeave);
|
|
19958
|
+
zone.addEventListener('drop', fileEvents.drop);
|
|
19959
|
+
for (const field of fields) {
|
|
19960
|
+
field.addEventListener('paste', fileEvents.paste);
|
|
19961
|
+
field.addEventListener('input', onInput);
|
|
19962
|
+
}
|
|
19963
|
+
input.addEventListener('change', onChoose);
|
|
19964
|
+
attach.addEventListener('click', onAttach);
|
|
19965
|
+
helpTrigger.addEventListener('click', onHelpToggle);
|
|
19966
|
+
helpClose.addEventListener('click', onHelpClose);
|
|
19967
|
+
for (const part of [helpTrigger, helpPanel]) {
|
|
19968
|
+
part.addEventListener('keydown', onHelpKey);
|
|
19969
|
+
part.addEventListener('focusout', onHelpFocusOut);
|
|
19970
|
+
}
|
|
19971
|
+
|
|
19972
|
+
function clear(keepAttached = false) {
|
|
19973
|
+
revision += 1;
|
|
19974
|
+
const previous = entries;
|
|
19975
|
+
entries = [];
|
|
19976
|
+
for (const entry of previous) {
|
|
19977
|
+
entry.controller?.abort();
|
|
19978
|
+
if (!keepAttached || entry.state !== FILE_STATE.COMPLETE) void cancel(entry.target, entry.attachmentId);
|
|
19979
|
+
}
|
|
19980
|
+
list.replaceChildren();
|
|
19981
|
+
input.value = '';
|
|
19982
|
+
setNotice(null);
|
|
19983
|
+
}
|
|
19984
|
+
|
|
19985
|
+
return {
|
|
19986
|
+
frame,
|
|
19987
|
+
notice,
|
|
19988
|
+
get hasFiles() {
|
|
19989
|
+
return entries.length > 0;
|
|
19990
|
+
},
|
|
19991
|
+
get attachmentIds() {
|
|
19992
|
+
return entries.filter((entry) => entry.state === FILE_STATE.COMPLETE).map((entry) => entry.attachmentId);
|
|
19993
|
+
},
|
|
19994
|
+
get holdCopy() {
|
|
19995
|
+
if (entries.some((entry) => IN_FLIGHT.has(entry.state))) return HOLD_COPY.uploading;
|
|
19996
|
+
if (entries.some((entry) => entry.state === FILE_STATE.RECEIVED)) return HOLD_COPY.storing;
|
|
19997
|
+
if (entries.some((entry) => entry.state === FILE_STATE.FAILED && entry.retryable)) return HOLD_COPY.retryable;
|
|
19998
|
+
if (entries.some((entry) => entry.state !== FILE_STATE.COMPLETE)) return HOLD_COPY.refused;
|
|
19999
|
+
return null;
|
|
20000
|
+
},
|
|
20001
|
+
async start() {
|
|
20002
|
+
await Promise.all(entries.map((entry) => entry.operation ?? (entry.state === FILE_STATE.QUEUED ? run(entry) : null)));
|
|
20003
|
+
},
|
|
20004
|
+
lock(value) {
|
|
20005
|
+
locked = value;
|
|
20006
|
+
syncPicking();
|
|
20007
|
+
entries.forEach(controls);
|
|
20008
|
+
},
|
|
20009
|
+
disablePicking(value) {
|
|
20010
|
+
pickingDisabled = value;
|
|
20011
|
+
syncPicking();
|
|
20012
|
+
},
|
|
20013
|
+
hideFiles(value) {
|
|
20014
|
+
list.hidden = value;
|
|
20015
|
+
},
|
|
20016
|
+
rebind(rebound) {
|
|
20017
|
+
for (const entry of entries) {
|
|
20018
|
+
if (entry.target !== null) entry.target = rebound(entry.target);
|
|
20019
|
+
}
|
|
20020
|
+
},
|
|
20021
|
+
clear,
|
|
20022
|
+
destroy(keepAttached = false) {
|
|
20023
|
+
destroyed = true;
|
|
20024
|
+
clear(keepAttached);
|
|
20025
|
+
setHelpOpen(false);
|
|
20026
|
+
zone.removeEventListener('dragenter', fileEvents.dragOver);
|
|
20027
|
+
zone.removeEventListener('dragover', fileEvents.dragOver);
|
|
20028
|
+
zone.removeEventListener('dragleave', fileEvents.dragLeave);
|
|
20029
|
+
zone.removeEventListener('drop', fileEvents.drop);
|
|
20030
|
+
for (const field of fields) {
|
|
20031
|
+
field.removeEventListener('paste', fileEvents.paste);
|
|
20032
|
+
field.removeEventListener('input', onInput);
|
|
20033
|
+
}
|
|
20034
|
+
input.removeEventListener('change', onChoose);
|
|
20035
|
+
attach.removeEventListener('click', onAttach);
|
|
20036
|
+
helpTrigger.removeEventListener('click', onHelpToggle);
|
|
20037
|
+
helpClose.removeEventListener('click', onHelpClose);
|
|
20038
|
+
for (const part of [helpTrigger, helpPanel]) {
|
|
20039
|
+
part.removeEventListener('keydown', onHelpKey);
|
|
20040
|
+
part.removeEventListener('focusout', onHelpFocusOut);
|
|
20041
|
+
}
|
|
20042
|
+
}
|
|
20043
|
+
};
|
|
19503
20044
|
}
|
|
19504
20045
|
|
|
19505
20046
|
const TTL_MS = 30 * 60 * 1000;
|
|
@@ -19646,6 +20187,18 @@ function saveFormDraft(deskId, requesterId, value) {
|
|
|
19646
20187
|
}
|
|
19647
20188
|
|
|
19648
20189
|
let formSequence = 0;
|
|
20190
|
+
/**
|
|
20191
|
+
* The desk API's refusal of a file's draft or upload, as the composer reads
|
|
20192
|
+
* it (status 0 for no answer); null for an error the SDK did not build.
|
|
20193
|
+
*/
|
|
20194
|
+
function draftUploadRefusal(error) {
|
|
20195
|
+
if (!(error instanceof SparkVaultError))
|
|
20196
|
+
return null;
|
|
20197
|
+
const details = error.details ?? null;
|
|
20198
|
+
const resetsAt = typeof details?.resets_at === 'number' ? details.resets_at
|
|
20199
|
+
: error.retryAfterMs !== null ? Math.ceil((Date.now() + error.retryAfterMs) / 1000) : null;
|
|
20200
|
+
return { status: error.statusCode ?? 0, code: error.serviceCode ?? error.code, details, resetsAt };
|
|
20201
|
+
}
|
|
19649
20202
|
/** An absent or server-side answer cannot establish that the write was refused. */
|
|
19650
20203
|
function unknownSubmissionOutcome(error) {
|
|
19651
20204
|
// The client can suppress a response after the write was accepted. A new
|
|
@@ -19696,16 +20249,16 @@ function textButton(text, action) {
|
|
|
19696
20249
|
button.addEventListener('click', action);
|
|
19697
20250
|
return button;
|
|
19698
20251
|
}
|
|
19699
|
-
const UNSENT_NOTE_COPY =
|
|
19700
|
-
const SIGN_IN_HELP_COPY =
|
|
20252
|
+
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.";
|
|
20253
|
+
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
20254
|
const SIGNING_IN_COPY = 'Finish signing in using the secure window.';
|
|
19702
20255
|
const SWITCHING_COPY = 'Choose an account in the secure window.';
|
|
19703
|
-
const SIGNED_OUT_COPY = '
|
|
20256
|
+
const SIGNED_OUT_COPY = "You're signed out of support. What you wrote is still here.";
|
|
19704
20257
|
const FILES_AGAIN_COPY = 'Choose your files again before sending.';
|
|
19705
|
-
const SIGN_IN_CANCELLED_COPY =
|
|
20258
|
+
const SIGN_IN_CANCELLED_COPY = "Sign-in was cancelled. Your request is still here and hasn't been sent.";
|
|
19706
20259
|
const RECOVER_STATUS_COPY = 'Sign in again to recover your saved request.';
|
|
19707
20260
|
const RECOVER_WEBSITE_COPY = 'Sign in to your website account again to recover your saved request.';
|
|
19708
|
-
const WEBSITE_SIGNED_OUT_COPY = '
|
|
20261
|
+
const WEBSITE_SIGNED_OUT_COPY = "You're not signed in to the website. Sign in there, then choose Use website account again.";
|
|
19709
20262
|
const RECOVER_NOTE_COPY = 'Sign in with the same email as before to recover your saved request.';
|
|
19710
20263
|
/** Host callback failures do not change a ticket's accepted or failed result. */
|
|
19711
20264
|
function notify$1(callback, value) {
|
|
@@ -19911,26 +20464,42 @@ function mountHelpDeskForm(client, options) {
|
|
|
19911
20464
|
event.preventDefault();
|
|
19912
20465
|
focusAtEnd(description.input);
|
|
19913
20466
|
});
|
|
19914
|
-
|
|
19915
|
-
|
|
19916
|
-
|
|
19917
|
-
|
|
19918
|
-
|
|
19919
|
-
|
|
19920
|
-
|
|
19921
|
-
|
|
19922
|
-
|
|
19923
|
-
|
|
19924
|
-
|
|
19925
|
-
|
|
20467
|
+
// A file uploads to the request's draft, made once the customer is signed
|
|
20468
|
+
// in; until then it waits for the send.
|
|
20469
|
+
const transport = client.desk.customer_can_attach_files && options.attachments !== false
|
|
20470
|
+
? {
|
|
20471
|
+
async target() {
|
|
20472
|
+
const ownGeneration = generation;
|
|
20473
|
+
const token = await tokenFor(ownGeneration);
|
|
20474
|
+
if (!token || !alive(ownGeneration))
|
|
20475
|
+
return null;
|
|
20476
|
+
const id = await ensureDraft(ownGeneration, token);
|
|
20477
|
+
if (!alive(ownGeneration))
|
|
20478
|
+
return null;
|
|
20479
|
+
return { draftId: id, expectedSessionToken: token };
|
|
20480
|
+
},
|
|
20481
|
+
initiate: (upload, file) => client.initiateDraftAttachment(upload.draftId, file, { expectedSessionToken: upload.expectedSessionToken }),
|
|
20482
|
+
cancel: (upload, attachmentId) => client.cancelDraftAttachment(upload.draftId, attachmentId, { expectedSessionToken: upload.expectedSessionToken }),
|
|
20483
|
+
send: (url, file, transfer) => client.sendAttachment(url, file, transfer),
|
|
20484
|
+
resume: (session, file, transfer) => client.resumeAttachment(session, file, transfer),
|
|
20485
|
+
refusal: draftUploadRefusal,
|
|
20486
|
+
}
|
|
20487
|
+
: null;
|
|
20488
|
+
const composer = createHelpDeskComposer({
|
|
20489
|
+
textarea: description.input,
|
|
20490
|
+
transport,
|
|
20491
|
+
deskRefusesFiles: !client.desk.customer_can_attach_files,
|
|
20492
|
+
organization: client.desk.organization_name,
|
|
20493
|
+
dropZone: form,
|
|
20494
|
+
pasteFields: [subject.input],
|
|
20495
|
+
active: () => step === 'details',
|
|
20496
|
+
// What the request carries is saved with it; a file's step is not.
|
|
20497
|
+
onFilesChange: () => {
|
|
20498
|
+
if (composer.hasFiles)
|
|
19926
20499
|
restoredFiles = false;
|
|
19927
20500
|
persistDraft();
|
|
19928
20501
|
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',
|
|
20502
|
+
},
|
|
19934
20503
|
});
|
|
19935
20504
|
description.wrapper.classList.add('svhd-composer-field');
|
|
19936
20505
|
description.wrapper.insertBefore(composer.frame, description.error);
|
|
@@ -20071,8 +20640,14 @@ function mountHelpDeskForm(client, options) {
|
|
|
20071
20640
|
let websiteSignedOut = false;
|
|
20072
20641
|
// The form is held while the secure window chooses another account: no send is under way.
|
|
20073
20642
|
let switchingAccount = false;
|
|
20643
|
+
/**
|
|
20644
|
+
* Save the request as the form holds it. Never while a sign-in is under
|
|
20645
|
+
* way: a session notification then blanks the fields until the sign-in's
|
|
20646
|
+
* answer confirms its customer, and nothing may save that blank over the
|
|
20647
|
+
* request.
|
|
20648
|
+
*/
|
|
20074
20649
|
function persistDraft() {
|
|
20075
|
-
if (!options.persist || completed || destroyed)
|
|
20650
|
+
if (!options.persist || completed || destroyed || authenticating)
|
|
20076
20651
|
return;
|
|
20077
20652
|
if (!draftOwner) {
|
|
20078
20653
|
// The hidden request is a previous customer's; nothing is saved over it.
|
|
@@ -20082,7 +20657,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20082
20657
|
}
|
|
20083
20658
|
saveFormDraft(client.desk.desk_id, draftOwner.requester_id, {
|
|
20084
20659
|
subject: subject.input.value, body: description.input.value, ticketId: draftId,
|
|
20085
|
-
uncertain: uncertainSubmission, hadFiles: restoredFiles ||
|
|
20660
|
+
uncertain: uncertainSubmission, hadFiles: restoredFiles || composer.hasFiles,
|
|
20086
20661
|
});
|
|
20087
20662
|
}
|
|
20088
20663
|
function forgetDraft() {
|
|
@@ -20133,7 +20708,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20133
20708
|
*/
|
|
20134
20709
|
function safeComposition() {
|
|
20135
20710
|
return pending || uncertainSubmission !== null || completed ? null
|
|
20136
|
-
: { subject: subject.input.value, body: description.input.value, hadFiles:
|
|
20711
|
+
: { subject: subject.input.value, body: description.input.value, hadFiles: composer.hasFiles };
|
|
20137
20712
|
}
|
|
20138
20713
|
/** What the send button reads while nothing is in flight. */
|
|
20139
20714
|
function idleLabel() {
|
|
@@ -20317,8 +20892,8 @@ function mountHelpDeskForm(client, options) {
|
|
|
20317
20892
|
for (const button of widgetAccount.querySelectorAll('button'))
|
|
20318
20893
|
button.disabled = disabled || uncertainSubmission !== null || completed;
|
|
20319
20894
|
renderResend();
|
|
20320
|
-
|
|
20321
|
-
|
|
20895
|
+
composer.disablePicking(disabled || recovery !== null);
|
|
20896
|
+
composer.lock(completed || uncertainSubmission !== null);
|
|
20322
20897
|
}
|
|
20323
20898
|
function clearCode() {
|
|
20324
20899
|
code.input.value = '';
|
|
@@ -20397,7 +20972,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20397
20972
|
return false;
|
|
20398
20973
|
return (pending && state !== 'authenticating') || uncertainSubmission !== null || challenge !== null || step === 'identity'
|
|
20399
20974
|
|| edited(subject.input, filledWith('subject')) || edited(description.input, filledWith('body'))
|
|
20400
|
-
||
|
|
20975
|
+
|| composer.hasFiles;
|
|
20401
20976
|
}
|
|
20402
20977
|
/**
|
|
20403
20978
|
* The field a request the ticket write would refuse is refused under, with
|
|
@@ -20474,11 +21049,9 @@ function mountHelpDeskForm(client, options) {
|
|
|
20474
21049
|
done = null;
|
|
20475
21050
|
form.hidden = false;
|
|
20476
21051
|
closeConfirm(false);
|
|
20477
|
-
|
|
20478
|
-
|
|
20479
|
-
|
|
20480
|
-
attachments.list.hidden = false;
|
|
20481
|
-
composer.clearNotice();
|
|
21052
|
+
composer.clear(completed || uncertainSubmission !== null);
|
|
21053
|
+
composer.lock(false);
|
|
21054
|
+
composer.hideFiles(false);
|
|
20482
21055
|
subject.input.value = '';
|
|
20483
21056
|
description.input.value = '';
|
|
20484
21057
|
email.input.value = '';
|
|
@@ -20517,7 +21090,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20517
21090
|
// and never authenticates one as a side effect of cleanup.
|
|
20518
21091
|
const token = client.verifiedSessionTokenFor(change.requesterId);
|
|
20519
21092
|
if (token && previousToken) {
|
|
20520
|
-
|
|
21093
|
+
composer.rebind((upload) => upload.expectedSessionToken === previousToken ? { ...upload, expectedSessionToken: token } : upload);
|
|
20521
21094
|
sessionToken = token;
|
|
20522
21095
|
}
|
|
20523
21096
|
return;
|
|
@@ -20538,8 +21111,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20538
21111
|
name.input.value = '';
|
|
20539
21112
|
email.input.value = '';
|
|
20540
21113
|
clearCode();
|
|
20541
|
-
|
|
20542
|
-
attachments.list.hidden = true;
|
|
21114
|
+
composer.hideFiles(true);
|
|
20543
21115
|
return;
|
|
20544
21116
|
}
|
|
20545
21117
|
// Preserve the old request before hiding it. The next verified requester
|
|
@@ -20735,8 +21307,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20735
21307
|
sessionToken = token;
|
|
20736
21308
|
sessionKnown = true;
|
|
20737
21309
|
authenticating = false;
|
|
20738
|
-
|
|
20739
|
-
attachments.list.hidden = false;
|
|
21310
|
+
composer.hideFiles(false);
|
|
20740
21311
|
subject.input.value = subjectText;
|
|
20741
21312
|
description.input.value = detailsText;
|
|
20742
21313
|
if (widget && session) {
|
|
@@ -20799,8 +21370,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20799
21370
|
sessionToken = token;
|
|
20800
21371
|
sessionKnown = true;
|
|
20801
21372
|
authenticating = false;
|
|
20802
|
-
|
|
20803
|
-
attachments.list.hidden = false;
|
|
21373
|
+
composer.hideFiles(false);
|
|
20804
21374
|
dropChallenge();
|
|
20805
21375
|
subject.input.value = subjectText;
|
|
20806
21376
|
description.input.value = detailsText;
|
|
@@ -20841,12 +21411,13 @@ function mountHelpDeskForm(client, options) {
|
|
|
20841
21411
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
20842
21412
|
return;
|
|
20843
21413
|
}
|
|
20844
|
-
if (!recoveringSubmission &&
|
|
20845
|
-
await
|
|
21414
|
+
if (!recoveringSubmission && transport) {
|
|
21415
|
+
await composer.start();
|
|
20846
21416
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
20847
21417
|
return;
|
|
20848
|
-
|
|
20849
|
-
|
|
21418
|
+
const held = composer.holdCopy;
|
|
21419
|
+
if (held !== null) {
|
|
21420
|
+
message(held, true);
|
|
20850
21421
|
return;
|
|
20851
21422
|
}
|
|
20852
21423
|
}
|
|
@@ -20863,12 +21434,12 @@ function mountHelpDeskForm(client, options) {
|
|
|
20863
21434
|
sourceArticleId = options.sourceArticleId?.();
|
|
20864
21435
|
}
|
|
20865
21436
|
catch { /* Optional context cannot prevent sending. */ }
|
|
20866
|
-
uncertainSubmission = { ticketId: id, subject: subjectText, body, attachments:
|
|
21437
|
+
uncertainSubmission = { ticketId: id, subject: subjectText, body, attachments: composer.attachmentIds,
|
|
20867
21438
|
...(typeof sourceArticleId === 'string' && sourceArticleId.length > 0 && sourceArticleId.length <= 256 &&
|
|
20868
21439
|
!Array.from(sourceArticleId).some(character => character.charCodeAt(0) <= 32 || character === '\\') && { source_article_id: sourceArticleId }) };
|
|
20869
21440
|
}
|
|
20870
21441
|
persistDraft();
|
|
20871
|
-
|
|
21442
|
+
composer.lock(true);
|
|
20872
21443
|
ticketAttempted = true;
|
|
20873
21444
|
const ticket = await client.createTicket({ ...uncertainSubmission, attachments: [...uncertainSubmission.attachments], ...options.assistanceContext?.() }, { expectedSessionToken: token });
|
|
20874
21445
|
if (!alive(ownGeneration) || !(await tokenFor(ownGeneration)))
|
|
@@ -20903,7 +21474,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
20903
21474
|
if (draftExpired) {
|
|
20904
21475
|
draftId = null;
|
|
20905
21476
|
draftPromise = null;
|
|
20906
|
-
|
|
21477
|
+
composer.clear();
|
|
20907
21478
|
}
|
|
20908
21479
|
if (error instanceof SparkVaultError && error.serviceCode === 'PIN_INVALID') {
|
|
20909
21480
|
clearCode();
|
|
@@ -21082,8 +21653,7 @@ function mountHelpDeskForm(client, options) {
|
|
|
21082
21653
|
destroyed = true;
|
|
21083
21654
|
generation += 1;
|
|
21084
21655
|
stopResendCountdown();
|
|
21085
|
-
|
|
21086
|
-
composer.destroy();
|
|
21656
|
+
composer.destroy(completed || uncertainSubmission !== null);
|
|
21087
21657
|
live.destroy();
|
|
21088
21658
|
unsubscribe();
|
|
21089
21659
|
form.removeEventListener('submit', onSubmit);
|
|
@@ -23474,7 +24044,12 @@ function createSupportLauncher(options, open) {
|
|
|
23474
24044
|
};
|
|
23475
24045
|
}
|
|
23476
24046
|
|
|
23477
|
-
/**
|
|
24047
|
+
/**
|
|
24048
|
+
* The support journey's only skin. Customer content stays in the product register.
|
|
24049
|
+
* The panel's focus ring is 2px, 3px out, in the desk's focus color: its width and
|
|
24050
|
+
* offset are the panel's custom properties, which the help desk composer inside
|
|
24051
|
+
* its request form reads, so the composer rings as the fields beside it do.
|
|
24052
|
+
*/
|
|
23478
24053
|
function injectHelpDeskSupportStyles() {
|
|
23479
24054
|
if (document.getElementById('sparkvault-help-desk-support-styles'))
|
|
23480
24055
|
return;
|
|
@@ -23482,6 +24057,7 @@ function injectHelpDeskSupportStyles() {
|
|
|
23482
24057
|
style.id = 'sparkvault-help-desk-support-styles';
|
|
23483
24058
|
style.textContent = `
|
|
23484
24059
|
.svhs-panel,.svhs-panel *{box-sizing:border-box}
|
|
24060
|
+
.svhs-panel{--hd-focus-width:2px;--hd-focus-offset:3px}
|
|
23485
24061
|
.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
24062
|
.svhs-panel[hidden],.svhs-panel [hidden]{display:none!important}
|
|
23487
24063
|
.svhs-panel[data-stage=results]{height:680px}
|
|
@@ -23493,7 +24069,7 @@ function injectHelpDeskSupportStyles() {
|
|
|
23493
24069
|
.svhs-panel button,.svhs-panel a{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
|
|
23494
24070
|
.svhs-panel button{appearance:none;cursor:pointer;margin:0}
|
|
23495
24071
|
.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:
|
|
24072
|
+
.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
24073
|
.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
24074
|
.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
24075
|
.svhs-desk-name{font-size:14px;font-weight:600;line-height:1.35;color:${DS.slate600};overflow-wrap:anywhere;min-width:0}
|
|
@@ -23612,10 +24188,6 @@ function injectHelpDeskSupportStyles() {
|
|
|
23612
24188
|
.svhs-contact-target .svhd-auth{gap:14px}
|
|
23613
24189
|
.svhs-contact-target .svhd-text-button{color:var(--hd-accent-ink,${DS.action})}
|
|
23614
24190
|
.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
24191
|
.svhs-contact-target .svhd-widget-form{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
23620
24192
|
/* The request fills the panel: the details step, and in it the composer and its text, take the height the fields leave. */
|
|
23621
24193
|
.svhs-contact-target .svhd-widget-form>[data-contact-step=details]{display:flex;flex:1;flex-direction:column;gap:16px}
|
|
@@ -23874,120 +24446,6 @@ class SupportPhoneHistory {
|
|
|
23874
24446
|
}
|
|
23875
24447
|
}
|
|
23876
24448
|
|
|
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
24449
|
/** Darken only the narrow range where neither white nor the product ink reaches AA. */
|
|
23992
24450
|
function accessibleFill(color) {
|
|
23993
24451
|
let fill = color;
|
|
@@ -24422,7 +24880,7 @@ class SupportView {
|
|
|
24422
24880
|
continue;
|
|
24423
24881
|
frame.setAttribute('aria-busy', 'false');
|
|
24424
24882
|
status.hidden = false;
|
|
24425
|
-
status.replaceChildren(document.createTextNode(
|
|
24883
|
+
status.replaceChildren(document.createTextNode("This image couldn't be loaded."));
|
|
24426
24884
|
const canonical = httpUrl(this.state?.article?.canonical_url);
|
|
24427
24885
|
if (canonical) {
|
|
24428
24886
|
const link = element('a', '', 'Open the full article');
|
|
@@ -24550,7 +25008,7 @@ class SupportView {
|
|
|
24550
25008
|
this.headings.get('results').textContent = state.busy ? 'Checking for helpful articles…'
|
|
24551
25009
|
: state.kbState === 'locked' ? 'View helpful articles'
|
|
24552
25010
|
: results.length && state.kbState !== 'unavailable' ? 'These articles may help'
|
|
24553
|
-
: '
|
|
25011
|
+
: "Let's get you some help";
|
|
24554
25012
|
const signature = JSON.stringify(results);
|
|
24555
25013
|
if (signature !== this.resultSignature) {
|
|
24556
25014
|
this.resultSignature = signature;
|
|
@@ -24629,12 +25087,12 @@ class SupportView {
|
|
|
24629
25087
|
this.actions.onUnlock?.(); }));
|
|
24630
25088
|
}
|
|
24631
25089
|
else {
|
|
24632
|
-
this.resultStatus.append(element('p', 'svhs-copy',
|
|
25090
|
+
this.resultStatus.append(element('p', 'svhs-copy', "The help center isn't available from this network. You can still contact support below."));
|
|
24633
25091
|
}
|
|
24634
25092
|
}
|
|
24635
25093
|
else if (state.kbState === 'unavailable') {
|
|
24636
25094
|
this.resultStatus.removeAttribute('role');
|
|
24637
|
-
this.resultStatus.append(element('h3', 'svhs-heading',
|
|
25095
|
+
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
25096
|
if (this.actions.onRetry)
|
|
24639
25097
|
this.resultStatus.append(button('svhs-secondary', 'Try again', () => this.actions.onRetry?.()));
|
|
24640
25098
|
}
|
|
@@ -24660,7 +25118,7 @@ class SupportView {
|
|
|
24660
25118
|
this.articleError.hidden = !this.articleError.textContent;
|
|
24661
25119
|
this.articleRetry.hidden = !this.articleError.textContent || Boolean(state.busy) || !this.actions.onRetry;
|
|
24662
25120
|
this.articleContent.hidden = Boolean(state.busy);
|
|
24663
|
-
this.articleTitle.textContent = article?.title || (state.error ?
|
|
25121
|
+
this.articleTitle.textContent = article?.title || (state.error ? "We couldn't load this article" : 'Help article');
|
|
24664
25122
|
const category = state.results?.find((result) => result.id === article?.id)?.category;
|
|
24665
25123
|
this.articleCategory.textContent = category || '';
|
|
24666
25124
|
this.articleCategory.hidden = !category;
|
|
@@ -24769,7 +25227,7 @@ class SupportView {
|
|
|
24769
25227
|
}
|
|
24770
25228
|
renderReceipt(state) {
|
|
24771
25229
|
const receipt = state.receipt;
|
|
24772
|
-
this.receiptCopy.replaceChildren(document.createTextNode(receipt?.email ?
|
|
25230
|
+
this.receiptCopy.replaceChildren(document.createTextNode(receipt?.email ? "Your message has been sent. We'll reply to " : 'Your message has been sent.'));
|
|
24773
25231
|
if (receipt?.email)
|
|
24774
25232
|
this.receiptCopy.append(element('strong', '', receipt.email), document.createTextNode('.'));
|
|
24775
25233
|
this.receiptTicket.textContent = receipt?.ticketNumber !== undefined ? `Ticket #${receipt.ticketNumber}` : '';
|
|
@@ -30540,7 +30998,7 @@ class SparkVault {
|
|
|
30540
30998
|
}
|
|
30541
30999
|
/** Get the SDK version */
|
|
30542
31000
|
static get version() {
|
|
30543
|
-
return '16.
|
|
31001
|
+
return '16.9.0';
|
|
30544
31002
|
}
|
|
30545
31003
|
}
|
|
30546
31004
|
if (typeof window !== 'undefined') {
|