slotlock 0.6.3 → 0.7.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +467 -0
  2. package/CONTRIBUTING.md +12 -5
  3. package/README.md +50 -1551
  4. package/SECURITY.md +5 -2
  5. package/SPEC.md +1 -1
  6. package/agent-server.d.ts +160 -8
  7. package/agent-server.js +559 -44
  8. package/agent-store-backend.d.ts +34 -1
  9. package/agent-store-backend.js +1399 -38
  10. package/api-keys.d.ts +69 -3
  11. package/api-keys.js +217 -28
  12. package/application-api.d.ts +56 -3
  13. package/application-api.js +826 -15
  14. package/approvals.d.ts +88 -0
  15. package/approvals.js +293 -0
  16. package/assistant.d.ts +40 -0
  17. package/assistant.js +115 -0
  18. package/billing.d.ts +114 -0
  19. package/billing.js +258 -0
  20. package/config.d.ts +25 -4
  21. package/config.js +72 -3
  22. package/dashboard-icon.d.ts +1 -0
  23. package/dashboard-icon.js +5 -0
  24. package/dashboard.d.ts +203 -7
  25. package/dashboard.js +1545 -64
  26. package/ddl.d.ts +51 -12
  27. package/ddl.js +2566 -54
  28. package/event-feed.d.ts +30 -4
  29. package/event-feed.js +171 -19
  30. package/index.d.ts +15 -4
  31. package/index.js +8 -2
  32. package/maintenance.d.ts +10 -0
  33. package/maintenance.js +16 -2
  34. package/metrics.d.ts +41 -0
  35. package/metrics.js +22 -0
  36. package/openapi.json +14675 -5957
  37. package/otel.d.ts +86 -0
  38. package/otel.js +273 -0
  39. package/overage.d.ts +33 -0
  40. package/overage.js +115 -0
  41. package/package.json +1 -1
  42. package/partner-billing.d.ts +81 -0
  43. package/partner-billing.js +333 -0
  44. package/partner-names.d.ts +8 -0
  45. package/partner-names.js +10 -0
  46. package/partners.d.ts +147 -0
  47. package/partners.js +375 -0
  48. package/plans.d.ts +92 -0
  49. package/plans.js +115 -0
  50. package/quotas.d.ts +108 -0
  51. package/quotas.js +258 -0
  52. package/rate-limit.d.ts +21 -1
  53. package/rate-limit.js +82 -15
  54. package/resource-profile.d.ts +135 -0
  55. package/resource-profile.js +263 -0
  56. package/rest-api.d.ts +2 -0
  57. package/rest-api.js +68 -3
  58. package/sandbox.d.ts +70 -0
  59. package/sandbox.js +295 -0
  60. package/self-host.d.ts +33 -5
  61. package/self-host.js +950 -22
  62. package/slotlock.manifest.json +1 -1
  63. package/store.d.ts +373 -4
  64. package/store.js +1212 -118
  65. package/teams.d.ts +25 -0
  66. package/teams.js +63 -0
  67. package/timezone.js +13 -1
  68. package/types.d.ts +95 -1
  69. package/usage.d.ts +106 -0
  70. package/usage.js +238 -0
package/ddl.d.ts CHANGED
@@ -22,19 +22,19 @@ export declare const SLOTLOCK_API_KEY_RETAINED_LIMIT = 1000;
22
22
  * The tables behind API keys. No role but their owner holds a right on them; they are reached only
23
23
  * through SLOTLOCK_API_KEY_FUNCTIONS.
24
24
  */
25
- export declare const SLOTLOCK_API_KEY_TABLES: readonly ["api_keys", "api_key_retired_digests"];
25
+ export declare const SLOTLOCK_API_KEY_TABLES: readonly ["api_keys", "api_key_retired_digests", "api_key_resource_scopes", "api_key_limits"];
26
26
  /**
27
27
  * The SECURITY DEFINER functions through which the serving role reaches API keys, by signature.
28
28
  * They run as the deployment role, which owns the tables.
29
29
  */
