Compare commits

..

14 Commits

Author SHA1 Message Date
bee256416f 4.0.3 2020-02-10 14:40:56 +00:00
afa2679501 fix(core): update 2020-02-10 14:40:55 +00:00
7838642fd5 4.0.2 2020-02-10 14:38:45 +00:00
7a992badf4 fix(core): update 2020-02-10 14:38:44 +00:00
c65790e2f9 4.0.1 2020-02-10 11:26:13 +00:00
7ec0fe78fc fix(core): update 2020-02-10 11:26:13 +00:00
12f4456ebd 4.0.0 2020-02-09 18:22:35 +00:00
3e8cf73877 BREAKING CHANGE(API): move to .convenience property 2020-02-09 18:22:34 +00:00
0032292714 3.0.7 2020-02-09 17:54:34 +00:00
ead87ceb63 fix(core): update 2020-02-09 17:54:33 +00:00
04d70a4d12 3.0.6 2020-02-09 17:36:30 +00:00
8da43a79d3 fix(core): update 2020-02-09 17:36:29 +00:00
3153021190 3.0.5 2019-07-19 12:39:40 +02:00
82701c19e7 fix(core): update 2019-07-19 12:39:39 +02:00
17 changed files with 748 additions and 817 deletions

View File

@ -4,13 +4,13 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache: cache:
paths: paths:
- .npmci_cache/ - .npmci_cache/
key: "$CI_BUILD_STAGE" key: '$CI_BUILD_STAGE'
stages: stages:
- security - security
- test - test
- release - release
- metadata - metadata
# ==================== # ====================
# security stage # security stage
@ -20,17 +20,19 @@ mirror:
script: script:
- npmci git mirror - npmci git mirror
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
snyk: snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -38,38 +40,41 @@ snyk:
# test stage # test stage
# ==================== # ====================
testLTS: testStable:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv - priv
testBuild: testBuild:
stage: test stage: test
script: script:
- npmci npm prepare - npmci npm prepare
- npmci node install lts - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
release: release:
stage: release stage: release
script: script:
- npmci node install lts - npmci node install stable
- npmci npm publish - npmci npm publish
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
@ -81,9 +86,11 @@ codequality:
allow_failure: true allow_failure: true
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts" - npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless
- docker - docker
- priv - priv
@ -94,18 +101,20 @@ trigger:
only: only:
- tags - tags
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata stage: metadata
script: script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc - npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command tsdoc
tags: tags:
- lossless
- docker - docker
- notpriv - notpriv
only: only:

29
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"request": "launch",
"args": [
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
}
}
}
}
}
}
]
}

View File

@ -4,6 +4,7 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "mojoio", "gitscope": "mojoio",

