@tinycloud/operations 0.5.0-beta.0 → 0.5.0-beta.1
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/cli-runtime.cjs +60 -45
- package/dist/cli-runtime.cjs.map +1 -1
- package/dist/cli-runtime.js +60 -45
- package/dist/cli-runtime.js.map +1 -1
- package/dist/index.cjs +60 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +60 -45
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5529,7 +5529,10 @@ async function importRequestBoundDelegation(context, input) {
|
|
|
5529
5529
|
delegation,
|
|
5530
5530
|
{ host }
|
|
5531
5531
|
);
|
|
5532
|
-
} catch {
|
|
5532
|
+
} catch (error) {
|
|
5533
|
+
if (typeof error === "object" && error !== null && "reason" in error && error.reason === "expired") {
|
|
5534
|
+
return expiredDelegation();
|
|
5535
|
+
}
|
|
5533
5536
|
return operationFailure(
|
|
5534
5537
|
"DELEGATION_REJECTED",
|
|
5535
5538
|
"The delegation was rejected by the TinyCloud runtime."
|
|
@@ -5547,55 +5550,67 @@ async function importRequestBoundDelegation(context, input) {
|
|
|
5547
5550
|
);
|
|
5548
5551
|
}
|
|
5549
5552
|
try {
|
|
5550
|
-
return await
|
|
5551
|
-
context.summary.profile
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
return {
|
|
5558
|
-
|
|
5559
|
-
|
|
5553
|
+
return await withProfileLock(context.summary.profile, async () => {
|
|
5554
|
+
const previousRecords = await readAdditionalDelegations(context.summary.profile);
|
|
5555
|
+
const result = await updateProfileStore(
|
|
5556
|
+
context.summary.profile,
|
|
5557
|
+
"additional-delegations",
|
|
5558
|
+
async (records) => {
|
|
5559
|
+
const state = await importState(context, input.requestId);
|
|
5560
|
+
if (!state.ok) return { records, result: state.result };
|
|
5561
|
+
if (state.sessionDid !== sessionDid || normalizeHost(state.host) !== normalizeHost(host)) {
|
|
5562
|
+
return {
|
|
5563
|
+
records,
|
|
5564
|
+
result: audienceMismatch(state.sessionDid, sessionDid)
|
|
5565
|
+
};
|
|
5566
|
+
}
|
|
5567
|
+
if (state.request.profile !== context.summary.profile || !samePrincipal(state.request.sessionDid, sessionDid) || normalizeHost(state.request.host) !== normalizeHost(host) || JSON.stringify(canonicalizeOperationCapabilities(state.request.requested, resolveSpace2)) !== JSON.stringify(canonicalizeOperationCapabilities(request.requested, resolveSpace2))) {
|
|
5568
|
+
return {
|
|
5569
|
+
records,
|
|
5570
|
+
result: operationFailure(
|
|
5571
|
+
"DELEGATION_ARTIFACT_INVALID",
|
|
5572
|
+
"The delegation does not reference a current stored request."
|
|
5573
|
+
)
|
|
5574
|
+
};
|
|
5575
|
+
}
|
|
5576
|
+
const record = {
|
|
5577
|
+
delegation: activated.delegation,
|
|
5578
|
+
permissions: activated.effectivePermissions,
|
|
5579
|
+
authorityRequest: {
|
|
5580
|
+
requestId: request.requestId,
|
|
5581
|
+
requested: request.requested
|
|
5582
|
+
}
|
|
5560
5583
|
};
|
|
5561
|
-
|
|
5562
|
-
|
|
5584
|
+
const position = records.findIndex((entry) => delegationCid(entry) === activated.cid);
|
|
5585
|
+
const alreadyPresent = position !== -1;
|
|
5586
|
+
const others = records.filter((entry) => delegationCid(entry) !== activated.cid);
|
|
5563
5587
|
return {
|
|
5564
|
-
records,
|
|
5565
|
-
result:
|
|
5566
|
-
"
|
|
5567
|
-
|
|
5568
|
-
|
|
5588
|
+
records: alreadyPresent ? [...others.slice(0, position), record, ...others.slice(position)] : [...records, record],
|
|
5589
|
+
result: {
|
|
5590
|
+
status: "ok",
|
|
5591
|
+
output: {
|
|
5592
|
+
cid: activated.cid,
|
|
5593
|
+
effectivePermissions,
|
|
5594
|
+
expiry: activated.expiry.toISOString(),
|
|
5595
|
+
audience: activated.audience,
|
|
5596
|
+
host: activated.host,
|
|
5597
|
+
activated: true,
|
|
5598
|
+
alreadyPresent
|
|
5599
|
+
}
|
|
5600
|
+
}
|
|
5569
5601
|
};
|
|
5570
5602
|
}
|
|
5571
|
-
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
const position = records.findIndex((entry) => delegationCid(entry) === activated.cid);
|
|
5580
|
-
const alreadyPresent = position !== -1;
|
|
5581
|
-
const others = records.filter((entry) => delegationCid(entry) !== activated.cid);
|
|
5582
|
-
return {
|
|
5583
|
-
records: alreadyPresent ? [...others.slice(0, position), record, ...others.slice(position)] : [...records, record],
|
|
5584
|
-
result: {
|
|
5585
|
-
status: "ok",
|
|
5586
|
-
output: {
|
|
5587
|
-
cid: activated.cid,
|
|
5588
|
-
effectivePermissions,
|
|
5589
|
-
expiry: activated.expiry.toISOString(),
|
|
5590
|
-
audience: activated.audience,
|
|
5591
|
-
host: activated.host,
|
|
5592
|
-
activated: true,
|
|
5593
|
-
alreadyPresent
|
|
5594
|
-
}
|
|
5595
|
-
}
|
|
5596
|
-
};
|
|
5603
|
+
);
|
|
5604
|
+
if (activated.expiry.getTime() <= Date.now()) {
|
|
5605
|
+
await updateProfileStore(
|
|
5606
|
+
context.summary.profile,
|
|
5607
|
+
"additional-delegations",
|
|
5608
|
+
() => ({ records: previousRecords, result: void 0 })
|
|
5609
|
+
);
|
|
5610
|
+
return expiredDelegation();
|
|
5597
5611
|
}
|
|
5598
|
-
|
|
5612
|
+
return result;
|
|
5613
|
+
});
|
|
5599
5614
|
} catch {
|
|
5600
5615
|
return internalImportFailure();
|
|
5601
5616
|
}
|