@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.
- package/.pinejs-cache.json +1 -1
- package/.versionbot/CHANGELOG.yml +15 -1
- package/CHANGELOG.md +5 -0
- package/VERSION +1 -1
- package/out/sbvr-api/permissions.js +7 -9
- package/out/sbvr-api/permissions.js.map +1 -1
- package/package.json +2 -2
- package/src/sbvr-api/permissions.ts +160 -150
@@ -1192,18 +1192,21 @@ const memoizedGetConstrainedModel = (
|
|
1192
1192
|
getBoundConstrainedMemoizer(abstractSqlModel)(permissionsLookup, vocabulary);
|
1193
1193
|
|
1194
1194
|
const getCheckPasswordQuery = _.once(() =>
|
1195
|
-
sbvrUtils.api.Auth.prepare
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
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
|
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:
|
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
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
$
|
1250
|
-
|
1251
|
-
|
1252
|
-
$
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
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
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
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
|
-
|
1307
|
-
|
1308
|
-
|
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
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
$
|
1361
|
-
|
1362
|
-
|
1363
|
-
$
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
$
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
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
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
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
|
-
|
1438
|
-
|
1439
|
-
|
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
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
$
|
1492
|
-
|
1493
|
-
|
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
|
1529
|
+
return apiKeyActorID;
|
1520
1530
|
},
|
1521
1531
|
{
|
1522
1532
|
promise: true,
|