Compare commits

...

14 Commits

Author SHA1 Message Date
42feb09b4f 6.0.3 2023-06-13 19:01:56 +02:00
d72bb28cf9 fix(core): update 2023-06-13 19:01:56 +02:00
b9f0b798c9 6.0.2 2023-06-13 18:54:26 +02:00
9b5f42ef9b fix(core): update 2023-06-13 18:54:25 +02:00
4e3355dc43 6.0.1 2022-09-27 19:24:52 +02:00
fc0a27f5b6 fix(core): update 2022-09-27 19:24:52 +02:00
0248d52548 6.0.0 2022-09-27 19:24:00 +02:00
c3984819cc BREAKING CHANGE(core): switch to esm 2022-09-27 19:24:00 +02:00
045b87a4a2 5.0.10 2022-09-27 19:23:21 +02:00
48ca9fdbb9 fix(core): update 2022-09-27 19:23:20 +02:00
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
21 changed files with 15024 additions and 9050 deletions

View File

@ -12,30 +12,35 @@ stages:
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci git mirror
- 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:
- lossless
- docker
- notpriv
allow_failure: true
audit:
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high
- npmci command npm audit --audit-level=high --only=dev
tags:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +55,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +66,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,11 +86,12 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci command npm install -g typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
@ -109,11 +111,10 @@ trigger:
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci node install stable
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
- npmci command npm run buildDocs
tags:
- lossless
- docker

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0",
"configurations": [
{
"name": "current file",
"type": "node",
"command": "npm test",
"name": "Run npm test",
"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"
"type": "node-terminal"
}
]
}

View File

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

View File

@ -9,8 +9,8 @@
"githost": "gitlab.com",
"gitscope": "mojoio",
"gitrepo": "cloudflare",
"shortDescription": "easy cloudflare management",
"npmPackagename": "@mojoio/cloudflare",
"description": "easy cloudflare management",
"npmPackagename": "@apiclient.xyz/cloudflare",
"license": "MIT"
}
}

19398
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,15 @@
{
"name": "@mojoio/cloudflare",
"version": "5.0.7",
"name": "@apiclient.xyz/cloudflare",
"version": "6.0.3",
"private": false,
"description": "easy cloudflare management",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"type": "module",
"scripts": {
"test": "(tstest test/)",
"build": "(tsbuild --web)"
"build": "(tsbuild --web --allowimplicitany)",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
@ -24,22 +26,20 @@
},
"homepage": "https://gitlab.com/pushrocks/cflare#readme",
"dependencies": {
"@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"
"@pushrocks/smartdelay": "^3.0.1",
"@pushrocks/smartlog": "^3.0.2",
"@pushrocks/smartpromise": "^4.0.2",
"@pushrocks/smartrequest": "^2.0.15",
"@pushrocks/smartstring": "^4.0.5",
"@tsclass/tsclass": "^4.0.42"
},
"devDependencies": {
"@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"
"@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.42",
"@gitzone/tstest": "^1.0.74",
"@pushrocks/qenv": "^5.0.2",
"@pushrocks/tapbundle": "^5.0.4",
"@types/node": "^20.3.1"
},
"files": [
"ts/**/*",
@ -52,5 +52,8 @@
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
]
}

