@adonisjs/http-server 6.8.2-9 → 7.0.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 (107) hide show
  1. package/build/chunk-XX72ATFY.js +4388 -0
  2. package/build/factories/main.d.ts +149 -6
  3. package/build/factories/main.js +331 -14
  4. package/build/index.d.ts +272 -14
  5. package/build/index.js +308 -22
  6. package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
  7. package/build/main-e5b46c83.d.ts +2210 -0
  8. package/build/src/types/main.d.ts +14 -7
  9. package/build/src/types/main.js +0 -15
  10. package/package.json +62 -53
  11. package/build/factories/http_context.d.ts +0 -25
  12. package/build/factories/http_context.js +0 -51
  13. package/build/factories/http_server.d.ts +0 -8
  14. package/build/factories/http_server.js +0 -26
  15. package/build/factories/qs_parser_factory.d.ts +0 -20
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.d.ts +0 -29
  18. package/build/factories/request.js +0 -73
  19. package/build/factories/response.d.ts +0 -29
  20. package/build/factories/response.js +0 -77
  21. package/build/factories/router.d.ts +0 -23
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.d.ts +0 -29
  24. package/build/factories/server_factory.js +0 -65
  25. package/build/src/cookies/client.d.ts +0 -37
  26. package/build/src/cookies/client.js +0 -84
  27. package/build/src/cookies/drivers/encrypted.d.ts +0 -16
  28. package/build/src/cookies/drivers/encrypted.js +0 -36
  29. package/build/src/cookies/drivers/plain.d.ts +0 -15
  30. package/build/src/cookies/drivers/plain.js +0 -33
  31. package/build/src/cookies/drivers/signed.d.ts +0 -16
  32. package/build/src/cookies/drivers/signed.js +0 -36
  33. package/build/src/cookies/parser.d.ts +0 -37
  34. package/build/src/cookies/parser.js +0 -167
  35. package/build/src/cookies/serializer.d.ts +0 -33
  36. package/build/src/cookies/serializer.js +0 -79
  37. package/build/src/debug.d.ts +0 -3
  38. package/build/src/debug.js +0 -10
  39. package/build/src/define_config.d.ts +0 -5
  40. package/build/src/define_config.js +0 -51
  41. package/build/src/define_middleware.d.ts +0 -11
  42. package/build/src/define_middleware.js +0 -35
  43. package/build/src/exception_handler.d.ts +0 -112
  44. package/build/src/exception_handler.js +0 -303
  45. package/build/src/exceptions.d.ts +0 -84
  46. package/build/src/exceptions.js +0 -38
  47. package/build/src/helpers.d.ts +0 -23
  48. package/build/src/helpers.js +0 -84
  49. package/build/src/http_context/local_storage.d.ts +0 -12
  50. package/build/src/http_context/local_storage.js +0 -39
  51. package/build/src/http_context/main.d.ts +0 -58
  52. package/build/src/http_context/main.js +0 -105
  53. package/build/src/qs.d.ts +0 -11
  54. package/build/src/qs.js +0 -25
  55. package/build/src/redirect.d.ts +0 -42
  56. package/build/src/redirect.js +0 -140
  57. package/build/src/request.d.ts +0 -565
  58. package/build/src/request.js +0 -865
  59. package/build/src/response.d.ts +0 -540
  60. package/build/src/response.js +0 -1208
  61. package/build/src/router/brisk.d.ts +0 -42
  62. package/build/src/router/brisk.js +0 -85
  63. package/build/src/router/executor.d.ts +0 -8
  64. package/build/src/router/executor.js +0 -29
  65. package/build/src/router/factories/use_return_value.d.ts +0 -6
  66. package/build/src/router/factories/use_return_value.js +0 -22
  67. package/build/src/router/group.d.ts +0 -65
  68. package/build/src/router/group.js +0 -207
  69. package/build/src/router/lookup_store/main.d.ts +0 -49
  70. package/build/src/router/lookup_store/main.js +0 -86
  71. package/build/src/router/lookup_store/route_finder.d.ts +0 -21
  72. package/build/src/router/lookup_store/route_finder.js +0 -49
  73. package/build/src/router/lookup_store/url_builder.d.ts +0 -52
  74. package/build/src/router/lookup_store/url_builder.js +0 -209
  75. package/build/src/router/main.d.ts +0 -128
  76. package/build/src/router/main.js +0 -316
  77. package/build/src/router/matchers.d.ts +0 -27
  78. package/build/src/router/matchers.js +0 -36
  79. package/build/src/router/parser.d.ts +0 -5
  80. package/build/src/router/parser.js +0 -17
  81. package/build/src/router/resource.d.ts +0 -54
  82. package/build/src/router/resource.js +0 -216
  83. package/build/src/router/route.d.ts +0 -92
  84. package/build/src/router/route.js +0 -293
  85. package/build/src/router/store.d.ts +0 -66
  86. package/build/src/router/store.js +0 -195
  87. package/build/src/server/factories/final_handler.d.ts +0 -9
  88. package/build/src/server/factories/final_handler.js +0 -30
  89. package/build/src/server/factories/middleware_handler.d.ts +0 -8
  90. package/build/src/server/factories/middleware_handler.js +0 -16
  91. package/build/src/server/factories/write_response.d.ts +0 -6
  92. package/build/src/server/factories/write_response.js +0 -24
  93. package/build/src/server/main.js +0 -283
  94. package/build/src/types/base.d.ts +0 -19
  95. package/build/src/types/base.js +0 -9
  96. package/build/src/types/middleware.d.ts +0 -35
  97. package/build/src/types/middleware.js +0 -9
  98. package/build/src/types/qs.d.ts +0 -68
  99. package/build/src/types/qs.js +0 -9
  100. package/build/src/types/request.d.ts +0 -39
  101. package/build/src/types/request.js +0 -9
  102. package/build/src/types/response.d.ts +0 -45
  103. package/build/src/types/response.js +0 -9
  104. package/build/src/types/route.d.ts +0 -165
  105. package/build/src/types/route.js +0 -9
  106. package/build/src/types/server.d.ts +0 -72
  107. package/build/src/types/server.js +0 -9
