@xenterprises/fastify-xconfig 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +171 -18
- package/dist/utils/randomUUID.d.ts +1 -1
- package/dist/xConfig.d.ts +1 -2
- package/dist/xConfig.js +2 -7
- package/dist/xConfig.js.map +1 -1
- package/package.json +23 -42
- package/server/app.js +78 -0
- package/src/auth/admin.js +181 -0
- package/src/auth/portal.js +177 -0
- package/src/integrations/cloudinary.js +98 -0
- package/src/integrations/geocode.js +43 -0
- package/src/integrations/prisma.js +30 -0
- package/src/integrations/sendgrid.js +58 -0
- package/src/integrations/twilio.js +146 -0
- package/src/lifecycle/xFastifyAfter.js +27 -0
- package/src/middleware/bugsnag.js +10 -0
- package/src/middleware/cors.js +10 -0
- package/src/middleware/fancyErrors.js +26 -0
- package/src/middleware/multipart.js +6 -0
- package/src/middleware/rateLimit.js +6 -0
- package/src/middleware/underPressure.js +6 -0
- package/src/utils/colorize.js +37 -0
- package/src/utils/cookie.js +5 -0
- package/src/utils/formatBytes.js +16 -0
- package/src/utils/health.js +126 -0
- package/src/utils/xEcho.js +12 -0
- package/src/utils/xSlugify.js +20 -0
- package/src/utils/xUUID.js +14 -0
- package/src/xConfig.js +117 -0
- package/test/index.js +17 -0
- package/tsconfig.json +9 -11
- package/xConfigReference.js +1526 -0
- package/xConfigWorkingList.js +720 -0
- package/.github/workflows/ci.yml +0 -19
- package/.taprc +0 -3
- package/example.ts +0 -13
- package/src/xConfig.ts +0 -20
- package/test/index.test-d.ts +0 -13
- package/test/index.test.js +0 -14
- package/test/xConfig.js +0 -115
- /package/{src → ts-reference}/integrations/cloudinary.ts +0 -0
- /package/{src → ts-reference}/integrations/prisma.ts +0 -0
- /package/{src → ts-reference}/integrations/sendgrid.ts +0 -0
- /package/{src → ts-reference}/integrations/stripe.ts +0 -0
- /package/{src → ts-reference}/integrations/twilio.ts +0 -0
- /package/{src → ts-reference}/middleware/bugsnag.ts +0 -0
- /package/{src → ts-reference}/middleware/cors.ts +0 -0
- /package/{src → ts-reference}/middleware/errorHandler.ts +0 -0
- /package/{src → ts-reference}/middleware/multipart.ts +0 -0
- /package/{src → ts-reference}/middleware/rateLimit.ts +0 -0
- /package/{src → ts-reference}/middleware/underPressure.ts +0 -0
- /package/{src → ts-reference}/utils/colorize.ts +0 -0
- /package/{src → ts-reference}/utils/formatBytes.ts +0 -0
- /package/{src → ts-reference}/utils/randomUUID.ts +0 -0
- /package/{src → ts-reference}/utils/statAsync.ts +0 -0
package/.github/workflows/ci.yml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
name: CI workflow
|
|
2
|
-
on: [push, pull_request]
|
|
3
|
-
jobs:
|
|
4
|
-
test:
|
|
5
|
-
runs-on: ${{ matrix.os }}
|
|
6
|
-
strategy:
|
|
7
|
-
matrix:
|
|
8
|
-
node-version: [10.x, 12.x, 14.x]
|
|
9
|
-
os: [ubuntu-latest, windows-latest]
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v2
|
|
12
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
13
|
-
uses: actions/setup-node@v1
|
|
14
|
-
with:
|
|
15
|
-
node-version: ${{ matrix.node-version }}
|
|
16
|
-
- name: Install Dependencies
|
|
17
|
-
run: npm install --ignore-scripts
|
|
18
|
-
- name: Test
|
|
19
|
-
run: npm run test
|
package/.taprc
DELETED
package/example.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FastifyPluginCallback } from 'fastify'
|
|
2
|
-
|
|
3
|
-
declare module 'fastify' {
|
|
4
|
-
export interface FastifyInstance {
|
|
5
|
-
// This is an example decorator type added to fastify
|
|
6
|
-
exampleDecorator: () => string
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare const example: FastifyPluginCallback<() => string>
|
|
11
|
-
|
|
12
|
-
export { example }
|
|
13
|
-
export default example
|
package/src/xConfig.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import fp from "fastify-plugin";
|
|
2
|
-
import type { FastifyInstance, FastifyPluginOptions } from "fastify";
|
|
3
|
-
import { captureRoutes, printRoutes } from "./utils/colorize";
|
|
4
|
-
|
|
5
|
-
async function xConfig(
|
|
6
|
-
fastify: FastifyInstance,
|
|
7
|
-
options: FastifyPluginOptions
|
|
8
|
-
) {
|
|
9
|
-
// Capture routes using the hook
|
|
10
|
-
const routes = captureRoutes(fastify);
|
|
11
|
-
|
|
12
|
-
// After all plugins are loaded, print the routes
|
|
13
|
-
fastify.ready(() => {
|
|
14
|
-
printRoutes(routes);
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default fp(xConfig, {
|
|
19
|
-
name: "xConfig",
|
|
20
|
-
});
|
package/test/index.test-d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import fastify from 'fastify'
|
|
2
|
-
import example from '../example'
|
|
3
|
-
import { expectType } from 'tsd'
|
|
4
|
-
|
|
5
|
-
let app
|
|
6
|
-
try {
|
|
7
|
-
app = fastify()
|
|
8
|
-
void app.ready()
|
|
9
|
-
void app.register(example)
|
|
10
|
-
expectType<() => string>(app.exampleDecorator)
|
|
11
|
-
} catch (err) {
|
|
12
|
-
console.error(err)
|
|
13
|
-
}
|
package/test/index.test.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { test } = require('node:test')
|
|
4
|
-
const assert = require('node:assert')
|
|
5
|
-
|
|
6
|
-
test('should register the correct decorator', async t => {
|
|
7
|
-
const app = require('fastify')()
|
|
8
|
-
|
|
9
|
-
app.register(require('..'))
|
|
10
|
-
|
|
11
|
-
await app.ready()
|
|
12
|
-
|
|
13
|
-
assert.equal(app.exampleDecorator(), 'decorated')
|
|
14
|
-
})
|
package/test/xConfig.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { test } from 'node:test';
|
|
2
|
-
import * as assert from 'node:assert';
|
|
3
|
-
import Fastify from 'fastify';
|
|
4
|
-
import xConfig from '../path/to/xConfig.js'; // Adjust the path accordingly
|
|
5
|
-
|
|
6
|
-
test('xConfig plugin works standalone', async (t) => {
|
|
7
|
-
const fastify = Fastify();
|
|
8
|
-
|
|
9
|
-
// Register the xConfig plugin with necessary options
|
|
10
|
-
await fastify.register(xConfig, {
|
|
11
|
-
prisma: { active: false }, // Mocked or disabled for testing
|
|
12
|
-
sendGrid: { active: false },
|
|
13
|
-
twilio: { active: false },
|
|
14
|
-
stripe: { active: false },
|
|
15
|
-
auth: {
|
|
16
|
-
admin: { active: false },
|
|
17
|
-
user: { active: false }
|
|
18
|
-
},
|
|
19
|
-
cors: { active: true },
|
|
20
|
-
underPressure: { active: false },
|
|
21
|
-
rateLimit: { active: false }
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
await fastify.ready();
|
|
25
|
-
|
|
26
|
-
// Test if the plugin registered correctly
|
|
27
|
-
assert.ok(fastify.prisma === undefined, 'Prisma should not be registered');
|
|
28
|
-
assert.ok(fastify.sendGrid === undefined, 'SendGrid should not be registered');
|
|
29
|
-
assert.ok(fastify.stripe === undefined, 'Stripe should not be registered');
|
|
30
|
-
|
|
31
|
-
// Test if health route is registered and works
|
|
32
|
-
const response = await fastify.inject({
|
|
33
|
-
method: 'GET',
|
|
34
|
-
url: '/health'
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const body = JSON.parse(response.body);
|
|
38
|
-
assert.strictEqual(response.statusCode, 200, 'Health route should return status 200');
|
|
39
|
-
assert.strictEqual(body.status, 'healthy', 'Health status should be healthy');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('xConfig CORS is enabled', async (t) => {
|
|
43
|
-
const fastify = Fastify();
|
|
44
|
-
|
|
45
|
-
// Register the xConfig plugin with CORS enabled
|
|
46
|
-
await fastify.register(xConfig, {
|
|
47
|
-
cors: {
|
|
48
|
-
active: true,
|
|
49
|
-
origin: ['http://localhost:3000'],
|
|
50
|
-
credentials: true
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await fastify.ready();
|
|
55
|
-
|
|
56
|
-
// Check if the CORS headers are returned correctly
|
|
57
|
-
const response = await fastify.inject({
|
|
58
|
-
method: 'OPTIONS',
|
|
59
|
-
url: '/',
|
|
60
|
-
headers: {
|
|
61
|
-
origin: 'http://localhost:3000'
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
assert.strictEqual(response.headers['access-control-allow-origin'], 'http://localhost:3000');
|
|
66
|
-
assert.strictEqual(response.headers['access-control-allow-credentials'], 'true');
|
|
67
|
-
assert.strictEqual(response.statusCode, 204, 'CORS preflight request should return 204');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('xConfig routes are listed correctly', async (t) => {
|
|
71
|
-
const fastify = Fastify();
|
|
72
|
-
|
|
73
|
-
// Register xConfig plugin with a dummy route to check if routes are listed
|
|
74
|
-
await fastify.register(xConfig, {
|
|
75
|
-
prisma: { active: false },
|
|
76
|
-
auth: { admin: { active: false }, user: { active: false } }
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
fastify.get('/test-route', async (request, reply) => {
|
|
80
|
-
reply.send({ message: 'Test Route' });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
await fastify.ready();
|
|
84
|
-
|
|
85
|
-
// Test if the '/test-route' is available
|
|
86
|
-
const response = await fastify.inject({
|
|
87
|
-
method: 'GET',
|
|
88
|
-
url: '/test-route'
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
assert.strictEqual(response.statusCode, 200, 'Test route should return 200');
|
|
92
|
-
assert.strictEqual(JSON.parse(response.body).message, 'Test Route');
|
|
93
|
-
|
|
94
|
-
// Check if routes are printed correctly (this is more of a manual log observation)
|
|
95
|
-
fastify.ready(() => {
|
|
96
|
-
fastify.printRoutes(); // This will print routes to console
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('xConfig fails if required options are missing', async (t) => {
|
|
101
|
-
const fastify = Fastify();
|
|
102
|
-
|
|
103
|
-
// Test missing required options like SendGrid API Key
|
|
104
|
-
try {
|
|
105
|
-
await fastify.register(xConfig, {
|
|
106
|
-
sendGrid: { active: true }
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
await fastify.ready();
|
|
110
|
-
assert.fail('Should have thrown an error due to missing SendGrid API Key');
|
|
111
|
-
} catch (err) {
|
|
112
|
-
assert.ok(err instanceof Error, 'Should throw an error');
|
|
113
|
-
assert.strictEqual(err.message, 'SendGrid API key must be provided.');
|
|
114
|
-
}
|
|
115
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|