@signalhousellc/sdk 1.5.1 → 1.7.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 +5 -56
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/package.json +32 -34
- package/voice-browser.d.ts +1 -0
- package/voice-browser.js +2 -0
- package/warn.js +7 -0
- package/webhooks.d.ts +1 -0
- package/webhooks.js +2 -0
- package/scripts/install-skills.mjs +0 -329
- package/skills/VENDORED.json +0 -22
- package/skills/signalhouse-10dlc/SKILL.md +0 -172
- package/skills/signalhouse-10dlc/examples/brightsmile-onboarding.md +0 -62
- package/skills/signalhouse-10dlc/references/tcr-rejection-causes.md +0 -104
- package/skills/signalhouse-advisor/SKILL.md +0 -84
- package/skills/signalhouse-numbers/SKILL.md +0 -82
- package/skills/signalhouse-setup/SKILL.md +0 -121
- package/skills/signalhouse-sms/SKILL.md +0 -81
- package/skills/signalhouse-webhooks/SKILL.md +0 -148
- package/src/SignalHouseSDK.js +0 -201
- package/src/domains/Agents.js +0 -987
- package/src/domains/Auth.js +0 -225
- package/src/domains/Billing.js +0 -265
- package/src/domains/Brands.js +0 -566
- package/src/domains/Campaigns.js +0 -691
- package/src/domains/Dnc.js +0 -168
- package/src/domains/Groups.js +0 -187
- package/src/domains/Landings.js +0 -237
- package/src/domains/Messages.js +0 -609
- package/src/domains/Notifications.js +0 -62
- package/src/domains/Numbers.js +0 -574
- package/src/domains/Onboarding.js +0 -128
- package/src/domains/Registrations.js +0 -246
- package/src/domains/Shortlinks.js +0 -80
- package/src/domains/Subgroups.js +0 -136
- package/src/domains/Subscriptions.js +0 -164
- package/src/domains/Templates.js +0 -403
- package/src/domains/Tickets.js +0 -100
- package/src/domains/Users.js +0 -228
- package/src/domains/Voice.js +0 -41
- package/src/domains/Webhooks.js +0 -125
- package/src/domains/voice/Analytics.js +0 -82
- package/src/domains/voice/CallLogs.js +0 -111
- package/src/domains/voice/Calls.js +0 -118
- package/src/domains/voice/GlobalVoiceSettings.js +0 -54
- package/src/domains/voice/NumberRoutes.js +0 -82
- package/src/domains/voice/ProgrammableVoiceProfiles.js +0 -191
- package/src/domains/voice/SipProfiles.js +0 -203
- package/src/domains/voice/SipTrunks.js +0 -203
- package/src/domains/voice/Tokens.js +0 -96
- package/src/domains/voice/browser/Call.js +0 -366
- package/src/domains/voice/browser/Device.js +0 -484
- package/src/domains/voice/browser/index.js +0 -17
- package/src/webhooks/verifySignature.js +0 -66
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
|
|
2
|
-
/**
|
|
3
|
-
* @template T
|
|
4
|
-
* @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export class Subscriptions {
|
|
8
|
-
constructor(client, enableAdmin) {
|
|
9
|
-
this.client = client;
|
|
10
|
-
this.enableAdmin = enableAdmin;
|
|
11
|
-
|
|
12
|
-
if (enableAdmin) {
|
|
13
|
-
this.admin = {
|
|
14
|
-
/**
|
|
15
|
-
* Get subscription templates with optional filtering by template ID
|
|
16
|
-
* @async
|
|
17
|
-
* @roles signalhouse
|
|
18
|
-
* @param {Object} params - The parameters for getting subscription templates
|
|
19
|
-
* @param {string} [params.templateId] - The ID of a specific template to retrieve (optional)
|
|
20
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
21
|
-
* @returns {Promise<SdkResponse<any>>} - The subscription templates returned from the server
|
|
22
|
-
*/
|
|
23
|
-
getTemplates: async ({ templateId, options = {} }) => {
|
|
24
|
-
const filters = { templateId };
|
|
25
|
-
const queryString = this.client._getQueryString(filters);
|
|
26
|
-
return this.client(`/subscription/template${queryString}`, { method: "GET", ...options });
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Create a new subscription template with the provided template data
|
|
31
|
-
* @async
|
|
32
|
-
* @roles signalhouse
|
|
33
|
-
* @param {Object} params - The parameters for creating a subscription template
|
|
34
|
-
* @param {Object} params.templateData - The data for the new subscription template, including required fields such as templateName and monthlyFee
|
|
35
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
36
|
-
* @throws {Error} Throws an error if the templateData parameter is missing or if required fields within templateData are missing
|
|
37
|
-
* @returns {Promise<SdkResponse<any>>} - The created subscription template object returned from the server
|
|
38
|
-
*/
|
|
39
|
-
createTemplate: async ({ templateData, options = {} }) => {
|
|
40
|
-
this.client._require({ templateData: templateData });
|
|
41
|
-
return this.client(`/subscription/template`, { method: "POST", body: templateData, ...options });
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Update an existing subscription template with the provided template data
|
|
46
|
-
* @async
|
|
47
|
-
* @roles signalhouse
|
|
48
|
-
* @param {Object} params - The parameters for updating a subscription template
|
|
49
|
-
* @param {string} params.templateId - The ID of the subscription template to update
|
|
50
|
-
* @param {Object} params.templateData - The data for the subscription template, including fields such as templateName and monthlyFee
|
|
51
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
52
|
-
* @throws {Error} Throws an error if the templateId or templateData parameter is missing
|
|
53
|
-
* @returns {Promise<SdkResponse<any>>} - The updated subscription template object returned from the server
|
|
54
|
-
*/
|
|
55
|
-
updateTemplate: async ({ templateId, templateData, options = {} }) => {
|
|
56
|
-
this.client._require({ templateId, templateData });
|
|
57
|
-
const safeTemplateId = encodeURIComponent(templateId);
|
|
58
|
-
return this.client(`/subscription/template/${safeTemplateId}`, { method: "PUT", body: templateData, ...options });
|
|
59
|
-
},
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Delete an existing subscription template
|
|
63
|
-
* @async
|
|
64
|
-
* @roles signalhouse
|
|
65
|
-
* @param {Object} params - The parameters for deleting a subscription template
|
|
66
|
-
* @param {string} params.templateId - The ID of the subscription template to delete
|
|
67
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
68
|
-
* @throws {Error} Throws an error if the templateId parameter is missing
|
|
69
|
-
* @returns {Promise<SdkResponse<any>>} - The deleted subscription template object returned from the server
|
|
70
|
-
*/
|
|
71
|
-
deleteTemplate: async ({ templateId, options = {} }) => {
|
|
72
|
-
this.client._require({ templateId });
|
|
73
|
-
const safeTemplateId = encodeURIComponent(templateId);
|
|
74
|
-
return this.client(`/subscription/template/${safeTemplateId}`, { method: "DELETE", ...options });
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Create a custom subscription for a group with the provided subscription data.
|
|
79
|
-
* Optional volumeTiers, rampDays, and monthlyMinimumSmsSegments enable graduated SMS rates and a monthly minimum that ramps up linearly over rampDays.
|
|
80
|
-
* @async
|
|
81
|
-
* @roles signalhouse
|
|
82
|
-
* @param {Object} params - The parameters for creating a custom subscription
|
|
83
|
-
* @param {string} params.groupId - The ID of the group to create the custom subscription for
|
|
84
|
-
* @param {Object} params.subscriptionData - The data for the custom subscription, including required fields such as name and monthlyFee
|
|
85
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
86
|
-
* @throws {Error} Throws an error if the groupId or subscriptionData parameter is missing or if required fields within subscriptionData are missing
|
|
87
|
-
* @returns {Promise<SdkResponse<any>>} - The created custom subscription object returned from the server
|
|
88
|
-
*/
|
|
89
|
-
createCustomSubscription: async ({ groupId, subscriptionData, options = {} }) => {
|
|
90
|
-
this.client._require({ groupId, subscriptionData });
|
|
91
|
-
const safeGroupId = encodeURIComponent(groupId);
|
|
92
|
-
return this.client(`/subscription/user/custom/${safeGroupId}`, { method: "POST", body: subscriptionData, ...options });
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Update volume tiers, ramp, and monthly minimum on an active custom subscription
|
|
97
|
-
* @async
|
|
98
|
-
* @roles signalhouse
|
|
99
|
-
* @param {Object} params - The parameters for updating the custom subscription
|
|
100
|
-
* @param {string} params.groupId - The ID of the group whose custom subscription to update
|
|
101
|
-
* @param {Object} params.updateData - Fields to change (name, description, monthlyFee, volumeTiers, monthlyMinimumSmsSegments, rampDays)
|
|
102
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
103
|
-
* @throws {Error} Throws an error if the groupId or updateData parameter is missing
|
|
104
|
-
* @returns {Promise<SdkResponse<any>>} - The updated custom subscription object returned from the server
|
|
105
|
-
*/
|
|
106
|
-
updateCustomSubscription: async ({ groupId, updateData, options = {} }) => {
|
|
107
|
-
this.client._require({ groupId, updateData });
|
|
108
|
-
const safeGroupId = encodeURIComponent(groupId);
|
|
109
|
-
return this.client(`/subscription/user/custom/${safeGroupId}`, { method: "PUT", body: updateData, ...options });
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Get a list of subscription history for a group, with optional filters
|
|
117
|
-
* @async
|
|
118
|
-
* @roles api, admin, developer, billing, user
|
|
119
|
-
* @param {Object} params - The parameters for getting subscription history
|
|
120
|
-
* @param {string} params.groupId - The ID of the group to get subscription history for
|
|
121
|
-
* @param {boolean} [params.onlyActive] - Whether to only include active subscriptions
|
|
122
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
123
|
-
* @returns {Promise<SdkResponse<any>>} - The subscription history returned from the server
|
|
124
|
-
*/
|
|
125
|
-
async getSubscriptions({ groupId, onlyActive, options = {} }) {
|
|
126
|
-
const filters = { groupId, onlyActive };
|
|
127
|
-
const queryString = this.client._getQueryString(filters);
|
|
128
|
-
return this.client(`/subscription/user${queryString}`, { method: "GET", ...options });
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Subscribe a group to a template
|
|
133
|
-
* @async
|
|
134
|
-
* @roles api, admin, developer, billing, user
|
|
135
|
-
* @param {Object} params - The parameters for subscribing a group to a template
|
|
136
|
-
* @param {string} params.groupId - The ID of the group to subscribe
|
|
137
|
-
* @param {string} params.templateId - The ID of the template to subscribe the group to
|
|
138
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
139
|
-
* @throws {Error} Throws an error if the groupId or templateId parameter is missing
|
|
140
|
-
* @returns {Promise<SdkResponse<any>>} - The subscription object returned from the server
|
|
141
|
-
*/
|
|
142
|
-
async subscribe({ groupId, templateId, options = {} }) {
|
|
143
|
-
this.client._require({ groupId, templateId });
|
|
144
|
-
const safeGroupId = encodeURIComponent(groupId);
|
|
145
|
-
const safeTemplateId = encodeURIComponent(templateId);
|
|
146
|
-
return this.client(`/subscription/user/subscribe/${safeGroupId}/${safeTemplateId}`, { method: "POST", body: {}, ...options });
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Unsubscribe a group from a template
|
|
151
|
-
* @async
|
|
152
|
-
* @roles api, admin, developer, billing, user
|
|
153
|
-
* @param {Object} params - The parameters for unsubscribing a group from a template
|
|
154
|
-
* @param {string} params.groupId - The ID of the group to unsubscribe
|
|
155
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
156
|
-
* @throws {Error} Throws an error if the groupId parameter is missing
|
|
157
|
-
* @returns {Promise<SdkResponse<any>>} - The subscription object returned from the server
|
|
158
|
-
*/
|
|
159
|
-
async unsubscribe({ groupId, options = {} }) {
|
|
160
|
-
this.client._require({ groupId });
|
|
161
|
-
const safeGroupId = encodeURIComponent(groupId);
|
|
162
|
-
return this.client(`/subscription/user/cancel/${safeGroupId}`, { method: "POST", ...options });
|
|
163
|
-
}
|
|
164
|
-
}
|
package/src/domains/Templates.js
DELETED
|
@@ -1,403 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
|
|
2
|
-
/**
|
|
3
|
-
* @template T
|
|
4
|
-
* @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A version selector: a positive version number, "draft" or "published". Omitted means the published
|
|
9
|
-
* version when one exists, otherwise the draft; an explicit selector never falls back (404 when missing).
|
|
10
|
-
* @typedef {number|"draft"|"published"} VersionSelector
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {Object} RcsVariable
|
|
15
|
-
* @property {string} key - Placeholder key used as {{key}} (/^[a-z][a-z0-9_]{0,63}$/)
|
|
16
|
-
* @property {string} [label] - Display label
|
|
17
|
-
* @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
|
|
20
|
-
* @property {string} [sample] - Example value for previews
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The raw RCS template body. Unknown keys are rejected at every level; see the API docs for the block,
|
|
25
|
-
* suggestion and fallback shapes.
|
|
26
|
-
* @typedef {Object} RcsTemplateBody
|
|
27
|
-
* @property {"rcs"} channel - Always "rcs"
|
|
28
|
-
* @property {"rcs.blocks.v1"} contentFormat - Always "rcs.blocks.v1"
|
|
29
|
-
* @property {{ blocks: Object[] }} content - Ordered blocks of kind text, richCard, video, carousel, suggestions or attachment
|
|
30
|
-
* @property {RcsVariable[]} [variables] - Declared placeholders; omitted means []
|
|
31
|
-
* @property {{ trafficType?: string, ttlSeconds?: number }} [defaults] - Send defaults; omitted means {}
|
|
32
|
-
* @property {{ delivery?: { channel: "sms"|"mms", campaignId?: string, phoneNumber?: string, content: Object }, validitySeconds?: number }} [fallback] - SMS/MMS sent when RCS cannot be delivered; no delivery means no fallback
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {Object} TemplateHead
|
|
37
|
-
* @property {string} templateId - "TPL" + 10 characters
|
|
38
|
-
* @property {string} groupId - Owning group
|
|
39
|
-
* @property {"rcs"} channel - Template channel
|
|
40
|
-
* @property {string} name - 1-120 characters, unique per group and channel
|
|
41
|
-
* @property {string|null} tag - Tag (1-60 characters) or null
|
|
42
|
-
* @property {string|null} archivedAt - When the template was archived
|
|
43
|
-
* @property {number|null} draftVersion - The current draft version
|
|
44
|
-
* @property {number|null} publishedVersion - The current published version
|
|
45
|
-
* @property {number} revision - Head revision, incremented on every write; starts at 1
|
|
46
|
-
* @property {string} createdBy - Creating user
|
|
47
|
-
* @property {string} createdAt - ISO timestamp
|
|
48
|
-
* @property {string} updatedAt - ISO timestamp
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @typedef {TemplateHead & { state: "DRAFT"|"PUBLISHED"|"ARCHIVED", hasUnpublishedChanges: boolean }} TemplateSummary
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {Object} VersionSummary
|
|
57
|
-
* @property {string} templateId - The template ID
|
|
58
|
-
* @property {string} groupId - Owning group
|
|
59
|
-
* @property {number} version - Version number
|
|
60
|
-
* @property {"DRAFT"|"PUBLISHED"} state - Version state
|
|
61
|
-
* @property {string} contentHash - Hex SHA-256 of the canonical body JSON
|
|
62
|
-
* @property {string} createdBy - Creating user
|
|
63
|
-
* @property {string} createdAt - ISO timestamp
|
|
64
|
-
* @property {string} updatedAt - ISO timestamp
|
|
65
|
-
* @property {string|null} publishedAt - ISO timestamp
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @typedef {VersionSummary & { body: RcsTemplateBody }} TemplateVersion
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @typedef {Object} TemplateDetail
|
|
74
|
-
* @property {TemplateSummary} head - The template head
|
|
75
|
-
* @property {TemplateVersion} version - The selected version
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @template T
|
|
80
|
-
* @typedef {{ data: T[], total: number, page: number, limit: number }} Page
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @typedef {Object} ValidationIssue
|
|
85
|
-
* @property {"error"|"warning"} severity - Issue severity
|
|
86
|
-
* @property {string} path - JSON path of the offending field
|
|
87
|
-
* @property {string} code - Machine-readable code
|
|
88
|
-
* @property {string} message - Human-readable message
|
|
89
|
-
* @property {string} [blockId] - The block the issue belongs to
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* @typedef {Object} ValidationResult
|
|
94
|
-
* @property {boolean} valid - Whether the body is publishable
|
|
95
|
-
* @property {string} contentHash - Hex SHA-256 of the canonical body JSON
|
|
96
|
-
* @property {string} validatorVersion - The validator that produced the result
|
|
97
|
-
* @property {ValidationIssue[]} errors - Publication errors
|
|
98
|
-
* @property {ValidationIssue[]} warnings - Non-blocking warnings
|
|
99
|
-
*/
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @typedef {Object} MediaAsset
|
|
103
|
-
* @property {string} mediaId - "MED" + 10 characters
|
|
104
|
-
* @property {string} groupId - Owning group
|
|
105
|
-
* @property {string} url - Public HTTPS URL to reference from a template body
|
|
106
|
-
* @property {number} bytes - File size
|
|
107
|
-
* @property {string} mimeType - MIME type
|
|
108
|
-
* @property {"image"|"video"|"audio"|"file"} kind - Media kind
|
|
109
|
-
* @property {number|null} width - Pixel width, when known
|
|
110
|
-
* @property {number|null} height - Pixel height, when known
|
|
111
|
-
* @property {string} createdAt - ISO timestamp
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Server-defined channel capabilities; values come from the server and drive client-side editors.
|
|
116
|
-
* @typedef {Object} Capabilities
|
|
117
|
-
* @property {"rcs"} channel - The channel described
|
|
118
|
-
* @property {"rcs.blocks.v1"} contentFormat - The body format
|
|
119
|
-
* @property {string} validatorVersion - The validator version
|
|
120
|
-
* @property {string[]} blockKinds - Allowed block kinds
|
|
121
|
-
* @property {string[]} actionTypes - Allowed suggestion types
|
|
122
|
-
* @property {string[]} variableTypes - Allowed variable types
|
|
123
|
-
* @property {string[]} trafficTypes - Allowed traffic types
|
|
124
|
-
* @property {string[]} cardWidths - Allowed carousel card widths
|
|
125
|
-
* @property {string[]} mediaHeights - Allowed card media heights
|
|
126
|
-
* @property {Object<string, number>} limits - Length and count limits (maxBlocks, maxTextLength, maxCarouselCards, ...)
|
|
127
|
-
* @property {{ maxUploadBytes: number, mimeTypes: string[] }} media - Upload constraints
|
|
128
|
-
* @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
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Build the client-side validation error the SDK throws for a malformed request.
|
|
133
|
-
* @param {string} message - The error message
|
|
134
|
-
* @returns {Error & { status?: number }} - An error named SignalHouseValidationError with status 400
|
|
135
|
-
*/
|
|
136
|
-
function validationError(message) {
|
|
137
|
-
const error = /** @type {Error & { status?: number }} */ (new Error(message));
|
|
138
|
-
error.name = "SignalHouseValidationError";
|
|
139
|
-
error.status = 400;
|
|
140
|
-
return error;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Build the update request body; a null tag stays on the wire, an undefined one is dropped.
|
|
145
|
-
* @param {Object} params - The update fields
|
|
146
|
-
* @param {string} params.groupId - The owning group
|
|
147
|
-
* @param {string} [params.name] - New name
|
|
148
|
-
* @param {string|null} [params.tag] - New tag; null clears it, undefined leaves it unchanged
|
|
149
|
-
* @param {RcsTemplateBody} [params.body] - Full replacement body
|
|
150
|
-
* @returns {Object} - The request body
|
|
151
|
-
*/
|
|
152
|
-
export function templateUpdateBody({ groupId, name, tag, body }) {
|
|
153
|
-
return { groupId, name, tag, body };
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Build the validate request body from exactly one of body or version.
|
|
158
|
-
* @param {Object} params - The validate fields
|
|
159
|
-
* @param {string} params.groupId - The owning group
|
|
160
|
-
* @param {RcsTemplateBody} [params.body] - An unsaved body to validate
|
|
161
|
-
* @param {VersionSelector} [params.version] - A stored version to validate
|
|
162
|
-
* @throws {Error} Throws a SignalHouseValidationError unless exactly one of body or version is given
|
|
163
|
-
* @returns {Object} - The request body
|
|
164
|
-
*/
|
|
165
|
-
export function templateValidateBody({ groupId, body, version }) {
|
|
166
|
-
const hasBody = body !== undefined && body !== null;
|
|
167
|
-
const hasVersion = version !== undefined && version !== null;
|
|
168
|
-
if (hasBody === hasVersion) throw validationError("Pass exactly one of body or version");
|
|
169
|
-
return hasBody ? { groupId, body } : { groupId, version };
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Build the multipart form for a media upload.
|
|
174
|
-
* @param {Object} params - The upload fields
|
|
175
|
-
* @param {string} params.groupId - The owning group
|
|
176
|
-
* @param {Blob|File} params.file - The file to upload
|
|
177
|
-
* @param {string} [params.fileName] - File name to send with the file
|
|
178
|
-
* @returns {FormData} - The form with file and groupId fields
|
|
179
|
-
*/
|
|
180
|
-
export function templateMediaForm({ groupId, file, fileName }) {
|
|
181
|
-
const formData = new FormData();
|
|
182
|
-
if (fileName) formData.append("file", file, fileName);
|
|
183
|
-
else formData.append("file", file);
|
|
184
|
-
formData.append("groupId", groupId);
|
|
185
|
-
return formData;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Channel-generic message templates under /template. Templates keep an immutable published version and
|
|
190
|
-
* at most one editable draft; writes apply directly (last write wins). 404 while the environment's RCS
|
|
191
|
-
* switch is off.
|
|
192
|
-
*/
|
|
193
|
-
export class Templates {
|
|
194
|
-
constructor(client, multipartClient, enableAdmin) {
|
|
195
|
-
this.client = client;
|
|
196
|
-
this.multipartClient = multipartClient;
|
|
197
|
-
this.enableAdmin = enableAdmin;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Create a template with draft version 1
|
|
202
|
-
* @async
|
|
203
|
-
* @roles api, admin, developer
|
|
204
|
-
* @param {Object} params - The parameters for creating a template
|
|
205
|
-
* @param {string} params.groupId - The owning group
|
|
206
|
-
* @param {string} params.name - Template name (1-120 characters, unique per group and channel)
|
|
207
|
-
* @param {string} [params.tag] - Tag (1-60 characters)
|
|
208
|
-
* @param {RcsTemplateBody} params.body - The raw template body
|
|
209
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
210
|
-
* @returns {Promise<SdkResponse<TemplateDetail>>} A promise that resolves to the new template and its draft (201)
|
|
211
|
-
*/
|
|
212
|
-
async create({ groupId, name, tag, body, options = {} }) {
|
|
213
|
-
this.client._require({ groupId, name, body });
|
|
214
|
-
return this.client(`/template`, {
|
|
215
|
-
method: "POST",
|
|
216
|
-
body: { groupId, name, tag, body },
|
|
217
|
-
...options,
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* List a group's templates
|
|
223
|
-
* @async
|
|
224
|
-
* @roles api, admin, developer, billing, user
|
|
225
|
-
* @param {Object} params - The parameters for listing templates
|
|
226
|
-
* @param {string} params.groupId - The owning group
|
|
227
|
-
* @param {("DRAFT"|"PUBLISHED"|"ARCHIVED")} [params.state] - Filter by state
|
|
228
|
-
* @param {"rcs"} [params.channel] - Filter by channel
|
|
229
|
-
* @param {string} [params.tag] - Filter by tag
|
|
230
|
-
* @param {string} [params.search] - Search template names
|
|
231
|
-
* @param {("name"|"createdAt"|"updatedAt")} [params.sortBy] - Sort field
|
|
232
|
-
* @param {("asc"|"desc")} [params.sortOrder] - Sort direction
|
|
233
|
-
* @param {number} [params.page] - Page number (default 1)
|
|
234
|
-
* @param {number} [params.limit] - Templates per page (default 25, max 100)
|
|
235
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
236
|
-
* @returns {Promise<SdkResponse<Page<TemplateSummary>>>} A promise that resolves to { data, total, page, limit }
|
|
237
|
-
*/
|
|
238
|
-
async list({ groupId, state, channel, tag, search, sortBy, sortOrder, page, limit, options = {} }) {
|
|
239
|
-
this.client._require({ groupId });
|
|
240
|
-
const queryString = this.client._getQueryString({ groupId, state, channel, tag, search, sortBy, sortOrder, page, limit });
|
|
241
|
-
return this.client(`/template${queryString}`, { method: "GET", ...options });
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Get a template with one of its versions
|
|
246
|
-
* @async
|
|
247
|
-
* @roles api, admin, developer, billing, user
|
|
248
|
-
* @param {Object} params - The parameters for getting a template
|
|
249
|
-
* @param {string} params.templateId - The template ID
|
|
250
|
-
* @param {string} params.groupId - The owning group
|
|
251
|
-
* @param {VersionSelector} [params.version] - Version to return; defaults to published, else draft
|
|
252
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
253
|
-
* @returns {Promise<SdkResponse<TemplateDetail>>} A promise that resolves to { head, version }
|
|
254
|
-
*/
|
|
255
|
-
async get({ templateId, groupId, version, options = {} }) {
|
|
256
|
-
this.client._require({ templateId, groupId });
|
|
257
|
-
const safeId = encodeURIComponent(templateId);
|
|
258
|
-
const queryString = this.client._getQueryString({ groupId, version });
|
|
259
|
-
return this.client(`/template/${safeId}${queryString}`, { method: "GET", ...options });
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Update a template's name, tag or draft body; editing the body of a published template opens a new draft
|
|
264
|
-
* @async
|
|
265
|
-
* @roles api, admin, developer
|
|
266
|
-
* @param {Object} params - The parameters for updating a template
|
|
267
|
-
* @param {string} params.templateId - The template ID
|
|
268
|
-
* @param {string} params.groupId - The owning group
|
|
269
|
-
* @param {string} [params.name] - New name
|
|
270
|
-
* @param {string|null} [params.tag] - New tag; null clears it, omitted leaves it unchanged
|
|
271
|
-
* @param {RcsTemplateBody} [params.body] - Full replacement body
|
|
272
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
273
|
-
* @returns {Promise<SdkResponse<TemplateDetail>>} A promise that resolves to { head, version }
|
|
274
|
-
*/
|
|
275
|
-
async update({ templateId, groupId, name, tag, body, options = {} }) {
|
|
276
|
-
this.client._require({ templateId, groupId });
|
|
277
|
-
const safeId = encodeURIComponent(templateId);
|
|
278
|
-
return this.client(`/template/${safeId}`, {
|
|
279
|
-
method: "PUT",
|
|
280
|
-
body: templateUpdateBody({ groupId, name, tag, body }),
|
|
281
|
-
...options,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* 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
|
|
287
|
-
* @async
|
|
288
|
-
* @roles api, admin, developer
|
|
289
|
-
* @param {Object} params - The parameters for publishing a template
|
|
290
|
-
* @param {string} params.templateId - The template ID
|
|
291
|
-
* @param {string} params.groupId - The owning group
|
|
292
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
293
|
-
* @returns {Promise<SdkResponse<TemplateDetail>>} A promise that resolves to { head, version } for the published version
|
|
294
|
-
*/
|
|
295
|
-
async publish({ templateId, groupId, options = {} }) {
|
|
296
|
-
this.client._require({ templateId, groupId });
|
|
297
|
-
const safeId = encodeURIComponent(templateId);
|
|
298
|
-
return this.client(`/template/${safeId}/publish`, {
|
|
299
|
-
method: "POST",
|
|
300
|
-
body: { groupId },
|
|
301
|
-
...options,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Archive a template
|
|
307
|
-
* @async
|
|
308
|
-
* @roles api, admin, developer
|
|
309
|
-
* @param {Object} params - The parameters for archiving a template
|
|
310
|
-
* @param {string} params.templateId - The template ID
|
|
311
|
-
* @param {string} params.groupId - The owning group
|
|
312
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
313
|
-
* @returns {Promise<SdkResponse<TemplateHead>>} A promise that resolves to the archived template head
|
|
314
|
-
*/
|
|
315
|
-
async archive({ templateId, groupId, options = {} }) {
|
|
316
|
-
this.client._require({ templateId, groupId });
|
|
317
|
-
const safeId = encodeURIComponent(templateId);
|
|
318
|
-
return this.client(`/template/${safeId}/archive`, {
|
|
319
|
-
method: "POST",
|
|
320
|
-
body: { groupId },
|
|
321
|
-
...options,
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* List a template's versions without their bodies
|
|
327
|
-
* @async
|
|
328
|
-
* @roles api, admin, developer, billing, user
|
|
329
|
-
* @param {Object} params - The parameters for listing versions
|
|
330
|
-
* @param {string} params.templateId - The template ID
|
|
331
|
-
* @param {string} params.groupId - The owning group
|
|
332
|
-
* @param {number} [params.page] - Page number (default 1)
|
|
333
|
-
* @param {number} [params.limit] - Versions per page (default 25, max 100)
|
|
334
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
335
|
-
* @returns {Promise<SdkResponse<Page<VersionSummary>>>} A promise that resolves to { data, total, page, limit }
|
|
336
|
-
*/
|
|
337
|
-
async versions({ templateId, groupId, page, limit, options = {} }) {
|
|
338
|
-
this.client._require({ templateId, groupId });
|
|
339
|
-
const safeId = encodeURIComponent(templateId);
|
|
340
|
-
const queryString = this.client._getQueryString({ groupId, page, limit });
|
|
341
|
-
return this.client(`/template/${safeId}/versions${queryString}`, { method: "GET", ...options });
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Validate an unsaved body or a stored version without writing anything
|
|
346
|
-
* @async
|
|
347
|
-
* @roles api, admin, developer, billing, user
|
|
348
|
-
* @param {Object} params - The parameters for validation; pass exactly one of body or version
|
|
349
|
-
* @param {string} params.templateId - The template ID
|
|
350
|
-
* @param {string} params.groupId - The owning group
|
|
351
|
-
* @param {RcsTemplateBody} [params.body] - An unsaved body to validate
|
|
352
|
-
* @param {VersionSelector} [params.version] - A stored version to validate
|
|
353
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
354
|
-
* @throws {Error} Throws a SignalHouseValidationError unless exactly one of body or version is given
|
|
355
|
-
* @returns {Promise<SdkResponse<ValidationResult>>} A promise that resolves to { valid, contentHash, validatorVersion, errors, warnings }
|
|
356
|
-
*/
|
|
357
|
-
async validate({ templateId, groupId, body, version, options = {} }) {
|
|
358
|
-
this.client._require({ templateId, groupId });
|
|
359
|
-
const safeId = encodeURIComponent(templateId);
|
|
360
|
-
return this.client(`/template/${safeId}/validate`, {
|
|
361
|
-
method: "POST",
|
|
362
|
-
body: templateValidateBody({ groupId, body, version }),
|
|
363
|
-
...options,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Get a channel's template capabilities: allowed blocks, actions, limits and upload constraints
|
|
369
|
-
* @async
|
|
370
|
-
* @roles api, admin, developer, billing, user
|
|
371
|
-
* @param {Object} params - The parameters for getting capabilities
|
|
372
|
-
* @param {string} params.groupId - The owning group
|
|
373
|
-
* @param {"rcs"} [params.channel] - The channel (default "rcs")
|
|
374
|
-
* @param {("infobip"|"sinch")} [params.provider] - Include this provider's limits and unsupported features
|
|
375
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
376
|
-
* @returns {Promise<SdkResponse<Capabilities>>} A promise that resolves to the capabilities
|
|
377
|
-
*/
|
|
378
|
-
async capabilities({ groupId, channel, provider, options = {} }) {
|
|
379
|
-
this.client._require({ groupId });
|
|
380
|
-
const queryString = this.client._getQueryString({ groupId, channel, provider });
|
|
381
|
-
return this.client(`/template/capabilities${queryString}`, { method: "GET", ...options });
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Upload a media file for use in template bodies; returns its public URL. 503 when media storage is not configured
|
|
386
|
-
* @async
|
|
387
|
-
* @roles api, admin, developer
|
|
388
|
-
* @param {Object} params - The parameters for the upload
|
|
389
|
-
* @param {string} params.groupId - The owning group
|
|
390
|
-
* @param {Blob|File} params.file - The file to upload
|
|
391
|
-
* @param {string} [params.fileName] - File name to send with the file
|
|
392
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
393
|
-
* @returns {Promise<SdkResponse<MediaAsset>>} A promise that resolves to the stored media asset (201)
|
|
394
|
-
*/
|
|
395
|
-
async uploadMedia({ groupId, file, fileName, options = {} }) {
|
|
396
|
-
this.client._require({ groupId, file });
|
|
397
|
-
return this.multipartClient(`/template/media`, {
|
|
398
|
-
method: "POST",
|
|
399
|
-
body: templateMediaForm({ groupId, file, fileName }),
|
|
400
|
-
...options,
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
}
|
package/src/domains/Tickets.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
|
|
2
|
-
/**
|
|
3
|
-
* @template T
|
|
4
|
-
* @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export class Tickets {
|
|
8
|
-
constructor(client, enableAdmin) {
|
|
9
|
-
this.client = client;
|
|
10
|
-
this.enableAdmin = enableAdmin;
|
|
11
|
-
|
|
12
|
-
// Hidden Admin namespace INSIDE the domain (staff-only customer ticket → Jira)
|
|
13
|
-
if (enableAdmin) {
|
|
14
|
-
this.admin = {
|
|
15
|
-
/**
|
|
16
|
-
* Load Jira form metadata (issue types, priorities, active sprint, field IDs). Staff-only.
|
|
17
|
-
* @async
|
|
18
|
-
* @roles signalhouse
|
|
19
|
-
* @param {Object} [params] - Optional parameters
|
|
20
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
21
|
-
* @returns {Promise<SdkResponse<any>>} - Jira form metadata
|
|
22
|
-
*/
|
|
23
|
-
getJiraMetadata: async ({ options = {} } = {}) => {
|
|
24
|
-
return this.client(`/admin/ticket/jira/metadata`, { method: "GET", ...options });
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Search open SHGHL epics for the parent picker. Staff-only.
|
|
29
|
-
* @async
|
|
30
|
-
* @roles signalhouse
|
|
31
|
-
* @param {Object} [params]
|
|
32
|
-
* @param {string} [params.query] - Optional epic summary/key filter
|
|
33
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
34
|
-
* @returns {Promise<SdkResponse<any>>} - `{ epics: Array<{ id, key, summary }> }`
|
|
35
|
-
*/
|
|
36
|
-
searchJiraEpics: async ({ query, options = {} } = {}) => {
|
|
37
|
-
const queryString = this.client._getQueryString({ query });
|
|
38
|
-
return this.client(`/admin/ticket/jira/epics${queryString}`, { method: "GET", ...options });
|
|
39
|
-
},
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Search open non-Epic, non-Subtask issues for the Subtask parent picker. Staff-only.
|
|
43
|
-
* @async
|
|
44
|
-
* @roles signalhouse
|
|
45
|
-
* @param {Object} [params]
|
|
46
|
-
* @param {string} [params.query] - Optional issue summary/key filter
|
|
47
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
48
|
-
* @returns {Promise<SdkResponse<any>>} - `{ issues: Array<{ id, key, summary }> }`
|
|
49
|
-
*/
|
|
50
|
-
searchJiraParentIssues: async ({ query, options = {} } = {}) => {
|
|
51
|
-
const queryString = this.client._getQueryString({ query });
|
|
52
|
-
return this.client(`/admin/ticket/jira/parent-issues${queryString}`, { method: "GET", ...options });
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Search assignable Jira users for the assignee picker. Staff-only.
|
|
57
|
-
* @async
|
|
58
|
-
* @roles signalhouse
|
|
59
|
-
* @param {Object} [params]
|
|
60
|
-
* @param {string} [params.query] - Partial name or email
|
|
61
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
62
|
-
* @returns {Promise<SdkResponse<any>>} - `{ users: Array<{ accountId, displayName, emailAddress }> }`
|
|
63
|
-
*/
|
|
64
|
-
searchJiraAssignees: async ({ query, options = {} } = {}) => {
|
|
65
|
-
const queryString = this.client._getQueryString({ query });
|
|
66
|
-
return this.client(`/admin/ticket/jira/assignees${queryString}`, { method: "GET", ...options });
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Suggest Jira labels matching a query. Staff-only.
|
|
71
|
-
* @async
|
|
72
|
-
* @roles signalhouse
|
|
73
|
-
* @param {Object} [params]
|
|
74
|
-
* @param {string} [params.query] - Partial label text
|
|
75
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
76
|
-
* @returns {Promise<SdkResponse<any>>} - `{ labels: string[] }`
|
|
77
|
-
*/
|
|
78
|
-
searchJiraLabels: async ({ query, options = {} } = {}) => {
|
|
79
|
-
const queryString = this.client._getQueryString({ query });
|
|
80
|
-
return this.client(`/admin/ticket/jira/labels${queryString}`, { method: "GET", ...options });
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Create a Jira ticket from the admin customer ticket form. Staff-only.
|
|
85
|
-
* @async
|
|
86
|
-
* @roles signalhouse
|
|
87
|
-
* @param {Object} params
|
|
88
|
-
* @param {Object} params.data - Create payload (groupId, issueTypeId, priorityId, summary required)
|
|
89
|
-
* @param {RequestOptions} [params.options] - Additional options for the request
|
|
90
|
-
* @throws {Error} Throws an error if the data parameter is missing
|
|
91
|
-
* @returns {Promise<SdkResponse<any>>} - Created ticket summary (key, browseUrl, reporter, etc.)
|
|
92
|
-
*/
|
|
93
|
-
createJiraTicket: async ({ data, options = {} }) => {
|
|
94
|
-
this.client._require({ data });
|
|
95
|
-
return this.client(`/admin/ticket/jira`, { method: "POST", body: data, ...options });
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|