microfox 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/README.md +114 -0
  3. package/dist/agent-template.txt +486 -0
  4. package/dist/background-agent/.gitignore.txt +22 -0
  5. package/dist/background-agent/eslint.config.js.txt +48 -0
  6. package/dist/background-agent/microfox.json.txt +4 -0
  7. package/dist/background-agent/openapi.md.txt +1 -0
  8. package/dist/background-agent/package.json.txt +47 -0
  9. package/dist/background-agent/serverless.yml.txt +123 -0
  10. package/dist/background-agent/src/functions/cron-paginate.ts.txt +135 -0
  11. package/dist/background-agent/src/functions/cron-populate.ts.txt +33 -0
  12. package/dist/background-agent/src/functions/route-trigger-index.ts.txt +157 -0
  13. package/dist/background-agent/src/functions/route-trigger-populate.ts.txt +0 -0
  14. package/dist/background-agent/src/functions/sqs-index.ts.txt +147 -0
  15. package/dist/background-agent/src/helpers/ragRedis.ts.txt +78 -0
  16. package/dist/background-agent/src/index.ts.txt +69 -0
  17. package/dist/background-agent/tsconfig.json.txt +33 -0
  18. package/dist/chunk-4HNHBA2H.mjs +104 -0
  19. package/dist/chunk-4HNHBA2H.mjs.map +1 -0
  20. package/dist/chunk-ARAHSYJI.mjs +263 -0
  21. package/dist/chunk-ARAHSYJI.mjs.map +1 -0
  22. package/dist/chunk-JGAX4PD6.mjs +290 -0
  23. package/dist/chunk-JGAX4PD6.mjs.map +1 -0
  24. package/dist/chunk-KPJJOO76.mjs +12 -0
  25. package/dist/chunk-KPJJOO76.mjs.map +1 -0
  26. package/dist/chunk-TZQZMKHP.mjs +11 -0
  27. package/dist/chunk-TZQZMKHP.mjs.map +1 -0
  28. package/dist/chunk-UFRGJMF4.mjs +154 -0
  29. package/dist/chunk-UFRGJMF4.mjs.map +1 -0
  30. package/dist/chunk-UHWJTQKW.mjs +139 -0
  31. package/dist/chunk-UHWJTQKW.mjs.map +1 -0
  32. package/dist/chunk-UYROVW53.mjs +89 -0
  33. package/dist/chunk-UYROVW53.mjs.map +1 -0
  34. package/dist/chunk-XGFSFWK3.mjs +113 -0
  35. package/dist/chunk-XGFSFWK3.mjs.map +1 -0
  36. package/dist/cli.d.mts +2 -0
  37. package/dist/cli.d.ts +2 -0
  38. package/dist/cli.js +1154 -0
  39. package/dist/cli.js.map +1 -0
  40. package/dist/cli.mjs +52 -0
  41. package/dist/cli.mjs.map +1 -0
  42. package/dist/commands/add.d.mts +5 -0
  43. package/dist/commands/add.d.ts +5 -0
  44. package/dist/commands/add.js +126 -0
  45. package/dist/commands/add.js.map +1 -0
  46. package/dist/commands/add.mjs +10 -0
  47. package/dist/commands/add.mjs.map +1 -0
  48. package/dist/commands/code.d.mts +5 -0
  49. package/dist/commands/code.d.ts +5 -0
  50. package/dist/commands/code.js +187 -0
  51. package/dist/commands/code.js.map +1 -0
  52. package/dist/commands/code.mjs +9 -0
  53. package/dist/commands/code.mjs.map +1 -0
  54. package/dist/commands/install.d.mts +5 -0
  55. package/dist/commands/install.d.ts +5 -0
  56. package/dist/commands/install.js +296 -0
  57. package/dist/commands/install.js.map +1 -0
  58. package/dist/commands/install.mjs +9 -0
  59. package/dist/commands/install.mjs.map +1 -0
  60. package/dist/commands/kickstart.d.mts +5 -0
  61. package/dist/commands/kickstart.d.ts +5 -0
  62. package/dist/commands/kickstart.js +322 -0
  63. package/dist/commands/kickstart.js.map +1 -0
  64. package/dist/commands/kickstart.mjs +10 -0
  65. package/dist/commands/kickstart.mjs.map +1 -0
  66. package/dist/commands/push.d.mts +5 -0
  67. package/dist/commands/push.d.ts +5 -0
  68. package/dist/commands/push.js +137 -0
  69. package/dist/commands/push.js.map +1 -0
  70. package/dist/commands/push.mjs +9 -0
  71. package/dist/commands/push.mjs.map +1 -0
  72. package/dist/commands/status.d.mts +7 -0
  73. package/dist/commands/status.d.ts +7 -0
  74. package/dist/commands/status.js +148 -0
  75. package/dist/commands/status.js.map +1 -0
  76. package/dist/commands/status.mjs +13 -0
  77. package/dist/commands/status.mjs.map +1 -0
  78. package/dist/commands/update.d.mts +5 -0
  79. package/dist/commands/update.d.ts +5 -0
  80. package/dist/commands/update.js +172 -0
  81. package/dist/commands/update.js.map +1 -0
  82. package/dist/commands/update.mjs +9 -0
  83. package/dist/commands/update.mjs.map +1 -0
  84. package/dist/index.d.mts +20 -0
  85. package/dist/index.d.ts +20 -0
  86. package/dist/index.js +406 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/index.mjs +14 -0
  89. package/dist/index.mjs.map +1 -0
  90. package/dist/package-template.txt +494 -0
  91. package/package.json +68 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,72 @@
