From ad43998daeaaf0d8988d47663d202c41064ca805 Mon Sep 17 00:00:00 2001 From: Wilson Lin <125257432+wilson-dnsimple@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:03:25 +1000 Subject: [PATCH] Add support for domain transfer lock APIs (#183) --- CHANGELOG.md | 1 + lib/registrar.ts | 78 +++++++++++++++++++ lib/types.ts | 2 + .../disableDomainTransferLock/success.http | 20 +++++ .../enableDomainTransferLock/success.http | 20 +++++ .../getDomainTransferLock/success.http | 20 +++++ test/registrar_domain_transfer_lock.spec.ts | 75 ++++++++++++++++++ 7 files changed, 216 insertions(+) create mode 100644 test/fixtures.http/disableDomainTransferLock/success.http create mode 100644 test/fixtures.http/enableDomainTransferLock/success.http create mode 100644 test/fixtures.http/getDomainTransferLock/success.http create mode 100644 test/registrar_domain_transfer_lock.spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index faa9b7f..3355ac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ FEATURES: - NEW: Added `listRegistrantChanges`, `createRegistrantChange`, `checkRegistrantChange`, `getRegistrantChange`, and `deleteRegistrantChange` APIs to manage registrant changes. (dnsimple/dnsimple-node#181) +- NEW: Added `getDomainTransferLock`, `enableDomainTransferLock`, `disableDomainTransferLock` APIs to manage domain transfer locks. (dnsimple/dnsimple-node#183) ## 7.1.1 diff --git a/lib/registrar.ts b/lib/registrar.ts index 8612792..67dbc00 100644 --- a/lib/registrar.ts +++ b/lib/registrar.ts @@ -764,4 +764,82 @@ export class Registrar { ); return method; })(); + + /** + * Gets the transfer lock status for a domain. + * + * GET /{account}/registrar/domains/{domain}/transfer_lock + * + * @see https://developer.dnsimple.com/v2/registrar/#getDomainTransferLock + * + * @param account The account id + * @param domain The domain name or id + * @param params Query parameters + */ + getDomainTransferLock = (() => { + const method = ( + account: number, + domain: string, + params: QueryParams & {} = {} + ): Promise<{ data: types.DomainTransferLock }> => + this._client.request( + "GET", + `/${account}/registrar/domains/${domain}/transfer_lock`, + null, + params + ); + return method; + })(); + + /** + * Locks the domain to prevent unauthorized transfers. + * + * POST /{account}/registrar/domains/{domain}/transfer_lock + * + * @see https://developer.dnsimple.com/v2/registrar/#enableDomainTransferLock + * + * @param account The account id + * @param domain The domain name or id + * @param params Query parameters + */ + enableDomainTransferLock = (() => { + const method = ( + account: number, + domain: string, + params: QueryParams & {} = {} + ): Promise<{ data: types.DomainTransferLock }> => + this._client.request( + "POST", + `/${account}/registrar/domains/${domain}/transfer_lock`, + null, + params + ); + return method; + })(); + + /** + * Unlocks the domain to allow domain transfers. + * + * DELETE /{account}/registrar/domains/{domain}/transfer_lock + * + * @see https://developer.dnsimple.com/v2/registrar/#disableDomainTransferLock + * + * @param account The account id + * @param domain The domain name or id + * @param params Query parameters + */ + disableDomainTransferLock = (() => { + const method = ( + account: number, + domain: string, + params: QueryParams & {} = {} + ): Promise<{ data: types.DomainTransferLock }> => + this._client.request( + "DELETE", + `/${account}/registrar/domains/${domain}/transfer_lock`, + null, + params + ); + return method; + })(); } diff --git a/lib/types.ts b/lib/types.ts index 2991d00..20861c8 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -448,3 +448,5 @@ export type RegistrantChangeCheck = { extended_attributes: Array; registry_owner_change: boolean; }; + +export type DomainTransferLock = { enabled: boolean }; diff --git a/test/fixtures.http/disableDomainTransferLock/success.http b/test/fixtures.http/disableDomainTransferLock/success.http new file mode 100644 index 0000000..d562c1e --- /dev/null +++ b/test/fixtures.http/disableDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":false}} diff --git a/test/fixtures.http/enableDomainTransferLock/success.http b/test/fixtures.http/enableDomainTransferLock/success.http new file mode 100644 index 0000000..e90c83c --- /dev/null +++ b/test/fixtures.http/enableDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 201 Created +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":true}} diff --git a/test/fixtures.http/getDomainTransferLock/success.http b/test/fixtures.http/getDomainTransferLock/success.http new file mode 100644 index 0000000..f93ffb3 --- /dev/null +++ b/test/fixtures.http/getDomainTransferLock/success.http @@ -0,0 +1,20 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Tue, 15 Aug 2023 09:58:37 GMT +Content-Type: application/json; charset=utf-8 +Connection: keep-alive +X-RateLimit-Limit: 2400 +X-RateLimit-Remaining: 2398 +X-RateLimit-Reset: 1488538623 +ETag: W/"fc2368a31a1b6a3afcca33bb37ff6b9d" +Cache-Control: max-age=0, private, must-revalidate +X-Request-Id: 8b0fe49a-c810-4552-84ab-a1cd9b4a7786 +X-Runtime: 0.024780 +X-Content-Type-Options: nosniff +X-Download-Options: noopen +X-Frame-Options: DENY +X-Permitted-Cross-Domain-Policies: none +X-XSS-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 + +{"data":{"enabled":true}} diff --git a/test/registrar_domain_transfer_lock.spec.ts b/test/registrar_domain_transfer_lock.spec.ts new file mode 100644 index 0000000..f547356 --- /dev/null +++ b/test/registrar_domain_transfer_lock.spec.ts @@ -0,0 +1,75 @@ +import { expect } from "chai"; +import * as nock from "nock"; +import { createTestClient, loadFixture } from "./util"; + +const dnsimple = createTestClient(); + +describe("domain transfer lock", () => { + const accountId = 1010; + + describe("#getDomainTransferLock", () => { + const fixture = loadFixture("getDomainTransferLock/success.http"); + + it("produces a transfer lock", (done) => { + nock("https://api.dnsimple.com") + .get("/v2/1010/registrar/domains/101/transfer_lock") + .reply(fixture.statusCode, fixture.body); + + dnsimple.registrar.getDomainTransferLock(accountId, "101").then( + ({ data }) => { + expect(data).to.deep.eq({ + enabled: true, + }); + done(); + }, + (error) => { + done(error); + } + ); + }); + }); + + describe("#enableDomainTransferLock", () => { + const fixture = loadFixture("enableDomainTransferLock/success.http"); + + it("produces a transfer lock", (done) => { + nock("https://api.dnsimple.com") + .post("/v2/1010/registrar/domains/101/transfer_lock") + .reply(fixture.statusCode, fixture.body); + + dnsimple.registrar.enableDomainTransferLock(accountId, "101").then( + ({ data }) => { + expect(data).to.deep.eq({ + enabled: true, + }); + done(); + }, + (error) => { + done(error); + } + ); + }); + }); + + describe("#disableDomainTransferLock", () => { + const fixture = loadFixture("disableDomainTransferLock/success.http"); + + it("produces a transfer lock", (done) => { + nock("https://api.dnsimple.com") + .delete("/v2/1010/registrar/domains/101/transfer_lock") + .reply(fixture.statusCode, fixture.body); + + dnsimple.registrar.disableDomainTransferLock(accountId, "101").then( + ({ data }) => { + expect(data).to.deep.eq({ + enabled: false, + }); + done(); + }, + (error) => { + done(error); + } + ); + }); + }); +});