Skip to content

Commit 855edd1

Browse files
authored
2023 update (#207)
2023 update
1 parent f50bfc0 commit 855edd1

File tree

198 files changed

+79943
-194471
lines changed

Some content is hidden

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

198 files changed

+79943
-194471
lines changed

Diff for: book/1-end/app/package.json

+15-15
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
"lint": "eslint . --ext .ts,.tsx"
99
},
1010
"dependencies": {
11-
"dotenv": "^8.2.0",
12-
"next": "^9.1.2",
13-
"react": "^17.0.2",
14-
"react-dom": "^17.0.2",
15-
"typescript": "^4.7.3"
11+
"dotenv": "^16.3.1",
12+
"next": "^14.0.3",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"typescript": "^5.3.2"
1616
},
1717
"devDependencies": {
18-
"@types/node": "^12.12.2",
19-
"@types/react": "^18.0.14",
20-
"@types/react-dom": "^18.0.5",
21-
"@typescript-eslint/eslint-plugin": "^4.2.0",
22-
"@typescript-eslint/parser": "^4.2.0",
23-
"eslint": "^6.8.0",
24-
"eslint-config-prettier": "^7.1.0",
25-
"eslint-plugin-prettier": "^3.3.1",
26-
"eslint-plugin-react": "^7.21.5",
27-
"prettier": "^2.2.1"
18+
"@types/node": "^20.10.1",
19+
"@types/react": "^18.2.39",
20+
"@types/react-dom": "^18.2.17",
21+
"@typescript-eslint/eslint-plugin": "^6.13.1",
22+
"@typescript-eslint/parser": "^6.13.1",
23+
"eslint": "^8.54.0",
24+
"eslint-config-prettier": "^9.0.0",
25+
"eslint-plugin-prettier": "^5.0.1",
26+
"eslint-plugin-react": "^7.33.2",
27+
"prettier": "^3.1.0"
2828
}
2929
}

Diff for: book/1-end/app/yarn.lock

+1,783-5,907
Large diffs are not rendered by default.

Diff for: book/10-begin/api/.elasticbeanstalk/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ environment-defaults:
88
global:
99
application_name: api-saas-boilerplate-app
1010
default_ec2_keyname: null
11-
default_platform: Node.js 14 running on 64bit Amazon Linux 2
11+
default_platform: Node.js 18 running on 64bit Amazon Linux 2
1212
default_region: us-east-1
1313
include_git_submodules: true
1414
instance_profile: null

Diff for: book/10-begin/api/package.json

+30-33
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,48 @@
1515
"testEnvironment": "node"
1616
},
1717
"dependencies": {
18-
"aws-sdk": "^2.796.0",
19-
"bcrypt": "^5.0.0",
20-
"compression": "^1.7.4",
21-
"connect-mongo": "^3.2.0",
18+
"aws-sdk": "^2.1512.0",
19+
"bcrypt": "^5.1.1",
20+
"connect-mongo": "^5.1.0",
2221
"cors": "^2.8.5",
23-
"dotenv": "^8.2.0",
24-
"express": "^4.17.1",
22+
"dotenv": "^16.3.1",
23+
"express": "^4.18.2",
2524
"express-session": "^1.17.1",
2625
"he": "^1.2.0",
27-
"helmet": "4.1.0-rc.2",
28-
"highlight.js": "^10.5.0",
26+
"highlight.js": "^11.9.0",
2927
"lodash": "^4.17.20",
30-
"marked": "^4.0.16",
31-
"mongoose": "^6.3.5",
32-
"node-fetch": "^2.6.1",
33-
"passport": "^0.6.0",
28+
"marked": "^11.0.0",
29+
"mongoose": "^8.0.2",
30+
"node-fetch": "2.6.1",
31+
"passport": "^0.7.0",
3432
"passport-google-oauth": "^2.0.0",
3533
"passwordless": "^1.1.3",
3634
"passwordless-tokenstore": "^0.0.10",
37-
"socket.io": "^3.0.3",
38-
"stripe": "^8.129.0",
39-
"typescript": "^4.7.3",
40-
"winston": "^3.3.3"
35+
"socket.io": "^4.7.2",
36+
"stripe": "^14.7.0",
37+
"typescript": "^5.3.2"
4138
},
4239
"devDependencies": {
4340
"@types/connect-mongo": "^3.1.3",
4441
"@types/dotenv": "^8.2.0",
45-
"@types/express": "^4.11.1",
46-
"@types/express-session": "^1.15.8",
47-
"@types/jest": "^22.2.3",
48-
"@types/lodash": "^4.14.108",
42+
"@types/express": "^4.17.21",
43+
"@types/express-session": "^1.17.10",
44+
"@types/jest": "^29.5.11",
45+
"@types/lodash": "^4.14.202",
4946
"@types/mongoose": "^5.5.43",
50-
"@types/node": "^12.12.2",
51-
"@types/node-fetch": "^1.6.9",
52-
"@types/passport": "^1.0.8",
47+
"@types/node": "^20.10.3",
48+
"@types/node-fetch": "^2.6.9",
49+
"@types/passport": "^1.0.16",
5350
"@types/socket.io": "^3.0.2",
54-
"@typescript-eslint/eslint-plugin": "^4.2.0",
55-
"@typescript-eslint/parser": "^4.2.0",
56-
"eslint": "^7.25.0",
57-
"eslint-config-prettier": "^7.1.0",
58-
"eslint-plugin-prettier": "^3.3.1",
59-
"jest": "^26.4.2",
60-
"nodemon": "^2.0.7",
61-
"prettier": "^2.2.1",
62-
"ts-jest": "^26.4.4",
63-
"ts-node": "^10.8.1"
51+
"@typescript-eslint/eslint-plugin": "^6.13.2",
52+
"@typescript-eslint/parser": "^6.13.2",
53+
"eslint": "^8.55.0",
54+
"eslint-config-prettier": "^9.1.0",
55+
"eslint-plugin-prettier": "^5.0.1",
56+
"jest": "^29.7.0",
57+
"nodemon": "^3.0.2",
58+
"prettier": "^3.1.0",
59+
"ts-jest": "^29.1.1",
60+
"ts-node": "^10.9.1"
6461
}
6562
}

