stentor-response 1.48.6 → 1.48.10
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/lib/compileResponse.d.ts +6 -0
- package/lib/compileResponse.js +20 -9
- package/lib/compileResponse.js.map +1 -1
- package/package.json +9 -9
- package/CHANGELOG.md +0 -5485
package/lib/compileResponse.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { Context, Request, Response } from "stentor-models";
|
|
2
2
|
import { MacroMap } from "stentor-utils";
|
|
3
|
+
/**
|
|
4
|
+
* Necessary to JSON.parse strings with newlines that need escaping. Otherwise JSON.parse fails.
|
|
5
|
+
* @param json
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function jsonEscape(json: string): string;
|
|
3
9
|
/**
|
|
4
10
|
* Compiles a templated response with provided request and context.
|
|
5
11
|
*
|
package/lib/compileResponse.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileResponse = void 0;
|
|
3
|
+
exports.compileResponse = exports.jsonEscape = void 0;
|
|
4
4
|
/*! Copyright (c) 2019, XAPPmedia */
|
|
5
5
|
const stentor_constants_1 = require("stentor-constants");
|
|
6
6
|
const stentor_guards_1 = require("stentor-guards");
|
|
@@ -8,6 +8,15 @@ const stentor_locales_1 = require("stentor-locales");
|
|
|
8
8
|
const stentor_logger_1 = require("stentor-logger");
|
|
9
9
|
const stentor_utils_1 = require("stentor-utils");
|
|
10
10
|
const compileSegments_1 = require("./compileSegments");
|
|
11
|
+
/**
|
|
12
|
+
* Necessary to JSON.parse strings with newlines that need escaping. Otherwise JSON.parse fails.
|
|
13
|
+
* @param json
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
function jsonEscape(json) {
|
|
17
|
+
return json.replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
|
|
18
|
+
}
|
|
19
|
+
exports.jsonEscape = jsonEscape;
|
|
11
20
|
/**
|
|
12
21
|
* Compiles a templated response with provided request and context.
|
|
13
22
|
*
|
|
@@ -58,7 +67,7 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
58
67
|
if (Array.isArray(compiledResponse.displays) && compiledResponse.displays.length > 0) {
|
|
59
68
|
// We want to first check to see if they have the itemObject feature
|
|
60
69
|
// Note, just care about the first one here.
|
|
61
|
-
const firstDisplay = compiledResponse.displays[0];
|
|
70
|
+
const firstDisplay = Object.assign({}, compiledResponse.displays[0]);
|
|
62
71
|
if ((0, stentor_guards_1.isTemplatedList)(firstDisplay)) {
|
|
63
72
|
// This is what we will replace the items on firstDisplay with
|
|
64
73
|
const compiledItems = [];
|
|
@@ -103,7 +112,7 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
103
112
|
// Time to iterate and do replacements
|
|
104
113
|
itemsObjectArray.forEach((item, index) => {
|
|
105
114
|
// Stringify
|
|
106
|
-
const itemString = JSON.stringify(itemTemplate
|
|
115
|
+
const itemString = JSON.stringify(itemTemplate);
|
|
107
116
|
let compiledItemString = (0, compileSegments_1.compileSegments)(itemString, compiledResponse.segments, request, context);
|
|
108
117
|
// New compiler
|
|
109
118
|
const itemCompiler = new stentor_utils_1.Compiler({
|
|
@@ -113,25 +122,27 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
113
122
|
});
|
|
114
123
|
compiledItemString = itemCompiler.compile(compiledItemString, request, context);
|
|
115
124
|
try {
|
|
116
|
-
const compiledItem = JSON.parse(compiledItemString);
|
|
125
|
+
const compiledItem = JSON.parse(jsonEscape(compiledItemString));
|
|
117
126
|
// Only update if it doesn't explode
|
|
118
127
|
compiledItems.push(compiledItem);
|
|
119
128
|
}
|
|
120
129
|
catch (e) {
|
|
121
|
-
(0, stentor_logger_1.log)().error(`Could not compile display:`, e);
|
|
130
|
+
(0, stentor_logger_1.log)().error(`Could not compile display item:`, e);
|
|
122
131
|
}
|
|
123
|
-
// ok, time to update the items.
|
|
124
|
-
firstDisplay.items = compiledItems;
|
|
125
132
|
});
|
|
133
|
+
// ok, time to update the items.
|
|
134
|
+
firstDisplay.items = compiledItems;
|
|
135
|
+
// update on the compiled response
|
|
136
|
+
compiledResponse.displays[0] = firstDisplay;
|
|
126
137
|
}
|
|
127
138
|
// Then pass it through as a string convert it to a string
|
|
128
|
-
const displaysString = JSON.stringify(compiledResponse.displays
|
|
139
|
+
const displaysString = JSON.stringify(compiledResponse.displays);
|
|
129
140
|
// Compile the segments
|
|
130
141
|
let compiledDisplayString = (0, compileSegments_1.compileSegments)(displaysString, compiledResponse.segments, request, context);
|
|
131
142
|
compiledDisplayString = compiler.compile(compiledDisplayString, request, context);
|
|
132
143
|
// Set it back
|
|
133
144
|
try {
|
|
134
|
-
const compiledDisplays = JSON.parse(compiledDisplayString);
|
|
145
|
+
const compiledDisplays = JSON.parse(jsonEscape(compiledDisplayString));
|
|
135
146
|
// Only update if it doesn't explode
|
|
136
147
|
compiledResponse.displays = compiledDisplays;
|
|
137
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileResponse.js","sourceRoot":"","sources":["../src/compileResponse.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AACpC,yDAAmD;AACnD,mDAAiD;AACjD,qDAA2C;AAC3C,mDAAqC;AAErC,iDAAmG;AAEnG,uDAAoD;AAEpD;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,eAAe,CAC3B,QAAkB,EAClB,OAAgB,EAChB,OAAgB,EAChB,iBAA2C,EAC3C,MAAiB;;IAEjB,YAAY;IACZ,IAAI,CAAC,QAAQ,EAAE;QACX,OAAO,QAAQ,CAAC;KACnB;IAED,MAAM,QAAQ,GAAG,IAAI,wBAAQ,CACzB;QACI,MAAM,kCAAO,8BAAc,GAAK,MAAM,CAAE;QACxC,iBAAiB;QACjB,oBAAoB,EAAE,IAAI;KAC7B,CACJ,CAAC;IAEF,+B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AE,OAAO,CAAC,CAAC;QAEzG,qBAAqB,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAElF,cAAc;QACd,IAAI;YACA,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC;YACvE,oCAAoC;YACpC,gBAAgB,CAAC,QAAQ,GAAG,gBAAgB,CAAC;SAChD;QAAC,OAAO,CAAC,EAAE;YACR,IAAA,oBAAG,GAAE,CAAC,KAAK,CAAC,4BAA4B,EAAE,CAAC,CAAC,CAAC;SAChD;KACJ;IAED,oBAAoB;IACpB,OAAO,gBAAgB,CAAC;AAC5B,CAAC;AAtKD,0CAsKC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.48.
|
|
7
|
+
"version": "1.48.10",
|
|
8
8
|
"description": "Response for stentor",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"mocha": "9.1.3",
|
|
25
25
|
"sinon": "10.0.0",
|
|
26
26
|
"sinon-chai": "3.7.0",
|
|
27
|
-
"stentor-models": "1.48.
|
|
28
|
-
"ts-node": "
|
|
27
|
+
"stentor-models": "1.48.7",
|
|
28
|
+
"ts-node": "10.4.0",
|
|
29
29
|
"typescript": "4.4.4"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@xapp/patterns": "1.37.29",
|
|
33
33
|
"lodash.template": "4.5.0",
|
|
34
|
-
"stentor-determiner": "1.48.
|
|
35
|
-
"stentor-locales": "1.48.
|
|
36
|
-
"stentor-media": "1.48.
|
|
37
|
-
"stentor-request": "1.48.
|
|
38
|
-
"stentor-utils": "1.48.
|
|
34
|
+
"stentor-determiner": "1.48.10",
|
|
35
|
+
"stentor-locales": "1.48.10",
|
|
36
|
+
"stentor-media": "1.48.10",
|
|
37
|
+
"stentor-request": "1.48.10",
|
|
38
|
+
"stentor-utils": "1.48.10"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"stentor-models": "1.x"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"clean": "rm -rf ./lib/* ",
|
|
46
46
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "f11b5c50e5447fd96d2bbf437003b313e0ace23f"
|
|
49
49
|
}
|