@fonoster/sdk 0.27.0 → 0.31.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 +12 -9
- package/dist/node/Agents.js +5 -20
- package/dist/node/Applications.d.ts +21 -85
- package/dist/node/Applications.js +64 -74
- package/dist/node/Billing.d.ts +50 -0
- package/dist/node/Billing.js +84 -0
- package/dist/node/CallRecords.d.ts +92 -0
- package/dist/node/CallRecords.js +127 -0
- package/dist/node/Calls.d.ts +3 -1
- package/dist/node/Calls.js +3 -1
- package/dist/node/Domains.js +4 -2
- package/dist/node/Numbers.js +2 -7
- package/dist/node/Providers.d.ts +49 -0
- package/dist/node/Providers.js +109 -0
- package/dist/node/Regions.d.ts +91 -0
- package/dist/node/Regions.js +127 -0
- package/dist/node/Usage.d.ts +44 -0
- package/dist/node/Usage.js +41 -0
- package/dist/node/Users.d.ts +4 -2
- package/dist/node/Users.js +4 -2
- package/dist/node/Webhooks.d.ts +56 -0
- package/dist/node/Webhooks.js +139 -0
- package/dist/node/Workspaces.d.ts +22 -3
- package/dist/node/Workspaces.js +29 -2
- package/dist/node/client/AbstractClient.d.ts +94 -3
- package/dist/node/client/AbstractClient.js +101 -1
- package/dist/node/client/Client.d.ts +9 -0
- package/dist/node/client/Client.js +34 -1
- package/dist/node/client/jsonToObject.js +17 -0
- package/dist/node/client/objectToJson.js +35 -0
- package/dist/node/client/types/ApplicationsClient.d.ts +2 -1
- package/dist/node/client/types/BillingClient.d.ts +28 -0
- package/dist/node/client/types/BillingClient.js +2 -0
- package/dist/node/client/types/CapabilitiesClient.d.ts +24 -0
- package/dist/node/client/types/CapabilitiesClient.js +2 -0
- package/dist/node/client/types/FonosterClient.d.ts +12 -0
- package/dist/node/client/types/IdentityClient.d.ts +3 -1
- package/dist/node/client/types/ProvidersClient.d.ts +28 -0
- package/dist/node/client/types/ProvidersClient.js +2 -0
- package/dist/node/client/types/UsageClient.d.ts +24 -0
- package/dist/node/client/types/UsageClient.js +2 -0
- package/dist/node/client/types/WebhooksClient.d.ts +31 -0
- package/dist/node/client/types/WebhooksClient.js +2 -0
- package/dist/node/client/types/index.d.ts +5 -0
- package/dist/node/client/types/index.js +5 -0
- package/dist/node/generated/node/applications_grpc_pb.js +34 -0
- package/dist/node/generated/node/applications_pb.js +2991 -178
- package/dist/node/generated/node/billing_grpc_pb.js +169 -0
- package/dist/node/generated/node/billing_pb.js +1720 -0
- package/dist/node/generated/node/calls_pb.js +62 -2
- package/dist/node/generated/node/capabilities_grpc_pb.js +66 -0
- package/dist/node/generated/node/capabilities_pb.js +2288 -0
- package/dist/node/generated/node/identity_grpc_pb.js +34 -0
- package/dist/node/generated/node/identity_pb.js +609 -5
- package/dist/node/generated/node/providers_grpc_pb.js +200 -0
- package/dist/node/generated/node/providers_pb.js +3094 -0
- package/dist/node/generated/node/usage_grpc_pb.js +64 -0
- package/dist/node/generated/node/usage_pb.js +866 -0
- package/dist/node/generated/node/webhooks_grpc_pb.js +302 -0
- package/dist/node/generated/node/webhooks_pb.js +3314 -0
- package/dist/node/generated/web/ApplicationsServiceClientPb.ts +43 -0
- package/dist/node/generated/web/BillingServiceClientPb.ts +258 -0
- package/dist/node/generated/web/CapabilitiesServiceClientPb.ts +87 -0
- package/dist/node/generated/web/IdentityServiceClientPb.ts +43 -0
- package/dist/node/generated/web/ProvidersServiceClientPb.ts +258 -0
- package/dist/node/generated/web/UsageServiceClientPb.ts +86 -0
- package/dist/node/generated/web/WebhooksServiceClientPb.ts +387 -0
- package/dist/node/generated/web/applications_pb.d.ts +343 -1
- package/dist/node/generated/web/applications_pb.js +2991 -178
- package/dist/node/generated/web/billing_pb.d.ts +210 -0
- package/dist/node/generated/web/billing_pb.js +1720 -0
- package/dist/node/generated/web/calls_pb.d.ts +8 -0
- package/dist/node/generated/web/calls_pb.js +62 -2
- package/dist/node/generated/web/capabilities_pb.d.ts +273 -0
- package/dist/node/generated/web/capabilities_pb.js +2288 -0
- package/dist/node/generated/web/identity_pb.d.ts +76 -0
- package/dist/node/generated/web/identity_pb.js +609 -5
- package/dist/node/generated/web/providers_pb.d.ts +372 -0
- package/dist/node/generated/web/providers_pb.js +3094 -0
- package/dist/node/generated/web/usage_pb.d.ts +106 -0
- package/dist/node/generated/web/usage_pb.js +866 -0
- package/dist/node/generated/web/webhooks_pb.d.ts +398 -0
- package/dist/node/generated/web/webhooks_pb.js +3314 -0
- package/dist/node/node.d.ts +7 -0
- package/dist/node/node.js +6 -0
- package/dist/node/tsconfig.tsbuildinfo +1 -1
- package/dist/node/utils.d.ts +7 -12
- package/dist/node/utils.js +18 -39
- package/dist/web/fonoster.min.js +1 -1
- package/dist/web/index.esm.js +1 -1
- package/package.json +8 -13
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegionsError = exports.Regions = void 0;
|
|
4
|
+
/** An error answer from the regions API (status and its `error` code). */
|
|
5
|
+
class RegionsError extends Error {
|
|
6
|
+
status;
|
|
7
|
+
code;
|
|
8
|
+
constructor(status, code, message) {
|
|
9
|
+
super(message ?? `regions API: ${status} ${code}`);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.code = code;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.RegionsError = RegionsError;
|
|
15
|
+
/**
|
|
16
|
+
* @classdesc Regions (add-private-regions, PR-12..PR-21) through the HTTP API (`/api/regions`).
|
|
17
|
+
* Regions belong to the signed-in user: create a private region (id, display name, SIP domain),
|
|
18
|
+
* get its one-time enrollment token, watch its status, re-issue the token, disconnect or delete
|
|
19
|
+
* it. A workspace picks a region when it is created (`workspaces.createWorkspace({name, region})`).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const regions = new SDK.Regions(client);
|
|
23
|
+
* const { items } = await regions.listRegions();
|
|
24
|
+
* const { ref, token } = await regions.createRegion({
|
|
25
|
+
* id: "acme-hq", displayName: "Acme HQ", sipDomain: "sip.acme.com"
|
|
26
|
+
* });
|
|
27
|
+
* const region = await regions.getRegion("acme-hq");
|
|
28
|
+
*/
|
|
29
|
+
class Regions {
|
|
30
|
+
client;
|
|
31
|
+
baseUrl;
|
|
32
|
+
fetchFn;
|
|
33
|
+
constructor(client, options = {}) {
|
|
34
|
+
this.client = client;
|
|
35
|
+
this.baseUrl = options.baseUrl?.replace(/\/+$/, "");
|
|
36
|
+
// Called as a method below, so never store the global unbound: in browsers a detached
|
|
37
|
+
// `fetch` throws "Illegal invocation".
|
|
38
|
+
this.fetchFn =
|
|
39
|
+
options.fetch ??
|
|
40
|
+
((input, init) => globalThis.fetch(input, init));
|
|
41
|
+
}
|
|
42
|
+
headers(auth, body) {
|
|
43
|
+
const h = {};
|
|
44
|
+
if (body !== undefined)
|
|
45
|
+
h["content-type"] = "application/json";
|
|
46
|
+
if (!auth)
|
|
47
|
+
return h;
|
|
48
|
+
const token = this.client.getAccessToken?.();
|
|
49
|
+
if (token)
|
|
50
|
+
h.authorization = `Bearer ${token}`;
|
|
51
|
+
const accessKeyId = this.client.getAccessKeyId?.();
|
|
52
|
+
if (accessKeyId)
|
|
53
|
+
h["x-accesskey-id"] = accessKeyId;
|
|
54
|
+
return h;
|
|
55
|
+
}
|
|
56
|
+
async json(path, method = "GET", body, auth = true) {
|
|
57
|
+
const base = this.baseUrl ?? this.client.getHttpUrl?.() ?? "https://api.fonoster.ai";
|
|
58
|
+
const attempt = () => this.fetchFn(`${base}/api/regions${path}`, {
|
|
59
|
+
method,
|
|
60
|
+
headers: this.headers(auth, body),
|
|
61
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {})
|
|
62
|
+
});
|
|
63
|
+
let res = await attempt();
|
|
64
|
+
if (res.status === 401 && auth) {
|
|
65
|
+
await this.client.refreshToken();
|
|
66
|
+
res = await attempt();
|
|
67
|
+
}
|
|
68
|
+
const out = (await res.json().catch(() => ({})));
|
|
69
|
+
if (!res.ok)
|
|
70
|
+
throw new RegionsError(res.status, String(out.error ?? "error"), out.message);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
static path(region) {
|
|
74
|
+
return `/${encodeURIComponent(region)}`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The regions a new workspace can pick: the offered public regions and, when signed in, your
|
|
78
|
+
* private regions (with status).
|
|
79
|
+
*/
|
|
80
|
+
async listRegions() {
|
|
81
|
+
let signedIn = false;
|
|
82
|
+
try {
|
|
83
|
+
signedIn = !!this.client.getAccessToken?.();
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
signedIn = false;
|
|
87
|
+
}
|
|
88
|
+
return this.json("", "GET", undefined, signedIn);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a private region (PR-15, PR-16, PR-18). The token (`token`, also `enrollmentToken`)
|
|
92
|
+
* is returned once; run `fonoster-region enroll <token>` on the region machine.
|
|
93
|
+
*/
|
|
94
|
+
async createRegion(request) {
|
|
95
|
+
return this.json("", "POST", request);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* One region by id or ref; without an argument, the current workspace's region (its status,
|
|
99
|
+
* secrets and connection details).
|
|
100
|
+
*/
|
|
101
|
+
async getRegion(region) {
|
|
102
|
+
return this.json(region ? Regions.path(region) : "/current");
|
|
103
|
+
}
|
|
104
|
+
/** Changes a private region's display name (the id never changes). */
|
|
105
|
+
async updateRegion(region, request) {
|
|
106
|
+
return this.json(Regions.path(region), "PATCH", request);
|
|
107
|
+
}
|
|
108
|
+
/** A new one-time enrollment token; enrolling with it revokes the current cell. */
|
|
109
|
+
async reissueRegionToken(region) {
|
|
110
|
+
return this.json(`${Regions.path(await this.refOf(region))}/token`, "POST");
|
|
111
|
+
}
|
|
112
|
+
/** Revokes the region's cell now; the region goes back to `waiting`. */
|
|
113
|
+
async disconnectRegion(region) {
|
|
114
|
+
await this.json(`${Regions.path(await this.refOf(region))}/disconnect`, "POST");
|
|
115
|
+
}
|
|
116
|
+
/** Deletes a private region; refused (`region_in_use`) while any workspace uses it. */
|
|
117
|
+
async deleteRegion(region) {
|
|
118
|
+
return this.json(Regions.path(region), "DELETE");
|
|
119
|
+
}
|
|
120
|
+
/** The given region, or the current workspace's region. */
|
|
121
|
+
async refOf(region) {
|
|
122
|
+
if (region)
|
|
123
|
+
return region;
|
|
124
|
+
return (await this.getRegion()).ref;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.Regions = Regions;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/fonoster
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Fonoster
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { GetUsageRequest, GetUsageResponse } from "@fonoster/types";
|
|
20
|
+
import { FonosterClient } from "./client/types";
|
|
21
|
+
/**
|
|
22
|
+
* @classdesc What the workspace consumed: call minutes, speech, language-model tokens, noise
|
|
23
|
+
* cancelling, answering-machine detections, recordings and storage. Quantities only, never money.
|
|
24
|
+
* Each total says whose key a vendor was called with (`keySource`: `workspace` or `platform`).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const usage = new SDK.Usage(client);
|
|
28
|
+
* const { rows } = await usage.getUsage({
|
|
29
|
+
* fromDay: "2026-10-01",
|
|
30
|
+
* toDay: "2026-10-31",
|
|
31
|
+
* groupBy: ["key_source"]
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
declare class Usage {
|
|
35
|
+
private readonly client;
|
|
36
|
+
constructor(client: FonosterClient);
|
|
37
|
+
/**
|
|
38
|
+
* Usage totals for a range of days (UTC, inclusive), split by meter and by the dimensions in
|
|
39
|
+
* `groupBy` (day, workspace, provider, model, key_source, origin). With `allOwned`, a workspace
|
|
40
|
+
* owner gets every workspace they own.
|
|
41
|
+
*/
|
|
42
|
+
getUsage(request: GetUsageRequest): Promise<GetUsageResponse>;
|
|
43
|
+
}
|
|
44
|
+
export { Usage };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Usage = void 0;
|
|
4
|
+
const makeRpcRequest_1 = require("./client/makeRpcRequest");
|
|
5
|
+
const usage_pb_1 = require("./generated/node/usage_pb");
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc What the workspace consumed: call minutes, speech, language-model tokens, noise
|
|
8
|
+
* cancelling, answering-machine detections, recordings and storage. Quantities only, never money.
|
|
9
|
+
* Each total says whose key a vendor was called with (`keySource`: `workspace` or `platform`).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const usage = new SDK.Usage(client);
|
|
13
|
+
* const { rows } = await usage.getUsage({
|
|
14
|
+
* fromDay: "2026-10-01",
|
|
15
|
+
* toDay: "2026-10-31",
|
|
16
|
+
* groupBy: ["key_source"]
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
class Usage {
|
|
20
|
+
client;
|
|
21
|
+
constructor(client) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Usage totals for a range of days (UTC, inclusive), split by meter and by the dimensions in
|
|
26
|
+
* `groupBy` (day, workspace, provider, model, key_source, origin). With `allOwned`, a workspace
|
|
27
|
+
* owner gets every workspace they own.
|
|
28
|
+
*/
|
|
29
|
+
async getUsage(request) {
|
|
30
|
+
const client = this.client.getUsageClient();
|
|
31
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
32
|
+
method: client.getUsage.bind(client),
|
|
33
|
+
requestPBObjectConstructor: usage_pb_1.GetUsageRequest,
|
|
34
|
+
metadata: this.client.getMetadata(),
|
|
35
|
+
request: { groupBy: [], ...request },
|
|
36
|
+
repeatableObjectMapping: [["rowsList", usage_pb_1.UsageRow]]
|
|
37
|
+
});
|
|
38
|
+
return { rows: raw.rows ?? [] };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Usage = Usage;
|
package/dist/node/Users.d.ts
CHANGED
|
@@ -117,7 +117,8 @@ declare class Users {
|
|
|
117
117
|
* @param {UpdateUserRequest} request - The request object that contains the necessary information to update a User
|
|
118
118
|
* @param {string} request.ref - The reference of the User to update
|
|
119
119
|
* @param {string} [request.name] - The name of the User
|
|
120
|
-
* @param {string} [request.password] -
|
|
120
|
+
* @param {string} [request.password] - A new password for the User; requires currentPassword and signs the User out everywhere
|
|
121
|
+
* @param {string} [request.currentPassword] - The User's current password, required to set a new one
|
|
121
122
|
* @param {string} [request.avatar] - The avatar of the User
|
|
122
123
|
* @param {string} [request.phone] - The phone number of the User (optional)
|
|
123
124
|
* @return {Promise<BaseApiObject>} - The response object that contains the reference to the updated User
|
|
@@ -127,7 +128,8 @@ declare class Users {
|
|
|
127
128
|
* const request = {
|
|
128
129
|
* ref: "00000000-0000-0000-0000-000000000000",
|
|
129
130
|
* name: "John Doe",
|
|
130
|
-
* password: "password",
|
|
131
|
+
* password: "a-new-password",
|
|
132
|
+
* currentPassword: "the-current-password",
|
|
131
133
|
* avatar: "https://example.com/avatar.jpg",
|
|
132
134
|
* phone: "+1234567890"
|
|
133
135
|
* };
|
package/dist/node/Users.js
CHANGED
|
@@ -128,7 +128,8 @@ class Users {
|
|
|
128
128
|
* @param {UpdateUserRequest} request - The request object that contains the necessary information to update a User
|
|
129
129
|
* @param {string} request.ref - The reference of the User to update
|
|
130
130
|
* @param {string} [request.name] - The name of the User
|
|
131
|
-
* @param {string} [request.password] -
|
|
131
|
+
* @param {string} [request.password] - A new password for the User; requires currentPassword and signs the User out everywhere
|
|
132
|
+
* @param {string} [request.currentPassword] - The User's current password, required to set a new one
|
|
132
133
|
* @param {string} [request.avatar] - The avatar of the User
|
|
133
134
|
* @param {string} [request.phone] - The phone number of the User (optional)
|
|
134
135
|
* @return {Promise<BaseApiObject>} - The response object that contains the reference to the updated User
|
|
@@ -138,7 +139,8 @@ class Users {
|
|
|
138
139
|
* const request = {
|
|
139
140
|
* ref: "00000000-0000-0000-0000-000000000000",
|
|
140
141
|
* name: "John Doe",
|
|
141
|
-
* password: "password",
|
|
142
|
+
* password: "a-new-password",
|
|
143
|
+
* currentPassword: "the-current-password",
|
|
142
144
|
* avatar: "https://example.com/avatar.jpg",
|
|
143
145
|
* phone: "+1234567890"
|
|
144
146
|
* };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/fonoster
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Fonoster
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { BaseApiObject, CreateWebhookRequest, CreateWebhookResponse, ListWebhookDeliveriesRequest, ListWebhookDeliveriesResponse, ListWebhooksRequest, ListWebhooksResponse, RotateWebhookSecretResponse, UpdateWebhookRequest, Webhook, WebhookDelivery } from "@fonoster/types";
|
|
20
|
+
import { FonosterClient } from "./client/types";
|
|
21
|
+
/**
|
|
22
|
+
* @classdesc Fonoster Webhooks, a capability of Fonoster's Workspaces. Webhooks receive call
|
|
23
|
+
* events (call.started, call.ended, call.failed, call_record.sealed, provider.deprecated),
|
|
24
|
+
* signed with the endpoint's secret.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const SDK = require("@fonoster/sdk");
|
|
28
|
+
*
|
|
29
|
+
* async function main() {
|
|
30
|
+
* const client = new SDK.Client({ accessKeyId: "WO00000000000000000000000000000000" });
|
|
31
|
+
* await client.loginWithApiKey("APXXXXXXXXXXXXXXXX", "YYYYYYYYYYYYYYYYY");
|
|
32
|
+
* const webhooks = new SDK.Webhooks(client);
|
|
33
|
+
* const { ref, secret } = await webhooks.createWebhook({
|
|
34
|
+
* url: "https://example.com/fonoster",
|
|
35
|
+
* events: ["call.ended"]
|
|
36
|
+
* });
|
|
37
|
+
* }
|
|
38
|
+
*/
|
|
39
|
+
declare class Webhooks {
|
|
40
|
+
private readonly client;
|
|
41
|
+
constructor(client: FonosterClient);
|
|
42
|
+
/** Creates an endpoint. The secret is returned only here and on rotation. */
|
|
43
|
+
createWebhook(request: CreateWebhookRequest): Promise<CreateWebhookResponse>;
|
|
44
|
+
getWebhook(ref: string): Promise<Webhook>;
|
|
45
|
+
listWebhooks(request?: ListWebhooksRequest): Promise<ListWebhooksResponse>;
|
|
46
|
+
/** Changes the URL and/or events; fields left out are kept. */
|
|
47
|
+
updateWebhook(request: UpdateWebhookRequest): Promise<BaseApiObject>;
|
|
48
|
+
deleteWebhook(ref: string): Promise<BaseApiObject>;
|
|
49
|
+
/** A new secret; the previous one keeps verifying for 24 hours. */
|
|
50
|
+
rotateWebhookSecret(ref: string): Promise<RotateWebhookSecretResponse>;
|
|
51
|
+
/** The delivery log, newest first (optionally one endpoint's). */
|
|
52
|
+
listWebhookDeliveries(request?: ListWebhookDeliveriesRequest): Promise<ListWebhookDeliveriesResponse>;
|
|
53
|
+
/** Sends a delivery again now, with the same event id and a fresh signature. */
|
|
54
|
+
resendWebhookDelivery(ref: string): Promise<WebhookDelivery>;
|
|
55
|
+
}
|
|
56
|
+
export { Webhooks };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Webhooks = void 0;
|
|
4
|
+
const makeRpcRequest_1 = require("./client/makeRpcRequest");
|
|
5
|
+
const webhooks_pb_1 = require("./generated/node/webhooks_pb");
|
|
6
|
+
const date = (seconds) => typeof seconds === "number" && seconds > 0
|
|
7
|
+
? new Date(seconds * 1000)
|
|
8
|
+
: undefined;
|
|
9
|
+
function toWebhook(raw) {
|
|
10
|
+
const { eventsList, previousSecretUntil, ...rest } = raw;
|
|
11
|
+
return {
|
|
12
|
+
...rest,
|
|
13
|
+
events: (raw.events ?? eventsList ?? []),
|
|
14
|
+
previousSecretUntil: date(previousSecretUntil)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function toDelivery(raw) {
|
|
18
|
+
return {
|
|
19
|
+
...raw,
|
|
20
|
+
lastAttemptAt: date(raw.lastAttemptAt),
|
|
21
|
+
nextAttemptAt: date(raw.nextAttemptAt)
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @classdesc Fonoster Webhooks, a capability of Fonoster's Workspaces. Webhooks receive call
|
|
26
|
+
* events (call.started, call.ended, call.failed, call_record.sealed, provider.deprecated),
|
|
27
|
+
* signed with the endpoint's secret.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const SDK = require("@fonoster/sdk");
|
|
31
|
+
*
|
|
32
|
+
* async function main() {
|
|
33
|
+
* const client = new SDK.Client({ accessKeyId: "WO00000000000000000000000000000000" });
|
|
34
|
+
* await client.loginWithApiKey("APXXXXXXXXXXXXXXXX", "YYYYYYYYYYYYYYYYY");
|
|
35
|
+
* const webhooks = new SDK.Webhooks(client);
|
|
36
|
+
* const { ref, secret } = await webhooks.createWebhook({
|
|
37
|
+
* url: "https://example.com/fonoster",
|
|
38
|
+
* events: ["call.ended"]
|
|
39
|
+
* });
|
|
40
|
+
* }
|
|
41
|
+
*/
|
|
42
|
+
class Webhooks {
|
|
43
|
+
client;
|
|
44
|
+
constructor(client) {
|
|
45
|
+
this.client = client;
|
|
46
|
+
}
|
|
47
|
+
/** Creates an endpoint. The secret is returned only here and on rotation. */
|
|
48
|
+
async createWebhook(request) {
|
|
49
|
+
const client = this.client.getWebhooksClient();
|
|
50
|
+
return await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
51
|
+
method: client.createWebhook.bind(client),
|
|
52
|
+
requestPBObjectConstructor: webhooks_pb_1.CreateWebhookRequest,
|
|
53
|
+
metadata: this.client.getMetadata(),
|
|
54
|
+
request
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async getWebhook(ref) {
|
|
58
|
+
const client = this.client.getWebhooksClient();
|
|
59
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
60
|
+
method: client.getWebhook.bind(client),
|
|
61
|
+
requestPBObjectConstructor: webhooks_pb_1.GetWebhookRequest,
|
|
62
|
+
metadata: this.client.getMetadata(),
|
|
63
|
+
request: { ref }
|
|
64
|
+
});
|
|
65
|
+
return toWebhook(raw);
|
|
66
|
+
}
|
|
67
|
+
async listWebhooks(request = {}) {
|
|
68
|
+
const client = this.client.getWebhooksClient();
|
|
69
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
70
|
+
method: client.listWebhooks.bind(client),
|
|
71
|
+
requestPBObjectConstructor: webhooks_pb_1.ListWebhooksRequest,
|
|
72
|
+
metadata: this.client.getMetadata(),
|
|
73
|
+
request,
|
|
74
|
+
repeatableObjectMapping: [["itemsList", webhooks_pb_1.Webhook]]
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
items: (raw.items ?? []).map(toWebhook),
|
|
78
|
+
nextPageToken: raw.nextPageToken
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** Changes the URL and/or events; fields left out are kept. */
|
|
82
|
+
async updateWebhook(request) {
|
|
83
|
+
const client = this.client.getWebhooksClient();
|
|
84
|
+
return await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
85
|
+
method: client.updateWebhook.bind(client),
|
|
86
|
+
requestPBObjectConstructor: webhooks_pb_1.UpdateWebhookRequest,
|
|
87
|
+
metadata: this.client.getMetadata(),
|
|
88
|
+
request
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async deleteWebhook(ref) {
|
|
92
|
+
const client = this.client.getWebhooksClient();
|
|
93
|
+
return await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
94
|
+
method: client.deleteWebhook.bind(client),
|
|
95
|
+
requestPBObjectConstructor: webhooks_pb_1.DeleteWebhookRequest,
|
|
96
|
+
metadata: this.client.getMetadata(),
|
|
97
|
+
request: { ref }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/** A new secret; the previous one keeps verifying for 24 hours. */
|
|
101
|
+
async rotateWebhookSecret(ref) {
|
|
102
|
+
const client = this.client.getWebhooksClient();
|
|
103
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
104
|
+
method: client.rotateWebhookSecret.bind(client),
|
|
105
|
+
requestPBObjectConstructor: webhooks_pb_1.RotateWebhookSecretRequest,
|
|
106
|
+
metadata: this.client.getMetadata(),
|
|
107
|
+
request: { ref }
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
ref: raw.ref,
|
|
111
|
+
secret: raw.secret,
|
|
112
|
+
previousSecretUntil: date(raw.previousSecretUntil)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** The delivery log, newest first (optionally one endpoint's). */
|
|
116
|
+
async listWebhookDeliveries(request = {}) {
|
|
117
|
+
const client = this.client.getWebhooksClient();
|
|
118
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
119
|
+
method: client.listWebhookDeliveries.bind(client),
|
|
120
|
+
requestPBObjectConstructor: webhooks_pb_1.ListWebhookDeliveriesRequest,
|
|
121
|
+
metadata: this.client.getMetadata(),
|
|
122
|
+
request,
|
|
123
|
+
repeatableObjectMapping: [["itemsList", webhooks_pb_1.WebhookDelivery]]
|
|
124
|
+
});
|
|
125
|
+
return { items: (raw.items ?? []).map(toDelivery) };
|
|
126
|
+
}
|
|
127
|
+
/** Sends a delivery again now, with the same event id and a fresh signature. */
|
|
128
|
+
async resendWebhookDelivery(ref) {
|
|
129
|
+
const client = this.client.getWebhooksClient();
|
|
130
|
+
const raw = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
131
|
+
method: client.resendWebhookDelivery.bind(client),
|
|
132
|
+
requestPBObjectConstructor: webhooks_pb_1.ResendWebhookDeliveryRequest,
|
|
133
|
+
metadata: this.client.getMetadata(),
|
|
134
|
+
request: { ref }
|
|
135
|
+
});
|
|
136
|
+
return toDelivery(raw);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.Webhooks = Webhooks;
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { BaseApiObject, CreateWorkspaceRequest, InviteUserToWorkspaceRequest, ListWorkspaceMembersRequest, ListWorkspaceMembersResponse, ListWorkspacesResponse, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationResponse, UpdateWorkspaceRequest, Workspace } from "@fonoster/types";
|
|
19
|
+
import { BaseApiObject, CreateWorkspaceRequest, CreateWorkspaceResponse, InviteUserToWorkspaceRequest, ListWorkspaceMembersRequest, ListWorkspaceMembersResponse, ListWorkspacesResponse, Region, RegionEnrollmentToken, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationResponse, UpdateWorkspaceRequest, Workspace } from "@fonoster/types";
|
|
20
20
|
import { FonosterClient } from "./client/types";
|
|
21
21
|
/**
|
|
22
22
|
* @classdesc Fonoster Workspaces, part of the Fonoster Identity subsystem,
|
|
@@ -66,7 +66,8 @@ declare class Workspaces {
|
|
|
66
66
|
*
|
|
67
67
|
* @param {CreateWorkspaceRequest} request - The request object that contains the necessary information to create a new Workspace
|
|
68
68
|
* @param {string} request.name - The name of the Workspace
|
|
69
|
-
* @
|
|
69
|
+
* @param {string} request.region - An offered public region id (default `default`) or one of your private regions (id or ref, see `Regions.createRegion`); fixed for life
|
|
70
|
+
* @return {Promise<CreateWorkspaceResponse>} - The reference and the stored region
|
|
70
71
|
* @example
|
|
71
72
|
* const workspaces = new SDK.Workspaces(client); // Existing client object
|
|
72
73
|
*
|
|
@@ -79,7 +80,25 @@ declare class Workspaces {
|
|
|
79
80
|
* .then(console.log) // successful response
|
|
80
81
|
* .catch(console.error); // an error occurred
|
|
81
82
|
*/
|
|
82
|
-
createWorkspace(request: CreateWorkspaceRequest): Promise<
|
|
83
|
+
createWorkspace(request: CreateWorkspaceRequest): Promise<CreateWorkspaceResponse>;
|
|
84
|
+
/**
|
|
85
|
+
* The current workspace's region (add-private-regions): for a private region, the cell's status,
|
|
86
|
+
* version, components, active calls and which secrets it needs and has.
|
|
87
|
+
*
|
|
88
|
+
* @return {Promise<Region>} - The region view
|
|
89
|
+
*/
|
|
90
|
+
getRegion(): Promise<Region>;
|
|
91
|
+
/**
|
|
92
|
+
* Issues a new one-time enrollment token for the current workspace's region (its owner only).
|
|
93
|
+
* Enrolling a cell with it revokes the previous cell's credentials.
|
|
94
|
+
*
|
|
95
|
+
* @return {Promise<RegionEnrollmentToken>} - The token (shown once) and its expiry
|
|
96
|
+
*/
|
|
97
|
+
reissueRegionToken(): Promise<RegionEnrollmentToken>;
|
|
98
|
+
/**
|
|
99
|
+
* Revokes the current workspace's region cell now; it goes back to `waiting` (region owner).
|
|
100
|
+
*/
|
|
101
|
+
disconnectRegion(): Promise<void>;
|
|
83
102
|
/**
|
|
84
103
|
* Retrieves an existing Workspace in the system.
|
|
85
104
|
*
|
package/dist/node/Workspaces.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Workspaces = void 0;
|
|
4
4
|
const makeRpcRequest_1 = require("./client/makeRpcRequest");
|
|
5
5
|
const identity_pb_1 = require("./generated/node/identity_pb");
|
|
6
|
+
const Regions_1 = require("./Regions");
|
|
6
7
|
/**
|
|
7
8
|
* @classdesc Fonoster Workspaces, part of the Fonoster Identity subsystem,
|
|
8
9
|
* allows you to create, update, retrieve, and delete Workspaces in the system.
|
|
@@ -53,7 +54,8 @@ class Workspaces {
|
|
|
53
54
|
*
|
|
54
55
|
* @param {CreateWorkspaceRequest} request - The request object that contains the necessary information to create a new Workspace
|
|
55
56
|
* @param {string} request.name - The name of the Workspace
|
|
56
|
-
* @
|
|
57
|
+
* @param {string} request.region - An offered public region id (default `default`) or one of your private regions (id or ref, see `Regions.createRegion`); fixed for life
|
|
58
|
+
* @return {Promise<CreateWorkspaceResponse>} - The reference and the stored region
|
|
57
59
|
* @example
|
|
58
60
|
* const workspaces = new SDK.Workspaces(client); // Existing client object
|
|
59
61
|
*
|
|
@@ -68,12 +70,37 @@ class Workspaces {
|
|
|
68
70
|
*/
|
|
69
71
|
async createWorkspace(request) {
|
|
70
72
|
const client = this.client.getIdentityClient();
|
|
71
|
-
|
|
73
|
+
const res = await (0, makeRpcRequest_1.makeRpcRequest)({
|
|
72
74
|
method: client.createWorkspace.bind(client),
|
|
73
75
|
requestPBObjectConstructor: identity_pb_1.CreateWorkspaceRequest,
|
|
74
76
|
metadata: this.client.getMetadata(),
|
|
75
77
|
request
|
|
76
78
|
});
|
|
79
|
+
return { ref: res.ref, region: res.region || undefined };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The current workspace's region (add-private-regions): for a private region, the cell's status,
|
|
83
|
+
* version, components, active calls and which secrets it needs and has.
|
|
84
|
+
*
|
|
85
|
+
* @return {Promise<Region>} - The region view
|
|
86
|
+
*/
|
|
87
|
+
async getRegion() {
|
|
88
|
+
return new Regions_1.Regions(this.client).getRegion();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Issues a new one-time enrollment token for the current workspace's region (its owner only).
|
|
92
|
+
* Enrolling a cell with it revokes the previous cell's credentials.
|
|
93
|
+
*
|
|
94
|
+
* @return {Promise<RegionEnrollmentToken>} - The token (shown once) and its expiry
|
|
95
|
+
*/
|
|
96
|
+
async reissueRegionToken() {
|
|
97
|
+
return new Regions_1.Regions(this.client).reissueRegionToken();
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Revokes the current workspace's region cell now; it goes back to `waiting` (region owner).
|
|
101
|
+
*/
|
|
102
|
+
async disconnectRegion() {
|
|
103
|
+
return new Regions_1.Regions(this.client).disconnectRegion();
|
|
77
104
|
}
|
|
78
105
|
/**
|
|
79
106
|
* Retrieves an existing Workspace in the system.
|