@usegraft/sdk-react 0.2.0 → 1.0.0-beta.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/dist/index.d.ts +7 -1
- package/dist/index.js +22 -3
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,13 @@ export { AnyCollection, ChangeSet, ClientOptions, Document, GraftClient, ListOpt
|
|
|
3
3
|
import { ReactNode, ReactElement } from 'react';
|
|
4
4
|
export { ContentApiReaderOptions, createContentApiReader } from '@usegraft/content-api';
|
|
5
5
|
|
|
6
|
-
interface GraftOptions<TCollections extends Record<string, AnyCollection>> extends Omit<ClientOptions<TCollections>, "
|
|
6
|
+
interface GraftOptions<TCollections extends Record<string, AnyCollection>> extends Omit<ClientOptions<TCollections>, "index"> {
|
|
7
|
+
/**
|
|
8
|
+
* Your own reader, when `endpoint` is not enough. Optional here because
|
|
9
|
+
* `endpoint` is the ordinary way to configure this package, and exactly one
|
|
10
|
+
* of the two is required.
|
|
11
|
+
*/
|
|
12
|
+
index?: ClientOptions<TCollections>["index"];
|
|
7
13
|
/** Content API base URL, e.g. `https://cms.example.com/api/content/v1`. */
|
|
8
14
|
endpoint?: string | URL;
|
|
9
15
|
/** Static headers sent with every read, such as `Authorization`. */
|
package/dist/index.js
CHANGED
|
@@ -35,11 +35,30 @@ function createGraft(options) {
|
|
|
35
35
|
collections: options.collections,
|
|
36
36
|
branch: options.branch
|
|
37
37
|
});
|
|
38
|
+
const endpointPinned = options.endpoint !== void 0;
|
|
39
|
+
function assertNoBranch(opts) {
|
|
40
|
+
if (!endpointPinned || opts?.branch === void 0) return;
|
|
41
|
+
throw new GraftError({
|
|
42
|
+
code: "CONFIG_INVALID",
|
|
43
|
+
message: "`branch` cannot be passed to a read on an endpoint-backed handle.",
|
|
44
|
+
fix: "Each content API endpoint serves exactly one branch, fixed by the server, and the branch query param is refused. Point a second handle at the preview's own endpoint instead of asking this one for a branch.",
|
|
45
|
+
details: { branch: opts.branch, endpoint: String(options.endpoint) }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
38
48
|
return {
|
|
39
49
|
client,
|
|
40
|
-
getContent
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
async getContent(collection, slug, opts) {
|
|
51
|
+
assertNoBranch(opts);
|
|
52
|
+
return client.getDocument(collection, slug, opts);
|
|
53
|
+
},
|
|
54
|
+
async listContent(collection, opts) {
|
|
55
|
+
assertNoBranch(opts);
|
|
56
|
+
return client.listDocuments(collection, opts);
|
|
57
|
+
},
|
|
58
|
+
async searchContent(collection, query, opts) {
|
|
59
|
+
assertNoBranch(opts);
|
|
60
|
+
return client.searchDocuments(collection, query, opts);
|
|
61
|
+
}
|
|
43
62
|
};
|
|
44
63
|
}
|
|
45
64
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usegraft/sdk-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0-beta.0",
|
|
4
4
|
"description": "React browser client: typed content reads and hooks over Graft's read-only content API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@usegraft/content-api": "0.
|
|
42
|
-
"@usegraft/contracts": "0.
|
|
43
|
-
"@usegraft/sdk-core": "0.
|
|
41
|
+
"@usegraft/content-api": "1.0.0-beta.0",
|
|
42
|
+
"@usegraft/contracts": "1.0.0-beta.0",
|
|
43
|
+
"@usegraft/sdk-core": "1.0.0-beta.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@testing-library/react": "^16.3.0",
|
|
47
47
|
"@types/react": "^19.0.0",
|
|
48
48
|
"@types/react-dom": "^19.0.0",
|
|
49
|
-
"@usegraft/core": "0.
|
|
49
|
+
"@usegraft/core": "1.0.0-beta.0",
|
|
50
50
|
"jsdom": "^25.0.1",
|
|
51
51
|
"react": "^19.0.0",
|
|
52
52
|
"react-dom": "^19.0.0"
|