@8base/api-token-auth-client
Advanced tools
Comparing version 0.35.1 to 0.36.0
@@ -1,19 +0,18 @@ | ||
import { AuthState, IAuthClient } from '@8base/utils'; | ||
declare type ApiTokenAuthClientOptions = { | ||
import { IAuthState, IAuthClient, IStorage } from '@8base/utils'; | ||
interface IApiTokenAuthClientOptions { | ||
apiToken: string; | ||
}; | ||
} | ||
/** | ||
* Create instacne of the api token auth client | ||
* @param {string} apiToken Api Token generated in 8base app. | ||
* Creates instacne of the api token auth client | ||
*/ | ||
declare class ApiTokenAuthClient implements IAuthClient { | ||
apiToken: string; | ||
state: {}; | ||
constructor({ apiToken }: ApiTokenAuthClientOptions); | ||
getAuthState: () => Promise<AuthState>; | ||
setAuthState: (state: AuthState) => Promise<void>; | ||
purgeAuthState: () => Promise<void>; | ||
checkIsAuthorized: () => Promise<boolean>; | ||
private storageAPI; | ||
private apiToken; | ||
constructor(options: IApiTokenAuthClientOptions, storage?: IStorage, storageKey?: string); | ||
getState(): IAuthState; | ||
setState(state: IAuthState): void; | ||
purgeState(): void; | ||
checkIsAuthorized(): boolean; | ||
} | ||
export { ApiTokenAuthClient }; | ||
//# sourceMappingURL=ApiTokenAuthClient.d.ts.map |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("@8base/utils"); | ||
/** | ||
* Create instacne of the api token auth client | ||
* @param {string} apiToken Api Token generated in 8base app. | ||
* Creates instacne of the api token auth client | ||
*/ | ||
class ApiTokenAuthClient { | ||
constructor({ apiToken }) { | ||
this.getAuthState = () => __awaiter(this, void 0, void 0, function* () { | ||
return (Object.assign({ token: this.apiToken }, this.state)); | ||
}); | ||
this.setAuthState = (state) => __awaiter(this, void 0, void 0, function* () { | ||
this.state = Object.assign({}, this.state, state, { token: this.apiToken }); | ||
}); | ||
this.purgeAuthState = () => __awaiter(this, void 0, void 0, function* () { | ||
this.state = {}; | ||
}); | ||
this.checkIsAuthorized = () => __awaiter(this, void 0, void 0, function* () { return true; }); | ||
if (!apiToken) { | ||
throw new utils_1.SDKError(utils_1.ERROR_CODES.MISSING_PARAMETER, utils_1.PACKAGES.API_TOKEN_AUTH_CLIENT, 'apiToken is required'); | ||
} | ||
constructor(options, storage = window.localStorage, storageKey = 'auth') { | ||
utils_1.throwIfMissingRequiredParameters(['apiToken'], utils_1.PACKAGES.API_TOKEN_AUTH_CLIENT, options); | ||
const { apiToken } = options; | ||
this.storageAPI = new utils_1.StorageAPI(storage, storageKey); | ||
this.apiToken = apiToken; | ||
this.state = {}; | ||
this.storageAPI.setState({ token: apiToken }); | ||
} | ||
getState() { | ||
return Object.assign({}, this.storageAPI.getState(), { token: this.apiToken }); | ||
} | ||
setState(state) { | ||
this.storageAPI.setState(Object.assign({}, state, { token: this.apiToken })); | ||
} | ||
purgeState() { | ||
this.storageAPI.purgeState(); | ||
this.storageAPI.setState({ token: this.apiToken }); | ||
} | ||
checkIsAuthorized() { | ||
return true; | ||
} | ||
} | ||
exports.ApiTokenAuthClient = ApiTokenAuthClient; | ||
//# sourceMappingURL=ApiTokenAuthClient.js.map |
{ | ||
"name": "@8base/api-token-auth-client", | ||
"version": "0.35.1", | ||
"version": "0.36.0", | ||
"author": "8base", | ||
@@ -17,3 +17,3 @@ "repository": "https://github.com/8base/sdk", | ||
"dependencies": { | ||
"@8base/utils": "^0.35.1" | ||
"@8base/utils": "^0.36.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "devDependencies": { |
@@ -26,3 +26,3 @@ # 8base api token auth client | ||
```js | ||
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/auth'; | ||
import { AuthContext, AuthProvider, type AuthContextProps } from '@8base/react-auth'; | ||
import { ApiTokenAuthClient } form '@8base/api-token-auth-client'; | ||
@@ -29,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6323
62
+ Added@8base/utils@0.36.6(transitive)
- Removed@8base/utils@0.35.1(transitive)
Updated@8base/utils@^0.36.0