@miqro/core 1.3.9 → 1.4.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.
Files changed (114) hide show
  1. package/README.md +0 -18
  2. package/dist/handler/app.d.ts +1 -2
  3. package/dist/handler/app.js +2 -3
  4. package/dist/handler/app.js.map +1 -1
  5. package/dist/handler/common/context.d.ts +2 -10
  6. package/dist/handler/common/context.js +4 -4
  7. package/dist/handler/common/context.js.map +1 -1
  8. package/dist/handler/common/index.js.map +1 -1
  9. package/dist/handler/common/router-utils.js.map +1 -1
  10. package/dist/handler/middleware/cookie.js +2 -2
  11. package/dist/handler/middleware/cookie.js.map +1 -1
  12. package/dist/handler/middleware/form.js.map +1 -1
  13. package/dist/handler/middleware/index.js.map +1 -1
  14. package/dist/handler/middleware/json.js.map +1 -1
  15. package/dist/handler/middleware/session.js.map +1 -1
  16. package/dist/handler/middleware/text.js.map +1 -1
  17. package/dist/index.d.ts +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/util/cli/index.d.ts +2 -1
  21. package/dist/util/cli/index.js.map +1 -1
  22. package/dist/util/error/configfilenotfound.js.map +1 -1
  23. package/dist/util/error/forbiddenerror.js.map +1 -1
  24. package/dist/util/error/notfound.js.map +1 -1
  25. package/dist/util/error/notimplemented.js.map +1 -1
  26. package/dist/util/error/parsererror.js.map +1 -1
  27. package/dist/util/error/unauthorizederror.js.map +1 -1
  28. package/dist/util/index.js +0 -2
  29. package/dist/util/index.js.map +1 -1
  30. package/dist/util/session/service.js +2 -2
  31. package/dist/util/session/service.js.map +1 -1
  32. package/package.json +12 -5
  33. package/src/handler/app.ts +2 -2
  34. package/src/handler/common/context.ts +5 -14
  35. package/src/handler/common/index.ts +1 -2
  36. package/src/handler/common/router-utils.ts +44 -51
  37. package/src/handler/middleware/cookie.ts +12 -12
  38. package/src/handler/middleware/form.ts +1 -1
  39. package/src/handler/middleware/index.ts +24 -24
  40. package/src/handler/middleware/json.ts +1 -1
  41. package/src/handler/middleware/session.ts +128 -128
  42. package/src/handler/middleware/text.ts +1 -1
  43. package/src/index.ts +0 -1
  44. package/src/util/cli/index.ts +2 -1
  45. package/src/util/error/configfilenotfound.ts +1 -1
  46. package/src/util/error/forbiddenerror.ts +1 -1
  47. package/src/util/error/notfound.ts +1 -1
  48. package/src/util/error/notimplemented.ts +1 -1
  49. package/src/util/error/parsererror.ts +1 -1
  50. package/src/util/error/unauthorizederror.ts +1 -1
  51. package/src/util/index.ts +0 -2
  52. package/src/util/parser/common.ts +1 -1
  53. package/src/util/parser/index.ts +0 -3
  54. package/src/util/request/index.ts +1 -1
  55. package/src/util/session/index.ts +1 -1
  56. package/src/util/session/service.ts +126 -126
  57. package/dist/test/common/app.d.ts +0 -3
  58. package/dist/test/common/app.js +0 -51
  59. package/dist/test/common/app.js.map +0 -1
  60. package/dist/test/common/common.d.ts +0 -6
  61. package/dist/test/common/common.js +0 -15
  62. package/dist/test/common/common.js.map +0 -1
  63. package/dist/test/common/index.d.ts +0 -3
  64. package/dist/test/common/index.js +0 -16
  65. package/dist/test/common/index.js.map +0 -1
  66. package/dist/test/common/runner.d.ts +0 -28
  67. package/dist/test/common/runner.js +0 -88
  68. package/dist/test/common/runner.js.map +0 -1
  69. package/dist/test/index.d.ts +0 -1
  70. package/dist/test/index.js +0 -14
  71. package/dist/test/index.js.map +0 -1
  72. package/dist/test/main.d.ts +0 -1
  73. package/dist/test/main.js +0 -31
  74. package/dist/test/main.js.map +0 -1
  75. package/dist/util/cookie/cookie.d.ts +0 -50
  76. package/dist/util/cookie/cookie.js +0 -168
  77. package/dist/util/cookie/cookie.js.map +0 -1
  78. package/dist/util/cookie/index.d.ts +0 -16
  79. package/dist/util/cookie/index.js +0 -9
  80. package/dist/util/cookie/index.js.map +0 -1
  81. package/dist/util/uuid/index.d.ts +0 -7
  82. package/dist/util/uuid/index.js +0 -8
  83. package/dist/util/uuid/index.js.map +0 -1
  84. package/dist/util/uuid/regex.d.ts +0 -2
  85. package/dist/util/uuid/regex.js +0 -5
  86. package/dist/util/uuid/regex.js.map +0 -1
  87. package/dist/util/uuid/rng.d.ts +0 -1
  88. package/dist/util/uuid/rng.js +0 -18
  89. package/dist/util/uuid/rng.js.map +0 -1
  90. package/dist/util/uuid/stringify.d.ts +0 -2
  91. package/dist/util/uuid/stringify.js +0 -50
  92. package/dist/util/uuid/stringify.js.map +0 -1
  93. package/dist/util/uuid/v4.d.ts +0 -5
  94. package/dist/util/uuid/v4.js +0 -27
  95. package/dist/util/uuid/v4.js.map +0 -1
  96. package/dist/util/uuid/validate.d.ts +0 -2
  97. package/dist/util/uuid/validate.js +0 -12
  98. package/dist/util/uuid/validate.js.map +0 -1
  99. package/src/test/common/app.ts +0 -45
  100. package/src/test/common/common.ts +0 -17
  101. package/src/test/common/index.ts +0 -3
  102. package/src/test/common/runner.ts +0 -116
  103. package/src/test/index.ts +0 -1
  104. package/src/test/main.ts +0 -32
  105. package/src/util/cookie/cookie.ts +0 -207
  106. package/src/util/cookie/index.ts +0 -6
  107. package/src/util/uuid/index.ts +0 -5
  108. package/src/util/uuid/regex.ts +0 -2
  109. package/src/util/uuid/rng.ts +0 -14
  110. package/src/util/uuid/stringify.ts +0 -53
  111. package/src/util/uuid/v4.ts +0 -30
  112. package/src/util/uuid/validate.ts +0 -8
  113. package/test.md +0 -0
  114. package/tsconfig-test.json +0 -13
