@eienjs/adonisjs-simple-auth 1.0.1 → 2.0.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.
Files changed (49) hide show
  1. package/{LICENSE.md → LICENSE} +1 -1
  2. package/README.md +26 -3
  3. package/build/_virtual/_@oxc-project_runtime@0.137.0/helpers/esm/decorate.js +9 -0
  4. package/build/commands/generate_api_key.d.ts +11 -7
  5. package/build/commands/generate_api_key.js +23 -347
  6. package/build/configure.d.ts +6 -2
  7. package/build/configure.js +18 -0
  8. package/build/index.d.ts +6 -5
  9. package/build/index.js +6 -49
  10. package/build/middleware/simple_auth_middleware.d.ts +12 -0
  11. package/build/middleware/simple_auth_middleware.js +14 -0
  12. package/build/plugins/api_client.d.ts +14 -0
  13. package/build/plugins/api_client.js +23 -0
  14. package/build/providers/simple_auth_provider.d.ts +13 -9
  15. package/build/providers/simple_auth_provider.js +16 -26
  16. package/build/src/define_config.d.ts +7 -3
  17. package/build/src/define_config.js +13 -0
  18. package/build/src/errors.d.ts +20 -16
  19. package/build/src/errors.js +41 -0
  20. package/build/src/helpers/crc32.js +308 -0
  21. package/build/src/simple_auth.d.ts +14 -10
  22. package/build/src/simple_auth.js +23 -0
  23. package/build/stubs/main.d.ts +4 -5
  24. package/build/stubs/main.js +4 -0
  25. package/build/types.d.ts +13 -0
  26. package/build/types.js +1 -0
  27. package/package.json +91 -92
  28. package/build/chunk-EUXUH3YW.js +0 -15
  29. package/build/chunk-EUXUH3YW.js.map +0 -1
  30. package/build/chunk-JUF7K25A.js +0 -80
  31. package/build/chunk-JUF7K25A.js.map +0 -1
  32. package/build/chunk-TVVNPJ4M.js +0 -19
  33. package/build/chunk-TVVNPJ4M.js.map +0 -1
  34. package/build/commands/generate_api_key.js.map +0 -1
  35. package/build/index.js.map +0 -1
  36. package/build/metafile-esm.json +0 -1
  37. package/build/providers/simple_auth_provider.js.map +0 -1
  38. package/build/src/helpers/crc32.d.ts +0 -24
  39. package/build/src/middleware/simple_auth_middleware.d.ts +0 -8
  40. package/build/src/middleware/simple_auth_middleware.js +0 -9
  41. package/build/src/middleware/simple_auth_middleware.js.map +0 -1
  42. package/build/src/plugins/japa/api_client.d.ts +0 -11
  43. package/build/src/plugins/japa/api_client.js +0 -34
  44. package/build/src/plugins/japa/api_client.js.map +0 -1
  45. package/build/src/types.d.ts +0 -9
  46. package/build/src/types.js +0 -1
  47. package/build/src/types.js.map +0 -1
  48. /package/build/{config.stub → stubs/config.stub} +0 -0
  49. /package/build/{middleware → stubs/middleware}/api_key.stub +0 -0
package/package.json CHANGED
@@ -1,60 +1,8 @@
1
1
  {
2
2
  "name": "@eienjs/adonisjs-simple-auth",
3
- "description": "Single authentication api key that allows authenticate",
4
- "version": "1.0.1",
5
3
  "type": "module",
6
- "module": "build/index.js",
7
- "types": "build/index.d.ts",
8
- "files": [
9
- "build",
10
- "!build/bin",
11
- "!build/tests"
12
- ],
13
- "exports": {
14
- ".": "./build/index.js",
15
- "./types": "./build/src/types.js",
16
- "./commands": "./build/commands/main.js",
17
- "./commands/*": "./build/commands/*.js",
18
- "./simple_auth_provider": "./build/providers/simple_auth_provider.js",
19
- "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
20
- "./simple_auth_middleware": "./build/src/middleware/simple_auth_middleware.js"
21
- },
22
- "devDependencies": {
23
- "@adonisjs/assembler": "^7.8.2",
24
- "@adonisjs/core": "^6.17.2",
25
- "@adonisjs/i18n": "^2.2.0",
26
- "@commitlint/cli": "^19.8.1",
27
- "@commitlint/config-conventional": "^19.8.1",
28
- "@japa/api-client": "^3.1.0",
29
- "@japa/assert": "^4.0.1",
30
- "@japa/runner": "^4.2.0",
31
- "@nodecfdi/eslint-config": "^3.2.1",
32
- "@nodecfdi/prettier-config": "^1.4.1",
33
- "@nodecfdi/tsconfig": "^1.7.4",
34
- "@swc/core": "^1.11.24",
35
- "@types/node": "^22.15.16",
36
- "auto-changelog": "^2.5.0",
37
- "c8": "^10.1.3",
38
- "del-cli": "^6.0.0",
39
- "eslint": "^9.26.0",
40
- "husky": "^9.1.7",
41
- "is-in-ci": "^1.0.0",
42
- "native-copyfiles": "^0.3.2",
43
- "np": "^10.2.0",
44
- "prettier": "^3.5.3",
45
- "ts-node-maintained": "^10.9.5",
46
- "tsup": "^8.4.0",
47
- "typescript": "^5.8.3"
48
- },
49
- "peerDependencies": {
50
- "@adonisjs/core": "^6.17.2",
51
- "@japa/api-client": "^3.1.0"
52
- },
53
- "peerDependenciesMeta": {
54
- "@japa/api-client": {
55
- "optional": true
56
- }
57
- },
4
+ "version": "2.0.0",
5
+ "description": "Single authentication api key that allows authenticate",
58
6
  "author": "Fernando Isidro <luffynando@gmail.com>",
59
7
  "license": "MIT",
60
8
  "homepage": "https://github.com/eienjs/adonisjs-simple-auth",
@@ -72,8 +20,55 @@
72
20
  "key",
73
21
  "headers"
74
22
  ],
