chore: pipeline utils 转移到basic

pull/213/head
xiaojunnuo 2024-10-08 19:02:51 +08:00
parent 01b79bbeaf
commit 9498d189e4
31 changed files with 301 additions and 104 deletions

View File

@ -0,0 +1,22 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier"
],
"env": {
"mocha": true
},
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"@typescript-eslint/no-explicit-any": "off",
// "no-unused-expressions": "off",
"max-len": [0, 160, 2, { "ignoreUrls": true }]
}
}

28
packages/core/basic/.gitignore vendored Normal file
View File

@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
test/user.secret.*
test/**/*.js
src/**/*.spec.ts

View File

@ -0,0 +1,3 @@
node_modules
src
dist/**/*.spec.*

View File

@ -0,0 +1,2 @@
link-workspace-packages=true
prefer-workspace-packages=true

View File

@ -1,10 +0,0 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.25.9](https://github.com/certd/certd/compare/v1.25.8...v1.25.9) (2024-10-01)
### Bug Fixes
* 修复西部数码账户级别apikey不可用的bug ([f8f3e8b](https://github.com/certd/certd/commit/f8f3e8b43fd5d815887bcb53b95f46dc96424b79))

View File

@ -1,12 +1,68 @@
{
"name": "@certd/basic",
"private": false,
"version": "1.25.9",
"main": "src/index.js",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "echo 'basic'"
"dev": "vite",
"before-build": "rimraf dist && rimraf tsconfig.tsbuildinfo && rimraf .rollup.cache",
"build": "npm run before-build && tsc --skipLibCheck",
"build3": "rollup -c",
"build2": "vue-tsc --noEmit && vite build",
"preview": "vite preview",
"test": "mocha --loader=ts-node/esm"
},
"dependencies": {
"nanoid": "^5.0.7",
"axios": "^1.7.2",
"fix-path": "^4.0.0",
"http-proxy-agent": "^7.0.2",
"https-proxy-agent": "^7.0.5",
"lodash-es": "^4.17.21",
"lru-cache": "^10.0.0",
"node-forge": "^1.3.1",
"nodemailer": "^6.9.3",
"proxy-agent": "^6.4.0",
"qs": "^6.11.2",
"dayjs": "^1.11.7"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^23.0.4",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.0.0",
"@types/lodash-es": "^4.17.12",
"@types/node-forge": "^1.3.2",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@types/mocha": "^10.0.1",
"@types/chai": "^4.3.10",
"chai": "4.3.10",
"mocha": "^10.2.0",
"dayjs": "^1.11.7",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"iconv-lite": "^0.6.3",
"log4js": "^6.9.1",
"prettier": "^2.8.8",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.5",
"rollup": "^3.7.4",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-visualizer": "^5.8.2",
"ts-node": "^10.9.1",
"tsc-esm-fix": "^3.0.0",
"tslib": "^2.5.2",
"typescript": "^5.4.2",
"vite": "^4.3.8",
"vue-tsc": "^1.6.5"
},
"author": "",
"license": "MIT",
"description": "",
"gitHead": "afa8155fda10f9a32427b351454b460897295a2c"
}

View File

@ -0,0 +1 @@
export * from './utils/index.js'

View File

@ -0,0 +1,33 @@
import sleep from "./util.sleep.js";
import { http } from "./util.request.js";
export * from "./util.request.js";
export * from "./util.log.js";
export * from "./util.file.js";
export * from "./util.sp.js";
export * from "./util.promise.js";
export * from "./util.hash.js";
export * from "./util.merge.js";
export * from "./util.cache.js";
import { nanoid } from "nanoid";
import { mergeUtils } from "./util.merge.js";
import { sp } from "./util.sp.js";
import { hashUtils } from "./util.hash.js";
import { promises } from "./util.promise.js";
import { fileUtils } from "./util.file.js";
import _ from "lodash-es";
import { cache } from "./util.cache.js";
import dayjs from 'dayjs';
export const utils = {
sleep,
http,
sp,
hash: hashUtils,
promises,
file: fileUtils,
_,
mergeUtils,
cache,
nanoid,
dayjs
};

View File

@ -1,10 +1,10 @@
import axios, { AxiosRequestConfig } from "axios";
import { logger } from "./util.log.js";
import { Logger } from "log4js";
import { HttpProxyAgent } from "http-proxy-agent";
import { HttpsProxyAgent } from "https-proxy-agent";
import nodeHttp from "http";
import * as https from "node:https";
import axios, { AxiosRequestConfig } from 'axios';
import { logger } from './util.log.js';
import { Logger } from 'log4js';
import { HttpProxyAgent } from 'http-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';
import nodeHttp from 'http';
import * as https from 'node:https';
export class HttpError extends Error {
status?: number;
statusText?: string;
@ -18,8 +18,8 @@ export class HttpError extends Error {
}
super(error.message);
if (error?.message?.indexOf("ssl3_get_record:wrong version number") >= 0) {
this.message = "http协议错误服务端要求http协议请检查是否使用了https请求";
if (error?.message?.indexOf('ssl3_get_record:wrong version number') >= 0) {
this.message = 'http协议错误服务端要求http协议请检查是否使用了https请求';
}
this.name = error.name;
@ -64,7 +64,7 @@ export function createAxiosService({ logger }: { logger: Logger }) {
}
let agents = defaultAgents;
if (config.skipSslVerify) {
logger.info("跳过SSL验证");
logger.info('跳过SSL验证');
agents = createAgent({ rejectUnauthorized: false } as any);
}
delete config.skipSslVerify;
@ -75,51 +75,51 @@ export function createAxiosService({ logger }: { logger: Logger }) {
},
(error: Error) => {
// 发送失败
logger.error("接口请求失败:", error);
logger.error('接口请求失败:', error);
return Promise.reject(error);
}
);
// 响应拦截
service.interceptors.response.use(
(response: any) => {
logger.info("http response:", JSON.stringify(response?.data));
logger.info('http response:', JSON.stringify(response?.data));
return response.data;
},
(error: any) => {
const status = error.response?.status;
switch (status) {
case 400:
error.message = "请求错误";
error.message = '请求错误';
break;
case 401:
error.message = "未授权,请登录";
error.message = '未授权,请登录';
break;
case 403:
error.message = "拒绝访问";
error.message = '拒绝访问';
break;
case 404:
error.message = `请求地址出错: ${error.response.config.url}`;
break;
case 408:
error.message = "请求超时";
error.message = '请求超时';
break;
case 500:
error.message = "服务器内部错误";
error.message = '服务器内部错误';
break;
case 501:
error.message = "服务未实现";
error.message = '服务未实现';
break;
case 502:
error.message = "网关错误";
error.message = '网关错误';
break;
case 503:
error.message = "服务不可用";
error.message = '服务不可用';
break;
case 504:
error.message = "网关超时";
error.message = '网关超时';
break;
case 505:
error.message = "HTTP版本不受支持";
error.message = 'HTTP版本不受支持';
break;
default:
break;
@ -127,12 +127,12 @@ export function createAxiosService({ logger }: { logger: Logger }) {
logger.error(
`请求出错status:${error.response?.status},statusText:${error.response?.statusText},url:${error.config?.url},method:${error.config?.method}`
);
logger.error("返回数据:", JSON.stringify(error.response?.data));
logger.error('返回数据:', JSON.stringify(error.response?.data));
if (error.response?.data) {
error.message = error.response.data.message || error.response.data.msg || error.response.data.error || error.response.data;
}
if (error instanceof AggregateError) {
logger.error("AggregateError", error);
logger.error('AggregateError', error);
}
const err = new HttpError(error);
return Promise.reject(err);
@ -155,14 +155,14 @@ export function createAgent(opts: nodeHttp.AgentOptions = {}) {
let httpAgent, httpsAgent;
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;
if (httpProxy) {
logger.info("use httpProxy:", httpProxy);
logger.info('use httpProxy:', httpProxy);
httpAgent = new HttpProxyAgent(httpProxy, opts as any);
} else {
httpAgent = new nodeHttp.Agent(opts);
}
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
if (httpsProxy) {
logger.info("use httpsProxy:", httpsProxy);
logger.info('use httpsProxy:', httpsProxy);
httpsAgent = new HttpsProxyAgent(httpsProxy, opts as any);
} else {
httpsAgent = new https.Agent(opts);

View File

@ -0,0 +1,42 @@
{
"compileOnSave": true,
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"inlineSourceMap":true,
"noImplicitThis": true,
"noUnusedLocals": true,
"stripInternal": true,
"skipLibCheck": true,
"pretty": true,
"declaration": true,
"forceConsistentCasingInFileNames": true,
"typeRoots": [ "./typings", "./node_modules/@types"],
"outDir": "dist",
"rootDir": "src",
"composite": true,
"useDefineForClassFields": true,
"strict": true,
// "sourceMap": true,
"resolveJsonModule": true,
"isolatedModules": false,
"lib": ["ESNext", "DOM"],
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.json"
],
"exclude": [
"*.js",
"*.ts",
"*.spec.ts",
"dist",
"node_modules",
"test"
],
}

View File

@ -36,14 +36,15 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.0.0",
"@types/chai": "^4.3.10",
"@types/lodash-es": "^4.17.12",
"@types/mocha": "^10.0.1",
"@types/node-forge": "^1.3.2",
"@types/uuid": "^9.0.2",
"@typescript-eslint/eslint-plugin": "^5.59.7",
"@typescript-eslint/parser": "^5.59.7",
"@types/mocha": "^10.0.1",
"@types/chai": "^4.3.10",
"chai": "4.3.10",
"mocha": "^10.2.0",
"dayjs": "^1.11.7",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
@ -52,7 +53,6 @@
"eslint-plugin-prettier": "^4.2.1",
"iconv-lite": "^0.6.3",
"log4js": "^6.9.1",
"mocha": "^10.2.0",
"prettier": "^2.8.8",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.5",

View File

@ -4,16 +4,15 @@ import { RunHistory, RunnableCollection } from "./run-history.js";
import { AbstractTaskPlugin, PluginDefine, pluginRegistry, TaskInstanceContext, UserInfo } from "../plugin/index.js";
import { ContextFactory, IContext } from "./context.js";
import { IStorage } from "./storage.js";
import { logger } from "../utils/util.log.js";
import { logger } from "../utils/index.js";
import { Logger } from "log4js";
import { createAxiosService } from "../utils/util.request.js";
import { createAxiosService } from "../utils/index.js";
import { IAccessService } from "../access/index.js";
import { RegistryItem } from "../registry/index.js";
import { Decorator } from "../decorator/index.js";
import { ICnameProxyService, IEmailService } from "../service/index.js";
import { FileStore } from "./file-store.js";
import { hashUtils, utils } from "../utils/index.js";
// import { TimeoutPromise } from "../utils/util.promise.js";
export type ExecutorOptions = {
pipeline: Pipeline;

View File

@ -1,6 +1,6 @@
import { HistoryResult, Pipeline, ResultType, Runnable, RunnableMap, Stage, Step, Task } from "../dt/index.js";
import _ from "lodash-es";
import { buildLogger } from "../utils/util.log.js";
import { buildLogger } from "../utils/index.js";
import { Logger } from "log4js";
export type HistoryStatus = {

View File

@ -1,6 +1,6 @@
import fs from "fs";
import path from "path";
import { fileUtils } from "../utils/util.file.js";
import { fileUtils } from "../utils/index.js";
export interface IStorage {
get(scope: string, namespace: string, version: string, key: string): Promise<string | null>;

View File

@ -6,7 +6,7 @@ import { IAccessService } from "../access/index.js";
import { ICnameProxyService, IEmailService } from "../service/index.js";
import { IContext, PluginRequestHandleReq, RunnableCollection } from "../core/index.js";
import { ILogger, logger, utils } from "../utils/index.js";
import { HttpClient } from "../utils/util.request.js";
import { HttpClient } from "../utils/index.js";
import dayjs from "dayjs";
import _ from "lodash-es";
export type UserInfo = {

View File

@ -1,33 +1 @@
import sleep from "./util.sleep.js";
import { http } from "./util.request.js";
export * from "./util.request.js";
export * from "./util.log.js";
export * from "./util.file.js";
export * from "./util.sp.js";
export * from "./util.promise.js";
export * from "./util.hash.js";
export * from "./util.merge.js";
export * from "./util.cache.js";
import { nanoid } from "nanoid";
import { mergeUtils } from "./util.merge.js";
import { sp } from "./util.sp.js";
import { hashUtils } from "./util.hash.js";
import { promises } from "./util.promise.js";
import { fileUtils } from "./util.file.js";
import _ from "lodash-es";
import { cache } from "./util.cache.js";
import dayjs from 'dayjs';
export const utils = {
sleep,
http,
sp,
hash: hashUtils,
promises,
file: fileUtils,
_,
mergeUtils,
cache,
nanoid,
dayjs
};
export * from "@certd/basic";

View File

@ -37,7 +37,7 @@
"typeorm": "^0.3.20",
"lodash-es": "^4.17.21",
"dayjs": "^1.11.7",
"@midwayjs/upload": "3"
"@midwayjs/upload": "^3.16.4"
},
"devDependencies": {
"mwts": "^1.3.0",

View File

@ -1,5 +1,6 @@
<template>
<tr v-if="cnameRecord" class="cname-record-info">
<tbody v-if="cnameRecord" class="cname-record-info">
<tr>
<!-- <td class="domain">-->
<!-- {{ props.domain }}-->
<!-- </td>-->
@ -10,23 +11,24 @@
<fs-copyable v-model="cnameRecord.recordValue"></fs-copyable>
</td>
<td class="status center flex-center">
<fs-values-format v-model="cnameRecord.status" :dict="statusDict" />
<fs-values-format v-model="cnameRecord.status" :dict="statusDict"/>
<fs-icon icon="ion:refresh-outline" class="pointer" @click="doRefresh"></fs-icon>
</td>
</tr>
</tbody>
</template>
<script lang="ts" setup>
import { CnameRecord, GetByDomain } from "/@/components/plugins/cert/domains-verify-plan-editor/api";
import { ref, watch } from "vue";
import { dict } from "@fast-crud/fast-crud";
import {CnameRecord, GetByDomain} from "/@/components/plugins/cert/domains-verify-plan-editor/api";
import {ref, watch} from "vue";
import {dict} from "@fast-crud/fast-crud";
const statusDict = dict({
data: [
{ label: "待设置CNAME", value: "cname", color: "warning" },
{ label: "验证中", value: "validating", color: "primary" },
{ label: "验证成功", value: "valid", color: "success" },
{ label: "验证失败", value: "failed", color: "error" }
{label: "待设置CNAME", value: "cname", color: "warning"},
{label: "验证中", value: "validating", color: "primary"},
{label: "验证成功", value: "valid", color: "success"},
{label: "验证失败", value: "failed", color: "error"}
]
});
@ -63,13 +65,13 @@ async function doRefresh() {
}
watch(
() => props.domain,
async (value) => {
await doRefresh();
},
{
immediate: true
}
() => props.domain,
async (value) => {
await doRefresh();
},
{
immediate: true
}
);
</script>

View File

@ -1,10 +1,14 @@
<template>
<table class="cname-verify-plan">
<thead>
<tr>
<td style="width: 160px">主机记录</td>
<td style="width: 250px">请设置CNAME记录</td>
<td style="width: 120px" class="center">状态</td>
</tr>
</thead>
<template v-for="key in domains" :key="key">
<cname-record-info :domain="key" @change="onRecordChange(key, $event)" />
</template>

View File

@ -7,11 +7,14 @@
<fs-icon :icon="fullscreen ? 'material-symbols:fullscreen' : 'material-symbols:fullscreen-exit'" @click="fullscreen = !fullscreen"></fs-icon>
</div>
<table class="plan-table">
<thead>
<tr>
<th>域名</th>
<th>验证方式</th>
<th>验证计划</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, key) of planRef" :key="key" class="row">
<td>{{ item.domain }}</td>
<td>
@ -54,6 +57,7 @@
</div>
</td>
</tr>
</tbody>
</table>
<div class="error">
{{ errorMessageRef }}

View File

@ -44,7 +44,7 @@
"@midwayjs/logger": "^3.1.0",
"@midwayjs/static-file": "^3.16.4",
"@midwayjs/typeorm": "^3.16.4",
"@midwayjs/upload": "3",
"@midwayjs/upload": "~3.16.4",
"@midwayjs/validate": "^3.16.4",
"ali-oss": "^6.21.0",
"axios": "^1.7.2",

View File

@ -1,7 +1,7 @@
import { ALL, Body, Controller, Inject, Post, Provide } from '@midwayjs/core';
import { SysSettingsService } from '@certd/lib-server';
import { ALL, Body, Controller, Get, Inject, Post, Provide } from '@midwayjs/core';
import { Constants, SysSettingsService } from '@certd/lib-server';
import { BaseController } from '@certd/lib-server';
import { AppKey } from '@certd/pipeline';
import { AppKey, http, PlusRequestService, verify } from '@certd/pipeline';
import { SysInstallInfo } from '@certd/lib-server';
import { logger } from '@certd/pipeline';
import { PlusService } from '@certd/lib-server';
@ -50,6 +50,49 @@ export class SysPlusController extends BaseController {
installInfo.bindUrl = url;
await this.sysSettingsService.saveSetting(installInfo);
//重新验证配置
await this.plusService.verify();
return this.ok(true);
}
@Get('/test', { summary: Constants.per.guest })
async test() {
const subjectId = 'vpyoZb6fDBjzzSZp67OBP';
const license = '';
const timestamps = 1728365013899;
const bindUrl = 'http://89.21.0.171:7001/';
const service = new PlusRequestService({
logger: logger,
http: http,
subjectId: subjectId,
plusServerBaseUrls: ['https://api.ai.handsfree.work'],
});
const body = { subjectId, appKey: 'kQth6FHM71IPV3qdWc', url: bindUrl };
async function test() {
await verify({
subjectId: subjectId,
license: license,
plusRequestService: service,
});
const res = await service.sign(body, timestamps);
console.log('sign:', res);
const res2 = await service.request({
url: '/activation/subject/vip/check',
data: {
url: 'http://127.0.0.1:7001/',
},
});
console.log('res2:', res2);
}
console.log('2222');
await test();
console.log('3333');
return this.ok(true);
}
}