Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx committed Apr 22, 2024
1 parent 48a4ed7 commit 1ff18df
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 202 deletions.
80 changes: 40 additions & 40 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/// <reference lib="deno.ns" />
import * as esbuild from 'https://deno.land/x/[email protected]/mod.js';
import { green } from 'https://deno.land/[email protected]/fmt/colors.ts';
import { parseArgs } from 'https://deno.land/[email protected]/cli/parse_args.ts';

const args = parseArgs<{
watch: boolean | undefined,
develope: boolean | undefined,
logLevel: esbuild.LogLevel
}>(Deno.args);

const filesConfig : esbuild.BuildOptions = {
allowOverwrite: true,
logLevel: args.logLevel ?? 'info',
legalComments: args.develope ? 'inline' : 'none',
color: true,
minify: !args.develope ?? true,
bundle: true,
format: 'esm',
target: 'es2022',
sourcemap: args.develope ?? false,
sourcesContent: args.develope ?? false,
outfile: 'worker/worker.js',
entryPoints: [
'./src/index.ts'
],
}

console.log('Build process started.');

const timestampNow = Date.now();

if (args.watch) {
esbuild.context(filesConfig).then((context) => context.watch());
} else {
esbuild.build(filesConfig).then(() => {
esbuild.stop();
console.log(green(`esbuild ${esbuild.version} finished build in ${(Date.now() - timestampNow).toString()}ms.`));
})
}
/// <reference lib="deno.ns" />
import * as esbuild from 'https://deno.land/x/[email protected]/mod.js';
import { green } from 'https://deno.land/[email protected]/fmt/colors.ts';
import { parseArgs } from 'https://deno.land/[email protected]/cli/parse_args.ts';

const args = parseArgs<{
watch: boolean | undefined,
develope: boolean | undefined,
logLevel: esbuild.LogLevel
}>(Deno.args);

const filesConfig : esbuild.BuildOptions = {
allowOverwrite: true,
logLevel: args.logLevel ?? 'info',
legalComments: args.develope ? 'inline' : 'none',
color: true,
minify: !args.develope ?? true,
bundle: true,
format: 'esm',
target: 'es2022',
sourcemap: args.develope ?? false,
sourcesContent: args.develope ?? false,
outfile: 'worker/worker.js',
entryPoints: [
'./src/index.ts'
],
}

console.log('Build process started.');

const timestampNow = Date.now();

if (args.watch) {
esbuild.context(filesConfig).then((context) => context.watch());
} else {
esbuild.build(filesConfig).then(() => {
esbuild.stop();
console.log(green(`esbuild ${esbuild.version} finished build in ${(Date.now() - timestampNow).toString()}ms.`));
})
}
104 changes: 52 additions & 52 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
{
"tasks": {
"build": "deno run -A ./build.config.ts",
"build:watch": "deno run -A ./build.config.ts --watch",
"build:dev": "deno run -A ./build.config.ts --develope",
"build:dev:watch": "deno run -A ./build.config.ts --develope --watch",
"lint": "deno lint",
"test": "deno test -A --check --reload --doc --allow-none --junit-path=\"./report.xml\""
},
"exclude": [
"./dist/",
"./worker/"
],
"test": {
"include": [
"**/*.test.ts"
]
},
"compilerOptions": {
"experimentalDecorators": true,
"lib": [
"ES6",
"DOM",
"DOM.Iterable"
]
},
"fmt": {
"singleQuote": true,
"lineWidth": 120
},
"lint": {
"rules": {
"tags": [
"recommended"
],
"include": [
"camelcase",
"default-param-last",
"eqeqeq",
"explicit-function-return-type",
"explicit-module-boundary-types",
"guard-for-in",
"no-eval",
"no-sparse-arrays",
"prefer-ascii"
],
"exclude": [
"no-inferrable-types"
]
}
}
}
{
"tasks": {
"build": "deno run -A ./build.config.ts",
"build:watch": "deno run -A ./build.config.ts --watch",
"build:dev": "deno run -A ./build.config.ts --develope",
"build:dev:watch": "deno run -A ./build.config.ts --develope --watch",
"lint": "deno lint",
"test": "deno test -A --check --reload --doc --allow-none --junit-path=\"./report.xml\""
},
"exclude": [
"./dist/",
"./worker/"
],
"test": {
"include": [
"**/*.test.ts"
]
},
"compilerOptions": {
"experimentalDecorators": true,
"lib": [
"ES6",
"DOM",
"DOM.Iterable"
]
},
"fmt": {
"singleQuote": true,
"lineWidth": 120
},
"lint": {
"rules": {
"tags": [
"recommended"
],
"include": [
"camelcase",
"default-param-last",
"eqeqeq",
"explicit-function-return-type",
"explicit-module-boundary-types",
"guard-for-in",
"no-eval",
"no-sparse-arrays",
"prefer-ascii"
],
"exclude": [
"no-inferrable-types"
]
}
}
}
18 changes: 9 additions & 9 deletions src/api/dns_records_url.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { endpoints } from './endpoints.ts';

