Repository navigation
feat(sdk): send an Idempotency-Key with a project create - #9
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The dms-antelope-cloud first-run setup (ANT-1906) has to retry a project create whose answer was lost and get its own project back, instead of guessing ownership from slug, region and repository. The cloud now accepts an
Idempotency-KeyonPOST /api/cloud/projects(ANT-1993). This PR exposes it in the spec and the SDK. Task: ANT-2016.What changes
sdk/openapi/projects.yaml(new) holds the/api/cloud/projects/path item, moved out ofcloud.openapi.yaml, which would otherwise pass its 20,000-byte test ceiling.listProjectsis unchanged.createProjectdeclares an optionalIdempotency-Keyheader: a string of 1 to 255 visible ASCII characters (0x21-0x7E).cloud.errors.projects.invalid_idempotency_key; 409cloud.errors.projects.slug_takenandcloud.errors.projects.creation_in_progress; 422cloud.errors.projects.idempotency_key_reused.src/projects/create.tsat4dab2553):slug,region,repositoryandbranchprojectId, currentslug,region, and the originalenvironmentIdandserviceId. No new project, no GitHub call, no room needed under the plan's ceiling.idempotency_key_reusedslug_takencreation_in_progress: retry with the same keyinvalid_idempotency_keyA key belongs to its workspace and to the member who sent it.
CloudApi.createProject(body, { idempotencyKey })sends the key as the header. Without one, no header is sent. The one-argument call keeps working.ajs cloudCLI sends no key. ItsensureProjectnever re-sends a create; it only retriesslug_takenwith another slug, so a key would never be reused.Merge after AntelopeJS/cloud#637 (ANT-1993). The spec matches its route (
src/routes/projects.ts) and creation flow (src/projects/create.ts) at4dab2553: header name and pattern, every error code, the replay body, member scoping, and the digest fields.Proof
sdk/test/api.test.ts: "a create sends its idempotency key as the Idempotency-Key header, and no header without one". It fails on a wrong header name, on a literal"undefined"header when no key is given, and on a body dropped whenparamsis added.Before (
pnpm --dir sdk testonorigin/mainwith the new test):After:
pnpm run checks:Checks: 11 passed, 0 failed.pnpm run check:generated: no diff.sequenceDiagram participant C as Client (DMS setup) participant S as CloudApi.createProject participant A as POST /api/cloud/projects C->>S: body, { idempotencyKey: k } S->>A: Idempotency-Key: k A-->>S: 200 CreatedProject Note over C,A: answer lost, client retries C->>S: same body, { idempotencyKey: k } S->>A: Idempotency-Key: k A-->>S: 200 same project, no new one C->>S: other body, { idempotencyKey: k } S->>A: Idempotency-Key: k A-->>S: 422 idempotency_key_reused C->>S: same body, { idempotencyKey: k } while first create runs S->>A: Idempotency-Key: k A-->>S: 409 creation_in_progress, retry with k