23
+ "exports": {
24
+ ".": "./build/index.js",
25
+ "./commands/generate_api_key": "./build/commands/generate_api_key.js",
26
+ "./middleware/simple_auth_middleware": "./build/middleware/simple_auth_middleware.js",
27
+ "./plugins/api_client": "./build/plugins/api_client.js",
28
+ "./providers/simple_auth_provider": "./build/providers/simple_auth_provider.js",
29
+ "./types": "./build/types.js",
30
+ "./package.json": "./package.json",
31
+ "./commands": "./build/commands/main.js"
32
+ },
33
+ "types": "build/index.d.ts",
34
+ "files": [
35
+ "build"
36
+ ],
75
37
  "engines": {
76
- "node": ">=20.6.0"
38
+ "node": ">=24.0.0"
39
+ },
40
+ "peerDependencies": {
41
+ "@adonisjs/core": "^7.3.4",
42
+ "@japa/api-client": "^3.2.1"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@japa/api-client": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@adonisjs/assembler": "^8.4.0",
51
+ "@adonisjs/core": "^7.3.4",
52
+ "@adonisjs/eslint-plugin": "^2.2.2",
53
+ "@adonisjs/i18n": "^3.0.1",
54
+ "@adonisjs/tsconfig": "^2.0.0",
55
+ "@commitlint/cli": "^21.1.0",
56
+ "@commitlint/config-conventional": "^21.1.0",
57
+ "@eienjs/eslint-config": "^2.1.1",
58
+ "@japa/api-client": "^3.2.1",
59
+ "@japa/assert": "^4.2.0",
60
+ "@japa/runner": "^5.3.0",
61
+ "@types/node": "^24.13.2",
62
+ "auto-changelog": "^2.6.0",
63
+ "c8": "^11.0.0",
64
+ "eslint": "^10.5.0",
65
+ "eslint-plugin-erasable-syntax-only": "^0.4.2",
66
+ "husky": "^9.1.7",
67
+ "is-in-ci": "^2.0.0",
68
+ "release-it": "^20.2.1",
69
+ "tsdown": "^0.22.3",
70
+ "tsdown-stale-guard": "^0.1.2",
71
+ "typescript": "^6.0.3"
77
72
  },
78
73
  "c8": {
79
74
  "reporter": [
@@ -90,55 +85,59 @@
90
85
  "@commitlint/config-conventional"
91
86
  ]
92
87
  },
93
- "prettier": "@nodecfdi/prettier-config/pkg",
94
88
  "publishConfig": {
95
89
  "access": "public",
96
90
  "tag": "latest"
97
91
  },
98
92
  "auto-changelog": {
99
93
  "template": "keepachangelog",
100
- "hideCredit": true
101
- },
102
- "np": {
103
- "message": "chore(release): :tada: %s",
104
- "tag": "latest",
105
- "branch": "main",
106
- "testScript": "test"
94
+ "hideCredit": true,
95
+ "commitLimit": false
107
96
  },
