@cosmicdrift/kumiko-bundled-features 0.55.1 → 0.56.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-bundled-features",
3
- "version": "0.55.1",
3
+ "version": "0.56.0",
4
4
  "description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -80,11 +80,11 @@
80
80
  "./step-dispatcher": "./src/step-dispatcher/index.ts"
81
81
  },
82
82
  "dependencies": {
83
- "@cosmicdrift/kumiko-dispatcher-live": "0.50.0",
84
- "@cosmicdrift/kumiko-framework": "0.50.0",
85
- "@cosmicdrift/kumiko-headless": "0.50.0",
86
- "@cosmicdrift/kumiko-renderer": "0.50.0",
87
- "@cosmicdrift/kumiko-renderer-web": "0.50.0",
83
+ "@cosmicdrift/kumiko-dispatcher-live": "0.55.1",
84
+ "@cosmicdrift/kumiko-framework": "0.55.1",
85
+ "@cosmicdrift/kumiko-headless": "0.55.1",
86
+ "@cosmicdrift/kumiko-renderer": "0.55.1",
87
+ "@cosmicdrift/kumiko-renderer-web": "0.55.1",
88
88
  "@mollie/api-client": "^4.5.0",
89
89
  "@node-rs/argon2": "^2.0.2",
90
90
  "@types/nodemailer": "^8.0.0",
@@ -22,6 +22,7 @@ export const ConfigErrors = {
22
22
  unknownKey: "unknown_config_key",
23
23
  systemOnly: "config_key_is_system_only",
24
24
  invalidScope: "invalid_scope",
25
+ systemScopeWriteDenied: "system_scope_write_denied",
25
26
  typeError: "type_error",
26
27
  invalidOption: "invalid_option",
27
28
  } as const;
@@ -184,6 +184,33 @@ describe("prepareConfigWrite", () => {
184
184
  expect(result.tenantId).toBe("t-99");
185
185
  expect(result.userId).toBe("u-99");
186
186
  });
187
+
188
+ test("TenantAdmin cannot write tenant-scoped key at system scope (platform default row)", () => {
189
+ const tenantKey = createTenantConfig("text", { write: access.admin });
190
+ const result = prepareConfigWrite({
191
+ registry: registryStub({ "ns:config:smtp-host": tenantKey }),
192
+ user: userStub(["TenantAdmin"]),
193
+ key: "ns:config:smtp-host",
194
+ scope: ConfigScopes.system,
195
+ });
196
+ expect(result.ok).toBe(false);
197
+ if (result.ok) throw new Error("unreachable");
198
+ expect(result.failure.error.code).toBe("access_denied");
199
+ expect(result.failure.error.i18nKey).toBe("config.errors.systemScopeWriteDenied");
200
+ });
201
+
202
+ test("SystemAdmin can write tenant-scoped key at system scope", () => {
203
+ const tenantKey = createTenantConfig("text", { write: access.admin });
204
+ const result = prepareConfigWrite({
205
+ registry: registryStub({ "ns:config:smtp-host": tenantKey }),
206
+ user: userStub(["SystemAdmin"], SYSTEM_TENANT_ID, "sys-1"),
207
+ key: "ns:config:smtp-host",
208
+ scope: ConfigScopes.system,
209
+ });
210
+ expect(result.ok).toBe(true);
211
+ if (!result.ok) throw new Error("unreachable");
212
+ expect(result.scope).toBe(ConfigScopes.system);
213
+ });
187
214
  });
188
215
 
189
216
  describe("validateBounds", () => {
@@ -101,6 +101,9 @@ export function prepareConfigWrite(args: PrepareConfigWriteArgs): PrepareConfigW
101
101
  if (writeError) return { ok: false, failure: writeFailure(writeError) };
102
102
 
103
103
  const scope = requestedScope ?? keyDef.scope;
104
+ const scopeWriteError = checkScopeWriteAccess(scope, user.roles);
105
+ if (scopeWriteError) return { ok: false, failure: writeFailure(scopeWriteError) };
106
+
104
107
  const { tenantId, userId } = resolveScopeIds(scope, user.tenantId, user.id);
105
108
  return { ok: true, keyDef, scope, tenantId, userId };
106
109
  }
@@ -141,6 +144,24 @@ export function checkWriteAccess(
141
144
  });
142
145
  }
143
146
 
147
+ /**
148
+ * Level-aware write gate: writing the system-row (platform default) requires
149
+ * SystemAdmin even when the key's flat write-set includes TenantAdmin.
150
+ */
151
+ export function checkScopeWriteAccess(
152
+ scope: ConfigScope,
153
+ userRoles: readonly string[],
154
+ ): KumikoError | null {
155
+ if (scope !== ConfigScopes.system) return null;
156
+ if (userRoles.includes(SYSTEM_ROLE)) return null;
157
+ if (userRoles.includes("SystemAdmin")) return null;
158
+ return new AccessDeniedError({
159
+ message: "system-scope config write requires SystemAdmin",
160
+ i18nKey: "config.errors.systemScopeWriteDenied",
161
+ details: { reason: ConfigErrors.systemScopeWriteDenied, scope },
162
+ });
163
+ }
164
+
144
165
  export function validateScope(
145
166
  requestedScope: ConfigScope,
146
167
  definedScope: ConfigScope,