@fonoster/sdk 0.7.22 → 0.7.25

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.
@@ -1,3 +1,4 @@
1
+ import { ContactType } from "@fonoster/types";
1
2
  import { ApplicationsClient, CallsClient, FonosterClient, IdentityClient, SecretsClient } from "./types";
2
3
  import { AclsClient } from "./types/AclsClient";
3
4
  import { AgentsClient } from "./types/AgentsClient";
@@ -14,9 +15,17 @@ declare abstract class AbstractClient implements FonosterClient {
14
15
  accessKeyId: string;
15
16
  identityClient: IdentityClient;
16
17
  });
17
- login(username: string, password: string): Promise<void>;
18
+ login(username: string, password: string, verificationCode?: string): Promise<void>;
18
19
  loginWithRefreshToken(refreshToken: string): Promise<void>;
19
20
  loginWithApiKey(apiKey: string): Promise<void>;
21
+ loginWithOauth2Code(provider: "GITHUB", username: string, code: string): Promise<void>;
22
+ sendVerificationCode(contactType: ContactType, value: string): Promise<void>;
23
+ verifyCode(request: {
24
+ username: string;
25
+ contactType: ContactType;
26
+ value: string;
27
+ verificationCode: string;
28
+ }): Promise<void>;
20
29
  refreshToken(): Promise<void>;
21
30
  getAccessKeyId(): string;
22
31
  getAccessToken(): string;
