@nesso-how/plugin 0.6.0 → 0.8.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.
@@ -4,8 +4,6 @@ import validateName from 'validate-npm-package-name';
4
4
  import { checkMessageSize, parseDefinition, parsePluginI18n, parsePluginManifest, parseOrThrow, PluginError, sha256Hex, } from './runtime.js';
5
5
  export const packageLimits = {
6
6
  entry: 16 * 1024 * 1024,
7
- font: 4 * 1024 * 1024,
8
- fonts: 32,
9
7
  record: 32 * 1024 * 1024,
10
8
  installed: 32,
11
9
  total: 128 * 1024 * 1024,
@@ -81,56 +79,21 @@ export async function preparePluginPackage(input) {
81
79
  const { name, version, author, repository, nesso: declaration, i18n: translations, } = parsePackageIdentity(input.manifest);
82
80
  const nesso = parsePluginManifest(declaration);
83
81
  const i18n = parsePluginI18n(translations);
84
- if (!Array.isArray(input.files) ||
85
- !input.files.length ||
86
- input.files.length > (nesso.kind === 'theme' ? packageLimits.fonts + 1 : 1))
82
+ if (!Array.isArray(input.files) || input.files.length !== 1)
87
83
  throw new PluginError('invalid-input', [
88
- { path: 'files', message: 'Expected one entry and supported local theme fonts only' },
84
+ { path: 'files', message: 'Expected one plugin entry only' },
89
85
  ]);
90
- const paths = new Set();
91
- const fonts = [];
92
- const files = [];
93
- let bytes;
94
- let admitted = 0;
95
- for (const file of input.files) {
96
- if (!file ||
97
- typeof file.path !== 'string' ||
98
- file.path.length > 240 ||
99
- paths.has(file.path) ||
100
- !(file.bytes instanceof Uint8Array) ||
101
- !file.bytes.byteLength ||
102
- file.bytes.byteLength > (file.path === nesso.entry ? packageLimits.entry : packageLimits.font))
103
- throw new PluginError('invalid-input', [
104
- { path: 'files', message: 'Invalid, duplicate, or oversized package file' },
105
- ]);
106
- paths.add(file.path);
107
- admitted +=
108
- file.path === nesso.entry ? file.bytes.byteLength : Math.ceil(file.bytes.byteLength / 3) * 4;
109
- if (admitted > packageLimits.record)
110
- throw new PluginError('invalid-input', [
111
- { path: 'files', message: 'Package record budget exceeded' },
112
- ]);
113
- const content = new Uint8Array(file.bytes);
114
- if (file.path === nesso.entry)
115
- bytes = content;
116
- else {
117
- if (nesso.kind !== 'theme' ||
118
- !/^(?:[\w-]+\/)*[\w-]+\.woff2$/.test(file.path) ||
119
- new TextDecoder().decode(content.subarray(0, 4)) !== 'wOF2')
120
- throw new PluginError('invalid-input', [
121
- { path: file.path, message: 'Expected a package-local WOFF2 font' },
122
- ]);
123
- let binary = '';
124
- for (let offset = 0; offset < content.length; offset += 32_768)
125
- binary += String.fromCharCode(...content.subarray(offset, offset + 32_768));
126
- fonts.push({ path: file.path, data: btoa(binary) });
127
- }
128
- files.push({ path: file.path, size: content.byteLength, sha256: await sha256Hex(content) });
129
- }
130
- if (!bytes)
86
+ const file = input.files[0];
87
+ if (!file ||
88
+ file.path !== nesso.entry ||
89
+ !(file.bytes instanceof Uint8Array) ||
90
+ !file.bytes.byteLength ||
91
+ file.bytes.byteLength > packageLimits.entry)
131
92
  throw new PluginError('invalid-input', [
132
- { path: 'nesso.entry', message: 'Missing plugin entry' },
93
+ { path: 'files', message: 'Expected the plugin entry within size limits' },
133
94
  ]);
95
+ const bytes = new Uint8Array(file.bytes);
96
+ const files = [{ path: file.path, size: bytes.byteLength, sha256: await sha256Hex(bytes) }];
134
97
  let code;
135
98
  try {
136
99
  code = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
@@ -152,8 +115,7 @@ export async function preparePluginPackage(input) {
152
115
  }
153
116
  parseDefinition(nesso.kind, raw);
154
117
  }
155
- const order = (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
156
- const index = { name, version, author, repository, nesso, i18n, files: files.sort(order) };
118
+ const index = { name, version, author, repository, nesso, i18n, files };
157
119
  const prepared = {
158
120
  name,
159
121
  version,
@@ -162,7 +124,6 @@ export async function preparePluginPackage(input) {
162
124
  nesso,
163
125
  i18n,
164
126
  code,
165
- fonts: fonts.sort(order),
166
127
  contentId: await sha256Hex(new TextEncoder().encode(canonical(index))),
167
128
  };
168
129
  if (new TextEncoder().encode(JSON.stringify(prepared)).byteLength > packageLimits.record)
@@ -171,37 +132,11 @@ export async function preparePluginPackage(input) {
171
132
  ]);
172
133
  return prepared;
173
134
  }
174
- export function packageFonts(value) {
175
- if (!Array.isArray(value.fonts) || value.fonts.length > packageLimits.fonts)
176
- throw new PluginError('invalid-input', [
177
- { path: 'fonts', message: 'Invalid installed font assets' },
178
- ]);
179
- return new Map(value.fonts.map((font) => {
180
- if (!font ||
181
- typeof font.path !== 'string' ||
182
- typeof font.data !== 'string' ||
183
- font.data.length > Math.ceil(packageLimits.font / 3) * 4)
184
- throw new PluginError('invalid-input', [
185
- { path: 'fonts', message: 'Invalid font encoding or budget' },
186
- ]);
187
- try {
188
- return [font.path, Uint8Array.from(atob(font.data), (character) => character.charCodeAt(0))];
189
- }
190
- catch {
191
- throw new PluginError('invalid-input', [
192
- { path: 'fonts', message: 'Invalid font encoding' },
193
- ]);
194
- }
195
- }));
196
- }
197
135
  export async function verifyPluginPackage(value) {
198
136
  if (!value || typeof value.code !== 'string' || value.code.length > packageLimits.entry)
199
137
  throw new PluginError('invalid-input', [
200
138
  { path: 'package', message: 'Invalid installed plugin package' },
201
139
  ]);
202
- const fonts = packageFonts(value);
203
- if (fonts.size !== value.fonts.length)
204
- throw new PluginError('invalid-input', [{ path: 'fonts', message: 'Duplicate font assets' }]);
205
140
  const prepared = await preparePluginPackage({
206
141
  manifest: {
207
142
  name: value.name,
@@ -211,10 +146,7 @@ export async function verifyPluginPackage(value) {
211
146
  nesso: value.nesso,
212
147
  i18n: value.i18n,
213
148
  },
214
- files: [
215
- { path: value.nesso?.entry, bytes: new TextEncoder().encode(value.code) },
216
- ...[...fonts].map(([path, bytes]) => ({ path, bytes })),
217
- ],
149
+ files: [{ path: value.nesso?.entry, bytes: new TextEncoder().encode(value.code) }],
218
150
  });
219
151
  if (prepared.contentId !== value.contentId)
220
152
  throw new PluginError('denied', [
@@ -1,4 +1,6 @@
1
1
  import { z } from 'zod';
2
+ import { type ImageRenderOptions, type RenderedImage } from './images.ts';
3
+ export type { ImageRenderOptions, RenderedImage } from './images.ts';
2
4
  import type { ComponentType } from 'react';
3
5
  import type { DeepReadonly, GraphSnapshot, NessoOperation, Selection, SavedView, VocabDefinition } from '@nesso-how/core';
4
6
  import type { Locale } from '@nesso-how/i18n';
@@ -10,7 +12,6 @@ import { type PluginStorage, type PluginStorageRecord } from './storage.ts';
10
12
  export { checkMessageSize } from './data.ts';
11
13
  export { parsePluginStorageKey, parsePluginStorageRecord, parsePluginStorageSnapshot, pluginStorageLimits, } from './storage.ts';
12
14
  export { resolvePluginText, type LocalizedText } from './i18n.ts';
13
- export { fontFaces } from './theme-fonts.ts';
14
15
  export { parseOrThrow, PluginError } from './errors.ts';
15
16
  export { parseDefinition, themeColors, type Definition } from './definitions.ts';
16
17
  export { parseFileOptions, fileTextLimit, type FileOpenOptions, type FileSaveOptions, type FileOpenResult, } from './files.ts';
@@ -66,7 +67,7 @@ export type PluginI18n = DeepReadonly<{
66
67
  }>;
67
68
  export declare function parsePluginI18n(value: unknown): PluginI18n;
68
69
  declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
69
- apiVersion: z.ZodLiteral<1>;
70
+ apiVersion: z.ZodLiteral<3>;
70
71
  kind: z.ZodLiteral<"actions">;
71
72
  entry: z.ZodString;
72
73
  writes: z.ZodArray<z.ZodEnum<{
@@ -89,12 +90,13 @@ declare const manifest: z.ZodDiscriminatedUnion<[z.ZodObject<{
89
90
  }>>;
90
91
  capabilities: z.ZodArray<z.ZodEnum<{
91
92
  files: "files";
93
+ images: "images";
92
94
  notifications: "notifications";
93
95
  storage: "storage";
94
96
  ui: "ui";
95
97
  }>>;
96
98
  }, z.core.$strict>, ...z.ZodObject<{
97
- apiVersion: z.ZodLiteral<1>;
99
+ apiVersion: z.ZodLiteral<3>;
98
100
  kind: z.ZodLiteral<"theme" | "vocab">;
99
101
  entry: z.ZodString;
100
102
  writes: z.ZodTuple<[], null>;
@@ -272,7 +274,13 @@ declare const message: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject
272
274
  method: z.ZodLiteral<"storage.set">;
273
275
  params: z.ZodObject<{
274
276
  key: z.ZodString;
275
- conceptId: z.ZodOptional<z.ZodString>;
277
+ scope: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
278
+ kind: z.ZodLiteral<"concept">;
279
+ id: z.ZodString;
280
+ }, z.core.$strict>, z.ZodObject<{
281
+ kind: z.ZodLiteral<"view">;
282
+ id: z.ZodString;
283
+ }, z.core.$strict>], "kind">>;
276
284
  value: z.ZodPipe<z.ZodCustom<string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | readonly (string | number | boolean | /*elided*/ any | {
277
285
  readonly [key: string]: string | number | boolean | /*elided*/ any | /*elided*/ any | null;
278
286
  } | null)[] | {
@@ -379,7 +387,13 @@ declare const message: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject
379
387
  method: z.ZodLiteral<"storage.delete">;
380
388
  params: z.ZodObject<{
381
389
  key: z.ZodString;
382
- conceptId: z.ZodOptional<z.ZodString>;
390
+ scope: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
391
+ kind: z.ZodLiteral<"concept">;
392
+ id: z.ZodString;
393
+ }, z.core.$strict>, z.ZodObject<{
394
+ kind: z.ZodLiteral<"view">;
395
+ id: z.ZodString;
396
+ }, z.core.$strict>], "kind">>;
383
397
  revision: z.ZodNumber;
384
398
  }, z.core.$strict>;
385
399
  }, z.core.$strict>, z.ZodObject<{
@@ -417,10 +431,23 @@ declare const message: z.ZodUnion<readonly [z.ZodDiscriminatedUnion<[z.ZodObject
417
431
  id: z.ZodNumber;
418
432
  contextId: z.ZodString;
419
433
  method: z.ZodLiteral<"files.save">;
420
- params: z.ZodObject<{
434
+ params: z.ZodUnion<readonly [z.ZodObject<{
421
435
  name: z.ZodString;
422
436
  mediaType: z.ZodString;
423
437
  text: z.ZodString;
438
+ }, z.core.$strict>, z.ZodObject<{
439
+ name: z.ZodString;
440
+ mediaType: z.ZodString;
441
+ base64: z.ZodString;
442
+ }, z.core.$strict>]>;
443
+ }, z.core.$strict>, z.ZodObject<{
444
+ type: z.ZodLiteral<"request">;
445
+ id: z.ZodNumber;
446
+ contextId: z.ZodString;
447
+ method: z.ZodLiteral<"images.renderView">;
448
+ params: z.ZodObject<{
449
+ format: z.ZodLiteral<"png">;
450
+ scale: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<2>, z.ZodLiteral<4>]>>;
424
451
  }, z.core.$strict>;
425
452
  }, z.core.$strict>], "method">, z.ZodObject<{
426
453
  type: z.ZodLiteral<"panel-ready">;
@@ -544,6 +571,9 @@ export type ActionContext = {
544
571
  }>;
545
572
  };
546
573
  readonly storage: PluginStorage;
574
+ readonly images: {
575
+ readonly renderView: (options: ImageRenderOptions) => Promise<RenderedImage>;
576
+ };
547
577
  readonly signal: AbortSignal;
548
578
  };
549
579
  export declare function parsePluginMessage(value: unknown): z.infer<typeof message>;
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
+ import { imageRenderOptions, renderedImage, } from './images.js';
2
3
  import { graphSchema, positionSchema } from '@nesso-how/schema';
3
- import { parseOrThrow, PluginError } from './errors.js';
4
+ import { parseOrThrow, PluginError, pluginErrorCodes } from './errors.js';
4
5
  import { parseDefinition, themeColors, vocabRelationType } from './definitions.js';
5
6
  import { fileOpenOptions, fileOpenResult, fileSaveOptions, } from './files.js';
6
7
  import { createWriteCommands } from '@nesso-how/core';
@@ -10,7 +11,6 @@ import { pluginStorageKey, pluginStorageRecord, pluginStorageRevision, pluginSto
10
11
  export { checkMessageSize } from './data.js';
11
12
  export { parsePluginStorageKey, parsePluginStorageRecord, parsePluginStorageSnapshot, pluginStorageLimits, } from './storage.js';
12
13
  export { resolvePluginText } from './i18n.js';
13
- export { fontFaces } from './theme-fonts.js';
14
14
  export { parseOrThrow, PluginError } from './errors.js';
15
15
  export { parseDefinition, themeColors } from './definitions.js';
16
16
  export { parseFileOptions, fileTextLimit, } from './files.js';
@@ -118,7 +118,7 @@ export function parsePluginI18n(value) {
118
118
  return parseOrThrow(pluginI18n, value, 'i18n.');
119
119
  }
120
120
  const manifestFields = {
121
- apiVersion: z.literal(1),
121
+ apiVersion: z.literal(3),
122
122
  };
123
123
  const jsEntry = z
124
124
  .string()
@@ -154,7 +154,7 @@ const manifest = z
154
154
  kind: z.literal('actions'),
155
155
  entry: jsEntry,
156
156
  writes: operationDeclarations,
157
- capabilities: z.array(z.enum(['files', 'notifications', 'storage', 'ui'])),
157
+ capabilities: z.array(z.enum(['files', 'images', 'notifications', 'storage', 'ui'])),
158
158
  }),
159
159
  ...['theme', 'vocab'].map((kind) => z.strictObject({
160
160
  ...manifestFields,
@@ -208,19 +208,14 @@ const request = z.discriminatedUnion('method', [
208
208
  }),
209
209
  z.strictObject({ ...envelope, method: z.literal('files.open'), params: fileOpenOptions }),
210
210
  z.strictObject({ ...envelope, method: z.literal('files.save'), params: fileSaveOptions }),
211
+ z.strictObject({
212
+ ...envelope,
213
+ method: z.literal('images.renderView'),
214
+ params: imageRenderOptions,
215
+ }),
211
216
  ]);
212
217
  const wireError = z.strictObject({
213
- code: z.enum([
214
- 'invalid-input',
215
- 'denied',
216
- 'stale-state',
217
- 'stale-context',
218
- 'unavailable',
219
- 'cancelled',
220
- 'timeout',
221
- 'closed',
222
- 'failed',
223
- ]),
218
+ code: z.enum(pluginErrorCodes),
224
219
  issues: z
225
220
  .array(z.strictObject({ path: text(256), message: text(2048) }))
226
221
  .min(1)
@@ -340,6 +335,7 @@ const results = {
340
335
  'notifications.notify': id,
341
336
  'files.open': fileOpenResult,
342
337
  'files.save': z.strictObject({ saved: z.boolean() }),
338
+ 'images.renderView': renderedImage,
343
339
  };
344
340
  export function parsePluginMessage(value) {
345
341
  checkMessageSize(value, runtimeLimits.request);
@@ -491,14 +487,15 @@ export function createPluginClient(port, initial) {
491
487
  applyOperations,
492
488
  },
493
489
  notifications: { notify: (value) => call('notifications.notify', value) },
490
+ images: { renderView: (options) => call('images.renderView', options) },
494
491
  files: {
495
492
  open: (options) => call('files.open', options),
496
493
  save: (options) => call('files.save', options),
497
494
  },
498
495
  storage: {
499
496
  list: listStorage,
500
- set: (key, value, conceptId) => mutateStorage('storage.set', conceptId === undefined ? { key, value } : { key, value, conceptId }),
501
- delete: (key, conceptId) => mutateStorage('storage.delete', conceptId === undefined ? { key } : { key, conceptId }),
497
+ set: (key, value, scope) => mutateStorage('storage.set', scope === undefined ? { key, value } : { key, value, scope }),
498
+ delete: (key, scope) => mutateStorage('storage.delete', scope === undefined ? { key } : { key, scope }),
502
499
  },
503
500
  signal: controller.signal,
504
501
  };
@@ -11,13 +11,32 @@ export declare const pluginStorageLimits: {
11
11
  type JsonValue = null | string | number | boolean | readonly JsonValue[] | {
12
12
  readonly [key: string]: JsonValue;
13
13
  };
14
+ declare const pluginStorageScope: z.ZodDiscriminatedUnion<[z.ZodObject<{
15
+ kind: z.ZodLiteral<"concept">;
16
+ id: z.ZodString;
17
+ }, z.core.$strict>, z.ZodObject<{
18
+ kind: z.ZodLiteral<"view">;
19
+ id: z.ZodString;
20
+ }, z.core.$strict>], "kind">;
14
21
  export declare const pluginStorageKey: z.ZodObject<{
15
22
  key: z.ZodString;
16
- conceptId: z.ZodOptional<z.ZodString>;
23
+ scope: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
24
+ kind: z.ZodLiteral<"concept">;
25
+ id: z.ZodString;
26
+ }, z.core.$strict>, z.ZodObject<{
27
+ kind: z.ZodLiteral<"view">;
28
+ id: z.ZodString;
29
+ }, z.core.$strict>], "kind">>;
17
30
  }, z.core.$strict>;
18
31
  export declare const pluginStorageRecord: z.ZodObject<{
19
32
  key: z.ZodString;
20
- conceptId: z.ZodOptional<z.ZodString>;
33
+ scope: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
34
+ kind: z.ZodLiteral<"concept">;
35
+ id: z.ZodString;
36
+ }, z.core.$strict>, z.ZodObject<{
37
+ kind: z.ZodLiteral<"view">;
38
+ id: z.ZodString;
39
+ }, z.core.$strict>], "kind">>;
21
40
  value: z.ZodPipe<z.ZodCustom<JsonValue, JsonValue>, z.ZodTransform<string | number | boolean | readonly JsonValue[] | {
22
41
  readonly [key: string]: JsonValue;
23
42
  } | null, JsonValue>>;
@@ -27,7 +46,13 @@ export declare const pluginStorageSnapshot: z.ZodObject<{
27
46
  revision: z.ZodNumber;
28
47
  records: z.ZodArray<z.ZodObject<{
29
48
  key: z.ZodString;
30
- conceptId: z.ZodOptional<z.ZodString>;
49
+ scope: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
50
+ kind: z.ZodLiteral<"concept">;
51
+ id: z.ZodString;
52
+ }, z.core.$strict>, z.ZodObject<{
53
+ kind: z.ZodLiteral<"view">;
54
+ id: z.ZodString;
55
+ }, z.core.$strict>], "kind">>;
31
56
  value: z.ZodPipe<z.ZodCustom<JsonValue, JsonValue>, z.ZodTransform<string | number | boolean | readonly JsonValue[] | {
32
57
  readonly [key: string]: JsonValue;
33
58
  } | null, JsonValue>>;
@@ -35,10 +60,11 @@ export declare const pluginStorageSnapshot: z.ZodObject<{
35
60
  }, z.core.$strict>;
36
61
  export type PluginStorageRecord = DeepReadonly<z.infer<typeof pluginStorageRecord>>;
37
62
  export type PluginStorageKey = DeepReadonly<z.infer<typeof pluginStorageKey>>;
63
+ export type PluginStorageScope = DeepReadonly<z.infer<typeof pluginStorageScope>>;
38
64
  export type PluginStorage = {
39
65
  readonly list: () => Promise<readonly PluginStorageRecord[]>;
40
- readonly set: (key: string, value: PluginStorageRecord['value'], conceptId?: string) => Promise<boolean>;
41
- readonly delete: (key: string, conceptId?: string) => Promise<boolean>;
66
+ readonly set: (key: string, value: PluginStorageRecord['value'], scope?: PluginStorageScope) => Promise<boolean>;
67
+ readonly delete: (key: string, scope?: PluginStorageScope) => Promise<boolean>;
42
68
  };
43
69
  export declare function parsePluginStorageSnapshot(value: unknown): DeepReadonly<z.infer<typeof pluginStorageSnapshot>>;
44
70
  export declare function parsePluginStorageRecord(value: unknown): PluginStorageRecord;
@@ -25,9 +25,13 @@ const isJsonValue = (value, depth = 0) => {
25
25
  Reflect.ownKeys(value).length === Object.keys(value).length &&
26
26
  Object.values(value).every((item) => isJsonValue(item, depth + 1)));
27
27
  };
28
+ const pluginStorageScope = z.discriminatedUnion('kind', [
29
+ z.strictObject({ kind: z.literal('concept'), id: z.string().max(2048) }),
30
+ z.strictObject({ kind: z.literal('view'), id: z.string().max(2048) }),
31
+ ]);
28
32
  const fields = {
29
33
  key: z.string().min(1).max(128),
30
- conceptId: z.string().max(2048).optional(),
34
+ scope: pluginStorageScope.optional(),
31
35
  };
32
36
  export const pluginStorageKey = z.strictObject(fields);
33
37
  export const pluginStorageRecord = z
package/dist/package.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import { c as PluginI18n, l as PluginManifest } from "./runtime-BxtTAcko.js";
1
+ import { c as PluginI18n, l as PluginManifest } from "./runtime-DCyJA620.js";
2
2
  //#region src/package.d.ts
3
3
  export declare const packageLimits: {
4
4
  readonly entry: number;
5
- readonly font: number;
6
- readonly fonts: 32;
7
5
  readonly record: number;
8
6
  readonly installed: 32;
9
7
  readonly total: number;
@@ -23,14 +21,9 @@ export type PreparedPlugin = {
23
21
  readonly nesso: PluginManifest;
24
22
  readonly i18n: PluginI18n;
25
23
  readonly code: string;
26
- readonly fonts: readonly {
27
- readonly path: string;
28
- readonly data: string;
29
- }[];
30
24
  readonly contentId: string;
31
25
  };
32
26
  export declare function parsePackageIdentity(value: unknown): any;
33
27
  export declare function preparePluginPackage(input: PluginPackageInput): Promise<PreparedPlugin>;
34
- export declare function packageFonts(value: PreparedPlugin): ReadonlyMap<string, Uint8Array>;
35
28
  export declare function verifyPluginPackage(value: PreparedPlugin): Promise<PreparedPlugin>;
36
29
  //#endregion
package/dist/package.js CHANGED
@@ -1,12 +1,10 @@
1
- import { C as PluginError, _ as checkMessageSize, o as parsePluginI18n, s as parsePluginManifest, u as sha256Hex, w as parseOrThrow, x as parseDefinition } from "./runtime-BM45o1qi.js";
1
+ import { C as parseOrThrow, S as PluginError, g as checkMessageSize, o as parsePluginI18n, s as parsePluginManifest, u as sha256Hex, v as parseDefinition } from "./runtime-uvKgm2yV.js";
2
2
  import { z } from "zod";
3
3
  import parseVersion from "semver/functions/parse.js";
4
4
  import validateName from "validate-npm-package-name";
5
5
  //#region src/package.ts
6
6
  const packageLimits = {
7
7
  entry: 16777216,
8
- font: 4194304,
9
- fonts: 32,
10
8
  record: 33554432,
11
9
  installed: 32,
12
10
  total: 134217728
@@ -48,50 +46,21 @@ async function preparePluginPackage(input) {
48
46
  const { name, version, author, repository, nesso: declaration, i18n: translations } = parsePackageIdentity(input.manifest);
49
47
  const nesso = parsePluginManifest(declaration);
50
48
  const i18n = parsePluginI18n(translations);
51
- if (!Array.isArray(input.files) || !input.files.length || input.files.length > (nesso.kind === "theme" ? packageLimits.fonts + 1 : 1)) throw new PluginError("invalid-input", [{
49
+ if (!Array.isArray(input.files) || input.files.length !== 1) throw new PluginError("invalid-input", [{
52
50
  path: "files",
53
- message: "Expected one entry and supported local theme fonts only"
51
+ message: "Expected one plugin entry only"
54
52
  }]);
55
- const paths = /* @__PURE__ */ new Set();
56
- const fonts = [];
57
- const files = [];
58
- let bytes;
59
- let admitted = 0;
60
- for (const file of input.files) {
61
- if (!file || typeof file.path !== "string" || file.path.length > 240 || paths.has(file.path) || !(file.bytes instanceof Uint8Array) || !file.bytes.byteLength || file.bytes.byteLength > (file.path === nesso.entry ? packageLimits.entry : packageLimits.font)) throw new PluginError("invalid-input", [{
62
- path: "files",
63
- message: "Invalid, duplicate, or oversized package file"
64
- }]);
65
- paths.add(file.path);
66
- admitted += file.path === nesso.entry ? file.bytes.byteLength : Math.ceil(file.bytes.byteLength / 3) * 4;
67
- if (admitted > packageLimits.record) throw new PluginError("invalid-input", [{
68
- path: "files",
69
- message: "Package record budget exceeded"
70
- }]);
71
- const content = new Uint8Array(file.bytes);
72
- if (file.path === nesso.entry) bytes = content;
73
- else {
74
- if (nesso.kind !== "theme" || !/^(?:[\w-]+\/)*[\w-]+\.woff2$/.test(file.path) || new TextDecoder().decode(content.subarray(0, 4)) !== "wOF2") throw new PluginError("invalid-input", [{
75
- path: file.path,
76
- message: "Expected a package-local WOFF2 font"
77
- }]);
78
- let binary = "";
79
- for (let offset = 0; offset < content.length; offset += 32768) binary += String.fromCharCode(...content.subarray(offset, offset + 32768));
80
- fonts.push({
81
- path: file.path,
82
- data: btoa(binary)
83
- });
84
- }
85
- files.push({
86
- path: file.path,
87
- size: content.byteLength,
88
- sha256: await sha256Hex(content)
89
- });
90
- }
91
- if (!bytes) throw new PluginError("invalid-input", [{
92
- path: "nesso.entry",
93
- message: "Missing plugin entry"
53
+ const file = input.files[0];
54
+ if (!file || file.path !== nesso.entry || !(file.bytes instanceof Uint8Array) || !file.bytes.byteLength || file.bytes.byteLength > packageLimits.entry) throw new PluginError("invalid-input", [{
55
+ path: "files",
56
+ message: "Expected the plugin entry within size limits"
94
57
  }]);
58
+ const bytes = new Uint8Array(file.bytes);
59
+ const files = [{
60
+ path: file.path,
61
+ size: bytes.byteLength,
62
+ sha256: await sha256Hex(bytes)
63
+ }];
95
64
  let code;
96
65
  try {
97
66
  code = new TextDecoder("utf-8", {
@@ -116,7 +85,6 @@ async function preparePluginPackage(input) {
116
85
  }
117
86
  parseDefinition(nesso.kind, raw);
118
87
  }
119
- const order = (left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
120
88
  const index = {
121
89
  name,
122
90
  version,
@@ -124,7 +92,7 @@ async function preparePluginPackage(input) {
124
92
  repository,
125
93
  nesso,
126
94
  i18n,
127
- files: files.sort(order)
95
+ files
128
96
  };
129
97
  const prepared = {
130
98
  name,
@@ -134,7 +102,6 @@ async function preparePluginPackage(input) {
134
102
  nesso,
135
103
  i18n,
136
104
  code,
137
- fonts: fonts.sort(order),
138
105
  contentId: await sha256Hex(new TextEncoder().encode(canonical(index)))
139
106
  };
140
107
  if (new TextEncoder().encode(JSON.stringify(prepared)).byteLength > packageLimits.record) throw new PluginError("invalid-input", [{
@@ -143,36 +110,11 @@ async function preparePluginPackage(input) {
143
110
  }]);
144
111
  return prepared;
145
112
  }
146
- function packageFonts(value) {
147
- if (!Array.isArray(value.fonts) || value.fonts.length > packageLimits.fonts) throw new PluginError("invalid-input", [{
148
- path: "fonts",
149
- message: "Invalid installed font assets"
150
- }]);
151
- return new Map(value.fonts.map((font) => {
152
- if (!font || typeof font.path !== "string" || typeof font.data !== "string" || font.data.length > Math.ceil(packageLimits.font / 3) * 4) throw new PluginError("invalid-input", [{
153
- path: "fonts",
154
- message: "Invalid font encoding or budget"
155
- }]);
156
- try {
157
- return [font.path, Uint8Array.from(atob(font.data), (character) => character.charCodeAt(0))];
158
- } catch {
159
- throw new PluginError("invalid-input", [{
160
- path: "fonts",
161
- message: "Invalid font encoding"
162
- }]);
163
- }
164
- }));
165
- }
166
113
  async function verifyPluginPackage(value) {
167
114
  if (!value || typeof value.code !== "string" || value.code.length > packageLimits.entry) throw new PluginError("invalid-input", [{
168
115
  path: "package",
169
116
  message: "Invalid installed plugin package"
170
117
  }]);
171
- const fonts = packageFonts(value);
172
- if (fonts.size !== value.fonts.length) throw new PluginError("invalid-input", [{
173
- path: "fonts",
174
- message: "Duplicate font assets"
175
- }]);
176
118
  const prepared = await preparePluginPackage({
177
119
  manifest: {
178
120
  name: value.name,
@@ -185,10 +127,7 @@ async function verifyPluginPackage(value) {
185
127
  files: [{
186
128
  path: value.nesso?.entry,
187
129
  bytes: new TextEncoder().encode(value.code)
188
- }, ...[...fonts].map(([path, bytes]) => ({
189
- path,
190
- bytes
191
- }))]
130
+ }]
192
131
  });
193
132
  if (prepared.contentId !== value.contentId) throw new PluginError("denied", [{
194
133
  path: "contentId",
@@ -197,4 +136,4 @@ async function verifyPluginPackage(value) {
197
136
  return prepared;
198
137
  }
199
138
  //#endregion
200
- export { packageFonts, packageLimits, parsePackageIdentity, preparePluginPackage, verifyPluginPackage };
139
+ export { packageLimits, parsePackageIdentity, preparePluginPackage, verifyPluginPackage };