@protobase/server 0.48.0 → 0.49.1

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.
Files changed (74) hide show
  1. package/dist/admin-options.d.ts +2 -2
  2. package/dist/app-identity.d.ts +2 -2
  3. package/dist/app-name.d.ts +2 -0
  4. package/dist/better-auth/auth-settings.d.ts +8773 -0
  5. package/dist/better-auth/auth-settings.js +43 -0
  6. package/dist/better-auth/authenticate-settings.d.ts +15 -0
  7. package/dist/better-auth/authenticate-settings.js +12 -0
  8. package/dist/better-auth/create-auth.d.ts +51 -11
  9. package/dist/better-auth/create-auth.js +33 -11
  10. package/dist/better-auth/mcp/mcp-auth-plugins.d.ts +2719 -0
  11. package/dist/better-auth/mcp/mcp-auth-plugins.js +68 -0
  12. package/dist/better-auth/mcp/mcp-plugins.d.ts +7 -2
  13. package/dist/better-auth/mcp/mcp-plugins.js +3 -68
  14. package/dist/better-auth/mcp/mcp-token-claims.js +1 -1
  15. package/dist/better-auth/organizations/store.d.ts +1 -0
  16. package/dist/better-auth/saml-plugin.d.ts +993 -0
  17. package/dist/better-auth/saml-plugin.js +36 -0
  18. package/dist/better-auth/saml-sign-in.d.ts +27 -1
  19. package/dist/better-auth/saml-sign-in.js +1 -33
  20. package/dist/better-auth/secret-versions.d.ts +7 -0
  21. package/dist/better-auth/secret-versions.js +21 -0
  22. package/dist/better-auth/signing-keys.js +86 -0
  23. package/dist/better-auth/tokens.js +1 -0
  24. package/dist/better-auth/user-table.js +1 -1
  25. package/dist/better-auth/users.d.ts +1 -1
  26. package/dist/create-admin.d.ts +5 -3
  27. package/dist/create-admin.js +3 -1
  28. package/dist/encryption/keyring.js +1 -1
  29. package/dist/files/options.d.ts +5 -8
  30. package/dist/files/provider-settings.d.ts +16 -0
  31. package/dist/files/provider-settings.js +17 -0
  32. package/dist/files/runtime.js +4 -4
  33. package/dist/forms/runtime.js +3 -3
  34. package/dist/gotrue/sessions-plugin.js +3 -9
  35. package/dist/index.d.ts +16 -15
  36. package/dist/index.js +8 -10
  37. package/dist/internal.d.ts +13 -0
  38. package/dist/internal.js +13 -0
  39. package/dist/jobs/declared-job.d.ts +24 -0
  40. package/dist/jobs/declared-job.js +26 -0
  41. package/dist/jobs/job-types.d.ts +1 -1
  42. package/dist/mcp/mcp-authenticator.js +3 -3
  43. package/dist/notifications/device-store-of.d.ts +1 -1
  44. package/dist/notifications/device-store-of.js +1 -1
  45. package/dist/notifications/device-store.d.ts +1 -1
  46. package/dist/notifications/device-store.js +1 -1
  47. package/dist/notifications/history-store-of.d.ts +1 -1
  48. package/dist/notifications/history-store-of.js +1 -1
  49. package/dist/notifications/history-store.d.ts +1 -1
  50. package/dist/notifications/history-store.js +1 -1
  51. package/dist/notifications/options.d.ts +3 -1
  52. package/dist/notifications/options.js +1 -1
  53. package/dist/notifications/schema.d.ts +2 -2
  54. package/dist/notifications/schema.js +7 -7
  55. package/dist/notifications/send-notification.js +1 -1
  56. package/dist/notifications/sender.d.ts +1 -1
  57. package/dist/notifications/sender.js +2 -2
  58. package/dist/notifications/senders-of.d.ts +1 -1
  59. package/dist/notifications/senders-of.js +1 -1
  60. package/dist/package.js +1 -1
  61. package/dist/webhooks/subscription.d.ts +1 -0
  62. package/dist/webhooks/table/options.d.ts +1 -1
  63. package/dist/webhooks/table/schema.d.ts +2 -2
  64. package/dist/webhooks/table/schema.js +2 -2
  65. package/dist/webhooks/table/webhook-table.js +2 -2
  66. package/dist/webhooks/table/webhooks-module.d.ts +108 -0
  67. package/dist/webhooks/table/webhooks-module.js +11 -0
  68. package/package.json +6 -5
  69. package/dist/notifications/plugin.d.ts +0 -13
  70. package/dist/notifications/plugin.js +0 -16
  71. package/dist/project-config.d.ts +0 -54
  72. package/dist/project-config.js +0 -182
  73. package/dist/webhooks/table/plugin.d.ts +0 -10
  74. package/dist/webhooks/table/plugin.js +0 -18
