@harnesys/sdk 0.0.0-stage → 1.0.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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -2
  3. package/dist/addon-context-factory.d.ts +6 -0
  4. package/dist/addon-context-factory.js +160 -0
  5. package/dist/addon-context.d.ts +346 -0
  6. package/dist/addon-context.js +0 -0
  7. package/dist/define-addon.d.ts +57 -0
  8. package/dist/define-addon.js +53 -0
  9. package/dist/families/config.d.ts +14 -0
  10. package/dist/families/config.js +16 -0
  11. package/dist/families/content.d.ts +28 -0
  12. package/dist/families/content.js +19 -0
  13. package/dist/families/field-spec.d.ts +100 -0
  14. package/dist/families/field-spec.js +85 -0
  15. package/dist/families/hook.d.ts +37 -0
  16. package/dist/families/hook.js +25 -0
  17. package/dist/families/job.d.ts +45 -0
  18. package/dist/families/job.js +26 -0
  19. package/dist/families/json-schema.d.ts +36 -0
  20. package/dist/families/json-schema.js +101 -0
  21. package/dist/families/lsp.d.ts +18 -0
  22. package/dist/families/lsp.js +18 -0
  23. package/dist/families/mcp.d.ts +18 -0
  24. package/dist/families/mcp.js +18 -0
  25. package/dist/families/registry.d.ts +9 -0
  26. package/dist/families/registry.js +34 -0
  27. package/dist/families/route.d.ts +38 -0
  28. package/dist/families/route.js +37 -0
  29. package/dist/families/source-kind.d.ts +24 -0
  30. package/dist/families/source-kind.js +21 -0
  31. package/dist/families/tool-pack.d.ts +68 -0
  32. package/dist/families/tool-pack.js +57 -0
  33. package/dist/families/transport.d.ts +52 -0
  34. package/dist/families/transport.js +29 -0
  35. package/dist/families/trigger.d.ts +97 -0
  36. package/dist/families/trigger.js +46 -0
  37. package/dist/families/view.d.ts +255 -0
  38. package/dist/families/view.js +87 -0
  39. package/dist/families/viewer.d.ts +31 -0
  40. package/dist/families/viewer.js +26 -0
  41. package/dist/families/worker.d.ts +23 -0
  42. package/dist/families/worker.js +19 -0
  43. package/dist/host-client.d.ts +11 -0
  44. package/dist/host-client.js +30 -0
  45. package/dist/index.d.ts +35 -0
  46. package/dist/index.js +35 -0
  47. package/dist/manifest/branding.d.ts +14 -0
  48. package/dist/manifest/branding.js +18 -0
  49. package/dist/manifest/connections.d.ts +21 -0
  50. package/dist/manifest/connections.js +10 -0
  51. package/dist/manifest/json-schema.d.ts +2 -0
  52. package/dist/manifest/json-schema.js +13 -0
  53. package/dist/manifest/l10n.d.ts +9 -0
  54. package/dist/manifest/l10n.js +28 -0
  55. package/dist/manifest/manifest.d.ts +112 -0
  56. package/dist/manifest/manifest.js +45 -0
  57. package/dist/manifest/validate.d.ts +14 -0
  58. package/dist/manifest/validate.js +144 -0
  59. package/dist/permissions/permissions.d.ts +31 -0
  60. package/dist/permissions/permissions.js +53 -0
  61. package/dist/process-entry.d.ts +26 -0
  62. package/dist/process-entry.js +146 -0
  63. package/dist/protocol/envelope.d.ts +115 -0
  64. package/dist/protocol/envelope.js +72 -0
  65. package/dist/protocol/error.d.ts +67 -0
  66. package/dist/protocol/error.js +61 -0
  67. package/dist/protocol/handshake.d.ts +55 -0
  68. package/dist/protocol/handshake.js +26 -0
  69. package/dist/protocol/map.d.ts +1090 -0
  70. package/dist/protocol/map.js +127 -0
  71. package/dist/protocol/meta.d.ts +31 -0
  72. package/dist/protocol/meta.js +14 -0
  73. package/dist/protocol/method-spec.d.ts +13 -0
  74. package/dist/protocol/method-spec.js +9 -0
  75. package/dist/protocol/org-service-methods.d.ts +135 -0
  76. package/dist/protocol/org-service-methods.js +106 -0
  77. package/dist/protocol/shared.d.ts +389 -0
  78. package/dist/protocol/shared.js +231 -0
  79. package/dist/protocol/source-methods.d.ts +218 -0
  80. package/dist/protocol/source-methods.js +18 -0
  81. package/dist/protocol/thread-service-methods.d.ts +50 -0
  82. package/dist/protocol/thread-service-methods.js +32 -0
  83. package/dist/runtime.d.ts +25 -0
  84. package/dist/runtime.js +229 -0
  85. package/dist/testing/fake-db.d.ts +15 -0
  86. package/dist/testing/fake-db.js +120 -0
  87. package/dist/testing/fake-files.d.ts +9 -0
  88. package/dist/testing/fake-files.js +87 -0
  89. package/dist/testing/fake-host.d.ts +115 -0
  90. package/dist/testing/fake-host.js +152 -0
  91. package/dist/testing/fake-services.d.ts +63 -0
  92. package/dist/testing/fake-services.js +277 -0
  93. package/dist/testing/fixtures.d.ts +4 -0
  94. package/dist/testing/fixtures.js +84 -0
  95. package/dist/testing/index.d.ts +4 -0
  96. package/dist/testing/index.js +2 -0
  97. package/package.json +66 -4
  98. package/src/addon-context-factory.ts +236 -0
  99. package/src/addon-context.ts +313 -0
  100. package/src/define-addon.ts +178 -0
  101. package/src/families/config.ts +24 -0
  102. package/src/families/content.ts +35 -0
  103. package/src/families/field-spec.ts +175 -0
  104. package/src/families/hook.ts +34 -0
  105. package/src/families/job.ts +41 -0
  106. package/src/families/json-schema.ts +167 -0
  107. package/src/families/lsp.ts +28 -0
  108. package/src/families/mcp.ts +28 -0
  109. package/src/families/registry.ts +44 -0
  110. package/src/families/route.ts +52 -0
  111. package/src/families/source-kind.ts +34 -0
  112. package/src/families/tool-pack.ts +92 -0
  113. package/src/families/transport.ts +52 -0
  114. package/src/families/trigger.ts +92 -0
  115. package/src/families/view.ts +144 -0
  116. package/src/families/viewer.ts +43 -0
  117. package/src/families/worker.ts +30 -0
  118. package/src/host-client.ts +52 -0
  119. package/src/index.ts +341 -0
  120. package/src/manifest/branding.ts +24 -0
  121. package/src/manifest/connections.ts +21 -0
  122. package/src/manifest/json-schema.ts +24 -0
  123. package/src/manifest/l10n.ts +39 -0
  124. package/src/manifest/manifest.ts +94 -0
  125. package/src/manifest/validate.ts +200 -0
  126. package/src/permissions/permissions.ts +79 -0
  127. package/src/process-entry.ts +205 -0
  128. package/src/protocol/envelope.ts +126 -0
  129. package/src/protocol/error.ts +81 -0
  130. package/src/protocol/handshake.ts +43 -0
  131. package/src/protocol/map.ts +339 -0
  132. package/src/protocol/meta.ts +26 -0
  133. package/src/protocol/method-spec.ts +40 -0
  134. package/src/protocol/org-service-methods.ts +148 -0
  135. package/src/protocol/shared.ts +345 -0
  136. package/src/protocol/source-methods.ts +61 -0
  137. package/src/protocol/thread-service-methods.ts +50 -0
  138. package/src/runtime.ts +332 -0
  139. package/src/testing/fake-db.ts +140 -0
  140. package/src/testing/fake-files.ts +114 -0
  141. package/src/testing/fake-host.ts +261 -0
  142. package/src/testing/fake-services.ts +345 -0
  143. package/src/testing/fixtures.ts +88 -0
  144. package/src/testing/index.ts +12 -0
