Skip to content

Commit ff6adbc

Browse files
committed
fix: prettier and CI setup
1 parent 16eb340 commit ff6adbc

File tree

8 files changed

+83
-83
lines changed

8 files changed

+83
-83
lines changed

.github/workflows/lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Linting
33
on: [push]
44

55
jobs:
6-
eslint:
6+
prettier:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v4

.github/workflows/push.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ jobs:
2828
- name: Install dependencies
2929
run: yarn --frozen-lockfile
3030

31-
- name: Build
32-
run: yarn build
33-
3431
- name: Install latest npm
3532
run: npm install -g npm@latest
3633

@@ -39,4 +36,4 @@ jobs:
3936
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
4037
NPM_TOKEN: ${{secrets.NPM_TOKEN}}
4138
NPM_CONFIG_PROVENANCE: true
42-
run: yarn release
39+
run: yarn release

.github/workflows/test.yml

+3-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88

9-
strategy:
10-
matrix:
11-
node-version: [16.x, 18.x, 20.x]
12-
139
steps:
1410
- uses: actions/checkout@v4
15-
- name: Use Node ${{ matrix.node-version }}
11+
- name: Setup node
1612
uses: actions/setup-node@v4
1713
with:
18-
node-version: ${{ matrix.node-version }}
19-
cache: "yarn"
14+
node-version: 20
15+
cache: yarn
2016
- run: yarn
2117
- run: yarn test

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{}

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,26 @@ yarn add @includable/serverless-middleware
1313
## Example usage
1414

1515
```js
16-
import { middleware, auth } from '@includable/serverless-middleware';
16+
import { middleware, auth } from "@includable/serverless-middleware";
1717

1818
const dependencies = {
19-
// dependencies for the dependency injector
19+
// dependencies for the dependency injector
2020
};
2121

22-
export const app = async ({ query, path, body }, { currentUser, /* dependences */ }) => {
23-
// if `auth` is included in the second param of `middleware`, currentUser
24-
// will be an object in the form of `{ id, groups, email, ... }`
22+
export const app = async (
23+
{ query, path, body },
24+
{ currentUser /* dependences */ },
25+
) => {
26+
// if `auth` is included in the second param of `middleware`, currentUser
27+
// will be an object in the form of `{ id, groups, email, ... }`
2528

26-
// your business logic goes here
29+
// your business logic goes here
2730

28-
return {
29-
success: true,
30-
text: 'Hello, world!'
31-
};
32-
}
31+
return {
32+
success: true,
33+
text: "Hello, world!",
34+
};
35+
};
3336

3437
export const handler = middleware(app, [auth]).register(dependencies);
3538
```
@@ -38,14 +41,12 @@ export const handler = middleware(app, [auth]).register(dependencies);
3841

3942
### Warmup support
4043

