@pantechdynamic/sdk 0.1.0 → 0.2.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/index.js CHANGED
@@ -86,6 +86,18 @@ var OrderFailedError = class extends PantechError {
86
86
  this.order = order;
87
87
  }
88
88
  };
89
+ var CloudFailedError = class extends PantechError {
90
+ name = "CloudFailedError";
91
+ /** `connection` or `scan`. */
92
+ kind;
93
+ /** The failed connection or scan, as the API returned it. */
94
+ resource;
95
+ constructor(message, kind, resource, init = {}) {
96
+ super(message, init);
97
+ this.kind = kind;
98
+ this.resource = resource;
99
+ }
100
+ };
89
101
  var WaitTimeoutError = class extends PantechError {
90
102
  name = "WaitTimeoutError";
91
103
  };
@@ -773,6 +785,136 @@ var MeResource = class extends APIResource {
773
785
  }
774
786
  };
775
787
 
788
+ // src/resources/migrate.ts
789
+ var CONNECTION_WAIT_MS = 10 * 6e4;
790
+ var SCAN_WAIT_MS = 30 * 6e4;
791
+ function cloudFailed(kind, id, failure, resource) {
792
+ const detail = failure?.message ?? `The ${kind} failed.`;
793
+ const code = failure?.code;
794
+ return new CloudFailedError(
795
+ code ? `Cloud ${kind} ${id} failed: ${detail} (${code})` : `Cloud ${kind} ${id} failed: ${detail}`,
796
+ kind,
797
+ resource,
798
+ { code, detail }
799
+ );
800
+ }
801
+ var Migrate = class extends APIResource {
802
+ /** Connections to AWS accounts through a read-only role only Pantech can assume. */
803
+ connections = new CloudConnections(this._client);
804
+ /** Reads of everything a connection's role can see. */
805
+ scans = new CloudScans(this._client);
806
+ /** Plans to move what a scan found to Pantech. Nothing is created until you apply the Terraform. */
807
+ migrations = new Migrations(this._client);
808
+ };
809
+ var CloudConnections = class extends APIResource {
810
+ list(params = {}, options) {
811
+ return this._get("/cloud-connections", params, options);
812
+ }
813
+ listAll(params = {}, options) {
814
+ return this._listAll("/cloud-connections", params, options);
815
+ }
816
+ /**
817
+ * Starts a connection. Its `setup` holds the CloudFormation template (and,
818
+ * when offered, a one-click `quick_create_url`) that creates the read-only
819
+ * role in your AWS account; send the stack's `RoleArn` output with `update`.
820
+ */
821
+ create(body, options) {
822
+ return this._post("/cloud-connections", body, options);
823
+ }
824
+ get(connectionId, options) {
825
+ return this._get(path`/cloud-connections/${connectionId}`, void 0, options);
826
+ }
827
+ /** Renames the connection, sets its `role_arn`, or retries a failed check (`retry: true`). */
828
+ update(connectionId, body, options) {
829
+ return this._patch(path`/cloud-connections/${connectionId}`, body, options);
830
+ }
831
+ /** Removes the connection and its scans; plans made from it stay. Delete the stack in AWS to revoke the role there. */
832
+ delete(connectionId, options) {
833
+ return this._delete(path`/cloud-connections/${connectionId}`, options);
834
+ }
835
+ /**
836
+ * Polls the connection until it is `connected` (resolves with it) or its
837
+ * check fails (rejects with CloudFailedError). Set the role ARN with
838
+ * `update` first. Default timeout 10 minutes, polling every 5 seconds.
839
+ */
840
+ wait(connectionId, options = {}) {
841
+ return poll(
842
+ () => this.get(connectionId, { signal: options.signal }),
843
+ (c) => {
844
+ if (c.status === "failed") throw cloudFailed("connection", c.id, c.failure, c);
845
+ return c.status === "connected";
846
+ },
847
+ `Cloud connection ${connectionId}`,
848
+ { timeoutMs: CONNECTION_WAIT_MS, pollIntervalMs: 5e3, ...options }
849
+ );
850
+ }
851
+ };
852
+ var CloudScans = class extends APIResource {
853
+ /** A connection's scans, newest first, without their inventories. */
854
+ list(connectionId, params = {}, options) {
855
+ return this._get(path`/cloud-connections/${connectionId}/scans`, params, options);
856
+ }
857
+ listAll(connectionId, params = {}, options) {
858
+ return this._listAll(path`/cloud-connections/${connectionId}/scans`, params, options);
859
+ }
860
+ /** Queues a scan of a connected account. Follow it with `wait`. */
861
+ start(connectionId, options) {
862
+ return this._post(path`/cloud-connections/${connectionId}/scans`, void 0, options);
863
+ }
864
+ /** A scan's status and counts. Pass `{ include: "inventory" }` for everything it found. */
865
+ get(scanId, params = {}, options) {
866
+ return this._get(path`/cloud-scans/${scanId}`, params, options);
867
+ }
868
+ /**
869
+ * Polls the scan until it `succeeded` (resolves with it, without its
870
+ * inventory) or failed (rejects with CloudFailedError). Default timeout 30
871
+ * minutes, polling every 10 seconds.
872
+ */
873
+ wait(scanId, options = {}) {
874
+ return poll(
875
+ () => this.get(scanId, {}, { signal: options.signal }),
876
+ (s) => {
877
+ if (s.status === "failed") throw cloudFailed("scan", s.id, s.failure, s);
878
+ return s.status === "succeeded";
879
+ },
880
+ `Cloud scan ${scanId}`,
881
+ { timeoutMs: SCAN_WAIT_MS, pollIntervalMs: 1e4, ...options }
882
+ );
883
+ }
884
+ };
885
+ var Migrations = class extends APIResource {
886
+ /** Your migration plans, newest first, without their items or estimate. */
887
+ list(params = {}, options) {
888
+ return this._get("/migrations", params, options);
889
+ }
890
+ listAll(params = {}, options) {
891
+ return this._listAll("/migrations", params, options);
892
+ }
893
+ /** Builds a plan, with a price comparison, from a scan that succeeded. Nothing is created on Pantech. */
894
+ create(body, options) {
895
+ return this._post("/migrations", body, options);
896
+ }
897
+ /** A plan with every item, and a price comparison computed now. */
898
+ get(migrationId, options) {
899
+ return this._get(path`/migrations/${migrationId}`, void 0, options);
900
+ }
901
+ rename(migrationId, body, options) {
902
+ return this._patch(path`/migrations/${migrationId}`, body, options);
903
+ }
904
+ /** Deletes the plan. Nothing on Pantech or in the other cloud is touched. */
905
+ delete(migrationId, options) {
906
+ return this._delete(path`/migrations/${migrationId}`, options);
907
+ }
908
+ /** Changes one item, named by its `key`: exclude it, or change its plan, size, range, role or email. */
909
+ updateItem(migrationId, body, options) {
910
+ return this._patch(path`/migrations/${migrationId}/items`, body, options);
911
+ }
912
+ /** The plan's planned items as Terraform: `main.tf` and `variables.tf`. */
913
+ exportTerraform(migrationId, options) {
914
+ return this._get(path`/migrations/${migrationId}/terraform`, void 0, options);
915
+ }
916
+ };
917
+
776
918
  // src/resources/networks.ts
