@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.
package/dist/index.d.ts CHANGED
@@ -173,4 +173,45 @@ declare namespace schemas {
173
173
  export { schemas_acceptInvitationSchema as acceptInvitationSchema, schemas_addMemberRoleSchema as addMemberRoleSchema, schemas_createInvitationsSchema as createInvitationsSchema, schemas_createRoleSchema as createRoleSchema, schemas_createWorkspaceSchema as createWorkspaceSchema, schemas_setRolePermissionsSchema as setRolePermissionsSchema, schemas_updateRoleSchema as updateRoleSchema, schemas_updateSettingsSchema as updateSettingsSchema, schemas_updateWorkspaceSchema as updateWorkspaceSchema };
174
174
  }
175
175
 
176
- export { EVENT_KEYS, IInvitation, type IInvitationDTO, IMember, type IMemberDTO, IRole, type IRoleDTO, IWorkspace, type IWorkspaceDTO, IWorkspaceSettings, type IWorkspaceSettingsDTO, type IWorkspacesConfig, MESSAGE_KEYS, type WorkspacesEventKey, type WorkspacesMessageKey, WorkspacesModule, schemas, toInvitationDTO, toMemberDTO, toRoleDTO, toSettingsDTO, toWorkspaceDTO };
176
+ interface IImportWorkspace {
177
+ id?: string;
178
+ name: string;
179
+ slug: string;
180
+ ownerId: string;
181
+ type?: string;
182
+ plan?: string;
183
+ description?: string | null;
184
+ settings?: Record<string, unknown>;
185
+ isPersonal?: boolean;
186
+ motto?: string | null;
187
+ phone?: string | null;
188
+ businessType?: string | null;
189
+ address?: Record<string, unknown>;
190
+ createdAt?: Date;
191
+ archivedAt?: Date | null;
192
+ archivedBy?: string | null;
193
+ }
194
+ declare function importWorkspace(store: IStoreAdapter, ws: IImportWorkspace): Promise<{
195
+ id: string;
196
+ }>;
197
+ interface IImportRole {
198
+ id?: string;
199
+ name: string;
200
+ workspaceId: string;
201
+ description?: string | null;
202
+ active?: boolean;
203
+ createdAt?: Date;
204
+ }
205
+ declare function importRole(store: IStoreAdapter, role: IImportRole): Promise<{
206
+ id: string;
207
+ }>;
208
+ interface IImportMembership {
209
+ userId: string;
210
+ workspaceId: string;
211
+ roleId: string;
212
+ confirmed?: boolean;
213
+ createdAt?: Date;
214
+ }
215
+ declare function importMembership(store: IStoreAdapter, m: IImportMembership): Promise<void>;
216
+
217
+ export { EVENT_KEYS, type IImportMembership, type IImportRole, type IImportWorkspace, IInvitation, type IInvitationDTO, IMember, type IMemberDTO, IRole, type IRoleDTO, IWorkspace, type IWorkspaceDTO, IWorkspaceSettings, type IWorkspaceSettingsDTO, type IWorkspacesConfig, MESSAGE_KEYS, type WorkspacesEventKey, type WorkspacesMessageKey, WorkspacesModule, importMembership, importRole, importWorkspace, schemas, toInvitationDTO, toMemberDTO, toRoleDTO, toSettingsDTO, toWorkspaceDTO };
package/dist/index.js CHANGED
@@ -1385,10 +1385,88 @@ var requireWorkspace = async (ctx, next) => {
1385
1385
  }
1386
1386
  return next();
1387
1387
  };
