@vectorx/cloud-toolkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +1 -0
  2. package/lib/agent.kit.js +274 -0
  3. package/lib/config/api.config.js +12 -0
  4. package/lib/config/index.js +17 -0
  5. package/lib/container/container.js +11 -0
  6. package/lib/container/identifiers.js +7 -0
  7. package/lib/container/index.js +31 -0
  8. package/lib/container/types.js +2 -0
  9. package/lib/index.js +27 -0
  10. package/lib/services/auth-service.js +148 -0
  11. package/lib/services/index.js +18 -0
  12. package/lib/services/upload-service.js +194 -0
  13. package/lib/utils/config-merger.js +54 -0
  14. package/lib/utils/cos-uploader.js +104 -0
  15. package/lib/utils/env-helper.js +4 -0
  16. package/lib/utils/helper.js +66 -0
  17. package/lib/utils/loading.js +68 -0
  18. package/lib/utils/logger.js +89 -0
  19. package/lib/utils/open-browser.js +24 -0
  20. package/lib/utils/openChrome.applescript +78 -0
  21. package/lib/utils/output.js +37 -0
  22. package/lib/utils/port-finder.js +55 -0
  23. package/lib/utils/project-validator.js +124 -0
  24. package/lib/utils/request.js +74 -0
  25. package/lib/utils/tracker/device.js +85 -0
  26. package/lib/utils/tracker/index.js +134 -0
  27. package/lib/utils/tracker/tracker.js +2 -0
  28. package/package.json +54 -0
  29. package/types/agent.kit.d.ts +68 -0
  30. package/types/config/api.config.d.ts +2 -0
  31. package/types/config/index.d.ts +1 -0
  32. package/types/container/container.d.ts +3 -0
  33. package/types/container/identifiers.d.ts +6 -0
  34. package/types/container/index.d.ts +9 -0
  35. package/types/container/types.d.ts +19 -0
  36. package/types/index.d.ts +12 -0
  37. package/types/services/auth-service.d.ts +22 -0
  38. package/types/services/index.d.ts +2 -0
  39. package/types/services/upload-service.d.ts +95 -0
  40. package/types/utils/config-merger.d.ts +1 -0
  41. package/types/utils/cos-uploader.d.ts +41 -0
  42. package/types/utils/env-helper.d.ts +1 -0
  43. package/types/utils/helper.d.ts +6 -0
  44. package/types/utils/loading.d.ts +18 -0
  45. package/types/utils/logger.d.ts +24 -0
  46. package/types/utils/open-browser.d.ts +2 -0
  47. package/types/utils/output.d.ts +1 -0
  48. package/types/utils/port-finder.d.ts +2 -0
  49. package/types/utils/project-validator.d.ts +10 -0
  50. package/types/utils/request.d.ts +25 -0
  51. package/types/utils/tracker/device.d.ts +4 -0
  52. package/types/utils/tracker/index.d.ts +27 -0
  53. package/types/utils/tracker/tracker.d.ts +22 -0
