@sparkvault/sdk-js 13.4.0 → 14.1.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/README.md CHANGED
@@ -129,9 +129,144 @@ app.post('/api/auth/login', async (req, res) => {
129
129
  | `entropy` | Server-generated random values | [Entropy](https://sparkvault.com/api/docs/sdk-js/#reference-entropy) |
130
130
  | `notify` | SparkVault's own inbox and Web Push, for a person signed in to SparkVault itself | [Notifications](https://sparkvault.com/api/docs/sdk-js/#reference-notify) |
131
131
  | `products.notify` | Your Notify sends, your recipients' inboxes, send history, receipts and config (server-side, with `apiKey`) | [Notify API](https://sparkvault.com/api/docs/products/notify/) |
132
+ | `products.helpDesk` | Customer ticket API, email verification and an optional injected form | [Help Desk](#help-desk) |
132
133
  | `health` | API availability | [Health](https://sparkvault.com/api/docs/sdk-js/#health-api-reference) |
133
134
 
134
- `products.identity`, `vaults.upload` and `health` send neither a Core JWT nor an `apiKey`. The widget needs the vault's Embedded Upload Widget setting enabled, with or without a `token`: it opens by reading the vault's upload info, a request that carries no VAT and is refused while the setting is off. The other modules call the Core API with a Core JWT (`accessToken` or `getAccessToken`) or, server-side, an `apiKey`; `notify` needs a SparkVault user's session JWT. Configuration, errors and TypeScript: the [reference](https://sparkvault.com/api/docs/sdk-js/#configuration-options).
135
+ `products.identity`, `products.helpDesk`, `vaults.upload` and `health` send neither a Core JWT nor an `apiKey`. Help Desk uses only a desk customer session (`hdt_`), with cookies omitted. The upload widget needs the vault's Embedded Upload Widget setting enabled, with or without a `token`: it opens by reading the vault's upload info, a request that carries no VAT and is refused while the setting is off. The other modules call the Core API with a Core JWT (`accessToken` or `getAccessToken`) or, server-side, an `apiKey`; `notify` needs a SparkVault user's session JWT. Configuration, errors and TypeScript: the [reference](https://sparkvault.com/api/docs/sdk-js/#configuration-options).
136
+
137
+ ## Help Desk
138
+
139
+ Use an existing support button with the SDK's modal and callback handling:
140
+
141
+ ```typescript
142
+ const removeSupport = sv.products.helpDesk.attach('.support-button', {
143
+ host: 'support.example.com',
144
+ onSuccess: ({ number }) => showConfirmation(number)
145
+ });
146
+ ```
147
+
148
+ Call `removeSupport()` on unmount/account change to detach its listeners and close its form.
149
+
150
+ `openForm(options)` opens the same modal programmatically. It handles close,
151
+ Escape, backdrop, focus restoration and teardown. These browser UI methods
152
+ complement the inline form and headless client below.
153
+ Closing a form suppresses later UI callbacks; it cannot undo a submission the
154
+ server has already accepted. Check the customer's ticket history before
155
+ starting another request after closing an in-flight send.
156
+
157
+ Inject a ticket form into an element in your page or popup:
158
+
159
+ ```typescript
160
+ const sv = SparkVault.init({
161
+ accountId: 'acc_YOUR_ACCOUNT_ID',
162
+ preloadConfig: false // A help-desk-only page does not need Identity preloading.
163
+ });
164
+ const form = await sv.products.helpDesk.mountForm({
165
+ host: 'support.example.com', // Your configured help desk hostname.
166
+ target: '#support-form',
167
+ onSuccess: ({ number }) => showConfirmation(number),
168
+ onError: (error) => showSupportError(error.message)
169
+ });
170
+ ```
171
+
172
+ Call `form.destroy()` when your component unmounts or your website customer changes.
173
+
174
+ The form handles subject/description, screenshots and files, the desk's email-code flow, a missing
175
+ display name, submitting once, and retrying the same draft after an uncertain
176
+ response. `onSuccess` runs only after the service confirms a ticket number.
177
+ `onStateChange` observes `authenticating`, `editing`, `verifying`, `submitting`, `uncertain`, `success` and
178
+ `destroyed`; `reset()` clears an idle/completed form. Observer callback errors
179
+ do not turn an accepted ticket into a retry. The file picker appears when the
180
+ desk permits customer attachments; pass `attachments: false` to hide it. It uses
181
+ the shared file policy (20 files, up to 25 MiB each) and handles server quota
182
+ refusals visibly. Files wait for sign-in, then upload directly to Forge through
183
+ the standard resumable ceremony, with progress, cancellation and retry. Only a
184
+ confirmed publication receipt adds a file to the ticket. A received file still
185
+ being stored offers Check upload, resuming the same upload instead of sending
186
+ its bytes again. A full ticket-status page remains in the hosted customer portal.
187
+
188
+ For a custom UI, use the same customer API without injecting markup:
189
+
190
+ ```typescript
191
+ const desk = await sv.products.helpDesk.connect({ host: 'support.example.com' });
192
+ const challenge = await desk.startPin(email);
193
+ await desk.verifyPin({
194
+ challengeId: challenge.challenge_id,
195
+ bindingSecret: challenge.binding_secret,
196
+ code // The six digits entered by the customer.
197
+ });
198
+ const token = await desk.getSessionToken();
199
+ const draft = await desk.createDraft({ expectedSessionToken: token! });
200
+ // Keep this draft ID for retries. Do not open another draft after a timeout.
201
+ const ticket = await desk.createTicket({
202
+ ticketId: draft.ticket_id,
203
+ subject,
204
+ body
205
+ }, { expectedSessionToken: token! });
206
+ const requests = await desk.listTickets({ status: 'open' });
207
+ ```
208
+
209
+ `getMe`, `updateMe`, `getTicket`, `listEvents`, `replyToTicket`, `resolveTicket`,
210
+ `muteTicket` and attachment methods expose the existing customer routes.
211
+ `sendAttachment(forgeUrl, file, { signal, onProgress, onSessionCreated })` and
212
+ `resumeAttachment({ sessionUrl }, file, { signal, onProgress })` use the same
213
+ direct Forge transfer as `ingots.sendUpload`, without Core or customer credentials.
214
+ Pass
215
+ `expectedSessionToken` in a write's context argument to refuse a send if a
216
+ dynamic session provider has switched customers. A session stays in memory by
217
+ default. `setSession(answer)` accepts a server-issued session answer; it does
218
+ not authenticate a browser's claimed identity. `clearSession()` overrides any
219
+ token provider with a signed-out state; `refreshSession()` explicitly resumes
220
+ that provider. `logout()` revokes the current desk session. On account change,
221
+ clear/destroy the customer UI before showing a new customer's data.
222
+ The client also rejects an authenticated response that arrives after its
223
+ session changed (`HELP_DESK_SESSION_CHANGED`), rather than return another
224
+ customer's stale data. A write may already have been accepted for the original
225
+ customer; reconcile it under that customer's session instead of retrying it as
226
+ the replacement account.
227
+
228
+ After a send with an uncertain outcome (timeout, connection failure or server
229
+ error), the injected form keeps the exact submitted text and attachment IDs locked and offers
230
+ Check submission. This recovers the original ticket instead of silently treating
231
+ edited text as a second version of an already-accepted draft. `reset()` cannot
232
+ discard an unresolved send. A definitive validation refusal allows corrections.
233
+
234
+ For a company-session desk, add the company's authenticated assertion endpoint
235
+ to the same form/modal options:
236
+
237
+ ```typescript
238
+ const form = await sv.products.helpDesk.mountForm({
239
+ host: 'support.example.com',
240
+ target: '#support-form',
241
+ identityEndpoint: '/api/support/assertion', // Same origin; company's cookie/CSRF policy.
242
+ onSuccess: ({ number }) => showConfirmation(number)
243
+ });
244
+ ```
245
+
246
+ For a bearer-authenticated app, use
247
+ `getIdentityAssertion: async ({ nonce, audience, deskId }) => ...` instead. Call
248
+ the company's backend with `{nonce,audience,desk_id:deskId}` through its normal
249
+ authenticated API client; return the backend's assertion string, or explicit
250
+ `null` for an anonymous visitor. The backend derives identity from its current
251
+ verified caller and signs a purpose-specific, one-use, 60-second assertion.
252
+ Register its public key and exact origins once in Help Desk's Company session
253
+ settings. Keep all signing keys and integration credentials server-side.
254
+
255
+ The form authenticates silently before customer actions. The headless client's
256
+ `authenticate()` performs the same exchange. `mountClientForm(client, options)`
257
+ and `openClientForm(client, options)` reuse that client. Same server-verified
258
+ requester renewal preserves work; account change/logout cancels old state.
259
+ Explicit guest policy can allow email codes for a null anonymous answer;
260
+ authentication errors never downgrade to a guest. This creates a desk-local
261
+ requester/session without a second login, consent or auth.SV account.
262
+
263
+ A host can also supply an existing server-issued desk session through
264
+ `getSessionToken` or `onAuthRequired`; never construct a session from browser
265
+ user IDs/emails. Return the session answer from `onAuthRequired` and let the form
266
+ install it, rather than calling `setSession` inside the callback. Identity-mode
267
+ completion remains restricted to desk portal origins. See the
268
+ [website integration guide](https://github.com/Spark-Vault/platform/blob/main/docs/HELP_DESK_WEBSITE_INTEGRATION.md)
269
+ and [company-session contract](https://github.com/Spark-Vault/platform/blob/main/docs/HELP_DESK_IDENTITY_HANDOFF.md).
135
270
 
136
271
  ## Content Security Policy (CSP)
137
272
 
package/dist/http.d.ts CHANGED
@@ -12,6 +12,8 @@ export interface RequestOptions {
12
12
  /** The unsealed vault's Vault Access Token, sent as `X-Vault-Access-Token`. */
13
13
  vat?: string;
14
14
  timeout?: number;
15
+ /** Override browser cookie behavior for a credential-isolated product surface. */
16
+ credentials?: 'omit' | 'same-origin' | 'include';
15
17
  }
16
18
  /** A successful answer: its `data`, unwrapped from the `{ data, meta }` envelope. */
17
19
  export interface ApiResponse<T = unknown> {