@fonoster/sdk 0.8.64 → 0.9.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.
@@ -10,6 +10,7 @@ declare abstract class AbstractClient implements FonosterClient {
10
10
  protected accessKeyId: string;
11
11
  protected _accessToken: string;
12
12
  protected _refreshToken: string;
13
+ protected _idToken: string;
13
14
  protected identityClient: IdentityClient;
14
15
  constructor(config: {
15
16
  accessKeyId: string;
@@ -19,7 +20,7 @@ declare abstract class AbstractClient implements FonosterClient {
19
20
  loginWithRefreshToken(refreshToken: string): Promise<void>;
20
21
  loginWithApiKey(accessKeyId: string, accessKeySecret: string): Promise<void>;
21
22
  loginWithOauth2Code(provider: "GITHUB", username: string, code: string): Promise<void>;
22
- setAccessToken(accessToken: string): Promise<void>;
23
+ setAccessToken(accessToken: string): void;
23
24
  sendVerificationCode(contactType: ContactType, value: string): Promise<void>;
24
25
  verifyCode(request: {
25
26
  username: string;
@@ -31,6 +32,7 @@ declare abstract class AbstractClient implements FonosterClient {
31
32
  getAccessKeyId(): string;
32
33
  getAccessToken(): string;
33
34
  getRefreshToken(): string;
35
+ getIdToken(): string;
34
36
  abstract getMetadata(): unknown;
35
37
  abstract getApplicationsClient(): ApplicationsClient;
36
38
  abstract getIdentityClient(): IdentityClient;
@@ -7,15 +7,17 @@ class AbstractClient {
7
7
  accessKeyId;
8
8
  _accessToken;
9
9
  _refreshToken;
10
+ _idToken;
10
11
  identityClient;
11
12
  constructor(config) {
12
13
  this.accessKeyId = config.accessKeyId;
13
14
  this.identityClient = config.identityClient;
14
15
  this._accessToken = "";
15
16
  this._refreshToken = "";
17
+ this._idToken = "";
16
18
  }
17
19
  async login(username, password, verificationCode) {
18
- const { refreshToken, accessToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
20
+ const { refreshToken, accessToken, idToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
19
21
  method: this.identityClient.exchangeCredentials.bind(this.identityClient),
20
22
  requestPBObjectConstructor: identity_pb_1.ExchangeCredentialsRequest,
21
23
  metadata: {},
@@ -27,9 +29,10 @@ class AbstractClient {
27
29
  });
28
30
  this._refreshToken = refreshToken;
29
31
  this._accessToken = accessToken;
32
+ this._idToken = idToken;
30
33
  }
31
34
  async loginWithRefreshToken(refreshToken) {
32
- const { accessToken, refreshToken: newRefreshToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
35
+ const { accessToken, refreshToken: newRefreshToken, idToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
33
36
  method: this.identityClient.exchangeRefreshToken.bind(this.identityClient),
34
37
  requestPBObjectConstructor: identity_pb_1.ExchangeRefreshTokenRequest,
35
38
  metadata: {},
@@ -39,6 +42,7 @@ class AbstractClient {
39
42
  });
40
43
  this._refreshToken = newRefreshToken;
41
44
  this._accessToken = accessToken;
45
+ this._idToken = idToken;
42
46
  }
43
47
  async loginWithApiKey(accessKeyId, accessKeySecret) {
44
48
  const { refreshToken, accessToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
@@ -54,7 +58,7 @@ class AbstractClient {
54
58
  this._accessToken = accessToken;
55
59
  }
56
60
  async loginWithOauth2Code(provider, username, code) {
57
- const { refreshToken, accessToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
61
+ const { refreshToken, accessToken, idToken } = await (0, makeRpcRequest_1.makeRpcRequest)({
58
62
  method: this.identityClient.exchangeOauth2Code,
59
63
  requestPBObjectConstructor: identity_pb_1.ExchangeOauth2CodeRequest,
60
64
  metadata: {},
@@ -66,12 +70,13 @@ class AbstractClient {
66
70
  });
67
71
  this._refreshToken = refreshToken;
68
72
  this._accessToken = accessToken;
73
+ this._idToken = idToken;
69
74
  }
70
- async setAccessToken(accessToken) {
75
+ setAccessToken(accessToken) {
71
76
  this._accessToken = accessToken;
72
77
  }
73
78
  async sendVerificationCode(contactType, value) {
74
- await (0, makeRpcRequest_1.makeRpcRequest)({
79
+ return (0, makeRpcRequest_1.makeRpcRequest)({
75
80
  method: this.identityClient.sendVerificationCode.bind(this.identityClient),
76
81
  requestPBObjectConstructor: identity_pb_1.SendVerificationCodeRequest,
77
82
  metadata: {},
@@ -83,7 +88,7 @@ class AbstractClient {
83
88
  });
84
89
  }
85
90
  async verifyCode(request) {
86
- await (0, makeRpcRequest_1.makeRpcRequest)({
91
+ return (0, makeRpcRequest_1.makeRpcRequest)({
87
92
  method: this.identityClient.verifyCode.bind(this.identityClient),
88
93
  requestPBObjectConstructor: identity_pb_1.VerifyCodeRequest,
89
94
  metadata: {},
@@ -92,7 +97,7 @@ class AbstractClient {
92
97
  });
93
98
  }
94
99
  async refreshToken() {
95
- return await this.loginWithRefreshToken(this._refreshToken);
100
+ return this.loginWithRefreshToken(this._refreshToken);
96
101
  }
97
102
  getAccessKeyId() {
98
103
  return this.accessKeyId;
@@ -103,5 +108,8 @@ class AbstractClient {
103
108
  getRefreshToken() {
104
109
  return this._refreshToken;
105
110
  }
111
+ getIdToken() {
112
+ return this._idToken;
113
+ }
106
114
  }
107
115
  exports.AbstractClient = AbstractClient;
@@ -4,7 +4,7 @@ export declare class Client extends AbstractClient {
4
4
  private readonly endpoint;
5
5
  private readonly tokenRefresherInterceptor;
6
6
  private readonly channelCredentials;
7
- constructor(config: {
7
+ constructor(config?: {
8
8
  endpoint?: string;
9
9
  accessKeyId: string;
10
10
  allowInsecure?: boolean;
@@ -37,7 +37,12 @@ class Client extends AbstractClient_1.AbstractClient {
37
37
  endpoint;
38
38
  tokenRefresherInterceptor;
39
39
  channelCredentials;
40
- constructor(config) {
40
+ constructor(config = {
41
+ endpoint: DEFAULT_ENDPOINT,
42
+ accessKeyId: "",
43
+ allowInsecure: false,
44
+ withoutInterceptors: false
45
+ }) {
41
46
  const channelCredentials = config.allowInsecure
42
47
  ? grpc_js_1.credentials.createInsecure()
43
48
  : grpc_js_1.credentials.createSsl();