@selvajs/platform 0.14.2 → 0.15.0-beta.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 (196) hide show
  1. package/LICENSE +1 -1
  2. package/dist/auth.d.ts +60 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +12 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/compute.d.ts +47 -0
  7. package/dist/compute.d.ts.map +1 -0
  8. package/dist/compute.js +11 -0
  9. package/dist/compute.js.map +1 -0
  10. package/dist/computeServer/index.d.ts +2 -0
  11. package/dist/computeServer/index.d.ts.map +1 -1
  12. package/dist/computeServer/index.js +6 -0
  13. package/dist/computeServer/index.js.map +1 -1
  14. package/dist/computeServer/interface.d.ts +10 -0
  15. package/dist/computeServer/interface.d.ts.map +1 -1
  16. package/dist/computeServer/secrets.d.ts +53 -0
  17. package/dist/computeServer/secrets.d.ts.map +1 -0
  18. package/dist/computeServer/secrets.js +67 -0
  19. package/dist/computeServer/secrets.js.map +1 -0
  20. package/dist/context.d.ts +7 -0
  21. package/dist/context.d.ts.map +1 -1
  22. package/dist/context.js +13 -0
  23. package/dist/context.js.map +1 -1
  24. package/dist/data/interface.d.ts +33 -0
  25. package/dist/data/interface.d.ts.map +1 -1
  26. package/dist/definitions/interface.d.ts +18 -0
  27. package/dist/definitions/interface.d.ts.map +1 -1
  28. package/dist/definitions/schemas.d.ts +1 -0
  29. package/dist/definitions/schemas.d.ts.map +1 -1
  30. package/dist/definitions/schemas.js +3 -0
  31. package/dist/definitions/schemas.js.map +1 -1
  32. package/dist/definitions/service.d.ts +62 -0
  33. package/dist/definitions/service.d.ts.map +1 -0
  34. package/dist/definitions/service.js +149 -0
  35. package/dist/definitions/service.js.map +1 -0
  36. package/dist/definitions/types.d.ts +24 -1
  37. package/dist/definitions/types.d.ts.map +1 -1
  38. package/dist/definitions.d.ts +146 -0
  39. package/dist/definitions.d.ts.map +1 -0
  40. package/dist/definitions.js +23 -0
  41. package/dist/definitions.js.map +1 -0
  42. package/dist/errors/interface.d.ts +44 -0
  43. package/dist/errors/interface.d.ts.map +1 -0
  44. package/dist/errors/interface.js +9 -0
  45. package/dist/errors/interface.js.map +1 -0
  46. package/dist/events/interface.d.ts +23 -0
  47. package/dist/events/interface.d.ts.map +1 -1
  48. package/dist/events/interface.js.map +1 -1
  49. package/dist/index.d.ts +14 -5
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +7 -2
  52. package/dist/index.js.map +1 -1
  53. package/dist/invites/schemas.d.ts +24 -0
  54. package/dist/invites/schemas.d.ts.map +1 -0
  55. package/dist/invites/schemas.js +17 -0
  56. package/dist/invites/schemas.js.map +1 -0
  57. package/dist/metrics/interface.d.ts +6 -0
  58. package/dist/metrics/interface.d.ts.map +1 -1
  59. package/dist/metrics/interface.js.map +1 -1
  60. package/dist/organizations/index.d.ts +4 -3
  61. package/dist/organizations/index.d.ts.map +1 -1
  62. package/dist/organizations/index.js +2 -1
  63. package/dist/organizations/index.js.map +1 -1
  64. package/dist/organizations/interface.d.ts +1 -1
  65. package/dist/organizations/interface.d.ts.map +1 -1
  66. package/dist/organizations/paths.d.ts +22 -0
  67. package/dist/organizations/paths.d.ts.map +1 -0
  68. package/dist/organizations/paths.js +43 -0
  69. package/dist/organizations/paths.js.map +1 -0
  70. package/dist/organizations/schemas.d.ts +10 -0
  71. package/dist/organizations/schemas.d.ts.map +1 -1
  72. package/dist/organizations/schemas.js +6 -0
  73. package/dist/organizations/schemas.js.map +1 -1
  74. package/dist/organizations/types.d.ts +10 -1
  75. package/dist/organizations/types.d.ts.map +1 -1
  76. package/dist/organizations.d.ts +93 -0
  77. package/dist/organizations.d.ts.map +1 -0
  78. package/dist/organizations.js +14 -0
  79. package/dist/organizations.js.map +1 -0
  80. package/dist/solveCache/interface.d.ts +86 -0
  81. package/dist/solveCache/interface.d.ts.map +1 -0
  82. package/dist/solveCache/interface.js +12 -0
  83. package/dist/solveCache/interface.js.map +1 -0
  84. package/dist/storage/assetClasses.d.ts +59 -0
  85. package/dist/storage/assetClasses.d.ts.map +1 -0
  86. package/dist/storage/assetClasses.js +86 -0
  87. package/dist/storage/assetClasses.js.map +1 -0
  88. package/dist/storage/cacheBust.d.ts +21 -0
  89. package/dist/storage/cacheBust.d.ts.map +1 -0
  90. package/dist/storage/cacheBust.js +29 -0
  91. package/dist/storage/cacheBust.js.map +1 -0
  92. package/dist/storage/image.d.ts +6 -1
  93. package/dist/storage/image.d.ts.map +1 -1
  94. package/dist/storage/image.js +8 -3
  95. package/dist/storage/image.js.map +1 -1
  96. package/dist/storage/index.d.ts +3 -0
  97. package/dist/storage/index.d.ts.map +1 -1
  98. package/dist/storage/index.js +2 -0
  99. package/dist/storage/index.js.map +1 -1
  100. package/dist/testing/adapterSuite.d.ts +33 -0
  101. package/dist/testing/adapterSuite.d.ts.map +1 -0
  102. package/dist/testing/adapterSuite.js +166 -0
  103. package/dist/testing/adapterSuite.js.map +1 -0
  104. package/dist/testing/suites/definitionStoreSuite.d.ts.map +1 -1
  105. package/dist/testing/suites/definitionStoreSuite.js +87 -0
  106. package/dist/testing/suites/definitionStoreSuite.js.map +1 -1
  107. package/dist/testing/suites/eventSinkSuite.js +1 -0
  108. package/dist/testing/suites/eventSinkSuite.js.map +1 -1
  109. package/dist/testing/suites/orgStoreSuite.d.ts.map +1 -1
  110. package/dist/testing/suites/orgStoreSuite.js +12 -0
  111. package/dist/testing/suites/orgStoreSuite.js.map +1 -1
  112. package/dist/testing/suites/platformPermissionStoreSuite.d.ts +9 -0
  113. package/dist/testing/suites/platformPermissionStoreSuite.d.ts.map +1 -1
  114. package/dist/testing/suites/platformPermissionStoreSuite.js +34 -1
  115. package/dist/testing/suites/platformPermissionStoreSuite.js.map +1 -1
  116. package/dist/testing/suites/runner.d.ts +21 -0
  117. package/dist/testing/suites/runner.d.ts.map +1 -0
  118. package/dist/testing/suites/runner.js +7 -0
  119. package/dist/testing/suites/runner.js.map +1 -0
  120. package/dist/testing/suites/storageProviderSuite.d.ts.map +1 -1
  121. package/dist/testing/suites/storageProviderSuite.js +18 -0
  122. package/dist/testing/suites/storageProviderSuite.js.map +1 -1
  123. package/package.json +9 -24
  124. package/src/access/index.ts +0 -23
  125. package/src/access/rules.ts +0 -276
  126. package/src/auth/index.ts +0 -8
  127. package/src/auth/interface.ts +0 -279
  128. package/src/auth/types.ts +0 -32
  129. package/src/bindings/index.ts +0 -2
  130. package/src/bindings/interface.ts +0 -61
  131. package/src/computeServer/index.ts +0 -17
  132. package/src/computeServer/interface.ts +0 -62
  133. package/src/computeServer/types.ts +0 -74
  134. package/src/computeServer/utils.ts +0 -112
  135. package/src/config.ts +0 -99
  136. package/src/context.ts +0 -66
  137. package/src/data/index.ts +0 -1
  138. package/src/data/interface.ts +0 -70
  139. package/src/definitions/index.ts +0 -26
  140. package/src/definitions/interface.ts +0 -78
  141. package/src/definitions/paths.ts +0 -31
  142. package/src/definitions/schemas.ts +0 -64
  143. package/src/definitions/types.ts +0 -111
  144. package/src/errors.ts +0 -16
  145. package/src/events/audit.ts +0 -67
  146. package/src/events/index.ts +0 -9
  147. package/src/events/interface.ts +0 -102
  148. package/src/index.ts +0 -219
  149. package/src/invites/index.ts +0 -2
  150. package/src/invites/interface.ts +0 -38
  151. package/src/invites/types.ts +0 -39
  152. package/src/metrics/interface.ts +0 -86
  153. package/src/organizations/index.ts +0 -14
  154. package/src/organizations/interface.ts +0 -68
  155. package/src/organizations/schemas.ts +0 -52
  156. package/src/organizations/types.ts +0 -31
  157. package/src/pagination.ts +0 -45
  158. package/src/permissions/index.ts +0 -3
  159. package/src/permissions/interface.ts +0 -60
  160. package/src/permissions/types.ts +0 -21
  161. package/src/platformProjects/index.ts +0 -3
  162. package/src/platformProjects/interface.ts +0 -27
  163. package/src/platformProjects/schemas.ts +0 -13
  164. package/src/platformProjects/types.ts +0 -22
  165. package/src/projects/index.ts +0 -4
  166. package/src/projects/interface.ts +0 -58
  167. package/src/projects/schemas.ts +0 -28
  168. package/src/projects/types.ts +0 -36
  169. package/src/shareLinks/index.ts +0 -5
  170. package/src/shareLinks/interface.ts +0 -35
  171. package/src/shareLinks/schemas.ts +0 -21
  172. package/src/shareLinks/types.ts +0 -34
  173. package/src/storage/image.ts +0 -77
  174. package/src/storage/index.ts +0 -9
  175. package/src/storage/interface.ts +0 -27
  176. package/src/testing/index.ts +0 -47
  177. package/src/testing/suites/authProviderSuite.ts +0 -207
  178. package/src/testing/suites/computeServerStoreSuite.ts +0 -195
  179. package/src/testing/suites/definitionStoreSuite.ts +0 -585
  180. package/src/testing/suites/emailLinkAuthSuite.ts +0 -83
  181. package/src/testing/suites/eventSinkSuite.ts +0 -379
  182. package/src/testing/suites/helpers.ts +0 -87
  183. package/src/testing/suites/inviteStoreSuite.ts +0 -143
  184. package/src/testing/suites/orgStoreSuite.ts +0 -412
  185. package/src/testing/suites/platformPermissionStoreSuite.ts +0 -196
  186. package/src/testing/suites/platformProjectGrantStoreSuite.ts +0 -166
  187. package/src/testing/suites/projectStoreSuite.ts +0 -381
  188. package/src/testing/suites/shareLinkStoreSuite.ts +0 -203
  189. package/src/testing/suites/solveMetricSinkSuite.ts +0 -135
  190. package/src/testing/suites/storageProviderSuite.ts +0 -175
  191. package/src/testing/suites/userProfileStoreSuite.ts +0 -134
  192. package/src/userProfile/index.ts +0 -3
  193. package/src/userProfile/interface.ts +0 -48
  194. package/src/userProfile/types.ts +0 -24
  195. package/src/utils/audit.ts +0 -46
  196. package/src/utils/index.ts +0 -2
