@orderlyshop/core-client 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,105 @@
1
+ # `@orderlyshop/core-client`
2
+
3
+ TypeScript client for the Orderly core gRPC API.
4
+
5
+ The package is generated from the protobuf contracts in `../../../../interface` and supports:
6
+
7
+ - binary gRPC in Node.js
8
+ - gRPC-web in browsers
9
+ - API key, bearer token, and browser cookie-backed authentication flows
10
+ - memory-only token storage by default
11
+ - non-secret browser identity hints in localStorage
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @orderlyshop/core-client
17
+ ```
18
+
19
+ ## Browser gRPC-web
20
+
21
+ ```ts
22
+ import { createOrderlyWebClient } from "@orderlyshop/core-client/web";
23
+
24
+ const orderly = createOrderlyWebClient({
25
+ baseUrl: "https://api.orderly.example"
26
+ });
27
+
28
+ await orderly.auth.authenticateWithSmsChallenge({
29
+ phoneNumber: { CountryCode: "45", Number: "12345678" },
30
+ code: "123456"
31
+ });
32
+
33
+ const login = await orderly.getCurrentLogin();
34
+ ```
35
+
36
+ Browser clients use `credentials: "include"` by default. If the backend sets an `HttpOnly; Secure; SameSite=None; Partitioned` cookie in a gRPC-web auth response, the browser can persist the server session without exposing the cookie to JavaScript. The client library does not read or manage that cookie.
37
+
38
+ The cookie value should be an opaque server-side session key, not an OAuth token. A recommended server cookie shape is:
39
+
40
+ ```http
41
+ Set-Cookie: __Host-Http-orderly_session=<opaque-session-id>; Path=/; Secure; HttpOnly; SameSite=None; Partitioned; Max-Age=...
42
+ ```
43
+
44
+ CHIPS cookie persistence depends on browser support. Recent Chrome, Edge, Firefox, and iOS Safari 26.2+ have strong support, but older browsers may fall back to page-lifetime bearer auth unless the application provides its own `TokenStore`.
45
+
46
+ ## Node binary gRPC
47
+
48
+ ```ts
49
+ import { createOrderlyNodeClient } from "@orderlyshop/core-client/node";
50
+
51
+ const orderly = createOrderlyNodeClient({
52
+ baseUrl: "https://api.orderly.example",
53
+ auth: { type: "apiKey", apiKey: process.env.ORDERLY_API_KEY! }
54
+ });
55
+
56
+ const login = await orderly.getCurrentLogin();
57
+ ```
58
+
59
+ ## Authentication Storage
60
+
61
+ The default `TokenStore` is memory-only. It does not persist access tokens, refresh tokens, API keys, or full OAuth responses to Web Storage, IndexedDB, cookies, files, or logs.
62
+
63
+ You can provide a custom token store when you intentionally accept the persistence tradeoff:
64
+
65
+ ```ts
66
+ import type { TokenStore } from "@orderlyshop/core-client";
67
+
68
+ const tokenStore: TokenStore = {
69
+ get: async () => undefined,
70
+ set: async (token) => {
71
+ // Store only in an application-owned secure location.
72
+ },
73
+ clear: async () => {}
74
+ };
75
+ ```
76
+
77
+ Browser identity hints are separate from authentication. The default browser identity store may cache only:
78
+
79
+ - `userId`
80
+ - `displayName`
81
+ - `updatedAt`
82
+
83
+ This cache is for UI only. It must not be used as proof of authentication; call `getCurrentLogin()` or another protected RPC to verify the server session.
84
+
85
+ `clearAuth()` clears the configured token store and identity store. It cannot clear server-managed `HttpOnly` cookies from JavaScript; use a server-side logout endpoint or RPC when that feature is available.
86
+
87
+ ## Updating Protobuf Contracts
88
+
89
+ Regenerate generated TypeScript and bump the package minor version:
90
+
91
+ ```sh
92
+ npm run update:proto
93
+ ```
94
+
95
+ Preview the update without mutating package metadata:
96
+
97
+ ```sh
98
+ npm run update:proto -- --dry-run
99
+ ```
100
+
101
+ For breaking contract releases:
102
+
103
+ ```sh
104
+ npm run update:proto -- --major
105
+ ```