@eienjs/adonisjs-simple-auth 1.0.0 → 1.0.2
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/build/{chunk-2NK343C3.js → chunk-JUF7K25A.js} +5 -5
- package/build/chunk-JUF7K25A.js.map +1 -0
- package/build/{chunk-Y74LYCT7.js → chunk-TVVNPJ4M.js} +2 -2
- package/build/commands/generate_api_key.js +2 -2
- package/build/index.js +1 -1
- package/build/metafile-esm.json +1 -1
- package/build/providers/simple_auth_provider.js +2 -2
- package/build/src/errors.d.ts +2 -2
- package/build/src/middleware/simple_auth_middleware.js +2 -2
- package/package.json +12 -12
- package/build/chunk-2NK343C3.js.map +0 -1
- /package/build/{chunk-Y74LYCT7.js.map → chunk-TVVNPJ4M.js.map} +0 -0
|
@@ -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.${
|
|
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-
|
|
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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T;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-
|
|
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-
|
|
19
|
+
//# sourceMappingURL=chunk-TVVNPJ4M.js.map
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
} from "../chunk-EUXUH3YW.js";
|
|
4
4
|
|
|
5
5
|
// commands/generate_api_key.ts
|
|
6
|
-
import process from "
|
|
6
|
+
import process from "process";
|
|
7
7
|
import { BaseCommand, flags } from "@adonisjs/core/ace";
|
|
8
8
|
import { EnvEditor } from "@adonisjs/core/env/editor";
|
|
9
9
|
import { base64, Secret } from "@adonisjs/core/helpers";
|
|
10
10
|
import string from "@adonisjs/core/helpers/string";
|
|
11
11
|
|
|
12
12
|
// src/helpers/crc32.ts
|
|
13
|
-
import { TextEncoder } from "
|
|
13
|
+
import { TextEncoder } from "util";
|
|
14
14
|
var CRC32 = class {
|
|
15
15
|
/**
|
|
16
16
|
* Lookup table calculated for 0xEDB88320 divisor
|
package/build/index.js
CHANGED
package/build/metafile-esm.json
CHANGED
|
@@ -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":
|
|
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/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/helpers/crc32.ts":{"bytes":4896,"imports":[{"path":"util","kind":"import-statement","external":true}],"format":"esm"},"commands/generate_api_key.ts":{"bytes":1616,"imports":[{"path":"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/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/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/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":"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":"util","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"commands/generate_api_key.ts","inputs":{"commands/generate_api_key.ts":{"bytesInOutput":1552},"src/helpers/crc32.ts":{"bytesInOutput":5024}},"bytes":6765},"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}}}
|
package/build/src/errors.d.ts
CHANGED
|
@@ -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
|
|
5
|
-
static readonly status
|
|
4
|
+
static readonly code = "E_SIMPLE_UNAUTHORIZED_ACCESS";
|
|
5
|
+
static readonly status = 401;
|
|
6
6
|
/**
|
|
7
7
|
* Translation identifier. Can be customized
|
|
8
8
|
*/
|
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.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "build/index.js",
|
|
7
7
|
"types": "build/index.d.ts",
|
|
@@ -22,28 +22,28 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@adonisjs/assembler": "^7.8.2",
|
|
24
24
|
"@adonisjs/core": "^6.17.2",
|
|
25
|
-
"@adonisjs/i18n": "^2.2.
|
|
25
|
+
"@adonisjs/i18n": "^2.2.2",
|
|
26
26
|
"@commitlint/cli": "^19.8.1",
|
|
27
27
|
"@commitlint/config-conventional": "^19.8.1",
|
|
28
28
|
"@japa/api-client": "^3.1.0",
|
|
29
|
-
"@japa/assert": "^4.
|
|
30
|
-
"@japa/runner": "^4.
|
|
31
|
-
"@nodecfdi/eslint-config": "^3.
|
|
29
|
+
"@japa/assert": "^4.1.1",
|
|
30
|
+
"@japa/runner": "^4.3.0",
|
|
31
|
+
"@nodecfdi/eslint-config": "^3.5.1",
|
|
32
32
|
"@nodecfdi/prettier-config": "^1.4.1",
|
|
33
33
|
"@nodecfdi/tsconfig": "^1.7.4",
|
|
34
|
-
"@swc/core": "^1.
|
|
35
|
-
"@types/node": "^22.
|
|
34
|
+
"@swc/core": "^1.13.2",
|
|
35
|
+
"@types/node": "^22.16.5",
|
|
36
36
|
"auto-changelog": "^2.5.0",
|
|
37
37
|
"c8": "^10.1.3",
|
|
38
38
|
"del-cli": "^6.0.0",
|
|
39
|
-
"eslint": "^9.
|
|
39
|
+
"eslint": "^9.31.0",
|
|
40
40
|
"husky": "^9.1.7",
|
|
41
41
|
"is-in-ci": "^1.0.0",
|
|
42
|
-
"native-copyfiles": "^
|
|
42
|
+
"native-copyfiles": "^1.3.5",
|
|
43
43
|
"np": "^10.2.0",
|
|
44
|
-
"prettier": "^3.
|
|
44
|
+
"prettier": "^3.6.2",
|
|
45
45
|
"ts-node-maintained": "^10.9.5",
|
|
46
|
-
"tsup": "^8.
|
|
46
|
+
"tsup": "^8.5.0",
|
|
47
47
|
"typescript": "^5.8.3"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
},
|
|
124
124
|
"scripts": {
|
|
125
125
|
"clean": "del-cli build",
|
|
126
|
-
"copy:templates": "copyfiles
|
|
126
|
+
"copy:templates": "copyfiles \"stubs/**/*.stub\" build --up 1",
|
|
127
127
|
"changelog": "auto-changelog -p && git add CHANGELOG.md",
|
|
128
128
|
"typecheck": "tsc --noEmit",
|
|
129
129
|
"lint": "eslint . --fix",
|
|
@@ -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,4BAA4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