@@ -0,0 +1,19 @@
1
+ import type { CheckStatusRequest, CheckStatusResponse } from "../services/auth-service";
2
+ import type { BuildPreCheckResponse, IBuildPreCheckParams, IDeployParams } from "../services/upload-service";
3
+ export interface IAuthService {
4
+ hasLogin(): boolean;
5
+ getLoginInfo(): Promise<LoginInfo | null>;
6
+ check(params: CheckStatusRequest): Promise<CheckStatusResponse>;
7
+ clearLoginInfo(): Promise<void>;
8
+ }
9
+ export interface IUploadService {
10
+ getCloudBaseSecretToken(): Promise<string>;
11
+ buildPreCheck(params: IBuildPreCheckParams): Promise<BuildPreCheckResponse>;
12
+ deploy(params: IDeployParams): Promise<any>;
13
+ }
14
+ export interface LoginInfo {
15
+ secret_id: string;
16
+ cli_token: string;
17
+ create_at: number;
18
+ expire_in_sec: number;
19
+ }
@@ -0,0 +1,12 @@
1
+ export * from "./agent.kit";
2
+ export * from "./container";
3
+ export * from "./services";
4
+ export * from "./utils/config-merger";
5
+ export * from "./utils/env-helper";
6
+ export * from "./utils/helper";
7
+ export * from "./utils/logger";
8
+ export * from "./utils/tracker";
9
+ export * from "./utils/port-finder";
10
+ export * from "./utils/open-browser";
11
+ export * from "./utils/output";
12
+ export type { TokenRequest, TokenResponse, UploadTempPermit, InternalTokenRequest, } from "./services/upload-service";
@@ -0,0 +1,22 @@
1
+ import type { IAuthService, LoginInfo } from "../container";
2
+ export interface CheckStatusResponse {
3
+ code: number;
4
+ msg: string;
5
+ data: LoginInfo;
6
+ }
7
+ export type CheckStatusRequest = {
8
+ secret_id: string;
9
+ nonce: string;
10
+ cli_token: string;
11
+ };
12
+ export declare class AuthService implements IAuthService {
13
+ private readonly configDir;
14
+ private readonly configFile;
15
+ constructor();
16
+ getToken(secretId: string, secretKey: string, nonce: string): string;
17
+ hasLogin(): boolean;
18
+ saveLoginInfo(loginInfo: LoginInfo): Promise<void>;
19
+ getLoginInfo(): Promise<LoginInfo | null>;
20
+ check(params: CheckStatusRequest): Promise<CheckStatusResponse>;
21
+ clearLoginInfo(): Promise<void>;
22
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./auth-service";
2
+ export * from "./upload-service";
@@ -0,0 +1,95 @@
1
+ import { type IUploadService } from "../container";
2
+ export interface TokenRequest {
3
+ bizName: string;
4
+ scene: string;
5
+ fileCount: number;
6
+ fileFormat?: string;
7
+ persistentOps?: string;
8
+ persistentNotifyUrl?: string;
9
+ }
10
+ export interface TokenResponse {
11
+ uploadLimitPolicy?: {
12
+ fileTypes?: string[];
13
+ maxSize?: number;
14
+ };
15
+ uploadTempPermits: UploadTempPermit[];
16
+ }
17
+ export type GetToken = () => Promise<TokenResponse>;
18
+ export interface IBuildPreCheckParams {
19
+ agent_id: string;
20
+ version: string;
21
+ desc: string;
22
+ }
23
+ export interface UploadTempPermit {
24
+ secretId?: string;
25
+ secretKey?: string;
26
+ token: string;
27
+ uploadAddr: string;
28
+ expireTime: number;
29
+ qos: number;
30
+ cloudType: number;
31
+ bucket: string;
32
+ region: string;
33
+ fileIds: string[];
34
+ masterCloudId: number;
35
+ uploadId: number;
36
+ cdnDomain?: string;
37
+ }
38
+ export interface TokenRequest {
39
+ bizName: string;
40
+ scene: string;
41
+ fileCount: number;
42
+ fileFormat?: string;
43
+ persistentOps?: string;
44
+ persistentNotifyUrl?: string;
45
+ }
46
+ export interface InternalTokenRequest extends TokenRequest {
47
+ subsystem: string;
48
+ }
49
+ export interface TokenResponse {
50
+ uploadLimitPolicy?: {
51
+ fileTypes?: string[];
52
+ maxSize?: number;
53
+ };
54
+ uploadTempPermits: UploadTempPermit[];
55
+ }
56
+ export interface InternalTokenRequest extends TokenRequest {
57
+ subsystem: string;
58
+ }
59
+ export interface BuildPreCheckResponse {
60
+ code: number;
61
+ success: boolean;
62
+ msg: string;
63
+ }
64
+ export interface IDeployResponse {
65
+ code: number;
66
+ success: boolean;
67
+ msg: string;
68
+ }
69
+ export interface IDeployParams {
70
+ targetPath: string;
71
+ agentId: string;
72
+ version: string;
73
+ desc: string;
74
+ }
75
+ export interface IUploadAgentPackageParams {
76
+ agent_id: string;
77
+ version: string;
78
+ desc: string;
79
+ file_url: string;
80
+ cloud_type: number;
81
+ }
82
+ export interface UploadAgentPackageResponse {
83
+ code: number;
84
+ success: boolean;
85
+ msg: string;
86
+ }
87
+ export declare class UploadService implements IUploadService {
88
+ private readonly authService;
89
+ constructor();
90
+ getCloudBaseSecretToken(): Promise<string>;
91
+ getToken(): Promise<TokenResponse>;
92
+ buildPreCheck(params: IBuildPreCheckParams): Promise<BuildPreCheckResponse>;
93
+ deploy(params: IDeployParams): Promise<IDeployResponse>;
94
+ private uploadAgentPackage;
95
+ }
@@ -0,0 +1 @@
1
+ export declare function mergeProjectConfigs(workDir: string): void;
@@ -0,0 +1,41 @@
1
+ import COS, { type UploadBody } from "cos-nodejs-sdk-v5";
2
+ import type { GetToken } from "../services/upload-service";
3
+ interface IFileInfo {
4
+ name: string;
5
+ size: number;
6
+ type: string;
7
+ }
8
+ export interface UploadResponse extends COS.UploadFileResult {
9
+ bizName: string;
10
+ scene: string;
11
+ cloudType: number;
12
+ cdnDomain?: string;
13
+ fileId: string;
14
+ previewUrl?: string;
15
+ staticUrl?: string;
16
+ url?: string;
17
+ useCache?: boolean;
18
+ sliceSize?: number;
19
+ isSlice?: boolean;
20
+ tokenFail?: boolean;
21
+ }
22
+ export declare class Uploader {
23
+ bizName: string;
24
+ scene: string;
25
+ getToken: GetToken;
26
+ enableResume?: boolean;
27
+ constructor(args: {
28
+ bizName: string;
29
+ scene: string;
30
+ getToken: GetToken;
31
+ enableResume?: boolean;
32
+ });
33
+ private getPermit;
34
+ post(options: Omit<COS.UploadFileParams, "Bucket" | "Region" | "Key"> & {
35
+ Body: UploadBody;
36
+ fileInfo: IFileInfo;
37
+ fileFormat?: string;
38
+ onInstanceCreated?: (instance: COS) => void;
39
+ }): Promise<UploadResponse>;
40
+ }
41
+ export {};
@@ -0,0 +1 @@
1
+ export declare const isIDE: boolean;
@@ -0,0 +1,6 @@
1
+ export declare const getFixedFormatTime: (format: string, timeDistance?: number) => string;
2
+ export declare function getNonce(): string;
3
+ export declare function getMd5(str: string): string;
4
+ export declare function guid(): string;
5
+ export declare function retry<T>(fn: () => Promise<T>, maxRetries?: number, delay?: number): Promise<T>;
6
+ export declare const toHump: (str: string) => string;
@@ -0,0 +1,18 @@
1
+ declare class Loading {
2
+ private spinner;
3
+ constructor();
4
+ set text(text: string);
5
+ start(text: string): void;
6
+ stop(): void;
7
+ succeed(text: string): void;
8
+ fail(text: string): void;
9
+ }
10
+ export declare const loadingFactory: () => Loading;
11
+ type Task<T> = (flush: (text: string) => void, ...args: any[]) => Promise<T>;
12
+ export interface ILoadingOptions {
13
+ startTip?: string;
14
+ successTip?: string;
15
+ failTip?: string;
16
+ }
17
+ export declare const execWithLoading: <T>(task: Task<T>, options?: ILoadingOptions) => Promise<T>;
18
+ export {};
@@ -0,0 +1,24 @@
1
+ import ora, { type Ora } from "ora";
2
+ export declare class Logger {
3
+ c: {
4
+ _times: Map<any, any>;
5
+ log(a: string, ...args: string[]): void;
6
+ };
7
+ verboseEnabled: boolean;
8
+ constructor(options?: {
9
+ verbose?: boolean;
10
+ });
11
+ breakLine(): void;
12
+ log(...args: any): void;
13
+ info(msg: string): void;
14
+ success(msg: string): void;
15
+ warn(msg: string): void;
16
+ error(msg: string): void;
17
+ verbose(...args: any): void;
18
+ debug(...args: any): void;
19
+ genClickableLink(link: string): string;
20
+ printClickableLink(link: string): void;
21
+ time(label: string, fn: Promise<any> | (() => Promise<any>)): Promise<any>;
22
+ spinner(text: string, color?: ora.Color): Ora;
23
+ }
24
+ export declare const logger: Logger;
@@ -0,0 +1,2 @@
1
+ declare const openBrowser: (host: string, port: number) => boolean;
2
+ export { openBrowser };
@@ -0,0 +1 @@
1
+ export declare const outputHelpInfo: () => void;
@@ -0,0 +1,2 @@
1
+ export declare function findAvailablePort(startPort: number): Promise<number>;
2
+ export declare function isPortAvailable(port: number): Promise<boolean>;
@@ -0,0 +1,10 @@
1
+ import type { IUploadOptions } from "../agent.kit";
2
+ export declare class ProjectValidator {
3
+ private workDir;
4
+ private uploadInfo;
5
+ constructor(workDir: string, uploadInfo: IUploadOptions);
6
+ validate(): Promise<{
7
+ valid: boolean;
8
+ errors: string[];
9
+ }>;
10
+ }
@@ -0,0 +1,25 @@
1
+ export interface RequestOptions {
2
+ method?: "GET" | "POST" | "PUT" | "DELETE";
3
+ url: string;
4
+ data?: {
5
+ params?: any;
6
+ body?: any;
7
+ withCredentials?: boolean;
8
+ query?: any;
9
+ };
10
+ headers?: Record<string, string>;
11
+ }
12
+ export interface RequestResponse<T> {
13
+ status: number;
14
+ data: T;
15
+ headers: any;
16
+ }
17
+ export declare class Request {
18
+ fetch<T = any>(options: RequestOptions): Promise<RequestResponse<T>>;
19
+ handleHttpStatus<T>(response: RequestResponse<T>): T;
20
+ handleCode<T extends {
21
+ code: number;
22
+ msg: string;
23
+ }>(data: T): T;
24
+ }
25
+ export declare const request: Request;
@@ -0,0 +1,4 @@
1
+ import type { IDeviceInfo, IDeviceUA } from "./tracker";
2
+ export declare function getDeviceInfo(): IDeviceInfo;
3
+ export declare function deviceUA(): IDeviceUA;
4
+ export declare function machineId(): string;
@@ -0,0 +1,27 @@
1
+ import type { IBase } from "./tracker";
2
+ interface ISequence {
3
+ context_sdkSeqId: number;
4
+ context_sdkSessionId: string;
5
+ context_pageSessionId: string;
6
+ clientTime: number;
7
+ }
8
+ interface IReqItem {
9
+ suquence: ISequence;
10
+ measurement_name: string;
11
+ measurement_data: Record<string, any>;
12
+ }
13
+ export declare class APM {
14
+ private reportQueue;
15
+ private allowReport;
16
+ private eventSeq;
17
+ private context;
18
+ private baseData;
19
+ setContext(userId: string, base?: IBase): void;
20
+ private startReport;
21
+ private getSequence;
22
+ private _request;
23
+ private bactchReport;
24
+ private timer;
25
+ report(measurement_name: string, measurement_data?: IReqItem["measurement_data"]): void;
26
+ }
27
+ export {};
@@ -0,0 +1,22 @@
1
+ export interface IDeviceInfo {
2
+ os_platform: string;
3
+ os_arch: string;
4
+ cpu_speed: number;
5
+ cpu_model: string;
6
+ machine_memory: number;
7
+ os_version: string;
8
+ }
9
+ export interface IDeviceUA {
10
+ login_user?: string;
11
+ node_version: string;
12
+ }
13
+ export interface IBase {
14
+ app_id?: string;
15
+ app_name?: string;
16
+ third_name?: string;
17
+ page_key?: string;
18
+ base_version?: string;
19
+ app_env?: number;
20
+ app_type?: number;
21
+ bundle_version?: string;
22
+ }