@geek-fun/serverlessinsight 0.5.8 → 0.6.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.
- package/AGENTS.md +372 -0
- package/README.md +2 -2
- package/README.zh-CN.md +11 -8
- package/dist/package.json +3 -1
- package/dist/src/commands/index.js +5 -4
- package/dist/src/common/aliyunClient/apigwOperations.js +96 -9
- package/dist/src/common/aliyunClient/casOperations.js +116 -0
- package/dist/src/common/aliyunClient/index.js +8 -0
- package/dist/src/common/aliyunClient/ossOperations.js +61 -4
- package/dist/src/common/aliyunClient/ramOperations.js +65 -20
- package/dist/src/common/certificateResolver.js +63 -0
- package/dist/src/common/iacHelper.js +9 -1
- package/dist/src/common/index.js +1 -0
- package/dist/src/common/tencentClient/index.js +18 -0
- package/dist/src/common/tencentClient/sslOperations.js +107 -0
- package/dist/src/lang/en.js +169 -0
- package/dist/src/lang/index.js +6 -0
- package/dist/src/lang/zh-CN.js +167 -0
- package/dist/src/parser/bucketParser.js +19 -1
- package/dist/src/parser/certificateParser.js +23 -0
- package/dist/src/parser/index.js +2 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +15 -9
- package/dist/src/stack/aliyunStack/apigwPlanner.js +15 -2
- package/dist/src/stack/aliyunStack/apigwResource.js +44 -17
- package/dist/src/stack/aliyunStack/apigwTypes.js +36 -5
- package/dist/src/stack/aliyunStack/databaseExecutor.js +24 -9
- package/dist/src/stack/aliyunStack/databaseResource.js +5 -1
- package/dist/src/stack/aliyunStack/deployer.js +11 -2
- package/dist/src/stack/aliyunStack/destroyer.js +5 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +10 -9
- package/dist/src/stack/aliyunStack/fc3Resource.js +36 -27
- package/dist/src/stack/aliyunStack/ossExecutor.js +9 -9
- package/dist/src/stack/aliyunStack/ossResource.js +48 -5
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +21 -9
- package/dist/src/stack/localStack/event.js +1 -1
- package/dist/src/stack/scfStack/cosExecutor.js +9 -9
- package/dist/src/stack/scfStack/cosResource.js +45 -7
- package/dist/src/stack/scfStack/deployer.js +5 -1
- package/dist/src/stack/scfStack/destroyer.js +5 -1
- package/dist/src/stack/scfStack/esServerlessExecutor.js +21 -9
- package/dist/src/stack/scfStack/esServerlessResource.js +2 -1
- package/dist/src/stack/scfStack/scfExecutor.js +9 -9
- package/dist/src/stack/scfStack/scfResource.js +2 -1
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +9 -9
- package/dist/src/stack/scfStack/tdsqlcResource.js +5 -1
- package/dist/src/types/domains/certificate.js +2 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/validator/bucketSchema.js +27 -1
- package/dist/src/validator/certificateSchema.js +31 -0
- package/dist/src/validator/eventSchema.js +12 -0
- package/dist/src/validator/iacSchema.js +2 -0
- package/dist/src/validator/rootSchema.js +3 -0
- package/dist/src/validator/templateRefSchema.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
# AGENTS.md - Coding Conventions for AI Agents
|
|
2
|
+
|
|
3
|
+
This document defines coding conventions that AI agents (and human developers) must follow when contributing to ServerlessInsight.
|
|
4
|
+
|
|
5
|
+
## Build/Lint/Test Commands
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Build the project
|
|
9
|
+
npm run build
|
|
10
|
+
|
|
11
|
+
# Lint check (without fixing)
|
|
12
|
+
npm run lint:check
|
|
13
|
+
|
|
14
|
+
# Lint and auto-fix issues
|
|
15
|
+
npm run lint:fix
|
|
16
|
+
|
|
17
|
+
# Run all tests
|
|
18
|
+
npm test
|
|
19
|
+
|
|
20
|
+
# Run tests for a specific file pattern
|
|
21
|
+
npm test -- --testPathPatterns="fc3Resource" --passWithNoTests
|
|
22
|
+
|
|
23
|
+
# Run a single test file
|
|
24
|
+
npm test -- --testPathPatterns="path/to/test.test.ts" --passWithNoTests
|
|
25
|
+
|
|
26
|
+
# Run tests matching a test name pattern
|
|
27
|
+
npm test -- --testNamePattern="should create resource" --passWithNoTests
|
|
28
|
+
|
|
29
|
+
# CI test run (no debug output)
|
|
30
|
+
npm run test:ci
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Internationalization (i18n) - MANDATORY
|
|
34
|
+
|
|
35
|
+
**All user-facing messages MUST use the i18n system. Never hardcode English strings.**
|
|
36
|
+
|
|
37
|
+
### Pattern
|
|
38
|
+
|
|
39
|
+
1. Add the message key to `src/lang/en.ts`:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
YOUR_MESSAGE_KEY: 'Your message with {{variable}} placeholder',
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. Add the Chinese translation to `src/lang/zh-CN.ts`:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
YOUR_MESSAGE_KEY: '带有 {{variable}} 占位符的中文消息',
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
3. Use the message in code:
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
import { lang } from '../../lang';
|
|
55
|
+
|
|
56
|
+
throw new Error(lang.__('YOUR_MESSAGE_KEY', { variable: value }));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Examples
|
|
60
|
+
|
|
61
|
+
**WRONG - Hardcoded English string:**
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
throw new Error(`RAM role "${roleName}" does not exist in the cloud provider.`);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**CORRECT - Using i18n:**
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { lang } from '../../lang';
|
|
71
|
+
|
|
72
|
+
throw new Error(lang.__('RAM_ROLE_NOT_FOUND_IN_CLOUD', { roleName }));
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Where this applies
|
|
76
|
+
|
|
77
|
+
- Error messages
|
|
78
|
+
- Warning messages
|
|
79
|
+
- Info/log messages
|
|
80
|
+
- User prompts
|
|
81
|
+
- Any text that could be seen by an end user
|
|
82
|
+
|
|
83
|
+
### Where this does NOT apply
|
|
84
|
+
|
|
85
|
+
- Internal debug identifiers
|
|
86
|
+
- API request/response field names
|
|
87
|
+
- Code comments
|
|
88
|
+
- Variable/function names
|
|
89
|
+
|
|
90
|
+
## Functional TypeScript
|
|
91
|
+
|
|
92
|
+
### Function Style
|
|
93
|
+
|
|
94
|
+
- **Define functions as `const`**: Use `const xxx = (...) => ...` syntax
|
|
95
|
+
- **Prefer functional decomposition over OOP**: Avoid classes unless strictly necessary
|
|
96
|
+
- **Keep functions small and focused**: Single responsibility, easy to test
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
// GOOD
|
|
100
|
+
const buildAssumeRolePolicy = (trustedServices: string[]): string =>
|
|
101
|
+
JSON.stringify({
|
|
102
|
+
Version: '1',
|
|
103
|
+
Statement: [{ Action: 'sts:AssumeRole', Effect: 'Allow', Principal: { Service: trustedServices } }],
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// AVOID
|
|
107
|
+
class RolePolicyBuilder {
|
|
108
|
+
build(trustedServices: string[]) { ... }
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Declarative Collection Handling
|
|
113
|
+
|
|
114
|
+
Replace `for`/`while` loops with `map`, `filter`, `find`, `some`, `every`, `reduce`, `flatMap`. Favor pipeline-style transformations.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
// GOOD
|
|
118
|
+
const roleArns = instances.filter((i) => i.type === 'ALIYUN_RAM_ROLE').map((i) => i.roleArn);
|
|
119
|
+
|
|
120
|
+
// AVOID
|
|
121
|
+
const roleArns: string[] = [];
|
|
122
|
+
for (const i of instances) {
|
|
123
|
+
if (i.type === 'ALIYUN_RAM_ROLE') {
|
|
124
|
+
roleArns.push(i.roleArn);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Immutability
|
|
130
|
+
|
|
131
|
+
- Avoid in-place mutation (`push`, `splice`, mutating objects/arrays)
|
|
132
|
+
- Return new arrays/objects
|
|
133
|
+
- Model changes as explicit state-transform functions
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// GOOD - return new object
|
|
137
|
+
const newState = { ...state, resources: { ...state.resources, [id]: resource } };
|
|
138
|
+
|
|
139
|
+
// AVOID - mutation
|
|
140
|
+
state.resources[id] = resource;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Pure Functions
|
|
144
|
+
|
|
145
|
+
- Keep functions side-effect-free where possible
|
|
146
|
+
- Isolate effects (I/O, logging) at boundaries
|
|
147
|
+
- Keep core logic pure
|
|
148
|
+
|
|
149
|
+
## Module & Export Discipline
|
|
150
|
+
|
|
151
|
+
### Module Boundaries
|
|
152
|
+
|
|
153
|
+
- Each module exports **only** via its `index.ts`
|
|
154
|
+
- Avoid deep imports from outside the module
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// GOOD
|
|
158
|
+
import { createAliyunClient } from '../../common/aliyunClient';
|
|
159
|
+
|
|
160
|
+
// AVOID
|
|
161
|
+
import { createRamOperations } from '../../common/aliyunClient/ramOperations';
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Export Discipline
|
|
165
|
+
|
|
166
|
+
- Only export functions/types/constants that are used outside the module
|
|
167
|
+
- Keep implementation details private
|
|
168
|
+
|
|
169
|
+
### Provider-Agnostic Design
|
|
170
|
+
|
|
171
|
+
- Keep abstractions provider-agnostic
|
|
172
|
+
- Clean separation of concerns between providers
|
|
173
|
+
|
|
174
|
+
## Code Style
|
|
175
|
+
|
|
176
|
+
### TypeScript
|
|
177
|
+
|
|
178
|
+
- **Target**: ES2020, CommonJS modules
|
|
179
|
+
- **Strict mode**: Enabled
|
|
180
|
+
- **Use `type` over `interface`** for type definitions
|
|
181
|
+
- Use early returns to reduce nesting
|
|
182
|
+
|
|
183
|
+
### Imports
|
|
184
|
+
|
|
185
|
+
Group imports in this order, separated by blank lines:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// 1. External packages
|
|
189
|
+
import RamClient from '@alicloud/ram20150501';
|
|
190
|
+
import * as ram from '@alicloud/ram20150501';
|
|
191
|
+
import fs from 'node:fs';
|
|
192
|
+
|
|
193
|
+
// 2. Internal modules (use relative paths with barrel exports)
|
|
194
|
+
import { createAliyunClient } from '../../common/aliyunClient';
|
|
195
|
+
import { Context, StateFile } from '../../types';
|
|
196
|
+
|
|
197
|
+
// 3. Types (if needed separately)
|
|
198
|
+
import type { RamRoleInfo } from './types';
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Naming Conventions
|
|
202
|
+
|
|
203
|
+
- **Files**: camelCase for modules (e.g., `fc3Resource.ts`, `ramOperations.ts`)
|
|
204
|
+
- **Functions**: camelCase, verb-first (e.g., `createResource`, `getRoleArnFromState`)
|
|
205
|
+
- **Types**: PascalCase (e.g., `FunctionDomain`, `StateFile`)
|
|
206
|
+
- **Constants**: SCREAMING_SNAKE_CASE (e.g., `RAM_ROLE_PROPAGATION_DELAY_MS`)
|
|
207
|
+
- **Private helpers**: camelCase at module level (e.g., `buildAssumeRolePolicy`, `delay`)
|
|
208
|
+
|
|
209
|
+
### Error Handling
|
|
210
|
+
|
|
211
|
+
- Always use i18n for error messages
|
|
212
|
+
- Throw `Error` objects with localized messages
|
|
213
|
+
- For cloud SDK errors, catch and wrap with meaningful messages:
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
try {
|
|
217
|
+
await client.ram.getRole(request);
|
|
218
|
+
} catch (error: unknown) {
|
|
219
|
+
if (
|
|
220
|
+
error &&
|
|
221
|
+
typeof error === 'object' &&
|
|
222
|
+
'code' in error &&
|
|
223
|
+
error.code === 'EntityNotExist.Role'
|
|
224
|
+
) {
|
|
225
|
+
throw new Error(lang.__('RAM_ROLE_NOT_FOUND_IN_CLOUD', { roleName }));
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Logging
|
|
232
|
+
|
|
233
|
+
Use the pino logger from `src/common/logger`:
|
|
234
|
+
|
|
235
|
+
```typescript
|
|
236
|
+
import { logger } from '../../common/logger';
|
|
237
|
+
|
|
238
|
+
logger.info(lang.__('CREATING_RAM_ROLE', { roleName }));
|
|
239
|
+
logger.warn(lang.__('STAGE_VARIABLE_NOT_FOUND', { key, stage }));
|
|
240
|
+
logger.error(lang.__('FAILED_TO_DEPLOY_STACK', { error }));
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Documentation
|
|
244
|
+
|
|
245
|
+
- **Minimal inline comments**: Behavior should be clear from tests and naming
|
|
246
|
+
- Code should be self-documenting
|
|
247
|
+
|
|
248
|
+
### Testing
|
|
249
|
+
|
|
250
|
+
- Tests live in `tests/` mirroring the `src/` structure
|
|
251
|
+
- Use Jest with `jest.fn()` for mocks
|
|
252
|
+
- Group mocks at the top of the test file
|
|
253
|
+
- Use `jest.mock()` for module mocking before imports
|
|
254
|
+
- Use `describe/it` blocks for organization
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
describe('updateResource', () => {
|
|
258
|
+
it('should update resource and refresh state from provider', async () => {
|
|
259
|
+
// Arrange
|
|
260
|
+
mockedFc3Operations.updateFunctionConfiguration.mockResolvedValue(undefined);
|
|
261
|
+
|
|
262
|
+
// Act
|
|
263
|
+
const result = await updateResource(mockContext, testFunction, initialState);
|
|
264
|
+
|
|
265
|
+
// Assert
|
|
266
|
+
expect(mockedFc3Operations.updateFunctionConfiguration).toHaveBeenCalledWith(
|
|
267
|
+
expect.objectContaining({ functionName: 'test-function' }),
|
|
268
|
+
);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Formatting
|
|
274
|
+
|
|
275
|
+
Prettier configuration (`.prettierrc`):
|
|
276
|
+
|
|
277
|
+
- Single quotes
|
|
278
|
+
- Print width: 100
|
|
279
|
+
- Tab width: 2
|
|
280
|
+
|
|
281
|
+
Run `npm run lint:fix` to auto-format before committing.
|
|
282
|
+
|
|
283
|
+
## Architecture Principles
|
|
284
|
+
|
|
285
|
+
### Decision Checklist
|
|
286
|
+
|
|
287
|
+
Before making architecture changes, verify:
|
|
288
|
+
|
|
289
|
+
1. **Standard Solution First**
|
|
290
|
+
- Is this an industry-standard approach?
|
|
291
|
+
- Are there successful case studies?
|
|
292
|
+
- Good documentation and community support?
|
|
293
|
+
|
|
294
|
+
2. **Cross-Platform Compatibility**
|
|
295
|
+
- Can Windows users use this normally?
|
|
296
|
+
- Path separators handled correctly?
|
|
297
|
+
- Platform compatibility tested?
|
|
298
|
+
|
|
299
|
+
3. **Simplicity**
|
|
300
|
+
- Script under 50 lines?
|
|
301
|
+
- Existing tools available?
|
|
302
|
+
- New member can understand in 10 minutes?
|
|
303
|
+
|
|
304
|
+
4. **Reproducible Build**
|
|
305
|
+
- Consistent across different machines?
|
|
306
|
+
- No dependency on local state?
|
|
307
|
+
- Build verification in place?
|
|
308
|
+
|
|
309
|
+
5. **Full Evaluation**
|
|
310
|
+
- ADR (Architecture Decision Record) written?
|
|
311
|
+
- At least 3 alternatives considered?
|
|
312
|
+
- 1-year maintenance cost evaluated?
|
|
313
|
+
- Team discussion and consensus?
|
|
314
|
+
|
|
315
|
+
### Red Flags
|
|
316
|
+
|
|
317
|
+
Avoid these patterns:
|
|
318
|
+
|
|
319
|
+
- Abandoning standard solutions for convenience
|
|
320
|
+
- Platform-specific scripts
|
|
321
|
+
- Scripts over 50 lines
|
|
322
|
+
- No cross-platform testing
|
|
323
|
+
- Rushed decisions
|
|
324
|
+
|
|
325
|
+
## Project Structure
|
|
326
|
+
|
|
327
|
+
```
|
|
328
|
+
src/
|
|
329
|
+
├── commands/ # CLI command handlers (deploy, destroy, plan, etc.)
|
|
330
|
+
├── common/ # Shared utilities, clients, state management
|
|
331
|
+
│ └── aliyunClient/ # Aliyun SDK wrapper functions
|
|
332
|
+
├── lang/ # i18n translations (en.ts, zh-CN.ts)
|
|
333
|
+
├── parser/ # YAML parsing and validation
|
|
334
|
+
├── stack/ # Provider-specific resource logic
|
|
335
|
+
│ ├── aliyunStack/ # Alibaba Cloud resources
|
|
336
|
+
│ ├── scfStack/ # Tencent Cloud resources
|
|
337
|
+
│ └── localStack/ # Local development server
|
|
338
|
+
├── types/ # TypeScript type definitions
|
|
339
|
+
└── validator/ # JSON schema validation
|
|
340
|
+
|
|
341
|
+
tests/ # Test files mirroring src/ structure
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Key Patterns
|
|
345
|
+
|
|
346
|
+
### Resource Functions
|
|
347
|
+
|
|
348
|
+
Each resource module exports:
|
|
349
|
+
|
|
350
|
+
- `createResource(context, definition, state)` - Create new resource
|
|
351
|
+
- `readResource(context, identifier)` - Read from provider
|
|
352
|
+
- `updateResource(context, definition, state)` - Update existing resource
|
|
353
|
+
- `deleteResource(context, state)` - Delete resource
|
|
354
|
+
|
|
355
|
+
### Client Pattern
|
|
356
|
+
|
|
357
|
+
Cloud SDK clients are wrapped in functional modules:
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
// src/common/aliyunClient/ramOperations.ts
|
|
361
|
+
export const createRamOperations = (ramClient: RamSdkClient) => ({
|
|
362
|
+
createRole: async (roleName: string, trustedServices: string[]): Promise<RamRoleInfo> => { ... },
|
|
363
|
+
getRole: async (roleName: string): Promise<RamRoleInfo | null> => { ... },
|
|
364
|
+
deleteRole: async (roleName: string): Promise<void> => { ... },
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### State Management
|
|
369
|
+
|
|
370
|
+
- State is stored in `.serverlessinsight/state-{app}-{service}.json`
|
|
371
|
+
- Use `setResource`, `getResource`, `removeResource` from `src/common/stateManager`
|
|
372
|
+
- Resources have a `status`: `'ready'` | `'tainted'`
|
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ ServerlessInsight supports the following cloud providers:
|
|
|
50
50
|
| Provider | Functions | API Gateway | Storage | Databases | Status |
|
|
51
51
|
| ----------------- | ---------------- | -------------- | -------------- | ---------------- | ------- |
|
|
52
52
|
| **Alibaba Cloud** | ✅ FC3 | ✅ API Gateway | ✅ OSS | ✅ RDS, OTS, ESS | Stable |
|
|
53
|
-
| **Tencent Cloud** | ✅ SCF |
|
|
53
|
+
| **Tencent Cloud** | ✅ SCF | 🚧 Coming Soon | ✅ COS | ✅ TDSQL-C | Stable |
|
|
54
54
|
| **Huawei Cloud** | ✅ FunctionGraph | 🚧 Coming Soon | 🚧 Coming Soon | 🚧 Coming Soon | Beta |
|
|
55
55
|
| **AWS** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
|
|
56
56
|
| **Azure** | 🔜 Planned | 🔜 Planned | 🔜 Planned | 🔜 Planned | Planned |
|
|
@@ -165,7 +165,7 @@ npm run build
|
|
|
165
165
|
npm link
|
|
166
166
|
|
|
167
167
|
# Run local development server
|
|
168
|
-
si local
|
|
168
|
+
si local -f serverless.yml -s local
|
|
169
169
|
|
|
170
170
|
# Run tests
|
|
171
171
|
npm test
|
package/README.zh-CN.md
CHANGED
|
@@ -50,11 +50,11 @@ ServerlessInsight 支持以下云服务商:
|
|
|
50
50
|
| 云服务商 | 函数 | API 网关 | 存储 | 数据库 | 状态 |
|
|
51
51
|
| ---------------- | ---------------- | ----------- | ----------- | ---------------- | ------ |
|
|
52
52
|
| **阿里云** | ✅ FC3 | ✅ API 网关 | ✅ OSS | ✅ RDS, OTS, ESS | 稳定 |
|
|
53
|
+
| **腾讯云** | ✅ SCF | 🚧 即将推出 | ✅ COS | ✅ TDSQL-C | 稳定 |
|
|
53
54
|
| **华为云** | ✅ FunctionGraph | 🚧 即将推出 | 🚧 即将推出 | 🚧 即将推出 | 测试版 |
|
|
54
55
|
| **AWS** | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 计划中 |
|
|
55
56
|
| **Azure** | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 计划中 |
|
|
56
57
|
| **Google Cloud** | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 计划中 |
|
|
57
|
-
| **腾讯云** | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 🔜 计划中 | 计划中 |
|
|
58
58
|
|
|
59
59
|
---
|
|
60
60
|
|
|
@@ -85,19 +85,22 @@ si --version
|
|
|
85
85
|
|
|
86
86
|
```bash
|
|
87
87
|
# 验证您的 Serverless 配置
|
|
88
|
-
si validate
|
|
88
|
+
si validate -f serverless.yml
|
|
89
|
+
|
|
90
|
+
# 生成部署计划(查看将要发生的变更)
|
|
91
|
+
si plan -f serverless.yml
|
|
89
92
|
|
|
90
93
|
# 部署您的 Serverless 应用
|
|
91
|
-
si deploy
|
|
94
|
+
si deploy -f serverless.yml -s dev
|
|
92
95
|
|
|
93
96
|
# 本地运行您的应用进行调试
|
|
94
|
-
si local
|
|
97
|
+
si local -f serverless.yml -s local
|
|
95
98
|
|
|
96
|
-
#
|
|
97
|
-
si
|
|
99
|
+
# 显示已部署资源信息
|
|
100
|
+
si show -f serverless.yml
|
|
98
101
|
|
|
99
102
|
# 销毁已部署的堆栈
|
|
100
|
-
si destroy
|
|
103
|
+
si destroy -f serverless.yml
|
|
101
104
|
```
|
|
102
105
|
|
|
103
106
|
---
|
|
@@ -162,7 +165,7 @@ npm run build
|
|
|
162
165
|
npm link
|
|
163
166
|
|
|
164
167
|
# 运行本地开发服务器
|
|
165
|
-
si local
|
|
168
|
+
si local -f serverless.yml -s local
|
|
166
169
|
|
|
167
170
|
# 运行测试
|
|
168
171
|
npm test
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/alidns20150109": "^4.3.1",
|
|
53
|
+
"@alicloud/cas20200407": "^3.2.0",
|
|
53
54
|
"@alicloud/cloudapi20160714": "^4.7.9",
|
|
54
55
|
"@alicloud/ecs20140526": "^7.6.0",
|
|
55
56
|
"@alicloud/es-serverless20230627": "^2.3.0",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"tencentcloud-sdk-nodejs-dnspod": "^4.1.197",
|
|
76
77
|
"tencentcloud-sdk-nodejs-es": "^4.1.183",
|
|
77
78
|
"tencentcloud-sdk-nodejs-scf": "^4.1.168",
|
|
79
|
+
"tencentcloud-sdk-nodejs-ssl": "^4.1.191",
|
|
78
80
|
"yaml": "^2.8.2"
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
@@ -61,11 +61,12 @@ program
|
|
|
61
61
|
.description('show deployed resources from state')
|
|
62
62
|
.option('-f, --file <path>', 'specify the yaml file')
|
|
63
63
|
.option('-s, --stage <stage>', 'specify the stage')
|
|
64
|
-
.action(actionWrapper('show', async (
|
|
65
|
-
const iacLocation = (0, common_1.getIacLocation)(
|
|
64
|
+
.action(actionWrapper('show', async ({ file, stage }) => {
|
|
65
|
+
const iacLocation = (0, common_1.getIacLocation)(file);
|
|
66
66
|
const rawIac = (0, parser_1.parseYaml)(iacLocation);
|
|
67
67
|
await (0, common_1.setContext)({
|
|
68
|
-
|
|
68
|
+
location: file,
|
|
69
|
+
stage,
|
|
69
70
|
app: rawIac.app,
|
|
70
71
|
service: rawIac.service,
|
|
71
72
|
iacProvider: rawIac.provider,
|
|
@@ -74,7 +75,7 @@ program
|
|
|
74
75
|
const context = (0, common_1.getContext)();
|
|
75
76
|
const iac = (0, parser_1.revalYaml)(iacLocation, context);
|
|
76
77
|
(0, common_1.setIac)(iac);
|
|
77
|
-
await (0, show_1.show)({ stage
|
|
78
|
+
await (0, show_1.show)({ stage, location: file, iac });
|
|
78
79
|
}));
|
|
79
80
|
program
|
|
80
81
|
.command('validate')
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createApigwOperations = void 0;
|
|
36
|
+
exports.createApigwOperations = exports.isDomainAlreadyBoundError = exports.isNetworkTimeoutError = void 0;
|
|
37
37
|
const cloudapi = __importStar(require("@alicloud/cloudapi20160714"));
|
|
38
38
|
const node_dns_1 = require("node:dns");
|
|
39
39
|
const dnsOperations_1 = require("./dnsOperations");
|
|
@@ -47,6 +47,28 @@ const removeUndefined = (obj) => {
|
|
|
47
47
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
|
|
48
48
|
};
|
|
49
49
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
|
+
const isNetworkTimeoutError = (error) => {
|
|
51
|
+
if (!error || typeof error !== 'object')
|
|
52
|
+
return false;
|
|
53
|
+
const err = error;
|
|
54
|
+
return (err.name === 'RequestTimeoutError' ||
|
|
55
|
+
err.name === 'ConnectTimeout' ||
|
|
56
|
+
err.code === 'RequestTimeoutError' ||
|
|
57
|
+
err.code === 'ConnectTimeout' ||
|
|
58
|
+
(err.message?.includes('ConnectTimeout') ?? false) ||
|
|
59
|
+
(err.message?.includes('RequestTimeoutError') ?? false));
|
|
60
|
+
};
|
|
61
|
+
exports.isNetworkTimeoutError = isNetworkTimeoutError;
|
|
62
|
+
const isDomainAlreadyBoundError = (error) => {
|
|
63
|
+
if (!error || typeof error !== 'object')
|
|
64
|
+
return false;
|
|
65
|
+
const err = error;
|
|
66
|
+
return (err.code === 'DomainAlreadyBind' ||
|
|
67
|
+
err.code === 'RepeatedCommit' ||
|
|
68
|
+
(err.message?.includes('bindingExists') ?? false) ||
|
|
69
|
+
(err.message?.toLowerCase().includes('domain bindedbyother') ?? false));
|
|
70
|
+
};
|
|
71
|
+
exports.isDomainAlreadyBoundError = isDomainAlreadyBoundError;
|
|
50
72
|
const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
51
73
|
const dnsOps = (0, dnsOperations_1.createDnsOperations)(dnsClient);
|
|
52
74
|
const buildTxtVerificationRecord = (groupId, domainName, groupSubdomain, mainDomain) => {
|
|
@@ -241,9 +263,34 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
241
263
|
logger_1.logger.info(lang_1.lang.__('APIGW_TXT_ADDING_RECORD', { rr: txtRecord.rr, value: txtRecord.value }));
|
|
242
264
|
try {
|
|
243
265
|
const existingRecords = await dnsOps.describeDomainRecords(mainDomain, txtRecord.rr);
|
|
244
|
-
const
|
|
245
|
-
|
|
266
|
+
const existingRecord = existingRecords.find((record) => record.rr === txtRecord.rr && record.type === 'TXT' && record.value === txtRecord.value);
|
|
267
|
+
const now = new Date();
|
|
268
|
+
if (existingRecord) {
|
|
246
269
|
logger_1.logger.info(lang_1.lang.__('APIGW_TXT_RECORD_ALREADY_EXISTS', { rr: txtRecord.rr }));
|
|
270
|
+
// Track existing record in state so it can be cleaned up on destroy
|
|
271
|
+
const dnsResourceState = {
|
|
272
|
+
mode: 'managed',
|
|
273
|
+
region,
|
|
274
|
+
definition: {
|
|
275
|
+
domainName,
|
|
276
|
+
mainDomain,
|
|
277
|
+
rr: txtRecord.rr,
|
|
278
|
+
value: txtRecord.value,
|
|
279
|
+
type: 'TXT',
|
|
280
|
+
groupId,
|
|
281
|
+
groupSubdomain,
|
|
282
|
+
},
|
|
283
|
+
instances: [
|
|
284
|
+
{
|
|
285
|
+
sid: (0, sidUtils_1.buildSid)('aliyun', 'alidns', _context.stage, 'existing'),
|
|
286
|
+
id: 'existing',
|
|
287
|
+
type: 'TXT',
|
|
288
|
+
status: 'EXISTING',
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
lastUpdated: now.toISOString(),
|
|
292
|
+
};
|
|
293
|
+
state = (0, stateManager_1.setResource)(state, txtResourceId, dnsResourceState);
|
|
247
294
|
return state;
|
|
248
295
|
}
|
|
249
296
|
const recordId = await dnsOps.addDomainRecord({
|
|
@@ -253,6 +300,12 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
253
300
|
value: txtRecord.value,
|
|
254
301
|
ttl: 600,
|
|
255
302
|
});
|
|
303
|
+
logger_1.logger.info(lang_1.lang.__('APIGW_DNS_RECORD_ADDED', {
|
|
304
|
+
record: txtRecord.rr,
|
|
305
|
+
type: 'TXT',
|
|
306
|
+
value: txtRecord.value,
|
|
307
|
+
}));
|
|
308
|
+
// Track DNS record in state
|
|
256
309
|
const dnsResourceState = {
|
|
257
310
|
mode: 'managed',
|
|
258
311
|
region,
|
|
@@ -273,14 +326,9 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
273
326
|
status: 'CREATED',
|
|
274
327
|
},
|
|
275
328
|
],
|
|
276
|
-
lastUpdated:
|
|
329
|
+
lastUpdated: now.toISOString(),
|
|
277
330
|
};
|
|
278
331
|
state = (0, stateManager_1.setResource)(state, txtResourceId, dnsResourceState);
|
|
279
|
-
logger_1.logger.info(lang_1.lang.__('APIGW_DNS_RECORD_ADDED', {
|
|
280
|
-
record: txtRecord.rr,
|
|
281
|
-
type: 'TXT',
|
|
282
|
-
value: txtRecord.value,
|
|
283
|
-
}));
|
|
284
332
|
return state;
|
|
285
333
|
}
|
|
286
334
|
catch (error) {
|
|
@@ -651,6 +699,45 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
651
699
|
}
|
|
652
700
|
catch (error) {
|
|
653
701
|
const err = error;
|
|
702
|
+
// Handle network timeout errors with retry
|
|
703
|
+
if ((0, exports.isNetworkTimeoutError)(error)) {
|
|
704
|
+
for (let attempt = 1; attempt <= constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES; attempt++) {
|
|
705
|
+
logger_1.logger.warn(lang_1.lang.__('APIGW_DOMAIN_BIND_TIMEOUT_RETRY', {
|
|
706
|
+
attempt: String(attempt),
|
|
707
|
+
max: String(constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES),
|
|
708
|
+
}));
|
|
709
|
+
await sleep(constants_1.APIGW_DOMAIN_BIND_RETRY_DELAY_MS);
|
|
710
|
+
try {
|
|
711
|
+
await apigwClient.setDomain(setDomainRequest);
|
|
712
|
+
await setCertificate();
|
|
713
|
+
logger_1.logger.info(lang_1.lang.__('APIGW_DOMAIN_BOUND_SUCCESS', { domain: config.domainName }));
|
|
714
|
+
return state;
|
|
715
|
+
}
|
|
716
|
+
catch (retryError) {
|
|
717
|
+
if ((0, exports.isDomainAlreadyBoundError)(retryError)) {
|
|
718
|
+
logger_1.logger.info(lang_1.lang.__('APIGW_DOMAIN_BIND_ALREADY_BOUND', { domain: config.domainName }));
|
|
719
|
+
await setCertificate();
|
|
720
|
+
return state;
|
|
721
|
+
}
|
|
722
|
+
if (!(0, exports.isNetworkTimeoutError)(retryError)) {
|
|
723
|
+
throw retryError;
|
|
724
|
+
}
|
|
725
|
+
if (attempt === constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES) {
|
|
726
|
+
logger_1.logger.error(lang_1.lang.__('APIGW_DOMAIN_BIND_TIMEOUT_ALL_FAILED', {
|
|
727
|
+
max: String(constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES),
|
|
728
|
+
error: String(retryError),
|
|
729
|
+
}));
|
|
730
|
+
throw retryError;
|
|
731
|
+
}
|
|
732
|
+
logger_1.logger.warn(lang_1.lang.__('APIGW_DOMAIN_BIND_TIMEOUT_RETRY_FAILED', {
|
|
733
|
+
attempt: String(attempt),
|
|
734
|
+
error: String(retryError),
|
|
735
|
+
}));
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
// All timeout retries exhausted (or MAX_RETRIES is 0) — re-throw the original error
|
|
739
|
+
throw error;
|
|
740
|
+
}
|
|
654
741
|
if (err.code !== 'SingleDomainOwnershipCheckFail' && !err.message?.includes('ownership')) {
|
|
655
742
|
throw error;
|
|
656
743
|
}
|