docuseal-svelte 0.0.4 → 0.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
@@ -26,6 +26,18 @@ This package supports:
26
26
  - Svelte 4.x
27
27
  - Svelte 5.x
28
28
 
29
+ ## Development
30
+
31
+ ```bash
32
+ npm test # run the test suite once
33
+ npm run test:watch # re-run tests as you edit
34
+ npm run check # type-check the library and the tests
35
+ ```
36
+
37
+ Tests live in the top-level `tests/` directory rather than beside the source, because
38
+ `svelte-package` copies everything under `src/lib` into `dist`. `npm run prepack` fails if a
39
+ test file ever reaches the built package.
40
+
29
41
  ## How to Contribute
30
42
 
31
43
  Contributions are welcome! Please fork the repository and create a pull request with your changes. Make sure to create a changeset for any significant updates.
@@ -14,7 +14,12 @@
14
14
  withTitle = true,
15
15
  withDocumentsList = true,
16
16
  withFieldsList = true,
17
+ withFieldsDetection = false,
17
18
  withFieldPlaceholder = false,
19
+ withDynamicDocuments = false,
20
+ withPrefillable = false,
21
+ withCustomFieldsTab = false,
22
+ withRevisions = false,
18
23
  onlyDefinedFields = false,
19
24
  preview = false,
20
25
  previewMode = false,
@@ -27,6 +32,7 @@
27
32
  fields = [],
28
33
  submitters = [],
29
34
  requiredFields = [],
35
+ dateFormats = [],
30
36
  i18n = {},
31
37
  withSignYourselfButton = true,
32
38
  withUploadButton = true,
@@ -45,6 +51,7 @@
45
51
  onSend = undefined,
46
52
  onSave = undefined,
47
53
  onChange = undefined,
54
+ onError = undefined,
48
55
  }: {
49
56
  token: string
50
57
  host?: string
@@ -53,7 +60,12 @@
53
60
  withTitle?: boolean
54
61
  withDocumentsList?: boolean
55
62
  withFieldsList?: boolean
63
+ withFieldsDetection?: boolean
56
64
  withFieldPlaceholder?: boolean
65
+ withDynamicDocuments?: boolean
66
+ withPrefillable?: boolean
67
+ withCustomFieldsTab?: boolean
68
+ withRevisions?: boolean
57
69
  onlyDefinedFields?: boolean
58
70
  preview?: boolean
59
71
  previewMode?: boolean
@@ -66,6 +78,7 @@
66
78
  fields?: DocuSealBuilderField[]
67
79
  submitters?: DocuSealBuilderSubmitter[]
68
80
  requiredFields?: DocuSealBuilderField[]
81
+ dateFormats?: string[]
69
82
  i18n?: object
70
83
  withSignYourselfButton?: boolean
71
84
  withUploadButton?: boolean
@@ -84,6 +97,7 @@
84
97
  onSend?: ((detail: any) => void) | undefined
85
98
  onSave?: ((detail: any) => void) | undefined
86
99
  onChange?: ((detail: any) => void) | undefined
100
+ onError?: ((error: DocuSealError) => void) | undefined
87
101
  } = $props()
88
102
 
89
103
  let el = $state<HTMLElement | null>(null)
@@ -125,8 +139,8 @@
125
139
  reject(
126
140
  new DocuSealError(
127
141
  `Failed to load DocuSeal builder script from ${scriptSrc}`,
128
- "SCRIPT_LOAD_ERROR"
129
- )
142
+ "SCRIPT_LOAD_ERROR",
143
+ ),
130
144
  )
131
145
 
132
146
  document.head.appendChild(script)
@@ -180,9 +194,17 @@
180
194
  }
181
195
  }
182
196
 
