@raydiant/playlist-window-manager 0.14.24 → 0.14.25
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/build/embeddedApps.js +10 -5
- package/build/embeddedApps.test.js +7 -0
- package/package.json +1 -1
- package/src/embeddedApps.test.ts +15 -0
- package/src/embeddedApps.ts +12 -5
package/build/embeddedApps.js
CHANGED
|
@@ -14,8 +14,9 @@ function createEmbeddedApp(presentation, applicationVersion) {
|
|
|
14
14
|
// replace
|
|
15
15
|
var url = applicationVersion.embeddedUrlFormat || '';
|
|
16
16
|
matches.forEach(function (m) {
|
|
17
|
-
var
|
|
18
|
-
var
|
|
17
|
+
var queryParamVariableName = m[1]; // Where the value of your input will be injected. E.g. ":location"
|
|
18
|
+
var queryParamName = m[2]; // The query param name. E.g. "location"
|
|
19
|
+
var _a = queryParamVariableName.split(':'), variableName = _a[1];
|
|
19
20
|
// Don't replace variables that are numbers to allow setting
|
|
20
21
|
// port numbers in the embedded app url.
|
|
21
22
|
if (!isNaN(Number(variableName)))
|
|
@@ -24,12 +25,16 @@ function createEmbeddedApp(presentation, applicationVersion) {
|
|
|
24
25
|
// If the presentation property is not found (this shouldn't happen), default to encoding the value.
|
|
25
26
|
// Otherwise, only skip encoding if the presentation property's encode property is false.
|
|
26
27
|
var shouldEncodeValue = !presentationProperty || presentationProperty.encode !== false;
|
|
27
|
-
var value = presentation.applicationVariables[
|
|
28
|
+
var value = presentation.applicationVariables[queryParamName];
|
|
28
29
|
if (value === undefined)
|
|
29
30
|
value = '';
|
|
30
|
-
if (
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
value = JSON.stringify(value);
|
|
33
|
+
}
|
|
34
|
+
if (shouldEncodeValue) {
|
|
31
35
|
value = encodeURIComponent(value);
|
|
32
|
-
|
|
36
|
+
}
|
|
37
|
+
url = url.replace(queryParamVariableName, value);
|
|
33
38
|
});
|
|
34
39
|
return url;
|
|
35
40
|
}
|
|
@@ -63,3 +63,10 @@ test('Does not encode value if presentation property disables encoding', functio
|
|
|
63
63
|
presentationProperties: [{ name: 'url', encode: false }]
|
|
64
64
|
}))).toBe("https://raydiant.com");
|
|
65
65
|
});
|
|
66
|
+
test('Encodes a variables containing an array', function () {
|
|
67
|
+
var fooValue = ['option-a', 'option-b', 'option-c'];
|
|
68
|
+
var fooValueEncoded = '%5B%22option-a%22%2C%22option-b%22%2C%22option-c%22%5D';
|
|
69
|
+
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: fooValue } }), createApplicationVersion({
|
|
70
|
+
embeddedUrlFormat: "http://localhost:8080?foo=:foo"
|
|
71
|
+
}))).toBe("http://localhost:8080?foo=" + fooValueEncoded);
|
|
72
|
+
});
|
package/package.json
CHANGED
package/src/embeddedApps.test.ts
CHANGED
|
@@ -116,3 +116,18 @@ test('Does not encode value if presentation property disables encoding', () => {
|
|
|
116
116
|
)
|
|
117
117
|
).toBe(`https://raydiant.com`);
|
|
118
118
|
});
|
|
119
|
+
|
|
120
|
+
test('Encodes a variables containing an array', () => {
|
|
121
|
+
const fooValue = ['option-a', 'option-b', 'option-c'];
|
|
122
|
+
const fooValueEncoded =
|
|
123
|
+
'%5B%22option-a%22%2C%22option-b%22%2C%22option-c%22%5D';
|
|
124
|
+
|
|
125
|
+
expect(
|
|
126
|
+
createEmbeddedApp(
|
|
127
|
+
createPresentation({ applicationVariables: { foo: fooValue } }),
|
|
128
|
+
createApplicationVersion({
|
|
129
|
+
embeddedUrlFormat: `http://localhost:8080?foo=:foo`
|
|
130
|
+
})
|
|
131
|
+
)
|
|
132
|
+
).toBe(`http://localhost:8080?foo=${fooValueEncoded}`);
|
|
133
|
+
});
|
package/src/embeddedApps.ts
CHANGED
|
@@ -19,8 +19,10 @@ export default function createEmbeddedApp(
|
|
|
19
19
|
// replace
|
|
20
20
|
let url = applicationVersion.embeddedUrlFormat || '';
|
|
21
21
|
matches.forEach(m => {
|
|
22
|
-
const
|
|
23
|
-
const [
|
|
22
|
+
const queryParamVariableName = m[1]; // Where the value of your input will be injected. E.g. ":location"
|
|
23
|
+
const queryParamName = m[2]; // The query param name. E.g. "location"
|
|
24
|
+
|
|
25
|
+
const [, variableName] = queryParamVariableName.split(':');
|
|
24
26
|
// Don't replace variables that are numbers to allow setting
|
|
25
27
|
// port numbers in the embedded app url.
|
|
26
28
|
if (!isNaN(Number(variableName))) return;
|
|
@@ -34,11 +36,16 @@ export default function createEmbeddedApp(
|
|
|
34
36
|
const shouldEncodeValue =
|
|
35
37
|
!presentationProperty || presentationProperty.encode !== false;
|
|
36
38
|
|
|
37
|
-
let value = presentation.applicationVariables[
|
|
39
|
+
let value = presentation.applicationVariables[queryParamName];
|
|
38
40
|
if (value === undefined) value = '';
|
|
39
|
-
if (
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
value = JSON.stringify(value);
|
|
43
|
+
}
|
|
44
|
+
if (shouldEncodeValue) {
|
|
45
|
+
value = encodeURIComponent(value);
|
|
46
|
+
}
|
|
40
47
|
|
|
41
|
-
url = url.replace(
|
|
48
|
+
url = url.replace(queryParamVariableName, value);
|
|
42
49
|
});
|
|
43
50
|
|
|
44
51
|
return url;
|