@nymphjs/server 1.0.0-beta.23 → 1.0.0-beta.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.
@@ -55,4 +55,49 @@ export declare class Employee extends Entity<EmployeeData> {
55
55
  static throwErrorStatic(): Promise<any>;
56
56
  static inaccessibleMethod(): Promise<any>;
57
57
  }
58
- export default Employee;
58
+ export type RestrictedModelData = {
59
+ name: string;
60
+ };
61
+ export declare class RestrictedModel extends EntityServer<RestrictedModelData> {
62
+ static ETYPE: string;
63
+ static class: string;
64
+ static restEnabled: boolean;
65
+ static factory(guid?: string): Promise<RestrictedModel & RestrictedModelData>;
66
+ static factorySync(guid?: string): RestrictedModel & RestrictedModelData;
67
+ constructor(guid?: string);
68
+ $save(): Promise<boolean>;
69
+ $testMethod(value: string): string;
70
+ static testStatic(value: number): number;
71
+ }
72
+ export type RestrictedData = {
73
+ name: string;
74
+ };
75
+ export declare class Restricted extends Entity<RestrictedData> {
76
+ static class: string;
77
+ constructor(guid?: string);
78
+ static factory(guid?: string): Promise<Restricted & RestrictedData>;
79
+ static factorySync(guid?: string): Restricted & RestrictedData;
80
+ $testMethod(value: number): Promise<any>;
81
+ static testStatic(value: number): Promise<any>;
82
+ }
83
+ export type PubSubDisabledModelData = {
84
+ name: string;
85
+ };
86
+ export declare class PubSubDisabledModel extends EntityServer<PubSubDisabledModelData> {
87
+ static ETYPE: string;
88
+ static class: string;
89
+ static pubSubEnabled: boolean;
90
+ static factory(guid?: string): Promise<PubSubDisabledModel & PubSubDisabledModelData>;
91
+ static factorySync(guid?: string): PubSubDisabledModel & PubSubDisabledModelData;
92
+ constructor(guid?: string);
93
+ $save(): Promise<boolean>;
94
+ }
95
+ export type PubSubDisabledData = {
96
+ name: string;
97
+ };
98
+ export declare class PubSubDisabled extends Entity<PubSubDisabledData> {
99
+ static class: string;
100
+ constructor(guid?: string);
101
+ static factory(guid?: string): Promise<PubSubDisabled & PubSubDisabledData>;
102
+ static factorySync(guid?: string): PubSubDisabled & PubSubDisabledData;
103
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Employee = exports.BadFunctionCallError = exports.EmployeeModel = void 0;
3
+ exports.PubSubDisabled = exports.PubSubDisabledModel = exports.Restricted = exports.RestrictedModel = exports.Employee = exports.BadFunctionCallError = exports.EmployeeModel = void 0;
4
4
  const nymph_1 = require("@nymphjs/nymph");
5
5
  const client_1 = require("@nymphjs/client");
6
6
  const HttpError_1 = require("./HttpError");
@@ -49,10 +49,10 @@ class EmployeeModel extends nymph_1.Entity {
49
49
  }
50
50
  async $save() {
51
51
  const error = new nymph_1.EntityInvalidDataError('Invalid entity data.');
52
- if (this.$data.name == null || this.$data.name == '') {
52
+ if (this.$data.name == null || this.$data.name === '') {
53
53
  error.addField('name');
54
54
  }
55
- if (this.$data.title == null || this.$data.title == '') {
55
+ if (this.$data.title == null || this.$data.title === '') {
56
56
  error.addField('title');
57
57
  }
58
58
  if (this.$data.startDate == null) {
@@ -146,5 +146,104 @@ class Employee extends client_1.Entity {
146
146
  }
147
147
  Employee.class = 'Employee';
148
148
  exports.Employee = Employee;
149
- exports.default = Employee;
149
+ class RestrictedModel extends nymph_1.Entity {
150
+ static async factory(guid) {
151
+ return (await super.factory(guid));
152
+ }
153
+ static factorySync(guid) {
154
+ return super.factorySync(guid);
155
+ }
156
+ constructor(guid) {
157
+ super(guid);
158
+ if (this.guid == null) {
159
+ this.$data.name = '';
160
+ }
161
+ }
162
+ async $save() {
163
+ const error = new nymph_1.EntityInvalidDataError('Invalid entity data.');
164
+ if (this.$data.name == null || this.$data.name === '') {
165
+ error.addField('name');
166
+ }
167
+ if (error.getFields().length) {
168
+ throw error;
169
+ }
170
+ return await super.$save();
171
+ }
172
+ $testMethod(value) {
173
+ return value;
174
+ }
175
+ static testStatic(value) {
176
+ return value;
177
+ }
178
+ }
179
+ RestrictedModel.ETYPE = 'restricted';
180
+ RestrictedModel.class = 'Restricted';
181
+ RestrictedModel.restEnabled = false;
182
+ exports.RestrictedModel = RestrictedModel;
183
+ class Restricted extends client_1.Entity {
184
+ constructor(guid) {
185
+ super(guid);
186
+ if (guid == null) {
187
+ this.$data.name = '';
188
+ }
189
+ }
190
+ static async factory(guid) {
191
+ return (await super.factory(guid));
192
+ }
193
+ static factorySync(guid) {
194
+ return super.factorySync(guid);
195
+ }
196
+ $testMethod(value) {
197
+ return this.$serverCall('$testMethod', [value]);
198
+ }
199
+ static testStatic(value) {
200
+ return this.serverCallStatic('testStatic', [value]);
201
+ }
202
+ }
203
+ Restricted.class = 'Restricted';
204
+ exports.Restricted = Restricted;
205
+ class PubSubDisabledModel extends nymph_1.Entity {
206
+ static async factory(guid) {
207
+ return (await super.factory(guid));
208
+ }
209
+ static factorySync(guid) {
210
+ return super.factorySync(guid);
211
+ }
212
+ constructor(guid) {
213
+ super(guid);
214
+ if (guid == null) {
215
+ this.$data.name = '';
216
+ }
217
+ }
218
+ async $save() {
219
+ const error = new nymph_1.EntityInvalidDataError('Invalid entity data.');
220
+ if (this.$data.name == null || this.$data.name === '') {
221
+ error.addField('name');
222
+ }
223
+ if (error.getFields().length) {
224
+ throw error;
225
+ }
226
+ return await super.$save();
227
+ }
228
+ }
229
+ PubSubDisabledModel.ETYPE = 'pubsub_disabled';
230
+ PubSubDisabledModel.class = 'PubSubDisabled';
231
+ PubSubDisabledModel.pubSubEnabled = false;
232
+ exports.PubSubDisabledModel = PubSubDisabledModel;
233
+ class PubSubDisabled extends client_1.Entity {
234
+ constructor(guid) {
235
+ super(guid);
236
+ if (guid == null) {
237
+ this.$data.name = '';
238
+ }
239
+ }
240
+ static async factory(guid) {
241
+ return (await super.factory(guid));
242
+ }
243
+ static factorySync(guid) {
244
+ return super.factorySync(guid);
245
+ }
246
+ }
247
+ PubSubDisabled.class = 'PubSubDisabled';
248
+ exports.PubSubDisabled = PubSubDisabled;
150
249
  //# sourceMappingURL=testArtifacts.js.map
@@ -1 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CAClB,IAAa;QAEb,OAAO,CAAC,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAwC,CAAC;IAC5E,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAa;QAC9B,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,CAAwC,CAAC;IACxE,CAAC;;AAlBa,oBAAK,GAAG,gBAAgB,CAAC;AAF5B,wCAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nymphjs/server",
3
- "version": "1.0.0-beta.23",
3
+ "version": "1.0.0-beta.25",
4
4
  "description": "NymphJS - REST Server",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -31,14 +31,14 @@
31
31
  },
32
32
  "license": "Apache-2.0",
33
33
  "dependencies": {
34
- "@nymphjs/nymph": "^1.0.0-beta.23",
34
+ "@nymphjs/nymph": "^1.0.0-beta.25",
35
35
  "cookie-parser": "^1.4.6",
36
36
  "express": "^4.18.2"
37
37
  },
38
38
  "devDependencies": {
39
- "@nymphjs/client": "^1.0.0-beta.23",
40
- "@nymphjs/client-node": "^1.0.0-beta.23",
41
- "@nymphjs/driver-sqlite3": "^1.0.0-beta.23",
39
+ "@nymphjs/client": "^1.0.0-beta.25",
40
+ "@nymphjs/client-node": "^1.0.0-beta.25",
41
+ "@nymphjs/driver-sqlite3": "^1.0.0-beta.25",
42
42
  "@tsconfig/recommended": "^1.0.2",
43
43
  "@types/cookie-parser": "^1.4.3",
44
44
  "@types/express": "^4.17.17",
@@ -47,5 +47,5 @@
47
47
  "ts-jest": "^29.1.0",
48
48
  "typescript": "^5.0.4"
49
49
  },
50
- "gitHead": "e993c62b64051f9426eae2f8e629495e50bd97f9"
50
+ "gitHead": "a2466847d9be48ef3d69182bbc081a6ec24f2a42"
51
51
  }
@@ -24,6 +24,14 @@ type NymphResponse = Response<any, { nymph: Nymph }>;
24
24
 
25
25
  const NOT_FOUND_ERROR = 'Entity is not found.';
26
26
 
27
+ export class ForbiddenClassError extends Error {
28
+ constructor(message: string) {
29
+ super(message);
30
+
31
+ this.name = 'ForbiddenClassError';
32
+ }
33
+ }
34
+
27
35
  /**
28
36
  * A REST server middleware creator for Nymph.
29
37
  *
@@ -140,6 +148,10 @@ export function createServer(
140
148
  let EntityClass;
141
149
  try {
142
150
  EntityClass = response.locals.nymph.getEntityClass(data[0].class);
151
+ if (!EntityClass.restEnabled) {
152
+ httpError(response, 403);
153
+ return;
154
+ }
143
155
  } catch (e: any) {
144
156
  httpError(response, 400, e);
145
157
  return;
@@ -147,10 +159,21 @@ export function createServer(
147
159
  options.class = EntityClass;
148
160
  options.source = 'client';
149
161
  options.skipAc = false;
150
- selectors = classNamesToEntityConstructors(
151
- response.locals.nymph,
152
- selectors
153
- );
162
+ try {
163
+ selectors = classNamesToEntityConstructors(
164
+ response.locals.nymph,
165
+ selectors,
166
+ true
167
+ );
168
+ } catch (e: any) {
169
+ if (e?.message === 'Not accessible.') {
170
+ httpError(response, 403);
171
+ return;
172
+ } else {
173
+ httpError(response, 500, e);
174
+ return;
175
+ }
176
+ }
154
177
  let result:
155
178
  | EntityInterface
156
179
  | EntityInterface[]
@@ -241,6 +264,7 @@ export function createServer(
241
264
  let invalidRequest = false;
242
265
  let conflict = false;
243
266
  let notfound = false;
267
+ let forbidden = false;
244
268
  let lastException = null;
245
269
  for (let entData of data) {
246
270
  if (entData.guid) {
@@ -254,6 +278,8 @@ export function createServer(
254
278
  } catch (e: any) {
255
279
  if (e instanceof EntityConflictError) {
256
280
  conflict = true;
281
+ } else if (e instanceof ForbiddenClassError) {
282
+ forbidden = true;
257
283
  } else if (e.message === NOT_FOUND_ERROR) {
258
284
  notfound = true;
259
285
  } else if (e instanceof InvalidParametersError) {
@@ -293,6 +319,9 @@ export function createServer(
293
319
  } else if (conflict) {
294
320
  httpError(response, 409);
295
321
  return;
322
+ } else if (forbidden) {
323
+ httpError(response, 403);
324
+ return;
296
325
  } else if (notfound) {
297
326
  httpError(response, 404);
298
327
  return;
@@ -313,92 +342,108 @@ export function createServer(
313
342
  httpError(response, 400);
314
343
  return;
315
344
  }
316
- const params = referencesToEntities(
317
- [...data.params],
318
- response.locals.nymph
319
- );
320
- if (data.static) {
321
- let EntityClass: EntityConstructor;
322
- try {
323
- EntityClass = response.locals.nymph.getEntityClass(data.class);
324
- } catch (e: any) {
325
- httpError(response, 400);
326
- return;
327
- }
328
- if (
329
- EntityClass.clientEnabledStaticMethods.indexOf(data.method) === -1
330
- ) {
331
- httpError(response, 403);
332
- return;
333
- }
334
- if (!(data.method in EntityClass)) {
335
- httpError(response, 400);
336
- return;
337
- }
338
- // @ts-ignore Dynamic methods make TypeScript sad.
339
- const method: Function = EntityClass[data.method];
340
- if (typeof method !== 'function') {
341
- httpError(response, 400);
342
- return;
343
- }
344
- try {
345
- const result = method.call(EntityClass, ...params);
346
- let ret = result;
347
- if (result instanceof Promise) {
348
- ret = await result;
345
+ try {
346
+ const params = referencesToEntities(
347
+ [...data.params],
348
+ response.locals.nymph
349
+ );
350
+ if (data.static) {
351
+ let EntityClass: EntityConstructor;
352
+ try {
353
+ EntityClass = response.locals.nymph.getEntityClass(data.class);
354
+ if (!EntityClass.restEnabled) {
355
+ httpError(response, 403);
356
+ return;
357
+ }
358
+ } catch (e: any) {
359
+ httpError(response, 400);
360
+ return;
349
361
  }
350
- response.status(200);
351
- response.setHeader('Content-Type', 'application/json');
352
- response.send({ return: ret });
353
- } catch (e: any) {
354
- httpError(response, 500, e);
355
- return;
356
- }
357
- } else {
358
- let entity: EntityInterface;
359
- try {
360
- entity = await loadEntity(data.entity, response.locals.nymph);
361
- } catch (e: any) {
362
- if (e instanceof EntityConflictError) {
363
- httpError(response, 409);
364
- } else if (e.message === NOT_FOUND_ERROR) {
365
- httpError(response, 404, e);
366
- } else if (e instanceof InvalidParametersError) {
367
- httpError(response, 400, e);
368
- } else {
362
+ if (
363
+ EntityClass.clientEnabledStaticMethods.indexOf(data.method) === -1
364
+ ) {
365
+ httpError(response, 403);
366
+ return;
367
+ }
368
+ if (!(data.method in EntityClass)) {
369
+ httpError(response, 400);
370
+ return;
371
+ }
372
+ // @ts-ignore Dynamic methods make TypeScript sad.
373
+ const method: Function = EntityClass[data.method];
374
+ if (typeof method !== 'function') {
375
+ httpError(response, 400);
376
+ return;
377
+ }
378
+ try {
379
+ const result = method.call(EntityClass, ...params);
380
+ let ret = result;
381
+ if (result instanceof Promise) {
382
+ ret = await result;
383
+ }
384
+ response.status(200);
385
+ response.setHeader('Content-Type', 'application/json');
386
+ response.send({ return: ret });
387
+ } catch (e: any) {
369
388
  httpError(response, 500, e);
389
+ return;
390
+ }
391
+ } else {
392
+ let entity: EntityInterface;
393
+ try {
394
+ entity = await loadEntity(data.entity, response.locals.nymph);
395
+ } catch (e: any) {
396
+ if (e instanceof EntityConflictError) {
397
+ httpError(response, 409);
398
+ } else if (e instanceof ForbiddenClassError) {
399
+ httpError(response, 403);
400
+ } else if (e.message === NOT_FOUND_ERROR) {
401
+ httpError(response, 404, e);
402
+ } else if (e instanceof InvalidParametersError) {
403
+ httpError(response, 400, e);
404
+ } else {
405
+ httpError(response, 500, e);
406
+ }
407
+ return;
408
+ }
409
+ if (data.entity.guid && !entity.guid) {
410
+ httpError(response, 400);
411
+ return;
412
+ }
413
+ if (entity.$getClientEnabledMethods().indexOf(data.method) === -1) {
414
+ httpError(response, 403);
415
+ return;
416
+ }
417
+ if (
418
+ !(data.method in entity) ||
419
+ typeof entity[data.method] !== 'function'
420
+ ) {
421
+ httpError(response, 400);
422
+ return;
423
+ }
424
+ try {
425
+ const result = entity[data.method](...params);
426
+ let ret = result;
427
+ if (result instanceof Promise) {
428
+ ret = await result;
429
+ }
430
+ response.status(200);
431
+ response.setHeader('Content-Type', 'application/json');
432
+ if (data.stateless) {
433
+ response.send({ return: ret });
434
+ } else {
435
+ response.send({ entity: entity, return: ret });
436
+ }
437
+ } catch (e: any) {
438
+ httpError(response, 500, e);
439
+ return;
370
440
  }
371
- return;
372
- }
373
- if (data.entity.guid && !entity.guid) {
374
- httpError(response, 400);
375
- return;
376
441
  }
377
- if (entity.$getClientEnabledMethods().indexOf(data.method) === -1) {
442
+ } catch (e: any) {
443
+ if (e instanceof ForbiddenClassError) {
378
444
  httpError(response, 403);
379
445
  return;
380
- }
381
- if (
382
- !(data.method in entity) ||
383
- typeof entity[data.method] !== 'function'
384
- ) {
385
- httpError(response, 400);
386
- return;
387
- }
388
- try {
389
- const result = entity[data.method](...params);
390
- let ret = result;
391
- if (result instanceof Promise) {
392
- ret = await result;
393
- }
394
- response.status(200);
395
- response.setHeader('Content-Type', 'application/json');
396
- if (data.stateless) {
397
- response.send({ return: ret });
398
- } else {
399
- response.send({ entity: entity, return: ret });
400
- }
401
- } catch (e: any) {
446
+ } else {
402
447
  httpError(response, 500, e);
403
448
  return;
404
449
  }
@@ -512,6 +557,7 @@ export function createServer(
512
557
  let hadSuccess = false;
513
558
  let invalidRequest = false;
514
559
  let conflict = false;
560
+ let forbidden = false;
515
561
  let notfound = false;
516
562
  let lastException = null;
517
563
  for (let entData of data) {
@@ -526,6 +572,8 @@ export function createServer(
526
572
  } catch (e: any) {
527
573
  if (e instanceof EntityConflictError) {
528
574
  conflict = true;
575
+ } else if (e instanceof ForbiddenClassError) {
576
+ forbidden = true;
529
577
  } else if (e.message === NOT_FOUND_ERROR) {
530
578
  notfound = true;
531
579
  } else if (e instanceof InvalidParametersError) {
@@ -561,6 +609,8 @@ export function createServer(
561
609
  if (!hadSuccess) {
562
610
  if (invalidRequest) {
563
611
  httpError(response, 400, lastException);
612
+ } else if (forbidden) {
613
+ httpError(response, 403);
564
614
  } else if (conflict) {
565
615
  httpError(response, 409);
566
616
  } else if (notfound) {
@@ -605,6 +655,10 @@ export function createServer(
605
655
  let EntityClass: EntityConstructor;
606
656
  try {
607
657
  EntityClass = response.locals.nymph.getEntityClass(entData.class);
658
+ if (!EntityClass.restEnabled) {
659
+ httpError(response, 403);
660
+ return;
661
+ }
608
662
  } catch (e: any) {
609
663
  invalidRequest = true;
610
664
  failures = true;
@@ -707,6 +761,9 @@ export function createServer(
707
761
  );
708
762
  }
709
763
  let EntityClass = nymph.getEntityClass(entityData.class);
764
+ if (!EntityClass.restEnabled) {
765
+ throw new ForbiddenClassError('Not accessible.');
766
+ }
710
767
  let entity: EntityInterface | null;
711
768
  if (entityData.guid) {
712
769
  entity = await nymph.getEntity(
@@ -743,6 +800,9 @@ export function createServer(
743
800
  if (item.length === 3 && item[0] === 'nymph_entity_reference') {
744
801
  try {
745
802
  const EntityClass = nymph.getEntityClass(item[1]);
803
+ if (!EntityClass.restEnabled) {
804
+ throw new ForbiddenClassError('Not accessible.');
805
+ }
746
806
  return EntityClass.factoryReference(item as EntityReference);
747
807
  } catch (e: any) {
748
808
  return item;
package/src/index.test.ts CHANGED
@@ -2,12 +2,14 @@ import express from 'express';
2
2
  import SQLite3Driver from '@nymphjs/driver-sqlite3';
3
3
  import { Nymph as NymphServer } from '@nymphjs/nymph';
4
4
  import { Nymph } from '@nymphjs/client-node';
5
- import { Entity } from '@nymphjs/client';
5
+ import { Entity, HttpError } from '@nymphjs/client';
6
6
 
7
7
  import createServer from './index';
8
8
  import {
9
9
  EmployeeModel as EmployeeModelClass,
10
10
  Employee as EmployeeClass,
11
+ RestrictedModel as RestrictedModelClass,
12
+ Restricted as RestrictedClass,
11
13
  } from './testArtifacts';
12
14
 
13
15
  const sqliteConfig = {
@@ -16,6 +18,7 @@ const sqliteConfig = {
16
18
 
17
19
  const nymphServer = new NymphServer({}, new SQLite3Driver(sqliteConfig));
18
20
  const EmployeeModel = nymphServer.addEntityClass(EmployeeModelClass);
21
+ const RestrictedModel = nymphServer.addEntityClass(RestrictedModelClass);
19
22
 
20
23
  const app = express();
21
24
  app.use('/test', createServer(nymphServer));
@@ -25,6 +28,7 @@ const nymph = new Nymph({
25
28
  restUrl: 'http://localhost:5080/test/',
26
29
  });
27
30
  const Employee = nymph.addEntityClass(EmployeeClass);
31
+ const Restricted = nymph.addEntityClass(RestrictedClass);
28
32
 
29
33
  describe('Nymph REST Server and Client', () => {
30
34
  async function createJane() {
@@ -668,6 +672,66 @@ describe('Nymph REST Server and Client', () => {
668
672
  expect(first.$is(third)).toEqual(false);
669
673
  });
670
674
 
675
+ it("doesn't allow creation of a restricted entity class", async () => {
676
+ const attempt = await Restricted.factory();
677
+ attempt.name = 'Jane Doe';
678
+
679
+ let error = null;
680
+
681
+ try {
682
+ await attempt.$save();
683
+ } catch (e: any) {
684
+ error = e;
685
+ }
686
+
687
+ expect(error).toBeInstanceOf(HttpError);
688
+ expect(error.status).toEqual(403);
689
+ });
690
+
691
+ it("doesn't allow search of a restricted entity class", async () => {
692
+ let error = null;
693
+
694
+ try {
695
+ await nymph.getEntity({
696
+ class: Restricted,
697
+ });
698
+ } catch (e: any) {
699
+ error = e;
700
+ }
701
+
702
+ expect(error).toBeInstanceOf(HttpError);
703
+ expect(error.status).toEqual(403);
704
+ });
705
+
706
+ it("doesn't allow methods of a restricted entity class", async () => {
707
+ const attempt = await Restricted.factory();
708
+ attempt.name = 'Jane Doe';
709
+
710
+ let error = null;
711
+
712
+ try {
713
+ await attempt.$testMethod(1);
714
+ } catch (e: any) {
715
+ error = e;
716
+ }
717
+
718
+ expect(error).toBeInstanceOf(HttpError);
719
+ expect(error.status).toEqual(403);
720
+ });
721
+
722
+ it("doesn't allow static methods of a restricted entity class", async () => {
723
+ let error = null;
724
+
725
+ try {
726
+ await Restricted.testStatic(1);
727
+ } catch (e: any) {
728
+ error = e;
729
+ }
730
+
731
+ expect(error).toBeInstanceOf(HttpError);
732
+ expect(error.status).toEqual(403);
733
+ });
734
+
671
735
  it('get a new UID', async () => {
672
736
  const uidValue = await nymph.newUID('employee');
673
737
  expect(typeof uidValue).toEqual('number');