Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
d98c2f89c5 | |||
2b722816f6 | |||
91d58277dd | |||
2458da6754 | |||
d4379d19d3 | |||
b0fdd520f3 | |||
a746577945 | |||
bc4cae3333 | |||
e0614b5956 | |||
f568949085 | |||
bee256416f | |||
afa2679501 | |||
7838642fd5 | |||
7a992badf4 |
20
package-lock.json
generated
20
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/cloudflare",
|
"name": "@mojoio/cloudflare",
|
||||||
"version": "4.0.1",
|
"version": "5.0.2",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -348,9 +348,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@tsclass/tsclass": {
|
"@tsclass/tsclass": {
|
||||||
"version": "3.0.4",
|
"version": "3.0.7",
|
||||||
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-3.0.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@tsclass%2ftsclass/-/tsclass-3.0.7.tgz",
|
||||||
"integrity": "sha512-q9PnwBFDTTlwKp6jYn/tL6zhqWvwaKyGsf81xI8xcV6IhjmFo3hk0iM4L3ydw7iTwqR+WmhYaWO5WdMy3/KA+w==",
|
"integrity": "sha512-3s3pU0xrQsMpsvxby0eUgz6z3DpJTaRghLpoFSJ+uJMzi7n0QhwuEiydLbp1CgVvDnIByvQcN8LvU9q3tOswSA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/tapbundle": "^3.0.13"
|
"@pushrocks/tapbundle": "^3.0.13"
|
||||||
}
|
}
|
||||||
@ -429,9 +429,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "13.7.0",
|
"version": "13.7.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-13.7.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-13.7.2.tgz",
|
||||||
"integrity": "sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ=="
|
"integrity": "sha512-uvilvAQbdJvnSBFcKJ2td4016urcGvsiR+N4dHGU87ml8O2Vl6l+ErOi9w0kXSPiwJ1AYlIW+0pDXDWWMOiWbw=="
|
||||||
},
|
},
|
||||||
"@types/shortid": {
|
"@types/shortid": {
|
||||||
"version": "0.0.29",
|
"version": "0.0.29",
|
||||||
@ -933,9 +933,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"js-base64": {
|
"js-base64": {
|
||||||
"version": "2.5.1",
|
"version": "2.5.2",
|
||||||
"resolved": "https://verdaccio.lossless.one/js-base64/-/js-base64-2.5.1.tgz",
|
"resolved": "https://verdaccio.lossless.one/js-base64/-/js-base64-2.5.2.tgz",
|
||||||
"integrity": "sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw=="
|
"integrity": "sha512-Vg8czh0Q7sFBSUMWWArX/miJeBWYBPpdU/3M/DKSaekLMqrqVPaedp+5mZhie/r0lgrcaYBfwXatEew6gwgiQQ=="
|
||||||
},
|
},
|
||||||
"js-tokens": {
|
"js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/cloudflare",
|
"name": "@mojoio/cloudflare",
|
||||||
"version": "4.0.1",
|
"version": "5.0.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "easy cloudflare management",
|
"description": "easy cloudflare management",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartrequest": "^1.1.47",
|
"@pushrocks/smartrequest": "^1.1.47",
|
||||||
"@pushrocks/smartstring": "^3.0.18",
|
"@pushrocks/smartstring": "^3.0.18",
|
||||||
"@tsclass/tsclass": "^3.0.4"
|
"@tsclass/tsclass": "^3.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.17",
|
||||||
@ -37,7 +37,7 @@
|
|||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/qenv": "^4.0.6",
|
"@pushrocks/qenv": "^4.0.6",
|
||||||
"@pushrocks/tapbundle": "^3.2.0",
|
"@pushrocks/tapbundle": "^3.2.0",
|
||||||
"@types/node": "^13.7.0",
|
"@types/node": "^13.7.2",
|
||||||
"tslint": "^6.0.0",
|
"tslint": "^6.0.0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
|
@ -23,11 +23,7 @@ Use TypeScript for best in class instellisense.
|
|||||||
```javascript
|
```javascript
|
||||||
import * as cflare from '@mojoio/cloudflare';
|
import * as cflare from '@mojoio/cloudflare';
|
||||||
|
|
||||||
const myCflareAccount = new cflare.CflareAccount();
|
const myCflareAccount = new cflare.CflareAccount('mySuperAwesomeAccountToken');
|
||||||
testCflareAccount.auth({
|
|
||||||
email: 'someuser@example.com',
|
|
||||||
key: 'someLongApiKey'
|
|
||||||
});
|
|
||||||
|
|
||||||
const myAsyncCflareManagement = async () => {
|
const myAsyncCflareManagement = async () => {
|
||||||
// get things
|
// get things
|
||||||
|
@ -11,10 +11,7 @@ const randomPrefix = Math.floor(Math.random() * 2000);
|
|||||||
let testCloudflareAccount: cloudflare.CloudflareAccount;
|
let testCloudflareAccount: cloudflare.CloudflareAccount;
|
||||||
|
|
||||||
tap.test('should create a valid instance of CloudflareAccount', async () => {
|
tap.test('should create a valid instance of CloudflareAccount', async () => {
|
||||||
testCloudflareAccount = new cloudflare.CloudflareAccount({
|
testCloudflareAccount = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_KEY'));
|
||||||
email: testQenv.getEnvVarOnDemand('CF_EMAIL'),
|
|
||||||
key: testQenv.getEnvVarOnDemand('CF_KEY')
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('.listZones() -> should display an entire account', async tools => {
|
tap.test('.listZones() -> should display an entire account', async tools => {
|
||||||
@ -27,7 +24,7 @@ tap.test(
|
|||||||
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
|
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
|
||||||
async tools => {
|
async tools => {
|
||||||
tools.timeout(600000);
|
tools.timeout(600000);
|
||||||
await testCloudflareAccount.getZoneId('bleu.de');
|
await testCloudflareAccount.convenience.getZoneId('bleu.de');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ import { WorkerManager } from './cloudflare.classes.workermanager';
|
|||||||
import { ZoneManager } from './cloudflare.classes.zonemanager';
|
import { ZoneManager } from './cloudflare.classes.zonemanager';
|
||||||
|
|
||||||
export class CloudflareAccount {
|
export class CloudflareAccount {
|
||||||
private authEmail: string;
|
private authToken: string;
|
||||||
private authKey: string;
|
|
||||||
private accountIdentifier: string;
|
private accountIdentifier: string;
|
||||||
|
|
||||||
public workerManager = new WorkerManager(this);
|
public workerManager = new WorkerManager(this);
|
||||||
@ -17,9 +16,8 @@ export class CloudflareAccount {
|
|||||||
* constructor sets auth information on the CloudflareAccountInstance
|
* constructor sets auth information on the CloudflareAccountInstance
|
||||||
* @param optionsArg
|
* @param optionsArg
|
||||||
*/
|
*/
|
||||||
constructor(optionsArg: { email: string; key: string }) {
|
constructor(authTokenArg: string) {
|
||||||
this.authEmail = optionsArg.email;
|
this.authToken = authTokenArg;
|
||||||
this.authKey = optionsArg.key;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,28 +32,27 @@ export class CloudflareAccount {
|
|||||||
return this.accountIdentifier;
|
return this.accountIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* gets a zone id of a domain from cloudflare
|
|
||||||
* @param domainName
|
|
||||||
*/
|
|
||||||
public async getZoneId(domainName: string) {
|
|
||||||
const domain = new plugins.smartstring.Domain(domainName);
|
|
||||||
const zoneArray = await this.convenience.listZones(domain.zoneName);
|
|
||||||
const filteredResponse = zoneArray.filter(zoneArg => {
|
|
||||||
return zoneArg.name === domainName;
|
|
||||||
});
|
|
||||||
if (filteredResponse.length >= 1) {
|
|
||||||
return filteredResponse[0].id;
|
|
||||||
} else {
|
|
||||||
plugins.smartlog.defaultLogger.log(
|
|
||||||
'error',
|
|
||||||
`the domain ${domainName} does not appear to be in this account!`
|
|
||||||
);
|
|
||||||
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public convenience = {
|
public convenience = {
|
||||||
|
/**
|
||||||
|
* gets a zone id of a domain from cloudflare
|
||||||
|
* @param domainName
|
||||||
|
*/
|
||||||
|
getZoneId: async (domainName: string) => {
|
||||||
|
const domain = new plugins.smartstring.Domain(domainName);
|
||||||
|
const zoneArray = await this.convenience.listZones(domain.zoneName);
|
||||||
|
const filteredResponse = zoneArray.filter(zoneArg => {
|
||||||
|
return zoneArg.name === domainName;
|
||||||
|
});
|
||||||
|
if (filteredResponse.length >= 1) {
|
||||||
|
return filteredResponse[0].id;
|
||||||
|
} else {
|
||||||
|
plugins.smartlog.defaultLogger.log(
|
||||||
|
'error',
|
||||||
|
`the domain ${domainName} does not appear to be in this account!`
|
||||||
|
);
|
||||||
|
throw new Error(`the domain ${domainName} does not appear to be in this account!`);
|
||||||
|
}
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* gets a record
|
* gets a record
|
||||||
* @param domainNameArg
|
* @param domainNameArg
|
||||||
@ -63,7 +60,7 @@ export class CloudflareAccount {
|
|||||||
*/
|
*/
|
||||||
getRecord: async (
|
getRecord: async (
|
||||||
domainNameArg: string,
|
domainNameArg: string,
|
||||||
typeArg: plugins.tsclass.network.TDnsRecord
|
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
): Promise<interfaces.ICflareRecord> => {
|
): Promise<interfaces.ICflareRecord> => {
|
||||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
const recordArrayArg = await this.convenience.listRecords(domain.zoneName);
|
const recordArrayArg = await this.convenience.listRecords(domain.zoneName);
|
||||||
@ -77,11 +74,11 @@ export class CloudflareAccount {
|
|||||||
*/
|
*/
|
||||||
createRecord: async (
|
createRecord: async (
|
||||||
domainNameArg: string,
|
domainNameArg: string,
|
||||||
typeArg: plugins.tsclass.network.TDnsRecord,
|
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
contentArg: string
|
contentArg: string
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
const domainIdArg = await this.getZoneId(domain.zoneName);
|
const domainIdArg = await this.convenience.getZoneId(domain.zoneName);
|
||||||
const dataObject = {
|
const dataObject = {
|
||||||
name: domain.fullName,
|
name: domain.fullName,
|
||||||
type: typeArg,
|
type: typeArg,
|
||||||
@ -101,7 +98,7 @@ export class CloudflareAccount {
|
|||||||
*/
|
*/
|
||||||
removeRecord: async (
|
removeRecord: async (
|
||||||
domainNameArg: string,
|
domainNameArg: string,
|
||||||
typeArg: plugins.tsclass.network.TDnsRecord
|
typeArg: plugins.tsclass.network.TDnsRecordType
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
const cflareRecord = await this.convenience.getRecord(domain.fullName, typeArg);
|
const cflareRecord = await this.convenience.getRecord(domain.fullName, typeArg);
|
||||||
@ -115,13 +112,20 @@ export class CloudflareAccount {
|
|||||||
/**
|
/**
|
||||||
* cleanrecord allows the cleaning of any previous records to avoid unwanted sideeffects
|
* cleanrecord allows the cleaning of any previous records to avoid unwanted sideeffects
|
||||||
*/
|
*/
|
||||||
|
cleanRecord: async (domainNameArg: string, typeArg: plugins.tsclass.network.TDnsRecordType) => {
|
||||||
|
console.log(`cleaning record for ${domainNameArg}`);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* updates a record
|
* updates a record
|
||||||
* @param domainNameArg
|
* @param domainNameArg
|
||||||
* @param typeArg
|
* @param typeArg
|
||||||
* @param valueArg
|
* @param valueArg
|
||||||
*/
|
*/
|
||||||
updateRecord: async (domainNameArg: string, typeArg: string, valueArg) => {
|
updateRecord: async (
|
||||||
|
domainNameArg: string,
|
||||||
|
typeArg: plugins.tsclass.network.TDnsRecordType,
|
||||||
|
valueArg
|
||||||
|
) => {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
},
|
},
|
||||||
@ -131,7 +135,7 @@ export class CloudflareAccount {
|
|||||||
*/
|
*/
|
||||||
listRecords: async (domainNameArg: string): Promise<interfaces.ICflareRecord[]> => {
|
listRecords: async (domainNameArg: string): Promise<interfaces.ICflareRecord[]> => {
|
||||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||||
const domainId = await this.getZoneId(domain.zoneName);
|
const domainId = await this.convenience.getZoneId(domain.zoneName);
|
||||||
const responseArg: any = await this.request(
|
const responseArg: any = await this.request(
|
||||||
'GET',
|
'GET',
|
||||||
'/zones/' + domainId + '/dns_records?per_page=100'
|
'/zones/' + domainId + '/dns_records?per_page=100'
|
||||||
@ -161,7 +165,7 @@ export class CloudflareAccount {
|
|||||||
*/
|
*/
|
||||||
purgeZone: async (domainName: string): Promise<void> => {
|
purgeZone: async (domainName: string): Promise<void> => {
|
||||||
const domain = new plugins.smartstring.Domain(domainName);
|
const domain = new plugins.smartstring.Domain(domainName);
|
||||||
const domainId = await this.getZoneId(domain.zoneName);
|
const domainId = await this.convenience.getZoneId(domain.zoneName);
|
||||||
const requestUrl = `/zones/${domainId}/purge_cache`;
|
const requestUrl = `/zones/${domainId}/purge_cache`;
|
||||||
const payload = {
|
const payload = {
|
||||||
purge_everything: true
|
purge_everything: true
|
||||||
@ -170,7 +174,7 @@ export class CloudflareAccount {
|
|||||||
},
|
},
|
||||||
// acme convenience functions
|
// acme convenience functions
|
||||||
acmeSetDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
acmeSetDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
||||||
await this.convenience.removeRecord(dnsChallenge.hostName, 'TXT');
|
await this.convenience.cleanRecord(dnsChallenge.hostName, 'TXT');
|
||||||
await this.convenience.createRecord(dnsChallenge.hostName, 'TXT', dnsChallenge.challenge);
|
await this.convenience.createRecord(dnsChallenge.hostName, 'TXT', dnsChallenge.challenge);
|
||||||
},
|
},
|
||||||
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
|
||||||
@ -178,47 +182,89 @@ export class CloudflareAccount {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public request(
|
public async request(
|
||||||
methodArg: string,
|
methodArg: string,
|
||||||
routeArg: string,
|
routeArg: string,
|
||||||
dataArg: any = {},
|
dataArg: any = {},
|
||||||
requestHeadersArg = {}
|
requestHeadersArg = {}
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const done = plugins.smartpromise.defer();
|
|
||||||
const options: plugins.smartrequest.ISmartRequestOptions = {
|
const options: plugins.smartrequest.ISmartRequestOptions = {
|
||||||
method: methodArg,
|
method: methodArg,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'X-Auth-Email': this.authEmail,
|
Authorization: `Bearer ${this.authToken}`,
|
||||||
'X-Auth-Key': this.authKey,
|
|
||||||
'Content-Length': Buffer.byteLength(JSON.stringify(dataArg)),
|
'Content-Length': Buffer.byteLength(JSON.stringify(dataArg)),
|
||||||
...requestHeadersArg
|
...requestHeadersArg
|
||||||
},
|
},
|
||||||
requestBody: dataArg
|
requestBody: dataArg
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// route analysis
|
||||||
|
const routeWithoutQuery = routeArg.split('?')[0];
|
||||||
|
let queryParams: string[] = [];
|
||||||
|
if (routeArg.split('?').length > 1) {
|
||||||
|
queryParams = routeArg.split('?')[1].split('&');
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(options);
|
// console.log(options);
|
||||||
|
|
||||||
let retryCount = 0; // count the amount of retries
|
let retryCount = 0; // count the amount of retries
|
||||||
|
let pageCount = 1;
|
||||||
|
|
||||||
const makeRequest = async () => {
|
const getQueryParams = () => {
|
||||||
const response: any = await plugins.smartrequest.request(
|
let result = '';
|
||||||
`https://api.cloudflare.com/client/v4${routeArg}`,
|
if (queryParams.length > 0) {
|
||||||
options
|
result += '?';
|
||||||
);
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
let isFirst = true;
|
||||||
|
for (const queryParam of queryParams) {
|
||||||
|
if (!isFirst) {
|
||||||
|
result += '&';
|
||||||
|
}
|
||||||
|
isFirst = false;
|
||||||
|
const queryParamSerialized = queryParam.split('=');
|
||||||
|
if (queryParam === 'page') {
|
||||||
|
result += `page=${pageCount}`;
|
||||||
|
} else {
|
||||||
|
result += queryParam;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const makeRequest = async (): Promise<plugins.smartrequest.IExtendedIncomingMessage> => {
|
||||||
|
const requestUrl = `https://api.cloudflare.com/client/v4${routeWithoutQuery}${getQueryParams()}`;
|
||||||
|
const response = await plugins.smartrequest.request(requestUrl, options);
|
||||||
if (response.statusCode === 200) {
|
if (response.statusCode === 200) {
|
||||||
done.resolve(response.body);
|
if (response.body.result_info) {
|
||||||
|
const rI = response.body.result_info;
|
||||||
|
if (rI.total_count / rI.per_page > pageCount) {
|
||||||
|
pageCount++;
|
||||||
|
const subresponse = await makeRequest();
|
||||||
|
response.body.result = response.body.result.concat(subresponse.body.result);
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
} else if (response.statusCode === 429) {
|
} else if (response.statusCode === 429) {
|
||||||
console.log('rate limited! Waiting for retry!');
|
console.log('rate limited! Waiting for retry!');
|
||||||
retryRequest();
|
return await retryRequest();
|
||||||
} else if (response.statusCode === 400) {
|
} else if (response.statusCode === 400) {
|
||||||
console.log(`bad request for route ${routeArg}! Going to retry!`);
|
console.log(`bad request for route ${requestUrl}!`);
|
||||||
console.log(response.body);
|
console.log(response.body);
|
||||||
|
throw new Error(`request failed for ${requestUrl}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(response.statusCode);
|
console.log(response.statusCode);
|
||||||
done.reject(new Error('request failed'));
|
throw Error('request failed');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const retryRequest = async (
|
const retryRequest = async (
|
||||||
delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)
|
delayTimeArg = Math.floor(Math.random() * (60000 - 8000) + 8000)
|
||||||
) => {
|
) => {
|
||||||
@ -229,11 +275,11 @@ export class CloudflareAccount {
|
|||||||
return await makeRequest();
|
return await makeRequest();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
makeRequest();
|
const response = await makeRequest();
|
||||||
return done.promise;
|
return response.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
private authCheck() {
|
private authCheck() {
|
||||||
return this.authEmail && this.authKey; // check if auth is available
|
return !!this.authToken; // check if auth is available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
import * as plugins from './cloudflare.plugins';
|
||||||
|
|
||||||
|
export class CloudflareRecord {
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -73,14 +73,14 @@ export class CloudflareWorker {
|
|||||||
|
|
||||||
// lets care about actually setting routes
|
// lets care about actually setting routes
|
||||||
if (routeStatus === 'new') {
|
if (routeStatus === 'new') {
|
||||||
const zoneId = await this.workerManager.cfAccount.getZoneId(newRoute.zoneName);
|
const zoneId = await this.workerManager.cfAccount.convenience.getZoneId(newRoute.zoneName);
|
||||||
const requestRoute = `/zones/${zoneId}/workers/routes`;
|
const requestRoute = `/zones/${zoneId}/workers/routes`;
|
||||||
await this.workerManager.cfAccount.request('POST', requestRoute, {
|
await this.workerManager.cfAccount.request('POST', requestRoute, {
|
||||||
pattern: newRoute.pattern,
|
pattern: newRoute.pattern,
|
||||||
script: this.id
|
script: this.id
|
||||||
});
|
});
|
||||||
} else if (routeStatus === 'needsUpdate') {
|
} else if (routeStatus === 'needsUpdate') {
|
||||||
const zoneId = await this.workerManager.cfAccount.getZoneId(newRoute.zoneName);
|
const zoneId = await this.workerManager.cfAccount.convenience.getZoneId(newRoute.zoneName);
|
||||||
const requestRoute = `/zones/${zoneId}/workers/routes/${routeIdForUpdate}`;
|
const requestRoute = `/zones/${zoneId}/workers/routes/${routeIdForUpdate}`;
|
||||||
await this.workerManager.cfAccount.request('PUT', requestRoute, {
|
await this.workerManager.cfAccount.request('PUT', requestRoute, {
|
||||||
pattern: newRoute.pattern,
|
pattern: newRoute.pattern,
|
||||||
|
@ -1,6 +1,51 @@
|
|||||||
import * as plugins from './cloudflare.plugins';
|
import * as plugins from './cloudflare.plugins';
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
export class CloudflareZone {
|
export class CloudflareZone implements interfaces.ICflareZone {
|
||||||
public static async createFromApiObject() {}
|
public static createFromApiObject(apiObject: interfaces.ICflareZone) {
|
||||||
|
const cloudflareZone = new CloudflareZone();
|
||||||
|
Object.assign(cloudflareZone, apiObject);
|
||||||
|
return cloudflareZone;
|
||||||
|
}
|
||||||
|
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
development_mode: number;
|
||||||
|
original_name_servers: string[];
|
||||||
|
original_registrar: string;
|
||||||
|
original_dnshost: string;
|
||||||
|
created_on: string;
|
||||||
|
modified_on: string;
|
||||||
|
name_servers: string[];
|
||||||
|
owner: {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
owner_type: string;
|
||||||
|
};
|
||||||
|
permissions: string[];
|
||||||
|
plan: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
currency: string;
|
||||||
|
frequency: string;
|
||||||
|
legacy_id: string;
|
||||||
|
is_subscribed: boolean;
|
||||||
|
can_subscribe: boolean;
|
||||||
|
};
|
||||||
|
plan_pending: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
price: number;
|
||||||
|
currency: string;
|
||||||
|
frequency: string;
|
||||||
|
legacy_id: string;
|
||||||
|
is_subscribed: string;
|
||||||
|
can_subscribe: string;
|
||||||
|
};
|
||||||
|
status: string;
|
||||||
|
paused: boolean;
|
||||||
|
type: string;
|
||||||
|
checked_on: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import * as plugins from './cloudflare.plugins';
|
import * as plugins from './cloudflare.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
import { CloudflareAccount } from './cloudflare.classes.account';
|
import { CloudflareAccount } from './cloudflare.classes.account';
|
||||||
|
import { CloudflareZone } from './cloudflare.classes.zone';
|
||||||
|
|
||||||
export class ZoneManager {
|
export class ZoneManager {
|
||||||
public cfAccount: CloudflareAccount;
|
public cfAccount: CloudflareAccount;
|
||||||
@ -9,5 +11,22 @@ export class ZoneManager {
|
|||||||
this.cfAccount = cfAccountArg;
|
this.cfAccount = cfAccountArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getZones() {}
|
public async getZones(zoneName: string) {
|
||||||
|
let requestRoute = `/zones?per_page=50`;
|
||||||
|
// may be optionally filtered by domain name
|
||||||
|
|
||||||
|
if (zoneName) {
|
||||||
|
requestRoute = `${requestRoute}&name=${zoneName}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response: any = await this.cfAccount.request('GET', requestRoute);
|
||||||
|
const apiObjects: interfaces.ICflareZone[] = response.result;
|
||||||
|
|
||||||
|
const cloudflareZoneArray = [];
|
||||||
|
for (const apiObject of apiObjects) {
|
||||||
|
cloudflareZoneArray.push(CloudflareZone.createFromApiObject(apiObject));
|
||||||
|
}
|
||||||
|
|
||||||
|
return cloudflareZoneArray;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user