30
- export declare const SLOTLOCK_API_KEY_FUNCTIONS: readonly ["slotlock.create_api_key(text, text, text, bytea, text[], timestamptz, text)", "slotlock.list_api_keys(text)", "slotlock.rotate_api_key(text, uuid, text, bytea)", "slotlock.revoke_api_key(text, uuid)", "slotlock.authenticate_api_key(bytea)", "slotlock.erase_api_keys(text)"];
30
+ export declare const SLOTLOCK_API_KEY_FUNCTIONS: readonly ["slotlock.create_api_key(text, text, text, bytea, text[], timestamptz, text)", "slotlock.list_api_keys(text)", "slotlock.rotate_api_key(text, uuid, text, bytea)", "slotlock.revoke_api_key(text, uuid)", "slotlock.authenticate_api_key(bytea)", "slotlock.erase_api_keys(text)", "slotlock.set_api_key_resource_scope(text, uuid, text[], text[])", "slotlock.authenticate_scoped_api_key(bytea)", "slotlock.list_api_key_resource_scopes(text)", "slotlock.set_api_key_limits(text, uuid, integer, integer, integer, boolean)", "slotlock.list_api_key_limits(text)", "slotlock.authenticate_limited_api_key(bytea)"];
31
31
  /**
32
32
  * The table behind the dashboard's shared records (dashboard.ts). No role but its owner holds a
33
33
  * right on it; it is reached only through SLOTLOCK_DASHBOARD_FUNCTIONS.
34
34
  */
35
- export declare const SLOTLOCK_DASHBOARD_TABLES: readonly ["dashboard_tokens"];
35
+ export declare const SLOTLOCK_DASHBOARD_TABLES: readonly ["dashboard_tokens", "dashboard_organizations"];
36
36
  /** The SECURITY DEFINER functions through which the serving role reaches the dashboard's records. */
37
- export declare const SLOTLOCK_DASHBOARD_FUNCTIONS: readonly ["slotlock.use_dashboard_token(text, bytea, timestamptz, bytea)", "slotlock.dashboard_session_ended(bytea, timestamptz)"];
37
+ export declare const SLOTLOCK_DASHBOARD_FUNCTIONS: readonly ["slotlock.use_dashboard_token(text, bytea, timestamptz, bytea)", "slotlock.dashboard_session_ended(bytea, timestamptz)", "slotlock.enabled_organizations(text)", "slotlock.enable_organization(text, text, text)", "slotlock.disable_organization(text, text)"];
38
38
  /** Live form records one person may leave in the dashboard's records (12 hours of forms). */
39
39
  export declare const SLOTLOCK_DASHBOARD_FORM_LIMIT = 1000;
40
40
  /** The table that records which release migrated the schema (SLOTLOCK_SCHEMA_VERSION). */
@@ -42,21 +42,49 @@ export declare const SLOTLOCK_SCHEMA_TABLES: readonly ["schema_version"];
42
42
  /** The SECURITY DEFINER function through which a server reads the version it is serving. */
43
43
  export declare const SLOTLOCK_SCHEMA_FUNCTIONS: readonly ["slotlock.installed_schema_version()"];
44
44
  /** The table of suspended tenants: they may read, and write nothing (store.ts withTenant). */
45
- export declare const SLOTLOCK_TENANT_ADMIN_TABLES: readonly ["tenant_suspensions", "webhook_tenants", "rate_buckets", "assistant_tenants", "maintenance_tenants"];
45
+ export declare const SLOTLOCK_TENANT_ADMIN_TABLES: readonly ["tenant_suspensions", "tenant_plans", "plan_defaults", "usage_daily", "usage_flushes", "usage_cursors", "usage_meter_start", "usage_notices", "overage_reports", "webhook_tenants", "rate_buckets", "assistant_tenants", "maintenance_tenants"];
46
46
  /**
47
47
  * The SECURITY DEFINER functions through which a server checks a tenant's suspension and erases a
48
48
  * tenant, by signature.
49
49
  */
