The generator code was correct, but it was inside a template literal that needed double-escaping!
// Line 705 in enterprise-sdk-generator-fixed.cjs
// Inside a template literal starting at line 465
constructor(config: BackendDataKeyConfig) {
this.apiBase = config.apiEndpoint.replace(/\/$/, ''); // ❌ SINGLE BACKSLASH
this.kekName = config.kekName;
this.context = config.context;
}// In generated SDK
constructor(config: BackendDataKeyConfig) {
this.apiBase = config.apiEndpoint.replace(//$/, ''); // ❌ BACKSLASH DISAPPEARED!
// ^^
// TypeScript Error: TS1005: ')' expected.
}When code is inside a template literal (backticks), backslashes are processed twice:
-
First Pass (Template Literal):
\is an escape character/\/$becomes//$(backslash consumed)
-
Second Pass (Generated Code):
//$is invalid regex- Missing the escaped forward slash
// In template literal, use DOUBLE backslash
replace(/\\/$/, '')
// ^^
// First backslash escapes the second backslash
// Result in generated code: /\/$/ ✅// Line 705 in enterprise-sdk-generator-fixed.cjs
constructor(config: BackendDataKeyConfig) {
this.apiBase = config.apiEndpoint.replace(/\\/$/, ''); // ✅ DOUBLE BACKSLASH
// ^^^
this.kekName = config.kekName;
this.context = config.context;
}// In generated SDK
constructor(config: BackendDataKeyConfig) {
this.apiBase = config.apiEndpoint.replace(/\/$/, ''); // ✅ CORRECT!
// ^^^
this.kekName = config.kekName;
this.context = config.context;
}| Code Location | Backslashes Needed | Why |
|---|---|---|
| Normal TypeScript | \/ (1 backslash) |
Escape forward slash in regex |
| Template Literal | \\/ (2 backslashes) |
First \ escapes second \ |
| String in String | \\\\/ (4 backslashes) |
Each level doubles escaping |
- Generate a new SDK
- Check the generated code:
grep -n "apiEndpoint.replace" src/index.ts - Expected output:
263: this.apiBase = config.apiEndpoint.replace(/\/$/, ''); - Compile the SDK:
npx ts-node test-sdk.ts
- Expected: No TypeScript errors ✅
Let me verify if there are other regex patterns in template literals that might need fixing:
\.- Match literal dot\s- Match whitespace\d- Match digit\w- Match word character\/- Match forward slash ← THIS ONE WAS THE ISSUE
\\.- Outputs\.✅\\s- Outputs\s✅\\d- Outputs\d✅\\w- Outputs\w✅\\/- Outputs\/✅ NOW FIXED
// Generator has: /\/$/
// Generates: //$/ ❌
// Result: TypeScript compilation error// Generator has: /\\/$/
// Generates: /\/$/ ✅
// Result: Compiles successfully| File | Line | Change |
|---|---|---|
enterprise-sdk-generator-fixed.cjs |
705 | /\/$ → /\\/$ |
- Generator code updated with double backslash
- Generate new SDK to verify fix
- Compile generated SDK without errors
- Run SDK tests successfully
- Verify envelope encryption works
- Regenerate all existing SDKs to get the fix
- Test envelope encryption with new SDKs
- Verify backend integration works correctly
Root Cause: Template literal consumed the backslash escape character
Solution: Double-escape the backslash in the generator template literal
Result: Generated SDKs will now have correct regex pattern and compile successfully
Status: ✅ GENERATOR FIXED - REGENERATE SDKs TO APPLY FIX