@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.
Files changed (91) hide show
  1. package/README.md +12 -9
  2. package/dist/node/Agents.js +5 -20
  3. package/dist/node/Applications.d.ts +21 -85
  4. package/dist/node/Applications.js +64 -74
  5. package/dist/node/Billing.d.ts +50 -0
  6. package/dist/node/Billing.js +84 -0
  7. package/dist/node/CallRecords.d.ts +92 -0
  8. package/dist/node/CallRecords.js +127 -0
  9. package/dist/node/Calls.d.ts +3 -1
  10. package/dist/node/Calls.js +3 -1
  11. package/dist/node/Domains.js +4 -2
  12. package/dist/node/Numbers.js +2 -7
  13. package/dist/node/Providers.d.ts +49 -0
  14. package/dist/node/Providers.js +109 -0
  15. package/dist/node/Regions.d.ts +91 -0
  16. package/dist/node/Regions.js +127 -0
  17. package/dist/node/Usage.d.ts +44 -0
  18. package/dist/node/Usage.js +41 -0
  19. package/dist/node/Users.d.ts +4 -2
  20. package/dist/node/Users.js +4 -2
  21. package/dist/node/Webhooks.d.ts +56 -0
  22. package/dist/node/Webhooks.js +139 -0
  23. package/dist/node/Workspaces.d.ts +22 -3
  24. package/dist/node/Workspaces.js +29 -2
  25. package/dist/node/client/AbstractClient.d.ts +94 -3
  26. package/dist/node/client/AbstractClient.js +101 -1
  27. package/dist/node/client/Client.d.ts +9 -0
  28. package/dist/node/client/Client.js +34 -1
  29. package/dist/node/client/jsonToObject.js +17 -0
  30. package/dist/node/client/objectToJson.js +35 -0
  31. package/dist/node/client/types/ApplicationsClient.d.ts +2 -1
  32. package/dist/node/client/types/BillingClient.d.ts +28 -0
  33. package/dist/node/client/types/BillingClient.js +2 -0
  34. package/dist/node/client/types/CapabilitiesClient.d.ts +24 -0
  35. package/dist/node/client/types/CapabilitiesClient.js +2 -0
  36. package/dist/node/client/types/FonosterClient.d.ts +12 -0
  37. package/dist/node/client/types/IdentityClient.d.ts +3 -1
  38. package/dist/node/client/types/ProvidersClient.d.ts +28 -0
  39. package/dist/node/client/types/ProvidersClient.js +2 -0
  40. package/dist/node/client/types/UsageClient.d.ts +24 -0
  41. package/dist/node/client/types/UsageClient.js +2 -0
  42. package/dist/node/client/types/WebhooksClient.d.ts +31 -0
  43. package/dist/node/client/types/WebhooksClient.js +2 -0
  44. package/dist/node/client/types/index.d.ts +5 -0
  45. package/dist/node/client/types/index.js +5 -0
  46. package/dist/node/generated/node/applications_grpc_pb.js +34 -0
  47. package/dist/node/generated/node/applications_pb.js +2991 -178
  48. package/dist/node/generated/node/billing_grpc_pb.js +169 -0
  49. package/dist/node/generated/node/billing_pb.js +1720 -0
  50. package/dist/node/generated/node/calls_pb.js +62 -2
  51. package/dist/node/generated/node/capabilities_grpc_pb.js +66 -0
  52. package/dist/node/generated/node/capabilities_pb.js +2288 -0
  53. package/dist/node/generated/node/identity_grpc_pb.js +34 -0
  54. package/dist/node/generated/node/identity_pb.js +609 -5
  55. package/dist/node/generated/node/providers_grpc_pb.js +200 -0
  56. package/dist/node/generated/node/providers_pb.js +3094 -0
  57. package/dist/node/generated/node/usage_grpc_pb.js +64 -0
  58. package/dist/node/generated/node/usage_pb.js +866 -0
  59. package/dist/node/generated/node/webhooks_grpc_pb.js +302 -0
  60. package/dist/node/generated/node/webhooks_pb.js +3314 -0
  61. package/dist/node/generated/web/ApplicationsServiceClientPb.ts +43 -0
  62. package/dist/node/generated/web/BillingServiceClientPb.ts +258 -0
  63. package/dist/node/generated/web/CapabilitiesServiceClientPb.ts +87 -0
  64. package/dist/node/generated/web/IdentityServiceClientPb.ts +43 -0
  65. package/dist/node/generated/web/ProvidersServiceClientPb.ts +258 -0
  66. package/dist/node/generated/web/UsageServiceClientPb.ts +86 -0
  67. package/dist/node/generated/web/WebhooksServiceClientPb.ts +387 -0
  68. package/dist/node/generated/web/applications_pb.d.ts +343 -1
  69. package/dist/node/generated/web/applications_pb.js +2991 -178
  70. package/dist/node/generated/web/billing_pb.d.ts +210 -0
  71. package/dist/node/generated/web/billing_pb.js +1720 -0
  72. package/dist/node/generated/web/calls_pb.d.ts +8 -0
  73. package/dist/node/generated/web/calls_pb.js +62 -2
  74. package/dist/node/generated/web/capabilities_pb.d.ts +273 -0
  75. package/dist/node/generated/web/capabilities_pb.js +2288 -0
  76. package/dist/node/generated/web/identity_pb.d.ts +76 -0
  77. package/dist/node/generated/web/identity_pb.js +609 -5
  78. package/dist/node/generated/web/providers_pb.d.ts +372 -0
  79. package/dist/node/generated/web/providers_pb.js +3094 -0
  80. package/dist/node/generated/web/usage_pb.d.ts +106 -0
  81. package/dist/node/generated/web/usage_pb.js +866 -0
  82. package/dist/node/generated/web/webhooks_pb.d.ts +398 -0
  83. package/dist/node/generated/web/webhooks_pb.js +3314 -0
  84. package/dist/node/node.d.ts +7 -0
  85. package/dist/node/node.js +6 -0
  86. package/dist/node/tsconfig.tsbuildinfo +1 -1
  87. package/dist/node/utils.d.ts +7 -12
  88. package/dist/node/utils.js +18 -39
  89. package/dist/web/fonoster.min.js +1 -1
  90. package/dist/web/index.esm.js +1 -1
  91. package/package.json +8 -13
