Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for domain transfer lock APIs #183

Merged
3 commits merged into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
78 changes: 78 additions & 0 deletions lib/registrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})();
}
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,3 +448,5 @@ export type RegistrantChangeCheck = {
extended_attributes: Array<ExtendedAttribute>;
registry_owner_change: boolean;
};

export type DomainTransferLock = { enabled: boolean };
20 changes: 20 additions & 0 deletions test/fixtures.http/disableDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
20 changes: 20 additions & 0 deletions test/fixtures.http/enableDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
20 changes: 20 additions & 0 deletions test/fixtures.http/getDomainTransferLock/success.http
Original file line number Diff line number Diff line change
@@ -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}}
75 changes: 75 additions & 0 deletions test/registrar_domain_transfer_lock.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
}
);
});
});
});