@byok-sdk/cloud-dataplane 0.10.1 → 0.10.2
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.js +50 -9
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +50 -9
- package/dist/runtime.js.map +1 -1
- package/dist/stores/devices.d.ts +17 -0
- package/package.json +4 -4
package/dist/runtime.js
CHANGED
|
@@ -804,6 +804,18 @@ function toRecord(row) {
|
|
|
804
804
|
};
|
|
805
805
|
}
|
|
806
806
|
var SELECT_COLUMNS = "tenant_id, device_id, product_id, device_name, device_public_key, proof_key_id, proof_key_epoch, revoked, machine_id, capabilities";
|
|
807
|
+
var DEVICE_STATE_DELETES = [
|
|
808
|
+
"DELETE FROM device_presence WHERE tenant_id = $1 AND device_id = ANY($2::text[])",
|
|
809
|
+
"DELETE FROM auth_nonce WHERE tenant_id = $1 AND device_id = ANY($2::text[])",
|
|
810
|
+
"DELETE FROM inbound_dedup WHERE tenant_id = $1 AND device_id = ANY($2::text[])",
|
|
811
|
+
"DELETE FROM device_assertion_replay WHERE tenant_id = $1 AND device_id = ANY($2::text[])"
|
|
812
|
+
];
|
|
813
|
+
async function deleteDeviceState(client, tenant, deviceIds) {
|
|
814
|
+
if (deviceIds.length === 0) return;
|
|
815
|
+
for (const statement of DEVICE_STATE_DELETES) {
|
|
816
|
+
await client.query(statement, [tenant, [...deviceIds]]);
|
|
817
|
+
}
|
|
818
|
+
}
|
|
807
819
|
async function rollback(client) {
|
|
808
820
|
try {
|
|
809
821
|
await client.query("ROLLBACK");
|
|
@@ -822,11 +834,16 @@ var PostgresDeviceDirectory = class {
|
|
|
822
834
|
try {
|
|
823
835
|
await client.query("BEGIN");
|
|
824
836
|
if (input.machineId !== void 0) {
|
|
825
|
-
await client.query(
|
|
826
|
-
`
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
[tenant, input.productId, input.machineId]
|
|
837
|
+
const superseded = await client.query(
|
|
838
|
+
`DELETE FROM device
|
|
839
|
+
WHERE tenant_id = $1 AND product_id = $2 AND machine_id = $3 AND device_id <> $4
|
|
840
|
+
RETURNING device_id`,
|
|
841
|
+
[tenant, input.productId, input.machineId, input.deviceId]
|
|
842
|
+
);
|
|
843
|
+
await deleteDeviceState(
|
|
844
|
+
client,
|
|
845
|
+
tenant,
|
|
846
|
+
superseded.rows.map((row) => row.device_id)
|
|
830
847
|
);
|
|
831
848
|
}
|
|
832
849
|
const result = await client.query(
|
|
@@ -873,11 +890,35 @@ var PostgresDeviceDirectory = class {
|
|
|
873
890
|
const row = result.rows[0];
|
|
874
891
|
return row === void 0 ? void 0 : toRecord(row);
|
|
875
892
|
}
|
|
893
|
+
/**
|
|
894
|
+
* Revocation removes the registration and the device-scoped state that only
|
|
895
|
+
* existed to serve it, in one transaction: a half-applied revoke that left
|
|
896
|
+
* live presence or an unspent challenge nonce behind would be state for a
|
|
897
|
+
* device the directory can no longer name.
|
|
898
|
+
*
|
|
899
|
+
* A no-op for a device this tenant does not own: revoking what you cannot
|
|
900
|
+
* address deletes nothing and reports nothing back.
|
|
901
|
+
*/
|
|
876
902
|
async revoke(tenant, deviceId) {
|
|
877
|
-
await this.#pool.
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
903
|
+
const client = await this.#pool.connect();
|
|
904
|
+
try {
|
|
905
|
+
await client.query("BEGIN");
|
|
906
|
+
const removed = await client.query(
|
|
907
|
+
"DELETE FROM device WHERE tenant_id = $1 AND device_id = $2 RETURNING device_id",
|
|
908
|
+
[tenant, deviceId]
|
|
909
|
+
);
|
|
910
|
+
await deleteDeviceState(
|
|
911
|
+
client,
|
|
912
|
+
tenant,
|
|
913
|
+
removed.rows.map((row) => row.device_id)
|
|
914
|
+
);
|
|
915
|
+
await client.query("COMMIT");
|
|
916
|
+
} catch (cause) {
|
|
917
|
+
await rollback(client);
|
|
918
|
+
throw cause;
|
|
919
|
+
} finally {
|
|
920
|
+
client.release();
|
|
921
|
+
}
|
|
881
922
|
}
|
|
882
923
|
async recordCapabilities(tenant, input) {
|
|
883
924
|
const result = await this.#pool.query(
|