@farthershore/farthershore-js 0.1.0 → 0.1.1
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/CHANGELOG.md +23 -0
- package/README.md +95 -5
- package/dist/client.d.ts +51 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +48 -0
- package/dist/client.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -2
- package/dist/config.js.map +1 -1
- package/dist/errors.d.ts +31 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +37 -2
- package/dist/errors.js.map +1 -1
- package/dist/http.d.ts +3 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +12 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/react/hooks.d.ts.map +1 -1
- package/dist/react/hooks.js +5 -5
- package/dist/react/hooks.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +3 -3
- package/dist/react/provider.js.map +1 -1
- package/dist/react/use-async.d.ts +4 -2
- package/dist/react/use-async.d.ts.map +1 -1
- package/dist/react/use-async.js +11 -2
- package/dist/react/use-async.js.map +1 -1
- package/dist/resources/auth.d.ts +4 -1
- package/dist/resources/auth.d.ts.map +1 -1
- package/dist/resources/auth.js +2 -1
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/billing.d.ts +6 -2
- package/dist/resources/billing.d.ts.map +1 -1
- package/dist/resources/billing.js +4 -2
- package/dist/resources/billing.js.map +1 -1
- package/dist/resources/keys.d.ts +5 -1
- package/dist/resources/keys.d.ts.map +1 -1
- package/dist/resources/keys.js +2 -1
- package/dist/resources/keys.js.map +1 -1
- package/dist/resources/usage.d.ts +9 -3
- package/dist/resources/usage.d.ts.map +1 -1
- package/dist/resources/usage.js +8 -7
- package/dist/resources/usage.js.map +1 -1
- package/package.json +7 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@farthershore/farthershore-js` are documented here.
|
|
4
|
+
This project adheres to Semantic Versioning (pre-1.0: minors may break).
|
|
5
|
+
|
|
6
|
+
## [Unreleased]
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2026-06-09
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `createServerClient()` — a documented SSR/server entry point (explicit `portalHost` + injectable `fetch` + per-request `getToken`; no `window`/`location` assumption).
|
|
13
|
+
- Request cancellation: the read methods (`auth.getSession`, `keys.list`, `usage.*`, `billing.subscription`/`creditBalance`) accept `{ signal }`, and the React hooks abort the in-flight request on unmount / dep-change.
|
|
14
|
+
- `FartherShoreAbortError` — mapped from a fetch `AbortError`; ignored by the hooks (a cancelled read is never a user-facing error).
|
|
15
|
+
- `FartherShoreConfigError` for construction/misconfiguration; an ESLint guard on `src/**` ensures every failure stays a typed `FartherShore*` error.
|
|
16
|
+
- Contract **drift-detection** test that guards the SDK's mapped shapes against `@farthershore/contracts` (compile-time + runtime), plus exhaustive unit coverage (35 → 65 tests) and a tree-shaking verification test.
|
|
17
|
+
- Docs: Getting Started, Versioning & stability sections, and this CHANGELOG.
|
|
18
|
+
|
|
19
|
+
## [0.1.0] - 2026-06-08
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- Initial public release: a framework-agnostic client + `/react` hooks + `catalog.ts` display helpers; the `auth` (Clerk `setToken` + persona `signIn`), `keys`, `usage`, `billing`, `plans`, `product`, and Gateway `feature()` resources. ESM, tree-shakeable (`sideEffects: false`), with the domain types re-exported from the `/react` subpath.
|
package/README.md
CHANGED
|
@@ -4,11 +4,16 @@ The **Farther Shore Frontend SDK** — the canonical browser integration layer
|
|
|
4
4
|
between a static frontend artifact (the default dev-portal template, generated
|
|
5
5
|
frontends, managed components, custom frontends) and the Farther Shore platform.
|
|
6
6
|
|
|
7
|
-
> **
|
|
8
|
-
>
|
|
9
|
-
> managed
|
|
10
|
-
>
|
|
11
|
-
>
|
|
7
|
+
> **Status: `0.1.0` (early release).** Published to npm. Pre-1.0, so minor
|
|
8
|
+
> versions may include breaking changes while the API stabilizes against the dev
|
|
9
|
+
> portal, managed template, and real builder features. See [`PUBLISHING.md`](./PUBLISHING.md)
|
|
10
|
+
> for the gates to `1.0.0` (wire-contract lock, browser token exchange, gateway
|
|
11
|
+
> CORS, stage e2e). The `@stripe/stripe-js` analog to the server-side
|
|
12
|
+
> `@farthershore/sdk`.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @farthershore/farthershore-js # React is an optional peer (for /react)
|
|
16
|
+
```
|
|
12
17
|
|
|
13
18
|
## Philosophy
|
|
14
19
|
|
|
@@ -31,6 +36,45 @@ The SDK decides **where** each request goes (Core for platform concerns, the
|
|
|
31
36
|
Gateway for builder features), **how** it's authenticated, and the host/env
|
|
32
37
|
scoping headers Core needs.
|
|
33
38
|
|
|
39
|
+
## Getting started
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pnpm add @farthershore/farthershore-js
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { createFartherShoreClient } from "@farthershore/farthershore-js";
|
|
47
|
+
|
|
48
|
+
// 1. Create the client. In the browser, `coreUrl` is usually the only required
|
|
49
|
+
// field — `portalHost` defaults to `window.location.host`.
|
|
50
|
+
const fs = createFartherShoreClient({
|
|
51
|
+
coreUrl: "https://core.farthershore.com",
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 2. Discover the product/env/plans for this host (memoized; safe to re-call).
|
|
55
|
+
const { product, plans } = await fs.bootstrap();
|
|
56
|
+
|
|
57
|
+
// 3. Authenticate. In a preview/test env, exchange a persona access key for a
|
|
58
|
+
// session (Clerk envs instead pass `getToken` to the config / `setToken`).
|
|
59
|
+
await fs.auth.signIn({ apiKey: "fsk_test_…" });
|
|
60
|
+
|
|
61
|
+
// 4. Read platform state through the typed resources (→ Core).
|
|
62
|
+
const keys = await fs.keys.list(); // ApiKey[]
|
|
63
|
+
const usage = await fs.usage.snapshot(); // { summary, events, billingBasis }
|
|
64
|
+
|
|
65
|
+
// 5. Call a builder-defined feature (→ Gateway). Set the consumer API key once,
|
|
66
|
+
// then express intent by feature name + path — no Gateway URL in app code.
|
|
67
|
+
fs.setApiKey("fsk_live_…");
|
|
68
|
+
const forecast = await fs.feature("weather").json("/forecast?city=NYC");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
In React, the same calls are hooks that return `{ data, loading, error, refresh }`
|
|
72
|
+
(plus mutations) — see [React](#react-farthershorefarthershore-jsreact) below:
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
const { data, loading, error, refresh } = useApiKeys();
|
|
76
|
+
```
|
|
77
|
+
|
|
34
78
|
## Surface
|
|
35
79
|
|
|
36
80
|
| Namespace | Routes to | Methods |
|
|
@@ -41,6 +85,7 @@ scoping headers Core needs.
|
|
|
41
85
|
| `fs.keys` | Core | `list()`, `create()`, `revoke()`, `rotate()` |
|
|
42
86
|
| `fs.usage` | Core | `summary()`, `events()`, `snapshot()` |
|
|
43
87
|
| `fs.billing` | Core | `subscription()`, `openBillingPortal()`, `creditBalance()` |
|
|
88
|
+
| `fs.plans` | Core / (bootstrap) | `list()`, `subscribe()` |
|
|
44
89
|
| `fs.feature(name)` / `fs.invoke(path)` | **Gateway** | `fetch(path)`, `json(path)` |
|
|
45
90
|
|
|
46
91
|
## Auth
|
|
@@ -71,6 +116,29 @@ createFartherShoreClient({
|
|
|
71
116
|
});
|
|
72
117
|
```
|
|
73
118
|
|
|
119
|
+
## SSR / server usage
|
|
120
|
+
|
|
121
|
+
On a server there is no `window`/`location` to infer the portal host from and no
|
|
122
|
+
ambient browser session — so use `createServerClient`, a documented alias for
|
|
123
|
+
`createFartherShoreClient` that makes that contract explicit. Pass `portalHost`
|
|
124
|
+
and `fetch` instead of relying on globals, and resolve the per-request session
|
|
125
|
+
via `getToken` (each request authenticates as a different user). Behaviour is
|
|
126
|
+
identical to the browser client — the config already guards `globalThis.location`
|
|
127
|
+
and requires an injectable `fetch` — so this is purely a discoverable entry point.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { createServerClient } from "@farthershore/farthershore-js";
|
|
131
|
+
|
|
132
|
+
const fs = createServerClient({
|
|
133
|
+
coreUrl: process.env.FS_CORE_URL!,
|
|
134
|
+
portalHost: "weather.farthershore.com", // no window.location on the server
|
|
135
|
+
getToken: () => sessionTokenForThisRequest, // per-request bearer
|
|
136
|
+
fetch, // Node 18+ global, or an injected impl
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const sub = await fs.billing.subscription();
|
|
140
|
+
```
|
|
141
|
+
|
|
74
142
|
## React (`@farthershore/farthershore-js/react`)
|
|
75
143
|
|
|
76
144
|
The hooks live in a **subpath** of the same package — `react` is an _optional_
|
|
@@ -117,6 +185,28 @@ client. They're thin wrappers over the client — no duplicated logic.
|
|
|
117
185
|
- A browser-safe **short-lived gateway token** (vs. a long-lived `fsk_` key in the
|
|
118
186
|
page) — the platform's `fsc_` context token is server-minted today.
|
|
119
187
|
|
|
188
|
+
## Versioning & stability
|
|
189
|
+
|
|
190
|
+
This package is **pre-1.0 (`0.x`)**. Under SemVer's 0.x rules a **minor** bump
|
|
191
|
+
(`0.1.x` → `0.2.0`) may include **breaking changes**, so the usual caret range is
|
|
192
|
+
unsafe here:
|
|
193
|
+
|
|
194
|
+
- ❌ `^0.1` / `^0.1.0` — caret does **not** lock the minor across `0.x`; it would
|
|
195
|
+
silently accept a breaking `0.2.0`.
|
|
196
|
+
- ✅ Pin **exact** (`0.1.0`) or use a patch-only tilde (`~0.1.0`) until `1.0.0`.
|
|
197
|
+
|
|
198
|
+
Breaking changes within `0.x` are recorded in [`CHANGELOG.md`](./CHANGELOG.md)
|
|
199
|
+
(Keep a Changelog format) — read it before bumping.
|
|
200
|
+
|
|
201
|
+
**Path to `1.0.0`:** the API graduates to a stable major once the
|
|
202
|
+
[`PUBLISHING.md`](./PUBLISHING.md) gates clear — wire-contract lock (generated
|
|
203
|
+
from / pinned to `@farthershore/contracts`), the browser-safe gateway token
|
|
204
|
+
exchange, gateway CORS for product origins, and a live-stage e2e. At `1.0.0`,
|
|
205
|
+
caret ranges become safe again.
|
|
206
|
+
|
|
207
|
+
The `/react` subpath ships in the same package and version; **`react` is an
|
|
208
|
+
_optional_ peer dependency**, so non-React consumers never pull it in.
|
|
209
|
+
|
|
120
210
|
## Scripts
|
|
121
211
|
|
|
122
212
|
```bash
|
package/dist/client.d.ts
CHANGED
|
@@ -16,10 +16,15 @@ export interface FartherShoreClient {
|
|
|
16
16
|
setApiKey(key: string | null): void;
|
|
17
17
|
/** Set the Core session bearer directly (e.g. from the Clerk browser SDK). */
|
|
18
18
|
setSessionToken(token: string | null): void;
|
|
19
|
+
/** The product this frontend runs for (resolved via bootstrap). */
|
|
19
20
|
readonly product: ProductResource;
|
|
21
|
+
/** Consumer session: persona/Clerk sign-in, the current session, sign-out. */
|
|
20
22
|
readonly auth: AuthResource;
|
|
23
|
+
/** The consumer's API keys (list / create / revoke / rotate). */
|
|
21
24
|
readonly keys: KeysResource;
|
|
25
|
+
/** Per-dimension usage totals + recent events for this product. */
|
|
22
26
|
readonly usage: UsageResource;
|
|
27
|
+
/** The consumer's subscription, the Stripe billing portal, and credit balance. */
|
|
23
28
|
readonly billing: BillingResource;
|
|
24
29
|
/** The product's plan catalog + the subscribe/checkout flow. */
|
|
25
30
|
readonly plans: PlansResource;
|
|
@@ -38,5 +43,51 @@ export interface FartherShoreClient {
|
|
|
38
43
|
*/
|
|
39
44
|
core<T>(req: CoreRequest): Promise<T>;
|
|
40
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* SSR / server-side entry point. A thin, documented alias for
|
|
48
|
+
* {@link createFartherShoreClient} that makes the server contract explicit:
|
|
49
|
+
* there is **no `window`/`location`** to fall back on, so a server caller must
|
|
50
|
+
* supply what the browser would otherwise provide implicitly —
|
|
51
|
+
*
|
|
52
|
+
* - `portalHost` — the product/env host (no `globalThis.location.host` default
|
|
53
|
+
* exists on the server);
|
|
54
|
+
* - `fetch` — an injectable fetch (the platform doesn't assume a global one);
|
|
55
|
+
* - `getToken` — the per-request session bearer (each request authenticates as a
|
|
56
|
+
* different user, so resolve the token per call rather than via the browser's
|
|
57
|
+
* ambient session).
|
|
58
|
+
*
|
|
59
|
+
* Behaviour is identical to {@link createFartherShoreClient} — `buildContext`
|
|
60
|
+
* already guards `globalThis.location` and requires an injectable `fetch` — so
|
|
61
|
+
* this adds no runtime behaviour; it's a discoverable, self-documenting entry
|
|
62
|
+
* point for SSR/server usage.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const fs = createServerClient({
|
|
67
|
+
* coreUrl: process.env.FS_CORE_URL!,
|
|
68
|
+
* portalHost: "weather.farthershore.com",
|
|
69
|
+
* getToken: () => sessionTokenForThisRequest,
|
|
70
|
+
* fetch, // Node 18+ global, or an injected impl
|
|
71
|
+
* });
|
|
72
|
+
* const sub = await fs.billing.subscription();
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function createServerClient(config: FartherShoreConfig): FartherShoreClient;
|
|
76
|
+
/**
|
|
77
|
+
* Create a {@link FartherShoreClient}. In the browser the minimal config is
|
|
78
|
+
* `{ coreUrl }` — the platform Core base URL; `portalHost` defaults to
|
|
79
|
+
* `window.location.host` and the product is discovered at {@link
|
|
80
|
+
* FartherShoreClient.bootstrap}. The returned client owns all routing (Core vs
|
|
81
|
+
* Gateway), auth, and host/env scoping; app code only expresses intent via its
|
|
82
|
+
* typed resources (`fs.usage`, `fs.keys`, `fs.feature(…)`, …). For SSR/server
|
|
83
|
+
* use, prefer {@link createServerClient}.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* const fs = createFartherShoreClient({ coreUrl: "https://core.farthershore.com" });
|
|
88
|
+
* const { product } = await fs.bootstrap();
|
|
89
|
+
* const keys = await fs.keys.list();
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
41
92
|
export declare function createFartherShoreClient(config: FartherShoreConfig): FartherShoreClient;
|
|
42
93
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,aAAa,CAAC;AAErB,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC;yCACqC;IACrC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,+DAA+D;IAC/D,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IACpC,8EAA8E;IAC9E,eAAe,C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B,GACzB,kBAAkB,CAwCpB"}
|
package/dist/client.js
CHANGED
|
@@ -12,6 +12,54 @@ import { createUsageResource } from "./resources/usage.js";
|
|
|
12
12
|
import { createBillingResource, } from "./resources/billing.js";
|
|
13
13
|
import { createPlansResource } from "./resources/plans.js";
|
|
14
14
|
import { createFeature, } from "./resources/feature.js";
|
|
15
|
+
/**
|
|
16
|
+
* SSR / server-side entry point. A thin, documented alias for
|
|
17
|
+
* {@link createFartherShoreClient} that makes the server contract explicit:
|
|
18
|
+
* there is **no `window`/`location`** to fall back on, so a server caller must
|
|
19
|
+
* supply what the browser would otherwise provide implicitly —
|
|
20
|
+
*
|
|
21
|
+
* - `portalHost` — the product/env host (no `globalThis.location.host` default
|
|
22
|
+
* exists on the server);
|
|
23
|
+
* - `fetch` — an injectable fetch (the platform doesn't assume a global one);
|
|
24
|
+
* - `getToken` — the per-request session bearer (each request authenticates as a
|
|
25
|
+
* different user, so resolve the token per call rather than via the browser's
|
|
26
|
+
* ambient session).
|
|
27
|
+
*
|
|
28
|
+
* Behaviour is identical to {@link createFartherShoreClient} — `buildContext`
|
|
29
|
+
* already guards `globalThis.location` and requires an injectable `fetch` — so
|
|
30
|
+
* this adds no runtime behaviour; it's a discoverable, self-documenting entry
|
|
31
|
+
* point for SSR/server usage.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const fs = createServerClient({
|
|
36
|
+
* coreUrl: process.env.FS_CORE_URL!,
|
|
37
|
+
* portalHost: "weather.farthershore.com",
|
|
38
|
+
* getToken: () => sessionTokenForThisRequest,
|
|
39
|
+
* fetch, // Node 18+ global, or an injected impl
|
|
40
|
+
* });
|
|
41
|
+
* const sub = await fs.billing.subscription();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function createServerClient(config) {
|
|
45
|
+
return createFartherShoreClient(config);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a {@link FartherShoreClient}. In the browser the minimal config is
|
|
49
|
+
* `{ coreUrl }` — the platform Core base URL; `portalHost` defaults to
|
|
50
|
+
* `window.location.host` and the product is discovered at {@link
|
|
51
|
+
* FartherShoreClient.bootstrap}. The returned client owns all routing (Core vs
|
|
52
|
+
* Gateway), auth, and host/env scoping; app code only expresses intent via its
|
|
53
|
+
* typed resources (`fs.usage`, `fs.keys`, `fs.feature(…)`, …). For SSR/server
|
|
54
|
+
* use, prefer {@link createServerClient}.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* const fs = createFartherShoreClient({ coreUrl: "https://core.farthershore.com" });
|
|
59
|
+
* const { product } = await fs.bootstrap();
|
|
60
|
+
* const keys = await fs.keys.list();
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
15
63
|
export function createFartherShoreClient(config) {
|
|
16
64
|
const ctx = buildContext(config);
|
|
17
65
|
let cached = null;
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,sCAAsC;AAEtC,OAAO,EAGL,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAoB,MAAM,WAAW,CAAC;AACtE,OAAO,EACL,qBAAqB,GAEtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAqB,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAsB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EACL,qBAAqB,GAEtB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAsB,MAAM,sBAAsB,CAAC;AAC/E,OA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AAM,EAAE,kBAAkB,GAAG,aAAa,CAkCtE;AAED;4DAC4D;AAC5D,wBAAsB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAO7E"}
|
package/dist/config.js
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
// endpoints, or routing rules. It configures the client ONCE (usually just a
|
|
5
5
|
// coreUrl) and expresses intent (`fs.usage.summary()`); the SDK owns where the
|
|
6
6
|
// request goes and how it's authenticated.
|
|
7
|
+
import { FartherShoreConfigError } from "./errors.js";
|
|
7
8
|
function trimTrailingSlash(u) {
|
|
8
9
|
return u.replace(/\/+$/, "");
|
|
9
10
|
}
|
|
10
11
|
export function buildContext(config) {
|
|
11
12
|
if (!config.coreUrl) {
|
|
12
|
-
throw new
|
|
13
|
+
throw new FartherShoreConfigError("createFartherShoreClient: `coreUrl` is required");
|
|
13
14
|
}
|
|
14
15
|
const portalHost = config.portalHost ??
|
|
15
16
|
(typeof globalThis !== "undefined" &&
|
|
@@ -19,7 +20,7 @@ export function buildContext(config) {
|
|
|
19
20
|
const fetchImpl = config.fetch ??
|
|
20
21
|
(typeof fetch !== "undefined" ? fetch.bind(globalThis) : undefined);
|
|
21
22
|
if (!fetchImpl) {
|
|
22
|
-
throw new
|
|
23
|
+
throw new FartherShoreConfigError("createFartherShoreClient: no global fetch; pass `fetch` in the config");
|
|
23
24
|
}
|
|
24
25
|
return {
|
|
25
26
|
coreUrl: trimTrailingSlash(config.coreUrl),
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAAE;AACF,+EAA+E;AAC/E,6EAA6E;AAC7E,+EAA+E;AAC/E,2CAA2C;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,EAA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AAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;QAC3E,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,IAAI;QAC7B,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,KAAK,EAAE,SAAS;KACjB,CAAC;AACJ,CAAC;AAED;4DAC4D;AAC5D,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAkB;IACnD,IAAI,GAAG,CAAC,YAAY;QAAE,OAAO,GAAG,CAAC,YAAY,CAAC;IAC9C,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjB,MAAM,CAAC,GAAG,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,IAAI,IAAI,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
export declare class FartherShoreError extends Error {
|
|
2
2
|
constructor(message: string);
|
|
3
3
|
}
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
4
|
+
/**
|
|
5
|
+
* A non-2xx response from Core or the Gateway. Exposes:
|
|
6
|
+
* - `.status` — the HTTP status code;
|
|
7
|
+
* - `.code` — the platform error code from the `{ error: { code, message } }`
|
|
8
|
+
* envelope (or a fallback when the envelope is absent);
|
|
9
|
+
* - `.body` — the parsed response body, for richer error detail.
|
|
10
|
+
*
|
|
11
|
+
* Callers commonly branch on `.status` — e.g. `401`/`403` (re-auth), `404`
|
|
12
|
+
* (treat as absent), `409` (conflict/retry) — rather than parsing the message.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* try {
|
|
17
|
+
* await fs.keys.list();
|
|
18
|
+
* } catch (err) {
|
|
19
|
+
* if (err instanceof FartherShoreApiError && err.status === 401) {
|
|
20
|
+
* // session expired — prompt re-auth
|
|
21
|
+
* } else throw err;
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
6
25
|
export declare class FartherShoreApiError extends FartherShoreError {
|
|
7
26
|
readonly status: number;
|
|
8
27
|
readonly code: string;
|
|
@@ -14,9 +33,19 @@ export declare class FartherShoreNetworkError extends FartherShoreError {
|
|
|
14
33
|
readonly cause?: unknown;
|
|
15
34
|
constructor(message: string, cause?: unknown);
|
|
16
35
|
}
|
|
36
|
+
/** Thrown when a request was aborted (e.g. a React hook unmounted or its deps
|
|
37
|
+
* changed before the request resolved). Callers/hooks should ignore it. */
|
|
38
|
+
export declare class FartherShoreAbortError extends FartherShoreError {
|
|
39
|
+
constructor(message?: string);
|
|
40
|
+
}
|
|
17
41
|
/** Thrown when the client is used before `bootstrap()` has resolved the product
|
|
18
42
|
* it needs (e.g. a per-product call with no configured productId). */
|
|
19
43
|
export declare class FartherShoreNotReadyError extends FartherShoreError {
|
|
20
44
|
constructor(message: string);
|
|
21
45
|
}
|
|
46
|
+
/** Thrown at client construction for invalid/missing config (e.g. no `coreUrl`,
|
|
47
|
+
* no global `fetch`). */
|
|
48
|
+
export declare class FartherShoreConfigError extends FartherShoreError {
|
|
49
|
+
constructor(message: string);
|
|
50
|
+
}
|
|
22
51
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,oBAAqB,SAAQ,iBAAiB;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBACX,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;CAOzE;AAED,8DAA8D;AAC9D,qBAAa,wBAAyB,SAAQ,iBAAiB;IAC7D,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBACb,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C;AAED;4EAC4E;AAC5E,qBAAa,sBAAuB,SAAQ,iBAAiB;gBAC/C,OAAO,SAAoB;CAIxC;AAED;uEACuE;AACvE,qBAAa,yBAA0B,SAAQ,iBAAiB;gBAClD,OAAO,EAAE,MAAM;CAI5B;AAED;0BAC0B;AAC1B,qBAAa,uBAAwB,SAAQ,iBAAiB;gBAChD,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.js
CHANGED
|
@@ -5,8 +5,27 @@ export class FartherShoreError extends Error {
|
|
|
5
5
|
this.name = "FartherShoreError";
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
8
|
+
/**
|
|
9
|
+
* A non-2xx response from Core or the Gateway. Exposes:
|
|
10
|
+
* - `.status` — the HTTP status code;
|
|
11
|
+
* - `.code` — the platform error code from the `{ error: { code, message } }`
|
|
12
|
+
* envelope (or a fallback when the envelope is absent);
|
|
13
|
+
* - `.body` — the parsed response body, for richer error detail.
|
|
14
|
+
*
|
|
15
|
+
* Callers commonly branch on `.status` — e.g. `401`/`403` (re-auth), `404`
|
|
16
|
+
* (treat as absent), `409` (conflict/retry) — rather than parsing the message.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* try {
|
|
21
|
+
* await fs.keys.list();
|
|
22
|
+
* } catch (err) {
|
|
23
|
+
* if (err instanceof FartherShoreApiError && err.status === 401) {
|
|
24
|
+
* // session expired — prompt re-auth
|
|
25
|
+
* } else throw err;
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
10
29
|
export class FartherShoreApiError extends FartherShoreError {
|
|
11
30
|
status;
|
|
12
31
|
code;
|
|
@@ -28,6 +47,14 @@ export class FartherShoreNetworkError extends FartherShoreError {
|
|
|
28
47
|
this.cause = cause;
|
|
29
48
|
}
|
|
30
49
|
}
|
|
50
|
+
/** Thrown when a request was aborted (e.g. a React hook unmounted or its deps
|
|
51
|
+
* changed before the request resolved). Callers/hooks should ignore it. */
|
|
52
|
+
export class FartherShoreAbortError extends FartherShoreError {
|
|
53
|
+
constructor(message = "Request aborted") {
|
|
54
|
+
super(message);
|
|
55
|
+
this.name = "FartherShoreAbortError";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
31
58
|
/** Thrown when the client is used before `bootstrap()` has resolved the product
|
|
32
59
|
* it needs (e.g. a per-product call with no configured productId). */
|
|
33
60
|
export class FartherShoreNotReadyError extends FartherShoreError {
|
|
@@ -36,4 +63,12 @@ export class FartherShoreNotReadyError extends FartherShoreError {
|
|
|
36
63
|
this.name = "FartherShoreNotReadyError";
|
|
37
64
|
}
|
|
38
65
|
}
|
|
66
|
+
/** Thrown at client construction for invalid/missing config (e.g. no `coreUrl`,
|
|
67
|
+
* no global `fetch`). */
|
|
68
|
+
export class FartherShoreConfigError extends FartherShoreError {
|
|
69
|
+
constructor(message) {
|
|
70
|
+
super(message);
|
|
71
|
+
this.name = "FartherShoreConfigError";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
39
74
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uEAAuE;AAEvE,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC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AK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAED;0BAC0B;AAC1B,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAC5D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF"}
|
package/dist/http.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export interface CoreRequest {
|
|
|
7
7
|
/** "session" attaches the consumer session bearer; "none" is for public
|
|
8
8
|
* endpoints (resolve/discover). Defaults to "session". */
|
|
9
9
|
auth?: "session" | "none";
|
|
10
|
+
/** Abort signal — when it fires (e.g. a React hook unmounts or its deps
|
|
11
|
+
* change), the in-flight read rejects with {@link FartherShoreAbortError}. */
|
|
12
|
+
signal?: AbortSignal;
|
|
10
13
|
}
|
|
11
14
|
/** Issue a Core request, returning the parsed JSON body (typed by the caller).
|
|
12
15
|
* Adds the consumer session bearer + the host/env/org scoping headers Core
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAgB,MAAM,aAAa,CAAC;AAO/D,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,CAAC;IAC3D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;+DAC2D;IAC3D,IAAI,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC1B;mFAC+E;IAC/E,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAiDD;;+DAE+D;AAC/D,wBAAsB,SAAS,CAAC,CAAC,EAC/B,GAAG,EAAE,aAAa,EAClB,GAAG,EAAE,WAAW,GACf,OAAO,CAAC,CAAC,CAAC,CAqCZ;AAED;;;6BAG6B;AAC7B,wBAAsB,YAAY,CAChC,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAC3C,OAAO,CAAC,QAAQ,CAAC,CA+BnB"}
|
package/dist/http.js
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
// Gateway (builder features) — and the auth each one needs. Frontend code never
|
|
3
3
|
// constructs a URL or sets an auth header; it goes through here.
|
|
4
4
|
import { resolveToken } from "./config.js";
|
|
5
|
-
import { FartherShoreApiError, FartherShoreNetworkError } from "./errors.js";
|
|
5
|
+
import { FartherShoreAbortError, FartherShoreApiError, FartherShoreNetworkError, } from "./errors.js";
|
|
6
|
+
/** Whether a thrown fetch error is an abort (so we surface
|
|
7
|
+
* {@link FartherShoreAbortError} instead of {@link FartherShoreNetworkError}). */
|
|
8
|
+
function isAbortError(err) {
|
|
9
|
+
return ((err instanceof DOMException && err.name === "AbortError") ||
|
|
10
|
+
err?.name === "AbortError");
|
|
11
|
+
}
|
|
6
12
|
function buildUrl(base, path, query) {
|
|
7
13
|
const url = new URL(base + path);
|
|
8
14
|
if (query) {
|
|
@@ -57,9 +63,12 @@ export async function coreFetch(ctx, req) {
|
|
|
57
63
|
method: req.method,
|
|
58
64
|
headers,
|
|
59
65
|
body: req.body !== undefined ? JSON.stringify(req.body) : undefined,
|
|
66
|
+
signal: req.signal,
|
|
60
67
|
});
|
|
61
68
|
}
|
|
62
69
|
catch (err) {
|
|
70
|
+
if (isAbortError(err))
|
|
71
|
+
throw new FartherShoreAbortError();
|
|
63
72
|
throw new FartherShoreNetworkError(`Core request failed: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
64
73
|
}
|
|
65
74
|
if (res.status === 204)
|
|
@@ -92,6 +101,8 @@ export async function gatewayFetch(ctx, path, init = {}) {
|
|
|
92
101
|
res = await ctx.fetch(url, { ...rest, headers });
|
|
93
102
|
}
|
|
94
103
|
catch (err) {
|
|
104
|
+
if (isAbortError(err))
|
|
105
|
+
throw new FartherShoreAbortError();
|
|
95
106
|
throw new FartherShoreNetworkError(`Gateway request failed: ${err instanceof Error ? err.message : String(err)}`, err);
|
|
96
107
|
}
|
|
97
108
|
if (!res.ok) {
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,iEAAiE;AAEjE,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,iEAAiE;AAEjE,OAAO,EAAsB,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAerB;mFACmF;AACnF,SAAS,YAAY,CAAC,GAAY;IAChC,OAAO,CACL,CAAC,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC;QACzD,GAAyB,EAAE,IAAI,KAAK,YAAY,CAClD,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,IAAY,EACZ,IAAY,EACZ,KAA4B;IAE5B,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC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C,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IACxE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IACxC,KAAK,KAAK,CAAC;IACX,IAAI,GAAa,CAAC;IAClB,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,YAAY,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,sBAAsB,EAAE,CAAC;QAC1D,MAAM,IAAI,wBAAwB,CAChC,2BAA2B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAC7E,GAAG,CACJ,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;QACZ,MAAM,IAAI,GAAG,MAAM,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { createFartherShoreClient } from "./client.js";
|
|
1
|
+
export { createFartherShoreClient, createServerClient } from "./client.js";
|
|
2
2
|
export type { FartherShoreClient } from "./client.js";
|
|
3
3
|
export type { FartherShoreConfig, TokenProvider, FetchLike } from "./config.js";
|
|
4
4
|
/** Shape of a generic authenticated Core call — see {@link FartherShoreClient.core}. */
|
|
5
5
|
export type { CoreRequest } from "./http.js";
|
|
6
|
-
export { FartherShoreError, FartherShoreApiError, FartherShoreNetworkError, FartherShoreNotReadyError, } from "./errors.js";
|
|
6
|
+
export { FartherShoreError, FartherShoreApiError, FartherShoreNetworkError, FartherShoreAbortError, FartherShoreNotReadyError, FartherShoreConfigError, } from "./errors.js";
|
|
7
7
|
export type { Branding, Product, Meter, AuthStrategy, EnvironmentInfo, Bootstrap, Plan, PlanMeter, PlanLimit, Grant, Subscriber, Session, ApiKey, CreatedApiKey, UsageSummary, UsageEvent, UsageBillingBasis, UsageSnapshot, Subscription, SignInResult, } from "./types.js";
|
|
8
8
|
export type { ProductResource } from "./resources/product.js";
|
|
9
9
|
export type { AuthResource } from "./resources/auth.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChF,wFAAwF;AACxF,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,QAAQ,EACR,OAAO,EACP,KAAK,EACL,YAAY,EACZ,eAAe,EACf,SAAS,EACT,IAAI,EACJ,SAAS,EACT,SAAS,EACT,KAAK,EACL,UAAU,EACV,OAAO,EACP,MAAM,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtE,YAAY,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC7E,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAKhF,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
// const { product } = await fs.bootstrap();
|
|
10
10
|
// const keys = await fs.keys.list();
|
|
11
11
|
// const forecast = await fs.feature("weather").json("/forecast?city=NYC");
|
|
12
|
-
export { createFartherShoreClient } from "./client.js";
|
|
13
|
-
export { FartherShoreError, FartherShoreApiError, FartherShoreNetworkError, FartherShoreNotReadyError, } from "./errors.js";
|
|
12
|
+
export { createFartherShoreClient, createServerClient } from "./client.js";
|
|
13
|
+
export { FartherShoreError, FartherShoreApiError, FartherShoreNetworkError, FartherShoreAbortError, FartherShoreNotReadyError, FartherShoreConfigError, } from "./errors.js";
|
|
14
14
|
// Pure catalog/pricing display helpers (plan classification, price/grant/quota
|
|
15
15
|
// formatting) — port of the SSR portal's renderers so any frontend renders the
|
|
16
16
|
// catalog identically without re-deriving the math.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,kFAAkF;AAClF,EAAE;AACF,8EAA8E;AAC9E,uFAAuF;AACvF,8CAA8C;AAC9C,uCAAuC;AACvC,6EAA6E;AAE7E,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,iFAAiF;AACjF,iFAAiF;AACjF,kFAAkF;AAClF,EAAE;AACF,8EAA8E;AAC9E,uFAAuF;AACvF,8CAA8C;AAC9C,uCAAuC;AACvC,6EAA6E;AAE7E,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAO3E,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAqCrB,+EAA+E;AAC/E,+EAA+E;AAC/E,oDAAoD;AACpD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.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UAAU,IAAI,aAAa,CAoB1C;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB;;6EAEyE;IACzE,YAAY,EAAE,iBAAiB,CAAC;CACjC;AACD,wBAAgB,QAAQ,CAAC,KAAK,CAAC,EAAE;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,WAAW,CAAC,SAAS,CAAC,CAQzB;AAED,MAAM,WAAW,aAAc,SAAQ,WAAW,CAAC,YAAY,GAAG,IAAI,CAAC;IACrE,iBAAiB,CAAC,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7E;AACD,wBAAgB,UAAU,IAAI,aAAa,CAO1C;AAED;gFACgF;AAChF,MAAM,WAAW,WAAY,SAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;IACtD,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC5D;AACD,wBAAgB,QAAQ,IAAI,WAAW,CAOtC;AAED,yEAAyE;AACzE,wBAAgB,gBAAgB,IAAI,WAAW,CAAC,aAAa,GAAG,IAAI,CAAC,CAGpE;AAED,yEAAyE;AACzE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAGtD"}
|
package/dist/react/hooks.js
CHANGED
|
@@ -14,7 +14,7 @@ export function useProduct() {
|
|
|
14
14
|
}
|
|
15
15
|
export function useSession() {
|
|
16
16
|
const fs = useFartherShore();
|
|
17
|
-
const state = useAsync(() => fs.auth.getSession(), [fs]);
|
|
17
|
+
const state = useAsync((signal) => fs.auth.getSession({ signal }), [fs]);
|
|
18
18
|
return {
|
|
19
19
|
...state,
|
|
20
20
|
async signIn(input) {
|
|
@@ -29,7 +29,7 @@ export function useSession() {
|
|
|
29
29
|
}
|
|
30
30
|
export function useApiKeys() {
|
|
31
31
|
const fs = useFartherShore();
|
|
32
|
-
const state = useAsync(() => fs.keys.list(), [fs]);
|
|
32
|
+
const state = useAsync((signal) => fs.keys.list({ signal }), [fs]);
|
|
33
33
|
return {
|
|
34
34
|
...state,
|
|
35
35
|
async create(input) {
|
|
@@ -52,11 +52,11 @@ export function useUsage(range) {
|
|
|
52
52
|
const fs = useFartherShore();
|
|
53
53
|
// One round-trip via snapshot() — summary + events + billingBasis together —
|
|
54
54
|
// instead of two separate calls, and it carries the basis the UI needs.
|
|
55
|
-
return useAsync(() => fs.usage.snapshot(range), [fs, range?.from, range?.to]);
|
|
55
|
+
return useAsync((signal) => fs.usage.snapshot(range, { signal }), [fs, range?.from, range?.to]);
|
|
56
56
|
}
|
|
57
57
|
export function useBilling() {
|
|
58
58
|
const fs = useFartherShore();
|
|
59
|
-
const state = useAsync(() => fs.billing.subscription(), [fs]);
|
|
59
|
+
const state = useAsync((signal) => fs.billing.subscription({ signal }), [fs]);
|
|
60
60
|
return {
|
|
61
61
|
...state,
|
|
62
62
|
openBillingPortal: (input) => fs.billing.openBillingPortal(input),
|
|
@@ -73,7 +73,7 @@ export function usePlans() {
|
|
|
73
73
|
/** Live prepaid/credit balance for the current subscription, or null. */
|
|
74
74
|
export function useCreditBalance() {
|
|
75
75
|
const fs = useFartherShore();
|
|
76
|
-
return useAsync(() => fs.billing.creditBalance(), [fs]);
|
|
76
|
+
return useAsync((signal) => fs.billing.creditBalance({ signal }), [fs]);
|
|
77
77
|
}
|
|
78
78
|
/** A stable handle to a builder feature (routed through the Gateway). */
|
|
79
79
|
export function useFeature(name) {
|
package/dist/react/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,oDAAoD;AAEpD,O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KAChD,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAE,GAAG,eAAe,EAAE,CAAC;IAC7B,OAAO,QAAQ,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,MAAM,EAAE,GAAG,eAAe,EAAE,CAAC;IAC7B,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/react/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { FartherShoreProvider, useFartherShore } from "./provider.js";
|
|
|
2
2
|
export type { FartherShoreProviderProps } from "./provider.js";
|
|
3
3
|
export { useAsync } from "./use-async.js";
|
|
4
4
|
export type { AsyncState, AsyncResult } from "./use-async.js";
|
|
5
|
+
export { FartherShoreAbortError } from "../errors.js";
|
|
5
6
|
export { useBootstrap, useProduct, useSession, useApiKeys, useUsage, useBilling, usePlans, useCreditBalance, useFeature, } from "./hooks.js";
|
|
6
7
|
export type { SessionResult, ApiKeysResult, UsageData, BillingResult, PlansResult, } from "./hooks.js";
|
|
7
8
|
export type * from "../types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtE,YAAY,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAK9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,aAAa,EACb,aAAa,EACb,SAAS,EACT,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAKpB,mBAAmB,aAAa,CAAC"}
|
package/dist/react/index.js
CHANGED
|
@@ -6,5 +6,9 @@
|
|
|
6
6
|
// in; the core SDK ('@farthershore/farthershore-js') stays framework-agnostic.
|
|
7
7
|
export { FartherShoreProvider, useFartherShore } from "./provider.js";
|
|
8
8
|
export { useAsync } from "./use-async.js";
|
|
9
|
+
// Re-export the abort error so component code rendered against this subpath can
|
|
10
|
+
// `instanceof FartherShoreAbortError` (e.g. to ignore a cancelled read) without
|
|
11
|
+
// also reaching into the core entry.
|
|
12
|
+
export { FartherShoreAbortError } from "../errors.js";
|
|
9
13
|
export { useBootstrap, useProduct, useSession, useApiKeys, useUsage, useBilling, usePlans, useCreditBalance, useFeature, } from "./hooks.js";
|
|
10
14
|
//# sourceMappingURL=index.js.map
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,4FAA4F;AAC5F,EAAE;AACF,kFAAkF;AAClF,+EAA+E;AAE/E,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,4FAA4F;AAC5F,EAAE;AACF,kFAAkF;AAClF,+EAA+E;AAE/E,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGtE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,gFAAgF;AAChF,gFAAgF;AAChF,qCAAqC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC3E,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,yBAAyB;IACxC,sEAAsE;IACtE,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B;gEAC4D;IAC5D,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,iFAAiF;AACjF,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,MAAM,EACN,QAAQ,GACT,EAAE,yBAAyB,2CAgB3B;AAED,kEAAkE;AAClE,wBAAgB,eAAe,IAAI,kBAAkB,CAQpD"}
|
package/dist/react/provider.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useContext, useMemo } from "react";
|
|
3
|
-
import { createFartherShoreClient, } from "../index.js";
|
|
3
|
+
import { createFartherShoreClient, FartherShoreConfigError, } from "../index.js";
|
|
4
4
|
const FartherShoreContext = createContext(null);
|
|
5
5
|
/** Provides one Farther Shore client to the tree. Mount once at the app root. */
|
|
6
6
|
export function FartherShoreProvider({ client, config, children, }) {
|
|
@@ -8,7 +8,7 @@ export function FartherShoreProvider({ client, config, children, }) {
|
|
|
8
8
|
if (client)
|
|
9
9
|
return client;
|
|
10
10
|
if (!config) {
|
|
11
|
-
throw new
|
|
11
|
+
throw new FartherShoreConfigError("FartherShoreProvider requires a `client` or `config`.");
|
|
12
12
|
}
|
|
13
13
|
return createFartherShoreClient(config);
|
|
14
14
|
}, [client, config]);
|
|
@@ -18,7 +18,7 @@ export function FartherShoreProvider({ client, config, children, }) {
|
|
|
18
18
|
export function useFartherShore() {
|
|
19
19
|
const client = useContext(FartherShoreContext);
|
|
20
20
|
if (!client) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new FartherShoreConfigError("useFartherShore must be used within <FartherShoreProvider>.");
|
|
22
22
|
}
|
|
23
23
|
return client;
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AAC3E,OAAO,EACL,wBAAwB,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/react/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AAC3E,OAAO,EACL,wBAAwB,EACxB,uBAAuB,GAGxB,MAAM,aAAa,CAAC;AAErB,MAAM,mBAAmB,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAW3E,iFAAiF;AACjF,MAAM,UAAU,oBAAoB,CAAC,EACnC,MAAM,EACN,MAAM,EACN,QAAQ,GACkB;IAC1B,MAAM,KAAK,GAAG,OAAO,CAAqB,GAAG,EAAE;QAC7C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,uBAAuB,CAC/B,uDAAuD,CACxD,CAAC;QACJ,CAAC;QACD,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAErB,OAAO,CACL,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACvC,QAAQ,GACoB,CAChC,CAAC;AACJ,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,eAAe;IAC7B,MAAM,MAAM,GAAG,UAAU,CAAC,mBAAmB,CAAC,CAAC;IAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,uBAAuB,CAC/B,6DAA6D,CAC9D,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -9,6 +9,8 @@ export interface AsyncResult<T> extends AsyncState<T> {
|
|
|
9
9
|
}
|
|
10
10
|
/** A small data-fetching primitive the hooks share: tracks {data, loading,
|
|
11
11
|
* error}, re-runs when `deps` change or `refresh()` is called, and ignores a
|
|
12
|
-
* resolution after unmount/dep-change (no setState-after-unmount).
|
|
13
|
-
|
|
12
|
+
* resolution after unmount/dep-change (no setState-after-unmount). The `fn`
|
|
13
|
+
* receives an {@link AbortSignal} that fires on unmount/dep-change/refresh, so
|
|
14
|
+
* the stale in-flight read is cancelled rather than left to resolve. */
|
|
15
|
+
export declare function useAsync<T>(fn: (signal: AbortSignal) => Promise<T>, deps: readonly unknown[]): AsyncResult<T>;
|
|
14
16
|
//# sourceMappingURL=use-async.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-async.d.ts","sourceRoot":"","sources":["../../src/react/use-async.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-async.d.ts","sourceRoot":"","sources":["../../src/react/use-async.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACnD,iCAAiC;IACjC,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;yEAIyE;AACzE,wBAAgB,QAAQ,CAAC,CAAC,EACxB,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACvC,IAAI,EAAE,SAAS,OAAO,EAAE,GACvB,WAAW,CAAC,CAAC,CAAC,CAuChB"}
|
package/dist/react/use-async.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { FartherShoreAbortError } from "../errors.js";
|
|
2
3
|
/** A small data-fetching primitive the hooks share: tracks {data, loading,
|
|
3
4
|
* error}, re-runs when `deps` change or `refresh()` is called, and ignores a
|
|
4
|
-
* resolution after unmount/dep-change (no setState-after-unmount).
|
|
5
|
+
* resolution after unmount/dep-change (no setState-after-unmount). The `fn`
|
|
6
|
+
* receives an {@link AbortSignal} that fires on unmount/dep-change/refresh, so
|
|
7
|
+
* the stale in-flight read is cancelled rather than left to resolve. */
|
|
5
8
|
export function useAsync(fn, deps) {
|
|
6
9
|
const [state, setState] = useState({
|
|
7
10
|
data: null,
|
|
@@ -13,14 +16,19 @@ export function useAsync(fn, deps) {
|
|
|
13
16
|
fnRef.current = fn;
|
|
14
17
|
useEffect(() => {
|
|
15
18
|
let active = true;
|
|
19
|
+
const controller = new AbortController();
|
|
16
20
|
setState((s) => ({ data: s.data, loading: true, error: null }));
|
|
17
21
|
fnRef
|
|
18
|
-
.current()
|
|
22
|
+
.current(controller.signal)
|
|
19
23
|
.then((data) => {
|
|
20
24
|
if (active)
|
|
21
25
|
setState({ data, loading: false, error: null });
|
|
22
26
|
})
|
|
23
27
|
.catch((e) => {
|
|
28
|
+
// An abort is never a user-facing error — the read was cancelled by
|
|
29
|
+
// unmount/dep-change/refresh, so leave state untouched.
|
|
30
|
+
if (e instanceof FartherShoreAbortError)
|
|
31
|
+
return;
|
|
24
32
|
if (active) {
|
|
25
33
|
setState({
|
|
26
34
|
data: null,
|
|
@@ -31,6 +39,7 @@ export function useAsync(fn, deps) {
|
|
|
31
39
|
});
|
|
32
40
|
return () => {
|
|
33
41
|
active = false;
|
|
42
|
+
controller.abort();
|
|
34
43
|
};
|
|
35
44
|
}, [...deps, nonce]);
|
|
36
45
|
const refresh = useCallback(() => setNonce((n) => n + 1), []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-async.js","sourceRoot":"","sources":["../../src/react/use-async.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
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I,MAAM,EAAE,CAAC;gBACX,QAAQ,CAAC;oBACP,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;iBACrD,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QACL,OAAO,GAAG,EAAE;YACV,MAAM,GAAG,KAAK,CAAC;YACf,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAErB,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9D,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
|
package/dist/resources/auth.d.ts
CHANGED
|
@@ -3,13 +3,16 @@ import type { Session, SignInResult } from "../types.js";
|
|
|
3
3
|
export interface AuthResource {
|
|
4
4
|
/** The current session (authenticated + a light subscriber slice). Resolves to
|
|
5
5
|
* `{ authenticated: false }` on a 401/403 rather than throwing. */
|
|
6
|
-
getSession(
|
|
6
|
+
getSession(opts?: {
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}): Promise<Session>;
|
|
7
9
|
/** Test/preview-env sign-in: exchange an `fsk_test_…` access key for a session
|
|
8
10
|
* (persona strategy). Clerk-strategy envs sign in via the Clerk browser SDK —
|
|
9
11
|
* pass `getToken` to the client config and call `setToken` instead. */
|
|
10
12
|
signIn(input: {
|
|
11
13
|
apiKey: string;
|
|
12
14
|
}): Promise<SignInResult>;
|
|
15
|
+
/** Clear the current session (server-side persona logout + local token). */
|
|
13
16
|
signOut(): Promise<void>;
|
|
14
17
|
/** Set the session bearer directly (e.g. from Clerk's `session.getToken()`). */
|
|
15
18
|
setToken(token: string | null): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAgBrE,MAAM,WAAW,YAAY;IAC3B;wEACoE;IACpE,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAc,MAAM,aAAa,CAAC;AAgBrE,MAAM,WAAW,YAAY;IAC3B;wEACoE;IACpE,UAAU,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D;;4EAEwE;IACxE,MAAM,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACzD,4EAA4E;IAC5E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,gFAAgF;IAChF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;CACtC;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,YAAY,CA4DnE"}
|
package/dist/resources/auth.js
CHANGED
|
@@ -3,12 +3,13 @@ import { FartherShoreApiError } from "../errors.js";
|
|
|
3
3
|
import { mePath, requireProductId } from "./_shared.js";
|
|
4
4
|
export function createAuthResource(ctx) {
|
|
5
5
|
return {
|
|
6
|
-
async getSession() {
|
|
6
|
+
async getSession(opts) {
|
|
7
7
|
const productId = requireProductId(ctx);
|
|
8
8
|
try {
|
|
9
9
|
const raw = await coreFetch(ctx, {
|
|
10
10
|
method: "GET",
|
|
11
11
|
path: mePath(productId),
|
|
12
|
+
signal: opts?.signal,
|
|
12
13
|
});
|
|
13
14
|
const s = raw.subscriber;
|
|
14
15
|
const subscriber = s
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/resources/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA6BxD,MAAM,UAAU,kBAAkB,CAAC,GAAkB;IACnD,OAAO;QACL,KAAK,CAAC,UAAU,CAAC,IAAI;YACnB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACxC,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,SAAS,CAAuB,GAAG,EAAE;oBACrD,MAAM,EAAE,KAAK;oBACb,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC;oBACvB,MAAM,EAAE,IAAI,EAAE,MAAM;iBACrB,CAAC,CAAC;gBACH,MAAM,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC;gBACzB,MAAM,UAAU,GAAsB,CAAC;oBACrC,CAAC,CAAC;wBACE,MAAM,EAAE,CAAC,CAAC,MA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AAG,CAAC,YAAY,GAAG,KAAK,CAAC;QAC3B,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -13,7 +13,9 @@ export interface CreditBalance {
|
|
|
13
13
|
}
|
|
14
14
|
export interface BillingResource {
|
|
15
15
|
/** The consumer's current subscription for this product, or null. */
|
|
16
|
-
subscription(
|
|
16
|
+
subscription(opts?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<Subscription | null>;
|
|
17
19
|
/** Open the Stripe-hosted billing portal (payment method + invoices). Returns
|
|
18
20
|
* the URL to navigate to. This is also how invoices are viewed in V0. */
|
|
19
21
|
openBillingPortal(input?: {
|
|
@@ -24,7 +26,9 @@ export interface BillingResource {
|
|
|
24
26
|
/** Live prepaid/credit balance for the current subscription, or null when
|
|
25
27
|
* there is no credit surface. Degrades to null rather than throwing on a
|
|
26
28
|
* 404 (no subscription/grant). */
|
|
27
|
-
creditBalance(
|
|
29
|
+
creditBalance(opts?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<CreditBalance | null>;
|
|
28
32
|
}
|
|
29
33
|
export declare function createBillingResource(ctx: ClientContext): BillingResource;
|
|
30
34
|
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+BhD;;4BAE4B;AAC5B,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,YAAY,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA+BhD;;4BAE4B;AAC5B,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,qEAAqE;IACrE,YAAY,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC5E;8EAC0E;IAC1E,iBAAiB,CAAC,KAAK,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5E;;uCAEmC;IACnC,aAAa,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;CAC/E;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,aAAa,GAAG,eAAe,CAyDzE"}
|
|
@@ -3,11 +3,12 @@ import { FartherShoreApiError } from "../errors.js";
|
|
|
3
3
|
import { mePath, requireProductId } from "./_shared.js";
|
|
4
4
|
export function createBillingResource(ctx) {
|
|
5
5
|
return {
|
|
6
|
-
async subscription() {
|
|
6
|
+
async subscription(opts) {
|
|
7
7
|
const productId = requireProductId(ctx);
|
|
8
8
|
const raw = await coreFetch(ctx, {
|
|
9
9
|
method: "GET",
|
|
10
10
|
path: mePath(productId, "/subscription"),
|
|
11
|
+
signal: opts?.signal,
|
|
11
12
|
});
|
|
12
13
|
if (!raw)
|
|
13
14
|
return null;
|
|
@@ -28,12 +29,13 @@ export function createBillingResource(ctx) {
|
|
|
28
29
|
});
|
|
29
30
|
return { url: raw.url };
|
|
30
31
|
},
|
|
31
|
-
async creditBalance() {
|
|
32
|
+
async creditBalance(opts) {
|
|
32
33
|
const productId = requireProductId(ctx);
|
|
33
34
|
try {
|
|
34
35
|
const raw = await coreFetch(ctx, {
|
|
35
36
|
method: "GET",
|
|
36
37
|
path: mePath(productId, "/credit-balance"),
|
|
38
|
+
signal: opts?.signal,
|
|
37
39
|
});
|
|
38
40
|
if (!raw.balance)
|
|
39
41
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAsDxD,MAAM,UAAU,qBAAqB,CAAC,GAAkB;IACtD,OAAO;QACL,KAAK,CAAC,YAAY;
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/resources/billing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAsDxD,MAAM,UAAU,qBAAqB,CAAC,GAAkB;IACtD,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,IAAI;YACrB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAyB,GAAG,EAAE;gBACvD,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,iBAAiB,CAAC;oBAC1C,MAAM,EAAE,IAAI,EAAE,MAAM;iBACrB,CAAC,CAAC;gBACH,IAAI,CAAC,GAAG,CAAC,OAAO;oBAAE,OAAO,IAAI,CAAC;gBAC9B,OAAO;oBACL,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,cAAc;oBAC1C,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW;oBACpC,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ;iBAC/B,CAAC;YACJ,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,qEAAqE;gBACrE,wDAAwD;gBACxD,IACE,GAAG,YAAY,oBAAoB;oBACnC,CAAC,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,EAChE,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;gBACD,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/resources/keys.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type ClientContext } from "../config.js";
|
|
2
2
|
import type { ApiKey, CreatedApiKey } from "../types.js";
|
|
3
3
|
export interface KeysResource {
|
|
4
|
-
|
|
4
|
+
/** The consumer's API keys for this product (secrets are never returned). */
|
|
5
|
+
list(opts?: {
|
|
6
|
+
signal?: AbortSignal;
|
|
7
|
+
}): Promise<ApiKey[]>;
|
|
5
8
|
/** Create a key. The returned `secret` is shown ONCE. */
|
|
6
9
|
create(input?: {
|
|
7
10
|
label?: string;
|
|
8
11
|
scopes?: string[];
|
|
9
12
|
}): Promise<CreatedApiKey>;
|
|
13
|
+
/** Permanently revoke a key by id. */
|
|
10
14
|
revoke(keyId: string): Promise<void>;
|
|
11
15
|
/** Rotate a key — revokes the old and returns a new `secret` (shown once). */
|
|
12
16
|
rotate(keyId: string): Promise<CreatedApiKey>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/resources/keys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmCzD,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../src/resources/keys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmCzD,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,IAAI,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACzD,yDAAyD;IACzD,MAAM,CAAC,KAAK,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC9E,sCAAsC;IACtC,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,8EAA8E;IAC9E,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/C;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,aAAa,GAAG,YAAY,CA0CnE"}
|
package/dist/resources/keys.js
CHANGED
|
@@ -18,11 +18,12 @@ function withSecret(k) {
|
|
|
18
18
|
}
|
|
19
19
|
export function createKeysResource(ctx) {
|
|
20
20
|
return {
|
|
21
|
-
async list() {
|
|
21
|
+
async list(opts) {
|
|
22
22
|
const productId = requireProductId(ctx);
|
|
23
23
|
const raw = await coreFetch(ctx, {
|
|
24
24
|
method: "GET",
|
|
25
25
|
path: mePath(productId, "/api-keys"),
|
|
26
|
+
signal: opts?.signal,
|
|
26
27
|
});
|
|
27
28
|
return raw.map(mapKey);
|
|
28
29
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/resources/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgBxD,SAAS,MAAM,CAAC,CAAS;IACvB,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,KAAK,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI;QACtB,4EAA4E;QAC5E,oEAAoE;QACpE,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE;QACtC,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,IAAI;QAChC,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,IAAI;KAC/B,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,CAAgB;IAClC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;AACjE,CAAC;
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../src/resources/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAgBxD,SAA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,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE;aACnD,CAAC,CAAC;YACH,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,KAAK;YAChB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,SAAS,CAAO,GAAG,EAAE;gBACzB,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,aAAa,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,KAAK;YAChB,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;YACxC,MAAM,GAAG,GAAG,MAAM,SAAS,CAAgB,GAAG,EAAE;gBAC9C,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,MAAM,CACV,SAAS,EACT,aAAa,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAChD;aACF,CAAC,CAAC;YACH,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -6,12 +6,18 @@ export interface UsageRange {
|
|
|
6
6
|
}
|
|
7
7
|
export interface UsageResource {
|
|
8
8
|
/** Dimension → total for the period (requests/tokens/computeMs/dollars…). */
|
|
9
|
-
summary(range?: UsageRange
|
|
9
|
+
summary(range?: UsageRange, opts?: {
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}): Promise<UsageSummary>;
|
|
10
12
|
/** The most-recent usage events (platform caps this list). */
|
|
11
|
-
events(range?: UsageRange
|
|
13
|
+
events(range?: UsageRange, opts?: {
|
|
14
|
+
signal?: AbortSignal;
|
|
15
|
+
}): Promise<UsageEvent[]>;
|
|
12
16
|
/** Everything in one round-trip: per-dimension totals + recent events + the
|
|
13
17
|
* billing basis (the "Requests" vs "Usage" meter-label hint). */
|
|
14
|
-
snapshot(range?: UsageRange
|
|
18
|
+
snapshot(range?: UsageRange, opts?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<UsageSnapshot>;
|
|
15
21
|
}
|
|
16
22
|
export declare function createUsageResource(ctx: ClientContext): UsageResource;
|
|
17
23
|
//# sourceMappingURL=usage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAEV,UAAU,EACV,aAAa,EACb,YAAY,EACb,MAAM,aAAa,CAAC;AAsBrB,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,OAAO,
|
|
1
|
+
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAEV,UAAU,EACV,aAAa,EACb,YAAY,EACb,MAAM,aAAa,CAAC;AAsBrB,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,aAAa;IAC5B,6EAA6E;IAC7E,OAAO,CACL,KAAK,CAAC,EAAE,UAAU,EAClB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAC9B,OAAO,CAAC,YAAY,CAAC,CAAC;IACzB,8DAA8D;IAC9D,MAAM,CACJ,KAAK,CAAC,EAAE,UAAU,EAClB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAC9B,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IACzB;sEACkE;IAClE,QAAQ,CACN,KAAK,CAAC,EAAE,UAAU,EAClB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAC9B,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3B;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,aAAa,CA+CrE"}
|
package/dist/resources/usage.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { coreFetch } from "../http.js";
|
|
2
2
|
import { mePath, requireProductId } from "./_shared.js";
|
|
3
3
|
export function createUsageResource(ctx) {
|
|
4
|
-
async function fetchUsage(range) {
|
|
4
|
+
async function fetchUsage(range, opts) {
|
|
5
5
|
const productId = requireProductId(ctx);
|
|
6
6
|
return coreFetch(ctx, {
|
|
7
7
|
method: "GET",
|
|
8
8
|
path: mePath(productId, "/usage"),
|
|
9
9
|
query: { from: range?.from, to: range?.to },
|
|
10
|
+
signal: opts?.signal,
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
function toEvent(i) {
|
|
@@ -24,14 +25,14 @@ export function createUsageResource(ctx) {
|
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
return {
|
|
27
|
-
async summary(range) {
|
|
28
|
-
return (await fetchUsage(range)).summary;
|
|
28
|
+
async summary(range, opts) {
|
|
29
|
+
return (await fetchUsage(range, opts)).summary;
|
|
29
30
|
},
|
|
30
|
-
async events(range) {
|
|
31
|
-
return (await fetchUsage(range)).items.map(toEvent);
|
|
31
|
+
async events(range, opts) {
|
|
32
|
+
return (await fetchUsage(range, opts)).items.map(toEvent);
|
|
32
33
|
},
|
|
33
|
-
async snapshot(range) {
|
|
34
|
-
const raw = await fetchUsage(range);
|
|
34
|
+
async snapshot(range, opts) {
|
|
35
|
+
const raw = await fetchUsage(range, opts);
|
|
35
36
|
return {
|
|
36
37
|
summary: raw.summary,
|
|
37
38
|
events: raw.items.map(toEvent),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQvC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/resources/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQvC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AA6CxD,MAAM,UAAU,mBAAmB,CAAC,GAAkB;IACpD,KAAK,UAAU,UAAU,CACvB,KAAkB,EAClB,IAA+B;QAE/B,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QACxC,OAAO,SAAS,CAAW,GAAG,EAAE;YAC9B,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC;YACjC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YAC3C,MAAM,EAAE,IAAI,EAAE,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;IAED,SAAS,OAAO,CAAC,CAAe;QAC9B,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI;YACjD,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,IAAI;YAChC,MAAM,EAAE,CAAC,CAAC,MAAM;YAChB,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI;YACpB,SAAS,EAAE,CAAC,CAAC,SAAS,IAAI,IAAI;YAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;YAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI,IAAI;SACzB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI;YACvB,OAAO,CAAC,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;QACjD,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI;YACtB,OAAO,CAAC,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI;YACxB,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC1C,OAAO;gBACL,OAAO,EAAE,GAAG,CAAC,OAAO;gBACpB,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;gBAC9B,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,UAAU;aAC7C,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farthershore/farthershore-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Farther Shore Frontend SDK — the browser integration layer between static frontends and the Farther Shore platform (Core + Gateway).",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
-
"README.md"
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md"
|
|
26
27
|
],
|
|
27
28
|
"engines": {
|
|
28
29
|
"node": ">=22"
|
|
@@ -47,19 +48,21 @@
|
|
|
47
48
|
"@testing-library/react": "^16.1.0",
|
|
48
49
|
"@types/node": "^25.7.0",
|
|
49
50
|
"@types/react": "^19.0.0",
|
|
51
|
+
"esbuild": "^0.27.7",
|
|
50
52
|
"eslint": "^10.3.0",
|
|
51
53
|
"jsdom": "^26.0.0",
|
|
52
54
|
"react": "^19.0.0",
|
|
53
55
|
"react-dom": "^19.0.0",
|
|
54
56
|
"typescript": "^6.0.2",
|
|
55
57
|
"typescript-eslint": "^8.59.3",
|
|
56
|
-
"vitest": "^4.1.6"
|
|
58
|
+
"vitest": "^4.1.6",
|
|
59
|
+
"@farthershore/contracts": "0.61.1"
|
|
57
60
|
},
|
|
58
61
|
"scripts": {
|
|
59
62
|
"build": "tsc",
|
|
60
63
|
"typecheck": "tsc --noEmit",
|
|
61
64
|
"lint": "eslint .",
|
|
62
65
|
"lint:fix": "eslint . --fix",
|
|
63
|
-
"test": "vitest run"
|
|
66
|
+
"test": "tsc -p test/tsconfig.json && vitest run"
|
|
64
67
|
}
|
|
65
68
|
}
|