@chargebee/chargebee-apps 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 +472 -0
- package/SECURITY.md +8 -0
- package/bin/index.js +1 -0
- package/dist/api/iparams.routes.d.ts +6 -0
- package/dist/api/iparams.routes.js +73 -0
- package/dist/api/routes.d.ts +39 -0
- package/dist/api/routes.js +339 -0
- package/dist/commands/create.d.ts +30 -0
- package/dist/commands/create.js +102 -0
- package/dist/commands/index.d.ts +7 -0
- package/dist/commands/index.js +93 -0
- package/dist/commands/package.d.ts +20 -0
- package/dist/commands/package.js +93 -0
- package/dist/commands/run.d.ts +25 -0
- package/dist/commands/run.js +106 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/registry.d.ts +17 -0
- package/dist/registry.js +39 -0
- package/package.json +70 -0
|
@@ -0,0 +1,93 @@
|
|
|
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.packageCommand = exports.PackageCommand = void 0;
|
|
7
|
+
const chargebee_apps_shared_1 = require("@chargebee/chargebee-apps-shared");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const registry_1 = require("../registry");
|
|
11
|
+
/**
|
|
12
|
+
* Package configuration for file inclusion rules
|
|
13
|
+
* Only includes essential files needed for the serverless application
|
|
14
|
+
*/
|
|
15
|
+
const PACKAGE_CONFIG = {
|
|
16
|
+
include: {
|
|
17
|
+
directories: [
|
|
18
|
+
{
|
|
19
|
+
name: '.', // Root directory - only include specific files
|
|
20
|
+
includeFiles: ['manifest.json', 'iparams.json'], // Include manifest.json and iparams.json
|
|
21
|
+
excludeSubdirs: ['node_modules', 'dist', 'handler', 'test_data', 'types']
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'handler',
|
|
25
|
+
allowedExtensions: ['.js', '.json'],
|
|
26
|
+
excludeSubdirs: ['node_modules'],
|
|
27
|
+
excludeFiles: ['package.json', 'package-lock.json']
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Main package command class
|
|
34
|
+
*/
|
|
35
|
+
class PackageCommand {
|
|
36
|
+
constructor(fileSystem, process, fileManagementService, packageValidator, archiveService) {
|
|
37
|
+
const registry = registry_1.PublicCliRegistry.getInstance();
|
|
38
|
+
this.fileSystem = fileSystem || registry.fileSystem;
|
|
39
|
+
this.process = process || registry.process;
|
|
40
|
+
this.fileManagementService = fileManagementService || new chargebee_apps_shared_1.FileManagementService(this.fileSystem, PACKAGE_CONFIG);
|
|
41
|
+
this.packageValidator = packageValidator || new chargebee_apps_shared_1.PackageValidator(this.fileSystem);
|
|
42
|
+
this.archiveService = archiveService || new chargebee_apps_shared_1.ArchiveService(this.fileSystem);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Packages a serverless application into a zip file
|
|
46
|
+
* @param {string} appDir - The application directory to package
|
|
47
|
+
* @param {string} packageName - The name of the package
|
|
48
|
+
*/
|
|
49
|
+
async execute(appDir, options) {
|
|
50
|
+
const targetDir = path_1.default.resolve(appDir);
|
|
51
|
+
const appName = path_1.default.basename(targetDir);
|
|
52
|
+
chargebee_apps_shared_1.__logger.info('Packaging serverless application...');
|
|
53
|
+
chargebee_apps_shared_1.__logger.info(`App directory: ${targetDir}`);
|
|
54
|
+
// Validate app directory
|
|
55
|
+
this.validate(targetDir);
|
|
56
|
+
chargebee_apps_shared_1.__logger.info(chalk_1.default.green('✓ Valid application directory'));
|
|
57
|
+
// Determine output path
|
|
58
|
+
const outputPath = this.fileManagementService.determineOutputPath(targetDir, appName, options.name);
|
|
59
|
+
// Clean existing packages in dist directory
|
|
60
|
+
this.fileManagementService.cleanExistingPackages(targetDir);
|
|
61
|
+
try {
|
|
62
|
+
const filesToPackage = this.fileManagementService.collectFilesToPackage(targetDir);
|
|
63
|
+
await this.archiveService.createZipPackage(filesToPackage, targetDir, outputPath);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const err = error;
|
|
67
|
+
chargebee_apps_shared_1.__logger.error(`Error while creating zip: ${err.message}`);
|
|
68
|
+
this.process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
// Create the zip package
|
|
71
|
+
chargebee_apps_shared_1.__logger.info(chalk_1.default.green(`✓ Package created successfully: ${outputPath}`));
|
|
72
|
+
chargebee_apps_shared_1.__logger.info(`Package size: ${this.fileManagementService.getFileSize(outputPath)}`);
|
|
73
|
+
}
|
|
74
|
+
validate(targetDir) {
|
|
75
|
+
if (!this.packageValidator.validateAppDirectoryExists(targetDir)) {
|
|
76
|
+
chargebee_apps_shared_1.__logger.error('✗ Application directory does not exist');
|
|
77
|
+
this.process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
if (!this.packageValidator.validateManifestExists(targetDir)) {
|
|
80
|
+
chargebee_apps_shared_1.__logger.error('✗ manifest.json not found in the specified directory');
|
|
81
|
+
chargebee_apps_shared_1.__logger.info('Make sure you are running the command from a valid serverless app directory');
|
|
82
|
+
this.process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
if (!this.packageValidator.validateHandlerExists(targetDir)) {
|
|
85
|
+
chargebee_apps_shared_1.__logger.error('✗ handler.js not found in the specified directory');
|
|
86
|
+
chargebee_apps_shared_1.__logger.info('Make sure you are running the command from a valid serverless app directory');
|
|
87
|
+
this.process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.PackageCommand = PackageCommand;
|
|
92
|
+
// Export for use in commands/index.ts
|
|
93
|
+
exports.packageCommand = new PackageCommand();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CBFileSystem, CBProcess, DependencyManager, RunOptions } from '@chargebee/chargebee-apps-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Main run command class
|
|
4
|
+
*/
|
|
5
|
+
export declare class RunCommand {
|
|
6
|
+
private portService;
|
|
7
|
+
private process;
|
|
8
|
+
private fileSystem;
|
|
9
|
+
private packageValidator;
|
|
10
|
+
private dependencyManager;
|
|
11
|
+
private iparamsService;
|
|
12
|
+
constructor(fileSystem?: CBFileSystem, process?: CBProcess, dependencyManager?: DependencyManager);
|
|
13
|
+
/**
|
|
14
|
+
* Starts the local development server for testing serverless applications
|
|
15
|
+
* @param {string} options - The options for the run command
|
|
16
|
+
* @param {string} appDir - The application directory to run
|
|
17
|
+
*/
|
|
18
|
+
execute(options: RunOptions, appDir: string): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Validates manifest and installs dependencies using manifest.dependencies.
|
|
21
|
+
*/
|
|
22
|
+
private installDependencies;
|
|
23
|
+
private validate;
|
|
24
|
+
}
|
|
25
|
+
export declare const runCommand: RunCommand;
|
|
@@ -0,0 +1,106 @@
|
|
|
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.runCommand = exports.RunCommand = void 0;
|
|
7
|
+
const chargebee_apps_libs_1 = require("@chargebee/chargebee-apps-libs");
|
|
8
|
+
const chargebee_apps_shared_1 = require("@chargebee/chargebee-apps-shared");
|
|
9
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const routes_1 = require("../api/routes");
|
|
12
|
+
const registry_1 = require("../registry");
|
|
13
|
+
/**
|
|
14
|
+
* Main run command class
|
|
15
|
+
*/
|
|
16
|
+
class RunCommand {
|
|
17
|
+
constructor(fileSystem, process, dependencyManager) {
|
|
18
|
+
const registry = registry_1.PublicCliRegistry.getInstance();
|
|
19
|
+
this.process = process || registry.process;
|
|
20
|
+
this.fileSystem = fileSystem || registry.fileSystem;
|
|
21
|
+
this.portService = new chargebee_apps_libs_1.PortService();
|
|
22
|
+
this.packageValidator = new chargebee_apps_shared_1.PackageValidator(registry.fileSystem);
|
|
23
|
+
this.dependencyManager = dependencyManager || registry.dependencyManager;
|
|
24
|
+
this.iparamsService = new chargebee_apps_shared_1.IparamsService(registry.fileSystem);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Starts the local development server for testing serverless applications
|
|
28
|
+
* @param {string} options - The options for the run command
|
|
29
|
+
* @param {string} appDir - The application directory to run
|
|
30
|
+
*/
|
|
31
|
+
async execute(options, appDir) {
|
|
32
|
+
const port = options.port;
|
|
33
|
+
if (!this.portService.isValidPort(port)) {
|
|
34
|
+
chargebee_apps_shared_1.__logger.error('Invalid port number: ' + port);
|
|
35
|
+
this.process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
const portNumber = this.portService.parsePort(port);
|
|
38
|
+
const targetDir = path_1.default.resolve(appDir);
|
|
39
|
+
chargebee_apps_shared_1.__logger.info('Starting development server...');
|
|
40
|
+
chargebee_apps_shared_1.__logger.info('');
|
|
41
|
+
chargebee_apps_shared_1.__logger.info(`App directory: ${targetDir}`);
|
|
42
|
+
chargebee_apps_shared_1.__logger.info(`Port: ${portNumber}`);
|
|
43
|
+
chargebee_apps_shared_1.__logger.info('');
|
|
44
|
+
this.validate(targetDir);
|
|
45
|
+
await this.installDependencies(targetDir);
|
|
46
|
+
// Change to the app directory before starting the server
|
|
47
|
+
this.process.chdir(targetDir);
|
|
48
|
+
chargebee_apps_shared_1.__logger.info(chalk_1.default.green(`✓ Server started successfully on http://localhost:${portNumber}`));
|
|
49
|
+
chargebee_apps_shared_1.__logger.info(`Press Ctrl+C to stop the server`);
|
|
50
|
+
chargebee_apps_shared_1.__logger.info('');
|
|
51
|
+
// Start the actual API server
|
|
52
|
+
(0, routes_1.setupServer)(portNumber, targetDir, this.fileSystem, this.process, this.dependencyManager);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Validates manifest and installs dependencies using manifest.dependencies.
|
|
56
|
+
*/
|
|
57
|
+
async installDependencies(targetDir) {
|
|
58
|
+
try {
|
|
59
|
+
const configLoader = new chargebee_apps_libs_1.ConfigLoader(this.fileSystem);
|
|
60
|
+
const allowedModules = configLoader.loadAllowedModules();
|
|
61
|
+
const manifestValidator = new chargebee_apps_shared_1.ManifestValidator(allowedModules, this.fileSystem);
|
|
62
|
+
const manifestPath = path_1.default.join(targetDir, 'manifest.json');
|
|
63
|
+
const manifest = manifestValidator.validateAndGetManifestFile(manifestPath);
|
|
64
|
+
await this.dependencyManager.ensureDependencies(targetDir, manifest);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const err = error;
|
|
68
|
+
chargebee_apps_shared_1.__logger.error('✗ Failed to install dependencies');
|
|
69
|
+
chargebee_apps_shared_1.__logger.error(err.message);
|
|
70
|
+
this.process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
validate(targetDir) {
|
|
74
|
+
// Check if the directory exists
|
|
75
|
+
if (!this.packageValidator.validateAppDirectoryExists(targetDir)) {
|
|
76
|
+
chargebee_apps_shared_1.__logger.error('✗ Application directory does not exist');
|
|
77
|
+
this.process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
// Check if it's a valid serverless app directory
|
|
80
|
+
if (!this.packageValidator.validateManifestExists(targetDir)) {
|
|
81
|
+
chargebee_apps_shared_1.__logger.error('✗ manifest.json not found in the specified directory');
|
|
82
|
+
chargebee_apps_shared_1.__logger.error('Make sure you are running the command from a valid serverless app directory');
|
|
83
|
+
this.process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
// Check if the handler.js file exists
|
|
86
|
+
if (!this.packageValidator.validateHandlerExists(targetDir)) {
|
|
87
|
+
chargebee_apps_shared_1.__logger.error('✗ handler.js not found in the specified directory');
|
|
88
|
+
chargebee_apps_shared_1.__logger.error('Make sure you are running the command from a valid serverless app directory');
|
|
89
|
+
this.process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
if (this.iparamsService.iparamsFileExists(targetDir)) {
|
|
92
|
+
try {
|
|
93
|
+
this.iparamsService.validateIparamDefns(targetDir);
|
|
94
|
+
chargebee_apps_shared_1.__logger.debug('✓ iparams.json is valid');
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
chargebee_apps_shared_1.__logger.error('✗ Invalid iparams.json');
|
|
98
|
+
chargebee_apps_shared_1.__logger.error(error.message);
|
|
99
|
+
this.process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.RunCommand = RunCommand;
|
|
105
|
+
// Export for use in commands/index.ts
|
|
106
|
+
exports.runCommand = new RunCommand();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CBFileSystem, CBProcess, DependencyManager, InternalLogger } from '@chargebee/chargebee-apps-shared';
|
|
2
|
+
/**
|
|
3
|
+
* Public CLI Registry - Configures all dependencies for public CLI
|
|
4
|
+
*/
|
|
5
|
+
export declare class PublicCliRegistry {
|
|
6
|
+
private static instance;
|
|
7
|
+
private _fileSystem;
|
|
8
|
+
private _process;
|
|
9
|
+
private _dependencyManager;
|
|
10
|
+
private _logger;
|
|
11
|
+
private constructor();
|
|
12
|
+
static getInstance(): PublicCliRegistry;
|
|
13
|
+
get fileSystem(): CBFileSystem;
|
|
14
|
+
get process(): CBProcess;
|
|
15
|
+
get dependencyManager(): DependencyManager;
|
|
16
|
+
get logger(): InternalLogger;
|
|
17
|
+
}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublicCliRegistry = void 0;
|
|
4
|
+
const chargebee_apps_shared_1 = require("@chargebee/chargebee-apps-shared");
|
|
5
|
+
/**
|
|
6
|
+
* Public CLI Registry - Configures all dependencies for public CLI
|
|
7
|
+
*/
|
|
8
|
+
class PublicCliRegistry {
|
|
9
|
+
constructor() {
|
|
10
|
+
// Initialize with public implementations
|
|
11
|
+
this._fileSystem = new chargebee_apps_shared_1.FileSystemService();
|
|
12
|
+
this._process = new chargebee_apps_shared_1.ProcessService();
|
|
13
|
+
this._dependencyManager = new chargebee_apps_shared_1.DependencyManager(this._fileSystem);
|
|
14
|
+
// Initialize logger with public CLI configuration
|
|
15
|
+
const loggerConfig = {
|
|
16
|
+
useJsonFormat: false
|
|
17
|
+
};
|
|
18
|
+
this._logger = new chargebee_apps_shared_1.InternalLogger(loggerConfig);
|
|
19
|
+
}
|
|
20
|
+
static getInstance() {
|
|
21
|
+
if (!PublicCliRegistry.instance) {
|
|
22
|
+
PublicCliRegistry.instance = new PublicCliRegistry();
|
|
23
|
+
}
|
|
24
|
+
return PublicCliRegistry.instance;
|
|
25
|
+
}
|
|
26
|
+
get fileSystem() {
|
|
27
|
+
return this._fileSystem;
|
|
28
|
+
}
|
|
29
|
+
get process() {
|
|
30
|
+
return this._process;
|
|
31
|
+
}
|
|
32
|
+
get dependencyManager() {
|
|
33
|
+
return this._dependencyManager;
|
|
34
|
+
}
|
|
35
|
+
get logger() {
|
|
36
|
+
return this._logger;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.PublicCliRegistry = PublicCliRegistry;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chargebee/chargebee-apps",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Chargebee Apps CLI tool that enables you to create, test and package the applications",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"chargebee-apps": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"bin",
|
|
12
|
+
"LICENSE",
|
|
13
|
+
"SECURITY.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"clean": "rm -rf dist && rm -rf coverage",
|
|
18
|
+
"start": "node dist/index.js",
|
|
19
|
+
"cli": "node dist/index.js",
|
|
20
|
+
"dev": "ts-node src/index.ts",
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"test:watch": "jest --watch",
|
|
23
|
+
"test:coverage": "jest --coverage",
|
|
24
|
+
"test:coverage:unit": "jest --coverage --testPathPattern=tests/unit",
|
|
25
|
+
"test:coverage:integration": "jest --coverage --testPathPattern=tests/integration",
|
|
26
|
+
"test:coverage:detailed": "jest --coverage --coverageReporters=text-lcov --coverageReporters=html --coverageReporters=json",
|
|
27
|
+
"test:unit": "jest --testPathPattern=tests/unit",
|
|
28
|
+
"test:integration": "jest --testPathPattern=tests/integration",
|
|
29
|
+
"minify": "esbuild 'dist/**/*.js' --minify --platform=node --outdir=dist --allow-overwrite"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@chargebee/chargebee-apps-libs": "0.0.2",
|
|
33
|
+
"@chargebee/chargebee-apps-shared": "0.0.2",
|
|
34
|
+
"archiver": "^7.0.1",
|
|
35
|
+
"chalk": "^4.1.2",
|
|
36
|
+
"commander": "^11.0.0",
|
|
37
|
+
"express": "^5.1.0",
|
|
38
|
+
"semver": "^7.7.2",
|
|
39
|
+
"winston": "^3.11.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/archiver": "^6.0.3",
|
|
43
|
+
"@types/express": "^4.17.23",
|
|
44
|
+
"@types/jest": "^29.5.0",
|
|
45
|
+
"@types/node": "^24.3.0",
|
|
46
|
+
"@types/semver": "^7.7.0",
|
|
47
|
+
"@types/supertest": "^6.0.3",
|
|
48
|
+
"@types/winston": "^2.4.4",
|
|
49
|
+
"esbuild": "^0.28.1",
|
|
50
|
+
"jest": "^29.5.0",
|
|
51
|
+
"mock-fs": "^5.2.0",
|
|
52
|
+
"supertest": "^6.3.4",
|
|
53
|
+
"tmp": "^0.2.1",
|
|
54
|
+
"ts-jest": "^29.1.0",
|
|
55
|
+
"ts-node": "^10.9.0",
|
|
56
|
+
"typescript": "^5.0.0"
|
|
57
|
+
},
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public"
|
|
60
|
+
},
|
|
61
|
+
"license": "MIT",
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22.0.0"
|
|
64
|
+
},
|
|
65
|
+
"config": {
|
|
66
|
+
"defaultPort": 15000,
|
|
67
|
+
"defaultTemplate": "serverless-node-starter-app",
|
|
68
|
+
"defaultPackageName": "app"
|
|
69
|
+
}
|
|
70
|
+
}
|