@@ -1,102 +0,0 @@
1
- /**
2
- * Domain-event sink. Stores call `emit` AFTER a successful mutation; failed
3
- * writes do not emit. `emit` MUST NOT throw — failures are the sink's
4
- * problem to log and swallow.
5
- *
6
- * `actorId` is the user who triggered the change, or `'system'` for
7
- * SYSTEM_CONTEXT mutations (bootstrap, janitor, migrations).
8
- */
9
-
10
- export type DomainEvent =
11
- | { type: 'org.created'; orgId: string; actorId: string }
12
- | { type: 'org.deleted'; orgId: string; actorId: string }
13
- | { type: 'org_member.added'; orgId: string; userId: string; actorId: string }
14
- | { type: 'org_member.removed'; orgId: string; userId: string; actorId: string }
15
- | {
16
- type: 'org_member.role_changed';
17
- orgId: string;
18
- userId: string;
19
- role: string;
20
- actorId: string;
21
- }
22
- | {
23
- type: 'org_member.permissions_changed';
24
- orgId: string;
25
- userId: string;
26
- permissions: readonly string[];
27
- actorId: string;
28
- }
29
- | { type: 'project.created'; projectId: string; orgId: string; actorId: string }
30
- | { type: 'project.deleted'; projectId: string; actorId: string }
31
- | { type: 'project_member.added'; projectId: string; userId: string; actorId: string }
32
- | { type: 'project_member.removed'; projectId: string; userId: string; actorId: string }
33
- | {
34
- type: 'project_member.role_changed';
35
- projectId: string;
36
- userId: string;
37
- role: string;
38
- actorId: string;
39
- }
40
- | { type: 'definition.created'; definitionId: string; projectId: string; actorId: string }
41
- | { type: 'definition.deleted'; definitionId: string; actorId: string }
42
- | { type: 'definition.published'; definitionId: string; versionId: string; actorId: string }
43
- | {
44
- type: 'definition_version.created';
45
- versionId: string;
46
- definitionId: string;
47
- actorId: string;
48
- }
49
- | { type: 'definition_version.deleted'; versionId: string; actorId: string }
50
- | { type: 'share_link.minted'; linkId: string; definitionId: string; actorId: string }
51
- | { type: 'share_link.revoked'; linkId: string; actorId: string }
52
- | {
53
- type: 'invite.created';
54
- inviteId: string;
55
- orgId: string;
56
- email: string;
57
- actorId: string;
58
- }
59
- | { type: 'invite.accepted'; inviteId: string; orgId: string; userId: string; actorId: string }
60
- | { type: 'invite.revoked'; inviteId: string; orgId: string; actorId: string };
61
-
62
- export type DomainEventType = DomainEvent['type'];
63
-
64
- export interface IEventSink {
65
- /**
66
- * Record a domain event. Called by stores AFTER a successful mutation; a
67
- * failed write does not emit.
68
- *
69
- * MUST NOT throw — this method is on the hot path of every mutating
70
- * operation, and an exception here would surface as a failed write even
71
- * though the actual mutation already committed. Implementations MUST
72
- * catch network errors, queue overflows, and any other transient or
73
- * persistent failures internally and log them; the only side effect
74
- * visible to the caller is a fulfilled promise.
75
- *
76
- * MAY be fire-and-forget — the contract is "best-effort durable
77
- * recording," not synchronous persistence. Adapters that queue + flush
78
- * asynchronously are valid as long as they preserve event ordering per
79
- * `actorId`.
80
- */
81
- emit(event: DomainEvent): Promise<void>;
82
- }
83
-
84
- /**
85
- * Resolve the actor id from a RequestContext. Returns `ctx.userId` when set,
86
- * `'system'` otherwise — matches the `SYSTEM_CONTEXT` convention where
87
- * `userId === ''` denotes a server-internal caller (bootstrap, janitors,
88
- * migrations).
89
- */
90
- export function actorFrom(ctx: { userId: string; system?: boolean }): string {
91
- return ctx.userId || 'system';
92
- }
93
-
94
- /**
95
- * Default `IEventSink` — discards every event. Used when `SelvaConfig.events`
96
- * is omitted, and as the safe fallback for adapters whose data layer has no
97
- * event log (local-provider). Drop-in replace via `SelvaConfig.events` once a
98
- * real dispatcher is wired.
99
- */
100
- export class NoopEventSink implements IEventSink {
101
- async emit(_event: DomainEvent): Promise<void> {}
102
- }
package/src/index.ts DELETED
@@ -1,219 +0,0 @@
1
- // @selvajs/platform — published API contract. Every symbol here is breaking-change-protected.
2
-
3
- // auth
4
- export type { AuthUser, UserManagementResult, LoginResult } from './auth/types.js';
5
- export type {
6
- IAuthProvider,
7
- IOAuthAuth,
8
- IPasswordAuth,
9
- IEmailLinkAuth,
10
- IProxyAuth
11
- } from './auth/interface.js';
12
-
13
- // ---------------------------------------------------------------------------
14
- // permissions
15
- // ---------------------------------------------------------------------------
16
- export type { PlatformPermission } from './permissions/types.js';
17
- export { PlatformPermissionSchema, ALL_PLATFORM_PERMISSIONS } from './permissions/types.js';
18
- export type { IPlatformPermissionStore } from './permissions/interface.js';
19
-
20
- // userProfile
21
- export type { IUserProfileStore } from './userProfile/interface.js';
22
- export type { UserProfile, RecentRun } from './userProfile/types.js';
23
- export { emptyProfile } from './userProfile/types.js';
24
-
25
- // organizations
26
- export type { Organization, OrgMember } from './organizations/types.js';
27
- export type { IOrgStore } from './organizations/interface.js';
28
- export type {
29
- OrgRole,
30
- OrgPermission,
31
- CreateOrgInput,
32
- UpdateOrgInput
33
- } from './organizations/schemas.js';
34
- export {
35
- OrgRoleSchema,
36
- OrgPermissionSchema,
37
- SlugSchema,
38
- CreateOrgSchema,
39
- UpdateOrgSchema,
40
- ALL_ORG_PERMISSIONS,
41
- DEFAULT_ORG_PERMISSIONS,
42
- OWNER_ADMIN_ONLY_PERMISSIONS,
43
- MEMBER_ASSIGNABLE_PERMISSIONS
44
- } from './organizations/schemas.js';
45
-
46
- // invites
47
- export type { Invite } from './invites/types.js';
48
- export type { IInviteStore } from './invites/interface.js';
49
-
50
- // projects
51
- export type { Project, ProjectMember } from './projects/types.js';
52
- export type { IProjectStore } from './projects/interface.js';
53
- export type { ProjectVisibility, ProjectRole } from './projects/schemas.js';
54
- export {
55
- ProjectVisibilitySchema,
56
- ProjectRoleSchema,
57
- validateProjectFlags
58
- } from './projects/schemas.js';
59
-
60
- // platformProjects
61
- export type { PlatformProjectGrant, PlatformProjectGranteeType } from './platformProjects/types.js';
62
- export type { IPlatformProjectGrantStore } from './platformProjects/interface.js';
63
- export {
64
- PlatformProjectGrantSchema,
65
- PlatformProjectGranteeTypeSchema
66
- } from './platformProjects/schemas.js';
67
-
68
- // definitions
69
- export type {
70
- DefinitionFileExt,
71
- DefinitionRecord,
72
- DefinitionRecordPatch,
73
- DefinitionStatus,
74
- DefinitionVersion,
75
- DefinitionChannel
76
- } from './definitions/types.js';
77
- export type { IDefinitionStore } from './definitions/interface.js';
78
- export type { UISchema } from '@selvajs/schemas';
79
- export {
80
- GH_EXTENSIONS,
81
- COVER_IMAGE_EXTENSIONS,
82
- ALLOWED_UPLOAD_EXTENSIONS,
83
- COVER_IMAGE_CONTENT_TYPES
84
- } from './definitions/types.js';
85
- export { definitionPaths } from './definitions/paths.js';
86
- export type { UpdateMetadataInput } from './definitions/schemas.js';
87
- export {
88
- DefinitionChannelSchema,
89
- PublishVersionInputSchema,
90
- CreateDefinitionInputSchema,
91
- UpdateMetadataInputSchema,
92
- GuidSchema,
93
- UUID_REGEX
94
- } from './definitions/schemas.js';
95
-
96
- // ---------------------------------------------------------------------------
97
- // shareLinks
98
- // ---------------------------------------------------------------------------
99
- export type { ShareLink } from './shareLinks/types.js';
100
- export type { IShareLinkStore } from './shareLinks/interface.js';
101
- export { DEFAULT_SHARE_LINK_MAX_SOLVES } from './shareLinks/types.js';
102
- export type { CreateShareLinkInput } from './shareLinks/schemas.js';
103
- export { CreateShareLinkInputSchema } from './shareLinks/schemas.js';
104
-
105
- // ---------------------------------------------------------------------------
106
- // storage
107
- // ---------------------------------------------------------------------------
108
- export type { IStorageProvider } from './storage/interface.js';
109
- export {
110
- IMAGE_MAX_WIDTH,
111
- IMAGE_WEBP_QUALITY,
112
- isImageUpload,
113
- toWebpPath,
114
- transcodeImageIfNeeded
115
- } from './storage/image.js';
116
- export type { TranscodeResult } from './storage/image.js';
117
-
118
- // ---------------------------------------------------------------------------
119
- // data (composition root)
120
- // ---------------------------------------------------------------------------
121
- export type { IDataProvider } from './data/interface.js';
122
-
123
- // ---------------------------------------------------------------------------
124
- // computeServer
125
- // ---------------------------------------------------------------------------
126
- export type {
127
- ComputeServerConfig,
128
- ComputeConfig,
129
- PlatformComputeServer,
130
- OrgComputeServer
131
- } from './computeServer/types.js';
132
- export { isPlatformServer, isOrgServer } from './computeServer/types.js';
133
- export type { IComputeServerStore } from './computeServer/interface.js';
134
- export type { ResolveOptions } from './computeServer/utils.js';
135
- export {
136
- serversVisibleTo,
137
- defaultServerIdFor,
138
- resolveServerForOrg,
139
- findServerById,
140
- platformServers,
141
- orgServersFor
142
- } from './computeServer/utils.js';
143
-
144
- // ---------------------------------------------------------------------------
145
- // access (pure permission predicates)
146
- // ---------------------------------------------------------------------------
147
- export type {
148
- ProjectAccessInput,
149
- DefinitionAccessInput,
150
- VisibilityChangeInput,
151
- ReclaimAccessInput,
152
- CreateProjectAccessInput,
153
- OwnerRemovalInput,
154
- OwnerRemovalCheck
155
- } from './access/rules.js';
156
- export {
157
- canView,
158
- canSolve,
159
- canEdit,
160
- canManage,
161
- canEditProjectSettings,
162
- canChangeVisibilityToPublic,
163
- canEditDefinition,
164
- canReclaim,
165
- canCreateProject,
166
- checkOwnerRemoval,
167
- withAdminBypass
168
- } from './access/rules.js';
169
-
170
- // ---------------------------------------------------------------------------
171
- // events
172
- // ---------------------------------------------------------------------------
173
- export type { DomainEvent, DomainEventType, IEventSink } from './events/interface.js';
174
- export { actorFrom, NoopEventSink } from './events/interface.js';
175
- export type {
176
- AuditEventRow,
177
- AuditCursor,
178
- AuditQueryFilters,
179
- AuditQueryResult,
180
- IAuditQuery
181
- } from './events/audit.js';
182
-
183
- // ---------------------------------------------------------------------------
184
- // metrics (per-solve timing telemetry)
185
- // ---------------------------------------------------------------------------
186
- export type { ISolveMetricSink, SolveMetric, SolveFailureKind } from './metrics/interface.js';
187
- export { NoopSolveMetricSink } from './metrics/interface.js';
188
-
189
- // ---------------------------------------------------------------------------
190
- // bindings (server-side resolver for schema inputs marked `source.kind === 'server'`)
191
- // ---------------------------------------------------------------------------
192
- export type { IBindingResolver } from './bindings/interface.js';
193
- export { NoopBindingResolver } from './bindings/interface.js';
194
-
195
- // ---------------------------------------------------------------------------
196
- // utils
197
- // ---------------------------------------------------------------------------
198
- export type { AuditUpdate, AuditSoftDelete } from './utils/audit.js';
199
- export { auditUpdate, auditSoftDelete } from './utils/audit.js';
200
-
201
- // ---------------------------------------------------------------------------
202
- // top-level (context, pagination, config, errors)
203
- // ---------------------------------------------------------------------------
204
- export type { RequestContext } from './context.js';
205
- export { SYSTEM_CONTEXT, hasPermission } from './context.js';
206
-
207
- export type { ListOptions, DefinitionListOptions, Page } from './pagination.js';
208
- export { DEFAULT_PAGE_LIMIT, MAX_PAGE_LIMIT } from './pagination.js';
209
-
210
- export type {
211
- TenancyMode,
212
- SelvaFlags,
213
- SelvaBranding,
214
- SelvaConfig,
215
- SelvaConfigFactory
216
- } from './config.js';
217
- export { isFlagEnabled, defineConfig } from './config.js';
218
-
219
- export { ProviderError } from './errors.js';
@@ -1,2 +0,0 @@
1
- export type { Invite } from './types.js';
2
- export type { IInviteStore } from './interface.js';
@@ -1,38 +0,0 @@
1
- import type { RequestContext } from '../context.js';
2
- import type { ListOptions, Page } from '../pagination.js';
3
- import type { Invite } from './types.js';
4
-
5
- /**
6
- * "Admin invites a user, user clicks link and joins" flow. Decoupled from
7
- * `IAuthProvider` so accept works regardless of how credentials are owned.
8
- *
9
- * Mutations require a session (gated by route layer). `getByTokenHash` and
10
- * `markAccepted` accept `SYSTEM_CONTEXT` because the token is the capability
11
- * — the public /accept-invite page has no session yet.
12
- */
13
- export interface IInviteStore {
14
- create(ctx: RequestContext, invite: Invite): Promise<void>;
15
-
16
- /**
17
- * Lookup by HMAC hash of the raw token. Caller hashes the inbound token
18
- * (e.g. via `packages/selva/src/lib/server/invites/token.server.ts`) and
19
- * passes the digest here. Returns null for unknown, expired, or
20
- * consumed invites.
21
- */
22
- getByTokenHash(ctx: RequestContext, tokenHash: string): Promise<Invite | null>;
23
-
24
- listByOrg(ctx: RequestContext, orgId: string, opts?: ListOptions): Promise<Page<Invite>>;
25
-
26
- /** No-op if already accepted. */
27
- markAccepted(ctx: RequestContext, id: string, userId: string): Promise<void>;
28
-
29
- /** No-op if already consumed or missing. */
30
- revoke(ctx: RequestContext, id: string): Promise<void>;
31
-
32
- /**
33
- * Hard-delete every invite belonging to an org. Called from `deleteOrg`
34
- * cascade — pending invites to a deleted org are unredeemable, so leaving
35
- * them behind only creates orphans.
36
- */
37
- deleteByOrg(ctx: RequestContext, orgId: string): Promise<void>;
38
- }
@@ -1,39 +0,0 @@
1
- import type { OrgRole, OrgPermission } from '../organizations/schemas.js';
2
-
3
- /**
4
- * "The holder of the raw token whose hash is `tokenHash` may join `orgId` at
5
- * `orgRole` with these org permissions." Accepting creates the user (if
6
- * needed), the org membership, and marks the invite consumed.
7
- *
8
- * The raw token is shown to the admin once at mint time and embedded in the
9
- * accept URL; the store sees only `HMAC-SHA256(secret, rawToken)`. A DB-only
10
- * leak therefore can't be replayed — the attacker would need the instance
11
- * secret too. Mirrors the share-link design (`ShareLink.tokenHash`).
12
- *
13
- * `getByTokenHash` is callable without a session — knowing a valid token
14
- * (and therefore being able to hash it) is the auth.
15
- */
16
- export interface Invite {
17
- id: string;
18
- /**
19
- * `HMAC-SHA256(INVITE_TOKEN_SECRET, rawToken)` — base64url. The raw token
20
- * never crosses the store boundary; the route layer hashes inbound tokens
21
- * before lookup.
22
- */
23
- tokenHash: string;
24
- /** Lowercase email the invite was issued for. */
25
- email: string;
26
- orgId: string;
27
- orgRole: OrgRole;
28
- /**
29
- * Permissions to grant on accept. May be empty — adapters may seed from
30
- * `DEFAULT_ORG_PERMISSIONS` in that case.
31
- */
32
- orgPermissions: OrgPermission[];
33
- invitedBy: string;
34
- createdAt: string;
35
- expiresAt: string;
36
- /** Set when consumed. Consumed invites are not re-usable. */
37
- acceptedAt?: string;
38
- acceptedByUserId?: string;
39
- }
@@ -1,86 +0,0 @@
1
- import type { RequestContext } from '../context.js';
2
-
3
- /**
4
- * Why a solve did not produce a usable result. `ok` means the solve completed
5
- * (it may still carry Grasshopper runtime errors — see `errorCount`). The
6
- * failure kinds mirror the distinct branches the compute route already
7
- * distinguishes, so the recorded reason matches the HTTP status the client saw.
8
- */
9
- export type SolveFailureKind =
10
- /** Solve completed; the response was returned to the client. */
11
- | 'ok'
12
- /** Scheduler deadline exceeded (HTTP 504). */
13
- | 'timeout'
14
- /** Client disconnected mid-solve; the request signal aborted (HTTP 499). */
15
- | 'client_abort'
16
- /** Rejected by the per-key rate limiter before solving (HTTP 429). */
17
- | 'rate_limited'
18
- /** Share-link solve cap reached before solving (HTTP 429). */
19
- | 'share_cap'
20
- /** Result exceeded the response size limit (HTTP 413). */
21
- | 'too_large'
22
- /** Compute server unreachable or the solve threw for any other reason. */
23
- | 'compute_error';
24
-
25
- /**
26
- * One solve's timing and outcome, recorded once per solve attempt — including
27
- * attempts rejected before `scheduler.solve()` runs (rate limit, share cap).
28
- *
29
- * `durationMs` is wall time around the Rhino.Compute solve call only — it
30
- * excludes definition loading, auth, schema work, and result serialization. It
31
- * is 0 for attempts rejected before the solve started.
32
- */
33
- export interface SolveMetric {
34
- /** Definition the solve ran against. `local:<guid>` or a remote URL. */
35
- definitionUrl: string;
36
- /**
37
- * Local definition id (the `local:` guid), or null for remote-URL solves.
38
- * Stored alongside `definitionUrl` so timings join to the definition record.
39
- */
40
- definitionId: string | null;
41
- /**
42
- * The exact version solved, or null for remote-URL solves (and for local
43
- * attempts rejected before the version resolved). Lets you compare timings
44
- * across versions of the same definition.
45
- */
46
- versionId: string | null;
47
- /** Channel solved, mirroring the compute request. */
48
- channel: 'live' | 'draft';
49
- /** Org whose compute pool served the solve, or null for remote definitions. */
50
- orgId: string | null;
51
- /** Wall-clock duration of `scheduler.solve()` in milliseconds. 0 if never started. */
52
- durationMs: number;
53
- /** Whether the solve completed and returned a result. */
54
- ok: boolean;
55
- /** Why the solve did not return a result; `'ok'` when it did. */
56
- failureKind: SolveFailureKind;
57
- /**
58
- * Count of Grasshopper runtime errors in the solve response. A solve can be
59
- * `ok` yet still report component-level errors — this is distinct from
60
- * `failureKind`. 0 when the solve never returned a response.
61
- */
62
- errorCount: number;
63
- /** Count of Grasshopper runtime warnings in the solve response. */
64
- warningCount: number;
65
- }
66
-
67
- /**
68
- * Sink for per-solve timing telemetry. Called once per solve attempt from the
69
- * compute route, AFTER the solve resolves or rejects.
70
- *
71
- * MUST NOT throw — recording is best-effort and sits on the hot path of every
72
- * solve. Implementations catch and log their own failures; the only side
73
- * effect visible to the caller is a fulfilled promise. MAY be fire-and-forget.
74
- */
75
- export interface ISolveMetricSink {
76
- record(ctx: RequestContext, metric: SolveMetric): Promise<void>;
77
- }
78
-
79
- /**
80
- * Default `ISolveMetricSink` — discards every metric. Used when
81
- * `SelvaConfig.solveMetrics` is omitted. Swap in a real sink to persist or
82
- * aggregate solve timings.
83
- */
84
- export class NoopSolveMetricSink implements ISolveMetricSink {
85
- async record(_ctx: RequestContext, _metric: SolveMetric): Promise<void> {}
86
- }
@@ -1,14 +0,0 @@
1
- export type { Organization, OrgMember } from './types.js';
2
- export type { IOrgStore } from './interface.js';
3
- export type { OrgRole, OrgPermission, CreateOrgInput, UpdateOrgInput } from './schemas.js';
4
- export {
5
- OrgRoleSchema,
6
- OrgPermissionSchema,
7
- SlugSchema,
8
- CreateOrgSchema,
9
- UpdateOrgSchema,
10
- ALL_ORG_PERMISSIONS,
11
- DEFAULT_ORG_PERMISSIONS,
12
- OWNER_ADMIN_ONLY_PERMISSIONS,
13
- MEMBER_ASSIGNABLE_PERMISSIONS
14
- } from './schemas.js';
@@ -1,68 +0,0 @@
1
- import type { RequestContext } from '../context.js';
2
- import type { ListOptions, Page } from '../pagination.js';
3
- import type { Organization, OrgMember } from './types.js';
4
- import type { OrgRole, OrgPermission } from './schemas.js';
5
-
6
- /**
7
- * Organizations + org members. Tenancy boundary for everything else; reads and
8
- * writes scope by `ctx.actingOrgId`.
9
- */
10
- export interface IOrgStore {
11
- // Organizations
12
- listOrgs(ctx: RequestContext, opts?: ListOptions): Promise<Page<Organization>>;
13
- getOrg(ctx: RequestContext, id: string): Promise<Organization | null>;
14
- getOrgBySlug(ctx: RequestContext, slug: string): Promise<Organization | null>;
15
- createOrg(ctx: RequestContext, org: Organization): Promise<void>;
16
- updateOrg(
17
- ctx: RequestContext,
18
- id: string,
19
- patch: Partial<Pick<Organization, 'name' | 'slug'>>
20
- ): Promise<void>;
21
- /**
22
- * Soft-delete the org. Cascades soft-delete to org members, projects in the
23
- * org, and project members. Definitions and share links cascade through the
24
- * project deletion. Invites and the org compute-server override are NOT
25
- * cascaded — clean those up explicitly if needed.
26
- */
27
- deleteOrg(ctx: RequestContext, id: string): Promise<void>;
28
-
29
- // Org members
30
- listOrgMembers(ctx: RequestContext, orgId: string, opts?: ListOptions): Promise<Page<OrgMember>>;
31
- getOrgMember(ctx: RequestContext, orgId: string, userId: string): Promise<OrgMember | null>;
32
- /**
33
- * Find ONE org membership for the user. Used by the request-bootstrap
34
- * path to resolve `actingOrgId` without N+1-ing over `listOrgs`.
35
- *
36
- * Returns `null` when the user has no live membership. When the user has
37
- * multiple memberships (multi-tenant deployments), the choice between
38
- * them is adapter-defined — single-tenant deployments have exactly one,
39
- * and multi-tenant deployments will eventually use a URL prefix
40
- * (`/o/{slug}/...`) to pick explicitly. Soft-deleted memberships are
41
- * excluded.
42
- *
43
- * Both `org` and `member` are scoped by `ctx` (RLS-aware on Supabase).
44
- */
45
- findUserMembership(
46
- ctx: RequestContext,
47
- userId: string
48
- ): Promise<{ org: Organization; member: OrgMember } | null>;
49
- addOrgMember(ctx: RequestContext, member: OrgMember): Promise<void>;
50
- updateOrgMemberRole(
51
- ctx: RequestContext,
52
- orgId: string,
53
- userId: string,
54
- role: OrgRole
55
- ): Promise<void>;
56
- /**
57
- * Replace `OrgPermission` set without changing role. Use this for
58
- * permission edits — round-tripping through remove + add cascades the
59
- * org-removal soft-delete into project memberships.
60
- */
61
- updateOrgMemberPermissions(
62
- ctx: RequestContext,
63
- orgId: string,
64
- userId: string,
65
- permissions: readonly OrgPermission[]
66
- ): Promise<void>;
67
- removeOrgMember(ctx: RequestContext, orgId: string, userId: string): Promise<void>;
68
- }
@@ -1,52 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- /** Lowercase alphanumeric with internal hyphens, 3–63 chars. */
4
- export const SlugSchema = z
5
- .string()
6
- .min(3, 'Slug must be at least 3 characters')
7
- .max(63, 'Slug must be at most 63 characters')
8
- .regex(
9
- /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/,
10
- 'Slug must be lowercase alphanumeric with hyphens (no leading/trailing/consecutive hyphens)'
11
- );
12
-
13
- export const OrgRoleSchema = z.enum(['owner', 'admin', 'member']);
14
- export type OrgRole = z.infer<typeof OrgRoleSchema>;
15
-
16
- /** Org-scope permissions. A user may hold different sets in different orgs. */
17
- export const OrgPermissionSchema = z.enum([
18
- 'manage_org_members',
19
- 'manage_org_compute',
20
- 'manage_definitions',
21
- 'manage_projects'
22
- ]);
23
- export type OrgPermission = z.infer<typeof OrgPermissionSchema>;
24
-
25
- export const ALL_ORG_PERMISSIONS: readonly OrgPermission[] = OrgPermissionSchema.options;
26
-
27
- /** Governance perms — never grantable to `member`. */
28
- export const OWNER_ADMIN_ONLY_PERMISSIONS: readonly OrgPermission[] = [
29
- 'manage_org_members',
30
- 'manage_org_compute'
31
- ];
32
-
33
- export const MEMBER_ASSIGNABLE_PERMISSIONS: readonly OrgPermission[] = ALL_ORG_PERMISSIONS.filter(
34
- (p) => !OWNER_ADMIN_ONLY_PERMISSIONS.includes(p)
35
- );
36
-
37
- /** Applied when adding a member without an explicit permissions list. */
38
- export const DEFAULT_ORG_PERMISSIONS: Record<OrgRole, readonly OrgPermission[]> = {
39
- owner: [...ALL_ORG_PERMISSIONS],
40
- admin: [...ALL_ORG_PERMISSIONS],
41
- member: []
42
- };
43
-
44
- export const CreateOrgSchema = z.object({
45
- name: z.string().min(1, 'Organization name is required').max(128),
46
- slug: SlugSchema
47
- });
48
-
49
- export const UpdateOrgSchema = CreateOrgSchema.partial();
50
-
51
- export type CreateOrgInput = z.infer<typeof CreateOrgSchema>;
52
- export type UpdateOrgInput = z.infer<typeof UpdateOrgSchema>;
@@ -1,31 +0,0 @@
1
- import type { OrgRole, OrgPermission } from './schemas.js';
2
-
3
- export interface Organization {
4
- id: string;
5
- name: string;
6
- /** URL-safe unique identifier, e.g. "acme-corp". */
7
- slug: string;
8
- /** Transferable; distinct from `createdBy`. */
9
- ownerId: string;
10
- /** Immutable even on ownership transfer. */
11
- createdBy: string;
12
- updatedBy: string;
13
- createdAt: string;
14
- updatedAt: string;
15
- deletedAt?: string | null;
16
- }
17
-
18
- export interface OrgMember {
19
- orgId: string;
20
- userId: string;
21
- role: OrgRole;
22
- /**
23
- * `role` is the user-facing summary; `permissions` is what adapters check.
24
- * Seeded from `DEFAULT_ORG_PERMISSIONS[role]` when not specified.
25
- */
26
- permissions: OrgPermission[];
27
- joinedAt: string;
28
- updatedAt: string;
29
- updatedBy: string;
30
- deletedAt?: string | null;
31
- }