@fonderie/workspaces 6.0.2 → 6.0.3

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.cjs CHANGED
@@ -1255,6 +1255,18 @@ async function cancelInvitation(invitationId, workspaceId, store) {
1255
1255
  [invitationId, workspaceId]
1256
1256
  );
1257
1257
  }
1258
+ async function assertRoleAssignable(roleId, workspaceId, store) {
1259
+ const rows = await store.query(
1260
+ `SELECT id FROM fonderie_roles
1261
+ WHERE id = $1
1262
+ AND (
1263
+ (workspace_id = $2 AND is_system = false)
1264
+ OR (is_system = true AND name = 'GUEST')
1265
+ )`,
1266
+ [roleId, workspaceId]
1267
+ );
1268
+ if (rows.length === 0) throw new Error("Invitation role is no longer assignable");
1269
+ }
1258
1270
  async function acceptInvitationByPin(opts, store) {
1259
1271
  const [inv] = await store.query(
1260
1272
  `SELECT id, workspace_id AS "workspaceId", role_id AS "roleId", expires_at AS "expiresAt"
@@ -1264,6 +1276,7 @@ async function acceptInvitationByPin(opts, store) {
1264
1276
  );
1265
1277
  if (!inv) throw new Error("Invalid PIN");
1266
1278
  if (/* @__PURE__ */ new Date() > new Date(inv.expiresAt)) throw new Error("Invitation expired");
1279
+ await assertRoleAssignable(inv.roleId, inv.workspaceId, store);
1267
1280
  await store.transaction(async (tx) => {
1268
1281
  await Promise.all([
1269
1282
  tx.query(
@@ -1289,6 +1302,7 @@ async function acceptInvitationByToken(token, userId, store) {
1289
1302
  );
1290
1303
  if (!inv) throw new Error("Invalid token");
1291
1304
  if (/* @__PURE__ */ new Date() > new Date(inv.expiresAt)) throw new Error("Invitation expired");
1305
+ await assertRoleAssignable(inv.roleId, inv.workspaceId, store);
1292
1306
  await store.transaction(async (tx) => {
1293
1307
  await Promise.all([
1294
1308
  tx.query(