Compare commits

..

10 Commits

Author SHA1 Message Date
e466944c55 5.0.9 2021-01-22 21:12:42 +00:00
6d8deca9d4 fix(core): update 2021-01-22 21:12:42 +00:00
a4518f3068 5.0.8 2021-01-22 20:46:26 +00:00
9e338354c6 fix(core): update 2021-01-22 20:46:26 +00:00
9d8c14d187 5.0.7 2021-01-22 20:45:36 +00:00
5a0b12f6aa fix(core): update 2021-01-22 20:45:35 +00:00
387f00078f 5.0.6 2020-06-10 05:34:48 +00:00
fe2f45e3a9 fix(core): update 2020-06-10 05:34:47 +00:00
90c9bfc906 5.0.5 2020-06-10 05:15:23 +00:00
4f9e81f612 fix(core): update 2020-06-10 05:15:22 +00:00
14 changed files with 10472 additions and 611 deletions

4
.gitignore vendored
View File

@ -15,8 +15,6 @@ node_modules/
# builds
dist/
dist_web/
dist_serve/
dist_ts_web/
dist_*/
# custom

View File

@ -19,22 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command snyk test
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -49,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -62,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -84,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm"]
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}

10959
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
{
"name": "@mojoio/cloudflare",
"version": "5.0.4",
"version": "5.0.9",
"private": false,
"description": "easy cloudflare management",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild)"
"build": "(tsbuild --web)"
},
"repository": {
"type": "git",
@ -24,32 +24,36 @@
},
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
"dependencies": {
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.47",
"@pushrocks/smartstring": "^3.0.18",
"@tsclass/tsclass": "^3.0.7"
"@pushrocks/smartdelay": "^2.0.10",
"@pushrocks/smartlog": "^2.0.39",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartrequest": "^1.1.51",
"@pushrocks/smartstring": "^3.0.24",
"@tsclass/tsclass": "^3.0.29"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/qenv": "^4.0.6",
"@pushrocks/tapbundle": "^3.2.0",
"@types/node": "^13.7.2",
"tslint": "^6.0.0",
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/qenv": "^4.0.10",
"@pushrocks/tapbundle": "^3.2.9",
"@types/node": "^14.14.22",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_web/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

View File

@ -8,13 +8,20 @@ easy cloudflare management
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
## Status for 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)
[![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)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/mojoio/cloudflare/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/mojoio/cloudflare/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@mojoio/cloudflare)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/mojoio/cloudflare)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@mojoio/cloudflare)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@mojoio/cloudflare)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@mojoio/cloudflare)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage

View File