197
+ const asDocuSealError = (error: unknown): DocuSealError =>
198
+ error instanceof DocuSealError
199
+ ? error
200
+ : new DocuSealError(
201
+ "Failed to initialize DocuSeal Builder",
202
+ "INIT_ERROR",
203
+ error,
204
+ )
205
+
183
206
  onMount(() => {
184
207
  let cleanup: (() => void) | undefined
185
-
186
208
  ;(async () => {
187
209
  try {
188
210
  validateHost(host)
@@ -191,15 +213,12 @@
191
213
  cleanup = setupEventListeners(el)
192
214
  }
193
215
  } catch (error) {
194
- console.error("DocuSeal Builder initialization error:", error)
195
- if (error instanceof DocuSealError) {
196
- throw error
216
+ const initError = asDocuSealError(error)
217
+ if (onError) {
218
+ onError(initError)
219
+ } else {
220
+ console.error("DocuSeal Builder initialization error:", initError)
197
221
  }
198
- throw new DocuSealError(
199
- "Failed to initialize DocuSeal Builder",
200
- "INIT_ERROR",
201
- error
202
- )
203
222
  }
204
223
  })()
205
224
 
@@ -213,7 +232,7 @@
213
232
  bind:this={el}
214
233
  data-token={token}
215
234
  data-preview={booleanToAttr(preview || previewMode)}
216
- data-input-mode={inputMode}
235
+ data-input-mode={booleanToAttr(inputMode)}
217
236
  data-language={language}
218
237
  data-autosave={booleanToAttr(autosave)}
219
238
  data-send-button-text={sendButtonText}
@@ -224,6 +243,7 @@
224
243
  data-fields={JSON.stringify(fields)}
225
244
  data-submitters={JSON.stringify(submitters)}
226
245
  data-required-fields={JSON.stringify(requiredFields)}
246
+ data-date-formats={dateFormats.join(",")}
227
247
  data-i18n={JSON.stringify(i18n)}
228
248
  data-custom-button-title={customButton.title}
229
249
  data-custom-button-url={customButton.url}
@@ -232,9 +252,14 @@
232
252
  data-with-recipients-button={booleanToAttr(withRecipientsButton)}
233
253
  data-with-send-button={booleanToAttr(withSendButton)}
234
254
  data-with-documents-list={booleanToAttr(withDocumentsList)}
255
+ data-with-dynamic-documents={booleanToAttr(withDynamicDocuments)}
235
256
  data-with-fields-list={booleanToAttr(withFieldsList)}
257
+ data-with-fields-detection={booleanToAttr(withFieldsDetection)}
236
258
  data-with-field-placeholder={booleanToAttr(withFieldPlaceholder)}
259
+ data-with-prefillable={booleanToAttr(withPrefillable)}
260
+ data-with-custom-fields-tab={booleanToAttr(withCustomFieldsTab)}
237
261
  data-with-signature-id={booleanToAttr(withSignatureId)}
262
+ data-with-revisions={booleanToAttr(withRevisions)}
238
263
  data-with-title={booleanToAttr(withTitle)}
239
264
  data-only-defined-fields={booleanToAttr(onlyDefinedFields)}
240
265
  data-with-upload-button={booleanToAttr(withUploadButton)}
@@ -1,4 +1,5 @@
1
1
  import type { DocuSealBuilderField, DocuSealBuilderSubmitter } from "../types/index.js";
2
+ import { DocuSealError } from "../utils/docuseal.js";
2
3
  type $$ComponentProps = {
3
4
  token: string;
4
5
  host?: string;
@@ -7,7 +8,12 @@ type $$ComponentProps = {
7
8
  withTitle?: boolean;
8
9
  withDocumentsList?: boolean;
9
10
  withFieldsList?: boolean;
11
+ withFieldsDetection?: boolean;
10
12
  withFieldPlaceholder?: boolean;
13
+ withDynamicDocuments?: boolean;
14
+ withPrefillable?: boolean;
15
+ withCustomFieldsTab?: boolean;
16
+ withRevisions?: boolean;
11
17
  onlyDefinedFields?: boolean;
12
18
  preview?: boolean;
13
19
  previewMode?: boolean;
@@ -20,6 +26,7 @@ type $$ComponentProps = {
20
26
  fields?: DocuSealBuilderField[];
21
27
  submitters?: DocuSealBuilderSubmitter[];
22
28
  requiredFields?: DocuSealBuilderField[];
29
+ dateFormats?: string[];
23
30
  i18n?: object;
24
31
  withSignYourselfButton?: boolean;
25
32
  withUploadButton?: boolean;
@@ -44,6 +51,7 @@ type $$ComponentProps = {
44
51
  onSend?: ((detail: any) => void) | undefined;
45
52
  onSave?: ((detail: any) => void) | undefined;
46
53
  onChange?: ((detail: any) => void) | undefined;
54
+ onError?: ((error: DocuSealError) => void) | undefined;
47
55
  };
48
56
  declare const DocuSealBuilder: import("svelte").Component<$$ComponentProps, {}, "">;
49
57
  type DocuSealBuilder = ReturnType<typeof DocuSealBuilder>;
@@ -37,6 +37,7 @@
37
37
  export let withFieldNames: boolean = true
38
38
  export let withFieldPlaceholder: boolean = false
39
39
  export let withDownloadButton: boolean = true
40
+ export let onlyRequiredFields: boolean = false
40
41
  export let allowToResubmit: boolean = true
41
42
  export let allowTypedSignature: boolean = true
42
43
  export let signature: string = ""
@@ -115,7 +116,7 @@
115
116
  data-external-id={externalId || applicationKey}
116
117
  data-expand={booleanToAttr(expand)}
117
118
  data-minimize={booleanToAttr(minimize)}
118
- data-order-as-on-page={orderAsOnPage}
119
+ data-order-as-on-page={booleanToAttr(orderAsOnPage)}
119
120
  data-preview={booleanToAttr(preview)}
120
121
  data-dry-run={booleanToAttr(dryRun)}
121
122
  data-go-to-last={booleanToAttr(goToLast)}
@@ -129,6 +130,7 @@
129
130
  data-with-field-names={booleanToAttr(withFieldNames)}
130
131
  data-with-field-placeholder={booleanToAttr(withFieldPlaceholder)}
131
132
  data-with-download-button={booleanToAttr(withDownloadButton)}
133
+ data-only-required-fields={booleanToAttr(onlyRequiredFields)}
132
134
  data-allow-to-resubmit={booleanToAttr(allowToResubmit)}
133
135
  data-allow-typed-signature={booleanToAttr(allowTypedSignature)}
134
136
  data-signature={signature}
@@ -48,6 +48,7 @@ declare const DocuSealForm: $$__sveltets_2_IsomorphicComponent<{
48
48
  withFieldNames?: boolean;
49
49
  withFieldPlaceholder?: boolean;
50
50
  withDownloadButton?: boolean;
51
+ onlyRequiredFields?: boolean;
51
52
  allowToResubmit?: boolean;
52
53
  allowTypedSignature?: boolean;
53
54
  signature?: string;
@@ -65,6 +65,7 @@ export interface DocuSealFormProps {
65
65
  withDownloadButton?: boolean;
66
66
  withSendCopyButton?: boolean;
67
67
  withCompleteButton?: boolean;
68
+ onlyRequiredFields?: boolean;
68
69
  allowToResubmit?: boolean;
69
70
  allowTypedSignature?: boolean;
70
71
  signature?: string;
@@ -1,6 +1,3 @@
1
- /**
2
- * Validates if a URL is a valid DocuSeal URL
3
- */
4
1
  export declare function isValidDocuSealUrl(url: string): boolean;
5
2
  /**
6
3
  * Builds a DocuSeal form URL with query parameters
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Validates if a URL is a valid DocuSeal URL
3
3
  */
4
+ const DOCUSEAL_DOMAINS = ['docuseal.co', 'docuseal.com'];
4
5
  export function isValidDocuSealUrl(url) {
5
6
  try {
6
- const parsed = new URL(url);
7
- return parsed.hostname.includes('docuseal.co') ||
8
- parsed.hostname.includes('docuseal.com');
7
+ const { hostname } = new URL(url);
8
+ return DOCUSEAL_DOMAINS.some((domain) => hostname === domain || hostname.endsWith(`.${domain}`));
9
9
  }
10
10
  catch {
11
11
  return false;
package/package.json CHANGED
@@ -1,20 +1,23 @@
1
1
  {
2
2
  "name": "docuseal-svelte",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Docuseal Svelte component library for document signing and management.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/SirCen/docuseal-svelte.git"
8
+ "url": "git+https://github.com/SirCen/docuseal-svelte.git"
9
9
  },
10
10
  "scripts": {
11
11
  "dev": "vite dev",
12
12
  "build": "vite build && npm run prepack",
13
+ "release": "npm stage publish",
13
14
  "preview": "vite preview",
14
15
  "prepare": "svelte-kit sync || echo ''",
15
- "prepack": "svelte-kit sync && svelte-package && publint",
16
+ "prepack": "svelte-kit sync && svelte-package && node scripts/assert-no-tests-in-dist.js && publint",
16
17
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
17
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
18
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest"
18
21
  },
19
22
  "files": [
20
23
  "dist",
@@ -42,11 +45,14 @@
42
45
  "@sveltejs/kit": "^2.49.1",
43
46
  "@sveltejs/package": "^2.5.7",
44
47
  "@sveltejs/vite-plugin-svelte": "^6.2.1",
48
+ "@testing-library/svelte": "^5.4.2",
49
+ "jsdom": "^30.0.1",
45
50
  "publint": "^0.3.15",
46
51
  "svelte": "^5.45.6",
47
52
  "svelte-check": "^4.3.4",
48
53
  "typescript": "^5.9.3",
49
- "vite": "^7.2.6"
54
+ "vite": "^7.2.6",
55
+ "vitest": "^4.1.11"
50
56
  },
51
57
  "keywords": [
52
58
  "svelte",