Skip to content

Commit 8e3941b

Browse files
authored
Restructure + nodenext (#185)
* disable package-lock generation * move types to types folder simplify npm scripts * restructure and rename variables
1 parent d1c31ee commit 8e3941b

File tree

8 files changed

+242
-212
lines changed

8 files changed

+242
-212
lines changed

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.taprc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,2 @@
1-
100: true
2-
ts: false
3-
jsx: false
4-
flow: false
5-
coverage: true
6-
check-coverage: true
1+
files:
2+
- 'test/**/*.test.js'

index.d.ts

Lines changed: 0 additions & 133 deletions
This file was deleted.

index.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function defaultGenerateCallbackUriParams (callbackUriParams) {
2525
return callbackUriParams
2626
}
2727

28-
const oauthPlugin = fp(function (fastify, options, next) {
28+
function fastifyOauth2 (fastify, options, next) {
2929
if (typeof options.name !== 'string') {
3030
return next(new Error('options.name should be a string'))
3131
}
@@ -152,12 +152,9 @@ const oauthPlugin = fp(function (fastify, options, next) {
152152
}
153153

154154
next()
155-
}, {
156-
fastify: '4.x',
157-
name: '@fastify/oauth2'
158-
})
155+
}
159156

160-
oauthPlugin.APPLE_CONFIGURATION = {
157+
fastifyOauth2.APPLE_CONFIGURATION = {
161158
authorizeHost: 'https://appleid.apple.com',
162159
authorizePath: '/auth/authorize',
163160
tokenHost: 'https://appleid.apple.com',
@@ -181,87 +178,92 @@ oauthPlugin.APPLE_CONFIGURATION = {
181178
}
182179
}
183180

184-
oauthPlugin.FACEBOOK_CONFIGURATION = {
181+
fastifyOauth2.FACEBOOK_CONFIGURATION = {
185182
authorizeHost: 'https://facebook.com',
186183
authorizePath: '/v6.0/dialog/oauth',
187184
tokenHost: 'https://graph.facebook.com',
188185
tokenPath: '/v6.0/oauth/access_token'
189186
}
190187

191-
oauthPlugin.GITHUB_CONFIGURATION = {
188+
fastifyOauth2.GITHUB_CONFIGURATION = {
192189
tokenHost: 'https://github.com',
193190
tokenPath: '/login/oauth/access_token',
194191
authorizePath: '/login/oauth/authorize'
195192
}
196193

197-
oauthPlugin.LINKEDIN_CONFIGURATION = {
194+
fastifyOauth2.LINKEDIN_CONFIGURATION = {
198195
authorizeHost: 'https://www.linkedin.com',
199196
authorizePath: '/oauth/v2/authorization',
200197
tokenHost: 'https://www.linkedin.com',
201198
tokenPath: '/oauth/v2/accessToken'
202199
}
203200

204-
oauthPlugin.GOOGLE_CONFIGURATION = {
201+
fastifyOauth2.GOOGLE_CONFIGURATION = {
205202
authorizeHost: 'https://accounts.google.com',
206203
authorizePath: '/o/oauth2/v2/auth',
207204
tokenHost: 'https://www.googleapis.com',
208205
tokenPath: '/oauth2/v4/token'
209206
}
210207

211-
oauthPlugin.MICROSOFT_CONFIGURATION = {
208+
fastifyOauth2.MICROSOFT_CONFIGURATION = {
212209
authorizeHost: 'https://login.microsoftonline.com',
213210
authorizePath: '/common/oauth2/v2.0/authorize',
214211
tokenHost: 'https://login.microsoftonline.com',
215212
tokenPath: '/common/oauth2/v2.0/token'
216213
}
217214

218-
oauthPlugin.VKONTAKTE_CONFIGURATION = {
215+
fastifyOauth2.VKONTAKTE_CONFIGURATION = {
219216
authorizeHost: 'https://oauth.vk.com',
220217
authorizePath: '/authorize',
221218
tokenHost: 'https://oauth.vk.com',
222219
tokenPath: '/access_token'
223220
}
224221

225-
oauthPlugin.SPOTIFY_CONFIGURATION = {
222+
fastifyOauth2.SPOTIFY_CONFIGURATION = {
226223
authorizeHost: 'https://accounts.spotify.com',
227224
authorizePath: '/authorize',
228225
tokenHost: 'https://accounts.spotify.com',
229226
tokenPath: '/api/token'
230227
}
231228

232-
oauthPlugin.DISCORD_CONFIGURATION = {
229+
fastifyOauth2.DISCORD_CONFIGURATION = {
233230
authorizeHost: 'https://discord.com',
234231
authorizePath: '/api/oauth2/authorize',
235232
tokenHost: 'https://discord.com',
236233
tokenPath: '/api/oauth2/token'
237234
}
238235

239-
oauthPlugin.TWITCH_CONFIGURATION = {
236+
fastifyOauth2.TWITCH_CONFIGURATION = {
240237
authorizeHost: 'https://id.twitch.tv',
241238
authorizePath: '/oauth2/authorize',
242239
tokenHost: 'https://id.twitch.tv',
243240
tokenPath: '/oauth2/token'
244241
}
245242

246-
oauthPlugin.VATSIM_CONFIGURATION = {
243+
fastifyOauth2.VATSIM_CONFIGURATION = {
247244
authorizeHost: 'https://auth.vatsim.net',
248245
authorizePath: '/oauth/authorize',
249246
tokenHost: 'https://auth.vatsim.net',
250247
tokenPath: '/oauth/token'
251248
}
252249

253-
oauthPlugin.VATSIM_DEV_CONFIGURATION = {
250+
fastifyOauth2.VATSIM_DEV_CONFIGURATION = {
254251
authorizeHost: 'https://auth-dev.vatsim.net',
255252
authorizePath: '/oauth/authorize',
256253
tokenHost: 'https://auth-dev.vatsim.net',
257254
tokenPath: '/oauth/token'
258255
}
259256

260-
oauthPlugin.EPIC_GAMES_CONFIGURATION = {
257+
fastifyOauth2.EPIC_GAMES_CONFIGURATION = {
261258
authorizeHost: 'https://www.epicgames.com',
262259
authorizePath: '/id/authorize',
263260
tokenHost: 'https://api.epicgames.dev',
264261
tokenPath: '/epic/oauth/v1/token'
265262
}
266263

267-
module.exports = oauthPlugin
264+
module.exports = fp(fastifyOauth2, {
265+
fastify: '4.x',
266+
name: '@fastify/oauth2'
267+
})
268+
module.exports.default = fastifyOauth2
269+
module.exports.fastifyOauth2 = fastifyOauth2

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"version": "6.1.0",
44
"description": "Perform login using oauth2 protocol",
55
"main": "index.js",
6-
"types": "index.d.ts",
6+
"types": "types/index.d.ts",
77
"scripts": {
8-
"coverage": "npm run unit -- --cov --coverage-report=html",
98
"lint": "standard | snazzy",
109
"lint:fix": "standard --fix",
11-
"test": "npm run unit && npm run test:typescript",
10+
"test": "npm run test:unit && npm run test:typescript",
11+
"test:coverage": "npm run unit -- --cov --coverage-report=html",
1212
"test:typescript": "tsd",
13-
"unit": "tap -J \"test/*.test.js\""
13+
"test:unit": "tap"
1414
},
1515
"repository": {
1616
"type": "git",
@@ -41,10 +41,11 @@
4141
"fastify-plugin": "^4.0.0",
4242
"simple-oauth2": "^5.0.0"
4343
},
44-
"tsd": {
45-
"directory": "test/types"
46-
},
4744
"publishConfig": {
4845
"access": "public"
49-
}
46+
},
47+
"pre-commit": [
48+
"lint",
49+
"test"
50+
]
5051
}

0 commit comments

Comments
 (0)