@unboundcx/sdk 4.13.84 → 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/base.js CHANGED
@@ -114,6 +114,20 @@ export class BaseSDK {
114
114
  process.env?.API_BASE_URL || defaultDomain
115
115
  }`;
116
116
  }
117
+ } else if (this._constructorBaseURL && !this.namespace) {
118
+ // Forms v2 P3 fix: a browser-environment instance constructed with
119
+ // ONLY a literal baseURL (no namespace) -- e.g. sdk.forms.public /
120
+ // sdk.webchat.visitor on a page that resolves its tenant server-side
121
+ // from an opaque key, never a namespace subdomain -- must hit that
122
+ // exact baseURL. Before this fix, this branch unconditionally built
123
+ // `https://${namespace}.${baseUrl}` even when namespace was
124
+ // undefined, producing a literal "https://undefined.<host>" request
125
+ // URL (caught via forms-v2 marketing-site integration, P3). The
126
+ // Node branch above already had the equivalent guard
127
+ // (`if (!this._constructorBaseURL)`); this mirrors it for browser.
128
+ // A namespace passed ALONGSIDE baseURL still prefixes it (unchanged,
129
+ // existing behavior other callers rely on).
130
+ this.fullUrl = this._constructorBaseURL;
117
131
  } else {
118
132
  this.fullUrl = `https://${this.namespace}.${this.baseUrl}`;
119
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.84",
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
  }