@sapphire/plugin-api
Advanced tools
Comparing version 2.2.1-next.84f5a8d.0 to 3.0.0-next.050a6d5.0
@@ -28,3 +28,3 @@ import type { Server, ServerOptions } from './lib/structures/http/Server'; | ||
} | ||
declare module '@sapphire/framework' { | ||
declare module '@sapphire/pieces' { | ||
interface StoreRegistryEntries { | ||
@@ -35,3 +35,6 @@ routes: RouteStore; | ||
} | ||
interface Container { | ||
server: Server; | ||
} | ||
} | ||
//# sourceMappingURL=index.d.ts.map |
@@ -81,3 +81,3 @@ "use strict"; | ||
} | ||
return this.status(error).json({ error: data !== null && data !== void 0 ? data : http_1.STATUS_CODES[error] }); | ||
return this.status(error).json({ error: data ?? http_1.STATUS_CODES[error] }); | ||
} | ||
@@ -84,0 +84,0 @@ /** |
@@ -10,3 +10,2 @@ "use strict"; | ||
constructor(request, response, secure, domainOverwrite) { | ||
var _a, _b; | ||
super(); | ||
@@ -50,4 +49,4 @@ Object.defineProperty(this, "request", { | ||
} | ||
const [splitHost] = (_b = (_a = this.request.headers.host) === null || _a === void 0 ? void 0 : _a.split(':')) !== null && _b !== void 0 ? _b : ['']; | ||
this.domain = domainOverwrite !== null && domainOverwrite !== void 0 ? domainOverwrite : this.getHostDomain(splitHost); | ||
const [splitHost] = this.request.headers.host?.split(':') ?? ['']; | ||
this.domain = domainOverwrite ?? this.getHostDomain(splitHost); | ||
if (this.request.socket.remoteAddress === this.domain) { | ||
@@ -93,9 +92,9 @@ throw new Error('The connection must be established from the domain name (i.e., not an IP address)'); | ||
// RFC 6265 5.1.3 Domain Matching | ||
domain = (domain !== null && domain !== void 0 ? domain : this.domain).toLowerCase(); | ||
domain = (domain ?? this.domain).toLowerCase(); | ||
entry += `; Domain=${domain}`; | ||
entry += `; Path=${path !== null && path !== void 0 ? path : '/'}`; | ||
entry += `; Path=${path ?? '/'}`; | ||
if (this.secure) { | ||
entry += `; Secure`; | ||
} | ||
if (httpOnly !== null && httpOnly !== void 0 ? httpOnly : true) { | ||
if (httpOnly ?? true) { | ||
entry += `; HttpOnly`; | ||
@@ -102,0 +101,0 @@ } |
@@ -11,3 +11,2 @@ "use strict"; | ||
constructor(options) { | ||
var _a, _b, _c, _d; | ||
/** | ||
@@ -72,8 +71,8 @@ * The client's application id, this can be retrieved in Discord Developer Portal at https://discord.com/developers/applications. | ||
this.id = options.id; | ||
this.cookie = (_a = options.cookie) !== null && _a !== void 0 ? _a : 'SAPPHIRE_AUTH'; | ||
this.scopes = (_b = options.scopes) !== null && _b !== void 0 ? _b : ['identify']; | ||
this.cookie = options.cookie ?? 'SAPPHIRE_AUTH'; | ||
this.scopes = options.scopes ?? ['identify']; | ||
this.redirect = options.redirect; | ||
tslib_1.__classPrivateFieldSet(this, _Auth_secret, options.secret, "f"); | ||
this.transformers = (_c = options.transformers) !== null && _c !== void 0 ? _c : []; | ||
this.domainOverwrite = (_d = options.domainOverwrite) !== null && _d !== void 0 ? _d : null; | ||
this.transformers = options.transformers ?? []; | ||
this.domainOverwrite = options.domainOverwrite ?? null; | ||
} | ||
@@ -150,3 +149,3 @@ /** | ||
static create(options) { | ||
if (!(options === null || options === void 0 ? void 0 : options.secret) || !options.id) | ||
if (!options?.secret || !options.id) | ||
return null; | ||
@@ -153,0 +152,0 @@ return new Auth(options); |
@@ -172,7 +172,2 @@ /// <reference types="node" /> | ||
} | ||
declare module '@sapphire/pieces' { | ||
interface PieceContextExtras { | ||
server: Server; | ||
} | ||
} | ||
//# sourceMappingURL=Server.d.ts.map |
@@ -33,3 +33,2 @@ "use strict"; | ||
constructor({ auth, ...options } = {}) { | ||
var _a; | ||
super(); | ||
@@ -96,3 +95,3 @@ /** | ||
}); | ||
pieces_1.Store.injectedContext.server = this; | ||
pieces_1.container.server = this; | ||
this.options = options; | ||
@@ -104,3 +103,3 @@ this.server = http_1.createServer({ | ||
ServerResponse: ApiResponse_1.ApiResponse, | ||
...((_a = options.server) !== null && _a !== void 0 ? _a : {}) | ||
...(options.server ?? {}) | ||
}); | ||
@@ -115,7 +114,6 @@ this.routes = new RouteStore_1.RouteStore(); | ||
connect() { | ||
var _a; | ||
const { server } = this; | ||
server.listen({ | ||
port: 4000, | ||
...((_a = this.options.listenOptions) !== null && _a !== void 0 ? _a : {}) | ||
...(this.options.listenOptions ?? {}) | ||
}); | ||
@@ -122,0 +120,0 @@ return new Promise((resolve, reject) => { |
@@ -53,4 +53,3 @@ "use strict"; | ||
contentStream(request) { | ||
var _a; | ||
switch (((_a = request.headers['content-encoding']) !== null && _a !== void 0 ? _a : 'identity').toLowerCase()) { | ||
switch ((request.headers['content-encoding'] ?? 'identity').toLowerCase()) { | ||
// RFC 7230 4.2.2: | ||
@@ -57,0 +56,0 @@ // |
@@ -10,3 +10,2 @@ "use strict"; | ||
constructor(context, options = {}) { | ||
var _a; | ||
super(context, options); | ||
@@ -29,3 +28,3 @@ /** | ||
}); | ||
this.position = (_a = options.position) !== null && _a !== void 0 ? _a : 1000; | ||
this.position = options.position ?? 1000; | ||
} | ||
@@ -32,0 +31,0 @@ } |
@@ -13,3 +13,2 @@ "use strict"; | ||
constructor(context, options = {}) { | ||
var _a, _b, _c, _d, _e, _f; | ||
super(context, options); | ||
@@ -52,4 +51,4 @@ /** | ||
}); | ||
const api = this.context.server.options; | ||
this.router = new RouteData_1.RouteData(`${(_a = api.prefix) !== null && _a !== void 0 ? _a : ''}${(_b = options.route) !== null && _b !== void 0 ? _b : ''}`); | ||
const api = this.container.server.options; | ||
this.router = new RouteData_1.RouteData(`${api.prefix ?? ''}${options.route ?? this.name ?? ''}`); | ||
for (const [method, symbol] of HttpMethods_1.methodEntries) { | ||
@@ -60,4 +59,4 @@ const value = Reflect.get(this, symbol); | ||
} | ||
this.maximumBodyLength = (_d = (_c = options.maximumBodyLength) !== null && _c !== void 0 ? _c : api.maximumBodyLength) !== null && _d !== void 0 ? _d : 1024 * 1024 * 50; | ||
this.acceptedContentMimeTypes = (_f = (_e = options.acceptedContentMimeTypes) !== null && _e !== void 0 ? _e : api.acceptedContentMimeTypes) !== null && _f !== void 0 ? _f : null; | ||
this.maximumBodyLength = options.maximumBodyLength ?? api.maximumBodyLength ?? 1024 * 1024 * 50; | ||
this.acceptedContentMimeTypes = options.acceptedContentMimeTypes ?? api.acceptedContentMimeTypes ?? null; | ||
} | ||
@@ -64,0 +63,0 @@ /** |
@@ -7,3 +7,2 @@ "use strict"; | ||
constructor(context) { | ||
var _a, _b; | ||
super(context, { position: 40 }); | ||
@@ -16,4 +15,4 @@ Object.defineProperty(this, "cookieName", { | ||
}); | ||
const { server } = this.context; | ||
this.cookieName = (_b = (_a = server.auth) === null || _a === void 0 ? void 0 : _a.cookie) !== null && _b !== void 0 ? _b : 'SAPPHIRE_AUTH'; | ||
const { server } = this.container; | ||
this.cookieName = server.auth?.cookie ?? 'SAPPHIRE_AUTH'; | ||
this.enabled = server.auth !== null; | ||
@@ -29,3 +28,3 @@ } | ||
// Decrypt the cookie, and if the token is invalid, remove the cookie: | ||
request.auth = this.context.server.auth.decrypt(authorization); | ||
request.auth = this.container.server.auth.decrypt(authorization); | ||
if (request.auth === null) | ||
@@ -32,0 +31,0 @@ response.cookies.remove(this.cookieName); |
@@ -15,3 +15,3 @@ "use strict"; | ||
}); | ||
this.mediaParsers = this.context.server.mediaParsers; | ||
this.mediaParsers = this.container.server.mediaParsers; | ||
} | ||
@@ -18,0 +18,0 @@ async run(request, response, route) { |
@@ -8,3 +8,2 @@ "use strict"; | ||
constructor(context) { | ||
var _a, _b; | ||
super(context, { position: 30 }); | ||
@@ -23,4 +22,4 @@ Object.defineProperty(this, "production", { | ||
}); | ||
const { server } = this.context; | ||
this.domainOverwrite = (_b = (_a = server.auth) === null || _a === void 0 ? void 0 : _a.domainOverwrite) !== null && _b !== void 0 ? _b : null; | ||
const { server } = this.container; | ||
this.domainOverwrite = server.auth?.domainOverwrite ?? null; | ||
} | ||
@@ -27,0 +26,0 @@ run(request, response) { |
@@ -8,3 +8,2 @@ "use strict"; | ||
constructor(context) { | ||
var _a; | ||
super(context, { position: 10 }); | ||
@@ -23,3 +22,3 @@ Object.defineProperty(this, "origin", { | ||
}); | ||
this.origin = (_a = this.context.server.options.origin) !== null && _a !== void 0 ? _a : '*'; | ||
this.origin = this.container.server.options.origin ?? '*'; | ||
} | ||
@@ -26,0 +25,0 @@ run(request, response, route) { |
@@ -21,3 +21,3 @@ "use strict"; | ||
.register(this.server.middlewares); | ||
this.stores.get('events').registerPath(path_1.join(__dirname, 'events')); | ||
this.stores.get('listeners').registerPath(path_1.join(__dirname, 'listeners')); | ||
this.server.routes.registerPath(path_1.join(__dirname, 'routes')); | ||
@@ -24,0 +24,0 @@ this.server.middlewares.registerPath(path_1.join(__dirname, 'middlewares')); |
@@ -12,3 +12,2 @@ "use strict"; | ||
constructor(context) { | ||
var _a; | ||
super(context, { route: 'oauth/callback' }); | ||
@@ -21,9 +20,9 @@ Object.defineProperty(this, "redirectUri", { | ||
}); | ||
const { server } = this.context; | ||
const { server } = this.container; | ||
this.enabled = server.auth !== null; | ||
this.redirectUri = (_a = server.auth) === null || _a === void 0 ? void 0 : _a.redirect; | ||
this.redirectUri = server.auth?.redirect; | ||
} | ||
async [HttpMethods_1.methods.POST](request, response) { | ||
const body = request.body; | ||
if (typeof (body === null || body === void 0 ? void 0 : body.code) !== 'string') { | ||
if (typeof body?.code !== 'string') { | ||
return response.badRequest(); | ||
@@ -36,3 +35,3 @@ } | ||
const now = Date.now(); | ||
const auth = this.context.server.auth; | ||
const auth = this.container.server.auth; | ||
const data = await auth.fetchData(value.access_token); | ||
@@ -52,4 +51,3 @@ if (!data.user) { | ||
async fetchAuth(body) { | ||
var _a; | ||
const { id, secret } = this.context.server.auth; | ||
const { id, secret } = this.container.server.auth; | ||
const data = { | ||
@@ -61,3 +59,3 @@ /* eslint-disable @typescript-eslint/naming-convention */ | ||
grant_type: 'authorization_code', | ||
redirect_uri: (_a = this.redirectUri) !== null && _a !== void 0 ? _a : body.redirectUri | ||
redirect_uri: this.redirectUri ?? body.redirectUri | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
@@ -75,3 +73,3 @@ }; | ||
return json; | ||
this.context.client.logger.error(json); | ||
this.container.logger.error(json); | ||
return null; | ||
@@ -78,0 +76,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
super(context, { route: 'oauth/logout' }); | ||
this.enabled = this.context.server.auth !== null; | ||
this.enabled = this.container.server.auth !== null; | ||
} | ||
@@ -52,7 +52,7 @@ async [HttpMethods_1.methods.POST](request, response) { | ||
// Sending an empty cookie with "expires" set to 1970-01-01 makes the browser instantly remove the cookie. | ||
response.cookies.remove(this.context.server.auth.cookie); | ||
response.cookies.remove(this.container.server.auth.cookie); | ||
return response.json({ success: true }); | ||
} | ||
async revoke(token) { | ||
const auth = this.context.server.auth; | ||
const auth = this.container.server.auth; | ||
// RFC 7009 2.1. | ||
@@ -59,0 +59,0 @@ // The following parameters must be formatted as "application/x-www-form-urlencoded" in the HTTP request-body: |
{ | ||
"name": "@sapphire/plugin-api", | ||
"version": "2.2.1-next.84f5a8d.0", | ||
"version": "3.0.0-next.050a6d5.0", | ||
"description": "Plugin for @sapphire/framework to expose a REST API", | ||
@@ -36,8 +36,8 @@ "author": "@sapphire", | ||
"dependencies": { | ||
"@types/node-fetch": "^2.5.11", | ||
"@types/node-fetch": "^2.5.12", | ||
"@types/psl": "^1.1.0", | ||
"@types/ws": "latest", | ||
"@types/ws": "7.4.7", | ||
"node-fetch": "^2.6.1", | ||
"psl": "^1.8.0", | ||
"tslib": "^2.3.0" | ||
"tslib": "^2.3.1" | ||
}, | ||
@@ -74,3 +74,3 @@ "repository": { | ||
}, | ||
"gitHead": "84f5a8d2cef3d1dbdbb44eaafe0d738f60c660d0" | ||
"gitHead": "050a6d5fabe0cb2172487060d4377f1e11b9ebee" | ||
} |
@@ -34,3 +34,2 @@ <div align="center"> | ||
- [`@sapphire/framework`](https://www.npmjs.com/package/@sapphire/framework) | ||
- [`@sapphire/pieces v1.x`](https://www.npmjs.com/package/@sapphire/pieces/v/1.2.5) | ||
- [`discord.js`](https://www.npmjs.com/package/discord.js) | ||
@@ -42,3 +41,3 @@ - [`discord-api-types`](https://www.npmjs.com/package/discord-api-types) | ||
```sh | ||
npm install @sapphire/plugin-api @sapphire/framework @sapphire/pieces@1 discord.js discord-api-types | ||
npm install @sapphire/plugin-api @sapphire/framework discord.js discord-api-types | ||
``` | ||
@@ -45,0 +44,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
198472
3266
141
+ Added@types/ws@7.4.7(transitive)
- Removed@types/ws@8.5.13(transitive)
Updated@types/node-fetch@^2.5.12
Updated@types/ws@7.4.7
Updatedtslib@^2.3.1