Diff for: book/10-begin/api/server/google-auth.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ function setupGoogle({ server }) {
6464
});
6565

6666
passport.deserializeUser((id, done) => {
67-
User.findById(id, User.publicFields()).exec((err, user) => {
68-
done(err, user);
69-
});
67+
User.findById(id, User.publicFields())
68+
.then((user) => {
69+
done(null, user);
70+
})
71+
.catch((error) => {
72+
done(error, null);
73+
});
7074
});
7175

7276
server.use(passport.initialize());

Diff for: book/10-begin/api/server/models/Post.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as mongoose from 'mongoose';
22

33
import * as he from 'he';
4-
import * as hljs from 'highlight.js';
4+
import hljs from 'highlight.js';
55
import { marked } from 'marked';
66

77
import Discussion from './Discussion';
@@ -52,16 +52,19 @@ function markdownToHtml(content) {
5252
`;
5353
};
5454

55+
renderer.code = (code, infostring: string) => {
56+
const [lang] = infostring.split(' | ');
57+
58+
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
59+
60+
return `<pre><code class="hljs language-${lang}">${
61+
hljs.highlight(code, { language }).value
62+
}</code></pre>`;
63+
};
64+
5565
marked.setOptions({
5666
renderer,
5767
breaks: true,
58-
highlight(code, lang) {
59-
if (!lang) {
60-
return hljs.highlightAuto(code).value;
61-
}
62-
63-
return hljs.highlight(lang, code).value;
64-
},
6568
});
6669

6770
return marked(he.decode(content));

Diff for: book/10-begin/api/server/passwordless-auth.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ function setupPasswordless({ server }) {
3636

3737
server.use((req, __, next) => {
3838
if (req.user && typeof req.user === 'string') {
39-
User.findById(req.user, User.publicFields()).exec((err, user) => {
40-
req.user = user;
41-
console.log('passwordless middleware');
42-
next(err);
43-
});
39+
User.findById(req.user, User.publicFields())
40+
.then((user) => {
41+
req.user = user;
42+
console.log('passwordless middleware');
43+
next();
44+
})
45+
.catch((err) => {
46+
next(err);
47+
});
4448
} else {
4549
next();
4650
}
@@ -77,14 +81,14 @@ function setupPasswordless({ server }) {
7781
'/auth/logged_in',
7882
passwordless.acceptToken(),
7983
(req, __, next) => {
80-
if (req.user && typeof req.user === 'string') {
81-
User.findById(req.user, User.publicFields()).exec((err, user) => {
84+
User.findById(req.user, User.publicFields())
85+
.then((user) => {
8286
req.user = user;
87+
next();
88+
})
89+
.catch((err) => {
8390
next(err);
8491
});
85-
} else {
86-
next();
87-
}
8892
},
8993
async (req, res) => {
9094
let teamSlugOfInvitedTeam;

Diff for: book/10-begin/api/server/server.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import * as mongoSessionStore from 'connect-mongo';
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const MongoStore = require('connect-mongo');
3+
24
import * as cors from 'cors';
35
import * as express from 'express';
46
import * as session from 'express-session';
@@ -30,15 +32,13 @@ stripeWebhookAndCheckoutCallback({ server });
3032

3133
server.use(express.json());
3234

33-
const MongoStore = mongoSessionStore(session);
34-
3535
const sessionOptions = {
3636
name: process.env.SESSION_NAME,
3737
secret: process.env.SESSION_SECRET,
3838
resave: false,
3939
saveUninitialized: false,
40-
store: new MongoStore({
41-
mongooseConnection: mongoose.connection,
40+
store: MongoStore.create({
41+
mongoUrl: process.env.MONGO_URL_TEST,
4242
ttl: 14 * 24 * 60 * 60, // save session 14 days
4343
autoRemove: 'interval',
4444
autoRemoveInterval: 1440, // clears every day

Diff for: book/10-begin/api/server/sockets.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function setupSockets({ httpServer, origin, sessionMiddleware }) {
1616
credentials: true,
1717
},
1818
cookie: {
19+
name: 'io',
1920
httpOnly: true,
2021
maxAge: 14 * 24 * 60 * 60 * 1000, // expires in 14 days
2122
domain: 'localhost',
@@ -29,7 +30,7 @@ function setupSockets({ httpServer, origin, sessionMiddleware }) {
2930

3031
io.use(wrap(sessionMiddleware));
3132

32-
io.on('connection', (socket) => {
33+
io.on('connection', (socket: any) => {
3334
if (
3435
!socket.request.session ||
3536
((!socket.request.session.passport || !socket.request.session.passport.user) &&

Diff for: book/10-begin/api/server/stripe.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const dev = process.env.NODE_ENV !== 'production';
88

99
const stripeInstance = new Stripe(
1010
dev ? process.env.STRIPE_TEST_SECRETKEY : process.env.STRIPE_LIVE_SECRETKEY,
11-
{ apiVersion: '2020-08-27' },
11+
{ apiVersion: '2023-10-16' },
1212
);
1313

1414
function createSession({ userId, teamId, teamSlug, customerId, subscriptionId, userEmail, mode }) {
@@ -66,7 +66,7 @@ function updateSubscription(subscriptionId: string, params: Stripe.SubscriptionU
6666

6767
function cancelSubscription({ subscriptionId }) {
6868
console.log('cancel subscription', subscriptionId);
69-
return stripeInstance.subscriptions.del(subscriptionId);
69+
return stripeInstance.subscriptions.cancel(subscriptionId);
7070
}
7171

7272
function getListOfInvoices({ customerId }) {
@@ -93,7 +93,6 @@ function stripeWebhookAndCheckoutCallback({ server }) {
9393
// Occurs whenever an invoice payment attempt fails, due either to a declined payment or to the lack of a stored payment method.
9494

9595
if (event.type === 'invoice.payment_failed') {
96-
// @ts-expect-error subscription does not exist on type Object
9796
const { subscription } = event.data.object;
9897
console.log(JSON.stringify(subscription));
9998

Diff for: book/10-begin/api/test/server/utils/slugify.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { generateSlug } from '../../../server/utils/slugify';
66
require('dotenv').config();
77

88
describe('slugify', () => {
9-
beforeAll(async (done) => {
9+
beforeAll(async () => {
1010
await mongoose.connect(process.env.MONGO_URL_TEST);
1111

1212
const mockUsers = [
@@ -34,8 +34,6 @@ describe('slugify', () => {
3434
];
3535

3636
await User.insertMany(mockUsers);
37-
38-
done();
3937
});
4038

4139
test('not duplicated', async () => {
@@ -56,10 +54,8 @@ describe('slugify', () => {
5654
await expect(generateSlug(User, 'John & Johnson@#$')).resolves.toEqual('john-johnson-2');
5755
});
5856

59-
afterAll(async (done) => {
57+
afterAll(async () => {
6058
await User.deleteMany({ slug: { $in: ['john', 'john-johnson', 'john-johnson-1'] } });
6159
await mongoose.disconnect();
62-
63-
done();
6460
});
6561
});

0 commit comments

Comments
 (0)