@medalsocial/sdk 1.5.0 → 1.6.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 +145 -1
- package/dist/openapi/medal-social.openapi.json +725 -5
- package/dist/src/index.d.mts +788 -240
- package/dist/src/index.d.ts +788 -240
- package/dist/src/index.js +310 -26
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +305 -26
- package/dist/src/index.mjs.map +1 -1
- package/dist/src/openapi.generated.d.mts +321 -7
- package/dist/src/openapi.generated.d.ts +321 -7
- package/dist/src/openapi.generated.js.map +1 -1
- package/openapi/medal-social.openapi.yaml +428 -5
- package/package.json +1 -1
- package/skills/resources/SKILL.md +3 -2
package/dist/src/index.d.ts
CHANGED
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
export { components as OpenApiComponents, operations as OpenApiOperations, paths as OpenApiPaths } from './openapi.generated.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
token: string;
|
|
7
|
-
workspaceId?: string;
|
|
8
|
-
timeout: number;
|
|
9
|
-
userAgent: string;
|
|
3
|
+
/** Successful API response wrapper */
|
|
4
|
+
interface ApiResponse<T> {
|
|
5
|
+
data: T;
|
|
10
6
|
}
|
|
11
|
-
/**
|
|
12
|
-
interface
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
idempotencyKey?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Capability confirmation token sent as the `X-Capability-Confirmation`
|
|
22
|
-
* header. Required alongside `idempotencyKey` when a token granted a
|
|
23
|
-
* capability-style scope directly (e.g. `helpdesk.webhook.manage`) executes
|
|
24
|
-
* a confirmable write route. Obtain one from
|
|
25
|
-
* `POST /api/v1/capability-confirmations`. API keys with legacy scopes do
|
|
26
|
-
* not need it.
|
|
27
|
-
*/
|
|
28
|
-
capabilityConfirmation?: string;
|
|
7
|
+
/** Paginated API response */
|
|
8
|
+
interface PaginatedResponse<T> {
|
|
9
|
+
data: T[];
|
|
10
|
+
pagination: {
|
|
11
|
+
has_more: boolean;
|
|
12
|
+
next_cursor: string | null;
|
|
13
|
+
};
|
|
29
14
|
}
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
42
|
-
/** Execute an authenticated PATCH request with a JSON body. */
|
|
43
|
-
patch<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
44
|
-
/** Execute an authenticated DELETE request. */
|
|
45
|
-
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
46
|
-
private writeHeaders;
|
|
47
|
-
private buildUrl;
|
|
48
|
-
private request;
|
|
15
|
+
/** API error thrown by the client */
|
|
16
|
+
declare class MedalApiError extends Error {
|
|
17
|
+
readonly status: number;
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly details?: unknown;
|
|
20
|
+
constructor(status: number, code: string, message: string, details?: unknown);
|
|
21
|
+
}
|
|
22
|
+
/** Pagination options for list endpoints */
|
|
23
|
+
interface PaginationOptions {
|
|
24
|
+
limit?: number;
|
|
25
|
+
cursor?: string;
|
|
49
26
|
}
|
|
50
27
|
|
|
51
28
|
/** Lifecycle status of a hosted connect link. */
|
|
@@ -91,8 +68,8 @@ interface ConnectLink {
|
|
|
91
68
|
/** Unix timestamp in milliseconds. */
|
|
92
69
|
created_at: number;
|
|
93
70
|
}
|
|
94
|
-
/** Filters for listing connect links. */
|
|
95
|
-
interface ListConnectLinksOptions {
|
|
71
|
+
/** Filters and cursor pagination for listing connect links. */
|
|
72
|
+
interface ListConnectLinksOptions extends PaginationOptions {
|
|
96
73
|
channel_type?: string;
|
|
97
74
|
status?: ConnectLinkStatus;
|
|
98
75
|
}
|
|
@@ -120,35 +97,564 @@ interface ChannelConnectionDisconnectResult {
|
|
|
120
97
|
state: "disconnected";
|
|
121
98
|
}
|
|
122
99
|
|
|
123
|
-
/**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
100
|
+
/** Lifecycle status of a helpdesk conversation. */
|
|
101
|
+
type ConversationStatus = "open" | "snoozed" | "closed";
|
|
102
|
+
/** Who authored a helpdesk message. */
|
|
103
|
+
type MessageAuthorType = "visitor" | "operator" | "ai" | "system";
|
|
104
|
+
/** Kind of helpdesk message. `note` is operator-internal and never delivered to the customer. */
|
|
105
|
+
type HelpdeskMessageType = "chat" | "email" | "note";
|
|
106
|
+
/** A helpdesk conversation across any connected channel (widget, email, social DMs, …). */
|
|
107
|
+
interface Conversation {
|
|
108
|
+
id: string;
|
|
109
|
+
/** Channel type, e.g. 'widget', 'instagram', 'messenger', 'whatsapp', 'email'. */
|
|
110
|
+
channel: string;
|
|
111
|
+
channel_connection_id: string | null;
|
|
112
|
+
status: ConversationStatus;
|
|
113
|
+
subject: string | null;
|
|
114
|
+
assignee_user_id: string | null;
|
|
115
|
+
contact_id: string | null;
|
|
116
|
+
visitor_name: string | null;
|
|
117
|
+
visitor_email: string | null;
|
|
118
|
+
external_conversation_id: string | null;
|
|
119
|
+
channel_account_id: string | null;
|
|
120
|
+
message_count: number;
|
|
121
|
+
unread_for_operator: number;
|
|
122
|
+
/** Unix timestamp in milliseconds. */
|
|
123
|
+
last_message_at: number;
|
|
124
|
+
last_message_preview: string | null;
|
|
125
|
+
last_message_author_type: MessageAuthorType | null;
|
|
126
|
+
/** Unix timestamp in milliseconds. */
|
|
127
|
+
created_at: number;
|
|
128
|
+
/** Unix timestamp in milliseconds. */
|
|
129
|
+
updated_at: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Outbound delivery state of a helpdesk message.
|
|
133
|
+
*
|
|
134
|
+
* - `pending` — queued for the channel, not handed off yet.
|
|
135
|
+
* - `sent` — handed to the channel provider, no confirmation yet.
|
|
136
|
+
* - `delivered` — the channel confirmed delivery to the customer.
|
|
137
|
+
* - `failed` — delivery failed; see `delivery_error` on the message.
|
|
138
|
+
*/
|
|
139
|
+
type MessageDeliveryStatus = "pending" | "sent" | "delivered" | "failed";
|
|
140
|
+
/** A single message inside a helpdesk conversation. */
|
|
141
|
+
interface ConversationMessage {
|
|
142
|
+
id: string;
|
|
143
|
+
conversation_id: string;
|
|
144
|
+
author_type: MessageAuthorType;
|
|
145
|
+
message_type: HelpdeskMessageType;
|
|
146
|
+
author_user_id: string | null;
|
|
147
|
+
author_name: string | null;
|
|
148
|
+
body: string;
|
|
149
|
+
/**
|
|
150
|
+
* Outbound delivery state, or `null` for inbound messages and internal
|
|
151
|
+
* notes — neither is ever sent to a channel, so neither has delivery state.
|
|
152
|
+
*
|
|
153
|
+
* **A `201` from `helpdesk.replies.create` means the reply was ACCEPTED, not
|
|
154
|
+
* delivered.** The channel hand-off happens asynchronously afterwards: poll
|
|
155
|
+
* this field (or subscribe to the `helpdesk.message_delivery_updated`
|
|
156
|
+
* webhook event, which carries the same values) to learn whether the message
|
|
157
|
+
* actually reached the customer.
|
|
158
|
+
*/
|
|
159
|
+
delivery_status: MessageDeliveryStatus | null;
|
|
160
|
+
/**
|
|
161
|
+
* Last send error for a `failed` outbound message, or `null` when there is
|
|
162
|
+
* no error to report (including on inbound messages and internal notes).
|
|
163
|
+
*/
|
|
164
|
+
delivery_error: string | null;
|
|
165
|
+
/** Unix timestamp in milliseconds. */
|
|
166
|
+
created_at: number;
|
|
167
|
+
}
|
|
168
|
+
/** Filters for listing/searching helpdesk conversations. */
|
|
169
|
+
interface ListConversationsOptions extends PaginationOptions {
|
|
170
|
+
status?: ConversationStatus;
|
|
171
|
+
/** Only conversations assigned to this user. */
|
|
172
|
+
assignee_user_id?: string;
|
|
173
|
+
/** Match against visitor name/email. */
|
|
174
|
+
requester?: string;
|
|
175
|
+
/** Free-text search query. */
|
|
176
|
+
query?: string;
|
|
177
|
+
/** Only conversations on these channels (serialized as CSV). */
|
|
178
|
+
channels?: string[];
|
|
179
|
+
}
|
|
180
|
+
/** Input for updating a conversation's status and/or assignee. At least one field is required. */
|
|
181
|
+
interface UpdateConversationInput {
|
|
182
|
+
status?: ConversationStatus;
|
|
183
|
+
/** User ID to assign, or `null` to unassign. */
|
|
184
|
+
assignee_user_id?: string | null;
|
|
185
|
+
}
|
|
186
|
+
/** Result of a conversation update. */
|
|
187
|
+
interface ConversationUpdateResult {
|
|
188
|
+
id: string;
|
|
189
|
+
status: ConversationStatus;
|
|
190
|
+
assignee_user_id: string | null;
|
|
191
|
+
}
|
|
192
|
+
/** Input for sending an operator reply (or internal note) into a conversation. */
|
|
193
|
+
interface CreateReplyInput {
|
|
194
|
+
conversation_id: string;
|
|
195
|
+
/** Message body (max 20,000 characters). */
|
|
196
|
+
body: string;
|
|
197
|
+
/** `note` = operator-internal note (not delivered to the customer). Default `chat`. */
|
|
198
|
+
message_type?: "chat" | "note";
|
|
199
|
+
/** Agent display name for bridged replies (shown in widget + inbox). */
|
|
200
|
+
author_name?: string;
|
|
201
|
+
}
|
|
202
|
+
/** Result returned after creating a reply (HTTP 201). */
|
|
203
|
+
interface ReplyCreateResult {
|
|
204
|
+
id: string;
|
|
205
|
+
conversation_id: string;
|
|
206
|
+
status: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** A webhook endpoint registered in the workspace. */
|
|
210
|
+
interface WebhookEndpoint {
|
|
211
|
+
id: string;
|
|
212
|
+
name: string;
|
|
213
|
+
/** Destination URL (must be https). */
|
|
214
|
+
url: string;
|
|
215
|
+
enabled: boolean;
|
|
216
|
+
/** Subscribed event types. Empty array = all events. */
|
|
217
|
+
event_types: string[];
|
|
218
|
+
/** Channel-type filter (e.g. ['widget', 'whatsapp']), or `null` for all channels. */
|
|
219
|
+
channels: string[] | null;
|
|
220
|
+
/** Channel-connection filter, or `null` for all connections. */
|
|
221
|
+
channel_connection_ids: string[] | null;
|
|
222
|
+
/** Last 4 characters of the signing secret, for identification. */
|
|
223
|
+
secret_last4: string;
|
|
224
|
+
consecutive_failures: number;
|
|
225
|
+
/** Unix timestamps in milliseconds, or `null` if never. */
|
|
226
|
+
last_delivery_at: number | null;
|
|
227
|
+
last_success_at: number | null;
|
|
228
|
+
last_error_at: number | null;
|
|
229
|
+
last_error: string | null;
|
|
230
|
+
created_at: number;
|
|
231
|
+
updated_at: number;
|
|
232
|
+
/**
|
|
233
|
+
* Full signing secret (`whsec_…`) — present ONLY in the `create` response.
|
|
234
|
+
* It is returned exactly once and can never be retrieved again. Store it
|
|
235
|
+
* securely immediately; you need it to verify delivery signatures.
|
|
236
|
+
*/
|
|
237
|
+
secret?: string;
|
|
238
|
+
}
|
|
239
|
+
/** Input for creating a webhook endpoint. */
|
|
240
|
+
interface CreateWebhookInput {
|
|
241
|
+
/** Display name (max 100 characters). */
|
|
242
|
+
name: string;
|
|
243
|
+
/** Destination URL — must be https. */
|
|
244
|
+
url: string;
|
|
245
|
+
/** Event types to subscribe to (e.g. 'helpdesk.message_received'). Empty = all. */
|
|
246
|
+
event_types: string[];
|
|
247
|
+
/** Restrict to these channel types (e.g. ['widget', 'whatsapp']). */
|
|
248
|
+
channels?: string[];
|
|
249
|
+
/** Restrict to these channel connection IDs. */
|
|
250
|
+
channel_connection_ids?: string[];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Input for updating a webhook endpoint. Only provided fields change.
|
|
254
|
+
* Pass `null` for `channels` or `channel_connection_ids` to CLEAR an existing
|
|
255
|
+
* filter (deliver for all channels / all accounts again); omitting the field
|
|
256
|
+
* leaves the current filter unchanged.
|
|
257
|
+
*/
|
|
258
|
+
interface UpdateWebhookInput {
|
|
259
|
+
name?: string;
|
|
260
|
+
url?: string;
|
|
261
|
+
event_types?: string[];
|
|
262
|
+
channels?: string[] | null;
|
|
263
|
+
channel_connection_ids?: string[] | null;
|
|
264
|
+
enabled?: boolean;
|
|
265
|
+
}
|
|
266
|
+
/** Result of deleting a webhook endpoint. */
|
|
267
|
+
interface WebhookDeleteResult {
|
|
268
|
+
id: string;
|
|
269
|
+
status: string;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* A delivery attempt record for a webhook endpoint.
|
|
273
|
+
*
|
|
274
|
+
* `id` is the same value sent as the `X-Medal-Delivery-Id` and
|
|
275
|
+
* `Idempotency-Key` headers on the outbound request, so you can join your own
|
|
276
|
+
* receiving log to this listing exactly.
|
|
277
|
+
*
|
|
278
|
+
* **Deliveries never carry payload bodies.** The event payload can contain
|
|
279
|
+
* customer PII, so it is not returned here — use the correlation fields below
|
|
280
|
+
* to look the subject up through the regular API instead.
|
|
281
|
+
*
|
|
282
|
+
* All correlation fields (`resource_id`, `conversation_id`, `message_id`,
|
|
283
|
+
* `connection_ref`, `channel`, `channel_connection_id`) are derived from the
|
|
284
|
+
* stored event and **fail closed to `null`** whenever no canonical event
|
|
285
|
+
* exists for the delivery — e.g. `test.ping` deliveries, or events that have
|
|
286
|
+
* aged out of retention. Always null-check before using them.
|
|
287
|
+
*/
|
|
288
|
+
interface WebhookDelivery {
|
|
289
|
+
id: string;
|
|
290
|
+
event_type: string;
|
|
291
|
+
/**
|
|
292
|
+
* Primary subject id of the announced event (a message id for message
|
|
293
|
+
* events, a connection id for channel lifecycle events, …), or `null`.
|
|
294
|
+
*/
|
|
295
|
+
resource_id: string | null;
|
|
296
|
+
/** Helpdesk conversation the event belongs to, or `null`. */
|
|
297
|
+
conversation_id: string | null;
|
|
298
|
+
/** Helpdesk message the event belongs to, or `null`. */
|
|
299
|
+
message_id: string | null;
|
|
300
|
+
/** Opaque connection reference carried by the event, or `null`. */
|
|
301
|
+
connection_ref: string | null;
|
|
302
|
+
/** Channel type (e.g. `telegram_inbox`, `widget`), or `null`. */
|
|
303
|
+
channel: string | null;
|
|
304
|
+
/** Channel connection the event belongs to, or `null`. */
|
|
305
|
+
channel_connection_id: string | null;
|
|
306
|
+
status: "pending" | "delivered" | "dead_letter";
|
|
307
|
+
attempt_count: number;
|
|
308
|
+
/** Unix timestamp in milliseconds of the next retry, or `null`. */
|
|
309
|
+
next_attempt_at: number | null;
|
|
310
|
+
response_status: number | null;
|
|
311
|
+
duration_ms: number | null;
|
|
312
|
+
last_error: string | null;
|
|
313
|
+
/** Unix timestamp in milliseconds, or `null` if not delivered. */
|
|
314
|
+
delivered_at: number | null;
|
|
315
|
+
created_at: number;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Options for listing recent deliveries.
|
|
319
|
+
*
|
|
320
|
+
* This endpoint is **not** cursor-paginated — it returns the most recent
|
|
321
|
+
* deliveries only, capped by `limit`. There is no `cursor` parameter; to keep
|
|
322
|
+
* a durable record, ingest deliveries as they arrive (or poll and de-duplicate
|
|
323
|
+
* on the delivery `id`).
|
|
324
|
+
*/
|
|
325
|
+
interface ListDeliveriesOptions {
|
|
326
|
+
limit?: number;
|
|
327
|
+
}
|
|
328
|
+
/** Result returned after queuing a test delivery (HTTP 202). */
|
|
329
|
+
interface WebhookTestResult {
|
|
330
|
+
delivery_id: string;
|
|
331
|
+
status: string;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Capability confirmation types.
|
|
336
|
+
*
|
|
337
|
+
* Medal's confirmable write routes require BOTH an `Idempotency-Key` and an
|
|
338
|
+
* `X-Capability-Confirmation` token whenever the calling credential holds the
|
|
339
|
+
* capability scope *directly* — which is the case for every correctly-scoped
|
|
340
|
+
* partner key and OAuth grant. (API keys carrying only legacy scopes are
|
|
341
|
+
* exempt.) The token is minted by `POST /api/v1/capability-confirmations` and
|
|
342
|
+
* is bound to the workspace, the auth subject, the HTTP method + path, the
|
|
343
|
+
* capability's required scopes, and the idempotency key.
|
|
344
|
+
*/
|
|
345
|
+
/**
|
|
346
|
+
* Confirmable capability ids backing the write routes this SDK exposes.
|
|
347
|
+
*
|
|
348
|
+
* Mirrors the server-side capability registry. Each id maps to exactly one
|
|
349
|
+
* method + path template — see {@link CAPABILITY_ROUTES}.
|
|
350
|
+
*/
|
|
351
|
+
declare const CAPABILITY_IDS: readonly ["channel.connect_link.create.execute", "channel.connect_link.revoke.execute", "channel.connection.disconnect.execute", "helpdesk.conversation.reply.execute", "helpdesk.conversation.update.execute", "helpdesk.webhook.create.execute", "helpdesk.webhook.update.execute", "helpdesk.webhook.delete.execute"];
|
|
352
|
+
/** A confirmable capability id backing an SDK write route. */
|
|
353
|
+
type CapabilityId = (typeof CAPABILITY_IDS)[number];
|
|
354
|
+
/** The API route a capability confirms, as registered server-side. */
|
|
355
|
+
interface CapabilityRoute {
|
|
356
|
+
method: "POST" | "PATCH" | "DELETE";
|
|
357
|
+
/** Path template; `{id}` is filled from `path_params.id`. */
|
|
358
|
+
path_template: string;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Method + path template for each confirmable capability.
|
|
362
|
+
*
|
|
363
|
+
* The server resolves the same mapping from its capability registry — this
|
|
364
|
+
* copy exists so the SDK can build human-readable previews and supply
|
|
365
|
+
* `path_params` without a round trip.
|
|
366
|
+
*/
|
|
367
|
+
declare const CAPABILITY_ROUTES: Record<CapabilityId, CapabilityRoute>;
|
|
368
|
+
/** Primitive accepted as a capability path parameter value. */
|
|
369
|
+
type CapabilityPathParamValue = string | number | boolean;
|
|
370
|
+
/** Input for `POST /api/v1/capability-confirmations`. */
|
|
371
|
+
interface IssueCapabilityConfirmationInput {
|
|
372
|
+
/**
|
|
373
|
+
* Capability to confirm. Unknown ids are rejected with
|
|
374
|
+
* `CAPABILITY_NOT_FOUND`; read-only or non-confirmable capabilities with
|
|
375
|
+
* `CAPABILITY_NOT_CONFIRMABLE`.
|
|
376
|
+
*/
|
|
377
|
+
capability_id: CapabilityId | (string & {});
|
|
378
|
+
/**
|
|
379
|
+
* Concrete `/api/v1/...` path the token should be bound to. Optional when
|
|
380
|
+
* the capability has exactly one API target (all capabilities in
|
|
381
|
+
* {@link CAPABILITY_ROUTES} do); required when it has several. Must match a
|
|
382
|
+
* path built from the capability's own templates.
|
|
383
|
+
*/
|
|
384
|
+
api_path?: string;
|
|
385
|
+
/** Values for the capability path template's parameters, e.g. `{ id: 'wh_1' }`. */
|
|
386
|
+
path_params?: Record<string, CapabilityPathParamValue>;
|
|
387
|
+
/**
|
|
388
|
+
* The exact `Idempotency-Key` you will send on the confirmed write. The
|
|
389
|
+
* token is bound to it — a mismatch is rejected. Required for every
|
|
390
|
+
* capability in {@link CAPABILITY_ROUTES}.
|
|
391
|
+
*/
|
|
392
|
+
idempotency_key?: string;
|
|
393
|
+
/**
|
|
394
|
+
* Human-readable description of the action being approved (1–4000 chars).
|
|
395
|
+
* This is the text your user saw and approved, and it is retained for audit.
|
|
396
|
+
*/
|
|
397
|
+
preview_summary: string;
|
|
398
|
+
/**
|
|
399
|
+
* Must be `true`.
|
|
400
|
+
*
|
|
401
|
+
* **This asserts that a human on your side approved this specific action.**
|
|
402
|
+
* Do not send it to rubber-stamp unattended writes — it is the audit record
|
|
403
|
+
* that a person, not a script, authorised the change.
|
|
404
|
+
*/
|
|
405
|
+
user_approved: true;
|
|
406
|
+
}
|
|
407
|
+
/** A minted capability confirmation token. */
|
|
408
|
+
interface CapabilityConfirmation {
|
|
409
|
+
/** Send this as the `X-Capability-Confirmation` header on the write. */
|
|
410
|
+
confirmation_token: string;
|
|
411
|
+
token_type: "medal_capability_confirmation";
|
|
412
|
+
capability_id: string;
|
|
413
|
+
/** HTTP method the token is bound to. */
|
|
414
|
+
method: string;
|
|
415
|
+
/** Concrete API path the token is bound to. */
|
|
416
|
+
path: string;
|
|
417
|
+
/** Capability scopes the token was minted against. */
|
|
418
|
+
required_scopes: string[];
|
|
419
|
+
/** Idempotency key the token is bound to, or `null` if it was minted unbound. */
|
|
420
|
+
idempotency_key: string | null;
|
|
421
|
+
/** Lifetime in seconds (60–900). */
|
|
422
|
+
expires_in: number;
|
|
423
|
+
/** ISO-8601 expiry timestamp. */
|
|
424
|
+
expires_at: string;
|
|
425
|
+
/** Echo of the submitted `preview_summary`. */
|
|
426
|
+
preview_summary: string;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Request body type for each confirmable capability.
|
|
430
|
+
*
|
|
431
|
+
* `undefined` for routes that take no request body (the `DELETE` routes).
|
|
432
|
+
*/
|
|
433
|
+
interface CapabilityWriteBodies {
|
|
434
|
+
"channel.connect_link.create.execute": CreateConnectLinkInput;
|
|
435
|
+
"channel.connect_link.revoke.execute": undefined;
|
|
436
|
+
"channel.connection.disconnect.execute": undefined;
|
|
437
|
+
"helpdesk.conversation.reply.execute": CreateReplyInput;
|
|
438
|
+
"helpdesk.conversation.update.execute": UpdateConversationInput;
|
|
439
|
+
"helpdesk.webhook.create.execute": CreateWebhookInput;
|
|
440
|
+
"helpdesk.webhook.update.execute": UpdateWebhookInput;
|
|
441
|
+
"helpdesk.webhook.delete.execute": undefined;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* A capability paired with the request body for that exact route.
|
|
445
|
+
*
|
|
446
|
+
* Modelled as a discriminated union rather than two independent parameters so
|
|
447
|
+
* the pair cannot be decoupled: passing a `helpdesk.conversation.reply.execute`
|
|
448
|
+
* id alongside a webhook payload is a compile error, even when the id's static
|
|
449
|
+
* type is the full {@link CapabilityId} union.
|
|
450
|
+
*/
|
|
451
|
+
type CapabilityWriteRequest = {
|
|
452
|
+
[K in CapabilityId]: {
|
|
453
|
+
/** Capability about to be confirmed. */
|
|
454
|
+
capabilityId: K;
|
|
455
|
+
/** The request body of the pending write, or `undefined` for `DELETE` routes. */
|
|
456
|
+
body: CapabilityWriteBodies[K];
|
|
457
|
+
};
|
|
458
|
+
}[CapabilityId];
|
|
459
|
+
/** Fields common to every {@link AutoConfirmContext} variant. */
|
|
460
|
+
interface AutoConfirmContextBase {
|
|
461
|
+
/** HTTP method of the write. */
|
|
462
|
+
method: string;
|
|
463
|
+
/** Resolved API path of the write (path params substituted + encoded). */
|
|
464
|
+
path: string;
|
|
465
|
+
/** Path parameters used to resolve `path`, if any. */
|
|
466
|
+
pathParams?: Record<string, CapabilityPathParamValue>;
|
|
467
|
+
/** Idempotency key that will be bound to the token and sent on the write. */
|
|
468
|
+
idempotencyKey: string;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Context handed to an {@link AutoConfirmOptions.previewSummary} callback.
|
|
472
|
+
*
|
|
473
|
+
* A discriminated union on `capabilityId` — narrow on it to get the exact
|
|
474
|
+
* `body` type for that route:
|
|
475
|
+
*
|
|
476
|
+
* ```ts
|
|
477
|
+
* previewSummary: (ctx) => {
|
|
478
|
+
* if (ctx.capabilityId === 'helpdesk.conversation.reply.execute') {
|
|
479
|
+
* // ctx.body is CreateReplyInput here
|
|
480
|
+
* return `Reply to ${ctx.body.conversation_id}: ${ctx.body.body}`;
|
|
481
|
+
* }
|
|
482
|
+
* return `${ctx.method} ${ctx.path}`;
|
|
483
|
+
* }
|
|
484
|
+
* ```
|
|
485
|
+
*
|
|
486
|
+
* `body` is the **exact object you passed to the SDK method**, by reference
|
|
487
|
+
* and unmodified — it is your own payload, so there is nothing to redact and
|
|
488
|
+
* nothing crosses a tenant boundary. Treat it as read-only: mutating it from
|
|
489
|
+
* the callback would change what is actually sent.
|
|
490
|
+
*/
|
|
491
|
+
type AutoConfirmContext = AutoConfirmContextBase & CapabilityWriteRequest;
|
|
492
|
+
/**
|
|
493
|
+
* Opt-in auto-confirmation.
|
|
494
|
+
*
|
|
495
|
+
* When configured, the SDK mints an idempotency key and a confirmation token
|
|
496
|
+
* for you before each confirmable write, then attaches both headers.
|
|
497
|
+
*
|
|
498
|
+
* **This is not a bypass.** Every minted token carries
|
|
499
|
+
* `user_approved: true`, which asserts that *your own user* approved that
|
|
500
|
+
* specific action — the `preview_summary` you return is the audit record of
|
|
501
|
+
* what they approved. Only enable this on a code path where a human really did
|
|
502
|
+
* approve the write. Never wire it into unattended automation.
|
|
503
|
+
*/
|
|
504
|
+
interface AutoConfirmOptions {
|
|
505
|
+
/**
|
|
506
|
+
* Build the `preview_summary` for the pending write. Must return a
|
|
507
|
+
* non-empty string describing what the user approved; returning blank text
|
|
508
|
+
* throws instead of asserting an approval that has no description.
|
|
509
|
+
*
|
|
510
|
+
* The context includes the pending request `body`, so the summary can name
|
|
511
|
+
* the specific action rather than the route — narrow on
|
|
512
|
+
* `context.capabilityId` to get the exact payload type. Prefer a
|
|
513
|
+
* payload-aware summary: `"Reply to conv_1: 'Refund issued'"` is an audit
|
|
514
|
+
* record, `"POST /api/v1/helpdesk/replies"` is not.
|
|
515
|
+
*
|
|
516
|
+
* The server caps `preview_summary` at 4000 characters, so summarise the
|
|
517
|
+
* payload rather than serialising it wholesale.
|
|
518
|
+
*/
|
|
519
|
+
previewSummary: (context: AutoConfirmContext) => string;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/** Configuration for the low-level HTTP client. */
|
|
523
|
+
interface ClientConfig {
|
|
524
|
+
baseUrl: string;
|
|
525
|
+
token: string;
|
|
526
|
+
workspaceId?: string;
|
|
527
|
+
timeout: number;
|
|
528
|
+
userAgent: string;
|
|
529
|
+
}
|
|
530
|
+
/** Per-request options for write operations. */
|
|
531
|
+
interface RequestOptions {
|
|
532
|
+
/**
|
|
533
|
+
* Idempotency key sent as the `Idempotency-Key` header. Retries with the
|
|
534
|
+
* same key return the original result instead of repeating the operation.
|
|
535
|
+
* Required by some endpoints for capability-scoped tokens (e.g. helpdesk
|
|
536
|
+
* replies, webhook creation).
|
|
537
|
+
*/
|
|
538
|
+
idempotencyKey?: string;
|
|
539
|
+
/**
|
|
540
|
+
* Capability confirmation token sent as the `X-Capability-Confirmation`
|
|
541
|
+
* header. Required alongside `idempotencyKey` when a token granted a
|
|
542
|
+
* capability-style scope directly (e.g. `helpdesk.webhook.manage`) executes
|
|
543
|
+
* a confirmable write route. Obtain one from
|
|
544
|
+
* `POST /api/v1/capability-confirmations`. API keys with legacy scopes do
|
|
545
|
+
* not need it.
|
|
546
|
+
*/
|
|
547
|
+
capabilityConfirmation?: string;
|
|
548
|
+
/**
|
|
549
|
+
* Opt in to (or out of) automatic capability confirmation for this call.
|
|
550
|
+
*
|
|
551
|
+
* Supply `{ previewSummary }` to have the SDK mint the idempotency key and
|
|
552
|
+
* the `X-Capability-Confirmation` token itself; pass `false` to suppress a
|
|
553
|
+
* client-level `autoConfirmCapabilities` default. Defaults to the client
|
|
554
|
+
* setting, which itself defaults to OFF.
|
|
555
|
+
*
|
|
556
|
+
* Auto-confirmation sends `user_approved: true` on your behalf, asserting
|
|
557
|
+
* that a human on your side approved this exact action — only use it where
|
|
558
|
+
* that is true.
|
|
559
|
+
*
|
|
560
|
+
* Ignored on routes that do not require a capability confirmation.
|
|
561
|
+
*/
|
|
562
|
+
autoConfirm?: AutoConfirmOptions | false;
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Low-level HTTP client used by all resource classes.
|
|
566
|
+
* Handles authentication, retries, timeout, and error parsing.
|
|
567
|
+
*/
|
|
568
|
+
declare class BaseClient {
|
|
569
|
+
/** Resolved client configuration. */
|
|
570
|
+
readonly config: ClientConfig;
|
|
571
|
+
constructor(config: ClientConfig);
|
|
572
|
+
/** Execute an authenticated GET request and return the parsed JSON body. */
|
|
573
|
+
get<T>(path: string, params?: Record<string, string | undefined>): Promise<T>;
|
|
574
|
+
/** Execute an authenticated POST request with a JSON body. */
|
|
575
|
+
post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
576
|
+
/** Execute an authenticated PATCH request with a JSON body. */
|
|
577
|
+
patch<T>(path: string, body: unknown, options?: RequestOptions): Promise<T>;
|
|
578
|
+
/** Execute an authenticated DELETE request. */
|
|
579
|
+
delete<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
580
|
+
private writeHeaders;
|
|
581
|
+
private buildUrl;
|
|
582
|
+
private request;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Mint short-lived capability confirmation tokens.
|
|
587
|
+
*
|
|
588
|
+
* Medal's confirmable write routes (connect links, channel connections,
|
|
589
|
+
* helpdesk replies/updates, webhook endpoint writes) require BOTH an
|
|
590
|
+
* `Idempotency-Key` and an `X-Capability-Confirmation` header when the calling
|
|
591
|
+
* credential holds the capability scope *directly* — which is the case for
|
|
592
|
+
* every correctly-scoped partner key. This resource issues that header value.
|
|
593
|
+
*
|
|
594
|
+
* @example Explicit flow
|
|
595
|
+
* ```ts
|
|
596
|
+
* const idempotencyKey = crypto.randomUUID();
|
|
597
|
+
* const { data: confirmation } = await medal.capabilityConfirmations.create({
|
|
598
|
+
* capability_id: 'channel.connect_link.create.execute',
|
|
599
|
+
* idempotency_key: idempotencyKey,
|
|
600
|
+
* preview_summary: 'Mint a Telegram connect link for Acme Support',
|
|
601
|
+
* user_approved: true, // a human on your side approved this exact action
|
|
602
|
+
* });
|
|
603
|
+
*
|
|
604
|
+
* await medal.channels.connectLinks.create(
|
|
605
|
+
* { channel_type: 'telegram_inbox', label: 'Acme Support' },
|
|
606
|
+
* { idempotencyKey, capabilityConfirmation: confirmation.confirmation_token },
|
|
607
|
+
* );
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
declare class CapabilityConfirmations {
|
|
611
|
+
private client;
|
|
612
|
+
constructor(client: BaseClient);
|
|
613
|
+
/**
|
|
614
|
+
* Issue a confirmation token for one pending write.
|
|
615
|
+
*
|
|
616
|
+
* The token is bound to the workspace, the auth subject, the capability's
|
|
617
|
+
* method + path, its required scopes, and `idempotency_key` — so it is
|
|
618
|
+
* usable exactly once, for exactly the write it describes, and expires
|
|
619
|
+
* within 15 minutes.
|
|
620
|
+
*
|
|
621
|
+
* Setting `user_approved: true` asserts that a human on your side approved
|
|
622
|
+
* this specific action. `preview_summary` is what they approved, and is
|
|
623
|
+
* retained for audit — write it for a human reader, not a log parser.
|
|
624
|
+
*/
|
|
625
|
+
create(input: IssueCapabilityConfirmationInput): Promise<ApiResponse<CapabilityConfirmation>>;
|
|
141
626
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
627
|
+
|
|
628
|
+
/**
|
|
629
|
+
* Resolves the `Idempotency-Key` + `X-Capability-Confirmation` pair required
|
|
630
|
+
* by confirmable write routes.
|
|
631
|
+
*
|
|
632
|
+
* Auto-confirmation is OFF unless the integrator opts in — either globally via
|
|
633
|
+
* the `Medal` constructor's `autoConfirmCapabilities`, or per call via
|
|
634
|
+
* `{ autoConfirm: { previewSummary } }`. When it is off this is a pass-through:
|
|
635
|
+
* whatever headers the caller supplied are what gets sent.
|
|
636
|
+
*/
|
|
637
|
+
declare class CapabilityConfirmer {
|
|
638
|
+
private confirmations;
|
|
639
|
+
private defaults?;
|
|
640
|
+
constructor(confirmations: CapabilityConfirmations, defaults?: AutoConfirmOptions | undefined);
|
|
641
|
+
/**
|
|
642
|
+
* Return the request options to use for a confirmable write, minting the
|
|
643
|
+
* idempotency key and confirmation token first when auto-confirm is active.
|
|
644
|
+
*
|
|
645
|
+
* `body` is the pending request payload (`undefined` for `DELETE` routes).
|
|
646
|
+
* It is handed to the `previewSummary` callback by reference so the summary
|
|
647
|
+
* can describe the specific action, not just the route — it is the caller's
|
|
648
|
+
* own payload, so it is passed through unmodified and unredacted.
|
|
649
|
+
*/
|
|
650
|
+
prepare(request: CapabilityWriteRequest, pathParams?: Record<string, CapabilityPathParamValue>, options?: RequestOptions): Promise<RequestOptions | undefined>;
|
|
146
651
|
}
|
|
147
652
|
|
|
148
653
|
/** Mint, list, and revoke hosted connect links. */
|
|
149
654
|
declare class ChannelConnectLinks {
|
|
150
655
|
private client;
|
|
151
|
-
|
|
656
|
+
private confirmer;
|
|
657
|
+
constructor(client: BaseClient, confirmer: CapabilityConfirmer);
|
|
152
658
|
/**
|
|
153
659
|
* Mint a single-use hosted connect link. Returns HTTP 201.
|
|
154
660
|
*
|
|
@@ -161,17 +667,37 @@ declare class ChannelConnectLinks {
|
|
|
161
667
|
* need the workspace `admin` role.
|
|
162
668
|
*/
|
|
163
669
|
create(input: CreateConnectLinkInput, options?: RequestOptions): Promise<ApiResponse<ConnectLinkCreateResult>>;
|
|
164
|
-
/**
|
|
165
|
-
|
|
670
|
+
/**
|
|
671
|
+
* List the workspace's connect links (tokens are never returned), newest
|
|
672
|
+
* first, with cursor-based pagination.
|
|
673
|
+
*
|
|
674
|
+
* `limit` defaults to 50 server-side and is capped at 100. Follow
|
|
675
|
+
* `pagination.next_cursor` while `pagination.has_more` is true.
|
|
676
|
+
*
|
|
677
|
+
* The `channel_type` / `status` filters are applied **within** each page,
|
|
678
|
+
* so a page may hold fewer than `limit` items while `has_more` is still
|
|
679
|
+
* true — drive the loop off `has_more`, never off the item count.
|
|
680
|
+
*/
|
|
681
|
+
list(options?: ListConnectLinksOptions): Promise<PaginatedResponse<ConnectLink>>;
|
|
166
682
|
/** Revoke a pending connect link so it can no longer be consumed. */
|
|
167
683
|
revoke(id: string, options?: RequestOptions): Promise<ApiResponse<ConnectLinkRevokeResult>>;
|
|
168
684
|
}
|
|
169
685
|
/** List and disconnect the workspace's channel connections. */
|
|
170
686
|
declare class ChannelConnections {
|
|
171
687
|
private client;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
688
|
+
private confirmer;
|
|
689
|
+
constructor(client: BaseClient, confirmer: CapabilityConfirmer);
|
|
690
|
+
/**
|
|
691
|
+
* List the workspace's channel connections (generic, channel-agnostic
|
|
692
|
+
* shape), newest first, with cursor-based pagination.
|
|
693
|
+
*
|
|
694
|
+
* `limit` defaults to 50 server-side and is capped at 100. Follow
|
|
695
|
+
* `pagination.next_cursor` while `pagination.has_more` is true. Rows that
|
|
696
|
+
* are not projectable as connections are dropped within the page, so a page
|
|
697
|
+
* may hold fewer than `limit` items while `has_more` is still true — drive
|
|
698
|
+
* the loop off `has_more`, never off the item count.
|
|
699
|
+
*/
|
|
700
|
+
list(options?: PaginationOptions): Promise<PaginatedResponse<ChannelConnection>>;
|
|
175
701
|
/**
|
|
176
702
|
* Disconnect a connected channel account (best-effort platform logout, then
|
|
177
703
|
* local revoke). Emits a `helpdesk.channel_disconnected` webhook event with
|
|
@@ -188,7 +714,7 @@ declare class ChannelConnections {
|
|
|
188
714
|
declare class Channels {
|
|
189
715
|
readonly connectLinks: ChannelConnectLinks;
|
|
190
716
|
readonly connections: ChannelConnections;
|
|
191
|
-
constructor(client: BaseClient);
|
|
717
|
+
constructor(client: BaseClient, confirmer?: CapabilityConfirmer);
|
|
192
718
|
}
|
|
193
719
|
|
|
194
720
|
/** A contact in the workspace CRM. */
|
|
@@ -650,94 +1176,11 @@ declare class Gdpr {
|
|
|
650
1176
|
}>;
|
|
651
1177
|
}
|
|
652
1178
|
|
|
653
|
-
/** Lifecycle status of a helpdesk conversation. */
|
|
654
|
-
type ConversationStatus = "open" | "snoozed" | "closed";
|
|
655
|
-
/** Who authored a helpdesk message. */
|
|
656
|
-
type MessageAuthorType = "visitor" | "operator" | "ai" | "system";
|
|
657
|
-
/** Kind of helpdesk message. `note` is operator-internal and never delivered to the customer. */
|
|
658
|
-
type HelpdeskMessageType = "chat" | "email" | "note";
|
|
659
|
-
/** A helpdesk conversation across any connected channel (widget, email, social DMs, …). */
|
|
660
|
-
interface Conversation {
|
|
661
|
-
id: string;
|
|
662
|
-
/** Channel type, e.g. 'widget', 'instagram', 'messenger', 'whatsapp', 'email'. */
|
|
663
|
-
channel: string;
|
|
664
|
-
channel_connection_id: string | null;
|
|
665
|
-
status: ConversationStatus;
|
|
666
|
-
subject: string | null;
|
|
667
|
-
assignee_user_id: string | null;
|
|
668
|
-
contact_id: string | null;
|
|
669
|
-
visitor_name: string | null;
|
|
670
|
-
visitor_email: string | null;
|
|
671
|
-
external_conversation_id: string | null;
|
|
672
|
-
channel_account_id: string | null;
|
|
673
|
-
message_count: number;
|
|
674
|
-
unread_for_operator: number;
|
|
675
|
-
/** Unix timestamp in milliseconds. */
|
|
676
|
-
last_message_at: number;
|
|
677
|
-
last_message_preview: string | null;
|
|
678
|
-
last_message_author_type: MessageAuthorType | null;
|
|
679
|
-
/** Unix timestamp in milliseconds. */
|
|
680
|
-
created_at: number;
|
|
681
|
-
/** Unix timestamp in milliseconds. */
|
|
682
|
-
updated_at: number;
|
|
683
|
-
}
|
|
684
|
-
/** A single message inside a helpdesk conversation. */
|
|
685
|
-
interface ConversationMessage {
|
|
686
|
-
id: string;
|
|
687
|
-
conversation_id: string;
|
|
688
|
-
author_type: MessageAuthorType;
|
|
689
|
-
message_type: HelpdeskMessageType;
|
|
690
|
-
author_user_id: string | null;
|
|
691
|
-
author_name: string | null;
|
|
692
|
-
body: string;
|
|
693
|
-
/** Unix timestamp in milliseconds. */
|
|
694
|
-
created_at: number;
|
|
695
|
-
}
|
|
696
|
-
/** Filters for listing/searching helpdesk conversations. */
|
|
697
|
-
interface ListConversationsOptions extends PaginationOptions {
|
|
698
|
-
status?: ConversationStatus;
|
|
699
|
-
/** Only conversations assigned to this user. */
|
|
700
|
-
assignee_user_id?: string;
|
|
701
|
-
/** Match against visitor name/email. */
|
|
702
|
-
requester?: string;
|
|
703
|
-
/** Free-text search query. */
|
|
704
|
-
query?: string;
|
|
705
|
-
/** Only conversations on these channels (serialized as CSV). */
|
|
706
|
-
channels?: string[];
|
|
707
|
-
}
|
|
708
|
-
/** Input for updating a conversation's status and/or assignee. At least one field is required. */
|
|
709
|
-
interface UpdateConversationInput {
|
|
710
|
-
status?: ConversationStatus;
|
|
711
|
-
/** User ID to assign, or `null` to unassign. */
|
|
712
|
-
assignee_user_id?: string | null;
|
|
713
|
-
}
|
|
714
|
-
/** Result of a conversation update. */
|
|
715
|
-
interface ConversationUpdateResult {
|
|
716
|
-
id: string;
|
|
717
|
-
status: ConversationStatus;
|
|
718
|
-
assignee_user_id: string | null;
|
|
719
|
-
}
|
|
720
|
-
/** Input for sending an operator reply (or internal note) into a conversation. */
|
|
721
|
-
interface CreateReplyInput {
|
|
722
|
-
conversation_id: string;
|
|
723
|
-
/** Message body (max 20,000 characters). */
|
|
724
|
-
body: string;
|
|
725
|
-
/** `note` = operator-internal note (not delivered to the customer). Default `chat`. */
|
|
726
|
-
message_type?: "chat" | "note";
|
|
727
|
-
/** Agent display name for bridged replies (shown in widget + inbox). */
|
|
728
|
-
author_name?: string;
|
|
729
|
-
}
|
|
730
|
-
/** Result returned after creating a reply (HTTP 201). */
|
|
731
|
-
interface ReplyCreateResult {
|
|
732
|
-
id: string;
|
|
733
|
-
conversation_id: string;
|
|
734
|
-
status: string;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
1179
|
/** Browse and manage helpdesk conversations. */
|
|
738
1180
|
declare class HelpdeskConversations {
|
|
739
1181
|
private client;
|
|
740
|
-
|
|
1182
|
+
private confirmer;
|
|
1183
|
+
constructor(client: BaseClient, confirmer: CapabilityConfirmer);
|
|
741
1184
|
/** List/search conversations with cursor-based pagination and optional filters. */
|
|
742
1185
|
list(options?: ListConversationsOptions): Promise<PaginatedResponse<Conversation>>;
|
|
743
1186
|
/** Get a conversation by ID. */
|
|
@@ -750,7 +1193,8 @@ declare class HelpdeskConversations {
|
|
|
750
1193
|
/** Send operator replies (or internal notes) into conversations. */
|
|
751
1194
|
declare class HelpdeskReplies {
|
|
752
1195
|
private client;
|
|
753
|
-
|
|
1196
|
+
private confirmer;
|
|
1197
|
+
constructor(client: BaseClient, confirmer: CapabilityConfirmer);
|
|
754
1198
|
/**
|
|
755
1199
|
* Send an operator reply or internal note. Returns HTTP 201.
|
|
756
1200
|
*
|
|
@@ -763,7 +1207,7 @@ declare class HelpdeskReplies {
|
|
|
763
1207
|
declare class Helpdesk {
|
|
764
1208
|
readonly conversations: HelpdeskConversations;
|
|
765
1209
|
readonly replies: HelpdeskReplies;
|
|
766
|
-
constructor(client: BaseClient);
|
|
1210
|
+
constructor(client: BaseClient, confirmer?: CapabilityConfirmer);
|
|
767
1211
|
}
|
|
768
1212
|
|
|
769
1213
|
/** A post in the workspace (list view). */
|
|
@@ -872,97 +1316,168 @@ declare class Posts {
|
|
|
872
1316
|
channels(): Promise<ApiResponse<Channel[]>>;
|
|
873
1317
|
}
|
|
874
1318
|
|
|
875
|
-
/**
|
|
876
|
-
interface
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
event_types: string[];
|
|
884
|
-
/** Channel-type filter (e.g. ['widget', 'whatsapp']), or `null` for all channels. */
|
|
885
|
-
channels: string[] | null;
|
|
886
|
-
/** Channel-connection filter, or `null` for all connections. */
|
|
887
|
-
channel_connection_ids: string[] | null;
|
|
888
|
-
/** Last 4 characters of the signing secret, for identification. */
|
|
889
|
-
secret_last4: string;
|
|
890
|
-
consecutive_failures: number;
|
|
891
|
-
/** Unix timestamps in milliseconds, or `null` if never. */
|
|
892
|
-
last_delivery_at: number | null;
|
|
893
|
-
last_success_at: number | null;
|
|
894
|
-
last_error_at: number | null;
|
|
895
|
-
last_error: string | null;
|
|
896
|
-
created_at: number;
|
|
897
|
-
updated_at: number;
|
|
898
|
-
/**
|
|
899
|
-
* Full signing secret (`whsec_…`) — present ONLY in the `create` response.
|
|
900
|
-
* It is returned exactly once and can never be retrieved again. Store it
|
|
901
|
-
* securely immediately; you need it to verify delivery signatures.
|
|
902
|
-
*/
|
|
903
|
-
secret?: string;
|
|
1319
|
+
/** Input for creating a scan — provide exactly ONE of `url`, `orgnr`, or `name`. */
|
|
1320
|
+
interface ScanCreateInput {
|
|
1321
|
+
/** Website URL to scan directly (https is assumed when the scheme is missing). */
|
|
1322
|
+
url?: string;
|
|
1323
|
+
/** 9-digit Norwegian organisation number — resolved via the public registry. */
|
|
1324
|
+
orgnr?: string;
|
|
1325
|
+
/** Company name — resolved to the best registry match before scanning. */
|
|
1326
|
+
name?: string;
|
|
904
1327
|
}
|
|
905
|
-
/**
|
|
906
|
-
interface
|
|
907
|
-
|
|
1328
|
+
/** Reference returned when a scan job is queued (HTTP 202). */
|
|
1329
|
+
interface ScanCreateResult {
|
|
1330
|
+
id: string;
|
|
1331
|
+
status: "pending" | string;
|
|
1332
|
+
message?: string;
|
|
1333
|
+
}
|
|
1334
|
+
/** Lifecycle of an asynchronous scan job. */
|
|
1335
|
+
type ScanStatus = "pending" | "running" | "done" | "failed";
|
|
1336
|
+
/** A company-registry search hit from `scan.companies()`. */
|
|
1337
|
+
interface ScanCompany {
|
|
1338
|
+
orgnr: string;
|
|
908
1339
|
name: string;
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
1340
|
+
org_form: string | null;
|
|
1341
|
+
industry: string | null;
|
|
1342
|
+
city: string | null;
|
|
1343
|
+
website: string | null;
|
|
1344
|
+
}
|
|
1345
|
+
/** Nettskår sub-scores (0–100); null = the axis could not be measured. */
|
|
1346
|
+
interface ScanSubScores {
|
|
1347
|
+
fart: number | null;
|
|
1348
|
+
google: number | null;
|
|
1349
|
+
ai: number | null;
|
|
1350
|
+
trygghet: number | null;
|
|
1351
|
+
omdomme: number | null;
|
|
917
1352
|
}
|
|
918
1353
|
/**
|
|
919
|
-
*
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
* leaves the current filter unchanged.
|
|
1354
|
+
* The versioned scan findings payload. Shapes within are additive per
|
|
1355
|
+
* `version`; string unions stay open (`| string`) so new detections never
|
|
1356
|
+
* break consumers.
|
|
923
1357
|
*/
|
|
924
|
-
interface
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1358
|
+
interface ScanResultPayload {
|
|
1359
|
+
version: number;
|
|
1360
|
+
/** Weighted composite score (0–100); null when nothing could be measured. */
|
|
1361
|
+
nettskaar: number | null;
|
|
1362
|
+
subScores: ScanSubScores;
|
|
1363
|
+
registry?: {
|
|
1364
|
+
orgnr: string;
|
|
1365
|
+
navn: string;
|
|
1366
|
+
organisasjonsform?: string;
|
|
1367
|
+
naeringBeskrivelse?: string;
|
|
1368
|
+
antallAnsatte?: number;
|
|
1369
|
+
poststed?: string;
|
|
1370
|
+
};
|
|
1371
|
+
signals: {
|
|
1372
|
+
version: number;
|
|
1373
|
+
tech: string[];
|
|
1374
|
+
pixels: string[];
|
|
1375
|
+
consent: string[];
|
|
1376
|
+
commerce: string[];
|
|
1377
|
+
marketing?: string[];
|
|
1378
|
+
social: Record<string, string | undefined>;
|
|
1379
|
+
emailProvider?: string;
|
|
1380
|
+
unreachable?: boolean;
|
|
1381
|
+
inconclusive?: boolean;
|
|
1382
|
+
dnsPending?: boolean;
|
|
1383
|
+
};
|
|
1384
|
+
pagespeed?: {
|
|
1385
|
+
mobileScore?: number;
|
|
1386
|
+
lcpMs?: number;
|
|
1387
|
+
cls?: number;
|
|
1388
|
+
inpMs?: number;
|
|
1389
|
+
error?: string;
|
|
1390
|
+
};
|
|
1391
|
+
seo: {
|
|
1392
|
+
titleLength: number;
|
|
1393
|
+
metaDescriptionLength: number;
|
|
1394
|
+
h1Count: number;
|
|
1395
|
+
hasOg: boolean;
|
|
1396
|
+
hasCanonical: boolean;
|
|
1397
|
+
hreflangCount: number;
|
|
1398
|
+
hasViewport: boolean;
|
|
1399
|
+
};
|
|
1400
|
+
ai: {
|
|
1401
|
+
/** null = llms.txt could not be checked (unknown), false = confirmed absent. */
|
|
1402
|
+
llmsTxtFound: boolean | null;
|
|
1403
|
+
/** null = robots.txt could not be read (unknown, not "none blocked"). */
|
|
1404
|
+
blockedBots: string[] | null;
|
|
1405
|
+
jsonLdTypes: string[];
|
|
1406
|
+
faqFound: boolean;
|
|
1407
|
+
};
|
|
1408
|
+
gdpr: {
|
|
1409
|
+
/**
|
|
1410
|
+
* true = tracking pixels load with no consent platform; false = clean or
|
|
1411
|
+
* a consent platform is present; null = unknown (unreachable / JS-only).
|
|
1412
|
+
*/
|
|
1413
|
+
trackingBeforeConsent: boolean | null;
|
|
1414
|
+
cmp: string | null;
|
|
1415
|
+
privacyPageFound: boolean;
|
|
1416
|
+
};
|
|
1417
|
+
mailAuth: {
|
|
1418
|
+
spf: "ok" | "missing" | "unknown" | string;
|
|
1419
|
+
dmarc: "ok" | "missing" | "unknown" | string;
|
|
1420
|
+
dmarcPolicy?: string;
|
|
1421
|
+
};
|
|
1422
|
+
httpsOk: boolean;
|
|
936
1423
|
}
|
|
937
|
-
/** A
|
|
938
|
-
interface
|
|
1424
|
+
/** A scan job as returned by `scan.get()`. */
|
|
1425
|
+
interface ScanJob {
|
|
939
1426
|
id: string;
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
/**
|
|
949
|
-
|
|
950
|
-
created_at:
|
|
1427
|
+
status: ScanStatus | string;
|
|
1428
|
+
input: ScanCreateInput;
|
|
1429
|
+
resolved: {
|
|
1430
|
+
orgnr?: string;
|
|
1431
|
+
companyName?: string;
|
|
1432
|
+
websiteUrl?: string;
|
|
1433
|
+
} | null;
|
|
1434
|
+
result: ScanResultPayload | null;
|
|
1435
|
+
/** Public-safe failure code (`company_not_found`, `no_website`, …). */
|
|
1436
|
+
error: string | null;
|
|
1437
|
+
created_at: string | null;
|
|
1438
|
+
finished_at: string | null;
|
|
951
1439
|
}
|
|
952
|
-
/** Options for
|
|
953
|
-
interface
|
|
954
|
-
|
|
1440
|
+
/** Options for `scan.waitForResult()`. */
|
|
1441
|
+
interface WaitForScanOptions {
|
|
1442
|
+
/** Poll interval in milliseconds. Default 2500. */
|
|
1443
|
+
intervalMs?: number;
|
|
1444
|
+
/** Give up after this long. Default 120000 (scans normally finish in ~30 s). */
|
|
1445
|
+
timeoutMs?: number;
|
|
955
1446
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Company & website scans (Nettsjekk) — score a Norwegian company's web
|
|
1450
|
+
* presence (performance, SEO, GDPR consent, AI visibility, mail auth) from a
|
|
1451
|
+
* URL, an organisation number, or a company name.
|
|
1452
|
+
*/
|
|
1453
|
+
declare class Scan {
|
|
1454
|
+
private client;
|
|
1455
|
+
constructor(client: BaseClient);
|
|
1456
|
+
/**
|
|
1457
|
+
* Queue a scan. Provide exactly one of `url`, `orgnr`, or `name`.
|
|
1458
|
+
* Runs asynchronously — poll with `get()` or use `waitForResult()`.
|
|
1459
|
+
*
|
|
1460
|
+
* @throws Error before any request when zero or several selectors are set —
|
|
1461
|
+
* the server would reject the body anyway; failing locally is clearer.
|
|
1462
|
+
*/
|
|
1463
|
+
create(input: ScanCreateInput): Promise<ApiResponse<ScanCreateResult>>;
|
|
1464
|
+
/** Get a scan job's status and, once done, its findings payload. */
|
|
1465
|
+
get(id: string): Promise<ApiResponse<ScanJob>>;
|
|
1466
|
+
/** Search the Norwegian company registry by name (typeahead, top 5 hits). */
|
|
1467
|
+
companies(q: string): Promise<ApiResponse<ScanCompany[]>>;
|
|
1468
|
+
/**
|
|
1469
|
+
* Poll a scan until it settles. Resolves with the job for both `done` and
|
|
1470
|
+
* `failed` (check `job.error`); throws only when the deadline passes while
|
|
1471
|
+
* the scan is still pending/running.
|
|
1472
|
+
*/
|
|
1473
|
+
waitForResult(id: string, options?: WaitForScanOptions): Promise<ScanJob>;
|
|
960
1474
|
}
|
|
961
1475
|
|
|
962
1476
|
/** Manage webhook endpoints and inspect their deliveries. */
|
|
963
1477
|
declare class Webhooks {
|
|
964
1478
|
private client;
|
|
965
|
-
|
|
1479
|
+
private confirmer;
|
|
1480
|
+
constructor(client: BaseClient, confirmer?: CapabilityConfirmer);
|
|
966
1481
|
/** List all webhook endpoints in the workspace. */
|
|
967
1482
|
list(): Promise<ApiResponse<WebhookEndpoint[]>>;
|
|
968
1483
|
/**
|
|
@@ -1227,6 +1742,37 @@ interface MedalOptions {
|
|
|
1227
1742
|
* OAuth tokens can access multiple workspaces, so you must specify which one.
|
|
1228
1743
|
*/
|
|
1229
1744
|
workspaceId?: string;
|
|
1745
|
+
/**
|
|
1746
|
+
* Opt in to automatic capability confirmation for confirmable writes.
|
|
1747
|
+
* **Defaults to OFF.**
|
|
1748
|
+
*
|
|
1749
|
+
* Medal's confirmable write routes (connect links, channel connections,
|
|
1750
|
+
* helpdesk replies/updates, webhook endpoint writes) require BOTH an
|
|
1751
|
+
* `Idempotency-Key` and an `X-Capability-Confirmation` token whenever the
|
|
1752
|
+
* credential holds the capability scope directly — which is the case for
|
|
1753
|
+
* every correctly-scoped partner key. With this option set, the SDK mints
|
|
1754
|
+
* both for you before each such write instead of making you hand-roll
|
|
1755
|
+
* `POST /api/v1/capability-confirmations`.
|
|
1756
|
+
*
|
|
1757
|
+
* **Read before enabling:** each minted token carries `user_approved: true`,
|
|
1758
|
+
* which asserts to Medal that *a human on your side approved that specific
|
|
1759
|
+
* action*, and the `previewSummary` you return is retained as the audit
|
|
1760
|
+
* record of what they approved. Enable it only on code paths where that is
|
|
1761
|
+
* genuinely true — never to rubber-stamp unattended writes. Pass
|
|
1762
|
+
* `{ autoConfirm: false }` on an individual call to opt out again, or use
|
|
1763
|
+
* `medal.capabilityConfirmations.create(...)` for full manual control.
|
|
1764
|
+
*
|
|
1765
|
+
* @example
|
|
1766
|
+
* ```ts
|
|
1767
|
+
* const medal = new Medal('medal_xxx', {
|
|
1768
|
+
* autoConfirmCapabilities: {
|
|
1769
|
+
* previewSummary: (ctx) =>
|
|
1770
|
+
* `${operator.email} approved ${ctx.method} ${ctx.path}`,
|
|
1771
|
+
* },
|
|
1772
|
+
* });
|
|
1773
|
+
* ```
|
|
1774
|
+
*/
|
|
1775
|
+
autoConfirmCapabilities?: AutoConfirmOptions;
|
|
1230
1776
|
}
|
|
1231
1777
|
/**
|
|
1232
1778
|
* Medal Social SDK client.
|
|
@@ -1275,6 +1821,7 @@ interface MedalOptions {
|
|
|
1275
1821
|
* ```
|
|
1276
1822
|
*/
|
|
1277
1823
|
declare class Medal {
|
|
1824
|
+
readonly capabilityConfirmations: CapabilityConfirmations;
|
|
1278
1825
|
readonly channels: Channels;
|
|
1279
1826
|
readonly emails: Emails;
|
|
1280
1827
|
readonly contacts: Contacts;
|
|
@@ -1282,6 +1829,7 @@ declare class Medal {
|
|
|
1282
1829
|
readonly gdpr: Gdpr;
|
|
1283
1830
|
readonly helpdesk: Helpdesk;
|
|
1284
1831
|
readonly posts: Posts;
|
|
1832
|
+
readonly scan: Scan;
|
|
1285
1833
|
readonly webhooks: Webhooks;
|
|
1286
1834
|
readonly workspaces: Workspaces;
|
|
1287
1835
|
constructor(token: string, options?: MedalOptions);
|
|
@@ -1290,4 +1838,4 @@ declare class Medal {
|
|
|
1290
1838
|
/** Convenience factory — equivalent to `new Medal(apiKey, options)`. */
|
|
1291
1839
|
declare function createMedalClient(apiKey: string, options?: MedalOptions): Medal;
|
|
1292
1840
|
|
|
1293
|
-
export { type Activity, type AddNoteInput, type ApiResponse, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateConnectLinkInput, type CreateContactInput, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type ReplyCreateResult, type RequestOptions, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
|
|
1841
|
+
export { type Activity, type AddNoteInput, type ApiResponse, type AutoConfirmContext, type AutoConfirmOptions, BaseClient, type BatchSendInput, type BatchSendResult, type BatchSendSummary, CAPABILITY_IDS, CAPABILITY_ROUTES, type CapabilityConfirmation, CapabilityConfirmations, CapabilityConfirmer, type CapabilityId, type CapabilityPathParamValue, type CapabilityRoute, type CapabilityWriteBodies, type CapabilityWriteRequest, type Channel, type ChannelConnectedEvent, type ChannelConnection, type ChannelConnectionDisconnectResult, type ChannelConnectionState, type ChannelDisconnectReason, type ChannelDisconnectedEvent, Channels, type ConnectLink, type ConnectLinkCreateResult, type ConnectLinkRevokeResult, type ConnectLinkStatus, type ConsentRecord, type ConsentResult, type ConsentType, type Contact, type ContactConsents, type ContactCreateResult, type ContactNoteResult, type ContactRemoveResult, type ContactStatus, type ContactUpdateResult, Contacts, type Conversation, type ConversationAssignedEvent, type ConversationCreatedEvent, type ConversationMessage, type ConversationStatus, type ConversationStatusChangedEvent, type ConversationUpdateResult, type CookieCategoryConsent, type CookieConsentInput, type CreateConnectLinkInput, type CreateContactInput, type CreateDealInput, type CreatePostInput, type CreateReplyInput, type CreateWebhookInput, DEFAULT_WEBHOOK_TOLERANCE_MS, type Deal, type DealCreateResult, type DealRemoveResult, type DealStatus, type DealUpdateResult, Deals, type EmailSend, type EmailSendResult, type EmailStatus, type EmailTemplate, type EmailTemplateDetail, Emails, Gdpr, type GdprExport, type GetTemplateOptions, Helpdesk, type HelpdeskMessageType, type ImportContactInput, type ImportContactsResult, type IssueCapabilityConfirmationInput, type ListConnectLinksOptions, type ListContactsOptions, type ListConversationsOptions, type ListDealsOptions, type ListDeliveriesOptions, type ListPostsOptions, Medal, MedalApiError, type MedalOptions, type MessageAuthorType, type MessageDeliveryStatus, type MessageDeliveryUpdatedEvent, type MessageReceivedEvent, type MessageSentEvent, type PaginatedResponse, type PaginationOptions, type Post, type PostDetail, type PostType, type PostVariant, Posts, type PublishResult, type RecordConsentInput, type ReplyCreateResult, type RequestOptions, Scan, type ScanCompany, type ScanCreateInput, type ScanCreateResult, type ScanJob, type ScanResultPayload, type ScanStatus, type ScanSubScores, type SchedulePostInput, type ScheduleResult, type SendEmailInput, type TestPingEvent, type UpdateContactInput, type UpdateConversationInput, type UpdateDealInput, type UpdatePostInput, type UpdateWebhookInput, type VerifyWebhookSignatureInput, type WaitForScanOptions, type WebhookChannelLifecycleData, type WebhookConversationSnapshot, type WebhookDeleteResult, type WebhookDelivery, type WebhookEndpoint, type WebhookEvent, type WebhookMessageSnapshot, type WebhookTestResult, WebhookVerificationError, type WebhookVerificationErrorCode, Webhooks, type Workspace, Workspaces, createMedalClient, Medal as default, verifyWebhookSignature };
|