@duplojs/http 0.8.5 → 0.10.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 (171) hide show
  1. package/dist/core/builders/preflight/builder.d.ts +5 -6
  2. package/dist/core/builders/preflight/process.d.ts +3 -4
  3. package/dist/core/builders/preflight/route.d.ts +4 -5
  4. package/dist/core/builders/process/builder.d.ts +4 -5
  5. package/dist/core/builders/process/checker.d.ts +2 -3
  6. package/dist/core/builders/process/cut.d.ts +4 -5
  7. package/dist/core/builders/process/exports.d.ts +3 -4
  8. package/dist/core/builders/process/extract.d.ts +2 -3
  9. package/dist/core/builders/process/presetChecker.d.ts +2 -3
  10. package/dist/core/builders/process/process.d.ts +3 -4
  11. package/dist/core/builders/route/builder.d.ts +6 -6
  12. package/dist/core/builders/route/checker.d.ts +2 -3
  13. package/dist/core/builders/route/cut.d.ts +4 -5
  14. package/dist/core/builders/route/extract.d.ts +3 -3
  15. package/dist/core/builders/route/handler.d.ts +3 -4
  16. package/dist/core/builders/route/presetChecker.d.ts +2 -3
  17. package/dist/core/builders/route/process.d.ts +3 -4
  18. package/dist/core/defaultHooks/index.d.ts +1 -1
  19. package/dist/core/functionsBuilders/index.cjs +1 -0
  20. package/dist/core/functionsBuilders/index.d.ts +1 -0
  21. package/dist/core/functionsBuilders/index.mjs +1 -0
  22. package/dist/core/functionsBuilders/route/build.d.ts +5 -2
  23. package/dist/core/functionsBuilders/route/create.d.ts +3 -5
  24. package/dist/core/functionsBuilders/route/{hook.cjs → default/hook.cjs} +16 -7
  25. package/dist/core/functionsBuilders/route/{hook.d.ts → default/hook.d.ts} +5 -5
  26. package/dist/core/functionsBuilders/route/{hook.mjs → default/hook.mjs} +16 -7
  27. package/dist/core/functionsBuilders/route/{default.cjs → default/index.cjs} +22 -34
  28. package/dist/core/functionsBuilders/route/default/index.d.ts +2 -0
  29. package/dist/core/functionsBuilders/route/{default.mjs → default/index.mjs} +11 -29
  30. package/dist/core/functionsBuilders/route/index.cjs +2 -9
  31. package/dist/core/functionsBuilders/route/index.d.ts +0 -1
  32. package/dist/core/functionsBuilders/route/index.mjs +1 -2
  33. package/dist/core/functionsBuilders/router/build.cjs +7 -0
  34. package/dist/core/functionsBuilders/router/build.d.ts +14 -0
  35. package/dist/core/functionsBuilders/router/build.mjs +5 -0
  36. package/dist/core/functionsBuilders/router/create.cjs +7 -0
  37. package/dist/core/functionsBuilders/router/create.d.ts +15 -0
  38. package/dist/core/functionsBuilders/router/create.mjs +5 -0
  39. package/dist/core/functionsBuilders/router/default/index.cjs +52 -0
  40. package/dist/core/functionsBuilders/router/default/index.d.ts +1 -0
  41. package/dist/core/functionsBuilders/router/default/index.mjs +50 -0
  42. package/dist/core/functionsBuilders/router/index.cjs +11 -0
  43. package/dist/core/functionsBuilders/router/index.d.ts +3 -0
  44. package/dist/core/functionsBuilders/router/index.mjs +3 -0
  45. package/dist/core/functionsBuilders/steps/create.d.ts +3 -6
  46. package/dist/core/hub/defaultMalformedUrlHandler.d.ts +1 -1
  47. package/dist/core/hub/defaultNotfoundHandler.d.ts +1 -1
  48. package/dist/core/hub/hooks.d.ts +2 -2
  49. package/dist/core/hub/index.cjs +5 -0
  50. package/dist/core/hub/index.d.ts +6 -3
  51. package/dist/core/hub/index.mjs +5 -0
  52. package/dist/core/implementHttpServer.cjs +1 -1
  53. package/dist/core/implementHttpServer.d.ts +2 -2
  54. package/dist/core/implementHttpServer.mjs +2 -2
  55. package/dist/core/index.cjs +15 -14
  56. package/dist/core/index.mjs +8 -6
  57. package/dist/core/process/index.d.ts +0 -7
  58. package/dist/core/route/hooks.cjs +2 -17
  59. package/dist/core/route/hooks.d.ts +15 -32
  60. package/dist/core/route/hooks.mjs +3 -17
  61. package/dist/core/route/index.cjs +0 -1
  62. package/dist/core/route/index.mjs +1 -1
  63. package/dist/core/router/{buildSystemRoute.cjs → createRouterElementSystem.cjs} +4 -3
  64. package/dist/core/router/createRouterElementSystem.d.ts +9 -0
  65. package/dist/core/router/{buildSystemRoute.mjs → createRouterElementSystem.mjs} +4 -3
  66. package/dist/core/router/index.cjs +19 -60
  67. package/dist/core/router/index.d.ts +3 -4
  68. package/dist/core/router/index.mjs +17 -56
  69. package/dist/core/router/types/buildedRouter.d.ts +2 -12
  70. package/dist/core/router/types/index.cjs +4 -0
  71. package/dist/core/router/types/index.d.ts +4 -0
  72. package/dist/core/router/types/index.mjs +4 -0
  73. package/dist/core/router/types/router.cjs +2 -0
  74. package/dist/core/router/types/router.d.ts +12 -0
  75. package/dist/core/router/types/router.mjs +1 -0
  76. package/dist/core/router/types/routerElement.cjs +2 -0
  77. package/dist/core/router/types/routerElement.d.ts +8 -0
  78. package/dist/core/router/types/routerElement.mjs +1 -0
  79. package/dist/core/router/types/routerElementSystem.cjs +2 -0
  80. package/dist/core/router/types/routerElementSystem.d.ts +6 -0
  81. package/dist/core/router/types/routerElementSystem.mjs +1 -0
  82. package/dist/core/router/types/routerElementWrapper.cjs +2 -0
  83. package/dist/core/router/types/routerElementWrapper.d.ts +2 -0
  84. package/dist/core/router/types/routerElementWrapper.mjs +1 -0
  85. package/dist/core/steps/cut.d.ts +1 -2
  86. package/dist/core/steps/handler.d.ts +1 -2
  87. package/dist/core/steps/types/stepFunctionParams.d.ts +2 -2
  88. package/dist/interfaces/node/createHttpServer.cjs +2 -2
  89. package/dist/interfaces/node/createHttpServer.mjs +2 -2
  90. package/dist/interfaces/node/hooks/index.d.ts +3 -3
  91. package/dist/plugins/cacheController/hooks.cjs +2 -1
  92. package/dist/plugins/cacheController/hooks.d.ts +1 -1
  93. package/dist/plugins/cacheController/hooks.mjs +2 -1
  94. package/dist/plugins/cookie/hooks/cookieHooks.cjs +15 -0
  95. package/dist/plugins/cookie/hooks/cookieHooks.d.ts +11 -0
  96. package/dist/plugins/cookie/hooks/cookieHooks.mjs +13 -0
  97. package/dist/plugins/cookie/hooks/index.cjs +11 -0
  98. package/dist/plugins/cookie/hooks/index.d.ts +3 -0
  99. package/dist/plugins/cookie/hooks/index.mjs +3 -0
  100. package/dist/plugins/cookie/hooks/parseRequestCookie.cjs +20 -0
  101. package/dist/plugins/cookie/hooks/parseRequestCookie.d.ts +8 -0
  102. package/dist/plugins/cookie/hooks/parseRequestCookie.mjs +18 -0
  103. package/dist/plugins/cookie/hooks/serializeResponseCookie.cjs +17 -0
  104. package/dist/plugins/cookie/hooks/serializeResponseCookie.d.ts +7 -0
  105. package/dist/plugins/cookie/hooks/serializeResponseCookie.mjs +15 -0
  106. package/dist/plugins/cookie/index.cjs +25 -0
  107. package/dist/plugins/cookie/index.d.ts +6 -0
  108. package/dist/plugins/cookie/index.mjs +9 -0
  109. package/dist/plugins/cookie/kind.cjs +9 -0
  110. package/dist/plugins/cookie/kind.d.ts +6 -0
  111. package/dist/plugins/cookie/kind.mjs +7 -0
  112. package/dist/plugins/cookie/metadata.cjs +8 -0
  113. package/dist/plugins/cookie/metadata.d.ts +1 -0
  114. package/dist/plugins/cookie/metadata.mjs +6 -0
  115. package/dist/plugins/cookie/override.cjs +30 -0
  116. package/dist/plugins/cookie/override.d.ts +16 -0
  117. package/dist/plugins/cookie/override.mjs +28 -0
  118. package/dist/plugins/cookie/parser.cjs +84 -0
  119. package/dist/plugins/cookie/parser.d.ts +2 -0
  120. package/dist/plugins/cookie/parser.mjs +79 -0
  121. package/dist/plugins/cookie/plugin.cjs +30 -0
  122. package/dist/plugins/cookie/plugin.d.ts +8 -0
  123. package/dist/plugins/cookie/plugin.mjs +28 -0
  124. package/dist/plugins/cookie/serialize.cjs +84 -0
  125. package/dist/plugins/cookie/serialize.d.ts +29 -0
  126. package/dist/plugins/cookie/serialize.mjs +81 -0
  127. package/dist/plugins/cors/headerFunctions/allowHeaders.cjs +11 -0
  128. package/dist/plugins/cors/headerFunctions/allowHeaders.d.ts +5 -0
  129. package/dist/plugins/cors/headerFunctions/allowHeaders.mjs +9 -0
  130. package/dist/plugins/cors/headerFunctions/allowMethods.cjs +16 -0
  131. package/dist/plugins/cors/headerFunctions/allowMethods.d.ts +6 -0
  132. package/dist/plugins/cors/headerFunctions/allowMethods.mjs +14 -0
  133. package/dist/plugins/cors/headerFunctions/allowOrigin.cjs +24 -0
  134. package/dist/plugins/cors/headerFunctions/allowOrigin.d.ts +7 -0
  135. package/dist/plugins/cors/headerFunctions/allowOrigin.mjs +22 -0
  136. package/dist/plugins/cors/headerFunctions/credentials.cjs +11 -0
  137. package/dist/plugins/cors/headerFunctions/credentials.d.ts +5 -0
  138. package/dist/plugins/cors/headerFunctions/credentials.mjs +9 -0
  139. package/dist/plugins/cors/headerFunctions/exposeHeaders.cjs +11 -0
  140. package/dist/plugins/cors/headerFunctions/exposeHeaders.d.ts +5 -0
  141. package/dist/plugins/cors/headerFunctions/exposeHeaders.mjs +9 -0
  142. package/dist/plugins/cors/headerFunctions/index.cjs +19 -0
  143. package/dist/plugins/cors/headerFunctions/index.d.ts +7 -0
  144. package/dist/plugins/cors/headerFunctions/index.mjs +7 -0
  145. package/dist/plugins/cors/headerFunctions/maxAge.cjs +11 -0
  146. package/dist/plugins/cors/headerFunctions/maxAge.d.ts +5 -0
  147. package/dist/plugins/cors/headerFunctions/maxAge.mjs +9 -0
  148. package/dist/plugins/cors/headerFunctions/vary.cjs +35 -0
  149. package/dist/plugins/cors/headerFunctions/vary.d.ts +5 -0
  150. package/dist/plugins/cors/headerFunctions/vary.mjs +33 -0
  151. package/dist/plugins/cors/index.cjs +9 -0
  152. package/dist/plugins/cors/index.d.ts +2 -0
  153. package/dist/plugins/cors/index.mjs +2 -0
  154. package/dist/plugins/cors/metadata.cjs +8 -0
  155. package/dist/plugins/cors/metadata.d.ts +1 -0
  156. package/dist/plugins/cors/metadata.mjs +6 -0
  157. package/dist/plugins/cors/plugin.cjs +108 -0
  158. package/dist/plugins/cors/plugin.d.ts +12 -0
  159. package/dist/plugins/cors/plugin.mjs +106 -0
  160. package/dist/plugins/openApiGenerator/makeOpenApiRoute.d.ts +1 -1
  161. package/dist/plugins/static/makeRouteFile.d.ts +2 -2
  162. package/dist/plugins/static/makeRouteFolder.cjs +1 -1
  163. package/dist/plugins/static/makeRouteFolder.d.ts +2 -2
  164. package/dist/plugins/static/makeRouteFolder.mjs +1 -1
  165. package/dist/plugins/static/plugin.d.ts +1 -1
  166. package/package.json +37 -7
  167. package/dist/core/functionsBuilders/route/default.d.ts +0 -1
  168. package/dist/core/router/buildSystemRoute.d.ts +0 -11
  169. /package/dist/core/{router/decodeUrl.cjs → decodeUrl.cjs} +0 -0
  170. /package/dist/core/{router/decodeUrl.d.ts → decodeUrl.d.ts} +0 -0
  171. /package/dist/core/{router/decodeUrl.mjs → decodeUrl.mjs} +0 -0
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ function findPairEndIndex(value, start, len) {
7
+ const index = value.indexOf(";", start);
8
+ return index === -1 ? len : index;
9
+ }
10
+ /**
11
+ * @internal
12
+ */
13
+ function sliceAndTrimOws(value, min, max) {
14
+ if (min === max) {
15
+ return "";
16
+ }
17
+ let start = min;
18
+ let end = max;
19
+ do {
20
+ const code = value.charCodeAt(start);
21
+ if (code !== 32 /* */ && code !== 9 /* \t */) {
22
+ break;
23
+ }
24
+ } while (++start < end);
25
+ while (end > start) {
26
+ const code = value.charCodeAt(end - 1);
27
+ if (code !== 32 /* */ && code !== 9 /* \t */) {
28
+ break;
29
+ }
30
+ end--;
31
+ }
32
+ return value.slice(start, end);
33
+ }
34
+ /**
35
+ * @internal
36
+ */
37
+ function decode(value) {
38
+ if (!value.includes("%")) {
39
+ return value;
40
+ }
41
+ try {
42
+ return decodeURIComponent(value);
43
+ }
44
+ catch {
45
+ return value;
46
+ }
47
+ }
48
+ function defaultParser(value) {
49
+ const result = {};
50
+ const valueLength = value.length;
51
+ if (valueLength < 2) {
52
+ return result;
53
+ }
54
+ let index = 0;
55
+ do {
56
+ const equalCharIndex = value.indexOf("=", index);
57
+ if (equalCharIndex === -1) {
58
+ break;
59
+ }
60
+ const pairEndIndex = findPairEndIndex(value, index, valueLength);
61
+ if (equalCharIndex > pairEndIndex) {
62
+ index = value.lastIndexOf(";", equalCharIndex - 1) + 1;
63
+ continue;
64
+ }
65
+ const key = sliceAndTrimOws(value, index, equalCharIndex);
66
+ if (key === ""
67
+ || key === "__proto__"
68
+ || key === "constructor"
69
+ || key === "prototype") {
70
+ index = pairEndIndex + 1;
71
+ continue;
72
+ }
73
+ if (result[key] === undefined) {
74
+ result[key] = decode(sliceAndTrimOws(value, equalCharIndex + 1, pairEndIndex));
75
+ }
76
+ index = pairEndIndex + 1;
77
+ } while (index < valueLength);
78
+ return result;
79
+ }
80
+
81
+ exports.decode = decode;
82
+ exports.defaultParser = defaultParser;
83
+ exports.findPairEndIndex = findPairEndIndex;
84
+ exports.sliceAndTrimOws = sliceAndTrimOws;
@@ -0,0 +1,2 @@
1
+ export declare function defaultParser(value: string): Partial<Record<string, string>>;
2
+ export type Parser = typeof defaultParser;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ function findPairEndIndex(value, start, len) {
5
+ const index = value.indexOf(";", start);
6
+ return index === -1 ? len : index;
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ function sliceAndTrimOws(value, min, max) {
12
+ if (min === max) {
13
+ return "";
14
+ }
15
+ let start = min;
16
+ let end = max;
17
+ do {
18
+ const code = value.charCodeAt(start);
19
+ if (code !== 32 /* */ && code !== 9 /* \t */) {
20
+ break;
21
+ }
22
+ } while (++start < end);
23
+ while (end > start) {
24
+ const code = value.charCodeAt(end - 1);
25
+ if (code !== 32 /* */ && code !== 9 /* \t */) {
26
+ break;
27
+ }
28
+ end--;
29
+ }
30
+ return value.slice(start, end);
31
+ }
32
+ /**
33
+ * @internal
34
+ */
35
+ function decode(value) {
36
+ if (!value.includes("%")) {
37
+ return value;
38
+ }
39
+ try {
40
+ return decodeURIComponent(value);
41
+ }
42
+ catch {
43
+ return value;
44
+ }
45
+ }
46
+ function defaultParser(value) {
47
+ const result = {};
48
+ const valueLength = value.length;
49
+ if (valueLength < 2) {
50
+ return result;
51
+ }
52
+ let index = 0;
53
+ do {
54
+ const equalCharIndex = value.indexOf("=", index);
55
+ if (equalCharIndex === -1) {
56
+ break;
57
+ }
58
+ const pairEndIndex = findPairEndIndex(value, index, valueLength);
59
+ if (equalCharIndex > pairEndIndex) {
60
+ index = value.lastIndexOf(";", equalCharIndex - 1) + 1;
61
+ continue;
62
+ }
63
+ const key = sliceAndTrimOws(value, index, equalCharIndex);
64
+ if (key === ""
65
+ || key === "__proto__"
66
+ || key === "constructor"
67
+ || key === "prototype") {
68
+ index = pairEndIndex + 1;
69
+ continue;
70
+ }
71
+ if (result[key] === undefined) {
72
+ result[key] = decode(sliceAndTrimOws(value, equalCharIndex + 1, pairEndIndex));
73
+ }
74
+ index = pairEndIndex + 1;
75
+ } while (index < valueLength);
76
+ return result;
77
+ }
78
+
79
+ export { decode, defaultParser, findPairEndIndex, sliceAndTrimOws };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@duplojs/utils');
4
+ require('./hooks/index.cjs');
5
+ var metadata = require('./metadata.cjs');
6
+ var cookieHooks = require('./hooks/cookieHooks.cjs');
7
+
8
+ function cookiePlugin(params) {
9
+ return () => ({
10
+ name: "cookie-plugin",
11
+ hooksHubLifeCycle: [
12
+ {
13
+ beforeBuildRoute: (route) => {
14
+ if (utils.A.some(route.definition.metadata, metadata.IgnoreRouteCookieMetadata.is)) {
15
+ return route;
16
+ }
17
+ return {
18
+ ...route,
19
+ definition: {
20
+ ...route.definition,
21
+ hooks: [...route.definition.hooks, cookieHooks.cookieHooks(params)],
22
+ },
23
+ };
24
+ },
25
+ },
26
+ ],
27
+ });
28
+ }
29
+
30
+ exports.cookiePlugin = cookiePlugin;
@@ -0,0 +1,8 @@
1
+ import type { HubPlugin } from "../../core/hub";
2
+ import type { Parser } from "./parser";
3
+ import type { Serializer } from "./serialize";
4
+ export interface CookiePluginParams {
5
+ parser?: Parser;
6
+ serializer?: Serializer;
7
+ }
8
+ export declare function cookiePlugin(params?: CookiePluginParams): () => HubPlugin;
@@ -0,0 +1,28 @@
1
+ import { A } from '@duplojs/utils';
2
+ import './hooks/index.mjs';
3
+ import { IgnoreRouteCookieMetadata } from './metadata.mjs';
4
+ import { cookieHooks } from './hooks/cookieHooks.mjs';
5
+
6
+ function cookiePlugin(params) {
7
+ return () => ({
8
+ name: "cookie-plugin",
9
+ hooksHubLifeCycle: [
10
+ {
11
+ beforeBuildRoute: (route) => {
12
+ if (A.some(route.definition.metadata, IgnoreRouteCookieMetadata.is)) {
13
+ return route;
14
+ }
15
+ return {
16
+ ...route,
17
+ definition: {
18
+ ...route.definition,
19
+ hooks: [...route.definition.hooks, cookieHooks(params)],
20
+ },
21
+ };
22
+ },
23
+ },
24
+ ],
25
+ });
26
+ }
27
+
28
+ export { cookiePlugin };
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ var utils = require('@duplojs/utils');
4
+ var kind = require('./kind.cjs');
5
+
6
+ const nameRegex = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
7
+ const domainValueRegex = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
8
+ const pathValueRegex = /^[\u0020-\u003A\u003C-\u007E]*$/;
9
+ class SerializeCookieError extends utils.kindHeritage("serialize-cookie-error", kind.createCookiePluginKind("serialize-cookie-error"), Error) {
10
+ constructor(message) {
11
+ super({}, [message]);
12
+ }
13
+ }
14
+ function defaultSerializer(name, value, params) {
15
+ if (!nameRegex.test(name)) {
16
+ throw new SerializeCookieError(`argument name is invalid: ${name}`);
17
+ }
18
+ let encodedValue = "";
19
+ try {
20
+ encodedValue = encodeURIComponent(value);
21
+ }
22
+ catch {
23
+ throw new SerializeCookieError(`argument value is invalid: ${value}`);
24
+ }
25
+ let setCookie = `${name}=${encodedValue}`;
26
+ if (params?.maxAge !== undefined) {
27
+ if (!Number.isInteger(params.maxAge)) {
28
+ throw new SerializeCookieError(`param maxAge is invalid: ${params.maxAge}`);
29
+ }
30
+ setCookie += `; Max-Age=${params.maxAge}`;
31
+ }
32
+ if (params?.domain) {
33
+ if (!domainValueRegex.test(params.domain)) {
34
+ throw new SerializeCookieError(`param domain is invalid: ${params.domain}`);
35
+ }
36
+ setCookie += `; Domain=${params.domain}`;
37
+ }
38
+ if (params?.path) {
39
+ if (!pathValueRegex.test(params.path)) {
40
+ throw new SerializeCookieError(`param path is invalid: ${params.path}`);
41
+ }
42
+ setCookie += `; Path=${params.path}`;
43
+ }
44
+ if (params?.expires && params?.expireIn) {
45
+ throw new SerializeCookieError("params expires and expireIn are mutually exclusive");
46
+ }
47
+ if (params?.expires) {
48
+ setCookie += `; Expires=${params.expires.toUTCString()}`;
49
+ }
50
+ if (params?.expireIn !== undefined) {
51
+ setCookie += `; Expires=${utils.D.addTime(utils.D.now(), params.expireIn).toUTCString()}`;
52
+ }
53
+ if (params?.httpOnly) {
54
+ setCookie += "; HttpOnly";
55
+ }
56
+ if (params?.secure) {
57
+ setCookie += "; Secure";
58
+ }
59
+ if (params?.partitioned) {
60
+ setCookie += "; Partitioned";
61
+ }
62
+ if (params?.priority === "high") {
63
+ setCookie += "; Priority=High";
64
+ }
65
+ else if (params?.priority === "low") {
66
+ setCookie += "; Priority=Low";
67
+ }
68
+ else if (params?.priority === "medium") {
69
+ setCookie += "; Priority=Medium";
70
+ }
71
+ if (params?.sameSite === "strict") {
72
+ setCookie += "; SameSite=Strict";
73
+ }
74
+ else if (params?.sameSite === "lax") {
75
+ setCookie += "; SameSite=Lax";
76
+ }
77
+ else if (params?.sameSite === "none") {
78
+ setCookie += "; SameSite=None";
79
+ }
80
+ return setCookie;
81
+ }
82
+
83
+ exports.SerializeCookieError = SerializeCookieError;
84
+ exports.defaultSerializer = defaultSerializer;
@@ -0,0 +1,29 @@
1
+ import { D } from "@duplojs/utils";
2
+ declare const SerializeCookieError_base: new (params: {
3
+ "@DuplojsCookiePlugin/serialize-cookie-error"?: unknown;
4
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"@DuplojsCookiePlugin/serialize-cookie-error", unknown>, unknown> & import("@duplojs/utils").Kind<import("@duplojs/utils").KindDefinition<"serialize-cookie-error", unknown>, unknown> & Error;
5
+ export declare class SerializeCookieError extends SerializeCookieError_base {
6
+ constructor(message: string);
7
+ }
8
+ interface SerializerParamsBase {
9
+ maxAge?: number;
10
+ domain?: string;
11
+ path?: string;
12
+ httpOnly?: boolean;
13
+ secure?: boolean;
14
+ partitioned?: boolean;
15
+ priority?: "low" | "medium" | "high";
16
+ sameSite?: "lax" | "strict" | "none";
17
+ }
18
+ export interface SerializerParamsWithExpires extends SerializerParamsBase {
19
+ expires?: D.TheDate;
20
+ expireIn?: undefined;
21
+ }
22
+ export interface SerializerParamsWithExpireIn extends SerializerParamsBase {
23
+ expires?: undefined;
24
+ expireIn?: D.TheTime;
25
+ }
26
+ export type SerializerParams = SerializerParamsWithExpires | SerializerParamsWithExpireIn;
27
+ export declare function defaultSerializer(name: string, value: string, params?: SerializerParams): string;
28
+ export type Serializer = typeof defaultSerializer;
29
+ export {};
@@ -0,0 +1,81 @@
1
+ import { kindHeritage, D } from '@duplojs/utils';
2
+ import { createCookiePluginKind } from './kind.mjs';
3
+
4
+ const nameRegex = /^[!#$%&'*+\-.^_`|~A-Za-z0-9]+$/;
5
+ const domainValueRegex = /^([.]?[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)([.][a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)*$/i;
6
+ const pathValueRegex = /^[\u0020-\u003A\u003C-\u007E]*$/;
7
+ class SerializeCookieError extends kindHeritage("serialize-cookie-error", createCookiePluginKind("serialize-cookie-error"), Error) {
8
+ constructor(message) {
9
+ super({}, [message]);
10
+ }
11
+ }
12
+ function defaultSerializer(name, value, params) {
13
+ if (!nameRegex.test(name)) {
14
+ throw new SerializeCookieError(`argument name is invalid: ${name}`);
15
+ }
16
+ let encodedValue = "";
17
+ try {
18
+ encodedValue = encodeURIComponent(value);
19
+ }
20
+ catch {
21
+ throw new SerializeCookieError(`argument value is invalid: ${value}`);
22
+ }
23
+ let setCookie = `${name}=${encodedValue}`;
24
+ if (params?.maxAge !== undefined) {
25
+ if (!Number.isInteger(params.maxAge)) {
26
+ throw new SerializeCookieError(`param maxAge is invalid: ${params.maxAge}`);
27
+ }
28
+ setCookie += `; Max-Age=${params.maxAge}`;
29
+ }
30
+ if (params?.domain) {
31
+ if (!domainValueRegex.test(params.domain)) {
32
+ throw new SerializeCookieError(`param domain is invalid: ${params.domain}`);
33
+ }
34
+ setCookie += `; Domain=${params.domain}`;
35
+ }
36
+ if (params?.path) {
37
+ if (!pathValueRegex.test(params.path)) {
38
+ throw new SerializeCookieError(`param path is invalid: ${params.path}`);
39
+ }
40
+ setCookie += `; Path=${params.path}`;
41
+ }
42
+ if (params?.expires && params?.expireIn) {
43
+ throw new SerializeCookieError("params expires and expireIn are mutually exclusive");
44
+ }
45
+ if (params?.expires) {
46
+ setCookie += `; Expires=${params.expires.toUTCString()}`;
47
+ }
48
+ if (params?.expireIn !== undefined) {
49
+ setCookie += `; Expires=${D.addTime(D.now(), params.expireIn).toUTCString()}`;
50
+ }
51
+ if (params?.httpOnly) {
52
+ setCookie += "; HttpOnly";
53
+ }
54
+ if (params?.secure) {
55
+ setCookie += "; Secure";
56
+ }
57
+ if (params?.partitioned) {
58
+ setCookie += "; Partitioned";
59
+ }
60
+ if (params?.priority === "high") {
61
+ setCookie += "; Priority=High";
62
+ }
63
+ else if (params?.priority === "low") {
64
+ setCookie += "; Priority=Low";
65
+ }
66
+ else if (params?.priority === "medium") {
67
+ setCookie += "; Priority=Medium";
68
+ }
69
+ if (params?.sameSite === "strict") {
70
+ setCookie += "; SameSite=Strict";
71
+ }
72
+ else if (params?.sameSite === "lax") {
73
+ setCookie += "; SameSite=Lax";
74
+ }
75
+ else if (params?.sameSite === "none") {
76
+ setCookie += "; SameSite=None";
77
+ }
78
+ return setCookie;
79
+ }
80
+
81
+ export { SerializeCookieError, defaultSerializer };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const allowHeadersFunction = {
4
+ default(allowHeaders) {
5
+ return (request, response) => {
6
+ response.setHeader("access-control-allow-headers", allowHeaders);
7
+ };
8
+ },
9
+ };
10
+
11
+ exports.allowHeadersFunction = allowHeadersFunction;
@@ -0,0 +1,5 @@
1
+ import type { Request } from "../../../core/request";
2
+ import type { Response } from "../../../core/response";
3
+ export declare const allowHeadersFunction: {
4
+ default(allowHeaders: string): (request: Request, response: Response) => void;
5
+ };
@@ -0,0 +1,9 @@
1
+ const allowHeadersFunction = {
2
+ default(allowHeaders) {
3
+ return (request, response) => {
4
+ response.setHeader("access-control-allow-headers", allowHeaders);
5
+ };
6
+ },
7
+ };
8
+
9
+ export { allowHeadersFunction };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ const allowMethodsFunction = {
4
+ default(methods) {
5
+ return (request, response) => {
6
+ response.setHeader("access-control-allow-methods", methods);
7
+ };
8
+ },
9
+ isBool(allowMethods) {
10
+ return (request, response) => {
11
+ response.setHeader("access-control-allow-methods", allowMethods[request.path]);
12
+ };
13
+ },
14
+ };
15
+
16
+ exports.allowMethodsFunction = allowMethodsFunction;
@@ -0,0 +1,6 @@
1
+ import type { Request } from "../../../core/request";
2
+ import type { Response } from "../../../core/response";
3
+ export declare const allowMethodsFunction: {
4
+ default(methods: string): (request: Request, response: Response) => void;
5
+ isBool(allowMethods: Record<string, string>): (request: Request, response: Response) => void;
6
+ };
@@ -0,0 +1,14 @@
1
+ const allowMethodsFunction = {
2
+ default(methods) {
3
+ return (request, response) => {
4
+ response.setHeader("access-control-allow-methods", methods);
5
+ };
6
+ },
7
+ isBool(allowMethods) {
8
+ return (request, response) => {
9
+ response.setHeader("access-control-allow-methods", allowMethods[request.path]);
10
+ };
11
+ },
12
+ };
13
+
14
+ export { allowMethodsFunction };
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const allowOriginFunction = {
4
+ default(allowOrigin) {
5
+ return (request, response) => {
6
+ if (allowOrigin.test(request.origin)) {
7
+ response.setHeader("access-control-allow-origin", request.origin);
8
+ }
9
+ };
10
+ },
11
+ isFunction(allowOrigin) {
12
+ return async (request, response) => {
13
+ let result = allowOrigin(request.origin);
14
+ if (result instanceof Promise) {
15
+ result = await result;
16
+ }
17
+ if (result === true) {
18
+ response.setHeader("access-control-allow-origin", request.origin);
19
+ }
20
+ };
21
+ },
22
+ };
23
+
24
+ exports.allowOriginFunction = allowOriginFunction;
@@ -0,0 +1,7 @@
1
+ import type { Request } from "../../../core/request";
2
+ import type { Response } from "../../../core/response";
3
+ import type { MaybePromise } from "@duplojs/utils";
4
+ export declare const allowOriginFunction: {
5
+ default(allowOrigin: RegExp): (request: Request, response: Response) => void;
6
+ isFunction(allowOrigin: (origin: string) => MaybePromise<boolean>): (request: Request, response: Response) => Promise<void>;
7
+ };
@@ -0,0 +1,22 @@
1
+ const allowOriginFunction = {
2
+ default(allowOrigin) {
3
+ return (request, response) => {
4
+ if (allowOrigin.test(request.origin)) {
5
+ response.setHeader("access-control-allow-origin", request.origin);
6
+ }
7
+ };
8
+ },
9
+ isFunction(allowOrigin) {
10
+ return async (request, response) => {
11
+ let result = allowOrigin(request.origin);
12
+ if (result instanceof Promise) {
13
+ result = await result;
14
+ }
15
+ if (result === true) {
16
+ response.setHeader("access-control-allow-origin", request.origin);
17
+ }
18
+ };
19
+ },
20
+ };
21
+
22
+ export { allowOriginFunction };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const credentialsFunction = {
4
+ default() {
5
+ return (request, response) => {
6
+ response.setHeader("access-control-allow-credentials", "true");
7
+ };
8
+ },
9
+ };
10
+
11
+ exports.credentialsFunction = credentialsFunction;
@@ -0,0 +1,5 @@
1
+ import type { Request } from "../../../core/request";
2
+ import type { Response } from "../../../core/response";
3
+ export declare const credentialsFunction: {
4
+ default(): (request: Request, response: Response) => void;
5
+ };
@@ -0,0 +1,9 @@
1
+ const credentialsFunction = {
2
+ default() {
3
+ return (request, response) => {
4
+ response.setHeader("access-control-allow-credentials", "true");
5
+ };
6
+ },
7
+ };
8
+
9
+ export { credentialsFunction };
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const exposeHeadersFunction = {
4
+ default(exposeHeaders) {
5
+ return (request, response) => {
6
+ response.setHeader("access-control-expose-headers", exposeHeaders);
7
+ };
8
+ },
9
+ };
10
+
11
+ exports.exposeHeadersFunction = exposeHeadersFunction;
@@ -0,0 +1,5 @@
1
+ import type { Request } from "../../../core/request";
2
+ import type { Response } from "../../../core/response";
3
+ export declare const exposeHeadersFunction: {
4
+ default(exposeHeaders: string): (request: Request, response: Response) => void;
5
+ };
@@ -0,0 +1,9 @@
1
+ const exposeHeadersFunction = {
2
+ default(exposeHeaders) {
3
+ return (request, response) => {
4
+ response.setHeader("access-control-expose-headers", exposeHeaders);
5
+ };
6
+ },
7
+ };
8
+
9
+ export { exposeHeadersFunction };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var allowHeaders = require('./allowHeaders.cjs');
4
+ var allowMethods = require('./allowMethods.cjs');
5
+ var allowOrigin = require('./allowOrigin.cjs');
6
+ var credentials = require('./credentials.cjs');
7
+ var exposeHeaders = require('./exposeHeaders.cjs');
8
+ var maxAge = require('./maxAge.cjs');
9
+ var vary = require('./vary.cjs');
10
+
11
+
12
+
13
+ exports.allowHeadersFunction = allowHeaders.allowHeadersFunction;
14
+ exports.allowMethodsFunction = allowMethods.allowMethodsFunction;
15
+ exports.allowOriginFunction = allowOrigin.allowOriginFunction;
16
+ exports.credentialsFunction = credentials.credentialsFunction;
17
+ exports.exposeHeadersFunction = exposeHeaders.exposeHeadersFunction;
18
+ exports.maxAgeFunction = maxAge.maxAgeFunction;
19
+ exports.varyFunction = vary.varyFunction;
@@ -0,0 +1,7 @@
1
+ export * from "./allowHeaders";
2
+ export * from "./allowMethods";
3
+ export * from "./allowOrigin";
4
+ export * from "./credentials";
5
+ export * from "./exposeHeaders";
6
+ export * from "./maxAge";
7
+ export * from "./vary";
@@ -0,0 +1,7 @@
1
+ export { allowHeadersFunction } from './allowHeaders.mjs';
2
+ export { allowMethodsFunction } from './allowMethods.mjs';
3
+ export { allowOriginFunction } from './allowOrigin.mjs';
4
+ export { credentialsFunction } from './credentials.mjs';
5
+ export { exposeHeadersFunction } from './exposeHeaders.mjs';
6
+ export { maxAgeFunction } from './maxAge.mjs';
7
+ export { varyFunction } from './vary.mjs';
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ const maxAgeFunction = {
4
+ default(maxAge) {
5
+ return (request, response) => {
6
+ response.setHeader("access-control-max-age", maxAge);
7
+ };
8
+ },
9
+ };
10
+
11
+ exports.maxAgeFunction = maxAgeFunction;