@@ -17,13 +17,75 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  import { ContactType } from "@fonoster/types";
20
- import { ApplicationsClient, CallsClient, FonosterClient, IdentityClient, SecretsClient } from "./types";
20
+ import { GetCapabilitiesResponse as GetCapabilitiesResponsePB } from "../generated/node/capabilities_pb";
21
+ import { ApplicationsClient, CallsClient, CapabilitiesClient, FonosterClient, IdentityClient, SecretsClient } from "./types";
21
22
  import { AclsClient } from "./types/AclsClient";
22
23
  import { AgentsClient } from "./types/AgentsClient";
24
+ import { BillingClient } from "./types/BillingClient";
23
25
  import { CredentialsClient } from "./types/CredentialsClient";
24
26
  import { DomainsClient } from "./types/DomainsClient";
25
27
  import { NumbersClient } from "./types/NumbersClient";
28
+ import { ProvidersClient } from "./types/ProvidersClient";
26
29
  import { TrunksClient } from "./types/TrunksClient";
30
+ import { UsageClient } from "./types/UsageClient";
31
+ import { WebhooksClient } from "./types/WebhooksClient";
32
+ type AuthMethod = "password" | "email_code" | "github";
33
+ /** The deployment's capabilities, from the Capabilities service. */
34
+ type Capabilities = {
35
+ auth: {
36
+ methods: AuthMethod[];
37
+ signup: "invite" | "open";
38
+ github?: {
39
+ clientId: string;
40
+ authorizeUrl: string;
41
+ };
42
+ };
43
+ billing: {
44
+ enabled: boolean;
45
+ };
46
+ costs: {
47
+ display: "none" | "usage" | "prices";
48
+ };
49
+ domain: string;
50
+ appUrl: string;
51
+ /**
52
+ * `private` is true only when the operator configured the region hub, so
53
+ * workspaces can enroll private regions. The local public region always
54
+ * exists and is not a reason to show region features.
55
+ */
56
+ regions: {
57
+ private: boolean;
58
+ };
59
+ /**
60
+ * Where carriers and softphones reach this deployment (its default public
61
+ * region): SIP endpoints, addresses to allowlist and the RTP port range.
62
+ * Empty lists when the operator listed none or the server is older.
63
+ */
64
+ connection: ConnectionDetails;
65
+ /**
66
+ * How SIP names (trunk inbound URIs, domains) are checked: "domain" (one
67
+ * label under `sip.<domain>`, the default) or "any" (any host or IP).
68
+ */
69
+ sip: {
70
+ names: "domain" | "any";
71
+ };
72
+ };
73
+ type SipTransport = "udp" | "tcp" | "tls" | "ws" | "wss";
74
+ type ConnectionDetails = {
75
+ sip: {
76
+ host: string;
77
+ port: number;
78
+ transport: SipTransport;
79
+ }[];
80
+ signalingAddresses: string[];
81
+ mediaAddresses: string[];
82
+ rtpPorts?: {
83
+ min: number;
84
+ max: number;
85
+ };
86
+ };
87
+ /** The Capabilities response's connection details as plain values. */
88
+ declare function toConnectionDetails(response: GetCapabilitiesResponsePB): ConnectionDetails;
27
89
  declare abstract class AbstractClient implements FonosterClient {
28
90
  protected accessKeyId: string;
29
91
  protected _accessToken: string;
@@ -35,10 +97,33 @@ declare abstract class AbstractClient implements FonosterClient {
35
97
  identityClient: IdentityClient;
36
98
  });
