@chargebee/chargebee-apps-libs 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 +270 -0
- package/SECURITY.md +8 -0
- package/config/README.md +83 -0
- package/config/allowed-modules.json +24 -0
- package/dist/config/config-loader.d.ts +24 -0
- package/dist/config/config-loader.js +95 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +21 -0
- package/dist/libs/port-service.d.ts +18 -0
- package/dist/libs/port-service.js +27 -0
- package/dist/logger/cb-public-logger.d.ts +59 -0
- package/dist/logger/cb-public-logger.js +158 -0
- package/dist/sandbox/public-sandbox-wrapper.d.ts +41 -0
- package/dist/sandbox/public-sandbox-wrapper.js +208 -0
- package/package.json +44 -0
- package/templates/serverless-node-starter-app/.env +4 -0
- package/templates/serverless-node-starter-app/README.md +290 -0
- package/templates/serverless-node-starter-app/handler/handler.js +34 -0
- package/templates/serverless-node-starter-app/jsconfig.json +35 -0
- package/templates/serverless-node-starter-app/manifest.json +15 -0
- package/templates/serverless-node-starter-app/test_data/customer_created.json +51 -0
- package/templates/serverless-node-starter-app/test_data/invoice_generated.json +112 -0
- package/templates/serverless-node-starter-app/test_data/subscription_created.json +173 -0
- package/templates/serverless-node-starter-app/types/types.d.ts +45 -0
- package/templates/serverless-node-starter-app-with-iparams/.env +4 -0
- package/templates/serverless-node-starter-app-with-iparams/README.md +717 -0
- package/templates/serverless-node-starter-app-with-iparams/handler/handler.js +39 -0
- package/templates/serverless-node-starter-app-with-iparams/iparams.json +41 -0
- package/templates/serverless-node-starter-app-with-iparams/iparams.local.json +9 -0
- package/templates/serverless-node-starter-app-with-iparams/jsconfig.json +35 -0
- package/templates/serverless-node-starter-app-with-iparams/manifest.json +15 -0
- package/templates/serverless-node-starter-app-with-iparams/test_data/customer_created.json +51 -0
- package/templates/serverless-node-starter-app-with-iparams/test_data/invoice_generated.json +112 -0
- package/templates/serverless-node-starter-app-with-iparams/test_data/subscription_created.json +173 -0
- package/templates/serverless-node-starter-app-with-iparams/types/types.d.ts +63 -0
- package/ui/README.md +118 -0
- package/ui/web/assets/css/main.css +1121 -0
- package/ui/web/assets/images/Chargebee-logo.png +0 -0
- package/ui/web/assets/js/main.js +61 -0
- package/ui/web/assets/js/modules/api.js +97 -0
- package/ui/web/assets/js/modules/constants.js +33 -0
- package/ui/web/assets/js/modules/editors.js +41 -0
- package/ui/web/assets/js/modules/events.js +195 -0
- package/ui/web/assets/js/modules/form-utils.js +70 -0
- package/ui/web/assets/js/modules/iparams-inputs.js +495 -0
- package/ui/web/assets/js/modules/iparams.js +82 -0
- package/ui/web/assets/js/modules/ui-utils.js +87 -0
- package/ui/web/index.html +164 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2011-2024 Chargebee, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person
|
|
6
|
+
obtaining a copy of this software and associated documentation
|
|
7
|
+
files (the "Software"), to deal in the Software without
|
|
8
|
+
restriction, including without limitation the rights to use,
|
|
9
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the
|
|
11
|
+
Software is furnished to do so, subject to the following
|
|
12
|
+
conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# @chargebee/chargebee-apps-libs
|
|
2
|
+
|
|
3
|
+
Production-ready library implementations for the public Chargebee Apps CLI.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides concrete implementations of the interfaces defined in `@chargebee/chargebee-apps-shared`, specifically designed for public use. These implementations focus on local development, testing, and user-facing functionality without exposing internal production details. It also includes the web UI for interactive testing of serverless applications.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
The public-libs package implements the contracts defined in the shared package while providing functionality optimized for local development environments.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
@chargebee/chargebee-apps-libs
|
|
15
|
+
├── src/
|
|
16
|
+
│ ├── config/ # Configuration management
|
|
17
|
+
│ ├── logger/ # Winston-based logging implementations
|
|
18
|
+
│ ├── sandbox/ # VM-based sandbox execution
|
|
19
|
+
│ ├── libs/ # Utility services (port, template, etc.)
|
|
20
|
+
│ └── index.ts # Main exports
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Core Components
|
|
24
|
+
|
|
25
|
+
This package provides concrete implementations organized into focused modules. Each module has detailed documentation with implementation examples and usage patterns.
|
|
26
|
+
|
|
27
|
+
### Configuration Management
|
|
28
|
+
- **ConfigLoader** - Application configuration with caching and validation
|
|
29
|
+
|
|
30
|
+
### Logging System
|
|
31
|
+
- **CBPublicLogger** - Winston-based logging with multiple transports
|
|
32
|
+
- **Safe Console** - Controlled console interface for sandboxed code
|
|
33
|
+
|
|
34
|
+
### Sandbox Execution
|
|
35
|
+
- **PublicSandboxWrapper** - VM-based secure code execution environment
|
|
36
|
+
|
|
37
|
+
### Utility Services
|
|
38
|
+
- **PortService** - Port validation and parsing utilities
|
|
39
|
+
- **TemplateService** - Template management and file operations
|
|
40
|
+
- **FileSystemService** - File system operations implementation
|
|
41
|
+
- **ProcessService** - Process operations implementation
|
|
42
|
+
|
|
43
|
+
### Web UI
|
|
44
|
+
- **Interactive Testing Interface** - Web-based UI for testing serverless applications
|
|
45
|
+
- **Event Simulation** - Form-based event data input and testing
|
|
46
|
+
- **Real-time Results** - Live display of handler execution results and logs
|
|
47
|
+
|
|
48
|
+
## Templates
|
|
49
|
+
|
|
50
|
+
### Built-in Templates
|
|
51
|
+
The package includes starter templates for common use cases:
|
|
52
|
+
|
|
53
|
+
#### `serverless-node-starter-app`
|
|
54
|
+
A complete Node.js serverless application template with:
|
|
55
|
+
- Pre-configured `manifest.json`
|
|
56
|
+
- Sample event handlers
|
|
57
|
+
- Test data files
|
|
58
|
+
- TypeScript definitions
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
templates/serverless-node-starter-app/
|
|
62
|
+
├── handler/
|
|
63
|
+
│ └── handler.js # Sample event handlers
|
|
64
|
+
├── test_data/
|
|
65
|
+
│ ├── customer_created.json
|
|
66
|
+
│ ├── subscription_created.json
|
|
67
|
+
│ └── invoice_generated.json
|
|
68
|
+
├── types/
|
|
69
|
+
│ └── types.d.ts # TypeScript definitions
|
|
70
|
+
├── manifest.json # Application configuration
|
|
71
|
+
├── jsconfig.json # JavaScript configuration
|
|
72
|
+
└── README.md # Template documentation
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
#### `serverless-node-starter-app-with-iparams`
|
|
76
|
+
Same as the starter app, plus sectioned installation parameters:
|
|
77
|
+
- `iparams.json` — parameter definitions under `installation_parameters.sections`
|
|
78
|
+
- `iparams.local.json` — local values keyed by section name
|
|
79
|
+
- Handlers receive `payload.iparams.<section>.<param>`
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
templates/serverless-node-starter-app-with-iparams/
|
|
83
|
+
├── handler/
|
|
84
|
+
│ └── handler.js # Sample event handlers
|
|
85
|
+
├── test_data/
|
|
86
|
+
│ ├── customer_created.json
|
|
87
|
+
│ ├── subscription_created.json
|
|
88
|
+
│ └── invoice_generated.json
|
|
89
|
+
├── types/
|
|
90
|
+
│ └── types.d.ts # TypeScript definitions
|
|
91
|
+
├── iparams.json # Parameter definitions (sectioned schema)
|
|
92
|
+
├── iparams.local.json # Local parameter values, keyed by section
|
|
93
|
+
├── manifest.json # Application configuration
|
|
94
|
+
├── jsconfig.json # JavaScript configuration
|
|
95
|
+
└── README.md # Template documentation
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
See [`templates/serverless-node-starter-app-with-iparams/README.md`](templates/serverless-node-starter-app-with-iparams/README.md) for the full iparams schema and examples.
|
|
99
|
+
|
|
100
|
+
## Usage Examples
|
|
101
|
+
|
|
102
|
+
### Complete Development Workflow
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import {
|
|
106
|
+
ConfigLoader,
|
|
107
|
+
createCBPublicLogger,
|
|
108
|
+
PublicSandboxWrapper,
|
|
109
|
+
ManifestValidator,
|
|
110
|
+
TemplateService
|
|
111
|
+
} from '@chargebee/chargebee-apps-libs';
|
|
112
|
+
import { DependencyManager } from '@chargebee/chargebee-apps-shared';
|
|
113
|
+
|
|
114
|
+
// 1. Load configuration
|
|
115
|
+
const configLoader = new ConfigLoader();
|
|
116
|
+
const allowedModules = configLoader.loadAllowedModules();
|
|
117
|
+
|
|
118
|
+
// 2. Create application from template
|
|
119
|
+
const templateService = new TemplateService();
|
|
120
|
+
await templateService.copyTemplate('serverless-node-starter-app', './my-app');
|
|
121
|
+
|
|
122
|
+
// 3. Validate manifest
|
|
123
|
+
const validator = new ManifestValidator(allowedModules);
|
|
124
|
+
const manifest = validator.validateFile('./my-app/manifest.json');
|
|
125
|
+
|
|
126
|
+
// 4. Setup dependencies
|
|
127
|
+
const dependencyManager = new DependencyManager();
|
|
128
|
+
await dependencyManager.ensureDependencies('./my-app', manifest);
|
|
129
|
+
|
|
130
|
+
// 5. Create logger for user code
|
|
131
|
+
const logger = createCBPublicLogger(fileSystem, process, './my-app');
|
|
132
|
+
|
|
133
|
+
// 6. Execute user code in sandbox
|
|
134
|
+
const sandbox = new PublicSandboxWrapper();
|
|
135
|
+
const result = await sandbox.execute(handlerCode, {
|
|
136
|
+
event: eventData,
|
|
137
|
+
console: createSafeConsole(logger),
|
|
138
|
+
require: dependencyManager.createIsolatedRequire('./my-app', allowedModules)
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Custom Logger Implementation
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
import { CBPublicLogger, createSafeConsole } from '@chargebee/chargebee-apps-libs';
|
|
146
|
+
import { CBFileSystem, CBProcess } from '@chargebee/chargebee-apps-shared';
|
|
147
|
+
|
|
148
|
+
class MyCustomLogger extends CBPublicLogger {
|
|
149
|
+
constructor(fileSystem: CBFileSystem, process: CBProcess, userCodeDir: string) {
|
|
150
|
+
super(fileSystem, process, userCodeDir);
|
|
151
|
+
// Add custom transports or configuration
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
customLog(level: string, message: string): void {
|
|
155
|
+
// Custom logging logic
|
|
156
|
+
this.log(level, message);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Advanced Sandbox Configuration
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { PublicSandboxWrapper } from '@chargebee/chargebee-apps-libs';
|
|
165
|
+
|
|
166
|
+
const sandbox = new PublicSandboxWrapper();
|
|
167
|
+
|
|
168
|
+
// Custom context creation
|
|
169
|
+
const context = {
|
|
170
|
+
event: eventData,
|
|
171
|
+
console: createSafeConsole(logger),
|
|
172
|
+
require: customRequireFunction,
|
|
173
|
+
// Add custom globals
|
|
174
|
+
utils: {
|
|
175
|
+
timestamp: () => new Date().toISOString(),
|
|
176
|
+
uuid: () => crypto.randomUUID()
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const result = await sandbox.execute(handlerCode, context);
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
### Building
|
|
186
|
+
```bash
|
|
187
|
+
npm run build
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Testing
|
|
191
|
+
```bash
|
|
192
|
+
npm run test
|
|
193
|
+
npm run test:coverage
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Linting
|
|
197
|
+
```bash
|
|
198
|
+
npm run lint
|
|
199
|
+
npm run lint:fix
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Dependencies
|
|
203
|
+
|
|
204
|
+
### Runtime Dependencies
|
|
205
|
+
- **@chargebee/chargebee-apps-shared**: Core interfaces and types
|
|
206
|
+
- **winston**: Logging framework
|
|
207
|
+
- **archiver**: Zip file creation
|
|
208
|
+
- **chalk**: Terminal colors
|
|
209
|
+
- **semver**: Semantic versioning utilities
|
|
210
|
+
|
|
211
|
+
### Development Dependencies
|
|
212
|
+
- **TypeScript 5.0+**: Type system and compilation
|
|
213
|
+
- **Jest**: Unit testing framework
|
|
214
|
+
- **@types/node**: Node.js type definitions
|
|
215
|
+
|
|
216
|
+
## Package Structure
|
|
217
|
+
|
|
218
|
+
- [`src/config/`](src/config/README.md) - Configuration management with caching and validation
|
|
219
|
+
- [`src/logger/`](src/logger/README.md) - Winston-based logging with multiple transports
|
|
220
|
+
- [`src/sandbox/`](src/sandbox/README.md) - VM-based secure code execution environment
|
|
221
|
+
- [`src/libs/`](src/libs/README.md) - Core utility services (port, template, file system, process)
|
|
222
|
+
- `templates/` - Built-in application templates
|
|
223
|
+
- [`ui/`](ui/README.md) - Web UI for local development server
|
|
224
|
+
- `tests/unit/` - Unit tests with comprehensive coverage
|
|
225
|
+
|
|
226
|
+
## Testing
|
|
227
|
+
|
|
228
|
+
### Unit Test Coverage
|
|
229
|
+
- **Minimum 85% coverage** required for all modules
|
|
230
|
+
- **90% coverage** target for critical paths
|
|
231
|
+
- Comprehensive mocking of external dependencies
|
|
232
|
+
- Edge case and error condition testing
|
|
233
|
+
|
|
234
|
+
### Test Categories
|
|
235
|
+
- **Service Tests**: Individual service functionality
|
|
236
|
+
- **Integration Tests**: Service interactions
|
|
237
|
+
- **Template Tests**: Template copying and validation
|
|
238
|
+
- **Configuration Tests**: Config loading and caching
|
|
239
|
+
- **Dependency Tests**: npm operations and module validation
|
|
240
|
+
|
|
241
|
+
## Security Considerations
|
|
242
|
+
|
|
243
|
+
- **Module Whitelisting**: Only approved modules can be installed
|
|
244
|
+
- **Version Constraints**: Semver validation prevents malicious versions
|
|
245
|
+
- **Path Traversal Protection**: File operations are restricted to safe paths
|
|
246
|
+
- **Sandboxed Execution**: User code runs in isolated VM contexts
|
|
247
|
+
- **Controlled Logging**: User code logging is managed and correlated
|
|
248
|
+
|
|
249
|
+
## Performance Features
|
|
250
|
+
|
|
251
|
+
- **Configuration Caching**: Loaded configs are cached for performance
|
|
252
|
+
- **Lazy Dependency Installation**: Dependencies installed only when needed
|
|
253
|
+
- **Efficient File Operations**: Optimized file copying and validation
|
|
254
|
+
- **Memory Management**: Proper cleanup of temporary resources
|
|
255
|
+
|
|
256
|
+
## Error Handling
|
|
257
|
+
|
|
258
|
+
- **Graceful Degradation**: Services handle errors without crashing
|
|
259
|
+
- **Detailed Error Messages**: Clear, actionable error descriptions
|
|
260
|
+
- **Proper Exit Codes**: Consistent error reporting for automation
|
|
261
|
+
- **Logging Integration**: All errors are properly logged with context
|
|
262
|
+
|
|
263
|
+
## Contributing
|
|
264
|
+
|
|
265
|
+
When adding new services or features:
|
|
266
|
+
1. Implement the corresponding interface from `@chargebee/chargebee-apps-shared`
|
|
267
|
+
2. Add comprehensive unit tests with 85%+ coverage
|
|
268
|
+
3. Include JSDoc documentation for all public methods
|
|
269
|
+
4. Follow the existing error handling patterns
|
|
270
|
+
5. Update this README with usage examples
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
At Chargebee, we take data integrity and security very seriously. Due to the nature of the product and service we provide, we are committed to working with individuals to stay updated on the latest security techniques and fix any security weakness in our application or infrastructure reported to us responsibly by external parties.
|
|
4
|
+
|
|
5
|
+
https://www.chargebee.com/security/responsible-disclosure-policy/
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
Reach out to us at security@chargebee.com. Please do not open GitHub issues or pull requests as this makes the problem immediately visible to everyone, including malicious actors. Chargebee's security team will triage your report and respond according to its impact.
|
package/config/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
This directory contains static configuration files for the Chargebee Apps CLI tool.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
### `allowed-modules.json`
|
|
8
|
+
|
|
9
|
+
Defines the list of Node.js modules that are allowed to be used in user applications. This configuration ensures security by restricting which modules can be imported in the sandbox environment.
|
|
10
|
+
|
|
11
|
+
#### Structure
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"modules": [
|
|
16
|
+
{
|
|
17
|
+
"name": "module-name",
|
|
18
|
+
"version": "semver-range"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### Fields
|
|
25
|
+
|
|
26
|
+
- **name** (required): The npm package name
|
|
27
|
+
- **version** (optional): A semver range that specifies allowed versions
|
|
28
|
+
|
|
29
|
+
#### Example
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"modules": [
|
|
34
|
+
{
|
|
35
|
+
"name": "lodash",
|
|
36
|
+
"version": "^4.17.0",
|
|
37
|
+
"description": "Utility library for common JavaScript operations"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "axios",
|
|
41
|
+
"version": "^1.0.0",
|
|
42
|
+
"description": "HTTP client for making API requests"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"name": "uuid",
|
|
46
|
+
"version": "^9.0.0 || ^10.0.0",
|
|
47
|
+
"description": "Generate RFC-compliant UUIDs"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Semver Version Examples
|
|
54
|
+
|
|
55
|
+
The `version` field supports various semver patterns:
|
|
56
|
+
|
|
57
|
+
- **All versions**: `*` (allows any version)
|
|
58
|
+
- **Exact version**: `4.17.21` (only this specific version)
|
|
59
|
+
- **Caret range**: `^4.17.0` (allows 4.17.x but not 5.0.0)
|
|
60
|
+
- **Tilde range**: `~4.17.0` (allows 4.17.x but not 4.18.0)
|
|
61
|
+
- **Range**: `>=4.17.0 <5.0.0` (custom range)
|
|
62
|
+
- **Multiple ranges**: `^9.0.0 || ^10.0.0` (allows either 9.x.x or 10.x.x)
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
The configuration is loaded by the `ConfigLoader` class in `src/libs/config-loader.ts` and used by the sandbox environment to validate user dependencies.
|
|
67
|
+
|
|
68
|
+
## Notes
|
|
69
|
+
|
|
70
|
+
- This is static configuration that doesn't change during runtime
|
|
71
|
+
- Located in the root directory for easy access and modification
|
|
72
|
+
- Used by the sandbox to enforce security restrictions
|
|
73
|
+
|
|
74
|
+
## Future Plans
|
|
75
|
+
|
|
76
|
+
**⚠️ Temporary Implementation**: This static JSON configuration is a temporary solution. In the future, the allowed modules configuration will be moved to a dynamic API that will be served by Chargebee. This will allow for:
|
|
77
|
+
|
|
78
|
+
- **Dynamic updates**: Module allowlist can be updated without CLI releases
|
|
79
|
+
- **Centralized management**: All configurations managed by Chargebee
|
|
80
|
+
- **Real-time changes**: Immediate updates to security policies
|
|
81
|
+
- **Better scalability**: Support for more complex module management
|
|
82
|
+
|
|
83
|
+
The current static JSON approach is maintained for development and testing purposes until the API integration is complete.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"modules": [
|
|
3
|
+
{
|
|
4
|
+
"name": "lodash",
|
|
5
|
+
"version": "^4.17.0",
|
|
6
|
+
"description": "Utility library for common JavaScript operations"
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"name": "axios",
|
|
10
|
+
"version": "^1.0.0",
|
|
11
|
+
"description": "HTTP client for making API requests"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "uuid",
|
|
15
|
+
"version": "^9.0.0 || ^10.0.0",
|
|
16
|
+
"description": "Generate RFC-compliant UUIDs"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "chargebee",
|
|
20
|
+
"version": "^3.0.0",
|
|
21
|
+
"description": "Chargebee SDK for Node.js"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AllowedModule, CBFileSystem } from '@chargebee/chargebee-apps-shared';
|
|
2
|
+
/**
|
|
3
|
+
* ConfigLoader provides utilities for loading and managing configuration files
|
|
4
|
+
* Public implementation for loading allowed modules configuration
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConfigLoader {
|
|
7
|
+
private cache;
|
|
8
|
+
private fileSystem;
|
|
9
|
+
constructor(fileSystem: CBFileSystem);
|
|
10
|
+
/**
|
|
11
|
+
* Loads and validates the allowed modules configuration
|
|
12
|
+
* @returns {AllowedModule[]} Array of validated allowed modules
|
|
13
|
+
* @throws {Error} If configuration is invalid or cannot be loaded
|
|
14
|
+
*/
|
|
15
|
+
loadAllowedModules(): AllowedModule[];
|
|
16
|
+
/**
|
|
17
|
+
* Loads a JSON configuration file with caching
|
|
18
|
+
* @param {string} configPath - Path to the configuration file
|
|
19
|
+
* @param {boolean} useCache - Whether to use cached version if available
|
|
20
|
+
* @returns {any} Parsed configuration object
|
|
21
|
+
* @throws {Error} If file cannot be loaded or parsed
|
|
22
|
+
*/
|
|
23
|
+
loadConfig(configPath: string, useCache?: boolean): any;
|
|
24
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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.ConfigLoader = void 0;
|
|
7
|
+
const chargebee_apps_shared_1 = require("@chargebee/chargebee-apps-shared");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const semver_1 = __importDefault(require("semver"));
|
|
10
|
+
/**
|
|
11
|
+
* ConfigLoader provides utilities for loading and managing configuration files
|
|
12
|
+
* Public implementation for loading allowed modules configuration
|
|
13
|
+
*/
|
|
14
|
+
class ConfigLoader {
|
|
15
|
+
constructor(fileSystem) {
|
|
16
|
+
this.fileSystem = fileSystem;
|
|
17
|
+
this.cache = new Map();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Loads and validates the allowed modules configuration
|
|
21
|
+
* @returns {AllowedModule[]} Array of validated allowed modules
|
|
22
|
+
* @throws {Error} If configuration is invalid or cannot be loaded
|
|
23
|
+
*/
|
|
24
|
+
loadAllowedModules() {
|
|
25
|
+
try {
|
|
26
|
+
// Get config file path
|
|
27
|
+
let configPath;
|
|
28
|
+
try {
|
|
29
|
+
// Production: Find @chargebee/chargebee-apps-libs package and get config from package root
|
|
30
|
+
const packageJsonPath = require.resolve('@chargebee/chargebee-apps-libs');
|
|
31
|
+
const packageRoot = path_1.default.dirname(path_1.default.dirname(packageJsonPath));
|
|
32
|
+
configPath = path_1.default.join(packageRoot, 'config', 'allowed-modules.json');
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
chargebee_apps_shared_1.__logger.error('Error: Failed to find allowed modules in the published package', error);
|
|
36
|
+
// Development: Use relative path
|
|
37
|
+
configPath = path_1.default.join(__dirname, '../../config/allowed-modules.json');
|
|
38
|
+
}
|
|
39
|
+
const config = this.loadConfig(configPath);
|
|
40
|
+
if (!config.modules || !Array.isArray(config.modules)) {
|
|
41
|
+
throw new Error('Invalid allowed modules format: "modules" must be an array');
|
|
42
|
+
}
|
|
43
|
+
const validatedModules = config.modules.map((module, index) => {
|
|
44
|
+
if (!module.name || typeof module.name !== 'string') {
|
|
45
|
+
throw new Error(`Invalid module at index ${index}: "name" must be a string`);
|
|
46
|
+
}
|
|
47
|
+
if (module.version && typeof module.version !== 'string') {
|
|
48
|
+
throw new Error(`Invalid module "${module.name}": "version" must be a string`);
|
|
49
|
+
}
|
|
50
|
+
if (module.version && !semver_1.default.validRange(module.version)) {
|
|
51
|
+
throw new Error(`Invalid semver range "${module.version}" for module "${module.name}"`);
|
|
52
|
+
}
|
|
53
|
+
return module;
|
|
54
|
+
});
|
|
55
|
+
chargebee_apps_shared_1.__logger.debug(`Loaded ${validatedModules.length} allowed modules from configuration`);
|
|
56
|
+
return validatedModules;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const err = error;
|
|
60
|
+
chargebee_apps_shared_1.__logger.error('Failed to load allowed-modules.json:', err.message);
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Loads a JSON configuration file with caching
|
|
66
|
+
* @param {string} configPath - Path to the configuration file
|
|
67
|
+
* @param {boolean} useCache - Whether to use cached version if available
|
|
68
|
+
* @returns {any} Parsed configuration object
|
|
69
|
+
* @throws {Error} If file cannot be loaded or parsed
|
|
70
|
+
*/
|
|
71
|
+
loadConfig(configPath, useCache = true) {
|
|
72
|
+
const absolutePath = path_1.default.resolve(configPath);
|
|
73
|
+
// Check cache first
|
|
74
|
+
if (useCache && this.cache.has(absolutePath)) {
|
|
75
|
+
return this.cache.get(absolutePath);
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
if (!this.fileSystem.existsSync(absolutePath)) {
|
|
79
|
+
throw new Error(`Configuration file not found: ${absolutePath}`);
|
|
80
|
+
}
|
|
81
|
+
const configContent = this.fileSystem.readFileSync(absolutePath, 'utf8');
|
|
82
|
+
const config = JSON.parse(configContent);
|
|
83
|
+
// Cache the result
|
|
84
|
+
if (useCache) {
|
|
85
|
+
this.cache.set(absolutePath, config);
|
|
86
|
+
}
|
|
87
|
+
return config;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
const err = error;
|
|
91
|
+
throw new Error(`Failed to load configuration from ${absolutePath}: ${err.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.ConfigLoader = ConfigLoader;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// Export all public library implementations
|
|
18
|
+
__exportStar(require("./config/config-loader"), exports);
|
|
19
|
+
__exportStar(require("./libs/port-service"), exports);
|
|
20
|
+
__exportStar(require("./logger/cb-public-logger"), exports);
|
|
21
|
+
__exportStar(require("./sandbox/public-sandbox-wrapper"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Port parsing service
|
|
3
|
+
*/
|
|
4
|
+
export declare class PortService {
|
|
5
|
+
constructor();
|
|
6
|
+
/**
|
|
7
|
+
* Validates port number
|
|
8
|
+
* @param {string} port - Port string input
|
|
9
|
+
* @returns {boolean} True if port is valid
|
|
10
|
+
*/
|
|
11
|
+
isValidPort(port: string): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Parses port number from string input
|
|
14
|
+
* @param {string} port - Port string input
|
|
15
|
+
* @returns {number} Parsed port number or default
|
|
16
|
+
*/
|
|
17
|
+
parsePort(port: string): number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PortService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Port parsing service
|
|
6
|
+
*/
|
|
7
|
+
class PortService {
|
|
8
|
+
constructor() { }
|
|
9
|
+
/**
|
|
10
|
+
* Validates port number
|
|
11
|
+
* @param {string} port - Port string input
|
|
12
|
+
* @returns {boolean} True if port is valid
|
|
13
|
+
*/
|
|
14
|
+
isValidPort(port) {
|
|
15
|
+
const parsedPort = parseInt(port);
|
|
16
|
+
return !isNaN(parsedPort);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parses port number from string input
|
|
20
|
+
* @param {string} port - Port string input
|
|
21
|
+
* @returns {number} Parsed port number or default
|
|
22
|
+
*/
|
|
23
|
+
parsePort(port) {
|
|
24
|
+
return parseInt(port);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.PortService = PortService;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { CBFileSystem, CBProcess, ICBLogger, SafeConsole } from '@chargebee/chargebee-apps-shared';
|
|
2
|
+
import winston from 'winston';
|
|
3
|
+
/**
|
|
4
|
+
* Public logger implementation for local development
|
|
5
|
+
* This logger provides controlled logging capabilities for sandboxed code execution
|
|
6
|
+
* with correlation context and formatted output using Winston
|
|
7
|
+
*/
|
|
8
|
+
export declare class CBPublicLogger implements ICBLogger {
|
|
9
|
+
private logger;
|
|
10
|
+
private userCodeDir;
|
|
11
|
+
private fileSystem;
|
|
12
|
+
private process;
|
|
13
|
+
constructor(fileSystem: CBFileSystem, process: CBProcess, userCodeDir: string);
|
|
14
|
+
/**
|
|
15
|
+
* Creates a Winston logger with console and file transports
|
|
16
|
+
* @returns {winston.Logger} Configured Winston logger instance
|
|
17
|
+
*/
|
|
18
|
+
protected createWinstonLogger(): winston.Logger;
|
|
19
|
+
/**
|
|
20
|
+
* Logs an info message
|
|
21
|
+
* @param {...any[]} args - The message arguments to log
|
|
22
|
+
*/
|
|
23
|
+
info(...args: any[]): void;
|
|
24
|
+
/**
|
|
25
|
+
* Logs a warning message
|
|
26
|
+
* @param {...any[]} args - The message arguments to log
|
|
27
|
+
*/
|
|
28
|
+
warn(...args: any[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Logs an error message
|
|
31
|
+
* @param {...any[]} args - The message arguments to log
|
|
32
|
+
*/
|
|
33
|
+
error(...args: any[]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Logs a debug message
|
|
36
|
+
* @param {...any[]} args - The message arguments to log
|
|
37
|
+
*/
|
|
38
|
+
debug(...args: any[]): void;
|
|
39
|
+
/**
|
|
40
|
+
* Formats a message with timestamp and level
|
|
41
|
+
* @param {winston.Logform.TransformableInfo} info - The log info
|
|
42
|
+
* @returns {string} The formatted message
|
|
43
|
+
*/
|
|
44
|
+
formatMessage(info: winston.Logform.TransformableInfo): string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a safe console object that uses the logger
|
|
48
|
+
* @param {ICBLogger} logger - The logger instance to use
|
|
49
|
+
* @returns {SafeConsole} A safe console object
|
|
50
|
+
*/
|
|
51
|
+
export declare function createSafeConsole(logger: ICBLogger): SafeConsole;
|
|
52
|
+
/**
|
|
53
|
+
* Creates a new CBPublicLogger instance for a specific user code directory
|
|
54
|
+
* @param {CBFileSystem} fileSystem - The filesystem implementation to use
|
|
55
|
+
* @param {CBProcess} process - The process implementation to use
|
|
56
|
+
* @param {string} userCodeDir - The user code directory where logs should be stored
|
|
57
|
+
* @returns {CBPublicLogger} A new CBPublicLogger instance
|
|
58
|
+
*/
|
|
59
|
+
export declare function createCBPublicLogger(fileSystem: CBFileSystem, process: CBProcess, userCodeDir: string): CBPublicLogger;
|