@@ -1,45 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { AppFactory } from '@adonisjs/application/factories';
10
- import { EncryptionFactory } from '@adonisjs/encryption/factories';
11
- import { Router } from '../src/router/main.js';
12
- import { QsParserFactory } from './qs_parser_factory.js';
13
- /**
14
- * Router factory is used to generate router class instances for
15
- * testing
16
- */
17
- export class RouterFactory {
18
- #parameters = {};
19
- /**
20
- * Returns an instance of the application class
21
- */
22
- #getApp() {
23
- return (this.#parameters.app || new AppFactory().create(new URL('./app/', import.meta.url), () => { }));
24
- }
25
- /**
26
- * Returns an instance of the encryptor to encrypt
27
- * signed URLs
28
- */
29
- #createEncryption() {
30
- return this.#parameters.encryption || new EncryptionFactory().create();
31
- }
32
- /**
33
- * Merge factory params
34
- */
35
- merge(params) {
36
- Object.assign(this.#parameters, params);
37
- return this;
38
- }
39
- /**
40
- * Create router instance
41
- */
42
- create() {
43
- return new Router(this.#getApp(), this.#createEncryption(), new QsParserFactory().create());
44
- }
45
- }
@@ -1,29 +0,0 @@
1
- import { Logger } from '@adonisjs/logger';
2
- import { Emitter } from '@adonisjs/events';
3
- import type { Encryption } from '@adonisjs/encryption';
4
- import type { Application } from '@adonisjs/application';
5
- import { Server } from '../src/server/main.js';
6
- import type { ServerConfig } from '../src/types/server.js';
7
- type FactoryParameters = {
8
- app: Application<any>;
9
- logger: Logger;
10
- encryption: Encryption;
11
- emitter: Emitter<any>;
12
- config: Partial<ServerConfig>;
13
- };
14
- /**
15
- * Server factory is used to generate server class instances for
16
- * testing
17
- */
18
- export declare class ServerFactory {
19
- #private;
20
- /**
21
- * Merge factory params
22
- */
23
- merge(params: Partial<FactoryParameters>): this;
24
- /**
25
- * Create server instance
26
- */
27
- create(): Server;
28
- }
29
- export {};
@@ -1,65 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { Logger } from '@adonisjs/logger';
10
- import { Emitter } from '@adonisjs/events';
11
- import { AppFactory } from '@adonisjs/application/factories';
12
- import { EncryptionFactory } from '@adonisjs/encryption/factories';
13
- import { Server } from '../src/server/main.js';
14
- import { defineConfig } from '../src/define_config.js';
15
- /**
16
- * Server factory is used to generate server class instances for
17
- * testing
18
- */
19
- export class ServerFactory {
20
- #parameters = {};
21
- /**
22
- * Returns the emitter instance
23
- */
24
- #getEmitter() {
25
- return this.#parameters.emitter || new Emitter(this.#getApp());
26
- }
27
- /**
28
- * Returns the logger instance
29
- */
30
- #getLogger() {
31
- return this.#parameters.logger || new Logger({ enabled: false });
32
- }
33
- /**
34
- * Returns the config for the server class
35
- */
36
- #getConfig() {
37
- return defineConfig(this.#parameters.config || {});
38
- }
39
- /**
40
- * Returns an instance of the application class
41
- */
42
- #getApp() {
43
- return (this.#parameters.app || new AppFactory().create(new URL('./app/', import.meta.url), () => { }));
44
- }
45
- /**
46
- * Returns an instance of the encryptor to encrypt
47
- * signed URLs
48
- */
49
- #createEncryption() {
50
- return this.#parameters.encryption || new EncryptionFactory().create();
51
- }
52
- /**
53
- * Merge factory params
54
- */
55
- merge(params) {
56
- Object.assign(this.#parameters, params);
57
- return this;
58
- }
59
- /**
60
- * Create server instance
61
- */
62
- create() {
63
- return new Server(this.#getApp(), this.#createEncryption(), this.#getEmitter(), this.#getLogger(), this.#getConfig());
64
- }
65
- }
@@ -1,37 +0,0 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- /**
3
- * Cookie client exposes the API to parse/set AdonisJS cookies
4
- * as a client.
5
- */
6
- export declare class CookieClient {
7
- #private;
8
- constructor(encryption: Encryption);
9
- /**
10
- * Encrypt a key value pair to be sent in the cookie header
11
- */
12
- encrypt(key: string, value: any): string | null;
13
- /**
14
- * Sign a key value pair to be sent in the cookie header
15
- */
16
- sign(key: string, value: any): string | null;
17
- /**
18
- * Encode a key value pair to be sent in the cookie header
19
- */
20
- encode(_: string, value: any): string | null;
21
- /**
22
- * Unsign a signed cookie value
23
- */
24
- unsign(key: string, value: string): any;
25
- /**
26
- * Decrypt an encrypted cookie value
27
- */
28
- decrypt(key: string, value: string): any;
29
- /**
30
- * Decode an encoded cookie value
31
- */
32
- decode(_: string, value: string): any;
33
- /**
34
- * Parse response cookie
35
- */
36
- parse(key: string, value: any): any;
37
- }
@@ -1,84 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import * as plainCookiesDriver from './drivers/plain.js';
10
- import * as signedCookiesDriver from './drivers/signed.js';
11
- import * as encryptedCookiesDriver from './drivers/encrypted.js';
12
- /**
13
- * Cookie client exposes the API to parse/set AdonisJS cookies
14
- * as a client.
15
- */
16
- export class CookieClient {
17
- #encryption;
18
- constructor(encryption) {
19
- this.#encryption = encryption;
20
- }
21
- /**
22
- * Encrypt a key value pair to be sent in the cookie header
23
- */
24
- encrypt(key, value) {
25
- return encryptedCookiesDriver.pack(key, value, this.#encryption);
26
- }
27
- /**
28
- * Sign a key value pair to be sent in the cookie header
29
- */
30
- sign(key, value) {
31
- return signedCookiesDriver.pack(key, value, this.#encryption);
32
- }
33
- /**
34
- * Encode a key value pair to be sent in the cookie header
35
- */
36
- encode(_, value) {
37
- return plainCookiesDriver.pack(value);
38
- }
39
- /**
40
- * Unsign a signed cookie value
41
- */
42
- unsign(key, value) {
43
- return signedCookiesDriver.canUnpack(value)
44
- ? signedCookiesDriver.unpack(key, value, this.#encryption)
45
- : null;
46
- }
47
- /**
48
- * Decrypt an encrypted cookie value
49
- */
50
- decrypt(key, value) {
51
- return encryptedCookiesDriver.canUnpack(value)
52
- ? encryptedCookiesDriver.unpack(key, value, this.#encryption)
53
- : null;
54
- }
55
- /**
56
- * Decode an encoded cookie value
57
- */
58
- decode(_, value) {
59
- return plainCookiesDriver.canUnpack(value) ? plainCookiesDriver.unpack(value) : null;
60
- }
61
- /**
62
- * Parse response cookie
63
- */
64
- parse(key, value) {
65
- /**
66
- * Unsign signed cookie
67
- */
68
- if (signedCookiesDriver.canUnpack(value)) {
69
- return signedCookiesDriver.unpack(key, value, this.#encryption);
70
- }
71
- /**
72
- * Decrypted encrypted cookie
73
- */
74
- if (encryptedCookiesDriver.canUnpack(value)) {
75
- return encryptedCookiesDriver.unpack(key, value, this.#encryption);
76
- }
77
- /**
78
- * Decode encoded cookie
79
- */
80
- if (plainCookiesDriver.canUnpack(value)) {
81
- return plainCookiesDriver.unpack(value);
82
- }
83
- }
84
- }
@@ -1,16 +0,0 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- /**
3
- * Encrypt a value to be set as cookie
4
- */
5
- export declare function pack(key: string, value: any, encryption: Encryption): null | string;
6
- /**
7
- * Returns a boolean, if the unpack method from this module can attempt
8
- * to unpack encrypted value.
9
- */
10
- export declare function canUnpack(encryptedValue: string): boolean;
11
- /**
12
- * Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
13
- * Only call this method, when `canUnpack` returns true, otherwise runtime
14
- * exceptions can be raised.
15
- */
16
- export declare function unpack(key: string, encryptedValue: string, encryption: Encryption): null | any;
@@ -1,36 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * Encrypt a value to be set as cookie
11
- */
12
- export function pack(key, value, encryption) {
13
- if (value === undefined || value === null) {
14
- return null;
15
- }
16
- return `e:${encryption.encrypt(value, undefined, key)}`;
17
- }
18
- /**
19
- * Returns a boolean, if the unpack method from this module can attempt
20
- * to unpack encrypted value.
21
- */
22
- export function canUnpack(encryptedValue) {
23
- return typeof encryptedValue === 'string' && encryptedValue.substring(0, 2) === 'e:';
24
- }
25
- /**
26
- * Attempts to unpack the encrypted cookie value. Returns null, when fails to do so.
27
- * Only call this method, when `canUnpack` returns true, otherwise runtime
28
- * exceptions can be raised.
29
- */
30
- export function unpack(key, encryptedValue, encryption) {
31
- const value = encryptedValue.slice(2);
32
- if (!value) {
33
- return null;
34
- }
35
- return encryption.decrypt(value, key);
36
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * Encodes a value into a base64 url encoded string to
3
- * be set as cookie
4
- */
5
- export declare function pack(value: any): null | string;
6
- /**
7
- * Returns true when this `unpack` method of this module can attempt
8
- * to unpack the encode value.
9
- */
10
- export declare function canUnpack(encodedValue: string): boolean;
11
- /**
12
- * Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
13
- * before calling this method
14
- */
15
- export declare function unpack(encodedValue: string): null | any;
@@ -1,33 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { base64, MessageBuilder } from '@poppinss/utils';
10
- /**
11
- * Encodes a value into a base64 url encoded string to
12
- * be set as cookie
13
- */
14
- export function pack(value) {
15
- if (value === undefined || value === null) {
16
- return null;
17
- }
18
- return base64.urlEncode(new MessageBuilder().build(value));
19
- }
20
- /**
21
- * Returns true when this `unpack` method of this module can attempt
22
- * to unpack the encode value.
23
- */
24
- export function canUnpack(encodedValue) {
25
- return typeof encodedValue === 'string';
26
- }
27
- /**
28
- * Attempts to unpack the value by decoding it. Make sure to call, `canUnpack`
29
- * before calling this method
30
- */
31
- export function unpack(encodedValue) {
32
- return new MessageBuilder().verify(base64.urlDecode(encodedValue, 'utf-8', false));
33
- }
@@ -1,16 +0,0 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- /**
3
- * Signs a value to be shared as a cookie. The signed output has a
4
- * hash to verify tampering with the original value
5
- */
6
- export declare function pack(key: string, value: any, encryption: Encryption): null | string;
7
- /**
8
- * Returns a boolean, if the unpack method from this module can attempt
9
- * to unpack the signed value.
10
- */
11
- export declare function canUnpack(signedValue: string): boolean;
12
- /**
13
- * Attempts to unpack the signed value. Make sure to call `canUnpack` before
14
- * calling this method.
15
- */
16
- export declare function unpack(key: string, signedValue: string, encryption: Encryption): null | any;
@@ -1,36 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- /**
10
- * Signs a value to be shared as a cookie. The signed output has a
11
- * hash to verify tampering with the original value
12
- */
13
- export function pack(key, value, encryption) {
14
- if (value === undefined || value === null) {
15
- return null;
16
- }
17
- return `s:${encryption.verifier.sign(value, undefined, key)}`;
18
- }
19
- /**
20
- * Returns a boolean, if the unpack method from this module can attempt
21
- * to unpack the signed value.
22
- */
23
- export function canUnpack(signedValue) {
24
- return typeof signedValue === 'string' && signedValue.substring(0, 2) === 's:';
25
- }
26
- /**
27
- * Attempts to unpack the signed value. Make sure to call `canUnpack` before
28
- * calling this method.
29
- */
30
- export function unpack(key, signedValue, encryption) {
31
- const value = signedValue.slice(2);
32
- if (!value) {
33
- return null;
34
- }
35
- return encryption.verifier.unsign(value, key);
36
- }
@@ -1,37 +0,0 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- /**
3
- * Cookie parser parses the HTTP `cookie` header and collects all cookies
4
- * inside an object of `key-value` pair, but doesn't attempt to decrypt
5
- * or unsign or decode the individual values.
6
- *
7
- * The cookie values are lazily decrypted, or unsigned to avoid unncessary
8
- * processing, which infact can be used as a means to burden the server
9
- * by sending too many cookies which even doesn't belongs to the
10
- * server.
11
- */
12
- export declare class CookieParser {
13
- #private;
14
- constructor(cookieHeader: string, encryption: Encryption);
15
- /**
16
- * Attempts to decode a cookie by the name. When calling this method,
17
- * you are assuming that the cookie was just encoded in the first
18
- * place and not signed or encrypted.
19
- */
20
- decode(key: string, encoded?: boolean): any | null;
21
- /**
22
- * Attempts to unsign a cookie by the name. When calling this method,
23
- * you are assuming that the cookie was signed in the first place.
24
- */
25
- unsign(key: string): null | any;
26
- /**
27
- * Attempts to decrypt a cookie by the name. When calling this method,
28
- * you are assuming that the cookie was encrypted in the first place.
29
- */
30
- decrypt(key: string): null | any;
31
- /**
32
- * Returns an object of cookies key-value pair. Do note, the
33
- * cookies are not decoded, unsigned or decrypted inside this
34
- * list.
35
- */
36
- list(): Record<string, any>;
37
- }
@@ -1,167 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import cookie from 'cookie';
10
- import { CookieClient } from './client.js';
11
- /**
12
- * Cookie parser parses the HTTP `cookie` header and collects all cookies
13
- * inside an object of `key-value` pair, but doesn't attempt to decrypt
14
- * or unsign or decode the individual values.
15
- *
16
- * The cookie values are lazily decrypted, or unsigned to avoid unncessary
17
- * processing, which infact can be used as a means to burden the server
18
- * by sending too many cookies which even doesn't belongs to the
19
- * server.
20
- */
21
- export class CookieParser {
22
- #client;
23
- /**
24
- * A copy of cached cookies, they are cached during a request after
25
- * initial decoding, unsigning or decrypting.
26
- */
27
- #cachedCookies = {
28
- signedCookies: {},
29
- plainCookies: {},
30
- encryptedCookies: {},
31
- };
32
- /**
33
- * An object of key-value pair collected by parsing
34
- * the request cookie header.
35
- */
36
- #cookies;
37
- constructor(cookieHeader, encryption) {
38
- this.#client = new CookieClient(encryption);
39
- this.#cookies = this.#parse(cookieHeader);
40
- }
41
- /**
42
- * Parses the request `cookie` header
43
- */
44
- #parse(cookieHeader) {
45
- /*
46
- * Set to empty object when cookie header is empty string
47
- */
48
- if (!cookieHeader) {
49
- return {};
50
- }
51
- /*
52
- * Parse and store reference
53
- */
54
- return cookie.parse(cookieHeader);
55
- }
56
- /**
57
- * Attempts to decode a cookie by the name. When calling this method,
58
- * you are assuming that the cookie was just encoded in the first
59
- * place and not signed or encrypted.
60
- */
61
- decode(key, encoded = true) {
62
- /*
63
- * Ignore when initial value is not defined or null
64
- */
65
- const value = this.#cookies[key];
66
- if (value === null || value === undefined) {
67
- return null;
68
- }
69
- /*
70
- * Reference to the cache object. Mainly done to avoid typos,
71
- * since this object is referenced a handful of times inside
72
- * this method.
73
- */
74
- const cache = this.#cachedCookies.plainCookies;
75
- /*
76
- * Return from cache, when already parsed
77
- */
78
- if (cache[key] !== undefined) {
79
- return cache[key];
80
- }
81
- /*
82
- * Attempt to unpack and cache it for future. The value is only
83
- * when value it is not null.
84
- */
85
- const parsed = encoded ? this.#client.decode(key, value) : value;
86
- if (parsed !== null) {
87
- cache[key] = parsed;
88
- }
89
- return parsed;
90
- }
91
- /**
92
- * Attempts to unsign a cookie by the name. When calling this method,
93
- * you are assuming that the cookie was signed in the first place.
94
- */
95
- unsign(key) {
96
- /*
97
- * Ignore when initial value is not defined or null
98
- */
99
- const value = this.#cookies[key];
100
- if (value === null || value === undefined) {
101
- return null;
102
- }
103
- /*
104
- * Reference to the cache object. Mainly done to avoid typos,
105
- * since this object is referenced a handful of times inside
106
- * this method.
107
- */
108
- const cache = this.#cachedCookies.signedCookies;
109
- /*
110
- * Return from cache, when already parsed
111
- */
112
- if (cache[key] !== undefined) {
113
- return cache[key];
114
- }
115
- /*
116
- * Attempt to unpack and cache it for future. The value is only
117
- * when value it is not null.
118
- */
119
- const parsed = this.#client.unsign(key, value);
120
- if (parsed !== null) {
121
- cache[key] = parsed;
122
- }
123
- return parsed;
124
- }
125
- /**
126
- * Attempts to decrypt a cookie by the name. When calling this method,
127
- * you are assuming that the cookie was encrypted in the first place.
128
- */
129
- decrypt(key) {
130
- /*
131
- * Ignore when initial value is not defined or null
132
- */
133
- const value = this.#cookies[key];
134
- if (value === null || value === undefined) {
135
- return null;
136
- }
137
- /*
138
- * Reference to the cache object. Mainly done to avoid typos,
139
- * since this object is referenced a handful of times inside
140
- * this method.
141
- */
142
- const cache = this.#cachedCookies.encryptedCookies;
143
- /*
144
- * Return from cache, when already parsed
145
- */
146
- if (cache[key] !== undefined) {
147
- return cache[key];
148
- }
149
- /*
150
- * Attempt to unpack and cache it for future. The value is only
151
- * when value it is not null.
152
- */
153
- const parsed = this.#client.decrypt(key, value);
154
- if (parsed !== null) {
155
- cache[key] = parsed;
156
- }
157
- return parsed;
158
- }
159
- /**
160
- * Returns an object of cookies key-value pair. Do note, the
161
- * cookies are not decoded, unsigned or decrypted inside this
162
- * list.
163
- */
164
- list() {
165
- return this.#cookies;
166
- }
167
- }
@@ -1,33 +0,0 @@
1
- import type { Encryption } from '@adonisjs/encryption';
2
- import type { CookieOptions } from '../types/response.js';
3
- /**
4
- * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
5
- * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
6
- * and then set them individually using the `set-cookie` header.
7
- */
8
- export declare class CookieSerializer {
9
- #private;
10
- constructor(encryption: Encryption);
11
- /**
12
- * Encodes value as a plain cookie. By default, the plain value will be converted
13
- * to a string using "JSON.stringify" method and then encoded as a base64 string.
14
- *
15
- * You can disable encoding of the cookie by setting `options.encoded = false`.
16
- *
17
- * ```ts
18
- * serializer.encode('name', 'virk')
19
- * ```
20
- */
21
- encode(key: string, value: any, options?: Partial<CookieOptions & {
22
- encode: boolean;
23
- }>): string | null;
24
- /**
25
- * Sign a key-value pair to a signed cookie. The signed value has a
26
- * verification hash attached to it to detect data tampering.
27
- */
28
- sign(key: string, value: any, options?: Partial<CookieOptions>): string | null;
29
- /**
30
- * Encrypts a key-value pair to an encrypted cookie.
31
- */
32
- encrypt(key: string, value: any, options?: Partial<CookieOptions>): string | null;
33
- }