@brokerize/client 1.3.1 → 1.3.3
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/dist/apiCtx.js +2 -0
- package/dist/client.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +35 -0
- package/package.json +1 -1
package/dist/apiCtx.js
CHANGED
|
@@ -54,6 +54,8 @@ export function createAuth({ authCfg, cfg, options, tokenRefreshCallback, }) {
|
|
|
54
54
|
tokenType: responseJson.token_type,
|
|
55
55
|
refreshTokenExpiresIn: responseJson.refresh_token_expires_in,
|
|
56
56
|
idToken: responseJson.access_token,
|
|
57
|
+
refreshTokenWithoutTradingsession: responseJson.refresh_Token_without_tradingsession,
|
|
58
|
+
refreshTokenWithoutTradingsessionExpiresIn: responseJson.refresh_token_without_tradingsession_expires_in,
|
|
57
59
|
},
|
|
58
60
|
};
|
|
59
61
|
if (tokenRefreshCallback) {
|
package/dist/client.d.ts
CHANGED
|
@@ -1438,6 +1438,7 @@ export declare class Brokerize {
|
|
|
1438
1438
|
private _cfg;
|
|
1439
1439
|
private _defaultApi;
|
|
1440
1440
|
constructor(cfg: BrokerizeConfig);
|
|
1441
|
+
refreshGuestUser(refreshToken: string): Promise<GuestAuthContextConfiguration>;
|
|
1441
1442
|
createGuestUser(): Promise<AuthContextConfiguration>;
|
|
1442
1443
|
/**
|
|
1443
1444
|
* Create a context for making authorized API calls. This context will automatically take care of refreshing the access token
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthContextConfiguration, BrokerizeConfig, CognitoConfig, CognitoFacade, CognitoPoolConfig, Auth, RegisteredUserAuthContextConfiguration, TokenSet } from "./apiCtx";
|
|
1
|
+
import { AuthContextConfiguration, BrokerizeConfig, CognitoConfig, CognitoFacade, CognitoPoolConfig, Auth, RegisteredUserAuthContextConfiguration, TokenSet, GuestAuthContextConfiguration } from "./apiCtx";
|
|
2
2
|
import { AuthorizedApiContext } from "./authorizedApiContext";
|
|
3
3
|
import { BrokerizeError } from "./errors";
|
|
4
4
|
import * as Models from "./modelExports";
|
|
@@ -12,6 +12,7 @@ export declare class Brokerize {
|
|
|
12
12
|
private _cfg;
|
|
13
13
|
private _defaultApi;
|
|
14
14
|
constructor(cfg: BrokerizeConfig);
|
|
15
|
+
refreshGuestUser(refreshToken: string): Promise<GuestAuthContextConfiguration>;
|
|
15
16
|
createGuestUser(): Promise<AuthContextConfiguration>;
|
|
16
17
|
/**
|
|
17
18
|
* Create a context for making authorized API calls. This context will automatically take care of refreshing the access token
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,41 @@ export class Brokerize {
|
|
|
37
37
|
this._cfg = cfg;
|
|
38
38
|
this._defaultApi = new openApiClient.DefaultApi(createConfiguration(cfg));
|
|
39
39
|
}
|
|
40
|
+
async refreshGuestUser(refreshToken) {
|
|
41
|
+
const response = await fetch(this._cfg.basePath + "/user/token", {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"x-brkrz-client-id": this._cfg.clientId,
|
|
45
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
46
|
+
},
|
|
47
|
+
// XXX some runtimes do not have URLSearchParams, so just produce the body in the old-fashioned way
|
|
48
|
+
body: `grant_type=refresh_token&refresh_token=${encodeURIComponent(refreshToken)}`,
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new BrokerizeError(401, {
|
|
52
|
+
msg: "The token could not be refreshed. Please log in again.",
|
|
53
|
+
code: "AUTH",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const responseJson = (await response.json());
|
|
57
|
+
return {
|
|
58
|
+
type: "guest",
|
|
59
|
+
idToken: responseJson.access_token,
|
|
60
|
+
tokens: {
|
|
61
|
+
updatedAt: Date.now(),
|
|
62
|
+
response: {
|
|
63
|
+
accessToken: responseJson.access_token,
|
|
64
|
+
refreshToken: responseJson.refresh_token,
|
|
65
|
+
expiresIn: responseJson.expires_in,
|
|
66
|
+
tokenType: responseJson.token_type,
|
|
67
|
+
refreshTokenExpiresIn: responseJson.refresh_token_expires_in,
|
|
68
|
+
idToken: responseJson.access_token,
|
|
69
|
+
refreshTokenWithoutTradingsession: responseJson.refresh_Token_without_tradingsession,
|
|
70
|
+
refreshTokenWithoutTradingsessionExpiresIn: responseJson.refresh_token_without_tradingsession_expires_in,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
40
75
|
async createGuestUser() {
|
|
41
76
|
const updatedAt = Date.now();
|
|
42
77
|
const user = await this._defaultApi.createGuestUser({
|