aios-core 3.6.0 → 3.7.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.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Error definitions for {{pascalCase serviceName}} service.
3
+ * @module @aios/{{kebabCase serviceName}}/errors
4
+ * @story {{storyId}}
5
+ */
6
+
7
+ /**
8
+ * Error codes for {{pascalCase serviceName}} service.
9
+ */
10
+ export enum {{pascalCase serviceName}}ErrorCode {
11
+ /** Configuration is missing or invalid */
12
+ CONFIGURATION_ERROR = 'CONFIGURATION_ERROR',
13
+
14
+ /** Network or connectivity issue */
15
+ NETWORK_ERROR = 'NETWORK_ERROR',
16
+
17
+ /** Operation timed out */
18
+ TIMEOUT_ERROR = 'TIMEOUT_ERROR',
19
+
20
+ /** Feature not yet implemented */
21
+ NOT_IMPLEMENTED = 'NOT_IMPLEMENTED',
22
+
23
+ /** Unknown or unexpected error */
24
+ UNKNOWN_ERROR = 'UNKNOWN_ERROR',
25
+
26
+ {{#if isApiIntegration}}
27
+ /** API rate limit exceeded */
28
+ RATE_LIMIT_EXCEEDED = 'RATE_LIMIT_EXCEEDED',
29
+
30
+ /** API authentication failed */
31
+ AUTHENTICATION_ERROR = 'AUTHENTICATION_ERROR',
32
+
33
+ /** API authorization failed */
34
+ AUTHORIZATION_ERROR = 'AUTHORIZATION_ERROR',
35
+
36
+ /** API returned an error response */
37
+ API_ERROR = 'API_ERROR',
38
+
39
+ /** Invalid API response format */
40
+ INVALID_RESPONSE = 'INVALID_RESPONSE',
41
+ {{/if}}
42
+ }
43
+
44
+ /**
45
+ * Custom error class for {{pascalCase serviceName}} service.
46
+ */
47
+ export class {{pascalCase serviceName}}Error extends Error {
48
+ /**
49
+ * Error code for programmatic handling.
50
+ */
51
+ public readonly code: {{pascalCase serviceName}}ErrorCode;
52
+
53
+ /**
54
+ * Additional error details.
55
+ */
56
+ public readonly details?: Record<string, unknown>;
57
+
58
+ /**
59
+ * Original error that caused this error.
60
+ */
61
+ public readonly cause?: Error;
62
+
63
+ {{#if isApiIntegration}}
64
+ /**
65
+ * HTTP status code (for API errors).
66
+ */
67
+ public readonly statusCode?: number;
68
+
69
+ /**
70
+ * Rate limit information (for rate limit errors).
71
+ */
72
+ public readonly rateLimit?: {
73
+ remaining: number;
74
+ reset: number;
75
+ };
76
+ {{/if}}
77
+
78
+ constructor(
79
+ message: string,
80
+ code: {{pascalCase serviceName}}ErrorCode = {{pascalCase serviceName}}ErrorCode.UNKNOWN_ERROR,
81
+ options?: {
82
+ details?: Record<string, unknown>;
83
+ cause?: Error;
84
+ {{#if isApiIntegration}}
85
+ statusCode?: number;
86
+ rateLimit?: { remaining: number; reset: number };
87
+ {{/if}}
88
+ }
89
+ ) {
90
+ super(message);
91
+ this.name = '{{pascalCase serviceName}}Error';
92
+ this.code = code;
93
+ this.details = options?.details;
94
+ this.cause = options?.cause;
95
+ {{#if isApiIntegration}}
96
+ this.statusCode = options?.statusCode;
97
+ this.rateLimit = options?.rateLimit;
98
+ {{/if}}
99
+
100
+ // Maintains proper stack trace for where error was thrown
101
+ if (Error.captureStackTrace) {
102
+ Error.captureStackTrace(this, {{pascalCase serviceName}}Error);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Returns a JSON representation of the error.
108
+ */
109
+ toJSON(): Record<string, unknown> {
110
+ return {
111
+ name: this.name,
112
+ code: this.code,
113
+ message: this.message,
114
+ details: this.details,
115
+ cause: this.cause ? { name: this.cause.name, message: this.cause.message } : undefined,
116
+ {{#if isApiIntegration}}
117
+ statusCode: this.statusCode,
118
+ rateLimit: this.rateLimit,
119
+ {{/if}}
120
+ };
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Factory functions for creating typed errors.
126
+ */
127
+ export const {{pascalCase serviceName}}Errors = {
128
+ /**
129
+ * Create a configuration error.
130
+ */
131
+ configurationError(message: string, details?: Record<string, unknown>): {{pascalCase serviceName}}Error {
132
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.CONFIGURATION_ERROR, { details });
133
+ },
134
+
135
+ /**
136
+ * Create a network error.
137
+ */
138
+ networkError(message: string, cause?: Error): {{pascalCase serviceName}}Error {
139
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.NETWORK_ERROR, { cause });
140
+ },
141
+
142
+ /**
143
+ * Create a timeout error.
144
+ */
145
+ timeoutError(message: string, details?: Record<string, unknown>): {{pascalCase serviceName}}Error {
146
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.TIMEOUT_ERROR, { details });
147
+ },
148
+
149
+ {{#if isApiIntegration}}
150
+ /**
151
+ * Create a rate limit error.
152
+ */
153
+ rateLimitError(retryAfter: number, rateLimit: { remaining: number; reset: number }): {{pascalCase serviceName}}Error {
154
+ return new {{pascalCase serviceName}}Error(
155
+ `Rate limit exceeded. Retry after ${retryAfter} seconds.`,
156
+ {{pascalCase serviceName}}ErrorCode.RATE_LIMIT_EXCEEDED,
157
+ { statusCode: 429, rateLimit }
158
+ );
159
+ },
160
+
161
+ /**
162
+ * Create an authentication error.
163
+ */
164
+ authenticationError(message: string = 'Authentication failed'): {{pascalCase serviceName}}Error {
165
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.AUTHENTICATION_ERROR, { statusCode: 401 });
166
+ },
167
+
168
+ /**
169
+ * Create an authorization error.
170
+ */
171
+ authorizationError(message: string = 'Access denied'): {{pascalCase serviceName}}Error {
172
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.AUTHORIZATION_ERROR, { statusCode: 403 });
173
+ },
174
+
175
+ /**
176
+ * Create an API error from response.
177
+ */
178
+ apiError(statusCode: number, message: string, details?: Record<string, unknown>): {{pascalCase serviceName}}Error {
179
+ return new {{pascalCase serviceName}}Error(message, {{pascalCase serviceName}}ErrorCode.API_ERROR, { statusCode, details });
180
+ },
181
+ {{/if}}
182
+ };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module @aios/{{kebabCase serviceName}}
3
+ * @description {{description}}
4
+ * @story {{storyId}}
5
+ */
6
+
7
+ // Re-export types
8
+ export * from './types';
9
+
10
+ // Re-export errors
11
+ export * from './errors';
12
+
13
+ {{#if isApiIntegration}}
14
+ // Re-export client (API integrations only)
15
+ export { {{pascalCase serviceName}}Client } from './client';
16
+ {{/if}}
17
+
18
+ import type { {{pascalCase serviceName}}Config, {{pascalCase serviceName}}Service } from './types';
19
+ import { {{pascalCase serviceName}}Error, {{pascalCase serviceName}}ErrorCode } from './errors';
20
+ {{#if isApiIntegration}}
21
+ import { {{pascalCase serviceName}}Client } from './client';
22
+ {{/if}}
23
+
24
+ /**
25
+ * Creates a new {{pascalCase serviceName}} service instance.
26
+ *
27
+ * @param config - Service configuration
28
+ * @returns Configured service instance
29
+ * @throws {{{pascalCase serviceName}}Error} If configuration is invalid
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * const service = create{{pascalCase serviceName}}Service({
34
+ * // configuration options
35
+ * });
36
+ *
37
+ * const result = await service.execute();
38
+ * ```
39
+ */
40
+ export function create{{pascalCase serviceName}}Service(
41
+ config: {{pascalCase serviceName}}Config
42
+ ): {{pascalCase serviceName}}Service {
43
+ // Validate configuration
44
+ validateConfig(config);
45
+
46
+ {{#if isApiIntegration}}
47
+ // Create API client
48
+ const client = new {{pascalCase serviceName}}Client(config);
49
+
50
+ {{/if}}
51
+ return {
52
+ /**
53
+ * Execute the primary service operation.
54
+ */
55
+ async execute(): Promise<void> {
56
+ // TODO: Implement primary operation
57
+ throw new {{pascalCase serviceName}}Error(
58
+ 'Not implemented',
59
+ {{pascalCase serviceName}}ErrorCode.NOT_IMPLEMENTED
60
+ );
61
+ },
62
+
63
+ /**
64
+ * Get the current configuration (without sensitive values).
65
+ */
66
+ getConfig(): Partial<{{pascalCase serviceName}}Config> {
67
+ return {
68
+ // Return non-sensitive config values
69
+ {{#each envVars}}
70
+ {{#unless this.sensitive}}
71
+ {{camelCase this.name}}: config.{{camelCase this.name}},
72
+ {{/unless}}
73
+ {{/each}}
74
+ };
75
+ },
76
+
77
+ /**
78
+ * Check if the service is properly configured and operational.
79
+ */
80
+ async healthCheck(): Promise<boolean> {
81
+ try {
82
+ {{#if isApiIntegration}}
83
+ // Verify API connectivity
84
+ await client.ping();
85
+ {{/if}}
86
+ return true;
87
+ } catch {
88
+ return false;
89
+ }
90
+ },
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Validates the service configuration.
96
+ * @throws {{{pascalCase serviceName}}Error} If configuration is invalid
97
+ */
98
+ function validateConfig(config: {{pascalCase serviceName}}Config): void {
99
+ if (!config) {
100
+ throw new {{pascalCase serviceName}}Error(
101
+ 'Configuration is required',
102
+ {{pascalCase serviceName}}ErrorCode.CONFIGURATION_ERROR
103
+ );
104
+ }
105
+
106
+ {{#each envVars}}
107
+ {{#if this.required}}
108
+ if (config.{{camelCase this.name}} === undefined || config.{{camelCase this.name}} === null) {
109
+ throw new {{pascalCase serviceName}}Error(
110
+ '{{this.name}} is required',
111
+ {{pascalCase serviceName}}ErrorCode.CONFIGURATION_ERROR
112
+ );
113
+ }
114
+
115
+ {{/if}}
116
+ {{/each}}
117
+ }
118
+
119
+ // Default export
120
+ export default create{{pascalCase serviceName}}Service;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Jest configuration for service testing.
3
+ * @type {import('jest').Config}
4
+ */
5
+ module.exports = {
6
+ // Use ts-jest for TypeScript support
7
+ preset: 'ts-jest',
8
+
9
+ // Test environment
10
+ testEnvironment: 'node',
11
+
12
+ // Root directories for tests
13
+ roots: ['<rootDir>'],
14
+
15
+ // Test file patterns
16
+ testMatch: [
17
+ '**/__tests__/**/*.test.ts',
18
+ '**/__tests__/**/*.spec.ts',
19
+ ],
20
+
21
+ // TypeScript transformation
22
+ transform: {
23
+ '^.+\\.tsx?$': [
24
+ 'ts-jest',
25
+ {
26
+ useESM: true,
27
+ tsconfig: {
28
+ module: 'ESNext',
29
+ moduleResolution: 'NodeNext',
30
+ },
31
+ },
32
+ ],
33
+ },
34
+
35
+ // Module file extensions
36
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
37
+
38
+ // Coverage configuration
39
+ collectCoverageFrom: [
40
+ '**/*.ts',
41
+ '!**/*.d.ts',
42
+ '!**/__tests__/**',
43
+ '!**/node_modules/**',
44
+ '!**/dist/**',
45
+ ],
46
+
47
+ // Coverage thresholds (targeting >70%)
48
+ coverageThreshold: {
49
+ global: {
50
+ branches: 70,
51
+ functions: 70,
52
+ lines: 70,
53
+ statements: 70,
54
+ },
55
+ },
56
+
57
+ // Coverage reporters
58
+ coverageReporters: ['text', 'text-summary', 'lcov', 'html'],
59
+
60
+ // Coverage output directory
61
+ coverageDirectory: 'coverage',
62
+
63
+ // Clear mocks between tests
64
+ clearMocks: true,
65
+
66
+ // Verbose output
67
+ verbose: true,
68
+
69
+ // Test timeout (30 seconds)
70
+ testTimeout: 30000,
71
+
72
+ // Setup files
73
+ // setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
74
+
75
+ // Module name mapper for path aliases
76
+ moduleNameMapper: {
77
+ '^@/(.*)$': '<rootDir>/$1',
78
+ },
79
+
80
+ // Ignore patterns
81
+ testPathIgnorePatterns: [
82
+ '/node_modules/',
83
+ '/dist/',
84
+ ],
85
+
86
+ // Global setup/teardown
87
+ // globalSetup: '<rootDir>/jest.global-setup.ts',
88
+ // globalTeardown: '<rootDir>/jest.global-teardown.ts',
89
+ };
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "@aios/{{kebabCase serviceName}}",
3
+ "version": "1.0.0",
4
+ "description": "{{description}}",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./types": {
15
+ "types": "./dist/types.d.ts",
16
+ "import": "./dist/types.js"
17
+ },
18
+ "./errors": {
19
+ "types": "./dist/errors.d.ts",
20
+ "import": "./dist/errors.js"
21
+ }{{#if isApiIntegration}},
22
+ "./client": {
23
+ "types": "./dist/client.d.ts",
24
+ "import": "./dist/client.js"
25
+ }{{/if}}
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "build:watch": "tsc --watch",
34
+ "clean": "rimraf dist coverage",
35
+ "test": "jest",
36
+ "test:watch": "jest --watch",
37
+ "test:coverage": "jest --coverage",
38
+ "typecheck": "tsc --noEmit",
39
+ "lint": "eslint . --ext .ts",
40
+ "lint:fix": "eslint . --ext .ts --fix",
41
+ "prepublishOnly": "npm run clean && npm run build && npm test"
42
+ },
43
+ "keywords": [
44
+ "aios",
45
+ "{{kebabCase serviceName}}",
46
+ "service"{{#if isApiIntegration}},
47
+ "api",
48
+ "integration"{{/if}}
49
+ ],
50
+ "author": "AIOS-FullStack",
51
+ "license": "MIT",
52
+ "engines": {
53
+ "node": ">=18.0.0"
54
+ },
55
+ "devDependencies": {
56
+ "@types/jest": "^29.5.12",
57
+ "@types/node": "^20.11.0",
58
+ "@typescript-eslint/eslint-plugin": "^6.19.0",
59
+ "@typescript-eslint/parser": "^6.19.0",
60
+ "eslint": "^8.56.0",
61
+ "jest": "^29.7.0",
62
+ "rimraf": "^5.0.5",
63
+ "ts-jest": "^29.1.2",
64
+ "typescript": "^5.3.3"
65
+ },
66
+ "peerDependencies": {
67
+ "typescript": ">=5.0.0"
68
+ },
69
+ "peerDependenciesMeta": {
70
+ "typescript": {
71
+ "optional": true
72
+ }
73
+ },
74
+ "repository": {
75
+ "type": "git",
76
+ "url": "https://github.com/aios-fullstack/{{kebabCase serviceName}}.git"
77
+ },
78
+ "bugs": {
79
+ "url": "https://github.com/aios-fullstack/{{kebabCase serviceName}}/issues"
80
+ },
81
+ "homepage": "https://github.com/aios-fullstack/{{kebabCase serviceName}}#readme",
82
+ "aios": {
83
+ "storyId": "{{storyId}}",
84
+ "type": "{{#if isApiIntegration}}api-integration{{else}}utility-service{{/if}}",
85
+ "generatedAt": "{{generatedAt}}"
86
+ }
87
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2020"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "strictNullChecks": true,
15
+ "strictFunctionTypes": true,
16
+ "strictBindCallApply": true,
17
+ "strictPropertyInitialization": true,
18
+ "noImplicitThis": true,
19
+ "useUnknownInCatchVariables": true,
20
+ "alwaysStrict": true,
21
+ "noUnusedLocals": true,
22
+ "noUnusedParameters": true,
23
+ "exactOptionalPropertyTypes": false,
24
+ "noImplicitReturns": true,
25
+ "noFallthroughCasesInSwitch": true,
26
+ "noUncheckedIndexedAccess": true,
27
+ "noImplicitOverride": true,
28
+ "noPropertyAccessFromIndexSignature": false,
29
+ "esModuleInterop": true,
30
+ "forceConsistentCasingInFileNames": true,
31
+ "skipLibCheck": true,
32
+ "resolveJsonModule": true,
33
+ "isolatedModules": true
34
+ },
35
+ "include": [
36
+ "./**/*.ts"
37
+ ],
38
+ "exclude": [
39
+ "node_modules",
40
+ "dist",
41
+ "**/*.test.ts",
42
+ "**/*.spec.ts",
43
+ "__tests__"
44
+ ]
45
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Type definitions for {{pascalCase serviceName}} service.
3
+ * @module @aios/{{kebabCase serviceName}}/types
4
+ * @story {{storyId}}
5
+ */
6
+
7
+ /**
8
+ * Configuration options for the {{pascalCase serviceName}} service.
9
+ */
10
+ export interface {{pascalCase serviceName}}Config {
11
+ {{#each envVars}}
12
+ /**
13
+ * {{this.description}}
14
+ {{#if this.required}}
15
+ * @required
16
+ {{/if}}
17
+ */
18
+ {{camelCase this.name}}{{#unless this.required}}?{{/unless}}: string;
19
+
20
+ {{/each}}
21
+ {{#if isApiIntegration}}
22
+ /**
23
+ * Base URL for the API.
24
+ * @default '{{apiBaseUrl}}'
25
+ */
26
+ baseUrl?: string;
27
+
28
+ /**
29
+ * Request timeout in milliseconds.
30
+ * @default 30000
31
+ */
32
+ timeout?: number;
33
+
34
+ /**
35
+ * Maximum number of retry attempts.
36
+ * @default 3
37
+ */
38
+ maxRetries?: number;
39
+
40
+ /**
41
+ * Enable debug logging.
42
+ * @default false
43
+ */
44
+ debug?: boolean;
45
+
46
+ {{/if}}
47
+ }
48
+
49
+ /**
50
+ * The {{pascalCase serviceName}} service interface.
51
+ */
52
+ export interface {{pascalCase serviceName}}Service {
53
+ /**
54
+ * Execute the primary service operation.
55
+ */
56
+ execute(): Promise<void>;
57
+
58
+ /**
59
+ * Get the current configuration (without sensitive values).
60
+ */
61
+ getConfig(): Partial<{{pascalCase serviceName}}Config>;
62
+
63
+ /**
64
+ * Check if the service is properly configured and operational.
65
+ */
66
+ healthCheck(): Promise<boolean>;
67
+ }
68
+
69
+ {{#if isApiIntegration}}
70
+ /**
71
+ * Base API response structure.
72
+ */
73
+ export interface {{pascalCase serviceName}}ApiResponse<T = unknown> {
74
+ success: boolean;
75
+ data?: T;
76
+ error?: {
77
+ code: string;
78
+ message: string;
79
+ details?: Record<string, unknown>;
80
+ };
81
+ meta?: {
82
+ requestId?: string;
83
+ rateLimit?: {
84
+ remaining: number;
85
+ reset: number;
86
+ };
87
+ };
88
+ }
89
+
90
+ /**
91
+ * Request options for API calls.
92
+ */
93
+ export interface {{pascalCase serviceName}}RequestOptions {
94
+ /**
95
+ * HTTP method.
96
+ */
97
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
98
+
99
+ /**
100
+ * Request headers.
101
+ */
102
+ headers?: Record<string, string>;
103
+
104
+ /**
105
+ * Request body.
106
+ */
107
+ body?: unknown;
108
+
109
+ /**
110
+ * Query parameters.
111
+ */
112
+ params?: Record<string, string | number | boolean>;
113
+
114
+ /**
115
+ * Request timeout override.
116
+ */
117
+ timeout?: number;
118
+
119
+ /**
120
+ * Skip retry on failure.
121
+ */
122
+ noRetry?: boolean;
123
+ }
124
+
125
+ /**
126
+ * Rate limit information.
127
+ */
128
+ export interface {{pascalCase serviceName}}RateLimit {
129
+ /**
130
+ * Maximum requests allowed.
131
+ */
132
+ limit: number;
133
+
134
+ /**
135
+ * Remaining requests in current window.
136
+ */
137
+ remaining: number;
138
+
139
+ /**
140
+ * Unix timestamp when the rate limit resets.
141
+ */
142
+ reset: number;
143
+ }
144
+
145
+ {{/if}}