@unboundcx/sdk 4.13.85 → 4.13.86
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.86",
|
|
4
4
|
"description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -54,4 +54,42 @@ export class FormsPublicService {
|
|
|
54
54
|
true,
|
|
55
55
|
);
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Upload a file for a `file` inputType field (D21), ahead of the real
|
|
60
|
+
* `submit()` call. Mirrors `webchat.visitor.files.upload()`'s shape:
|
|
61
|
+
* browser-only (needs `FormData`), no progress event. The returned
|
|
62
|
+
* `token` must be echoed back inside `submit()`'s `fields[fieldKey]` as
|
|
63
|
+
* `JSON.stringify({fileId, token})` -- the server (formFileAttach.js)
|
|
64
|
+
* verifies it names this exact (formId, fieldKey, fileId) triple before
|
|
65
|
+
* attaching the file to the submission.
|
|
66
|
+
* @param {string} publicKey
|
|
67
|
+
* @param {string} fieldKey - Must match a `file` inputType field on the form.
|
|
68
|
+
* @param {File|Blob} file
|
|
69
|
+
* @returns {Promise<{fileId:string, token:string, fileName:string, fileType:string, fileSize:number}>}
|
|
70
|
+
*/
|
|
71
|
+
async upload(publicKey, fieldKey, file) {
|
|
72
|
+
this.sdk.validateParams(
|
|
73
|
+
{ publicKey, fieldKey },
|
|
74
|
+
{
|
|
75
|
+
publicKey: { type: 'string', required: true },
|
|
76
|
+
fieldKey: { type: 'string', required: true },
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
if (typeof FormData === 'undefined' || !file) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'forms.public.upload :: a browser File/Blob and FormData support are required',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
const body = new FormData();
|
|
85
|
+
body.append('fieldKey', fieldKey);
|
|
86
|
+
body.append('file', file);
|
|
87
|
+
return internalRequest(
|
|
88
|
+
this.sdk,
|
|
89
|
+
`/f/${publicKey}/upload`,
|
|
90
|
+
'POST',
|
|
91
|
+
{ body },
|
|
92
|
+
true,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
57
95
|
}
|