@icanbwell/bwell-sdk-ts 0.3.1 → 0.3.2

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";
@@ -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";
@@ -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
  }
@@ -117,7 +117,7 @@ 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();
@@ -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/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",
4
4
  "description": "b.well TypeScript SDK",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",