@chargebee/chargebee-apps-shared 0.0.2
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.
- package/LICENSE +24 -0
- package/README.md +113 -0
- package/SECURITY.md +8 -0
- package/dist/config/environment.d.ts +78 -0
- package/dist/config/environment.js +150 -0
- package/dist/config/path-resolver.d.ts +117 -0
- package/dist/config/path-resolver.js +247 -0
- package/dist/dependency/dependency-manager.d.ts +66 -0
- package/dist/dependency/dependency-manager.js +257 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +17 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +36 -0
- package/dist/libs/archive-service.d.ts +21 -0
- package/dist/libs/archive-service.js +145 -0
- package/dist/libs/file-management-service.d.ts +59 -0
- package/dist/libs/file-management-service.js +189 -0
- package/dist/libs/iparams-service.d.ts +69 -0
- package/dist/libs/iparams-service.js +136 -0
- package/dist/libs/template-service.d.ts +57 -0
- package/dist/libs/template-service.js +152 -0
- package/dist/logger/cb-logger.d.ts +56 -0
- package/dist/logger/cb-logger.js +13 -0
- package/dist/logger/internal-logger.d.ts +81 -0
- package/dist/logger/internal-logger.js +146 -0
- package/dist/node/file-system.d.ts +66 -0
- package/dist/node/file-system.js +76 -0
- package/dist/node/process.d.ts +30 -0
- package/dist/node/process.js +25 -0
- package/dist/sandbox/sandbox-context.d.ts +37 -0
- package/dist/sandbox/sandbox-context.js +48 -0
- package/dist/sandbox/sandbox-wrapper.d.ts +75 -0
- package/dist/sandbox/sandbox-wrapper.js +2 -0
- package/dist/types/common.d.ts +135 -0
- package/dist/types/common.js +20 -0
- package/dist/validator/iparam-constants.d.ts +49 -0
- package/dist/validator/iparam-constants.js +52 -0
- package/dist/validator/iparam-defns-validator.d.ts +46 -0
- package/dist/validator/iparam-defns-validator.js +291 -0
- package/dist/validator/iparams-inputs-validator.d.ts +62 -0
- package/dist/validator/iparams-inputs-validator.js +289 -0
- package/dist/validator/manifest-validator.d.ts +48 -0
- package/dist/validator/manifest-validator.js +138 -0
- package/dist/validator/package-validator.d.ts +27 -0
- package/dist/validator/package-validator.js +43 -0
- package/dist/validator/validator-utils.d.ts +13 -0
- package/dist/validator/validator-utils.js +26 -0
- package/package.json +45 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TemplateService = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const internal_logger_1 = require("../logger/internal-logger");
|
|
9
|
+
/**
|
|
10
|
+
* Template service for managing templates across different CLI packages
|
|
11
|
+
*/
|
|
12
|
+
class TemplateService {
|
|
13
|
+
constructor(fileSystem, templatesDir) {
|
|
14
|
+
this.fileSystem = fileSystem;
|
|
15
|
+
this.templatesDir = templatesDir;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Validates template exists
|
|
19
|
+
* @param {string} template - Template name to validate
|
|
20
|
+
* @returns {boolean} True if template is valid
|
|
21
|
+
*/
|
|
22
|
+
validateTemplate(template) {
|
|
23
|
+
const availableTemplates = this.getAvailableTemplates();
|
|
24
|
+
return availableTemplates.includes(template);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates app directory for conflicts
|
|
28
|
+
* @param {string} targetDir - Target directory path
|
|
29
|
+
* @param {string} appDir - Original app directory argument
|
|
30
|
+
* @param {string} template - Template name
|
|
31
|
+
* @returns {string[]} Array of conflicting files (empty if no conflicts)
|
|
32
|
+
*/
|
|
33
|
+
validateAppDirectory(targetDir, appDir, template) {
|
|
34
|
+
if (!this.fileSystem.existsSync(targetDir)) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
if (appDir === '.') {
|
|
38
|
+
// When using current directory, check for conflicting files
|
|
39
|
+
const templatePath = path_1.default.join(this.templatesDir, template);
|
|
40
|
+
const templateFiles = this.getTemplateFiles(templatePath);
|
|
41
|
+
const existingFiles = this.fileSystem.readdirSync(targetDir);
|
|
42
|
+
return templateFiles.filter(file => existingFiles.includes(file));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// For other directories, check if not empty
|
|
46
|
+
const files = this.fileSystem.readdirSync(targetDir);
|
|
47
|
+
if (files.length > 0) {
|
|
48
|
+
throw new Error(`Directory '${targetDir}' already exists and is not empty.`);
|
|
49
|
+
}
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets a list of available templates from the templates directory
|
|
55
|
+
* @returns {string[]} Array of template names
|
|
56
|
+
*/
|
|
57
|
+
getAvailableTemplates() {
|
|
58
|
+
if (!this.fileSystem.existsSync(this.templatesDir)) {
|
|
59
|
+
internal_logger_1.__logger.warn(`Templates directory not found: ${this.templatesDir}`);
|
|
60
|
+
return [];
|
|
61
|
+
}
|
|
62
|
+
const templates = this.fileSystem.readdirSync(this.templatesDir, { withFileTypes: true })
|
|
63
|
+
.filter(dirent => dirent.isDirectory())
|
|
64
|
+
.map(dirent => dirent.name);
|
|
65
|
+
return templates;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets the full path to a specific template
|
|
69
|
+
* @param {string} template - Template name
|
|
70
|
+
* @returns {string} Full path to the template directory
|
|
71
|
+
*/
|
|
72
|
+
getTemplatePath(template) {
|
|
73
|
+
return path_1.default.join(this.templatesDir, template);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the templates directory path
|
|
77
|
+
* @returns {string} Path to the templates directory
|
|
78
|
+
*/
|
|
79
|
+
getTemplatesDirectory() {
|
|
80
|
+
return this.templatesDir;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Recursively collects all files from a template directory
|
|
84
|
+
* @param {string} templatePath - Path to the template directory
|
|
85
|
+
* @returns {string[]} Array of file paths relative to template root
|
|
86
|
+
*/
|
|
87
|
+
getTemplateFiles(templatePath) {
|
|
88
|
+
const files = [];
|
|
89
|
+
const collectFiles = (dir, basePath = '') => {
|
|
90
|
+
const items = this.fileSystem.readdirSync(dir);
|
|
91
|
+
for (const item of items) {
|
|
92
|
+
const sourcePath = path_1.default.join(dir, item);
|
|
93
|
+
const relativePath = path_1.default.join(basePath, item);
|
|
94
|
+
const stat = this.fileSystem.statSync(sourcePath);
|
|
95
|
+
if (stat.isDirectory()) {
|
|
96
|
+
collectFiles(sourcePath, relativePath);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
files.push(relativePath);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
collectFiles(templatePath);
|
|
104
|
+
return files;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Recursively copies all files from template directory to target directory
|
|
108
|
+
* @param {string} templatePath - Source template directory path
|
|
109
|
+
* @param {string} targetPath - Target directory path
|
|
110
|
+
*/
|
|
111
|
+
copyTemplateFiles(templatePath, targetPath) {
|
|
112
|
+
const items = this.fileSystem.readdirSync(templatePath);
|
|
113
|
+
for (const item of items) {
|
|
114
|
+
const sourcePath = path_1.default.join(templatePath, item);
|
|
115
|
+
const destPath = path_1.default.join(targetPath, item);
|
|
116
|
+
const stat = this.fileSystem.statSync(sourcePath);
|
|
117
|
+
if (stat.isDirectory()) {
|
|
118
|
+
this.fileSystem.mkdirSync(destPath, { recursive: true });
|
|
119
|
+
this.copyTemplateFiles(sourcePath, destPath);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
this.fileSystem.copyFileSync(sourcePath, destPath);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Prints a tree-like structure of the project directory
|
|
128
|
+
* @param {string} dir - Directory path to print structure for
|
|
129
|
+
* @param {string} [indent=''] - Current indentation level
|
|
130
|
+
*/
|
|
131
|
+
printProjectStructure(dir, indent = '') {
|
|
132
|
+
const items = this.fileSystem.readdirSync(dir);
|
|
133
|
+
for (let i = 0; i < items.length; i++) {
|
|
134
|
+
const item = items[i];
|
|
135
|
+
const itemPath = path_1.default.join(dir, item || '');
|
|
136
|
+
const stat = this.fileSystem.statSync(itemPath);
|
|
137
|
+
const isDirectory = stat.isDirectory();
|
|
138
|
+
const isLastItem = i === items.length - 1;
|
|
139
|
+
// Tree characters
|
|
140
|
+
const treeChar = isLastItem ? '└── ' : '├── ';
|
|
141
|
+
const nextIndent = isLastItem ? ' ' : '│ ';
|
|
142
|
+
// File/directory name
|
|
143
|
+
const name = isDirectory ? item + '/' : item;
|
|
144
|
+
const coloredName = name;
|
|
145
|
+
internal_logger_1.__logger.info(`${indent}${treeChar}${coloredName}`);
|
|
146
|
+
if (isDirectory) {
|
|
147
|
+
this.printProjectStructure(itemPath, indent + nextIndent);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.TemplateService = TemplateService;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for CBLogger to provide strong typing
|
|
3
|
+
* This interface defines the contract that both public and private logger implementations must follow
|
|
4
|
+
*/
|
|
5
|
+
export interface ICBLogger {
|
|
6
|
+
/**
|
|
7
|
+
* Logs an informational message
|
|
8
|
+
* @param args - The message arguments to log
|
|
9
|
+
*/
|
|
10
|
+
info(...args: any[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* Logs a warning message
|
|
13
|
+
* @param args - The message arguments to log
|
|
14
|
+
*/
|
|
15
|
+
warn(...args: any[]): void;
|
|
16
|
+
/**
|
|
17
|
+
* Logs an error message
|
|
18
|
+
* @param args - The message arguments to log
|
|
19
|
+
*/
|
|
20
|
+
error(...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Logs a debug message
|
|
23
|
+
* @param args - The message arguments to log
|
|
24
|
+
*/
|
|
25
|
+
debug(...args: any[]): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Log levels enum for consistent logging across packages
|
|
29
|
+
*/
|
|
30
|
+
export declare enum LogLevel {
|
|
31
|
+
ERROR = "ERROR",
|
|
32
|
+
WARN = "WARN",
|
|
33
|
+
INFO = "INFO",
|
|
34
|
+
DEBUG = "DEBUG"
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Safe console interface that provides controlled console methods
|
|
38
|
+
*/
|
|
39
|
+
export interface SafeConsole {
|
|
40
|
+
log: (...args: any[]) => void;
|
|
41
|
+
info: (...args: any[]) => void;
|
|
42
|
+
warn: (...args: any[]) => void;
|
|
43
|
+
error: (...args: any[]) => void;
|
|
44
|
+
debug: (...args: any[]) => void;
|
|
45
|
+
trace: () => void;
|
|
46
|
+
table: () => void;
|
|
47
|
+
time: () => void;
|
|
48
|
+
timeEnd: () => void;
|
|
49
|
+
timeLog: () => void;
|
|
50
|
+
count: () => void;
|
|
51
|
+
countReset: () => void;
|
|
52
|
+
group: () => void;
|
|
53
|
+
groupCollapsed: () => void;
|
|
54
|
+
groupEnd: () => void;
|
|
55
|
+
clear: () => void;
|
|
56
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogLevel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Log levels enum for consistent logging across packages
|
|
6
|
+
*/
|
|
7
|
+
var LogLevel;
|
|
8
|
+
(function (LogLevel) {
|
|
9
|
+
LogLevel["ERROR"] = "ERROR";
|
|
10
|
+
LogLevel["WARN"] = "WARN";
|
|
11
|
+
LogLevel["INFO"] = "INFO";
|
|
12
|
+
LogLevel["DEBUG"] = "DEBUG";
|
|
13
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import winston from 'winston';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for InternalLogger
|
|
4
|
+
*/
|
|
5
|
+
export interface InternalLoggerConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to use JSON format for logging (default: false)
|
|
8
|
+
*/
|
|
9
|
+
useJsonFormat?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Context options for child loggers
|
|
13
|
+
*/
|
|
14
|
+
export interface ChildLoggerContext {
|
|
15
|
+
/**
|
|
16
|
+
* Additional context to include in all log messages
|
|
17
|
+
*/
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Winston-based InternalLogger provides logging capabilities for the Chargebee Apps CLI itself
|
|
22
|
+
* This is separate from the user-facing cb-logger and uses Winston for structured logging
|
|
23
|
+
* Shared implementation for both public and private CLI packages
|
|
24
|
+
*/
|
|
25
|
+
export declare class InternalLogger {
|
|
26
|
+
private logger;
|
|
27
|
+
private config;
|
|
28
|
+
constructor(config?: InternalLoggerConfig);
|
|
29
|
+
/**
|
|
30
|
+
* Creates a Winston logger instance with appropriate formatting
|
|
31
|
+
* @returns {winston.Logger} The configured Winston logger
|
|
32
|
+
*/
|
|
33
|
+
private createWinstonLogger;
|
|
34
|
+
/**
|
|
35
|
+
* Creates JSON format for structured logging
|
|
36
|
+
* @returns {winston.Logform.Format} The JSON format
|
|
37
|
+
*/
|
|
38
|
+
protected createJsonFormat(): winston.Logform.Format;
|
|
39
|
+
/**
|
|
40
|
+
* Creates text format for human-readable logging
|
|
41
|
+
* @returns {winston.Logform.Format} The text format
|
|
42
|
+
*/
|
|
43
|
+
protected createTextFormat(): winston.Logform.Format;
|
|
44
|
+
/**
|
|
45
|
+
* Logs an informational message
|
|
46
|
+
* @param {...any} args - The message arguments to log
|
|
47
|
+
*/
|
|
48
|
+
info(...args: any[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Logs a warning message
|
|
51
|
+
* @param {...any} args - The message arguments to log
|
|
52
|
+
*/
|
|
53
|
+
warn(...args: any[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Logs an error message
|
|
56
|
+
* @param {...any} args - The message arguments to log
|
|
57
|
+
*/
|
|
58
|
+
error(...args: any[]): void;
|
|
59
|
+
/**
|
|
60
|
+
* Logs a debug message
|
|
61
|
+
* @param {...any} args - The message arguments to log
|
|
62
|
+
*/
|
|
63
|
+
debug(...args: any[]): void;
|
|
64
|
+
/**
|
|
65
|
+
* Logs a success message (alias for info with success indicator)
|
|
66
|
+
* @param {...any} args - The message arguments to log
|
|
67
|
+
*/
|
|
68
|
+
success(...args: any[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Logs a failure message (alias for error with failure indicator)
|
|
71
|
+
* @param {...any} args - The message arguments to log
|
|
72
|
+
*/
|
|
73
|
+
failure(...args: any[]): void;
|
|
74
|
+
/**
|
|
75
|
+
* Creates a child logger with additional context
|
|
76
|
+
* @param {ChildLoggerContext} context - Additional context to include in all log messages
|
|
77
|
+
* @returns {InternalLogger} A new InternalLogger instance with the child context
|
|
78
|
+
*/
|
|
79
|
+
child(context: ChildLoggerContext): InternalLogger;
|
|
80
|
+
}
|
|
81
|
+
export declare const __logger: InternalLogger;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.__logger = exports.InternalLogger = void 0;
|
|
7
|
+
const cb_logger_1 = require("./cb-logger");
|
|
8
|
+
const winston_1 = __importDefault(require("winston"));
|
|
9
|
+
/**
|
|
10
|
+
* Winston-based InternalLogger provides logging capabilities for the Chargebee Apps CLI itself
|
|
11
|
+
* This is separate from the user-facing cb-logger and uses Winston for structured logging
|
|
12
|
+
* Shared implementation for both public and private CLI packages
|
|
13
|
+
*/
|
|
14
|
+
class InternalLogger {
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
this.config = {
|
|
17
|
+
useJsonFormat: false,
|
|
18
|
+
...config
|
|
19
|
+
};
|
|
20
|
+
this.logger = this.createWinstonLogger();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a Winston logger instance with appropriate formatting
|
|
24
|
+
* @returns {winston.Logger} The configured Winston logger
|
|
25
|
+
*/
|
|
26
|
+
createWinstonLogger() {
|
|
27
|
+
const logLevel = process.env['CB_LOG_LEVEL'] || cb_logger_1.LogLevel.INFO;
|
|
28
|
+
// Create custom format based on configuration
|
|
29
|
+
const customFormat = winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.errors({ stack: true }), this.config.useJsonFormat ? this.createJsonFormat() : this.createTextFormat());
|
|
30
|
+
return winston_1.default.createLogger({
|
|
31
|
+
level: logLevel.toLowerCase(),
|
|
32
|
+
format: customFormat,
|
|
33
|
+
transports: [
|
|
34
|
+
new winston_1.default.transports.Console({})
|
|
35
|
+
]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates JSON format for structured logging
|
|
40
|
+
* @returns {winston.Logform.Format} The JSON format
|
|
41
|
+
*/
|
|
42
|
+
createJsonFormat() {
|
|
43
|
+
return winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.printf((info) => {
|
|
44
|
+
const logEntry = {
|
|
45
|
+
timestamp: info['timestamp'],
|
|
46
|
+
level: info.level,
|
|
47
|
+
service: 'Internal',
|
|
48
|
+
message: info.message
|
|
49
|
+
};
|
|
50
|
+
// Include all additional context from child loggers
|
|
51
|
+
Object.keys(info).forEach(key => {
|
|
52
|
+
if (!['timestamp', 'level', 'message', 'stack'].includes(key)) {
|
|
53
|
+
logEntry[key] = info[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (info['stack']) {
|
|
57
|
+
logEntry.stack = info['stack'];
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify(logEntry);
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Creates text format for human-readable logging
|
|
64
|
+
* @returns {winston.Logform.Format} The text format
|
|
65
|
+
*/
|
|
66
|
+
createTextFormat() {
|
|
67
|
+
return winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.colorize(), winston_1.default.format.printf((info) => {
|
|
68
|
+
const timestamp = info['timestamp'];
|
|
69
|
+
const level = info.level;
|
|
70
|
+
const service = 'Internal';
|
|
71
|
+
const message = info.message;
|
|
72
|
+
const stack = info['stack'] ? `\n${info['stack']}` : '';
|
|
73
|
+
// Build context string from additional properties
|
|
74
|
+
const contextParts = [];
|
|
75
|
+
Object.keys(info).forEach(key => {
|
|
76
|
+
if (!['timestamp', 'level', 'message', 'stack'].includes(key)) {
|
|
77
|
+
contextParts.push(`${key}=${info[key]}`);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const contextStr = contextParts.length > 0 ? ` [${contextParts.join(', ')}]` : '';
|
|
81
|
+
return `${timestamp} [${level}] [${service}]${contextStr} ${message}${stack}`;
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Logs an informational message
|
|
86
|
+
* @param {...any} args - The message arguments to log
|
|
87
|
+
*/
|
|
88
|
+
info(...args) {
|
|
89
|
+
const message = args.join(' ');
|
|
90
|
+
this.logger.info(message);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Logs a warning message
|
|
94
|
+
* @param {...any} args - The message arguments to log
|
|
95
|
+
*/
|
|
96
|
+
warn(...args) {
|
|
97
|
+
const message = args.join(' ');
|
|
98
|
+
this.logger.warn(message);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Logs an error message
|
|
102
|
+
* @param {...any} args - The message arguments to log
|
|
103
|
+
*/
|
|
104
|
+
error(...args) {
|
|
105
|
+
const message = args.join(' ');
|
|
106
|
+
this.logger.error(message);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Logs a debug message
|
|
110
|
+
* @param {...any} args - The message arguments to log
|
|
111
|
+
*/
|
|
112
|
+
debug(...args) {
|
|
113
|
+
const message = args.join(' ');
|
|
114
|
+
this.logger.debug(message);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Logs a success message (alias for info with success indicator)
|
|
118
|
+
* @param {...any} args - The message arguments to log
|
|
119
|
+
*/
|
|
120
|
+
success(...args) {
|
|
121
|
+
const message = args.join(' ');
|
|
122
|
+
this.logger.info(`✅ ${message}`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Logs a failure message (alias for error with failure indicator)
|
|
126
|
+
* @param {...any} args - The message arguments to log
|
|
127
|
+
*/
|
|
128
|
+
failure(...args) {
|
|
129
|
+
const message = args.join(' ');
|
|
130
|
+
this.logger.error(`❌ ${message}`);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Creates a child logger with additional context
|
|
134
|
+
* @param {ChildLoggerContext} context - Additional context to include in all log messages
|
|
135
|
+
* @returns {InternalLogger} A new InternalLogger instance with the child context
|
|
136
|
+
*/
|
|
137
|
+
child(context) {
|
|
138
|
+
const childLogger = new InternalLogger(this.config);
|
|
139
|
+
// Create a Winston child logger with the provided context
|
|
140
|
+
childLogger.logger = this.logger.child(context);
|
|
141
|
+
return childLogger;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.InternalLogger = InternalLogger;
|
|
145
|
+
// Create a singleton instance for default logger
|
|
146
|
+
exports.__logger = new InternalLogger();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import fs, { Stats } from 'fs';
|
|
2
|
+
/**
|
|
3
|
+
* FileSystem interface provides a strongly-typed abstraction
|
|
4
|
+
* over common Node.js filesystem operations.
|
|
5
|
+
*/
|
|
6
|
+
export interface CBFileSystem {
|
|
7
|
+
/** Checks whether a given path exists on the filesystem. */
|
|
8
|
+
existsSync: (path: string) => boolean;
|
|
9
|
+
/** Reads the contents of a directory and returns an array of entries. */
|
|
10
|
+
readdirSync: (path: string, options?: any) => any[];
|
|
11
|
+
/** Creates a new directory, optionally allowing recursive creation. */
|
|
12
|
+
mkdirSync: (path: string, options?: {
|
|
13
|
+
recursive: boolean;
|
|
14
|
+
}) => void;
|
|
15
|
+
/** Deletes a file at the given path. */
|
|
16
|
+
unlinkSync: (path: string) => void;
|
|
17
|
+
/** Removes a directory at the given path. */
|
|
18
|
+
rmdirSync: (path: string) => void;
|
|
19
|
+
/** Returns stats for a given path, including directory check and size. */
|
|
20
|
+
statSync: (path: string) => {
|
|
21
|
+
isDirectory: () => boolean;
|
|
22
|
+
size: number;
|
|
23
|
+
};
|
|
24
|
+
/** Creates a writable stream to a file at the given path. */
|
|
25
|
+
createWriteStream: (path: string) => NodeJS.WritableStream;
|
|
26
|
+
/** Reads a file's contents as a string with specified encoding. */
|
|
27
|
+
readFileSync: (path: string, encoding: string) => string;
|
|
28
|
+
/** Writes string data to a file at the given path. */
|
|
29
|
+
writeFileSync: (path: string, data: string) => void;
|
|
30
|
+
/** Copies a file from source to destination. */
|
|
31
|
+
copyFileSync: (src: string, dest: string) => void;
|
|
32
|
+
/** Returns stats for a given path, including symbolic link check. */
|
|
33
|
+
lstatSync: (path: string) => Stats;
|
|
34
|
+
/** Renames a file or directory. */
|
|
35
|
+
renameSync: (oldPath: string, newPath: string) => void;
|
|
36
|
+
/** Copies a file or directory from source to destination. */
|
|
37
|
+
cpSync: (src: string, dest: string, options?: {
|
|
38
|
+
recursive: boolean;
|
|
39
|
+
}) => void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* FileSystemService provides a class-based implementation of the FileSystem interface.
|
|
43
|
+
* Use this for dependency injection for all the filesystem operations, and for testing we can use custom implemenatation if needed.
|
|
44
|
+
*/
|
|
45
|
+
export declare class FileSystemService implements CBFileSystem {
|
|
46
|
+
existsSync(path: string): boolean;
|
|
47
|
+
readdirSync(path: string, options?: any): any[];
|
|
48
|
+
mkdirSync(path: string, options?: {
|
|
49
|
+
recursive: boolean;
|
|
50
|
+
}): void;
|
|
51
|
+
unlinkSync(path: string): void;
|
|
52
|
+
rmdirSync(path: string): void;
|
|
53
|
+
statSync(path: string): {
|
|
54
|
+
isDirectory: () => boolean;
|
|
55
|
+
size: number;
|
|
56
|
+
};
|
|
57
|
+
createWriteStream(path: string): fs.WriteStream;
|
|
58
|
+
readFileSync(path: string, encoding: string): string;
|
|
59
|
+
writeFileSync(path: string, data: string): void;
|
|
60
|
+
copyFileSync(src: string, dest: string): void;
|
|
61
|
+
lstatSync(path: string): Stats;
|
|
62
|
+
renameSync(oldPath: string, newPath: string): void;
|
|
63
|
+
cpSync(src: string, dest: string, options?: {
|
|
64
|
+
recursive: boolean;
|
|
65
|
+
}): void;
|
|
66
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FileSystemService = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
/**
|
|
9
|
+
* FileSystemService provides a class-based implementation of the FileSystem interface.
|
|
10
|
+
* Use this for dependency injection for all the filesystem operations, and for testing we can use custom implemenatation if needed.
|
|
11
|
+
*/
|
|
12
|
+
class FileSystemService {
|
|
13
|
+
existsSync(path) {
|
|
14
|
+
return fs_1.default.existsSync(path);
|
|
15
|
+
}
|
|
16
|
+
readdirSync(path, options) {
|
|
17
|
+
return fs_1.default.readdirSync(path, options);
|
|
18
|
+
}
|
|
19
|
+
mkdirSync(path, options) {
|
|
20
|
+
fs_1.default.mkdirSync(path, options);
|
|
21
|
+
}
|
|
22
|
+
unlinkSync(path) {
|
|
23
|
+
fs_1.default.unlinkSync(path);
|
|
24
|
+
}
|
|
25
|
+
rmdirSync(path) {
|
|
26
|
+
fs_1.default.rmdirSync(path);
|
|
27
|
+
}
|
|
28
|
+
statSync(path) {
|
|
29
|
+
return fs_1.default.statSync(path);
|
|
30
|
+
}
|
|
31
|
+
createWriteStream(path) {
|
|
32
|
+
return fs_1.default.createWriteStream(path);
|
|
33
|
+
}
|
|
34
|
+
readFileSync(path, encoding) {
|
|
35
|
+
return fs_1.default.readFileSync(path, encoding);
|
|
36
|
+
}
|
|
37
|
+
writeFileSync(path, data) {
|
|
38
|
+
fs_1.default.writeFileSync(path, data);
|
|
39
|
+
}
|
|
40
|
+
copyFileSync(src, dest) {
|
|
41
|
+
fs_1.default.copyFileSync(src, dest);
|
|
42
|
+
}
|
|
43
|
+
lstatSync(path) {
|
|
44
|
+
return fs_1.default.lstatSync(path);
|
|
45
|
+
}
|
|
46
|
+
renameSync(oldPath, newPath) {
|
|
47
|
+
try {
|
|
48
|
+
fs_1.default.renameSync(oldPath, newPath);
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (err.code === 'EXDEV') {
|
|
52
|
+
// Cross-device rename (e.g. Docker overlay filesystem) — fall back to copy + delete
|
|
53
|
+
try {
|
|
54
|
+
fs_1.default.cpSync(oldPath, newPath, { recursive: true });
|
|
55
|
+
fs_1.default.rmSync(oldPath, { recursive: true, force: true });
|
|
56
|
+
}
|
|
57
|
+
catch (copyErr) {
|
|
58
|
+
try {
|
|
59
|
+
fs_1.default.rmSync(newPath, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// best-effort cleanup; ignore errors
|
|
63
|
+
}
|
|
64
|
+
throw copyErr;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
cpSync(src, dest, options) {
|
|
73
|
+
fs_1.default.cpSync(src, dest, options);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.FileSystemService = FileSystemService;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process interface provides a typed abstraction over common Node.js
|
|
3
|
+
* process-level operations.
|
|
4
|
+
*
|
|
5
|
+
* It covers process lifecycle control, environment variables,
|
|
6
|
+
* current working directory management, and event handling.
|
|
7
|
+
*/
|
|
8
|
+
export interface CBProcess {
|
|
9
|
+
/** Changes the current working directory */
|
|
10
|
+
chdir: (path: string) => void;
|
|
11
|
+
/** Terminates the Node.js process */
|
|
12
|
+
exit: (code?: number) => never;
|
|
13
|
+
/** Returns the current working directory */
|
|
14
|
+
cwd: () => string;
|
|
15
|
+
/** Access to environment variables */
|
|
16
|
+
env: NodeJS.ProcessEnv;
|
|
17
|
+
/** Registers an event listener */
|
|
18
|
+
on: (event: string, listener: (...args: any[]) => void) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* ProcessService provides a class-based implementation of the Process interface.
|
|
22
|
+
* Use this for dependency injection for all the process operations, and for testing we can use custom implemenatation if needed.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ProcessService implements CBProcess {
|
|
25
|
+
chdir(path: string): void;
|
|
26
|
+
cwd(): string;
|
|
27
|
+
exit(code?: number): never;
|
|
28
|
+
on(event: string, listener: (...args: any[]) => void): void;
|
|
29
|
+
get env(): NodeJS.ProcessEnv;
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProcessService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* ProcessService provides a class-based implementation of the Process interface.
|
|
6
|
+
* Use this for dependency injection for all the process operations, and for testing we can use custom implemenatation if needed.
|
|
7
|
+
*/
|
|
8
|
+
class ProcessService {
|
|
9
|
+
chdir(path) {
|
|
10
|
+
process.chdir(path);
|
|
11
|
+
}
|
|
12
|
+
cwd() {
|
|
13
|
+
return process.cwd();
|
|
14
|
+
}
|
|
15
|
+
exit(code) {
|
|
16
|
+
process.exit(code);
|
|
17
|
+
}
|
|
18
|
+
on(event, listener) {
|
|
19
|
+
process.on(event, listener);
|
|
20
|
+
}
|
|
21
|
+
get env() {
|
|
22
|
+
return process.env;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ProcessService = ProcessService;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ContextData {
|
|
2
|
+
eventId: string;
|
|
3
|
+
eventType: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ExecutionContext extends ContextData {
|
|
6
|
+
startTime: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* SandboxContext manages the execution context for sandboxed code execution
|
|
10
|
+
* using AsyncLocalStorage to maintain correlation between event and site information
|
|
11
|
+
*/
|
|
12
|
+
export declare class SandboxContext {
|
|
13
|
+
private asyncLocalStorage;
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new execution context with event and site information
|
|
17
|
+
* @param {Object} contextData - The context data containing event and site information
|
|
18
|
+
* @param {string} contextData.eventId - The unique identifier for the event
|
|
19
|
+
* @param {string} contextData.eventType - The type of the event (e.g., 'customer_created')
|
|
20
|
+
* @param {string} contextData.site - The site/tenant identifier in Chargebee
|
|
21
|
+
* @param {Function} callback - The function to execute within this context
|
|
22
|
+
* @returns {Promise<any>} The result of the callback execution
|
|
23
|
+
*/
|
|
24
|
+
run(contextData: ContextData, callback: () => Promise<any>): Promise<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the current execution context
|
|
27
|
+
* @returns {Object|null} The current context or null if not in an execution context
|
|
28
|
+
*/
|
|
29
|
+
getCurrentContext(): ExecutionContext | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if there is an active execution context
|
|
32
|
+
* @returns {boolean} True if there is an active context, false otherwise
|
|
33
|
+
*/
|
|
34
|
+
hasContext(): boolean;
|
|
35
|
+
}
|
|
36
|
+
export declare const sandboxContext: SandboxContext;
|
|
37
|
+
export default sandboxContext;
|