@ -14,7 +14,7 @@ tap.test('should create a valid instance of CloudflareAccount', async () => {
testCloudflareAccount = new cloudflare.CloudflareAccount(testQenv.getEnvVarOnDemand('CF_KEY'));
});
tap.test('.listZones() -> should display an entire account', async tools => {
tap.test('.listZones() -> should display an entire account', async (tools) => {
tools.timeout(600000);
const result = await testCloudflareAccount.convenience.listZones();
console.log(result);
@ -22,7 +22,7 @@ tap.test('.listZones() -> should display an entire account', async tools => {
tap.test(
'.getZoneId(domainName) -> should get an Cloudflare Id for a domain string',
async tools => {
async (tools) => {
tools.timeout(600000);
await testCloudflareAccount.convenience.getZoneId('bleu.de');
}
@ -30,37 +30,38 @@ tap.test(
tap.test(
'.listRecords(domainName) -> should list all records for a specific Domain Name',
async tools => {
async (tools) => {
tools.timeout(600000);
await testCloudflareAccount.convenience.listRecords('bleu.de').then(async responseArg => {
await testCloudflareAccount.convenience.listRecords('bleu.de').then(async (responseArg) => {
console.log(responseArg);
});
}
);
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);
await testCloudflareAccount.convenience.createRecord(
`${randomPrefix}subdomain.bleu.de`,
'A',
'127.0.0.1'
'127.0.0.1',
120
);
});
tap.test('should get a record from Cloudflare', async tools => {
tap.test('should get a record from Cloudflare', async (tools) => {
tools.timeout(600000);
await testCloudflareAccount.convenience
.getRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(responseArg => {
.then((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);
await testCloudflareAccount.convenience
.removeRecord(`${randomPrefix}subdomain.bleu.de`, 'A')
.then(async responseArg => {
.then(async (responseArg) => {
console.log(responseArg);
});
});
@ -78,8 +79,8 @@ tap.test('should create a worker', async () => {
await worker.setRoutes([
{
zoneName: 'bleu.de',
pattern: 'https://*bleu.de/hello'
}
pattern: 'https://*bleu.de/hello',
},
]);
console.log(worker);
});

View File

@ -1,4 +1,5 @@
import plugins = require('./cloudflare.plugins');
import { logger } from './cloudflare.logger';
import * as interfaces from './interfaces';
// interfaces
@ -40,16 +41,13 @@ export class CloudflareAccount {
getZoneId: async (domainName: string) => {
const domain = new plugins.smartstring.Domain(domainName);
const zoneArray = await this.convenience.listZones(domain.zoneName);
const filteredResponse = zoneArray.filter(zoneArg => {
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!`
);
logger.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!`);
}
},
@ -64,7 +62,7 @@ export class CloudflareAccount {
): Promise<interfaces.ICflareRecord> => {
const domain = new plugins.smartstring.Domain(domainNameArg);
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 filteredResponse[0];
@ -75,14 +73,16 @@ export class CloudflareAccount {
createRecord: async (
domainNameArg: string,
typeArg: plugins.tsclass.network.TDnsRecordType,
contentArg: string
contentArg: string,
ttlArg = 1
): Promise<any> => {
const domain = new plugins.smartstring.Domain(domainNameArg);
const domainIdArg = await this.convenience.getZoneId(domain.zoneName);
const dataObject = {
name: domain.fullName,
type: typeArg,
content: contentArg
content: contentArg,
ttl: ttlArg,
};
const response = await this.request(
'POST',
@ -168,18 +168,18 @@ export class CloudflareAccount {
const domainId = await this.convenience.getZoneId(domain.zoneName);
const requestUrl = `/zones/${domainId}/purge_cache`;
const payload = {
purge_everything: true
purge_everything: true,
};
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);
await this.convenience.createRecord(dnsChallenge.hostName, 'TXT', dnsChallenge.challenge, 120);
},
acmeRemoveDnsChallenge: async (dnsChallenge: plugins.tsclass.network.IDnsChallenge) => {
await this.convenience.removeRecord(dnsChallenge.hostName, 'TXT');
}
},
};
public async request(
@ -194,9 +194,9 @@ export class CloudflareAccount {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.authToken}`,
'Content-Length': Buffer.byteLength(JSON.stringify(dataArg)),
...requestHeadersArg
...requestHeadersArg,
},
requestBody: dataArg
requestBody: dataArg,
};
// route analysis

View File

@ -1,5 +1,3 @@
import * as plugins from './cloudflare.plugins';
export class CloudflareRecord {
}
export class CloudflareRecord {}

View File

@ -1,6 +1,7 @@
import * as plugins from './cloudflare.plugins';
import * as interfaces from './interfaces';
import { WorkerManager } from './cloudflare.classes.workermanager';
import { logger } from './cloudflare.logger';
export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
zoneName: string;
@ -66,7 +67,7 @@ export class CloudflareWorker {
routeIdForUpdate = existingRoute.id;
if (existingRoute.script === this.id) {
routeStatus = 'alreadyUpToDate';
plugins.smartlog.defaultLogger.log('info', `route already exists, no update needed`);
logger.log('info', `route already exists, no update needed`);
}
}
}
@ -77,14 +78,14 @@ export class CloudflareWorker {
const requestRoute = `/zones/${zoneId}/workers/routes`;
await this.workerManager.cfAccount.request('POST', requestRoute, {
pattern: newRoute.pattern,
script: this.id
script: this.id,
});
} else if (routeStatus === 'needsUpdate') {
const zoneId = await this.workerManager.cfAccount.convenience.getZoneId(newRoute.zoneName);
const requestRoute = `/zones/${zoneId}/workers/routes/${routeIdForUpdate}`;
await this.workerManager.cfAccount.request('PUT', requestRoute, {
pattern: newRoute.pattern,
script: this.id
script: this.id,
});
}
}

View File

@ -14,7 +14,7 @@ export class WorkerManager {
const route = `/accounts/${accountIdentifier}/workers/scripts/${workerName}`;
const responseBody = await this.cfAccount.request('PUT', route, workerScript, {
'Content-Type': 'application/javascript',
'Content-Length': Buffer.byteLength(workerScript)
'Content-Length': Buffer.byteLength(workerScript),
});
return CloudflareWorker.fromApiObject(this, responseBody.result);
}

View File

@ -47,5 +47,4 @@ export class CloudflareZone implements interfaces.ICflareZone {
paused: boolean;
type: string;
checked_on: string;
}

3
ts/cloudflare.logger.ts Normal file
View File

@ -0,0 +1,3 @@
import * as plugins from './cloudflare.plugins';
export const logger = new plugins.smartlog.ConsoleLog();