@@ -4,7 +4,7 @@ import { checkEnvVariables } from "../config";
4
4
  import { UnAuthorizedError } from "../error";
5
5
  import { request, RequestOptions, RequestResponse } from "../request";
6
6
  import { parse } from "../parser";
7
- import { COOKIE } from "../cookie";
7
+ import { parse as cookieParse } from "cookie";
8
8
 
9
9
  const DEFAULT_TOKEN_LOCATION = "header";
10
10
  const DEFAULT_TOKEN_HEADER = "Authorization";
@@ -12,143 +12,143 @@ const DEFAULT_TOKEN_QUERY = "token";
12
12
  const DEFAULT_TOKEN_COOKIE = "Authorization";
13
13
 
14
14
  export interface VerifyTokenService {
15
- verify(args: { token: string; ctx: Context }): Promise<Session | null>;
15
+ verify(args: { token: string; ctx: Context }): Promise<Session | null>;
16
16
  }
17
17
 
18
18
  export interface VerifyEndpointServiceOptions {
19
- url: string;
20
- method: string;
21
- tokenLocation: "header" | "query" | "cookie";
22
- tokenLocationName: string | ((ctx: Context) => Promise<string>);
19
+ url: string;
20
+ method: string;
21
+ tokenLocation: "header" | "query" | "cookie";
22
+ tokenLocationName: string | ((ctx: Context) => Promise<string>);
23
23
  }
24
24
 
