mirror of
https://github.com/sasjs/adapter.git
synced 2026-01-06 20:10:05 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a7b4a1de4 | ||
|
|
5a35237de5 | ||
|
|
5d77bbba8b |
2076
package-lock.json
generated
2076
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -46,6 +46,7 @@
|
|||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"jest-extended": "^0.11.5",
|
"jest-extended": "^0.11.5",
|
||||||
"mime": "^2.5.2",
|
"mime": "^2.5.2",
|
||||||
|
"node-polyfill-webpack-plugin": "^1.1.4",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
"process": "^0.11.10",
|
"process": "^0.11.10",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
@@ -64,12 +65,11 @@
|
|||||||
},
|
},
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sasjs/utils": "^2.21.0",
|
"@sasjs/utils": "^2.22.0",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"axios-cookiejar-support": "^1.0.1",
|
"axios-cookiejar-support": "^1.0.1",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"https": "^1.0.0",
|
"https": "^1.0.0",
|
||||||
"jwt-decode": "^3.1.2",
|
|
||||||
"tough-cookie": "^4.0.0",
|
"tough-cookie": "^4.0.0",
|
||||||
"url": "^0.11.0"
|
"url": "^0.11.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,7 @@ import {
|
|||||||
isRelativePath,
|
isRelativePath,
|
||||||
isUri,
|
isUri,
|
||||||
isUrl,
|
isUrl,
|
||||||
fetchLogByChunks,
|
fetchLogByChunks
|
||||||
isAccessTokenExpiring,
|
|
||||||
isRefreshTokenExpiring
|
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import * as NodeFormData from 'form-data'
|
import * as NodeFormData from 'form-data'
|
||||||
import {
|
import {
|
||||||
@@ -27,11 +25,18 @@ import {
|
|||||||
import { formatDataForRequest } from './utils/formatDataForRequest'
|
import { formatDataForRequest } from './utils/formatDataForRequest'
|
||||||
import { SessionManager } from './SessionManager'
|
import { SessionManager } from './SessionManager'
|
||||||
import { ContextManager } from './ContextManager'
|
import { ContextManager } from './ContextManager'
|
||||||
import { timestampToYYYYMMDDHHMMSS } from '@sasjs/utils/time'
|
import {
|
||||||
import { Logger, LogLevel } from '@sasjs/utils/logger'
|
timestampToYYYYMMDDHHMMSS,
|
||||||
|
isAccessTokenExpiring,
|
||||||
|
isRefreshTokenExpiring,
|
||||||
|
Logger,
|
||||||
|
LogLevel,
|
||||||
|
SasAuthResponse,
|
||||||
|
MacroVar,
|
||||||
|
AuthConfig
|
||||||
|
} from '@sasjs/utils'
|
||||||
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
import { isAuthorizeFormRequired } from './auth/isAuthorizeFormRequired'
|
||||||
import { RequestClient } from './request/RequestClient'
|
import { RequestClient } from './request/RequestClient'
|
||||||
import { SasAuthResponse, MacroVar, AuthConfig } from '@sasjs/utils/types'
|
|
||||||
import { prefixMessage } from '@sasjs/utils/error'
|
import { prefixMessage } from '@sasjs/utils/error'
|
||||||
import * as mime from 'mime'
|
import * as mime from 'mime'
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
import jwtDecode from 'jwt-decode'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the Access Token is expired or is expiring in 1 hour. A default Access Token
|
|
||||||
* lasts 12 hours. If the Access Token expires, the Refresh Token is used to fetch a new
|
|
||||||
* Access Token. In the case that the Refresh Token is expired, 1 hour is enough to let
|
|
||||||
* most jobs finish.
|
|
||||||
* @param {string} token- token string that will be evaluated
|
|
||||||
*/
|
|
||||||
export function isAccessTokenExpiring(token: string): boolean {
|
|
||||||
if (!token) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
const payload = jwtDecode<{ exp: number }>(token)
|
|
||||||
const timeToLive = payload.exp - new Date().valueOf() / 1000
|
|
||||||
|
|
||||||
return timeToLive <= 60 * 60 // 1 hour
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the Refresh Token is expired or expiring in 30 secs. A default Refresh Token
|
|
||||||
* lasts 30 days. Once the Refresh Token expires, the user must re-authenticate (provide
|
|
||||||
* credentials in a browser to obtain an authorisation code). 30 seconds is enough time
|
|
||||||
* to make a request for a final Access Token.
|
|
||||||
* @param {string} token- token string that will be evaluated
|
|
||||||
*/
|
|
||||||
export function isRefreshTokenExpiring(token?: string): boolean {
|
|
||||||
if (!token) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
const payload = jwtDecode<{ exp: number }>(token)
|
|
||||||
const timeToLive = payload.exp - new Date().valueOf() / 1000
|
|
||||||
|
|
||||||
return timeToLive <= 30 // 30 seconds
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
export * from './asyncForEach'
|
export * from './asyncForEach'
|
||||||
export * from './auth'
|
|
||||||
export * from './compareTimestamps'
|
export * from './compareTimestamps'
|
||||||
export * from './convertToCsv'
|
export * from './convertToCsv'
|
||||||
export * from './isRelativePath'
|
export * from './isRelativePath'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const webpack = require('webpack')
|
const webpack = require('webpack')
|
||||||
const terserPlugin = require('terser-webpack-plugin')
|
const terserPlugin = require('terser-webpack-plugin')
|
||||||
|
const nodePolyfillPlugin = require('node-polyfill-webpack-plugin')
|
||||||
|
|
||||||
const defaultPlugins = [
|
const defaultPlugins = [
|
||||||
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
|
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
|
||||||
@@ -37,7 +38,7 @@ const browserConfig = {
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.js'],
|
extensions: ['.ts', '.js'],
|
||||||
fallback: { https: false }
|
fallback: { https: false, fs: false, readline: false }
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
filename: 'index.js',
|
filename: 'index.js',
|
||||||
@@ -49,7 +50,8 @@ const browserConfig = {
|
|||||||
...defaultPlugins,
|
...defaultPlugins,
|
||||||
new webpack.ProvidePlugin({
|
new webpack.ProvidePlugin({
|
||||||
process: 'process/browser'
|
process: 'process/browser'
|
||||||
})
|
}),
|
||||||
|
new nodePolyfillPlugin()
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user