@@ -1,24 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractClient = void 0;
4
- /*
5
- * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
4
  const makeRpcRequest_1 = require("./makeRpcRequest");
23
5
  const identity_pb_1 = require("../generated/node/identity_pb");
24
6
  class AbstractClient {
@@ -32,14 +14,15 @@ class AbstractClient {
32
14
  this._accessToken = "";
33
15
  this._refreshToken = "";
34
16
  }
35
- async login(username, password) {
17
+ async login(username, password, verificationCode) {
36
18
  const { refreshToken, accessToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
37
19
  method: this.identityClient.exchangeCredentials.bind(this.identityClient),
38
20
  requestPBObjectConstructor: identity_pb_1.ExchangeCredentialsRequest,
39
21
  metadata: {},
40
22
  request: {
41
23
  username,
42
- password
24
+ password,
25
+ verificationCode
43
26
  }
44
27
  });
45
28
  this._refreshToken = refreshToken;
@@ -69,6 +52,41 @@ class AbstractClient {
69
52
  this._refreshToken = refreshToken;
70
53
  this._accessToken = accessToken;
71
54
  }
55
+ async loginWithOauth2Code(provider, username, code) {
56
+ const { refreshToken, accessToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
57
+ method: this.identityClient.exchangeOauth2Code,
58
+ requestPBObjectConstructor: identity_pb_1.ExchangeOauth2CodeRequest,
59
+ metadata: {},
60
+ request: {
61
+ provider,
62
+ username,
63
+ code
64
+ }
65
+ });
66
+ this._refreshToken = refreshToken;
67
+ this._accessToken = accessToken;
68
+ }
69
+ async sendVerificationCode(contactType, value) {
70
+ await (0, makeRpcRequest_1.makeRpcRequest)({
71
+ method: this.identityClient.sendVerificationCode.bind(this.identityClient),
72
+ requestPBObjectConstructor: identity_pb_1.SendVerificationCodeRequest,
73
+ metadata: {},
74
+ request: {
75
+ contactType: contactType,
76
+ value
77
+ },
78
+ enumMapping: [["contactType", identity_pb_1.ContactType]]
79
+ });
80
+ }
81
+ async verifyCode(request) {
82
+ await (0, makeRpcRequest_1.makeRpcRequest)({
83
+ method: this.identityClient.verifyCode.bind(this.identityClient),
84
+ requestPBObjectConstructor: identity_pb_1.VerifyCodeRequest,
85
+ metadata: {},
86
+ request,
87
+ enumMapping: [["contactType", identity_pb_1.ContactType]]
88
+ });
89
+ }
72
90
  async refreshToken() {
73
91
  return await this.loginWithRefreshToken(this._refreshToken);
74
92
  }
@@ -1,4 +1,4 @@
1
- import { CreateApiKeyRequest, CreateApiKeyResponse, CreateUserRequest, CreateUserResponse, CreateWorkspaceRequest, DeleteApiKeyRequest, DeleteApiKeyResponse, DeleteUserRequest, DeleteUserResponse, DeleteWorkspaceRequest, DeleteWorkspaceResponse, ExchangeApiKeyRequest, ExchangeApiKeyResponse, ExchangeCredentialsRequest, ExchangeCredentialsResponse, ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse, GetUserRequest, GetWorkspaceRequest, InviteUserToWorkspaceRequest, InviteUserToWorkspaceResponse, ListApiKeysRequest, ListApiKeysResponse, ListWorkspacesRequest, ListWorkspacesResponse, RegenerateApiKeyRequest, RegenerateApiKeyResponse, RemoveUserFromWorkspaceRequest, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationRequest, ResendWorkspaceMembershipInvitationResponse, UpdateUserRequest, UpdateWorkspaceRequest, UpdateWorkspaceResponse, User, Workspace } from "../../generated/web/identity_pb";
1
+ import { CreateApiKeyRequest, CreateApiKeyResponse, CreateUserRequest, CreateUserResponse, CreateWorkspaceRequest, DeleteApiKeyRequest, DeleteApiKeyResponse, DeleteUserRequest, DeleteUserResponse, DeleteWorkspaceRequest, DeleteWorkspaceResponse, ExchangeApiKeyRequest, ExchangeApiKeyResponse, ExchangeCredentialsRequest, ExchangeCredentialsResponse, ExchangeOauth2CodeRequest, ExchangeOauth2CodeResponse, ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse, GetUserRequest, GetWorkspaceRequest, InviteUserToWorkspaceRequest, InviteUserToWorkspaceResponse, ListApiKeysRequest, ListApiKeysResponse, ListWorkspacesRequest, ListWorkspacesResponse, RegenerateApiKeyRequest, RegenerateApiKeyResponse, RemoveUserFromWorkspaceRequest, RemoveUserFromWorkspaceResponse, ResendWorkspaceMembershipInvitationRequest, ResendWorkspaceMembershipInvitationResponse, SendVerificationCodeRequest, UpdateUserRequest, UpdateWorkspaceRequest, UpdateWorkspaceResponse, User, VerifyCodeRequest, Workspace } from "../../generated/web/identity_pb";
2
2
  import { ClientFunction } from "../types";
3
3
  type IdentityClient = {
4
4
  createApiKey: ClientFunction<CreateApiKeyRequest, CreateApiKeyResponse>;
@@ -7,11 +7,14 @@ type IdentityClient = {
7
7
  deleteApiKey: ClientFunction<DeleteApiKeyRequest, DeleteApiKeyResponse>;
8
8
  exchangeApiKey: ClientFunction<ExchangeApiKeyRequest, ExchangeApiKeyResponse>;
9
9
  exchangeCredentials: ClientFunction<ExchangeCredentialsRequest, ExchangeCredentialsResponse>;
10
+ exchangeOauth2Code: ClientFunction<ExchangeOauth2CodeRequest, ExchangeOauth2CodeResponse>;
10
11
  exchangeRefreshToken: ClientFunction<ExchangeRefreshTokenRequest, ExchangeRefreshTokenResponse>;
11
12
  createUser: ClientFunction<CreateUserRequest, CreateUserResponse>;
12
13
  getUser: ClientFunction<GetUserRequest, User>;
13
14
  updateUser: ClientFunction<UpdateUserRequest, CreateUserResponse>;
14
15
  deleteUser: ClientFunction<DeleteUserRequest, DeleteUserResponse>;
16
+ sendVerificationCode: ClientFunction<SendVerificationCodeRequest, never>;
17
+ verifyCode: ClientFunction<VerifyCodeRequest, never>;
15
18
  createWorkspace: ClientFunction<CreateWorkspaceRequest, CreateUserResponse>;
16
19
  getWorkspace: ClientFunction<GetWorkspaceRequest, Workspace>;
17
20
  listWorkspaces: ClientFunction<ListWorkspacesRequest, ListWorkspacesResponse>;
@@ -199,26 +199,26 @@ function deserialize_fonoster_identity_v1beta2_ExchangeCredentialsResponse(buffe
199
199
  return identity_pb.ExchangeCredentialsResponse.deserializeBinary(new Uint8Array(buffer_arg));
200
200
  }
201
201
 
202
- function serialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeRequest(arg) {
203
- if (!(arg instanceof identity_pb.ExchangeOAuth2CodeRequest)) {
204
- throw new Error('Expected argument of type fonoster.identity.v1beta2.ExchangeOAuth2CodeRequest');
202
+ function serialize_fonoster_identity_v1beta2_ExchangeOauth2CodeRequest(arg) {
203
+ if (!(arg instanceof identity_pb.ExchangeOauth2CodeRequest)) {
204
+ throw new Error('Expected argument of type fonoster.identity.v1beta2.ExchangeOauth2CodeRequest');
205
205
  }
206
206
  return Buffer.from(arg.serializeBinary());
207
207
  }
208
208
 
209
- function deserialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeRequest(buffer_arg) {
210
- return identity_pb.ExchangeOAuth2CodeRequest.deserializeBinary(new Uint8Array(buffer_arg));
209
+ function deserialize_fonoster_identity_v1beta2_ExchangeOauth2CodeRequest(buffer_arg) {
210
+ return identity_pb.ExchangeOauth2CodeRequest.deserializeBinary(new Uint8Array(buffer_arg));
211
211
  }
212
212
 
213
- function serialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeResponse(arg) {
214
- if (!(arg instanceof identity_pb.ExchangeOAuth2CodeResponse)) {
215
- throw new Error('Expected argument of type fonoster.identity.v1beta2.ExchangeOAuth2CodeResponse');
213
+ function serialize_fonoster_identity_v1beta2_ExchangeOauth2CodeResponse(arg) {
214
+ if (!(arg instanceof identity_pb.ExchangeOauth2CodeResponse)) {
215
+ throw new Error('Expected argument of type fonoster.identity.v1beta2.ExchangeOauth2CodeResponse');
216
216
  }
217
217
  return Buffer.from(arg.serializeBinary());
218
218
  }
219
219
 
220
- function deserialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeResponse(buffer_arg) {
221
- return identity_pb.ExchangeOAuth2CodeResponse.deserializeBinary(new Uint8Array(buffer_arg));
220
+ function deserialize_fonoster_identity_v1beta2_ExchangeOauth2CodeResponse(buffer_arg) {
221
+ return identity_pb.ExchangeOauth2CodeResponse.deserializeBinary(new Uint8Array(buffer_arg));
222
222
  }
223
223
 
224
224
  function serialize_fonoster_identity_v1beta2_ExchangeRefreshTokenRequest(arg) {
@@ -430,6 +430,17 @@ function deserialize_fonoster_identity_v1beta2_RevokeTokenResponse(buffer_arg) {
430
430
  return identity_pb.RevokeTokenResponse.deserializeBinary(new Uint8Array(buffer_arg));
431
431
  }
432
432
 
433
+ function serialize_fonoster_identity_v1beta2_SendVerificationCodeRequest(arg) {
434
+ if (!(arg instanceof identity_pb.SendVerificationCodeRequest)) {
435
+ throw new Error('Expected argument of type fonoster.identity.v1beta2.SendVerificationCodeRequest');
436
+ }
437
+ return Buffer.from(arg.serializeBinary());
438
+ }
439
+
440
+ function deserialize_fonoster_identity_v1beta2_SendVerificationCodeRequest(buffer_arg) {
441
+ return identity_pb.SendVerificationCodeRequest.deserializeBinary(new Uint8Array(buffer_arg));
442
+ }
443
+
433
444
  function serialize_fonoster_identity_v1beta2_UpdateUserRequest(arg) {
434
445
  if (!(arg instanceof identity_pb.UpdateUserRequest)) {
435
446
  throw new Error('Expected argument of type fonoster.identity.v1beta2.UpdateUserRequest');
@@ -485,6 +496,17 @@ function deserialize_fonoster_identity_v1beta2_User(buffer_arg) {
485
496
  return identity_pb.User.deserializeBinary(new Uint8Array(buffer_arg));
486
497
  }
487
498
 
499
+ function serialize_fonoster_identity_v1beta2_VerifyCodeRequest(arg) {
500
+ if (!(arg instanceof identity_pb.VerifyCodeRequest)) {
501
+ throw new Error('Expected argument of type fonoster.identity.v1beta2.VerifyCodeRequest');
502
+ }
503
+ return Buffer.from(arg.serializeBinary());
504
+ }
505
+
506
+ function deserialize_fonoster_identity_v1beta2_VerifyCodeRequest(buffer_arg) {
507
+ return identity_pb.VerifyCodeRequest.deserializeBinary(new Uint8Array(buffer_arg));
508
+ }
509
+
488
510
  function serialize_fonoster_identity_v1beta2_Workspace(arg) {
489
511
  if (!(arg instanceof identity_pb.Workspace)) {
490
512
  throw new Error('Expected argument of type fonoster.identity.v1beta2.Workspace');
@@ -643,6 +665,28 @@ createUser: {
643
665
  responseSerialize: serialize_fonoster_identity_v1beta2_DeleteUserResponse,
644
666
  responseDeserialize: deserialize_fonoster_identity_v1beta2_DeleteUserResponse,
645
667
  },
668
+ sendVerificationCode: {
669
+ path: '/fonoster.identity.v1beta2.Identity/SendVerificationCode',
670
+ requestStream: false,
671
+ responseStream: false,
672
+ requestType: identity_pb.SendVerificationCodeRequest,
673
+ responseType: google_protobuf_empty_pb.Empty,
674
+ requestSerialize: serialize_fonoster_identity_v1beta2_SendVerificationCodeRequest,
675
+ requestDeserialize: deserialize_fonoster_identity_v1beta2_SendVerificationCodeRequest,
676
+ responseSerialize: serialize_google_protobuf_Empty,
677
+ responseDeserialize: deserialize_google_protobuf_Empty,
678
+ },
679
+ verifyCode: {
680
+ path: '/fonoster.identity.v1beta2.Identity/VerifyCode',
681
+ requestStream: false,
682
+ responseStream: false,
683
+ requestType: identity_pb.VerifyCodeRequest,
684
+ responseType: google_protobuf_empty_pb.Empty,
685
+ requestSerialize: serialize_fonoster_identity_v1beta2_VerifyCodeRequest,
686
+ requestDeserialize: deserialize_fonoster_identity_v1beta2_VerifyCodeRequest,
687
+ responseSerialize: serialize_google_protobuf_Empty,
688
+ responseDeserialize: deserialize_google_protobuf_Empty,
689
+ },
646
690
  // ApiKey actions
647
691
  createApiKey: {
648
692
  path: '/fonoster.identity.v1beta2.Identity/CreateApiKey',
@@ -711,16 +755,16 @@ exchangeCredentials: {
711
755
  responseSerialize: serialize_fonoster_identity_v1beta2_ExchangeApiKeyResponse,
712
756
  responseDeserialize: deserialize_fonoster_identity_v1beta2_ExchangeApiKeyResponse,
713
757
  },
714
- exchangeOAuth2Code: {
715
- path: '/fonoster.identity.v1beta2.Identity/ExchangeOAuth2Code',
758
+ exchangeOauth2Code: {
759
+ path: '/fonoster.identity.v1beta2.Identity/ExchangeOauth2Code',
716
760
  requestStream: false,
717
761
  responseStream: false,
718
- requestType: identity_pb.ExchangeOAuth2CodeRequest,
719
- responseType: identity_pb.ExchangeOAuth2CodeResponse,
720
- requestSerialize: serialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeRequest,
721
- requestDeserialize: deserialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeRequest,
722
- responseSerialize: serialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeResponse,
723
- responseDeserialize: deserialize_fonoster_identity_v1beta2_ExchangeOAuth2CodeResponse,
762
+ requestType: identity_pb.ExchangeOauth2CodeRequest,
763
+ responseType: identity_pb.ExchangeOauth2CodeResponse,
764
+ requestSerialize: serialize_fonoster_identity_v1beta2_ExchangeOauth2CodeRequest,
765
+ requestDeserialize: deserialize_fonoster_identity_v1beta2_ExchangeOauth2CodeRequest,
766
+ responseSerialize: serialize_fonoster_identity_v1beta2_ExchangeOauth2CodeResponse,
767
+ responseDeserialize: deserialize_fonoster_identity_v1beta2_ExchangeOauth2CodeResponse,
724
768
  },
725
769
  exchangeRefreshToken: {
726
770
  path: '/fonoster.identity.v1beta2.Identity/ExchangeRefreshToken',