@balena/pinejs 18.2.8 → 18.2.9

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.
@@ -1192,18 +1192,21 @@ const memoizedGetConstrainedModel = (
1192
1192
  getBoundConstrainedMemoizer(abstractSqlModel)(permissionsLookup, vocabulary);
1193
1193
 
1194
1194
  const getCheckPasswordQuery = _.once(() =>
1195
- sbvrUtils.api.Auth.prepare<{ username: string }, 'user'>({
1196
- resource: 'user',
1197
- passthrough: {
1198
- req: rootRead,
1199
- },
1200
- id: {
1201
- username: { '@': 'username' },
1202
- },
1203
- options: {
1204
- $select: ['id', 'actor', 'password'],
1195
+ sbvrUtils.api.Auth.prepare(
1196
+ {
1197
+ resource: 'user',
1198
+ passthrough: {
1199
+ req: rootRead,
1200
+ },
1201
+ id: {
1202
+ username: { '@': 'username' },
1203
+ },
1204
+ options: {
1205
+ $select: ['id', 'actor', 'password'],
1206
+ },
1205
1207
  },
1206
- }),
1208
+ { username: ['string'] },
1209
+ ),
1207
1210
  );
1208
1211
  export const checkPassword = async (
1209
1212
  username: string,
@@ -1220,17 +1223,15 @@ export const checkPassword = async (
1220
1223
  if (user == null) {
1221
1224
  throw new Error('User not found');
1222
1225
  }
1223
- const hash = user.password;
1224
- const userId = user.id;
1225
- const actorId = user.actor;
1226
- const res = await sbvrUtils.sbvrTypes.Hashed.compare(password, hash);
1226
+ const res = await sbvrUtils.sbvrTypes.Hashed.compare(password, user.password);
1227
1227
  if (!res) {
1228
1228
  throw new Error('Passwords do not match');
1229
1229
  }
1230
+ const userId = user.id;
1230
1231
  const permissions = await getUserPermissions(userId);
1231
1232
  return {
1232
1233
  id: userId,
1233
- actor: actorId,
1234
+ actor: user.actor.__id,
1234
1235
  username,
1235
1236
  permissions,
1236
1237
  };
@@ -1238,58 +1239,60 @@ export const checkPassword = async (
1238
1239
 
1239
1240
  const $getUserPermissions = (() => {
1240
1241
  const getUserPermissionsQuery = _.once(() =>
1241
- sbvrUtils.api.Auth.prepare<{ userId: number }, 'permission'>({
1242
- resource: 'permission',
1243
- passthrough: {
1244
- req: rootRead,
1245
- },
1246
- options: {
1247
- $select: 'name',
1248
- $filter: {
1249
- $or: {
1250
- is_of__user: {
1251
- $any: {
1252
- $alias: 'uhp',
1253
- $expr: {
1254
- uhp: { user: { '@': 'userId' } },
1255
- $or: [
1256
- {
1257
- uhp: { expiry_date: null },
1258
- },
1259
- {
1260
- uhp: {
1261
- expiry_date: { $gt: { $now: null } },
1242
+ sbvrUtils.api.Auth.prepare(
1243
+ {
1244
+ resource: 'permission',
1245
+ passthrough: {
1246
+ req: rootRead,
1247
+ },
1248
+ options: {
1249
+ $select: 'name',
1250
+ $filter: {
1251
+ $or: {
1252
+ is_of__user: {
1253
+ $any: {
1254
+ $alias: 'uhp',
1255
+ $expr: {
1256
+ uhp: { user: { '@': 'userId' } },
1257
+ $or: [
1258
+ {
1259
+ uhp: { expiry_date: null },
1262
1260
  },
1263
- },
1264
- ],
1261
+ {
1262
+ uhp: {
1263
+ expiry_date: { $gt: { $now: null } },
1264
+ },
1265
+ },
1266
+ ],
1267
+ },
1265
1268
  },
1266
1269
  },
1267
- },
1268
- is_of__role: {
1269
- $any: {
1270
- $alias: 'rhp',
1271
- $expr: {
1272
- rhp: {
1273
- role: {
1274
- $any: {
1275
- $alias: 'r',
1276
- $expr: {
1277
- r: {
1278
- is_of__user: {
1279
- $any: {
1280
- $alias: 'uhr',
1281
- $expr: {
1282
- uhr: { user: { '@': 'userId' } },
1283
- $or: [
1284
- {
1285
- uhr: { expiry_date: null },
1286
- },
1287
- {
1288
- uhr: {
1289
- expiry_date: { $gt: { $now: null } },
1270
+ is_of__role: {
1271
+ $any: {
1272
+ $alias: 'rhp',
1273
+ $expr: {
1274
+ rhp: {
1275
+ role: {
1276
+ $any: {
1277
+ $alias: 'r',
1278
+ $expr: {
1279
+ r: {
1280
+ is_of__user: {
1281
+ $any: {
1282
+ $alias: 'uhr',
1283
+ $expr: {
1284
+ uhr: { user: { '@': 'userId' } },
1285
+ $or: [
1286
+ {
1287
+ uhr: { expiry_date: null },
1290
1288
  },
1291
- },
1292
- ],
1289
+ {
1290
+ uhr: {
1291
+ expiry_date: { $gt: { $now: null } },
1292
+ },
1293
+ },
1294
+ ],
1295
+ },
1293
1296
  },
1294
1297
  },
1295
1298
  },
@@ -1302,13 +1305,14 @@ const $getUserPermissions = (() => {
1302
1305
  },
1303
1306
  },
1304
1307
  },
1305
- },
1306
- // We orderby to increase the hit rate for the `_checkPermissions` memoisation
1307
- $orderby: {
1308
- name: 'asc',
1308
+ // We orderby to increase the hit rate for the `_checkPermissions` memoisation
1309
+ $orderby: {
1310
+ name: 'asc',
1311
+ },
1309
1312
  },
1310
1313
  },
1311
- }),
1314
+ { userId: ['number'] },
1315
+ ),
1312
1316
  );
1313
1317
  return env.createCache(
1314
1318
  'userPermissions',
@@ -1349,74 +1353,76 @@ export const getUserPermissions = async (
1349
1353
 
1350
1354
  const $getApiKeyPermissions = (() => {
1351
1355
  const getApiKeyPermissionsQuery = _.once(() =>
1352
- sbvrUtils.api.Auth.prepare<{ apiKey: string }, 'permission'>({
1353
- resource: 'permission',
1354
- passthrough: {
1355
- req: rootRead,
1356
- },
1357
- options: {
1358
- $select: 'name',
1359
- $filter: {
1360
- $or: {
1361
- is_of__api_key: {
1362
- $any: {
1363
- $alias: 'khp',
1364
- $expr: {
1365
- khp: {
1366
- api_key: {
1367
- $any: {
1368
- $alias: 'k',
1369
- $expr: {
1370
- k: { key: { '@': 'apiKey' } },
1371
- $or: [
1372
- {
1373
- k: { expiry_date: null },
1374
- },
1375
- {
1376
- k: {
1377
- expiry_date: { $gt: { $now: null } },
1356
+ sbvrUtils.api.Auth.prepare(
1357
+ {
1358
+ resource: 'permission',
1359
+ passthrough: {
1360
+ req: rootRead,
1361
+ },
1362
+ options: {
1363
+ $select: 'name',
1364
+ $filter: {
1365
+ $or: {
1366
+ is_of__api_key: {
1367
+ $any: {
1368
+ $alias: 'khp',
1369
+ $expr: {
1370
+ khp: {
1371
+ api_key: {
1372
+ $any: {
1373
+ $alias: 'k',
1374
+ $expr: {
1375
+ k: { key: { '@': 'apiKey' } },
1376
+ $or: [
1377
+ {
1378
+ k: { expiry_date: null },
1378
1379
  },
1379
- },
1380
- ],
1380
+ {
1381
+ k: {
1382
+ expiry_date: { $gt: { $now: null } },
1383
+ },
1384
+ },
1385
+ ],
1386
+ },
1381
1387
  },
1382
1388
  },
1383
1389
  },
1384
1390
  },
1385
1391
  },
1386
1392
  },
1387
- },
1388
- is_of__role: {
1389
- $any: {
1390
- $alias: 'rhp',
1391
- $expr: {
1392
- rhp: {
1393
- role: {
1394
- $any: {
1395
- $alias: 'r',
1396
- $expr: {
1397
- r: {
1398
- is_of__api_key: {
1399
- $any: {
1400
- $alias: 'khr',
1401
- $expr: {
1402
- khr: {
1403
- api_key: {
1404
- $any: {
1405
- $alias: 'k',
1406
- $expr: {
1407
- k: { key: { '@': 'apiKey' } },
1408
- $or: [
1409
- {
1410
- k: { expiry_date: null },
1411
- },
1412
- {
1413
- k: {
1414
- expiry_date: {
1415
- $gt: { $now: null },
1393
+ is_of__role: {
1394
+ $any: {
1395
+ $alias: 'rhp',
1396
+ $expr: {
1397
+ rhp: {
1398
+ role: {
1399
+ $any: {
1400
+ $alias: 'r',
1401
+ $expr: {
1402
+ r: {
1403
+ is_of__api_key: {
1404
+ $any: {
1405
+ $alias: 'khr',
1406
+ $expr: {
1407
+ khr: {
1408
+ api_key: {
1409
+ $any: {
1410
+ $alias: 'k',
1411
+ $expr: {
1412
+ k: { key: { '@': 'apiKey' } },
1413
+ $or: [
1414
+ {
1415
+ k: { expiry_date: null },
1416
+ },
1417
+ {
1418
+ k: {
1419
+ expiry_date: {
1420
+ $gt: { $now: null },
1421
+ },
1416
1422
  },
1417
1423
  },
1418
- },
1419
- ],
1424
+ ],
1425
+ },
1420
1426
  },
1421
1427
  },
1422
1428
  },
@@ -1433,13 +1439,14 @@ const $getApiKeyPermissions = (() => {
1433
1439
  },
1434
1440
  },
1435
1441
  },
1436
- },
1437
- // We orderby to increase the hit rate for the `_checkPermissions` memoisation
1438
- $orderby: {
1439
- name: 'asc',
1442
+ // We orderby to increase the hit rate for the `_checkPermissions` memoisation
1443
+ $orderby: {
1444
+ name: 'asc',
1445
+ },
1440
1446
  },
1441
1447
  },
1442
- }),
1448
+ { apiKey: ['string'] },
1449
+ ),
1443
1450
  );
1444
1451
  return env.createCache(
1445
1452
  'apiKeyPermissions',
@@ -1477,24 +1484,27 @@ export const getApiKeyPermissions = async (
1477
1484
 
1478
1485
  const getApiKeyActorId = (() => {
1479
1486
  const getApiKeyActorIdQuery = _.once(() =>
1480
- sbvrUtils.api.Auth.prepare<{ apiKey: string }, 'api_key'>({
1481
- resource: 'api_key',
1482
- passthrough: {
1483
- req: rootRead,
1484
- },
1485
- id: {
1486
- key: { '@': 'apiKey' },
1487
- },
1488
- options: {
1489
- $select: 'is_of__actor',
1490
- $filter: {
1491
- $or: [
1492
- { expiry_date: null },
1493
- { expiry_date: { $gt: { $now: null } } },
1494
- ],
1487
+ sbvrUtils.api.Auth.prepare(
1488
+ {
1489
+ resource: 'api_key',
1490
+ passthrough: {
1491
+ req: rootRead,
1492
+ },
1493
+ id: {
1494
+ key: { '@': 'apiKey' },
1495
+ },
1496
+ options: {
1497
+ $select: 'is_of__actor',
1498
+ $filter: {
1499
+ $or: [
1500
+ { expiry_date: null },
1501
+ { expiry_date: { $gt: { $now: null } } },
1502
+ ],
1503
+ },
1495
1504
  },
1496
1505
  },
1497
- }),
1506
+ { apiKey: ['string'] },
1507
+ ),
1498
1508
  );
1499
1509
  const apiActorPermissionError = new PermissionError();
1500
1510
  return env.createCache(
@@ -1516,7 +1526,7 @@ const getApiKeyActorId = (() => {
1516
1526
  if (apiKeyActorID == null) {
1517
1527
  throw new Error('API key is not linked to a actor?!');
1518
1528
  }
1519
- return apiKeyActorID as number;
1529
+ return apiKeyActorID;
1520
1530
  },
1521
1531
  {
1522
1532
  promise: true,