@pwrdrvr/microapps-router-lib 0.4.0-alpha.8 → 1.0.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/app-cache.d.ts +58 -0
- package/dist/app-cache.d.ts.map +1 -0
- package/dist/app-cache.js +154 -0
- package/dist/app-cache.js.map +1 -0
- package/dist/get-app-info.d.ts +9 -0
- package/dist/get-app-info.d.ts.map +1 -0
- package/dist/get-app-info.js +25 -0
- package/dist/get-app-info.js.map +1 -0
- package/dist/get-route.d.ts +83 -0
- package/dist/get-route.d.ts.map +1 -0
- package/dist/get-route.js +154 -0
- package/dist/get-route.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/log.d.ts +5 -0
- package/dist/lib/log.d.ts.map +1 -0
- package/dist/lib/log.js +11 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/load-app-frame.d.ts +8 -0
- package/dist/load-app-frame.d.ts.map +1 -0
- package/dist/load-app-frame.js +38 -0
- package/dist/load-app-frame.js.map +1 -0
- package/dist/normalize-path-prefix.d.ts +8 -0
- package/dist/normalize-path-prefix.d.ts.map +1 -0
- package/dist/normalize-path-prefix.js +21 -0
- package/dist/normalize-path-prefix.js.map +1 -0
- package/dist/redirect-default-file.d.ts +18 -0
- package/dist/redirect-default-file.d.ts.map +1 -0
- package/dist/redirect-default-file.js +54 -0
- package/dist/redirect-default-file.js.map +1 -0
- package/dist/route-app.d.ts +23 -0
- package/dist/route-app.d.ts.map +1 -0
- package/dist/route-app.js +169 -0
- package/dist/route-app.js.map +1 -0
- package/package.json +5 -2
- package/src/app-cache.spec.ts +175 -0
- package/src/app-cache.ts +193 -0
- package/src/get-app-info.spec.ts +77 -0
- package/src/get-app-info.ts +31 -0
- package/src/get-route.spec.ts +585 -0
- package/src/get-route.ts +267 -0
- package/src/index.ts +5 -536
- package/src/load-app-frame.spec.ts +51 -0
- package/src/load-app-frame.ts +36 -0
- package/src/normalize-path-prefix.spec.ts +27 -0
- package/src/normalize-path-prefix.ts +18 -0
- package/src/redirect-default-file.spec.ts +98 -0
- package/src/redirect-default-file.ts +79 -0
- package/src/route-app.spec.ts +128 -0
- package/src/route-app.ts +202 -0
- package/src/index.spec.ts +0 -318
- /package/src/{index.prefix.spec.ts → get-route.prefix.spec.ts} +0 -0
package/src/index.spec.ts
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
|
-
import 'jest-dynalite/withDb';
|
|
3
|
-
import * as dynamodb from '@aws-sdk/client-dynamodb';
|
|
4
|
-
import { Application, DBManager, Version, Rules } from '@pwrdrvr/microapps-datalib';
|
|
5
|
-
import { GetRoute } from './index';
|
|
6
|
-
|
|
7
|
-
let dynamoClient: dynamodb.DynamoDBClient;
|
|
8
|
-
let dbManager: DBManager;
|
|
9
|
-
|
|
10
|
-
const TEST_TABLE_NAME = 'microapps';
|
|
11
|
-
|
|
12
|
-
describe('router - without prefix', () => {
|
|
13
|
-
beforeAll(() => {
|
|
14
|
-
dynamoClient = new dynamodb.DynamoDBClient({
|
|
15
|
-
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
|
|
16
|
-
tls: false,
|
|
17
|
-
region: 'local',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
// Init the DB manager to point it at the right table
|
|
21
|
-
dbManager = new DBManager({ dynamoClient, tableName: TEST_TABLE_NAME });
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should serve appframe with version and default file substitued', async () => {
|
|
25
|
-
const app = new Application({
|
|
26
|
-
AppName: 'Bat',
|
|
27
|
-
DisplayName: 'Bat App',
|
|
28
|
-
});
|
|
29
|
-
await app.Save(dbManager);
|
|
30
|
-
|
|
31
|
-
const version = new Version({
|
|
32
|
-
AppName: 'Bat',
|
|
33
|
-
DefaultFile: 'bat.html',
|
|
34
|
-
IntegrationID: 'abcd',
|
|
35
|
-
SemVer: '3.2.1-beta.1',
|
|
36
|
-
Status: 'deployed',
|
|
37
|
-
Type: 'lambda',
|
|
38
|
-
});
|
|
39
|
-
await version.Save(dbManager);
|
|
40
|
-
|
|
41
|
-
const rules = new Rules({
|
|
42
|
-
AppName: 'Bat',
|
|
43
|
-
Version: 0,
|
|
44
|
-
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
45
|
-
});
|
|
46
|
-
await rules.Save(dbManager);
|
|
47
|
-
|
|
48
|
-
// Call the handler
|
|
49
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/' });
|
|
50
|
-
|
|
51
|
-
expect(response).toHaveProperty('statusCode');
|
|
52
|
-
expect(response.statusCode).toBe(200);
|
|
53
|
-
expect(response).toBeDefined();
|
|
54
|
-
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('static app - request to app/x.y.z should redirect to defaultFile', async () => {
|
|
58
|
-
const app = new Application({
|
|
59
|
-
AppName: 'Bat',
|
|
60
|
-
DisplayName: 'Bat App',
|
|
61
|
-
});
|
|
62
|
-
await app.Save(dbManager);
|
|
63
|
-
|
|
64
|
-
const version = new Version({
|
|
65
|
-
AppName: 'Bat',
|
|
66
|
-
DefaultFile: 'bat.html',
|
|
67
|
-
IntegrationID: 'abcd',
|
|
68
|
-
SemVer: '3.2.1-beta.1',
|
|
69
|
-
Status: 'deployed',
|
|
70
|
-
Type: 'static',
|
|
71
|
-
});
|
|
72
|
-
await version.Save(dbManager);
|
|
73
|
-
|
|
74
|
-
const rules = new Rules({
|
|
75
|
-
AppName: 'Bat',
|
|
76
|
-
Version: 0,
|
|
77
|
-
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
78
|
-
});
|
|
79
|
-
await rules.Save(dbManager);
|
|
80
|
-
|
|
81
|
-
// Call the handler
|
|
82
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.1' });
|
|
83
|
-
|
|
84
|
-
expect(response).toHaveProperty('statusCode');
|
|
85
|
-
expect(response.statusCode).toBe(302);
|
|
86
|
-
expect(response.redirectLocation).toBeDefined();
|
|
87
|
-
expect(response.redirectLocation).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
88
|
-
}, 60000);
|
|
89
|
-
|
|
90
|
-
it('static app - request to app/x.y.z/ should not redirect if no defaultFile', async () => {
|
|
91
|
-
const app = new Application({
|
|
92
|
-
AppName: 'Bat',
|
|
93
|
-
DisplayName: 'Bat App',
|
|
94
|
-
});
|
|
95
|
-
await app.Save(dbManager);
|
|
96
|
-
|
|
97
|
-
const version = new Version({
|
|
98
|
-
AppName: 'Bat',
|
|
99
|
-
IntegrationID: 'abcd',
|
|
100
|
-
SemVer: '3.2.1-beta.1',
|
|
101
|
-
Status: 'deployed',
|
|
102
|
-
Type: 'static',
|
|
103
|
-
});
|
|
104
|
-
await version.Save(dbManager);
|
|
105
|
-
|
|
106
|
-
const rules = new Rules({
|
|
107
|
-
AppName: 'Bat',
|
|
108
|
-
Version: 0,
|
|
109
|
-
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
110
|
-
});
|
|
111
|
-
await rules.Save(dbManager);
|
|
112
|
-
|
|
113
|
-
// Call the handler
|
|
114
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.1/' });
|
|
115
|
-
|
|
116
|
-
expect(response).toHaveProperty('appName');
|
|
117
|
-
expect(response.appName).toBe('bat');
|
|
118
|
-
expect(response).toHaveProperty('semVer');
|
|
119
|
-
expect(response.semVer).toBe('3.2.1-beta.1');
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('static app - request to app/x.y.z/ should redirect to defaultFile', async () => {
|
|
123
|
-
const app = new Application({
|
|
124
|
-
AppName: 'Bat',
|
|
125
|
-
DisplayName: 'Bat App',
|
|
126
|
-
});
|
|
127
|
-
await app.Save(dbManager);
|
|
128
|
-
|
|
129
|
-
const version = new Version({
|
|
130
|
-
AppName: 'Bat',
|
|
131
|
-
DefaultFile: 'bat.html',
|
|
132
|
-
IntegrationID: 'abcd',
|
|
133
|
-
SemVer: '3.2.1-beta.1',
|
|
134
|
-
Status: 'deployed',
|
|
135
|
-
Type: 'static',
|
|
136
|
-
});
|
|
137
|
-
await version.Save(dbManager);
|
|
138
|
-
|
|
139
|
-
const rules = new Rules({
|
|
140
|
-
AppName: 'Bat',
|
|
141
|
-
Version: 0,
|
|
142
|
-
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
143
|
-
});
|
|
144
|
-
await rules.Save(dbManager);
|
|
145
|
-
|
|
146
|
-
// Call the handler
|
|
147
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.1/' });
|
|
148
|
-
|
|
149
|
-
expect(response).toHaveProperty('statusCode');
|
|
150
|
-
expect(response.statusCode).toBe(302);
|
|
151
|
-
expect(response.redirectLocation).toBeDefined();
|
|
152
|
-
expect(response.redirectLocation).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it('static app - request to app/notVersion should load app frame with defaultFile', async () => {
|
|
156
|
-
const app = new Application({
|
|
157
|
-
AppName: 'Bat',
|
|
158
|
-
DisplayName: 'Bat App',
|
|
159
|
-
});
|
|
160
|
-
await app.Save(dbManager);
|
|
161
|
-
|
|
162
|
-
const version = new Version({
|
|
163
|
-
AppName: 'Bat',
|
|
164
|
-
DefaultFile: 'bat.html',
|
|
165
|
-
IntegrationID: 'abcd',
|
|
166
|
-
SemVer: '3.2.1-beta.1',
|
|
167
|
-
Status: 'deployed',
|
|
168
|
-
Type: 'static',
|
|
169
|
-
});
|
|
170
|
-
await version.Save(dbManager);
|
|
171
|
-
|
|
172
|
-
const rules = new Rules({
|
|
173
|
-
AppName: 'Bat',
|
|
174
|
-
Version: 0,
|
|
175
|
-
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
176
|
-
});
|
|
177
|
-
await rules.Save(dbManager);
|
|
178
|
-
|
|
179
|
-
// Call the handler
|
|
180
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/notVersion' });
|
|
181
|
-
|
|
182
|
-
expect(response).toHaveProperty('statusCode');
|
|
183
|
-
expect(response.statusCode).toBe(200);
|
|
184
|
-
expect(response).toBeDefined();
|
|
185
|
-
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('should serve appframe with no default file', async () => {
|
|
189
|
-
const app = new Application({
|
|
190
|
-
AppName: 'Bat',
|
|
191
|
-
DisplayName: 'Bat App',
|
|
192
|
-
});
|
|
193
|
-
await app.Save(dbManager);
|
|
194
|
-
|
|
195
|
-
const version = new Version({
|
|
196
|
-
AppName: 'Bat',
|
|
197
|
-
DefaultFile: '',
|
|
198
|
-
IntegrationID: 'abcd',
|
|
199
|
-
SemVer: '3.2.1-beta1',
|
|
200
|
-
Status: 'deployed',
|
|
201
|
-
Type: 'lambda',
|
|
202
|
-
});
|
|
203
|
-
await version.Save(dbManager);
|
|
204
|
-
|
|
205
|
-
const rules = new Rules({
|
|
206
|
-
AppName: 'Bat',
|
|
207
|
-
Version: 0,
|
|
208
|
-
RuleSet: { default: { SemVer: '3.2.1-beta1', AttributeName: '', AttributeValue: '' } },
|
|
209
|
-
});
|
|
210
|
-
await rules.Save(dbManager);
|
|
211
|
-
|
|
212
|
-
// Call the handler
|
|
213
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/' });
|
|
214
|
-
|
|
215
|
-
expect(response).toBeDefined();
|
|
216
|
-
expect(response).toHaveProperty('statusCode');
|
|
217
|
-
expect(response.statusCode).toBe(200);
|
|
218
|
-
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta1');
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should serve appframe with sub-route', async () => {
|
|
222
|
-
const app = new Application({
|
|
223
|
-
AppName: 'Bat',
|
|
224
|
-
DisplayName: 'Bat App',
|
|
225
|
-
});
|
|
226
|
-
await app.Save(dbManager);
|
|
227
|
-
|
|
228
|
-
const version = new Version({
|
|
229
|
-
AppName: 'Bat',
|
|
230
|
-
DefaultFile: '',
|
|
231
|
-
IntegrationID: 'abcd',
|
|
232
|
-
SemVer: '3.2.1-beta2',
|
|
233
|
-
Status: 'deployed',
|
|
234
|
-
Type: 'lambda',
|
|
235
|
-
});
|
|
236
|
-
await version.Save(dbManager);
|
|
237
|
-
|
|
238
|
-
const rules = new Rules({
|
|
239
|
-
AppName: 'Bat',
|
|
240
|
-
Version: 0,
|
|
241
|
-
RuleSet: { default: { SemVer: '3.2.1-beta2', AttributeName: '', AttributeValue: '' } },
|
|
242
|
-
});
|
|
243
|
-
await rules.Save(dbManager);
|
|
244
|
-
|
|
245
|
-
// Call the handler
|
|
246
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/demo/grid' });
|
|
247
|
-
|
|
248
|
-
expect(response).toBeDefined();
|
|
249
|
-
expect(response).toHaveProperty('statusCode');
|
|
250
|
-
expect(response.statusCode).toBe(200);
|
|
251
|
-
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta2/demo/grid');
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should serve appframe with sub-route', async () => {
|
|
255
|
-
const app = new Application({
|
|
256
|
-
AppName: 'Bat',
|
|
257
|
-
DisplayName: 'Bat App',
|
|
258
|
-
});
|
|
259
|
-
await app.Save(dbManager);
|
|
260
|
-
|
|
261
|
-
const version = new Version({
|
|
262
|
-
AppName: 'Bat',
|
|
263
|
-
DefaultFile: 'someFile.html',
|
|
264
|
-
IntegrationID: 'abcd',
|
|
265
|
-
SemVer: '3.2.1-beta3',
|
|
266
|
-
Status: 'deployed',
|
|
267
|
-
Type: 'lambda',
|
|
268
|
-
});
|
|
269
|
-
await version.Save(dbManager);
|
|
270
|
-
|
|
271
|
-
const rules = new Rules({
|
|
272
|
-
AppName: 'Bat',
|
|
273
|
-
Version: 0,
|
|
274
|
-
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
275
|
-
});
|
|
276
|
-
await rules.Save(dbManager);
|
|
277
|
-
|
|
278
|
-
// Call the handler
|
|
279
|
-
const response = await GetRoute({ dbManager, rawPath: '/bat/demo' });
|
|
280
|
-
|
|
281
|
-
expect(response).toBeDefined();
|
|
282
|
-
expect(response).toHaveProperty('statusCode');
|
|
283
|
-
expect(response.statusCode).toBe(200);
|
|
284
|
-
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta3/demo');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('should return 404 for /favicon.ico', async () => {
|
|
288
|
-
const app = new Application({
|
|
289
|
-
AppName: 'Bat',
|
|
290
|
-
DisplayName: 'Bat App',
|
|
291
|
-
});
|
|
292
|
-
await app.Save(dbManager);
|
|
293
|
-
|
|
294
|
-
const version = new Version({
|
|
295
|
-
AppName: 'Bat',
|
|
296
|
-
DefaultFile: 'someFile.html',
|
|
297
|
-
IntegrationID: 'abcd',
|
|
298
|
-
SemVer: '3.2.1-beta3',
|
|
299
|
-
Status: 'deployed',
|
|
300
|
-
Type: 'lambda',
|
|
301
|
-
});
|
|
302
|
-
await version.Save(dbManager);
|
|
303
|
-
|
|
304
|
-
const rules = new Rules({
|
|
305
|
-
AppName: 'Bat',
|
|
306
|
-
Version: 0,
|
|
307
|
-
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
308
|
-
});
|
|
309
|
-
await rules.Save(dbManager);
|
|
310
|
-
|
|
311
|
-
// Call the handler
|
|
312
|
-
const response = await GetRoute({ dbManager, rawPath: '/favicon.ico' });
|
|
313
|
-
|
|
314
|
-
expect(response).toBeDefined();
|
|
315
|
-
expect(response).toHaveProperty('statusCode');
|
|
316
|
-
expect(response.statusCode).toBe(404);
|
|
317
|
-
});
|
|
318
|
-
});
|
|
File without changes
|