777
919
  var Networks = class extends APIResource {
778
920
  /** A network's subnets: `client.networks.subnets.list(networkId)`. */
@@ -1183,7 +1325,7 @@ var WebhookDeliveries = class extends APIResource {
1183
1325
  };
1184
1326
 
1185
1327
  // src/version.ts
1186
- var VERSION = "0.1.0";
1328
+ var VERSION = "0.2.0";
1187
1329
 
1188
1330
  // src/client.ts
1189
1331
  var DEFAULT_BASE_URL = "https://api.pantechdynamics.com/public/v1";
@@ -1228,6 +1370,8 @@ var Pantech = class {
1228
1370
  databaseOrders;
1229
1371
  sshKeys;
1230
1372
  webhooks;
1373
+ /** Move from another cloud: connections, scans and migration plans. */
1374
+ migrate;
1231
1375
  operations;
1232
1376
  constructor(options = {}) {
1233
1377
  const apiKey = options.apiKey ?? readEnv("PANTECH_API_KEY");
@@ -1269,6 +1413,7 @@ var Pantech = class {
1269
1413
  this.databaseOrders = new DatabaseOrders(this);
1270
1414
  this.sshKeys = new SshKeys(this);
1271
1415
  this.webhooks = new Webhooks(this);
1416
+ this.migrate = new Migrate(this);
1272
1417
  }
1273
1418
  /**
1274
1419
  * Sends one request and returns its decoded body (undefined for an empty
@@ -1484,6 +1629,6 @@ async function signWebhook(options) {
1484
1629
  return `t=${t},v1=${await hmacHex(options.secret, t, bytes(options.body))}`;
1485
1630
  }
1486
1631
 
1487
- export { APIConnectionError, APITimeoutError, AuthenticationError, BadRequestError, ConflictError, DEFAULT_BASE_URL, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, InternalServerError, NotFoundError, OperationFailedError, OrderFailedError, Pantech, PantechError, PaymentRequiredError, PermissionDeniedError, RateLimitError, VERSION, ValidationError, WEBHOOK_SIGNATURE_HEADER, WaitTimeoutError, WebhookVerificationError, isPantechError, paginate, signWebhook, verifyWebhook };
1632
+ export { APIConnectionError, APITimeoutError, AuthenticationError, BadRequestError, CloudFailedError, ConflictError, DEFAULT_BASE_URL, DEFAULT_WEBHOOK_TOLERANCE_SECONDS, InternalServerError, NotFoundError, OperationFailedError, OrderFailedError, Pantech, PantechError, PaymentRequiredError, PermissionDeniedError, RateLimitError, VERSION, ValidationError, WEBHOOK_SIGNATURE_HEADER, WaitTimeoutError, WebhookVerificationError, isPantechError, paginate, signWebhook, verifyWebhook };
1488
1633
  //# sourceMappingURL=index.js.map
1489
1634
  //# sourceMappingURL=index.js.map