50
- export declare const SLOTLOCK_TENANT_ADMIN_FUNCTIONS: readonly ["slotlock.tenant_suspended(text)", "slotlock.erase_tenant(text)", "slotlock.register_webhook_tenant(text)", "slotlock.webhook_tenants(text)", "slotlock.unregister_webhook_tenant(text)", "slotlock.take_rate_token(text, double precision, double precision)", "slotlock.register_assistant_tenant(text, timestamptz)", "slotlock.sweep_assistant_conversations(integer)", "slotlock.list_maintenance_tenant()", "slotlock.maintenance_tenants(text)"];
50
+ export declare const SLOTLOCK_TENANT_ADMIN_FUNCTIONS: readonly ["slotlock.tenant_suspended(text)", "slotlock.erase_tenant(text)", "slotlock.register_webhook_tenant(text)", "slotlock.webhook_tenants(text)", "slotlock.unregister_webhook_tenant(text)", "slotlock.take_rate_token(text, double precision, double precision)", "slotlock.register_assistant_tenant(text, timestamptz)", "slotlock.sweep_assistant_conversations(integer)", "slotlock.list_maintenance_tenant()", "slotlock.maintenance_tenants(text)", "slotlock.tenant_plan(text)", "slotlock.set_tenant_plan(text, text, text, integer, integer, integer, text, text, timestamptz)", "slotlock.plan_default()", "slotlock.enrol_tenant_plan(text)", "slotlock.record_usage(uuid, jsonb)", "slotlock.roll_up_usage(text, integer)", "slotlock.tenant_usage(text, date, date)", "slotlock.tenant_quota_usage(text, date)", "slotlock.note_usage_threshold(text, date, text, integer, bigint, bigint)", "slotlock.tenant_plan_quotas(text)", "slotlock.reset_test_tenant(text)"];
51
+ /** The functions usage metering runs (SLOTLOCK_USAGE=on): serve checks it may, before it starts. */
52
+ export declare const SLOTLOCK_USAGE_FUNCTIONS: readonly ["slotlock.record_usage(uuid, jsonb)", "slotlock.roll_up_usage(text, integer)", "slotlock.tenant_usage(text, date, date)"];
53
+ /** The functions quotas run (SLOTLOCK_QUOTAS=on, quotas.ts): serve checks it may, before it starts. */
54
+ export declare const SLOTLOCK_QUOTA_FUNCTIONS: readonly ["slotlock.tenant_plan(text)", "slotlock.tenant_quota_usage(text, date)", "slotlock.note_usage_threshold(text, date, text, integer, bigint, bigint)"];
55
+ /** What a plan's monthly quotas count (quotas.ts): operations run and bookings made. */
56
+ export declare const SLOTLOCK_QUOTA_METRICS: readonly ["operations", "bookings"];
57
+ /** The shares of a quota, in percent, at which a tenant is told once a month (usage.threshold_reached). */
58
+ export declare const SLOTLOCK_QUOTA_NOTICE_PERCENTS: readonly [80, 100];
59
+ /** The most bookings past the roll-up cursor one quota read counts: more than any plan allows. */
60
+ export declare const SLOTLOCK_QUOTA_UNROLLED_LIMIT = 100000;
51
61
  /**
52
- * Functions only the deployment role runs: suspending and lifting a suspension. No other role is
53
- * granted them, so a serving role cannot lift a suspension.
62
+ * What usage.ts meters, per tenant and day: operations run, bookings and holds committed, webhook
63
+ * deliveries accepted, messages to the dashboard assistant, and resources held (a count each day, not
64
+ * a sum).
54
65
  */
55
- export declare const SLOTLOCK_OPERATOR_FUNCTIONS: readonly ["slotlock.suspend_tenant(text, text)", "slotlock.unsuspend_tenant(text)"];
66
+ export declare const SLOTLOCK_USAGE_METRICS: readonly ["operations", "bookings", "holds", "webhook_deliveries", "assistant_messages", "resources"];
67
+ /** The metrics a server counts and records (slotlock.record_usage); the rest the database counts. */
68
+ export declare const SLOTLOCK_RECORDED_USAGE_METRICS: readonly ["operations", "webhook_deliveries", "assistant_messages"];
69
+ /** Days a tenant's daily usage is kept: a yearly plan, and a month for disputes after it. */
70
+ export declare const SLOTLOCK_USAGE_RETENTION_DAYS = 400;
71
+ /**
72
+ * Functions only the deployment role runs: suspending and lifting a suspension, and setting the
73
+ * hosted plan every tenant without one of its own is on. No other role is granted them, so a serving
74
+ * role cannot lift a suspension or change the default plan.
75
+ */
76
+ export declare const SLOTLOCK_OPERATOR_FUNCTIONS: readonly ["slotlock.suspend_tenant(text, text)", "slotlock.unsuspend_tenant(text)", "slotlock.set_plan_default(text, integer, integer, integer, timestamptz)"];
56
77
  /** Every SECURITY DEFINER function the serving role may execute, by signature. */
