-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: added connect-session-server package * refactor: remove server scripts from connect-session package * feat: resolved connect session server package * docs: removed node usage and added link to new connect-session-server package * refactor: changed lib to server lib for reapit connect server session * chore: added package scripts * feat: added connect-session-server label * chore: added jest badges for project * docs: added badges to readme * chore: easier reading of condition for sonarcloud * fix: replaced connect-session with connect-session-server package * fix: updated tsconfig path for reapit package * fix: updated node version target
- Loading branch information
Showing
52 changed files
with
490 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-1.02 MB
.yarn/cache/@rollup-rollup-linux-x64-gnu-npm-4.13.0-834923f1a9-10.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file renamed
BIN
+15.2 MB
...linux-x64-gnu-npm-1.4.8-3a20ef526a-10.zip → ...-darwin-arm64-npm-1.4.8-6193726d0f-10.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+812 KB
.yarn/cache/@typescript-eslint-eslint-plugin-npm-7.7.0-de43f1e757-9e6b6fbb99.zip
Binary file not shown.
Binary file added
BIN
+8.93 KB
.yarn/cache/@typescript-eslint-parser-npm-7.7.0-1113d8c99f-9f8c53ca29.zip
Binary file not shown.
Binary file added
BIN
+333 KB
.yarn/cache/@typescript-eslint-scope-manager-npm-7.7.0-11c4ce86ce-c8890aaf99.zip
Binary file not shown.
Binary file added
BIN
+53.4 KB
.yarn/cache/@typescript-eslint-type-utils-npm-7.7.0-78eaba3e4e-a3f5358b4b.zip
Binary file not shown.
Binary file added
BIN
+30.5 KB
.yarn/cache/@typescript-eslint-types-npm-7.7.0-9680b728d4-d54ff9eeea.zip
Binary file not shown.
Binary file added
BIN
+174 KB
.yarn/cache/@typescript-eslint-typescript-estree-npm-7.7.0-a66322a4aa-40af26b3ed.zip
Binary file not shown.
Binary file added
BIN
+119 KB
.yarn/cache/@typescript-eslint-utils-npm-7.7.0-ce9a309e60-4223233ee0.zip
Binary file not shown.
Binary file added
BIN
+9.8 KB
.yarn/cache/@typescript-eslint-visitor-keys-npm-7.7.0-c5686658e8-9f03591ab6.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { baseEslint } = require('@reapit/ts-scripts') | ||
|
||
module.exports = baseEslint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//registry.npmjs.org/:_authToken=${NPM_TOKEN} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities. | ||
version: v1.14.1 | ||
ignore: {} | ||
patch: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Connect Session Server | ||
|
||
![lines](./src/tests/badges/badge-lines.svg) ![functions](./src/tests/badges/badge-functions.svg) ![branches](./src/tests/badges/badge-branches.svg) ![statements](./src/tests/badges/badge-statements.svg) | ||
|
||
## Install | ||
|
||
```bash | ||
$ yarn add @reapit/connect-session-server | ||
``` | ||
|
||
## Usage | ||
|
||
For server side usage, we also export a Node module with a stripped down API that simply returns a promise from a connectAccessToken method. For a basic and slightly contrived example, see the simple Express app below: | ||
|
||
```ts | ||
import express, { Router, Request, Response } from 'express' | ||
import bodyParser from 'body-parser' | ||
import cors from 'cors' | ||
import { ReapitConnectServerSession, ReapitConnectServerSessionInitializers } from '@reapit/connect-session-server' | ||
import config from './config.json' | ||
|
||
const router = Router() | ||
|
||
const { connectClientId, connectClientSecret, connectOAuthUrl } = config as ReapitConnectServerSessionInitializers | ||
|
||
// Instance as a singleton as token will be cached within the class (prevents duplicate requests for access token) | ||
const reapitConnectSession = new ReapitConnectServerSession({ | ||
connectClientId, | ||
connectClientSecret, | ||
connectOAuthUrl, | ||
}) | ||
|
||
router.get('/get-access-token', async (req: Request, res: Response) => { | ||
const accessToken = await reapitConnectSession.connectAccessToken() | ||
// Do some stuff with my access token here, will just return it to the user as an example | ||
res.status(200) | ||
res.send(accessToken) | ||
res.end() | ||
}) | ||
|
||
const app = express() | ||
|
||
app.use(cors()) | ||
app.use(bodyParser.urlencoded({ extended: true })) | ||
app.use(bodyParser.json()) | ||
app.use('/', router) | ||
|
||
app.listen('3000', () => { | ||
console.log('App is listening on 3000') | ||
}) | ||
``` | ||
|
||
As per the browser usage, you will need to instantiate the class with your initializers, in this case `connectClientId`, `connectOAuthUrl` (in the same way as the browser module), but with the addition of the `connectClientSecret` you obtain from your app listing page. | ||
|
||
The module will fetch and refresh your session as the token expires, caching it locally to minimise calls to Reapit Connect token endpoint. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest') | ||
const { compilerOptions } = require('./tsconfig.json') | ||
const { jestGlobalConfig } = require('@reapit/ts-scripts') | ||
|
||
module.exports = { | ||
...jestGlobalConfig, | ||
modulePathIgnorePatterns: ['<rootDir>[/\\\\](node_modules|public|dist)[/\\\\]'], | ||
moduleNameMapper: { | ||
...pathsToModuleNameMapper(compilerOptions.paths, { | ||
prefix: '<rootDir>/', | ||
}), | ||
}, | ||
coveragePathIgnorePatterns: [ | ||
'<rootDir>[/\\\\](node_modules|src/tests|src/__mocks__)[/\\\\]', | ||
'<rootDir>/src/types.ts', | ||
'<rootDir>/src/index.ts', | ||
'.d.ts', | ||
], | ||
coverageThreshold: { | ||
global: { | ||
branches: 69, | ||
functions: 96, | ||
lines: 91, | ||
statements: 91, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@reapit/connect-session-server", | ||
"packageManager": "[email protected]", | ||
"description": "Server OAuth Flow for Reapit Connect", | ||
"keywords": [ | ||
"reapit-connect", | ||
"server", | ||
"connect-session" | ||
], | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"homepage": "https://github.com/reapit/foundations#readme", | ||
"bugs": { | ||
"url": "https://github.com/reapit/foundations/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/reapit/foundations.git" | ||
}, | ||
"devDependencies": { | ||
"@types/eslint": "^8", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.12.7", | ||
"@typescript-eslint/eslint-plugin": "^7.7.0", | ||
"@typescript-eslint/parser": "^7.7.0", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"jest": "^29.7.0", | ||
"jest-coverage-badges": "^1.1.2", | ||
"prettier": "^3.2.5", | ||
"ts-jest": "^29.1.2", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.4.5" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"lint": "eslint --cache --ext=ts,js src", | ||
"test": "cross-env jest --watch --colors", | ||
"check": "tsc --noEmit --skipLibCheck", | ||
"release": "echo '...skipping...'", | ||
"deploy": "echo '...skipping...'", | ||
"publish": "yarn npm publish --access public", | ||
"conf": "echo '...skipping...'", | ||
"commit": "yarn test --coverage --no-cache --silent --forceExit --detectOpenHandles --runInBand --watch=false && jest-coverage-badges --input src/tests/coverage/coverage-summary.json --output src/tests/badges && yarn lint --fix && yarn check" | ||
}, | ||
"dependencies": { | ||
"axios": "^1.6.8", | ||
"jwt-decode": "^4.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ReapitConnectServerSessionInitializers, CoginitoSession } from '../' | ||
import base64 from 'base-64' | ||
|
||
export const createMockToken = (token: { [s: string]: any } | string): string => | ||
`${base64.encode('{}')}.${base64.encode(typeof token === 'string' ? token : JSON.stringify(token))}.${base64.encode( | ||
'{}', | ||
)}` | ||
|
||
export const mockLoginIdentity = { | ||
email: '[email protected]', | ||
name: 'name', | ||
developerId: 'SOME_DEVELOPER_ID', | ||
clientId: 'SOME_CLIENT_ID', | ||
adminId: 'SOME_ADMIN_ID', | ||
userCode: 'SOME_USER_ID', | ||
orgName: 'SOME_ORG_NAME', | ||
orgId: 'SOME_ORG_ID', | ||
groups: ['AgencyCloudDeveloperEdition', 'OrganisationAdmin', 'ReapitUser', 'ReapitDeveloper', 'ReapitDeveloperAdmin'], | ||
offGroupIds: 'MKV', | ||
offGrouping: true, | ||
offGroupName: 'Cool Office Group', | ||
officeId: 'MVK', | ||
orgProduct: 'agencyCloud', | ||
agencyCloudId: 'SOME_AC_ID', | ||
} | ||
|
||
export const mockServerInitializers: ReapitConnectServerSessionInitializers = { | ||
connectClientId: 'SOME_CLIENT_ID', | ||
connectOAuthUrl: 'SOME_URL', | ||
connectClientSecret: 'SOME_SECRET', | ||
} | ||
|
||
export const mockTokenResponse: CoginitoSession = { | ||
access_token: createMockToken({ | ||
exp: Math.round(new Date().getTime() / 1000) + 360, // time now + 6mins - we refresh session if expiry within 5mins | ||
}), | ||
refresh_token: 'SOME_REFRESH_TOKEN', | ||
id_token: createMockToken({ | ||
name: mockLoginIdentity.name, | ||
email: mockLoginIdentity.email, | ||
'custom:reapit:developerId': mockLoginIdentity.developerId, | ||
'custom:reapit:clientCode': mockLoginIdentity.clientId, | ||
'custom:reapit:marketAdmin': mockLoginIdentity.adminId, | ||
'custom:reapit:userCode': mockLoginIdentity.userCode, | ||
'cognito:groups': mockLoginIdentity.groups, | ||
}), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/connect-session-server/src/tests/badges/badge-branches.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/connect-session-server/src/tests/badges/badge-functions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/connect-session-server/src/tests/badges/badge-lines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/connect-session-server/src/tests/badges/badge-statements.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "ES2018", | ||
"typeRoots": ["./src/core/definitions.d.ts", "node_modules/@types", "../../node_modules/@types"], | ||
"baseUrl": "./", | ||
"sourceRoot": "/", | ||
"paths": { | ||
"@reapit/utils-nest": ["../utils-nest/src"], | ||
"@reapit/*": ["../*"] | ||
}, | ||
"declaration": true, | ||
"declarationDir": "dist", | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"strictPropertyInitialization": false, | ||
"outDir": "./dist" | ||
}, | ||
"include": ["src"], | ||
"exclude": ["public", "dist", "src/scripts", "node_modules", "src/tests/coverage", "../connect-session/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineConfig } from 'tsup'; | ||
import fs from 'fs'; | ||
|
||
const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf-8')) | ||
|
||
export default defineConfig({ | ||
entry: ['src/index.ts'], | ||
target: 'node18', | ||
outDir: 'dist', | ||
clean: true, | ||
minify: process.env.NODE_ENV === 'production', | ||
esbuildOptions: (opts) => { | ||
opts.resolveExtensions = ['.ts', '.mjs', '.js']; | ||
}, | ||
noExternal: Object.keys(pkgJson.dependencies), | ||
}) |
Oops, something went wrong.