Skip to content

Commit

Permalink
feat(browser): add LogtoClient constructor (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
IceHe authored Feb 10, 2022
1 parent 5d950ea commit d738c0b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/browser/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module.exports = {
coveragePathIgnorePatterns: ['/node_modules/', '/lib/'],
coverageReporters: ['text-summary', 'lcov'],
moduleFileExtensions: ['ts', 'js'],
setupFilesAfterEnv: ['./jest.setup.js'],
testEnvironment: 'jsdom',
testPathIgnorePatterns: ['lib'],
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|js)$',
transform: {
Expand Down
8 changes: 8 additions & 0 deletions packages/browser/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Need to disable following rules to mock text-decode/text-encoder and crypto for jsdom
// https://github.com/jsdom/jsdom/issues/1612
/* eslint-disable @silverhand/fp/no-mutation */
/* eslint-disable unicorn/prefer-module */
const { TextDecoder, TextEncoder } = require('text-encoder');

global.TextDecoder = TextDecoder;
global.TextEncoder = TextEncoder;
1 change: 1 addition & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"jest": "^27.0.6",
"lint-staged": "^12.3.3",
"prettier": "^2.3.2",
"text-encoder": "^0.0.4",
"ts-jest": "^27.0.4",
"ts-loader": "^9.2.6",
"typescript": "^4.3.5",
Expand Down
19 changes: 14 additions & 5 deletions packages/browser/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { TODO } from './index';
import { createRequester } from '@logto/js';

describe('TODO', () => {
test('TODO', () => {
const todo: TODO = 'TODO';
expect(todo).toEqual('TODO');
import LogtoClient from './index';

describe('LogtoClient', () => {
test('constructor', () => {
expect(
() =>
new LogtoClient({
endpoint: 'https://logto.dev',
clientId: 'client_id_value',
usingPersistStorage: false,
requester: createRequester(),
})
).not.toThrow();
});
});
29 changes: 28 additions & 1 deletion packages/browser/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
export type TODO = 'TODO';
import { OidcConfigResponse, Requester } from '@logto/js';

export type LogtoConfig = {
endpoint: string;
clientId: string;
scopes?: string[];
resources?: string[];
usingPersistStorage?: boolean;
requester: Requester;
};

export type AccessToken = {
token: string;
scope: string;
expiresAt: number; // Unix Timestamp in seconds
};

export default class LogtoClient {
protected accessTokenMap = new Map<string, AccessToken>();
protected refreshToken?: string;
protected idToken?: string;
protected logtoConfig: LogtoConfig;
protected oidcConfig?: OidcConfigResponse;

constructor(logtoConfig: LogtoConfig) {
this.logtoConfig = logtoConfig;
}
}
6 changes: 4 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d738c0b

Please sign in to comment.