@genesislcap/mock-server 15.74.0 → 15.76.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/README.md +296 -58
- package/dist/db/schema.d.ts +9 -1
- package/dist/db/schema.js +40 -11
- package/dist/db/store.d.ts +1 -0
- package/dist/db/store.js +4 -0
- package/dist/handlers/auth.d.ts +15 -6
- package/dist/handlers/auth.js +152 -33
- package/dist/handlers/commitEvent.js +43 -20
- package/dist/handlers/crudEvents.d.ts +3 -1
- package/dist/handlers/crudEvents.js +3 -2
- package/dist/handlers/eventValidation.js +6 -3
- package/dist/handlers/http.d.ts +2 -2
- package/dist/handlers/http.js +66 -43
- package/dist/handlers/jsonSchema.d.ts +1 -0
- package/dist/handlers/jsonSchema.js +72 -21
- package/dist/handlers/meta.d.ts +1 -1
- package/dist/handlers/meta.js +59 -10
- package/dist/handlers/requestReply.js +36 -9
- package/dist/index.d.ts +1 -1
- package/dist/presets/auth.d.ts +25 -0
- package/dist/presets/auth.js +855 -0
- package/dist/presets/cronExpression.d.ts +1 -0
- package/dist/presets/cronExpression.js +429 -0
- package/dist/presets/fileServer.d.ts +13 -0
- package/dist/presets/fileServer.js +399 -0
- package/dist/presets/gsf.d.ts +24 -0
- package/dist/presets/gsf.js +450 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/javaTime.d.ts +7 -0
- package/dist/presets/javaTime.js +322 -0
- package/dist/presets/multipart.d.ts +14 -0
- package/dist/presets/multipart.js +91 -0
- package/dist/presets/notify.d.ts +27 -0
- package/dist/presets/notify.js +250 -0
- package/dist/presets/notifyDispatch.d.ts +28 -0
- package/dist/presets/notifyDispatch.js +570 -0
- package/dist/presets/notifyRules.d.ts +9 -0
- package/dist/presets/notifyRules.js +754 -0
- package/dist/presets/platform/backing.json +8058 -217
- package/dist/presets/platform/criteria-model.json +362 -0
- package/dist/presets/platform/time-zones.json +608 -0
- package/dist/presets/platform.d.ts +7 -0
- package/dist/presets/platform.js +145 -103
- package/dist/presets/products.d.ts +9 -7
- package/dist/presets/products.js +89 -21
- package/dist/presets/reconciliation.d.ts +18 -0
- package/dist/presets/reconciliation.js +721 -0
- package/dist/presets/reporting.d.ts +14 -0
- package/dist/presets/reporting.js +862 -0
- package/dist/protocol/connection.d.ts +2 -0
- package/dist/protocol/connection.js +4 -0
- package/dist/protocol/dtoTypes.d.ts +30 -0
- package/dist/protocol/dtoTypes.js +250 -0
- package/dist/protocol/errors.d.ts +3 -1
- package/dist/protocol/errors.js +2 -0
- package/dist/protocol/fieldTypes.js +5 -0
- package/dist/protocol/router.d.ts +1 -0
- package/dist/protocol/router.js +3 -3
- package/dist/protocol/schemaValidation.d.ts +1 -1
- package/dist/protocol/schemaValidation.js +53 -8
- package/dist/server.js +34 -2
- package/dist/types.d.ts +50 -2
- package/package.json +1 -1
- package/src/db/schema.ts +56 -13
- package/src/db/store.ts +5 -0
- package/src/handlers/auth.ts +211 -37
- package/src/handlers/commitEvent.ts +44 -19
- package/src/handlers/crudEvents.ts +9 -2
- package/src/handlers/eventValidation.ts +6 -3
- package/src/handlers/http.ts +83 -42
- package/src/handlers/jsonSchema.ts +86 -23
- package/src/handlers/meta.ts +77 -9
- package/src/handlers/requestReply.ts +42 -6
- package/src/index.ts +7 -0
- package/src/presets/auth.ts +961 -0
- package/src/presets/cronExpression.ts +445 -0
- package/src/presets/fileServer.ts +475 -0
- package/src/presets/gsf.ts +475 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/javaTime.ts +354 -0
- package/src/presets/multipart.ts +110 -0
- package/src/presets/notify.ts +312 -0
- package/src/presets/notifyDispatch.ts +685 -0
- package/src/presets/notifyRules.ts +866 -0
- package/src/presets/platform/backing.json +8058 -217
- package/src/presets/platform/criteria-model.json +362 -0
- package/src/presets/platform/time-zones.json +608 -0
- package/src/presets/platform.ts +204 -115
- package/src/presets/products.ts +125 -19
- package/src/presets/reconciliation.ts +824 -0
- package/src/presets/reporting.ts +953 -0
- package/src/protocol/connection.ts +4 -0
- package/src/protocol/dtoTypes.ts +310 -0
- package/src/protocol/errors.ts +13 -1
- package/src/protocol/fieldTypes.ts +5 -0
- package/src/protocol/router.ts +3 -3
- package/src/protocol/schemaValidation.ts +61 -8
- package/src/server.ts +38 -2
- package/src/types.ts +147 -3
package/src/types.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type GenesisFieldType =
|
|
|
36
36
|
// README's "Declared schema".
|
|
37
37
|
export interface FieldDef {
|
|
38
38
|
name: string;
|
|
39
|
-
type: GenesisFieldType;
|
|
39
|
+
type: GenesisFieldType | NestedFieldType;
|
|
40
40
|
// Default true, as in the dictionary (`.notNull()` makes it false). Primary
|
|
41
41
|
// key and generated fields default to false.
|
|
42
42
|
nullable?: boolean;
|
|
@@ -76,8 +76,31 @@ export interface FieldDef {
|
|
|
76
76
|
// `optional: true` for a Kotlin default the metadata can't show, such as
|
|
77
77
|
// `val enabled: Boolean? = true`.
|
|
78
78
|
optional?: boolean;
|
|
79
|
+
// A DTO field (EventSchemaOverride.fields) that holds more than one value:
|
|
80
|
+
// an ARRAY's items or a MAP's values (unset: Any), and whether the ARRAY is
|
|
81
|
+
// a Kotlin Set (`unique`) rather than a List; an OBJECT's class name and its
|
|
82
|
+
// own fields, declared as here. Set and List items, map values and nested
|
|
83
|
+
// classes are described and checked as GSF does (src/protocol/dtoTypes.ts).
|
|
84
|
+
items?: FieldTypeDef;
|
|
85
|
+
unique?: boolean;
|
|
86
|
+
className?: string;
|
|
87
|
+
fields?: FieldDef[];
|
|
88
|
+
// An ENUM's class, for a DTO field whose enum isn't a generated one
|
|
89
|
+
// (ENUM_CLASS and DESCRIPTION; default: the generated DAO enum's name).
|
|
90
|
+
enumClass?: string;
|
|
91
|
+
// A DTO field that comes from a DAO the class unwraps (@JsonUnwrapped):
|
|
92
|
+
// described with the DAO's annotations, as a table event's fields are
|
|
93
|
+
// (TITLE, lengths, ranges, GENESIS_TYPE), and checked against them.
|
|
94
|
+
dao?: boolean;
|
|
79
95
|
}
|
|
80
96
|
|
|
97
|
+
// A DTO field's type when it isn't a single value: a Kotlin List or Set, a
|
|
98
|
+
// Map (string keys), a nested class, or Any.
|
|
99
|
+
export type NestedFieldType = 'ARRAY' | 'MAP' | 'OBJECT' | 'ANY';
|
|
100
|
+
|
|
101
|
+
// The type of an ARRAY's items or a MAP's values.
|
|
102
|
+
export type FieldTypeDef = Omit<FieldDef, 'name'>;
|
|
103
|
+
|
|
81
104
|
// A field the database fills on insert when the record leaves it out (a
|
|
82
105
|
// supplied value is kept). Metadata marks it NULLABLE:false, OPTIONAL:true
|
|
83
106
|
// and leaves it out of `required`. A SEQUENCE mints values like the key's
|
|
@@ -306,6 +329,9 @@ export interface QueryDef {
|
|
|
306
329
|
// The query's `indices { }` block, reported as META_REQUEST INDEXES. With
|
|
307
330
|
// none, INDEXES is the default [{NAME: null, FIELDS: 'RECORD_ID'}].
|
|
308
331
|
indexes?: IndexDef[];
|
|
332
|
+
// A dataserver GSF registers in code on its older engine (dataserver2,
|
|
333
|
+
// e.g. StatusDataserver's ALL_PROCESSES_STATUS): its META has no INDEXES.
|
|
334
|
+
legacyEngine?: boolean;
|
|
309
335
|
// Server-side where-clause equivalent, applied before any client
|
|
310
336
|
// CRITERIA_MATCH — to both the DATA_LOGON snapshot and live pushes. Use it
|
|
311
337
|
// for things the real query's filter/where clause does (e.g. keep template
|
|
@@ -321,6 +347,10 @@ export interface RequestReplyResolverCtx {
|
|
|
321
347
|
message: GenesisMessage;
|
|
322
348
|
user: RequestingUser;
|
|
323
349
|
store: Store;
|
|
350
|
+
// The server's whole config, as it is when the request comes: a reply that
|
|
351
|
+
// depends on what else the server serves (reporting's
|
|
352
|
+
// ALL_REPORT_DATASOURCES lists its request servers) reads it here.
|
|
353
|
+
config: MockServerConfig;
|
|
324
354
|
}
|
|
325
355
|
|
|
326
356
|
export interface RequestReplyDef {
|
|
@@ -364,6 +394,32 @@ export interface RequestReplyDef {
|
|
|
364
394
|
// `config { maxRows = N }`: the most rows a REP_ carries when the request
|
|
365
395
|
// names no DETAILS.MAX_ROWS. Default 10000 (RequestReply.DEFAULT_MAXIMUM_ROWS).
|
|
366
396
|
rowLimit?: number;
|
|
397
|
+
// The order a `source` server's rows come in, when it isn't the primary
|
|
398
|
+
// key's: a Kotlin reply that reads an index, or reads it backwards
|
|
399
|
+
// (getRangeFromEnd). Ignored with a resolver or criteriaOnly.
|
|
400
|
+
order?: (a: Row, b: Row) => number;
|
|
401
|
+
// A typed request server, `requestReply<In, Out>`, whose Kotlin builds the
|
|
402
|
+
// reply (with a `resolver`): META describes its classes as GSF's
|
|
403
|
+
// CustomReqRep does, and its replies are capped and typed as GSF's are
|
|
404
|
+
// (see TypedRequestReply).
|
|
405
|
+
typed?: TypedRequestReply;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// A typed request server's request and reply classes: META answers in the
|
|
409
|
+
// GPAL shape (DETAILS.FIELD for the request class, DETAILS.REPLY for the
|
|
410
|
+
// reply class, each field described as an event DTO's is), its REP_ carries
|
|
411
|
+
// PARAMETRIC_TYPE (the reply class), CRITERIA_MATCH filters the reply rows,
|
|
412
|
+
// and at most DETAILS.MAX_ROWS of them go out (default `rowLimit`, else
|
|
413
|
+
// 10000), with no paging (AbstractCustomReqRep.kt @v8.15.29). The fields are
|
|
414
|
+
// DTO fields, as an event schema's, listed in the order GSF reports them:
|
|
415
|
+
// by name, but for an unwrapped class's.
|
|
416
|
+
export interface TypedRequestReply {
|
|
417
|
+
request: { className: string; fields: FieldDef[] };
|
|
418
|
+
reply: { className: string; fields: FieldDef[] };
|
|
419
|
+
// The META DETAILS a real server sends, as it is, for classes these fields
|
|
420
|
+
// can't describe whole (a sealed class's subtypes and their constants, a
|
|
421
|
+
// DAO's annotations): the fields then only describe the JSON schema.
|
|
422
|
+
meta?: Row;
|
|
367
423
|
}
|
|
368
424
|
|
|
369
425
|
// How META_REQUEST / JSON_SCHEMA_REQUEST describe an event whose name doesn't
|
|
@@ -403,6 +459,56 @@ export interface AuthUser {
|
|
|
403
459
|
// per user. GSF sends USER: null without one, and so does the mock when
|
|
404
460
|
// this is unset. Not used under fidelity: 'legacy'.
|
|
405
461
|
loginAck?: Row;
|
|
462
|
+
// USER.STATUS, which a login checks as auth's does: DISABLED fails as a
|
|
463
|
+
// wrong password does (INCORRECT_CREDENTIALS), PASSWORD_EXPIRED and
|
|
464
|
+
// PASSWORD_RESET answer PASSWORD_EXPIRED whatever the password, and any
|
|
465
|
+
// other status but ENABLED LOCKED_ACCOUNT once the password is right.
|
|
466
|
+
// Unset: ENABLED.
|
|
467
|
+
status?: string;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Where logins find their users instead of AuthConfig.users, and how they
|
|
471
|
+
// decide and record one: the platform preset's reads auth's USER,
|
|
472
|
+
// PROFILE_USER and RIGHT_SUMMARY tables and writes what auth's login writes
|
|
473
|
+
// (USER_LOGIN_AUDIT, the lockout counter, USER's ONLINE and LAST_LOGIN), so a
|
|
474
|
+
// user an event adds, disables, re-profiles or gives a new password logs in
|
|
475
|
+
// as the store now says, as on the real server.
|
|
476
|
+
export interface AuthDirectory {
|
|
477
|
+
// The user a session names, as the store holds them now (their profiles,
|
|
478
|
+
// rights and USER_DETAILS); undefined when there's none. A silent login
|
|
479
|
+
// (event-login-details) and every token check read it.
|
|
480
|
+
user(username: string, store: Store): AuthUser | undefined;
|
|
481
|
+
// A credentials login (EVENT_LOGIN_AUTH with a USER_NAME and a PASSWORD):
|
|
482
|
+
// the user, or why it fails. `password` is undefined for a login no
|
|
483
|
+
// authenticator takes (no PASSWORD or no USER_NAME, and no refresh token),
|
|
484
|
+
// which fails NO_COMPATIBLE_PROVIDERS whatever this answers: record it.
|
|
485
|
+
login(username: string, password: string | undefined, ctx: LoginCtx): AuthUser | LoginFailure;
|
|
486
|
+
// A refresh-token login as the session's user; undefined when no session
|
|
487
|
+
// has the token.
|
|
488
|
+
refresh(username: string | undefined, ctx: LoginCtx): AuthUser | LoginFailure;
|
|
489
|
+
// A session's logout. `online`: whether the user still has another.
|
|
490
|
+
logout(username: string, online: boolean, ctx: LoginCtx): void;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Why a login fails: auth's AuthFailure.
|
|
494
|
+
export type LoginFailure =
|
|
495
|
+
| 'INCORRECT_CREDENTIALS'
|
|
496
|
+
| 'PASSWORD_EXPIRED'
|
|
497
|
+
| 'LOCKED_ACCOUNT'
|
|
498
|
+
| 'MAX_TRIES_REACHED'
|
|
499
|
+
| 'UNKNOWN_ACCOUNT'
|
|
500
|
+
| 'NO_COMPATIBLE_PROVIDERS';
|
|
501
|
+
|
|
502
|
+
// What a login runs with.
|
|
503
|
+
export interface LoginCtx {
|
|
504
|
+
store: Store;
|
|
505
|
+
broadcastTableChange: BroadcastTableChangeFn;
|
|
506
|
+
// DETAILS.HOSTNAME as GSF's router sets it on a login or logout: the
|
|
507
|
+
// client's HOSTNAME header, else its address ("/127.0.0.1").
|
|
508
|
+
hostname: string;
|
|
509
|
+
// The message's own USER_NAME, whom what the login writes is audited as;
|
|
510
|
+
// null without one.
|
|
511
|
+
messageUser: string | null;
|
|
406
512
|
}
|
|
407
513
|
|
|
408
514
|
// GSF's router `cookieAuthentication { }` block (genesis-router
|
|
@@ -435,7 +541,10 @@ export interface SsoIdentityProvider {
|
|
|
435
541
|
}
|
|
436
542
|
|
|
437
543
|
export interface AuthConfig {
|
|
544
|
+
// The users who can log in. With a `directory`, logins find users there
|
|
545
|
+
// instead, and this only names the user `httpAutoLogin: true` logs in as.
|
|
438
546
|
users?: AuthUser[];
|
|
547
|
+
directory?: AuthDirectory;
|
|
439
548
|
// Served from GET gwf/sso/list as { IDPS: [...] }. foundation-auth's login
|
|
440
549
|
// screen fetches this whenever sso.toggled is on, shows a red "Failed to
|
|
441
550
|
// fetch identity providers" AND hides the credentials form if the fetch
|
|
@@ -502,6 +611,10 @@ export interface EventHandlerCtx {
|
|
|
502
611
|
connection: import('./protocol/connection.ts').Connection;
|
|
503
612
|
store: Store;
|
|
504
613
|
message: GenesisMessage;
|
|
614
|
+
// The server's whole config, as it is when the event comes: a handler that
|
|
615
|
+
// depends on what else the server holds (a table's unique indexes, the
|
|
616
|
+
// request servers a report reads) reads it here.
|
|
617
|
+
config: MockServerConfig;
|
|
505
618
|
broadcast: BroadcastFn;
|
|
506
619
|
broadcastTableChange: BroadcastTableChangeFn;
|
|
507
620
|
// `VALIDATE: true` on the message: the client asks whether the event would
|
|
@@ -522,6 +635,13 @@ export interface EventHandlerCtx {
|
|
|
522
635
|
// throwing NackError.warning(...), which always NACKs. Always false under
|
|
523
636
|
// fidelity: 'legacy', which doesn't model it.
|
|
524
637
|
ignoreWarnings: boolean;
|
|
638
|
+
// Runs `callback` once the event has committed, before its ACK goes out
|
|
639
|
+
// (a push it makes still follows the ACK); never when it NACKs or only
|
|
640
|
+
// validates. Called after that (from a callback, or kept for later), it
|
|
641
|
+
// runs at once if the event committed. For state a handler keeps outside
|
|
642
|
+
// the store, which the store's rollback can't undo. Under fidelity:
|
|
643
|
+
// 'legacy', which keeps every write, at once.
|
|
644
|
+
afterCommit(callback: () => void): void;
|
|
525
645
|
}
|
|
526
646
|
|
|
527
647
|
// `warnings` (a non-empty list) is a GSF onValidate's warning-only
|
|
@@ -531,7 +651,17 @@ export interface EventHandlerCtx {
|
|
|
531
651
|
// `generated` (no WARNING), and the writes are kept. Errors are thrown
|
|
532
652
|
// (NackError), never returned: a thrown NackError NACKs with its errors and
|
|
533
653
|
// any warnings it carries, and rolls back too.
|
|
534
|
-
|
|
654
|
+
//
|
|
655
|
+
// `reply` is a typed GSF handler's own reply (`eventHandler<In, Out>` whose
|
|
656
|
+
// Out isn't EventReply, e.g. auth's CreateMfaSecretAck): sent as it is, with
|
|
657
|
+
// its own MESSAGE_TYPE, in place of the EVENT_ACK, under VALIDATE too (the
|
|
658
|
+
// handler returns its validate reply then). A NACK of its own type is a
|
|
659
|
+
// NackError with `messageType`.
|
|
660
|
+
export type EventHandlerResult = {
|
|
661
|
+
generated?: Row[];
|
|
662
|
+
warnings?: NackErrorInput[];
|
|
663
|
+
reply?: Row;
|
|
664
|
+
} | void;
|
|
535
665
|
|
|
536
666
|
export type EventHandler = (details: Row, ctx: EventHandlerCtx) => EventHandlerResult;
|
|
537
667
|
|
|
@@ -544,7 +674,21 @@ export type EventHandler = (details: Row, ctx: EventHandlerCtx) => EventHandlerR
|
|
|
544
674
|
export interface HttpRouteDef {
|
|
545
675
|
method?: string;
|
|
546
676
|
path: string | RegExp;
|
|
547
|
-
handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void>;
|
|
677
|
+
handler: (req: IncomingMessage, res: ServerResponse, ctx: HttpRouteCtx) => void | Promise<void>;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// What a route handler can reach: the store and the live pushes, as an event
|
|
681
|
+
// handler does, and who the request's session belongs to (none without one).
|
|
682
|
+
export interface HttpRouteCtx {
|
|
683
|
+
store: Store;
|
|
684
|
+
broadcast: BroadcastFn;
|
|
685
|
+
broadcastTableChange: BroadcastTableChangeFn;
|
|
686
|
+
userName?: string;
|
|
687
|
+
// Runs an event as `userName`, as a socket's would run (schema check,
|
|
688
|
+
// handler, transaction, audit), and gives back its reply: how GSF's router
|
|
689
|
+
// answers an event POSTed over HTTP. With auth.requireAuth, an event with
|
|
690
|
+
// no user NACKs NOT_LOGGED_ON, as on the socket.
|
|
691
|
+
commitEvent(message: GenesisMessage, userName: string | undefined): Row;
|
|
548
692
|
}
|
|
549
693
|
|
|
550
694
|
export interface OnMessageCtx {
|