@soulcraft/sdk 1.6.2 → 2.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 (176) hide show
  1. package/dist/client/create-client-sdk.d.ts +16 -2
  2. package/dist/client/create-client-sdk.d.ts.map +1 -1
  3. package/dist/client/create-client-sdk.js +2 -7
  4. package/dist/client/create-client-sdk.js.map +1 -1
  5. package/dist/client/index.d.ts +48 -37
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +61 -42
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/client/namespace-proxy.d.ts +108 -0
  10. package/dist/client/namespace-proxy.d.ts.map +1 -0
  11. package/dist/client/namespace-proxy.js +151 -0
  12. package/dist/client/namespace-proxy.js.map +1 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/modules/app-context/index.d.ts +214 -0
  17. package/dist/modules/app-context/index.d.ts.map +1 -0
  18. package/dist/modules/app-context/index.js +569 -0
  19. package/dist/modules/app-context/index.js.map +1 -0
  20. package/dist/modules/auth/products.d.ts +208 -0
  21. package/dist/modules/auth/products.d.ts.map +1 -0
  22. package/dist/modules/auth/products.js +165 -0
  23. package/dist/modules/auth/products.js.map +1 -0
  24. package/dist/namespaces.d.ts +2942 -0
  25. package/dist/namespaces.d.ts.map +1 -0
  26. package/dist/namespaces.js +37 -0
  27. package/dist/namespaces.js.map +1 -0
  28. package/dist/rpc.d.ts +156 -0
  29. package/dist/rpc.d.ts.map +1 -0
  30. package/dist/rpc.js +26 -0
  31. package/dist/rpc.js.map +1 -0
  32. package/dist/server/create-sdk.d.ts.map +1 -1
  33. package/dist/server/create-sdk.js +3 -13
  34. package/dist/server/create-sdk.js.map +1 -1
  35. package/dist/server/handlers/annotations.d.ts +52 -0
  36. package/dist/server/handlers/annotations.d.ts.map +1 -0
  37. package/dist/server/handlers/annotations.js +204 -0
  38. package/dist/server/handlers/annotations.js.map +1 -0
  39. package/dist/server/handlers/auth.d.ts +53 -0
  40. package/dist/server/handlers/auth.d.ts.map +1 -0
  41. package/dist/server/handlers/auth.js +66 -0
  42. package/dist/server/handlers/auth.js.map +1 -0
  43. package/dist/server/handlers/certification.d.ts +32 -0
  44. package/dist/server/handlers/certification.d.ts.map +1 -0
  45. package/dist/server/handlers/certification.js +253 -0
  46. package/dist/server/handlers/certification.js.map +1 -0
  47. package/dist/server/handlers/chat/conversations.d.ts +91 -0
  48. package/dist/server/handlers/chat/conversations.d.ts.map +1 -0
  49. package/dist/server/handlers/chat/conversations.js +314 -0
  50. package/dist/server/handlers/chat/conversations.js.map +1 -0
  51. package/dist/server/handlers/chat/delegator.d.ts +144 -0
  52. package/dist/server/handlers/chat/delegator.d.ts.map +1 -0
  53. package/dist/server/handlers/chat/delegator.js +431 -0
  54. package/dist/server/handlers/chat/delegator.js.map +1 -0
  55. package/dist/server/handlers/chat/engine.d.ts +81 -0
  56. package/dist/server/handlers/chat/engine.d.ts.map +1 -0
  57. package/dist/server/handlers/chat/engine.js +442 -0
  58. package/dist/server/handlers/chat/engine.js.map +1 -0
  59. package/dist/server/handlers/chat/executor.d.ts +65 -0
  60. package/dist/server/handlers/chat/executor.d.ts.map +1 -0
  61. package/dist/server/handlers/chat/executor.js +375 -0
  62. package/dist/server/handlers/chat/executor.js.map +1 -0
  63. package/dist/server/handlers/chat/index.d.ts +62 -0
  64. package/dist/server/handlers/chat/index.d.ts.map +1 -0
  65. package/dist/server/handlers/chat/index.js +182 -0
  66. package/dist/server/handlers/chat/index.js.map +1 -0
  67. package/dist/server/handlers/chat/memory.d.ts +91 -0
  68. package/dist/server/handlers/chat/memory.d.ts.map +1 -0
  69. package/dist/server/handlers/chat/memory.js +293 -0
  70. package/dist/server/handlers/chat/memory.js.map +1 -0
  71. package/dist/server/handlers/chat/models.d.ts +180 -0
  72. package/dist/server/handlers/chat/models.d.ts.map +1 -0
  73. package/dist/server/handlers/chat/models.js +304 -0
  74. package/dist/server/handlers/chat/models.js.map +1 -0
  75. package/dist/server/handlers/chat/planner.d.ts +116 -0
  76. package/dist/server/handlers/chat/planner.d.ts.map +1 -0
  77. package/dist/server/handlers/chat/planner.js +344 -0
  78. package/dist/server/handlers/chat/planner.js.map +1 -0
  79. package/dist/server/handlers/chat/types.d.ts +500 -0
  80. package/dist/server/handlers/chat/types.d.ts.map +1 -0
  81. package/dist/server/handlers/chat/types.js +11 -0
  82. package/dist/server/handlers/chat/types.js.map +1 -0
  83. package/dist/server/handlers/collections.d.ts +67 -0
  84. package/dist/server/handlers/collections.d.ts.map +1 -0
  85. package/dist/server/handlers/collections.js +484 -0
  86. package/dist/server/handlers/collections.js.map +1 -0
  87. package/dist/server/handlers/commerce.d.ts +106 -0
  88. package/dist/server/handlers/commerce.d.ts.map +1 -0
  89. package/dist/server/handlers/commerce.js +62 -0
  90. package/dist/server/handlers/commerce.js.map +1 -0
  91. package/dist/server/handlers/config.d.ts +112 -0
  92. package/dist/server/handlers/config.d.ts.map +1 -0
  93. package/dist/server/handlers/config.js +122 -0
  94. package/dist/server/handlers/config.js.map +1 -0
  95. package/dist/server/handlers/export.d.ts +72 -0
  96. package/dist/server/handlers/export.d.ts.map +1 -0
  97. package/dist/server/handlers/export.js +175 -0
  98. package/dist/server/handlers/export.js.map +1 -0
  99. package/dist/server/handlers/formats.d.ts +77 -0
  100. package/dist/server/handlers/formats.d.ts.map +1 -0
  101. package/dist/server/handlers/formats.js +65 -0
  102. package/dist/server/handlers/formats.js.map +1 -0
  103. package/dist/server/handlers/graph.d.ts +31 -0
  104. package/dist/server/handlers/graph.d.ts.map +1 -0
  105. package/dist/server/handlers/graph.js +490 -0
  106. package/dist/server/handlers/graph.js.map +1 -0
  107. package/dist/server/handlers/import.d.ts +96 -0
  108. package/dist/server/handlers/import.d.ts.map +1 -0
  109. package/dist/server/handlers/import.js +108 -0
  110. package/dist/server/handlers/import.js.map +1 -0
  111. package/dist/server/handlers/index.d.ts +68 -0
  112. package/dist/server/handlers/index.d.ts.map +1 -0
  113. package/dist/server/handlers/index.js +71 -0
  114. package/dist/server/handlers/index.js.map +1 -0
  115. package/dist/server/handlers/media.d.ts +76 -0
  116. package/dist/server/handlers/media.d.ts.map +1 -0
  117. package/dist/server/handlers/media.js +53 -0
  118. package/dist/server/handlers/media.js.map +1 -0
  119. package/dist/server/handlers/project.d.ts +45 -0
  120. package/dist/server/handlers/project.d.ts.map +1 -0
  121. package/dist/server/handlers/project.js +181 -0
  122. package/dist/server/handlers/project.js.map +1 -0
  123. package/dist/server/handlers/publish.d.ts +102 -0
  124. package/dist/server/handlers/publish.d.ts.map +1 -0
  125. package/dist/server/handlers/publish.js +130 -0
  126. package/dist/server/handlers/publish.js.map +1 -0
  127. package/dist/server/handlers/pulse.d.ts +39 -0
  128. package/dist/server/handlers/pulse.d.ts.map +1 -0
  129. package/dist/server/handlers/pulse.js +78 -0
  130. package/dist/server/handlers/pulse.js.map +1 -0
  131. package/dist/server/handlers/realtime.d.ts +55 -0
  132. package/dist/server/handlers/realtime.d.ts.map +1 -0
  133. package/dist/server/handlers/realtime.js +49 -0
  134. package/dist/server/handlers/realtime.js.map +1 -0
  135. package/dist/server/handlers/search.d.ts +21 -0
  136. package/dist/server/handlers/search.d.ts.map +1 -0
  137. package/dist/server/handlers/search.js +237 -0
  138. package/dist/server/handlers/search.js.map +1 -0
  139. package/dist/server/handlers/session.d.ts +47 -0
  140. package/dist/server/handlers/session.d.ts.map +1 -0
  141. package/dist/server/handlers/session.js +286 -0
  142. package/dist/server/handlers/session.js.map +1 -0
  143. package/dist/server/handlers/settings.d.ts +97 -0
  144. package/dist/server/handlers/settings.d.ts.map +1 -0
  145. package/dist/server/handlers/settings.js +131 -0
  146. package/dist/server/handlers/settings.js.map +1 -0
  147. package/dist/server/handlers/workspace.d.ts +78 -0
  148. package/dist/server/handlers/workspace.d.ts.map +1 -0
  149. package/dist/server/handlers/workspace.js +270 -0
  150. package/dist/server/handlers/workspace.js.map +1 -0
  151. package/dist/server/hono-router.d.ts +66 -0
  152. package/dist/server/hono-router.d.ts.map +1 -0
  153. package/dist/server/hono-router.js +203 -0
  154. package/dist/server/hono-router.js.map +1 -0
  155. package/dist/server/index.d.ts +29 -19
  156. package/dist/server/index.d.ts.map +1 -1
  157. package/dist/server/index.js +33 -19
  158. package/dist/server/index.js.map +1 -1
  159. package/dist/server/namespace-router.d.ts +204 -0
  160. package/dist/server/namespace-router.d.ts.map +1 -0
  161. package/dist/server/namespace-router.js +262 -0
  162. package/dist/server/namespace-router.js.map +1 -0
  163. package/dist/transports/http-namespace.d.ts +210 -0
  164. package/dist/transports/http-namespace.d.ts.map +1 -0
  165. package/dist/transports/http-namespace.js +514 -0
  166. package/dist/transports/http-namespace.js.map +1 -0
  167. package/dist/transports/workshop.d.ts +173 -0
  168. package/dist/transports/workshop.d.ts.map +1 -0
  169. package/dist/transports/workshop.js +307 -0
  170. package/dist/transports/workshop.js.map +1 -0
  171. package/dist/types.d.ts +65 -67
  172. package/dist/types.d.ts.map +1 -1
  173. package/dist/types.js +7 -3
  174. package/dist/types.js.map +1 -1
  175. package/docs/ADR-004-product-registry.md +108 -0
  176. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commerce.js","sourceRoot":"","sources":["../../../src/server/handlers/commerce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAsFH,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgC;IACpE,MAAM,QAAQ,GAAG,OAAO,EAAE,eAAe,CAAA;IAEzC,SAAS,eAAe;QACtB,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAA;QACH,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,OAAO;QACL,KAAK,CAAC,aAAa,CAAC,cAAmB,EAAE,GAAmB;YAC1D,OAAO,eAAe,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAA;QACxD,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,WAAgB;YACjC,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;QACpD,CAAC;QAED,KAAK,CAAC,UAAU,CAAC,SAAiB;YAChC,OAAO,eAAe,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAChD,CAAC;QAED,KAAK,CAAC,QAAQ,CAAC,eAAoB,EAAE,GAAmB;YACtD,OAAO,eAAe,EAAE,CAAC,QAAQ,CAAC;gBAChC,GAAG,eAAe;gBAClB,aAAa,EAAE,eAAe,CAAC,aAAa,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK;aAC/D,CAAC,CAAA;QACJ,CAAC;QAED,KAAK,CAAC,UAAU,CAAC,SAAiB;YAChC,OAAO,eAAe,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAChD,CAAC;QAED,KAAK,CAAC,YAAY,CAAC,WAAgB,EAAE,GAAmB;YACtD,OAAO,eAAe,EAAE,CAAC,YAAY,CAAC;gBACpC,GAAG,WAAW;gBACd,aAAa,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK;aAC9B,CAAC,CAAA;QACJ,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * @module server/handlers/config