57
- export declare const SLOTLOCK_DEFINER_FUNCTIONS: readonly ("slotlock.authenticate_api_key(bytea)" | "slotlock.create_api_key(text, text, text, bytea, text[], timestamptz, text)" | "slotlock.dashboard_session_ended(bytea, timestamptz)" | "slotlock.erase_api_keys(text)" | "slotlock.erase_tenant(text)" | "slotlock.installed_schema_version()" | "slotlock.list_api_keys(text)" | "slotlock.list_maintenance_tenant()" | "slotlock.maintenance_tenants(text)" | "slotlock.register_assistant_tenant(text, timestamptz)" | "slotlock.register_webhook_tenant(text)" | "slotlock.revoke_api_key(text, uuid)" | "slotlock.rotate_api_key(text, uuid, text, bytea)" | "slotlock.sweep_assistant_conversations(integer)" | "slotlock.take_rate_token(text, double precision, double precision)" | "slotlock.tenant_suspended(text)" | "slotlock.unregister_webhook_tenant(text)" | "slotlock.use_dashboard_token(text, bytea, timestamptz, bytea)" | "slotlock.webhook_tenants(text)")[];
78
+ /**
79
+ * Partner accounts (RFC 0003 part 4): what the serving role may call for a partner key and the
80
+ * partner API. A partner, its keys and its contract are made by the schema owner (`slotlock partner`).
81
+ */
82
+ export declare const SLOTLOCK_PARTNER_FUNCTIONS: readonly ["slotlock.partner_tenant_blocked(text)", "slotlock.authenticate_partner_key(bytea)", "slotlock.partner_contract(text)", "slotlock.put_partner_account(text, text, text)", "slotlock.list_partner_accounts(text)", "slotlock.get_partner_account(text, text)", "slotlock.set_partner_account_suspended(text, text, boolean, text)", "slotlock.partner_usage(text, date, date, text)", "slotlock.partner_account_tenant(text, text)", "slotlock.record_partner_reconciliation(text, date, integer, integer, numeric)"];
83
+ /** The partner tables: owner-only, reached through SLOTLOCK_PARTNER_FUNCTIONS. */
84
+ export declare const SLOTLOCK_PARTNER_TABLES: readonly ["partners", "partner_keys", "partner_accounts", "partner_invoices", "partner_month_closes", "partner_erased_usage", "partner_reconciliations"];
85
+ export declare const SLOTLOCK_DEFINER_FUNCTIONS: readonly ("slotlock.authenticate_api_key(bytea)" | "slotlock.authenticate_limited_api_key(bytea)" | "slotlock.authenticate_partner_key(bytea)" | "slotlock.authenticate_scoped_api_key(bytea)" | "slotlock.create_api_key(text, text, text, bytea, text[], timestamptz, text)" | "slotlock.dashboard_session_ended(bytea, timestamptz)" | "slotlock.disable_organization(text, text)" | "slotlock.enable_organization(text, text, text)" | "slotlock.enabled_organizations(text)" | "slotlock.enrol_tenant_plan(text)" | "slotlock.erase_api_keys(text)" | "slotlock.erase_tenant(text)" | "slotlock.get_partner_account(text, text)" | "slotlock.installed_schema_version()" | "slotlock.list_api_key_limits(text)" | "slotlock.list_api_key_resource_scopes(text)" | "slotlock.list_api_keys(text)" | "slotlock.list_maintenance_tenant()" | "slotlock.list_partner_accounts(text)" | "slotlock.maintenance_tenants(text)" | "slotlock.note_usage_threshold(text, date, text, integer, bigint, bigint)" | "slotlock.partner_account_tenant(text, text)" | "slotlock.partner_contract(text)" | "slotlock.partner_tenant_blocked(text)" | "slotlock.partner_usage(text, date, date, text)" | "slotlock.plan_default()" | "slotlock.put_partner_account(text, text, text)" | "slotlock.record_partner_reconciliation(text, date, integer, integer, numeric)" | "slotlock.record_usage(uuid, jsonb)" | "slotlock.register_assistant_tenant(text, timestamptz)" | "slotlock.register_webhook_tenant(text)" | "slotlock.reset_test_tenant(text)" | "slotlock.revoke_api_key(text, uuid)" | "slotlock.roll_up_usage(text, integer)" | "slotlock.rotate_api_key(text, uuid, text, bytea)" | "slotlock.set_api_key_limits(text, uuid, integer, integer, integer, boolean)" | "slotlock.set_api_key_resource_scope(text, uuid, text[], text[])" | "slotlock.set_partner_account_suspended(text, text, boolean, text)" | "slotlock.set_tenant_plan(text, text, text, integer, integer, integer, text, text, timestamptz)" | "slotlock.sweep_assistant_conversations(integer)" | "slotlock.take_rate_token(text, double precision, double precision)" | "slotlock.tenant_plan(text)" | "slotlock.tenant_plan_quotas(text)" | "slotlock.tenant_quota_usage(text, date)" | "slotlock.tenant_suspended(text)" | "slotlock.tenant_usage(text, date, date)" | "slotlock.unregister_webhook_tenant(text)" | "slotlock.use_dashboard_token(text, bytea, timestamptz, bytea)" | "slotlock.webhook_tenants(text)")[];
58
86
  /** Tables no role but their owner reads or writes, reached only through SLOTLOCK_DEFINER_FUNCTIONS. */