export default function dnsRecordsUrl(
zoneId : string,
filter? : Record<string, string>[]
) : string {
const filterString = filter?.map((key_value) => `${Object.keys(key_value)[0]}=${key_value[0]}`)
return `${endpoints.BASE}zones/${zoneId}/dns_records/?${filterString?.join('&')}`
}
import { endpoints } from './endpoints.ts';

export default function dnsRecordsUrl(
zoneId : string,
filter? : Record<string, string>[]
) : string {
const filterString = filter?.map((key_value) => `${Object.keys(key_value)[0]}=${key_value[0]}`)
return `${endpoints.BASE}zones/${zoneId}/dns_records/?${filterString?.join('&')}`
}
6 changes: 3 additions & 3 deletions src/api/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const endpoints = {
BASE: "https://api.cloudflare.com/client/v4/"
}
export const endpoints = {
BASE: "https://api.cloudflare.com/client/v4/"
}
76 changes: 38 additions & 38 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import buildUrlWithFilter from './url/build_url_with_filter.ts';
import { ListDNSRecordsResponse } from './response/list_dns_records_response.ts';
import { parseUrlParameters } from './url/parse_url_parameters.ts';
import { endpoints } from './api/endpoints.ts';
import getAllDnsRecords from './record/get_all_dns_records.ts';



export default {
/**
* [Reference](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/)
* @param request Incoming http request
*/
async fetch(request : Request) : Promise<void> {
const urlParameters = parseUrlParameters(new URL(request.url).searchParams);
const {
token,
zoneId,
records
} = urlParameters;

const authorizationHeader = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}

getAllDnsRecords(
`${endpoints.BASE}zones/${zoneId}/dns_records/`,
authorizationHeader
).then((response) => {
response
})

records.forEach(({type, name}) => {

})
}
}
import buildUrlWithFilter from './url/build_url_with_filter.ts';
import { ListDNSRecordsResponse } from './response/list_dns_records_response.ts';
import { parseUrlParameters } from './url/parse_url_parameters.ts';
import { endpoints } from './api/endpoints.ts';
import getAllDnsRecords from './record/get_all_dns_records.ts';



export default {
/**
* [Reference](https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/)
* @param request Incoming http request
*/
async fetch(request : Request) : Promise<void> {
const urlParameters = parseUrlParameters(new URL(request.url).searchParams);
const {
token,
zoneId,
records
} = urlParameters;

const authorizationHeader = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}

getAllDnsRecords(
`${endpoints.BASE}zones/${zoneId}/dns_records/`,
authorizationHeader
).then((response) => {
response
})

records.forEach(({type, name}) => {

})
}
}
22 changes: 11 additions & 11 deletions src/record/get_all_dns_records.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DNSRecord } from './dns_record.ts';

export default function getAllDnsRecords(
url : string,
authorizationHeader : {}
) : Promise<DNSRecord[]> {
return fetch(
url,
{headers: authorizationHeader}
).then(response => response.json()) as Promise<DNSRecord[]>
}
import { DNSRecord } from './dns_record.ts';

export default function getAllDnsRecords(
url : string,
authorizationHeader : {}
) : Promise<DNSRecord[]> {
return fetch(
url,
{headers: authorizationHeader}
).then(response => response.json()) as Promise<DNSRecord[]>
}
28 changes: 14 additions & 14 deletions src/response/list_dns_records_response.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DNSRecord } from '../record/dns_record.ts';

export interface ListDNSRecordsResponse {
errors : [],
messages : [],
result : DNSRecord[],
success : boolean,
result_info : {
count : number,
page : number,
per_page : number,
total_count : number
}
}
import { DNSRecord } from '../record/dns_record.ts';

export interface ListDNSRecordsResponse {
errors : [],
messages : [],
result : DNSRecord[],
success : boolean,
result_info : {
count : number,
page : number,
per_page : number,
total_count : number
}
}
20 changes: 10 additions & 10 deletions src/url/build_url_with_filter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export default function buildUrlWithFilter(
url : string,
filter? : Record<string, string>
) : string {
if (filter) {
return `${url}/?${Object.entries(filter).map(([key, value]) => `${key}=${value}`).join('&')}`
}

return url;
}
export default function buildUrlWithFilter(
url : string,
filter? : Record<string, string>
) : string {
if (filter) {
return `${url}/?${Object.entries(filter).map(([key, value]) => `${key}=${value}`).join('&')}`
}

return url;
}
Loading

0 comments on commit 1ff18df

Please sign in to comment.