Parse quoted payment config keys#741
Conversation
Greptile SummaryThis PR teaches the payments config parser to match JSON-style quoted object keys (
Confidence Score: 3/5The refactor and The regression in packages/cli/src/commands/config-payments.ts — specifically the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[parsePaymentsSummary] --> B[readObjectBody - payments]
B -->|no match| RU[return undefined]
B -->|found| C[readObjectBody - providers]
B --> D[readStringProperty - defaultProvider]
B --> E[readNumberProperty - platformFeeBps]
C --> F[readTopLevelObjectEntries]
F --> G[readStringProperty - use]
F --> H[readBooleanProperty - enabled]
G & H --> I[map to PaymentProviderSummary]
D & E & I --> J[return PaymentsSummary]
PK[propertyKeyPattern - optional quotes around key]
B -.->|anchor guards false positives| PK
D -.->|trailing quote may false-match| PK
E -.->|trailing quote may false-match| PK
G -.->|trailing quote may false-match| PK
H -.->|trailing quote may false-match| PK
Reviews (1): Last reviewed commit: "Parse quoted payment config keys" | Re-trigger Greptile |
| function readStringProperty(source: string, key: string): string | undefined { | ||
| const match = new RegExp(`${propertyKeyPattern(key)}\\s*:\\s*['"]([^'"]+)['"]`).exec(source); | ||
| return match?.[1]; | ||
| } | ||
|
|
||
| function readNumberProperty(source: string, key: string): number | undefined { | ||
| const match = new RegExp(`${propertyKeyPattern(key)}\\s*:\\s*(\\d+)`).exec(source); | ||
| return match?.[1] ? Number(match[1]) : undefined; | ||
| } | ||
|
|
||
| function readBooleanProperty(source: string, key: string): boolean | undefined { | ||
| const match = new RegExp(`${propertyKeyPattern(key)}\\s*:\\s*(true|false)`).exec(source); | ||
| return match?.[1] === undefined ? undefined : match[1] === 'true'; |
There was a problem hiding this comment.
Trailing
['"']? in propertyKeyPattern causes false-positive matches in value-reading helpers
propertyKeyPattern(key) returns ['"']?key['"']?. When used inside readStringProperty, readNumberProperty, and readBooleanProperty, the optional trailing quote can consume the closing quote of a longer key that ends with the searched key. For example, searching for use in a provider body containing "disuse": "something" — the old pattern (use\s*:) would fail because the " closing disuse appears before :. The new pattern (['"']?use['"']?\s*:) matches because ['"']? absorbs that ", and \s*: then matches :, returning something as the value of use. readObjectBody is safe because its (?:^|[,{\s]) anchor limits false starts, but the three value-reading helpers have no such anchor.
| function propertyKeyPattern(key: string): string { | ||
| return `['"]?${escapeRegExp(key)}['"]?`; | ||
| } |
There was a problem hiding this comment.
propertyKeyPattern permits mismatched opening/closing quotes
['"']?key['"']? treats the opening and closing quote as independent optional characters, so 'key" or "key' are accepted. While valid TS/JSON configs won't emit mismatched quotes, capturing the opening quote and back-referencing it for the close would make the intent unambiguous.
|
CI is green for PR #741. Verification:
uGig invoice evidence has been sent for this PR. |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
3 similar comments
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
|
🤖 Auto-rebase: The branch was rebased successfully locally but could not be pushed to the fork. Please enable 'Allow edits from maintainers' in the PR settings, or rebase manually: |
Closes #740.
Summary
"payments","providers", and"defaultProvider".Verification
corepack pnpm vitest run packages/cli/src/commands/config.test.tscorepack pnpm --filter @profullstack/sh1pt typecheck(fails on existing workspace/module-resolution errors unrelated to this change: missing@profullstack/sh1pt-core,@profullstack/sh1pt-openapi/*, etc.)