1388
+
1389
+ // src/migrate.ts
1390
+ async function importWorkspace(store, ws) {
1391
+ const cols = [];
1392
+ const vals = [];
1393
+ const placeholders = [];
1394
+ const add = (col, val) => {
1395
+ cols.push(col);
1396
+ vals.push(val);
1397
+ placeholders.push(`$${vals.length}`);
1398
+ };
1399
+ if (ws.id !== void 0) add("id", ws.id);
1400
+ add("name", ws.name);
1401
+ add("slug", ws.slug);
1402
+ add("owner_id", ws.ownerId);
1403
+ if (ws.type !== void 0) add("type", ws.type);
1404
+ if (ws.plan !== void 0) add("plan", ws.plan);
1405
+ if (ws.description !== void 0) add("description", ws.description);
1406
+ if (ws.settings !== void 0) add("settings", JSON.stringify(ws.settings));
1407
+ if (ws.isPersonal !== void 0) add("is_personal", ws.isPersonal);
1408
+ if (ws.motto !== void 0) add("motto", ws.motto);
1409
+ if (ws.phone !== void 0) add("phone", ws.phone);
1410
+ if (ws.businessType !== void 0) add("business_type", ws.businessType);
1411
+ if (ws.address !== void 0) add("address", JSON.stringify(ws.address));
1412
+ if (ws.createdAt !== void 0) add("created_at", ws.createdAt);
1413
+ if (ws.archivedAt !== void 0) add("archived_at", ws.archivedAt);
1414
+ if (ws.archivedBy !== void 0) add("archived_by", ws.archivedBy);
1415
+ const [row] = await store.query(
1416
+ `INSERT INTO fonderie_workspaces (${cols.join(", ")})
1417
+ VALUES (${placeholders.join(", ")})
1418
+ RETURNING id`,
1419
+ vals
1420
+ );
1421
+ if (!row) throw new Error("[workspaces] importWorkspace: insert returned no row");
1422
+ return row;
1423
+ }
1424
+ async function importRole(store, role) {
1425
+ const cols = [];
1426
+ const vals = [];
1427
+ const placeholders = [];
1428
+ const add = (col, val) => {
1429
+ cols.push(col);
1430
+ vals.push(val);
1431
+ placeholders.push(`$${vals.length}`);
1432
+ };
1433
+ if (role.id !== void 0) add("id", role.id);
1434
+ add("name", role.name);
1435
+ add("workspace_id", role.workspaceId);
1436
+ if (role.description !== void 0) add("description", role.description);
1437
+ if (role.active !== void 0) add("active", role.active);
1438
+ if (role.createdAt !== void 0) add("created_at", role.createdAt);
1439
+ const [row] = await store.query(
1440
+ `INSERT INTO fonderie_roles (${cols.join(", ")})
1441
+ VALUES (${placeholders.join(", ")})
1442
+ RETURNING id`,
1443
+ vals
1444
+ );
1445
+ if (!row) throw new Error("[workspaces] importRole: insert returned no row");
1446
+ return row;
1447
+ }
1448
+ async function importMembership(store, m) {
1449
+ const cols = ["user_id", "workspace_id", "role_id", "confirmed"];
1450
+ const vals = [m.userId, m.workspaceId, m.roleId, m.confirmed ?? true];
1451
+ if (m.createdAt !== void 0) {
1452
+ cols.push("created_at");
1453
+ vals.push(m.createdAt);
1454
+ }
1455
+ const placeholders = vals.map((_, i) => `$${i + 1}`);
1456
+ await store.query(
1457
+ `INSERT INTO fonderie_role_user_workspaces (${cols.join(", ")})
1458
+ VALUES (${placeholders.join(", ")})
1459
+ ON CONFLICT (user_id, workspace_id, role_id) DO NOTHING`,
1460
+ vals
1461
+ );
1462
+ }
1388
1463
  export {
1389
1464
  EVENT_KEYS,
1390
1465
  MESSAGE_KEYS,
1391
1466
  WorkspacesModule,
1467
+ importMembership,
1468
+ importRole,
1469
+ importWorkspace,
1392
1470
  requireWorkspace,
1393
1471
  schemas_exports as schemas,
1394
1472
  toInvitationDTO,