@signalhouse-sms/sdk 1.13.0 → 1.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalhouse-sms/sdk",
3
- "version": "1.13.0",
3
+ "version": "1.15.0",
4
4
  "description": "Signal House SDK for use with the Signal House platform",
5
5
  "type": "module",
6
6
  "main": "src/SignalHouseSDK.js",
@@ -48,7 +48,9 @@ import { Webhooks } from "./domains/Webhooks.js";
48
48
  import { Voice } from "./domains/Voice.js";
49
49
  import { Agents } from "./domains/Agents.js";
50
50
  import { Audit } from "./domains/Audit.js";
51
+ import { Contracts } from "./domains/Contracts.js";
51
52
  import { Verify } from "./domains/Verify.js";
53
+ import { Compliance } from "./domains/Compliance.js";
52
54
 
53
55
  export class SignalHouseSDK {
54
56
  /**
@@ -101,8 +103,11 @@ export class SignalHouseSDK {
101
103
  // AI Agents domain — customer-facing agent config under /agent.
102
104
  this.agents = new Agents(client, this.enableAdmin);
103
105
  this.audit = new Audit(client, this.enableAdmin);
106
+ this.contracts = new Contracts(client, this.enableAdmin);
104
107
  // Carrier phone-number checks (SIM Swap, Number Verify) under /verify.
105
108
  this.verify = new Verify(client, this.enableAdmin);
109
+ // Compliance cases under /compliance; staff methods under compliance.admin.
110
+ this.compliance = new Compliance(client, multipartClient, this.enableAdmin);
106
111
  }
107
112
 
108
113
  /**
@@ -519,6 +519,22 @@ export class Brands {
519
519
  return this.client(`/brand/appeal/${safeBrandId}`, { method: 'GET', ...options });
520
520
  }
521
521
 
522
+ /**
523
+ * Get TCR's identity feedback for a brand: why TCR could not verify it (status UNVERIFIED)
524
+ * @async
525
+ * @roles api, admin, developer, billing, user
526
+ * @param {Object} params - The parameters for getting the feedback
527
+ * @param {BrandLookupId} params.brandId - Brand lookup id (carrier Brand ID, record `_id`, or internal reference).
528
+ * @param {RequestOptions} [params.options] - Additional options for the request
529
+ * @throws {Error} Throws an error if the brandId parameter is missing
530
+ * @returns {Promise<SdkResponse<Object>>} BrandFeedback: { brandId, category: [{ id, displayName, description, fields, errors: [{ code, message }] }] }
531
+ */
532
+ async getBrandFeedback({ brandId, options = {} }) {
533
+ this.client._require({ brandId });
534
+ const safeBrandId = encodeURIComponent(brandId);
535
+ return this.client(`/brand/feedback/${safeBrandId}`, { method: 'GET', ...options });
536
+ }
537
+
522
538
  /**
523
539
  * Submit a brand identity status appeal with supporting documentation
524
540
  * @async
@@ -530,7 +546,7 @@ export class Brands {
530
546
  * @param {File|Blob} params.file - The supporting document file
531
547
  * @param {RequestOptions} [params.options] - Additional options for the request
532
548
  * @throws {Error} Throws an error if required parameters are missing
533
- * @returns {Promise<SdkResponse<any>>} The response from the server
549
+ * @returns {Promise<SdkResponse<any>>} The response from the server. When TCR refuses the appeal itself (a 4xx, e.g. code 592 for a brand older than 45 days), the error body is { error: "TCR refused the appeal: <reason>", details: { code, message } } with TCR's own code and message. Don't retry it unchanged; it will be refused again.
534
550
  */
535
551
  async submitAppeal({ brandId, appealCategories, explanation, file, options = {} }) {
536
552
  this.client._require({ brandId, appealCategories, explanation, file });
@@ -0,0 +1,324 @@
1
+ /** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
2
+ /**
3
+ * @template T
4
+ * @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
5
+ */
6
+
7
+ /**
8
+ * Compliance cases under /compliance. Signal House opens a case when a carrier suspends one of your objects, a carrier
9
+ * escalates a message, or Signal House needs something from you. You read your cases, answer their requirements and
10
+ * upload files; only Signal House opens, works and closes them. Staff methods are under `admin` (enableAdmin).
11
+ */
12
+ export class Compliance {
13
+ /**
14
+ * Keep the JSON and multipart clients every compliance request goes through.
15
+ * @param {any} client - The JSON request client
16
+ * @param {any} multipartClient - The multipart request client, for file uploads
17
+ * @param {boolean} [enableAdmin] - Whether the staff methods under `admin` are available
18
+ */
19
+ constructor(client, multipartClient, enableAdmin) {
20
+ this.client = client;
21
+ this.multipartClient = multipartClient;
22
+ this.enableAdmin = enableAdmin;
23
+
24
+ if (enableAdmin) {
25
+ this.admin = {
26
+ /**
27
+ * Log an alert by hand: a reading, a notice or a block. Blocks (and a Sev-0 carrier ticket) need signalhouse_admin.
28
+ * @async
29
+ * @roles signalhouse_admin, signalhouse_user
30
+ * @param {Object} params - The alert
31
+ * @param {Object} params.data - `{ form, type, subject: { kind, id }, ... }`: the intake input without a raw payload
32
+ * @param {RequestOptions} [params.options] - Additional options for the request
33
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ logged, recovered, updated, unmatched, duplicate }`
34
+ */
35
+ logAlert: async ({ data, options = {} }) => {
36
+ this.client._require({ data });
37
+ return this.client(`/compliance/alerts`, { method: "POST", body: data, ...options });
38
+ },
39
+
40
+ /**
41
+ * Lift a block by hand. signalhouse_admin only.
42
+ * @async
43
+ * @roles signalhouse_admin
44
+ * @param {Object} params - The lift
45
+ * @param {string} params.alertId - The block alert (ALR-…)
46
+ * @param {string} [params.note] - Why it lifted
47
+ * @param {string} [params.occurredAt] - When the source says it lifted (ISO 8601)
48
+ * @param {RequestOptions} [params.options] - Additional options for the request
49
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ alertId, recoveredAt, caseId, caseClosed, closeReason }`
50
+ */
51
+ liftBlock: async ({ alertId, note, occurredAt, options = {} }) => {
52
+ this.client._require({ alertId });
53
+ const body = { ...(note !== undefined && { note }), ...(occurredAt !== undefined && { occurredAt }) };
54
+ return this.client(`/compliance/alerts/${encodeURIComponent(alertId)}/lift`, { method: "POST", body, ...options });
55
+ },
56
+
57
+ /**
58
+ * List alerts, with the inbox counts.
59
+ * @async
60
+ * @roles signalhouse_admin, signalhouse_user
61
+ * @param {Object} [params] - Filters: type, form, severity, channel, source, subjectKind, subjectId, number, groupId, subgroupId, campaignId, caseId, inbox, open, blocks, slackPending, from, to, page, limit
62
+ * @param {RequestOptions} [params.options] - Additional options for the request
63
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ data, total, page, limit, totalPages, counts: { inCase, inbox, noted } }`
64
+ */
65
+ getAlerts: async ({ options = {}, ...filters } = {}) => {
66
+ return this.client(`/compliance/alerts${this.client._getQueryString(filters)}`, { method: "GET", ...options });
67
+ },
68
+
69
+ /**
70
+ * Get one alert with its raw payload, escalation chain, case summary and timeline.
71
+ * @async
72
+ * @roles signalhouse_admin, signalhouse_user
73
+ * @param {Object} params - The lookup
74
+ * @param {string} params.alertId - The alert (ALR-…)
75
+ * @param {RequestOptions} [params.options] - Additional options for the request
76
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the alert with `chain`, `case` and `timeline`
77
+ */
78
+ getAlert: async ({ alertId, options = {} }) => {
79
+ this.client._require({ alertId });
80
+ return this.client(`/compliance/alerts/${encodeURIComponent(alertId)}`, { method: "GET", ...options });
81
+ },
82
+
83
+ /**
84
+ * Work an inbox alert: `{ action: "assign", caseId }`, `{ action: "assign", object: { objectType, objectId } }` or `{ action: "note", note }`.
85
+ * @async
86
+ * @roles signalhouse_admin, signalhouse_user
87
+ * @param {Object} params - The action
88
+ * @param {string} params.alertId - The inbox alert (ALR-…)
89
+ * @param {Object} params.data - The action body
90
+ * @param {RequestOptions} [params.options] - Additional options for the request
91
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the alert after the action
92
+ */
93
+ triageAlert: async ({ alertId, data, options = {} }) => {
94
+ this.client._require({ alertId, data });
95
+ return this.client(`/compliance/alerts/${encodeURIComponent(alertId)}`, { method: "PUT", body: data, ...options });
96
+ },
97
+
98
+ /**
99
+ * Open a case by hand to send the customer a notice; its requirements go out at once. 409 when the object already has an open case.
100
+ * @async
101
+ * @roles signalhouse_admin, signalhouse_user
102
+ * @param {Object} params - The case
103
+ * @param {Object} params.data - `{ objectType, objectId, reasonTemplate, reason?, customerNote?, requirements: [{ kind, text }], fixByDays? }`
104
+ * @param {RequestOptions} [params.options] - Additional options for the request
105
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
106
+ */
107
+ openCase: async ({ data, options = {} }) => {
108
+ this.client._require({ data });
109
+ return this.client(`/compliance/cases`, { method: "POST", body: data, ...options });
110
+ },
111
+
112
+ /**
113
+ * Take, give or release ownership (assigneeUserId, null to release), and edit reasonTemplate, reason and customerNote.
114
+ * @async
115
+ * @roles signalhouse_admin, signalhouse_user
116
+ * @param {Object} params - The change
117
+ * @param {string} params.caseId - The case (CASE-…)
118
+ * @param {Object} params.data - `{ assigneeUserId?, reasonTemplate?, reason?, customerNote? }`
119
+ * @param {RequestOptions} [params.options] - Additional options for the request
120
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
121
+ */
122
+ updateCase: async ({ caseId, data, options = {} }) => {
123
+ this.client._require({ caseId, data });
124
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}`, { method: "PUT", body: data, ...options });
125
+ },
126
+
127
+ /**
128
+ * Send requirements the first time, or add more; either hands the case to the customer.
129
+ * @async
130
+ * @roles signalhouse_admin, signalhouse_user
131
+ * @param {Object} params - The requirements
132
+ * @param {string} params.caseId - The case (CASE-…)
133
+ * @param {Array<{kind: string, text: string}>} params.requirements - RECORDS, CAMPAIGN_EDIT, NUMBER_ACTION or CONFIRM, with the text
134
+ * @param {number} [params.fixByDays] - Days until they are due, 1-14 (default 5)
135
+ * @param {RequestOptions} [params.options] - Additional options for the request
136
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
137
+ */
138
+ sendRequirements: async ({ caseId, requirements, fixByDays, options = {} }) => {
139
+ this.client._require({ caseId, requirements });
140
+ const body = { requirements, ...(fixByDays !== undefined && { fixByDays }) };
141
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/requirements`, { method: "PUT", body, ...options });
142
+ },
143
+
144
+ /**
145
+ * Record that the lift request went upstream. The case must hold an open carrier suspension or provider pause.
146
+ * @async
147
+ * @roles signalhouse_admin, signalhouse_user
148
+ * @param {Object} params - The request
149
+ * @param {string} params.caseId - The case (CASE-…)
150
+ * @param {string} [params.note] - What was sent
151
+ * @param {RequestOptions} [params.options] - Additional options for the request
152
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
153
+ */
154
+ requestLift: async ({ caseId, note, options = {} }) => {
155
+ this.client._require({ caseId });
156
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/lift-request`, { method: "POST", body: { ...(note !== undefined && { note }) }, ...options });
157
+ },
158
+
159
+ /**
160
+ * Close a case. Lift its open blocks first.
161
+ * @async
162
+ * @roles signalhouse_admin, signalhouse_user
163
+ * @param {Object} params - The close
164
+ * @param {string} params.caseId - The case (CASE-…)
165
+ * @param {string} params.closeReason - CUSTOMER_REMEDIATED, SUSPENDED_BY_CARRIER, LIFTED, LABEL_REMOVED, TRACEBACK_ANSWERED, FALSE_POSITIVE or CLEARED
166
+ * @param {string} [params.closeNote] - Why
167
+ * @param {RequestOptions} [params.options] - Additional options for the request
168
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the closed case
169
+ */
170
+ closeCase: async ({ caseId, closeReason, closeNote, options = {} }) => {
171
+ this.client._require({ caseId, closeReason });
172
+ const body = { closeReason, ...(closeNote !== undefined && { closeNote }) };
173
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/close`, { method: "POST", body, ...options });
174
+ },
175
+
176
+ /**
177
+ * Email the customer a reminder of the requirements still open.
178
+ * @async
179
+ * @roles signalhouse_admin, signalhouse_user
180
+ * @param {Object} params - The reminder
181
+ * @param {string} params.caseId - The case (CASE-…)
182
+ * @param {RequestOptions} [params.options] - Additional options for the request
183
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
184
+ */
185
+ remindCase: async ({ caseId, options = {} }) => {
186
+ this.client._require({ caseId });
187
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/reminder`, { method: "POST", body: {}, ...options });
188
+ },
189
+
190
+ /**
191
+ * Add a staff note, or an email to or from the upstream, to a case's history.
192
+ * @async
193
+ * @roles signalhouse_admin, signalhouse_user
194
+ * @param {Object} params - The note
195
+ * @param {string} params.caseId - The case (CASE-…)
196
+ * @param {string} params.kind - STAFF, EMAIL_IN or EMAIL_OUT
197
+ * @param {string} params.text - The note
198
+ * @param {{from?: string, to?: string, subject?: string, body?: string}} [params.email] - The email, on EMAIL_IN and EMAIL_OUT
199
+ * @param {RequestOptions} [params.options] - Additional options for the request
200
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the staff view of the case
201
+ */
202
+ addCaseNote: async ({ caseId, kind, text, email, options = {} }) => {
203
+ this.client._require({ caseId, kind, text });
204
+ const body = { kind, text, ...(email !== undefined && { email }) };
205
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/note`, { method: "POST", body, ...options });
206
+ },
207
+
208
+ /**
209
+ * Get a group's strikes in the last 90 days, the block periods behind them, and whether an open case carries the review flag.
210
+ * @async
211
+ * @roles signalhouse_admin, signalhouse_user
212
+ * @param {Object} params - The lookup
213
+ * @param {string} params.groupId - The group
214
+ * @param {RequestOptions} [params.options] - Additional options for the request
215
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ groupId, windowDays, strikes, reviewDue, periods }`
216
+ */
217
+ getStrikes: async ({ groupId, options = {} }) => {
218
+ this.client._require({ groupId });
219
+ return this.client(`/compliance/strikes/${encodeURIComponent(groupId)}`, { method: "GET", ...options });
220
+ },
221
+ };
222
+ }
223
+ }
224
+
225
+ /**
226
+ * List the compliance cases you can see, newest first. `counts.waitingOnYou` is the open cases with requirements still to answer
227
+ * @async
228
+ * @roles api, admin, developer, billing, user
229
+ * @param {Object} [params] - Filters
230
+ * @param {string} [params.groupId] - A group you can view; defaults to your active group
231
+ * @param {string} [params.status] - OPEN, LIFT_REQUESTED or CLOSED
232
+ * @param {string} [params.stage] - new, customer, ready, lift_requested or closed
233
+ * @param {string} [params.objectType] - CAMPAIGN, BRAND, NUMBER, RCS_AGENT or SUBGROUP
234
+ * @param {string} [params.objectId] - The object's id
235
+ * @param {string} [params.subgroupId] - Only cases in this subgroup
236
+ * @param {boolean} [params.suspended] - true for cases with an open suspension or hold, false for the rest
237
+ * @param {string} [params.from] - Opened on or after this ISO 8601 time
238
+ * @param {string} [params.to] - Opened on or before this ISO 8601 time
239
+ * @param {string} [params.sort] - createdAt (default), fixBy or severity
240
+ * @param {number} [params.page] - Page number, from 1
241
+ * @param {number} [params.limit] - Cases per page, 1-200
242
+ * @param {RequestOptions} [params.options] - Additional options for the request
243
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ data, total, page, limit, totalPages, counts: { open, waitingOnYou } }`
244
+ */
245
+ async getCases({ groupId, status, stage, objectType, objectId, subgroupId, suspended, from, to, sort, page, limit, options = {} } = {}) {
246
+ const query = this.client._getQueryString({ groupId, status, stage, objectType, objectId, subgroupId, suspended, from, to, sort, page, limit });
247
+ return this.client(`/compliance/cases${query}`, { method: "GET", ...options });
248
+ }
249
+
250
+ /**
251
+ * Get one compliance case: its stage, suspensions, tickets and requirements
252
+ * @async
253
+ * @roles api, admin, developer, billing, user
254
+ * @param {Object} params - The lookup
255
+ * @param {string} params.caseId - The case (CASE-…)
256
+ * @param {RequestOptions} [params.options] - Additional options for the request
257
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the case
258
+ */
259
+ async getCase({ caseId, options = {} }) {
260
+ this.client._require({ caseId });
261
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}`, { method: "GET", ...options });
262
+ }
263
+
264
+ /**
265
+ * Answer one requirement with a note, files, or both. A RECORDS requirement needs a file or a note
266
+ * @async
267
+ * @roles api, admin, developer, user
268
+ * @param {Object} params - The answer
269
+ * @param {string} params.caseId - The case (CASE-…)
270
+ * @param {string} params.requirementId - The requirement (CASE-…-n)
271
+ * @param {string} [params.answer] - What you did, up to 2,000 characters
272
+ * @param {string[]} [params.fileIds] - Up to 10 fileIds from uploadFile, on this case
273
+ * @param {RequestOptions} [params.options] - Additional options for the request
274
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the case
275
+ */
276
+ async answerRequirement({ caseId, requirementId, answer, fileIds, options = {} }) {
277
+ this.client._require({ caseId, requirementId });
278
+ const body = { ...(answer !== undefined && { answer }), ...(fileIds !== undefined && { fileIds }) };
279
+ return this.client(`/compliance/cases/${encodeURIComponent(caseId)}/requirements/${encodeURIComponent(requirementId)}`, { method: "PUT", body, ...options });
280
+ }
281
+
282
+ /**
283
+ * Upload a file to a compliance case (CSV, XLSX, PDF, PNG, JPG or TXT, up to 10 MB). Pass the returned fileId in
284
+ * fileIds when you answer the requirement
285
+ * @async
286
+ * @roles api, admin, developer, user
287
+ * @param {Object} params - The upload
288
+ * @param {string} params.caseId - The case the file answers
289
+ * @param {string} [params.requirementId] - The requirement the file answers
290
+ * @param {Blob|File} params.file - The file, as a Blob/File
291
+ * @param {string} [params.fileName] - Multipart filename; required for a CSV/TXT Blob without a name
292
+ * @param {RequestOptions} [params.options] - Additional options for the request
293
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to `{ fileId, fileName, mimeType, size }`
294
+ */
295
+ async uploadFile({ caseId, requirementId, file, fileName, options = {} }) {
296
+ this.client._require({ caseId, file });
297
+ const name = fileName ?? ("name" in file && typeof file.name === "string" ? file.name : undefined);
298
+ if (!name && ["text/csv", "text/plain"].includes(file.type.split(";")[0])) {
299
+ const error = new Error("CSV/TXT Blob uploads require fileName (for example records.csv), or a named File.");
300
+ error.name = "SignalHouseValidationError";
301
+ throw error;
302
+ }
303
+ const formData = new FormData();
304
+ formData.append("caseId", caseId);
305
+ if (requirementId) formData.append("requirementId", requirementId);
306
+ if (name !== undefined) formData.append("file", file, name);
307
+ else formData.append("file", file);
308
+ return this.multipartClient(`/compliance/files`, { method: "POST", body: formData, ...options });
309
+ }
310
+
311
+ /**
312
+ * Download a compliance file
313
+ * @async
314
+ * @roles api, admin, developer, billing, user
315
+ * @param {Object} params - The lookup
316
+ * @param {string} params.fileId - The fileId uploadFile returned
317
+ * @param {RequestOptions} [params.options] - Additional options for the request
318
+ * @returns {Promise<SdkResponse<ArrayBuffer>>} A promise that resolves to the file bytes as an ArrayBuffer
319
+ */
320
+ async getFile({ fileId, options = {} }) {
321
+ this.client._require({ fileId });
322
+ return this.client(`/compliance/files/${encodeURIComponent(fileId)}`, { method: "GET", responseType: "arraybuffer", ...options });
323
+ }
324
+ }
@@ -0,0 +1,117 @@
1
+ /** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
2
+ /**
3
+ * @template T
4
+ * @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
5
+ */
6
+
7
+ /**
8
+ * Contracts domain: the staff queue for pricing read from signed PandaDoc contracts. Every method lives under
9
+ * the admin namespace, present only when the SDK is created with `enableAdmin: true`. JS SDK only by design.
10
+ */
11
+ export class Contracts {
12
+ constructor(client, enableAdmin) {
13
+ this.client = client;
14
+ this.enableAdmin = enableAdmin;
15
+
16
+ // Hidden Admin namespace INSIDE the domain
17
+ if (enableAdmin) {
18
+ this.admin = {
19
+ /**
20
+ * List contracts for the staff queue, newest first. Staff-only.
21
+ * @async
22
+ * @roles signalhouse
23
+ * @param {Object} [params]
24
+ * @param {string|string[]} [params.status] - One status, or several (an array or a comma-separated string)
25
+ * @param {string} [params.groupId] - Only this group's contracts, newest signed first
26
+ * @param {number} [params.page] - Page number (default 1)
27
+ * @param {number} [params.limit] - Contracts per page (default 25, max 100)
28
+ * @param {RequestOptions} [params.options] - Additional options for the request
29
+ * @returns {Promise<SdkResponse<any>>} - `{ data, total, page, limit }`; each contract carries `pandadocUrl`
30
+ */
31
+ getContracts: async ({ status, groupId, page, limit, options = {} } = {}) => {
32
+ const queryString = this.client._getQueryString({ status: Array.isArray(status) ? status.join(",") : status, groupId, page, limit });
33
+ return this.client(`/contract${queryString}`, { method: "GET", ...options });
34
+ },
35
+
36
+ /**
37
+ * Get one contract: issues, diff, signers, a PandaDoc link and, when it has no group, a suggested one. Staff-only.
38
+ * @async
39
+ * @roles signalhouse
40
+ * @param {Object} params
41
+ * @param {string} params.contractId - The contract's ID
42
+ * @param {RequestOptions} [params.options] - Additional options for the request
43
+ * @returns {Promise<SdkResponse<any>>} - The contract with `pandadocUrl` and `suggestedGroup`
44
+ */
45
+ getContract: async ({ contractId, options = {} }) => {
46
+ this.client._require({ contractId });
47
+ return this.client(`/contract/${encodeURIComponent(contractId)}`, { method: "GET", ...options });
48
+ },
49
+
50
+ /**
51
+ * Link a contract to a group by hand; the document is then read again against that group. The link resets the contract's
52
+ * status, so a scheduled contract loses its schedule. Staff-only.
53
+ * @async
54
+ * @roles signalhouse
55
+ * @param {Object} params
56
+ * @param {string} params.contractId - The contract's ID
57
+ * @param {string} params.groupId - The group the contract is for
58
+ * @param {RequestOptions} [params.options] - Additional options for the request
59
+ * @returns {Promise<SdkResponse<any>>} - The contract after the re-read
60
+ */
61
+ linkContractGroup: async ({ contractId, groupId, options = {} }) => {
62
+ this.client._require({ contractId, groupId });
63
+ return this.client(`/contract/${encodeURIComponent(contractId)}/link`, { method: "POST", body: { groupId }, ...options });
64
+ },
65
+
66
+ /**
67
+ * Apply a contract's pricing to its group now (staff approval). A contract dated in the future is scheduled instead.
68
+ * Staff-only.
69
+ * @async
70
+ * @roles signalhouse
71
+ * @param {Object} params
72
+ * @param {string} params.contractId - The contract's ID
73
+ * @param {string} params.expectedUpdatedAt - The `updatedAt` of the contract as reviewed; a changed contract gets a 409
74
+ * @param {string} params.expectedGroupId - The group the contract was reviewed for
75
+ * @param {?number} [params.expectedPlanCharge] - The immediate charge shown from `applyPreview`, in microdollars; a plan
76
+ * create that would charge anything else is refused before charging
77
+ * @param {RequestOptions} [params.options] - Additional options for the request
78
+ * @returns {Promise<SdkResponse<any>>} - The contract after the apply
79
+ */
80
+ applyContract: async ({ contractId, expectedUpdatedAt, expectedGroupId, expectedPlanCharge, options = {} }) => {
81
+ this.client._require({ contractId, expectedUpdatedAt, expectedGroupId });
82
+ return this.client(`/contract/${encodeURIComponent(contractId)}/apply`, { method: "POST", body: { expectedUpdatedAt, expectedGroupId, ...(expectedPlanCharge !== undefined ? { expectedPlanCharge } : {}) }, ...options });
83
+ },
84
+
85
+ /**
86
+ * Reject a contract so it is never applied. Staff-only.
87
+ * @async
88
+ * @roles signalhouse
89
+ * @param {Object} params
90
+ * @param {string} params.contractId - The contract's ID
91
+ * @param {string} params.reason - Why it is rejected
92
+ * @param {RequestOptions} [params.options] - Additional options for the request
93
+ * @returns {Promise<SdkResponse<any>>} - The rejected contract
94
+ */
95
+ rejectContract: async ({ contractId, reason, options = {} }) => {
96
+ this.client._require({ contractId, reason });
97
+ return this.client(`/contract/${encodeURIComponent(contractId)}/reject`, { method: "POST", body: { reason }, ...options });
98
+ },
99
+
100
+ /**
101
+ * Read a contract from PandaDoc again and re-parse it. Not allowed while scheduled, or once pricing is being written or has been applied.
102
+ * Staff-only.
103
+ * @async
104
+ * @roles signalhouse
105
+ * @param {Object} params
106
+ * @param {string} params.contractId - The contract's ID
107
+ * @param {RequestOptions} [params.options] - Additional options for the request
108
+ * @returns {Promise<SdkResponse<any>>} - The contract after the re-read
109
+ */
110
+ reparseContract: async ({ contractId, options = {} }) => {
111
+ this.client._require({ contractId });
112
+ return this.client(`/contract/${encodeURIComponent(contractId)}/reparse`, { method: "POST", body: {}, ...options });
113
+ },
114
+ };
115
+ }
116
+ }
117
+ }
@@ -496,7 +496,7 @@ export class RcsMessages {
496
496
  * @param {string} [params.expireTime] - ISO-8601 time the RCS message expires
497
497
  * @param {RcsMessageFallback} [params.fallback] - The fallback to price; its from is optional here, and with none the leg is priced on the channel of the agent's linked campaign
498
498
  * @param {RequestOptions} [params.options] - Additional options for the request
499
- * @returns {Promise<SdkResponse<any>>} A promise that resolves to { billingClass, segments, recipientCount, rcsLeg, fallbackLeg, totals, balance, issues, warnings }; rcsLeg.mediaSurcharge is the carrier's surcharge on media over 5 MB for one recipient, and rcsLeg.cost already holds it for every recipient; rcsLeg.cost is null with the fallback mode sms_only; a message over 100 MB adds a MEDIA_TOO_LARGE issue.
499
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { billingClass, segments, recipientCount, rcsLeg, fallbackLeg, totals, balance, issues, warnings }; rcsLeg.mediaSurcharge is the carrier's surcharge on media over 5 MB for one recipient, and rcsLeg.cost already holds it for every recipient; rcsLeg.cost is null with the fallback mode sms_only; a message over 100 MB adds a MEDIA_TOO_LARGE issue, and an external media URL that redirects adds a MEDIA_REDIRECT issue.
500
500
  */
501
501
  async estimate({ agentId, recipients, recipientCount, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, options = {} }) {
502
502
  this.client._require({ agentId });
@@ -48,6 +48,37 @@ export class Subgroups {
48
48
  constructor(client, enableAdmin) {
49
49
  this.client = client;
50
50
  this.enableAdmin = enableAdmin;
51
+
52
+ // Hidden Admin namespace INSIDE the domain
53
+ if (enableAdmin) {
54
+ this.admin = {
55
+ /**
56
+ * Link (or, with ghlLocationId: null, unlink) a GoHighLevel location to a subgroup. At most
57
+ * one subgroup may hold a given ghlLocationId; linking it here steals it from any other
58
+ * subgroup that currently holds it. Intended for ghl-app/backend's write-through right after
59
+ * it locally claims a location -> subgroup link.
60
+ * @async
61
+ * @roles signalhouse_api, signalhouse_admin
62
+ * @param {Object} params - The parameters for linking a GHL location
63
+ * @param {string} params.subgroupId - The subgroup to link
64
+ * @param {string|null} params.ghlLocationId - The GHL location ID to link, or null to unlink
65
+ * @param {string|null} [params.ghlLocationName] - Display name of the GHL location. Omit to leave the
66
+ * subgroup's currently stored name untouched (only when ghlLocationId is unchanged - otherwise
67
+ * cleared to null); always cleared to null when unlinking
68
+ * @param {Date|string} [params.claimedAt] - When this link was locally claimed by the caller.
69
+ * Required when linking (ghlLocationId is non-null) - used to detect and reject a delayed/
70
+ * out-of-order push whose claim has since been superseded by a newer one recorded elsewhere.
71
+ * Ignored when unlinking.
72
+ * @param {RequestOptions} [params.options] - Additional options for the request
73
+ * @throws {Error} Throws an error if the subgroupId parameter is missing
74
+ * @returns {Promise<SdkResponse<any>>} - The updated subgroup object returned from the server
75
+ */
76
+ linkGhlLocation: async ({ subgroupId, ghlLocationId, ghlLocationName, claimedAt, options = {} }) => {
77
+ this.client._require({ subgroupId });
78
+ return this.client(`/subgroup/ghl-location-link`, { method: "PUT", body: { subgroupId, ghlLocationId, ghlLocationName, claimedAt }, ...options });
79
+ },
80
+ };
81
+ }
51
82
  }
52
83
 
53
84
  /**
@@ -118,6 +149,26 @@ export class Subgroups {
118
149
  return this.client(`/subgroup/${safeId}`, { method: "PUT", body: updateData, ...options });
119
150
  }
120
151
 
152
+ /**
153
+ * Resolve the mapping between a GoHighLevel location and a Signal House subgroup, in either
154
+ * direction. Provide exactly one of ghlLocationId or subgroupId. groupId is optional - customer
155
+ * roles default to their own accessible group(s) and are rejected if they name a group they don't
156
+ * belong to; a subgroupId/ghlLocationId that belongs to a different group than the caller's returns
157
+ * a 404, identical to a nonexistent one.
158
+ * @async
159
+ * @roles api, admin, developer, billing, user
160
+ * @param {Object} params - The parameters for the lookup
161
+ * @param {string} [params.groupId] - Restrict the lookup to an accessible group ID
162
+ * @param {string} [params.ghlLocationId] - GHL location ID to resolve to its subgroup (mutually exclusive with subgroupId)
163
+ * @param {string} [params.subgroupId] - Subgroup ID to resolve to its GHL location (mutually exclusive with ghlLocationId)
164
+ * @param {RequestOptions} [params.options] - Additional options for the request
165
+ * @returns {Promise<SdkResponse<any>>} - `{ groupId, subgroupId, subgroupName, ghlLocationId, ghlLocationName }`
166
+ */
167
+ async lookupGhlLocation({ groupId, ghlLocationId, subgroupId, options = {} } = {}) {
168
+ const queryString = this.client._getQueryString({ groupId, ghlLocationId, subgroupId });
169
+ return this.client(`/subgroup/ghl-location-lookup${queryString}`, { method: "GET", ...options });
170
+ }
171
+
121
172
  /**
122
173
  * Delete a subgroup by its ID (mark as inactive)
123
174
  * @async
@@ -11,12 +11,20 @@
11
11
  */
12
12
 
13
13
  /**
14
+ * A declared placeholder. Placeholders go in text, card titles and descriptions, button labels and fallback text. A url
15
+ * variable may fill a whole link or media URL, and any variable may fill a URL's path, query or fragment, percent-encoded. A
16
+ * dial number takes one phoneNumber variable and a calendar time one dateTime variable, each for the whole field. A calendar
17
+ * title and description and postbackData take text. A location's address and label take none. The send checks each filled
18
+ * field and blocks a recipient whose field fails with CONTENT_INVALID.
14
19
  * @typedef {Object} RcsVariable
15
20
  * @property {string} key - Placeholder key used as {{key}} (/^[a-z][a-z0-9_]{0,63}$/)
16
21
  * @property {string} [label] - Display label
17
22
  * @property {"text"|"number"|"dateTime"|"phoneNumber"|"url"} type - Value type
18
- * @property {boolean} required - Whether a send must supply a value
19
- * @property {string} [default] - Value used when none is supplied
23
+ * @property {boolean} required - Without missingPolicy: whether a recipient with no value and no default is blocked
24
+ * @property {"default"|"block"|"drop"} [missingPolicy] - What a recipient with no value gets: the default (empty when none),
25
+ * a VARIABLE_MISSING block, or the send without each block that uses the variable. Omitted keeps the older rule: the
26
+ * default, else VARIABLE_MISSING when required, else empty. An empty value, or one of only spaces, counts as no value
27
+ * @property {string} [default] - Value used when none is supplied, by the default policy or with no policy
20
28
  * @property {string} [sample] - Example value for previews
21
29
  */
22
30
 
@@ -117,6 +125,8 @@
117
125
  * @property {"image"|"video"|"audio"|"file"} kind - Media kind
118
126
  * @property {number|null} width - Pixel width, when known
119
127
  * @property {number|null} height - Pixel height, when known
128
+ * @property {{ mms?: { url: string, bytes: number } }} variants - An image over the MMS size limit has an MMS copy, which an
129
+ * MMS fallback leg sends; {} otherwise
120
130
  * @property {string} createdAt - ISO timestamp
121
131
  */
122
132
 
@@ -138,7 +148,8 @@
138
148
  * @property {Object<string, string[]>} trafficByUseCase - The traffic types each agent use case may send
139
149
  * @property {Object<string, string>} defaultTrafficByUseCase - The traffic type a single-purpose agent sends when a request names none
140
150
  * @property {{ cardButtonsInline: number, suggestedActionsInline: number, linesPerField: number, charsPerLine: number }} ios - How an iPhone lays out RCS content
141
- * @property {{ maxUploadBytes: number, mimeTypes: string[] }} media - Upload constraints
151
+ * @property {{ maxUploadBytes: number, mimeTypes: string[], maxImageEdge: number, imageTargetBytes: number }} media - Upload
152
+ * constraints; an image over maxImageEdge or imageTargetBytes is compressed to both
142
153
  * @property {{ available: boolean }} geocoding - Whether this server resolves VIEW_LOCATION addresses (geocodeAddress answers 503 when false)
143
154
  * @property {{ provider: "infobip"|"sinch", adapterVersion: string, limits: Object<string, number>, unsupported: Array<{ feature: string, code: string, message: string }> }|null} provider - Provider-specific limits when a provider was requested
144
155
  */
@@ -308,7 +319,7 @@ export class Templates {
308
319
 
309
320
  /**
310
321
  * Publish a template's current draft; no draft returns 409 NO_DRAFT, a draft changed mid-publish returns 409 DRAFT_CHANGED (publish again) and an incomplete draft returns 400 TEMPLATE_INVALID
311
- * A block whose text or image the Moderation API flags is an error with code CONTENT_POLICY_FLAGGED, whose message names the category ("Content moderation flagged this text: spam"). The check passes when the Moderation API fails.
322
+ * A block whose text or image the Moderation API flags is an error with code CONTENT_POLICY_FLAGGED, whose message names the category ("Content moderation flagged this text: spam"). The check passes when the Moderation API fails. An image URL with a variable is moderated at send instead, with its value filled in, and a refused image blocks the recipient with MODERATION.
312
323
  * @async
313
324
  * @roles api, admin, developer
314
325
  * @param {Object} params - The parameters for publishing a template
@@ -368,7 +379,7 @@ export class Templates {
368
379
 
369
380
  /**
370
381
  * Validate an unsaved body or a stored version without writing anything
371
- * Validate runs the publish checks, the content policy check included: a block whose text or image the Moderation API flags is an error with code CONTENT_POLICY_FLAGGED. Saving a draft does not run that check.
382
+ * Validate runs the publish checks, the content policy check included: a block whose text or image the Moderation API flags is an error with code CONTENT_POLICY_FLAGGED. An image URL with a variable is moderated at send instead, with its value filled in, and a refused image blocks the recipient with MODERATION. Saving a draft does not run that check.
372
383
  * @async
373
384
  * @roles api, admin, developer, billing, user
374
385
  * @param {Object} params - The parameters for validation; pass exactly one of body or version
@@ -424,7 +435,9 @@ export class Templates {
424
435
  }
425
436
 
426
437
  /**
427
- * Upload a media file for use in template bodies; returns its public URL. 503 when media storage is not configured
438
+ * Upload a media file for use in template bodies; returns its public URL. An image over 1920 px on its longest edge or over
439
+ * 5,000,000 bytes is compressed to both, and one over the MMS size limit also gets an MMS copy in variants.mms. 503 when
440
+ * media storage is not configured
428
441
  * @async
429
442
  * @roles api, admin, developer
430
443
  * @param {Object} params - The parameters for the upload