@foir/sdk 0.7.0 → 0.8.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/CHANGELOG.md +805 -4
- package/README.md +46 -15
- package/dist/auth/auth.d.ts +104 -1
- package/dist/auth/index.d.ts +12 -6
- package/dist/auth/operations.d.ts +85 -64
- package/dist/auth/ops.d.ts +99 -0
- package/dist/auth.js +775 -106
- package/dist/chunk-IGNLWT3H.js +35 -0
- package/dist/chunk-OHYVKTGB.js +45 -0
- package/dist/chunk-TAL5H6VA.js +39 -0
- package/dist/client.js +25 -31
- package/dist/codegen/block-registry.d.ts +13 -19
- package/dist/codegen/block-registry.js +3 -31
- package/dist/codegen/block-scaffold.d.ts +12 -21
- package/dist/codegen/block-scaffold.js +3 -41
- package/dist/codegen/index.d.ts +9 -4
- package/dist/codegen/index.js +7 -11
- package/dist/codegen/item-registry.d.ts +28 -0
- package/dist/codegen/item-registry.js +7 -0
- package/dist/codegen/item-scaffold.d.ts +29 -0
- package/dist/codegen/item-scaffold.js +7 -0
- package/dist/codegen/preset.d.ts +14 -7
- package/dist/codegen/shared.d.ts +20 -9
- package/dist/content/content-renderer.d.ts +90 -24
- package/dist/content/index.d.ts +13 -7
- package/dist/content/richtext.d.ts +66 -18
- package/dist/content.js +227 -80
- package/dist/data/builtins.d.ts +302 -92
- package/dist/data/client.d.ts +97 -25
- package/dist/data/document.d.ts +251 -0
- package/dist/data/index.d.ts +38 -19
- package/dist/data/manifest.d.ts +266 -3
- package/dist/data/schema.d.ts +78 -8
- package/dist/data/selection.d.ts +231 -37
- package/dist/data/subjects.d.ts +221 -0
- package/dist/data/subscription-document.d.ts +75 -0
- package/dist/data/subscriptions.d.ts +181 -0
- package/dist/data/transport.d.ts +255 -37
- package/dist/data/ws-transport.d.ts +197 -0
- package/dist/data.js +1419 -45
- package/dist/graphql/cdn-route.d.ts +12 -28
- package/dist/media/index.d.ts +6 -2
- package/dist/media/media.d.ts +2 -2
- package/dist/media/screen-capture.d.ts +81 -0
- package/dist/media.js +97 -0
- package/dist/next.js +663 -182
- package/dist/push.js +700 -90
- package/dist/react/FoirFeedback.d.ts +62 -0
- package/dist/react/feedback-notes.d.ts +101 -0
- package/dist/react/index.d.ts +7 -1
- package/dist/react.js +1272 -194
- package/dist/realtime.js +1 -1
- package/dist/server/events-client.d.ts +279 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server.js +298 -0
- package/dist/transport/foir-http.d.ts +23 -6
- package/dist/transport/persisted-query.d.ts +68 -0
- package/dist/transport/retry.d.ts +1 -1
- package/package.json +13 -1
- package/dist/chunk-ADO5FJNM.js +0 -30
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatic persisted queries and the shared read lane — the `graphql`-free half
|
|
3
|
+
* of `graphql/cdn-route.ts`.
|
|
4
|
+
*
|
|
5
|
+
* Split out for the same reason `foir-http.ts` was split out of
|
|
6
|
+
* `graphql/foir-request.ts`: two surfaces need it and only one of them may
|
|
7
|
+
* import `graphql`. `@foir/sdk/client` prints a `TypedDocumentNode` and then
|
|
8
|
+
* hashes the text; `@foir/sdk/data` builds the text itself from a selection tree
|
|
9
|
+
* and must not drag the GraphQL parser into a storefront bundle. Everything
|
|
10
|
+
* below operates on a document STRING, so it belongs to neither.
|
|
11
|
+
*
|
|
12
|
+
* `graphql/cdn-route.ts` re-exports all of it unchanged, so that module's public
|
|
13
|
+
* surface is exactly what it always was; the only thing that stayed behind is
|
|
14
|
+
* the part that needs `print`.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The shared, cacheable read path. Same schema, same executor, same auth as
|
|
18
|
+
* `/graphql` — what differs is that a CDN in front of the caller can store the
|
|
19
|
+
* response, because the request is a GET and the credential is in the URL.
|
|
20
|
+
*/
|
|
21
|
+
export declare const FOIR_CDN_GRAPHQL_PATH = "/cdn/graphql";
|
|
22
|
+
/** The APQ handshake object, in Apollo's shape because every client uses it. */
|
|
23
|
+
export declare function persistedQueryExtension(hash: string): {
|
|
24
|
+
persistedQuery: {
|
|
25
|
+
version: number;
|
|
26
|
+
sha256Hash: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Build the shared-endpoint URL for a read.
|
|
31
|
+
*
|
|
32
|
+
* The credential goes in the URL deliberately: a shared cache keys on the URL
|
|
33
|
+
* alone, so a key that rode only in a header would let two callers with
|
|
34
|
+
* different reach collide on one entry and be served each other's body. The
|
|
35
|
+
* server enforces this and names the refusal `NOT_SHAREABLE` with
|
|
36
|
+
* `condition: "credential"` when the key arrives only as a header.
|
|
37
|
+
*/
|
|
38
|
+
export declare function buildCdnUrl(endpoint: string, apiKey: string, hash: string, variables?: unknown): string;
|
|
39
|
+
/**
|
|
40
|
+
* SHA-256 of the document text, hex encoded — the identity a persisted query is
|
|
41
|
+
* stored and retrieved under.
|
|
42
|
+
*
|
|
43
|
+
* Web Crypto rather than a bundled implementation: it is present in every
|
|
44
|
+
* runtime this SDK targets (workers, edge, Node 18+) and adds nothing to the
|
|
45
|
+
* caller's bundle. Reached through `globalThis`, never `import 'crypto'`, so
|
|
46
|
+
* the edge-safety assertion on `@foir/sdk/data`'s import graph still holds.
|
|
47
|
+
*/
|
|
48
|
+
export declare function documentHash(documentText: string): Promise<string>;
|
|
49
|
+
/** The code the server answers with when it has never seen this hash. */
|
|
50
|
+
export declare const PERSISTED_QUERY_NOT_FOUND = "PERSISTED_QUERY_NOT_FOUND";
|
|
51
|
+
/** The code the shared endpoint refuses with, so a caller knows to retry. */
|
|
52
|
+
export declare const NOT_SHAREABLE = "NOT_SHAREABLE";
|
|
53
|
+
/**
|
|
54
|
+
* Whether a response carries any of the handshake codes above.
|
|
55
|
+
*
|
|
56
|
+
* The response is CLONED before the body is read. A Response body can only be
|
|
57
|
+
* consumed once, and reading it here to inspect the code would leave the caller
|
|
58
|
+
* holding an empty stream on every successful read — turning a working fast
|
|
59
|
+
* path into silent data loss.
|
|
60
|
+
*
|
|
61
|
+
* Status is deliberately not part of the test. A persisted-query miss comes back
|
|
62
|
+
* **HTTP 200** with an errors array (verified against deployed dev), while a
|
|
63
|
+
* shareability refusal comes back 400; keying on the code alone reads both.
|
|
64
|
+
*
|
|
65
|
+
* Several codes at once rather than one call per code, because both callers ask
|
|
66
|
+
* about two and each call costs another clone and another parse of the same body.
|
|
67
|
+
*/
|
|
68
|
+
export declare function hasFoirErrorCode(res: Response, ...codes: string[]): Promise<boolean>;
|
|
@@ -54,7 +54,7 @@ export declare function foirRetryDelayMs(error: unknown, attempt: number, policy
|
|
|
54
54
|
* Run `fn`, retrying transient Foir failures.
|
|
55
55
|
*
|
|
56
56
|
* Deliberately takes a thunk rather than wrapping a specific request shape, so
|
|
57
|
-
* the same policy covers `/graphql
|
|
57
|
+
* the same policy covers `/graphql`, `/cdn/graphql` and anything either grows
|
|
58
58
|
* later. Non-Foir errors propagate untouched on the first throw — this is not a
|
|
59
59
|
* general-purpose retry helper and should not become one.
|
|
60
60
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foir/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Official Foir SDK — editor iframe client + server-side platform helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -61,6 +61,14 @@
|
|
|
61
61
|
"types": "./dist/codegen/index.d.ts",
|
|
62
62
|
"import": "./dist/codegen/index.js"
|
|
63
63
|
},
|
|
64
|
+
"./codegen/item-registry": {
|
|
65
|
+
"types": "./dist/codegen/item-registry.d.ts",
|
|
66
|
+
"import": "./dist/codegen/item-registry.js"
|
|
67
|
+
},
|
|
68
|
+
"./codegen/item-scaffold": {
|
|
69
|
+
"types": "./dist/codegen/item-scaffold.d.ts",
|
|
70
|
+
"import": "./dist/codegen/item-scaffold.js"
|
|
71
|
+
},
|
|
64
72
|
"./codegen/block-registry": {
|
|
65
73
|
"types": "./dist/codegen/block-registry.d.ts",
|
|
66
74
|
"import": "./dist/codegen/block-registry.js"
|
|
@@ -128,16 +136,20 @@
|
|
|
128
136
|
},
|
|
129
137
|
"devDependencies": {
|
|
130
138
|
"@graphql-codegen/cli": "^5.0.7",
|
|
139
|
+
"@testing-library/react": "^16.2.0",
|
|
131
140
|
"@types/react": "^19.2.0",
|
|
132
141
|
"@types/react-dom": "^19.2.0",
|
|
142
|
+
"@types/ws": "^8.5.13",
|
|
133
143
|
"blurhash": "^2.0.5",
|
|
134
144
|
"graphql": "^16.10.0",
|
|
135
145
|
"hls.js": "^1.6.16",
|
|
146
|
+
"jsdom": "^27.0.0",
|
|
136
147
|
"react": "^19.2.0",
|
|
137
148
|
"react-dom": "^19.2.0",
|
|
138
149
|
"tsup": "^8.5.1",
|
|
139
150
|
"typescript": "5.9.2",
|
|
140
151
|
"vitest": "^3.2.4",
|
|
152
|
+
"ws": "^8.18.0",
|
|
141
153
|
"y-websocket": "^3.0.0",
|
|
142
154
|
"yjs": "^13.6.30"
|
|
143
155
|
},
|
package/dist/chunk-ADO5FJNM.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/codegen/shared.ts
|
|
2
|
-
import { isUnionType } from "graphql";
|
|
3
|
-
var DEFAULT_UNIONS = ["Block"];
|
|
4
|
-
var DEFAULT_GRAPHQL_IMPORT = "./graphql";
|
|
5
|
-
var DEFAULT_SDK_IMPORT = "@foir/sdk/content";
|
|
6
|
-
function collectBlockMembers(schema, unionNames) {
|
|
7
|
-
const members = /* @__PURE__ */ new Set();
|
|
8
|
-
const missing = [];
|
|
9
|
-
for (const name of unionNames) {
|
|
10
|
-
const type = schema.getType(name);
|
|
11
|
-
if (!type || !isUnionType(type)) {
|
|
12
|
-
missing.push(name);
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
for (const member of type.getTypes()) members.add(member.name);
|
|
16
|
-
}
|
|
17
|
-
if (members.size === 0) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
`[foir codegen] no union members found. Looked for union(s): ${unionNames.join(", ")}` + (missing.length ? ` (not found or not a union: ${missing.join(", ")})` : "") + `. Run \`foir push\` and confirm the block union name.`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return [...members].sort();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
DEFAULT_UNIONS,
|
|
27
|
-
DEFAULT_GRAPHQL_IMPORT,
|
|
28
|
-
DEFAULT_SDK_IMPORT,
|
|
29
|
-
collectBlockMembers
|
|
30
|
-
};
|