@fonderie/workspaces 2.1.0 → 4.0.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.
@@ -162,4 +162,46 @@ function withWorkspace(store: IStoreAdapter): Middleware
162
162
  function requireWorkspace(ctx: IFonderieContext, next: () => Promise<Response>): Promise<Response>
163
163
 
164
164
  namespace schemas — exports: acceptInvitationSchema, addMemberRoleSchema, createInvitationsSchema, createRoleSchema, createWorkspaceSchema, setRolePermissionsSchema, updateRoleSchema, updateSettingsSchema, updateWorkspaceSchema
165
+
166
+ function importWorkspace(store: IStoreAdapter, ws: IImportWorkspace): Promise<{ id: string; }>
167
+
168
+ function importRole(store: IStoreAdapter, role: IImportRole): Promise<{ id: string; }>
169
+
170
+ function importMembership(store: IStoreAdapter, m: IImportMembership): Promise<void>
171
+
172
+ interface IImportWorkspace {
173
+ id?: string;
174
+ name: string;
175
+ slug: string;
176
+ ownerId: string;
177
+ type?: string;
178
+ plan?: string;
179
+ description?: string | null;
180
+ settings?: Record<string, unknown>;
181
+ isPersonal?: boolean;
182
+ motto?: string | null;
183
+ phone?: string | null;
184
+ businessType?: string | null;
185
+ address?: Record<string, unknown>;
186
+ createdAt?: Date;
187
+ archivedAt?: Date | null;
188
+ archivedBy?: string | null;
189
+ }
190
+
191
+ interface IImportRole {
192
+ id?: string;
193
+ name: string;
194
+ workspaceId: string;
195
+ description?: string | null;
196
+ active?: boolean;
197
+ createdAt?: Date;
198
+ }
199
+
200
+ interface IImportMembership {
201
+ userId: string;
202
+ workspaceId: string;
203
+ roleId: string;
204
+ confirmed?: boolean;
205
+ createdAt?: Date;
206
+ }
165
207
  ```
package/dist/index.cjs CHANGED
@@ -23,6 +23,9 @@ __export(index_exports, {
23
23
  EVENT_KEYS: () => EVENT_KEYS,
24
24
  MESSAGE_KEYS: () => MESSAGE_KEYS,
25
25
  WorkspacesModule: () => WorkspacesModule,
26
+ importMembership: () => importMembership,
27
+ importRole: () => importRole,
28
+ importWorkspace: () => importWorkspace,
26
29
  requireWorkspace: () => requireWorkspace,
27
30
  schemas: () => schemas_exports,
28
31
  toInvitationDTO: () => toInvitationDTO,
@@ -1415,11 +1418,89 @@ var requireWorkspace = async (ctx, next) => {
1415
1418
  }
1416
1419
  return next();
1417
1420
  };
1421
+
1422
+ // src/migrate.ts
1423
+ async function importWorkspace(store, ws) {
1424
+ const cols = [];
1425
+ const vals = [];
1426
+ const placeholders = [];
1427
+ const add = (col, val) => {
1428
+ cols.push(col);
1429
+ vals.push(val);
1430
+ placeholders.push(`$${vals.length}`);
1431
+ };
1432
+ if (ws.id !== void 0) add("id", ws.id);
1433
+ add("name", ws.name);
1434
+ add("slug", ws.slug);
1435
+ add("owner_id", ws.ownerId);
1436
+ if (ws.type !== void 0) add("type", ws.type);
1437
+ if (ws.plan !== void 0) add("plan", ws.plan);
1438
+ if (ws.description !== void 0) add("description", ws.description);
1439
+ if (ws.settings !== void 0) add("settings", JSON.stringify(ws.settings));
1440
+ if (ws.isPersonal !== void 0) add("is_personal", ws.isPersonal);
1441
+ if (ws.motto !== void 0) add("motto", ws.motto);
1442
+ if (ws.phone !== void 0) add("phone", ws.phone);
1443
+ if (ws.businessType !== void 0) add("business_type", ws.businessType);
1444
+ if (ws.address !== void 0) add("address", JSON.stringify(ws.address));
1445
+ if (ws.createdAt !== void 0) add("created_at", ws.createdAt);
1446
+ if (ws.archivedAt !== void 0) add("archived_at", ws.archivedAt);
1447
+ if (ws.archivedBy !== void 0) add("archived_by", ws.archivedBy);
1448
+ const [row] = await store.query(
1449
+ `INSERT INTO fonderie_workspaces (${cols.join(", ")})
1450
+ VALUES (${placeholders.join(", ")})
1451
+ RETURNING id`,
1452
+ vals
1453
+ );
1454
+ if (!row) throw new Error("[workspaces] importWorkspace: insert returned no row");
1455
+ return row;
1456
+ }
1457
+ async function importRole(store, role) {
1458
+ const cols = [];
1459
+ const vals = [];
1460
+ const placeholders = [];
1461
+ const add = (col, val) => {
1462
+ cols.push(col);
1463
+ vals.push(val);
1464
+ placeholders.push(`$${vals.length}`);
1465
+ };
1466
+ if (role.id !== void 0) add("id", role.id);
1467
+ add("name", role.name);
1468
+ add("workspace_id", role.workspaceId);
1469
+ if (role.description !== void 0) add("description", role.description);
1470
+ if (role.active !== void 0) add("active", role.active);
1471
+ if (role.createdAt !== void 0) add("created_at", role.createdAt);
1472
+ const [row] = await store.query(
1473
+ `INSERT INTO fonderie_roles (${cols.join(", ")})
1474
+ VALUES (${placeholders.join(", ")})
1475
+ RETURNING id`,
1476
+ vals
1477
+ );
1478
+ if (!row) throw new Error("[workspaces] importRole: insert returned no row");
1479
+ return row;
1480
+ }
1481
+ async function importMembership(store, m) {
1482
+ const cols = ["user_id", "workspace_id", "role_id", "confirmed"];
1483
+ const vals = [m.userId, m.workspaceId, m.roleId, m.confirmed ?? true];
1484
+ if (m.createdAt !== void 0) {
1485
+ cols.push("created_at");
1486
+ vals.push(m.createdAt);
1487
+ }
1488
+ const placeholders = vals.map((_, i) => `$${i + 1}`);
1489
+ await store.query(
1490
+ `INSERT INTO fonderie_role_user_workspaces (${cols.join(", ")})
1491
+ VALUES (${placeholders.join(", ")})
1492
+ ON CONFLICT (user_id, workspace_id, role_id) DO NOTHING`,
1493
+ vals
1494
+ );
1495
+ }
1418
1496
  // Annotate the CommonJS export names for ESM import in node:
1419
1497
  0 && (module.exports = {
1420
1498
  EVENT_KEYS,
1421
1499
  MESSAGE_KEYS,
1422
1500
  WorkspacesModule,
1501
+ importMembership,
1502
+ importRole,
1503
+ importWorkspace,
1423
1504
  requireWorkspace,
1424
1505
  schemas,
1425
1506
  toInvitationDTO,