@substrat-run/contracts 0.1.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/LICENSE +202 -0
- package/README.md +54 -0
- package/dist/attachments.d.ts +4 -0
- package/dist/attachments.d.ts.map +1 -0
- package/dist/attachments.js +8 -0
- package/dist/attachments.js.map +1 -0
- package/dist/events.d.ts +186 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +52 -0
- package/dist/events.js.map +1 -0
- package/dist/ids.d.ts +19 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +24 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +368 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +81 -0
- package/dist/manifest.js.map +1 -0
- package/dist/money.d.ts +24 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +64 -0
- package/dist/money.js.map +1 -0
- package/dist/permission.d.ts +257 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +78 -0
- package/dist/permission.js.map +1 -0
- package/dist/tenancy.d.ts +68 -0
- package/dist/tenancy.d.ts.map +1 -0
- package/dist/tenancy.js +35 -0
- package/dist/tenancy.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const node: z.ZodObject<{
|
|
3
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
4
|
+
scopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
7
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
8
|
+
}, {
|
|
9
|
+
tenantId: string;
|
|
10
|
+
scopeId: string | null;
|
|
11
|
+
}>;
|
|
12
|
+
export type Node = z.infer<typeof node>;
|
|
13
|
+
export declare const roleKey: z.ZodString;
|
|
14
|
+
export declare const roleDefinition: z.ZodObject<{
|
|
15
|
+
key: z.ZodString;
|
|
16
|
+
permissions: z.ZodArray<z.ZodBranded<z.ZodString, "PermissionKey">, "many">;
|
|
17
|
+
source: z.ZodUnion<[z.ZodBranded<z.ZodString, "ModuleId">, z.ZodLiteral<"vertical">]>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
key: string;
|
|
20
|
+
permissions: (string & z.BRAND<"PermissionKey">)[];
|
|
21
|
+
source: (string & z.BRAND<"ModuleId">) | "vertical";
|
|
22
|
+
}, {
|
|
23
|
+
key: string;
|
|
24
|
+
permissions: string[];
|
|
25
|
+
source: string;
|
|
26
|
+
}>;
|
|
27
|
+
export type RoleDefinition = z.infer<typeof roleDefinition>;
|
|
28
|
+
export declare const roleAssignment: z.ZodObject<{
|
|
29
|
+
principalId: z.ZodBranded<z.ZodString, "PrincipalId">;
|
|
30
|
+
roleKey: z.ZodString;
|
|
31
|
+
node: z.ZodObject<{
|
|
32
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
33
|
+
scopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
36
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
37
|
+
}, {
|
|
38
|
+
tenantId: string;
|
|
39
|
+
scopeId: string | null;
|
|
40
|
+
}>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
principalId: string & z.BRAND<"PrincipalId">;
|
|
43
|
+
roleKey: string;
|
|
44
|
+
node: {
|
|
45
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
46
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
47
|
+
};
|
|
48
|
+
}, {
|
|
49
|
+
principalId: string;
|
|
50
|
+
roleKey: string;
|
|
51
|
+
node: {
|
|
52
|
+
tenantId: string;
|
|
53
|
+
scopeId: string | null;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
export type RoleAssignment = z.infer<typeof roleAssignment>;
|
|
57
|
+
export declare const capabilityGrant: z.ZodObject<{
|
|
58
|
+
principalId: z.ZodBranded<z.ZodString, "PrincipalId">;
|
|
59
|
+
permission: z.ZodBranded<z.ZodString, "PermissionKey">;
|
|
60
|
+
node: z.ZodObject<{
|
|
61
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
62
|
+
scopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
|
64
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
65
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
66
|
+
}, {
|
|
67
|
+
tenantId: string;
|
|
68
|
+
scopeId: string | null;
|
|
69
|
+
}>;
|
|
70
|
+
entity: z.ZodOptional<z.ZodObject<{
|
|
71
|
+
entityType: z.ZodString;
|
|
72
|
+
entityId: z.ZodString;
|
|
73
|
+
}, "strip", z.ZodTypeAny, {
|
|
74
|
+
entityType: string;
|
|
75
|
+
entityId: string;
|
|
76
|
+
}, {
|
|
77
|
+
entityType: string;
|
|
78
|
+
entityId: string;
|
|
79
|
+
}>>;
|
|
80
|
+
expiresAt: z.ZodOptional<z.ZodBranded<z.ZodString, "Instant">>;
|
|
81
|
+
grantedBy: z.ZodBranded<z.ZodString, "PrincipalId">;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
principalId: string & z.BRAND<"PrincipalId">;
|
|
84
|
+
node: {
|
|
85
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
86
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
87
|
+
};
|
|
88
|
+
permission: string & z.BRAND<"PermissionKey">;
|
|
89
|
+
grantedBy: string & z.BRAND<"PrincipalId">;
|
|
90
|
+
entity?: {
|
|
91
|
+
entityType: string;
|
|
92
|
+
entityId: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
expiresAt?: (string & z.BRAND<"Instant">) | undefined;
|
|
95
|
+
}, {
|
|
96
|
+
principalId: string;
|
|
97
|
+
node: {
|
|
98
|
+
tenantId: string;
|
|
99
|
+
scopeId: string | null;
|
|
100
|
+
};
|
|
101
|
+
permission: string;
|
|
102
|
+
grantedBy: string;
|
|
103
|
+
entity?: {
|
|
104
|
+
entityType: string;
|
|
105
|
+
entityId: string;
|
|
106
|
+
} | undefined;
|
|
107
|
+
expiresAt?: string | undefined;
|
|
108
|
+
}>;
|
|
109
|
+
export type CapabilityGrant = z.infer<typeof capabilityGrant>;
|
|
110
|
+
export declare const objectRef: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
111
|
+
export type ObjectRef = z.infer<typeof objectRef>;
|
|
112
|
+
export declare const relationName: z.ZodString;
|
|
113
|
+
export declare const relationTuple: z.ZodObject<{
|
|
114
|
+
subject: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
115
|
+
relation: z.ZodString;
|
|
116
|
+
object: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
117
|
+
}, "strip", z.ZodTypeAny, {
|
|
118
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
119
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
120
|
+
relation: string;
|
|
121
|
+
}, {
|
|
122
|
+
object: string;
|
|
123
|
+
subject: string;
|
|
124
|
+
relation: string;
|
|
125
|
+
}>;
|
|
126
|
+
export type RelationTuple = z.infer<typeof relationTuple>;
|
|
127
|
+
export declare const decision: z.ZodDiscriminatedUnion<"allowed", [z.ZodObject<{
|
|
128
|
+
allowed: z.ZodLiteral<true>;
|
|
129
|
+
proof: z.ZodArray<z.ZodObject<{
|
|
130
|
+
subject: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
131
|
+
relation: z.ZodString;
|
|
132
|
+
object: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
133
|
+
}, "strip", z.ZodTypeAny, {
|
|
134
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
135
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
136
|
+
relation: string;
|
|
137
|
+
}, {
|
|
138
|
+
object: string;
|
|
139
|
+
subject: string;
|
|
140
|
+
relation: string;
|
|
141
|
+
}>, "many">;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
allowed: true;
|
|
144
|
+
proof: {
|
|
145
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
146
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
147
|
+
relation: string;
|
|
148
|
+
}[];
|
|
149
|
+
}, {
|
|
150
|
+
allowed: true;
|
|
151
|
+
proof: {
|
|
152
|
+
object: string;
|
|
153
|
+
subject: string;
|
|
154
|
+
relation: string;
|
|
155
|
+
}[];
|
|
156
|
+
}>, z.ZodObject<{
|
|
157
|
+
allowed: z.ZodLiteral<false>;
|
|
158
|
+
checked: z.ZodBranded<z.ZodString, "PermissionKey">;
|
|
159
|
+
node: z.ZodObject<{
|
|
160
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
161
|
+
scopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
162
|
+
}, "strip", z.ZodTypeAny, {
|
|
163
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
164
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
165
|
+
}, {
|
|
166
|
+
tenantId: string;
|
|
167
|
+
scopeId: string | null;
|
|
168
|
+
}>;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
node: {
|
|
171
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
172
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
173
|
+
};
|
|
174
|
+
allowed: false;
|
|
175
|
+
checked: string & z.BRAND<"PermissionKey">;
|
|
176
|
+
}, {
|
|
177
|
+
node: {
|
|
178
|
+
tenantId: string;
|
|
179
|
+
scopeId: string | null;
|
|
180
|
+
};
|
|
181
|
+
allowed: false;
|
|
182
|
+
checked: string;
|
|
183
|
+
}>]>;
|
|
184
|
+
export type Decision = z.infer<typeof decision>;
|
|
185
|
+
export declare const effectivePermissions: z.ZodObject<{
|
|
186
|
+
principalId: z.ZodBranded<z.ZodString, "PrincipalId">;
|
|
187
|
+
node: z.ZodObject<{
|
|
188
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
189
|
+
scopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
190
|
+
}, "strip", z.ZodTypeAny, {
|
|
191
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
192
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
193
|
+
}, {
|
|
194
|
+
tenantId: string;
|
|
195
|
+
scopeId: string | null;
|
|
196
|
+
}>;
|
|
197
|
+
permissions: z.ZodArray<z.ZodObject<{
|
|
198
|
+
permission: z.ZodBranded<z.ZodString, "PermissionKey">;
|
|
199
|
+
proof: z.ZodArray<z.ZodObject<{
|
|
200
|
+
subject: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
201
|
+
relation: z.ZodString;
|
|
202
|
+
object: z.ZodBranded<z.ZodString, "ObjectRef">;
|
|
203
|
+
}, "strip", z.ZodTypeAny, {
|
|
204
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
205
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
206
|
+
relation: string;
|
|
207
|
+
}, {
|
|
208
|
+
object: string;
|
|
209
|
+
subject: string;
|
|
210
|
+
relation: string;
|
|
211
|
+
}>, "many">;
|
|
212
|
+
}, "strip", z.ZodTypeAny, {
|
|
213
|
+
permission: string & z.BRAND<"PermissionKey">;
|
|
214
|
+
proof: {
|
|
215
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
216
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
217
|
+
relation: string;
|
|
218
|
+
}[];
|
|
219
|
+
}, {
|
|
220
|
+
permission: string;
|
|
221
|
+
proof: {
|
|
222
|
+
object: string;
|
|
223
|
+
subject: string;
|
|
224
|
+
relation: string;
|
|
225
|
+
}[];
|
|
226
|
+
}>, "many">;
|
|
227
|
+
}, "strip", z.ZodTypeAny, {
|
|
228
|
+
permissions: {
|
|
229
|
+
permission: string & z.BRAND<"PermissionKey">;
|
|
230
|
+
proof: {
|
|
231
|
+
object: string & z.BRAND<"ObjectRef">;
|
|
232
|
+
subject: string & z.BRAND<"ObjectRef">;
|
|
233
|
+
relation: string;
|
|
234
|
+
}[];
|
|
235
|
+
}[];
|
|
236
|
+
principalId: string & z.BRAND<"PrincipalId">;
|
|
237
|
+
node: {
|
|
238
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
239
|
+
scopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
240
|
+
};
|
|
241
|
+
}, {
|
|
242
|
+
permissions: {
|
|
243
|
+
permission: string;
|
|
244
|
+
proof: {
|
|
245
|
+
object: string;
|
|
246
|
+
subject: string;
|
|
247
|
+
relation: string;
|
|
248
|
+
}[];
|
|
249
|
+
}[];
|
|
250
|
+
principalId: string;
|
|
251
|
+
node: {
|
|
252
|
+
tenantId: string;
|
|
253
|
+
scopeId: string | null;
|
|
254
|
+
};
|
|
255
|
+
}>;
|
|
256
|
+
export type EffectivePermissions = z.infer<typeof effectivePermissions>;
|
|
257
|
+
//# sourceMappingURL=permission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.d.ts","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,eAAO,MAAM,IAAI;;;;;;;;;EAGf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAExC,eA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Id, permissionKey, principalId, scopeId, tenantId } from './ids.js';
|
|
3
|
+
import { entityRef } from './events.js';
|
|
4
|
+
// ============================================================================
|
|
5
|
+
// Authored surface — what humans and agents write (design doc §4.1).
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// A node in the assignable tree: tenant root (scopeId null) or a scope.
|
|
8
|
+
export const node = z.object({
|
|
9
|
+
tenantId,
|
|
10
|
+
scopeId: scopeId.nullable(),
|
|
11
|
+
});
|
|
12
|
+
export const roleKey = z.string().regex(/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/);
|
|
13
|
+
export const roleDefinition = z.object({
|
|
14
|
+
key: roleKey,
|
|
15
|
+
permissions: z.array(permissionKey).min(1),
|
|
16
|
+
source: z.union([moduleId, z.literal('vertical')]),
|
|
17
|
+
});
|
|
18
|
+
export const roleAssignment = z.object({
|
|
19
|
+
principalId,
|
|
20
|
+
roleKey,
|
|
21
|
+
node,
|
|
22
|
+
});
|
|
23
|
+
// Narrow, direct, time-boxable; also the cross-tenant mechanism (§5.4).
|
|
24
|
+
// `entity` narrows the grant to one entity and its declared descendants —
|
|
25
|
+
// how portal customers see only their own facilities/orders inside a shared
|
|
26
|
+
// scope (design doc §4.1, K-12). Always audited.
|
|
27
|
+
export const capabilityGrant = z.object({
|
|
28
|
+
principalId,
|
|
29
|
+
permission: permissionKey,
|
|
30
|
+
node,
|
|
31
|
+
entity: entityRef.optional(),
|
|
32
|
+
expiresAt: instant.optional(),
|
|
33
|
+
grantedBy: principalId,
|
|
34
|
+
});
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Evaluation representation — relationship tuples (design doc §4.2, plan D-23).
|
|
37
|
+
// Internal to the checker; verticals never author these. The fixed derivation
|
|
38
|
+
// algebra (role expansion, tree inheritance, declared entity parent edges,
|
|
39
|
+
// membership) lives in the evaluator, not in configurable rewrites.
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// 'principal:<ulid>' | 'org:<ulid>' | 'tenant:<ulid>' | 'scope:<ulid>' |
|
|
42
|
+
// '<entityType>:<entityId>' — namespace:id
|
|
43
|
+
export const objectRef = z
|
|
44
|
+
.string()
|
|
45
|
+
.regex(/^[a-z0-9_-]+:[^\s]+$/)
|
|
46
|
+
.brand();
|
|
47
|
+
// 'member' | 'parent' | 'role:staff' | 'granted:workorder:read' …
|
|
48
|
+
export const relationName = z.string().regex(/^[a-z0-9_:-]+$/);
|
|
49
|
+
export const relationTuple = z.object({
|
|
50
|
+
subject: objectRef,
|
|
51
|
+
relation: relationName,
|
|
52
|
+
object: objectRef,
|
|
53
|
+
});
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Decisions — an allow ALWAYS carries its proof: the tuple chain that granted
|
|
56
|
+
// access. Powers explain(), "view as user" (§7.8), and the human-readable
|
|
57
|
+
// permission diff. An unexplained allow is unrepresentable.
|
|
58
|
+
// ============================================================================
|
|
59
|
+
export const decision = z.discriminatedUnion('allowed', [
|
|
60
|
+
z.object({
|
|
61
|
+
allowed: z.literal(true),
|
|
62
|
+
proof: z.array(relationTuple).min(1),
|
|
63
|
+
}),
|
|
64
|
+
z.object({
|
|
65
|
+
allowed: z.literal(false),
|
|
66
|
+
checked: permissionKey,
|
|
67
|
+
node,
|
|
68
|
+
}),
|
|
69
|
+
]);
|
|
70
|
+
export const effectivePermissions = z.object({
|
|
71
|
+
principalId,
|
|
72
|
+
node,
|
|
73
|
+
permissions: z.array(z.object({
|
|
74
|
+
permission: permissionKey,
|
|
75
|
+
proof: z.array(relationTuple).min(1),
|
|
76
|
+
})),
|
|
77
|
+
});
|
|
78
|
+
//# sourceMappingURL=permission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permission.js","sourceRoot":"","sources":["../src/permission.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM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
export type TenantStatus = z.infer<typeof tenantStatus>;
|
|
4
|
+
export declare const tenant: z.ZodObject<{
|
|
5
|
+
id: z.ZodBranded<z.ZodString, "TenantId">;
|
|
6
|
+
slug: z.ZodString;
|
|
7
|
+
name: z.ZodString;
|
|
8
|
+
status: z.ZodEnum<["active", "suspended", "deleting"]>;
|
|
9
|
+
createdAt: z.ZodBranded<z.ZodString, "Instant">;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
status: "active" | "suspended" | "deleting";
|
|
12
|
+
id: string & z.BRAND<"TenantId">;
|
|
13
|
+
slug: string;
|
|
14
|
+
name: string;
|
|
15
|
+
createdAt: string & z.BRAND<"Instant">;
|
|
16
|
+
}, {
|
|
17
|
+
status: "active" | "suspended" | "deleting";
|
|
18
|
+
id: string;
|
|
19
|
+
slug: string;
|
|
20
|
+
name: string;
|
|
21
|
+
createdAt: string;
|
|
22
|
+
}>;
|
|
23
|
+
export type Tenant = z.infer<typeof tenant>;
|
|
24
|
+
export declare const scopeStatus: z.ZodEnum<["provisioning", "active", "suspended", "archiving", "archived"]>;
|
|
25
|
+
export type ScopeStatus = z.infer<typeof scopeStatus>;
|
|
26
|
+
export declare const storageShape: z.ZodEnum<["A", "B"]>;
|
|
27
|
+
export type StorageShape = z.infer<typeof storageShape>;
|
|
28
|
+
export declare const jurisdiction: z.ZodNullable<z.ZodEnum<["eu"]>>;
|
|
29
|
+
export type Jurisdiction = z.infer<typeof jurisdiction>;
|
|
30
|
+
export declare const scope: z.ZodObject<{
|
|
31
|
+
id: z.ZodBranded<z.ZodString, "ScopeId">;
|
|
32
|
+
tenantId: z.ZodBranded<z.ZodString, "TenantId">;
|
|
33
|
+
parentScopeId: z.ZodNullable<z.ZodBranded<z.ZodString, "ScopeId">>;
|
|
34
|
+
slug: z.ZodString;
|
|
35
|
+
kind: z.ZodString;
|
|
36
|
+
name: z.ZodString;
|
|
37
|
+
status: z.ZodEnum<["provisioning", "active", "suspended", "archiving", "archived"]>;
|
|
38
|
+
storageShape: z.ZodEnum<["A", "B"]>;
|
|
39
|
+
jurisdiction: z.ZodNullable<z.ZodEnum<["eu"]>>;
|
|
40
|
+
schemaVersion: z.ZodString;
|
|
41
|
+
createdAt: z.ZodBranded<z.ZodString, "Instant">;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
status: "active" | "suspended" | "provisioning" | "archiving" | "archived";
|
|
44
|
+
schemaVersion: string;
|
|
45
|
+
id: string & z.BRAND<"ScopeId">;
|
|
46
|
+
tenantId: string & z.BRAND<"TenantId">;
|
|
47
|
+
slug: string;
|
|
48
|
+
name: string;
|
|
49
|
+
createdAt: string & z.BRAND<"Instant">;
|
|
50
|
+
parentScopeId: (string & z.BRAND<"ScopeId">) | null;
|
|
51
|
+
kind: string;
|
|
52
|
+
storageShape: "A" | "B";
|
|
53
|
+
jurisdiction: "eu" | null;
|
|
54
|
+
}, {
|
|
55
|
+
status: "active" | "suspended" | "provisioning" | "archiving" | "archived";
|
|
56
|
+
schemaVersion: string;
|
|
57
|
+
id: string;
|
|
58
|
+
tenantId: string;
|
|
59
|
+
slug: string;
|
|
60
|
+
name: string;
|
|
61
|
+
createdAt: string;
|
|
62
|
+
parentScopeId: string | null;
|
|
63
|
+
kind: string;
|
|
64
|
+
storageShape: "A" | "B";
|
|
65
|
+
jurisdiction: "eu" | null;
|
|
66
|
+
}>;
|
|
67
|
+
export type Scope = z.infer<typeof scope>;
|
|
68
|
+
//# sourceMappingURL=tenancy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenancy.d.ts","sourceRoot":"","sources":["../src/tenancy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,YAAY,gDAA8C,CAAC;AACxE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;EAMjB,CAAC;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAE5C,eAAO,MAAM,WAAW,6EAMtB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAGtD,eAAO,MAAM,YAAY,uBAAqB,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAGxD,eAAO,MAAM,YAAY,kCAA4B,CAAC;AACtD,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAExD,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYhB,CAAC;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC"}
|
package/dist/tenancy.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { instant, scopeId, slug, tenantId } from './ids.js';
|
|
3
|
+
export const tenantStatus = z.enum(['active', 'suspended', 'deleting']);
|
|
4
|
+
export const tenant = z.object({
|
|
5
|
+
id: tenantId,
|
|
6
|
+
slug,
|
|
7
|
+
name: z.string().min(1),
|
|
8
|
+
status: tenantStatus,
|
|
9
|
+
createdAt: instant,
|
|
10
|
+
});
|
|
11
|
+
export const scopeStatus = z.enum([
|
|
12
|
+
'provisioning',
|
|
13
|
+
'active',
|
|
14
|
+
'suspended',
|
|
15
|
+
'archiving',
|
|
16
|
+
'archived',
|
|
17
|
+
]);
|
|
18
|
+
// §5.2 of the design doc: A = DO-embedded SQLite is primary; B = DO control plane + D1
|
|
19
|
+
export const storageShape = z.enum(['A', 'B']);
|
|
20
|
+
// Fixed at provisioning; a DO can never relocate (design K-7)
|
|
21
|
+
export const jurisdiction = z.enum(['eu']).nullable();
|
|
22
|
+
export const scope = z.object({
|
|
23
|
+
id: scopeId, // globally unique; APIs still take (tenantId, scopeId) and cross-check (K-3)
|
|
24
|
+
tenantId,
|
|
25
|
+
parentScopeId: scopeId.nullable(), // v1: always null; column ships so trees are additive (K-1)
|
|
26
|
+
slug, // unique within tenant
|
|
27
|
+
kind: z.string().min(1), // vertical vocabulary ('brf', 'filial'); kernel never branches on it
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
status: scopeStatus,
|
|
30
|
+
storageShape,
|
|
31
|
+
jurisdiction,
|
|
32
|
+
schemaVersion: z.string(),
|
|
33
|
+
createdAt: instant,
|
|
34
|
+
});
|
|
35
|
+
//# sourceMappingURL=tenancy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tenancy.js","sourceRoot":"","sources":["../src/tenancy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,CAAC,CAAC,CAAC;AAGxE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7B,EAAE,EAAE,QAAQ;IACZ,IAAI;IACJ,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,OAAO;CACnB,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,IAAI,CAAC;IAChC,cAAc;IACd,QAAQ;IACR,WAAW;IACX,WAAW;IACX,UAAU;CACX,CAAC,CAAC;AAGH,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAG/C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;AAGtD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,EAAE,EAAE,OAAO,EAAE,6EAA6E;IAC1F,QAAQ;IACR,aAAa,EAAE,OAAO,CAAC,QAAQ,EAAE,EAAE,4DAA4D;IAC/F,IAAI,EAAE,uBAAuB;IAC7B,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,qEAAqE;IAC9F,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,MAAM,EAAE,WAAW;IACnB,YAAY;IACZ,YAAY;IACZ,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,SAAS,EAAE,OAAO;CACnB,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@substrat-run/contracts",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Substrat kernel contract schemas — Zod is the source of truth (master plan D-22); OAS/JSON Schema are emitted artifacts",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/substrat-run/substrat.git",
|
|
9
|
+
"directory": "packages/contracts"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/substrat-run/substrat",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"zod": "^3.25.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.6.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
36
|
+
}
|
|
37
|
+
}
|