37
99
  login(username: string, password: string, twoFactorCode?: string): Promise<void>;
38
- logout(): void;
100
+ /**
101
+ * Signs out: forgets the tokens (right away, before the call returns) and
102
+ * revokes the refresh token on the server, so it can no longer be exchanged.
103
+ * Revocation is best effort: an unreachable server or an already-refused
104
+ * token does not make sign-out fail. Access tokens already issued stay valid
105
+ * until they expire.
106
+ */
107
+ logout(): Promise<void>;
108
+ /**
109
+ * Revokes `refreshToken` and every token rotated from the same sign-in.
110
+ * Needs no access token: holding the refresh token is the authorization.
111
+ */
112
+ revokeToken(refreshToken: string): Promise<void>;
39
113
  loginWithRefreshToken(refreshToken: string): Promise<void>;
40
114
  loginWithApiKey(accessKeyId: string, accessKeySecret: string): Promise<void>;
41
115
  loginWithOauth2Code(provider: "GITHUB", code: string): Promise<void>;
116
+ /**
117
+ * Passwordless sign-in: trades the 6-digit code emailed by
118
+ * `sendVerificationCode(ContactType.EMAIL, email)` for tokens.
119
+ */
120
+ loginWithVerificationCode(email: string, code: string): Promise<void>;
121
+ /**
122
+ * What the deployment supports (from the server's fonoster.yaml): sign-in
123
+ * methods, sign-up policy, the GitHub client id when enabled, billing, cost
124
+ * display, domain and app URL. Needs no credentials.
125
+ */
126
+ getCapabilities(): Promise<Capabilities>;
42
127
  setAccessToken(accessToken: string): void;
43
128
  sendVerificationCode(contactType: ContactType, value: string): Promise<void>;