25
25
  export class VerifyEndpointService implements VerifyTokenService {
26
26
 
27
- protected options: VerifyEndpointServiceOptions;
27
+ protected options: VerifyEndpointServiceOptions;
28
28
 
29
- constructor(options?: VerifyEndpointServiceOptions) {
30
- if (!options) {
31
- const [url, method] = checkEnvVariables(["TOKEN_VERIFY_ENDPOINT", "TOKEN_VERIFY_ENDPOINT_METHOD"]);
32
- const [tokenVerifyLocation] = checkEnvVariables(["TOKEN_VERIFY_LOCATION"], [DEFAULT_TOKEN_LOCATION]);
33
- let tokenLocationName;
34
- switch (tokenVerifyLocation) {
35
- case "header":
36
- tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
37
- break;
38
- case "query":
39
- tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
40
- break;
41
- case "cookie":
42
- tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
43
- break;
44
- default:
45
- throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header or query)`);
46
- }
47
- this.options = {
48
- url, method,
49
- tokenLocation: tokenVerifyLocation,
50
- tokenLocationName
51
- }
52
- } else {
53
- this.options = parse("options", options as any, [
54
- { name: "url", required: true, type: "string", stringMinLength: 1 },
55
- { name: "method", required: true, type: "string", stringMinLength: 1 },
56
- { name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
57
- { name: "tokenLocationName", required: true, type: "any" }
58
- ], "no_extra") as any;
59
- }
29
+ constructor(options?: VerifyEndpointServiceOptions) {
30
+ if (!options) {
31
+ const [url, method] = checkEnvVariables(["TOKEN_VERIFY_ENDPOINT", "TOKEN_VERIFY_ENDPOINT_METHOD"]);
32
+ const [tokenVerifyLocation] = checkEnvVariables(["TOKEN_VERIFY_LOCATION"], [DEFAULT_TOKEN_LOCATION]);
33
+ let tokenLocationName;
34
+ switch (tokenVerifyLocation) {
35
+ case "header":
36
+ tokenLocationName = checkEnvVariables(["TOKEN_HEADER"], [DEFAULT_TOKEN_HEADER])[0];
37
+ break;
38
+ case "query":
39
+ tokenLocationName = checkEnvVariables(["TOKEN_QUERY"], [DEFAULT_TOKEN_QUERY])[0];
40
+ break;
41
+ case "cookie":
42
+ tokenLocationName = checkEnvVariables(["TOKEN_COOKIE"], [DEFAULT_TOKEN_COOKIE])[0];
43
+ break;
44
+ default:
45
+ throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header or query)`);
46
+ }
47
+ this.options = {
48
+ url, method,
49
+ tokenLocation: tokenVerifyLocation,
50
+ tokenLocationName
51
+ }
52
+ } else {
53
+ this.options = parse("options", options as any, [
54
+ { name: "url", required: true, type: "string", stringMinLength: 1 },
55
+ { name: "method", required: true, type: "string", stringMinLength: 1 },
56
+ { name: "tokenLocation", required: true, type: "enum", enumValues: ["header", "query", "cookie"] },
57
+ { name: "tokenLocationName", required: true, type: "any" }
58
+ ], "no_extra") as any;
60
59
  }
60
+ }
61
61
 
