@icanbwell/bwell-sdk-ts 0.3.1 → 0.3.2-rc.1724346280

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,4 +1,4 @@
1
1
  /**
2
2
  * This file is automatically generated. Please do not edit this file directly.
3
3
  */
4
- export declare const VERSION = "0.3.1";
4
+ export declare const VERSION = "0.3.2-rc.1724346280";
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * This file is automatically generated. Please do not edit this file directly.
3
3
  */
4
- export const VERSION = "0.3.1";
4
+ export const VERSION = "0.3.2-rc.1724346280";
@@ -16,7 +16,7 @@ export type RefreshTokensRequest = {
16
16
  refreshToken: string;
17
17
  clientKey: string;
18
18
  };
19
- export type AuthenticateResults = {
19
+ export type AuthTokens = {
20
20
  accessToken: string;
21
21
  idToken: string;
22
22
  refreshToken: string;
@@ -26,7 +26,7 @@ export type AuthenticateResults = {
26
26
  */
27
27
  export interface IdentityManager {
28
28
  initialize(clientKey: string): Promise<BWellTransactionResult<SdkConfigurationResult, BaseManagerError>>;
29
- authenticateWithOauth(authenticateRequest: OauthAuthenticateRequest): Promise<BWellTransactionResult<AuthenticateResults, BaseManagerError>>;
30
- authenticateWithUsernamePassword(authenticateRequest: UsernamePasswordAuthenticateRequest): Promise<BWellTransactionResult<AuthenticateResults, BaseManagerError>>;
29
+ authenticateWithOauth(authenticateRequest: OauthAuthenticateRequest): Promise<BWellTransactionResult<AuthTokens, BaseManagerError>>;
30
+ authenticateWithUsernamePassword(authenticateRequest: UsernamePasswordAuthenticateRequest): Promise<BWellTransactionResult<AuthTokens, BaseManagerError>>;
31
31
  refreshAccessToken(refreshTokensRequest: RefreshTokensRequest): Promise<BWellTransactionResult<RefreshTokenResults, BaseManagerError>>;
32
32
  }
@@ -1,14 +1,14 @@
1
1
  import { type LoggerProvider } from "../../../logger/index.js";
2
2
  import { BWellTransactionResult } from "../../../results/index.js";
3
3
  import { BaseManagerError } from "../../base/errors.js";
4
- import { IdentityManager, UsernamePasswordAuthenticateRequest, type AuthenticateResults, type OauthAuthenticateRequest, type RefreshTokenResults, type RefreshTokensRequest, type SdkConfigurationResult } from "../../base/identity/index.js";
4
+ import { IdentityManager, UsernamePasswordAuthenticateRequest, type AuthTokens, type OauthAuthenticateRequest, type RefreshTokenResults, type RefreshTokensRequest, type SdkConfigurationResult } from "../../base/identity/index.js";
5
5
  import { GraphQLManager } from "../graphql-manager/index.js";
6
6
  import type { GraphQLSdk } from "../graphql-sdk/index.js";
7
7
  export declare class GraphQLIdentityManager extends GraphQLManager implements IdentityManager {
8
8
  #private;
9
9
  constructor(sdk: GraphQLSdk, loggerProvider?: LoggerProvider);
10
10
  initialize(clientKey: string): Promise<BWellTransactionResult<SdkConfigurationResult, BaseManagerError>>;
11
- authenticateWithOauth(authenticateRequest: OauthAuthenticateRequest): Promise<BWellTransactionResult<AuthenticateResults, BaseManagerError>>;
12
- authenticateWithUsernamePassword(authenticateRequest: UsernamePasswordAuthenticateRequest): Promise<BWellTransactionResult<AuthenticateResults, BaseManagerError>>;
11
+ authenticateWithOauth(authenticateRequest: OauthAuthenticateRequest): Promise<BWellTransactionResult<AuthTokens, BaseManagerError>>;
12
+ authenticateWithUsernamePassword(authenticateRequest: UsernamePasswordAuthenticateRequest): Promise<BWellTransactionResult<AuthTokens, BaseManagerError>>;
13
13
  refreshAccessToken(refreshTokensRequest: RefreshTokensRequest): Promise<BWellTransactionResult<RefreshTokenResults, BaseManagerError>>;
14
14
  }
@@ -73,6 +73,8 @@ export class GraphQLIdentityManager extends GraphQLManager {
73
73
  const authResponse = yield this.handleTransaction(__classPrivateFieldGet(this, _GraphQLIdentityManager_sdk, "f").login({
74
74
  email: authenticateRequest.email,
75
75
  password: authenticateRequest.password,
76
+ }, {
77
+ ClientKey: authenticateRequest.clientKey,
76
78
  }));
77
79
  __classPrivateFieldGet(this, _GraphQLIdentityManager_logger, "f").verbose("username/password authenticate query complete", authResponse);
78
80
  if (authResponse.failure()) {
@@ -2,9 +2,10 @@ import { IdentityManager } from "../api/base/identity/identity-manager.js";
2
2
  import { SdkConfig } from "../config/index.js";
3
3
  import { LoggerProvider } from "../logger/index.js";
4
4
  import { AuthStrategy } from "./auth-strategy.js";
5
+ import { Credentials } from "./credentials.js";
5
6
  /**
6
7
  * Factory class to create an AuthStrategy based on a user's configuration
7
8
  */
8
9
  export declare class AuthStrategyFactory {
9
- createAuthStrategy(config: SdkConfig, identityManager: IdentityManager, loggerProvider?: LoggerProvider): AuthStrategy;
10
+ createAuthStrategy(config: SdkConfig, identityManager: IdentityManager, credentials: Credentials, loggerProvider?: LoggerProvider): AuthStrategy;
10
11
  }
@@ -1,19 +1,21 @@
1
- import { AuthType } from "../config/index.js";
2
1
  import { ConsoleLoggerProvider } from "../logger/index.js";
2
+ import { isOauthCredentials, isUserPassCredentials, } from "./credentials.js";
3
3
  import { OAuthStrategy } from "./oauth-strategy.js";
4
4
  import { UsernamePasswordStrategy } from "./username-password-strategy.js";
5
5
  /**
6
6
  * Factory class to create an AuthStrategy based on a user's configuration
7
7
  */
8
8
  export class AuthStrategyFactory {
9
- createAuthStrategy(config, identityManager, loggerProvider = new ConsoleLoggerProvider()) {
10
- switch (config.authType) {
11
- case AuthType.OAuth:
12
- return new OAuthStrategy(config, identityManager, loggerProvider);
13
- case AuthType.UsernamePassword:
14
- return new UsernamePasswordStrategy(config, identityManager, loggerProvider);
15
- default:
16
- throw new Error(`Authentication Strategy ${config.authType} has not been implemented yet`);
9
+ createAuthStrategy(config, identityManager, credentials, loggerProvider = new ConsoleLoggerProvider()) {
10
+ if (isUserPassCredentials(credentials) && isOauthCredentials(credentials)) {
11
+ throw new Error("Invalid credentials type provided; expected UserPassCredentials or OauthCredentials, but not both.");
17
12
  }
13
+ if (isUserPassCredentials(credentials)) {
14
+ return new UsernamePasswordStrategy(config, identityManager, loggerProvider);
15
+ }
16
+ if (isOauthCredentials(credentials)) {
17
+ return new OAuthStrategy(config, identityManager, loggerProvider);
18
+ }
19
+ throw new Error("Invalid credentials type provided; expected UserPassCredentials or OauthCredentials");
18
20
  }
19
21
  }
@@ -1,9 +1,9 @@
1
1
  import type { BaseManagerError } from "../api/base/errors.js";
2
- import type { AuthenticateResults } from "../api/base/identity/index.js";
2
+ import type { AuthTokens } from "../api/base/identity/index.js";
3
3
  import type { InvalidCredentialsTypeError } from "../errors/index.js";
4
4
  import type { BWellTransactionResult } from "../results/index.js";
5
5
  import type { Credentials } from "./credentials.js";
6
6
  export type AuthenticateErrors = InvalidCredentialsTypeError | BaseManagerError;
7
7
  export interface AuthStrategy {
8
- authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthenticateResults, AuthenticateErrors>>;
8
+ authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthTokens, AuthenticateErrors>>;
9
9
  }
@@ -1,4 +1,4 @@
1
- import { AuthenticateResults, IdentityManager } from "../api/base/identity/index.js";
1
+ import { AuthTokens, IdentityManager } from "../api/base/identity/index.js";
2
2
  import { SdkConfig } from "../config/index.js";
3
3
  import { LoggerProvider } from "../logger/index.js";
4
4
  import { BWellTransactionResult } from "../results/index.js";
@@ -7,5 +7,5 @@ import { Credentials } from "./credentials.js";
7
7
  export declare class OAuthStrategy implements AuthStrategy {
8
8
  #private;
9
9
  constructor(sdkConfig: SdkConfig, identityManager: IdentityManager, loggerProvider?: LoggerProvider);
10
- authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthenticateResults, AuthenticateErrors>>;
10
+ authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthTokens, AuthenticateErrors>>;
11
11
  }
@@ -1,4 +1,4 @@
1
- import { AuthenticateResults, IdentityManager } from "../api/base/identity/identity-manager.js";
1
+ import { AuthTokens, IdentityManager } from "../api/base/identity/identity-manager.js";
2
2
  import { SdkConfig } from "../config/index.js";
3
3
  import { LoggerProvider } from "../logger/index.js";
4
4
  import { BWellTransactionResult } from "../results/index.js";
@@ -8,5 +8,5 @@ import { Credentials } from "./credentials.js";
8
8
  export declare class UsernamePasswordStrategy implements AuthStrategy {
9
9
  #private;
10
10
  constructor(sdkConfig: SdkConfig, identityManager: IdentityManager, loggerProvider?: LoggerProvider);
11
- authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthenticateResults, AuthenticateErrors>>;
11
+ authenticate(credentials: Credentials): Promise<BWellTransactionResult<AuthTokens, AuthenticateErrors>>;
12
12
  }
@@ -3,12 +3,14 @@ import type { ConnectionManager } from "../api/base/connection/connection-manage
3
3
  import type { DeviceManager } from "../api/base/device/device-manager.js";
4
4
  import type { EventManager } from "../api/base/event/event-manager.js";
5
5
  import type { HealthManager } from "../api/base/health-data/health-manager.js";
6
+ import type { AuthTokens } from "../api/base/identity/index.js";
6
7
  import type { SearchManager } from "../api/base/search/search-manager.js";
7
8
  import type { UserManager } from "../api/base/user/user-manager.js";
8
9
  import { type Credentials } from "../auth/index.js";
9
10
  import { type BWellConfig } from "../config/index.js";
10
11
  import { type AuthenticationError, type InvalidClientKeyError, type InvalidTokenError, type OperationOutcomeError } from "../errors/index.js";
11
12
  import { BWellTransactionResult } from "../results/index.js";
13
+ export { AuthTokens } from "../api/base/identity/index.js";
12
14
  /**
13
15
  * The BWell SDK is the main entry point for the SDK.
14
16
  *
@@ -60,6 +62,17 @@ export declare class BWellSDK {
60
62
  * ```
61
63
  */
62
64
  authenticate(credentials: Credentials): Promise<BWellTransactionResult<null, AuthenticationError | InvalidTokenError>>;
65
+ /**
66
+ * Sets auth tokens for a pre-authenticated user. Performs a token refresh to
67
+ * validate the provided tokens.
68
+ *
69
+ * This can be used in place of `authenticate` for times when a user has been
70
+ * authenticated through means other than the SDK.
71
+ *
72
+ * @param {AuthTokens} authTokens - Auth tokens for pre-authenticated user
73
+ * @returns {Promise<BWellTransactionResult<null, OperationOutcomeError | InvalidTokenError>>}
74
+ */
75
+ setAuthTokens(authTokens: AuthTokens): Promise<BWellTransactionResult<null, OperationOutcomeError | InvalidTokenError>>;
63
76
  get health(): HealthManager;
64
77
  get user(): UserManager;
65
78
  get connection(): ConnectionManager;
@@ -18,7 +18,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
18
18
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
19
19
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
20
20
  };
21
- var _BWellSDK_instances, _BWellSDK_config, _BWellSDK_sdkConfig, _BWellSDK_telemetry, _BWellSDK_loggerFactory, _BWellSDK_apiProviderFactory, _BWellSDK_identityManagerFactory, _BWellSDK_authStrategyFactory, _BWellSDK_loggerProvider, _BWellSDK_apiProvider, _BWellSDK_logger, _BWellSDK_identityManager, _BWellSDK_configManager, _BWellSDK_tokenManager, _BWellSDK_getApiProvider, _BWellSDK_reinitializeBaseDependencies, _BWellSDK_initLoggerProvider, _BWellSDK_initTelemetry, _BWellSDK_initApiProvider;
21
+ var _BWellSDK_instances, _BWellSDK_config, _BWellSDK_sdkConfig, _BWellSDK_telemetry, _BWellSDK_loggerFactory, _BWellSDK_apiProviderFactory, _BWellSDK_identityManagerFactory, _BWellSDK_authStrategyFactory, _BWellSDK_loggerProvider, _BWellSDK_apiProvider, _BWellSDK_logger, _BWellSDK_identityManager, _BWellSDK_configManager, _BWellSDK_tokenManager, _BWellSDK_bootstrapAuth, _BWellSDK_getApiProvider, _BWellSDK_reinitializeBaseDependencies, _BWellSDK_initLoggerProvider, _BWellSDK_initTelemetry, _BWellSDK_initApiProvider;
22
22
  import { ApiProviderFactory } from "../api/api-provider-factory.js";
23
23
  import { IdentityManagerFactory } from "../api/identity-manager-factory.js";
24
24
  import { AuthStrategyFactory } from "../auth/index.js";
@@ -117,32 +117,41 @@ export class BWellSDK {
117
117
  */
118
118
  authenticate(credentials) {
119
119
  return __awaiter(this, void 0, void 0, function* () {
120
- const authStrategy = __classPrivateFieldGet(this, _BWellSDK_authStrategyFactory, "f").createAuthStrategy(__classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f"), __classPrivateFieldGet(this, _BWellSDK_identityManager, "f"), __classPrivateFieldGet(this, _BWellSDK_loggerProvider, "f"));
120
+ const authStrategy = __classPrivateFieldGet(this, _BWellSDK_authStrategyFactory, "f").createAuthStrategy(__classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f"), __classPrivateFieldGet(this, _BWellSDK_identityManager, "f"), credentials, __classPrivateFieldGet(this, _BWellSDK_loggerProvider, "f"));
121
121
  const authenticateResults = yield authStrategy.authenticate(credentials);
122
122
  if (authenticateResults.failure()) {
123
123
  return authenticateResults.intoFailure();
124
124
  }
125
125
  const authResultsData = authenticateResults.data();
126
- try {
127
- const user = parseUserFromIdToken(authResultsData.idToken);
128
- __classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f").setContextUser(user);
126
+ return __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_bootstrapAuth).call(this, authResultsData);
127
+ });
128
+ }
129
+ /**
130
+ * Sets auth tokens for a pre-authenticated user. Performs a token refresh to
131
+ * validate the provided tokens.
132
+ *
133
+ * This can be used in place of `authenticate` for times when a user has been
134
+ * authenticated through means other than the SDK.
135
+ *
136
+ * @param {AuthTokens} authTokens - Auth tokens for pre-authenticated user
137
+ * @returns {Promise<BWellTransactionResult<null, OperationOutcomeError | InvalidTokenError>>}
138
+ */
139
+ setAuthTokens(authTokens) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const bootsrapResult = yield __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_bootstrapAuth).call(this, authTokens);
142
+ if (bootsrapResult.failure()) {
143
+ return bootsrapResult.intoFailure();
129
144
  }
130
- catch (e) {
131
- if (BWellError.isBwellError(e)) {
132
- return BWellTransactionResult.failure(e);
133
- }
134
- // Its difficult to get this to throw an unexpected error in tests
145
+ if (__classPrivateFieldGet(this, _BWellSDK_tokenManager, "f") === undefined) {
146
+ // Token manager is set by #bootstrapAuth so it shouldn't ever be undefined
147
+ // here. We can't imply that through TS though so we need to presence check
135
148
  /* istanbul ignore next */
136
- throw e;
149
+ throw new Error("TokenManager not set");
137
150
  }
138
- const tokenManagerConfig = Object.assign(Object.assign({}, authResultsData), { clientKey: __classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f").context.clientKey });
139
- const tokenManagerInit = yield JWTTokenManager.initialize(tokenManagerConfig, __classPrivateFieldGet(this, _BWellSDK_identityManager, "f"), __classPrivateFieldGet(this, _BWellSDK_loggerProvider, "f"), __classPrivateFieldGet(this, _BWellSDK_config, "f").tokenStorage);
140
- if (tokenManagerInit.failure()) {
141
- return tokenManagerInit.intoFailure();
151
+ const refreshResult = yield __classPrivateFieldGet(this, _BWellSDK_tokenManager, "f").refreshAccessToken();
152
+ if (refreshResult.failure()) {
153
+ return refreshResult.intoFailure();
142
154
  }
143
- __classPrivateFieldSet(this, _BWellSDK_tokenManager, tokenManagerInit.data(), "f");
144
- __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_reinitializeBaseDependencies).call(this);
145
- __classPrivateFieldSet(this, _BWellSDK_apiProvider, __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_initApiProvider).call(this, __classPrivateFieldGet(this, _BWellSDK_tokenManager, "f")), "f");
146
155
  return BWellTransactionResult.success(null);
147
156
  });
148
157
  }
@@ -168,7 +177,31 @@ export class BWellSDK {
168
177
  return __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_getApiProvider).call(this).search;
169
178
  }
170
179
  }
171
- _BWellSDK_config = new WeakMap(), _BWellSDK_sdkConfig = new WeakMap(), _BWellSDK_telemetry = new WeakMap(), _BWellSDK_loggerFactory = new WeakMap(), _BWellSDK_apiProviderFactory = new WeakMap(), _BWellSDK_identityManagerFactory = new WeakMap(), _BWellSDK_authStrategyFactory = new WeakMap(), _BWellSDK_loggerProvider = new WeakMap(), _BWellSDK_apiProvider = new WeakMap(), _BWellSDK_logger = new WeakMap(), _BWellSDK_identityManager = new WeakMap(), _BWellSDK_configManager = new WeakMap(), _BWellSDK_tokenManager = new WeakMap(), _BWellSDK_instances = new WeakSet(), _BWellSDK_getApiProvider = function _BWellSDK_getApiProvider() {
180
+ _BWellSDK_config = new WeakMap(), _BWellSDK_sdkConfig = new WeakMap(), _BWellSDK_telemetry = new WeakMap(), _BWellSDK_loggerFactory = new WeakMap(), _BWellSDK_apiProviderFactory = new WeakMap(), _BWellSDK_identityManagerFactory = new WeakMap(), _BWellSDK_authStrategyFactory = new WeakMap(), _BWellSDK_loggerProvider = new WeakMap(), _BWellSDK_apiProvider = new WeakMap(), _BWellSDK_logger = new WeakMap(), _BWellSDK_identityManager = new WeakMap(), _BWellSDK_configManager = new WeakMap(), _BWellSDK_tokenManager = new WeakMap(), _BWellSDK_instances = new WeakSet(), _BWellSDK_bootstrapAuth = function _BWellSDK_bootstrapAuth(identityTokens) {
181
+ return __awaiter(this, void 0, void 0, function* () {
182
+ try {
183
+ const user = parseUserFromIdToken(identityTokens.idToken);
184
+ __classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f").setContextUser(user);
185
+ }
186
+ catch (e) {
187
+ if (BWellError.isBwellError(e)) {
188
+ return BWellTransactionResult.failure(e);
189
+ }
190
+ // Its difficult to get this to throw an unexpected error in tests
191
+ /* istanbul ignore next */
192
+ throw e;
193
+ }
194
+ const tokenManagerConfig = Object.assign(Object.assign({}, identityTokens), { clientKey: __classPrivateFieldGet(this, _BWellSDK_sdkConfig, "f").context.clientKey });
195
+ const tokenManagerInit = yield JWTTokenManager.initialize(tokenManagerConfig, __classPrivateFieldGet(this, _BWellSDK_identityManager, "f"), __classPrivateFieldGet(this, _BWellSDK_loggerProvider, "f"), __classPrivateFieldGet(this, _BWellSDK_config, "f").tokenStorage);
196
+ if (tokenManagerInit.failure()) {
197
+ return tokenManagerInit.intoFailure();
198
+ }
199
+ __classPrivateFieldSet(this, _BWellSDK_tokenManager, tokenManagerInit.data(), "f");
200
+ __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_reinitializeBaseDependencies).call(this);
201
+ __classPrivateFieldSet(this, _BWellSDK_apiProvider, __classPrivateFieldGet(this, _BWellSDK_instances, "m", _BWellSDK_initApiProvider).call(this, __classPrivateFieldGet(this, _BWellSDK_tokenManager, "f")), "f");
202
+ return BWellTransactionResult.success(null);
203
+ });
204
+ }, _BWellSDK_getApiProvider = function _BWellSDK_getApiProvider() {
172
205
  if (__classPrivateFieldGet(this, _BWellSDK_apiProvider, "f") === undefined) {
173
206
  throw new Error("Unintialized");
174
207
  }
@@ -18,10 +18,6 @@ export type HttpConfig = {
18
18
  timeout: number;
19
19
  retryPolicy: Retry;
20
20
  };
21
- export declare enum AuthType {
22
- OAuth = "OAUTH",
23
- UsernamePassword = "USERNAME_PASSWORD"
24
- }
25
21
  /**
26
22
  * Central configuration class used across the SDK. Takes a use supplied BWellConfig
27
23
  * and merges defaults and a remote configuration.
@@ -39,7 +35,6 @@ export declare class SdkConfig {
39
35
  get telemetry(): TelemetryConfig;
40
36
  get http(): HttpConfig;
41
37
  get context(): Context;
42
- get authType(): AuthType;
43
38
  setContextUser(user: User): void;
44
39
  mergeRemoteConfig(remoteConfig: SdkConfiguration | null): void;
45
40
  }
@@ -9,17 +9,12 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _SdkConfig_instances, _SdkConfig_loggerSeverity, _SdkConfig_telemetryConfig, _SdkConfig_graphQLConfig, _SdkConfig_httpConfig, _SdkConfig_context, _SdkConfig_authType, _SdkConfig_mergeLogLevel, _SdkConfig_mergeGraphQLConfig, _SdkConfig_mergeTelemetryConfig, _SdkConfig_mergeHttpConfig, _SdkConfig_mergeDefautlBwellConfig, _SdkConfig_getEnvFromClientKey, _SdkConfig_createDefaultGraphQLConfig, _SdkConfig_createDefaultTelemetryConfig, _SdkConfig_createDefaultHttpConfig, _SdkConfig_createDefaultContext;
12
+ var _SdkConfig_instances, _SdkConfig_loggerSeverity, _SdkConfig_telemetryConfig, _SdkConfig_graphQLConfig, _SdkConfig_httpConfig, _SdkConfig_context, _SdkConfig_mergeLogLevel, _SdkConfig_mergeGraphQLConfig, _SdkConfig_mergeTelemetryConfig, _SdkConfig_mergeHttpConfig, _SdkConfig_mergeDefaultBwellConfig, _SdkConfig_getEnvFromClientKey, _SdkConfig_createDefaultGraphQLConfig, _SdkConfig_createDefaultTelemetryConfig, _SdkConfig_createDefaultHttpConfig, _SdkConfig_createDefaultContext;
13
13
  import { BWellError, InvalidClientKeyError } from "../errors/index.js";
14
14
  import { LoggerSeverity } from "../logger/index.js";
15
15
  import { BWellTransactionResult } from "../results/index.js";
16
16
  import { retrieveEnvironmentFromClientKey } from "../utils/index.js";
17
17
  import { DEFAULT_BWELL_CONFIG } from "./bwell-config.js";
18
- export var AuthType;
19
- (function (AuthType) {
20
- AuthType["OAuth"] = "OAUTH";
21
- AuthType["UsernamePassword"] = "USERNAME_PASSWORD";
22
- })(AuthType || (AuthType = {}));
23
18
  /**
24
19
  * Central configuration class used across the SDK. Takes a use supplied BWellConfig
25
20
  * and merges defaults and a remote configuration.
@@ -35,8 +30,7 @@ export class SdkConfig {
35
30
  _SdkConfig_graphQLConfig.set(this, void 0);
36
31
  _SdkConfig_httpConfig.set(this, void 0);
37
32
  _SdkConfig_context.set(this, void 0);
38
- _SdkConfig_authType.set(this, AuthType.OAuth);
39
- this.bwellConfig = __classPrivateFieldGet(this, _SdkConfig_instances, "m", _SdkConfig_mergeDefautlBwellConfig).call(this, bwellConfig);
33
+ this.bwellConfig = __classPrivateFieldGet(this, _SdkConfig_instances, "m", _SdkConfig_mergeDefaultBwellConfig).call(this, bwellConfig);
40
34
  __classPrivateFieldSet(this, _SdkConfig_loggerSeverity, LoggerSeverity.severityFromText(this.bwellConfig.logLevel), "f");
41
35
  __classPrivateFieldSet(this, _SdkConfig_context, __classPrivateFieldGet(this, _SdkConfig_instances, "m", _SdkConfig_createDefaultContext).call(this), "f");
42
36
  __classPrivateFieldSet(this, _SdkConfig_graphQLConfig, __classPrivateFieldGet(this, _SdkConfig_instances, "m", _SdkConfig_createDefaultGraphQLConfig).call(this), "f");
@@ -74,9 +68,6 @@ export class SdkConfig {
74
68
  get context() {
75
69
  return __classPrivateFieldGet(this, _SdkConfig_context, "f");
76
70
  }
77
- get authType() {
78
- return __classPrivateFieldGet(this, _SdkConfig_authType, "f");
79
- }
80
71
  setContextUser(user) {
81
72
  __classPrivateFieldGet(this, _SdkConfig_context, "f").user = user;
82
73
  }
@@ -87,7 +78,7 @@ export class SdkConfig {
87
78
  __classPrivateFieldSet(this, _SdkConfig_httpConfig, Object.freeze(__classPrivateFieldGet(this, _SdkConfig_instances, "m", _SdkConfig_mergeHttpConfig).call(this, remoteConfig)), "f");
88
79
  }
89
80
  }
90
- _SdkConfig_loggerSeverity = new WeakMap(), _SdkConfig_telemetryConfig = new WeakMap(), _SdkConfig_graphQLConfig = new WeakMap(), _SdkConfig_httpConfig = new WeakMap(), _SdkConfig_context = new WeakMap(), _SdkConfig_authType = new WeakMap(), _SdkConfig_instances = new WeakSet(), _SdkConfig_mergeLogLevel = function _SdkConfig_mergeLogLevel(remoteConfig) {
81
+ _SdkConfig_loggerSeverity = new WeakMap(), _SdkConfig_telemetryConfig = new WeakMap(), _SdkConfig_graphQLConfig = new WeakMap(), _SdkConfig_httpConfig = new WeakMap(), _SdkConfig_context = new WeakMap(), _SdkConfig_instances = new WeakSet(), _SdkConfig_mergeLogLevel = function _SdkConfig_mergeLogLevel(remoteConfig) {
91
82
  var _a;
92
83
  const remoteLogLevel = (_a = remoteConfig === null || remoteConfig === void 0 ? void 0 : remoteConfig.logLevel) !== null && _a !== void 0 ? _a : null;
93
84
  if (remoteLogLevel === null) {
@@ -136,7 +127,7 @@ _SdkConfig_loggerSeverity = new WeakMap(), _SdkConfig_telemetryConfig = new Weak
136
127
  timeout: (_b = remoteHttpConfig.requestTimeout) !== null && _b !== void 0 ? _b : __classPrivateFieldGet(this, _SdkConfig_httpConfig, "f").timeout,
137
128
  retryPolicy: (_c = remoteHttpConfig.retry) !== null && _c !== void 0 ? _c : __classPrivateFieldGet(this, _SdkConfig_httpConfig, "f").retryPolicy,
138
129
  };
139
- }, _SdkConfig_mergeDefautlBwellConfig = function _SdkConfig_mergeDefautlBwellConfig(bwellConfig) {
130
+ }, _SdkConfig_mergeDefaultBwellConfig = function _SdkConfig_mergeDefaultBwellConfig(bwellConfig) {
140
131
  return Object.assign(Object.assign({}, DEFAULT_BWELL_CONFIG), bwellConfig);
141
132
  }, _SdkConfig_getEnvFromClientKey = function _SdkConfig_getEnvFromClientKey() {
142
133
  try {
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from "./api/index.js";
2
2
  export * from "./errors/index.js";
3
3
  export * from "./requests/index.js";
4
4
  export { LogLevel, BWellConfig } from "./config/index.js";
5
- export { BWellSDK } from "./bwell-sdk/bwell-sdk.js";
5
+ export { BWellSDK, AuthTokens } from "./bwell-sdk/bwell-sdk.js";
6
6
  export { TokenStorage, InMemoryTokenStorage } from "./tokens/token-storage.js";
7
7
  export { BWellQueryResult } from "./results/bwell-query-result.js";
8
8
  export { BWellTransactionResult, BWellTransactionFailure, BWellTransactionSuccess, } from "./results/bwell-transaction-result.js";
@@ -11,6 +11,7 @@ export type TokenManagerConfig = {
11
11
  };
12
12
  export interface TokenManager {
13
13
  getAccessToken(): Promise<BWellTransactionResult<string, OperationOutcomeError | InvalidTokenError>>;
14
+ refreshAccessToken(): Promise<BWellTransactionResult<null, OperationOutcomeError | InvalidTokenError>>;
14
15
  getIdToken(): Promise<string | undefined>;
15
16
  }
16
17
  export declare class JWTTokenManager implements TokenManager {
@@ -29,4 +30,5 @@ export declare class JWTTokenManager implements TokenManager {
29
30
  static initialize(config: TokenManagerConfig, identManager: IdentityManager, loggerProvider?: LoggerProvider, tokenStorage?: TokenStorage): Promise<BWellTransactionResult<JWTTokenManager, InvalidTokenError>>;
30
31
  getAccessToken(): Promise<BWellTransactionResult<string, OperationOutcomeError | InvalidTokenError>>;
31
32
  getIdToken(): Promise<string | undefined>;
33
+ refreshAccessToken(): Promise<BWellTransactionResult<null, OperationOutcomeError | InvalidTokenError>>;
32
34
  }
@@ -87,6 +87,11 @@ export class JWTTokenManager {
87
87
  return yield __classPrivateFieldGet(this, _JWTTokenManager_tokenStorage, "f").get("idToken");
88
88
  });
89
89
  }
90
+ refreshAccessToken() {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ return __classPrivateFieldGet(this, _JWTTokenManager_instances, "m", _JWTTokenManager_refreshAccessToken).call(this);
93
+ });
94
+ }
90
95
  }
91
96
  _a = JWTTokenManager, _JWTTokenManager_identityManager = new WeakMap(), _JWTTokenManager_logger = new WeakMap(), _JWTTokenManager_tokenStorage = new WeakMap(), _JWTTokenManager_instances = new WeakSet(), _JWTTokenManager_parseTokenExpiration = function _JWTTokenManager_parseTokenExpiration(accessToken) {
92
97
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icanbwell/bwell-sdk-ts",
3
- "version": "0.3.1",
3
+ "version": "0.3.2-rc.1724346280",
4
4
  "description": "b.well TypeScript SDK",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",