@raydiant/playlist-window-manager 0.18.0 → 0.19.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/build/PresentationWindow.d.ts +1 -0
- package/build/PresentationWindow.js +13 -3
- package/build/embeddedApps.d.ts +2 -2
- package/build/embeddedApps.js +26 -15
- package/build/embeddedApps.test.js +53 -17
- package/build/types.d.ts +3 -0
- package/package.json +1 -1
- package/src/PresentationWindow.ts +21 -4
- package/src/embeddedApps.test.ts +80 -12
- package/src/embeddedApps.ts +33 -20
- package/src/types.ts +4 -0
|
@@ -101,6 +101,7 @@ export default class PresentationWindow {
|
|
|
101
101
|
private closeChildWindow;
|
|
102
102
|
private enableInteruptLock;
|
|
103
103
|
private disableInteruptLock;
|
|
104
|
+
private getEmbeddedAppUrl;
|
|
104
105
|
private handleEmbeddedMessage;
|
|
105
106
|
private handleLegacyMessage;
|
|
106
107
|
private handleReady;
|
|
@@ -449,7 +449,7 @@ var PresentationWindow = /** @class */ (function () {
|
|
|
449
449
|
_a = this.options, applicationVersion = _a.applicationVersion, windowId = _a.windowId;
|
|
450
450
|
if (!this.isEmbeddedApp()) return [3 /*break*/, 3];
|
|
451
451
|
if (!applicationVersion.embeddedUrlFormat) return [3 /*break*/, 2];
|
|
452
|
-
url =
|
|
452
|
+
url = this.getEmbeddedAppUrl();
|
|
453
453
|
this.logInfo("Reload window '" + windowId + "' for embedded app url '" + url + "'");
|
|
454
454
|
return [4 /*yield*/, this.loadWindow(url)];
|
|
455
455
|
case 1:
|
|
@@ -466,7 +466,11 @@ var PresentationWindow = /** @class */ (function () {
|
|
|
466
466
|
});
|
|
467
467
|
};
|
|
468
468
|
PresentationWindow.prototype.runGetProperties = function (builderState) {
|
|
469
|
-
|
|
469
|
+
// Do no support conditional properties for embedded apps. We will likely
|
|
470
|
+
// change the way conditional properties work.
|
|
471
|
+
if (!this.isEmbeddedApp()) {
|
|
472
|
+
this.sendMessage('run_get_properties', builderState);
|
|
473
|
+
}
|
|
470
474
|
};
|
|
471
475
|
PresentationWindow.prototype.isEmbeddedApp = function () {
|
|
472
476
|
var _a = this.options, applicationVersion = _a.applicationVersion, isPreview = _a.isPreview;
|
|
@@ -517,7 +521,7 @@ var PresentationWindow = /** @class */ (function () {
|
|
|
517
521
|
if (!applicationVersion.embeddedUrlFormat) {
|
|
518
522
|
throw new Error("Error loading embedded app, missing embeddedUrlFormat for '" + applicationVersion.id + "'");
|
|
519
523
|
}
|
|
520
|
-
url =
|
|
524
|
+
url = this.getEmbeddedAppUrl();
|
|
521
525
|
this.logInfo("Create window '" + windowId + "' for embedded app url '" + url + "'");
|
|
522
526
|
return [4 /*yield*/, this.createAndLoadWindow(this.appendWindowIdToHash(url, windowId),
|
|
523
527
|
// Embedded apps should not have a backgroundColor because some sites expect
|
|
@@ -827,6 +831,12 @@ var PresentationWindow = /** @class */ (function () {
|
|
|
827
831
|
this.disableInterruptLockCallback();
|
|
828
832
|
}
|
|
829
833
|
};
|
|
834
|
+
PresentationWindow.prototype.getEmbeddedAppUrl = function () {
|
|
835
|
+
var metadata = {
|
|
836
|
+
renderMode: this.options.isPreview ? 'preview' : 'live'
|
|
837
|
+
};
|
|
838
|
+
return embeddedApps_1.default(this.presentation, this.options.applicationVersion, metadata);
|
|
839
|
+
};
|
|
830
840
|
PresentationWindow.prototype.handleReady = function () {
|
|
831
841
|
this.didReceiveReady = true;
|
|
832
842
|
this.checkIsReadyCallback();
|
package/build/embeddedApps.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Presentation, ApplicationVersion } from './types';
|
|
2
|
-
export default function createEmbeddedApp(presentation: Presentation, applicationVersion: ApplicationVersion): string;
|
|
1
|
+
import { Presentation, ApplicationVersion, EmbeddedAppMetadata } from './types';
|
|
2
|
+
export default function createEmbeddedApp(presentation: Presentation, applicationVersion: ApplicationVersion, metadata: EmbeddedAppMetadata): string;
|
package/build/embeddedApps.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
function createEmbeddedApp(presentation, applicationVersion) {
|
|
3
|
+
function createEmbeddedApp(presentation, applicationVersion, metadata) {
|
|
4
4
|
// build matches
|
|
5
|
-
var parameterRegex = /(:([\w
|
|
5
|
+
var parameterRegex = /(:([\w-\$]+))(.?$|[^\w-\$])/gm;
|
|
6
6
|
var matches = [];
|
|
7
7
|
var match = null;
|
|
8
8
|
do {
|
|
@@ -17,19 +17,30 @@ function createEmbeddedApp(presentation, applicationVersion) {
|
|
|
17
17
|
var queryParamVariableName = m[1]; // Where the value of your input will be injected. E.g. ":location"
|
|
18
18
|
var queryParamName = m[2]; // The query param name. E.g. "location"
|
|
19
19
|
var _a = queryParamVariableName.split(':'), variableName = _a[1];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
20
|
+
var shouldEncodeValue = true;
|
|
21
|
+
var value = '';
|
|
22
|
+
if (variableName.charAt(0) === '$') {
|
|
23
|
+
var metadataKey = variableName.slice(1);
|
|
24
|
+
if (metadataKey === 'renderMode') {
|
|
25
|
+
value = metadata.renderMode;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Don't replace variables that are numbers to allow setting
|
|
30
|
+
// port numbers in the embedded app url.
|
|
31
|
+
if (!isNaN(Number(variableName)))
|
|
32
|
+
return;
|
|
33
|
+
var presentationProperty = applicationVersion.presentationProperties.find(function (p) { return p.name === variableName; });
|
|
34
|
+
// If the presentation property is not found (this shouldn't happen), default to encoding the value.
|
|
35
|
+
// Otherwise, only skip encoding if the presentation property's encode property is false.
|
|
36
|
+
shouldEncodeValue =
|
|
37
|
+
!presentationProperty || presentationProperty.encode !== false;
|
|
38
|
+
value = presentation.applicationVariables[queryParamName];
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
value = '';
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
value = JSON.stringify(value);
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
45
|
if (shouldEncodeValue) {
|
|
35
46
|
value = encodeURIComponent(value);
|
|
@@ -15,50 +15,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
var embeddedApps_1 = __importDefault(require("./embeddedApps"));
|
|
18
|
-
var createPresentation = function (overrides) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
var createPresentation = function (overrides) {
|
|
19
|
+
if (overrides === void 0) { overrides = {}; }
|
|
20
|
+
return (__assign({ id: 'id', name: 'name', applicationDeploymentId: 'applicationDeploymentId', themeId: null, applicationVariables: {}, duration: 0, r: {
|
|
21
|
+
resource: {
|
|
22
|
+
updatedAt: '',
|
|
23
|
+
createdAt: ''
|
|
24
|
+
},
|
|
25
|
+
presentationsPlaylists: []
|
|
26
|
+
} }, overrides));
|
|
27
|
+
};
|
|
28
|
+
var createApplicationVersion = function (overrides) {
|
|
29
|
+
if (overrides === void 0) { overrides = {}; }
|
|
30
|
+
return (__assign({ id: 'id', name: 'name', applicationId: 'applicationId', embeddedUrlFormat: null, configurableDuration: false, sourceUrl: null, presentationProperties: [] }, overrides));
|
|
31
|
+
};
|
|
32
|
+
var createMetadata = function (overrides) {
|
|
33
|
+
if (overrides === void 0) { overrides = {}; }
|
|
34
|
+
return (__assign({ renderMode: 'live' }, overrides));
|
|
35
|
+
};
|
|
26
36
|
test('Replaces variable in query parameteers', function () {
|
|
27
37
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: 'bar' } }), createApplicationVersion({
|
|
28
38
|
embeddedUrlFormat: 'https://example.com?foo=:foo'
|
|
29
|
-
}))).toBe('https://example.com?foo=bar');
|
|
39
|
+
}), createMetadata())).toBe('https://example.com?foo=bar');
|
|
30
40
|
});
|
|
31
41
|
test('Replaces variable in path', function () {
|
|
32
42
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: 'bar' } }), createApplicationVersion({
|
|
33
43
|
embeddedUrlFormat: 'https://example.com/:foo'
|
|
34
|
-
}))).toBe('https://example.com/bar');
|
|
44
|
+
}), createMetadata())).toBe('https://example.com/bar');
|
|
35
45
|
});
|
|
36
46
|
test('Replaces undefined variable with empty string', function () {
|
|
37
47
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: {} }), createApplicationVersion({
|
|
38
48
|
embeddedUrlFormat: 'https://example.com/:foo'
|
|
39
|
-
}))).toBe('https://example.com/');
|
|
49
|
+
}), createMetadata())).toBe('https://example.com/');
|
|
40
50
|
});
|
|
41
51
|
test('Replaces variable with underscore', function () {
|
|
42
52
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo_1: 'bar' } }), createApplicationVersion({
|
|
43
53
|
embeddedUrlFormat: 'https://example.com/:foo_1'
|
|
44
|
-
}))).toBe('https://example.com/bar');
|
|
54
|
+
}), createMetadata())).toBe('https://example.com/bar');
|
|
45
55
|
});
|
|
46
56
|
test('Replaces variable with hyphen', function () {
|
|
47
57
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { 'foo-1': 'bar' } }), createApplicationVersion({
|
|
48
58
|
embeddedUrlFormat: 'https://example.com/:foo-1'
|
|
49
|
-
}))).toBe('https://example.com/bar');
|
|
59
|
+
}), createMetadata())).toBe('https://example.com/bar');
|
|
50
60
|
});
|
|
51
61
|
test('Does not replace variable that is a number', function () {
|
|
52
62
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: 'bar' } }), createApplicationVersion({
|
|
53
63
|
embeddedUrlFormat: 'http://localhost:8080?foo=:foo'
|
|
54
|
-
}))).toBe('http://localhost:8080?foo=bar');
|
|
64
|
+
}), createMetadata())).toBe('http://localhost:8080?foo=bar');
|
|
55
65
|
});
|
|
56
66
|
test('Encodes a variables containing special characters', function () {
|
|
57
67
|
var fooValue = 'Lorem Ipsum. !@#$%^&*()-. More Text';
|
|
58
68
|
var fooValueEncoded = 'Lorem%20Ipsum.%20!%40%23%24%25%5E%26*()-.%20More%20Text';
|
|
59
69
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: fooValue } }), createApplicationVersion({
|
|
60
70
|
embeddedUrlFormat: "http://localhost:8080?foo=:foo"
|
|
61
|
-
}))).toBe("http://localhost:8080?foo=" + fooValueEncoded);
|
|
71
|
+
}), createMetadata())).toBe("http://localhost:8080?foo=" + fooValueEncoded);
|
|
62
72
|
});
|
|
63
73
|
test('Does not encode value if presentation property disables encoding', function () {
|
|
64
74
|
expect(embeddedApps_1.default(createPresentation({
|
|
@@ -66,12 +76,38 @@ test('Does not encode value if presentation property disables encoding', functio
|
|
|
66
76
|
}), createApplicationVersion({
|
|
67
77
|
embeddedUrlFormat: ":url",
|
|
68
78
|
presentationProperties: [{ name: 'url', encode: false }]
|
|
69
|
-
}))).toBe("https://raydiant.com");
|
|
79
|
+
}), createMetadata())).toBe("https://raydiant.com");
|
|
70
80
|
});
|
|
71
81
|
test('Encodes a variables containing an array', function () {
|
|
72
82
|
var fooValue = ['option-a', 'option-b', 'option-c'];
|
|
73
83
|
var fooValueEncoded = '%5B%22option-a%22%2C%22option-b%22%2C%22option-c%22%5D';
|
|
74
84
|
expect(embeddedApps_1.default(createPresentation({ applicationVariables: { foo: fooValue } }), createApplicationVersion({
|
|
75
85
|
embeddedUrlFormat: "http://localhost:8080?foo=:foo"
|
|
76
|
-
}))).toBe("http://localhost:8080?foo=" + fooValueEncoded);
|
|
86
|
+
}), createMetadata())).toBe("http://localhost:8080?foo=" + fooValueEncoded);
|
|
87
|
+
});
|
|
88
|
+
test('Replaces $renderMode with metadata', function () {
|
|
89
|
+
var presentation = createPresentation();
|
|
90
|
+
var applicationVersion = createApplicationVersion({
|
|
91
|
+
embeddedUrlFormat: 'https://example.com?renderMode=:$renderMode'
|
|
92
|
+
});
|
|
93
|
+
expect(embeddedApps_1.default(presentation, applicationVersion, createMetadata({ renderMode: 'preview' }))).toBe('https://example.com?renderMode=preview');
|
|
94
|
+
expect(embeddedApps_1.default(presentation, applicationVersion, createMetadata({ renderMode: 'live' }))).toBe('https://example.com?renderMode=live');
|
|
95
|
+
});
|
|
96
|
+
test('Replaces undefined metadata with empty string', function () {
|
|
97
|
+
var presentation = createPresentation();
|
|
98
|
+
var applicationVersion = createApplicationVersion({
|
|
99
|
+
embeddedUrlFormat: 'https://example.com?invalid=:$invalid'
|
|
100
|
+
});
|
|
101
|
+
expect(embeddedApps_1.default(presentation, applicationVersion, createMetadata())).toBe('https://example.com?invalid=');
|
|
102
|
+
});
|
|
103
|
+
test('Replace protocol, ip and port', function () {
|
|
104
|
+
expect(embeddedApps_1.default(createPresentation({
|
|
105
|
+
applicationVariables: {
|
|
106
|
+
protocol: 'http',
|
|
107
|
+
ip: '192.168.1.0',
|
|
108
|
+
port: 3000
|
|
109
|
+
}
|
|
110
|
+
}), createApplicationVersion({
|
|
111
|
+
embeddedUrlFormat: ":protocol://:ip::port"
|
|
112
|
+
}), createMetadata())).toBe("http://192.168.1.0:3000");
|
|
77
113
|
});
|
package/build/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -15,7 +15,8 @@ import {
|
|
|
15
15
|
Logger,
|
|
16
16
|
OpenChildWindowOptions,
|
|
17
17
|
BuilderState,
|
|
18
|
-
WorkerState
|
|
18
|
+
WorkerState,
|
|
19
|
+
EmbeddedAppMetadata
|
|
19
20
|
} from './types';
|
|
20
21
|
|
|
21
22
|
export interface PresentationWindowOptions {
|
|
@@ -324,7 +325,7 @@ export default class PresentationWindow {
|
|
|
324
325
|
|
|
325
326
|
if (this.isEmbeddedApp()) {
|
|
326
327
|
if (applicationVersion.embeddedUrlFormat) {
|
|
327
|
-
const url =
|
|
328
|
+
const url = this.getEmbeddedAppUrl();
|
|
328
329
|
|
|
329
330
|
this.logInfo(
|
|
330
331
|
`Reload window '${windowId}' for embedded app url '${url}'`
|
|
@@ -338,7 +339,11 @@ export default class PresentationWindow {
|
|
|
338
339
|
}
|
|
339
340
|
|
|
340
341
|
public runGetProperties(builderState?: BuilderState) {
|
|
341
|
-
|
|
342
|
+
// Do no support conditional properties for embedded apps. We will likely
|
|
343
|
+
// change the way conditional properties work.
|
|
344
|
+
if (!this.isEmbeddedApp()) {
|
|
345
|
+
this.sendMessage('run_get_properties', builderState);
|
|
346
|
+
}
|
|
342
347
|
}
|
|
343
348
|
|
|
344
349
|
private isEmbeddedApp() {
|
|
@@ -399,7 +404,7 @@ export default class PresentationWindow {
|
|
|
399
404
|
);
|
|
400
405
|
}
|
|
401
406
|
|
|
402
|
-
const url =
|
|
407
|
+
const url = this.getEmbeddedAppUrl();
|
|
403
408
|
this.logInfo(`Create window '${windowId}' for embedded app url '${url}'`);
|
|
404
409
|
|
|
405
410
|
await this.createAndLoadWindow(
|
|
@@ -735,6 +740,18 @@ export default class PresentationWindow {
|
|
|
735
740
|
}
|
|
736
741
|
}
|
|
737
742
|
|
|
743
|
+
private getEmbeddedAppUrl() {
|
|
744
|
+
const metadata: EmbeddedAppMetadata = {
|
|
745
|
+
renderMode: this.options.isPreview ? 'preview' : 'live'
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
return createEmbeddedApp(
|
|
749
|
+
this.presentation,
|
|
750
|
+
this.options.applicationVersion,
|
|
751
|
+
metadata
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
|
|
738
755
|
private handleEmbeddedMessage = async (type: string, payload?: any) => {
|
|
739
756
|
const { windowId } = this.options;
|
|
740
757
|
|
package/src/embeddedApps.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import createEmbeddedApp from './embeddedApps';
|
|
2
|
-
import { Presentation, ApplicationVersion } from './types';
|
|
2
|
+
import { Presentation, ApplicationVersion, EmbeddedAppMetadata } from './types';
|
|
3
3
|
|
|
4
4
|
const createPresentation = (
|
|
5
|
-
overrides: Partial<Presentation>
|
|
5
|
+
overrides: Partial<Presentation> = {}
|
|
6
6
|
): Presentation => ({
|
|
7
7
|
id: 'id',
|
|
8
8
|
name: 'name',
|
|
@@ -21,7 +21,7 @@ const createPresentation = (
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
const createApplicationVersion = (
|
|
24
|
-
overrides: Partial<ApplicationVersion>
|
|
24
|
+
overrides: Partial<ApplicationVersion> = {}
|
|
25
25
|
): ApplicationVersion => ({
|
|
26
26
|
id: 'id',
|
|
27
27
|
name: 'name',
|
|
@@ -33,13 +33,21 @@ const createApplicationVersion = (
|
|
|
33
33
|
...overrides
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
const createMetadata = (
|
|
37
|
+
overrides: Partial<EmbeddedAppMetadata> = {}
|
|
38
|
+
): EmbeddedAppMetadata => ({
|
|
39
|
+
renderMode: 'live',
|
|
40
|
+
...overrides
|
|
41
|
+
});
|
|
42
|
+
|
|
36
43
|
test('Replaces variable in query parameteers', () => {
|
|
37
44
|
expect(
|
|
38
45
|
createEmbeddedApp(
|
|
39
46
|
createPresentation({ applicationVariables: { foo: 'bar' } }),
|
|
40
47
|
createApplicationVersion({
|
|
41
48
|
embeddedUrlFormat: 'https://example.com?foo=:foo'
|
|
42
|
-
})
|
|
49
|
+
}),
|
|
50
|
+
createMetadata()
|
|
43
51
|
)
|
|
44
52
|
).toBe('https://example.com?foo=bar');
|
|
45
53
|
});
|
|
@@ -50,7 +58,8 @@ test('Replaces variable in path', () => {
|
|
|
50
58
|
createPresentation({ applicationVariables: { foo: 'bar' } }),
|
|
51
59
|
createApplicationVersion({
|
|
52
60
|
embeddedUrlFormat: 'https://example.com/:foo'
|
|
53
|
-
})
|
|
61
|
+
}),
|
|
62
|
+
createMetadata()
|
|
54
63
|
)
|
|
55
64
|
).toBe('https://example.com/bar');
|
|
56
65
|
});
|
|
@@ -61,7 +70,8 @@ test('Replaces undefined variable with empty string', () => {
|
|
|
61
70
|
createPresentation({ applicationVariables: {} }),
|
|
62
71
|
createApplicationVersion({
|
|
63
72
|
embeddedUrlFormat: 'https://example.com/:foo'
|
|
64
|
-
})
|
|
73
|
+
}),
|
|
74
|
+
createMetadata()
|
|
65
75
|
)
|
|
66
76
|
).toBe('https://example.com/');
|
|
67
77
|
});
|
|
@@ -72,7 +82,8 @@ test('Replaces variable with underscore', () => {
|
|
|
72
82
|
createPresentation({ applicationVariables: { foo_1: 'bar' } }),
|
|
73
83
|
createApplicationVersion({
|
|
74
84
|
embeddedUrlFormat: 'https://example.com/:foo_1'
|
|
75
|
-
})
|
|
85
|
+
}),
|
|
86
|
+
createMetadata()
|
|
76
87
|
)
|
|
77
88
|
).toBe('https://example.com/bar');
|
|
78
89
|
});
|
|
@@ -83,7 +94,8 @@ test('Replaces variable with hyphen', () => {
|
|
|
83
94
|
createPresentation({ applicationVariables: { 'foo-1': 'bar' } }),
|
|
84
95
|
createApplicationVersion({
|
|
85
96
|
embeddedUrlFormat: 'https://example.com/:foo-1'
|
|
86
|
-
})
|
|
97
|
+
}),
|
|
98
|
+
createMetadata()
|
|
87
99
|
)
|
|
88
100
|
).toBe('https://example.com/bar');
|
|
89
101
|
});
|
|
@@ -94,7 +106,8 @@ test('Does not replace variable that is a number', () => {
|
|
|
94
106
|
createPresentation({ applicationVariables: { foo: 'bar' } }),
|
|
95
107
|
createApplicationVersion({
|
|
96
108
|
embeddedUrlFormat: 'http://localhost:8080?foo=:foo'
|
|
97
|
-
})
|
|
109
|
+
}),
|
|
110
|
+
createMetadata()
|
|
98
111
|
)
|
|
99
112
|
).toBe('http://localhost:8080?foo=bar');
|
|
100
113
|
});
|
|
@@ -109,7 +122,8 @@ test('Encodes a variables containing special characters', () => {
|
|
|
109
122
|
createPresentation({ applicationVariables: { foo: fooValue } }),
|
|
110
123
|
createApplicationVersion({
|
|
111
124
|
embeddedUrlFormat: `http://localhost:8080?foo=:foo`
|
|
112
|
-
})
|
|
125
|
+
}),
|
|
126
|
+
createMetadata()
|
|
113
127
|
)
|
|
114
128
|
).toBe(`http://localhost:8080?foo=${fooValueEncoded}`);
|
|
115
129
|
});
|
|
@@ -123,7 +137,8 @@ test('Does not encode value if presentation property disables encoding', () => {
|
|
|
123
137
|
createApplicationVersion({
|
|
124
138
|
embeddedUrlFormat: `:url`,
|
|
125
139
|
presentationProperties: [{ name: 'url', encode: false }]
|
|
126
|
-
})
|
|
140
|
+
}),
|
|
141
|
+
createMetadata()
|
|
127
142
|
)
|
|
128
143
|
).toBe(`https://raydiant.com`);
|
|
129
144
|
});
|
|
@@ -138,7 +153,60 @@ test('Encodes a variables containing an array', () => {
|
|
|
138
153
|
createPresentation({ applicationVariables: { foo: fooValue } }),
|
|
139
154
|
createApplicationVersion({
|
|
140
155
|
embeddedUrlFormat: `http://localhost:8080?foo=:foo`
|
|
141
|
-
})
|
|
156
|
+
}),
|
|
157
|
+
createMetadata()
|
|
142
158
|
)
|
|
143
159
|
).toBe(`http://localhost:8080?foo=${fooValueEncoded}`);
|
|
144
160
|
});
|
|
161
|
+
|
|
162
|
+
test('Replaces $renderMode with metadata', () => {
|
|
163
|
+
const presentation = createPresentation();
|
|
164
|
+
const applicationVersion = createApplicationVersion({
|
|
165
|
+
embeddedUrlFormat: 'https://example.com?renderMode=:$renderMode'
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
expect(
|
|
169
|
+
createEmbeddedApp(
|
|
170
|
+
presentation,
|
|
171
|
+
applicationVersion,
|
|
172
|
+
createMetadata({ renderMode: 'preview' })
|
|
173
|
+
)
|
|
174
|
+
).toBe('https://example.com?renderMode=preview');
|
|
175
|
+
|
|
176
|
+
expect(
|
|
177
|
+
createEmbeddedApp(
|
|
178
|
+
presentation,
|
|
179
|
+
applicationVersion,
|
|
180
|
+
createMetadata({ renderMode: 'live' })
|
|
181
|
+
)
|
|
182
|
+
).toBe('https://example.com?renderMode=live');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test('Replaces undefined metadata with empty string', () => {
|
|
186
|
+
const presentation = createPresentation();
|
|
187
|
+
const applicationVersion = createApplicationVersion({
|
|
188
|
+
embeddedUrlFormat: 'https://example.com?invalid=:$invalid'
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
expect(
|
|
192
|
+
createEmbeddedApp(presentation, applicationVersion, createMetadata())
|
|
193
|
+
).toBe('https://example.com?invalid=');
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('Replace protocol, ip and port', () => {
|
|
197
|
+
expect(
|
|
198
|
+
createEmbeddedApp(
|
|
199
|
+
createPresentation({
|
|
200
|
+
applicationVariables: {
|
|
201
|
+
protocol: 'http',
|
|
202
|
+
ip: '192.168.1.0',
|
|
203
|
+
port: 3000
|
|
204
|
+
}
|
|
205
|
+
}),
|
|
206
|
+
createApplicationVersion({
|
|
207
|
+
embeddedUrlFormat: `:protocol://:ip::port`
|
|
208
|
+
}),
|
|
209
|
+
createMetadata()
|
|
210
|
+
)
|
|
211
|
+
).toBe(`http://192.168.1.0:3000`);
|
|
212
|
+
});
|
package/src/embeddedApps.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Presentation, ApplicationVersion } from './types';
|
|
1
|
+
import { Presentation, ApplicationVersion, EmbeddedAppMetadata } from './types';
|
|
2
2
|
|
|
3
3
|
export default function createEmbeddedApp(
|
|
4
4
|
presentation: Presentation,
|
|
5
|
-
applicationVersion: ApplicationVersion
|
|
5
|
+
applicationVersion: ApplicationVersion,
|
|
6
|
+
metadata: EmbeddedAppMetadata
|
|
6
7
|
) {
|
|
7
8
|
// build matches
|
|
8
|
-
const parameterRegex = /(:([\w
|
|
9
|
+
const parameterRegex = /(:([\w-\$]+))(.?$|[^\w-\$])/gm;
|
|
9
10
|
const matches = [];
|
|
10
11
|
let match = null;
|
|
11
12
|
do {
|
|
@@ -23,24 +24,36 @@ export default function createEmbeddedApp(
|
|
|
23
24
|
const queryParamName = m[2]; // The query param name. E.g. "location"
|
|
24
25
|
|
|
25
26
|
const [, variableName] = queryParamVariableName.split(':');
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
|
|
28
|
+
let shouldEncodeValue = true;
|
|
29
|
+
let value: any = '';
|
|
30
|
+
|
|
31
|
+
if (variableName.charAt(0) === '$') {
|
|
32
|
+
const metadataKey = variableName.slice(1);
|
|
33
|
+
if (metadataKey === 'renderMode') {
|
|
34
|
+
value = metadata.renderMode;
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
// Don't replace variables that are numbers to allow setting
|
|
38
|
+
// port numbers in the embedded app url.
|
|
39
|
+
if (!isNaN(Number(variableName))) return;
|
|
40
|
+
|
|
41
|
+
const presentationProperty = applicationVersion.presentationProperties.find(
|
|
42
|
+
p => p.name === variableName
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// If the presentation property is not found (this shouldn't happen), default to encoding the value.
|
|
46
|
+
// Otherwise, only skip encoding if the presentation property's encode property is false.
|
|
47
|
+
shouldEncodeValue =
|
|
48
|
+
!presentationProperty || presentationProperty.encode !== false;
|
|
49
|
+
|
|
50
|
+
value = presentation.applicationVariables[queryParamName];
|
|
51
|
+
if (value === undefined) value = '';
|
|
52
|
+
if (Array.isArray(value)) {
|
|
53
|
+
value = JSON.stringify(value);
|
|
54
|
+
}
|
|
43
55
|
}
|
|
56
|
+
|
|
44
57
|
if (shouldEncodeValue) {
|
|
45
58
|
value = encodeURIComponent(value);
|
|
46
59
|
}
|