59
- export declare const SLOTLOCK_DEFINER_TABLES: readonly ("api_key_retired_digests" | "api_keys" | "assistant_tenants" | "dashboard_tokens" | "maintenance_tenants" | "rate_buckets" | "schema_version" | "tenant_suspensions" | "webhook_tenants")[];
87
+ export declare const SLOTLOCK_DEFINER_TABLES: readonly ("api_key_limits" | "api_key_resource_scopes" | "api_key_retired_digests" | "api_keys" | "assistant_tenants" | "dashboard_organizations" | "dashboard_tokens" | "maintenance_tenants" | "overage_reports" | "partner_accounts" | "partner_erased_usage" | "partner_invoices" | "partner_keys" | "partner_month_closes" | "partner_reconciliations" | "partners" | "plan_defaults" | "rate_buckets" | "schema_version" | "tenant_plans" | "tenant_suspensions" | "usage_cursors" | "usage_daily" | "usage_flushes" | "usage_meter_start" | "usage_notices" | "webhook_tenants")[];
60
88
  /**
61
89
  * The advisory lock every server transaction for a tenant holds shared (store.ts withTenant), and
62
90
  * suspension and erasure take exclusively, keyed by this text's hashtextextended(…, 0).
@@ -88,7 +116,7 @@ export declare const SLOTLOCK_TENANT_CONTEXT_SETTING = "slotlock.tenant_ref";
88
116
  * `slotlock.rls_policy_contracts` and `slotlock.deployment_lifted_row_security` are
89
117
  * deployment-only and deliberately absent.
90
118
  */
91
- export declare const SLOTLOCK_TENANT_TABLES: readonly ["resources", "reservations", "reservation_tombstones", "reservation_conflict_archive", "calendar_events", "calendar_event_attendees", "calendar_event_reminders", "calendar_event_exceptions", "calendar_event_occurrences", "calendar_event_tombstones", "calendar_event_commands", "calendar_coverage", "hold_commands", "outbox", "outbox_pruned", "webhook_endpoints", "waitlist_entries", "booking_rule_defaults", "assistant_settings", "assistant_conversations"];
119
+ export declare const SLOTLOCK_TENANT_TABLES: readonly ["resources", "reservations", "reservation_tombstones", "reservation_conflict_archive", "calendar_events", "calendar_event_attendees", "calendar_event_reminders", "calendar_event_exceptions", "calendar_event_occurrences", "calendar_event_tombstones", "calendar_event_commands", "calendar_coverage", "hold_commands", "outbox", "outbox_pruned", "webhook_endpoints", "waitlist_entries", "booking_rule_defaults", "assistant_settings", "assistant_conversations", "locations", "resource_groups", "resource_group_members", "pool_settings", "composite_claims", "approval_policies", "approvals"];
92
120
  /**
93
121
  * Build the grants for the application role: USAGE on the schema, DML on the store's tables and
94
122
  * EXECUTE on the API key and dashboard functions, nothing else. The role must not be able to leave
@@ -101,5 +129,16 @@ export declare function createSlotlockApplicationRoleGrantsDdl(role: string): st
101
129
  * `slotlock.tenant_ref`; adapters may supply an established transaction-local setting name.
102
130
  * Every policy fails closed when the setting is absent or empty, and FORCE binds the table owner.
103
131
  */
132
+ /**
133
+ * The transaction-local setting withTenant sets for a key limited to part of its tenant (RFC 0003
134
+ * G6): the ids of the resources it reaches, as a uuid[] literal; empty for every other caller.
135
+ */
136
+ export declare const SLOTLOCK_RESOURCE_SCOPE_SETTING = "slotlock.resource_scope";
137
+ /**
138
+ * The tables a key limited to part of its tenant is held to, and how each row names its resource:
139
+ * the resource itself, or the event it belongs to. Tombstones and archives name none and stay as the
140
+ * tenant policy leaves them.
141
+ */
142
+ export declare const SLOTLOCK_RESOURCE_SCOPED_TABLES: Readonly<Record<string, string>>;
104
143
  export declare function createSlotlockTenantRlsDdl(tenantContextSetting?: string): string;
105
144
  export declare const SLOTLOCK_TENANT_RLS_DDL: string;