@tangen/graphql 0.1.27 → 0.1.29
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.js +18 -0
- package/dist/resolvers.d.ts +13 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -892,6 +892,8 @@ function createRequestContext(input) {
|
|
|
892
892
|
canWrite: input.canWrite ?? (() => false),
|
|
893
893
|
canReadDrafts: input.canReadDrafts ?? (() => false),
|
|
894
894
|
canPublish: input.canPublish ?? (() => false),
|
|
895
|
+
canReadTable: input.canReadTable ?? (() => false),
|
|
896
|
+
canReadGlobals: input.canReadGlobals ?? (() => false),
|
|
895
897
|
loaders: createBatchLoaders(input.client, input.canRead),
|
|
896
898
|
...input.realtime ? { realtime: input.realtime } : {}
|
|
897
899
|
};
|
|
@@ -910,6 +912,20 @@ function requireDraftRead(ctx, type) {
|
|
|
910
912
|
});
|
|
911
913
|
}
|
|
912
914
|
}
|
|
915
|
+
function requireReadTable(ctx, name) {
|
|
916
|
+
if (!ctx.canReadTable?.(name)) {
|
|
917
|
+
throw new GraphQLError3(`You do not have permission to read table '${name}'`, {
|
|
918
|
+
extensions: { code: "FORBIDDEN" }
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function requireReadGlobals(ctx, name) {
|
|
923
|
+
if (!ctx.canReadGlobals?.(name)) {
|
|
924
|
+
throw new GraphQLError3(`You do not have permission to read global '${name}'`, {
|
|
925
|
+
extensions: { code: "FORBIDDEN" }
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
913
929
|
function requirePublish(ctx, type) {
|
|
914
930
|
if (!ctx.canPublish || !ctx.canPublish(type)) {
|
|
915
931
|
throw new GraphQLError3(`You do not have permission to publish '${type}'`, {
|
|
@@ -1017,6 +1033,7 @@ function createResolvers() {
|
|
|
1017
1033
|
return { data: rows, meta: { total: rows.length, limit: rows.length, offset: 0, nextCursor: null } };
|
|
1018
1034
|
};
|
|
1019
1035
|
const table = (name) => async (_parent, args, ctx) => {
|
|
1036
|
+
requireReadTable(ctx, name);
|
|
1020
1037
|
if (!ctx.client.table)
|
|
1021
1038
|
return { data: [], meta: { total: 0 } };
|
|
1022
1039
|
let b = ctx.client.table(name).where(args.where ?? {});
|
|
@@ -1030,6 +1047,7 @@ function createResolvers() {
|
|
|
1030
1047
|
return { data: res.data ?? [], meta: res.meta ?? { total: (res.data ?? []).length } };
|
|
1031
1048
|
};
|
|
1032
1049
|
const global = () => async (_parent, args, ctx) => {
|
|
1050
|
+
requireReadGlobals(ctx, String(args.name));
|
|
1033
1051
|
if (!ctx.client.globals)
|
|
1034
1052
|
return null;
|
|
1035
1053
|
return ctx.client.globals(String(args.name)).get();
|
package/dist/resolvers.d.ts
CHANGED
|
@@ -29,6 +29,15 @@ export interface GraphqlRequestContext {
|
|
|
29
29
|
/** K0: publish, unpublish and preflight need objects:publish, not a write grant. */
|
|
30
30
|
canPublish?: (typeName: string) => boolean;
|
|
31
31
|
canReadDrafts?: (typeName: string) => boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Custom tables and globals have their own permission families, and until
|
|
34
|
+
* 2026-10-23 these two fields had NO gate here at all while REST asserted
|
|
35
|
+
* one - so an API key with no `tables` block was refused by
|
|
36
|
+
* `GET/POST /tables/:name` and served the same rows by GraphQL. Absent means
|
|
37
|
+
* denied, which is the same default `canWrite` takes.
|
|
38
|
+
*/
|
|
39
|
+
canReadTable?: (tableName: string) => boolean;
|
|
40
|
+
canReadGlobals?: (name: string) => boolean;
|
|
32
41
|
loaders: BatchLoaders;
|
|
33
42
|
/** Realtime R5: present only on the WebSocket adapter; subscription fields refuse without it. */
|
|
34
43
|
realtime?: RealtimeSubscriber;
|
|
@@ -43,6 +52,10 @@ export declare function createRequestContext(input: {
|
|
|
43
52
|
canReadDrafts?: (typeName: string) => boolean;
|
|
44
53
|
/** Absent ⇒ publish, unpublish and preflight denied (objects:publish). */
|
|
45
54
|
canPublish?: (typeName: string) => boolean;
|
|
55
|
+
/** Absent ⇒ custom-table reads denied (tables:read). */
|
|
56
|
+
canReadTable?: (tableName: string) => boolean;
|
|
57
|
+
/** Absent ⇒ globals reads denied (globals:read). */
|
|
58
|
+
canReadGlobals?: (name: string) => boolean;
|
|
46
59
|
/** Realtime R5: the per-connection subscriber the WebSocket adapter installs; absent over POST. */
|
|
47
60
|
realtime?: RealtimeSubscriber;
|
|
48
61
|
}): GraphqlRequestContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangen/graphql",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.29",
|
|
4
4
|
"description": "GraphQL API for Tangen CMS — a schema generated from your content model. Optional: install only when you enable GraphQL.",
|
|
5
5
|
"homepage": "https://github.com/raghunathj/tangen#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"test": "bun test"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tangen/types": "^0.
|
|
40
|
+
"@tangen/types": "^0.6.0",
|
|
41
41
|
"graphql": "^17.0.0"
|
|
42
42
|
},
|
|
43
43
|
"exports": {
|