3
+ * @description Config namespace handler — platform configuration, plans, models,
4
+ * maintenance mode, and announcements.
5
+ *
6
+ * Absorbs Workshop `routes/config.ts`. The handler delegates to an injected
7
+ * `ConfigService` interface so products can plug in their own configuration
8
+ * source (Firestore, env vars, static JSON, etc.).
9
+ *
10
+ * Methods:
11
+ * - `get` — Full platform config (features, limits, maintenance, announcements)
12
+ * - `getUser` — User-specific configuration (plan, effective limits, models)
13
+ * - `getAnnouncements` — Active announcements for the user's plan
14
+ * - `isMaintenanceMode` — Whether the platform is in maintenance mode
15
+ */
16
+ import type { NamespaceProvider } from '../namespace-router.js';
17
+ /**
18
+ * Configuration service interface injected into the handler factory.
19
+ *
20
+ * Products implement this to connect to their configuration source. Workshop
21
+ * uses Firestore-backed config with plan-based overrides; Venue might use
22
+ * static env vars.
23
+ */
24
+ export interface ConfigService {
25
+ /** Get the full platform configuration. */
26
+ getConfig(): Promise<{
27
+ global: {
28
+ freeTierEnabled: boolean;
29
+ maintenanceMode: boolean;
30
+ defaultModel: string;
31
+ soulcraftAccountUrl: string;
32
+ };
33
+ plans: Record<string, {
34
+ id: string;
35
+ displayName: string;
36
+ price: {
37
+ monthly: number;
38
+ yearly: number;
39
+ };
40
+ limits: Record<string, number>;
41
+ features: Record<string, unknown>;
42
+ }>;
43
+ models: Record<string, {
44
+ id: string;
45
+ name: string;
46
+ shortName: string;
47
+ pricing: {
48
+ input: number;
49
+ output: number;
50
+ };
51
+ maxTokens: number;
52
+ tiers: string[];
53
+ supportsThinking?: boolean;
54
+ bestFor?: string;
55
+ }>;
56
+ }>;
57
+ /** Get user-specific configuration (plan limits, available models). */
58
+ getUserConfig(userId: string, planId: string): Promise<{
59
+ plan: Record<string, unknown>;
60
+ effectiveLimits: Record<string, number>;
61
+ effectiveFeatures: Record<string, boolean>;
62
+ availableModels: Array<{
63
+ id: string;
64
+ name: string;
65
+ shortName: string;
66
+ maxTokens: number;
67
+ bestFor?: string;
68
+ }>;
69
+ hasOverrides: boolean;
70
+ }>;
71
+ /** Get active announcements, optionally filtered by plan. */
72
+ getAnnouncements(planId?: string): Promise<Array<{
73
+ id: string;
74
+ message: string;
75
+ type: string;
76
+ }>>;
77
+ /** Check if maintenance mode is active. */
78
+ isMaintenanceMode(): Promise<boolean>;
79
+ /** Invalidate the configuration cache (admin only). */
80
+ invalidateCache?(): void;
81
+ }
82
+ /**
83
+ * Billing service subset needed by the config handler to resolve the user's plan.
84
+ */
85
+ export interface ConfigBillingService {
86
+ /** Get the user's subscription to determine their plan. */
87
+ getSubscription(billingId: string): Promise<{
88
+ plan?: string;
89
+ } | null>;
90
+ }
91
+ /**
92
+ * Options for {@link createConfigHandler}.
93
+ */
94
+ export interface ConfigHandlerOptions {
95
+ /** Configuration service instance. */
96
+ configService: ConfigService;
97
+ /** Billing service for plan resolution. */
98
+ billing: ConfigBillingService;
99
+ /**
100
+ * Admin email check — returns `true` if the email belongs to a platform admin.
101
+ * Defaults to checking the `ADMIN_EMAILS` env var, falling back to `@soulcraft.com`.
102
+ */
103
+ isAdmin?: (email: string) => boolean;
104
+ }
105
+ /**
106
+ * Creates the `config` namespace handler.
107
+ *
108
+ * @param options - Config handler dependencies.
109
+ * @returns A {@link NamespaceProvider} implementing {@link ConfigNamespace}.
110
+ */
111
+ export declare function createConfigHandler(options: ConfigHandlerOptions): NamespaceProvider;
112
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,wBAAwB,CAAA;AAO/E;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,2CAA2C;IAC3C,SAAS,IAAI,OAAO,CAAC;QACnB,MAAM,EAAE;YACN,eAAe,EAAE,OAAO,CAAA;YACxB,eAAe,EAAE,OAAO,CAAA;YACxB,YAAY,EAAE,MAAM,CAAA;YACpB,mBAAmB,EAAE,MAAM,CAAA;SAC5B,CAAA;QACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE;YACpB,EAAE,EAAE,MAAM,CAAA;YACV,WAAW,EAAE,MAAM,CAAA;YACnB,KAAK,EAAE;gBAAE,OAAO,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,CAAA;YAC1C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAC9B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAClC,CAAC,CA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AC,IAAI,IAAI,CAAA;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2DAA2D;IAC3D,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;CACtE;AAMD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sCAAsC;IACtC,aAAa,EAAE,aAAa,CAAA;IAC5B,2CAA2C;IAC3C,OAAO,EAAE,oBAAoB,CAAA;IAC7B;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;CACrC;AAyBD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,iBAAiB,CA0FpF"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * @module server/handlers/config
3
+ * @description Config namespace handler — platform configuration, plans, models,
4
+ * maintenance mode, and announcements.
5
+ *
6
+ * Absorbs Workshop `routes/config.ts`. The handler delegates to an injected
7
+ * `ConfigService` interface so products can plug in their own configuration
8
+ * source (Firestore, env vars, static JSON, etc.).
9
+ *
10
+ * Methods:
11
+ * - `get` — Full platform config (features, limits, maintenance, announcements)
12
+ * - `getUser` — User-specific configuration (plan, effective limits, models)
13
+ * - `getAnnouncements` — Active announcements for the user's plan
14
+ * - `isMaintenanceMode` — Whether the platform is in maintenance mode
15
+ */
16
+ // ─────────────────────────────────────────────────────────────────────────────
17
+ // Default admin check
18
+ // ─────────────────────────────────────────────────────────────────────────────
19
+ /**
20
+ * Default admin check: uses `ADMIN_EMAILS` env var (comma-separated), falls
21
+ * back to `@soulcraft.com` domain.
22
+ *
23
+ * @param email - User email to check.
24
+ * @returns `true` if the user is a platform admin.
25
+ */
26
+ function defaultIsAdmin(email) {
27
+ const adminEmails = process.env.ADMIN_EMAILS;
28
+ if (adminEmails) {
29
+ return adminEmails.split(',').map(e => e.trim().toLowerCase()).includes(email.toLowerCase());
30
+ }
31
+ return email.toLowerCase().endsWith('@soulcraft.com');
32
+ }
33
+ // ─────────────────────────────────────────────────────────────────────────────
34
+ // Handler factory
35
+ // ─────────────────────────────────────────────────────────────────────────────
36
+ /**
37
+ * Creates the `config` namespace handler.
38
+ *
39
+ * @param options - Config handler dependencies.
40
+ * @returns A {@link NamespaceProvider} implementing {@link ConfigNamespace}.
41
+ */
42
+ export function createConfigHandler(options) {
43
+ const { configService, billing, isAdmin = defaultIsAdmin } = options;
44
+ return {
45
+ /**
46
+ * Get the full platform configuration for the current user.
47
+ *
48
+ * Resolves the user's plan via billing, then assembles global config,
49
+ * user-specific limits/features, plan definitions, and model pricing.
50
+ *
51
+ * @param ctx - Handler context with authenticated user.
52
+ * @returns Complete config payload.
53
+ */
54
+ async get(ctx) {
55
+ const userId = ctx.user.emailHash;
56
+ const billingId = ctx.user.email;
57
+ const subscription = await billing.getSubscription(billingId);
58
+ const planId = subscription?.plan || 'free';
59
+ const appConfig = await configService.getConfig();
60
+ const userConfig = await configService.getUserConfig(userId, planId);
61
+ const announcements = await configService.getAnnouncements(planId);
62
+ return {
63
+ features: {
64
+ freeTierEnabled: appConfig.global.freeTierEnabled,
65
+ maintenanceMode: appConfig.global.maintenanceMode,
66
+ ...userConfig.effectiveFeatures,
67
+ },
68
+ limits: {
69
+ ...userConfig.effectiveLimits,
70
+ },
71
+ maintenance: appConfig.global.maintenanceMode
72
+ ? { active: true }
73
+ : undefined,
74
+ announcements: announcements.length > 0 ? announcements : undefined,
75
+ };
76
+ },
77
+ /**
78
+ * Get user-specific configuration overrides.
79
+ *
80
+ * Returns the user's effective plan, limits, features, and available models.
81
+ *
82
+ * @param ctx - Handler context with authenticated user.
83
+ * @returns User-level config overrides.
84
+ */
85
+ async getUser(ctx) {
86
+ const userId = ctx.user.emailHash;
87
+ const billingId = ctx.user.email;
88
+ const subscription = await billing.getSubscription(billingId);
89
+ const planId = subscription?.plan || 'free';
90
+ const userConfig = await configService.getUserConfig(userId, planId);
91
+ return {
92
+ planId,
93
+ plan: userConfig.plan,
94
+ effectiveLimits: userConfig.effectiveLimits,
95
+ effectiveFeatures: userConfig.effectiveFeatures,
96
+ availableModels: userConfig.availableModels,
97
+ hasOverrides: userConfig.hasOverrides,
98
+ };
99
+ },
100
+ /**
101
+ * Get active platform announcements.
102
+ *
103
+ * @param ctx - Handler context with authenticated user.
104
+ * @returns Array of active announcements.
105
+ */
106
+ async getAnnouncements(ctx) {
107
+ const billingId = ctx.user.email;
108
+ const subscription = await billing.getSubscription(billingId);
109
+ const planId = subscription?.plan || 'free';
110
+ return configService.getAnnouncements(planId);
111
+ },
112
+ /**
113
+ * Check if maintenance mode is active.
114
+ *
115
+ * @returns `true` if the platform is in maintenance mode.
116
+ */
117
+ async isMaintenanceMode() {
118
+ return configService.isMaintenanceMode();
119
+ },
120
+ };
121
+ }
122
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/server/handlers/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgGH,gFAAgF;AAChF,sBAAsB;AACtB,gFAAgF;AAEhF;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,KAAa;IACnC,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAA;IAC5C,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;IAC9F,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AACvD,CAAC;AAED,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UA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S,CAAA;YACjC,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAA;YAEhC,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;YAC7D,MAAM,MAAM,GAAG,YAAY,EAAE,IAAI,IAAI,MAAM,CAAA;YAE3C,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;YAEpE,OAAO;gBACL,MAAM;gBACN,IAAI,EAAE,UAAU,CAAC,IAAI;gBACrB,eAAe,EAAE,UAAU,CAAC,eAAe;gBAC3C,iBAAiB,EAAE,UAAU,CAAC,iBAAiB;gBAC/C,eAAe,EAAE,UAAU,CAAC,eAAe;gBAC3C,YAAY,EAAE,UAAU,CAAC,YAAY;aACtC,CAAA;QACH,CAAC;QAED;;;;;WAKG;QACH,KAAK,CAAC,gBAAgB,CAAC,GAAmB;YACxC,MAAM,SAAS,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAA;YAChC,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;YAC7D,MAAM,MAAM,GAAG,YAAY,EAAE,IAAI,IAAI,MAAM,CAAA;YAE3C,OAAO,aAAa,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAC/C,CAAC;QAED;;;;WAIG;QACH,KAAK,CAAC,iBAAiB;YACrB,OAAO,aAAa,CAAC,iBAAiB,EAAE,CAAA;QAC1C,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @module server/handlers/export
3
+ * @description Export namespace handler — project download, knowledge graph
4
+ * export, and PDF generation.
5
+ *
6
+ * Absorbs Workshop `routes/export.ts` and `routes/knowledge-graph.ts`. The
7
+ * handler delegates format serialization to an injected `ExportPipeline`
8
+ * interface, allowing products to register exporters for their supported formats.
9
+ *
10
+ * Methods:
11
+ * - `getExporters` — List available export formats
12
+ * - `downloadProject` — Download full project as zip/tar
13
+ * - `exportKnowledgeGraph` — Export graph in standard interchange formats
14
+ * - `exportPdf` — Generate a PDF from selected entities
15
+ * - `downloadPdf` — Download a previously generated PDF
16
+ */
17
+ import type { NamespaceProvider } from '../namespace-router.js';
18
+ import type { ExportFormat } from '../../namespaces.js';
19
+ /**
20
+ * Export pipeline interface for serializing workspace data.
21
+ *
22
+ * Products implement this to register exporters for their supported formats.
23
+ * Workshop supports JSON, CSV, GraphML, GEXF, DOT, and PDF.
24
+ */
25
+ export interface ExportPipeline {
26
+ /**
27
+ * List available export formats.
28
+ *
29
+ * @returns Array of format descriptors.
30
+ */
31
+ getFormats(): ExportFormat[];
32
+ /**
33
+ * Export the knowledge graph in a standard format.
34
+ *
35
+ * @param format - Target format ID.
36
+ * @param brain - Brainy instance to read from.
37
+ * @param options - Export options (type filters, etc.).
38
+ * @returns Serialized graph data.
39
+ */
40
+ exportGraph(format: string, brain: any, options?: {
41
+ types?: string[];
42
+ }): Promise<string | ArrayBuffer>;
43
+ /**
44
+ * Generate a PDF from selected entities.
45
+ *
46
+ * @param entityIds - Entities to include.
47
+ * @param brain - Brainy instance to read from.
48
+ * @param options - PDF options.
49
+ * @returns The PDF as binary data.
50
+ */
51
+ exportPdf?(entityIds: string[], brain: any, options?: {
52
+ template?: string;
53
+ }): Promise<ArrayBuffer>;
54
+ }
55
+ /**
56
+ * Options for {@link createExportHandler}.
57
+ */
58
+ export interface ExportHandlerOptions {
59
+ /**
60
+ * Export pipeline implementation.
61
+ * If not provided, basic JSON/CSV export is available; other formats throw.
62
+ */
63
+ pipeline?: ExportPipeline;
64
+ }
65
+ /**
66
+ * Creates the `export` namespace handler.
67
+ *
68
+ * @param options - Optional export handler dependencies.
69
+ * @returns A {@link NamespaceProvider} implementing {@link ExportNamespace}.
70
+ */
71
+ export declare function createExportHandler(options?: ExportHandlerOptions): NamespaceProvider;
72
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAkB,MAAM,wBAAwB,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAMvD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,UAAU,IAAI,YAAY,EAAE,CAAA;IAE5B;;;;;;;OAOG;IACH,WAAW,CACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,GAC7B,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAA;IAEhC;;;;;;;OAOG;IACH,SAAS,CAAC,CACR,SAAS,EAAE,MAAM,EAAE,EACnB,KAAK,EAAE,GAAG,EACV,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9B,OAAO,CAAC,WAAW,CAAC,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;CAC1B;AAmED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,iBAAiB,CA0HrF"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @module server/handlers/export
3
+ * @description Export namespace handler — project download, knowledge graph
4
+ * export, and PDF generation.
5
+ *
6
+ * Absorbs Workshop `routes/export.ts` and `routes/knowledge-graph.ts`. The
7
+ * handler delegates format serialization to an injected `ExportPipeline`
8
+ * interface, allowing products to register exporters for their supported formats.
9
+ *
10
+ * Methods:
11
+ * - `getExporters` — List available export formats
12
+ * - `downloadProject` — Download full project as zip/tar
13
+ * - `exportKnowledgeGraph` — Export graph in standard interchange formats
14
+ * - `exportPdf` — Generate a PDF from selected entities
15
+ * - `downloadPdf` — Download a previously generated PDF
16
+ */
17
+ // ─────────────────────────────────────────────────────────────────────────────
18
+ // Built-in minimal exporters
19
+ // ─────────────────────────────────────────────────────────────────────────────
20
+ /** Built-in export formats available without an external pipeline. */
21
+ const BUILTIN_FORMATS = [
22
+ { id: 'json', name: 'JSON', extension: '.json', mimeType: 'application/json' },
23
+ { id: 'csv', name: 'CSV', extension: '.csv', mimeType: 'text/csv' },
24
+ ];
25
+ /**
26
+ * Built-in JSON export — serializes all entities as a JSON array.
27
+ *
28
+ * @param brain - Brainy instance.
29
+ * @param options - Export options.
30
+ * @returns JSON string.
31
+ */
32
+ async function exportJson(brain, options) {
33
+ let entities = await brain.find({ limit: 50000, excludeVFS: true });
34
+ if (options?.types && options.types.length > 0) {
35
+ const typeSet = new Set(options.types.map((t) => t.toLowerCase()));
36
+ entities = entities.filter((e) => typeSet.has((e.type || '').toLowerCase()));
37
+ }
38
+ return JSON.stringify(entities, null, 2);
39
+ }
40
+ /**
41
+ * Built-in CSV export — serializes entities as CSV with id, type, name, description columns.
42
+ *
43
+ * @param brain - Brainy instance.
44
+ * @param options - Export options.
45
+ * @returns CSV string.
46
+ */
47
+ async function exportCsv(brain, options) {
48
+ let entities = await brain.find({ limit: 50000, excludeVFS: true });
49
+ if (options?.types && options.types.length > 0) {
50
+ const typeSet = new Set(options.types.map((t) => t.toLowerCase()));
51
+ entities = entities.filter((e) => typeSet.has((e.type || '').toLowerCase()));
52
+ }
53
+ const header = 'id,type,name,description';
54
+ const rows = entities.map((e) => {
55
+ const meta = e.metadata || {};
56
+ const name = (meta.name || e.data || '').toString().replace(/"/g, '""');
57
+ const desc = (meta.description || '').toString().replace(/"/g, '""');
58
+ return `"${e.id}","${e.type || ''}","${name}","${desc}"`;
59
+ });
60
+ return [header, ...rows].join('\n');
61
+ }
62
+ // ─────────────────────────────────────────────────────────────────────────────
63
+ // PDF download cache
64
+ // ─────────────────────────────────────────────────────────────────────────────
65
+ /** Temporary cache for generated PDFs. */
66
+ const pdfCache = new Map();
67
+ // ─────────────────────────────────────────────────────────────────────────────
68
+ // Handler factory
69
+ // ─────────────────────────────────────────────────────────────────────────────
70
+ /**
71
+ * Creates the `export` namespace handler.
72
+ *
73
+ * @param options - Optional export handler dependencies.
74
+ * @returns A {@link NamespaceProvider} implementing {@link ExportNamespace}.
75
+ */
76
+ export function createExportHandler(options) {
77
+ const pipeline = options?.pipeline;
78
+ return {
79
+ /**
80
+ * List all available export formats.
81
+ *
82
+ * Merges built-in formats (JSON, CSV) with any formats from the pipeline.
83
+ *
84
+ * @returns Array of export format descriptors.
85
+ */
86
+ async getExporters() {
87
+ if (pipeline)
88
+ return pipeline.getFormats();
89
+ return BUILTIN_FORMATS;
90
+ },
91
+ /**
92
+ * Download the entire project as a zip or tar archive.
93
+ *
94
+ * This requires binary streaming — the actual archive assembly happens at
95
+ * the transport/route layer. The handler collects the data.
96
+ *
97
+ * @param downloadOptions - Archive format options.
98
+ * @param ctx - Handler context.
99
+ * @returns Archive as binary data.
100
+ */
101
+ async downloadProject(downloadOptions, ctx) {
102
+ // Project download requires zip/tar assembly at the transport layer.
103
+ // For now, return the project data as a JSON blob that the Hono adapter
104
+ // can wrap in a zip.
105
+ const { brain } = ctx;
106
+ const entities = await brain.find({ limit: 50000, excludeVFS: true });
107
+ const manifest = {
108
+ version: 1,
109
+ format: 'workshop-export',
110
+ createdAt: new Date().toISOString(),
111
+ entityCount: entities.length,
112
+ };
113
+ const json = JSON.stringify({ manifest, entities }, null, 2);
114
+ const encoder = new TextEncoder();
115
+ return encoder.encode(json).buffer;
116
+ },
117
+ /**
118
+ * Export the knowledge graph in a standard interchange format.
119
+ *
120
+ * Uses the external pipeline for formats like GraphML, GEXF, DOT.
121
+ * Falls back to built-in JSON/CSV for basic formats.
122
+ *
123
+ * @param format - Target format ID.
124
+ * @param exportOptions - Type filters.
125
+ * @param ctx - Handler context.
126
+ * @returns Serialized graph data.
127
+ */
128
+ async exportKnowledgeGraph(format, exportOptions, ctx) {
129
+ const { brain } = ctx;
130
+ // Built-in formats
131
+ if (format === 'json')
132
+ return exportJson(brain, exportOptions);
133
+ if (format === 'csv')
134
+ return exportCsv(brain, exportOptions);
135
+ // Delegate to pipeline for advanced formats
136
+ if (pipeline)
137
+ return pipeline.exportGraph(format, brain, exportOptions);
138
+ throw new Error(`Export format "${format}" is not supported. Available formats: json, csv`);
139
+ },
140
+ /**
141
+ * Generate a PDF from selected entities.
142
+ *
143
+ * @param entityIds - Entities to include.
144
+ * @param pdfOptions - PDF template options.
145
+ * @param ctx - Handler context.
146
+ * @returns Download URL for the generated PDF.
147
+ */
148
+ async exportPdf(entityIds, pdfOptions, ctx) {
149
+ if (!pipeline?.exportPdf) {
150
+ throw new Error('PDF export is not configured — provide an ExportPipeline with exportPdf support');
151
+ }
152
+ const pdfData = await pipeline.exportPdf(entityIds, ctx.brain, pdfOptions);
153
+ const exportId = `pdf-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
154
+ pdfCache.set(exportId, pdfData);
155
+ // Auto-cleanup after 10 minutes
156
+ setTimeout(() => pdfCache.delete(exportId), 10 * 60 * 1000);
157
+ return { downloadUrl: `__pdf__:${exportId}` };
158
+ },
159
+ /**
160
+ * Download a previously generated PDF.
161
+ *
162
+ * @param exportId - The export ID from `exportPdf`.
163
+ * @returns PDF as binary data.
164
+ */
165
+ async downloadPdf(exportId) {
166
+ const data = pdfCache.get(exportId);
167
+ if (!data) {
168
+ throw new Error(`PDF export "${exportId}" not found or expired`);
169
+ }
170
+ pdfCache.delete(exportId); // One-time download
171
+ return data;
172
+ },
173
+ };
174
+ }
175
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../../src/server/handlers/export.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA+DH,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF,sEAAsE;AACtE,MAAM,eA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,CAAC,CAAA,CAAC,oBAAoB;YAC9C,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @module server/handlers/formats
3
+ * @description Formats namespace handler — server-side format conversion and
4
+ * validation for Soulcraft portable formats (wdoc, wslide, wviz, wquiz).
5
+ *
6
+ * Data transformation only — visual rendering lives in `@soulcraft/views`.
7
+ * This handler delegates to an injected `FormatConverter` interface so products
8
+ * can register converters for different source→output format pairs.
9
+ *
10
+ * Methods:
11
+ * - `convert` — Convert a Soulcraft format document to an output format
12
+ * - `validate` — Validate a document against its format schema
13
+ * - `getOutputFormats` — List available output formats
14
+ */
15
+ import type { NamespaceProvider } from '../namespace-router.js';
16
+ /**
17
+ * Format converter interface.
18
+ *
19
+ * Products register converters for different source→output format pairs.
20
+ * For example, Workshop might register a puppeteer-based wdoc→pdf converter.
21
+ */
22
+ export interface FormatConverter {
23
+ /**
24
+ * Convert a document from one format to another.
25
+ *
26
+ * @param sourceFormat - Source format ID (e.g. 'wdoc', 'wslide').
27
+ * @param outputFormat - Target format ID (e.g. 'pdf', 'html', 'markdown').
28
+ * @param content - The source document (JSON or string).
29
+ * @param options - Format-specific conversion options.
30
+ * @returns Converted content (string for text, ArrayBuffer for binary).
31
+ */
32
+ convert(sourceFormat: string, outputFormat: string, content: unknown, options?: Record<string, unknown>): Promise<string | ArrayBuffer>;
33
+ /**
34
+ * Validate a document against its format schema.
35
+ *
36
+ * @param format - Format ID (e.g. 'wdoc', 'wviz').
37
+ * @param document - The document to validate.
38
+ * @returns Validation result.
39
+ */
40
+ validate(format: string, document: unknown): Promise<{
41
+ valid: boolean;
42
+ errors: Array<{
43
+ path: string;
44
+ message: string;
45
+ }>;
46
+ }>;
47
+ /**
48
+ * List available output formats and their supported source formats.
49
+ *
50
+ * @returns Array of output format descriptors.
51
+ */
52
+ getOutputFormats(): Promise<Array<{
53
+ id: string;
54
+ name: string;
55
+ extension: string;
56
+ mimeType: string;
57
+ sourceFormats: string[];
58
+ }>>;
59
+ }
60
+ /**
61
+ * Options for {@link createFormatsHandler}.
62
+ */
63
+ export interface FormatsHandlerOptions {
64
+ /**
65
+ * Format converter implementation.
66
+ * If not provided, all methods throw with a "not configured" error.
67
+ */
68
+ converter: FormatConverter;
69
+ }
70
+ /**
71
+ * Creates the `formats` namespace handler.
72
+ *
73
+ * @param options - Formats handler dependencies. If omitted, all methods throw.
74
+ * @returns A {@link NamespaceProvider} implementing {@link FormatsNamespace}.
75
+ */
76
+ export declare function createFormatsHandler(options?: FormatsHandlerOptions): NamespaceProvider;
77
+ //# sourceMappingURL=formats.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/formats.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAM/D;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,OAAO,CACL,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAA;IAEhC;;;;;;OAMG;IACH,QAAQ,CACN,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,OAAO,GAChB,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAAA;IAEhF;;;;OAIG;IACH,gBAAgB,IAAI,OAAO,CAAC,KAAK,CAAC;QAChC,EAAE,EAAE,MAAM,CAAA;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,EAAE,MAAM,CAAA;QAChB,aAAa,EAAE,MAAM,EAAE,CAAA;KACxB,CAAC,CAAC,CAAA;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,EAAE,eAAe,CAAA;CAC3B;AAMD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,iBAAiB,CA0DvF"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * @module server/handlers/formats
3
+ * @description Formats namespace handler — server-side format conversion and
4
+ * validation for Soulcraft portable formats (wdoc, wslide, wviz, wquiz).
5
+ *
6
+ * Data transformation only — visual rendering lives in `@soulcraft/views`.
7
+ * This handler delegates to an injected `FormatConverter` interface so products
8
+ * can register converters for different source→output format pairs.
9
+ *
10
+ * Methods:
11
+ * - `convert` — Convert a Soulcraft format document to an output format
12
+ * - `validate` — Validate a document against its format schema
13
+ * - `getOutputFormats` — List available output formats
14
+ */
15
+ // ─────────────────────────────────────────────────────────────────────────────
16
+ // Handler factory
17
+ // ─────────────────────────────────────────────────────────────────────────────
18
+ /**
19
+ * Creates the `formats` namespace handler.
20
+ *
21
+ * @param options - Formats handler dependencies. If omitted, all methods throw.
22
+ * @returns A {@link NamespaceProvider} implementing {@link FormatsNamespace}.
23
+ */
24
+ export function createFormatsHandler(options) {
25
+ const converter = options?.converter;
26
+ function requireConverter() {
27
+ if (!converter) {
28
+ throw new Error('formats namespace is not configured — provide a FormatConverter via providers.formats. ' +
29
+ 'Install @soulcraft/formats for schema validation or register custom converters.');
30
+ }
31
+ return converter;
32
+ }
33
+ return {
34
+ /**
35
+ * Convert a Soulcraft format document to an output format.
36
+ *
37
+ * @param sourceFormat - Source format ID.
38
+ * @param outputFormat - Target format ID.
39
+ * @param convertOptions - Content and conversion options.
40
+ * @returns Converted content.
41
+ */
42
+ async convert(sourceFormat, outputFormat, convertOptions) {
43
+ return requireConverter().convert(sourceFormat, outputFormat, convertOptions.content, convertOptions.options);
44
+ },
45
+ /**
46
+ * Validate a document against its format schema.
47
+ *
48
+ * @param format - Format ID (e.g. 'wdoc', 'wviz').
49
+ * @param document - The document to validate.
50
+ * @returns Validation result with errors.
51
+ */
52
+ async validate(format, document) {
53
+ return requireConverter().validate(format, document);
54
+ },
55
+ /**
56
+ * List available output formats and supported conversions.
57
+ *
58
+ * @returns Array of output format descriptors.
59
+ */
60
+ async getOutputFormats() {
61
+ return requireConverter().getOutputFormats();
62
+ },
63
+ };
64
+ }
65
+ //# sourceMappingURL=formats.js.map