1038
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/cloudflare", "name": "@mojoio/cloudflare",
"version": "3.0.4", "version": "4.0.3",
"private": false, "private": false,
"description": "easy cloudflare management", "description": "easy cloudflare management",
"main": "dist/index.js", "main": "dist/index.js",
@ -24,30 +24,30 @@
}, },
"homepage": "https://gitlab.com/pushrocks/cflare#readme", "homepage": "https://gitlab.com/pushrocks/cflare#readme",
"dependencies": { "dependencies": {
"@pushrocks/smartdelay": "^2.0.3", "@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartlog": "^2.0.19", "@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartpromise": "^3.0.2", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.16", "@pushrocks/smartrequest": "^1.1.47",
"@pushrocks/smartstring": "^3.0.10", "@pushrocks/smartstring": "^3.0.18",
"@tsclass/tsclass": "^2.0.1" "@tsclass/tsclass": "^3.0.4"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.11", "@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.24", "@gitzone/tstest": "^1.0.28",
"@pushrocks/qenv": "^4.0.0", "@pushrocks/qenv": "^4.0.6",
"@pushrocks/tapbundle": "^3.0.11", "@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^12.6.6", "@types/node": "^13.7.0",
"tslint": "^5.18.0", "tslint": "^6.0.0",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/*", "ts/**/*",
"ts_web/*", "ts_web/**/*",
"dist/*", "dist/**/*",
"dist_web/*", "dist_web/**/*",
"dist_ts_web/*", "dist_ts_web/**/*",
"assets/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"

View File

@ -8,7 +8,7 @@ easy cloudflare management
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/) * [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
## Status for master ## Status for master
[![build status](https://gitlab.com/mojoio/cloudflare/badges/master/build.svg)](https://gitlab.com/mojoio/cloudflare/commits/master) [![pipeline status](https://gitlab.com/mojoio/cloudflare/badges/master/pipeline.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
[![coverage report](https://gitlab.com/mojoio/cloudflare/badges/master/coverage.svg)](https://gitlab.com/mojoio/cloudflare/commits/master) [![coverage report](https://gitlab.com/mojoio/cloudflare/badges/master/coverage.svg)](https://gitlab.com/mojoio/cloudflare/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/cloudflare.svg)](https://www.npmjs.com/package/@mojoio/cloudflare) [![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/cloudflare.svg)](https://www.npmjs.com/package/@mojoio/cloudflare)
[![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/cloudflare/badge.svg)](https://snyk.io/test/npm/@mojoio/cloudflare) [![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/cloudflare/badge.svg)](https://snyk.io/test/npm/@mojoio/cloudflare)
@ -21,30 +21,29 @@ easy cloudflare management
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
```javascript ```javascript
import * as cflare from 'cflare' import * as cflare from '@mojoio/cloudflare';
let myCflareAccount = new cflare.CflareAccount() const myCflareAccount = new cflare.CflareAccount();
testCflareAccount.auth({ testCflareAccount.auth({
email: 'someuser@example.com', email: 'someuser@example.com',
key: 'someLongApiKey' key: 'someLongApiKey'
}) });
let myAsyncCflareManagement = async () => { const myAsyncCflareManagement = async () => {
// get things // get things
let myZones = await myCflareAccount.listZones() // zones are fully typed const myZones = await myCflareAccount.listZones(); // zones are fully typed
let myIdForADomain = await myCflareAccount.getZoneId('example.com') // type number const myIdForADomain = await myCflareAccount.getZoneId('example.com'); // type number
let myRecordsForADomain = await myCflareAccount.listRecords('example.com') // records are fully typed const myRecordsForADomain = await myCflareAccount.listRecords('example.com'); // records are fully typed
};
// set things
myCflareAccount.updateRecord(...)
myCflareAccount.createRecord(...)
myCflareAccount.deleteRecord(...)
}
``` ```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) > MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -17,11 +17,9 @@ tap.test('should create a valid instance of CloudflareAccount', async () => {
}); });
}); });
tap.test('.listZones() -> should display an entire account', async tools => {
tap.skip.test('.listZones() -> should display an entire account', async tools => {
tools.timeout(600000); tools.timeout(600000);
const result = await testCloudflareAccount.listZones(); const result = await testCloudflareAccount.convenience.listZones();
console.log(result); console.log(result);
}); });
@ -37,7 +35,7 @@ tap.test(
'.listRecords(domainName) -> should list all records for a specific Domain Name', '.listRecords(domainName) -> should list all records for a specific Domain Name',
async tools => { async tools => {
tools.timeout(600000); tools.timeout(600000);
await testCloudflareAccount.listRecords('bleu.de').then(async responseArg => { await testCloudflareAccount.convenience.listRecords('bleu.de').then(async responseArg => {
console.log(responseArg); console.log(responseArg);
}); });
} }
@ -45,19 +43,25 @@ tap.test(
tap.test('should create a valid record for a subdomain', async tools => { tap.test('should create a valid record for a subdomain', async tools => {
tools.timeout(600000); tools.timeout(600000);
await testCloudflareAccount.createRecord(`${randomPrefix}subdomain.bleu.de`, 'A', '127.0.0.1'); await testCloudflareAccount.convenience.createRecord(
`${randomPrefix}subdomain.bleu.de`,
'A',
'127.0.0.1'
);
}); });
tap.test('should get a record from Cloudflare', async tools => { tap.test('should get a record from Cloudflare', async tools => {
tools.timeout(600000); tools.timeout(600000);
await testCloudflareAccount.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A').then(responseArg => { await testCloudflareAccount.convenience
.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(responseArg => {
console.log(responseArg); console.log(responseArg);
}); });
}); });
tap.test('should remove a subdomain record from Cloudflare', async tools => { tap.test('should remove a subdomain record from Cloudflare', async tools => {
tools.timeout(600000); tools.timeout(600000);
await testCloudflareAccount await testCloudflareAccount.convenience
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A') .removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(async responseArg => { .then(async responseArg => {
console.log(responseArg); console.log(responseArg);
@ -65,12 +69,15 @@ tap.test('should remove a subdomain record from Cloudflare', async tools => {
}); });
tap.test('.purge(some.domain) -> should purge everything', async () => { tap.test('.purge(some.domain) -> should purge everything', async () => {
await testCloudflareAccount.purgeZone('bleu.de'); await testCloudflareAccount.convenience.purgeZone('bleu.de');
}); });
// WORKERS // WORKERS
tap.test('should create a worker', async () => { tap.test('should create a worker', async () => {
const worker = await testCloudflareAccount.workerManager.createWorker('myawesomescript', `addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`); const worker = await testCloudflareAccount.workerManager.createWorker(
'myawesomescript',
`addEventListener('fetch', event => { event.respondWith(fetch(event.request)) })`
);
await worker.setRoutes([ await worker.setRoutes([
{ {
zoneName: 'bleu.de', zoneName: 'bleu.de',

View File

@ -2,7 +2,6 @@ import plugins = require('./cloudflare.plugins');
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
// interfaces // interfaces
import { TDnsRecord } from '@tsclass/tsclass';
import { WorkerManager } from './cloudflare.classes.workermanager'; import { WorkerManager } from './cloudflare.classes.workermanager';
import { ZoneManager } from './cloudflare.classes.zonemanager'; import { ZoneManager } from './cloudflare.classes.zonemanager';
@ -23,12 +22,14 @@ export class CloudflareAccount {
this.authKey = optionsArg.key; this.authKey = optionsArg.key;
} }
/**
* gets you the account identifier
*/
public async getAccountIdentifier() { public async getAccountIdentifier() {
if (!this.accountIdentifier) { if (!this.accountIdentifier) {
const route = `/accounts?page=1&per_page=20&direction=desc`; const route = `/accounts?page=1&per_page=20&direction=desc`;
const response: any = await this.request('GET', route); const response: any = await this.request('GET', route);
this.accountIdentifier = response.result[0].id; this.accountIdentifier = response.result[0].id;
// console.log('Account identifier is: ' + this.accountIdentifier);
} }
return this.accountIdentifier; return this.accountIdentifier;
} }
@ -39,7 +40,7 @@ export class CloudflareAccount {
*/ */
public async getZoneId(domainName: string) { public async getZoneId(domainName: string) {
const domain = new plugins.smartstring.Domain(domainName); const domain = new plugins.smartstring.Domain(domainName);
const zoneArray = await this.listZones(domain.zoneName); const zoneArray = await this.convenience.listZones(domain.zoneName);
const filteredResponse = zoneArray.filter(zoneArg => { const filteredResponse = zoneArray.filter(zoneArg => {
return zoneArg.name === domainName; return zoneArg.name === domainName;
}); });
@ -54,28 +55,31 @@ export class CloudflareAccount {
} }
} }
public convenience = {
/** /**
* gets a record * gets a record
* @param domainNameArg * @param domainNameArg
* @param typeArg * @param typeArg
*/ */
public async getRecord( getRecord: async (
domainNameArg: string, domainNameArg: string,
typeArg: TDnsRecord typeArg: plugins.tsclass.network.TDnsRecord
): Promise<interfaces.ICflareRecord> { ): Promise<interfaces.ICflareRecord> => {
const domain = new plugins.smartstring.Domain(domainNameArg); const domain = new plugins.smartstring.Domain(domainNameArg);
const recordArrayArg = await this.listRecords(domain.zoneName); const recordArrayArg = await this.convenience.listRecords(domain.zoneName);
const filteredResponse = recordArrayArg.filter(recordArg => { const filteredResponse = recordArrayArg.filter(recordArg => {
return recordArg.type === typeArg && recordArg.name === domainNameArg; return recordArg.type === typeArg && recordArg.name === domainNameArg;
}); });
return filteredResponse[0]; return filteredResponse[0];
} },
/**
public async createRecord( * creates a record
*/
createRecord: async (
domainNameArg: string, domainNameArg: string,
typeArg: TDnsRecord, typeArg: plugins.tsclass.network.TDnsRecord,
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.getZoneId(domain.zoneName);
const dataObject = { const dataObject = {
@ -89,42 +93,46 @@ export class CloudflareAccount {
dataObject dataObject
); );
return response; return response;
} },
/** /**
* removes a record from Cloudflare * removes a record from Cloudflare
* @param domainNameArg * @param domainNameArg
* @param typeArg * @param typeArg
*/ */
public async removeRecord(domainNameArg: string, typeArg: TDnsRecord): Promise<any> { removeRecord: async (
domainNameArg: string,
typeArg: plugins.tsclass.network.TDnsRecord
): Promise<any> => {
const domain = new plugins.smartstring.Domain(domainNameArg); const domain = new plugins.smartstring.Domain(domainNameArg);
const cflareRecord = await this.getRecord(domain.fullName, typeArg); const cflareRecord = await this.convenience.getRecord(domain.fullName, typeArg);
if (cflareRecord) { if (cflareRecord) {
const requestRoute: string = `/zones/${cflareRecord.zone_id}/dns_records/${cflareRecord.id}`; const requestRoute: string = `/zones/${cflareRecord.zone_id}/dns_records/${cflareRecord.id}`;
return await this.request('DELETE', requestRoute); return await this.request('DELETE', requestRoute);
} else { } else {
throw new Error(`could not remove record for ${domainNameArg} with type ${typeArg}`); throw new Error(`could not remove record for ${domainNameArg} with type ${typeArg}`);
} }
} },
/**
* cleanrecord allows the cleaning of any previous records to avoid unwanted sideeffects
*/
cleanRecord: async (domainNameArg: string, typeArg: plugins.tsclass.network.TDnsRecord) => {
},
/** /**
* updates a record * updates a record
* @param domainNameArg * @param domainNameArg
* @param typeArg * @param typeArg
* @param valueArg * @param valueArg
*/ */
public updateRecord(domainNameArg: string, typeArg: string, valueArg) { updateRecord: async (domainNameArg: string, typeArg: plugins.tsclass.network.TDnsRecord, valueArg) => {
// TODO: implement // TODO: implement
const done = plugins.smartpromise.defer();
const domain = new plugins.smartstring.Domain(domainNameArg); const domain = new plugins.smartstring.Domain(domainNameArg);
return done.promise; },
}
/** /**
* list all records of a specified domain name * list all records of a specified domain name
* @param domainNameArg - the domain name that you want to get the records from * @param domainNameArg - the domain name that you want to get the records from
*/ */
public async listRecords(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.getZoneId(domain.zoneName);
const responseArg: any = await this.request( const responseArg: any = await this.request(
@ -133,13 +141,12 @@ export class CloudflareAccount {
); );
const result: interfaces.ICflareRecord[] = responseArg.result; const result: interfaces.ICflareRecord[] = responseArg.result;
return result; return result;
} },
/** /**
* list all zones in the associated authenticated account * list all zones in the associated authenticated account
* @param domainName * @param domainName
*/ */
public async listZones(domainName?: string): Promise<interfaces.ICflareZone[]> { listZones: async (domainName?: string): Promise<interfaces.ICflareZone[]> => {
// TODO: handle pagination // TODO: handle pagination
let requestRoute = `/zones?per_page=50`; let requestRoute = `/zones?per_page=50`;
@ -151,9 +158,11 @@ export class CloudflareAccount {
const response: any = await this.request('GET', requestRoute); const response: any = await this.request('GET', requestRoute);
const result = response.result; const result = response.result;
return result; return result;
} },
/**
public async purgeZone(domainName: string) { * purges a zone
*/
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.getZoneId(domain.zoneName);
const requestUrl = `/zones/${domainId}/purge_cache`; const requestUrl = `/zones/${domainId}/purge_cache`;
@ -161,7 +170,16 @@ export class CloudflareAccount {
purge_everything: true purge_everything: true
}; };
const respone = await this.request('DELETE', requestUrl, payload); const respone = await this.request('DELETE', requestUrl, payload);
},
// acme convenience functions
acmeSetDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
await this.convenience.cleanRecord(dnsChallenge.hostName, 'TXT');
await this.convenience.createRecord(dnsChallenge.hostName, 'TXT', dnsChallenge.challenge);
},
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
await this.convenience.removeRecord(dnsChallenge.hostName, 'TXT');
} }
};
public request( public request(
methodArg: string, methodArg: string,

View File

View File

@ -6,11 +6,14 @@ export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
zoneName: string; zoneName: string;
} }
export class Worker { export class CloudflareWorker {
// STATIC // STATIC
public static async fromApiObject(workerManager: WorkerManager, apiObject): Promise<Worker> { public static async fromApiObject(
const newWorker = new Worker(workerManager); workerManager: WorkerManager,
Object.assign(newWorker, apiObject.result); apiObject
): Promise<CloudflareWorker> {
const newWorker = new CloudflareWorker(workerManager);
Object.assign(newWorker, apiObject);
await newWorker.getRoutes(); await newWorker.getRoutes();
return newWorker; return newWorker;
} }
@ -35,22 +38,24 @@ export class Worker {
* gets all routes for a worker * gets all routes for a worker
*/ */
public async getRoutes() { public async getRoutes() {
const zones = await this.workerManager.cfAccount.listZones(); const zones = await this.workerManager.cfAccount.convenience.listZones();
for (const zone of zones) { for (const zone of zones) {
const requestRoute = `/zones/${zone.id}/workers/routes`; const requestRoute = `/zones/${zone.id}/workers/routes`;
const response: {result: interfaces.ICflareWorkerRoute[]} = await this.workerManager.cfAccount.request('GET', requestRoute); const response: {
result: interfaces.ICflareWorkerRoute[];
} = await this.workerManager.cfAccount.request('GET', requestRoute);
for (const route of response.result) { for (const route of response.result) {
console.log('hey'); console.log('hey');
console.log(route); console.log(route);
console.log(this.id); console.log(this.id);
if (route.script === this.id) { if (route.script === this.id) {
this.routes.push({...route, zoneName: zone.name}); this.routes.push({ ...route, zoneName: zone.name });
} }
} }
} }
} }
public async setRoutes(routeArray: Array<{zoneName: string, pattern: string}>) { public async setRoutes(routeArray: Array<{ zoneName: string; pattern: string }>) {
for (const newRoute of routeArray) { for (const newRoute of routeArray) {
// lets determine wether a route is new, needs an update or already up to date. // lets determine wether a route is new, needs an update or already up to date.
let routeStatus: 'new' | 'needsUpdate' | 'alreadyUpToDate' = 'new'; let routeStatus: 'new' | 'needsUpdate' | 'alreadyUpToDate' = 'new';

View File

@ -1,6 +1,6 @@
import * as plugins from './cloudflare.plugins'; import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account'; import { CloudflareAccount } from './cloudflare.classes.account';
import { Worker } from './cloudflare.classes.worker'; import { CloudflareWorker } from './cloudflare.classes.worker';
export class WorkerManager { export class WorkerManager {
public cfAccount: CloudflareAccount; public cfAccount: CloudflareAccount;
@ -9,14 +9,14 @@ export class WorkerManager {
this.cfAccount = cfAccountArg; this.cfAccount = cfAccountArg;
} }
public async createWorker(workerName: string, workerScript: string): Promise<Worker> { public async createWorker(workerName: string, workerScript: string): Promise<CloudflareWorker> {
const accountIdentifier = await this.cfAccount.getAccountIdentifier(); const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`; const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
const responseBody = await this.cfAccount.request('PUT', route, workerScript, { const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
'Content-Type': 'application/javascript', 'Content-Type': 'application/javascript',
'Content-Length': Buffer.byteLength(workerScript) 'Content-Length': Buffer.byteLength(workerScript)
}); });
return Worker.fromApiObject(this, responseBody); return CloudflareWorker.fromApiObject(this, responseBody.result);
} }
/** /**
@ -26,6 +26,11 @@ export class WorkerManager {
const accountIdentifier = await this.cfAccount.getAccountIdentifier(); const accountIdentifier = await this.cfAccount.getAccountIdentifier();
const route = `/accounts/${accountIdentifier}/workers/scripts`; const route = `/accounts/${accountIdentifier}/workers/scripts`;
const response = await this.cfAccount.request('GET', route); const response = await this.cfAccount.request('GET', route);
console.log(response); const results = response.result;
const workers: CloudflareWorker[] = [];
for (const apiObject of results) {
workers.push(await CloudflareWorker.fromApiObject(this, apiObject));
}
return workers;
} }
} }

View File

@ -2,5 +2,5 @@ import * as plugins from './cloudflare.plugins';
import * as interfaces from './interfaces'; import * as interfaces from './interfaces';
export class CloudflareZone { export class CloudflareZone {
// TODO public static async createFromApiObject() {}
} }

View File

@ -8,4 +8,6 @@ export class ZoneManager {
constructor(cfAccountArg: CloudflareAccount) { constructor(cfAccountArg: CloudflareAccount) {
this.cfAccount = cfAccountArg; this.cfAccount = cfAccountArg;
} }
public getZones() {}
} }

View File

@ -1 +1,2 @@
export { CloudflareAccount } from './cloudflare.classes.account'; export { CloudflareAccount } from './cloudflare.classes.account';
export { CloudflareWorker } from './cloudflare.classes.worker';

View File

@ -3,7 +3,6 @@
"rules": { "rules": {
"semicolon": [true, "always"], "semicolon": [true, "always"],
"no-console": false, "no-console": false,
"no-return-await": false,
"ordered-imports": false, "ordered-imports": false,
"object-literal-sort-keys": false, "object-literal-sort-keys": false,
"member-ordering": { "member-ordering": {