@rjromeoent/ein-supabase 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -79,13 +79,253 @@ Use semver intentionally:
79
79
  - Minor: additive contracts or new schemas/functions.
80
80
  - Major: renamed or removed contracts, breaking permission/app context changes.
81
81
 
82
- ## Consumer Rule
82
+ ## Package Boundary
83
83
 
84
- App repos may keep their UI-specific adapters and view models locally, but
85
- shared backend contracts belong here first:
84
+ This package is the shared contract layer between Event Intelligence Network and
85
+ independent app repos. It should stay small, stable, and backend-oriented.
86
86
 
87
- - generated `Database` types
88
- - app slugs and `x-ein-app`
89
- - canonical org roles and permission helpers
90
- - Edge Function request/response contracts
91
- - shared runtime guards that protect persisted JSON or Edge response boundaries
87
+ Use this rule:
88
+
89
+ > Put a thing in this package only when more than one app should depend on the
90
+ > same backend contract or helper. Keep app workflow, UI, and feature-specific
91
+ > shapes inside the app until reuse is real.
92
+
93
+ ### Belongs In This Package
94
+
95
+ #### Generated Database Types
96
+
97
+ Examples:
98
+
99
+ - `Database`
100
+ - schema table/view/function types generated from EIN Supabase
101
+ - schema-aware Supabase helpers like `schemaClient`
102
+
103
+ Why:
104
+
105
+ These represent the actual EIN database contract. Every connected app should
106
+ compile against the same source of truth instead of copying partial generated
107
+ types.
108
+
109
+ #### App Registry And Request Context
110
+
111
+ Examples:
112
+
113
+ - `EIN_APP_SLUGS`
114
+ - `EIN_APP_HEADER`
115
+ - `einAppHeaders("rad")`
116
+
117
+ Why:
118
+
119
+ RLS policies and app-scoped RPCs depend on the same `x-ein-app` slug everywhere.
120
+ If each app hand-types the slug/header, policy mismatches are easy to create and
121
+ hard to debug.
122
+
123
+ #### Shared Auth And Organization Vocabulary
124
+
125
+ Examples:
126
+
127
+ - `CoreOrgRole`
128
+ - role helpers for `core.app_organization_memberships`
129
+ - helpers that answer "can this user access this app/org?"
130
+
131
+ Why:
132
+
133
+ All apps should interpret core org membership the same way. An app can map
134
+ canonical roles to local workflow roles, but the canonical role vocabulary
135
+ belongs here.
136
+
137
+ Example local mapping:
138
+
139
+ ```ts
140
+ import type { CoreOrgRole } from "@rjromeoent/ein-supabase";
141
+
142
+ type BookingWorkflowRole = "admin" | "rep" | "viewer";
143
+
144
+ export function mapBookingRole(role: CoreOrgRole): BookingWorkflowRole {
145
+ if (role === "owner" || role === "admin") return "admin";
146
+ if (role === "member") return "rep";
147
+ return "viewer";
148
+ }
149
+ ```
150
+
151
+ #### Generic JSON Guards
152
+
153
+ Examples:
154
+
155
+ - `isJsonRecord`
156
+ - `toJsonRecord`
157
+ - `stringOrNull`
158
+ - `numberOrNull`
159
+ - `booleanOrFalse`
160
+ - `stringArrayOrEmpty`
161
+
162
+ Why:
163
+
164
+ Every EIN-connected app reads JSON metadata, Edge Function payloads, and
165
+ Supabase JSON columns. These low-level primitives are generic, stable, and not
166
+ tied to any app workflow. Keeping them here avoids each app recreating slightly
167
+ different JSON parsing behavior.
168
+
169
+ These helpers should stay small and dependency-free. App-specific parsers should
170
+ compose them locally.
171
+
172
+ #### Cross-App Backend Contracts
173
+
174
+ Examples:
175
+
176
+ - one RPC request/response type consumed by Atlas and RAD
177
+ - one Edge Function request/response type consumed by Launchpad and Event Ops
178
+ - canonical event-bus envelope types used by multiple apps
179
+
180
+ Why:
181
+
182
+ When two or more apps call the same backend function, keeping the contract here
183
+ prevents drift. A backend breaking change should become one package version
184
+ change, not several unrelated app edits.
185
+
186
+ Promotion test:
187
+
188
+ - Is the backend endpoint used by more than one app today?
189
+ - Would a contract drift bug affect more than one app?
190
+ - Is the payload stable enough that changing it should require a package
191
+ version bump?
192
+
193
+ If the answer is yes, it belongs here.
194
+
195
+ #### Shared Status Vocabularies
196
+
197
+ Examples:
198
+
199
+ - canonical app slugs
200
+ - canonical org roles
201
+ - shared lifecycle statuses consumed across multiple apps
202
+ - shared event-bus event names
203
+
204
+ Why:
205
+
206
+ String vocabularies are high-risk drift points. If multiple apps compare the
207
+ same status string, the source of truth should be shared.
208
+
209
+ ### Belongs In The App
210
+
211
+ #### Feature View Models
212
+
213
+ Examples:
214
+
215
+ - RAD dashboard row models
216
+ - Atlas artist search result cards
217
+ - Launchpad event hierarchy screen state
218
+ - Event Ops table/filter state
219
+
220
+ Why:
221
+
222
+ These are presentation shapes. They change as the UI changes and should not
223
+ force package releases.
224
+
225
+ #### App-Specific Edge Function Contracts
226
+
227
+ Examples:
228
+
229
+ - `rad-get-event-edition-grid`
230
+ - `rad-get-artist-availability-context`
231
+ - `rad-capture-search-snapshot`
232
+ - RAD saved event edition view payloads
233
+
234
+ Why:
235
+
236
+ These are RAD workflow contracts. They include UI restoration state, snapshots,
237
+ and RAD-specific orchestration. They should stay in RAD until another app
238
+ actually consumes the same payload.
239
+
240
+ If Event Ops or Atlas later needs the exact same contract, promote the stable
241
+ request/response shape into this package and update both apps to import it.
242
+
243
+ #### Adapters And Runtime Normalizers
244
+
245
+ Examples:
246
+
247
+ - `adaptEventEditionGrid`
248
+ - `adaptSearchResults`
249
+ - `adaptArtistAvailabilityContext`
250
+ - local parsing of nullable dates for UI display
251
+ - `parseSearchFilters`
252
+ - `isSearchResultSet`
253
+
254
+ Why:
255
+
256
+ Adapters convert backend transport into app/domain/view models. That conversion
257
+ usually reflects app-specific UI decisions. Share only small generic helpers
258
+ when multiple apps need identical parsing behavior.
259
+
260
+ #### App-Specific Permission Mapping
261
+
262
+ Examples:
263
+
264
+ - Booking Engine maps `owner/admin` to local `admin`
265
+ - Booking Engine maps `member` to local `rep`
266
+ - RAD maps org roles to internal/client mode affordances
267
+
268
+ Why:
269
+
270
+ Core org roles are shared. Workflow permissions are app-specific. Keep the
271
+ canonical role type here, but keep local permission policy near the feature that
272
+ uses it unless the same policy is shared.
273
+
274
+ #### Persisted UI State And Snapshots
275
+
276
+ Examples:
277
+
278
+ - RAD saved search filter payloads
279
+ - RAD search snapshot result blobs
280
+ - RAD saved event edition grid snapshots
281
+ - dashboard state tokens
282
+
283
+ Why:
284
+
285
+ These are intentionally flexible JSON blobs for restoring app state. They are
286
+ not stable backend schema contracts and should not be versioned through the
287
+ shared package unless multiple apps must read/write the same blob format.
288
+
289
+ ### Decision Checklist
290
+
291
+ Before adding a type/helper to this package, answer:
292
+
293
+ 1. Is it sourced from EIN backend schema, auth, RLS, app registry, or a shared
294
+ backend endpoint?
295
+ 2. Is it used by at least two apps, or is it foundational enough that every app
296
+ should use the same implementation?
297
+ 3. Would duplicating it in apps create real drift or security risk?
298
+ 4. Is it stable enough to version with semver?
299
+ 5. Does it avoid app UI state, feature-specific view models, and one-off screen
300
+ behavior?
301
+
302
+ Add it here only when the answer is yes to the relevant shared-contract
303
+ questions. Otherwise, keep it local in the app and revisit when reuse appears.
304
+
305
+ ### Examples
306
+
307
+ | Item | Location | Reason |
308
+ | --- | --- | --- |
309
+ | `Database` generated Supabase type | Package | Every app should use the same DB schema contract. |
310
+ | `EIN_APP_SLUGS.rad` | Package | RLS/app policies require consistent slugs. |
311
+ | `CoreOrgRole` | Package | Org role meaning must be consistent across apps. |
312
+ | `schemaClient(supabase, "rad")` | Package | Shared typed helper for schema-scoped Supabase access. |
313
+ | `rad-get-event-edition-grid` response | RAD app | RAD-only workflow and UI grid payload today. |
314
+ | RAD saved search filters | RAD app | Persisted UI state blob, not a shared backend contract. |
315
+ | Booking Engine role-to-workflow mapping | Booking app | Local workflow interpretation of shared core role. |
316
+ | Event bus envelope used by all apps | Package | Cross-app backend integration contract. |
317
+ | ARTEMIS recommendation card view model | RAD app | Presentation model, not shared transport. |
318
+
319
+ ### Promotion Process
320
+
321
+ When a local app contract becomes shared:
322
+
323
+ 1. Move the stable request/response or vocabulary into this package.
324
+ 2. Export it from `src/index.ts`.
325
+ 3. Add README usage notes if the boundary is non-obvious.
326
+ 4. Bump package version:
327
+ - patch for regenerated/additive types
328
+ - minor for new shared contracts
329
+ - major for renamed/removed/breaking contracts
330
+ 5. Update all consuming apps to import from the package.
331
+ 6. Remove local duplicate types from app repos.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./app-context.js";
2
2
  export * from "./auth.js";