package/src/index.ts ADDED
@@ -0,0 +1,341 @@
1
+ export {
2
+ type AddonAccounts,
3
+ type AddonBridge,
4
+ type AddonConfig,
5
+ type AddonContext,
6
+ type AddonDb,
7
+ type AddonEvents,
8
+ type AddonFileChunk,
9
+ type AddonFileStat,
10
+ type AddonFiles,
11
+ type AddonFileWriteResult,
12
+ type AddonHttp,
13
+ type AddonLog,
14
+ type AddonLogLevel,
15
+ type AddonProgress,
16
+ type AddonRuns,
17
+ type AddonSecrets,
18
+ type AddonSkills,
19
+ type AddonThreads,
20
+ type AddonTriggerField,
21
+ type AddonTriggers,
22
+ type AddonTriggerTarget,
23
+ type AddonUsage,
24
+ type AddonWorkers,
25
+ createAddonContext,
26
+ type DbRow,
27
+ type DbStatement,
28
+ type DbWriteResult,
29
+ type SqlParam,
30
+ } from './addon-context-factory.ts';
31
+ export {
32
+ type AddonDefinition,
33
+ defineAddon,
34
+ deriveHandlers,
35
+ type HookHandler,
36
+ type JobHandler,
37
+ type LifecycleHandlers,
38
+ type NotificationHandlers,
39
+ type ResolvedAddonDefinition,
40
+ type RouteHandler,
41
+ type SourceBackendHandlers,
42
+ type ToolHandler,
43
+ type TransportHandlers,
44
+ type TriggerPair,
45
+ type WorkerPair,
46
+ } from './define-addon.ts';
47
+ export {
48
+ CONFIG_SCHEMA_VERSION,
49
+ type ConfigDescriptor,
50
+ ConfigDescriptorSchema,
51
+ configFamily,
52
+ } from './families/config.ts';
53
+ export {
54
+ CONTENT_SCHEMA_VERSION,
55
+ type ContentDescriptor,
56
+ ContentDescriptorSchema,
57
+ contentFamily,
58
+ } from './families/content.ts';
59
+ export {
60
+ defaultConfigValues,
61
+ type FieldOption,
62
+ FieldOptionSchema,
63
+ type FieldOptionsFrom,
64
+ FieldOptionsFromSchema,
65
+ type FieldSpec,
66
+ FieldSpecSchema,
67
+ type FieldType,
68
+ FieldTypeSchema,
69
+ type FieldValue,
70
+ FieldValueSchema,
71
+ type FieldVisibleWhen,
72
+ FieldVisibleWhenSchema,
73
+ type FieldWidget,
74
+ FieldWidgetSchema,
75
+ } from './families/field-spec.ts';
76
+ export {
77
+ HOOK_SCHEMA_VERSION,
78
+ type HookDescriptor,
79
+ HookDescriptorSchema,
80
+ HookOnSchema,
81
+ hookFamily,
82
+ } from './families/hook.ts';
83
+ export {
84
+ JOB_SCHEMA_VERSION,
85
+ type JobDescriptor,
86
+ JobDescriptorSchema,
87
+ JobScheduleSchema,
88
+ jobFamily,
89
+ } from './families/job.ts';
90
+ export {
91
+ INPUT_SCHEMA_MAX_BYTES,
92
+ INPUT_SCHEMA_MAX_DEPTH,
93
+ type JsonSchemaSubset,
94
+ JsonSchemaSubsetSchema,
95
+ type SchemaViolation,
96
+ validateInputSchema,
97
+ } from './families/json-schema.ts';
98
+ export {
99
+ LSP_SCHEMA_VERSION,
100
+ type LspDescriptor,
101
+ LspDescriptorSchema,
102
+ lspFamily,
103
+ } from './families/lsp.ts';
104
+ export {
105
+ MCP_SCHEMA_VERSION,
106
+ type McpDescriptor,
107
+ McpDescriptorSchema,
108
+ mcpFamily,
109
+ } from './families/mcp.ts';
110
+ export {
111
+ FAMILY_NAMES,
112
+ type FamilyDefinition,
113
+ familyDefinition,
114
+ familyRegistry,
115
+ } from './families/registry.ts';
116
+ export {
117
+ ROUTE_SCHEMA_VERSION,
118
+ type RouteDescriptor,
119
+ RouteDescriptorSchema,
120
+ type RouteMethod,
121
+ routeFamily,
122
+ } from './families/route.ts';
123
+ export {
124
+ SOURCE_KIND_SCHEMA_VERSION,
125
+ type SourceKindDescriptor,
126
+ SourceKindDescriptorSchema,
127
+ sourceKindFamily,
128
+ } from './families/source-kind.ts';
129
+ export {
130
+ TOOL_PACK_SCHEMA_VERSION,
131
+ type ToolDescriptor,
132
+ ToolDescriptorSchema,
133
+ type ToolEffect,
134
+ type ToolPackDescriptor,
135
+ ToolPackDescriptorSchema,
136
+ toolPackFamily,
137
+ } from './families/tool-pack.ts';
138
+ export {
139
+ TRANSPORT_SCHEMA_VERSION,
140
+ type TransportCapabilities,
141
+ TransportCapabilitiesSchema,
142
+ type TransportDescriptor,
143
+ TransportDescriptorSchema,
144
+ transportFamily,
145
+ } from './families/transport.ts';
146
+ export {
147
+ TRIGGER_SCHEMA_VERSION,
148
+ type TriggerDescriptor,
149
+ TriggerDescriptorSchema,
150
+ type TriggerLimits,
151
+ triggerFamily,
152
+ } from './families/trigger.ts';
153
+ export {
154
+ type Action,
155
+ ActionSchema,
156
+ type Column,
157
+ ColumnSchema,
158
+ type RouteRef,
159
+ RouteRefSchema,
160
+ VIEW_SCHEMA_VERSION,
161
+ type ViewDescriptor,
162
+ ViewDescriptorSchema,
163
+ type ViewSection,
164
+ ViewSectionSchema,
165
+ viewFamily,
166
+ } from './families/view.ts';
167
+ export {
168
+ VIEWER_SCHEMA_VERSION,
169
+ type ViewerDescriptor,
170
+ ViewerDescriptorSchema,
171
+ ViewerExtensionSchema,
172
+ viewerFamily,
173
+ } from './families/viewer.ts';
174
+ export {
175
+ WORKER_SCHEMA_VERSION,
176
+ type WorkerDescriptor,
177
+ WorkerDescriptorSchema,
178
+ workerFamily,
179
+ } from './families/worker.ts';
180
+ export { createHostClient, type HostChannel } from './host-client.ts';
181
+ export { AddonIconRefSchema, HexColorSchema, LucideIconNameSchema } from './manifest/branding.ts';
182
+ export { type ConnectionRequirement, ConnectionRequirementSchema } from './manifest/connections.ts';
183
+ export { contributionDescriptorJsonSchema, manifestJsonSchema } from './manifest/json-schema.ts';
184
+ export { type L10n, L10nSchema, l10nKeys, resolveL10n } from './manifest/l10n.ts';
185
+ export {
186
+ type AddonDataSpec,
187
+ AddonDataSpecSchema,
188
+ AddonIdSchema,
189
+ type AddonManifest,
190
+ AddonManifestSchema,
191
+ type AddonRuntimeSpec,
192
+ AddonRuntimeSpecSchema,
193
+ type Contribution,
194
+ ContributionIdSchema,
195
+ ContributionSchema,
196
+ parseAddonManifest,
197
+ } from './manifest/manifest.ts';
198
+ export { type ManifestValidation, type Violation, validateManifest } from './manifest/validate.ts';
199
+ export {
200
+ BASELINE_PERMISSION_IDS,
201
+ type BaselinePermissionId,
202
+ type EffectivePermission,
203
+ EffectivePermissionSchema,
204
+ isBaselinePermissionId,
205
+ isKnownPermissionId,
206
+ type JsonObject,
207
+ JsonObjectSchema,
208
+ KNOWN_PERMISSION_IDS,
209
+ type KnownPermissionId,
210
+ type PermissionRequest,
211
+ PermissionRequestSchema,
212
+ type PermissionScope,
213
+ } from './permissions/permissions.ts';
214
+ export {
215
+ createStdioChannel,
216
+ PROTOCOL_PLATFORM,
217
+ type StartAddonProcessOptions,
218
+ type StdioWiring,
219
+ startAddonProcess,
220
+ } from './process-entry.ts';
221
+ export {
222
+ type CancelNotification,
223
+ CancelNotificationSchema,
224
+ decodeMessage,
225
+ encodeMessage,
226
+ errorResponse,
227
+ JSONRPC_VERSION,
228
+ type JsonRpcError,
229
+ JsonRpcErrorSchema,
230
+ JsonRpcIdSchema,
231
+ type JsonRpcNotification,
232
+ JsonRpcNotificationSchema,
233
+ type JsonRpcRequest,
234
+ JsonRpcRequestSchema,
235
+ type JsonRpcResponse,
236
+ JsonRpcResponseSchema,
237
+ MAX_MESSAGE_BYTES,
238
+ notification,
239
+ type ProgressNotification,
240
+ ProgressNotificationSchema,
241
+ request,
242
+ response,
243
+ } from './protocol/envelope.ts';
244
+ export {
245
+ AddonError,
246
+ type AddonErrorData,
247
+ AddonErrorDataSchema,
248
+ type AddonErrorReason,
249
+ AddonErrorReasonSchema,
250
+ isAddonError,
251
+ } from './protocol/error.ts';
252
+ export {
253
+ type InitializeParams,
254
+ InitializeParamsSchema,
255
+ type InitializeResult,
256
+ InitializeResultSchema,
257
+ } from './protocol/handshake.ts';
258
+ export {
259
+ type AddonDispatcher,
260
+ type AddonHandlerOf,
261
+ type AddonNotify,
262
+ type AddonToHostMethods,
263
+ addonMethod,
264
+ type HostNotify,
265
+ type HostRequestName,
266
+ type HostRequestParams,
267
+ type HostRequestResult,
268
+ type HostServiceClient,
269
+ type HostServiceName,
270
+ type HostServiceParams,
271
+ type HostServiceResult,
272
+ type HostToAddonMethods,
273
+ hostMethod,
274
+ type MethodDirection,
275
+ type MethodSpec,
276
+ type MethodsOf,
277
+ methodSpec,
278
+ type NotificationMethods,
279
+ type NotificationName,
280
+ type NotificationSender,
281
+ notificationSpec,
282
+ type ParamsOf,
283
+ PROTOCOL_METHODS,
284
+ type ProtocolEntry,
285
+ type ProtocolMethodMap,
286
+ protocolEntries,
287
+ protocolMap,
288
+ type ResultOf,
289
+ stripMeta,
290
+ } from './protocol/map.ts';
291
+ export { type CallMeta, CallMetaSchema } from './protocol/meta.ts';
292
+ export {
293
+ AccountSummarySchema,
294
+ type AppCredentials,
295
+ AppCredentialsSchema,
296
+ type BridgeInboundOutcome,
297
+ BridgeInboundOutcomeSchema,
298
+ CloudRemoteEntrySchema,
299
+ type CloudRemoteEntryWire,
300
+ CloudRemoteExportSchema,
301
+ type CloudRemoteExportWire,
302
+ FileReadParamsSchema,
303
+ FileReadResultSchema,
304
+ FileStatParamsSchema,
305
+ FileStatResultSchema,
306
+ FileWriteParamsSchema,
307
+ FileWriteResultSchema,
308
+ HttpAuthSchema,
309
+ HttpFetchParamsSchema,
310
+ HttpFetchResultSchema,
311
+ type InboundAttachment,
312
+ InboundAttachmentSchema,
313
+ InboundMessageSchema,
314
+ type LogLevel,
315
+ LogLevelSchema,
316
+ LogWriteParamsSchema,
317
+ type MessageFormat,
318
+ type RouteHandleResult,
319
+ RouteHandleResultSchema,
320
+ type RouteRequest,
321
+ RouteRequestSchema,
322
+ SourceBytesResultSchema,
323
+ SourceExportParamsSchema,
324
+ SourceListParamsSchema,
325
+ SourceListResultSchema,
326
+ SourceMkdirParamsSchema,
327
+ SourceMkdirResultSchema,
328
+ SourceReadParamsSchema,
329
+ SourceRemoveParamsSchema,
330
+ SourceStatParamsSchema,
331
+ SourceStatResultSchema,
332
+ SourceUploadParamsSchema,
333
+ SourceUploadResultSchema,
334
+ type TransportAttachment,
335
+ type TransportBindingSummary,
336
+ TransportBindingSummarySchema,
337
+ type TransportMessage,
338
+ TransportMessageSchema,
339
+ TriggerFireOutcomeSchema,
340
+ } from './protocol/shared.ts';
341
+ export { type AddonRuntime, type AddonRuntimeOptions, createAddonRuntime } from './runtime.ts';
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Lucide icon name in kebab-case (`'webhook'`, `'calendar-clock'`). Resolved by
5
+ * the web UI against `lucide-react/dynamic`; unknown names fall back to a
6
+ * default icon instead of failing.
7
+ */
8
+ export const LucideIconNameSchema = z
9
+ .string()
10
+ .regex(/^[a-z][a-z0-9-]*$/, 'icon must be a lucide icon name in kebab-case');
11
+
12
+ /**
13
+ * Addon-level icon: either a lucide icon name or an SVG shipped with the
14
+ * package (`'assets/icon.svg'`).
15
+ */
16
+ export const AddonIconRefSchema = z
17
+ .string()
18
+ .regex(
19
+ /^(assets\/[a-z0-9][a-z0-9._/-]*\.svg|[a-z][a-z0-9-]*)$/,
20
+ "icon must be a lucide icon name or an 'assets/*.svg' path",
21
+ );
22
+
23
+ /** Brand color as a 6-digit hex literal (`'#229ED9'`). */
24
+ export const HexColorSchema = z.string().regex(/^#[0-9a-fA-F]{6}$/, 'color must be #RRGGBB');
@@ -0,0 +1,21 @@
1
+ import { z } from 'zod';
2
+ import type { L10n } from './l10n.ts';
3
+ import { L10nSchema } from './l10n.ts';
4
+
5
+ export interface ConnectionRequirement {
6
+ id: string;
7
+ label: L10n;
8
+ accountKinds: string[];
9
+ scopes?: string[];
10
+ cardinality: 'one' | 'many';
11
+ optional?: boolean;
12
+ }
13
+
14
+ export const ConnectionRequirementSchema = z.object({
15
+ id: z.string().min(1),
16
+ label: L10nSchema,
17
+ accountKinds: z.array(z.string().min(1)).min(1),
18
+ scopes: z.array(z.string().min(1)).optional(),
19
+ cardinality: z.enum(['one', 'many']),
20
+ optional: z.boolean().optional(),
21
+ });
@@ -0,0 +1,24 @@
1
+ import { z } from 'zod';
2
+ import { familyRegistry } from '../families/registry.ts';
3
+ import { AddonManifestSchema } from './manifest.ts';
4
+
5
+ export function manifestJsonSchema(): Record<string, unknown> {
6
+ return z.toJSONSchema(AddonManifestSchema, { io: 'input', unrepresentable: 'any' }) as Record<
7
+ string,
8
+ unknown
9
+ >;
10
+ }
11
+
12
+ export function contributionDescriptorJsonSchema(
13
+ family: string,
14
+ v?: number,
15
+ ): Record<string, unknown> | null {
16
+ const module = familyRegistry[family];
17
+ if (!module) {
18
+ return null;
19
+ }
20
+ return z.toJSONSchema(module.schema(v ?? 1), { io: 'input', unrepresentable: 'any' }) as Record<
21
+ string,
22
+ unknown
23
+ >;
24
+ }
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+
3
+ export type L10n = string | Record<string, string>;
4
+
5
+ export const L10nSchema = z.union([z.string(), z.record(z.string(), z.string())]);
6
+
7
+ export interface L10nResolveOptions {
8
+ locale: string;
9
+ dict?: Record<string, string>;
10
+ }
11
+
12
+ export function resolveL10n(value: L10n, options: L10nResolveOptions): string {
13
+ if (typeof value === 'string') {
14
+ return interpolate(value, options.dict);
15
+ }
16
+ const direct = value[options.locale] ?? value.en ?? Object.values(value)[0];
17
+ return interpolate(direct ?? '', options.dict);
18
+ }
19
+
20
+ function interpolate(text: string, dict?: Record<string, string>): string {
21
+ if (!dict) {
22
+ return text;
23
+ }
24
+ return text.replace(/%([A-Za-z0-9_.-]+)%/g, (whole, key: string) => dict[key] ?? whole);
25
+ }
26
+
27
+ export function l10nKeys(value: L10n): string[] {
28
+ const source = typeof value === 'string' ? [value] : Object.values(value);
29
+ const keys: string[] = [];
30
+ for (const text of source) {
31
+ for (const match of text.matchAll(/%([A-Za-z0-9_.-]+)%/g)) {
32
+ const key = match[1];
33
+ if (key && !keys.includes(key)) {
34
+ keys.push(key);
35
+ }
36
+ }
37
+ }
38
+ return keys;
39
+ }
@@ -0,0 +1,94 @@
1
+ import { z } from 'zod';
2
+ import type { PermissionRequest } from '../permissions/permissions.ts';
3
+ import { PermissionRequestSchema } from '../permissions/permissions.ts';
4
+ import { AddonIconRefSchema, HexColorSchema } from './branding.ts';
5
+ import { type ConnectionRequirement, ConnectionRequirementSchema } from './connections.ts';
6
+ import { type L10n, L10nSchema } from './l10n.ts';
7
+
8
+ export type { ConnectionRequirement, L10n, PermissionRequest };
9
+
10
+ export interface AddonRuntimeSpec {
11
+ entry: string;
12
+ profile: 'trusted' | 'restricted';
13
+ }
14
+
15
+ export interface AddonDataSpec {
16
+ migrations: string;
17
+ quotaMb?: number;
18
+ }
19
+
20
+ export interface Contribution {
21
+ id: string;
22
+ family: string;
23
+ v?: number;
24
+ optional?: boolean;
25
+ descriptor: Record<string, unknown>;
26
+ }
27
+
28
+ export interface AddonManifest {
29
+ id: string;
30
+ version: string;
31
+ platform: number;
32
+ title: L10n;
33
+ description: L10n;
34
+ /** Lucide icon name or an SVG shipped with the package (`assets/*.svg`). */
35
+ icon?: string;
36
+ /** Brand color as `#RRGGBB`. */
37
+ color?: string;
38
+ homepage?: string;
39
+ license?: string;
40
+ runtime: AddonRuntimeSpec;
41
+ activation: 'lazy' | 'resident';
42
+ permissions: PermissionRequest[];
43
+ connections: ConnectionRequirement[];
44
+ data?: AddonDataSpec;
45
+ features?: string[];
46
+ contributions: Contribution[];
47
+ }
48
+
49
+ export const AddonIdSchema = z
50
+ .string()
51
+ .regex(/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/, 'addon id must be <publisher>.<name>');
52
+
53
+ export const ContributionIdSchema = z.string().regex(/^[a-z][a-z0-9-]*$/);
54
+
55
+ export const AddonRuntimeSpecSchema = z.object({
56
+ entry: z.string().min(1),
57
+ profile: z.enum(['trusted', 'restricted']),
58
+ });
59
+
60
+ export const AddonDataSpecSchema = z.object({
61
+ migrations: z.string().min(1),
62
+ quotaMb: z.number().int().positive().optional(),
63
+ });
64
+
65
+ export const ContributionSchema = z.object({
66
+ id: ContributionIdSchema,
67
+ family: z.string().min(1),
68
+ v: z.number().int().positive().optional(),
69
+ optional: z.boolean().optional(),
70
+ descriptor: z.record(z.string(), z.unknown()),
71
+ });
72
+
73
+ export const AddonManifestSchema = z.object({
74
+ id: AddonIdSchema,
75
+ version: z.string().regex(/^\d+\.\d+\.\d+$/, 'version must be semver'),
76
+ platform: z.number().int().positive(),
77
+ title: L10nSchema,
78
+ description: L10nSchema,
79
+ icon: AddonIconRefSchema.optional(),
80
+ color: HexColorSchema.optional(),
81
+ homepage: z.string().optional(),
82
+ license: z.string().optional(),
83
+ runtime: AddonRuntimeSpecSchema,
84
+ activation: z.enum(['lazy', 'resident']),
85
+ permissions: z.array(PermissionRequestSchema),
86
+ connections: z.array(ConnectionRequirementSchema),
87
+ data: AddonDataSpecSchema.optional(),
88
+ features: z.array(z.string()).optional(),
89
+ contributions: z.array(ContributionSchema),
90
+ });
91
+
92
+ export function parseAddonManifest(raw: unknown): AddonManifest {
93
+ return AddonManifestSchema.parse(raw);
94
+ }