1
+ # @microfox/cli
2
+
3
+ ## 1.0.11
4
+
5
+ ### Patch Changes
6
+
7
+ - e704003: Triggered by issue #633: release microfox patch
8
+ - Updated dependencies [c192e6b]
9
+ - @microfox/slack@1.2.1
10
+
11
+ ## 1.0.10
12
+
13
+ ### Patch Changes
14
+
15
+ - 21d20b0: Triggered by issue #615: release @microfox/cli patch
16
+
17
+ ## 1.0.9
18
+
19
+ ### Patch Changes
20
+
21
+ - 19771c8: release: improve npm package name checking and update MCP specification
22
+
23
+ ## 1.0.8
24
+
25
+ ### Patch Changes
26
+
27
+ - 6d313f0: Triggered by issue #612: release @microfox/cli patch
28
+
29
+ ## 1.0.7
30
+
31
+ ### Patch Changes
32
+
33
+ - acd01ee: Changes from PR #608: code_router_orchestrator
34
+
35
+ ## 1.0.6
36
+
37
+ ### Patch Changes
38
+
39
+ - b645496: Changes from PR #597: vwjt_code_router_july_2025
40
+
41
+ ## 1.0.5
42
+
43
+ ### Patch Changes
44
+
45
+ - 4a73559: Changes from PR #580: microfox-cli-push-script
46
+
47
+ ## 1.0.4
48
+
49
+ ### Patch Changes
50
+
51
+ - bbbb3e2: Changes from PR #576: microfox-cli-push-script
52
+
53
+ ## 1.0.3
54
+
55
+ ### Patch Changes
56
+
57
+ - fdd3040: Changes from PR #572: update-oauth-scopes-v2
58
+ - b239a68: Changes from PR #573: cli-agent-script
59
+
60
+ ## 1.0.2
61
+
62
+ ### Patch Changes
63
+
64
+ - ba98afc: Changes from PR #554: microfox-cli
65
+ - 704a854: Triggered by issue #555: release @microfox/cli patch
66
+
67
+ ## 1.0.1
68
+
69
+ ### Patch Changes
70
+
71
+ - 2ce84c6: Changes from PR #551: microfox-cli
72
+ - a8a1150: Triggered by issue #552: release @microfox/cli patch
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @microfox/cli
2
+
3
+ Universal CLI tool for creating modern TypeScript packages with comprehensive SDK templates, npm availability checking, and professional tooling setup.
4
+
5
+ ## Installation
6
+
7
+ ### Via npx (Recommended)
8
+
9
+ ```bash
10
+ npx @microfox/cli kickstart
11
+ ```
12
+
13
+ ### Global Installation
14
+
15
+ ```bash
16
+ npm install -g @microfox/cli
17
+ microfox kickstart
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Kickstart a New Package
23
+
24
+ ```bash
25
+ npx @microfox/cli kickstart
26
+ ```
27
+
28
+ This command will:
29
+ - **Ask for a package name** interactively
30
+ - **Check npm availability** for the package name
31
+ - **Prompt for a new name** if the package already exists
32
+ - Create a complete package directory structure
33
+ - Set up modern TypeScript configuration
34
+ - Generate minimal code templates with examples
35
+ - Create a basic test suite with Vitest
36
+ - Set up ESLint and Prettier for code quality
37
+ - Configure modern build system with tsup
38
+
39
+ ### Package Name Format
40
+
41
+ The CLI accepts any valid npm package name:
42
+ - Simple names: `my-awesome-package`
43
+ - Scoped packages: `@myorg/my-awesome-package`
44
+
45
+ ### Features
46
+
47
+ ✅ **Interactive Package Creation** - Asks for package name during setup
48
+ ✅ **NPM Availability Checking** - Automatically checks if your package name is available
49
+ ✅ **Interactive Name Selection** - Prompts for alternatives if name is taken
50
+ ✅ **Modern TypeScript Setup** - Full TypeScript configuration with strict mode
51
+ ✅ **Minimal Code Templates** - Simple SDK structure with commented examples
52
+ ✅ **Basic Test Suite** - Vitest configuration with example tests
53
+ ✅ **Code Quality Tools** - ESLint and Prettier pre-configured
54
+ ✅ **Professional Structure** - Based on popular open-source packages
55
+ ✅ **Simple Documentation** - Auto-generated README with minimal examples
56
+ ✅ **Modern Build System** - tsup for fast, modern bundling
57
+ ✅ **Git Ready** - Includes .gitignore and proper file structure
58
+
59
+ ## Commands
60
+
61
+ - `kickstart` - Kickstart a new TypeScript SDK package with modern tooling
62
+
63
+ ## What Gets Created
64
+
65
+ When you run the CLI, it creates a complete package with:
66
+
67
+ ```
68
+ my-package/
69
+ ├── src/
70
+ │ ├── index.ts # Main exports
71
+ │ ├── myPackageSdk.ts # Main SDK class
72
+ │ ├── types/
73
+ │ │ └── index.ts # TypeScript interfaces
74
+ │ ├── schemas/
75
+ │ │ └── index.ts # Zod validation schemas
76
+ │ └── __tests__/
77
+ │ └── myPackage.test.ts # Comprehensive tests
78
+ ├── docs/ # Documentation directory
79
+ ├── package.json # Modern package configuration
80
+ ├── package-info.json # Package metadata
81
+ ├── tsconfig.json # TypeScript configuration
82
+ ├── tsup.config.ts # Build configuration
83
+ ├── vitest.config.ts # Test configuration
84
+ ├── .eslintrc.js # Linting rules
85
+ ├── .prettierrc # Code formatting
86
+ ├── .gitignore # Git ignore rules
87
+ ├── README.md # Comprehensive documentation
88
+ └── CHANGELOG.md # Version history
89
+ ```
90
+
91
+ ## Example Usage
92
+
93
+ After creating a package:
94
+
95
+ ```typescript
96
+ import { MyPackageSdk } from 'my-package';
97
+
98
+ const sdk = new MyPackageSdk({
99
+ apiKey: 'your-api-key',
100
+ baseUrl: 'https://api.example.com'
101
+ });
102
+
103
+ // Example hello method (replace with your own methods)
104
+ const result = await sdk.hello('World');
105
+ console.log(result.data); // "Hello, World! Welcome to my-package SDK."
106
+
107
+ // TODO: Add your own SDK methods
108
+ // const data = await sdk.getData('123');
109
+ // const created = await sdk.createItem({ name: 'Example' });
110
+ ```
111
+
112
+ ## License
113
+
114
+ MIT
@@ -0,0 +1,486 @@
1
+ --- filename: package.json
2
+ {
3
+ "name": "<%= agentName %>",
4
+ "version": "1.0.0",
5
+ "description": "A Microbizz agent.",
6
+ "main": "dist/index.js",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "deploy": "npm run build && serverless deploy --stage dev",
11
+ "deploy:preview": "npm run build && serverless deploy --stage preview",
12
+ "deploy:prod": "npm run build && serverless deploy --stage prod",
13
+ "remove": "serverless remove",
14
+ "remove:preview": "serverless remove --stage preview",
15
+ "remove:prod": "serverless remove --stage prod",
16
+ "start": "serverless offline start",
17
+ "dev": "npm run build && serverless offline start",
18
+ "lint": "eslint ."
19
+ },
20
+ "dependencies": {
21
+ "@aws-sdk/client-sqs": "^3.504.0",
22
+ "@upstash/redis": "^1.28.4",
23
+ "ai": "latest",
24
+ "aws-lambda": "*",
25
+ "dotenv": "^16.4.5",
26
+ "uuid": "^9.0.1"
27
+ },
28
+ "devDependencies": {
29
+ "@eslint/js": "latest",
30
+ "@types/aws-lambda": "^8.10.138",
31
+ "@types/node": "^20.11.19",
32
+ "@types/uuid": "^9.0.8",
33
+ "@typescript-eslint/eslint-plugin": "latest",
34
+ "@typescript-eslint/parser": "latest",
35
+ "eslint": "^9.1.0",
36
+ "serverless": "^3.38.0",
37
+ "serverless-offline": "^13.3.3",
38
+ "serverless-plugin-typescript": "^2.1.5",
39
+ "typescript": "^5.3.3"
40
+ }
41
+ }
42
+ --- filename: serverless.yml
43
+ service: <%= agentName %>
44
+
45
+ package:
46
+ exclude:
47
+ - venv/**
48
+ - .idea/**
49
+ - .vscode/**
50
+ - src/**
51
+ - node_modules/serverless-offline/**
52
+
53
+ custom:
54
+ stage: ${env:ENVIRONMENT, 'dev'}
55
+ serverless-offline:
56
+ httpPort: 4000
57
+ lambdaPort: 4002
58
+ useChildProcesses: true
59
+ useWorkerThreads: true
60
+ noCookieValidation: true
61
+ allowCache: true
62
+ hideStackTraces: false
63
+ disableCookieValidation: true
64
+ noTimeout: true
65
+ environment: ${file(env.json)}
66
+
67
+ provider:
68
+ name: aws
69
+ runtime: nodejs20.x
70
+ region: us-east-1
71
+ stage: ${env:ENVIRONMENT, 'dev'}
72
+ environment: ${file(env.json)}
73
+ iam:
74
+ role:
75
+ statements:
76
+ - Effect: 'Allow'
77
+ Action:
78
+ - 'sqs:SendMessage'
79
+ Resource:
80
+ - Fn::GetAtt: [MessageQueue, Arn]
81
+
82
+ plugins:
83
+ - serverless-plugin-typescript
84
+ - serverless-offline
85
+
86
+ functions:
87
+ # Example HTTP Function
88
+ handleApiRequest:
89
+ handler: dist/functions/api-handler.handler
90
+ events:
91
+ - http:
92
+ path: /items
93
+ method: POST
94
+ cors: true
95
+
96
+ # Example Cron Job
97
+ handleScheduledTask:
98
+ handler: dist/functions/cron-handler.handler
99
+ events:
100
+ - schedule: rate(1 day)
101
+
102
+ # Example SQS Handler
103
+ handleQueueMessage:
104
+ handler: dist/functions/sqs-handler.handler
105
+ events:
106
+ - sqs:
107
+ arn:
108
+ Fn::GetAtt:
109
+ - MessageQueue
110
+ - Arn
111
+
112
+ # Documentation
113
+ getDocs:
114
+ handler: dist/index.getDocs
115
+ events:
116
+ - http:
117
+ path: /docs.json
118
+ method: get
119
+ cors: true
120
+
121
+ resources:
122
+ Resources:
123
+ MessageQueue:
124
+ Type: AWS::SQS::Queue
125
+ Properties:
126
+ QueueName: ${self:service}-message-queue-${opt:stage,env:ENVIRONMENT, 'dev'}
127
+ VisibilityTimeout: 300
128
+ Outputs:
129
+ ApiEndpoints:
130
+ Description: 'API Endpoints'
131
+ Value:
132
+ Fn::Join:
133
+ - ''
134
+ - - 'API: https://'
135
+ - Ref: 'ApiGatewayRestApi'
136
+ - '.execute-api.'
137
+ - Ref: 'AWS::Region'
138
+ - ".amazonaws.com/${env:ENVIRONMENT, 'dev'}"
139
+ --- filename: tsconfig.json
140
+ {
141
+ "compilerOptions": {
142
+ "target": "ES2020",
143
+ "module": "NodeNext",
144
+ "moduleResolution": "NodeNext",
145
+ "lib": ["ES2020"],
146
+ "allowJs": true,
147
+ "strict": true,
148
+ "esModuleInterop": true,
149
+ "skipLibCheck": true,
150
+ "forceConsistentCasingInFileNames": true,
151
+ "experimentalDecorators": true,
152
+ "emitDecoratorMetadata": true,
153
+ "strictPropertyInitialization": false,
154
+ "noImplicitAny": true,
155
+ "noCheck": false,
156
+ "outDir": "./dist",
157
+ "rootDir": "./src",
158
+ "baseUrl": "./src",
159
+ "paths": {
160
+ "@/*": ["*"]
161
+ }
162
+ },
163
+ "ts-node": {
164
+ "esm": true,
165
+ "compilerOptions": {
166
+ "module": "NodeNext",
167
+ "moduleResolution": "NodeNext"
168
+ }
169
+ },
170
+ "include": ["src/**/*"],
171
+ "exclude": ["node_modules", "dist/**", ".serverless/**"]
172
+ }
173
+ --- filename: eslint.config.js
174
+ import js from '@eslint/js';
175
+ import tseslint from '@typescript-eslint/eslint-plugin';
176
+ import tsparser from '@typescript-eslint/parser';
177
+
178
+ export default [
179
+ js.configs.recommended,
180
+ {
181
+ files: ['**/*.ts', '**/*.tsx'],
182
+ languageOptions: {
183
+ parser: tsparser,
184
+ parserOptions: {
185
+ ecmaVersion: 2020,
186
+ sourceType: 'module',
187
+ ecmaFeatures: {
188
+ jsx: true,
189
+ },
190
+ },
191
+ globals: {
192
+ console: 'readonly',
193
+ process: 'readonly',
194
+ },
195
+ },
196
+ plugins: {
197
+ '@typescript-eslint': tseslint,
198
+ },
199
+ rules: {
200
+ ...tseslint.configs.recommended.rules,
201
+ 'no-unused-vars': 'off',
202
+ '@typescript-eslint/no-unused-vars': ['warn'],
203
+ 'no-console': 'warn',
204
+ 'react/prop-types': 'off',
205
+ 'no-case-declarations': 'off',
206
+ '@typescript-eslint/no-explicit-any': 'off',
207
+ '@typescript-eslint/ban-ts-comment': 'off',
208
+ '@typescript-eslint/no-empty-function': 'off',
209
+ },
210
+ },
211
+ {
212
+ ignores: [
213
+ 'dist/**',
214
+ 'node_modules/**',
215
+ '.turbo/**',
216
+ 'coverage/**',
217
+ '**/*.js',
218
+ '**/*.test.ts',
219
+ ],
220
+ },
221
+ ];
222
+ --- filename: env.json
223
+ {
224
+ "ENVIRONMENT": "dev",
225
+ "UPSTASH_REDIS_REST_URL": "your_redis_url",
226
+ "UPSTASH_REDIS_REST_TOKEN": "your_redis_token"
227
+ }
228
+ --- filename: microfox.json
229
+ {
230
+ "stage": "prod"
231
+ }
232
+ --- filename: README.md
233
+ # <%= agentName %> Agent
234
+
235
+ This is a Microbizz agent for <%= agentName %>.
236
+
237
+ ## Getting Started
238
+
239
+ ### Prerequisites
240
+ - Node.js >= 20.x
241
+ - Serverless Framework
242
+ - AWS Account
243
+
244
+ ### Installation
245
+ 1. Clone the repository
246
+ 2. Install dependencies:
247
+ ```bash
248
+ npm install
249
+ ```
250
+ 3. Configure your environment variables in `env.json`.
251
+
252
+ ### Running locally
253
+ ```bash
254
+ npm run dev
255
+ ```
256
+
257
+ ### Deployment
258
+ ```bash
259
+ # Deploy to development
260
+ npm run deploy
261
+
262
+ # Deploy to production
263
+ npm run deploy:prod
264
+ ```
265
+ --- filename: .gitignore
266
+ # Dependencies
267
+ node_modules/
268
+ dist/
269
+ .serverless/
270
+ .env
271
+ env.json
272
+ npm-debug.log*
273
+ yarn-debug.log*
274
+ yarn-error.log*
275
+
276
+ # IDE
277
+ .idea/
278
+ .vscode/
279
+
280
+ # OS
281
+ .DS_Store
282
+
283
+ # Logs
284
+ logs
285
+ *.log
286
+ --- filename: src/index.ts
287
+ import { handleApiRequestDocs } from './functions/api-handler.js'
288
+ import { handleScheduledTaskDocs } from './functions/cron-handler.js'
289
+ import { handleQueueMessageDocs } from './functions/sqs-handler.js'
290
+
291
+ /**
292
+ * Complete API documentation
293
+ * This is an OpenAPI 3.0.1 definition for the agent's API.
294
+ */
295
+ const apiDocs = {
296
+ openapi: '3.0.1',
297
+ info: {
298
+ title: '<%= agentName %> API',
299
+ version: '1.0.0',
300
+ description: 'API for the <%= agentName %> agent.',
301
+ contact: {
302
+ name: 'API Support',
303
+ email: 'support@microfox.app',
304
+ },
305
+ },
306
+ servers: [
307
+ {
308
+ url: 'https://api.microfox.com/c/some-hash',
309
+ description: 'Production server',
310
+ },
311
+ ],
312
+ paths: {
313
+ '/items': {
314
+ post: handleApiRequestDocs,
315
+ },
316
+ },
317
+ components: {
318
+ schemas: {
319
+ //...handleApiRequestDocs.components.schemas
320
+ }
321
+ }
322
+ }
323
+
324
+ /**
325
+ * GET endpoint to serve API documentation.
326
+ * This function returns the OpenAPI specification in JSON format.
327
+ */
328
+ export const getDocs = async () => {
329
+ try {
330
+ return {
331
+ statusCode: 200,
332
+ headers: {
333
+ 'Content-Type': 'application/json',
334
+ 'Access-Control-Allow-Origin': '*',
335
+ 'Access-Control-Allow-Credentials': true,
336
+ },
337
+ body: JSON.stringify(apiDocs, null, 2),
338
+ }
339
+ } catch (error) {
340
+ console.error('Error serving docs:', error)
341
+ return {
342
+ statusCode: 500,
343
+ headers: {
344
+ 'Content-Type': 'application/json',
345
+ 'Access-Control-Allow-Origin': '*',
346
+ 'Access-Control-Allow-Credentials': true,
347
+ },
348
+ body: JSON.stringify({
349
+ error: error instanceof Error ? error.message : 'Unknown error',
350
+ }),
351
+ }
352
+ }
353
+ }
354
+ --- filename: src/helpers/redis.ts
355
+ import { Redis } from '@upstash/redis'
356
+
357
+ const redis = new Redis({
358
+ url: process.env.UPSTASH_REDIS_REST_URL || '',
359
+ token: process.env.UPSTASH_REDIS_REST_TOKEN || '',
360
+ })
361
+
362
+ export default redis;
363
+
364
+ // You can add your helper functions for redis here
365
+ --- filename: src/functions/api-handler.ts
366
+ import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
367
+ import redis from '../helpers/redis.js';
368
+
369
+ export const handler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
370
+ if (!event.body) {
371
+ return {
372
+ statusCode: 400,
373
+ body: JSON.stringify({ message: 'Missing request body' }),
374
+ };
375
+ }
376
+
377
+ try {
378
+ const { itemId } = JSON.parse(event.body);
379
+ if (!itemId) {
380
+ return {
381
+ statusCode: 400,
382
+ body: JSON.stringify({ message: 'Missing itemId in request body' }),
383
+ };
384
+ }
385
+
386
+ const item = await redis.get(`item:${itemId}`);
387
+ if (!item) {
388
+ return {
389
+ statusCode: 404,
390
+ body: JSON.stringify({ message: 'Item not found' }),
391
+ };
392
+ }
393
+ return {
394
+ statusCode: 200,
395
+ body: JSON.stringify(item),
396
+ };
397
+ } catch (error) {
398
+ console.error(error);
399
+ if (error instanceof SyntaxError) {
400
+ return {
401
+ statusCode: 400,
402
+ body: JSON.stringify({ message: 'Invalid JSON in request body' }),
403
+ };
404
+ }
405
+ return {
406
+ statusCode: 500,
407
+ body: JSON.stringify({ message: 'Internal server error' }),
408
+ };
409
+ }
410
+ };
411
+
412
+ export const handleApiRequestDocs = {
413
+ summary: 'Retrieve an item by ID',
414
+ description: 'Retrieves a specific item from the database using its ID.',
415
+ tags: ['Items'],
416
+ requestBody: {
417
+ required: true,
418
+ content: {
419
+ 'application/json': {
420
+ schema: {
421
+ type: 'object',
422
+ properties: {
423
+ itemId: {
424
+ type: 'string',
425
+ description: 'The ID of the item to retrieve.'
426
+ }
427
+ },
428
+ required: ['itemId']
429
+ }
430
+ }
431
+ }
432
+ },
433
+ responses: {
434
+ '200': {
435
+ description: 'Successful response with the item.',
436
+ content: {
437
+ 'application/json': {
438
+ schema: {
439
+ type: 'object',
440
+ properties: {
441
+ id: { type: 'string' },
442
+ data: { type: 'string' }
443
+ }
444
+ }
445
+ }
446
+ }
447
+ },
448
+ '400': { description: 'Bad Request: Missing or invalid request body.' },
449
+ '404': { description: 'Item not found.' },
450
+ '500': { description: 'Internal server error.' },
451
+ },
452
+ };
453
+ --- filename: src/functions/cron-handler.ts
454
+ export const handler = async () => {
455
+ console.log('Running scheduled task...');
456
+ // Add your logic for the scheduled task here.
457
+ // For example, processing data, generating reports, etc.
458
+ console.log('Scheduled task finished.');
459
+ };
460
+
461
+ export const handleScheduledTaskDocs = {
462
+ summary: 'Scheduled Task',
463
+ description: 'This function runs on a schedule to perform routine tasks.',
464
+ tags: ['Cron Jobs'],
465
+ };
466
+ --- filename: src/functions/sqs-handler.ts
467
+ import { SQSHandler, SQSEvent } from 'aws-lambda';
468
+
469
+ export const handler: SQSHandler = async (event: SQSEvent) => {
470
+ for (const record of event.Records) {
471
+ try {
472
+ const body = JSON.parse(record.body);
473
+ console.log('Processing message:', body);
474
+ // Add your SQS message processing logic here
475
+ } catch (error) {
476
+ console.error('Error processing message:', error);
477
+ // Decide if you want to re-queue the message, or send to a DLQ
478
+ }
479
+ }
480
+ };
481
+
482
+ export const handleQueueMessageDocs = {
483
+ summary: 'Process SQS Queue',
484
+ description: 'This function processes messages from an SQS queue.',
485
+ tags: ['SQS Handlers'],
486
+ };
@@ -0,0 +1,22 @@
1
+ # Dependencies
2
+ node_modules/
3
+ dist/
4
+ .build/
5
+ .serverless/
6
+ package-lock.json
7
+ .env
8
+ env.json
9
+ npm-debug.log*
10
+ yarn-debug.log*
11
+ yarn-error.log*
12
+
13
+ # IDE
14
+ .idea/
15
+ .vscode/
16
+
17
+ # OS
18
+ .DS_Store
19
+
20
+ # Logs
21
+ logs
22
+ *.log