Repository navigation
Expand file tree
/
Copy pathsys-scim-connection-binding.object.ts
More file actions
191 lines (171 loc) · 6.64 KB
/
Copy pathsys-scim-connection-binding.object.ts
File metadata and controls
191 lines (171 loc) · 6.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
import { ObjectSchema, Field } from '@objectstack/spec/data';
/**
* sys_scim_connection_binding — Durable lifecycle state for one SCIM connection
* (`@better-auth/scim` stable `scimConnectionBinding`).
*
* One row per provisioning connection the plugin has seen. The library creates
* the row the first time a connection provisions and drives the decommission
* state machine (`active` → `reconciling` → `complete`) through it when a
* connection is retired. Columns mirror the installed stable schema, bridged
* mechanically camelCase → snake_case by `objectql-adapter.ts` (see
* `better-auth-schema-parity.test.ts`, #3653).
*
* This is NOT a credential store — `connection_key` is a uniqueness key the
* library derives, not a secret. The bearer credentials that authenticate a
* connection live in `sys_scim_connection_credential`, which ObjectStack owns
* outright (stable `@better-auth/scim` stores no credential at all).
*
* @namespace sys
*/
export const SysScimConnectionBinding = ObjectSchema.create({
name: 'sys_scim_connection_binding',
label: 'SCIM Connection Binding',
pluralLabel: 'SCIM Connection Bindings',
icon: 'users',
isSystem: true,
managedBy: 'better-auth',
// ADR-0010 §3.7 — managed by better-auth; tenants may not edit schema.
protection: {
lock: 'full',
reason: 'Identity table managed by better-auth (@better-auth/scim) — see ADR-0134.',
docsUrl: 'https://objectstack.ai/docs/references/shared/protection',
},
description: 'Lifecycle state for a SCIM provisioning connection, including its decommission state machine',
displayNameField: 'connection_id',
nameField: 'connection_id', // [ADR-0079] canonical primary-title pointer
titleFormat: '{connection_id}',
highlightFields: ['connection_id', 'provisioning_domain_id', 'decommission_status'],
listViews: {
all: {
type: 'grid',
name: 'all',
label: 'All',
data: { provider: 'object', object: 'sys_scim_connection_binding' },
columns: ['connection_id', 'provisioning_domain_id', 'decommission_status', 'created_at'],
sort: [{ field: 'connection_id', order: 'asc' }],
pagination: { pageSize: 50 },
},
},
// [ADR-0095 D1, 2026-10-18 note] This object's default row scope: the one policy
// plugin-security's shipped permission sets used to spread for it, moved here
// verbatim; the sets no longer carry a copy (#24164 ruling E′ item 3's follow-up).
// Layer 0 is inert on this table (no organization column), so Layer 1 silence means
// this scope, not no filter. The security plugin's row-policy collection applies it
// when no set the caller holds carries a row policy for the object and operation —
// so to every shipped set's holder, whose reads and explain name this scope. An
// `extend` contribution cannot set or loosen it (refused at registration).
defaultRowScope: {
name: 'sys_scim_connection_binding_none',
operation: 'select',
using: 'id == null',
},
fields: {
id: Field.text({ label: 'ID', required: true, readonly: true, group: 'System' }),
connection_id: Field.text({
label: 'Connection ID',
required: true,
searchable: true,
maxLength: 255,
description: 'Immutable SCIM connection identifier that scopes every provisioned resource',
group: 'Connection',
}),
// Derived uniqueness key, declared `required: true, unique: true,
// returned: false` upstream — same class as `sys_team_member.membership_key`:
// owned end to end by the library, never authored from the ObjectStack side.
connection_key: Field.text({
label: 'Connection Key',
required: true,
readonly: true,
maxLength: 512,
description: 'Derived connection uniqueness key maintained by @better-auth/scim; do not write directly.',
group: 'System',
}),
provisioning_domain_id: Field.text({
label: 'Provisioning Domain',
required: true,
maxLength: 255,
description: 'Application-owned boundary that receives provisioned resources (defaults to the connection id)',
group: 'Connection',
}),
decommission_status: Field.text({
label: 'Decommission Status',
required: true,
defaultValue: 'active',
maxLength: 32,
description: 'Connection lifecycle state: active | reconciling | complete',
group: 'Decommission',
}),
decommissioned_at: Field.datetime({
label: 'Decommissioned At',
required: false,
readonly: true,
group: 'Decommission',
}),
decommission_cursor_user_id: Field.text({
label: 'Decommission Cursor User',
required: false,
readonly: true,
maxLength: 255,
description: 'Resumable reconciliation cursor maintained by the library',
group: 'Decommission',
}),
decommission_reconciled_user_count: Field.number({
label: 'Reconciled Users',
required: false,
defaultValue: 0,
readonly: true,
group: 'Decommission',
}),
decommission_batch_count: Field.number({
label: 'Decommission Batches',
required: false,
defaultValue: 0,
readonly: true,
group: 'Decommission',
}),
decommission_revision: Field.number({
label: 'Decommission Revision',
required: false,
defaultValue: 0,
readonly: true,
description: 'Optimistic-concurrency revision for the decommission state machine',
group: 'Decommission',
}),
decommission_completed_at: Field.datetime({
label: 'Decommission Completed At',
required: false,
readonly: true,
group: 'Decommission',
}),
decommission_lease_id: Field.text({
label: 'Decommission Lease',
required: false,
readonly: true,
maxLength: 255,
description: 'Single-worker reconciliation lease maintained by the library',
group: 'Decommission',
}),
decommission_lease_expires_at: Field.datetime({
label: 'Decommission Lease Expires At',
required: false,
readonly: true,
group: 'Decommission',
}),
created_at: Field.datetime({ label: 'Created At', readonly: true, group: 'System' }),
},
indexes: [
// UNIQUE mirrors @better-auth/scim's own declaration on connectionKey.
{ fields: ['connection_key'], unique: 'global' },
{ fields: ['connection_id'] },
{ fields: ['provisioning_domain_id'] },
],
enable: {
trackHistory: true,
searchable: false,
apiEnabled: true,
// Reads only: all mutations flow through @better-auth/scim's endpoints
// under /api/v1/auth/scim/v2/*; the generic data layer never writes.
apiMethods: ['get', 'list'],
},
});