Repository navigation
fix(api): use external key format for customer routes - #3078
Conversation
📝 WalkthroughWalkthroughA new type Changes
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Biome (1.9.4)api/client/javascript/src/zod/index.tsThe --json option is unstable/experimental and its output might change between patches/minor releases. ... [truncated 99999042 characters] ... \n 'Numeric represents an arbitrary precision number.'\n )\n .describe(\n 'The quantity of the usage discount.\n\nMust be positive.'\n ),\n })\n Biome encountered an unexpected error This is a bug in Biome, not an error in your code, and we would appreciate it if you could report it to https://github.com/biomejs/biome/issues/ along with the following information to help us fixing the issue: Source Location: crates/biome_console/src/lib.rs:149:14 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
ba38cfd to
59a979b
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (6)
api/openapi.yaml (6)
3109-3113: Same remark as above – reuse of the central schema is correct.
3182-3186: Same remark as above – reuse of the central schema is correct.
3318-3324: Same remark as above – reuse of the central schema is correct.
3388-3392: Same remark as above – reuse of the central schema is correct.
3466-3472: Same remark as above – reuse of the central schema is correct.
3625-3631: Same remark as above – reuse of the central schema is correct.
🧹 Nitpick comments (3)
api/openapi.yaml (1)
22488-22499: Tighten external-key specification & add exampleThe union schema definition works, but the “external key” branch is very permissive and lacks an example.
Consider adding a simple pattern (alphanumerics +_ . -) so accidental whitespace or path-breaking characters are caught early.- type: string + pattern: '^[A-Za-z0-9._-]{1,256}$' minLength: 1 maxLength: 256 description: ExternalKey is a looser version of key. + example: merchant_123ABCThis leaves plenty of freedom while still preventing obvious mistakes.
api/openapi.cloud.yaml (1)
21562-21573: Add format & examples toULIDOrExternalKeyfor better tooling supportNice union schema. Two small, non-blocking tweaks could improve generated SDKs and docs:
- Declare a
formatfor the ULID branch (format: ulid); many generators surface it for validation.- Provide an example for the external-key branch (
example: ext-customer-42) so docs don’t only show the ULID variant.- Optional: give each branch a
titleto make swagger-ui labels clearer.- type: string pattern: ^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$ + format: ulid + title: ULID description: ULID (Universally Unique Lexicographically Sortable Identifier). example: 01G65Z755AFWAKHE12NY0CQ9FH - type: string minLength: 1 maxLength: 256 + title: ExternalKey description: ExternalKey is a looser version of key. + example: ext-customer-42These tweaks are optional but help downstream consumers.
api/client/javascript/src/zod/index.ts (1)
6770-6788: Refactor to eliminate code duplication across validation schemas.The validation logic is correct and follows the proper pattern for
ULIDOrExternalKeyunion types. However, the same regex pattern and max length constants are duplicated across all customer operations.Consider creating a reusable helper function or shared constants:
+// Shared constants for customer ID validation +export const CUSTOMER_ID_ULID_REGEX = new RegExp( + '^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$' +) +export const CUSTOMER_EXTERNAL_KEY_MAX_LENGTH = 256 + +// Helper function for customer ID validation +export const createCustomerIdValidation = () => + zod.coerce + .string() + .regex(CUSTOMER_ID_ULID_REGEX) + .describe('ULID (Universally Unique Lexicographically Sortable Identifier).') + .or( + zod.coerce + .string() + .min(1) + .max(CUSTOMER_EXTERNAL_KEY_MAX_LENGTH) + .describe('ExternalKey is a looser version of key.') + ) // Then use in each operation: -export const getCustomerPathCustomerIdOrKeyRegExpOne = new RegExp( - '^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$' -) -export const getCustomerPathCustomerIdOrKeyMaxTwo = 256 - export const getCustomerParams = zod.object({ - customerIdOrKey: zod.coerce - .string() - .regex(getCustomerPathCustomerIdOrKeyRegExpOne) - .describe( - 'ULID (Universally Unique Lexicographically Sortable Identifier).' - ) - .or( - zod.coerce - .string() - .min(1) - .max(getCustomerPathCustomerIdOrKeyMaxTwo) - .describe('ExternalKey is a looser version of key.') - ), + customerIdOrKey: createCustomerIdValidation(), })Also applies to: 6808-6826, 6944-6962, 6987-7005, 7034-7052, 7389-7411, 7450-7468
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
api/client/javascript/src/client/schemas.ts(9 hunks)api/client/javascript/src/zod/index.ts(8 hunks)api/openapi.cloud.yaml(8 hunks)api/openapi.yaml(8 hunks)api/spec/src/customer.tsp(7 hunks)api/spec/src/types.tsp(1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
api/spec/src/types.tsp (1)
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
api/openapi.yaml (1)
undefined
<retrieved_learning>
Learnt from: chrisgacsal
PR: #2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
</retrieved_learning>
api/openapi.cloud.yaml (1)
undefined
<retrieved_learning>
Learnt from: chrisgacsal
PR: #2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
</retrieved_learning>
api/client/javascript/src/client/schemas.ts (1)
undefined
<retrieved_learning>
Learnt from: chrisgacsal
PR: #2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
</retrieved_learning>
api/client/javascript/src/zod/index.ts (1)
undefined
<retrieved_learning>
Learnt from: chrisgacsal
PR: #2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
</retrieved_learning>
api/spec/src/customer.tsp (1)
Learnt from: chrisgacsal
PR: openmeterio/openmeter#2522
File: api/spec/src/productcatalog/routes.tsp:163-314
Timestamp: 2025-03-25T09:13:03.300Z
Learning: ULIDOrKey is defined in api/spec/src/types.tsp as a scalar type with a pattern that validates against both ULID and Key formats, not as a type alias like PlanIdOrKey.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Migration Checks
- GitHub Check: Lint
- GitHub Check: E2E
- GitHub Check: CI
- GitHub Check: Developer environment
- GitHub Check: Quickstart
- GitHub Check: Commit hooks
- GitHub Check: Build
- GitHub Check: Test
- GitHub Check: Analyze (go)
🔇 Additional comments (8)
api/spec/src/types.tsp (1)
42-51: LGTM! Well-structured union type for flexible customer identification.The new
ULIDOrExternalKeyunion type provides a cleaner and more flexible approach compared to the existingULIDOrKeyscalar type. This design allows for:
- Type-safe distinction between ULID and ExternalKey
- More permissive external key validation (256 chars vs 64 chars for Key)
- Better code generation with explicit union handling
The TypeSpec syntax, annotations, and documentation are all properly implemented.
api/openapi.yaml (1)
3041-3046: Consistent identifier type 👍Switching the
customerIdpath parameter to the new$ref: '#/components/schemas/ULIDOrExternalKey'nicely centralises validation logic and removes duplicated regexes.
Just make sure any remainingULIDOrKey/ inline-regex usages were swept as well; otherwise generators may emit multiple, incompatible types.api/client/javascript/src/client/schemas.ts (4)
9840-9841: LGTM: Well-documented schema definitionThe new
ULIDOrExternalKeyschema type is properly defined with clear documentation explaining its purpose as a union type for identifiers.
10872-10872: LGTM: Consistent type export namingThe type export follows TypeScript conventions with
UlidOrExternalKey(camelCase) for the exported type while maintaining consistency with the schema definition.
14895-14895: LGTM: Consistent application across customer operationsAll customer-related API operations (
getCustomer,updateCustomer,deleteCustomer,listCustomerAppData,upsertCustomerAppData,deleteCustomerAppData,getCustomerAccess,listCustomerSubscriptions) have been consistently updated to use the newULIDOrExternalKeyschema type for thecustomerIdOrKeypath parameter.Also applies to: 14989-14989, 15087-15087, 15284-15284, 15378-15378, 15476-15476, 15675-15675
9840-9841: Ignore Zod validation alignment suggestionThe JavaScript client doesn’t include any Zod‐based validators—
schemas.tsonly defines TypeScript types, and all OpenAPI YAML schemas forULIDOrExternalKeyhave been updated correctly. You can safely disregard the recommendation to align a non‐existent Zod layer here.Likely an incorrect or invalid review comment.
api/client/javascript/src/zod/index.ts (2)
6770-6771: ULID regex pattern is correct.The regex
^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$correctly validates ULIDs:
- 26 total characters (1 + 25)
- Uses Crockford's Base32 alphabet
- First character restricted to 0-7 for timestamp encoding
Also applies to: 6808-6809, 6944-6945, 6987-6988, 7034-7035, 7389-7390, 7450-7451
6784-6788: External key validation is appropriate.The validation allowing 1-256 characters for external keys provides good flexibility while preventing empty strings and overly long identifiers.
Also applies to: 6822-6826, 6958-6962, 7001-7005, 7048-7052, 7407-7411, 7464-7468
Summary by CodeRabbit
New Features
Refactor