41-
Out of the box this middleware setup supports the [serverless-plugin-warmup](https://github.com/FidelLimited/serverless-plugin-warmup)
42-
serverless plugin.
44+
Out of the box this middleware setup supports the [serverless-plugin-warmup](https://github.com/FidelLimited/serverless-plugin-warmup)
45+
serverless plugin.
4346

44-
Simply install the serverless plugin, no other changes to your code necessary.
47+
Simply install the serverless plugin, no other changes to your code necessary.
4548
The middleware will automatically prevent code execution on warmup requests.
4649

47-
48-
4950
<br /><br />
5051

5152
---

src/policies/currentUser.js

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
const currentUser = ({ event }) => {
2-
const { requestContext: { authorizer } } = event;
3-
const { claims } = authorizer.jwt || authorizer; // Dealing with difference between production and sls-offline
2+
const {
3+
requestContext: { authorizer },
4+
} = event;
5+
const { claims } = authorizer.jwt || authorizer; // Dealing with difference between production and sls-offline
46

5-
if (!claims || !claims.sub || !claims.sub.length) {
6-
throw new Error('Unauthorized');
7-
}
7+
if (!claims || !claims.sub || !claims.sub.length) {
8+
throw new Error("Unauthorized");
9+
}
810

9-
const claimGroups = claims['cognito:groups'] ? claims['cognito:groups'] : '[]';
10-
const groups = claimGroups
11-
.substring(1, claimGroups.length - 1)
12-
.split(' ')
13-
.filter(Boolean);
11+
const claimGroups = claims["cognito:groups"]
12+
? claims["cognito:groups"]
13+
: "[]";
14+
const groups = claimGroups
15+
.substring(1, claimGroups.length - 1)
16+
.split(" ")
17+
.filter(Boolean);
1418

15-
function hasGroup(group) {
16-
return groups.includes(group);
17-
}
19+
function hasGroup(group) {
20+
return groups.includes(group);
21+
}
1822

19-
return {
20-
...claims,
21-
id: claims.sub,
22-
groups,
23-
hasGroup
24-
};
23+
return {
24+
...claims,
25+
id: claims.sub,
26+
groups,
27+
hasGroup,
28+
};
2529
};
2630

2731
module.exports = currentUser;

tests/eventbridge.test.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
const middleware = require('../src');
1+
const middleware = require("../src");
22

3-
it('eventbridge events are passed through', async() => {
4-
const payload = {
5-
'version': '0',
6-
'id': '03f6b260-9ee8-af5f-4a02-95ebf5fc0925',
7-
'detail-type': 'ArtworkUpdate',
8-
'source': 'some-other-system',
9-
'account': '493638157050',
10-
'time': '2020-11-10T10:36:28Z',
11-
'region': 'eu-west-1',
12-
'resources': [],
13-
'detail': {
14-
'id': 31329,
15-
'action': 'create',
16-
}
17-
};
3+
it("eventbridge events are passed through", async () => {
4+
const payload = {
5+
version: "0",
6+
id: "03f6b260-9ee8-af5f-4a02-95ebf5fc0925",
7+
"detail-type": "ArtworkUpdate",
8+
source: "some-other-system",
9+
account: "493638157050",
10+
time: "2020-11-10T10:36:28Z",
11+
region: "eu-west-1",
12+
resources: [],
13+
detail: {
14+
id: 31329,
15+
action: "create",
16+
},
17+
};
1818

19-
const exampleApp = middleware(async(event) => {
20-
return event;
21-
}).register(() => ({}));
19+
const exampleApp = middleware(async (event) => {
20+
return event;
21+
}).register(() => ({}));
2222

23-
expect(JSON.parse(JSON.stringify(await exampleApp(payload)))).toEqual({
24-
body: JSON.stringify(payload),
25-
headers: {
26-
'Content-Type': 'application/json; charset=utf-8',
27-
},
28-
isBase64Encoded: false,
29-
statusCode: 200,
30-
});
23+
expect(JSON.parse(JSON.stringify(await exampleApp(payload)))).toEqual({
24+
body: JSON.stringify(payload),
25+
headers: {
26+
"Content-Type": "application/json; charset=utf-8",
27+
},
28+
isBase64Encoded: false,
29+
statusCode: 200,
30+
});
3131
});

tests/warmup.test.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
const middleware = require('../src');
1+
const middleware = require("../src");
22

3-
it('responds correctly to serverless-plugin-warmup', async() => {
4-
const exampleApp = middleware(async() => {
5-
return 'Hello, world!';
6-
}).register(() => ({}));
3+
it("responds correctly to serverless-plugin-warmup", async () => {
4+
const exampleApp = middleware(async () => {
5+
return "Hello, world!";
6+
}).register(() => ({}));
77

8-
expect(await exampleApp({
9-
source: 'serverless-plugin-warmup'
10-
})).toEqual('Lambda is warm');
8+
expect(
9+
await exampleApp({
10+
source: "serverless-plugin-warmup",
11+
}),
12+
).toEqual("Lambda is warm");
1113
});

0 commit comments

Comments
 (0)