4420
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
# @mojoio/cloudflare
# @apiclient.xyz/cloudflare
easy cloudflare management
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@mojoio/cloudflare)
* [npmjs.org (npm package)](https://www.npmjs.com/package/@apiclient.xyz/cloudflare)
* [gitlab.com (source)](https://gitlab.com/mojoio/cloudflare)
* [github.com (source mirror)](https://github.com/mojoio/cloudflare)
* [docs (typedoc)](https://mojoio.gitlab.io/cloudflare/)
@ -13,14 +13,14 @@ 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)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@apiclient.xyz/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)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@apiclient.xyz/cloudflare)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@apiclient.xyz/cloudflare)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@apiclient.xyz/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
@ -28,7 +28,7 @@ Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20W
Use TypeScript for best in class instellisense.
```javascript
import * as cflare from '@mojoio/cloudflare';
import * as cflare from '@apiclient.xyz/cloudflare';
const myCflareAccount = new cflare.CflareAccount('mySuperAwesomeAccountToken');

View File

@ -3,7 +3,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
// tslint:disable-next-line: no-implicit-dependencies
import { Qenv } from '@pushrocks/qenv';
import cloudflare = require('../ts/index');
import * as cloudflare from '../ts/index.js';
const testQenv = new Qenv(process.cwd(), process.cwd() + '/.nogit');
@ -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);
});

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@apiclient.xyz/cloudflare',
version: '6.0.3',
description: 'easy cloudflare management'
}

View File

@ -1,10 +1,10 @@
import plugins = require('./cloudflare.plugins');
import { logger } from './cloudflare.logger';
import * as interfaces from './interfaces';
import * as plugins from './cloudflare.plugins.js';
import { logger } from './cloudflare.logger.js';
import * as interfaces from './interfaces/index.js';
// interfaces
import { WorkerManager } from './cloudflare.classes.workermanager';
import { ZoneManager } from './cloudflare.classes.zonemanager';
import { WorkerManager } from './cloudflare.classes.workermanager.js';
import { ZoneManager } from './cloudflare.classes.zonemanager.js';
export class CloudflareAccount {
private authToken: string;
@ -41,7 +41,7 @@ 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) {
@ -62,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];
@ -82,7 +82,7 @@ export class CloudflareAccount {
name: domain.fullName,
type: typeArg,
content: contentArg,
ttl: ttlArg
ttl: ttlArg,
};
const response = await this.request(
'POST',
@ -168,18 +168,23 @@ 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, 2);
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 +199,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,3 +1,3 @@
import * as plugins from './cloudflare.plugins';
import * as plugins from './cloudflare.plugins.js';
export class CloudflareRecord {}

View File

@ -1,7 +1,7 @@
import * as plugins from './cloudflare.plugins';
import * as interfaces from './interfaces';
import { WorkerManager } from './cloudflare.classes.workermanager';
import { logger } from './cloudflare.logger';
import * as plugins from './cloudflare.plugins.js';
import * as interfaces from './interfaces/index.js';
import { WorkerManager } from './cloudflare.classes.workermanager.js';
import { logger } from './cloudflare.logger.js';
export interface IWorkerRoute extends interfaces.ICflareWorkerRoute {
zoneName: string;
@ -78,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

@ -1,6 +1,6 @@
import * as plugins from './cloudflare.plugins';
import { CloudflareAccount } from './cloudflare.classes.account';
import { CloudflareWorker } from './cloudflare.classes.worker';
import * as plugins from './cloudflare.plugins.js';
import { CloudflareAccount } from './cloudflare.classes.account.js';
import { CloudflareWorker } from './cloudflare.classes.worker.js';
export class WorkerManager {
public cfAccount: CloudflareAccount;
@ -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

@ -1,5 +1,5 @@
import * as plugins from './cloudflare.plugins';
import * as interfaces from './interfaces';
import * as plugins from './cloudflare.plugins.js';
import * as interfaces from './interfaces/index.js';
export class CloudflareZone implements interfaces.ICflareZone {
public static createFromApiObject(apiObject: interfaces.ICflareZone) {

View File

@ -1,7 +1,7 @@
import * as plugins from './cloudflare.plugins';
import * as interfaces from './interfaces';
import { CloudflareAccount } from './cloudflare.classes.account';
import { CloudflareZone } from './cloudflare.classes.zone';
import * as plugins from './cloudflare.plugins.js';
import * as interfaces from './interfaces/index.js';
import { CloudflareAccount } from './cloudflare.classes.account.js';
import { CloudflareZone } from './cloudflare.classes.zone.js';
export class ZoneManager {
public cfAccount: CloudflareAccount;

View File

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

View File

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

View File

@ -1,3 +1,3 @@
export * from './cloudflare.api.record';
export * from './cloudflare.api.zone';
export * from './cloudflare.api.workerroute';
export * from './cloudflare.api.record.js';
export * from './cloudflare.api.zone.js';
export * from './cloudflare.api.workerroute.js';

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}