@@ -0,0 +1,108 @@
1
+ import { WebhooksOptions } from "./options.js";
2
+ //#region src/webhooks/table/webhooks-module.d.ts
3
+ /**
4
+ * What `webhooks` in `protobase.config.ts` adds to the app's resources: the Webhook subscriptions and Webhook deliveries
5
+ * pages, over a `webhooks` schema that `protobase migration` writes, and the delivery log with `deliveryLog`. Who may
6
+ * create subscriptions is the resources' access (`webhook_subscriptions.create`, ...); each delivers as its owner.
7
+ */
8
+ export declare const webhooksModule: (options?: WebhooksOptions) => {
9
+ webhookDeliveryLog?: import("@protobase/schema").ResourceBuilder<{
10
+ readonly id: import("@protobase/schema").Field<string>;
11
+ readonly subscription_id: import("@protobase/schema").Field<string | number>;
12
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
13
+ readonly event_id: import("@protobase/schema").Field<string>;
14
+ readonly event_type: import("@protobase/schema").Field<string>;
15
+ readonly status: import("@protobase/schema").Field<"failed" | "delivered">;
16
+ readonly attempt: import("@protobase/schema").Field<number>;
17
+ readonly status_code: import("@protobase/schema").Field<number | null>;
18
+ readonly response: import("@protobase/schema").Field<string | null>;
19
+ readonly duration_ms: import("@protobase/schema").Field<number>;
20
+ readonly at: import("@protobase/schema").Field<string>;
21
+ }, import("@protobase/schema").Ref<"id", string>> | undefined;
22
+ webhookDeliveryLogView?: import("@protobase/schema").ViewBuilder<import("@protobase/schema").ResourceBuilder<{
23
+ readonly id: import("@protobase/schema").Field<string>;
24
+ readonly subscription_id: import("@protobase/schema").Field<string | number>;
25
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
26
+ readonly event_id: import("@protobase/schema").Field<string>;
27
+ readonly event_type: import("@protobase/schema").Field<string>;
28
+ readonly status: import("@protobase/schema").Field<"failed" | "delivered">;
29
+ readonly attempt: import("@protobase/schema").Field<number>;
30
+ readonly status_code: import("@protobase/schema").Field<number | null>;
31
+ readonly response: import("@protobase/schema").Field<string | null>;
32
+ readonly duration_ms: import("@protobase/schema").Field<number>;
33
+ readonly at: import("@protobase/schema").Field<string>;
34
+ }, import("@protobase/schema").Ref<"id", string>>> | undefined;
35
+ webhookSubscriptions: import("@protobase/schema").ResourceBuilder<{
36
+ readonly id: import("@protobase/schema").Field<string>;
37
+ readonly name: import("@protobase/schema").Field<string>;
38
+ readonly events: import("@protobase/schema").Field<string>;
39
+ readonly url: import("@protobase/schema").Field<string>;
40
+ readonly filter: import("@protobase/schema").Field<string | null>;
41
+ readonly headers: import("@protobase/schema").Field<import("zod").JSONType>;
42
+ readonly payload: import("@protobase/schema").Field<"full" | "thin">;
43
+ readonly enabled: import("@protobase/schema").Field<boolean>;
44
+ readonly secret: import("@protobase/schema").Field<string>;
45
+ readonly previous_secret: null;
46
+ readonly previous_secret_until: null;
47
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
48
+ readonly owner_id: import("@protobase/schema").Field<string | null>;
49
+ readonly disabled_reason: import("@protobase/schema").Field<string | null>;
50
+ readonly last_success_at: import("@protobase/schema").Field<string | null>;
51
+ readonly failing_since: import("@protobase/schema").Field<string | null>;
52
+ readonly created_at: import("@protobase/schema").Field<string>;
53
+ readonly updated_at: import("@protobase/schema").Field<string>;
54
+ readonly rotate_secret: import("@protobase/schema").Field<boolean>;
55
+ readonly send_test: import("@protobase/schema").Field<boolean>;
56
+ readonly resend_failed: import("@protobase/schema").Field<boolean>;
57
+ }, import("@protobase/schema").Ref<"id", string>>;
58
+ webhookSubscriptionsView: import("@protobase/schema").ViewBuilder<import("@protobase/schema").ResourceBuilder<{
59
+ readonly id: import("@protobase/schema").Field<string>;
60
+ readonly name: import("@protobase/schema").Field<string>;
61
+ readonly events: import("@protobase/schema").Field<string>;
62
+ readonly url: import("@protobase/schema").Field<string>;
63
+ readonly filter: import("@protobase/schema").Field<string | null>;
64
+ readonly headers: import("@protobase/schema").Field<import("zod").JSONType>;
65
+ readonly payload: import("@protobase/schema").Field<"full" | "thin">;
66
+ readonly enabled: import("@protobase/schema").Field<boolean>;
67
+ readonly secret: import("@protobase/schema").Field<string>;
68
+ readonly previous_secret: null;
69
+ readonly previous_secret_until: null;
70
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
71
+ readonly owner_id: import("@protobase/schema").Field<string | null>;
72
+ readonly disabled_reason: import("@protobase/schema").Field<string | null>;
73
+ readonly last_success_at: import("@protobase/schema").Field<string | null>;
74
+ readonly failing_since: import("@protobase/schema").Field<string | null>;
75
+ readonly created_at: import("@protobase/schema").Field<string>;
76
+ readonly updated_at: import("@protobase/schema").Field<string>;
77
+ readonly rotate_secret: import("@protobase/schema").Field<boolean>;
78
+ readonly send_test: import("@protobase/schema").Field<boolean>;
79
+ readonly resend_failed: import("@protobase/schema").Field<boolean>;
80
+ }, import("@protobase/schema").Ref<"id", string>>>;
81
+ webhookDeliveries: import("@protobase/schema").ResourceBuilder<{
82
+ readonly id: import("@protobase/schema").Field<string>;
83
+ readonly subscription_id: import("@protobase/schema").Field<string | number>;
84
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
85
+ readonly event_type: import("@protobase/schema").Field<string>;
86
+ readonly event_id: import("@protobase/schema").Field<string>;
87
+ readonly status: import("@protobase/schema").Field<"waiting" | "failed">;
88
+ readonly attempt: import("@protobase/schema").Field<number>;
89
+ readonly next_attempt: import("@protobase/schema").Field<string | null>;
90
+ readonly last_error: import("@protobase/schema").Field<string | null>;
91
+ readonly created_at: import("@protobase/schema").Field<string>;
92
+ readonly resend: import("@protobase/schema").Field<boolean>;
93
+ }, import("@protobase/schema").Ref<"id", string>>;
94
+ webhookDeliveriesView: import("@protobase/schema").ViewBuilder<import("@protobase/schema").ResourceBuilder<{
95
+ readonly id: import("@protobase/schema").Field<string>;
96
+ readonly subscription_id: import("@protobase/schema").Field<string | number>;
97
+ readonly tenant_id: import("@protobase/schema").Field<string | null>;
98
+ readonly event_type: import("@protobase/schema").Field<string>;
99
+ readonly event_id: import("@protobase/schema").Field<string>;
100
+ readonly status: import("@protobase/schema").Field<"waiting" | "failed">;
101
+ readonly attempt: import("@protobase/schema").Field<number>;
102
+ readonly next_attempt: import("@protobase/schema").Field<string | null>;
103
+ readonly last_error: import("@protobase/schema").Field<string | null>;
104
+ readonly created_at: import("@protobase/schema").Field<string>;
105
+ readonly resend: import("@protobase/schema").Field<boolean>;
106
+ }, import("@protobase/schema").Ref<"id", string>>>;
107
+ };
108
+ //#endregion
@@ -0,0 +1,11 @@
1
+ import { webhooksSchema } from "./options.js";
2
+ import { webhookResources } from "@protobase/schema/internal";
3
+ //#region src/webhooks/table/webhooks-module.ts
4
+ /**
5
+ * What `webhooks` in `protobase.config.ts` adds to the app's resources: the Webhook subscriptions and Webhook deliveries
6
+ * pages, over a `webhooks` schema that `protobase migration` writes, and the delivery log with `deliveryLog`. Who may
7
+ * create subscriptions is the resources' access (`webhook_subscriptions.create`, ...); each delivers as its owner.
8
+ */
9
+ const webhooksModule = (options = {}) => webhookResources(webhooksSchema(options), { deliveryLog: Boolean(options.deliveryLog) });
10
+ //#endregion
11
+ export { webhooksModule };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.48.0",
3
+ "version": "0.49.1",
4
4
  "description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -19,7 +19,8 @@