108
- "tsup": {
109
- "entry": [
110
- "./index.ts",
111
- "./src/types.ts",
112
- "./src/middleware/simple_auth_middleware.ts",
113
- "./providers/simple_auth_provider.ts",
114
- "./src/plugins/japa/api_client.ts",
115
- "./commands/generate_api_key.ts"
116
- ],
117
- "outDir": "./build",
118
- "clean": true,
119
- "format": "esm",
120
- "dts": false,
121
- "sourcemap": true,
122
- "target": "esnext"
97
+ "release-it": {
98
+ "git": {
99
+ "commit": true,
100
+ "tag": true,
101
+ "push": true,
102
+ "requireCleanWorkingDir": true,
103
+ "commitMessage": "chore(release): :tada: v${version}",
104
+ "tagAnnotation": "chore(release): :tada: v${version}"
105
+ },
106
+ "github": {
107
+ "release": true,
108
+ "web": true,
109
+ "releaseName": "Release v${version}"
110
+ },
111
+ "npm": {
112
+ "publish": true,
113
+ "publishPackageManager": "pnpm",
114
+ "publishArgs": [
115
+ "--no-git-checks"
116
+ ]
117
+ },
118
+ "hooks": {
119
+ "before:init": [
120
+ "pnpm run lint:check",
121
+ "pnpm run typecheck"
122
+ ],
123
+ "after:bump": [
124
+ "pnpm run build",
125
+ "pnpm run changelog"
126
+ ]
127
+ }
123
128
  },
124
129
  "scripts": {
125
- "clean": "del-cli build",
126
- "copy:templates": "copyfiles --up 1 \"stubs/**/*.stub\" build",
127
- "changelog": "auto-changelog -p && git add CHANGELOG.md",
128
- "typecheck": "tsc --noEmit",
130
+ "changelog": "auto-changelog -u -p",
131
+ "commitlint": "commitlint --edit",
132
+ "index:commands": "adonis-kit index build/commands",
129
133
  "lint": "eslint . --fix",
130
134
  "lint:check": "eslint .",
131
- "format": "prettier --write .",
132
- "format:check": "prettier --check .",
133
- "test": "node --import ts-node-maintained/register/esm --enable-source-maps bin/test.ts",
135
+ "typecheck": "tsc --noEmit",
136
+ "test": "node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
134
137
  "test:coverage": "c8 pnpm run test",
135
- "tool:code": "pnpm run lint:check && pnpm run format:check && pnpm run typecheck",
138
+ "tool:code": "pnpm run lint:check && pnpm run typecheck",
136
139
  "tool:build": "pnpm run tool:code && pnpm run test",
137
- "prebuild": "pnpm run tool:code && pnpm run clean",
138
- "build": "tsup-node --metafile && tsc --emitDeclarationOnly --declaration",
139
- "postbuild": "pnpm run copy:templates && pnpm run index:commands",
140
- "release": "np",
141
- "version": "pnpm run build && pnpm run changelog",
142
- "index:commands": "adonis-kit index build/commands"
140
+ "build": "tsdown && pnpm run index:commands",
141
+ "release": "release-it"
143
142
  }
144
143
  }
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result) __defProp(target, key, result);
9
- return result;
10
- };
11
-
12
- export {
13
- __decorateClass
14
- };
15
- //# sourceMappingURL=chunk-EUXUH3YW.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,80 +0,0 @@
1
- // src/errors.ts
2
- import { Exception } from "@adonisjs/core/exceptions";
3
- var SimpleAuthException = class _SimpleAuthException extends Exception {
4
- static code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
5
- static status = 401;
6
- /**
7
- * Translation identifier. Can be customized
8
- */
9
- identifier = `errors.${_SimpleAuthException.code}`;
10
- /**
11
- * Returns the message to be sent in the HTTP response.
12
- * Feel free to override this method and return a custom
13
- * response.
14
- */
15
- getResponseMessage(error, ctx) {
16
- if ("i18n" in ctx) {
17
- return ctx.i18n.t(error.identifier, {}, error.message);
18
- }
19
- return error.message;
20
- }
21
- async handle(error, ctx) {
22
- const message = this.getResponseMessage(error, ctx);
23
- switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
24
- case "html":
25
- case null:
26
- case "json": {
27
- ctx.response.status(error.status).send({
28
- errors: [
29
- {
30
- message
31
- }
32
- ]
33
- });
34
- break;
35
- }
36
- case "application/vnd.api+json": {
37
- ctx.response.status(error.status).send({
38
- errors: [
39
- {
40
- code: error.code,
41
- title: message
42
- }
43
- ]
44
- });
45
- break;
46
- }
47
- }
48
- }
49
- };
50
-
51
- // src/simple_auth.ts
52
- var SimpleAuth = class {
53
- constructor(ctx, config) {
54
- this.ctx = ctx;
55
- this.config = config;
56
- }
57
- authenticationFailed() {
58
- return new SimpleAuthException("Unauthorized access");
59
- }
60
- getApiKeyRequest() {
61
- const apiKey = this.ctx.request.header(this.config.apiKeyHeader, "");
62
- if (!apiKey.trim()) {
63
- throw this.authenticationFailed();
64
- }
65
- return apiKey;
66
- }
67
- authenticate() {
68
- const apiKeyTokenRequest = this.getApiKeyRequest();
69
- const apiKeyTokenConfig = this.config.apiKeyValue;
70
- if (apiKeyTokenRequest !== apiKeyTokenConfig.release()) {
71
- throw this.authenticationFailed();
72
- }
73
- }
74
- };
75
-
76
- export {
77
- SimpleAuthException,
78
- SimpleAuth
79
- };
80
- //# sourceMappingURL=chunk-JUF7K25A.js.map
@@ -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.${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,19 +0,0 @@
1
- import {
2
- SimpleAuth
3
- } from "./chunk-JUF7K25A.js";
4
-
5
- // src/middleware/simple_auth_middleware.ts
6
- var SimpleAuthMiddleware = class {
7
- constructor(config) {
8
- this.config = config;
9
- }
10
- async handle(ctx, next) {
11
- ctx.simpleAuth = new SimpleAuth(ctx, this.config);
12
- return next();
13
- }
14
- };
15
-
16
- export {
17
- SimpleAuthMiddleware
18
- };
19
- //# sourceMappingURL=chunk-TVVNPJ4M.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/middleware/simple_auth_middleware.ts"],"sourcesContent":["import { type HttpContext } from '@adonisjs/core/http';\nimport { type NextFn } from '@adonisjs/core/types/http';\nimport { SimpleAuth } from '../simple_auth.js';\nimport { type ResolvedSimpleAuthConfig } from '../types.js';\n\nexport default class SimpleAuthMiddleware {\n public constructor(protected config: ResolvedSimpleAuthConfig) {}\n\n public async handle(ctx: HttpContext, next: NextFn) {\n ctx.simpleAuth = new SimpleAuth(ctx, this.config);\n\n return next();\n }\n}\n"],"mappings":";;;;;AAKA,IAAqB,uBAArB,MAA0C;AAAA,EACjC,YAAsB,QAAkC;AAAlC;AAAA,EAAmC;AAAA,EAEhE,MAAa,OAAO,KAAkB,MAAc;AAClD,QAAI,aAAa,IAAI,WAAW,KAAK,KAAK,MAAM;AAEhD,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../commands/generate_api_key.ts","../../src/helpers/crc32.ts"],"sourcesContent":["import process from 'node:process';\nimport { BaseCommand, flags } from '@adonisjs/core/ace';\nimport { EnvEditor } from '@adonisjs/core/env/editor';\nimport { base64, Secret } from '@adonisjs/core/helpers';\nimport string from '@adonisjs/core/helpers/string';\nimport { CRC32 } from '../src/helpers/crc32.js';\n\nexport default class GenerateApiKey extends BaseCommand {\n public static readonly commandName = 'generate:api-key';\n\n public static readonly description =\n 'Generate a a cryptographically secure random value suffixed with a CRC32 checksum';\n\n @flags.boolean({\n description: 'Display the token on the terminal, instead of writing it to .env file',\n })\n declare public show: boolean;\n\n @flags.boolean({\n description: 'Force update .env file in production environment',\n })\n declare public force: boolean;\n\n public async run() {\n let writeToFile = process.env.NODE_ENV !== 'production';\n if (this.force) {\n writeToFile = true;\n }\n\n if (this.show) {\n writeToFile = false;\n }\n\n const seed = string.random(40);\n const tokenSecret = new Secret(`${seed}${new CRC32().calculate(seed)}`);\n const result = new Secret(\n `oat_${base64.urlEncode(String(string.random(2)))}.${base64.urlEncode(tokenSecret.release())}`,\n );\n const tokenString = result.release();\n\n if (writeToFile) {\n const editor = await EnvEditor.create(this.app.appRoot);\n editor.add('API_KEY', tokenString, true);\n await editor.save();\n this.logger.action('add API_KEY to .env').succeeded();\n } else {\n this.logger.log(`API_KEY = ${tokenString}`);\n }\n }\n}\n","import { TextEncoder } from 'node:util';\n/**\n * We use CRC32 just to add a recognizable checksum to tokens. This helps\n * secret scanning tools like https://docs.github.com/en/github/administering-a-repository/about-secret-scanning easily detect tokens generated by a given program.\n *\n * You can learn more about appending checksum to a hash here in this Github\n * article. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/\n *\n * Code taken from:\n * https://github.com/adonisjs/auth/blob/9.x/modules/access_tokens_guard/crc32.ts\n */\n\nexport class CRC32 {\n /**\n * Lookup table calculated for 0xEDB88320 divisor\n */\n protected readonly lookupTable = [\n 0, 1996959894, 3993919788, 2567524794, 124634137, 1886057615, 3915621685, 2657392035, 249268274, 2044508324,\n 3772115230, 2547177864, 162941995, 2125561021, 3887607047, 2428444049, 498536548, 1789927666, 4089016648,\n 2227061214, 450548861, 1843258603, 4107580753, 2211677639, 325883990, 1684777152, 4251122042, 2321926636, 335633487,\n 1661365465, 4195302755, 2366115317, 997073096, 1281953886, 3579855332, 2724688242, 1006888145, 1258607687,\n 3524101629, 2768942443, 901097722, 1119000684, 3686517206, 2898065728, 853044451, 1172266101, 3705015759,\n 2882616665, 651767980, 1373503546, 3369554304, 3218104598, 565507253, 1454621731, 3485111705, 3099436303, 671266974,\n 1594198024, 3322730930, 2970347812, 795835527, 1483230225, 3244367275, 3060149565, 1994146192, 31158534, 2563907772,\n 4023717930, 1907459465, 112637215, 2680153253, 3904427059, 2013776290, 251722036, 2517215374, 3775830040,\n 2137656763, 141376813, 2439277719, 3865271297, 1802195444, 476864866, 2238001368, 4066508878, 1812370925, 453092731,\n 2181625025, 4111451223, 1706088902, 314042704, 2344532202, 4240017532, 1658658271, 366619977, 2362670323,\n 4224994405, 1303535960, 984961486, 2747007092, 3569037538, 1256170817, 1037604311, 2765210733, 3554079995,\n 1131014506, 879679996, 2909243462, 3663771856, 1141124467, 855842277, 2852801631, 3708648649, 1342533948, 654459306,\n 3188396048, 3373015174, 1466479909, 544179635, 3110523913, 3462522015, 1591671054, 702138776, 2966460450,\n 3352799412, 1504918807, 783551873, 3082640443, 3233442989, 3988292384, 2596254646, 62317068, 1957810842, 3939845945,\n 2647816111, 81470997, 1943803523, 3814918930, 2489596804, 225274430, 2053790376, 3826175755, 2466906013, 167816743,\n 2097651377, 4027552580, 2265490386, 503444072, 1762050814, 4150417245, 2154129355, 426522225, 1852507879,\n 4275313526, 2312317920, 282753626, 1742555852, 4189708143, 2394877945, 397917763, 1622183637, 3604390888,\n 2714866558, 953729732, 1340076626, 3518719985, 2797360999, 1068828381, 1219638859, 3624741850, 2936675148,\n 906185462, 1090812512, 3747672003, 2825379669, 829329135, 1181335161, 3412177804, 3160834842, 628085408, 1382605366,\n 3423369109, 3138078467, 570562233, 1426400815, 3317316542, 2998733608, 733239954, 1555261956, 3268935591,\n 3050360625, 752459403, 1541320221, 2607071920, 3965973030, 1969922972, 40735498, 2617837225, 3943577151, 1913087877,\n 83908371, 2512341634, 3803740692, 2075208622, 213261112, 2463272603, 3855990285, 2094854071, 198958881, 2262029012,\n 4057260610, 1759359992, 534414190, 2176718541, 4139329115, 1873836001, 414664567, 2282248934, 4279200368,\n 1711684554, 285281116, 2405801727, 4167216745, 1634467795, 376229701, 2685067896, 3608007406, 1308918612, 956543938,\n 2808555105, 3495958263, 1231636301, 1047427035, 2932959818, 3654703836, 1088359270, 936918000, 2847714899,\n 3736837829, 1202900863, 817233897, 3183342108, 3401237130, 1404277552, 615818150, 3134207493, 3453421203,\n 1423857449, 601450431, 3009837614, 3294710456, 1567103746, 711928724, 3020668471, 3272380065, 1510334235, 755167117,\n ];\n\n protected readonly initialCRC = 0xffffffff;\n\n protected calculateBytes(bytes: Uint8Array, accumulator?: number): number {\n let crc = accumulator ?? this.initialCRC;\n for (const byte of bytes) {\n const tableIndex = (crc ^ byte) & 0xff;\n const tableVal = this.lookupTable[tableIndex];\n crc = (crc >>> 8) ^ tableVal;\n }\n\n return crc;\n }\n\n protected crcToUint(crc: number): number {\n return this.toUint32(crc ^ 0xffffffff);\n }\n\n protected strToBytes(input: string): Uint8Array {\n const encoder = new TextEncoder();\n\n return encoder.encode(input);\n }\n\n protected toUint32(num: number): number {\n if (num >= 0) {\n return num;\n }\n\n return 0xffffffff - num * -1 + 1;\n }\n\n public calculate(input: string): number {\n return this.forString(input);\n }\n\n public forString(input: string): number {\n const bytes = this.strToBytes(input);\n\n return this.forBytes(bytes);\n }\n\n public forBytes(bytes: Uint8Array, accumulator?: number): number {\n const crc = this.calculateBytes(bytes, accumulator);\n\n return this.crcToUint(crc);\n }\n}\n"],"mappings":";;;;;AAAA,OAAO,aAAa;AACpB,SAAS,aAAa,aAAa;AACnC,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,cAAc;AAC/B,OAAO,YAAY;;;ACJnB,SAAS,mBAAmB;AAYrB,IAAM,QAAN,MAAY;AAAA;AAAA;AAAA;AAAA,EAIE,cAAc;AAAA,IAC/B;AAAA,IAAG;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IACjG;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAC9F;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAC1G;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAC/F;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAC9F;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAC1G;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAW;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAY;AAAA,IAAU;AAAA,IACzG;AAAA,IAAY;AAAA,IAAY;AAAA,IA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O,KAAK,IAAI,OAAO;AACtD,aAAO,IAAI,WAAW,aAAa,IAAI;AACvC,YAAM,OAAO,KAAK;AAClB,WAAK,OAAO,OAAO,qBAAqB,EAAE,UAAU;AAAA,IACtD,OAAO;AACL,WAAK,OAAO,IAAI,aAAa,WAAW,EAAE;AAAA,IAC5C;AAAA,EACF;AACF;AAjCiB;AAAA,EAHd,MAAM,QAAQ;AAAA,IACb,aAAa;AAAA,EACf,CAAC;AAAA,GARkB,eASJ;AAKA;AAAA,EAHd,MAAM,QAAQ;AAAA,IACb,aAAa;AAAA,EACf,CAAC;AAAA,GAbkB,eAcJ;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../stubs/main.ts","../configure.ts","../src/define_config.ts"],"sourcesContent":["import { getDirname } from '@adonisjs/core/helpers';\n\n/**\n * Path to the root directory where the stubs are stored. We use\n * this path within commands and the configure hook\n */\nexport const stubsRoot = getDirname(import.meta.url);\n","import type Configure from '@adonisjs/core/commands/configure';\nimport { stubsRoot } from './stubs/main.js';\n\nexport const configure = async (command: Configure): Promise<void> => {\n const codemods = await command.createCodemods();\n\n // Publish commands and provider\n await codemods.updateRcFile((rcFile) => {\n rcFile.addCommand('@eienjs/adonisjs-simple-auth/commands');\n rcFile.addProvider('@eienjs/adonisjs-simple-auth/simple_auth_provider');\n });\n\n // Publish config file\n await codemods.makeUsingStub(stubsRoot, 'config.stub', {});\n\n // Publish api key middleware\n await codemods.makeUsingStub(stubsRoot, 'middleware/api_key.stub', {\n entity: command.app.generators.createEntity('api_key'),\n });\n\n // Register middleware\n await codemods.registerMiddleware('router', [{ path: '@eienjs/adonisjs-simple-auth/simple_auth_middleware' }]);\n await codemods.registerMiddleware('named', [\n {\n name: 'apiKey',\n path: '#middleware/api_key_middleware',\n },\n ]);\n};\n","import { configProvider } from '@adonisjs/core';\nimport { Secret } from '@adonisjs/core/helpers';\nimport { type ConfigProvider } from '@adonisjs/core/types';\nimport { type ResolvedSimpleAuthConfig, type SimpleAuthConfig } from './types.js';\n\nexport const defineConfig = (config: SimpleAuthConfig): ConfigProvider<ResolvedSimpleAuthConfig> => {\n return configProvider.create(async (_) => {\n return {\n apiKeyHeader: config.apiKeyHeader ?? 'x-api-key',\n apiKeyValue: new Secret(config.apiKeyValue),\n };\n });\n};\n"],"mappings":";;;;;;;AAAA,SAAS,kBAAkB;AAMpB,IAAM,YAAY,WAAW,YAAY,GAAG;;;ACH5C,IAAM,YAAY,OAAO,YAAsC;AACpE,QAAM,WAAW,MAAM,QAAQ,eAAe;AAG9C,QAAM,SAAS,aAAa,CAAC,WAAW;AACtC,WAAO,WAAW,uCAAuC;AACzD,WAAO,YAAY,mDAAmD;AAAA,EACxE,CAAC;AAGD,QAAM,SAAS,cAAc,WAAW,eAAe,CAAC,CAAC;AAGzD,QAAM,SAAS,cAAc,WAAW,2BAA2B;AAAA,IACjE,QAAQ,QAAQ,IAAI,WAAW,aAAa,SAAS;AAAA,EACvD,CAAC;AAGD,QAAM,SAAS,mBAAmB,UAAU,CAAC,EAAE,MAAM,sDAAsD,CAAC,CAAC;AAC7G,QAAM,SAAS,mBAAmB,SAAS;AAAA,IACzC;AAAA,MACE,MAAM;AAAA,MACN,MAAM;AAAA,IACR;AAAA,EACF,CAAC;AACH;;;AC5BA,SAAS,sBAAsB;AAC/B,SAAS,cAAc;AAIhB,IAAM,eAAe,CAAC,WAAuE;AAClG,SAAO,eAAe,OAAO,OAAO,MAAM;AACxC,WAAO;AAAA,MACL,cAAc,OAAO,gBAAgB;AAAA,MACrC,aAAa,IAAI,OAAO,OAAO,WAAW;AAAA,IAC5C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1 +0,0 @@
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 +0,0 @@
1
- {"version":3,"sources":["../../providers/simple_auth_provider.ts"],"sourcesContent":["import { configProvider } from '@adonisjs/core';\nimport { RuntimeException } from '@adonisjs/core/exceptions';\nimport { type ApplicationService } from '@adonisjs/core/types';\nimport SimpleAuthMiddleware from '../src/middleware/simple_auth_middleware.js';\nimport { type SimpleAuth } from '../src/simple_auth.js';\nimport { type ResolvedSimpleAuthConfig, type SimpleAuthConfig } from '../src/types.js';\n\n/**\n * HttpContext augmentations\n */\ndeclare module '@adonisjs/core/http' {\n export interface HttpContext {\n simpleAuth: SimpleAuth;\n }\n}\n\nexport default class SimpleAuthProvider {\n public constructor(protected app: ApplicationService) {}\n\n public register(): void {\n this.app.container.singleton(SimpleAuthMiddleware, async () => {\n const simpleAuthConfigProvider = this.app.config.get<SimpleAuthConfig>('simpleauth');\n const config = await configProvider.resolve<ResolvedSimpleAuthConfig>(this.app, simpleAuthConfigProvider);\n if (!config) {\n throw new RuntimeException(\n 'Invalid \"config/simpleauth.ts\" file. Make sure you are using the \"defineConfig\" method',\n );\n }\n\n return new SimpleAuthMiddleware(config);\n });\n }\n}\n"],"mappings":";;;;;;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAejC,IAAqB,qBAArB,MAAwC;AAAA,EAC/B,YAAsB,KAAyB;AAAzB;AAAA,EAA0B;AAAA,EAEhD,WAAiB;AACtB,SAAK,IAAI,UAAU,UAAU,sBAAsB,YAAY;AAC7D,YAAM,2BAA2B,KAAK,IAAI,OAAO,IAAsB,YAAY;AACnF,YAAM,SAAS,MAAM,eAAe,QAAkC,KAAK,KAAK,wBAAwB;AACxG,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,aAAO,IAAI,qBAAqB,MAAM;AAAA,IACxC,CAAC;AAAA,EACH;AACF;","names":[]}
@@ -1,24 +0,0 @@
1
- /**
2
- * We use CRC32 just to add a recognizable checksum to tokens. This helps
3
- * secret scanning tools like https://docs.github.com/en/github/administering-a-repository/about-secret-scanning easily detect tokens generated by a given program.
4
- *
5
- * You can learn more about appending checksum to a hash here in this Github
6
- * article. https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
7
- *
8
- * Code taken from:
9
- * https://github.com/adonisjs/auth/blob/9.x/modules/access_tokens_guard/crc32.ts
10
- */
11
- export declare class CRC32 {
12
- /**
13
- * Lookup table calculated for 0xEDB88320 divisor
14
- */
15
- protected readonly lookupTable: number[];
16
- protected readonly initialCRC = 4294967295;
17
- protected calculateBytes(bytes: Uint8Array, accumulator?: number): number;
18
- protected crcToUint(crc: number): number;
19
- protected strToBytes(input: string): Uint8Array;
20
- protected toUint32(num: number): number;
21
- calculate(input: string): number;
22
- forString(input: string): number;
23
- forBytes(bytes: Uint8Array, accumulator?: number): number;
24
- }
@@ -1,8 +0,0 @@
1
- import { type HttpContext } from '@adonisjs/core/http';
2
- import { type NextFn } from '@adonisjs/core/types/http';
3
- import { type ResolvedSimpleAuthConfig } from '../types.js';
4
- export default class SimpleAuthMiddleware {
5
- protected config: ResolvedSimpleAuthConfig;
6
- constructor(config: ResolvedSimpleAuthConfig);
7
- handle(ctx: HttpContext, next: NextFn): Promise<any>;
8
- }
@@ -1,9 +0,0 @@
1
- import {
2
- SimpleAuthMiddleware
3
- } from "../../chunk-TVVNPJ4M.js";
4
- import "../../chunk-JUF7K25A.js";
5
- import "../../chunk-EUXUH3YW.js";
6
- export {
7
- SimpleAuthMiddleware as default
8
- };
9
- //# sourceMappingURL=simple_auth_middleware.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,11 +0,0 @@
1
- import { type ApplicationService } from '@adonisjs/core/types';
2
- import { type PluginFn } from '@japa/runner/types';
3
- declare const API_KEY_ENABLED: unique symbol;
4
- declare module '@japa/api-client' {
5
- interface ApiRequest {
6
- [API_KEY_ENABLED]: boolean;
7
- withApiKey(): this;
8
- }
9
- }
10
- export declare const simpleAuthApiClient: (app: ApplicationService) => PluginFn;
11
- export {};
@@ -1,34 +0,0 @@
1
- import "../../../chunk-EUXUH3YW.js";
2
-
3
- // src/plugins/japa/api_client.ts
4
- import { configProvider } from "@adonisjs/core";
5
- import { RuntimeException } from "@adonisjs/core/exceptions";
6
- import { ApiClient, ApiRequest } from "@japa/api-client";
7
- var API_KEY_ENABLED = Symbol.for("API_KEY_ENABLED");
8
- var simpleAuthApiClient = (app) => {
9
- const pluginFn = async function() {
10
- const simpleAuthConfigProvider = app.config.get("simpleauth");
11
- const config = await configProvider.resolve(app, simpleAuthConfigProvider);
12
- if (!config) {
13
- throw new RuntimeException(
14
- 'Invalid "config/simpleauth.ts" file. Make sure you are using the "defineConfig" method'
15
- );
16
- }
17
- ApiRequest.macro("withApiKey", function() {
18
- this[API_KEY_ENABLED] = true;
19
- return this;
20
- });
21
- ApiClient.setup(async (request) => {
22
- const isApiKeyEnabled = request[API_KEY_ENABLED];
23
- if (!isApiKeyEnabled) {
24
- return;
25
- }
26
- request.header(config.apiKeyHeader, config.apiKeyValue.release());
27
- });
28
- };
29
- return pluginFn;
30
- };
31
- export {
32
- simpleAuthApiClient
33
- };
34
- //# sourceMappingURL=api_client.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/plugins/japa/api_client.ts"],"sourcesContent":["import { configProvider } from '@adonisjs/core';\nimport { RuntimeException } from '@adonisjs/core/exceptions';\nimport { type ApplicationService } from '@adonisjs/core/types';\nimport { ApiClient, ApiRequest } from '@japa/api-client';\nimport { type PluginFn } from '@japa/runner/types';\nimport { type ResolvedSimpleAuthConfig, type SimpleAuthConfig } from '../../types.js';\n\nconst API_KEY_ENABLED = Symbol.for('API_KEY_ENABLED');\n\ndeclare module '@japa/api-client' {\n export interface ApiRequest {\n [API_KEY_ENABLED]: boolean;\n withApiKey(): this;\n }\n}\n\nexport const simpleAuthApiClient = (app: ApplicationService): PluginFn => {\n const pluginFn: PluginFn = async function () {\n const simpleAuthConfigProvider = app.config.get<SimpleAuthConfig>('simpleauth');\n const config = await configProvider.resolve<ResolvedSimpleAuthConfig>(app, simpleAuthConfigProvider);\n if (!config) {\n throw new RuntimeException(\n 'Invalid \"config/simpleauth.ts\" file. Make sure you are using the \"defineConfig\" method',\n );\n }\n\n ApiRequest.macro('withApiKey', function (this: ApiRequest) {\n this[API_KEY_ENABLED] = true;\n\n return this;\n });\n\n ApiClient.setup(async (request) => {\n const isApiKeyEnabled = request[API_KEY_ENABLED];\n if (!isApiKeyEnabled) {\n return;\n }\n\n request.header(config.apiKeyHeader, config.apiKeyValue.release());\n });\n };\n\n return pluginFn;\n};\n"],"mappings":";;;AAAA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAEjC,SAAS,WAAW,kBAAkB;AAItC,IAAM,kBAAkB,OAAO,IAAI,iBAAiB;AAS7C,IAAM,sBAAsB,CAAC,QAAsC;AACxE,QAAM,WAAqB,iBAAkB;AAC3C,UAAM,2BAA2B,IAAI,OAAO,IAAsB,YAAY;AAC9E,UAAM,SAAS,MAAM,eAAe,QAAkC,KAAK,wBAAwB;AACnG,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,eAAW,MAAM,cAAc,WAA4B;AACzD,WAAK,eAAe,IAAI;AAExB,aAAO;AAAA,IACT,CAAC;AAED,cAAU,MAAM,OAAO,YAAY;AACjC,YAAM,kBAAkB,QAAQ,eAAe;AAC/C,UAAI,CAAC,iBAAiB;AACpB;AAAA,MACF;AAEA,cAAQ,OAAO,OAAO,cAAc,OAAO,YAAY,QAAQ,CAAC;AAAA,IAClE,CAAC;AAAA,EACH;AAEA,SAAO;AACT;","names":[]}
@@ -1,9 +0,0 @@
1
- import { type Secret } from '@adonisjs/core/helpers';
2
- export interface SimpleAuthConfig {
3
- apiKeyHeader?: string;
4
- apiKeyValue: string;
5
- }
6
- export type ResolvedSimpleAuthConfig = {
7
- apiKeyHeader: string;
8
- apiKeyValue: Secret<string>;
9
- };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
File without changes