@eienjs/adonisjs-simple-auth 1.0.0 → 1.0.1

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.
@@ -1,12 +1,12 @@
1
1
  // src/errors.ts
2
2
  import { Exception } from "@adonisjs/core/exceptions";
3
- var SimpleAuthException = class extends Exception {
4
- static code;
5
- static status;
3
+ var SimpleAuthException = class _SimpleAuthException extends Exception {
4
+ static code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
5
+ static status = 401;
6
6
  /**
7
7
  * Translation identifier. Can be customized
8
8
  */
9
- identifier = `errors.${this.code}`;
9
+ identifier = `errors.${_SimpleAuthException.code}`;
10
10
  /**
11
11
  * Returns the message to be sent in the HTTP response.
12
12
  * Feel free to override this method and return a custom
@@ -77,4 +77,4 @@ export {
77
77
  SimpleAuthException,
78
78
  SimpleAuth
79
79
  };
80
- //# sourceMappingURL=chunk-2NK343C3.js.map
80
+ //# sourceMappingURL=chunk-JUF7K25A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/simple_auth.ts"],"sourcesContent":["import { Exception } from '@adonisjs/core/exceptions';\nimport { type HttpContext } from '@adonisjs/core/http';\nimport { type I18n } from '@adonisjs/i18n';\n\nexport class SimpleAuthException extends Exception {\n public static readonly code = 'E_SIMPLE_UNAUTHORIZED_ACCESS';\n\n public static readonly status = 401;\n\n /**\n * Translation identifier. Can be customized\n */\n public identifier = `errors.${SimpleAuthException.code}`;\n\n /**\n * Returns the message to be sent in the HTTP response.\n * Feel free to override this method and return a custom\n * response.\n */\n public getResponseMessage(error: this, ctx: HttpContext): string {\n if ('i18n' in ctx) {\n return (ctx.i18n as I18n).t(error.identifier, {}, error.message);\n }\n\n return error.message;\n }\n\n public async handle(error: this, ctx: HttpContext): Promise<void> {\n const message = this.getResponseMessage(error, ctx);\n\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'html':\n case null:\n case 'json': {\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n });\n break;\n }\n case 'application/vnd.api+json': {\n ctx.response.status(error.status).send({\n errors: [\n {\n code: error.code,\n title: message,\n },\n ],\n });\n break;\n }\n }\n }\n}\n","import { type HttpContext } from '@adonisjs/core/http';\nimport { SimpleAuthException } from './errors.js';\nimport { type ResolvedSimpleAuthConfig } from './types.js';\n\nexport class SimpleAuth {\n public constructor(\n protected ctx: HttpContext,\n protected config: ResolvedSimpleAuthConfig,\n ) {}\n\n protected authenticationFailed(): SimpleAuthException {\n return new SimpleAuthException('Unauthorized access');\n }\n\n protected getApiKeyRequest(): string {\n const apiKey = this.ctx.request.header(this.config.apiKeyHeader, '')!;\n if (!apiKey.trim()) {\n throw this.authenticationFailed();\n }\n\n return apiKey;\n }\n\n public authenticate(): void {\n const apiKeyTokenRequest = this.getApiKeyRequest();\n const apiKeyTokenConfig = this.config.apiKeyValue;\n\n if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {\n throw this.authenticationFailed();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAInB,IAAM,sBAAN,MAAM,6BAA4B,UAAU;AAAA,EACjD,OAAuB,OAAO;AAAA,EAE9B,OAAuB,SAAS;AAAA;AAAA;AAAA;AAAA,EAKzB,aAAa,UAAU,qBAAoB,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO/C,mBAAmB,OAAa,KAA0B;AAC/D,QAAI,UAAU,KAAK;AACjB,aAAQ,IAAI,KAAc,EAAE,MAAM,YAAY,CAAC,GAAG,MAAM,OAAO;AAAA,IACjE;AAEA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,OAAO,OAAa,KAAiC;AAChE,UAAM,UAAU,KAAK,mBAAmB,OAAO,GAAG;AAElD,YAAQ,IAAI,QAAQ,QAAQ,CAAC,QAAQ,4BAA4B,MAAM,CAAC,GAAG;AAAA,MACzE,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ;AACX,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAAA,MACA,KAAK,4BAA4B;AAC/B,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE,MAAM,MAAM;AAAA,cACZ,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;ACpDO,IAAM,aAAN,MAAiB;AAAA,EACf,YACK,KACA,QACV;AAFU;AACA;AAAA,EACT;AAAA,EAEO,uBAA4C;AACpD,WAAO,IAAI,oBAAoB,qBAAqB;AAAA,EACtD;AAAA,EAEU,mBAA2B;AACnC,UAAM,SAAS,KAAK,IAAI,QAAQ,OAAO,KAAK,OAAO,cAAc,EAAE;AACnE,QAAI,CAAC,OAAO,KAAK,GAAG;AAClB,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,eAAqB;AAC1B,UAAM,qBAAqB,KAAK,iBAAiB;AACjD,UAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAI,uBAAuB,kBAAkB,QAAQ,GAAG;AACtD,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAAA,EACF;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SimpleAuth
3
- } from "./chunk-2NK343C3.js";
3
+ } from "./chunk-JUF7K25A.js";
4
4
 
5
5
  // src/middleware/simple_auth_middleware.ts
6
6
  var SimpleAuthMiddleware = class {
@@ -16,4 +16,4 @@ var SimpleAuthMiddleware = class {
16
16
  export {
17
17
  SimpleAuthMiddleware
18
18
  };
19
- //# sourceMappingURL=chunk-Y74LYCT7.js.map
19
+ //# sourceMappingURL=chunk-TVVNPJ4M.js.map
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SimpleAuth,
3
3
  SimpleAuthException
4
- } from "./chunk-2NK343C3.js";
4
+ } from "./chunk-JUF7K25A.js";
5
5
  import "./chunk-EUXUH3YW.js";
6
6
 
7
7
  // stubs/main.ts
@@ -1 +1 @@
1
- {"inputs":{"stubs/main.ts":{"bytes":233,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":995,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/define_config.ts":{"bytes":526,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/errors.ts":{"bytes":1461,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/i18n","kind":"import-statement","external":true}],"format":"esm"},"src/simple_auth.ts":{"bytes":899,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"index.ts":{"bytes":250,"imports":[{"path":"configure.ts","kind":"import-statement","original":"./configure.js"},{"path":"src/define_config.ts","kind":"import-statement","original":"./src/define_config.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./src/errors.js"},{"path":"src/simple_auth.ts","kind":"import-statement","original":"./src/simple_auth.js"},{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/helpers/crc32.ts":{"bytes":4896,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"commands/generate_api_key.ts":{"bytes":1616,"imports":[{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"src/helpers/crc32.ts","kind":"import-statement","original":"../src/helpers/crc32.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/middleware/simple_auth_middleware.ts":{"bytes":473,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/http","kind":"import-statement","external":true},{"path":"src/simple_auth.ts","kind":"import-statement","original":"../simple_auth.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"providers/simple_auth_provider.ts":{"bytes":1187,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"src/middleware/simple_auth_middleware.ts","kind":"import-statement","original":"../src/middleware/simple_auth_middleware.js"},{"path":"../src/simple_auth.js","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":241,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"src/plugins/japa/api_client.ts":{"bytes":1434,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true},{"path":"@japa/runner/types","kind":"import-statement","external":true},{"path":"../../types.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2665},"build/index.js":{"imports":[{"path":"build/chunk-2NK343C3.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException","configure","defineConfig","stubsRoot"],"entryPoint":"index.ts","inputs":{"stubs/main.ts":{"bytesInOutput":98},"configure.ts":{"bytesInOutput":726},"index.ts":{"bytesInOutput":0},"src/define_config.ts":{"bytesInOutput":312}},"bytes":1391},"build/commands/generate_api_key.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":11126},"build/commands/generate_api_key.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/generate_api_key.ts","inputs":{"commands/generate_api_key.ts":{"bytesInOutput":1557},"src/helpers/crc32.ts":{"bytesInOutput":5029}},"bytes":6775},"build/providers/simple_auth_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1739},"build/providers/simple_auth_provider.js":{"imports":[{"path":"build/chunk-Y74LYCT7.js","kind":"import-statement"},{"path":"build/chunk-2NK343C3.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"providers/simple_auth_provider.ts","inputs":{"providers/simple_auth_provider.ts":{"bytesInOutput":671}},"bytes":878},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/types.js":{"imports":[],"exports":[],"entryPoint":"src/types.ts","inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"build/src/middleware/simple_auth_middleware.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/middleware/simple_auth_middleware.js":{"imports":[{"path":"build/chunk-Y74LYCT7.js","kind":"import-statement"},{"path":"build/chunk-2NK343C3.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"}],"exports":["default"],"entryPoint":"src/middleware/simple_auth_middleware.ts","inputs":{},"bytes":180},"build/chunk-Y74LYCT7.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":800},"build/chunk-Y74LYCT7.js":{"imports":[{"path":"build/chunk-2NK343C3.js","kind":"import-statement"}],"exports":["SimpleAuthMiddleware"],"inputs":{"src/middleware/simple_auth_middleware.ts":{"bytesInOutput":198}},"bytes":331},"build/chunk-2NK343C3.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3830},"build/chunk-2NK343C3.js":{"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException"],"inputs":{"src/errors.ts":{"bytesInOutput":1187},"src/simple_auth.ts":{"bytesInOutput":633}},"bytes":1909},"build/src/plugins/japa/api_client.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2170},"build/src/plugins/japa/api_client.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true}],"exports":["simpleAuthApiClient"],"entryPoint":"src/plugins/japa/api_client.ts","inputs":{"src/plugins/japa/api_client.ts":{"bytesInOutput":979}},"bytes":1085},"build/chunk-EUXUH3YW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/chunk-EUXUH3YW.js":{"imports":[],"exports":["__decorateClass"],"inputs":{},"bytes":524}}}
1
+ {"inputs":{"stubs/main.ts":{"bytes":233,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"configure.ts":{"bytes":995,"imports":[{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/define_config.ts":{"bytes":526,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"src/errors.ts":{"bytes":1478,"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/i18n","kind":"import-statement","external":true}],"format":"esm"},"src/simple_auth.ts":{"bytes":899,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"src/errors.ts","kind":"import-statement","original":"./errors.js"},{"path":"./types.js","kind":"import-statement","external":true}],"format":"esm"},"index.ts":{"bytes":250,"imports":[{"path":"configure.ts","kind":"import-statement","original":"./configure.js"},{"path":"src/define_config.ts","kind":"import-statement","original":"./src/define_config.js"},{"path":"src/errors.ts","kind":"import-statement","original":"./src/errors.js"},{"path":"src/simple_auth.ts","kind":"import-statement","original":"./src/simple_auth.js"},{"path":"stubs/main.ts","kind":"import-statement","original":"./stubs/main.js"}],"format":"esm"},"src/helpers/crc32.ts":{"bytes":4896,"imports":[{"path":"node:util","kind":"import-statement","external":true}],"format":"esm"},"commands/generate_api_key.ts":{"bytes":1616,"imports":[{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"src/helpers/crc32.ts","kind":"import-statement","original":"../src/helpers/crc32.js"},{"path":"<runtime>","kind":"import-statement","external":true}],"format":"esm"},"src/middleware/simple_auth_middleware.ts":{"bytes":473,"imports":[{"path":"@adonisjs/core/http","kind":"import-statement","external":true},{"path":"@adonisjs/core/types/http","kind":"import-statement","external":true},{"path":"src/simple_auth.ts","kind":"import-statement","original":"../simple_auth.js"},{"path":"../types.js","kind":"import-statement","external":true}],"format":"esm"},"providers/simple_auth_provider.ts":{"bytes":1187,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"src/middleware/simple_auth_middleware.ts","kind":"import-statement","original":"../src/middleware/simple_auth_middleware.js"},{"path":"../src/simple_auth.js","kind":"import-statement","external":true},{"path":"../src/types.js","kind":"import-statement","external":true}],"format":"esm"},"src/types.ts":{"bytes":241,"imports":[{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"format":"esm"},"src/plugins/japa/api_client.ts":{"bytes":1434,"imports":[{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@adonisjs/core/types","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true},{"path":"@japa/runner/types","kind":"import-statement","external":true},{"path":"../../types.js","kind":"import-statement","external":true}],"format":"esm"}},"outputs":{"build/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2665},"build/index.js":{"imports":[{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException","configure","defineConfig","stubsRoot"],"entryPoint":"index.ts","inputs":{"stubs/main.ts":{"bytesInOutput":98},"configure.ts":{"bytesInOutput":726},"index.ts":{"bytesInOutput":0},"src/define_config.ts":{"bytesInOutput":312}},"bytes":1391},"build/commands/generate_api_key.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":11126},"build/commands/generate_api_key.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"node:process","kind":"import-statement","external":true},{"path":"@adonisjs/core/ace","kind":"import-statement","external":true},{"path":"@adonisjs/core/env/editor","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers","kind":"import-statement","external":true},{"path":"@adonisjs/core/helpers/string","kind":"import-statement","external":true},{"path":"node:util","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/generate_api_key.ts","inputs":{"commands/generate_api_key.ts":{"bytesInOutput":1557},"src/helpers/crc32.ts":{"bytesInOutput":5029}},"bytes":6775},"build/providers/simple_auth_provider.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":1739},"build/providers/simple_auth_provider.js":{"imports":[{"path":"build/chunk-TVVNPJ4M.js","kind":"import-statement"},{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"providers/simple_auth_provider.ts","inputs":{"providers/simple_auth_provider.ts":{"bytesInOutput":671}},"bytes":878},"build/src/types.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/types.js":{"imports":[],"exports":[],"entryPoint":"src/types.ts","inputs":{"src/types.ts":{"bytesInOutput":0}},"bytes":0},"build/src/middleware/simple_auth_middleware.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/src/middleware/simple_auth_middleware.js":{"imports":[{"path":"build/chunk-TVVNPJ4M.js","kind":"import-statement"},{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"},{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"}],"exports":["default"],"entryPoint":"src/middleware/simple_auth_middleware.ts","inputs":{},"bytes":180},"build/chunk-TVVNPJ4M.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":800},"build/chunk-TVVNPJ4M.js":{"imports":[{"path":"build/chunk-JUF7K25A.js","kind":"import-statement"}],"exports":["SimpleAuthMiddleware"],"inputs":{"src/middleware/simple_auth_middleware.ts":{"bytesInOutput":198}},"bytes":331},"build/chunk-JUF7K25A.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":3865},"build/chunk-JUF7K25A.js":{"imports":[{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true}],"exports":["SimpleAuth","SimpleAuthException"],"inputs":{"src/errors.ts":{"bytesInOutput":1263},"src/simple_auth.ts":{"bytesInOutput":633}},"bytes":1985},"build/src/plugins/japa/api_client.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":2170},"build/src/plugins/japa/api_client.js":{"imports":[{"path":"build/chunk-EUXUH3YW.js","kind":"import-statement"},{"path":"@adonisjs/core","kind":"import-statement","external":true},{"path":"@adonisjs/core/exceptions","kind":"import-statement","external":true},{"path":"@japa/api-client","kind":"import-statement","external":true}],"exports":["simpleAuthApiClient"],"entryPoint":"src/plugins/japa/api_client.ts","inputs":{"src/plugins/japa/api_client.ts":{"bytesInOutput":979}},"bytes":1085},"build/chunk-EUXUH3YW.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"build/chunk-EUXUH3YW.js":{"imports":[],"exports":["__decorateClass"],"inputs":{},"bytes":524}}}
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SimpleAuthMiddleware
3
- } from "../chunk-Y74LYCT7.js";
4
- import "../chunk-2NK343C3.js";
3
+ } from "../chunk-TVVNPJ4M.js";
4
+ import "../chunk-JUF7K25A.js";
5
5
  import "../chunk-EUXUH3YW.js";
6
6
 
7
7
  // providers/simple_auth_provider.ts
@@ -1,8 +1,8 @@
1
1
  import { Exception } from '@adonisjs/core/exceptions';
2
2
  import { type HttpContext } from '@adonisjs/core/http';
3
3
  export declare class SimpleAuthException extends Exception {
4
- static readonly code: 'E_SIMPLE_UNAUTHORIZED_ACCESS';
5
- static readonly status: 401;
4
+ static readonly code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
5
+ static readonly status = 401;
6
6
  /**
7
7
  * Translation identifier. Can be customized
8
8
  */
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SimpleAuthMiddleware
3
- } from "../../chunk-Y74LYCT7.js";
4
- import "../../chunk-2NK343C3.js";
3
+ } from "../../chunk-TVVNPJ4M.js";
4
+ import "../../chunk-JUF7K25A.js";
5
5
  import "../../chunk-EUXUH3YW.js";
6
6
  export {
7
7
  SimpleAuthMiddleware as default
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eienjs/adonisjs-simple-auth",
3
3
  "description": "Single authentication api key that allows authenticate",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "type": "module",
6
6
  "module": "build/index.js",
7
7
  "types": "build/index.d.ts",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/simple_auth.ts"],"sourcesContent":["import { Exception } from '@adonisjs/core/exceptions';\nimport { type HttpContext } from '@adonisjs/core/http';\nimport { type I18n } from '@adonisjs/i18n';\n\nexport class SimpleAuthException extends Exception {\n public static readonly code: 'E_SIMPLE_UNAUTHORIZED_ACCESS';\n\n public static readonly status: 401;\n\n /**\n * Translation identifier. Can be customized\n */\n public identifier = `errors.${this.code}`;\n\n /**\n * Returns the message to be sent in the HTTP response.\n * Feel free to override this method and return a custom\n * response.\n */\n public getResponseMessage(error: this, ctx: HttpContext): string {\n if ('i18n' in ctx) {\n return (ctx.i18n as I18n).t(error.identifier, {}, error.message);\n }\n\n return error.message;\n }\n\n public async handle(error: this, ctx: HttpContext): Promise<void> {\n const message = this.getResponseMessage(error, ctx);\n\n switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {\n case 'html':\n case null:\n case 'json': {\n ctx.response.status(error.status).send({\n errors: [\n {\n message,\n },\n ],\n });\n break;\n }\n case 'application/vnd.api+json': {\n ctx.response.status(error.status).send({\n errors: [\n {\n code: error.code,\n title: message,\n },\n ],\n });\n break;\n }\n }\n }\n}\n","import { type HttpContext } from '@adonisjs/core/http';\nimport { SimpleAuthException } from './errors.js';\nimport { type ResolvedSimpleAuthConfig } from './types.js';\n\nexport class SimpleAuth {\n public constructor(\n protected ctx: HttpContext,\n protected config: ResolvedSimpleAuthConfig,\n ) {}\n\n protected authenticationFailed(): SimpleAuthException {\n return new SimpleAuthException('Unauthorized access');\n }\n\n protected getApiKeyRequest(): string {\n const apiKey = this.ctx.request.header(this.config.apiKeyHeader, '')!;\n if (!apiKey.trim()) {\n throw this.authenticationFailed();\n }\n\n return apiKey;\n }\n\n public authenticate(): void {\n const apiKeyTokenRequest = this.getApiKeyRequest();\n const apiKeyTokenConfig = this.config.apiKeyValue;\n\n if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {\n throw this.authenticationFailed();\n }\n }\n}\n"],"mappings":";AAAA,SAAS,iBAAiB;AAInB,IAAM,sBAAN,cAAkC,UAAU;AAAA,EACjD,OAAuB;AAAA,EAEvB,OAAuB;AAAA;AAAA;AAAA;AAAA,EAKhB,aAAa,UAAU,KAAK,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOhC,mBAAmB,OAAa,KAA0B;AAC/D,QAAI,UAAU,KAAK;AACjB,aAAQ,IAAI,KAAc,EAAE,MAAM,YAAY,CAAC,GAAG,MAAM,OAAO;AAAA,IACjE;AAEA,WAAO,MAAM;AAAA,EACf;AAAA,EAEA,MAAa,OAAO,OAAa,KAAiC;AAChE,UAAM,UAAU,KAAK,mBAAmB,OAAO,GAAG;AAElD,YAAQ,IAAI,QAAQ,QAAQ,CAAC,QAAQ,4BAA4B,MAAM,CAAC,GAAG;AAAA,MACzE,KAAK;AAAA,MACL,KAAK;AAAA,MACL,KAAK,QAAQ;AACX,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE;AAAA,YACF;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAAA,MACA,KAAK,4BAA4B;AAC/B,YAAI,SAAS,OAAO,MAAM,MAAM,EAAE,KAAK;AAAA,UACrC,QAAQ;AAAA,YACN;AAAA,cACE,MAAM,MAAM;AAAA,cACZ,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;;;ACpDO,IAAM,aAAN,MAAiB;AAAA,EACf,YACK,KACA,QACV;AAFU;AACA;AAAA,EACT;AAAA,EAEO,uBAA4C;AACpD,WAAO,IAAI,oBAAoB,qBAAqB;AAAA,EACtD;AAAA,EAEU,mBAA2B;AACnC,UAAM,SAAS,KAAK,IAAI,QAAQ,OAAO,KAAK,OAAO,cAAc,EAAE;AACnE,QAAI,CAAC,OAAO,KAAK,GAAG;AAClB,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAEA,WAAO;AAAA,EACT;AAAA,EAEO,eAAqB;AAC1B,UAAM,qBAAqB,KAAK,iBAAiB;AACjD,UAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAI,uBAAuB,kBAAkB,QAAQ,GAAG;AACtD,YAAM,KAAK,qBAAqB;AAAA,IAClC;AAAA,EACF;AACF;","names":[]}