@websolutespa/bom-mixer-store 3.1.0 → 3.1.1
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/CHANGELOG.md +2 -0
- package/dist/exports/proxy.js.map +1 -1
- package/package.json +8 -8
- package/src/__tests/session.test.ts +60 -60
- package/src/proxy/proxy.service.ts +22 -22
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","names":[],"sources":["../../src/proxy/proxy.service.ts"],"sourcesContent":["import mime from 'mime';\nimport { NextRequest } from 'next/server';\n\nconst API_BASE = process.env.NEXT_PUBLIC_API || '/api';\n\nexport function isStaticRequest(request: NextRequest) {\n const { pathname } = request.nextUrl;\n const isStatic = mime.getType(pathname) !== null;\n return isStatic;\n}\n\nexport function isNextRequest(request: NextRequest) {\n const { pathname } = request.nextUrl;\n const isNext = pathname.startsWith('/_next');\n return isNext;\n}\n\nexport function isApiRequest(request: NextRequest) {\n const { pathname } = request.nextUrl;\n const isApi = pathname.startsWith(API_BASE);\n return isApi;\n}\n"],"mappings":";;AAGA,MAAM,WAAW,QAAQ,IAAI,mBAAmB;AAEhD,SAAgB,gBAAgB,SAAsB;CACpD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADiB,KAAK,QAAQ,SAAS,KAAK;;AAI9C,SAAgB,cAAc,SAAsB;CAClD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADe,SAAS,WAAW,SAAS;;AAI9C,SAAgB,aAAa,SAAsB;CACjD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADc,SAAS,WAAW,SAAS"}
|
|
1
|
+
{"version":3,"file":"proxy.js","names":[],"sources":["../../src/proxy/proxy.service.ts"],"sourcesContent":["import mime from 'mime';\r\nimport { NextRequest } from 'next/server';\r\n\r\nconst API_BASE = process.env.NEXT_PUBLIC_API || '/api';\r\n\r\nexport function isStaticRequest(request: NextRequest) {\r\n const { pathname } = request.nextUrl;\r\n const isStatic = mime.getType(pathname) !== null;\r\n return isStatic;\r\n}\r\n\r\nexport function isNextRequest(request: NextRequest) {\r\n const { pathname } = request.nextUrl;\r\n const isNext = pathname.startsWith('/_next');\r\n return isNext;\r\n}\r\n\r\nexport function isApiRequest(request: NextRequest) {\r\n const { pathname } = request.nextUrl;\r\n const isApi = pathname.startsWith(API_BASE);\r\n return isApi;\r\n}\r\n"],"mappings":";;AAGA,MAAM,WAAW,QAAQ,IAAI,mBAAmB;AAEhD,SAAgB,gBAAgB,SAAsB;CACpD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADiB,KAAK,QAAQ,SAAS,KAAK;;AAI9C,SAAgB,cAAc,SAAsB;CAClD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADe,SAAS,WAAW,SAAS;;AAI9C,SAAgB,aAAa,SAAsB;CACjD,MAAM,EAAE,aAAa,QAAQ;AAE7B,QADc,SAAS,WAAW,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websolutespa/bom-mixer-store",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Mixer Store module of the BOM Repository",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bom",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@vitest/coverage-istanbul": "5.0.5",
|
|
38
|
-
"@websolutespa/bom-cli": "^3.1.
|
|
39
|
-
"@websolutespa/bom-mixer-models": "^3.1.
|
|
40
|
-
"@websolutespa/eslint-config": "^3.1.
|
|
41
|
-
"@websolutespa/test": "^3.1.
|
|
42
|
-
"@websolutespa/tsconfig": "^3.1.
|
|
38
|
+
"@websolutespa/bom-cli": "^3.1.1",
|
|
39
|
+
"@websolutespa/bom-mixer-models": "^3.1.1",
|
|
40
|
+
"@websolutespa/eslint-config": "^3.1.1",
|
|
41
|
+
"@websolutespa/test": "^3.1.1",
|
|
42
|
+
"@websolutespa/tsconfig": "^3.1.1",
|
|
43
43
|
"eslint": "10.13.0",
|
|
44
44
|
"npm-run-all": "4.1.5",
|
|
45
45
|
"payload": "3.91.0",
|
|
@@ -97,7 +97,6 @@
|
|
|
97
97
|
},
|
|
98
98
|
"types": "./dist/index.d.ts",
|
|
99
99
|
"main": "./dist/index.js",
|
|
100
|
-
"source": "./src/index.ts",
|
|
101
100
|
"exports": {
|
|
102
101
|
".": {
|
|
103
102
|
"import": "./dist/index.js",
|
|
@@ -114,5 +113,6 @@
|
|
|
114
113
|
"types": "./dist/exports/server.d.ts",
|
|
115
114
|
"default": "./dist/exports/server.js"
|
|
116
115
|
}
|
|
117
|
-
}
|
|
116
|
+
},
|
|
117
|
+
"source": "./src/index.ts"
|
|
118
118
|
}
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
-
import { Socket } from 'net';
|
|
3
|
-
import type { NextRequest } from 'next/server';
|
|
4
|
-
import { describe, expect, it } from 'vitest';
|
|
5
|
-
import { isStaticRequest } from '../proxy/proxy.service';
|
|
6
|
-
import { getSession, getSessionToken } from '../session/session.service';
|
|
7
|
-
|
|
8
|
-
function createRequest(cookie?: string) {
|
|
9
|
-
const request = new IncomingMessage(new Socket()) as IncomingMessage & { cookies: Record<string, string> };
|
|
10
|
-
if (cookie) {
|
|
11
|
-
request.headers.cookie = cookie;
|
|
12
|
-
}
|
|
13
|
-
request.cookies = {};
|
|
14
|
-
return request;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getCookie(response: ServerResponse) {
|
|
18
|
-
const header = response.getHeader('set-cookie');
|
|
19
|
-
const value = Array.isArray(header) ? header[0] : String(header);
|
|
20
|
-
return value.split(';')[0];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('session (iron-session)', () => {
|
|
24
|
-
it('seals the session in a cookie and reads it back on the next request', async () => {
|
|
25
|
-
const response = new ServerResponse(createRequest());
|
|
26
|
-
const session = await getSession<{ token?: string; exp?: number }>(createRequest(), response);
|
|
27
|
-
session.token = 'token';
|
|
28
|
-
session.exp = Math.floor(Date.now() / 1000) + 60;
|
|
29
|
-
await session.save();
|
|
30
|
-
|
|
31
|
-
const cookie = getCookie(response);
|
|
32
|
-
expect(cookie.startsWith('websolutespa-next-js=')).toBe(true);
|
|
33
|
-
const token = await getSessionToken(createRequest(cookie), new ServerResponse(createRequest()));
|
|
34
|
-
expect(token).toBe('token');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('clears an expired token', async () => {
|
|
38
|
-
const response = new ServerResponse(createRequest());
|
|
39
|
-
const session = await getSession<{ token?: string; exp?: number }>(createRequest(), response);
|
|
40
|
-
session.token = 'token';
|
|
41
|
-
session.exp = Math.floor(Date.now() / 1000) - 60;
|
|
42
|
-
await session.save();
|
|
43
|
-
|
|
44
|
-
const token = await getSessionToken(createRequest(getCookie(response)), new ServerResponse(createRequest()));
|
|
45
|
-
expect(token).toBeUndefined();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('isStaticRequest (mime)', () => {
|
|
50
|
-
const request = (pathname: string) => ({ nextUrl: { pathname } }) as NextRequest;
|
|
51
|
-
|
|
52
|
-
it('detects files by extension', () => {
|
|
53
|
-
expect(isStaticRequest(request('/images/logo.png'))).toBe(true);
|
|
54
|
-
expect(isStaticRequest(request('/fonts/font.woff2'))).toBe(true);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('ignores routes without a known extension', () => {
|
|
58
|
-
expect(isStaticRequest(request('/en/products'))).toBe(false);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import { Socket } from 'net';
|
|
3
|
+
import type { NextRequest } from 'next/server';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { isStaticRequest } from '../proxy/proxy.service';
|
|
6
|
+
import { getSession, getSessionToken } from '../session/session.service';
|
|
7
|
+
|
|
8
|
+
function createRequest(cookie?: string) {
|
|
9
|
+
const request = new IncomingMessage(new Socket()) as IncomingMessage & { cookies: Record<string, string> };
|
|
10
|
+
if (cookie) {
|
|
11
|
+
request.headers.cookie = cookie;
|
|
12
|
+
}
|
|
13
|
+
request.cookies = {};
|
|
14
|
+
return request;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getCookie(response: ServerResponse) {
|
|
18
|
+
const header = response.getHeader('set-cookie');
|
|
19
|
+
const value = Array.isArray(header) ? header[0] : String(header);
|
|
20
|
+
return value.split(';')[0];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('session (iron-session)', () => {
|
|
24
|
+
it('seals the session in a cookie and reads it back on the next request', async () => {
|
|
25
|
+
const response = new ServerResponse(createRequest());
|
|
26
|
+
const session = await getSession<{ token?: string; exp?: number }>(createRequest(), response);
|
|
27
|
+
session.token = 'token';
|
|
28
|
+
session.exp = Math.floor(Date.now() / 1000) + 60;
|
|
29
|
+
await session.save();
|
|
30
|
+
|
|
31
|
+
const cookie = getCookie(response);
|
|
32
|
+
expect(cookie.startsWith('websolutespa-next-js=')).toBe(true);
|
|
33
|
+
const token = await getSessionToken(createRequest(cookie), new ServerResponse(createRequest()));
|
|
34
|
+
expect(token).toBe('token');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('clears an expired token', async () => {
|
|
38
|
+
const response = new ServerResponse(createRequest());
|
|
39
|
+
const session = await getSession<{ token?: string; exp?: number }>(createRequest(), response);
|
|
40
|
+
session.token = 'token';
|
|
41
|
+
session.exp = Math.floor(Date.now() / 1000) - 60;
|
|
42
|
+
await session.save();
|
|
43
|
+
|
|
44
|
+
const token = await getSessionToken(createRequest(getCookie(response)), new ServerResponse(createRequest()));
|
|
45
|
+
expect(token).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('isStaticRequest (mime)', () => {
|
|
50
|
+
const request = (pathname: string) => ({ nextUrl: { pathname } }) as NextRequest;
|
|
51
|
+
|
|
52
|
+
it('detects files by extension', () => {
|
|
53
|
+
expect(isStaticRequest(request('/images/logo.png'))).toBe(true);
|
|
54
|
+
expect(isStaticRequest(request('/fonts/font.woff2'))).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('ignores routes without a known extension', () => {
|
|
58
|
+
expect(isStaticRequest(request('/en/products'))).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import mime from 'mime';
|
|
2
|
-
import { NextRequest } from 'next/server';
|
|
3
|
-
|
|
4
|
-
const API_BASE = process.env.NEXT_PUBLIC_API || '/api';
|
|
5
|
-
|
|
6
|
-
export function isStaticRequest(request: NextRequest) {
|
|
7
|
-
const { pathname } = request.nextUrl;
|
|
8
|
-
const isStatic = mime.getType(pathname) !== null;
|
|
9
|
-
return isStatic;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function isNextRequest(request: NextRequest) {
|
|
13
|
-
const { pathname } = request.nextUrl;
|
|
14
|
-
const isNext = pathname.startsWith('/_next');
|
|
15
|
-
return isNext;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function isApiRequest(request: NextRequest) {
|
|
19
|
-
const { pathname } = request.nextUrl;
|
|
20
|
-
const isApi = pathname.startsWith(API_BASE);
|
|
21
|
-
return isApi;
|
|
22
|
-
}
|
|
1
|
+
import mime from 'mime';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
|
|
4
|
+
const API_BASE = process.env.NEXT_PUBLIC_API || '/api';
|
|
5
|
+
|
|
6
|
+
export function isStaticRequest(request: NextRequest) {
|
|
7
|
+
const { pathname } = request.nextUrl;
|
|
8
|
+
const isStatic = mime.getType(pathname) !== null;
|
|
9
|
+
return isStatic;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isNextRequest(request: NextRequest) {
|
|
13
|
+
const { pathname } = request.nextUrl;
|
|
14
|
+
const isNext = pathname.startsWith('/_next');
|
|
15
|
+
return isNext;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function isApiRequest(request: NextRequest) {
|
|
19
|
+
const { pathname } = request.nextUrl;
|
|
20
|
+
const isApi = pathname.startsWith(API_BASE);
|
|
21
|
+
return isApi;
|
|
22
|
+
}
|