@amos.com/node 0.1.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/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # Amos
2
+
3
+ A typed Node.js client for the **Amos Pay** API, generated from the public OpenAPI spec with [`openapi-typescript`](https://openapi-ts.dev/) and powered by [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch).
4
+
5
+ > **Docs:** the full Amos API reference lives at [docs.amos.com](https://docs.amos.com/). This package is the typed Node.js binding for that API.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install amos
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ import Amos from "amos";
17
+
18
+ const amos = new Amos(process.env.AMOS_API_KEY!);
19
+
20
+ const { data, error } = await amos.POST("/customers", {
21
+ body: { customer: { email: "alex@example.com" } },
22
+ });
23
+
24
+ if (error) {
25
+ console.error(error);
26
+ } else {
27
+ console.log(data);
28
+ }
29
+ ```
30
+
31
+ ### Sandbox mode
32
+
33
+ ```ts
34
+ const amos = new Amos(process.env.AMOS_API_KEY!, { sandbox: true });
35
+ ```
36
+
37
+ ### Custom base URL or fetch
38
+
39
+ ```ts
40
+ const amos = new Amos(process.env.AMOS_API_KEY!, {
41
+ baseUrl: "https://my-proxy.example.com",
42
+ fetch: customFetchImpl,
43
+ headers: { "X-Trace-Id": "abc123" },
44
+ });
45
+ ```
46
+
47
+ ### Middleware (e.g. fresh idempotency keys)
48
+
49
+ ```ts
50
+ import type { Middleware } from "amos";
51
+
52
+ const idempotencyKey: Middleware = {
53
+ async onRequest({ request }) {
54
+ if (request.method === "POST") {
55
+ request.headers.set("Idempotency-Key", crypto.randomUUID());
56
+ }
57
+ return request;
58
+ },
59
+ };
60
+
61
+ amos.use(idempotencyKey);
62
+ ```
63
+
64
+ ## API surface
65
+
66
+ `new Amos(apiKey, options?)` returns an instance that:
67
+
68
+ - Sends `X-Api-Key` and `X-Api-Version` on every request.
69
+ - Exposes the full [`openapi-fetch`](https://openapi-ts.dev/openapi-fetch) interface directly: `GET`, `POST`, `PUT`, `DELETE`, `OPTIONS`, `HEAD`, `PATCH`, `TRACE`, `use`, `eject`.
70
+ - Also exposes the underlying client as `amos.client` for advanced use.
71
+
72
+ ### Constructor options
73
+
74
+ | Option | Type | Default | Description |
75
+ | --------------- | ------------------------ | ------------------------ | -------------------------------------------------------------------- |
76
+ | `apiVersion` | `string` | `"1"` | Sent as the `X-Api-Version` header. |
77
+ | `sandbox` | `boolean` | `false` | If `true`, uses the sandbox base URL. Ignored when `baseUrl` is set. |
78
+ | `baseUrl` | `string` | production / sandbox URL | Override the base URL entirely. |
79
+ | `headers` | `Record<string, string>` | `{}` | Additional default headers merged into every request. |
80
+ | `fetch` | `typeof fetch` | global `fetch` | Custom `fetch` implementation. |
81
+ | `clientOptions` | `Partial<ClientOptions>` | `{}` | Escape hatch for any other `openapi-fetch` client options. |
82
+
83
+ ## Types
84
+
85
+ All schema types are re-exported from the main entry. For example:
86
+
87
+ ```ts
88
+ import type { components, paths, operations } from "amos";
89
+
90
+ type Customer = components["schemas"]["Customer"];
91
+ ```
92
+
93
+ ## Versioning
94
+
95
+ We follow **SemVer** for the npm package, with one extra rule: **the major version tracks the wire-level `X-Api-Version` header**.
96
+
97
+ | npm range | `X-Api-Version` it targets |
98
+ | ---------- | -------------------------- |
99
+ | `amos@1.x` | `1` |
100
+ | `amos@2.x` | `2` (hypothetical) |
101
+
102
+ So bumping `DEFAULT_API_VERSION` in `src/index.ts` is always a major release, and consumers who pin to `amos@^1` know they will never be transparently upgraded onto a new wire contract.
103
+
104
+ > **Pre-1.0 caveat.** While we're on `0.x`, **breaking changes can land in any `0.x` release.** Strict SemVer (and the API-version-tracks-major rule above) starts the day we cut `1.0.0`. Pin to an exact `0.x.y` if you need stability today.
105
+
106
+ ### How spec changes map to bumps
107
+
108
+ The package is essentially "OpenAPI-derived types + a thin runtime wrapper", so we classify changes by their TypeScript-visible impact:
109
+
110
+ | Change in the spec or runtime | Bump |
111
+ | ------------------------------------------------------------------------------------------------------------ | ----- |
112
+ | Removing/renaming a path, operation, schema, or response enum value | major |
113
+ | Narrowing a type, making a request field required, changing a parameter from optional to required | major |
114
+ | Changing the `Amos` constructor surface in a breaking way, or bumping `DEFAULT_API_VERSION` | major |
115
+ | Adding endpoints, schemas, optional request fields, request enum values, or new runtime exports | minor |
116
+ | Spec descriptions/examples/tags only, internal refactors with no public type change, dependency-only updates | patch |
117
+
118
+ The mental rule: _"would a program that typechecked against the previous `dist/index.d.ts` still typecheck against the new one?"_ If no, it's a major.
119
+
120
+ ### Spec source of truth, not `info.version`
121
+
122
+ The npm version in `package.json` is **decoupled** from the `info.version` field of the upstream OpenAPI spec. They drift independently on purpose: a docs-only spec edit shouldn't ship an SDK release, and an SDK-only fix shouldn't wait for a spec change.
123
+
124
+ What we _do_ track per release is the upstream commit SHA, in two places:
125
+
126
+ - [`openapi/source.json`](./openapi/source.json) — the spec commit this package was last released against.
127
+ - `CHANGELOG.md` — every release entry references the upstream `amos/openapi` commit(s) that produced it (auto-populated by the regeneration workflow, see below).
128
+
129
+ ## Release process
130
+
131
+ Releases are managed with [Changesets](https://github.com/changesets/changesets). The flow has two paths.
132
+
133
+ ### Path A: regenerated from the OpenAPI spec (the common case)
134
+
135
+ 1. The [`Regenerate from OpenAPI`](./.github/workflows/regenerate.yml) workflow runs on `workflow_dispatch`, or when the OpenAPI source repo fires a `repository_dispatch` event of type `public-openapi-spec-updated` (dispatched by the upstream sync workflow whenever the public spec changes on its `main`).
136
+ 2. It checks out the spec repo at the dispatched commit, diffs that spec against the SHA recorded in [`openapi/source.json`](./openapi/source.json) using [`oasdiff`](https://github.com/oasdiff/oasdiff), and classifies the change as `major` / `minor` / `patch`.
137
+ 3. If anything changed, it regenerates `openapi/schema.ts` (via `npm run build`), updates `openapi/source.json`, writes a `.changeset/regen-<sha>.md` file with the recommended bump and the upstream commit log, and opens a PR.
138
+ 4. A maintainer reviews the PR — **adjust the bump in the changeset file if `oasdiff` misclassified anything** (e.g., a response-only enum addition that breaks exhaustive switches in your consumers should be promoted to `major`) — and merges.
139
+ 5. The [`Release`](./.github/workflows/release.yml) workflow then opens or updates a "Version Packages" PR. Merging that PR publishes to npm and tags the commit.
140
+
141
+ ### Path B: hand-authored change (runtime fix, refactor, dep bump)
142
+
143
+ 1. Make your change on a branch.
144
+ 2. Run `npx changeset` and answer the prompts to describe the bump.
145
+ 3. Open a PR. Reviewers will see the changeset file alongside the diff.
146
+ 4. Merging triggers the same `Release` workflow as above.
147
+
148
+ ### Required CI secrets
149
+
150
+ | Secret | Used by | Purpose |
151
+ | -------------------- | ---------------- | ----------------------------------------------------------------------------- |
152
+ | `NPM_TOKEN` | `release.yml` | Publishing to npm. Use an automation token from the `amos` org/account. |
153
+ | `OPENAPI_REPO_TOKEN` | `regenerate.yml` | Fine-grained PAT with `Contents: Read` on `amos/openapi`. Spec is private. |
154
+
155
+ The default `GITHUB_TOKEN` handles everything else. Make sure **Settings -> Actions -> General -> Workflow permissions -> "Allow GitHub Actions to create and approve pull requests"** is enabled so the regenerate workflow can open PRs.
156
+
157
+ ## Regenerating locally
158
+
159
+ If you want to preview a regeneration without going through CI:
160
+
161
+ ```bash
162
+ npm run generate
163
+ ```
164
+
165
+ This pulls the sibling `../openapi` checkout and rewrites `openapi/schema.ts`. It does **not** touch `openapi/source.json` or write a changeset — only the workflow does that, so the recorded SHA always matches a released version.
166
+
167
+ ## Development
168
+
169
+ ```bash
170
+ npm install
171
+ npm run build
172
+ ```
173
+
174
+ Add a changeset alongside any user-visible change:
175
+
176
+ ```bash
177
+ npx changeset
178
+ ```