@magda/typescript-common 0.0.60-alpha.9 → 0.0.60-dt.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.
- package/dist/appendUrlSegments.d.ts +2 -0
- package/dist/appendUrlSegments.js +18 -0
- package/dist/appendUrlSegments.js.map +1 -0
- package/dist/getAbsoluteUrl.d.ts +12 -0
- package/dist/getAbsoluteUrl.js +35 -0
- package/dist/getAbsoluteUrl.js.map +1 -0
- package/dist/markdownToHtml.js +1 -1
- package/dist/markdownToHtml.js.map +1 -1
- package/dist/session/cookieUtils.d.ts +16 -0
- package/dist/session/cookieUtils.js +19 -0
- package/dist/session/cookieUtils.js.map +1 -0
- package/dist/session/destroySession.d.ts +10 -0
- package/dist/session/destroySession.js +44 -0
- package/dist/session/destroySession.js.map +1 -0
- package/dist/session/getSessionId.d.ts +2 -0
- package/dist/session/getSessionId.js +28 -0
- package/dist/session/getSessionId.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const urijs_1 = __importDefault(require("urijs"));
|
|
7
|
+
function appendUrlSegments(url, segments) {
|
|
8
|
+
url = url ? url : "";
|
|
9
|
+
const uri = urijs_1.default(url);
|
|
10
|
+
return uri
|
|
11
|
+
.segmentCoded(uri
|
|
12
|
+
.segmentCoded()
|
|
13
|
+
.filter((item) => !!item)
|
|
14
|
+
.concat(segments))
|
|
15
|
+
.toString();
|
|
16
|
+
}
|
|
17
|
+
exports.default = appendUrlSegments;
|
|
18
|
+
//# sourceMappingURL=appendUrlSegments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendUrlSegments.js","sourceRoot":"","sources":["../src/appendUrlSegments.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,SAAS,iBAAiB,CAAC,GAAW,EAAE,QAAkB;IACtD,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,eAAK,CAAC,GAAG,CAAC,CAAC;IACvB,OAAO,GAAG;SACL,YAAY,CACT,GAAG;SACE,YAAY,EAAE;SACd,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACxB,MAAM,CAAC,QAAQ,CAAC,CACxB;SACA,QAAQ,EAAE,CAAC;AACpB,CAAC;AAED,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Join `url` with `baseUrl` if `url` is not an absolute url
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @param {string} url
|
|
6
|
+
* @param {string} baseUrl
|
|
7
|
+
* @param {{ [key: string]: string }} [optionalQueries]
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export default function getAbsoluteUrl(url: string, baseUrl: string, optionalQueries?: {
|
|
11
|
+
[key: string]: string;
|
|
12
|
+
}): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const urijs_1 = __importDefault(require("urijs"));
|
|
7
|
+
/**
|
|
8
|
+
* Join `url` with `baseUrl` if `url` is not an absolute url
|
|
9
|
+
*
|
|
10
|
+
* @export
|
|
11
|
+
* @param {string} url
|
|
12
|
+
* @param {string} baseUrl
|
|
13
|
+
* @param {{ [key: string]: string }} [optionalQueries]
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function getAbsoluteUrl(url, baseUrl, optionalQueries) {
|
|
17
|
+
const uri = urijs_1.default(url);
|
|
18
|
+
if (uri.hostname()) {
|
|
19
|
+
// --- absolute url, return directly
|
|
20
|
+
return url;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (typeof baseUrl !== "string") {
|
|
24
|
+
baseUrl = "";
|
|
25
|
+
}
|
|
26
|
+
const baseUri = urijs_1.default(baseUrl);
|
|
27
|
+
const query = uri.search(true);
|
|
28
|
+
const mergedUri = baseUri.segmentCoded(baseUri.segmentCoded().concat(uri.segmentCoded()));
|
|
29
|
+
return mergedUri
|
|
30
|
+
.search(Object.assign(Object.assign({}, (query ? query : {})), (optionalQueries ? optionalQueries : {})))
|
|
31
|
+
.toString();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = getAbsoluteUrl;
|
|
35
|
+
//# sourceMappingURL=getAbsoluteUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAbsoluteUrl.js","sourceRoot":"","sources":["../src/getAbsoluteUrl.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B;;;;;;;;GAQG;AACH,SAAwB,cAAc,CAClC,GAAW,EACX,OAAe,EACf,eAA2C;IAE3C,MAAM,GAAG,GAAG,eAAK,CAAC,GAAG,CAAC,CAAC;IACvB,IAAI,GAAG,CAAC,QAAQ,EAAE,EAAE;QAChB,oCAAoC;QACpC,OAAO,GAAG,CAAC;KACd;SAAM;QACH,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC7B,OAAO,GAAG,EAAE,CAAC;SAChB;QACD,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,CAClC,OAAO,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CACpD,CAAC;QAEF,OAAO,SAAS;aACX,MAAM,iCACA,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,GACpB,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAC7C;aACD,QAAQ,EAAE,CAAC;KACnB;AACL,CAAC;AA1BD,iCA0BC"}
|
package/dist/markdownToHtml.js
CHANGED
|
@@ -12,7 +12,7 @@ const md = new markdown_it_1.default({
|
|
|
12
12
|
});
|
|
13
13
|
const htmlRegex = /^\s*<[^>]+>/;
|
|
14
14
|
function markdownToHtml(markdownString, allowUnsafeHtml = false, options = {
|
|
15
|
-
FORBID_TAGS: ["svg", "math"]
|
|
15
|
+
FORBID_TAGS: ["svg", "math", "style"]
|
|
16
16
|
}) {
|
|
17
17
|
if (!markdownString || typeof markdownString !== "string") {
|
|
18
18
|
return markdownString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownToHtml.js","sourceRoot":"","sources":["../src/markdownToHtml.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AACrC,0DAAkC;AAElC,MAAM,EAAE,GAAG,IAAI,qBAAU,CAAC;IACtB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;CACf,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC,SAAwB,cAAc,CAClC,cAAsB,EACtB,kBAA2B,KAAK,EAChC,OAAO,GAAG;IACN,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"markdownToHtml.js","sourceRoot":"","sources":["../src/markdownToHtml.ts"],"names":[],"mappings":";;;;;AAAA,8DAAqC;AACrC,0DAAkC;AAElC,MAAM,EAAE,GAAG,IAAI,qBAAU,CAAC;IACtB,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;CACf,CAAC,CAAC;AAEH,MAAM,SAAS,GAAG,aAAa,CAAC;AAEhC,SAAwB,cAAc,CAClC,cAAsB,EACtB,kBAA2B,KAAK,EAChC,OAAO,GAAG;IACN,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;CACxC;IAED,IAAI,CAAC,cAAc,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE;QACvD,OAAO,cAAc,CAAC;KACzB;IACD,6EAA6E;IAC7E,0CAA0C;IAC1C,IAAI,UAAU,CAAC;IACf,IAAI,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE;QAChC,UAAU,GAAG,cAAc,CAAC;KAC/B;SAAM;QACH,2GAA2G;QAC3G,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;KAC1C;IACD,IAAI,eAAe,EAAE;QACjB,OAAO,UAAU,CAAC;KACrB;SAAM;QACH,OAAO,mBAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;KAClD;AACL,CAAC;AAxBD,iCAwBC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
/** This is present in the express-session types but not actually exported properly, so it needs to be copy-pasted here */
|
|
3
|
+
export declare type CookieOptions = {
|
|
4
|
+
maxAge?: number;
|
|
5
|
+
signed?: boolean;
|
|
6
|
+
expires?: Date;
|
|
7
|
+
httpOnly?: boolean;
|
|
8
|
+
path?: string;
|
|
9
|
+
domain?: string;
|
|
10
|
+
secure?: boolean | "auto";
|
|
11
|
+
encode?: (val: string) => string;
|
|
12
|
+
sameSite?: boolean | "lax" | "strict" | "none";
|
|
13
|
+
};
|
|
14
|
+
export declare const DEFAULT_SESSION_COOKIE_NAME: string;
|
|
15
|
+
export declare let DEFAULT_SESSION_COOKIE_OPTIONS: CookieOptions;
|
|
16
|
+
export declare function deleteCookie(cookieName: string, cookieOptions: CookieOptions, res: express.Response): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteCookie = exports.DEFAULT_SESSION_COOKIE_OPTIONS = exports.DEFAULT_SESSION_COOKIE_NAME = void 0;
|
|
4
|
+
exports.DEFAULT_SESSION_COOKIE_NAME = "connect.sid";
|
|
5
|
+
exports.DEFAULT_SESSION_COOKIE_OPTIONS = {
|
|
6
|
+
maxAge: 7 * 60 * 60 * 1000,
|
|
7
|
+
sameSite: "lax",
|
|
8
|
+
httpOnly: true,
|
|
9
|
+
secure: "auto"
|
|
10
|
+
};
|
|
11
|
+
function deleteCookie(cookieName, cookieOptions, res) {
|
|
12
|
+
const deleteCookieOptions = Object.assign({}, cookieOptions);
|
|
13
|
+
// --- `clearCookie` works in a way like it will fail to delete cookie if maxAge presents T_T
|
|
14
|
+
// --- https://github.com/expressjs/express/issues/3856#issuecomment-502397226
|
|
15
|
+
delete deleteCookieOptions.maxAge;
|
|
16
|
+
res.clearCookie(cookieName, deleteCookieOptions);
|
|
17
|
+
}
|
|
18
|
+
exports.deleteCookie = deleteCookie;
|
|
19
|
+
//# sourceMappingURL=cookieUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookieUtils.js","sourceRoot":"","sources":["../../src/session/cookieUtils.ts"],"names":[],"mappings":";;;AAea,QAAA,2BAA2B,GAAW,aAAa,CAAC;AAEtD,QAAA,8BAA8B,GAAkB;IACvD,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IAC1B,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,MAAM;CACjB,CAAC;AAEF,SAAgB,YAAY,CACxB,UAAkB,EAClB,aAA4B,EAC5B,GAAqB;IAErB,MAAM,mBAAmB,qBAClB,aAAa,CACnB,CAAC;IACF,6FAA6F;IAC7F,8EAA8E;IAC9E,OAAO,mBAAmB,CAAC,MAAM,CAAC;IAClC,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;AACrD,CAAC;AAZD,oCAYC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
/**
|
|
3
|
+
* destroy the session.
|
|
4
|
+
* - will delete the session data from session store only.
|
|
5
|
+
* - will not delete session cookie (Call deleteCookie method for deleting cookie)
|
|
6
|
+
* @export
|
|
7
|
+
* @param {express.Request} req
|
|
8
|
+
* @return {*} {Promise<void>}
|
|
9
|
+
*/
|
|
10
|
+
export default function destroySession(req: express.Request): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/**
|
|
13
|
+
* destroy the session.
|
|
14
|
+
* - will delete the session data from session store only.
|
|
15
|
+
* - will not delete session cookie (Call deleteCookie method for deleting cookie)
|
|
16
|
+
* @export
|
|
17
|
+
* @param {express.Request} req
|
|
18
|
+
* @return {*} {Promise<void>}
|
|
19
|
+
*/
|
|
20
|
+
function destroySession(req) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
var _a;
|
|
24
|
+
if ((_a = req === null || req === void 0 ? void 0 : req.session) === null || _a === void 0 ? void 0 : _a.destroy) {
|
|
25
|
+
req.session.destroy((err) => {
|
|
26
|
+
if (err) {
|
|
27
|
+
// Failed to access session storage to delete session data
|
|
28
|
+
reject(err);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
resolve();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// --- express-session 1.17 may not always initialise session
|
|
37
|
+
// --- if req.session not exist, should just resolve promise
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.default = destroySession;
|
|
44
|
+
//# sourceMappingURL=destroySession.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"destroySession.js","sourceRoot":"","sources":["../../src/session/destroySession.ts"],"names":[],"mappings":";;;;;;;;;;;AAEA;;;;;;;GAOG;AACH,SAA8B,cAAc,CACxC,GAAoB;;QAEpB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;;YACnC,UAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,0CAAE,OAAO,EAAE;gBACvB,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;oBACxB,IAAI,GAAG,EAAE;wBACL,0DAA0D;wBAC1D,MAAM,CAAC,GAAG,CAAC,CAAC;qBACf;yBAAM;wBACH,OAAO,EAAE,CAAC;qBACb;gBACL,CAAC,CAAC,CAAC;aACN;iBAAM;gBACH,6DAA6D;gBAC7D,4DAA4D;gBAC5D,OAAO,EAAE,CAAC;aACb;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CAAA;AAnBD,iCAmBC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cookie_signature_1 = __importDefault(require("cookie-signature"));
|
|
7
|
+
const cookieUtils_1 = require("./cookieUtils");
|
|
8
|
+
function getSessionId(req, secret = "") {
|
|
9
|
+
const sessionCookie = req.cookies[cookieUtils_1.DEFAULT_SESSION_COOKIE_NAME];
|
|
10
|
+
if (!sessionCookie) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
if (sessionCookie.substr(0, 2) === "s:") {
|
|
15
|
+
// --- process signed cookie
|
|
16
|
+
const unsignResult = cookie_signature_1.default.unsign(sessionCookie.slice(2), secret);
|
|
17
|
+
if (unsignResult === false) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return unsignResult;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return sessionCookie;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = getSessionId;
|
|
28
|
+
//# sourceMappingURL=getSessionId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSessionId.js","sourceRoot":"","sources":["../../src/session/getSessionId.ts"],"names":[],"mappings":";;;;;AACA,wEAAyC;AACzC,+CAA4D;AAE5D,SAAwB,YAAY,CAChC,GAAoB,EACpB,SAAiB,EAAE;IAEnB,MAAM,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC,yCAA2B,CAAW,CAAC;IACzE,IAAI,CAAC,aAAa,EAAE;QAChB,OAAO,IAAI,CAAC;KACf;SAAM;QACH,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE;YACrC,4BAA4B;YAC5B,MAAM,YAAY,GAAG,0BAAS,CAAC,MAAM,CACjC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,EACtB,MAAM,CACT,CAAC;YACF,IAAI,YAAY,KAAK,KAAK,EAAE;gBACxB,OAAO,IAAI,CAAC;aACf;YACD,OAAO,YAAY,CAAC;SACvB;aAAM;YACH,OAAO,aAAa,CAAC;SACxB;KACJ;AACL,CAAC;AAtBD,+BAsBC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magda/typescript-common",
|
|
3
3
|
"description": "Common TypeScript code shared between components.",
|
|
4
|
-
"version": "0.0.60-
|
|
4
|
+
"version": "0.0.60-dt.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prebuild": "rimraf dist tsconfig.tsbuildinfo",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"release": "npm publish || echo \"Skip releasing npm package @magda/typescript-common.\""
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@magda/registry-aspects": "^0.0.60-
|
|
21
|
-
"@magda/scripts": "^0.0.60-
|
|
20
|
+
"@magda/registry-aspects": "^0.0.60-dt.0",
|
|
21
|
+
"@magda/scripts": "^0.0.60-dt.0",
|
|
22
22
|
"@types/chai": "^4.0.0",
|
|
23
23
|
"@types/chai-as-promised": "^7.1.0",
|
|
24
24
|
"@types/cross-spawn": "^6.0.1",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@types/resolve": "^1.14.0",
|
|
52
52
|
"@types/vfile-message": "^2.0.0",
|
|
53
53
|
"body-parser": "^1.18.2",
|
|
54
|
-
"dompurify": "^2.0
|
|
54
|
+
"dompurify": "^2.3.0",
|
|
55
55
|
"express": "^4.17.1",
|
|
56
56
|
"isomorphic-fetch": "^2.2.1",
|
|
57
57
|
"jsonwebtoken": "^8.4.0",
|