stentor-response 1.48.5 → 1.48.9
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 +25 -10
- package/lib/compileResponse.js.map +1 -1
- package/package.json +9 -9
- package/CHANGELOG.md +0 -5474
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,12 +1,22 @@
|
|
|
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");
|
|
7
7
|
const stentor_locales_1 = require("stentor-locales");
|
|
8
|
+
const stentor_logger_1 = require("stentor-logger");
|
|
8
9
|
const stentor_utils_1 = require("stentor-utils");
|
|
9
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;
|
|
10
20
|
/**
|
|
11
21
|
* Compiles a templated response with provided request and context.
|
|
12
22
|
*
|
|
@@ -57,7 +67,7 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
57
67
|
if (Array.isArray(compiledResponse.displays) && compiledResponse.displays.length > 0) {
|
|
58
68
|
// We want to first check to see if they have the itemObject feature
|
|
59
69
|
// Note, just care about the first one here.
|
|
60
|
-
const firstDisplay = compiledResponse.displays[0];
|
|
70
|
+
const firstDisplay = Object.assign({}, compiledResponse.displays[0]);
|
|
61
71
|
if ((0, stentor_guards_1.isTemplatedList)(firstDisplay)) {
|
|
62
72
|
// This is what we will replace the items on firstDisplay with
|
|
63
73
|
const compiledItems = [];
|
|
@@ -65,6 +75,9 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
65
75
|
const itemsName = firstDisplay.itemsName || "items";
|
|
66
76
|
// The collection variable. The regex is just for the syntactical similarity. ex "${ $.session.storeList }"
|
|
67
77
|
const itemsObject = firstDisplay.itemsObject;
|
|
78
|
+
// then delete these since they may cause problems later in compilation
|
|
79
|
+
delete firstDisplay.itemsObject;
|
|
80
|
+
delete firstDisplay.itemsName;
|
|
68
81
|
// If dynamic no reason to give more
|
|
69
82
|
if (firstDisplay.items.length !== 1) {
|
|
70
83
|
throw new Error("Templated Lists must only have 1 item");
|
|
@@ -99,7 +112,7 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
99
112
|
// Time to iterate and do replacements
|
|
100
113
|
itemsObjectArray.forEach((item, index) => {
|
|
101
114
|
// Stringify
|
|
102
|
-
const itemString = JSON.stringify(itemTemplate
|
|
115
|
+
const itemString = JSON.stringify(itemTemplate);
|
|
103
116
|
let compiledItemString = (0, compileSegments_1.compileSegments)(itemString, compiledResponse.segments, request, context);
|
|
104
117
|
// New compiler
|
|
105
118
|
const itemCompiler = new stentor_utils_1.Compiler({
|
|
@@ -109,30 +122,32 @@ function compileResponse(response, request, context, additionalContext, macros)
|
|
|
109
122
|
});
|
|
110
123
|
compiledItemString = itemCompiler.compile(compiledItemString, request, context);
|
|
111
124
|
try {
|
|
112
|
-
const compiledItem = JSON.parse(compiledItemString);
|
|
125
|
+
const compiledItem = JSON.parse(jsonEscape(compiledItemString));
|
|
113
126
|
// Only update if it doesn't explode
|
|
114
127
|
compiledItems.push(compiledItem);
|
|
115
128
|
}
|
|
116
129
|
catch (e) {
|
|
117
|
-
|
|
130
|
+
(0, stentor_logger_1.log)().error(`Could not compile display item:`, e);
|
|
118
131
|
}
|
|
119
|
-
// ok, time to update the items.
|
|
120
|
-
firstDisplay.items = compiledItems;
|
|
121
132
|
});
|
|
133
|
+
// ok, time to update the items.
|
|
134
|
+
firstDisplay.items = compiledItems;
|
|
135
|
+
// update on the compiled response
|
|
136
|
+
compiledResponse.displays[0] = firstDisplay;
|
|
122
137
|
}
|
|
123
138
|
// Then pass it through as a string convert it to a string
|
|
124
|
-
const displaysString = JSON.stringify(compiledResponse.displays
|
|
139
|
+
const displaysString = JSON.stringify(compiledResponse.displays);
|
|
125
140
|
// Compile the segments
|
|
126
141
|
let compiledDisplayString = (0, compileSegments_1.compileSegments)(displaysString, compiledResponse.segments, request, context);
|
|
127
142
|
compiledDisplayString = compiler.compile(compiledDisplayString, request, context);
|
|
128
143
|
// Set it back
|
|
129
144
|
try {
|
|
130
|
-
const compiledDisplays = JSON.parse(compiledDisplayString);
|
|
145
|
+
const compiledDisplays = JSON.parse(jsonEscape(compiledDisplayString));
|
|
131
146
|
// Only update if it doesn't explode
|
|
132
147
|
compiledResponse.displays = compiledDisplays;
|
|
133
148
|
}
|
|
134
149
|
catch (e) {
|
|
135
|
-
|
|
150
|
+
(0, stentor_logger_1.log)().error(`Could not compile display:`, e);
|
|
136
151
|
}
|
|
137
152
|
}
|
|
138
153
|
// return the result
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileResponse.js","sourceRoot":"","sources":["../src/compileResponse.ts"],"names":[],"mappings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QAED,0DAA0D;QAC1D,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACjE,uBAAuB;QACvB,IAAI,qBAAqB,GAAG,IAAA,iCAAe,EAAC,cAAc,EAAE,gBAAgB,CAAC,QAAQ,EAAE,OAAO,EAAE,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.9",
|
|
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.9",
|
|
35
|
+
"stentor-locales": "1.48.9",
|
|
36
|
+
"stentor-media": "1.48.9",
|
|
37
|
+
"stentor-request": "1.48.9",
|
|
38
|
+
"stentor-utils": "1.48.9"
|
|
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": "d522f2e50da522c48f368eb025bb902b5e8eecf5"
|
|
49
49
|
}
|