@anvil-js/client 0.0.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/LICENSE +99 -0
- package/README.md +31 -0
- package/dist/chunk-DV6XOONA.js +41 -0
- package/dist/chunk-DV6XOONA.js.map +1 -0
- package/dist/chunk-WIGN6UED.js +728 -0
- package/dist/chunk-WIGN6UED.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/provider-2AIXk8yy.d.ts +15601 -0
- package/dist/react/index.d.ts +25 -0
- package/dist/react/index.js +16 -0
- package/dist/react/index.js.map +1 -0
- package/dist/schemas/index.d.ts +2584 -0
- package/dist/schemas/index.js +3 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/server.d.ts +3869 -0
- package/dist/server.js +492 -0
- package/dist/server.js.map +1 -0
- package/dist/ws/index.d.ts +298 -0
- package/dist/ws/index.js +608 -0
- package/dist/ws/index.js.map +1 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
ANVIL — PROPRIETARY LICENSE
|
|
2
|
+
Copyright (c) 2024–2026 Anvil contributors. All rights reserved.
|
|
3
|
+
|
|
4
|
+
================================================================================
|
|
5
|
+
NOTICE: PROPRIETARY SOFTWARE — UNPUBLISHED, NOT FOR DISTRIBUTION
|
|
6
|
+
================================================================================
|
|
7
|
+
|
|
8
|
+
This software and associated documentation files (the "Software") are
|
|
9
|
+
proprietary and confidential. The Software is NOT open-source, source-available,
|
|
10
|
+
or public in any form.
|
|
11
|
+
|
|
12
|
+
All rights, title, and interest in and to the Software, including all
|
|
13
|
+
intellectual property rights therein, are and shall remain the exclusive
|
|
14
|
+
property of the copyright holders.
|
|
15
|
+
|
|
16
|
+
================================================================================
|
|
17
|
+
1. INTERNAL USE GRANT
|
|
18
|
+
================================================================================
|
|
19
|
+
|
|
20
|
+
Permission is hereby granted, free of charge, to authorized contributors and
|
|
21
|
+
personnel explicitly added to this repository to use, copy, modify, merge,
|
|
22
|
+
publish, and distribute the Software, subject to the following conditions:
|
|
23
|
+
|
|
24
|
+
a) Access must be explicitly granted by a repository administrator.
|
|
25
|
+
b) All copies, modifications, and derivative works remain the property of
|
|
26
|
+
the copyright holders.
|
|
27
|
+
c) Distribution outside the authorized contributor list is strictly
|
|
28
|
+
prohibited.
|
|
29
|
+
|
|
30
|
+
================================================================================
|
|
31
|
+
2. NO PUBLIC DISTRIBUTION
|
|
32
|
+
================================================================================
|
|
33
|
+
|
|
34
|
+
The following activities are STRICTLY PROHIBITED without prior written
|
|
35
|
+
permission from the copyright holders:
|
|
36
|
+
|
|
37
|
+
a) Publishing the Software (or any portion thereof) to any public code
|
|
38
|
+
hosting platform (GitHub public, GitLab public, Bitbucket public, etc.).
|
|
39
|
+
b) Publishing the Software (or any portion thereof) to any package registry
|
|
40
|
+
(npmjs public, GitHub Packages public, PyPI, crates.io, etc.).
|
|
41
|
+
c) Distributing compiled binaries, installers, or any build artifacts
|
|
42
|
+
outside of authorized channels.
|
|
43
|
+
d) Publishing documentation, screenshots, or marketing materials that
|
|
44
|
+
reveal the internal architecture, source code, or business logic of
|
|
45
|
+
the Software.
|
|
46
|
+
e) Using the Software (or any portion thereof) to provide a competing
|
|
47
|
+
commercial product or service.
|
|
48
|
+
f) Sublicensing, reselling, or renting the Software.
|
|
49
|
+
|
|
50
|
+
================================================================================
|
|
51
|
+
3. THIRD-PARTY COMPONENTS
|
|
52
|
+
================================================================================
|
|
53
|
+
|
|
54
|
+
The Software may include or depend on third-party open-source components,
|
|
55
|
+
each governed by its own license. A list of such components and their
|
|
56
|
+
licenses is provided in THIRD-PARTY-NOTICES (or equivalent file) within
|
|
57
|
+
the repository. Use of such components is subject to their respective
|
|
58
|
+
license terms.
|
|
59
|
+
|
|
60
|
+
================================================================================
|
|
61
|
+
4. TRADEMARKS
|
|
62
|
+
================================================================================
|
|
63
|
+
|
|
64
|
+
"Anvil", the Anvil logo, and any related marks are trademarks of the
|
|
65
|
+
copyright holders. No license, express or implied, is granted to use
|
|
66
|
+
such trademarks without prior written permission.
|
|
67
|
+
|
|
68
|
+
================================================================================
|
|
69
|
+
5. NO WARRANTY
|
|
70
|
+
================================================================================
|
|
71
|
+
|
|
72
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
73
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
74
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
75
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
76
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
77
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
78
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
79
|
+
|
|
80
|
+
================================================================================
|
|
81
|
+
6. TERMINATION
|
|
82
|
+
================================================================================
|
|
83
|
+
|
|
84
|
+
Any breach of the conditions in this license automatically terminates
|
|
85
|
+
all rights granted herein. The copyright holders reserve the right to
|
|
86
|
+
revoke access to the repository at any time, for any reason, at their
|
|
87
|
+
sole discretion.
|
|
88
|
+
|
|
89
|
+
================================================================================
|
|
90
|
+
SUMMARY (NON-BINDING)
|
|
91
|
+
================================================================================
|
|
92
|
+
|
|
93
|
+
✓ You CAN: contribute to this private repository if you have access
|
|
94
|
+
✗ You MUST: keep all code, architecture, and business logic confidential
|
|
95
|
+
✗ You CANNOT: publish, distribute, sublicense, or commercialize the Software
|
|
96
|
+
✗ You CANNOT: use the "Anvil" name/logo for any external purpose
|
|
97
|
+
|
|
98
|
+
If you have questions about this license or wish to request permission
|
|
99
|
+
for activities prohibited herein, contact the repository administrators.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @anvil-js/client
|
|
2
|
+
|
|
3
|
+
Typed client for the [Anvil](https://anvil.my) API: the tRPC router types,
|
|
4
|
+
Zod schemas, TanStack Query React hooks, and the Essential WebSocket client.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm i @anvil-js/client
|
|
8
|
+
# react hooks need react as a peer:
|
|
9
|
+
npm i react @tanstack/react-query
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Entry points
|
|
13
|
+
|
|
14
|
+
| Import | Contents |
|
|
15
|
+
| --- | --- |
|
|
16
|
+
| `@anvil-js/client` | tRPC client factory, router type (`AppRouter`), core types |
|
|
17
|
+
| `@anvil-js/client/react` | TanStack Query provider + typed hooks |
|
|
18
|
+
| `@anvil-js/client/schemas` | Zod schemas (auth, builds, social, cosmetics, …) |
|
|
19
|
+
| `@anvil-js/client/server` | server-side router type helpers |
|
|
20
|
+
| `@anvil-js/client/ws` | Essential binary WS client + codec |
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createAnvilClient } from '@anvil-js/client';
|
|
24
|
+
|
|
25
|
+
const client = createAnvilClient({
|
|
26
|
+
baseUrl: 'https://anvil.my/v1',
|
|
27
|
+
getToken: async () => localStorage.getItem('anvil.jwt') ?? undefined,
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
ESM-only. Published from the Anvil monorepo (`packages/client`).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createTRPCReact } from '@trpc/react-query';
|
|
2
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { httpLink } from '@trpc/client';
|
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
|
6
|
+
|
|
7
|
+
// src/react/provider.tsx
|
|
8
|
+
var trpc = createTRPCReact();
|
|
9
|
+
function AnvilClientProvider({ config, children, devFetch }) {
|
|
10
|
+
const [queryClient] = useState(
|
|
11
|
+
() => new QueryClient({
|
|
12
|
+
defaultOptions: {
|
|
13
|
+
queries: {
|
|
14
|
+
staleTime: 5 * 60 * 1e3,
|
|
15
|
+
retry: 1,
|
|
16
|
+
refetchOnWindowFocus: false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
const [trpcClient] = useState(
|
|
22
|
+
() => trpc.createClient({
|
|
23
|
+
links: [
|
|
24
|
+
httpLink({
|
|
25
|
+
url: config.baseUrl,
|
|
26
|
+
headers: async () => {
|
|
27
|
+
const token = await config.getToken();
|
|
28
|
+
return token ? { authorization: `Bearer ${token}` } : {};
|
|
29
|
+
},
|
|
30
|
+
fetch: devFetch
|
|
31
|
+
})
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
);
|
|
35
|
+
return /* @__PURE__ */ jsx(trpc.Provider, { client: trpcClient, queryClient, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children }) });
|
|
36
|
+
}
|
|
37
|
+
var useAnvilClient = trpc.useContext;
|
|
38
|
+
|
|
39
|
+
export { AnvilClientProvider, trpc, useAnvilClient };
|
|
40
|
+
//# sourceMappingURL=chunk-DV6XOONA.js.map
|
|
41
|
+
//# sourceMappingURL=chunk-DV6XOONA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/provider.tsx"],"names":[],"mappings":";;;;;;;AASO,IAAM,OAAO,eAAA;AAyEb,SAAS,mBAAA,CAAoB,EAAE,MAAA,EAAQ,QAAA,EAAU,UAAS,EAA6B;AAC5F,EAAA,MAAM,CAAC,WAAW,CAAA,GAAI,QAAA;AAAA,IACpB,MACE,IAAI,WAAA,CAAY;AAAA,MACd,cAAA,EAAgB;AAAA,QACd,OAAA,EAAS;AAAA,UACP,SAAA,EAAW,IAAI,EAAA,GAAK,GAAA;AAAA,UACpB,KAAA,EAAO,CAAA;AAAA,UACP,oBAAA,EAAsB;AAAA;AACxB;AACF,KACD;AAAA,GACL;AAEA,EAAA,MAAM,CAAC,UAAU,CAAA,GAAI,QAAA;AAAA,IAAS,MAC5B,KAAK,YAAA,CAAa;AAAA,MAChB,KAAA,EAAO;AAAA,QACL,QAAA,CAAS;AAAA,UACP,KAAK,MAAA,CAAO,OAAA;AAAA,UACZ,SAAS,YAAY;AACnB,YAAA,MAAM,KAAA,GAAQ,MAAM,MAAA,CAAO,QAAA,EAAS;AACpC,YAAA,OAAO,QAAQ,EAAE,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA,KAAO,EAAC;AAAA,UACzD,CAAA;AAAA,UACA,KAAA,EAAO;AAAA,SACR;AAAA;AACH,KACD;AAAA,GACH;AAEA,EAAA,uBACE,GAAA,CAAC,IAAA,CAAK,QAAA,EAAL,EAAc,MAAA,EAAQ,UAAA,EAAY,WAAA,EACjC,QAAA,kBAAA,GAAA,CAAC,mBAAA,EAAA,EAAoB,MAAA,EAAQ,WAAA,EAAc,QAAA,EAAS,CAAA,EACtD,CAAA;AAEJ;AAEO,IAAM,iBAAiB,IAAA,CAAK","file":"chunk-DV6XOONA.js","sourcesContent":["'use client';\n\nimport { createTRPCReact } from '@trpc/react-query';\nimport { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport { useState, type ReactNode } from 'react';\nimport { httpLink } from '@trpc/client';\nimport type { AppRouter } from '../router';\nimport type { AnvilClientConfig } from '../client/factory';\n\nexport const trpc = createTRPCReact<AppRouter>();\n\nexport interface AnvilClientProviderProps {\n config: AnvilClientConfig;\n children: ReactNode;\n}\n\n/**\n * The Anvil tRPC client.\n *\n * History note: earlier versions of this provider used\n * `splitLink({ true: wsLink(...), false: httpBatchLink(...) })` so\n * subscription procedures would multiplex over a single WebSocket.\n * That setup opened a WebSocket on every mount, retried\n * indefinitely against `ws://localhost:3001/v1` (no real WS in dev),\n * spammed the console with \"ws connection error\", and held onto\n * EventSource handles that the GC couldn't free -- a noticeable\n * memory leak on the launcher tab.\n *\n * The router now has zero `subscription` procedures\n * (chat.subscribeChannel / social.presence.get are queries with\n * client-side polling, per Phase 5b / 6c). When real subscriptions\n * land, they should use a *dedicated* WS gateway with explicit\n * connect-on-subscribe semantics (tRPC v11 `createWSClient({ lazy: true })`)\n * so a tab with no active subscription never opens a socket.\n *\n * This scaffold uses `httpLink` (one request per call) instead of\n * `httpBatchLink`. Reason: the MSW dev layer returns a single\n * response object per registered handler. tRPC v11's batched GET\n * format (`?batch=1&input=...`) expects an array response\n * (`[{ result: { data } }, ...]`) and the dev path doesn't emit\n * that shape. Single-call links avoid the entire mismatch and keep\n * the dev path simple. When `apps/api` is wired, swapping back\n * to `httpBatchLink({ maxItems: 10 })` is a one-line change.\n */\nexport interface AnvilClientProviderProps {\n config: AnvilClientConfig;\n children: ReactNode;\n /**\n * Optional custom fetch for the in-process dev mock. When\n * provided, the tRPC client uses this fetch instead of the\n * real network. Production callers leave this undefined; the\n * `apps/web` dev bridge passes its own implementation.\n */\n devFetch?: typeof fetch;\n}\n\n/**\n * The Anvil tRPC client.\n *\n * History note: earlier versions of this provider used\n * `splitLink({ true: wsLink(...), false: httpBatchLink(...) })` so\n * subscription procedures would multiplex over a single WebSocket.\n * That setup opened a WebSocket on every mount, retried\n * indefinitely against `ws://localhost:3001/v1` (no real WS in dev),\n * spammed the console with \"ws connection error\", and held onto\n * EventSource handles that the GC couldn't free -- a noticeable\n * memory leak on the launcher tab.\n *\n * The router now has zero `subscription` procedures\n * (chat.subscribeChannel / social.presence.get are queries with\n * client-side polling, per Phase 5b / 6c). When real subscriptions\n * land, they should use a *dedicated* WS gateway with explicit\n * connect-on-subscribe semantics (tRPC v11 `createWSClient({ lazy: true })`)\n * so a tab with no active subscription never opens a socket.\n *\n * This scaffold uses `httpLink` with the default JSON transformer\n * (no superjson). For the dev renderer, a `devFetch` override\n * routes every request through the in-process mock registry in\n * `apps/web/src/lib/anvil-api/dev-fetch.ts`, bypassing the MSW\n * service worker entirely (which had wire-format issues with\n * tRPC v11's GET-batched queries).\n */\nexport function AnvilClientProvider({ config, children, devFetch }: AnvilClientProviderProps) {\n const [queryClient] = useState(\n () =>\n new QueryClient({\n defaultOptions: {\n queries: {\n staleTime: 5 * 60 * 1000,\n retry: 1,\n refetchOnWindowFocus: false,\n },\n },\n }),\n );\n\n const [trpcClient] = useState(() =>\n trpc.createClient({\n links: [\n httpLink({\n url: config.baseUrl,\n headers: async () => {\n const token = await config.getToken();\n return token ? { authorization: `Bearer ${token}` } : {};\n },\n fetch: devFetch,\n }),\n ],\n }),\n );\n\n return (\n <trpc.Provider client={trpcClient} queryClient={queryClient}>\n <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>\n </trpc.Provider>\n );\n}\n\nexport const useAnvilClient = trpc.useContext;\n"]}
|