@protobase/schema 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access/resolve.d.ts +1 -0
- package/dist/bottom-bar-errors.d.ts +14 -0
- package/dist/bottom-bar-errors.js +33 -0
- package/dist/bottom-bar.d.ts +35 -0
- package/dist/bottom-bar.js +44 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/menu-href.js +5 -0
- package/dist/model.d.ts +23 -0
- package/dist/user-menu.js +2 -1
- package/dist/webhooks/webhook-resources.d.ts +50 -50
- package/dist/webhooks/webhook-resources.js +78 -78
- package/package.json +1 -1
package/dist/access/resolve.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BottomBarModel } from "./model.js";
|
|
2
|
+
//#region src/bottom-bar-errors.d.ts
|
|
3
|
+
/** What the bottom bars may name. Without `roles` (an app whose roles are not declared) any role is accepted. */
|
|
4
|
+
export type BottomBarNames = {
|
|
5
|
+
resources: readonly string[];
|
|
6
|
+
pages: readonly string[];
|
|
7
|
+
roles?: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Why the bottom bars do not fit the app, as messages; empty when they do. Pure, so it can run wherever the config is
|
|
11
|
+
* known: at startup today, when a bundle is built later.
|
|
12
|
+
*/
|
|
13
|
+
export declare const bottomBarErrors: (bars: BottomBarModel[], names: BottomBarNames) => string[];
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "./bottom-bar.js";
|
|
2
|
+
//#region src/bottom-bar-errors.ts
|
|
3
|
+
const itemErrors = (item, names) => {
|
|
4
|
+
if (item.kind === "resource" && !names.resources.includes(item.resource)) return [`resource "${item.resource}" does not exist`];
|
|
5
|
+
if (item.kind === "page" && !names.pages.includes(item.page)) return [`page "${item.page}" does not exist`];
|
|
6
|
+
return [];
|
|
7
|
+
};
|
|
8
|
+
const barErrors = (bar, names) => {
|
|
9
|
+
const unknownRoles = names.roles ? bar.roles.filter((role) => !names.roles.includes(role)) : [];
|
|
10
|
+
return [
|
|
11
|
+
...bar.roles.length === 0 ? ["needs at least one role"] : [],
|
|
12
|
+
...unknownRoles.map((role) => `role "${role}" is not one of the roles: ${names.roles.join(", ")}`),
|
|
13
|
+
...bar.items.length === 0 ? ["needs at least one item"] : [],
|
|
14
|
+
...bar.items.length > 4 ? [`has ${bar.items.length} items; at most 4 fit beside "More"`] : [],
|
|
15
|
+
...bar.items.flatMap((item) => itemErrors(item, names))
|
|
16
|
+
].map((error) => `Bottom bar "${bar.label}": ${error}`);
|
|
17
|
+
};
|
|
18
|
+
const overlapErrors = (bars) => bars.flatMap((bar, index) => {
|
|
19
|
+
const earlier = bars.slice(0, index);
|
|
20
|
+
const sameLabel = earlier.some((other) => other.label === bar.label) ? [`Two bottom bars are labelled "${bar.label}"; give each its own label`] : [];
|
|
21
|
+
const shared = bar.roles.flatMap((role) => {
|
|
22
|
+
const other = earlier.find((candidate) => candidate.roles.includes(role));
|
|
23
|
+
return other ? [`Bottom bars "${other.label}" and "${bar.label}" both name role "${role}"; a role belongs to one bottom bar`] : [];
|
|
24
|
+
});
|
|
25
|
+
return [...sameLabel, ...shared];
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Why the bottom bars do not fit the app, as messages; empty when they do. Pure, so it can run wherever the config is
|
|
29
|
+
* known: at startup today, when a bundle is built later.
|
|
30
|
+
*/
|
|
31
|
+
const bottomBarErrors = (bars, names) => [...bars.flatMap((bar) => barErrors(bar, names)), ...overlapErrors(bars)];
|
|
32
|
+
//#endregion
|
|
33
|
+
export { bottomBarErrors };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BottomBarItemModel, BottomBarModel } from "./model.js";
|
|
2
|
+
//#region src/bottom-bar.d.ts
|
|
3
|
+
/** The tabs beside the last one, "More", which opens the sidebar: five tabs in all, as on iOS. */
|
|
4
|
+
export declare const maxBottomBarItems = 4;
|
|
5
|
+
declare const items: {
|
|
6
|
+
/** Opens the resource's list. */
|
|
7
|
+
resource: (resource: string, options: {
|
|
8
|
+
label: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
}) => BottomBarItemModel;
|
|
11
|
+
/** Opens a composed page (`page()` from @protobase/layout). */
|
|
12
|
+
page: (page: string, options: {
|
|
13
|
+
label: string;
|
|
14
|
+
icon?: string;
|
|
15
|
+
}) => BottomBarItemModel;
|
|
16
|
+
/** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
|
|
17
|
+
link: (label: string, href: string, options?: {
|
|
18
|
+
icon?: string;
|
|
19
|
+
}) => BottomBarItemModel;
|
|
20
|
+
};
|
|
21
|
+
/** What the server needs from a `bottomBar(...)` export of the config module. */
|
|
22
|
+
export type BottomBarSource = {
|
|
23
|
+
toBottomBarModel(): BottomBarModel;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Tabs at the bottom of the screen on phones, for the users holding one of `roles`. Export one per group of roles; a
|
|
27
|
+
* role belongs to one bottom bar. `label` names the bar where someone with several switches between them.
|
|
28
|
+
*/
|
|
29
|
+
export declare const bottomBar: (options: {
|
|
30
|
+
label: string;
|
|
31
|
+
roles: string[];
|
|
32
|
+
}, build: (m: typeof items) => BottomBarItemModel[]) => BottomBarSource;
|
|
33
|
+
/** The bottom bar of someone working as `role`: the one that names it, since a role belongs to one bar. */
|
|
34
|
+
export declare const bottomBarFor: (bars: readonly BottomBarModel[], role: string | undefined) => BottomBarModel | undefined;
|
|
35
|
+
//#endregion
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isMenuHref } from "./menu-href.js";
|
|
2
|
+
//#region src/bottom-bar.ts
|
|
3
|
+
/** The tabs beside the last one, "More", which opens the sidebar: five tabs in all, as on iOS. */
|
|
4
|
+
const maxBottomBarItems = 4;
|
|
5
|
+
const items = {
|
|
6
|
+
/** Opens the resource's list. */
|
|
7
|
+
resource: (resource, options) => ({
|
|
8
|
+
kind: "resource",
|
|
9
|
+
resource,
|
|
10
|
+
...options
|
|
11
|
+
}),
|
|
12
|
+
/** Opens a composed page (`page()` from @protobase/layout). */
|
|
13
|
+
page: (page, options) => ({
|
|
14
|
+
kind: "page",
|
|
15
|
+
page,
|
|
16
|
+
...options
|
|
17
|
+
}),
|
|
18
|
+
/** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
|
|
19
|
+
link: (label, href, options = {}) => {
|
|
20
|
+
if (!isMenuHref(href)) throw new Error(`Bottom bar link "${label}": href must start with https://, http:// or mailto:`);
|
|
21
|
+
return {
|
|
22
|
+
kind: "link",
|
|
23
|
+
label,
|
|
24
|
+
href,
|
|
25
|
+
...options
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Tabs at the bottom of the screen on phones, for the users holding one of `roles`. Export one per group of roles; a
|
|
31
|
+
* role belongs to one bottom bar. `label` names the bar where someone with several switches between them.
|
|
32
|
+
*/
|
|
33
|
+
const bottomBar = (options, build) => {
|
|
34
|
+
const model = {
|
|
35
|
+
label: options.label,
|
|
36
|
+
roles: [...options.roles],
|
|
37
|
+
items: build(items)
|
|
38
|
+
};
|
|
39
|
+
return { toBottomBarModel: () => structuredClone(model) };
|
|
40
|
+
};
|
|
41
|
+
/** The bottom bar of someone working as `role`: the one that names it, since a role belongs to one bar. */
|
|
42
|
+
const bottomBarFor = (bars, role) => role === void 0 ? void 0 : bars.find((bar) => bar.roles.includes(role));
|
|
43
|
+
//#endregion
|
|
44
|
+
export { bottomBar, bottomBarFor, maxBottomBarItems };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionModel, ActionRun, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterOf, FilterValue, FilterWidgetModel, KeyValue, LayoutItemModel, ListModel, ListQuery, Literal, NavModel, NavRecentModel, NowValue, OrderByItem, RelatedModel, ResourceModel, SaveFeedback, SearchMatch, SearchResultModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
1
|
+
import { ActionModel, ActionRun, BottomBarItemModel, BottomBarModel, ChartGranularity, ChartModel, ChartRange, CheckedFilter, CompareOp, DatePreset, DurationLiteral, DurationUnit, EventModel, EventOperation, FieldFormat, FieldModel, FieldPath, FieldType, FieldViewModel, FileFieldModel, FilterError, FilterErrorCode, FilterExpr, FilterOf, FilterValue, FilterWidgetModel, KeyValue, LayoutItemModel, ListModel, ListQuery, Literal, NavModel, NavRecentModel, NowValue, OrderByItem, RelatedModel, ResourceModel, SaveFeedback, SearchMatch, SearchResultModel, SortSpec, Span, StatusTone, UserMenuItemModel, UserMenuModel, ViewModel } from "./model.js";
|
|
2
2
|
import { AccessAction, AccessContext, AccessFn, AccessResult, AccessUser, FieldAccess, FieldRule } from "./access/types.js";
|
|
3
3
|
import { FileProcessor, FileProcessorInput, checkedAccept, checkedProvider, parseSize } from "./files/file-options.js";
|
|
4
4
|
import { Field } from "./field.js";
|
|
@@ -14,6 +14,8 @@ import { enumLabel } from "./enum-label.js";
|
|
|
14
14
|
import { SearchTerm, matchedSearchField, matchesSearch, searchTerms, termMatches } from "./search-match.js";
|
|
15
15
|
import { defaultRecentLimit, navRecentErrors, statusTones } from "./nav-recent.js";
|
|
16
16
|
import { UserMenuSource, userMenu } from "./user-menu.js";
|
|
17
|
+
import { BottomBarSource, bottomBar, bottomBarFor, maxBottomBarItems } from "./bottom-bar.js";
|
|
18
|
+
import { BottomBarNames, bottomBarErrors } from "./bottom-bar-errors.js";
|
|
17
19
|
import { layout } from "./layout.js";
|
|
18
20
|
import { KeyType, decodeKey, encodeKey, keyTypes } from "./keys.js";
|
|
19
21
|
import { FilterLimits, FilterParse, parseFilter } from "./filter/parse.js";
|
|
@@ -33,4 +35,4 @@ import "./access/index.js";
|
|
|
33
35
|
import { AssistantAction, AssistantActionRequest, AssistantCardPart, AssistantDiff, AssistantEvent, AssistantMessage, AssistantMessageRequest, AssistantPart, AssistantState, AssistantStep, AssistantStepState, AssistantTablePart, AssistantTextPart, AssistantTone, AssistantWidgetPart } from "./assistant/protocol.js";
|
|
34
36
|
import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
|
|
35
37
|
import { readEventStream } from "./assistant/event-stream.js";
|
|
36
|
-
export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type Capability, type CapabilityAction, type CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type DatePreset, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type Field, type FieldAccess, type FieldFormat, type FieldModel, type FieldPath, type FieldRule, type FieldType, type FieldViewModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type KeyType, type KeyValue, type LayoutItemModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type RecordKey, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SearchMatch, type SearchResultModel, type SearchTerm, type SortSpec, type Span, type StatusTone, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type ViewModel, accessWarnings, applyAssistantEvent, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
|
|
38
|
+
export { type AccessAction, type AccessContext, type AccessFn, type AccessResult, type AccessSource, type AccessUser, type ActionModel, type ActionRun, type AssistantAction, type AssistantActionRequest, type AssistantCardPart, type AssistantDiff, type AssistantEvent, type AssistantMessage, type AssistantMessageRequest, type AssistantPart, type AssistantState, type AssistantStep, type AssistantStepState, type AssistantTablePart, type AssistantTextPart, type AssistantTone, type AssistantWidgetPart, type BottomBarItemModel, type BottomBarModel, type BottomBarNames, type BottomBarSource, type Capability, type CapabilityAction, type CapabilityScope, type ChartGranularity, type ChartModel, type ChartRange, type CheckResult, type CheckedFilter, type CompareOp, type DatePreset, type DurationLiteral, type DurationUnit, type EvaluateOptions, type EventActor, type EventContext, type EventHelpers, type EventMatch, type EventModel, type EventOperation, type EventSpec, type Field, type FieldAccess, type FieldFormat, type FieldModel, type FieldPath, type FieldRule, type FieldType, type FieldViewModel, type FileField, type FileFieldModel, type FileProcessor, type FileProcessorInput, type FilterError, type FilterErrorCode, type FilterExpr, type FilterLimits, type FilterOf, type FilterParse, type FilterValue, type FilterWidgetModel, type InferRecord, type KeyType, type KeyValue, type LayoutItemModel, type ListModel, type ListQuery, type Literal, type NavModel, type NavRecentModel, type NowValue, type OrderByCheck, type OrderByItem, type OrderByParse, type RecordKey, type RelatedModel, type ResolveOptions, type ResolvedAccess, type ResourceModel, type Roles, type RolesOptions, type RowFilterOperation, type Rule, type SaveFeedback, type SearchMatch, type SearchResultModel, type SearchTerm, type SortSpec, type Span, type StatusTone, type UserMenuItemModel, type UserMenuModel, type UserMenuSource, type ViewModel, accessWarnings, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@ import { webhookResources } from "./webhooks/webhook-resources.js";
|
|
|
16
16
|
import { enumLabel } from "./enum-label.js";
|
|
17
17
|
import { matchedSearchField, matchesSearch, searchTerms, termMatches } from "./search-match.js";
|
|
18
18
|
import { userMenu } from "./user-menu.js";
|
|
19
|
+
import { bottomBar, bottomBarFor, maxBottomBarItems } from "./bottom-bar.js";
|
|
20
|
+
import { bottomBarErrors } from "./bottom-bar-errors.js";
|
|
19
21
|
import { decodeKey, encodeKey, keyTypes } from "./keys.js";
|
|
20
22
|
import { rule } from "./access/rule.js";
|
|
21
23
|
import { defineRoles } from "./access/roles.js";
|
|
@@ -23,4 +25,4 @@ import { pickView } from "./access/pick-view.js";
|
|
|
23
25
|
import { restrictModel } from "./access/restrict.js";
|
|
24
26
|
import { applyAssistantEvent, emptyAssistantState } from "./assistant/apply-event.js";
|
|
25
27
|
import { readEventStream } from "./assistant/event-stream.js";
|
|
26
|
-
export { accessWarnings, applyAssistantEvent, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
|
|
28
|
+
export { accessWarnings, applyAssistantEvent, bottomBar, bottomBarErrors, bottomBarFor, checkEventFilter, checkFilter, checkOrderBy, checkRecord, checkedAccept, checkedProvider, createWhere, decodeKey, defaultRecentLimit, defineRoles, emptyAssistantState, encodeKey, enumLabel, evaluateFilter, f, fieldsUsedBy, keyTypes, layout as l, matchedSearchField, matchesSearch, maxBottomBarItems, navRecentErrors, parseFilter, parseOrderBy, parseSize, pickView, printFilter, printOrderBy, readEventStream, resolveAccess, resource, restrictModel, rule, searchTerms, statusTones, termMatches, userMenu, view, webhookResources, where };
|
package/dist/model.d.ts
CHANGED
|
@@ -218,6 +218,29 @@ export type UserMenuItemModel = {
|
|
|
218
218
|
export type UserMenuModel = {
|
|
219
219
|
items: UserMenuItemModel[];
|
|
220
220
|
};
|
|
221
|
+
/** A tab of a bottom bar on phones: icon above an explicit label. */
|
|
222
|
+
export type BottomBarItemModel = {
|
|
223
|
+
kind: 'resource';
|
|
224
|
+
resource: string;
|
|
225
|
+
label: string;
|
|
226
|
+
icon?: string;
|
|
227
|
+
} | {
|
|
228
|
+
kind: 'page';
|
|
229
|
+
page: string;
|
|
230
|
+
label: string;
|
|
231
|
+
icon?: string;
|
|
232
|
+
} | {
|
|
233
|
+
kind: 'link';
|
|
234
|
+
label: string;
|
|
235
|
+
href: string;
|
|
236
|
+
icon?: string;
|
|
237
|
+
};
|
|
238
|
+
/** A bottom bar for the users holding one of `roles`; `label` names it in the role view switcher. */
|
|
239
|
+
export type BottomBarModel = {
|
|
240
|
+
label: string;
|
|
241
|
+
roles: string[];
|
|
242
|
+
items: BottomBarItemModel[];
|
|
243
|
+
};
|
|
221
244
|
/**
|
|
222
245
|
* The title replaces `title` in search results; `subtitle` is the second line unless the search matched another search
|
|
223
246
|
* field, which then shows instead. Without a subtitle, the first search field not in the title is the default.
|
package/dist/user-menu.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isMenuHref } from "./menu-href.js";
|
|
1
2
|
//#region src/user-menu.ts
|
|
2
3
|
const items = {
|
|
3
4
|
/** Opens the resource's list. A resource in the user menu is left out of the sidebar. */
|
|
@@ -14,7 +15,7 @@ const items = {
|
|
|
14
15
|
}),
|
|
15
16
|
/** An address outside the admin, opened in a new tab: `https:`, `http:` or `mailto:`. */
|
|
16
17
|
link: (label, href, options = {}) => {
|
|
17
|
-
if (
|
|
18
|
+
if (!isMenuHref(href)) throw new Error(`User menu link "${label}": href must start with https://, http:// or mailto:`);
|
|
18
19
|
return {
|
|
19
20
|
kind: "link",
|
|
20
21
|
label,
|
|
@@ -13,28 +13,28 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
|
|
|
13
13
|
}) => {
|
|
14
14
|
webhookDeliveryLog?: ResourceBuilder<{
|
|
15
15
|
readonly id: Field<string>;
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
16
|
+
readonly subscription_id: Field<string | number>;
|
|
17
|
+
readonly tenant_id: Field<string | null>;
|
|
18
|
+
readonly event_id: Field<string>;
|
|
19
|
+
readonly event_type: Field<string>;
|
|
20
20
|
readonly status: Field<"failed" | "delivered">;
|
|
21
21
|
readonly attempt: Field<number>;
|
|
22
|
-
readonly
|
|
22
|
+
readonly status_code: Field<number | null>;
|
|
23
23
|
readonly response: Field<string | null>;
|
|
24
|
-
readonly
|
|
24
|
+
readonly duration_ms: Field<number>;
|
|
25
25
|
readonly at: Field<string>;
|
|
26
26
|
}, Ref<"id", string>> | undefined;
|
|
27
27
|
webhookDeliveryLogView?: ViewBuilder<ResourceBuilder<{
|
|
28
28
|
readonly id: Field<string>;
|
|
29
|
-
readonly
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
readonly
|
|
29
|
+
readonly subscription_id: Field<string | number>;
|
|
30
|
+
readonly tenant_id: Field<string | null>;
|
|
31
|
+
readonly event_id: Field<string>;
|
|
32
|
+
readonly event_type: Field<string>;
|
|
33
33
|
readonly status: Field<"failed" | "delivered">;
|
|
34
34
|
readonly attempt: Field<number>;
|
|
35
|
-
readonly
|
|
35
|
+
readonly status_code: Field<number | null>;
|
|
36
36
|
readonly response: Field<string | null>;
|
|
37
|
-
readonly
|
|
37
|
+
readonly duration_ms: Field<number>;
|
|
38
38
|
readonly at: Field<string>;
|
|
39
39
|
}, Ref<"id", string>>> | undefined;
|
|
40
40
|
webhookSubscriptions: ResourceBuilder<{
|
|
@@ -47,18 +47,18 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
|
|
|
47
47
|
readonly payload: Field<"full" | "thin">;
|
|
48
48
|
readonly enabled: Field<boolean>;
|
|
49
49
|
readonly secret: Field<string>;
|
|
50
|
-
readonly
|
|
51
|
-
readonly
|
|
52
|
-
readonly
|
|
53
|
-
readonly
|
|
54
|
-
readonly
|
|
55
|
-
readonly
|
|
56
|
-
readonly
|
|
57
|
-
readonly
|
|
58
|
-
readonly
|
|
59
|
-
readonly
|
|
60
|
-
readonly
|
|
61
|
-
readonly
|
|
50
|
+
readonly previous_secret: null;
|
|
51
|
+
readonly previous_secret_until: null;
|
|
52
|
+
readonly tenant_id: Field<string | null>;
|
|
53
|
+
readonly owner_id: Field<string | null>;
|
|
54
|
+
readonly disabled_reason: Field<string | null>;
|
|
55
|
+
readonly last_success_at: Field<string | null>;
|
|
56
|
+
readonly failing_since: Field<string | null>;
|
|
57
|
+
readonly created_at: Field<string>;
|
|
58
|
+
readonly updated_at: Field<string>;
|
|
59
|
+
readonly rotate_secret: Field<boolean>;
|
|
60
|
+
readonly send_test: Field<boolean>;
|
|
61
|
+
readonly resend_failed: Field<boolean>;
|
|
62
62
|
}, Ref<"id", string>>;
|
|
63
63
|
webhookSubscriptionsView: ViewBuilder<ResourceBuilder<{
|
|
64
64
|
readonly id: Field<string>;
|
|
@@ -70,43 +70,43 @@ export declare const webhookResources: (schema: string, { deliveryLog }?: {
|
|
|
70
70
|
readonly payload: Field<"full" | "thin">;
|
|
71
71
|
readonly enabled: Field<boolean>;
|
|
72
72
|
readonly secret: Field<string>;
|
|
73
|
-
readonly
|
|
74
|
-
readonly
|
|
75
|
-
readonly
|
|
76
|
-
readonly
|
|
77
|
-
readonly
|
|
78
|
-
readonly
|
|
79
|
-
readonly
|
|
80
|
-
readonly
|
|
81
|
-
readonly
|
|
82
|
-
readonly
|
|
83
|
-
readonly
|
|
84
|
-
readonly
|
|
73
|
+
readonly previous_secret: null;
|
|
74
|
+
readonly previous_secret_until: null;
|
|
75
|
+
readonly tenant_id: Field<string | null>;
|
|
76
|
+
readonly owner_id: Field<string | null>;
|
|
77
|
+
readonly disabled_reason: Field<string | null>;
|
|
78
|
+
readonly last_success_at: Field<string | null>;
|
|
79
|
+
readonly failing_since: Field<string | null>;
|
|
80
|
+
readonly created_at: Field<string>;
|
|
81
|
+
readonly updated_at: Field<string>;
|
|
82
|
+
readonly rotate_secret: Field<boolean>;
|
|
83
|
+
readonly send_test: Field<boolean>;
|
|
84
|
+
readonly resend_failed: Field<boolean>;
|
|
85
85
|
}, Ref<"id", string>>>;
|
|
86
86
|
webhookDeliveries: ResourceBuilder<{
|
|
87
87
|
readonly id: Field<string>;
|
|
88
|
-
readonly
|
|
89
|
-
readonly
|
|
90
|
-
readonly
|
|
91
|
-
readonly
|
|
88
|
+
readonly subscription_id: Field<string | number>;
|
|
89
|
+
readonly tenant_id: Field<string | null>;
|
|
90
|
+
readonly event_type: Field<string>;
|
|
91
|
+
readonly event_id: Field<string>;
|
|
92
92
|
readonly status: Field<"waiting" | "failed">;
|
|
93
93
|
readonly attempt: Field<number>;
|
|
94
|
-
readonly
|
|
95
|
-
readonly
|
|
96
|
-
readonly
|
|
94
|
+
readonly next_attempt: Field<string | null>;
|
|
95
|
+
readonly last_error: Field<string | null>;
|
|
96
|
+
readonly created_at: Field<string>;
|
|
97
97
|
readonly resend: Field<boolean>;
|
|
98
98
|
}, Ref<"id", string>>;
|
|
99
99
|
webhookDeliveriesView: ViewBuilder<ResourceBuilder<{
|
|
100
100
|
readonly id: Field<string>;
|
|
101
|
-
readonly
|
|
102
|
-
readonly
|
|
103
|
-
readonly
|
|
104
|
-
readonly
|
|
101
|
+
readonly subscription_id: Field<string | number>;
|
|
102
|
+
readonly tenant_id: Field<string | null>;
|
|
103
|
+
readonly event_type: Field<string>;
|
|
104
|
+
readonly event_id: Field<string>;
|
|
105
105
|
readonly status: Field<"waiting" | "failed">;
|
|
106
106
|
readonly attempt: Field<number>;
|
|
107
|
-
readonly
|
|
108
|
-
readonly
|
|
109
|
-
readonly
|
|
107
|
+
readonly next_attempt: Field<string | null>;
|
|
108
|
+
readonly last_error: Field<string | null>;
|
|
109
|
+
readonly created_at: Field<string>;
|
|
110
110
|
readonly resend: Field<boolean>;
|
|
111
111
|
}, Ref<"id", string>>>;
|
|
112
112
|
};
|
|
@@ -4,7 +4,7 @@ import { layout } from "../layout.js";
|
|
|
4
4
|
import { view } from "../view.js";
|
|
5
5
|
//#region src/webhooks/webhook-resources.ts
|
|
6
6
|
/** Webhook subscriptions: a row per subscription someone made in the admin app, scoped to their tenant. */
|
|
7
|
-
const subscriptionsResource = (schema) => resource("
|
|
7
|
+
const subscriptionsResource = (schema) => resource("webhook_subscriptions").table(`${schema}.subscriptions`).fields({
|
|
8
8
|
id: f.uuid().readOnly().dbDefault(),
|
|
9
9
|
name: f.text().min(1).max(100).filterable().sortable(),
|
|
10
10
|
events: f.text().min(1).max(2e3),
|
|
@@ -14,20 +14,20 @@ const subscriptionsResource = (schema) => resource("webhookSubscriptions").table
|
|
|
14
14
|
payload: f.enum(["full", "thin"]).default("full"),
|
|
15
15
|
enabled: f.boolean().default(true).filterable(),
|
|
16
16
|
secret: f.text().sensitive().readOnly().dbDefault(),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}).primaryKey((r) => r.id).tenant((r) => r.
|
|
30
|
-
const subscriptionsView = view("
|
|
17
|
+
previous_secret: null,
|
|
18
|
+
previous_secret_until: null,
|
|
19
|
+
tenant_id: f.text().optional().readOnly(),
|
|
20
|
+
owner_id: f.text().optional().readOnly().dbDefault(),
|
|
21
|
+
disabled_reason: f.text().optional().readOnly(),
|
|
22
|
+
last_success_at: f.timestamp().optional().readOnly().sortable(),
|
|
23
|
+
failing_since: f.timestamp().optional().readOnly(),
|
|
24
|
+
created_at: f.timestamp().readOnly().dbDefault().sortable(),
|
|
25
|
+
updated_at: f.timestamp().readOnly().dbDefault(),
|
|
26
|
+
rotate_secret: f.boolean().default(false),
|
|
27
|
+
send_test: f.boolean().default(false),
|
|
28
|
+
resend_failed: f.boolean().default(false)
|
|
29
|
+
}).primaryKey((r) => r.id).tenant((r) => r.tenant_id).owner((r) => r.owner_id).search((r) => [r.name, r.url]);
|
|
30
|
+
const subscriptionsView = view("webhook_subscriptions").names({
|
|
31
31
|
singular: "Webhook subscription",
|
|
32
32
|
plural: "Webhook subscriptions"
|
|
33
33
|
}).icon("webhook").title((r) => r.name).help("Sends the app's events to a URL as they happen, signed with Standard Webhooks. It delivers as its owner: only the records and fields they may read.").fields((r) => ({
|
|
@@ -40,18 +40,18 @@ const subscriptionsView = view("webhookSubscriptions").names({
|
|
|
40
40
|
thin: "Thin"
|
|
41
41
|
}),
|
|
42
42
|
secret: r.secret.help("Receivers check the webhook-signature header with it"),
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
disabled_reason: r.disabled_reason.label("Disabled because"),
|
|
44
|
+
last_success_at: r.last_success_at.label("Last success"),
|
|
45
|
+
failing_since: r.failing_since.label("Failing since")
|
|
46
46
|
})).list((r) => ({
|
|
47
47
|
columns: [
|
|
48
48
|
r.name,
|
|
49
49
|
r.events,
|
|
50
50
|
r.url,
|
|
51
51
|
r.enabled,
|
|
52
|
-
r.
|
|
52
|
+
r.last_success_at
|
|
53
53
|
],
|
|
54
|
-
sort: [[r.
|
|
54
|
+
sort: [[r.created_at, "desc"]]
|
|
55
55
|
})).layout((r) => [
|
|
56
56
|
layout.section("Subscription", [
|
|
57
57
|
r.name,
|
|
@@ -64,38 +64,38 @@ const subscriptionsView = view("webhookSubscriptions").names({
|
|
|
64
64
|
]),
|
|
65
65
|
layout.section("Signing", [r.secret]),
|
|
66
66
|
layout.sidebar([
|
|
67
|
-
r.
|
|
68
|
-
r.
|
|
69
|
-
r.
|
|
70
|
-
r.
|
|
67
|
+
r.last_success_at,
|
|
68
|
+
r.failing_since,
|
|
69
|
+
r.disabled_reason,
|
|
70
|
+
r.created_at
|
|
71
71
|
]),
|
|
72
72
|
layout.related("Waiting and failed deliveries", {
|
|
73
|
-
resource: "
|
|
74
|
-
field: "
|
|
73
|
+
resource: "webhook_deliveries",
|
|
74
|
+
field: "subscription_id",
|
|
75
75
|
columns: [
|
|
76
|
-
"
|
|
76
|
+
"event_type",
|
|
77
77
|
"status",
|
|
78
78
|
"attempt",
|
|
79
|
-
"
|
|
80
|
-
"
|
|
79
|
+
"next_attempt",
|
|
80
|
+
"last_error"
|
|
81
81
|
]
|
|
82
82
|
})
|
|
83
83
|
]).actions((a) => [
|
|
84
|
-
a.update("
|
|
84
|
+
a.update("send_test", {
|
|
85
85
|
label: "Send test event",
|
|
86
86
|
icon: "send",
|
|
87
|
-
set: {
|
|
87
|
+
set: { send_test: true }
|
|
88
88
|
}),
|
|
89
|
-
a.update("
|
|
89
|
+
a.update("resend_failed", {
|
|
90
90
|
label: "Resend failed",
|
|
91
91
|
icon: "rotate-ccw",
|
|
92
|
-
set: {
|
|
92
|
+
set: { resend_failed: true },
|
|
93
93
|
confirm: "Try every failed delivery of this subscription once more?"
|
|
94
94
|
}),
|
|
95
|
-
a.update("
|
|
95
|
+
a.update("rotate_secret", {
|
|
96
96
|
label: "Rotate secret",
|
|
97
97
|
icon: "key-round",
|
|
98
|
-
set: {
|
|
98
|
+
set: { rotate_secret: true },
|
|
99
99
|
confirm: "Make a new secret? The old one keeps signing too for 24 hours."
|
|
100
100
|
}),
|
|
101
101
|
a.update("disable", {
|
|
@@ -105,51 +105,51 @@ const subscriptionsView = view("webhookSubscriptions").names({
|
|
|
105
105
|
})
|
|
106
106
|
]);
|
|
107
107
|
/** The deliveries of webhook subscriptions that wait for a retry or failed for good: delivery jobs, not a table. */
|
|
108
|
-
const deliveriesResource = (schema) => resource("
|
|
108
|
+
const deliveriesResource = (schema) => resource("webhook_deliveries").table(`${schema}.deliveries`).fields({
|
|
109
109
|
id: f.uuid().readOnly(),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
|
|
111
|
+
tenant_id: f.text().optional().readOnly(),
|
|
112
|
+
event_type: f.text().readOnly().filterable().sortable(),
|
|
113
|
+
event_id: f.text().readOnly().filterable(),
|
|
114
114
|
status: f.enum(["waiting", "failed"]).readOnly().filterable(),
|
|
115
115
|
attempt: f.integer().readOnly(),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
next_attempt: f.timestamp().optional().readOnly().sortable(),
|
|
117
|
+
last_error: f.text().optional().readOnly(),
|
|
118
|
+
created_at: f.timestamp().readOnly().sortable(),
|
|
119
119
|
resend: f.boolean()
|
|
120
|
-
}).primaryKey((r) => r.id).tenant((r) => r.
|
|
120
|
+
}).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
|
|
121
121
|
create: () => false,
|
|
122
122
|
delete: () => false
|
|
123
123
|
});
|
|
124
|
-
const deliveriesView = view("
|
|
124
|
+
const deliveriesView = view("webhook_deliveries").names({
|
|
125
125
|
singular: "Webhook delivery",
|
|
126
126
|
plural: "Webhook deliveries"
|
|
127
|
-
}).icon("send").title((r) => r.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
}).icon("send").title((r) => r.event_type).help("Deliveries that wait for their next try or failed for good. A delivery leaves the list once it succeeds.").fields((r) => ({
|
|
128
|
+
event_type: r.event_type.label("Event"),
|
|
129
|
+
event_id: r.event_id.label("Event id").format("code"),
|
|
130
|
+
next_attempt: r.next_attempt.label("Next try"),
|
|
131
|
+
last_error: r.last_error.label("Last error"),
|
|
132
132
|
attempt: r.attempt.label("Tries")
|
|
133
133
|
})).list((r) => ({
|
|
134
134
|
columns: [
|
|
135
|
-
r.
|
|
136
|
-
r.
|
|
135
|
+
r.event_type,
|
|
136
|
+
r.subscription_id,
|
|
137
137
|
r.status,
|
|
138
138
|
r.attempt,
|
|
139
|
-
r.
|
|
140
|
-
r.
|
|
139
|
+
r.next_attempt,
|
|
140
|
+
r.last_error
|
|
141
141
|
],
|
|
142
|
-
sort: [[r.
|
|
142
|
+
sort: [[r.created_at, "desc"]]
|
|
143
143
|
})).layout((r) => [layout.section("Delivery", [
|
|
144
|
-
r.
|
|
145
|
-
r.
|
|
146
|
-
r.
|
|
147
|
-
r.
|
|
144
|
+
r.subscription_id,
|
|
145
|
+
r.event_type,
|
|
146
|
+
r.event_id,
|
|
147
|
+
r.last_error
|
|
148
148
|
]), layout.sidebar([
|
|
149
149
|
r.status,
|
|
150
150
|
r.attempt,
|
|
151
|
-
r.
|
|
152
|
-
r.
|
|
151
|
+
r.next_attempt,
|
|
152
|
+
r.created_at
|
|
153
153
|
])]).actions((a) => [a.update("resend", {
|
|
154
154
|
label: "Resend",
|
|
155
155
|
icon: "rotate-ccw",
|
|
@@ -157,39 +157,39 @@ const deliveriesView = view("webhookDeliveries").names({
|
|
|
157
157
|
confirm: "Try this delivery once more, from now?"
|
|
158
158
|
})]);
|
|
159
159
|
/** Every try of every webhook subscription's deliveries, for 30 days (`deliveryLog: true`). */
|
|
160
|
-
const deliveryLogResource = (schema) => resource("
|
|
160
|
+
const deliveryLogResource = (schema) => resource("webhook_delivery_log").table(`${schema}.delivery_log`).fields({
|
|
161
161
|
id: f.bigint().readOnly(),
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
162
|
+
subscription_id: f.relation("webhook_subscriptions").readOnly().filterable(),
|
|
163
|
+
tenant_id: f.text().optional().readOnly(),
|
|
164
|
+
event_id: f.text().readOnly().filterable(),
|
|
165
|
+
event_type: f.text().readOnly().filterable().sortable(),
|
|
166
166
|
status: f.enum(["delivered", "failed"]).readOnly().filterable(),
|
|
167
167
|
attempt: f.integer().readOnly(),
|
|
168
|
-
|
|
168
|
+
status_code: f.integer().optional().readOnly().filterable(),
|
|
169
169
|
response: f.text().optional().readOnly(),
|
|
170
|
-
|
|
170
|
+
duration_ms: f.integer().readOnly(),
|
|
171
171
|
at: f.timestamp().readOnly().filterable().sortable()
|
|
172
|
-
}).primaryKey((r) => r.id).tenant((r) => r.
|
|
172
|
+
}).primaryKey((r) => r.id).tenant((r) => r.tenant_id).access({
|
|
173
173
|
create: () => false,
|
|
174
174
|
update: () => false,
|
|
175
175
|
delete: () => false
|
|
176
176
|
});
|
|
177
|
-
const deliveryLogView = view("
|
|
177
|
+
const deliveryLogView = view("webhook_delivery_log").names({
|
|
178
178
|
singular: "Webhook delivery log entry",
|
|
179
179
|
plural: "Webhook delivery log"
|
|
180
|
-
}).icon("scroll-text").title((r) => r.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
}).icon("scroll-text").title((r) => r.event_type).fields((r) => ({
|
|
181
|
+
event_type: r.event_type.label("Event"),
|
|
182
|
+
status_code: r.status_code.label("Status code"),
|
|
183
|
+
duration_ms: r.duration_ms.label("Duration (ms)"),
|
|
184
184
|
at: r.at.label("When")
|
|
185
185
|
})).list((r) => ({
|
|
186
186
|
columns: [
|
|
187
187
|
r.at,
|
|
188
|
-
r.
|
|
189
|
-
r.
|
|
188
|
+
r.event_type,
|
|
189
|
+
r.subscription_id,
|
|
190
190
|
r.status,
|
|
191
|
-
r.
|
|
192
|
-
r.
|
|
191
|
+
r.status_code,
|
|
192
|
+
r.duration_ms
|
|
193
193
|
],
|
|
194
194
|
sort: [[r.at, "desc"]]
|
|
195
195
|
}));
|