19
19
  "./auth-store": "./dist/auth-store.js",
20
20
  "./config-exports": "./dist/config-exports.js",
21
21
  "./email": "./dist/email.js",
22
- "./vapid": "./dist/vapid.js"
22
+ "./vapid": "./dist/vapid.js",
23
+ "./internal": "./dist/internal.js"
23
24
  },
24
25
  "types": "./dist/index.d.ts",
25
26
  "files": [
@@ -39,9 +40,9 @@
39
40
  "@better-auth/passkey": "^1.7.12",
40
41
  "@better-auth/sso": "^1.7.12",
41
42
  "@modelcontextprotocol/server": "^2.3.1",
42
- "@protobase/layout": "0.48.0",
43
- "@protobase/query": "0.48.0",
44
- "@protobase/schema": "0.48.0",
43
+ "@protobase/layout": "0.49.1",
44
+ "@protobase/query": "0.49.1",
45
+ "@protobase/schema": "0.49.1",
45
46
  "@react-email/render": "^2.1.0",
46
47
  "@scalar/hono-api-reference": "^0.12.10",
47
48
  "@sentry/core": "^11.7.0",
@@ -1,13 +0,0 @@
1
- import { NotificationsOptions } from "./options.js";
2
- import { ProjectConfig } from "../project-config.js";
3
- //#region src/notifications/plugin.d.ts
4
- /**
5
- * Notifications: `extends: [notifications()]` in `protobase.config.ts`. It keeps each user's devices, in the
6
- * `notifications.devices` table that `protobase migration` writes or in the `store` given, and serves the endpoints
7
- * through which a signed-in user registers and removes their own (`devicesPath`). It keeps each user's inbox
8
- * notifications in the `notifications.history` table or the `historyStore` given, and serves the endpoints through which
9
- * a signed-in user lists theirs and marks them read (`historyPath`). It delivers through `senders`, by default the
10
- * built-in ones whose environment is set (see `notificationSenders`).
11
- */
12
- export declare const notifications: (options?: NotificationsOptions) => ProjectConfig;
13
- //#endregion
@@ -1,16 +0,0 @@
1
- import { checkNotificationsOptions } from "./options.js";
2
- //#region src/notifications/plugin.ts
3
- /**
4
- * Notifications: `extends: [notifications()]` in `protobase.config.ts`. It keeps each user's devices, in the
5
- * `notifications.devices` table that `protobase migration` writes or in the `store` given, and serves the endpoints
6
- * through which a signed-in user registers and removes their own (`devicesPath`). It keeps each user's inbox
7
- * notifications in the `notifications.history` table or the `historyStore` given, and serves the endpoints through which
8
- * a signed-in user lists theirs and marks them read (`historyPath`). It delivers through `senders`, by default the
9
- * built-in ones whose environment is set (see `notificationSenders`).
10
- */
11
- const notifications = (options = {}) => ({
12
- name: "protobase-notifications",
13
- notifications: checkNotificationsOptions(options)
14
- });
15
- //#endregion
16
- export { notifications };
@@ -1,54 +0,0 @@
1
- import { MobileConfig } from "./mobile-config.js";
2
- import { AppIdentity } from "./app-identity.js";
3
- import { EventsOptions } from "./changes/events-options.js";
4
- import { Authenticator } from "./types.js";
5
- import { HistoryOptions } from "./history/options.js";
6
- import { WebhooksOptions } from "./webhooks/table/options.js";
7
- import { NotificationsOptions } from "./notifications/options.js";
8
- import { FilesOptions } from "./files/options.js";
9
- import { FunctionSource } from "./functions/define-function.js";
10
- import { AdminOptions } from "./admin-options.js";
11
- import { AdminAuth } from "./better-auth/create-auth.js";
12
- import { Db } from "@protobase/query";
13
- //#region src/project-config.d.ts
14
- /** What `protobase.config.ts` may default-export. Everything is optional. */
15
- export type ProjectConfig = {
16
- /** Names the config in errors, such as two configs defining the same tool; an extension should set it. */
17
- name?: string;
18
- /** Configs this one extends: merged in order before it (see `mergeConfig`). */
19
- extends?: ProjectConfig[];
20
- /** The config module, e.g. `import * as config from './config'`; default: ./config/index.ts and ./config/*\/ui.ts. */
21
- config?: Record<string, unknown>;
22
- db?: Db;
23
- authenticate?: Authenticator;
24
- /** A Better Auth instance; createAdmin mounts its routes under /api/auth. */
25
- auth?: AdminAuth;
26
- /** The API functions, each served at `/api/functions/<name>`; default: one per file in ./functions. */
27
- functions?: Record<string, FunctionSource>;
28
- /** Where file fields keep their bytes: providers by name, retention and the signing secret (see `FilesOptions`). */
29
- files?: FilesOptions;
30
- /** Where the changes that resources' events are raised from are captured (see `EventsOptions`). */
31
- events?: EventsOptions;
32
- /** How long the history of resources with `.history()` is kept (see `HistoryOptions`). */
33
- history?: HistoryOptions;
34
- /** Webhook subscriptions made in the admin app; set by `extends: [webhooks()]` (see `WebhooksOptions`). */
35
- webhooks?: WebhooksOptions;
36
- /** Notifications and each user's devices; set by `extends: [notifications()]` (see `NotificationsOptions`). */
37
- notifications?: NotificationsOptions;
38
- /** The module of the app's jobs, e.g. `import * as jobs from './config/jobs'`: every `defineJob` it exports. */
39
- jobs?: Record<string, unknown>;
40
- /** The app's iOS and Android build (see `MobileConfig`): `protobase mobile` needs it, and the API answers the app's origins. */
41
- mobile?: MobileConfig;
42
- /** The installed app's colours (see `AppIdentity`), which its web manifest carries. */
43
- app?: AppIdentity;
44
- options?: AdminOptions;
45
- };
46
- /** Typed identity, for `export default defineConfig({ extends: [...], config, auth, ... })` in `protobase.config.ts`. */
47
- export declare const defineConfig: (config: ProjectConfig) => ProjectConfig;
48
- /**
49
- * One config from several, each after the ones it `extends`, the last being the app's own. Named things are all kept:
50
- * resources, views and pages of the config modules, functions, jobs, assistant tools, file providers; one name defined by two configs is an error naming
51
- * both. Write hooks run in the same order. Every other value is the last config's that sets it, so the app's own wins.
52
- */
53
- export declare const mergeConfig: (...configs: ProjectConfig[]) => ProjectConfig;
54
- //#endregion
@@ -1,182 +0,0 @@
1
- import { jobDefinitions } from "./jobs/define-job.js";
2
- import { isSubscription } from "./webhooks/subscription.js";
3
- import { isPageDefinition } from "@protobase/layout";
4
- //#region src/project-config.ts
5
- /** Typed identity, for `export default defineConfig({ extends: [...], config, auth, ... })` in `protobase.config.ts`. */
6
- const defineConfig = (config) => config;
7
- const lastSet = (objects) => Object.fromEntries(objects.flatMap((object) => Object.entries(object)).filter(([, value]) => value !== void 0));
8
- const flatten = (config, label) => [...(config.extends ?? []).flatMap((parent, index) => flatten(parent, parent.name ?? `${label} extends[${index}]`)), {
9
- config,
10
- label
11
- }];
12
- const checkUnique = (kind, entries) => {
13
- const seen = /* @__PURE__ */ new Map();
14
- for (const { name, value, label } of entries) {
15
- const first = seen.get(name);
16
- if (first && first.value !== value) throw new Error(`${kind} "${name}" is defined twice, ${first.label === label ? `in ${label}` : `by ${first.label} and by ${label}`}; rename one of them`);
17
- if (!first) seen.set(name, {
18
- value,
19
- label
20
- });
21
- }
22
- };
23
- const mergedModule = (named) => {
24
- const withModule = named.filter(({ config }) => config.config);
25
- if (withModule.length === 0) return void 0;
26
- const exports = withModule.flatMap(({ config, label }) => Object.entries(config.config).map(([key, value]) => ({
27
- key,
28
- value,
29
- label
30
- })));
31
- const values = exports.map((entry) => ({
32
- ...entry,
33
- value: entry.value
34
- }));
35
- checkUnique("The resource", values.filter(({ value }) => typeof value?.recordSchema === "function" && typeof value.toModel === "function").map(({ value, label }) => ({
36
- name: String(value.toModel().name),
37
- value,
38
- label
39
- })));
40
- checkUnique("The page", exports.filter(({ value }) => isPageDefinition(value)).map(({ value, label }) => ({
41
- name: value.name,
42
- value,
43
- label
44
- })));
45
- checkUnique("The subscription", exports.filter(({ value }) => isSubscription(value)).map(({ value, label }) => ({
46
- name: value.name,
47
- value,
48
- label
49
- })));
50
- const menus = values.filter(({ value }) => typeof value?.toUserMenuModel === "function");
51
- if (new Set(menus.map(({ value }) => value)).size > 1) throw new Error(`Only one config may export a user menu; ${menus.map(({ label }) => label).join(" and ")} each do`);
52
- const module = {};
53
- const own = withModule.at(-1).label;
54
- for (const { key, value, label } of exports) {
55
- if (Object.values(module).includes(value)) continue;
56
- module[label === own ? key : `${label}:${key}`] = value;
57
- }
58
- return module;
59
- };
60
- const mergedAssistant = (named) => {
61
- const options = named.map(({ config, label }) => ({
62
- assistant: config.options?.assistant,
63
- label
64
- })).filter(({ assistant }) => assistant !== void 0);
65
- if (options.length === 0) return void 0;
66
- if (options.at(-1).assistant === false) return false;
67
- const after = options.slice(options.findLastIndex(({ assistant }) => assistant === false) + 1);
68
- const tools = after.flatMap(({ assistant, label }) => (assistant.tools ?? []).map((tool) => ({
69
- tool,
70
- label
71
- })));
72
- checkUnique("The assistant tool", tools.map(({ tool, label }) => ({
73
- name: tool.name,
74
- value: tool,
75
- label
76
- })));
77
- return {
78
- ...lastSet(after.map(({ assistant }) => assistant)),
79
- ...tools.length > 0 && { tools: tools.map(({ tool }) => tool) }
80
- };
81
- };
82
- const mergedFunctions = (named) => {
83
- const all = named.flatMap(({ config, label }) => Object.entries(config.functions ?? {}).map(([name, value]) => ({
84
- name,
85
- value,
86
- label
87
- })));
88
- if (all.length === 0) return void 0;
89
- checkUnique("The function", all);
90
- return Object.fromEntries(all.map(({ name, value }) => [name, value]));
91
- };
92
- const mergedFiles = (named) => {
93
- const all = named.flatMap(({ config, label }) => config.files ? [{
94
- files: config.files,
95
- label
96
- }] : []);
97
- if (all.length === 0) return void 0;
98
- const providers = all.flatMap(({ files, label }) => Object.entries(files.providers ?? {}).map(([name, value]) => ({
99
- name,
100
- value,
101
- label
102
- })));
103
- checkUnique("The file provider", providers);
104
- const trustedHosts = [...new Set(all.flatMap(({ files }) => files.trustedHosts ?? []))];
105
- const { retention, secret, sharp } = lastSet(all.map(({ files }) => ({
106
- retention: files.retention,
107
- secret: files.secret,
108
- sharp: files.sharp
109
- })));
110
- return {
111
- ...providers.length > 0 && { providers: Object.fromEntries(providers.map(({ name, value }) => [name, value])) },
112
- ...retention !== void 0 && { retention },
113
- ...secret !== void 0 && { secret },
114
- ...sharp !== void 0 && { sharp },
115
- ...trustedHosts.length > 0 && { trustedHosts }
116
- };
117
- };
118
- const mergedJobs = (named) => {
119
- const all = named.flatMap(({ config, label }) => jobDefinitions(config.jobs ?? {}).map((value) => ({
120
- name: value.name,
121
- value,
122
- label
123
- })));
124
- if (all.length === 0) return void 0;
125
- checkUnique("The job", all);
126
- return Object.fromEntries(all.map(({ name, value }) => [name, value]));
127
- };
128
- const mergedOptions = (named) => {
129
- const all = named.flatMap(({ config }) => config.options ? [config.options] : []);
130
- if (all.length === 0) return void 0;
131
- const writeHooks = all.flatMap((options) => options.writeHooks ?? []);
132
- const assistant = mergedAssistant(named);
133
- return {
134
- ...lastSet(all),
135
- ...writeHooks.length > 0 && { writeHooks },
136
- ...assistant !== void 0 && { assistant }
137
- };
138
- };
139
- /**
140
- * One config from several, each after the ones it `extends`, the last being the app's own. Named things are all kept:
141
- * resources, views and pages of the config modules, functions, jobs, assistant tools, file providers; one name defined by two configs is an error naming
142
- * both. Write hooks run in the same order. Every other value is the last config's that sets it, so the app's own wins.
143
- */
144
- const mergeConfig = (...configs) => {
145
- const named = configs.flatMap((config, index) => flatten(config, config.name ?? `config ${index + 1}`));
146
- const { db, authenticate, auth, events, history, webhooks, notifications, mobile, app } = lastSet(named.map(({ config }) => ({
147
- db: config.db,
148
- authenticate: config.authenticate,
149
- auth: config.auth,
150
- events: config.events,
151
- history: config.history,
152
- webhooks: config.webhooks,
153
- notifications: config.notifications,
154
- mobile: config.mobile,
155
- app: config.app
156
- })));
157
- const module = mergedModule(named);
158
- const functions = mergedFunctions(named);
159
- const files = mergedFiles(named);
160
- const jobs = mergedJobs(named);
161
- const options = mergedOptions(named);
162
- const name = configs.at(-1)?.name;
163
- return {
164
- ...name && { name },
165
- ...module && { config: module },
166
- ...db && { db },
167
- ...authenticate && { authenticate },
168
- ...auth && { auth },
169
- ...functions && { functions },
170
- ...files && { files },
171
- ...events && { events },
172
- ...history && { history },
173
- ...webhooks && { webhooks },
174
- ...notifications && { notifications },
175
- ...jobs && { jobs },
176
- ...mobile && { mobile },
177
- ...app && { app },
178
- ...options && { options }
179
- };
180
- };
181
- //#endregion
182
- export { defineConfig, mergeConfig };
@@ -1,10 +0,0 @@
1
- import { WebhooksOptions } from "./options.js";
2
- import { ProjectConfig } from "../../project-config.js";
3
- //#region src/webhooks/table/plugin.d.ts
4
- /**
5
- * Webhook subscriptions made in the admin app: `extends: [webhooks()]` in `protobase.config.ts`. It adds the Webhook
6
- * subscriptions and Webhook deliveries pages, over a `webhooks` schema that `protobase migration` writes. Who may
7
- * create subscriptions is the resources' access (`webhook_subscriptions.create`, ...); each delivers as its owner.
8
- */
9
- export declare const webhooks: (options?: WebhooksOptions) => ProjectConfig;
10
- //#endregion
@@ -1,18 +0,0 @@
1
- import { webhooksSchema } from "./options.js";
2
- import { webhookResources } from "@protobase/schema/internal";
3
- //#region src/webhooks/table/plugin.ts
4
- /**
5
- * Webhook subscriptions made in the admin app: `extends: [webhooks()]` in `protobase.config.ts`. It adds the Webhook
6
- * subscriptions and Webhook deliveries pages, over a `webhooks` schema that `protobase migration` writes. Who may
7
- * create subscriptions is the resources' access (`webhook_subscriptions.create`, ...); each delivers as its owner.
8
- */
9
- const webhooks = (options = {}) => {
10
- const schema = webhooksSchema(options);
11
- return {
12
- name: "protobase-webhooks",
13
- config: webhookResources(schema, { deliveryLog: Boolean(options.deliveryLog) }),
14
- webhooks: options
15
- };
16
- };
17
- //#endregion
18
- export { webhooks };