@sasjs/api 0.44.4 → 0.44.6
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/browser.js +529 -65
- package/build/cjs/corpus/records.js +272 -34
- package/build/cjs/host/dispatch.js +299 -24
- package/build/cjs/identity/records.js +5 -3
- package/build/cjs/routes/generated.js +35 -7
- package/build/esm/corpus/records.d.ts.map +1 -1
- package/build/esm/corpus/records.js +272 -34
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +299 -24
- package/build/esm/identity/records.d.ts +1 -1
- package/build/esm/identity/records.d.ts.map +1 -1
- package/build/esm/identity/records.js +5 -3
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +35 -7
- package/package.json +2 -2
|
@@ -105,14 +105,191 @@ const validate = (route, request) => {
|
|
|
105
105
|
};
|
|
106
106
|
/** The file an app is served from for a directory request, as the surface serves it. */
|
|
107
107
|
const APP_ENTRY_FILE = 'index.html';
|
|
108
|
+
/** A refusal worded the way Joi words it, so a caller sees one message on either host. */
|
|
109
|
+
const refused = (message) => new types_js_1.ApiError(400, message);
|
|
110
|
+
/** `Joi.string()`, with its type and emptiness refusals. */
|
|
111
|
+
const stringField = (field, value, allowEmpty = false) => {
|
|
112
|
+
if (typeof value !== 'string')
|
|
113
|
+
throw refused(`"${field}" must be a string`);
|
|
114
|
+
if (value === '' && !allowEmpty)
|
|
115
|
+
throw refused(`"${field}" is not allowed to be empty`);
|
|
116
|
+
return value;
|
|
117
|
+
};
|
|
118
|
+
/** `Joi.string().required()`, with its refusal for a field that is missing. */
|
|
119
|
+
const requiredField = (field, value) => {
|
|
120
|
+
if (value === undefined)
|
|
121
|
+
throw refused(`"${field}" is required`);
|
|
122
|
+
return stringField(field, value);
|
|
123
|
+
};
|
|
124
|
+
/** `Joi.string().alphanum().min(n).max(m)`, in its order and its wording. */
|
|
125
|
+
const alphanumeric = (field, value, min, max) => {
|
|
126
|
+
// alphanumeric, in either case: a username is folded before it is tested, a
|
|
127
|
+
// group's name is a label and keeps the case it was given
|
|
128
|
+
if (!/^[A-Za-z0-9]+$/.test(value))
|
|
129
|
+
throw refused(`"${field}" must only contain alpha-numeric characters`);
|
|
130
|
+
if (value.length < min)
|
|
131
|
+
throw refused(`"${field}" length must be at least ${min} characters long`);
|
|
132
|
+
if (value.length > max)
|
|
133
|
+
throw refused(`"${field}" length must be less than or equal to ${max} characters long`);
|
|
134
|
+
return value;
|
|
135
|
+
};
|
|
136
|
+
/** `Joi.string().min(n).max(m)`, in its order and its wording. */
|
|
137
|
+
const lengthBetween = (field, value, min, max) => {
|
|
138
|
+
if (value.length < min)
|
|
139
|
+
throw refused(`"${field}" length must be at least ${min} characters long`);
|
|
140
|
+
if (value.length > max)
|
|
141
|
+
throw refused(`"${field}" length must be less than or equal to ${max} characters long`);
|
|
142
|
+
return value;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* `displayName`'s rule, `Joi.string().trim().min(6)`: trimmed first, so a name of
|
|
146
|
+
* spaces is empty rather than short, which is the answer an installation gives.
|
|
147
|
+
*/
|
|
148
|
+
const trimmedName = (field, value) => {
|
|
149
|
+
const name = value.trim();
|
|
150
|
+
if (name === '')
|
|
151
|
+
throw refused(`"${field}" is not allowed to be empty`);
|
|
152
|
+
if (name.length < 6)
|
|
153
|
+
throw refused(`"${field}" length must be at least 6 characters long`);
|
|
154
|
+
return name;
|
|
155
|
+
};
|
|
156
|
+
/** The keys each of these bodies states; anything else is refused, as Joi does. */
|
|
157
|
+
const refuseUnknown = (body, keys) => {
|
|
158
|
+
for (const key of Object.keys(body))
|
|
159
|
+
if (!keys.includes(key))
|
|
160
|
+
throw refused(`"${key}" is not allowed`);
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* The routes sasjs/server guards with `verifyAdmin` before their schema runs.
|
|
164
|
+
*
|
|
165
|
+
* They are refused as callers first, so their body checks follow the gate - the order
|
|
166
|
+
* the installation's middleware produce. The identity routes gate the same way but
|
|
167
|
+
* validate through `controllerRules`, because their body rules are not the document's;
|
|
168
|
+
* `GET /permission` is absent because a caller may read their own rules there.
|
|
169
|
+
*/
|
|
170
|
+
const ADMIN_GATED_ROUTES = new Set([
|
|
171
|
+
'POST /SASjsApi/permission',
|
|
172
|
+
'PATCH /SASjsApi/permission/{uid}',
|
|
173
|
+
'DELETE /SASjsApi/permission/{uid}',
|
|
174
|
+
'GET /SASjsApi/client',
|
|
175
|
+
'POST /SASjsApi/client'
|
|
176
|
+
]);
|
|
177
|
+
/**
|
|
178
|
+
* `getUserValidation` for a `by/username` path parameter.
|
|
179
|
+
*
|
|
180
|
+
* The server validates that parameter with `usernameSchema` before the controller
|
|
181
|
+
* looks anything up, so the value is folded to lower case and checked against the
|
|
182
|
+
* same 3-to-16 alphanumeric rule - which is why `by/username/SASJSUSER` finds
|
|
183
|
+
* `sasjsuser` there. The gate that runs before it compares the raw parameter, so
|
|
184
|
+
* the folding happens here rather than in the caller's hands.
|
|
185
|
+
*/
|
|
186
|
+
const foldedUsername = (value) => alphanumeric('username', requiredField('username', value).toLowerCase(), 3, 16);
|
|
187
|
+
/**
|
|
188
|
+
* `deleteUserValidation`: the body a deletion carries.
|
|
189
|
+
*
|
|
190
|
+
* A caller deleting their own account supplies the password, and it is checked
|
|
191
|
+
* against the password schema before it is compared - so a short one is a 400 and
|
|
192
|
+
* never reaches the comparison. An administrator's deletion takes no body at all,
|
|
193
|
+
* and the schema declares no key for one.
|
|
194
|
+
*/
|
|
195
|
+
const deletionBody = (body, admin) => {
|
|
196
|
+
if (admin) {
|
|
197
|
+
for (const key of Object.keys(body))
|
|
198
|
+
throw refused(`"${key}" is not allowed`);
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
const password = lengthBetween('password', requiredField('password', body.password), 6, 1024);
|
|
202
|
+
for (const key of Object.keys(body))
|
|
203
|
+
if (key !== 'password')
|
|
204
|
+
throw refused(`"${key}" is not allowed`);
|
|
205
|
+
return { password };
|
|
206
|
+
};
|
|
207
|
+
/** The keys either user operation's body states; the two schemas declare the same six. */
|
|
208
|
+
const USER_KEYS = [
|
|
209
|
+
'displayName',
|
|
210
|
+
'username',
|
|
211
|
+
'password',
|
|
212
|
+
'isAdmin',
|
|
213
|
+
'isActive',
|
|
214
|
+
'autoExec'
|
|
215
|
+
];
|
|
216
|
+
/**
|
|
217
|
+
* `registerUserValidation`, in its order and its wording.
|
|
218
|
+
*
|
|
219
|
+
* The shared `validate` checks presence only, and in the document's order - so a
|
|
220
|
+
* body that trips two rules is refused for a different field here than on an
|
|
221
|
+
* installation, which is the class the update routes already had fixed. The
|
|
222
|
+
* conversion is the schema's too: the display name trimmed, the username folded.
|
|
223
|
+
*/
|
|
224
|
+
const userCreate = (body) => {
|
|
225
|
+
const displayName = trimmedName('displayName', requiredField('displayName', body.displayName));
|
|
226
|
+
const username = alphanumeric('username', requiredField('username', body.username).toLowerCase(), 3, 16);
|
|
227
|
+
const password = lengthBetween('password', requiredField('password', body.password), 6, 1024);
|
|
228
|
+
// the flags before `autoExec`, which is where `registerUserValidation` declares
|
|
229
|
+
// them, and both before the unknown keys, which Joi reports last of all
|
|
230
|
+
const isAdmin = booleanOf(body.isAdmin, 'isAdmin');
|
|
231
|
+
const isActive = booleanOf(body.isActive, 'isActive');
|
|
232
|
+
const autoExec = body.autoExec === undefined
|
|
233
|
+
? undefined
|
|
234
|
+
: stringField('autoExec', body.autoExec, true);
|
|
235
|
+
refuseUnknown(body, USER_KEYS);
|
|
236
|
+
return { displayName, username, password, isAdmin, isActive, autoExec };
|
|
237
|
+
};
|
|
238
|
+
const GROUP_CREATE_KEYS = ['name', 'description', 'isActive'];
|
|
239
|
+
/** `registerGroupValidation`, in its order and its wording. */
|
|
240
|
+
const groupCreate = (body) => {
|
|
241
|
+
// a group's name is a label rather than a login handle, so it is not folded
|
|
242
|
+
const name = alphanumeric('name', requiredField('name', body.name), 3, 16);
|
|
243
|
+
const description = body.description === undefined
|
|
244
|
+
? undefined
|
|
245
|
+
: stringField('description', body.description);
|
|
246
|
+
// as in `userCreate`: the flag first, the unknown keys last, which is the order
|
|
247
|
+
// the schema reports them in
|
|
248
|
+
const isActive = booleanOf(body.isActive, 'isActive');
|
|
249
|
+
refuseUnknown(body, GROUP_CREATE_KEYS);
|
|
250
|
+
return { name, description, isActive };
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* `updateUserValidation`, in its order and its wording.
|
|
254
|
+
*
|
|
255
|
+
* Every string here is optional, because an update may carry nothing but the flag
|
|
256
|
+
* it is changing - the document's `required` flags are tsoa's, not the schema's.
|
|
257
|
+
* The two flags themselves are declared only for an administrator, so a non-admin
|
|
258
|
+
* that sends one is refused as an unknown key, as is any key the schema omits.
|
|
259
|
+
*/
|
|
260
|
+
const userUpdate = (body, admin) => {
|
|
261
|
+
const changes = { ...body };
|
|
262
|
+
if (changes.displayName !== undefined)
|
|
263
|
+
changes.displayName = trimmedName('displayName', stringField('displayName', changes.displayName));
|
|
264
|
+
if (changes.username !== undefined)
|
|
265
|
+
changes.username = alphanumeric('username', stringField('username', changes.username).toLowerCase(), 3, 16);
|
|
266
|
+
if (changes.password !== undefined)
|
|
267
|
+
lengthBetween('password', stringField('password', changes.password), 6, 1024);
|
|
268
|
+
if (changes.autoExec !== undefined)
|
|
269
|
+
stringField('autoExec', changes.autoExec, true);
|
|
270
|
+
// On a non-admin's own update the schema declares neither flag, so the two are
|
|
271
|
+
// unknown keys like any other - and `refuseUnknown` reports whichever the body
|
|
272
|
+
// states first, which is the order Joi reports them in. Reporting them ahead of
|
|
273
|
+
// that loop would answer `"isAdmin" is not allowed` to a body whose first
|
|
274
|
+
// unknown key is something else.
|
|
275
|
+
const declared = admin
|
|
276
|
+
? USER_KEYS
|
|
277
|
+
: USER_KEYS.filter((key) => key !== 'isAdmin' && key !== 'isActive');
|
|
278
|
+
for (const field of ['isAdmin', 'isActive'])
|
|
279
|
+
if (admin && field in changes)
|
|
280
|
+
changes[field] = booleanOf(changes[field], field);
|
|
281
|
+
refuseUnknown(changes, declared);
|
|
282
|
+
return changes;
|
|
283
|
+
};
|
|
108
284
|
/**
|
|
109
285
|
* A body field the document states as a boolean, read the way the server reads it.
|
|
110
286
|
*
|
|
111
|
-
* The server validates
|
|
287
|
+
* The server validates these with `Joi.boolean()`, which converts real booleans
|
|
112
288
|
* and the string spellings of them - case-insensitively, and trimmed, as Joi 18
|
|
113
289
|
* does - and refuses every other shape. Both halves are reproduced here: a client
|
|
114
|
-
* that sent the string `"false"` and had its buffer laid out anyway
|
|
115
|
-
*
|
|
290
|
+
* that sent the string `"false"` and had its buffer laid out anyway, or an
|
|
291
|
+
* `isAdmin` of `"yes"` and had it stored, would find two hosts disagreeing about
|
|
292
|
+
* what it asked for.
|
|
116
293
|
*
|
|
117
294
|
* The conversion is limited to strings on purpose. `String(value)` would also read
|
|
118
295
|
* shapes the schema refuses - a one-element array `["true"]` stringifies to
|
|
@@ -122,9 +299,9 @@ const APP_ENTRY_FILE = 'index.html';
|
|
|
122
299
|
* installation gives it: `"yes"` is a caller's bug, and reading it as the default
|
|
123
300
|
* leaves that bug unanswered. `replaceOf` refuses its own boolean field for the
|
|
124
301
|
* same reason, though not by the same rules - an empty string there means the query
|
|
125
|
-
* parameter was not stated, and for
|
|
302
|
+
* parameter was not stated, and for a body field the schema refuses it.
|
|
126
303
|
*/
|
|
127
|
-
const
|
|
304
|
+
const booleanOf = (value, field) => {
|
|
128
305
|
if (value === undefined)
|
|
129
306
|
return undefined;
|
|
130
307
|
if (typeof value === 'boolean')
|
|
@@ -136,7 +313,7 @@ const layoutOf = (value) => {
|
|
|
136
313
|
if (text === 'false')
|
|
137
314
|
return false;
|
|
138
315
|
}
|
|
139
|
-
throw new types_js_1.ApiError(400,
|
|
316
|
+
throw new types_js_1.ApiError(400, `"${field}" must be a boolean`);
|
|
140
317
|
};
|
|
141
318
|
/**
|
|
142
319
|
* An app the index does not hold, in the wording the route answers with.
|
|
@@ -269,7 +446,6 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
269
446
|
!(await records.mayUseRoute(callerSubject, grantScoped)))
|
|
270
447
|
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
271
448
|
}
|
|
272
|
-
validate(route, request);
|
|
273
449
|
const query = request.query || {};
|
|
274
450
|
const body = request.body || {};
|
|
275
451
|
const params = request.params || {};
|
|
@@ -313,11 +489,113 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
313
489
|
status: 200,
|
|
314
490
|
contents: output.contents
|
|
315
491
|
});
|
|
492
|
+
/**
|
|
493
|
+
* The caller's own record, as the administration routes read it.
|
|
494
|
+
*
|
|
495
|
+
* The user routes ask two questions about the caller before they look at the
|
|
496
|
+
* body - who is this, and are they an administrator - because an installation
|
|
497
|
+
* mounts `authenticateAccessToken` and `verifyAdmin`/`verifyAdminIfNeeded`
|
|
498
|
+
* ahead of the schema. The store's own refusal travels from here rather than
|
|
499
|
+
* being folded into "not an admin": a caller it does not hold is refused
|
|
500
|
+
* `Unauthorized`, which is the answer the token gate gives.
|
|
501
|
+
*/
|
|
502
|
+
const callerRecord = async () => {
|
|
503
|
+
const recordsService = required();
|
|
504
|
+
const subject = await caller();
|
|
505
|
+
return recordsService.getUser(subject, {
|
|
506
|
+
uid: String(subject?.userId ?? '')
|
|
507
|
+
});
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* `verifyAdminIfNeeded`: the caller is an administrator, or the account the
|
|
511
|
+
* route names is their own. Answers whether they are an administrator, which
|
|
512
|
+
* is what the schema is built with on an installation.
|
|
513
|
+
*/
|
|
514
|
+
const verifyAdminIfNeeded = async (target) => {
|
|
515
|
+
const me = await callerRecord();
|
|
516
|
+
if (me.isAdmin)
|
|
517
|
+
return true;
|
|
518
|
+
const ownAccount = (target.uid !== undefined && target.uid === me.uid) ||
|
|
519
|
+
(target.username !== undefined && target.username === me.username);
|
|
520
|
+
if (!ownAccount)
|
|
521
|
+
throw new types_js_1.ApiError(401, 'Admin account required');
|
|
522
|
+
return false;
|
|
523
|
+
};
|
|
316
524
|
const required = () => {
|
|
317
525
|
if (!records)
|
|
318
526
|
throw new types_js_1.ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
|
|
319
527
|
return records;
|
|
320
528
|
};
|
|
529
|
+
/**
|
|
530
|
+
* The routes whose caller gate and body rules belong to the controller.
|
|
531
|
+
*
|
|
532
|
+
* An installation mounts `authenticateAccessToken`, then `verifyAdmin` or
|
|
533
|
+
* `verifyAdminIfNeeded`, and only then the schema - so on these routes the caller
|
|
534
|
+
* is refused before a field is read. And on the update and delete routes the
|
|
535
|
+
* schema is `updateUserValidation`'s or `deleteUserValidation`'s rather than the
|
|
536
|
+
* document's: every string on an update is optional, the two flags are declared
|
|
537
|
+
* only for an administrator, and a deletion carries the caller's password, which
|
|
538
|
+
* is checked against the password schema before it is compared.
|
|
539
|
+
*
|
|
540
|
+
* One entry per route answers both questions and hands back the body to apply, so
|
|
541
|
+
* the gate and the field rules it belongs with cannot drift apart, and the shared
|
|
542
|
+
* `validate` - which knows only what the document states - is skipped for exactly
|
|
543
|
+
* these routes rather than for a list that has to agree with the switch below.
|
|
544
|
+
*/
|
|
545
|
+
const controllerRules = {
|
|
546
|
+
'POST /SASjsApi/user': async (request) => {
|
|
547
|
+
if (!(await callerRecord()).isAdmin)
|
|
548
|
+
throw new types_js_1.ApiError(401, 'Admin account required');
|
|
549
|
+
return { body: userCreate(request.body || {}) };
|
|
550
|
+
},
|
|
551
|
+
'POST /SASjsApi/group': async (request) => {
|
|
552
|
+
if (!(await callerRecord()).isAdmin)
|
|
553
|
+
throw new types_js_1.ApiError(401, 'Admin account required');
|
|
554
|
+
return { body: groupCreate(request.body || {}) };
|
|
555
|
+
},
|
|
556
|
+
'PATCH /SASjsApi/user/{uid}': async (request) => {
|
|
557
|
+
const admin = await verifyAdminIfNeeded({
|
|
558
|
+
uid: String(request.params?.uid ?? '')
|
|
559
|
+
});
|
|
560
|
+
return { body: userUpdate(request.body || {}, admin) };
|
|
561
|
+
},
|
|
562
|
+
'PATCH /SASjsApi/user/by/username/{username}': async (request) => {
|
|
563
|
+
// the gate compares the raw parameter, as the server's does, and the schema
|
|
564
|
+
// checks it before the body is read
|
|
565
|
+
const admin = await verifyAdminIfNeeded({
|
|
566
|
+
username: String(request.params?.username ?? '')
|
|
567
|
+
});
|
|
568
|
+
const username = foldedUsername(request.params?.username);
|
|
569
|
+
return { body: userUpdate(request.body || {}, admin), username };
|
|
570
|
+
},
|
|
571
|
+
'DELETE /SASjsApi/user/by/username/{username}': async (request) => {
|
|
572
|
+
const admin = await verifyAdminIfNeeded({
|
|
573
|
+
username: String(request.params?.username ?? '')
|
|
574
|
+
});
|
|
575
|
+
// the parameter is checked before the body, as `getUserValidation` is mounted
|
|
576
|
+
// ahead of the deletion's own schema
|
|
577
|
+
const username = foldedUsername(request.params?.username);
|
|
578
|
+
return { body: deletionBody(request.body || {}, admin), username };
|
|
579
|
+
},
|
|
580
|
+
'DELETE /SASjsApi/user/{uid}': async (request) => {
|
|
581
|
+
const admin = await verifyAdminIfNeeded({
|
|
582
|
+
uid: String(request.params?.uid ?? '')
|
|
583
|
+
});
|
|
584
|
+
return { body: deletionBody(request.body || {}, admin) };
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
const controllerRule = controllerRules[routeId];
|
|
588
|
+
const controllerAnswer = controllerRule
|
|
589
|
+
? await controllerRule(request)
|
|
590
|
+
: undefined;
|
|
591
|
+
// the routes a controller owns were validated above, after their gate; the
|
|
592
|
+
// admin mounts refuse the caller before the schema, and everything else takes
|
|
593
|
+
// the document's checks as they come
|
|
594
|
+
if (!controllerRule) {
|
|
595
|
+
if (ADMIN_GATED_ROUTES.has(routeId) && !(await callerRecord()).isAdmin)
|
|
596
|
+
throw new types_js_1.ApiError(401, 'Admin account required');
|
|
597
|
+
validate(route, request);
|
|
598
|
+
}
|
|
321
599
|
if (routeId.startsWith('POST /SASjsApi/auth/') ||
|
|
322
600
|
routeId.startsWith('POST /SASLogon/') ||
|
|
323
601
|
routeId === 'GET /SASLogon/logout' ||
|
|
@@ -750,40 +1028,36 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
750
1028
|
return {
|
|
751
1029
|
status: 200,
|
|
752
1030
|
body: await required().getUser(await caller(), {
|
|
753
|
-
username:
|
|
1031
|
+
username: foldedUsername(params.username)
|
|
754
1032
|
})
|
|
755
1033
|
};
|
|
756
1034
|
case 'POST /SASjsApi/user':
|
|
757
1035
|
return {
|
|
758
1036
|
status: 200,
|
|
759
|
-
body: await required().createUser(await caller(),
|
|
760
|
-
username: String(body.username ?? ''),
|
|
761
|
-
displayName: String(body.displayName ?? ''),
|
|
762
|
-
password: String(body.password ?? ''),
|
|
763
|
-
isAdmin: body.isAdmin,
|
|
764
|
-
isActive: body.isActive,
|
|
765
|
-
autoExec: body.autoExec
|
|
766
|
-
})
|
|
1037
|
+
body: await required().createUser(await caller(), controllerAnswer.body)
|
|
767
1038
|
};
|
|
768
1039
|
case 'PATCH /SASjsApi/user/{uid}':
|
|
769
1040
|
return {
|
|
770
1041
|
status: 200,
|
|
771
|
-
body: await required().updateUser(await caller(), { uid: String(params.uid ?? '') },
|
|
1042
|
+
body: await required().updateUser(await caller(), { uid: String(params.uid ?? '') },
|
|
1043
|
+
// the body the controller's own schema accepted, with what Joi converts
|
|
1044
|
+
// already converted
|
|
1045
|
+
controllerAnswer.body)
|
|
772
1046
|
};
|
|
773
1047
|
case 'PATCH /SASjsApi/user/by/username/{username}':
|
|
774
1048
|
return {
|
|
775
1049
|
status: 200,
|
|
776
|
-
body: await required().updateUser(await caller(), { username:
|
|
1050
|
+
body: await required().updateUser(await caller(), { username: controllerAnswer.username ?? '' }, controllerAnswer.body)
|
|
777
1051
|
};
|
|
778
1052
|
case 'DELETE /SASjsApi/user/{uid}':
|
|
779
1053
|
return {
|
|
780
1054
|
status: 200,
|
|
781
|
-
body: await required().deleteUser(await caller(), { uid: String(params.uid ?? '') }, { password: body.password })
|
|
1055
|
+
body: await required().deleteUser(await caller(), { uid: String(params.uid ?? '') }, { password: controllerAnswer.body.password })
|
|
782
1056
|
};
|
|
783
1057
|
case 'DELETE /SASjsApi/user/by/username/{username}':
|
|
784
1058
|
return {
|
|
785
1059
|
status: 200,
|
|
786
|
-
body: await required().deleteUser(await caller(), { username:
|
|
1060
|
+
body: await required().deleteUser(await caller(), { username: controllerAnswer.username ?? '' }, { password: body.password })
|
|
787
1061
|
};
|
|
788
1062
|
case 'POST /SASjsApi/code/lint':
|
|
789
1063
|
if (!code)
|
|
@@ -805,7 +1079,7 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
805
1079
|
filePath: body.filePath,
|
|
806
1080
|
// the body is rebuilt field by field here, so a flag the service reads
|
|
807
1081
|
// has to be named or the request's own answer is lost on the way
|
|
808
|
-
layout:
|
|
1082
|
+
layout: booleanOf(body.layout, 'layout')
|
|
809
1083
|
})
|
|
810
1084
|
};
|
|
811
1085
|
case 'GET /SASjsApi/info/authorizedRoutes':
|
|
@@ -838,9 +1112,10 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
838
1112
|
return {
|
|
839
1113
|
status: 200,
|
|
840
1114
|
body: await required().createGroup(await caller(), {
|
|
841
|
-
name: String(body.name ?? ''),
|
|
842
|
-
|
|
843
|
-
|
|
1115
|
+
name: String(controllerAnswer.body.name ?? ''),
|
|
1116
|
+
// left absent rather than made empty: the service applies the model's default
|
|
1117
|
+
description: controllerAnswer.body.description,
|
|
1118
|
+
isActive: controllerAnswer.body.isActive
|
|
844
1119
|
})
|
|
845
1120
|
};
|
|
846
1121
|
case 'POST /SASjsApi/group/{groupUid}/{userUid}':
|
|
@@ -225,8 +225,9 @@ const createRecordService = (store, options = {}) => {
|
|
|
225
225
|
throw new types_js_1.ApiError(409, 'Username already exists.');
|
|
226
226
|
change.username = body.username;
|
|
227
227
|
}
|
|
228
|
-
|
|
229
|
-
|
|
228
|
+
// the controller always puts the sanitised name in the update, so an update
|
|
229
|
+
// that omits one stores the empty string rather than keeping the old name
|
|
230
|
+
change.displayName = displayName;
|
|
230
231
|
if (body.isAdmin !== undefined)
|
|
231
232
|
change.isAdmin = body.isAdmin;
|
|
232
233
|
if (body.isActive !== undefined)
|
|
@@ -281,7 +282,8 @@ const createRecordService = (store, options = {}) => {
|
|
|
281
282
|
throw new types_js_1.ApiError(409, 'Group name already exists.');
|
|
282
283
|
const created = await store.createGroup({
|
|
283
284
|
name: body.name,
|
|
284
|
-
description
|
|
285
|
+
// the model defaults the field, so an absent description is the model's
|
|
286
|
+
description: body.description ?? 'Group description.',
|
|
285
287
|
isActive: body.isActive !== false
|
|
286
288
|
});
|
|
287
289
|
return groupDetails(created);
|
|
@@ -1095,7 +1095,7 @@ exports.GENERATED_ROUTES = [
|
|
|
1095
1095
|
{
|
|
1096
1096
|
name: 'description',
|
|
1097
1097
|
in: 'body',
|
|
1098
|
-
required:
|
|
1098
|
+
required: false,
|
|
1099
1099
|
type: 'string'
|
|
1100
1100
|
},
|
|
1101
1101
|
{
|
|
@@ -1111,6 +1111,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1111
1111
|
status: 200,
|
|
1112
1112
|
description: 'Ok'
|
|
1113
1113
|
},
|
|
1114
|
+
{
|
|
1115
|
+
status: 400,
|
|
1116
|
+
description: 'A body the schema refuses, e.g. `"isActive" must be a boolean`.'
|
|
1117
|
+
},
|
|
1114
1118
|
{
|
|
1115
1119
|
status: 401,
|
|
1116
1120
|
description: 'Admin account required'
|
|
@@ -1809,6 +1813,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1809
1813
|
status: 200,
|
|
1810
1814
|
description: 'Ok'
|
|
1811
1815
|
},
|
|
1816
|
+
{
|
|
1817
|
+
status: 400,
|
|
1818
|
+
description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
|
|
1819
|
+
},
|
|
1812
1820
|
{
|
|
1813
1821
|
status: 401,
|
|
1814
1822
|
description: 'Admin account required'
|
|
@@ -1845,6 +1853,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1845
1853
|
status: 200,
|
|
1846
1854
|
description: 'Account Deleted!'
|
|
1847
1855
|
},
|
|
1856
|
+
{
|
|
1857
|
+
status: 400,
|
|
1858
|
+
description: 'A password shorter than six characters, or a key the deletion takes none of; e.g. `"password" is required`'
|
|
1859
|
+
},
|
|
1848
1860
|
{
|
|
1849
1861
|
status: 401,
|
|
1850
1862
|
description: 'Admin account required, or invalid password'
|
|
@@ -1901,19 +1913,19 @@ exports.GENERATED_ROUTES = [
|
|
|
1901
1913
|
{
|
|
1902
1914
|
name: 'displayName',
|
|
1903
1915
|
in: 'body',
|
|
1904
|
-
required:
|
|
1916
|
+
required: false,
|
|
1905
1917
|
type: 'string'
|
|
1906
1918
|
},
|
|
1907
1919
|
{
|
|
1908
1920
|
name: 'username',
|
|
1909
1921
|
in: 'body',
|
|
1910
|
-
required:
|
|
1922
|
+
required: false,
|
|
1911
1923
|
type: 'string'
|
|
1912
1924
|
},
|
|
1913
1925
|
{
|
|
1914
1926
|
name: 'password',
|
|
1915
1927
|
in: 'body',
|
|
1916
|
-
required:
|
|
1928
|
+
required: false,
|
|
1917
1929
|
type: 'string'
|
|
1918
1930
|
},
|
|
1919
1931
|
{
|
|
@@ -1941,6 +1953,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1941
1953
|
status: 200,
|
|
1942
1954
|
description: 'Ok'
|
|
1943
1955
|
},
|
|
1956
|
+
{
|
|
1957
|
+
status: 400,
|
|
1958
|
+
description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
|
|
1959
|
+
},
|
|
1944
1960
|
{
|
|
1945
1961
|
status: 401,
|
|
1946
1962
|
description: 'Admin account required'
|
|
@@ -1985,6 +2001,10 @@ exports.GENERATED_ROUTES = [
|
|
|
1985
2001
|
status: 200,
|
|
1986
2002
|
description: 'Account Deleted!'
|
|
1987
2003
|
},
|
|
2004
|
+
{
|
|
2005
|
+
status: 400,
|
|
2006
|
+
description: 'A username the schema refuses, a password shorter than six characters, or a key an administrator\'s deletion takes none of; e.g. `"password" is required`'
|
|
2007
|
+
},
|
|
1988
2008
|
{
|
|
1989
2009
|
status: 401,
|
|
1990
2010
|
description: 'Admin account required, or invalid password'
|
|
@@ -2015,6 +2035,10 @@ exports.GENERATED_ROUTES = [
|
|
|
2015
2035
|
status: 200,
|
|
2016
2036
|
description: 'Ok'
|
|
2017
2037
|
},
|
|
2038
|
+
{
|
|
2039
|
+
status: 400,
|
|
2040
|
+
description: 'A username the schema refuses, e.g. `"username" must only contain alpha-numeric characters`'
|
|
2041
|
+
},
|
|
2018
2042
|
{
|
|
2019
2043
|
status: 401,
|
|
2020
2044
|
description: 'Unauthorized'
|
|
@@ -2041,19 +2065,19 @@ exports.GENERATED_ROUTES = [
|
|
|
2041
2065
|
{
|
|
2042
2066
|
name: 'displayName',
|
|
2043
2067
|
in: 'body',
|
|
2044
|
-
required:
|
|
2068
|
+
required: false,
|
|
2045
2069
|
type: 'string'
|
|
2046
2070
|
},
|
|
2047
2071
|
{
|
|
2048
2072
|
name: 'username',
|
|
2049
2073
|
in: 'body',
|
|
2050
|
-
required:
|
|
2074
|
+
required: false,
|
|
2051
2075
|
type: 'string'
|
|
2052
2076
|
},
|
|
2053
2077
|
{
|
|
2054
2078
|
name: 'password',
|
|
2055
2079
|
in: 'body',
|
|
2056
|
-
required:
|
|
2080
|
+
required: false,
|
|
2057
2081
|
type: 'string'
|
|
2058
2082
|
},
|
|
2059
2083
|
{
|
|
@@ -2081,6 +2105,10 @@ exports.GENERATED_ROUTES = [
|
|
|
2081
2105
|
status: 200,
|
|
2082
2106
|
description: 'Ok'
|
|
2083
2107
|
},
|
|
2108
|
+
{
|
|
2109
|
+
status: 400,
|
|
2110
|
+
description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
|
|
2111
|
+
},
|
|
2084
2112
|
{
|
|
2085
2113
|
status: 401,
|
|
2086
2114
|
description: 'Admin account required'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/corpus/records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAA;AAkB/B,qFAAqF;AACrF,eAAO,MAAM,eAAe,EAAE,eAG7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,eA0C9B,CAAA;AAOD,eAAO,MAAM,aAAa,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../src/corpus/records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAA;AAkB/B,qFAAqF;AACrF,eAAO,MAAM,eAAe,EAAE,eAG7B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,eA0C9B,CAAA;AAOD,eAAO,MAAM,aAAa,EAAE,UAAU,EA25CrC,CAAA"}
|