3
+ export * from "./json.js";
3
4
  export * from "./schema-client.js";
4
5
  export type { Constants, Database, Enums, Json, Tables, TablesInsert, TablesUpdate, } from "./generated/database.types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./app-context.js";
2
2
  export * from "./auth.js";
3
+ export * from "./json.js";
3
4
  export * from "./schema-client.js";
package/dist/json.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export type JsonRecord = Record<string, unknown>;
2
+ export declare function isJsonRecord(value: unknown): value is JsonRecord;
3
+ export declare function toJsonRecord(value: unknown): JsonRecord;
4
+ export declare function stringValue(value: unknown): string | undefined;
5
+ export declare function stringOrNull(value: unknown): string | null;
6
+ export declare function nullableStringValue(value: unknown): string | null | undefined;
7
+ export declare function numberValue(value: unknown): number | undefined;
8
+ export declare function numberOrNull(value: unknown): number | null;
9
+ export declare function booleanValue(value: unknown): boolean | undefined;
10
+ export declare function booleanOrNull(value: unknown): boolean | null;
11
+ export declare function booleanOrFalse(value: unknown): boolean;
12
+ export declare function stringArrayValue(value: unknown): string[] | undefined;
13
+ export declare function stringArrayOrEmpty(value: unknown): string[];
package/dist/json.js ADDED
@@ -0,0 +1,40 @@
1
+ export function isJsonRecord(value) {
2
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3
+ }
4
+ export function toJsonRecord(value) {
5
+ return isJsonRecord(value) ? value : {};
6
+ }
7
+ export function stringValue(value) {
8
+ return typeof value === "string" ? value : undefined;
9
+ }
10
+ export function stringOrNull(value) {
11
+ return stringValue(value) ?? null;
12
+ }
13
+ export function nullableStringValue(value) {
14
+ return value === null ? null : stringValue(value);
15
+ }
16
+ export function numberValue(value) {
17
+ return typeof value === "number" && Number.isFinite(value)
18
+ ? value
19
+ : undefined;
20
+ }
21
+ export function numberOrNull(value) {
22
+ return numberValue(value) ?? null;
23
+ }
24
+ export function booleanValue(value) {
25
+ return typeof value === "boolean" ? value : undefined;
26
+ }
27
+ export function booleanOrNull(value) {
28
+ return booleanValue(value) ?? null;
29
+ }
30
+ export function booleanOrFalse(value) {
31
+ return value === true;
32
+ }
33
+ export function stringArrayValue(value) {
34
+ return Array.isArray(value)
35
+ ? value.filter((item) => typeof item === "string")
36
+ : undefined;
37
+ }
38
+ export function stringArrayOrEmpty(value) {
39
+ return stringArrayValue(value) ?? [];
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rjromeoent/ein-supabase",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Shared Supabase types, app context, and contract helpers for EIN-connected apps.",
5
5
  "type": "module",
6
6
  "sideEffects": false,