@byok-sdk/cloud-dataplane 0.9.0 → 0.10.0

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/runtime.js CHANGED
@@ -799,10 +799,17 @@ function toRecord(row) {
799
799
  proofKeyId: row.proof_key_id,
800
800
  proofKeyEpoch: row.proof_key_epoch,
801
801
  revoked: row.revoked,
802
+ ...row.machine_id == null ? {} : { machineId: row.machine_id },
802
803
  ...row.capabilities == null ? {} : { capabilities: Object.freeze([...row.capabilities]) }
803
804
  };
804
805
  }
805
- var SELECT_COLUMNS = "tenant_id, device_id, product_id, device_name, device_public_key, proof_key_id, proof_key_epoch, revoked, capabilities";
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
+ async function rollback(client) {
808
+ try {
809
+ await client.query("ROLLBACK");
810
+ } catch {
811
+ }
812
+ }
806
813
  var PostgresDeviceDirectory = class {
807
814
  #pool;
808
815
  #clock;
@@ -811,32 +818,52 @@ var PostgresDeviceDirectory = class {
811
818
  this.#clock = clock;
812
819
  }
813
820
  async register(tenant, input) {
814
- const result = await this.#pool.query(
815
- `INSERT INTO device (
816
- tenant_id, device_id, product_id, device_name, device_public_key,
817
- proof_key_id, proof_key_epoch, revoked
818
- )
819
- VALUES ($1, $2, $3, $4, $5, $6, $7, false)
820
- ON CONFLICT (tenant_id, device_id) DO UPDATE
821
- SET product_id = EXCLUDED.product_id,
822
- device_name = EXCLUDED.device_name,
823
- device_public_key = EXCLUDED.device_public_key,
824
- proof_key_id = EXCLUDED.proof_key_id,
825
- proof_key_epoch = EXCLUDED.proof_key_epoch,
826
- revoked = false,
827
- capabilities = NULL
828
- RETURNING ${SELECT_COLUMNS}`,
829
- [
830
- tenant,
831
- input.deviceId,
832
- input.productId,
833
- input.deviceName,
834
- input.devicePublicKey,
835
- input.proofKeyId,
836
- input.proofKeyEpoch
837
- ]
838
- );
839
- return toRecord(result.rows[0]);
821
+ const client = await this.#pool.connect();
822
+ try {
823
+ await client.query("BEGIN");
824
+ if (input.machineId !== void 0) {
825
+ await client.query(
826
+ `UPDATE device
827
+ SET revoked = true
828
+ WHERE tenant_id = $1 AND product_id = $2 AND machine_id = $3 AND NOT revoked`,
829
+ [tenant, input.productId, input.machineId]
830
+ );
831
+ }
832
+ const result = await client.query(
833
+ `INSERT INTO device (
834
+ tenant_id, device_id, product_id, device_name, device_public_key,
835
+ proof_key_id, proof_key_epoch, revoked, machine_id
836
+ )
837
+ VALUES ($1, $2, $3, $4, $5, $6, $7, false, $8)
838
+ ON CONFLICT (tenant_id, device_id) DO UPDATE
839
+ SET product_id = EXCLUDED.product_id,
840
+ device_name = EXCLUDED.device_name,
841
+ device_public_key = EXCLUDED.device_public_key,
842
+ proof_key_id = EXCLUDED.proof_key_id,
843
+ proof_key_epoch = EXCLUDED.proof_key_epoch,
844
+ revoked = false,
845
+ machine_id = EXCLUDED.machine_id,
846
+ capabilities = NULL
847
+ RETURNING ${SELECT_COLUMNS}`,
848
+ [
849
+ tenant,
850
+ input.deviceId,
851
+ input.productId,
852
+ input.deviceName,
853
+ input.devicePublicKey,
854
+ input.proofKeyId,
855
+ input.proofKeyEpoch,
856
+ input.machineId ?? null
857
+ ]
858
+ );
859
+ await client.query("COMMIT");
860
+ return toRecord(result.rows[0]);
861
+ } catch (cause) {
862
+ await rollback(client);
863
+ throw cause;
864
+ } finally {
865
+ client.release();
866
+ }
840
867
  }
841
868
  async get(tenant, deviceId) {
842
869
  const result = await this.#pool.query(
@@ -2079,7 +2106,7 @@ var PostgresAgentMemoryProjectionStore = class {
2079
2106
  }
2080
2107
  });
2081
2108
  } catch (cause) {
2082
- await rollback(client);
2109
+ await rollback2(client);
2083
2110
  throw cause;
2084
2111
  } finally {
2085
2112
  client.release();
@@ -2116,7 +2143,7 @@ var PostgresAgentMemoryProjectionStore = class {
2116
2143
  await client.query("COMMIT");
2117
2144
  return AgentMemoryProjectionEraseResultSchema.parse({ nextWriterEpoch });
2118
2145
  } catch (cause) {
2119
- await rollback(client);
2146
+ await rollback2(client);
2120
2147
  throw cause;
2121
2148
  } finally {
2122
2149
  client.release();
@@ -2253,7 +2280,7 @@ function toBase64(bytes) {
2253
2280
  function toBase64Url(bytes) {
2254
2281
  return toBase64(bytes).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/u, "");
2255
2282
  }
2256
- async function rollback(client) {
2283
+ async function rollback2(client) {
2257
2284
  try {
2258
2285
  await client.query("ROLLBACK");
2259
2286
  } catch {