@kubun/service-graph-api 0.15.0 → 0.16.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.
Files changed (2) hide show
  1. package/lib/handlers.js +14 -7
  2. package/package.json +18 -18
package/lib/handlers.js CHANGED
@@ -72,8 +72,9 @@ export function createGraphHandlers(params) {
72
72
  if (ctx.param.mutations != null) {
73
73
  // Pre-signed mode: client submitted JWT tokens keyed by GraphQL field alias
74
74
  const mutations = ctx.param.mutations;
75
- const keys = Object.keys(mutations);
76
- const tokens = keys.map((k)=>mutations[k]);
75
+ const entries = Object.entries(mutations);
76
+ const keys = entries.map(([key])=>key);
77
+ const tokens = entries.map(([, token])=>token);
77
78
  // Apply all mutations atomically via engine primitive. A
78
79
  // capability-check failure throws `WriteAccessDeniedError` from the
79
80
  // apply path; translate it into a GraphQL-shaped result so the wire
@@ -106,12 +107,12 @@ export function createGraphHandlers(params) {
106
107
  // mode does not configure an accessGate, so every result here carries
107
108
  // a non-null `document`.
108
109
  const mutatedDocuments = {};
109
- for(let i = 0; i < keys.length; i++){
110
- const doc = results[i].document;
110
+ for (const [i, key] of keys.entries()){
111
+ const doc = results[i]?.document;
111
112
  if (doc == null) {
112
113
  throw new Error('Unexpected dropped mutation in pre-signed apply (no gate configured)');
113
114
  }
114
- mutatedDocuments[keys[i]] = doc;
115
+ mutatedDocuments[key] = doc;
115
116
  }
116
117
  // Execute GraphQL with overridden mutation executors that return pre-applied results.
117
118
  // contextExtensions overrides the engine's default executors via shallow merge.
@@ -146,6 +147,12 @@ export function createGraphHandlers(params) {
146
147
  throw new Error('Delegated mutations require a SigningIdentity on the engine');
147
148
  }
148
149
  const transactionID = ctx.param.transactionID ?? null;
150
+ // Client may request an explicit document owner distinct from the signed
151
+ // viewer (e.g. a controller root the device is delegated to write for).
152
+ // The engine's write-access check gates it: when owner != signer, apply
153
+ // requires a delegation from `owner` for `document/write`. Omitting owner
154
+ // preserves the historical owner = viewerDID behavior.
155
+ const owner = ctx.param.owner ?? viewerDID;
149
156
  // Non-transaction delegated: engine.mutateGraph() handles signing internally
150
157
  if (transactionID == null) {
151
158
  const result = await engine.mutateGraph({
@@ -153,7 +160,7 @@ export function createGraphHandlers(params) {
153
160
  text: ctx.param.text,
154
161
  variables: ctx.param.variables ?? {},
155
162
  viewerDID,
156
- owner: viewerDID
163
+ owner
157
164
  });
158
165
  return toGraphResult(result);
159
166
  }
@@ -189,7 +196,7 @@ export function createGraphHandlers(params) {
189
196
  issuer: signingIdentity.id,
190
197
  hlc,
191
198
  getRandomValues,
192
- owner: viewerDID,
199
+ owner,
193
200
  async processSetMutation (mutation) {
194
201
  return await signAndBuffer(mutation);
195
202
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubun/service-graph-api",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "keywords": [],
5
5
  "license": "see LICENSE.md",
6
6
  "sideEffects": false,
@@ -17,29 +17,29 @@
17
17
  "dependencies": {
18
18
  "@enkaku/server": "^0.21.2",
19
19
  "@kokuin/token": "^0.5.0",
20
- "@kubun/engine": "^0.15.0",
21
- "@kubun/hlc": "^0.15.0",
22
- "@kubun/id": "^0.15.0",
23
- "@kubun/mutation": "^0.15.0",
24
- "@kubun/plugin-service-api": "^0.15.0",
25
- "@kubun/protocol": "^0.15.0",
20
+ "@kubun/engine": "^0.16.0",
21
+ "@kubun/hlc": "^0.16.0",
22
+ "@kubun/id": "^0.16.0",
23
+ "@kubun/mutation": "^0.16.0",
24
+ "@kubun/plugin-service-api": "^0.16.0",
25
+ "@kubun/protocol": "^0.16.1",
26
26
  "@sozai/generator": "^0.2.0",
27
27
  "@sozai/runtime": "^0.1.0",
28
28
  "graphql": "^16.14.2"
29
29
  },
30
30
  "devDependencies": {
31
- "@enkaku/client": "^0.21.1",
31
+ "@enkaku/client": "^0.21.2",
32
32
  "@enkaku/transport": "^0.21.0",
33
33
  "@kokuin/capability": "^0.3.0",
34
34
  "@kokuin/controller": "^0.1.0",
35
- "@kubun/client": "^0.15.0",
36
- "@kubun/db": "^0.15.0",
37
- "@kubun/plugin-service-server": "^0.15.0",
38
- "@kubun/store-controller": "^0.15.0",
39
- "@kubun/store-delegation": "^0.15.0",
40
- "@kubun/store-graph": "^0.15.0",
41
- "@kubun/store-p2p": "^0.15.0",
42
- "@kubun/test-utils": "^0.13.0"
35
+ "@kubun/client": "^0.16.0",
36
+ "@kubun/db": "^0.16.0",
37
+ "@kubun/plugin-service-server": "^0.16.0",
38
+ "@kubun/store-controller": "^0.16.0",
39
+ "@kubun/store-delegation": "^0.16.0",
40
+ "@kubun/store-graph": "^0.16.0",
41
+ "@kubun/store-p2p": "^0.16.0",
42
+ "@kubun/test-utils": "^0.0.0"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"
@@ -47,8 +47,8 @@
47
47
  "scripts": {
48
48
  "build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
49
49
  "build:clean": "del lib",
50
- "build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
51
- "build:types": "tsc --emitDeclarationOnly --skipLibCheck",
50
+ "build:js": "del 'lib/**/*.js' && swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
51
+ "build:types": "del 'lib/**/*.d.ts' 'lib/**/*.d.ts.map' && tsc --emitDeclarationOnly --skipLibCheck",
52
52
  "build:types:ci": "tsc --emitDeclarationOnly --declarationMap false",
53
53
  "test": "pnpm run test:types && pnpm run test:unit",
54
54
  "test:types": "tsc --noEmit -p tsconfig.test.json",