62
- public async verify({ token, ctx }: { token: string; ctx: Context }): Promise<Session | null> {
63
- try {
64
- let response = null;
65
- const tokenVerifyLocation = this.options.tokenLocation;
66
- const url = this.options.url;
67
- const method = this.options.method;
68
- switch (tokenVerifyLocation) {
69
- case "header":
70
- const tokenHeaderLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
71
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_HEADER=[${tokenHeaderLocation}]`);
72
- response = await this.getResponse({
73
- url,
74
- headers: {
75
- [tokenHeaderLocation]: token
76
- },
77
- method
78
- }, ctx);
79
- break;
80
- case "query":
81
- const tokenQueryLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
82
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_QUERY=[${tokenQueryLocation}]`);
83
- response = await this.getResponse({
84
- url,
85
- query: {
86
- [tokenQueryLocation]: token
87
- },
88
- method
89
- }, ctx);
90
- break;
91
- case "cookie":
92
- const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
93
- ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_COOKIE=[${tokenCookieLocation}]`);
94
- response = await this.getResponse({
95
- url,
96
- method,
97
- headers: {
98
- Cookie: `${tokenCookieLocation}=${token}; Path=/; HttpOnly;`
99
- }
100
- }, ctx);
101
- break;
102
- default:
103
- throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
62
+ public async verify({ token, ctx }: { token: string; ctx: Context }): Promise<Session | null> {
63
+ try {
64
+ let response = null;
65
+ const tokenVerifyLocation = this.options.tokenLocation;
66
+ const url = this.options.url;
67
+ const method = this.options.method;
68
+ switch (tokenVerifyLocation) {
69
+ case "header":
70
+ const tokenHeaderLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
71
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_HEADER=[${tokenHeaderLocation}]`);
72
+ response = await this.getResponse({
73
+ url,
74
+ headers: {
75
+ [tokenHeaderLocation]: token
76
+ },
77
+ method
78
+ }, ctx);
79
+ break;
80
+ case "query":
81
+ const tokenQueryLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
82
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_QUERY=[${tokenQueryLocation}]`);
83
+ response = await this.getResponse({
84
+ url,
85
+ query: {
86
+ [tokenQueryLocation]: token
87
+ },
88
+ method
89
+ }, ctx);
90
+ break;
91
+ case "cookie":
92
+ const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
93
+ ctx.logger.trace(`verifying [${token}] on TOKEN_VERIFY_ENDPOINT=[${process.env.TOKEN_VERIFY_ENDPOINT}] TOKEN_COOKIE=[${tokenCookieLocation}]`);
94
+ response = await this.getResponse({
95
+ url,
96
+ method,
97
+ headers: {
98
+ Cookie: `${tokenCookieLocation}=${token}; Path=/; HttpOnly;`
104
99
  }
105
- if (response) {
106
- const session = await this.decodeSession(response, token, ctx);
107
- if (!this.checkSession(session, ctx)) {
108
- ctx.logger.warn(`unauthorized token not valid [${token}]`);
109
- return null;
110
- } else {
111
- ctx.logger.trace("token [%s]authorized!", token);
100
+ }, ctx);
101
+ break;
102
+ default:
103
+ throw new Error(`TOKEN_VERIFY_LOCATION=${tokenVerifyLocation} not supported use (header, query or cookie)`);
104
+ }
105
+ if (response) {
106
+ const session = await this.decodeSession(response, token, ctx);
107
+ if (!this.checkSession(session, ctx)) {
108
+ ctx.logger.warn(`unauthorized token not valid [${token}]`);
109
+ return null;
110
+ } else {
111
+ ctx.logger.trace("token [%s]authorized!", token);
112
112
 
113
- if (tokenVerifyLocation === "cookie" && response.headers["set-cookie"]) {
114
- const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
115
- const cookies = response.headers["set-cookie"].map(c => COOKIE.parse(c)).filter(c => c[tokenCookieLocation] !== undefined);
116
- if (cookies.length === 1) {
117
- const value = cookies[0][tokenCookieLocation];
118
- if (value) {
119
- session.token = value; // replace token because token update via set-cookie
120
- }
121
- }
122
- }
123
- return {
124
- token,
125
- ...session
126
- } as Session;
127
- }
128
- } else {
129
- ctx.logger.warn(`unauthorized token not valid [${token}]`);
130
- return null;
113
+ if (tokenVerifyLocation === "cookie" && response.headers["set-cookie"]) {
114
+ const tokenCookieLocation = typeof this.options.tokenLocationName === "string" ? this.options.tokenLocationName : await this.options.tokenLocationName(ctx);
115
+ const cookies = response.headers["set-cookie"].map(c => cookieParse(c)).filter(c => c[tokenCookieLocation] !== undefined);
116
+ if (cookies.length === 1) {
117
+ const value = cookies[0][tokenCookieLocation];
118
+ if (value) {
119
+ session.token = value; // replace token because token update via set-cookie
120
+ }
131
121
  }
132
- } catch (e: any) {
133
- throw new UnAuthorizedError(`Fail to authenticate token! error verifying [${token}] [${e.status}][${e.config ? e.config.url : ""}]`);
122
+ }
123
+ return {
124
+ token,
125
+ ...session
126
+ } as Session;
134
127
  }
128
+ } else {
129
+ ctx.logger.warn(`unauthorized token not valid [${token}]`);
130
+ return null;
131
+ }
132
+ } catch (e: any) {
133
+ throw new UnAuthorizedError(`Fail to authenticate token! error verifying [${token}] [${e.status}][${e.config ? e.config.url : ""}]`);
135
134
  }
136
- /* eslint-disable @typescript-eslint/no-unused-vars */
137
- protected async getResponse(config: RequestOptions, ctx?: Context): Promise<RequestResponse> {
138
- return request(config);
139
- }
140
- /* eslint-disable @typescript-eslint/no-unused-vars */
141
- protected checkSession(session: NoTokenSession, ctx?: Context): boolean {
142
- parse("session", session, [
143
- { name: "username", required: true, type: "string" },
144
- { name: "account", required: true, type: "string" },
145
- { name: "groups", required: true, type: "array", arrayType: "string" }
146
- ], "add_extra");
147
- return true;
148
- }
149
- /* eslint-disable @typescript-eslint/no-unused-vars */
150
- protected async decodeSession(response: RequestResponse, token: string, ctx?: Context): Promise<NoTokenSession> {
151
- const session = response.data;
152
- return session as NoTokenSession;
153
- }
154
- }
135
+ }
136
+ /* eslint-disable @typescript-eslint/no-unused-vars */
137
+ protected async getResponse(config: RequestOptions, ctx?: Context): Promise<RequestResponse> {
138
+ return request(config);
139
+ }
140
+ /* eslint-disable @typescript-eslint/no-unused-vars */
141
+ protected checkSession(session: NoTokenSession, ctx?: Context): boolean {
142
+ parse("session", session, [
143
+ { name: "username", required: true, type: "string" },
144
+ { name: "account", required: true, type: "string" },
145
+ { name: "groups", required: true, type: "array", arrayType: "string" }
146
+ ], "add_extra");
147
+ return true;
148
+ }
149
+ /* eslint-disable @typescript-eslint/no-unused-vars */
150
+ protected async decodeSession(response: RequestResponse, token: string, ctx?: Context): Promise<NoTokenSession> {
151
+ const session = response.data;
152
+ return session as NoTokenSession;
153
+ }
154
+ }
@@ -1,3 +0,0 @@
1
- import { RequestOptions, RequestResponse } from "../../util/request";
2
- import { App } from "../../handler/app";
3
- export declare const TestHelper: (app: App, options: RequestOptions, cb?: ((response: RequestResponse) => void) | undefined) => Promise<RequestResponse>;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TestHelper = void 0;
4
- const request_1 = require("../../util/request");
5
- const fs_1 = require("fs");
6
- const http_1 = require("http");
7
- const TestHelper = async (app, options, cb) => {
8
- const unixSocket = `/tmp/socket.test.helper${Date.now()}`;
9
- if ((0, fs_1.existsSync)(unixSocket)) {
10
- (0, fs_1.unlinkSync)(unixSocket);
11
- }
12
- const server = (0, http_1.createServer)(app.listener);
13
- return new Promise((resolve, reject) => {
14
- server.listen(unixSocket, () => {
15
- (0, request_1.request)({
16
- disableThrow: true,
17
- ...options,
18
- socketPath: unixSocket
19
- }).then((response) => {
20
- server.close(() => {
21
- if (cb) {
22
- try {
23
- cb(response);
24
- }
25
- catch (ee) {
26
- reject(ee);
27
- }
28
- }
29
- resolve(response);
30
- });
31
- }).catch((e) => {
32
- server.close(() => {
33
- if (cb) {
34
- try {
35
- cb(e);
36
- }
37
- catch (ee) {
38
- reject(ee);
39
- }
40
- resolve(undefined);
41
- }
42
- else {
43
- reject(e);
44
- }
45
- });
46
- });
47
- });
48
- });
49
- };
50
- exports.TestHelper = TestHelper;
51
- //# sourceMappingURL=app.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app.js","sourceRoot":"","sources":["../../../src/test/common/app.ts"],"names":[],"mappings":";;;AAAA,gDAA8E;AAE9E,2BAA4C;AAC5C,+BAAoC;AAE7B,MAAM,UAAU,GAAG,KAAK,EAAE,GAAQ,EAAE,OAAuB,EAAE,EAAwC,EAA4B,EAAE;IACxI,MAAM,UAAU,GAAG,0BAA0B,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;IAC1D,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;QAC1B,IAAA,eAAU,EAAC,UAAU,CAAC,CAAC;KACxB;IACD,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,OAAO,IAAI,OAAO,CAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACtD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE;YAC7B,IAAA,iBAAO,EAAC;gBACN,YAAY,EAAE,IAAI;gBAClB,GAAG,OAAO;gBACV,UAAU,EAAE,UAAU;aACvB,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACnB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;oBAChB,IAAI,EAAE,EAAE;wBACN,IAAI;4BACF,EAAE,CAAC,QAAQ,CAAC,CAAC;yBACd;wBAAC,OAAO,EAAE,EAAE;4BACX,MAAM,CAAC,EAAE,CAAC,CAAC;yBACZ;qBACF;oBACD,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACpB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE;gBAClB,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;oBAChB,IAAI,EAAE,EAAE;wBACN,IAAI;4BACF,EAAE,CAAC,CAAQ,CAAC,CAAC;yBACd;wBAAC,OAAO,EAAE,EAAE;4BACX,MAAM,CAAC,EAAE,CAAC,CAAC;yBACZ;wBACD,OAAO,CAAC,SAAgB,CAAC,CAAC;qBAC3B;yBAAM;wBACL,MAAM,CAAC,CAAC,CAAC,CAAC;qBACX;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAA;AAvCY,QAAA,UAAU,cAuCtB"}
@@ -1,6 +0,0 @@
1
- export declare type Callback<T = any> = (...args: any[]) => T;
2
- export interface FakeCallback<T = any> extends Callback<T> {
3
- callCount: number;
4
- callArgs: T[];
5
- }
6
- export declare const fake: (cb: Callback) => FakeCallback;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fake = void 0;
4
- const fake = (cb) => {
5
- const ret = (...args) => {
6
- ret.callCount++;
7
- ret.callArgs.push(args);
8
- return cb(...args);
9
- };
10
- ret.callCount = 0;
11
- ret.callArgs = [];
12
- return ret;
13
- };
14
- exports.fake = fake;
15
- //# sourceMappingURL=common.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/test/common/common.ts"],"names":[],"mappings":";;;AAOO,MAAM,IAAI,GAAG,CAAC,EAAY,EAAgB,EAAE;IACjD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;QAC7B,GAAG,CAAC,SAAS,EAAE,CAAC;QAChB,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;IACrB,CAAC,CAAC;IACF,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC;IAClB,GAAG,CAAC,QAAQ,GAAG,EAAS,CAAC;IACzB,OAAO,GAAG,CAAC;AACb,CAAC,CAAA;AATY,QAAA,IAAI,QAShB"}
@@ -1,3 +0,0 @@
1
- export * from "./common";
2
- export * from "./app";
3
- export * from "./runner";
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./common"), exports);
14
- __exportStar(require("./app"), exports);
15
- __exportStar(require("./runner"), exports);
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/test/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,wCAAsB;AACtB,2CAAyB"}
@@ -1,28 +0,0 @@
1
- import { Console } from "console";
2
- import { Logger } from "../../util";
3
- export declare type TestFunction = () => void | Promise<void>;
4
- export declare const getTestCount: () => number;
5
- export declare const it: (title: string, impl: TestFunction, options?: {
6
- category?: string | undefined;
7
- timeout?: number | undefined;
8
- before?: TestFunction | undefined;
9
- after?: TestFunction | undefined;
10
- } | undefined, logger?: Logger | Console) => void;
11
- export declare const runTests: (title?: string | string[] | undefined, logger?: Logger | Console) => Promise<{
12
- passed: number;
13
- total: number;
14
- ignored: number;
15
- failed: {
16
- error: any;
17
- fullName: string;
18
- }[];
19
- }>;
20
- export declare const runTestModules: (modules: string[], title?: string | string[] | undefined, logger?: Logger | Console) => Promise<{
21
- passed: number;
22
- total: number;
23
- ignored: number;
24
- failed: {
25
- error: any;
26
- fullName: string;
27
- }[];
28
- }>;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runTestModules = exports.runTests = exports.it = exports.getTestCount = void 0;
4
- const console_1 = require("console");
5
- const util_1 = require("util");
6
- const DEFAULT_TIMEOUT = 2000;
7
- const tests = [];
8
- const getTestCount = () => tests.length;
9
- exports.getTestCount = getTestCount;
10
- const it = (title, impl, options, logger = new console_1.Console(process.stdout)) => {
11
- const category = options && options.category ? options.category : undefined;
12
- const fullName = `${category ? `${category} [` : ""}${title}${category ? "]" : ""}`;
13
- tests.push({
14
- run: () => new Promise((resolve, reject) => {
15
- const timeoutMS = options && options.timeout ? options.timeout : DEFAULT_TIMEOUT;
16
- const timeout = setTimeout(() => {
17
- reject(new Error((0, util_1.format)("%s failed\x1b[31m\n%s timeout %o\x1b", fullName, fullName, timeoutMS)));
18
- }, timeoutMS);
19
- try {
20
- (async () => {
21
- if (options && options.before) {
22
- await options.before();
23
- }
24
- const startMS = Date.now();
25
- await impl();
26
- const took = Date.now() - startMS;
27
- if (options && options.after) {
28
- await options.after();
29
- }
30
- return took;
31
- })().then((took) => {
32
- clearTimeout(timeout);
33
- logger.log("\x1b[32mpassed %s (took %sms)\x1b[0m", fullName, took);
34
- resolve();
35
- }).catch(e => {
36
- clearTimeout(timeout);
37
- reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
38
- });
39
- }
40
- catch (e) {
41
- clearTimeout(timeout);
42
- reject(new Error((0, util_1.format)("%s failed\n%s finished with errors %o", fullName, fullName, e)));
43
- }
44
- }), title,
45
- category,
46
- fullName
47
- });
48
- };
49
- exports.it = it;
50
- const runTests = async (title, logger = new console_1.Console(process.stdout)) => {
51
- const titles = title ? title instanceof Array ? title : [title] : [undefined];
52
- const ret = {
53
- total: tests.length,
54
- ignored: 0,
55
- passed: 0,
56
- failed: []
57
- };
58
- for (const test of tests) {
59
- for (const title of titles) {
60
- if (title && test.fullName.indexOf(title) !== -1 || !title) {
61
- try {
62
- await test.run();
63
- ret.passed++;
64
- }
65
- catch (e) {
66
- logger.error("\x1b[31m%s\x1b[0m", e);
67
- ret.failed.push({
68
- error: e,
69
- fullName: test.fullName
70
- });
71
- }
72
- }
73
- else {
74
- ret.ignored++;
75
- }
76
- }
77
- }
78
- return ret;
79
- };
80
- exports.runTests = runTests;
81
- const runTestModules = async (modules, title, logger = new console_1.Console(process.stdout)) => {
82
- for (const path of modules) {
83
- require(path);
84
- }
85
- return await (0, exports.runTests)(title, logger);
86
- };
87
- exports.runTestModules = runTestModules;
88
- //# sourceMappingURL=runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"runner.js","sourceRoot":"","sources":["../../../src/test/common/runner.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,+BAA8B;AAI9B,MAAM,eAAe,GAAG,IAAI,CAAC;AAI7B,MAAM,KAAK,GAAW,EAAE,CAAC;AAElB,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC;AAAlC,QAAA,YAAY,gBAAsB;AAExC,MAAM,EAAE,GAAG,CAAC,KAAa,EAAE,IAAkB,EAAE,OAKrD,EAAE,SAA2B,IAAI,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAQ,EAAE;IACjE,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5E,MAAM,QAAQ,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpF,KAAK,CAAC,IAAI,CAA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d,KAAK,EAAE,CAAC;wBACR,QAAQ,EAAE,IAAI,CAAC,QAAQ;qBACxB,CAAC,CAAA;iBACH;aACF;iBAAM;gBACL,GAAG,CAAC,OAAO,EAAE,CAAC;aACf;SACF;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AA3CW,QAAA,QAAQ,YA2CnB;AAEK,MAAM,cAAc,GAAG,KAAK,EAAE,OAAiB,EAAE,KAAyB,EAAE,SAA2B,IAAI,iBAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAQtI,EAAE;IACH,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;QAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;KACf;IACD,OAAO,MAAM,IAAA,gBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAA;AAbY,QAAA,cAAc,kBAa1B"}
@@ -1 +0,0 @@
1
- export * from "./common";
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./common"), exports);
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB"}
@@ -1 +0,0 @@
1
- export {};
package/dist/test/main.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const util_1 = require("../util");
5
- const common_1 = require("./common");
6
- const startMS = Date.now();
7
- const args = util_1.CLIUtil.extractFlags(process.argv.slice(2));
8
- const name = args.flags.n ? args.flags.n : "all";
9
- const logger = console;
10
- const modules = args.cmds;
11
- (0, common_1.runTestModules)(modules.map(m => (0, path_1.resolve)(process.cwd(), m)), typeof name === "string" && name.toLowerCase() === "all" ? undefined : name, console).then((ret) => {
12
- const took = Date.now() - startMS;
13
- logger.log("");
14
- logger.log("");
15
- logger.log(ret.passed + " tests pased");
16
- logger.log(ret.failed.length + " failed");
17
- logger.log("took " + took + "ms");
18
- logger.log("");
19
- logger.log("");
20
- if (ret.failed.length > 0) {
21
- ret.failed.forEach(e => {
22
- logger.error("\x1b[31m%s\x1b[0m", e.fullName);
23
- logger.error("\x1b[31m%s\x1b[0m", e.error);
24
- });
25
- process.exit(1);
26
- }
27
- }).catch(e => {
28
- logger.error(e);
29
- process.exit(1);
30
- });
31
- //# sourceMappingURL=main.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/test/main.ts"],"names":[],"mappings":";;AAAA,+BAA+B;AAC/B,kCAA6C;AAC7C,qCAA0C;AAE1C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;AAE3B,MAAM,IAAI,GAAG,cAAO,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACzD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAEjD,MAAM,MAAM,GAAG,OAAO,CAAC;AAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;AAC1B,IAAA,uBAAc,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,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/*!
2
- * cookie
3
- * Copyright(c) 2012-2014 Roman Shtylman
4
- * Copyright(c) 2015 Douglas Christopher Wilson
5
- * MIT Licensed
6
- */
7
- /// <reference types="node" />
8
- /**
9
- * Module exports.
10
- * @public
11
- */
12
- /**
13
- * Parse a cookie header.
14
- *
15
- * Parse the given cookie header string into an object
16
- * The object has the various cookies as keys(names) => values
17
- *
18
- * @param {string} str
19
- * @param {object} [options]
20
- * @return {object}
21
- * @public
22
- */
23
- export declare const parse: (str: string, options?: {
24
- decode?: ((value: string) => string) | undefined;
25
- } | undefined) => NodeJS.Dict<string>;
26
- /**
27
- * Serialize data into a cookie header.
28
- *
29
- * Serialize the a name value pair into a cookie string suitable for
30
- * http headers. An optional options object specified cookie parameters.
31
- *
32
- * serialize('foo', 'bar', { httpOnly: true })
33
- * => "foo=bar; httpOnly"
34
- *
35
- * @param {string} name
36
- * @param {string} val
37
- * @param {object} [options]
38
- * @return {string}
39
- * @public
40
- */
41
- export declare const serialize: (name: string, val: string, options?: {
42
- encode?: ((uriComponent: string | number | boolean) => string) | undefined;
43
- maxAge?: number | null | undefined;
44
- domain?: string | undefined;
45
- httpOnly?: boolean | undefined;
46
- secure?: boolean | undefined;
47
- path?: string | undefined;
48
- expires?: Date | undefined;
49
- sameSite?: true | "lax" | "strict" | "none" | undefined;
50
- } | undefined) => string;