Skip to content

Commit

Permalink
fix(polymorphic): Split libs into node and browser env, update webpac…
Browse files Browse the repository at this point in the history
…k config

* fix(polymorphic): Split libs into node and browser env + update webpack config

* test(polymorphic): run units on bundled modules instead of on clean typescript - support for node an

* refactor(cleanup): cleanup console logs, package

* fix(cloud): Remove sessionToken in inapp browser is enabled
  • Loading branch information
pcholuj authored Jan 24, 2020
1 parent 4882623 commit 82689c2
Show file tree
Hide file tree
Showing 14 changed files with 518 additions and 449 deletions.
33 changes: 11 additions & 22 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@ module.exports = {
name: 'filestack-js',
collectCoverage: true,
clearMocks: true,
projects: [{
projects: [
{
displayName: 'Common',
clearMocks: true,
testMatch: ['<rootDir>/src/**/*.spec.ts'],
testMatch: ['<rootDir>/build/main/**/*.spec.js', '<rootDir>/build/main/**/*.spec.node.js'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
}, {
displayName: 'Node',
clearMocks: true,
testMatch: ['<rootDir>/src/**/*.spec.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
testMatch: ['<rootDir>/src/**/*.spec.node.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
moduleFileExtensions: ['js'],
}, {
displayName: 'Browser',
testMatch: ['<rootDir>/src/**/*.browser.spec.ts'],
clearMocks: true,
testEnvironment: 'jsdom',
setupFiles: ['jest-localstorage-mock'],
testMatch: ['<rootDir>/src/**/*.spec.browser.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
}]
testMatch: [ '<rootDir>/build/main/**/*.spec.browser.js'],
moduleFileExtensions: ['js'],
moduleNameMapper: {
"\(.*)\\.node": "$1.browser",
}
}
]
};
142 changes: 43 additions & 99 deletions package-lock.json

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

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"webpack:profile": "npx webpack --profile --json > .stats.json",
"webpack:analyze": "npm run webpack:profile && npx webpack-bundle-analyzer .stats.json build/browser/",
"lint": "tslint -p tsconfig.tslint.json",
"test": "npm run lint && jest",
"test": "npm run lint && npm run build && jest",
"test:watch": "npm t -- --watch",
"test:codecov": "npx codecov",
"docs": "trash build/docs && typedoc src",
Expand All @@ -37,7 +37,7 @@
"node": ">=8"
},
"dependencies": {
"@sentry/minimal": "^5.5.0",
"@sentry/minimal": "^5.11.1",
"abab": "^2.0.0",
"axios": "0.18.1",
"debug": "^4.1.1",
Expand Down Expand Up @@ -88,10 +88,9 @@
"prettier-tslint": "^0.4.2",
"standard-version": "^6.0.1",
"trash-cli": "^3.0.0",
"ts-jest": "^24.0.2",
"tslint": "^5.18.0",
"tslint": "^6.0.0",
"tslint-config-semistandard": "^8.0.1",
"typedoc": "^0.15.1",
"typedoc": "^0.16.8",
"typescript": "^3.5.3",
"validate-commit-msg": "^2.14.0",
"webpack": "^4.35.3",
Expand Down
36 changes: 33 additions & 3 deletions src/lib/api/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,32 @@ export const CALLBACK_URL_KEY = 'fs-tab';
export class CloudClient {
session: Session;
cloudApiUrl: string;

/**
* Returns flag if token should be cached in local storage
*
* @private
* @type {boolean}
* @memberof CloudClient
*/
private cache: boolean = false;

/**
* Token returned from api for accessing clouds
*
* @private
* @type {string}
* @memberof CloudClient
*/
private _token: string;

/**
* Flag for in-app browser setup
* (in-app browsers are not supporting new window so we need to save token to session cache)
*
* @private
* @memberof CloudClient
*/
private _isInAppBrowser = false;

constructor(session: Session, options?: ClientOptions) {
Expand Down Expand Up @@ -193,9 +217,15 @@ export class CloudClient {

if (name) {
payload.clouds = { [name]: {} };
} else if (this.cache) {
// No name means logout of ALL clouds. Clear local session.
localStorage.removeItem(PICKER_KEY);
} else {
if (this.cache) {
// No name means logout of ALL clouds. Clear local session.
localStorage.removeItem(PICKER_KEY);
}

if (this._isInAppBrowser) {
sessionStorage.removeItem(PICKER_KEY);
}
}

return requestWithSource()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import axios from 'axios';
import { requestWithSource, postWithRetry } from './request';
import * as nock from 'nock';

const v = require('../../../package.json').version;
const v = require('../../../../package.json').version;

const testHost = 'https://test.com';

Expand Down
Loading

0 comments on commit 82689c2

Please sign in to comment.