@pantechdynamic/sdk 0.2.0 → 0.4.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.cjs CHANGED
@@ -39,6 +39,23 @@ var AuthenticationError = class extends PantechError {
39
39
  };
40
40
  var PaymentRequiredError = class extends PantechError {
41
41
  name = "PaymentRequiredError";
42
+ /**
43
+ * For a domain order waiting in `awaiting_payment`: the page where the bank
44
+ * asks the user to confirm the saved-card payment (US dollars only), when it
45
+ * does. Undefined when no confirmation is needed, for a naira order waiting
46
+ * for credit, and for a `402` answer.
47
+ */
48
+ paymentUrl;
49
+ /** When an unpaid order fails `insufficient_credit` (nothing is charged). */
50
+ paymentExpiresAt;
51
+ /** The order waiting for payment, as the API returned it. */
52
+ order;
53
+ constructor(message, init = {}) {
54
+ super(message, init);
55
+ this.paymentUrl = init.paymentUrl;
56
+ this.paymentExpiresAt = init.paymentExpiresAt;
57
+ this.order = init.order;
58
+ }
42
59
  };
43
60
  var PermissionDeniedError = class extends PantechError {
44
61
  name = "PermissionDeniedError";
@@ -49,6 +66,9 @@ var NotFoundError = class extends PantechError {
49
66
  var ConflictError = class extends PantechError {
50
67
  name = "ConflictError";
51
68
  };
69
+ var PreconditionFailedError = class extends PantechError {
70
+ name = "PreconditionFailedError";
71
+ };
52
72
  var ValidationError = class extends PantechError {
53
73
  name = "ValidationError";
54
74
  };
@@ -100,12 +120,115 @@ var CloudFailedError = class extends PantechError {
100
120
  this.resource = resource;
101
121
  }
102
122
  };
123
+ var DNSFailedError = class extends PantechError {
124
+ name = "DNSFailedError";
125
+ /** `zone` or `record`. */
126
+ kind;
127
+ /** The zone or record set, as the API returned it. */
128
+ resource;
129
+ constructor(message, kind, resource, init = {}) {
130
+ super(message, init);
131
+ this.kind = kind;
132
+ this.resource = resource;
133
+ }
134
+ };
135
+ var CertificateFailedError = class extends PantechError {
136
+ name = "CertificateFailedError";
137
+ /** The certificate, as the API returned it. */
138
+ certificate;
139
+ constructor(message, certificate, init = {}) {
140
+ super(message, init);
141
+ this.certificate = certificate;
142
+ }
143
+ };
103
144
  var WaitTimeoutError = class extends PantechError {
104
145
  name = "WaitTimeoutError";
105
146
  };
106
147
  var WebhookVerificationError = class extends PantechError {
107
148
  name = "WebhookVerificationError";
108
149
  };
150
+ var DNS_ERROR_CODES = [
151
+ "DNS_UNAVAILABLE",
152
+ "DNS_ZONE_NOT_FOUND",
153
+ "DNS_RECORD_NOT_FOUND",
154
+ "DNS_ZONE_LIMIT_REACHED",
155
+ "DNS_ZONE_CREATE_LIMIT_REACHED",
156
+ "DNS_RECORD_LIMIT_REACHED",
157
+ "DNS_ZONE_NAME_TAKEN",
158
+ "DNS_ZONE_ACTIVE_ELSEWHERE",
159
+ "DNS_RECORD_EXISTS",
160
+ "DNS_CNAME_CONFLICT",
161
+ "DNS_RECORD_READ_ONLY",
162
+ "DNS_ZONE_SUSPENDED",
163
+ "DNS_ZONE_NOT_WRITABLE",
164
+ "DNS_ZONE_IN_USE_BY_DOMAIN",
165
+ "VERSION_CONFLICT",
166
+ "TOO_MANY_CHANGES",
167
+ "INVALID_ZONE_FILE"
168
+ ];
169
+ var DOMAIN_ERROR_CODES = [
170
+ "DOMAINS_UNAVAILABLE",
171
+ "DOMAIN_NOT_FOUND",
172
+ "DOMAIN_ORDER_NOT_FOUND",
173
+ "DOMAIN_LOOKUP_UNAVAILABLE",
174
+ "TLD_NOT_SOLD",
175
+ "DOMAIN_NOT_AVAILABLE",
176
+ "DOMAIN_NOT_TRANSFERABLE",
177
+ "DOMAIN_ALREADY_HELD",
178
+ "DOMAIN_ORDER_IN_FLIGHT",
179
+ "DOMAIN_ORDER_NOT_AWAITING_PAYMENT",
180
+ "DOMAIN_ORDER_LIMIT_REACHED",
181
+ "DOMAIN_NOT_CONFIGURABLE",
182
+ "DOMAIN_LOCKED",
183
+ "DOMAIN_ZONE_MISMATCH"
184
+ ];
185
+ var REGISTRY_ERROR_CODES = [
186
+ "REGISTRY_UNAVAILABLE",
187
+ "REGISTRY_NAMESPACE_NOT_SET",
188
+ "REGISTRY_NAMESPACE_TAKEN",
189
+ "REGISTRY_NAMESPACE_LOCKED",
190
+ "INVALID_REGISTRY_NAMESPACE",
191
+ "INVALID_REPOSITORY_NAME",
192
+ "REPOSITORY_NOT_FOUND",
193
+ "TAG_NOT_FOUND",
194
+ "REGISTRY_TOKEN_NOT_FOUND",
195
+ "REPOSITORY_EXISTS",
196
+ "REPOSITORY_LIMIT_REACHED",
197
+ "REGISTRY_STORAGE_LIMIT_REACHED",
198
+ "REGISTRY_TOKEN_LIMIT_REACHED",
199
+ "TAG_IMMUTABLE",
200
+ "REPOSITORY_SUSPENDED"
201
+ ];
202
+ var IAM_ERROR_CODES = [
203
+ "ACCESS_DENIED",
204
+ "IAM_TEAM_NOT_FOUND",
205
+ "IAM_POLICY_NOT_FOUND",
206
+ "IAM_ATTACHMENT_NOT_FOUND",
207
+ "IAM_TEAM_NAME_TAKEN",
208
+ "IAM_POLICY_NAME_TAKEN",
209
+ "IAM_TEAM_LIMIT_REACHED",
210
+ "IAM_POLICY_LIMIT_REACHED",
211
+ "IAM_ATTACHMENT_LIMIT_REACHED",
212
+ "IAM_MANAGED_POLICY",
213
+ "IAM_ADMIN_TARGET",
214
+ "INVALID_POLICY",
215
+ "VERSION_CONFLICT"
216
+ ];
217
+ var CERTIFICATE_ERROR_CODES = [
218
+ "CERTIFICATES_UNAVAILABLE",
219
+ "CERTIFICATE_NOT_FOUND",
220
+ "CERTIFICATE_LIMIT_REACHED",
221
+ "CERTIFICATE_REQUEST_LIMIT_REACHED",
222
+ "CERTIFICATE_RATE_LIMITED",
223
+ "CERTIFICATE_IN_USE",
224
+ "CERTIFICATE_NOT_EXPORTABLE",
225
+ "CERTIFICATE_NOT_ISSUED",
226
+ "CERTIFICATE_NOT_REVOCABLE",
227
+ "CERTIFICATE_NOT_IMPORTED",
228
+ "CERTIFICATE_NOT_PENDING",
229
+ "CERTIFICATE_NAMES_MISMATCH",
230
+ "CONFLICT"
231
+ ];
109
232
  function isPantechError(err, code) {
110
233
  return err instanceof PantechError && (code === void 0 || err.code === code);
111
234
  }
@@ -117,6 +240,7 @@ var STATUS_TEXT = {
117
240
  404: "Not found",
118
241
  405: "Method not allowed",
119
242
  409: "Conflict",
243
+ 412: "Precondition failed",
120
244
  413: "Request too large",
121
245
  415: "Unsupported media type",
122
246
  422: "Validation failed",
@@ -175,6 +299,8 @@ function errorFromResponse(status, headers, bodyText, retryAfterSeconds) {
175
299
  return new NotFoundError(message, init);
176
300
  case status === 409:
177
301
  return new ConflictError(message, init);
302
+ case status === 412:
303
+ return new PreconditionFailedError(message, init);
178
304
  case status === 422:
179
305
  return new ValidationError(message, init);
180
306
  case status === 429:
@@ -201,6 +327,26 @@ async function* paginate(fetchPage, startCursor) {
201
327
  }
202
328
 
203
329
  // src/resource.ts
330
+ var SECRET_FIELDS = ["secret", "private_key_pem"];
331
+ function hideSecrets(value) {
332
+ if (value && typeof value === "object") {
333
+ for (const field of SECRET_FIELDS) {
334
+ if (Object.hasOwn(value, field)) {
335
+ const secret = value[field];
336
+ Object.defineProperty(value, field, { value: secret, enumerable: false, writable: false, configurable: true });
337
+ }
338
+ }
339
+ }
340
+ return value;
341
+ }
342
+ function withIfMatch(options) {
343
+ if (options?.ifMatch === void 0) return options;
344
+ const { ifMatch, ...rest } = options;
345
+ if (!Number.isInteger(ifMatch) || ifMatch < 0) {
346
+ throw new TypeError("ifMatch must be the version you read: a whole number, 0 or more.");
347
+ }
348
+ return { ...rest, headers: { ...rest.headers, "If-Match": String(ifMatch) } };
349
+ }
204
350
  var APIResource = class {
205
351
  _client;
206
352
  constructor(client) {
@@ -271,13 +417,13 @@ function sleep(ms, signal) {
271
417
  signal?.addEventListener("abort", onAbort, { once: true });
272
418
  });
273
419
  }
274
- function path(strings, ...ids) {
275
- let out = strings[0] ?? "";
420
+ function path(strings2, ...ids) {
421
+ let out = strings2[0] ?? "";
276
422
  ids.forEach((id, i) => {
277
423
  if (typeof id !== "string" || id === "") {
278
424
  throw new PantechError("A resource id is required, and it must be a non-empty string.");
279
425
  }
280
- out += encodeURIComponent(id) + (strings[i + 1] ?? "");
426
+ out += encodeURIComponent(id) + (strings2[i + 1] ?? "");
281
427
  });
282
428
  return out;
283
429
  }
@@ -397,6 +543,87 @@ async function poll(read, done, what, options = {}) {
397
543
  }
398
544
  }
399
545
 
546
+ // src/resources/certificates.ts
547
+ var ISSUE_WAIT_MS = 10 * 6e4;
548
+ var READY = /* @__PURE__ */ new Set(["issued", "renewing"]);
549
+ var FINISHED = /* @__PURE__ */ new Set(["failed", "revoked", "expired"]);
550
+ var Certificates = class extends APIResource {
551
+ /** One page of your certificates, newest first. Filter with `q` (any name), `status` or `kind`. */
552
+ list(params = {}, options) {
553
+ return this._get("/certificates", params, options);
554
+ }
555
+ listAll(params = {}, options) {
556
+ return this._listAll("/certificates", params, options);
557
+ }
558
+ /**
559
+ * Requests a certificate for 1 to 100 names. Names in your Pantech DNS
560
+ * zones are validated for you; for the others add each `validations[]`
561
+ * CNAME once. Follow it with `wait`.
562
+ */
563
+ request(body, options) {
564
+ return this._post("/certificates", body, options);
565
+ }
566
+ /** Imports a certificate and its private key. An expired or mismatched one is refused. */
567
+ import(body, options) {
568
+ return this._post("/certificates/import", body, options);
569
+ }
570
+ get(certificateId, options) {
571
+ return this._get(path`/certificates/${certificateId}`, void 0, options);
572
+ }
573
+ update(certificateId, body, options) {
574
+ return this._patch(path`/certificates/${certificateId}`, body, options);
575
+ }
576
+ /** Checks the CNAMEs of a certificate waiting for validation within seconds. */
577
+ verify(certificateId, options) {
578
+ return this._post(path`/certificates/${certificateId}/verify`, void 0, options);
579
+ }
580
+ /** Replaces an imported certificate with a new one for the same names. */
581
+ reimport(certificateId, body, options) {
582
+ return this._post(path`/certificates/${certificateId}/reimport`, body, options);
583
+ }
584
+ /**
585
+ * The certificate, its chain and its private key, for a certificate created
586
+ * with `exportable: true`. Needs the `delete` scope; every owner and admin is
587
+ * emailed. `private_key_pem` is non-enumerable: read it explicitly.
588
+ */
589
+ async export(certificateId, options) {
590
+ return hideSecrets(
591
+ await this._post(path`/certificates/${certificateId}/export`, void 0, options)
592
+ );
593
+ }
594
+ /** Asks the CA to revoke it (`reason`: `unspecified` or `key_compromise`). Refused while it is in use. */
595
+ revoke(certificateId, body = {}, options) {
596
+ return this._post(path`/certificates/${certificateId}/revoke`, body, options);
597
+ }
598
+ /** Deletes it. Refused while a Pantech service uses it. */
599
+ delete(certificateId, options) {
600
+ return this._delete(path`/certificates/${certificateId}`, options);
601
+ }
602
+ /**
603
+ * Polls the certificate until it is `issued` (resolves with it) or it
604
+ * `failed`, was revoked or expired (rejects with CertificateFailedError).
605
+ * Default timeout 10 minutes, polling every 5 seconds; a name validated by
606
+ * CNAME waits until you add it, up to 72 hours, so pass a longer `timeoutMs`.
607
+ */
608
+ wait(certificateId, options = {}) {
609
+ return poll(
610
+ () => this.get(certificateId, { signal: options.signal }),
611
+ (c) => {
612
+ if (FINISHED.has(c.status)) {
613
+ const code = c.failure_code ?? c.status;
614
+ const detail = code === c.status ? "" : ` (${code})`;
615
+ throw new CertificateFailedError(`Certificate ${c.id} (${c.names[0] ?? ""}) is ${c.status}${detail}.`, c, {
616
+ code
617
+ });
618
+ }
619
+ return READY.has(c.status);
620
+ },
621
+ `Certificate ${certificateId}`,
622
+ { timeoutMs: ISSUE_WAIT_MS, pollIntervalMs: 5e3, ...options }
623
+ );
624
+ }
625
+ };
626
+
400
627
  // src/orders.ts
401
628
  var orderId = (ref) => typeof ref === "string" ? ref : ref.order_id;
402
629
  async function waitForOrder(client, read, what, options = {}) {
@@ -514,6 +741,403 @@ var DatabaseOrders = class extends APIResource {
514
741
  }
515
742
  };
516
743
 
744
+ // src/resources/dns.ts
745
+ var RECORD_WAIT_MS = 5 * 6e4;
746
+ var ZONE_WAIT_MS = 5 * 6e4;
747
+ var DNS = class extends APIResource {
748
+ /** Hosted zones, with the name servers to delegate your domain to. */
749
+ zones = new DNSZones(this._client);
750
+ /** Record sets of a zone: one name and type each, with a TTL and values. */
751
+ records = new DNSRecords(this._client);
752
+ };
753
+ var DNSZones = class extends APIResource {
754
+ /** One page of your zones, newest first. Filter with `q` (name contains) or `status`. */
755
+ list(params = {}, options) {
756
+ return this._get("/dns/zones", params, options);
757
+ }
758
+ listAll(params = {}, options) {
759
+ return this._listAll("/dns/zones", params, options);
760
+ }
761
+ /**
762
+ * Hosts a zone. It is `pending`, then `awaiting_delegation` with its own
763
+ * two `name_servers` to set at your registrar, then `active` once the
764
+ * registry delegates to exactly those. Undelegated for 14 days, it is
765
+ * removed. The first 5 zones are free: see `quote`.
766
+ */
767
+ create(body, options) {
768
+ return this._post("/dns/zones", body, options);
769
+ }
770
+ /** The free zone allowance, and the monthly price of each further zone in your currency (before VAT). */
771
+ quote(options) {
772
+ return this._get("/dns/zones/quote", void 0, options);
773
+ }
774
+ get(zoneId, options) {
775
+ return this._get(path`/dns/zones/${zoneId}`, void 0, options);
776
+ }
777
+ /** Changes the zone's description. */
778
+ update(zoneId, body, options) {
779
+ return this._patch(path`/dns/zones/${zoneId}`, body, options);
780
+ }
781
+ /**
782
+ * Stops answering for the zone at once and removes its records. Refused
783
+ * with `DNS_ZONE_IN_USE_BY_DOMAIN` while a Pantech domain delegates to it.
784
+ */
785
+ delete(zoneId, options) {
786
+ return this._delete(path`/dns/zones/${zoneId}`, options);
787
+ }
788
+ /** Checks the zone's delegation within seconds instead of at the next scheduled check. */
789
+ verify(zoneId, options) {
790
+ return this._post(path`/dns/zones/${zoneId}/verify`, void 0, options);
791
+ }
792
+ /**
793
+ * Polls a new zone until it has its name servers: `awaiting_delegation`
794
+ * (set them at your registrar) or `active`. Rejects with DNSFailedError if
795
+ * it fails or is being deleted. Default timeout 5 minutes, polling every 3
796
+ * seconds. It does not wait for delegation, which is up to your registrar.
797
+ */
798
+ wait(zoneId, options = {}) {
799
+ return poll(
800
+ () => this.get(zoneId, { signal: options.signal }),
801
+ (z) => {
802
+ if (z.status === "failed" || z.status === "deleting" || z.status === "deleted") {
803
+ const code = z.failure_code ?? z.status;
804
+ throw new DNSFailedError(`DNS zone ${z.id} (${z.name}) is ${z.status} (${code}).`, "zone", z, { code });
805
+ }
806
+ return z.status === "awaiting_delegation" || z.status === "active";
807
+ },
808
+ `DNS zone ${zoneId}`,
809
+ { timeoutMs: ZONE_WAIT_MS, pollIntervalMs: 3e3, ...options }
810
+ );
811
+ }
812
+ /** The zone's record sets as a BIND zone file. */
813
+ exportZoneFile(zoneId, options) {
814
+ return this._request("GET", path`/dns/zones/${zoneId}/export`, { responseType: "text" }, options);
815
+ }
816
+ /**
817
+ * Creates and updates record sets from a BIND zone file (at most 1000
818
+ * changes). With `replace: true`, record sets the file lacks are deleted too.
819
+ */
820
+ importZoneFile(zoneId, body, options) {
821
+ return this._post(path`/dns/zones/${zoneId}/import`, body, options);
822
+ }
823
+ };
824
+ var DNSRecords = class extends APIResource {
825
+ /** One page of a zone's record sets, by name then type. Filter with `name`, `q` or `type`. */
826
+ list(zoneId, params = {}, options) {
827
+ return this._get(path`/dns/zones/${zoneId}/records`, params, options);
828
+ }
829
+ listAll(zoneId, params = {}, options) {
830
+ return this._listAll(path`/dns/zones/${zoneId}/records`, params, options);
831
+ }
832
+ /** Adds a record set, `pending` until it answers. Follow it with `wait`. */
833
+ create(zoneId, body, options) {
834
+ return this._post(path`/dns/zones/${zoneId}/records`, body, options);
835
+ }
836
+ get(zoneId, recordId, options) {
837
+ return this._get(path`/dns/zones/${zoneId}/records/${recordId}`, void 0, options);
838
+ }
839
+ /** Changes the TTL, values or comment. Pass `{ ifMatch: record.version }` to refuse a lost update. */
840
+ update(zoneId, recordId, body, options) {
841
+ return this._patch(path`/dns/zones/${zoneId}/records/${recordId}`, body, withIfMatch(options));
842
+ }
843
+ /** Removes the record set. Pass `{ ifMatch: record.version }` to refuse it if the record changed. */
844
+ delete(zoneId, recordId, options) {
845
+ return this._delete(path`/dns/zones/${zoneId}/records/${recordId}`, withIfMatch(options));
846
+ }
847
+ /**
848
+ * Up to 1000 creates, updates and deletes, all or nothing. A change's
849
+ * `version` refuses it with `412 VERSION_CONFLICT` if the record moved on.
850
+ */
851
+ batch(zoneId, body, options) {
852
+ return this._post(path`/dns/zones/${zoneId}/records/batch`, body, options);
853
+ }
854
+ /**
855
+ * Polls the record set until it is `active` (resolves with it) or its
856
+ * change failed (rejects with DNSFailedError). Default timeout 5
857
+ * minutes, polling every 3 seconds.
858
+ */
859
+ wait(zoneId, recordId, options = {}) {
860
+ return poll(
861
+ () => this.get(zoneId, recordId, { signal: options.signal }),
862
+ (r) => {
863
+ if (r.status === "failed") {
864
+ const code = r.failure_code ?? void 0;
865
+ throw new DNSFailedError(
866
+ `DNS record ${r.id} (${r.fqdn} ${r.type}) failed${code ? ` (${code})` : ""}. The previous values still answer.`,
867
+ "record",
868
+ r,
869
+ { code }
870
+ );
871
+ }
872
+ return r.status === "active";
873
+ },
874
+ `DNS record ${recordId}`,
875
+ { timeoutMs: RECORD_WAIT_MS, pollIntervalMs: 3e3, ...options }
876
+ );
877
+ }
878
+ };
879
+
880
+ // src/resources/domains.ts
881
+ var ORDER_WAIT_MS = 15 * 6e4;
882
+ var domainOrderId = (ref) => typeof ref === "string" ? ref : ref.order.id;
883
+ var Domains = class extends APIResource {
884
+ /** Registrations, renewals and transfers. */
885
+ orders = new DomainOrders(this._client);
886
+ /** Every TLD for sale to your organization, priced per year in minor units of its currency. */
887
+ listTlds(options) {
888
+ return this._get("/domains/tlds", void 0, options);
889
+ }
890
+ /** Checks a name across the TLDs for sale, plus suggestions, each with its price. */
891
+ search(params, options) {
892
+ return this._get("/domains/search", params, options);
893
+ }
894
+ /** Whether the registry lets the domain move to Pantech now, and what it costs. */
895
+ checkTransfer(params, options) {
896
+ return this._get("/domains/transfer-check", params, options);
897
+ }
898
+ list(params = {}, options) {
899
+ return this._get("/domains", params, options);
900
+ }
901
+ listAll(params = {}, options) {
902
+ return this._listAll("/domains", params, options);
903
+ }
904
+ /**
905
+ * Buys the domain for `years` (1 to 10), paid from your credit first; a
906
+ * failed order is refunded. `accept_terms` must be true. Follow the order
907
+ * with `orders.wait(result)`.
908
+ */
909
+ register(body, options) {
910
+ return this._post("/domains", body, options);
911
+ }
912
+ /** Moves a domain to Pantech with its auth code, adding `years` to its term. Follow it with `orders.wait`. */
913
+ transfer(body, options) {
914
+ return this._post("/domains/transfers", body, options);
915
+ }
916
+ get(domainId, options) {
917
+ return this._get(path`/domains/${domainId}`, void 0, options);
918
+ }
919
+ /** Turns auto-renew, the transfer lock or privacy on or off. */
920
+ update(domainId, body, options) {
921
+ return this._patch(path`/domains/${domainId}`, body, options);
922
+ }
923
+ /** Points the domain at its Pantech DNS zone, or at up to 6 custom name servers. */
924
+ setNameServers(domainId, body, options) {
925
+ return this._put(path`/domains/${domainId}/name-servers`, body, options);
926
+ }
927
+ /** The registrant contact. Owners and admins only. */
928
+ getContact(domainId, options) {
929
+ return this._get(path`/domains/${domainId}/contact`, void 0, options);
930
+ }
931
+ /** Replaces the registrant contact; applied at the registry in the background. */
932
+ updateContact(domainId, body, options) {
933
+ return this._put(path`/domains/${domainId}/contact`, body, options);
934
+ }
935
+ /** Adds `years` (default 1) to the domain's term, paid from your credit first. */
936
+ renew(domainId, body = {}, options) {
937
+ return this._post(path`/domains/${domainId}/renew`, body, options);
938
+ }
939
+ /**
940
+ * Asks for the code that moves the domain to another registrar. Needs the
941
+ * `delete` scope, and the transfer lock off. Read it with `getAuthCode`.
942
+ */
943
+ requestAuthCode(domainId, options) {
944
+ return this._post(path`/domains/${domainId}/auth-code`, void 0, options);
945
+ }
946
+ /** The auth code once it has arrived, or `{ status: "pending" }` while it is on its way. */
947
+ getAuthCode(domainId, options) {
948
+ return this._get(path`/domains/${domainId}/auth-code`, void 0, options);
949
+ }
950
+ };
951
+ var DomainOrders = class extends APIResource {
952
+ /** A domain's registrations, renewals and transfers, newest first. */
953
+ list(domainId, options) {
954
+ return this._get(path`/domains/${domainId}/orders`, void 0, options);
955
+ }
956
+ get(orderId2, options) {
957
+ return this._get(path`/domain-orders/${orderId2}`, void 0, options);
958
+ }
959
+ /**
960
+ * Makes an order waiting in `awaiting_payment` try its payment again now,
961
+ * and wait another hour: in US dollars the saved card is charged the
962
+ * difference once more (after a decline, or once a new card is saved); in
963
+ * naira the credit just added is taken. The call charges nothing itself
964
+ * and an order is never charged twice, so repeating it is safe. Resolves
965
+ * with the order (`202`); follow it with `wait(order, { waitForPayment: true })`.
966
+ * Rejects with ConflictError `DOMAIN_ORDER_NOT_AWAITING_PAYMENT` when the
967
+ * order is not waiting for a payment or its window has ended.
968
+ */
969
+ retryPayment(orderId2, options) {
970
+ return this._post(path`/domain-orders/${orderId2}/retry-payment`, void 0, options);
971
+ }
972
+ /**
973
+ * Polls the order until it `succeeded` (resolves with it) or `failed`
974
+ * (rejects with OrderFailedError; any amount taken is returned to your
975
+ * credit). An order your credit does not cover waits in `awaiting_payment`
976
+ * for an hour (in US dollars the saved card is charged the difference; in
977
+ * naira the user adds credit): it rejects with PaymentRequiredError carrying
978
+ * `paymentExpiresAt`, and `paymentUrl` only when the bank asks the user to
979
+ * confirm the payment; wait again with `{ waitForPayment: true }`, or call
980
+ * `retryPayment` to try again at once. An order not paid in time fails
981
+ * `insufficient_credit` and nothing is charged. Default timeout 15 minutes,
982
+ * polling every 5 seconds. A transfer can take days: pass a longer
983
+ * `timeoutMs`, or check the order later.
984
+ */
985
+ wait(ref, options = {}) {
986
+ const id = domainOrderId(ref);
987
+ const { waitForPayment, ...waitOptions } = options;
988
+ return poll(
989
+ () => this.get(id, { signal: options.signal }),
990
+ (o) => {
991
+ if (o.status === "awaiting_payment" && !waitForPayment) {
992
+ throw new PaymentRequiredError(
993
+ `Domain order ${o.id} is waiting for a payment: your credit does not cover it.${o.payment_url ? " The bank asks the user to confirm the card payment at paymentUrl." : ""} It must be paid${o.payment_expires_at ? ` before ${o.payment_expires_at}` : " within the hour"}; the order goes on by itself once it is, and retryPayment tries again at once.`,
994
+ {
995
+ status: 402,
996
+ code: "AWAITING_PAYMENT",
997
+ paymentUrl: o.payment_url ?? void 0,
998
+ paymentExpiresAt: o.payment_expires_at ?? void 0,
999
+ order: o
1000
+ }
1001
+ );
1002
+ }
1003
+ if (o.status === "failed") {
1004
+ const code = o.failure_code ?? "failed";
1005
+ throw new OrderFailedError(
1006
+ `Domain order ${o.id} failed (${code}).${o.refunded ? " The amount was returned to your credit." : ""}`,
1007
+ o,
1008
+ { code }
1009
+ );
1010
+ }
1011
+ return o.status === "succeeded";
1012
+ },
1013
+ `Domain order ${id}`,
1014
+ { timeoutMs: ORDER_WAIT_MS, pollIntervalMs: 5e3, ...waitOptions }
1015
+ );
1016
+ }
1017
+ };
1018
+
1019
+ // src/resources/iam.ts
1020
+ var IAM = class extends APIResource {
1021
+ /** The actions a policy statement can name. */
1022
+ actions = new IAMActions(this._client);
1023
+ /** Whether members may read everything, or only what their policies allow. */
1024
+ settings = new IAMSettings(this._client);
1025
+ /** The organization's members, with their teams and how many policies apply to each. */
1026
+ members = new IAMMembers(this._client);
1027
+ /** Teams of members that policies are attached to. */
1028
+ teams = new IAMTeams(this._client);
1029
+ /** Statements that allow or deny actions, attached to members or teams. */
1030
+ policies = new IAMPolicies(this._client);
1031
+ /** A member's role, teams and every policy that applies to them, with the team that brought it. */
1032
+ effectiveAccess(userId, options) {
1033
+ return this._get(path`/iam/members/${userId}/effective-access`, void 0, options);
1034
+ }
1035
+ /** Whether a member may do an action (on a resource, from an address, with MFA), and which policy decided. */
1036
+ simulate(body, options) {
1037
+ return this._post("/iam/simulate", body, options);
1038
+ }
1039
+ };
1040
+ var IAMActions = class extends APIResource {
1041
+ /** Every action, e.g. `instances:Stop`, with its description and whether it is a read. */
1042
+ list(options) {
1043
+ return this._get("/iam/actions", void 0, options);
1044
+ }
1045
+ };
1046
+ var IAMMembers = class extends APIResource {
1047
+ /** One page of members, by when they joined. Filter with `q` (email or name). */
1048
+ list(params = {}, options) {
1049
+ return this._get("/iam/members", params, options);
1050
+ }
1051
+ listAll(params = {}, options) {
1052
+ return this._listAll("/iam/members", params, options);
1053
+ }
1054
+ };
1055
+ var IAMSettings = class extends APIResource {
1056
+ get(options) {
1057
+ return this._get("/iam/settings", void 0, options);
1058
+ }
1059
+ /** Changes `member_baseline` (`read` or `none`). Owners only. Pass `{ ifMatch: settings.version }` to refuse a lost update. */
1060
+ update(body, options) {
1061
+ return this._put("/iam/settings", body, withIfMatch(options));
1062
+ }
1063
+ };
1064
+ var IAMTeams = class extends APIResource {
1065
+ /** Members of a team. */
1066
+ members = new IAMTeamMembers(this._client);
1067
+ list(params = {}, options) {
1068
+ return this._get("/iam/teams", params, options);
1069
+ }
1070
+ listAll(params = {}, options) {
1071
+ return this._listAll("/iam/teams", params, options);
1072
+ }
1073
+ create(body, options) {
1074
+ return this._post("/iam/teams", body, options);
1075
+ }
1076
+ get(teamId, options) {
1077
+ return this._get(path`/iam/teams/${teamId}`, void 0, options);
1078
+ }
1079
+ update(teamId, body, options) {
1080
+ return this._patch(path`/iam/teams/${teamId}`, body, options);
1081
+ }
1082
+ /** Deletes the team; its members lose what its policies gave them. */
1083
+ delete(teamId, options) {
1084
+ return this._delete(path`/iam/teams/${teamId}`, options);
1085
+ }
1086
+ };
1087
+ var IAMTeamMembers = class extends APIResource {
1088
+ list(teamId, params = {}, options) {
1089
+ return this._get(path`/iam/teams/${teamId}/members`, params, options);
1090
+ }
1091
+ listAll(teamId, params = {}, options) {
1092
+ return this._listAll(path`/iam/teams/${teamId}/members`, params, options);
1093
+ }
1094
+ /** Adds an organization member to the team. Only owners may add an admin. */
1095
+ add(teamId, userId, options) {
1096
+ return this._request("PUT", path`/iam/teams/${teamId}/members/${userId}`, {}, options);
1097
+ }
1098
+ remove(teamId, userId, options) {
1099
+ return this._delete(path`/iam/teams/${teamId}/members/${userId}`, options);
1100
+ }
1101
+ };
1102
+ var IAMPolicies = class extends APIResource {
1103
+ /** The members and teams a policy is attached to. */
1104
+ attachments = new IAMPolicyAttachments(this._client);
1105
+ /** Your policies and Pantech's managed ones; `{ managed: false }` for yours only. */
1106
+ list(params = {}, options) {
1107
+ return this._get("/iam/policies", params, options);
1108
+ }
1109
+ listAll(params = {}, options) {
1110
+ return this._listAll("/iam/policies", params, options);
1111
+ }
1112
+ /** Creates a policy of 1 to 20 statements. It does nothing until it is attached. */
1113
+ create(body, options) {
1114
+ return this._post("/iam/policies", body, options);
1115
+ }
1116
+ get(policyId, options) {
1117
+ return this._get(path`/iam/policies/${policyId}`, void 0, options);
1118
+ }
1119
+ /** Replaces the name, description and statements. Pass `{ ifMatch: policy.version }` to refuse a lost update. */
1120
+ update(policyId, body, options) {
1121
+ return this._put(path`/iam/policies/${policyId}`, body, withIfMatch(options));
1122
+ }
1123
+ /** Deletes the policy and detaches it everywhere. Pantech's managed policies cannot be deleted. */
1124
+ delete(policyId, options) {
1125
+ return this._delete(path`/iam/policies/${policyId}`, options);
1126
+ }
1127
+ };
1128
+ var IAMPolicyAttachments = class extends APIResource {
1129
+ list(policyId, options) {
1130
+ return this._get(path`/iam/policies/${policyId}/attachments`, void 0, options);
1131
+ }
1132
+ /** Attaches the policy to a member (`usr_…`) or a team (`team_…`). */
1133
+ attach(policyId, body, options) {
1134
+ return this._post(path`/iam/policies/${policyId}/attachments`, body, options);
1135
+ }
1136
+ detach(policyId, principalType, principalId, options) {
1137
+ return this._delete(path`/iam/policies/${policyId}/attachments/${principalType}/${principalId}`, options);
1138
+ }
1139
+ };
1140
+
517
1141
  // src/resources/instances.ts
518
1142
  var Instances = class extends APIResource {
519
1143
  /** Snapshots of an instance's root disk. */
@@ -1133,6 +1757,89 @@ var PortForwardingRules = class extends APIResource {
1133
1757
  }
1134
1758
  };
1135
1759
 
1760
+ // src/resources/registry.ts
1761
+ var Registry = class extends APIResource {
1762
+ /** Your organization's namespace, which every image name starts with. */
1763
+ namespace = new RegistryNamespaces(this._client);
1764
+ /** Repositories in your namespace. */
1765
+ repositories = new RegistryRepositories(this._client);
1766
+ /** Tags of a repository, and the images they point at. */
1767
+ tags = new RegistryTags(this._client);
1768
+ /** Registry-only credentials for CI and clusters. */
1769
+ tokens = new RegistryTokens(this._client);
1770
+ };
1771
+ var RegistryNamespaces = class extends APIResource {
1772
+ /** The namespace with its usage and limits. Rejects with `404 REGISTRY_NAMESPACE_NOT_SET` until one is claimed. */
1773
+ get(options) {
1774
+ return this._get("/registry", void 0, options);
1775
+ }
1776
+ /** Claims the namespace, or changes it or `create_on_push`. The name is fixed once a repository exists. */
1777
+ set(body, options) {
1778
+ return this._put("/registry", body, options);
1779
+ }
1780
+ };
1781
+ var RegistryRepositories = class extends APIResource {
1782
+ list(params = {}, options) {
1783
+ return this._get("/registry/repositories", params, options);
1784
+ }
1785
+ listAll(params = {}, options) {
1786
+ return this._listAll("/registry/repositories", params, options);
1787
+ }
1788
+ /** Creates a repository, private unless `visibility` is `public`. */
1789
+ create(body, options) {
1790
+ return this._post("/registry/repositories", body, options);
1791
+ }
1792
+ get(repositoryId, options) {
1793
+ return this._get(path`/registry/repositories/${repositoryId}`, void 0, options);
1794
+ }
1795
+ /** Changes the description, visibility, tag immutability or retention policy. */
1796
+ update(repositoryId, body, options) {
1797
+ return this._patch(path`/registry/repositories/${repositoryId}`, body, options);
1798
+ }
1799
+ /** Deletes the repository and every image in it. */
1800
+ delete(repositoryId, options) {
1801
+ return this._delete(path`/registry/repositories/${repositoryId}`, options);
1802
+ }
1803
+ };
1804
+ var RegistryTags = class extends APIResource {
1805
+ /** A repository's tags, newest push first. */
1806
+ list(repositoryId, params = {}, options) {
1807
+ return this._get(path`/registry/repositories/${repositoryId}/tags`, params, options);
1808
+ }
1809
+ listAll(repositoryId, params = {}, options) {
1810
+ return this._listAll(path`/registry/repositories/${repositoryId}/tags`, params, options);
1811
+ }
1812
+ get(repositoryId, tag, options) {
1813
+ return this._get(path`/registry/repositories/${repositoryId}/tags/${tag}`, void 0, options);
1814
+ }
1815
+ /** Removes the tag. Rejected with `409 TAG_IMMUTABLE` in a repository with immutable tags. */
1816
+ delete(repositoryId, tag, options) {
1817
+ return this._delete(path`/registry/repositories/${repositoryId}/tags/${tag}`, options);
1818
+ }
1819
+ };
1820
+ var RegistryTokens = class extends APIResource {
1821
+ /** Your registry tokens, without their secrets. */
1822
+ list(params = {}, options) {
1823
+ return this._get("/registry/tokens", params, options);
1824
+ }
1825
+ listAll(params = {}, options) {
1826
+ return this._listAll("/registry/tokens", params, options);
1827
+ }
1828
+ /**
1829
+ * Creates a token for `docker login`: `pull`, or `push` (which includes
1830
+ * pull), for every repository or only `repositories`. Its `secret` is in
1831
+ * this response alone. It is non-enumerable: `token.secret` reads it, but
1832
+ * console.log and JSON.stringify leave it out.
1833
+ */
1834
+ async create(body, options) {
1835
+ return hideSecrets(await this._post("/registry/tokens", body, options));
1836
+ }
1837
+ /** Revokes the token: logins stop at once, and access already granted ends within 5 minutes. */
1838
+ delete(tokenId, options) {
1839
+ return this._delete(path`/registry/tokens/${tokenId}`, options);
1840
+ }
1841
+ };
1842
+
1136
1843
  // src/resources/security-groups.ts
1137
1844
  var SecurityGroups = class extends APIResource {
1138
1845
  list(params = {}, options) {
@@ -1327,7 +2034,7 @@ var WebhookDeliveries = class extends APIResource {
1327
2034
  };
1328
2035
 
1329
2036
  // src/version.ts
1330
- var VERSION = "0.2.0";
2037
+ var VERSION = "0.4.0";
1331
2038
 
1332
2039
  // src/client.ts
1333
2040
  var DEFAULT_BASE_URL = "https://api.pantechdynamics.com/public/v1";
@@ -1335,6 +2042,12 @@ var DEFAULT_TIMEOUT_MS = 6e4;
1335
2042
  var DEFAULT_MAX_RETRIES = 3;
1336
2043
  var MAX_RETRY_AFTER_MS = 6e4;
1337
2044
  var RETRY_STATUSES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
2045
+ var ACCEPT = {
2046
+ json: "application/json",
2047
+ arrayBuffer: "*/*",
2048
+ text: "text/dns, text/plain;q=0.9",
2049
+ response: "application/json"
2050
+ };
1338
2051
  var Pantech = class {
1339
2052
  baseURL;
1340
2053
  maxRetries;
@@ -1374,6 +2087,16 @@ var Pantech = class {
1374
2087
  webhooks;
1375
2088
  /** Move from another cloud: connections, scans and migration plans. */
1376
2089
  migrate;
2090
+ /** Pantech DNS: hosted zones and their records, on Pantech's own name servers. */
2091
+ dns;
2092
+ /** Domains: search, register, transfer in, renew and configure. */
2093
+ domains;
2094
+ /** The private container registry: namespace, repositories, tags and registry tokens. */
2095
+ registry;
2096
+ /** Teams and access policies: who may do what, on which resources. */
2097
+ iam;
2098
+ /** TLS certificates Pantech issues and renews, or ones you import. */
2099
+ certificates;
1377
2100
  operations;
1378
2101
  constructor(options = {}) {
1379
2102
  const apiKey = options.apiKey ?? readEnv("PANTECH_API_KEY");
@@ -1416,6 +2139,11 @@ var Pantech = class {
1416
2139
  this.sshKeys = new SshKeys(this);
1417
2140
  this.webhooks = new Webhooks(this);
1418
2141
  this.migrate = new Migrate(this);
2142
+ this.dns = new DNS(this);
2143
+ this.domains = new Domains(this);
2144
+ this.registry = new Registry(this);
2145
+ this.iam = new IAM(this);
2146
+ this.certificates = new Certificates(this);
1419
2147
  }
1420
2148
  /**
1421
2149
  * Sends one request and returns its decoded body (undefined for an empty
@@ -1427,7 +2155,7 @@ var Pantech = class {
1427
2155
  const isWrite = req.method !== "GET";
1428
2156
  const headers = {
1429
2157
  ...this.#headers,
1430
- Accept: req.responseType === "arrayBuffer" ? "*/*" : "application/json",
2158
+ Accept: ACCEPT[req.responseType ?? "json"],
1431
2159
  ...options.headers,
1432
2160
  Authorization: `Bearer ${this.#apiKey}`
1433
2161
  };
@@ -1503,6 +2231,7 @@ function queryString(query) {
1503
2231
  async function readBody(res, type) {
1504
2232
  if (type === "response") return res;
1505
2233
  if (type === "arrayBuffer") return res.arrayBuffer();
2234
+ if (type === "text") return res.text();
1506
2235
  const text = await res.text();
1507
2236
  if (res.status === 204 || text === "") return void 0;
1508
2237
  try {
@@ -1558,6 +2287,59 @@ function linkSignal(parent, timeout) {
1558
2287
  };
1559
2288
  }
1560
2289
 
2290
+ // src/iam.ts
2291
+ var SID = /^[A-Za-z0-9_-]{1,64}$/;
2292
+ var MAX_ITEMS = 50;
2293
+ var MAX_SOURCE_IPS = 20;
2294
+ var MANAGED_POLICY_IDS = [
2295
+ "pol_pantech_read_only",
2296
+ "pol_pantech_developer",
2297
+ "pol_pantech_network_admin",
2298
+ "pol_pantech_database_admin",
2299
+ "pol_pantech_dns_manager",
2300
+ "pol_pantech_domain_manager",
2301
+ "pol_pantech_registry_push",
2302
+ "pol_pantech_registry_pull",
2303
+ "pol_pantech_billing_manager",
2304
+ "pol_pantech_support",
2305
+ "pol_pantech_deny_delete",
2306
+ "pol_pantech_require_mfa_for_writes"
2307
+ ];
2308
+ function strings(name, values, limit) {
2309
+ if (!Array.isArray(values)) throw new TypeError(`${name} must be an array of strings.`);
2310
+ if (values.length === 0) throw new RangeError(`${name} needs at least one entry.`);
2311
+ if (values.length > limit) throw new RangeError(`${name} takes at most ${limit} entries, got ${values.length}.`);
2312
+ for (const v of values) {
2313
+ if (typeof v !== "string" || v === "") throw new TypeError(`${name} entries must be non-empty strings.`);
2314
+ }
2315
+ return [...values];
2316
+ }
2317
+ function statement(effect, actions, resources = ["*"], options = {}) {
2318
+ if (effect !== "allow" && effect !== "deny") throw new TypeError(`effect must be "allow" or "deny".`);
2319
+ const out = {
2320
+ effect,
2321
+ actions: strings("actions", actions, MAX_ITEMS),
2322
+ resources: strings("resources", resources, MAX_ITEMS)
2323
+ };
2324
+ if (options.sid !== void 0) {
2325
+ if (!SID.test(options.sid)) throw new RangeError("sid must be 1 to 64 letters, digits, '_' or '-'.");
2326
+ out.sid = options.sid;
2327
+ }
2328
+ const conditions = {};
2329
+ if (options.sourceIp !== void 0) conditions.source_ip = strings("sourceIp", options.sourceIp, MAX_SOURCE_IPS);
2330
+ if (options.mfa !== void 0) conditions.mfa = options.mfa;
2331
+ if (Object.keys(conditions).length > 0) out.conditions = conditions;
2332
+ return out;
2333
+ }
2334
+ var iam = {
2335
+ /** An `allow` statement: `iam.allow(["instances:Start"], ["name:staging-*"])`. */
2336
+ allow: (actions, resources, options) => statement("allow", actions, resources, options),
2337
+ /** A `deny` statement, which wins over every allow: `iam.deny(["*:Delete"])`. */
2338
+ deny: (actions, resources, options) => statement("deny", actions, resources, options),
2339
+ statement,
2340
+ MANAGED_POLICY_IDS
2341
+ };
2342
+
1561
2343
  // src/webhooks.ts
1562
2344
  var WEBHOOK_SIGNATURE_HEADER = "Pantech-Signature";
1563
2345
  var DEFAULT_WEBHOOK_TOLERANCE_SECONDS = 300;
@@ -1635,10 +2417,16 @@ exports.APIConnectionError = APIConnectionError;
1635
2417
  exports.APITimeoutError = APITimeoutError;
1636
2418
  exports.AuthenticationError = AuthenticationError;
1637
2419
  exports.BadRequestError = BadRequestError;
2420
+ exports.CERTIFICATE_ERROR_CODES = CERTIFICATE_ERROR_CODES;
2421
+ exports.CertificateFailedError = CertificateFailedError;
1638
2422
  exports.CloudFailedError = CloudFailedError;
1639
2423
  exports.ConflictError = ConflictError;
1640
2424
  exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
1641
2425
  exports.DEFAULT_WEBHOOK_TOLERANCE_SECONDS = DEFAULT_WEBHOOK_TOLERANCE_SECONDS;
2426
+ exports.DNSFailedError = DNSFailedError;
2427
+ exports.DNS_ERROR_CODES = DNS_ERROR_CODES;
2428
+ exports.DOMAIN_ERROR_CODES = DOMAIN_ERROR_CODES;
2429
+ exports.IAM_ERROR_CODES = IAM_ERROR_CODES;
1642
2430
  exports.InternalServerError = InternalServerError;
1643
2431
  exports.NotFoundError = NotFoundError;
1644
2432
  exports.OperationFailedError = OperationFailedError;
@@ -1647,12 +2435,15 @@ exports.Pantech = Pantech;
1647
2435
  exports.PantechError = PantechError;
1648
2436
  exports.PaymentRequiredError = PaymentRequiredError;
1649
2437
  exports.PermissionDeniedError = PermissionDeniedError;
2438
+ exports.PreconditionFailedError = PreconditionFailedError;
2439
+ exports.REGISTRY_ERROR_CODES = REGISTRY_ERROR_CODES;
1650
2440
  exports.RateLimitError = RateLimitError;
1651
2441
  exports.VERSION = VERSION;
1652
2442
  exports.ValidationError = ValidationError;
1653
2443
  exports.WEBHOOK_SIGNATURE_HEADER = WEBHOOK_SIGNATURE_HEADER;
1654
2444
  exports.WaitTimeoutError = WaitTimeoutError;
1655
2445
  exports.WebhookVerificationError = WebhookVerificationError;
2446
+ exports.iam = iam;
1656
2447
  exports.isPantechError = isPantechError;
1657
2448
  exports.paginate = paginate;
1658
2449
  exports.signWebhook = signWebhook;