44
129
  verifyCode(request: {
@@ -56,6 +141,7 @@ declare abstract class AbstractClient implements FonosterClient {
56
141
  abstract getMetadata(): unknown;
57
142
  abstract getApplicationsClient(): ApplicationsClient;
58
143
  abstract getIdentityClient(): IdentityClient;
144
+ abstract getCapabilitiesClient(): CapabilitiesClient;
59
145
  abstract getSecretsClient(): SecretsClient;
60
146
  abstract getAgentsClient(): AgentsClient;
61
147
  abstract getNumbersClient(): NumbersClient;
@@ -64,5 +150,10 @@ declare abstract class AbstractClient implements FonosterClient {
64
150
  abstract getTrunksClient(): TrunksClient;
65
151
  abstract getAclsClient(): AclsClient;
66
152
  abstract getCallsClient(): CallsClient;
153
+ abstract getWebhooksClient(): WebhooksClient;
154
+ abstract getProvidersClient(): ProvidersClient;
155
+ abstract getUsageClient(): UsageClient;
156
+ abstract getBillingClient(): BillingClient;
157
+ abstract getHttpUrl(): string;
67
158
  }
68
- export { AbstractClient };
159
+ export { AbstractClient, AuthMethod, Capabilities, ConnectionDetails, toConnectionDetails };
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractClient = void 0;
4
+ exports.toConnectionDetails = toConnectionDetails;
5
+ const empty_pb_1 = require("google-protobuf/google/protobuf/empty_pb");
4
6
  const identity_pb_1 = require("../generated/node/identity_pb");
5
7
  const makeRpcRequest_1 = require("./makeRpcRequest");
8
+ /** The Capabilities response's connection details as plain values. */
9
+ function toConnectionDetails(response) {
10
+ const c = response.getConnection();
11
+ const ports = c?.getRtpPorts();
12
+ return {
13
+ sip: (c?.getSipList() ?? []).map((s) => ({
14
+ host: s.getHost(),
15
+ port: s.getPort(),
16
+ transport: s.getTransport()
17
+ })),
18
+ signalingAddresses: c?.getSignalingAddressesList() ?? [],
19
+ mediaAddresses: c?.getMediaAddressesList() ?? [],
20
+ rtpPorts: ports ? { min: ports.getMin(), max: ports.getMax() } : undefined
21
+ };
22
+ }
6
23
  class AbstractClient {
7
24
  accessKeyId;
8
25
  _accessToken;
@@ -31,10 +48,33 @@ class AbstractClient {
31
48
  this._accessToken = accessToken;
32
49
  this._idToken = idToken;
33
50
  }
34
- logout() {
51
+ /**
52
+ * Signs out: forgets the tokens (right away, before the call returns) and
53
+ * revokes the refresh token on the server, so it can no longer be exchanged.
54
+ * Revocation is best effort: an unreachable server or an already-refused
55
+ * token does not make sign-out fail. Access tokens already issued stay valid
56
+ * until they expire.
57
+ */
58
+ async logout() {
59
+ const refreshToken = this._refreshToken;
35
60
  this._refreshToken = "";
36
61
  this._accessToken = "";
37
62
  this._idToken = "";
63
+ if (!refreshToken)
64
+ return;
65
+ await this.revokeToken(refreshToken).catch(() => undefined);
66
+ }
67
+ /**
68
+ * Revokes `refreshToken` and every token rotated from the same sign-in.
69
+ * Needs no access token: holding the refresh token is the authorization.
70
+ */
71
+ async revokeToken(refreshToken) {
72
+ await (0, makeRpcRequest_1.makeRpcRequest)({
73
+ method: this.identityClient.revokeToken.bind(this.identityClient),
74
+ requestPBObjectConstructor: identity_pb_1.RevokeTokenRequest,
75
+ metadata: {},
76
+ request: { token: refreshToken }
77
+ });
38
78
  }
39
79
  async loginWithRefreshToken(refreshToken) {
40
80
  const { accessToken, refreshToken: newRefreshToken, idToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
@@ -77,6 +117,66 @@ class AbstractClient {
77
117
  this._accessToken = accessToken;
78
118
  this._idToken = idToken;
79
119
  }
120
+ /**
121
+ * Passwordless sign-in: trades the 6-digit code emailed by
122
+ * `sendVerificationCode(ContactType.EMAIL, email)` for tokens.
123
+ */
124
+ async loginWithVerificationCode(email, code) {
125
+ const { refreshToken, accessToken, idToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
126
+ method: this.identityClient.exchangeVerificationCode.bind(this.identityClient),
127
+ requestPBObjectConstructor: identity_pb_1.ExchangeVerificationCodeRequest,
128
+ metadata: {},
129
+ request: { email, code }
130
+ });
131
+ this._refreshToken = refreshToken;
132
+ this._accessToken = accessToken;
133
+ this._idToken = idToken;
134
+ }
135
+ /**
136
+ * What the deployment supports (from the server's fonoster.yaml): sign-in
137
+ * methods, sign-up policy, the GitHub client id when enabled, billing, cost
138
+ * display, domain and app URL. Needs no credentials.
139
+ */
140
+ async getCapabilities() {
141
+ return new Promise((resolve, reject) => {
142
+ this.getCapabilitiesClient().getCapabilities(new empty_pb_1.Empty(), {}, (error, response) => {
143
+ if (error) {
144
+ reject(error);
145
+ return;
146
+ }
147
+ const auth = response.getAuth();
148
+ const github = auth?.getGithub();
149
+ resolve({
150
+ auth: {
151
+ methods: (auth?.getMethodsList() ?? []),
152
+ signup: (auth?.getSignup() ||
153
+ "invite"),
154
+ github: github
155
+ ? {
156
+ clientId: github.getClientId(),
157
+ authorizeUrl: github.getAuthorizeUrl()
158
+ }
159
+ : undefined
160
+ },
161
+ billing: { enabled: response.getBilling()?.getEnabled() ?? false },
162
+ costs: {
163
+ display: (response.getCosts()?.getDisplay() ||
164
+ "none")
165
+ },
166
+ domain: response.getDomain(),
167
+ appUrl: response.getAppUrl(),
168
+ regions: {
169
+ private: response.getRegions()?.getPrivate() ?? false
170
+ },
171
+ connection: toConnectionDetails(response),
172
+ sip: {
173
+ // Older servers don't send it; they checked nothing.
174
+ names: response.getSip()?.getNames() === "domain" ? "domain" : "any"
175
+ }
176
+ });
177
+ });
178
+ });
179
+ }
80
180
  setAccessToken(accessToken) {
81
181
  this._accessToken = accessToken;
82
182
  }
@@ -20,6 +20,7 @@ import { Metadata } from "@grpc/grpc-js";
20
20
  import { AbstractClient } from "./AbstractClient";
21
21
  export declare class Client extends AbstractClient {
22
22
  private readonly endpoint;
23
+ private readonly httpUrl?;
23
24
  private readonly tokenRefresherInterceptor;
24
25
  private readonly channelCredentials;
25
26
  constructor(config?: {
@@ -27,16 +28,24 @@ export declare class Client extends AbstractClient {
27
28
  accessKeyId: string;
28
29
  allowInsecure?: boolean;
29
30
  withoutInterceptors?: boolean;
31
+ /** The HTTP API (call records); default https://<endpoint host>. */
32
+ httpUrl?: string;
30
33
  });
31
34
  getMetadata(): Metadata;
32
35
  getApplicationsClient(): any;
33
36
  getCallsClient(): any;
34
37
  getIdentityClient(): any;
38
+ getCapabilitiesClient(): any;
35
39
  getSecretsClient(): any;
36
40
  getAgentsClient(): any;
37
41
  getAclsClient(): any;
38
42
  getDomainsClient(): any;
39
43
  getTrunksClient(): any;
40
44
  getNumbersClient(): any;
45
+ getWebhooksClient(): any;
46
+ getProvidersClient(): any;
47
+ getUsageClient(): any;
48
+ getBillingClient(): any;
49
+ getHttpUrl(): string;
41
50
  getCredentialsClient(): any;
42
51
  }
@@ -23,18 +23,24 @@ const grpc_js_1 = require("@grpc/grpc-js");
23
23
  const acls_grpc_pb_1 = require("../generated/node/acls_grpc_pb");
24
24
  const agents_grpc_pb_1 = require("../generated/node/agents_grpc_pb");
25
25
  const applications_grpc_pb_1 = require("../generated/node/applications_grpc_pb");
26
+ const billing_grpc_pb_1 = require("../generated/node/billing_grpc_pb");
26
27
  const calls_grpc_pb_1 = require("../generated/node/calls_grpc_pb");
28
+ const capabilities_grpc_pb_1 = require("../generated/node/capabilities_grpc_pb");
27
29
  const credentials_grpc_pb_1 = require("../generated/node/credentials_grpc_pb");
28
30
  const domains_grpc_pb_1 = require("../generated/node/domains_grpc_pb");
29
31
  const identity_grpc_pb_1 = require("../generated/node/identity_grpc_pb");
30
32
  const numbers_grpc_pb_1 = require("../generated/node/numbers_grpc_pb");
33
+ const providers_grpc_pb_1 = require("../generated/node/providers_grpc_pb");
31
34
  const secrets_grpc_pb_1 = require("../generated/node/secrets_grpc_pb");
32
35
  const trunks_grpc_pb_1 = require("../generated/node/trunks_grpc_pb");
36
+ const usage_grpc_pb_1 = require("../generated/node/usage_grpc_pb");
37
+ const webhooks_grpc_pb_1 = require("../generated/node/webhooks_grpc_pb");
33
38
  const AbstractClient_1 = require("./AbstractClient");
34
39
  const TokenRefresherNode_1 = require("./TokenRefresherNode");
35
- const DEFAULT_ENDPOINT = "api.fonoster.com";
40
+ const DEFAULT_ENDPOINT = "api.fonoster.ai";
36
41
  class Client extends AbstractClient_1.AbstractClient {
37
42
  endpoint;
43
+ httpUrl;
38
44
  tokenRefresherInterceptor;
39
45
  channelCredentials;
40
46
  constructor(config = {
@@ -52,6 +58,7 @@ class Client extends AbstractClient_1.AbstractClient {
52
58
  });
53
59
  this.channelCredentials = channelCredentials;
54
60
  this.endpoint = config?.endpoint ?? DEFAULT_ENDPOINT;
61
+ this.httpUrl = config?.httpUrl;
55
62
  this.tokenRefresherInterceptor = config.withoutInterceptors
56
63
  ? null
57
64
  : new TokenRefresherNode_1.TokenRefresherNode(this).createInterceptor().bind(this);
@@ -75,6 +82,9 @@ class Client extends AbstractClient_1.AbstractClient {
75
82
  getIdentityClient() {
76
83
  return new identity_grpc_pb_1.IdentityClient(this.endpoint, this.channelCredentials);
77
84
  }
85
+ getCapabilitiesClient() {
86
+ return new capabilities_grpc_pb_1.CapabilitiesClient(this.endpoint, this.channelCredentials);
87
+ }
78
88
  getSecretsClient() {
79
89
  return new secrets_grpc_pb_1.SecretsClient(this.endpoint, this.channelCredentials, {
80
90
  interceptors: [this.tokenRefresherInterceptor]
@@ -105,6 +115,29 @@ class Client extends AbstractClient_1.AbstractClient {
105
115
  interceptors: [this.tokenRefresherInterceptor]
106
116
  });
107
117
  }
118
+ getWebhooksClient() {
119
+ return new webhooks_grpc_pb_1.WebhooksClient(this.endpoint, this.channelCredentials, {
120
+ interceptors: [this.tokenRefresherInterceptor]
121
+ });
122
+ }
123
+ getProvidersClient() {
124
+ return new providers_grpc_pb_1.ProvidersClient(this.endpoint, this.channelCredentials, {
125
+ interceptors: [this.tokenRefresherInterceptor]
126
+ });
127
+ }
128
+ getUsageClient() {
129
+ return new usage_grpc_pb_1.UsageClient(this.endpoint, this.channelCredentials, {
130
+ interceptors: [this.tokenRefresherInterceptor]
131
+ });
132
+ }
133
+ getBillingClient() {
134
+ return new billing_grpc_pb_1.BillingClient(this.endpoint, this.channelCredentials, {
135
+ interceptors: [this.tokenRefresherInterceptor]
136
+ });
137
+ }
138
+ getHttpUrl() {
139
+ return (this.httpUrl ?? `https://${this.endpoint.replace(/:\d+$/, "")}`).replace(/\/+$/, "");
140
+ }
108
141
  getCredentialsClient() {
109
142
  return new credentials_grpc_pb_1.CredentialsServiceClient(this.endpoint, this.channelCredentials, {
110
143
  interceptors: [this.tokenRefresherInterceptor]
@@ -10,6 +10,23 @@ function jsonToObject(params) {
10
10
  if (json[key] === null || json[key] === undefined) {
11
11
  return;
12
12
  }
13
+ // Repeated fields have "List" setters (setEgressPoliciesList); objects in
14
+ // them are built with the constructor from objectMapping.
15
+ const listSetterName = `${setterName}List`;
16
+ if (Array.isArray(json[key]) &&
17
+ typeof instance[listSetterName] === "function") {
18
+ const constructor = objectMapping?.find((tuple) => tuple[0] === key)?.[1];
19
+ const items = constructor
20
+ ? json[key].map((item) => jsonToObject({
21
+ json: item,
22
+ objectConstructor: constructor,
23
+ enumMapping,
24
+ objectMapping
25
+ }))
26
+ : json[key];
27
+ instance[listSetterName](items);
28
+ return;
29
+ }
13
30
  if ((0, utils_1.isMapping)(key, enumMapping)) {
14
31
  const enumValue = (0, utils_1.getEnumValue)(key, json[key], enumMapping);
15
32
  instance[setterName](enumValue);
@@ -2,6 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.objectToJson = objectToJson;
4
4
  const utils_1 = require("./utils");
5
+ /**
6
+ * A protobuf message to flatten. google.protobuf.Struct values (they have
7
+ * toJavaScript) are left as they are: callers convert them with toJavaScript().
8
+ */
9
+ function isMessage(value) {
10
+ return (value !== null &&
11
+ typeof value === "object" &&
12
+ typeof value.toObject === "function" &&
13
+ typeof value.toJavaScript !== "function");
14
+ }
15
+ /** protobuf toObject() names repeated fields "xList"; the SDK's types say "x". */
16
+ function withoutListSuffix(value) {
17
+ if (Array.isArray(value))
18
+ return value.map(withoutListSuffix);
19
+ if (value === null || typeof value !== "object")
20
+ return value;
21
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
22
+ key.endsWith("List") && Array.isArray(item) ? key.slice(0, -4) : key,
23
+ withoutListSuffix(item)
24
+ ]));
25
+ }
26
+ function plainMessage(message) {
27
+ return withoutListSuffix(message.toObject());
28
+ }
5
29
  function objectToJson(obj, enumMapping, objectMapping, repeatableObjectMapping) {
6
30
  const json = {};
7
31
  const includeEmptyStringProps = new Set(["nextPageToken"]);
@@ -29,6 +53,17 @@ function objectToJson(obj, enumMapping, objectMapping, repeatableObjectMapping)
29
53
  const repeatableKey = propName.slice(0, -4);
30
54
  json[repeatableKey] = value.map((item) => objectToJson(item, enumMapping, objectMapping, repeatableObjectMapping));
31
55
  }
56
+ else if (isMessage(value)) {
57
+ // A nested message without an explicit mapping (e.g. a domain's
58
+ // accessControlList): return it as a plain object, not a raw message.
59
+ json[propName] = plainMessage(value);
60
+ }
61
+ else if (propName.endsWith("List") &&
62
+ Array.isArray(value) &&
63
+ value.length > 0 &&
64
+ value.every(isMessage)) {
65
+ json[propName.slice(0, -4)] = value.map(plainMessage);
66
+ }
32
67
  else if (value !== undefined) {
33
68
  if (["createdAt", "updatedAt", "startedAt", "endedAt"].includes(propName)) {
34
69
  json[propName] = new Date(value * 1000);
@@ -17,7 +17,7 @@
17
17
  * limitations under the License.
18
18
  */
19
19
  import { Empty } from "google-protobuf/google/protobuf/empty_pb";
20
- import { Application, CreateApplicationRequest, CreateApplicationResponse, DeleteApplicationRequest, DeleteApplicationResponse, EvaluateIntelligenceEvent, EvaluateIntelligenceRequest, GetApplicationRequest, ListApplicationsRequest, ListApplicationsResponse, TestTokenResponse, UpdateApplicationRequest, UpdateApplicationResponse } from "../../generated/web/applications_pb";
20
+ import { Application, CreateApplicationRequest, CreateApplicationResponse, DeleteApplicationRequest, DeleteApplicationResponse, EvaluateIntelligenceEvent, EvaluateIntelligenceRequest, GetApplicationRequest, ListApplicationsRequest, ListApplicationsResponse, RotateSigningSecretRequest, RotateSigningSecretResponse, TestTokenResponse, UpdateApplicationRequest, UpdateApplicationResponse } from "../../generated/web/applications_pb";
21
21
  import { ClientFunction } from "./common";
22
22
  import type { ClientReadableStream } from "grpc-web";
23
23
  type ApplicationsClient = {
@@ -28,5 +28,6 @@ type ApplicationsClient = {
28
28
  deleteApplication: ClientFunction<DeleteApplicationRequest, DeleteApplicationResponse>;
29
29
  evaluateIntelligence: (request: EvaluateIntelligenceRequest, metadata?: Record<string, string> | null) => ClientReadableStream<EvaluateIntelligenceEvent>;
30
30
  createTestToken: ClientFunction<Empty, TestTokenResponse>;
31
+ rotateSigningSecret: ClientFunction<RotateSigningSecretRequest, RotateSigningSecretResponse>;
31
32
  };
32
33
  export { ApplicationsClient };
@@ -0,0 +1,28 @@
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 { BillingSummary, CreatePortalSessionRequest, CreatePortalSessionResponse, CreateTopUpRequest, GetBillingRequest, SubscribeRequest, UpdateAutoRechargeRequest } from "../../generated/web/billing_pb";
20
+ import { ClientFunction } from "./common";
21
+ type BillingClient = {
22
+ getBilling: ClientFunction<GetBillingRequest, BillingSummary>;
23
+ updateAutoRecharge: ClientFunction<UpdateAutoRechargeRequest, BillingSummary>;
24
+ createTopUp: ClientFunction<CreateTopUpRequest, BillingSummary>;
25
+ subscribe: ClientFunction<SubscribeRequest, BillingSummary>;
26
+ createPortalSession: ClientFunction<CreatePortalSessionRequest, CreatePortalSessionResponse>;
27
+ };
28
+ export { BillingClient };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
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 { GetCapabilitiesResponse } from "../../generated/web/capabilities_pb";
20
+ import { ClientFunction } from "./common";
21
+ type CapabilitiesClient = {
22
+ getCapabilities: ClientFunction<unknown, GetCapabilitiesResponse>;
23
+ };
24
+ export { CapabilitiesClient };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -19,19 +19,25 @@
19
19
  import { AclsClient } from "./AclsClient";
20
20
  import { AgentsClient } from "./AgentsClient";
21
21
  import { ApplicationsClient } from "./ApplicationsClient";
22
+ import { BillingClient } from "./BillingClient";
22
23
  import { CallsClient } from "./CallsClient";
24
+ import { CapabilitiesClient } from "./CapabilitiesClient";
23
25
  import { CredentialsClient } from "./CredentialsClient";
24
26
  import { DomainsClient } from "./DomainsClient";
25
27
  import { IdentityClient } from "./IdentityClient";
26
28
  import { NumbersClient } from "./NumbersClient";
29
+ import { ProvidersClient } from "./ProvidersClient";
27
30
  import { SecretsClient } from "./SecretsClient";
28
31
  import { TrunksClient } from "./TrunksClient";
32
+ import { UsageClient } from "./UsageClient";
33
+ import { WebhooksClient } from "./WebhooksClient";
29
34
  interface FonosterClient {
30
35
  getAccessToken(): string;
31
36
  getAccessKeyId(): string;
32
37
  getApplicationsClient(): ApplicationsClient;
33
38
  getCallsClient(): CallsClient;
34
39
  getIdentityClient(): IdentityClient;
40
+ getCapabilitiesClient(): CapabilitiesClient;
35
41
  getSecretsClient(): SecretsClient;
36
42
  getAgentsClient(): AgentsClient;
37
43
  getNumbersClient(): NumbersClient;
@@ -39,6 +45,12 @@ interface FonosterClient {
39
45
  getDomainsClient(): DomainsClient;
40
46
  getTrunksClient(): TrunksClient;
41
47
  getAclsClient(): AclsClient;
48
+ getWebhooksClient(): WebhooksClient;
49
+ getProvidersClient(): ProvidersClient;
50
+ getUsageClient(): UsageClient;
51
+ getBillingClient(): BillingClient;
52
+ /** Base URL of the HTTP API (/api/records), e.g. https://api.fonoster.ai. */
53
+ getHttpUrl?(): string;
42
54
  getMetadata(): unknown;
43
55
  refreshToken(): Promise<void>;
44
56
  }
@@ -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 { CreateApiKeyRequest, CreateApiKeyResponse, CreateUserRequest, CreateUserResponse, CreateUserWithOauth2CodeRequest, CreateWorkspaceRequest, DeleteApiKeyRequest, DeleteApiKeyResponse, DeleteUserRequest, DeleteUserResponse, DeleteWorkspaceRequest, DeleteWorkspaceResponse, ExchangeApiKeyRequest, ExchangeApiKeyResponse, ExchangeCredentialsRequest, ExchangeCredentialsResponse, ExchangeOauth2CodeRequest, ExchangeOauth2CodeResponse, ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse, GetUserRequest, GetWorkspaceRequest, InviteUserToWorkspaceRequest, InviteUserToWorkspaceResponse, ListApiKeysRequest, ListApiKeysResponse, ListWorkspaceMembersRequest, ListWorkspaceMembersResponse, ListWorkspacesRequest, ListWorkspacesResponse, RegenerateApiKeyRequest, RegenerateApiKeyResponse, RemoveUserFromWorkspaceRequest, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationRequest, ResendWorkspaceMembershipInvitationResponse, ResetPasswordRequest, SendResetPasswordCodeRequest, SendVerificationCodeRequest, UpdateUserRequest, UpdateWorkspaceRequest, UpdateWorkspaceResponse, User, VerifyCodeRequest, Workspace } from "../../generated/web/identity_pb";
19
+ import { CreateApiKeyRequest, CreateApiKeyResponse, CreateUserRequest, CreateUserResponse, CreateUserWithOauth2CodeRequest, CreateWorkspaceRequest, DeleteApiKeyRequest, DeleteApiKeyResponse, DeleteUserRequest, DeleteUserResponse, DeleteWorkspaceRequest, DeleteWorkspaceResponse, ExchangeApiKeyRequest, ExchangeApiKeyResponse, ExchangeCredentialsRequest, ExchangeCredentialsResponse, ExchangeOauth2CodeRequest, ExchangeOauth2CodeResponse, ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse, ExchangeVerificationCodeRequest, ExchangeVerificationCodeResponse, GetUserRequest, GetWorkspaceRequest, InviteUserToWorkspaceRequest, InviteUserToWorkspaceResponse, ListApiKeysRequest, ListApiKeysResponse, ListWorkspaceMembersRequest, ListWorkspaceMembersResponse, ListWorkspacesRequest, ListWorkspacesResponse, RegenerateApiKeyRequest, RegenerateApiKeyResponse, RemoveUserFromWorkspaceRequest, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationRequest, ResendWorkspaceMembershipInvitationResponse, ResetPasswordRequest, RevokeTokenRequest, RevokeTokenResponse, SendResetPasswordCodeRequest, SendVerificationCodeRequest, UpdateUserRequest, UpdateWorkspaceRequest, UpdateWorkspaceResponse, User, VerifyCodeRequest, Workspace } from "../../generated/web/identity_pb";
20
20
  import { ClientFunction } from "../types";
21
21
  type IdentityClient = {
22
22
  createApiKey: ClientFunction<CreateApiKeyRequest, CreateApiKeyResponse>;
@@ -27,6 +27,8 @@ type IdentityClient = {
27
27
  exchangeCredentials: ClientFunction<ExchangeCredentialsRequest, ExchangeCredentialsResponse>;
28
28
  exchangeOauth2Code: ClientFunction<ExchangeOauth2CodeRequest, ExchangeOauth2CodeResponse>;
29
29
  exchangeRefreshToken: ClientFunction<ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse>;
30
+ exchangeVerificationCode: ClientFunction<ExchangeVerificationCodeRequest, ExchangeVerificationCodeResponse>;
31
+ revokeToken: ClientFunction<RevokeTokenRequest, RevokeTokenResponse>;
30
32
  createUser: ClientFunction<CreateUserRequest, CreateUserResponse>;
31
33
  createUserWithOauth2Code: ClientFunction<CreateUserWithOauth2CodeRequest, ExchangeCredentialsResponse>;
32
34
  getUser: ClientFunction<GetUserRequest, User>;
@@ -0,0 +1,28 @@
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 { DeleteProviderKeyRequest, DeleteProviderKeyResponse, ListCatalogRequest, ListCatalogResponse, ListProviderKeysRequest, ListProviderKeysResponse, ListWarningsRequest, ListWarningsResponse, ProviderKey, SetProviderKeyRequest } from "../../generated/web/providers_pb";
20
+ import { ClientFunction } from "./common";
21
+ type ProvidersClient = {
22
+ listCatalog: ClientFunction<ListCatalogRequest, ListCatalogResponse>;
23
+ setProviderKey: ClientFunction<SetProviderKeyRequest, ProviderKey>;
24
+ listProviderKeys: ClientFunction<ListProviderKeysRequest, ListProviderKeysResponse>;
25
+ deleteProviderKey: ClientFunction<DeleteProviderKeyRequest, DeleteProviderKeyResponse>;
26
+ listWarnings: ClientFunction<ListWarningsRequest, ListWarningsResponse>;
27
+ };
28
+ export { ProvidersClient };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,24 @@
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 "../../generated/web/usage_pb";
20
+ import { ClientFunction } from "./common";
21
+ type UsageClient = {
22
+ getUsage: ClientFunction<GetUsageRequest, GetUsageResponse>;
23
+ };
24
+ export { UsageClient };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });