@widgetic/creator 0.3.81 → 0.4.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.
Files changed (62) hide show
  1. package/README.md +157 -0
  2. package/dist/CreatorApp.svelte +1103 -612
  3. package/dist/CreatorApp.svelte.d.ts +22 -0
  4. package/dist/components/BrandKitPanel.svelte +48 -40
  5. package/dist/components/BrandKitPanel.svelte.d.ts +1 -1
  6. package/dist/components/DesignQuickEdit.svelte +13 -4
  7. package/dist/components/EditableName.svelte +13 -8
  8. package/dist/components/EditableName.svelte.d.ts +2 -2
  9. package/dist/components/FileUrlSourceControl.svelte +21 -8
  10. package/dist/components/HoverTooltip.svelte +1 -1
  11. package/dist/components/SelectorDropdown.svelte +19 -15
  12. package/dist/components/SelectorDropdown.svelte.d.ts +2 -2
  13. package/dist/components/VersionDropdownRow.svelte +14 -11
  14. package/dist/components/WidgetDetails.svelte +118 -92
  15. package/dist/components/WidgetShapeLivePreviews.svelte +105 -46
  16. package/dist/creator-types.d.ts +96 -0
  17. package/dist/host/creatorHost.d.ts +176 -0
  18. package/dist/host/creatorHost.js +242 -0
  19. package/dist/host/limitRefusal.d.ts +64 -0
  20. package/dist/host/limitRefusal.js +109 -0
  21. package/dist/i18n/index.d.ts +5 -0
  22. package/dist/i18n/index.js +5 -0
  23. package/dist/i18n/labels.d.ts +14 -0
  24. package/dist/i18n/labels.js +39 -0
  25. package/dist/i18n/language.d.ts +559 -0
  26. package/dist/i18n/language.js +47 -0
  27. package/dist/i18n/languageKit.d.ts +52 -0
  28. package/dist/i18n/languageKit.js +45 -0
  29. package/dist/i18n/messages.d.ts +526 -0
  30. package/dist/i18n/messages.js +548 -0
  31. package/dist/i18n/slots.d.ts +22 -0
  32. package/dist/i18n/slots.js +42 -0
  33. package/dist/i18n/statusText.d.ts +22 -0
  34. package/dist/i18n/statusText.js +223 -0
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/stores/userSession.d.ts +8 -1
  38. package/dist/stores/userSession.js +18 -25
  39. package/dist/stores/websocketStore.d.ts +6 -0
  40. package/dist/stores/websocketStore.js +39 -4
  41. package/dist/utils/designIntentTelemetry.d.ts +8 -0
  42. package/dist/utils/designIntentTelemetry.js +52 -34
  43. package/dist/utils/directionPlacement.d.ts +51 -0
  44. package/dist/utils/directionPlacement.js +55 -0
  45. package/dist/utils/embedCode.d.ts +0 -1
  46. package/dist/utils/embedCode.js +0 -4
  47. package/dist/utils/nativeScrollbarPadding.js +1 -1
  48. package/dist/utils/pickedFile.d.ts +15 -0
  49. package/dist/utils/pickedFile.js +21 -0
  50. package/dist/utils/widgeticChatUpload.d.ts +9 -0
  51. package/dist/utils/widgeticChatUpload.js +24 -2
  52. package/package.json +5 -3
  53. package/dist/retiredSurface.test.d.ts +0 -1
  54. package/dist/retiredSurface.test.js +0 -113
  55. package/dist/utils/designIntentResolver.test.d.ts +0 -1
  56. package/dist/utils/designIntentResolver.test.js +0 -246
  57. package/dist/utils/designIntentTelemetry.test.d.ts +0 -1
  58. package/dist/utils/designIntentTelemetry.test.js +0 -385
  59. package/dist/utils/designQuickEditValues.test.d.ts +0 -1
  60. package/dist/utils/designQuickEditValues.test.js +0 -100
  61. package/dist/utils/widgeticChatUpload.test.d.ts +0 -1
  62. package/dist/utils/widgeticChatUpload.test.js +0 -257
@@ -1,257 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { CHAT_MULTIPART_MAX_BYTES, requestTusComplete, uploadChatFileToWidgeticApi } from './widgeticChatUpload';
3
- // The real client opens connections and sends the file in chunks. This stand-in "finishes" the moment it is
4
- // started, so each test only decides how the gateway answers `POST …/complete`.
5
- vi.mock('tus-js-client', () => {
6
- class Upload {
7
- file;
8
- options;
9
- url = 'https://api.test/v1/uploads/tus/0b9e0f7e-6d2c-4a39-8d36-2f6a5f0c7a11~0123456789abcdef0123456789abcdef';
10
- constructor(file, options) {
11
- this.file = file;
12
- this.options = options;
13
- }
14
- findPreviousUploads() {
15
- return Promise.resolve([]);
16
- }
17
- resumeFromPreviousUpload() { }
18
- start() {
19
- this.options.onSuccess();
20
- }
21
- abort() {
22
- return Promise.resolve();
23
- }
24
- }
25
- return { Upload };
26
- });
27
- const COMPLETE_URL = 'https://api.test/v1/uploads/tus/0b9e0f7e-6d2c-4a39-8d36-2f6a5f0c7a11~0123456789abcdef0123456789abcdef/complete';
28
- const BUSY_MESSAGE = 'The upload is in use by another request. Try again in a moment.';
29
- const INCOMPLETE_MESSAGE = 'Upload is not complete: 4 of 10 bytes received. Send the remaining chunks, then complete the upload.';
30
- const config = { apiBasePath: 'https://api.test/v1/', accessToken: 'Bearer test-token' };
31
- /** A file big enough to be sent with TUS, without allocating its bytes (the stand-in never reads them). */
32
- function largeFile() {
33
- const file = new File(['0123456789'], 'clip.mp4', { type: 'video/mp4' });
34
- Object.defineProperty(file, 'size', { value: CHAT_MULTIPART_MAX_BYTES + 1 });
35
- return file;
36
- }
37
- function jsonResponse(status, body) {
38
- return new Response(JSON.stringify(body), {
39
- status,
40
- headers: { 'Content-Type': 'application/json' }
41
- });
42
- }
43
- /** What api-gateway answers while another request still has the upload. */
44
- const busyAnswer = () => jsonResponse(409, {
45
- success: false,
46
- message: BUSY_MESSAGE,
47
- error: { code: 'TUS_UPLOAD_BUSY', message: BUSY_MESSAGE }
48
- });
49
- /** What api-gateway answers while chunks are missing: asking again cannot help. */
50
- const incompleteAnswer = () => jsonResponse(409, {
51
- success: false,
52
- message: INCOMPLETE_MESSAGE,
53
- error: { code: 'TUS_UPLOAD_INCOMPLETE', message: INCOMPLETE_MESSAGE }
54
- });
55
- const completedAnswer = () => jsonResponse(200, {
56
- success: true,
57
- data: {
58
- id: 'file_1',
59
- url: 'https://cdn.test/clip.mp4',
60
- file_name: 'clip.mp4',
61
- file_size: 10,
62
- mime_type: 'video/mp4'
63
- }
64
- });
65
- const fetchMock = vi.fn();
66
- const realSetTimeout = globalThis.setTimeout;
67
- /** Lets every pause end at once and records how long each one was asked to be. */
68
- function skipPauses() {
69
- const requestedPauses = [];
70
- vi.spyOn(globalThis, 'setTimeout').mockImplementation(((handler, delayMs) => {
71
- requestedPauses.push(delayMs ?? 0);
72
- return realSetTimeout(handler, 0);
73
- }));
74
- return requestedPauses;
75
- }
76
- beforeEach(() => {
77
- fetchMock.mockReset();
78
- vi.stubGlobal('fetch', fetchMock);
79
- vi.spyOn(console, 'warn').mockImplementation(() => { });
80
- vi.spyOn(console, 'error').mockImplementation(() => { });
81
- });
82
- afterEach(() => {
83
- vi.restoreAllMocks();
84
- vi.unstubAllGlobals();
85
- });
86
- describe('requestTusComplete', () => {
87
- const init = { method: 'POST', headers: { Authorization: 'Bearer test-token' } };
88
- it('asks once when the first answer is a success', async () => {
89
- fetchMock.mockResolvedValueOnce(completedAnswer());
90
- const response = await requestTusComplete(COMPLETE_URL, init);
91
- expect(response.ok).toBe(true);
92
- expect(fetchMock).toHaveBeenCalledTimes(1);
93
- expect(fetchMock).toHaveBeenCalledWith(COMPLETE_URL, init);
94
- });
95
- it('asks again after a "busy" answer and returns the answer that follows', async () => {
96
- fetchMock
97
- .mockResolvedValueOnce(busyAnswer())
98
- .mockResolvedValueOnce(busyAnswer())
99
- .mockResolvedValueOnce(completedAnswer());
100
- const response = await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
101
- expect(response.ok).toBe(true);
102
- expect(fetchMock).toHaveBeenCalledTimes(3);
103
- });
104
- it('pauses for each given delay, in order, before it asks again', async () => {
105
- fetchMock
106
- .mockResolvedValueOnce(busyAnswer())
107
- .mockResolvedValueOnce(busyAnswer())
108
- .mockResolvedValueOnce(completedAnswer());
109
- const requestedPauses = skipPauses();
110
- await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [1111, 2222, 3333] });
111
- expect(requestedPauses.filter((delayMs) => delayMs > 1000)).toEqual([1111, 2222]);
112
- });
113
- it('gives up after the last delay and returns the "busy" answer, message still readable', async () => {
114
- fetchMock.mockImplementation(async () => busyAnswer());
115
- const response = await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0] });
116
- expect(fetchMock).toHaveBeenCalledTimes(3);
117
- expect(response.status).toBe(409);
118
- expect(await response.json()).toMatchObject({
119
- error: { code: 'TUS_UPLOAD_BUSY', message: BUSY_MESSAGE }
120
- });
121
- });
122
- it('does not ask again when chunks are missing (409 TUS_UPLOAD_INCOMPLETE)', async () => {
123
- fetchMock.mockResolvedValueOnce(incompleteAnswer());
124
- const response = await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
125
- expect(fetchMock).toHaveBeenCalledTimes(1);
126
- expect(response.status).toBe(409);
127
- expect(await response.json()).toMatchObject({ error: { code: 'TUS_UPLOAD_INCOMPLETE' } });
128
- });
129
- it('does not ask again when a 409 carries another code', async () => {
130
- fetchMock.mockResolvedValueOnce(jsonResponse(409, { success: false, error: { code: 'SOMETHING_ELSE' } }));
131
- await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
132
- expect(fetchMock).toHaveBeenCalledTimes(1);
133
- });
134
- it('does not ask again when the "busy" code comes with another status', async () => {
135
- fetchMock.mockResolvedValueOnce(jsonResponse(503, { success: false, error: { code: 'TUS_UPLOAD_BUSY' } }));
136
- await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
137
- expect(fetchMock).toHaveBeenCalledTimes(1);
138
- });
139
- it('does not ask again when a 409 has no JSON body', async () => {
140
- fetchMock.mockResolvedValueOnce(new Response('<html>Conflict</html>', { status: 409 }));
141
- await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
142
- expect(fetchMock).toHaveBeenCalledTimes(1);
143
- });
144
- it.each([
145
- [404, 'TUS_UPLOAD_NOT_FOUND'],
146
- [413, 'QUOTA_STORAGE_EXCEEDED'],
147
- [415, 'UPLOAD_UNSUPPORTED_TYPE'],
148
- [503, 'TUS_DISABLED']
149
- ])('does not ask again after a %i %s', async (status, code) => {
150
- fetchMock.mockResolvedValueOnce(jsonResponse(status, { success: false, error: { code } }));
151
- const response = await requestTusComplete(COMPLETE_URL, init, { retryDelaysMs: [0, 0, 0] });
152
- expect(fetchMock).toHaveBeenCalledTimes(1);
153
- expect(response.status).toBe(status);
154
- });
155
- it('stops waiting when the upload is cancelled during a pause, and does not ask again', async () => {
156
- fetchMock.mockImplementation(async () => busyAnswer());
157
- const controller = new AbortController();
158
- // A pause long enough that only the cancel can end it.
159
- const pauseStarted = new Promise((resolve) => {
160
- vi.spyOn(globalThis, 'setTimeout').mockImplementation(((handler, delayMs) => {
161
- if (delayMs === 600_000)
162
- resolve();
163
- return realSetTimeout(handler, delayMs);
164
- }));
165
- });
166
- const answer = requestTusComplete(COMPLETE_URL, init, {
167
- retryDelaysMs: [600_000],
168
- abortSignal: controller.signal
169
- });
170
- await pauseStarted;
171
- controller.abort();
172
- const response = await answer;
173
- expect(fetchMock).toHaveBeenCalledTimes(1);
174
- expect(response.status).toBe(409);
175
- });
176
- it('does not wait or ask again when the upload was already cancelled', async () => {
177
- fetchMock.mockImplementation(async () => busyAnswer());
178
- const controller = new AbortController();
179
- controller.abort();
180
- const response = await requestTusComplete(COMPLETE_URL, init, {
181
- retryDelaysMs: [600_000],
182
- abortSignal: controller.signal
183
- });
184
- expect(fetchMock).toHaveBeenCalledTimes(1);
185
- expect(response.status).toBe(409);
186
- });
187
- });
188
- describe('uploadChatFileToWidgeticApi (file above the multipart limit)', () => {
189
- it('finishes the upload when /complete answers at once', async () => {
190
- fetchMock.mockResolvedValueOnce(completedAnswer());
191
- const result = await uploadChatFileToWidgeticApi(largeFile(), config);
192
- expect(result).toEqual({
193
- id: 'file_1',
194
- url: 'https://cdn.test/clip.mp4',
195
- fileType: 'video/mp4',
196
- fileName: 'clip.mp4',
197
- fileSize: 10
198
- });
199
- expect(fetchMock).toHaveBeenCalledTimes(1);
200
- const [calledUrl, calledInit] = fetchMock.mock.calls[0];
201
- expect(calledUrl).toBe(COMPLETE_URL);
202
- expect(calledInit).toMatchObject({
203
- method: 'POST',
204
- headers: { Authorization: 'Bearer test-token' }
205
- });
206
- });
207
- it('asks again after 0.5 s and then 1 s when /complete says the upload is busy, then finishes', async () => {
208
- fetchMock
209
- .mockResolvedValueOnce(busyAnswer())
210
- .mockResolvedValueOnce(busyAnswer())
211
- .mockResolvedValueOnce(completedAnswer());
212
- const requestedPauses = skipPauses();
213
- const result = await uploadChatFileToWidgeticApi(largeFile(), config);
214
- expect(result.id).toBe('file_1');
215
- expect(fetchMock).toHaveBeenCalledTimes(3);
216
- expect(requestedPauses.filter((delayMs) => delayMs >= 500)).toEqual([500, 1000]);
217
- });
218
- it('gives up after five more tries and fails with the message of the last answer', async () => {
219
- fetchMock.mockImplementation(async () => busyAnswer());
220
- const requestedPauses = skipPauses();
221
- await expect(uploadChatFileToWidgeticApi(largeFile(), config)).rejects.toThrow(BUSY_MESSAGE);
222
- expect(fetchMock).toHaveBeenCalledTimes(6);
223
- expect(requestedPauses.filter((delayMs) => delayMs >= 500)).toEqual([
224
- 500, 1000, 2000, 4000, 8000
225
- ]);
226
- });
227
- it('does not ask again when chunks are missing, and says so', async () => {
228
- fetchMock.mockResolvedValueOnce(incompleteAnswer());
229
- const requestedPauses = skipPauses();
230
- await expect(uploadChatFileToWidgeticApi(largeFile(), config)).rejects.toThrow(INCOMPLETE_MESSAGE);
231
- expect(fetchMock).toHaveBeenCalledTimes(1);
232
- expect(requestedPauses.filter((delayMs) => delayMs >= 500)).toEqual([]);
233
- });
234
- it('says the upload was cancelled, not that it was busy, when it is cancelled while waiting to ask again', async () => {
235
- fetchMock.mockImplementation(async () => busyAnswer());
236
- const controller = new AbortController();
237
- const pauseStarted = new Promise((resolve) => {
238
- vi.spyOn(globalThis, 'setTimeout').mockImplementation(((handler, delayMs) => {
239
- // Hold the first pause (0.5 s) open until the cancel arrives.
240
- if (delayMs === 500) {
241
- resolve();
242
- return realSetTimeout(handler, 600_000);
243
- }
244
- return realSetTimeout(handler, 0);
245
- }));
246
- });
247
- const pending = uploadChatFileToWidgeticApi(largeFile(), config, {
248
- abortSignal: controller.signal
249
- });
250
- // Keep the rejection from being reported as unhandled before the test reads it.
251
- const outcome = pending.then(() => 'resolved', (error) => error.message);
252
- await pauseStarted;
253
- controller.abort();
254
- expect(await outcome).toBe('Upload cancelled.');
255
- expect(fetchMock).toHaveBeenCalledTimes(1);
256
- });
257
- });