@shiqianjiang/ceru-plugin-issuer 0.2.0 → 0.2.2

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
@@ -21,4 +21,6 @@ console.log(readArtifact(bytes).signatureStatus)
21
21
 
22
22
  0.2.0 静态读取 `exports.manifest` / `exports.package`,并从 `exports.activate`、`exports.surfaces`、`exports.modules` 提取运行入口。旧 `CeruPlugin.define()` v2 容器仍可验证,但会返回迁移提示;v1 注释头只用于识别迁移来源,不能绕过 v2 Manifest 和权限模型直接运行。
23
23
 
24
+ `exports.manifest.config` 是同样可静态读取的 JSON 兼容对象。`createTemplate()` 默认从配置字段和类型生成 `personalization.config` 策略;`PreparedIssuer` 只能覆盖该策略允许的配置。`resolveArtifactConfig()` 递归合并清单默认值与签名交付值,业务代码与后端无需改写 bundle。
25
+
24
26
  [完整协议与命令](https://github.com/CeruMusic/CeruMusic-Plugin-Cli#readme)
package/dist/index.d.ts CHANGED
@@ -76,7 +76,17 @@ export declare function generateSigningKeys(): {
76
76
  };
77
77
  export declare function encodeHeader(header: ArtifactHeader): Buffer;
78
78
  export declare function encodeArtifact(header: ArtifactHeader, body: string): Buffer;
79
+ /** Resolves signed delivery configuration over the defaults embedded at build time. */
80
+ export declare function resolveArtifactConfig(header: ArtifactHeader): JsonObject;
81
+ /** Returns customer-facing metadata without changing plugin identity or permissions. */
82
+ export declare function resolveArtifactDisplay(header: ArtifactHeader): {
83
+ name: string;
84
+ description?: string;
85
+ author?: string;
86
+ };
79
87
  export declare const DEFAULT_PERSONALIZATION_SCHEMA: JsonObject;
88
+ /** Creates the default delivery policy from a plugin's build-time config shape. */
89
+ export declare function createPersonalizationSchema(config?: JsonObject): JsonObject;
80
90
  export declare function readArtifact(input: Uint8Array | string, options?: ValidationOptions): Artifact;
81
91
  export declare function signArtifact(input: Uint8Array, privateKey: string): Buffer;
82
92
  export declare function createTemplate(input: Uint8Array, options: {
package/dist/index.js CHANGED
@@ -128,6 +128,7 @@ export const MANIFEST_SCHEMA = object({
128
128
  author: string,
129
129
  publisher: string,
130
130
  license: string,
131
+ config: { type: 'object', additionalProperties: true },
131
132
  engines: object({
132
133
  hostApi: string,
133
134
  logicRuntime: { const: 'ceru-js@1' },
@@ -420,10 +421,12 @@ function checkProof(proof, data) {
420
421
  }
421
422
  export function encodeHeader(header) {
422
423
  const { manifest, ...metadata } = header;
424
+ const literal = (value) => JSON.stringify(value, null, 2).replace(/^(\s*)"([A-Za-z_$][A-Za-z0-9_$]*)":/gm, '$1$2:');
423
425
  const head = Buffer.from('exports.manifest = ' +
424
- JSON.stringify(manifest, null, 2) +
425
- ';\nexports.package = ' +
426
- JSON.stringify(metadata, null, 2) +
426
+ literal(manifest) +
427
+ ';\n' +
428
+ 'exports.package = ' +
429
+ literal(metadata) +
427
430
  ';\n');
428
431
  ensure(head.length <= LIMITS.header, 'Artifact metadata is too large');
429
432
  return head;
@@ -433,6 +436,49 @@ export function encodeArtifact(header, body) {
433
436
  ensure(result.length <= LIMITS.file, 'Artifact exceeds size limit');
434
437
  return result;
435
438
  }
439
+ function mergeConfig(base, override) {
440
+ const result = JSON.parse(canonical(base));
441
+ for (const [key, value] of Object.entries(override)) {
442
+ const current = result[key];
443
+ result[key] =
444
+ plain(current) && plain(value)
445
+ ? mergeConfig(current, value)
446
+ : JSON.parse(canonical(value));
447
+ }
448
+ return result;
449
+ }
450
+ /** Resolves signed delivery configuration over the defaults embedded at build time. */
451
+ export function resolveArtifactConfig(header) {
452
+ const personalization = header.delivery?.payload.personalization;
453
+ const personalizationObject = personalization && typeof personalization === 'object' && !Array.isArray(personalization)
454
+ ? personalization
455
+ : undefined;
456
+ const config = personalizationObject?.['config'];
457
+ const override = plain(config)
458
+ ? config
459
+ : Object.create(null);
460
+ return mergeConfig(header.manifest.config ?? Object.create(null), override);
461
+ }
462
+ /** Returns customer-facing metadata without changing plugin identity or permissions. */
463
+ export function resolveArtifactDisplay(header) {
464
+ const personalization = header.delivery?.payload.personalization;
465
+ const display = plain(personalization) && plain(personalization.display)
466
+ ? personalization.display
467
+ : Object.create(null);
468
+ return {
469
+ name: typeof display.name === 'string' ? display.name : header.manifest.name,
470
+ ...(typeof display.description === 'string'
471
+ ? { description: display.description }
472
+ : header.manifest.description
473
+ ? { description: header.manifest.description }
474
+ : {}),
475
+ ...(typeof display.author === 'string'
476
+ ? { author: display.author }
477
+ : header.manifest.author
478
+ ? { author: header.manifest.author }
479
+ : {}),
480
+ };
481
+ }
436
482
  function checkPolicy(schema, depth = 0) {
437
483
  ensure(depth <= 12, 'Personalization schema is too deep');
438
484
  exactKeys(schema, [
@@ -471,6 +517,7 @@ export const DEFAULT_PERSONALIZATION_SCHEMA = {
471
517
  properties: {
472
518
  name: { type: 'string', minLength: 1, maxLength: 120 },
473
519
  description: { type: 'string', maxLength: 1024 },
520
+ author: { type: 'string', maxLength: 120 },
474
521
  },
475
522
  additionalProperties: false,
476
523
  },
@@ -488,6 +535,33 @@ export const DEFAULT_PERSONALIZATION_SCHEMA = {
488
535
  },
489
536
  additionalProperties: false,
490
537
  };
538
+ function configValueSchema(value, depth = 0) {
539
+ ensure(depth <= 12, 'Plugin config is too deeply nested for personalization');
540
+ if (value === null)
541
+ return { type: 'null' };
542
+ if (typeof value === 'string')
543
+ return { type: 'string', maxLength: 8192 };
544
+ if (typeof value === 'boolean')
545
+ return { type: 'boolean' };
546
+ if (typeof value === 'number')
547
+ return { type: Number.isInteger(value) ? 'integer' : 'number' };
548
+ if (Array.isArray(value))
549
+ return {
550
+ type: 'array',
551
+ items: configValueSchema(value[0] ?? '', depth + 1),
552
+ maxItems: 256,
553
+ };
554
+ const properties = Object.create(null);
555
+ for (const [key, child] of Object.entries(value))
556
+ properties[key] = configValueSchema(child, depth + 1);
557
+ return { type: 'object', properties, additionalProperties: false };
558
+ }
559
+ /** Creates the default delivery policy from a plugin's build-time config shape. */
560
+ export function createPersonalizationSchema(config = {}) {
561
+ const schema = JSON.parse(canonical(DEFAULT_PERSONALIZATION_SCHEMA));
562
+ schema.properties.config = configValueSchema(config);
563
+ return schema;
564
+ }
491
565
  function policyValidator(schema) {
492
566
  checkPolicy(schema);
493
567
  ensure(schema.type === 'object', 'Personalization root must be an object');
@@ -835,7 +909,7 @@ export function createTemplate(input, options) {
835
909
  const artifact = readArtifact(input);
836
910
  ensure(!artifact.header.template, 'Input must be a normal plugin artifact');
837
911
  const key = createPrivateKey(options.privateKey);
838
- const policy = options.personalizationSchema ?? DEFAULT_PERSONALIZATION_SCHEMA;
912
+ const policy = options.personalizationSchema ?? createPersonalizationSchema(artifact.header.manifest.config);
839
913
  policyValidator(policy);
840
914
  ensure(options.issuerPublicKeys.length > 0 && options.issuerPublicKeys.length <= 16, 'Provide 1-16 issuer public keys');
841
915
  const header = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shiqianjiang/ceru-plugin-issuer",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Static verification, Ed25519 signing and cached personalized issuance of Ceru single-JS plugins",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "node": ">=22.12.0"
24
24
  },
25
25
  "dependencies": {
26
- "@shiqianjiang/ceru-plugin-sdk": "0.2.0",
26
+ "@shiqianjiang/ceru-plugin-sdk": "0.2.2",
27
27
  "acorn": "^8.18.0",
28
28
  "ajv": "^8.20.0"
29
29
  },