Skip to content

Commit 2f44469

Browse files
Prettier lint husky (#51)
* prettier * prettier, eslint config * address lint errors and warnings * fix * add husky * svelte eslint config * react eslint config * vu eslint config * fixes * format on save * format * nicer layout * remove commented out imports * cleanup, fixes --------- Co-authored-by: dickhardt <dick.hardt@hello.coop>
1 parent ff68345 commit 2f44469

157 files changed

Lines changed: 22192 additions & 20656 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run check

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
archive*

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode"
4+
}

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ A package to add login and registration with Hellō to an Fastify application.
1818

1919
[Hellō Fastify SDK documentation](https://www.hello.dev/docs/sdks/fastify)
2020

21-
2221
## [@hellocoop/nextjs](./nextjs/)
2322

2423
A package to add login and registration with Hellō to a Next.js application.
@@ -39,10 +38,9 @@ Svelte components for Hellō - BETA
3938

4039
[Hellō React SDK documentation](https://www.hello.dev/docs/sdks/svelte)
4140

42-
4341
## [@hellocoop/quickstart](./quickstart/)
4442

45-
A CLI and nodejs package to create or retrieve a Hellō `client_id`.
43+
A CLI and nodejs package to create or retrieve a Hellō `client_id`.
4644

4745
[Quickstart CLI and API Documentation](https://www.hello.dev/docs/sdks/quickstart)
4846

@@ -56,17 +54,15 @@ A set of client side helper functions for the Hellō OpenID Connect Provider.
5654

5755
[Hellō core / client SDK documentation](https://www.hello.dev/docs/sdks/helper/)
5856

59-
6057
# Publishing New Versions
6158

6259
- make updates and commit changes to repo
6360
- `npx lerna version` will then see which workspaces have changes and prompt to update the version, and all dependent versions
6461

65-
setup with
62+
setup with
6663

6764
`npx lerna init --independent`
6865

6966
`lerna publish from-package` will only publish packages that have a different version then what is published
7067

7168
`lerna publish` will prompt to update the version of the package as well
72-

api/README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# @hellocoop/api
22

33
This npm package is a TypeScript implementation of the Hellō Web Client API that is used by:
4+
45
- [@hellocoop/express](https://www.npmjs.com/package/@hellocoop/express)
56
- [@hellocoop/fastify](https://www.npmjs.com/package/@hellocoop/fastify)
67
- [@hellocoop/nextjs](https://www.npmjs.com/package/@hellocoop/nextjs)
78
- [@hellocoop/cdk-client](https://www.npmjs.com/package/@hellocoop/cdk-client)
89

9-
1010
## Hellō Web Client API
1111

12-
The API is a single route, that by default is `/api/hellocoop`. Having a single route simplifies integration into an application. The endpoint handles the API as well as being the protocol endpoint for the OpenID Connect `redirect_uri` and third party initiated login.
12+
The API is a single route, that by default is `/api/hellocoop`. Having a single route simplifies integration into an application. The endpoint handles the API as well as being the protocol endpoint for the OpenID Connect `redirect_uri` and third party initiated login.
1313

1414
The web client calls the API by passing the `op` query command set to one of the operations (`auth|login|logout|invite`)
1515

1616
[router.ts](src/handlers/router.ts) routes the commands to the different modules
1717

18-
### `auth`
18+
### `auth`
1919

2020
Returns the `auth` object:
2121

@@ -34,35 +34,32 @@ Returns the `auth` object:
3434
}
3535
```
3636

37-
3837
Implemented in [auth.ts](src/handlers/auth.ts)
3938

4039
### `login`
4140

42-
The client loads `/api/hellocoop?op=login` to start a login flow.
41+
The client loads `/api/hellocoop?op=login` to start a login flow.
4342

4443
Optional parameters described in [Web Client API](https://www.hello.dev/docs/apis/web-client/#login)
4544

46-
This will:
45+
This will:
4746

4847
1. discover the `redirect_uri` if not configured by bouncing a page to the browser to learn the full URL for the endpoint
4948
2. generate a PKCE `code_verifier` and `code_challenge`
5049
3. generate a `nonce`
5150
4. encrypt and store the `redirect_uri`, `code_verifier`, and `nonce` in the `hello_oidc` cookie
52-
4. create an authorization request and return a 302 redirect to that URL
51+
5. create an authorization request and return a 302 redirect to that URL
5352

5453
Implemented in [login.ts](src/handlers/login.ts)
5554

56-
57-
### `logout`
55+
### `logout`
5856

5957
The client loads `/api/hellocoop?op=logout` to clear the auth cookie and log the user out.
6058

6159
Optional parameters described in [Web Client API](https://www.hello.dev/docs/apis/web-client/#logout)
6260

6361
Implemented in [logout.ts](src/handlers/logout.ts)
6462

65-
6663
### `invite`
6764

6865
The client loads `/api/hellocoop?op=invite` to start the invite flow.
@@ -71,13 +68,11 @@ See the [Invite API](https://www.hello.dev/docs/apis/invite/) for details.
7168

7269
Implemented in [invite.ts](src/handlers/invite.ts)
7370

74-
75-
## OpenID Connect Protocol
76-
71+
## OpenID Connect Protocol
7772

7873
### Authorization Response
7974

80-
The API endpoint is the `redirect_uri` and is where the user is redirected after interacting with their Hellō Wallet.
75+
The API endpoint is the `redirect_uri` and is where the user is redirected after interacting with their Hellō Wallet.
8176

8277
If a successful login at Hellō, the endpoint receives an authorization code query parameter (`code`). It then will:
8378

@@ -88,15 +83,13 @@ If a successful login at Hellō, the endpoint receives an authorization code que
8883
5. set the `hellocoop_auth` cookie
8984
6. redirect the user to the `target_uri`
9085

91-
If the user is an administrator of the Hellō application and it is running at a dynamic endpoint and the `wildcard_console` parameter is returned,
86+
If the user is an administrator of the Hellō application and it is running at a dynamic endpoint and the `wildcard_console` parameter is returned,
9287
an intermediate page is generated by [wildcard.ts](src/handlers/wildcard.ts) and presented to the developer to simplify configuration of their application.
9388

94-
9589
If the log in was unsuccessful or canceled, the endpoint receives an `error` query parameter and the user is redirected to an error page.
9690

9791
Implemented in [callback.ts](src/handlers/callback.ts)
9892

99-
10093
### Third Party Initiated Login
10194

10295
This allows a user to log in to an application by clicking a link in a dashboard or loading a bookmark. The endpoint is passed the `iss` query parameter, which must be the Hellō issuer, `https://issuer.hello.coop`. `login_hint` or `domain_hint` can optionally be provided.

api/package.json

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
{
2-
"name": "@hellocoop/api",
3-
"version": "2.2.7",
4-
"description": "Client API for Hellō https://hello.dev",
5-
"repository": {
6-
"type": "git",
7-
"url": "git+https://github.com/hellocoop/packages.git"
8-
},
9-
"homepage": "https://www.hello.dev/docs/apis/web-client/",
10-
"main": "./dist/index.js",
11-
"types": "./dist/index.d.ts",
12-
"exports": {
13-
".": "./dist/index.js"
14-
},
15-
"files": [
16-
"dist/"
17-
],
18-
"keywords": [
19-
"hello",
20-
"openid",
21-
"oidc",
22-
"sso"
23-
],
24-
"author": {
25-
"name": "Hello Identity Co-op",
26-
"email": "contact@hello.coop",
27-
"url": "https://hello.coop"
28-
},
29-
"license": "MIT",
30-
"bugs": {
31-
"url": "https://github.com/hellocoop/packages/issues"
32-
},
33-
"scripts": {
34-
"watch": "tsc --watch",
35-
"prebuild": "rimraf dist node_modules",
36-
"build": "tsc"
37-
},
38-
"devDependencies": {
39-
"@tsconfig/node18": "^18.2.2",
40-
"@types/cookie": "^0.6.0",
41-
"rimraf": "^5.0.1",
42-
"typescript": "^5.2.2"
43-
},
44-
"engines": {
45-
"node": ">=18"
46-
},
47-
"dependencies": {
48-
"@hellocoop/definitions": "^1.0.9",
49-
"@hellocoop/helper-server": "^2.2.1",
50-
"cookie": "^1.0.1"
51-
},
52-
"gitHead": "96cc2f3fa1a3724a4a96b19cc7c5d97f04cc49f8"
2+
"name": "@hellocoop/api",
3+
"version": "2.2.7",
4+
"description": "Client API for Hellō https://hello.dev",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/hellocoop/packages.git"
8+
},
9+
"homepage": "https://www.hello.dev/docs/apis/web-client/",
10+
"main": "./dist/index.js",
11+
"types": "./dist/index.d.ts",
12+
"exports": {
13+
".": "./dist/index.js"
14+
},
15+
"files": [
16+
"dist/"
17+
],
18+
"keywords": [
19+
"hello",
20+
"openid",
21+
"oidc",
22+
"sso"
23+
],
24+
"author": {
25+
"name": "Hello Identity Co-op",
26+
"email": "contact@hello.coop",
27+
"url": "https://hello.coop"
28+
},
29+
"license": "MIT",
30+
"bugs": {
31+
"url": "https://github.com/hellocoop/packages/issues"
32+
},
33+
"scripts": {
34+
"watch": "tsc --watch",
35+
"prebuild": "rimraf dist node_modules",
36+
"build": "tsc"
37+
},
38+
"devDependencies": {
39+
"@tsconfig/node18": "^18.2.2",
40+
"@types/cookie": "^0.6.0",
41+
"rimraf": "^5.0.1",
42+
"typescript": "^5.2.2"
43+
},
44+
"engines": {
45+
"node": ">=18"
46+
},
47+
"dependencies": {
48+
"@hellocoop/definitions": "^1.0.9",
49+
"@hellocoop/helper-server": "^2.2.1",
50+
"cookie": "^1.0.1"
51+
},
52+
"gitHead": "96cc2f3fa1a3724a4a96b19cc7c5d97f04cc49f8"
5353
}

api/src/handlers/auth.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
11
import { HelloRequest, HelloResponse } from '../types'
22

3-
import { getAuthfromCookies, saveAuthCookie, clearAuthCookie } from '../lib/auth'
3+
import {
4+
getAuthfromCookies,
5+
saveAuthCookie,
6+
clearAuthCookie,
7+
} from '../lib/auth'
48

59
import { Auth, Claims } from '@hellocoop/definitions'
6-
import { decryptObj } from '@hellocoop/helper-server'
7-
import config from '../lib//config'
8-
910

1011
// export type AuthHelloRequest = HelloRequest & {
1112
// auth?: Auth
1213
// }
1314

14-
export type AuthUpdates =
15-
Claims & {
16-
[key: string]: any; // Allow arbitrary optional properties
17-
}
15+
export type AuthUpdates = Claims & {
16+
[key: string]: any // Allow arbitrary optional properties
17+
}
1818

19-
export const handleAuth = async function (req: HelloRequest, res: HelloResponse) {
20-
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
21-
res.setHeader('Pragma', 'no-cache');
22-
res.setHeader('Expires', '0');
23-
res.json(await getAuthfromCookies(req,res))
19+
export const handleAuth = async function (
20+
req: HelloRequest,
21+
res: HelloResponse,
22+
) {
23+
res.setHeader(
24+
'Cache-Control',
25+
'no-store, no-cache, must-revalidate, proxy-revalidate',
26+
)
27+
res.setHeader('Pragma', 'no-cache')
28+
res.setHeader('Expires', '0')
29+
res.json(await getAuthfromCookies(req, res))
2430
}
2531

26-
export const clearAuth = async function ( res: HelloResponse) {
32+
export const clearAuth = async function (res: HelloResponse) {
2733
clearAuthCookie(res)
2834
}
2935

30-
31-
32-
export const updateAuth = async function ( req: HelloRequest, res: HelloResponse, authUpdates: AuthUpdates )
33-
: Promise<Auth | null> {
34-
const auth = await getAuthfromCookies( req, res )
35-
if (!auth.isLoggedIn)
36-
return auth
36+
export const updateAuth = async function (
37+
req: HelloRequest,
38+
res: HelloResponse,
39+
authUpdates: AuthUpdates,
40+
): Promise<Auth | null> {
41+
const auth = await getAuthfromCookies(req, res)
42+
if (!auth.isLoggedIn) return auth
3743
const newAuth = {
3844
...auth,
3945
...authUpdates,
4046
sub: auth.sub,
41-
iat: auth.iat
47+
iat: auth.iat,
4248
}
43-
const success = await saveAuthCookie( res, newAuth)
44-
if (success)
45-
return newAuth
49+
const success = await saveAuthCookie(res, newAuth)
50+
if (success) return newAuth
4651
return null
4752
}
4853

@@ -51,12 +56,12 @@ export const updateAuth = async function ( req: HelloRequest, res: HelloResponse
5156
// if (!cookieToken)
5257
// return res.status(400).send('Invalid request')
5358
// try {
54-
// const auth = await decryptObj( cookieToken, config.secret as string) as Auth | undefined
59+
// const auth = await decryptObj( cookieToken, config.secret as string) as Auth | undefined
5560
// if (auth) {
5661
// return res.json(auth)
5762
// }
5863
// } catch( e ) {
5964
// console.error(e)
6065
// }
6166
// return res.status(401).send('Unauthorized')
62-
// }
67+
// }

0 commit comments

Comments
 (0)