openxiangda 1.0.143 → 1.0.144

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/README.md CHANGED
@@ -365,7 +365,7 @@ const PublicAccessError = ({ error }: { error: { message?: string } }) => (
365
365
 
366
366
  多表只读查询和固定口径统计优先声明 `src/resources/data-views/*.json` 数据视图,而不是在页面里手写多次单表查询再拼数据。默认 `storageMode: "materialized"` 会创建 PostgreSQL materialized view,适合读多写少和可接受刷新延迟的列表/报表;`storageMode: "live"` 每次查询实时编译逻辑视图,适合强实时但数据量可控的复杂查询。`viewType: "aggregate"` 是统计聚合视图,适合按客户、状态、月份等维度聚合 count/sum/avg/min/max。发布时 CLI 会把 `formCode` 解析为当前 profile 的 `formUuid`;页面通过 `sdk.dataView.query(code, params)` 查询行级视图,通过 `sdk.dataView.stats(code, params)` 查询聚合视图,也可以用 `sdk.dataSource.run()` 路由 `dataView.query` / `dataView.stats`。materialized 模式应为常用筛选、排序、统计维度和时间桶声明 `indexes`,并确认用户能接受的刷新延迟;live 模式忽略 `indexes`,不需要刷新。
367
367
 
368
- 后端业务逻辑优先声明为 App Function:源码放在 `src/functions/<functionCode>/index.ts`,资源 manifest 放在 `src/resources/functions/<functionCode>.json`。函数运行在 trusted_node 中,通过 `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`、`ctx.dataView`、`ctx.connector`、`ctx.notification`、`ctx.organization`、`ctx.platform.api` 等受控 API 访问平台能力;自动化、流程和运行时接口都可以调用同一个 function。运行时页面调用会在 `ctx.operator`、`ctx.currentUser`、`ctx.permissions` 中注入可信的 `roleCodes`、`currentRoleCode`、`hasFullAccess`、`isAppAdmin`、`isPlatformAdmin`,敏感动作必须读取这些服务端上下文做授权,不要信任页面 input 里传入的角色字段。`ctx.form.createOne/updateOne/updateById` 是后端受控写入,授权边界是函数 manifest 的 `resources.forms` 绑定和函数调用授权,不是页面用户对目标表单的直接提交入口;报名、签到、福利选择等内部多表写入应走 App Function,不要为了写内部表单给普通用户开放原始 submit 权限。JS_CODE V2 仍兼容,但新逻辑建议写成 function,再由 `function_call` 节点、`sdk.function.invoke(code, { input })` 或 `/:appType/v1/functions/:code/invoke.json` 调用。直接运行时接口默认要求调用者具备应用自动化管理权限;如果普通应用角色需要从页面调用,必须在函数 `definitionJson.runtimeInvoke.roleCodes` 显式声明允许的当前应用角色。自动化/流程内部调用走服务端受控上下文。
368
+ 后端业务逻辑优先声明为 App Function:源码放在 `src/functions/<functionCode>/index.ts`,资源 manifest 放在 `src/resources/functions/<functionCode>.json`。函数运行在 trusted_node 中,通过 `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`、`ctx.dataView`、`ctx.connector`、`ctx.notification`、`ctx.organization`、`ctx.platform.api` 等受控 API 访问平台能力;自动化、流程和运行时接口都可以调用同一个 function。运行时页面调用会在 `ctx.operator`、`ctx.currentUser`、`ctx.permissions` 中注入可信的 `roleCodes`、`currentRoleCode`、`hasFullAccess`、`isAppAdmin`、`isPlatformAdmin`,敏感动作必须读取这些服务端上下文做授权,不要信任页面 input 里传入的角色字段。`ctx.form.createOne/updateOne/updateById` 是后端受控写入,授权边界是函数 manifest 的 `resources.forms` 绑定和函数调用授权,不是页面用户对目标表单的直接提交入口;报名、签到、福利选择等内部多表写入应走 App Function,不要为了写内部表单给普通用户开放原始 submit 权限。JS_CODE V2 仍兼容,但新逻辑建议写成 function,再由 `function_call` 节点、`sdk.function.invoke(code, { input })` 或 `/:appType/v1/functions/:code/invoke.json` 调用。直接运行时接口默认要求调用者具备应用自动化管理权限;普通页面调用必须在函数 `definitionJson.runtimeInvoke.audience` 声明 `authenticated`、`page_permission_group`、`app_roles` 或 `scope_policy`,`roleCodes` 只用于当前应用角色精确匹配,不支持 `"*"` / `"all-app-roles"`。自动化/流程内部调用走服务端受控上下文。内部业务表单需要关闭原始写入接口时,在表单 settings 中设置 `runtimeWrite.mode="function_only"`。
369
369
 
370
370
  平台部门和账号管理走 app-scoped organization 能力。调用者必须在目标应用拥有 `app:organization:manage`;平台管理员天然可用,普通应用角色需要显式授权。Runtime service principal 不会直接放行,`ctx.organization` 会按真实操作人 / audit actor 校验权限。新接口只提供创建、更新、查询和密码专用操作,不提供删除;`account-update` 不能携带 `password`,重置他人密码必须走 `account-reset-password`,当前用户改密用 SDK / `ctx.organization.accounts.changeMyPassword({ oldPassword, newPassword })`。
371
371
 
package/lib/cli.js CHANGED
@@ -7009,6 +7009,7 @@ function validateResourceItem(kind, item, errors, warnings) {
7009
7009
  if (!item.definitionJson && !item.definitionFile) {
7010
7010
  errors.push(`${label}: 缺少 definitionJson 或 definitionFile`);
7011
7011
  }
7012
+ validateFunctionRuntimeInvoke(label, item, errors, warnings);
7012
7013
  }
7013
7014
  if (kind === 'dataViews') {
7014
7015
  const definition = item.definition || item;
@@ -7217,17 +7218,183 @@ function validateResourceItem(kind, item, errors, warnings) {
7217
7218
  if (!item.formCode && !item.formUuid && !item.code) {
7218
7219
  errors.push(`${label}: 缺少 formCode、formUuid 或 code`);
7219
7220
  }
7221
+ validateFormRuntimeWriteSettings(label, item, errors);
7220
7222
  if (
7221
7223
  item.settings === undefined &&
7222
7224
  item.indexes === undefined &&
7223
7225
  item.dataManagement === undefined &&
7224
- item.publicAccess === undefined
7226
+ item.publicAccess === undefined &&
7227
+ item.runtimeWrite === undefined
7225
7228
  ) {
7226
- warnings.push(`${label}: 未声明 settings/indexes/dataManagement/publicAccess`);
7229
+ warnings.push(`${label}: 未声明 settings/indexes/dataManagement/publicAccess/runtimeWrite`);
7227
7230
  }
7228
7231
  }
7229
7232
  }
7230
7233
 
7234
+ const FUNCTION_RUNTIME_INVOKE_AUDIENCE_TYPES = new Set([
7235
+ 'authenticated',
7236
+ 'app_roles',
7237
+ 'page_permission_group',
7238
+ 'scope_policy',
7239
+ ]);
7240
+
7241
+ const FUNCTION_RUNTIME_INVOKE_MAGIC_ROLE_CODES = new Set([
7242
+ '*',
7243
+ 'all-app-roles',
7244
+ 'all_app_roles',
7245
+ 'authenticated',
7246
+ 'logged_in',
7247
+ 'login',
7248
+ ]);
7249
+
7250
+ function validateFunctionRuntimeInvoke(label, item, errors, warnings) {
7251
+ const definition = item.definitionJson || {};
7252
+ const runtimeInvoke = item.runtimeInvoke || definition.runtimeInvoke;
7253
+ if (!runtimeInvoke) return;
7254
+ if (typeof runtimeInvoke !== 'object' || Array.isArray(runtimeInvoke)) {
7255
+ errors.push(`${label}: runtimeInvoke 必须是对象`);
7256
+ return;
7257
+ }
7258
+ if (
7259
+ runtimeInvoke.enabled !== undefined &&
7260
+ typeof runtimeInvoke.enabled !== 'boolean'
7261
+ ) {
7262
+ errors.push(`${label}: runtimeInvoke.enabled 必须是 boolean`);
7263
+ }
7264
+
7265
+ const roleCodeValues = [
7266
+ runtimeInvoke.roleCodes,
7267
+ runtimeInvoke.roles,
7268
+ runtimeInvoke.allowedRoleCodes,
7269
+ definition.invokeRoleCodes,
7270
+ ];
7271
+ let hasRoleGrant = false;
7272
+ for (const value of roleCodeValues) {
7273
+ if (value === undefined) continue;
7274
+ if (!Array.isArray(value)) {
7275
+ errors.push(`${label}: runtimeInvoke roleCodes/roles/allowedRoleCodes 必须是数组`);
7276
+ continue;
7277
+ }
7278
+ if (value.length > 0) hasRoleGrant = true;
7279
+ for (const roleCode of value) {
7280
+ const normalized = String(roleCode || '').trim();
7281
+ if (!normalized) continue;
7282
+ if (FUNCTION_RUNTIME_INVOKE_MAGIC_ROLE_CODES.has(normalized.toLowerCase())) {
7283
+ errors.push(
7284
+ `${label}: runtimeInvoke.roleCodes 不支持魔法值 "${normalized}";请使用 audience.type`
7285
+ );
7286
+ }
7287
+ }
7288
+ }
7289
+
7290
+ const audiences = [
7291
+ runtimeInvoke.audience,
7292
+ runtimeInvoke.audiences,
7293
+ definition.invokeAudience,
7294
+ definition.invokeAudiences,
7295
+ ].filter(value => value !== undefined);
7296
+ for (const audience of audiences) {
7297
+ validateFunctionRuntimeInvokeAudience(label, audience, errors);
7298
+ }
7299
+
7300
+ const hasAudience =
7301
+ audiences.length > 0 ||
7302
+ runtimeInvoke.allowAuthenticated === true ||
7303
+ runtimeInvoke.authenticated === true ||
7304
+ runtimeInvoke.allowLoggedIn === true ||
7305
+ runtimeInvoke.scopePolicyCode ||
7306
+ runtimeInvoke.policyCode ||
7307
+ runtimeInvoke.dataScopePolicyCode ||
7308
+ runtimeInvoke.pagePermissionGroupCodes ||
7309
+ runtimeInvoke.pagePermissionGroups ||
7310
+ runtimeInvoke.pageGroups;
7311
+
7312
+ if (!hasAudience && !hasRoleGrant) {
7313
+ warnings.push(
7314
+ `${label}: runtimeInvoke 未声明 audience 或有效 roleCodes,页面运行时调用仍会要求 app:automation:manage`
7315
+ );
7316
+ }
7317
+ }
7318
+
7319
+ function validateFunctionRuntimeInvokeAudience(label, value, errors) {
7320
+ if (Array.isArray(value)) {
7321
+ value.forEach(item => validateFunctionRuntimeInvokeAudience(label, item, errors));
7322
+ return;
7323
+ }
7324
+ if (typeof value === 'string') {
7325
+ const type = normalizeFunctionRuntimeInvokeAudienceType(value);
7326
+ if (!FUNCTION_RUNTIME_INVOKE_AUDIENCE_TYPES.has(type)) {
7327
+ errors.push(`${label}: 不支持的 runtimeInvoke.audience 类型 "${value}"`);
7328
+ }
7329
+ return;
7330
+ }
7331
+ if (!value || typeof value !== 'object') {
7332
+ errors.push(`${label}: runtimeInvoke.audience 必须是字符串、对象或数组`);
7333
+ return;
7334
+ }
7335
+ const type = normalizeFunctionRuntimeInvokeAudienceType(value.type);
7336
+ if (!FUNCTION_RUNTIME_INVOKE_AUDIENCE_TYPES.has(type)) {
7337
+ errors.push(`${label}: 不支持的 runtimeInvoke.audience.type "${value.type || ''}"`);
7338
+ return;
7339
+ }
7340
+ if (type === 'app_roles') {
7341
+ const roleCodes = normalizePermissionCodeArray(value.roleCodes || value.roles);
7342
+ if (!roleCodes.length) {
7343
+ errors.push(`${label}: audience.type=app_roles 时必须声明 roleCodes`);
7344
+ }
7345
+ for (const roleCode of roleCodes) {
7346
+ if (FUNCTION_RUNTIME_INVOKE_MAGIC_ROLE_CODES.has(roleCode.toLowerCase())) {
7347
+ errors.push(
7348
+ `${label}: audience.roleCodes 不支持魔法值 "${roleCode}";请改用 authenticated/page_permission_group/scope_policy`
7349
+ );
7350
+ }
7351
+ }
7352
+ }
7353
+ if (type === 'scope_policy') {
7354
+ const policyCode = String(
7355
+ value.policyCode || value.scopePolicyCode || value.dataScopePolicyCode || ''
7356
+ ).trim();
7357
+ if (!policyCode) {
7358
+ errors.push(`${label}: audience.type=scope_policy 时必须声明 policyCode`);
7359
+ }
7360
+ }
7361
+ }
7362
+
7363
+ function normalizeFunctionRuntimeInvokeAudienceType(value) {
7364
+ const type = String(value || '')
7365
+ .trim()
7366
+ .replace(/[-\s]+/g, '_')
7367
+ .toLowerCase();
7368
+ if (['logged_in', 'login', 'all_authenticated'].includes(type)) {
7369
+ return 'authenticated';
7370
+ }
7371
+ if (['app_role', 'roles', 'role_codes'].includes(type)) {
7372
+ return 'app_roles';
7373
+ }
7374
+ if (['page_permission_groups', 'page_group', 'page_groups'].includes(type)) {
7375
+ return 'page_permission_group';
7376
+ }
7377
+ if (['data_scope_policy', 'business_scope_policy'].includes(type)) {
7378
+ return 'scope_policy';
7379
+ }
7380
+ return type;
7381
+ }
7382
+
7383
+ function validateFormRuntimeWriteSettings(label, item, errors) {
7384
+ const runtimeWrite = item.runtimeWrite || item.settings?.runtimeWrite;
7385
+ if (runtimeWrite === undefined) return;
7386
+ if (!runtimeWrite || typeof runtimeWrite !== 'object' || Array.isArray(runtimeWrite)) {
7387
+ errors.push(`${label}: runtimeWrite 必须是对象`);
7388
+ return;
7389
+ }
7390
+ const mode = String(runtimeWrite.mode || '').trim();
7391
+ if (!['permission_group', 'function_only', 'public_form'].includes(mode)) {
7392
+ errors.push(
7393
+ `${label}: runtimeWrite.mode 只能是 permission_group、function_only 或 public_form`
7394
+ );
7395
+ }
7396
+ }
7397
+
7231
7398
  function validateScopePermissionResources(manifest, errors, warnings) {
7232
7399
  const policyCodes = new Set(
7233
7400
  (manifest.dataScopePolicies || [])
@@ -8507,12 +8674,16 @@ async function publishFormSettingsResources(config, target, settingsItems, resul
8507
8674
  const code = item.code || item.formCode || item.formUuid;
8508
8675
  const formUuid = resolveManifestFormUuid(target.bound, item, { fallbackToCode: true });
8509
8676
  if (!formUuid) fail(`表单设置 ${code} 无法解析 formUuid`);
8510
- if (item.settings !== undefined) {
8677
+ if (item.settings !== undefined || item.runtimeWrite !== undefined) {
8678
+ const settings = {
8679
+ ...(item.settings || {}),
8680
+ ...(item.runtimeWrite !== undefined ? { runtimeWrite: item.runtimeWrite } : {}),
8681
+ };
8511
8682
  await requestWithAuth(
8512
8683
  config,
8513
8684
  target.profileName,
8514
8685
  `/openxiangda-api/v1/apps/${encodeURIComponent(target.appType)}/forms/${encodeURIComponent(formUuid)}/settings`,
8515
- { method: 'POST', body: { settings: item.settings } }
8686
+ { method: 'POST', body: { settings } }
8516
8687
  );
8517
8688
  }
8518
8689
  if (item.indexes !== undefined) {
@@ -11551,6 +11722,9 @@ function normalizeFunctionDefinitionJson(functionItem, definitionJson) {
11551
11722
  kind: definition.kind || 'app_function',
11552
11723
  version: definition.version || 'function_v1',
11553
11724
  ...(functionCode ? { functionCode: String(functionCode) } : {}),
11725
+ ...(functionItem.runtimeInvoke !== undefined && definition.runtimeInvoke === undefined
11726
+ ? { runtimeInvoke: functionItem.runtimeInvoke }
11727
+ : {}),
11554
11728
  runtimeMode: definition.runtimeMode || 'trusted_node',
11555
11729
  sourceType: definition.sourceType || 'file_snapshot',
11556
11730
  });
@@ -11613,7 +11787,11 @@ function publicAccessPolicyEquals(bound, desired, existing) {
11613
11787
  String(existing.routeCode || '') === String(expected.routeCode || '') &&
11614
11788
  String(existing.pathPattern || '') === String(expected.pathPattern || '') &&
11615
11789
  stringSetEquals(existing.externalRoleCodes || [], expected.externalRoleCodes || []) &&
11616
- jsonEqualsForPlan(existing.grantsJson || existing.grants || {}, expected.grants || {}, desired.__dir) &&
11790
+ jsonEqualsForPlan(
11791
+ normalizePublicAccessGrants(bound, existing.grantsJson || existing.grants || {}),
11792
+ expected.grants || {},
11793
+ desired.__dir
11794
+ ) &&
11617
11795
  jsonEqualsForPlan(existing.ticketConfigJson || existing.ticketConfig || {}, expected.ticketConfig || {}, desired.__dir) &&
11618
11796
  jsonEqualsForPlan(existing.rateLimitJson || existing.rateLimit || {}, expected.rateLimit || {}, desired.__dir) &&
11619
11797
  String(existing.expiresAt || '') === String(expected.expiresAt || '')
@@ -522,6 +522,9 @@ const RESOURCE_EXPLAINS = {
522
522
  version: 'function_v1',
523
523
  runtimeMode: 'trusted_node',
524
524
  sourceType: 'inline',
525
+ runtimeInvoke: {
526
+ audience: { type: 'authenticated' },
527
+ },
525
528
  code: 'module.exports = async () => ({ ok: true })',
526
529
  },
527
530
  status: 'active',
@@ -162,7 +162,7 @@ When the user provides a root domain such as `https://yida.wisejob.cn/`, use it
162
162
  - Put engineering-managed resources in `src/resources/` and use `openxiangda resource validate|plan|publish|pull`. `workspace publish` publishes workspace forms/pages first, then runs non-destructive resource upsert. Only pass `--prune` when the user explicitly wants local manifests to delete platform-side extras.
163
163
  - For repeated read-only multi-form queries or predefined dashboard metrics, create a data view manifest in `src/resources/data-views/`. Use `storageMode: "materialized"` for refreshed lists/reports that tolerate delay; use `storageMode: "live"` for bounded real-time joins where source changes must appear immediately. Use row views plus `sdk.dataView.query` for joined lists/lookups; use `viewType: "aggregate"` plus `sdk.dataView.stats` for count/sum/avg/min/max statistics. Add `indexes` only for materialized views. Do not use data views for single-form CRUD, simple linkedForm selects, writes, write-back, unbounded realtime joins, or ad-hoc BI. Read `references/data-views.md` before designing one.
164
164
  - For external APIs, create a connector manifest in `src/resources/connectors/` and call it from pages through `sdk.connector`; never put third-party API keys in page source.
165
- - For reusable backend logic shared by pages, automations, and workflows, create an App Function in `src/resources/functions/<functionCode>.json` plus `src/functions/<functionCode>/index.ts`. Call it from pages with `sdk.function.invoke`, from automation/workflow graphs with `function_call`, or from the runtime endpoint when the caller has app automation management permission. Current App Function MVP exposes controlled helpers such as `ctx.resources`, `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`, `ctx.dataView`, `ctx.connector`, `ctx.notification`, `ctx.organization`, and `ctx.platform.api`; it does not expose raw SQL or Redis. Runtime functions also receive trusted role context on `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, and `ctx.permissions`; use these for server-side business authorization. Do not trust role codes sent in page input for sensitive actions. App Function form writes are trusted backend writes governed by declared `resources.forms` and function invocation authorization; do not grant normal users raw submit permission to internal forms just to let `ctx.form.createOne/updateOne/updateById` run.
165
+ - For reusable backend logic shared by pages, automations, and workflows, create an App Function in `src/resources/functions/<functionCode>.json` plus `src/functions/<functionCode>/index.ts`. Call it from pages with `sdk.function.invoke`, from automation/workflow graphs with `function_call`, or from the runtime endpoint. Direct runtime invocation defaults to app automation management permission; ordinary page callers must use `definitionJson.runtimeInvoke.audience` (`authenticated`, `page_permission_group`, `app_roles`, or `scope_policy`). `roleCodes` remains only for current app-role grants; never use `"*"` or `"all-app-roles"` there. Current App Function MVP exposes controlled helpers such as `ctx.resources`, `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`, `ctx.dataView`, `ctx.connector`, `ctx.notification`, `ctx.organization`, and `ctx.platform.api`; it does not expose raw SQL or Redis. Runtime functions also receive trusted role context on `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, and `ctx.permissions`; use these for server-side business authorization. Do not trust role codes sent in page input for sensitive actions. App Function form writes are trusted backend writes governed by declared `resources.forms` and function invocation authorization; do not grant normal users raw submit permission to internal forms just to let `ctx.form.createOne/updateOne/updateById` run. For internal function-only forms, publish form settings with `runtimeWrite.mode="function_only"` to close raw write endpoints.
166
166
  - For app-managed platform departments/accounts, use `sdk.organization.departments.*`, `sdk.organization.accounts.*`, `ctx.organization.departments.*`, or `ctx.organization.accounts.*`. The real current user/audit actor must hold `app:organization:manage` on the app; runtime service principals do not bypass this permission. Do not call legacy `/user` or `/department` write endpoints from apps. Do not include `password` in account updates; reset target accounts with `resetPassword`, and change the current user's password with `changeMyPassword({ oldPassword, newPassword })`.
167
167
  - For account, role, data-scope, organization-account, RBAC, or query-param authorization designs, read `references/permission-design-patterns.md` and choose a permission mode before writing forms/pages/resources. Formal backends should use platform roles, page permission groups, form permission groups, public-access grants, and App Function role/scope checks; frontend hiding is display only.
168
168
  - When a role such as 校区管理员 will create app roles, assign role members, grant role permissions, maintain permission groups, or manage organization accounts, its role manifest must declare the needed `apiPermissionCodes` such as `app:role:manage`, `app:page-permission-group:manage`, `app:form-permission-group:manage`, and `app:organization:manage`. If that administrator creates another administrator role, the new role must also declare its own `apiPermissionCodes`; permissions are not inherited from the creator.
@@ -32,7 +32,7 @@ Notification manifests live under `src/resources/notifications/` and contain `te
32
32
 
33
33
  Data view manifests live under `src/resources/data-views/` and define read-only joined or aggregate query resources. Use `storageMode: "materialized"` for refreshed lists/reports where lag is acceptable, and `storageMode: "live"` for bounded real-time query shapes. Use row views with `sdk.dataView.query` and aggregate views with `sdk.dataView.stats`. Before generating one, confirm freshness tolerance, query bounds, and indexes for materialized filters/sort fields/dimensions/date buckets. Do not use them for single-form CRUD, simple linkedForm selects, writes, write-back, or ad-hoc BI. See `data-views.md` before generating one.
34
34
 
35
- App Function manifests live under `src/resources/functions/`, with source in `src/functions/<functionCode>/index.ts`. Use them for reusable server-side logic that pages, automations, and workflows can share through `sdk.function.invoke` or `function_call` nodes. App Functions expose controlled runtime helpers such as `ctx.resources`, `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`, `ctx.dataView`, `ctx.connector`, `ctx.notification`, `ctx.organization`, and `ctx.platform.api`; they do not expose raw SQL or Redis in the current MVP. Runtime page invocations also expose trusted role context on `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, and `ctx.permissions`; use that context for server-side authorization, and never trust page-submitted role codes for sensitive actions. App Function form writes are trusted backend writes governed by declared `resources.forms` and function invocation authorization, not by direct page-user submit access to the target form. App Function organization writes require `app:organization:manage` on the real operator/audit actor. Use JS_CODE V2 only for node-local workflow/automation scripts.
35
+ App Function manifests live under `src/resources/functions/`, with source in `src/functions/<functionCode>/index.ts`. Use them for reusable server-side logic that pages, automations, and workflows can share through `sdk.function.invoke` or `function_call` nodes. App Functions expose controlled runtime helpers such as `ctx.resources`, `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`, `ctx.dataView`, `ctx.connector`, `ctx.notification`, `ctx.organization`, and `ctx.platform.api`; they do not expose raw SQL or Redis in the current MVP. Runtime page invocations also expose trusted role context on `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, and `ctx.permissions`; use that context for server-side authorization, and never trust page-submitted role codes for sensitive actions. Page-call grants should use `definitionJson.runtimeInvoke.audience` (`authenticated`, `page_permission_group`, `app_roles`, or `scope_policy`); `roleCodes` is only for current app-role grants and does not support `"*"` or `"all-app-roles"`. App Function form writes are trusted backend writes governed by declared `resources.forms` and function invocation authorization, not by direct page-user submit access to the target form. For internal function-only forms, publish form settings with `runtimeWrite.mode="function_only"` so raw write endpoints are closed. App Function organization writes require `app:organization:manage` on the real operator/audit actor. Use JS_CODE V2 only for node-local workflow/automation scripts.
36
36
 
37
37
  Auth manifests live under `src/resources/auth/`. Use them to enable app-level login methods and bind phone-code/CAS/custom providers to App Functions. Auth provider functions are called only by the platform auth flow. They validate external credentials and return identity assertions such as `phone`, `email`, `externalId`, or `unionId`; they must not issue tokens, set cookies, or mutate platform user/binding tables.
38
38
 
@@ -115,7 +115,7 @@ App Function source should prefer `export default async function(ctx, input) {}`
115
115
  The second argument is the `input` passed by `sdk.function.invoke`, and the
116
116
  same value is also available as `ctx.input` for compatibility.
117
117
 
118
- Use App Functions when the logic must run server-side and be reusable by pages, automations, or workflows. Runtime invocation requires app automation management permission by default. To let ordinary app users call a function from a page, declare the allowed current app roles in `definitionJson.runtimeInvoke.roleCodes`; keep sensitive admin-only functions without broad grants. Inside the function, authorize sensitive actions with trusted runtime context such as `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, or `ctx.permissions`; do not trust role codes sent in the page input. When the function writes forms with `ctx.form.createOne/updateOne/updateById`, treat the write as a trusted backend operation over declared `resources.forms`; do not open direct submit permission on internal forms just for that page action.
118
+ Use App Functions when the logic must run server-side and be reusable by pages, automations, or workflows. Runtime invocation requires app automation management permission by default. To let ordinary app users call a function from a page, declare `definitionJson.runtimeInvoke.audience` with `authenticated`, `page_permission_group`, `app_roles`, or `scope_policy`; use `roleCodes` only for current app-role grants. Do not use `"*"` or `"all-app-roles"` as role codes. Inside the function, authorize sensitive actions with trusted runtime context such as `ctx.operator.roleCodes`, `ctx.operator.currentRoleCode`, `ctx.operator.hasFullAccess`, `ctx.currentUser`, or `ctx.permissions`; do not trust role codes sent in the page input. When the function writes forms with `ctx.form.createOne/updateOne/updateById`, treat the write as a trusted backend operation over declared `resources.forms`; do not open direct submit permission on internal forms just for that page action.
119
119
 
120
120
  Organization management:
121
121
 
@@ -571,7 +571,10 @@ JS_CODE 调用:`ctx.notification.sendByType({ ... })`。允许的 channels:`
571
571
  "runtimeMode": "trusted_node",
572
572
  "timeout": 30000,
573
573
  "runtimeInvoke": {
574
- "roleCodes": ["union_admin", "member"]
574
+ "audience": {
575
+ "type": "page_permission_group",
576
+ "resourceCodes": ["member_portal_pages"]
577
+ }
575
578
  },
576
579
  "sourceFile": {
577
580
  "localPath": "src/functions/reservation_reminder_summary/index.ts"
@@ -643,7 +646,7 @@ const result = await sdk.function.invoke("reservation_reminder_summary", {
643
646
  }
644
647
  ```
645
648
 
646
- 适用边界:可复用后端业务逻辑、跨页面/自动化/流程共享的查询编排、连接器调用、通知编排、受控平台 API 调用。App Function 支持 `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`、`ctx.dataView`、`ctx.connector`、`ctx.notification`、`ctx.platform.api` 等受控 helper,当前 MVP 不暴露原始 SQL/Redis。`ctx.form.createOne/updateOne/updateById` 是后端受控写入,权限边界是 function manifest 的 `resources.forms` 和函数调用授权,不是页面用户对目标表单的直接提交权限;内部业务表单不要为了函数写入而开放普通用户原始 submit。运行时接口默认需要应用自动化管理权限;普通用户页面要调用时,在 `definitionJson.runtimeInvoke.roleCodes` 显式声明允许的当前应用角色。自动化/流程内部调用走服务端上下文,不受页面运行时授权限制。
649
+ 适用边界:可复用后端业务逻辑、跨页面/自动化/流程共享的查询编排、连接器调用、通知编排、受控平台 API 调用。App Function 支持 `ctx.form.queryOne/queryMany/getById/createOne/updateOne/updateById`、`ctx.dataView`、`ctx.connector`、`ctx.notification`、`ctx.platform.api` 等受控 helper,当前 MVP 不暴露原始 SQL/Redis。`ctx.form.createOne/updateOne/updateById` 是后端受控写入,权限边界是 function manifest 的 `resources.forms` 和函数调用授权,不是页面用户对目标表单的直接提交权限;内部业务表单不要为了函数写入而开放普通用户原始 submit。运行时接口默认需要应用自动化管理权限;普通用户页面要调用时,用 `definitionJson.runtimeInvoke.audience` 声明 `authenticated`、`page_permission_group`、`app_roles` 或 `scope_policy`,不要把 `"*"`、`"all-app-roles"` 写进 `roleCodes`。自动化/流程内部调用走服务端上下文,不受页面运行时授权限制。若表单只能由函数/流程写入,在 `src/resources/settings/forms/<formCode>.json` 设置 `runtimeWrite.mode="function_only"` 关闭原始写入接口。
647
650
 
648
651
  ## 5. Workflow — `src/resources/workflows/<code>/workflow.json`(manifest)+ `src/workflows/<code>/workflow.ts`(代码优先)
649
652
 
@@ -831,7 +834,10 @@ permission codes.
831
834
  "code": "customer",
832
835
  "settings": {
833
836
  "submitButtonText": "提交",
834
- "successMessage": "提交成功"
837
+ "successMessage": "提交成功",
838
+ "runtimeWrite": {
839
+ "mode": "permission_group"
840
+ }
835
841
  },
836
842
  "indexes": [
837
843
  { "fields": ["customerCode"], "unique": true },
@@ -841,6 +847,8 @@ permission codes.
841
847
  }
842
848
  ```
843
849
 
850
+ `runtimeWrite.mode` 可选 `permission_group`、`function_only`、`public_form`。内部业务表单需要强制走 App Function / Workflow 时使用 `function_only`;这会关闭页面原始写入接口,但不影响 `ctx.form.createOne/updateOne/updateById` 等受信后端写入。
851
+
844
852
  `publicAccess` 表单 setting 只用于旧 `sy-lowcode-view` 兼容。新 React SPA 公开页面必须使用 `src/resources/routes/` + `src/resources/public-access/` + `OpenXiangdaProvider` + `OpenXiangdaPageProvider` + `PublicAccessGate`。
845
853
 
846
854
  ## 12. Menu — `src/resources/menus/<code>.json`
@@ -103,7 +103,7 @@ Use `workflow pull` to inspect the live definition. Use `workflow list --json` a
103
103
 
104
104
  JS_CODE is the backend execution escape hatch for workflow and automation. Use it when the logic must run on the server after a backend trigger, such as a fixed cron schedule, a form date-field schedule, a form submit/update/delete/field-change event, or a workflow approval/process event. It is appropriate for cross-form data queries, create/update/batch update operations, process termination, platform API calls, external HTTP calls, and complex orchestration that the frontend cannot handle reliably.
105
105
 
106
- App Function is the reusable backend execution model. Use it when the logic should be called by custom pages, multiple automations, workflows, or the runtime API. Source lives in `src/functions/<functionCode>/index.ts`; manifest lives in `src/resources/functions/<functionCode>.json`. Call it from pages with `sdk.function.invoke(code, { input })`, from graph definitions with `function_call`, or from the runtime endpoint `/:appType/v1/functions/:code/invoke.json` when the caller has app automation management permission. Prefer `export default async function(ctx, input) {}` for App Function source; the second argument is the invoke input and the same value is available as `ctx.input`. Current MVP exposes controlled helpers only and does not expose raw SQL or Redis. `ctx.form.createOne/updateOne/updateById` are trusted backend writes governed by declared `resources.forms` and function invocation authorization; keep internal forms closed to direct user submit unless the business explicitly needs raw form submission.
106
+ App Function is the reusable backend execution model. Use it when the logic should be called by custom pages, multiple automations, workflows, or the runtime API. Source lives in `src/functions/<functionCode>/index.ts`; manifest lives in `src/resources/functions/<functionCode>.json`. Call it from pages with `sdk.function.invoke(code, { input })`, from graph definitions with `function_call`, or from the runtime endpoint `/:appType/v1/functions/:code/invoke.json`. Direct runtime invocation defaults to app automation management permission; ordinary page callers must declare `definitionJson.runtimeInvoke.audience` (`authenticated`, `page_permission_group`, `app_roles`, or `scope_policy`). Prefer `export default async function(ctx, input) {}` for App Function source; the second argument is the invoke input and the same value is available as `ctx.input`. Current MVP exposes controlled helpers only and does not expose raw SQL or Redis. `ctx.form.createOne/updateOne/updateById` are trusted backend writes governed by declared `resources.forms` and function invocation authorization; keep internal forms closed to direct user submit unless the business explicitly needs raw form submission. For internal function-only forms, set form settings `runtimeWrite.mode="function_only"` instead of relying only on missing submit permission groups.
107
107
 
108
108
  For new AI-authored automations, prefer code-first `automation_code_ts` resources instead of visual v3 graph definitions. Put the source in `src/automations/<resourceCode>/index.ts`, define `definition.code.json` with `kind: "automation_code_ts"`, and provide `preview.json` for read-only frontend display. Use `ctx.logger.debug/info/warn/error(message, data?)` at every important step; OpenXiangda can inspect logs with `automation executions`, `automation logs`, and `automation diagnose`.
109
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.143",
3
+ "version": "1.0.144",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {