@revenexx/app-sdk 1.5.0 → 2.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/README.md +92 -7
- package/dist/{chunk-PXQA7E4F.js → chunk-AVWPY5D2.js} +133 -31
- package/dist/chunk-AVWPY5D2.js.map +1 -0
- package/dist/{errors-CWT-wc8L.d.cts → errors-BsKwZ07u.d.cts} +15 -3
- package/dist/{errors-CWT-wc8L.d.ts → errors-BsKwZ07u.d.ts} +15 -3
- package/dist/index.cjs +129 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -5
- package/dist/index.js.map +1 -1
- package/dist/router/index.cjs +106 -30
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +49 -9
- package/dist/router/index.d.ts +49 -9
- package/dist/router/index.js +53 -21
- package/dist/router/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-PXQA7E4F.js.map +0 -1
package/dist/router/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as SettingsDefaults, l as ReadOptions, n as ResolvedSettings, r as SettingsSnapshot, u as WriteOptions, t as SettingsWriteResult, q as SettingsReader, p as SettingsOptions, e as BackdatingOptions, Q as Query, R as Row, P as Page, s as SettingsSource } from '../errors-
|
|
2
|
-
export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING, B as BackdatingEntity, U as BackdatingSource, D as DEFAULT_GATEWAY_ENDPOINT, f as DEFAULT_SETTINGS_ERROR_TTL_MS, g as DEFAULT_SETTINGS_TIMEOUT_MS, h as DEFAULT_SETTINGS_TTL_MS, H as HttpError, k as HttpErrorOptions, M as MAX_MONTHS_BACK, m as Refusal, v as backdated, V as backdatingAllowed, w as backdatingDb, X as badRequest, x as clock, Y as conflict, y as createSettings, Z as forbidden, z as isHttpError, _ as notFound, G as now, I as parseBackdate, J as refusalOf, K as runAt } from '../errors-
|
|
1
|
+
import { o as SettingsDefaults, l as ReadOptions, n as ResolvedSettings, r as SettingsSnapshot, u as WriteOptions, t as SettingsWriteResult, q as SettingsReader, p as SettingsOptions, e as BackdatingOptions, Q as Query, R as Row, P as Page, s as SettingsSource } from '../errors-BsKwZ07u.cjs';
|
|
2
|
+
export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING, B as BackdatingEntity, U as BackdatingSource, D as DEFAULT_GATEWAY_ENDPOINT, f as DEFAULT_SETTINGS_ERROR_TTL_MS, g as DEFAULT_SETTINGS_TIMEOUT_MS, h as DEFAULT_SETTINGS_TTL_MS, H as HttpError, k as HttpErrorOptions, M as MAX_MONTHS_BACK, m as Refusal, v as backdated, V as backdatingAllowed, w as backdatingDb, X as badRequest, x as clock, Y as conflict, y as createSettings, Z as forbidden, z as isHttpError, _ as notFound, G as now, I as parseBackdate, J as refusalOf, K as runAt } from '../errors-BsKwZ07u.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Who is acting — the person behind a request, as the platform established
|
|
@@ -31,6 +31,18 @@ export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING
|
|
|
31
31
|
* app deciding an approval has to be able to tell the two apart. An app that
|
|
32
32
|
* only attributes — a "last edited by" — can ignore it.
|
|
33
33
|
*
|
|
34
|
+
* A third person arrives the same way (ADR-0132 §9): a SALES REP.
|
|
35
|
+
* The rep portal's server asserts `rep:<rep_code>`, the gateway resolves it
|
|
36
|
+
* through the `sales-reps` app's role provider, and injects
|
|
37
|
+
* `X-Revenexx-Caller: rep`, `X-Revenexx-Rep` (the rep code) and the
|
|
38
|
+
* permissions — never the contact headers. A rep is always ASSERTED, and
|
|
39
|
+
* reads as the `rep` plane.
|
|
40
|
+
*
|
|
41
|
+
* The record-history envelope (`X-Revenexx-Audit`) is not read here. It is
|
|
42
|
+
* Baseline's evidence, not the app's: the adapters forward it to the data
|
|
43
|
+
* plane unchanged (adapters/runtime.ts, adapters/remote.ts), and the gateway
|
|
44
|
+
* signs a rep into it the same way it signs a contact.
|
|
45
|
+
*
|
|
34
46
|
* Every header read here is set ONLY by the gateway: it builds a fresh header
|
|
35
47
|
* set per dispatch and strips any copy a caller sent. So `actor.trust` cannot
|
|
36
48
|
* be talked up from outside, and an app never has to decide whether to believe
|
|
@@ -42,6 +54,9 @@ type ActorTrust = 'authenticated' | 'asserted' | 'none';
|
|
|
42
54
|
* Which side of the platform the caller is on.
|
|
43
55
|
*
|
|
44
56
|
* - `contact` — one of the tenant's own people: a buyer, an approver.
|
|
57
|
+
* - `rep` — one of the merchant's sales reps, asserted by the rep portal and
|
|
58
|
+
* named by their rep code (ADR-0132). Not a buyer: a rep acting FOR a buyer
|
|
59
|
+
* does so through a buyer session, which is the `contact` plane.
|
|
45
60
|
* - `operator` — a human the PLATFORM knows and the tenant's records do not.
|
|
46
61
|
* Back office: Cockpit staff, support, a partner operating the tenant. There
|
|
47
62
|
* is no contact to check a per-row rule against, and that absence is the
|
|
@@ -52,18 +67,23 @@ type ActorTrust = 'authenticated' | 'asserted' | 'none';
|
|
|
52
67
|
* treating "no contact resolved" as "must be the platform", which is also what
|
|
53
68
|
* an unknown customer looks like.
|
|
54
69
|
*/
|
|
55
|
-
type ActorPlane = 'contact' | 'operator' | 'system';
|
|
70
|
+
type ActorPlane = 'rep' | 'contact' | 'operator' | 'system';
|
|
56
71
|
/** The acting person, as far as the platform can state it. */
|
|
57
72
|
interface Actor {
|
|
58
73
|
/** The authenticated human's platform subject, or null when none was proven. */
|
|
59
74
|
user: string | null;
|
|
60
75
|
/** Their email claim, or null. Attribution — never a lookup key to trust on its own. */
|
|
61
76
|
email: string | null;
|
|
62
|
-
/** The `customers` contact the platform resolved them to, or null. */
|
|
77
|
+
/** The `customers` contact the platform resolved them to, or null. Always null for a rep. */
|
|
63
78
|
contact: string | null;
|
|
64
|
-
/** That contact's organization, or null. */
|
|
79
|
+
/** That contact's organization, or null. Always null for a rep. */
|
|
65
80
|
organization: string | null;
|
|
66
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The sales rep's code when the gateway resolved a rep (`X-Revenexx-Caller:
|
|
83
|
+
* rep` with `X-Revenexx-Rep`), or null. Set only when both arrive.
|
|
84
|
+
*/
|
|
85
|
+
rep: string | null;
|
|
86
|
+
/** The permissions the tenant's role provider granted them. Empty when there is no contact or rep. */
|
|
67
87
|
permissions: string[];
|
|
68
88
|
/** How well `contact` is known. `none` when nobody was established at all. */
|
|
69
89
|
trust: ActorTrust;
|
|
@@ -88,6 +108,10 @@ declare const ACTOR_HEADERS: {
|
|
|
88
108
|
readonly contact: "x-revenexx-contact";
|
|
89
109
|
readonly organization: "x-revenexx-organization";
|
|
90
110
|
readonly permissions: "x-revenexx-permissions";
|
|
111
|
+
/** `contact` or `rep` — the kind of person the gateway resolved. */
|
|
112
|
+
readonly caller: "x-revenexx-caller";
|
|
113
|
+
/** The rep's code, beside `caller: rep`, percent-encoded as UTF-8 (RFC 3986). */
|
|
114
|
+
readonly rep: "x-revenexx-rep";
|
|
91
115
|
};
|
|
92
116
|
/**
|
|
93
117
|
* Read the acting person out of a request's headers.
|
|
@@ -196,8 +220,8 @@ interface RouteContext<D extends SettingsDefaults = SettingsDefaults> {
|
|
|
196
220
|
*
|
|
197
221
|
* `c.tenant` says whose data this is; this says whose hand is on it. Read
|
|
198
222
|
* `c.actor.authenticated()` before enforcing a per-person rule, and
|
|
199
|
-
* `c.actor.plane` to tell one of the tenant's contacts from
|
|
200
|
-
* operator
|
|
223
|
+
* `c.actor.plane` to tell one of the tenant's contacts from one of the
|
|
224
|
+
* merchant's sales reps, a back-office operator or a system caller. Never derive either from the context
|
|
201
225
|
* token's claims: those describe the calling SYSTEM.
|
|
202
226
|
*/
|
|
203
227
|
actor: Actor;
|
|
@@ -327,9 +351,25 @@ interface CrudOptions {
|
|
|
327
351
|
* Column metadata (from the generated ENTITIES) — enables `?col=value` list
|
|
328
352
|
* filters. A list query key that is neither a column, a reserved key
|
|
329
353
|
* (`limit`, `offset`, `order`) nor declared in `queryParams` is refused with
|
|
330
|
-
* `400 unknown_filter`. Without `columns`, only those keys
|
|
354
|
+
* `400 unknown_filter`. Without `columns`, only those keys and the columns
|
|
355
|
+
* the entity's flags add are accepted.
|
|
331
356
|
*/
|
|
332
357
|
columns?: Record<string, unknown>;
|
|
358
|
+
/**
|
|
359
|
+
* The entity's schema flags. Read from the repo when it is an entity client
|
|
360
|
+
* of this SDK (`db.notes`), as PHP's `Crud::mount` reads them from the
|
|
361
|
+
* `Entity`. A repo of your own — a wrapper that rebuilds the client's methods
|
|
362
|
+
* — carries no descriptor: pass `trash: true` here, or its trash columns are
|
|
363
|
+
* guarded only when `columns` names `trash_batch`. A flag is only ever added:
|
|
364
|
+
* `trash: false` does not switch off what the descriptor says. The columns they add —
|
|
365
|
+
* `trash: true` the trash columns, `external_id: true` `external_id` — filter
|
|
366
|
+
* a list like a declared column, whether or not `columns` names them, unless
|
|
367
|
+
* `queryParams` claims the key. With `trash: true`, `POST` / `PUT` refuse a
|
|
368
|
+
* body that sets a trash column (`400 read_only_field`): only the trash
|
|
369
|
+
* routes write them.
|
|
370
|
+
*/
|
|
371
|
+
trash?: boolean;
|
|
372
|
+
external_id?: boolean;
|
|
333
373
|
/**
|
|
334
374
|
* Extra list query parameters the App handles itself (e.g. read by
|
|
335
375
|
* middleware, a wrapping handler, or simply tolerated). The list route
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as SettingsDefaults, l as ReadOptions, n as ResolvedSettings, r as SettingsSnapshot, u as WriteOptions, t as SettingsWriteResult, q as SettingsReader, p as SettingsOptions, e as BackdatingOptions, Q as Query, R as Row, P as Page, s as SettingsSource } from '../errors-
|
|
2
|
-
export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING, B as BackdatingEntity, U as BackdatingSource, D as DEFAULT_GATEWAY_ENDPOINT, f as DEFAULT_SETTINGS_ERROR_TTL_MS, g as DEFAULT_SETTINGS_TIMEOUT_MS, h as DEFAULT_SETTINGS_TTL_MS, H as HttpError, k as HttpErrorOptions, M as MAX_MONTHS_BACK, m as Refusal, v as backdated, V as backdatingAllowed, w as backdatingDb, X as badRequest, x as clock, Y as conflict, y as createSettings, Z as forbidden, z as isHttpError, _ as notFound, G as now, I as parseBackdate, J as refusalOf, K as runAt } from '../errors-
|
|
1
|
+
import { o as SettingsDefaults, l as ReadOptions, n as ResolvedSettings, r as SettingsSnapshot, u as WriteOptions, t as SettingsWriteResult, q as SettingsReader, p as SettingsOptions, e as BackdatingOptions, Q as Query, R as Row, P as Page, s as SettingsSource } from '../errors-BsKwZ07u.js';
|
|
2
|
+
export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING, B as BackdatingEntity, U as BackdatingSource, D as DEFAULT_GATEWAY_ENDPOINT, f as DEFAULT_SETTINGS_ERROR_TTL_MS, g as DEFAULT_SETTINGS_TIMEOUT_MS, h as DEFAULT_SETTINGS_TTL_MS, H as HttpError, k as HttpErrorOptions, M as MAX_MONTHS_BACK, m as Refusal, v as backdated, V as backdatingAllowed, w as backdatingDb, X as badRequest, x as clock, Y as conflict, y as createSettings, Z as forbidden, z as isHttpError, _ as notFound, G as now, I as parseBackdate, J as refusalOf, K as runAt } from '../errors-BsKwZ07u.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Who is acting — the person behind a request, as the platform established
|
|
@@ -31,6 +31,18 @@ export { L as BACKDATING_FIELD, N as BACKDATING_INVALID, T as BACKDATING_SETTING
|
|
|
31
31
|
* app deciding an approval has to be able to tell the two apart. An app that
|
|
32
32
|
* only attributes — a "last edited by" — can ignore it.
|
|
33
33
|
*
|
|
34
|
+
* A third person arrives the same way (ADR-0132 §9): a SALES REP.
|
|
35
|
+
* The rep portal's server asserts `rep:<rep_code>`, the gateway resolves it
|
|
36
|
+
* through the `sales-reps` app's role provider, and injects
|
|
37
|
+
* `X-Revenexx-Caller: rep`, `X-Revenexx-Rep` (the rep code) and the
|
|
38
|
+
* permissions — never the contact headers. A rep is always ASSERTED, and
|
|
39
|
+
* reads as the `rep` plane.
|
|
40
|
+
*
|
|
41
|
+
* The record-history envelope (`X-Revenexx-Audit`) is not read here. It is
|
|
42
|
+
* Baseline's evidence, not the app's: the adapters forward it to the data
|
|
43
|
+
* plane unchanged (adapters/runtime.ts, adapters/remote.ts), and the gateway
|
|
44
|
+
* signs a rep into it the same way it signs a contact.
|
|
45
|
+
*
|
|
34
46
|
* Every header read here is set ONLY by the gateway: it builds a fresh header
|
|
35
47
|
* set per dispatch and strips any copy a caller sent. So `actor.trust` cannot
|
|
36
48
|
* be talked up from outside, and an app never has to decide whether to believe
|
|
@@ -42,6 +54,9 @@ type ActorTrust = 'authenticated' | 'asserted' | 'none';
|
|
|
42
54
|
* Which side of the platform the caller is on.
|
|
43
55
|
*
|
|
44
56
|
* - `contact` — one of the tenant's own people: a buyer, an approver.
|
|
57
|
+
* - `rep` — one of the merchant's sales reps, asserted by the rep portal and
|
|
58
|
+
* named by their rep code (ADR-0132). Not a buyer: a rep acting FOR a buyer
|
|
59
|
+
* does so through a buyer session, which is the `contact` plane.
|
|
45
60
|
* - `operator` — a human the PLATFORM knows and the tenant's records do not.
|
|
46
61
|
* Back office: Cockpit staff, support, a partner operating the tenant. There
|
|
47
62
|
* is no contact to check a per-row rule against, and that absence is the
|
|
@@ -52,18 +67,23 @@ type ActorTrust = 'authenticated' | 'asserted' | 'none';
|
|
|
52
67
|
* treating "no contact resolved" as "must be the platform", which is also what
|
|
53
68
|
* an unknown customer looks like.
|
|
54
69
|
*/
|
|
55
|
-
type ActorPlane = 'contact' | 'operator' | 'system';
|
|
70
|
+
type ActorPlane = 'rep' | 'contact' | 'operator' | 'system';
|
|
56
71
|
/** The acting person, as far as the platform can state it. */
|
|
57
72
|
interface Actor {
|
|
58
73
|
/** The authenticated human's platform subject, or null when none was proven. */
|
|
59
74
|
user: string | null;
|
|
60
75
|
/** Their email claim, or null. Attribution — never a lookup key to trust on its own. */
|
|
61
76
|
email: string | null;
|
|
62
|
-
/** The `customers` contact the platform resolved them to, or null. */
|
|
77
|
+
/** The `customers` contact the platform resolved them to, or null. Always null for a rep. */
|
|
63
78
|
contact: string | null;
|
|
64
|
-
/** That contact's organization, or null. */
|
|
79
|
+
/** That contact's organization, or null. Always null for a rep. */
|
|
65
80
|
organization: string | null;
|
|
66
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* The sales rep's code when the gateway resolved a rep (`X-Revenexx-Caller:
|
|
83
|
+
* rep` with `X-Revenexx-Rep`), or null. Set only when both arrive.
|
|
84
|
+
*/
|
|
85
|
+
rep: string | null;
|
|
86
|
+
/** The permissions the tenant's role provider granted them. Empty when there is no contact or rep. */
|
|
67
87
|
permissions: string[];
|
|
68
88
|
/** How well `contact` is known. `none` when nobody was established at all. */
|
|
69
89
|
trust: ActorTrust;
|
|
@@ -88,6 +108,10 @@ declare const ACTOR_HEADERS: {
|
|
|
88
108
|
readonly contact: "x-revenexx-contact";
|
|
89
109
|
readonly organization: "x-revenexx-organization";
|
|
90
110
|
readonly permissions: "x-revenexx-permissions";
|
|
111
|
+
/** `contact` or `rep` — the kind of person the gateway resolved. */
|
|
112
|
+
readonly caller: "x-revenexx-caller";
|
|
113
|
+
/** The rep's code, beside `caller: rep`, percent-encoded as UTF-8 (RFC 3986). */
|
|
114
|
+
readonly rep: "x-revenexx-rep";
|
|
91
115
|
};
|
|
92
116
|
/**
|
|
93
117
|
* Read the acting person out of a request's headers.
|
|
@@ -196,8 +220,8 @@ interface RouteContext<D extends SettingsDefaults = SettingsDefaults> {
|
|
|
196
220
|
*
|
|
197
221
|
* `c.tenant` says whose data this is; this says whose hand is on it. Read
|
|
198
222
|
* `c.actor.authenticated()` before enforcing a per-person rule, and
|
|
199
|
-
* `c.actor.plane` to tell one of the tenant's contacts from
|
|
200
|
-
* operator
|
|
223
|
+
* `c.actor.plane` to tell one of the tenant's contacts from one of the
|
|
224
|
+
* merchant's sales reps, a back-office operator or a system caller. Never derive either from the context
|
|
201
225
|
* token's claims: those describe the calling SYSTEM.
|
|
202
226
|
*/
|
|
203
227
|
actor: Actor;
|
|
@@ -327,9 +351,25 @@ interface CrudOptions {
|
|
|
327
351
|
* Column metadata (from the generated ENTITIES) — enables `?col=value` list
|
|
328
352
|
* filters. A list query key that is neither a column, a reserved key
|
|
329
353
|
* (`limit`, `offset`, `order`) nor declared in `queryParams` is refused with
|
|
330
|
-
* `400 unknown_filter`. Without `columns`, only those keys
|
|
354
|
+
* `400 unknown_filter`. Without `columns`, only those keys and the columns
|
|
355
|
+
* the entity's flags add are accepted.
|
|
331
356
|
*/
|
|
332
357
|
columns?: Record<string, unknown>;
|
|
358
|
+
/**
|
|
359
|
+
* The entity's schema flags. Read from the repo when it is an entity client
|
|
360
|
+
* of this SDK (`db.notes`), as PHP's `Crud::mount` reads them from the
|
|
361
|
+
* `Entity`. A repo of your own — a wrapper that rebuilds the client's methods
|
|
362
|
+
* — carries no descriptor: pass `trash: true` here, or its trash columns are
|
|
363
|
+
* guarded only when `columns` names `trash_batch`. A flag is only ever added:
|
|
364
|
+
* `trash: false` does not switch off what the descriptor says. The columns they add —
|
|
365
|
+
* `trash: true` the trash columns, `external_id: true` `external_id` — filter
|
|
366
|
+
* a list like a declared column, whether or not `columns` names them, unless
|
|
367
|
+
* `queryParams` claims the key. With `trash: true`, `POST` / `PUT` refuse a
|
|
368
|
+
* body that sets a trash column (`400 read_only_field`): only the trash
|
|
369
|
+
* routes write them.
|
|
370
|
+
*/
|
|
371
|
+
trash?: boolean;
|
|
372
|
+
external_id?: boolean;
|
|
333
373
|
/**
|
|
334
374
|
* Extra list query parameters the App handles itself (e.g. read by
|
|
335
375
|
* middleware, a wrapping handler, or simply tolerated). The list route
|
package/dist/router/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
HttpError,
|
|
11
11
|
MAX_MONTHS_BACK,
|
|
12
12
|
OPS,
|
|
13
|
+
assertNoTrashFields,
|
|
13
14
|
backdated,
|
|
14
15
|
backdatingAllowed,
|
|
15
16
|
backdatingDb,
|
|
@@ -18,17 +19,22 @@ import {
|
|
|
18
19
|
clock,
|
|
19
20
|
conflict,
|
|
20
21
|
createSettings,
|
|
22
|
+
describedEntity,
|
|
23
|
+
flagColumns,
|
|
21
24
|
forbidden,
|
|
25
|
+
guardsTrash,
|
|
22
26
|
isHttpError,
|
|
27
|
+
isList,
|
|
23
28
|
notFound,
|
|
24
29
|
now,
|
|
30
|
+
oneRecordRefusal,
|
|
25
31
|
parseBackdate,
|
|
26
32
|
refusalBody,
|
|
27
33
|
refusalOf,
|
|
28
34
|
requestedMoment,
|
|
29
35
|
runAt,
|
|
30
36
|
updateFields
|
|
31
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-AVWPY5D2.js";
|
|
32
38
|
|
|
33
39
|
// src/instrument.ts
|
|
34
40
|
var started = false;
|
|
@@ -83,26 +89,42 @@ var ACTOR_HEADERS = {
|
|
|
83
89
|
trust: "x-revenexx-actor-trust",
|
|
84
90
|
contact: "x-revenexx-contact",
|
|
85
91
|
organization: "x-revenexx-organization",
|
|
86
|
-
permissions: "x-revenexx-permissions"
|
|
92
|
+
permissions: "x-revenexx-permissions",
|
|
93
|
+
/** `contact` or `rep` — the kind of person the gateway resolved. */
|
|
94
|
+
caller: "x-revenexx-caller",
|
|
95
|
+
/** The rep's code, beside `caller: rep`, percent-encoded as UTF-8 (RFC 3986). */
|
|
96
|
+
rep: "x-revenexx-rep"
|
|
87
97
|
};
|
|
88
98
|
var nullIfEmpty = (v) => v.trim() === "" ? null : v.trim();
|
|
99
|
+
var decodeRep = (v) => {
|
|
100
|
+
if (v === null) return null;
|
|
101
|
+
try {
|
|
102
|
+
return nullIfEmpty(decodeURIComponent(v));
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
89
107
|
function actorFrom(header) {
|
|
90
108
|
const read = (name) => {
|
|
91
109
|
const v = header(name);
|
|
92
110
|
return typeof v === "string" ? v : "";
|
|
93
111
|
};
|
|
94
112
|
const user = nullIfEmpty(read(ACTOR_HEADERS.user));
|
|
95
|
-
const
|
|
96
|
-
const
|
|
113
|
+
const isRepCall = read(ACTOR_HEADERS.caller).trim().toLowerCase() === "rep";
|
|
114
|
+
const rep = isRepCall ? decodeRep(nullIfEmpty(read(ACTOR_HEADERS.rep))) : null;
|
|
115
|
+
const contact = isRepCall ? null : nullIfEmpty(read(ACTOR_HEADERS.contact));
|
|
116
|
+
const organization = isRepCall ? null : nullIfEmpty(read(ACTOR_HEADERS.organization));
|
|
117
|
+
const permissions = isRepCall && rep === null ? [] : read(ACTOR_HEADERS.permissions).split(",").map((p) => p.trim()).filter(Boolean);
|
|
97
118
|
const raw = read(ACTOR_HEADERS.trust).trim().toLowerCase();
|
|
98
|
-
const trust = user === null && contact === null ? "none" : user !== null && raw === "authenticated" ? "authenticated" : "asserted";
|
|
99
|
-
const plane = contact !== null ? "contact" : user !== null ? "operator" : "system";
|
|
119
|
+
const trust = user === null && contact === null && rep === null ? "none" : !isRepCall && user !== null && raw === "authenticated" ? "authenticated" : "asserted";
|
|
120
|
+
const plane = rep !== null ? "rep" : contact !== null ? "contact" : user !== null ? "operator" : "system";
|
|
100
121
|
const held = new Set(permissions);
|
|
101
122
|
return {
|
|
102
123
|
user,
|
|
103
124
|
email: nullIfEmpty(read(ACTOR_HEADERS.email)),
|
|
104
125
|
contact,
|
|
105
|
-
organization
|
|
126
|
+
organization,
|
|
127
|
+
rep,
|
|
106
128
|
permissions,
|
|
107
129
|
trust,
|
|
108
130
|
plane,
|
|
@@ -321,13 +343,11 @@ function createApp(options = {}) {
|
|
|
321
343
|
const fields = matched.route.backdating;
|
|
322
344
|
if (!fields) return await matched.route.handler(c);
|
|
323
345
|
const at = await requestedMoment(c, fields);
|
|
324
|
-
if (at)
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
c.body = body;
|
|
330
|
-
}
|
|
346
|
+
if (at) span.setAttribute("revenexx.backdated_at", at);
|
|
347
|
+
if (strip && fields.some((field) => Object.prototype.hasOwnProperty.call(c.body ?? {}, field))) {
|
|
348
|
+
const body = { ...c.body };
|
|
349
|
+
for (const field of fields) delete body[field];
|
|
350
|
+
c.body = body;
|
|
331
351
|
}
|
|
332
352
|
const route = matched.route;
|
|
333
353
|
return await runAt(at, () => route.handler(c));
|
|
@@ -380,13 +400,12 @@ function assertJsonFilter(column, value) {
|
|
|
380
400
|
);
|
|
381
401
|
}
|
|
382
402
|
}
|
|
383
|
-
function assertKnownKeys(query, opts) {
|
|
384
|
-
const columns = opts.columns ?? {};
|
|
403
|
+
function assertKnownKeys(query, opts, flags) {
|
|
385
404
|
const extra = opts.queryParams ?? [];
|
|
386
|
-
const known = (k) =>
|
|
405
|
+
const known = (k) => isFilterColumn(opts, flags, k) || RESERVED_LIST_QUERY_KEYS.includes(k) || extra.includes(k);
|
|
387
406
|
const unknown = Object.keys(query).filter((k) => !known(k));
|
|
388
407
|
if (unknown.length === 0) return;
|
|
389
|
-
const allowed = [.../* @__PURE__ */ new Set([...Object.keys(columns), ...RESERVED_LIST_QUERY_KEYS, ...extra])].sort();
|
|
408
|
+
const allowed = [.../* @__PURE__ */ new Set([...Object.keys(opts.columns ?? {}), ...flagColumns(flags), ...RESERVED_LIST_QUERY_KEYS, ...extra])].sort();
|
|
390
409
|
const quoted = unknown.map((k) => `'${k}'`).join(", ");
|
|
391
410
|
throw new HttpError(
|
|
392
411
|
400,
|
|
@@ -395,6 +414,10 @@ function assertKnownKeys(query, opts) {
|
|
|
395
414
|
{ code: "unknown_filter" }
|
|
396
415
|
);
|
|
397
416
|
}
|
|
417
|
+
function isFilterColumn(opts, flags, k) {
|
|
418
|
+
if (opts.columns && Object.prototype.hasOwnProperty.call(opts.columns, k)) return true;
|
|
419
|
+
return !(opts.queryParams ?? []).includes(k) && flagColumns(flags).includes(k);
|
|
420
|
+
}
|
|
398
421
|
var OPERATOR_PREFIX = new RegExp(`^(?:not|${[...OPS].join("|")})\\.`);
|
|
399
422
|
function assertNoOperator(column, value) {
|
|
400
423
|
if (!OPERATOR_PREFIX.test(value)) return;
|
|
@@ -434,14 +457,19 @@ function mountCrud(app, repo, opts) {
|
|
|
434
457
|
const enabled = new Set(opts.only ?? ["list", "get", "create", "update", "delete"]);
|
|
435
458
|
const defaultLimit = opts.defaultLimit ?? 50;
|
|
436
459
|
const maxLimit = opts.maxLimit ?? 200;
|
|
460
|
+
const described = describedEntity(repo);
|
|
461
|
+
const flags = {
|
|
462
|
+
trash: guardsTrash(opts.trash, described?.trash, opts.columns),
|
|
463
|
+
external_id: opts.external_id === true || described?.external_id === true
|
|
464
|
+
};
|
|
437
465
|
if (enabled.has("list")) {
|
|
438
466
|
app.get(base, async (c) => {
|
|
439
|
-
assertKnownKeys(c.query, opts);
|
|
467
|
+
assertKnownKeys(c.query, opts, flags);
|
|
440
468
|
const where = {};
|
|
441
469
|
for (const [k, v] of Object.entries(c.query)) {
|
|
442
|
-
if (!
|
|
470
|
+
if (!isFilterColumn(opts, flags, k)) continue;
|
|
443
471
|
assertNoOperator(k, v);
|
|
444
|
-
if (isJsonColumn(opts.columns[k])) assertJsonFilter(k, v);
|
|
472
|
+
if (isJsonColumn(opts.columns?.[k])) assertJsonFilter(k, v);
|
|
445
473
|
where[k] = v;
|
|
446
474
|
}
|
|
447
475
|
await assertParentExists(c, opts.parent);
|
|
@@ -464,6 +492,8 @@ function mountCrud(app, repo, opts) {
|
|
|
464
492
|
}
|
|
465
493
|
if (enabled.has("create")) {
|
|
466
494
|
app.post(base, async (c) => {
|
|
495
|
+
if (isList(c.body)) throw oneRecordRefusal();
|
|
496
|
+
assertNoTrashFields(flags, c.body);
|
|
467
497
|
await assertParentExists(c, opts.parent);
|
|
468
498
|
const data = { ...c.body, ...parentWhere(c, opts.parent) };
|
|
469
499
|
return c.json(await repo.create(data), 201);
|
|
@@ -477,6 +507,8 @@ function mountCrud(app, repo, opts) {
|
|
|
477
507
|
}
|
|
478
508
|
if (enabled.has("update")) {
|
|
479
509
|
app.put(idTemplate, async (c) => {
|
|
510
|
+
if (isList(c.body)) throw oneRecordRefusal();
|
|
511
|
+
assertNoTrashFields(flags, c.body);
|
|
480
512
|
const { id } = await fetchOwned(repo, c, opts);
|
|
481
513
|
if (updateFields(c.body).length === 0) throw new HttpError(400, EMPTY_UPDATE_MESSAGE, void 0, { code: "empty_update" });
|
|
482
514
|
const patch = { ...c.body, ...parentWhere(c, opts.parent) };
|