@unboundcx/sdk 4.13.85 → 4.13.87
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/index.js +1 -0
- package/package.json +1 -1
- package/services/forms/HealthService.js +35 -0
- package/services/forms/PublicService.js +38 -0
- package/services/forms.js +3 -1
package/index.js
CHANGED
|
@@ -330,6 +330,7 @@ export { ExternalOAuthService } from './services/externalOAuth.js';
|
|
|
330
330
|
export { GoogleCalendarService } from './services/googleCalendar.js';
|
|
331
331
|
export { FormsService } from './services/forms.js';
|
|
332
332
|
export { FormsPublicService } from './services/forms/PublicService.js';
|
|
333
|
+
export { FormsHealthService } from './services/forms/HealthService.js';
|
|
333
334
|
export { DriveService } from './services/drive.js';
|
|
334
335
|
export { EnrollService } from './services/enroll.js';
|
|
335
336
|
export {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unboundcx/sdk",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.87",
|
|
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",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { internalRequest } from '../../base.js';
|
|
2
|
+
|
|
3
|
+
// Forms v2 P8 (plans/forms-v2-plan.md D13, forms-v2-precheck.md §9) --
|
|
4
|
+
// agent-authenticated Health tab data (`sdk.forms.health`): submissions
|
|
5
|
+
// tiles, a 30-day submissions-per-day sparkline, per-field fill rate, and
|
|
6
|
+
// drift alerts (a field with 0 non-blank values in the last 7 days after
|
|
7
|
+
// previously being filled >=50% of the time). Backed by the nightly
|
|
8
|
+
// `formFieldStats` rollup -- server route:
|
|
9
|
+
// `app1-api/src/services/forms/controllers/getFormHealth.js`.
|
|
10
|
+
export class FormsHealthService {
|
|
11
|
+
constructor(sdk) {
|
|
12
|
+
this.sdk = sdk;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {string} formId
|
|
17
|
+
* @returns {Promise<{
|
|
18
|
+
* tiles: {submissions:number, submissionsChangePct:number|null,
|
|
19
|
+
* spamCount:number, spamRatePct:number, companyLinkedPct:number,
|
|
20
|
+
* companyCreated:number, actionsFailed:number},
|
|
21
|
+
* sparkline: {day:string, submitted:number}[],
|
|
22
|
+
* fields: {fieldKey:string, label:string, fillRate:number|null,
|
|
23
|
+
* priorFillRate:number|null, isDrifting:boolean}[],
|
|
24
|
+
* driftAlerts: object[],
|
|
25
|
+
* windowDays: number,
|
|
26
|
+
* }>}
|
|
27
|
+
*/
|
|
28
|
+
async get(formId) {
|
|
29
|
+
return internalRequest(
|
|
30
|
+
this.sdk,
|
|
31
|
+
`/forms/${encodeURIComponent(formId)}/health`,
|
|
32
|
+
'GET',
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -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
|
}
|
package/services/forms.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { FormsPublicService } from './forms/PublicService.js';
|
|
2
2
|
import { FormsSubmissionsService } from './forms/SubmissionsService.js';
|
|
3
3
|
import { FormsSettingsService } from './forms/SettingsService.js';
|
|
4
|
+
import { FormsHealthService } from './forms/HealthService.js';
|
|
4
5
|
|
|
5
6
|
// Forms v2 (forms-v2-plan.md §7 / forms-v2-precheck.md §5) -- `sdk.forms`.
|
|
6
7
|
// `public` needs no agent auth (VisitorService pattern, publicKey-scoped);
|
|
7
|
-
// `submissions`/`settings` are normal agent-token calls.
|
|
8
|
+
// `submissions`/`settings`/`health` are normal agent-token calls.
|
|
8
9
|
export class FormsService {
|
|
9
10
|
constructor(sdk) {
|
|
10
11
|
this.sdk = sdk;
|
|
11
12
|
this.public = new FormsPublicService(sdk);
|
|
12
13
|
this.submissions = new FormsSubmissionsService(sdk);
|
|
13
14
|
this.settings = new FormsSettingsService(sdk);
|
|
15
|
+
this.health = new FormsHealthService(sdk);
|
|
14
16
|
}
|
|
15
17
|
}
|