@soulcraft/sdk 2.0.0 → 2.0.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/dist/client/index.d.ts +5 -38
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +5 -47
- package/dist/client/index.js.map +1 -1
- package/dist/client/namespace-proxy.d.ts +3 -4
- package/dist/client/namespace-proxy.d.ts.map +1 -1
- package/dist/client/namespace-proxy.js +3 -4
- package/dist/client/namespace-proxy.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/modules/hall/browser.d.ts +83 -27
- package/dist/modules/hall/browser.d.ts.map +1 -1
- package/dist/modules/hall/browser.js +238 -49
- package/dist/modules/hall/browser.js.map +1 -1
- package/dist/modules/hall/media.d.ts +164 -0
- package/dist/modules/hall/media.d.ts.map +1 -0
- package/dist/modules/hall/media.js +182 -0
- package/dist/modules/hall/media.js.map +1 -0
- package/dist/modules/hall/server.d.ts +83 -6
- package/dist/modules/hall/server.d.ts.map +1 -1
- package/dist/modules/hall/server.js +206 -9
- package/dist/modules/hall/server.js.map +1 -1
- package/dist/modules/hall/types.d.ts +548 -25
- package/dist/modules/hall/types.d.ts.map +1 -1
- package/dist/modules/hall/types.js +12 -7
- package/dist/modules/hall/types.js.map +1 -1
- package/dist/server/hall-handlers.d.ts +40 -12
- package/dist/server/hall-handlers.d.ts.map +1 -1
- package/dist/server/hall-handlers.js +40 -12
- package/dist/server/hall-handlers.js.map +1 -1
- package/dist/server/handlers/chat/engine.d.ts.map +1 -1
- package/dist/server/handlers/chat/engine.js +5 -1
- package/dist/server/handlers/chat/engine.js.map +1 -1
- package/dist/server/handlers/chat/types.d.ts +17 -2
- package/dist/server/handlers/chat/types.d.ts.map +1 -1
- package/dist/server/hono-router.d.ts +2 -9
- package/dist/server/hono-router.d.ts.map +1 -1
- package/dist/server/hono-router.js +2 -46
- package/dist/server/hono-router.js.map +1 -1
- package/dist/server/index.d.ts +4 -19
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +10 -29
- package/dist/server/index.js.map +1 -1
- package/dist/types.d.ts +2 -41
- package/dist/types.d.ts.map +1 -1
- package/docs/ADR-005-hall-integration.md +449 -0
- package/package.json +1 -1
- package/dist/client/create-client-sdk.d.ts +0 -113
- package/dist/client/create-client-sdk.d.ts.map +0 -1
- package/dist/client/create-client-sdk.js +0 -169
- package/dist/client/create-client-sdk.js.map +0 -1
- package/dist/modules/app-context/index.d.ts +0 -214
- package/dist/modules/app-context/index.d.ts.map +0 -1
- package/dist/modules/app-context/index.js +0 -569
- package/dist/modules/app-context/index.js.map +0 -1
- package/dist/modules/billing/firestore-provider.d.ts +0 -60
- package/dist/modules/billing/firestore-provider.d.ts.map +0 -1
- package/dist/modules/billing/firestore-provider.js +0 -315
- package/dist/modules/billing/firestore-provider.js.map +0 -1
- package/dist/modules/brainy/proxy.d.ts +0 -48
- package/dist/modules/brainy/proxy.d.ts.map +0 -1
- package/dist/modules/brainy/proxy.js +0 -95
- package/dist/modules/brainy/proxy.js.map +0 -1
- package/dist/server/create-sdk.d.ts +0 -74
- package/dist/server/create-sdk.d.ts.map +0 -1
- package/dist/server/create-sdk.js +0 -104
- package/dist/server/create-sdk.js.map +0 -1
- package/dist/server/from-license.d.ts +0 -252
- package/dist/server/from-license.d.ts.map +0 -1
- package/dist/server/from-license.js +0 -349
- package/dist/server/from-license.js.map +0 -1
- package/dist/server/handlers.d.ts +0 -312
- package/dist/server/handlers.d.ts.map +0 -1
- package/dist/server/handlers.js +0 -376
- package/dist/server/handlers.js.map +0 -1
- package/dist/server/postmessage-handler.d.ts +0 -152
- package/dist/server/postmessage-handler.d.ts.map +0 -1
- package/dist/server/postmessage-handler.js +0 -138
- package/dist/server/postmessage-handler.js.map +0 -1
- package/dist/transports/http.d.ts +0 -86
- package/dist/transports/http.d.ts.map +0 -1
- package/dist/transports/http.js +0 -137
- package/dist/transports/http.js.map +0 -1
- package/dist/transports/postmessage.d.ts +0 -159
- package/dist/transports/postmessage.d.ts.map +0 -1
- package/dist/transports/postmessage.js +0 -207
- package/dist/transports/postmessage.js.map +0 -1
- package/dist/transports/workshop.d.ts +0 -173
- package/dist/transports/workshop.d.ts.map +0 -1
- package/dist/transports/workshop.js +0 -307
- package/dist/transports/workshop.js.map +0 -1
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module server/create-sdk
|
|
3
|
-
* @description `createSDK` factory for server-mode @soulcraft/sdk.
|
|
4
|
-
*
|
|
5
|
-
* Assembles a complete `SoulcraftSDK` instance from a live Brainy instance.
|
|
6
|
-
* In server mode the SDK uses the {@link LocalTransport} — zero overhead, no
|
|
7
|
-
* serialization, in-process method dispatch directly into the Brainy instance.
|
|
8
|
-
*
|
|
9
|
-
* The returned SDK object is scoped to a single Brainy instance. In a typical
|
|
10
|
-
* server request handler the caller resolves the correct Brainy instance from a
|
|
11
|
-
* {@link BrainyInstancePool} and then calls `createSDK({ brain })`. A new SDK
|
|
12
|
-
* object per request is cheap — it's a thin wrapper, not a connection.
|
|
13
|
-
*
|
|
14
|
-
* @example Workshop request handler
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { BrainyInstancePool, createSDK } from '@soulcraft/sdk/server'
|
|
17
|
-
*
|
|
18
|
-
* const pool = new BrainyInstancePool({ storage: 'filesystem', dataPath: './data', strategy: 'per-user' })
|
|
19
|
-
*
|
|
20
|
-
* app.get('/api/inventory', requireAuth, async (c) => {
|
|
21
|
-
* const user = c.get('user')!
|
|
22
|
-
* const brain = await pool.forUser(user.emailHash, 'main')
|
|
23
|
-
* const sdk = createSDK({ brain })
|
|
24
|
-
*
|
|
25
|
-
* const items = await sdk.brainy.find({ query: 'inventory items', type: 'Product' })
|
|
26
|
-
* const readme = await sdk.vfs.readFile('/projects/my-project/README.md')
|
|
27
|
-
* return c.json({ items })
|
|
28
|
-
* })
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
import { LocalTransport } from '../transports/local.js';
|
|
32
|
-
import { createBrainyProxy } from '../modules/brainy/proxy.js';
|
|
33
|
-
import { createEventsModule } from '../modules/events/index.js';
|
|
34
|
-
import { createAiModule } from '../modules/ai/index.js';
|
|
35
|
-
import { createSkillsModule } from '../modules/skills/index.js';
|
|
36
|
-
import { createLicenseModule } from '../modules/license/index.js';
|
|
37
|
-
import { createKitsModule } from '../modules/kits/index.js';
|
|
38
|
-
import { createBillingModule } from '../modules/billing/index.js';
|
|
39
|
-
import { createNotificationsModule } from '../modules/notifications/index.js';
|
|
40
|
-
import { createCapabilityToken, verifyCapabilityToken } from '../modules/brainy/auth.js';
|
|
41
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
42
|
-
// Factory
|
|
43
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
44
|
-
/**
|
|
45
|
-
* Create a server-mode `SoulcraftSDK` wrapping a live Brainy instance.
|
|
46
|
-
*
|
|
47
|
-
* All `sdk.brainy.*` and `sdk.vfs.*` calls are dispatched in-process with zero
|
|
48
|
-
* serialization overhead via {@link LocalTransport}.
|
|
49
|
-
*
|
|
50
|
-
* `sdk.ai.*` calls go directly to the Anthropic API (requires `ANTHROPIC_API_KEY`).
|
|
51
|
-
* `sdk.skills.*` reads from the Brainy VFS and falls back to `@soulcraft/kits`.
|
|
52
|
-
* `sdk.events` is a local EventEmitter — events do not cross process boundaries.
|
|
53
|
-
* `sdk.billing.*` stores usage locally (dev) or via Portal credits (prod via `PORTAL_CREDIT_SECRET`).
|
|
54
|
-
* `sdk.license.*` activates via `@soulcraft/cortex` and delegates credit metering to `sdk.billing`.
|
|
55
|
-
* `sdk.kits.*` reads from the `@soulcraft/kits` registry (optional peer dependency).
|
|
56
|
-
* `sdk.notifications.*` sends via Postmark/Twilio or logs to the console in dev mode.
|
|
57
|
-
*
|
|
58
|
-
* @param options - SDK creation options.
|
|
59
|
-
* @returns A fully assembled `SoulcraftSDK` instance.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* ```typescript
|
|
63
|
-
* const brain = await pool.forUser(user.emailHash, workspaceId)
|
|
64
|
-
* const sdk = createSDK({ brain })
|
|
65
|
-
*
|
|
66
|
-
* const results = await sdk.brainy.find({ query: 'candle inventory' })
|
|
67
|
-
* const readme = await sdk.vfs.readFile('/projects/README.md')
|
|
68
|
-
* await sdk.events.emit('kit:session-completed', { userId, sessionId, kitId })
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
export function createSDK(options) {
|
|
72
|
-
const { brain } = options;
|
|
73
|
-
const transport = new LocalTransport(brain);
|
|
74
|
-
const brainyProxy = createBrainyProxy(transport);
|
|
75
|
-
const events = createEventsModule();
|
|
76
|
-
const ai = createAiModule();
|
|
77
|
-
const skills = createSkillsModule(brain);
|
|
78
|
-
const billing = createBillingModule();
|
|
79
|
-
const license = createLicenseModule({ billing });
|
|
80
|
-
const kits = createKitsModule();
|
|
81
|
-
const notifications = createNotificationsModule();
|
|
82
|
-
// This legacy factory wires only the Tier 1 modules (brainy, ai, billing, etc.).
|
|
83
|
-
// For full namespace support, use createSoulcraftRouter() which dispatches all
|
|
84
|
-
// 25 namespaces via the unified RPC endpoint.
|
|
85
|
-
return {
|
|
86
|
-
brainy: brainyProxy,
|
|
87
|
-
events,
|
|
88
|
-
ai,
|
|
89
|
-
skills,
|
|
90
|
-
license,
|
|
91
|
-
kits,
|
|
92
|
-
billing,
|
|
93
|
-
notifications,
|
|
94
|
-
async shutdown() {
|
|
95
|
-
billing.stopFlush();
|
|
96
|
-
await billing.flush();
|
|
97
|
-
license.stopHeartbeat();
|
|
98
|
-
// brain.close() flushes all deferred writes (HNSW dirty nodes, indexes,
|
|
99
|
-
// storage counts) and frees all resources — the correct full-shutdown path.
|
|
100
|
-
await brain.close();
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
//# sourceMappingURL=create-sdk.js.map
|
|
@@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C,CAAA;IAChD,MAAM,IAAI,GAAG,gBAAgB,EAAE,CAAA;IAC/B,MAAM,aAAa,GAAG,yBAAyB,EAAE,CAAA;IAEjD,iFAAiF;IACjF,+EAA+E;IAC/E,8CAA8C;IAC9C,OAAO;QACL,MAAM,EAAE,WAAW;QACnB,MAAM;QACN,EAAE;QACF,MAAM;QACN,OAAO;QACP,IAAI;QACJ,OAAO;QACP,aAAa;QAEb,KAAK,CAAC,QAAQ;YACZ,OAAO,CAAC,SAAS,EAAE,CAAA;YACnB,MAAM,OAAO,CAAC,KAAK,EAAE,CAAA;YACrB,OAAO,CAAC,aAAa,EAAE,CAAA;YACvB,wEAAwE;YACxE,4EAA4E;YAC5E,MAAM,KAAK,CAAC,KAAK,EAAE,CAAA;QACrB,CAAC;KACyB,CAAA;AAC9B,CAAC"}
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module server/from-license
|
|
3
|
-
* @description License-driven server SDK factory.
|
|
4
|
-
*
|
|
5
|
-
* `createServerSDK.fromLicense({ product })` is the recommended production entry point
|
|
6
|
-
* for product backends. It replaces the manual environment-variable wiring required by
|
|
7
|
-
* `createSDK()` with a single boot-time call to Portal:
|
|
8
|
-
*
|
|
9
|
-
* ```
|
|
10
|
-
* SOULCRAFT_LICENSE_KEY=SC-XXXX-XXXX-XXXX ← only secret needed
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* At startup the factory:
|
|
14
|
-
* 1. Reads `SOULCRAFT_LICENSE_KEY` from the environment.
|
|
15
|
-
* 2. POSTs `POST https://soulcraft.com/api/license/activate` with the key and product name.
|
|
16
|
-
* 3. Receives a config bundle (`anthropicApiKey`, `portalCreditSecret`, `hallSecret`, etc.).
|
|
17
|
-
* 4. Injects the bundle values into `process.env` so all SDK module factories pick them
|
|
18
|
-
* up automatically — no factory API changes required.
|
|
19
|
-
* 5. Writes the bundle to `.soulcraft-config.json` in the working directory for offline
|
|
20
|
-
* restarts (e.g. if Portal is temporarily unreachable after a product restart).
|
|
21
|
-
* 6. Schedules a background re-validation every 4 hours to pick up rotated secrets.
|
|
22
|
-
*
|
|
23
|
-
* The returned `ServerSDK` object is long-lived (one per process). Its `createSDK(brain)`
|
|
24
|
-
* method returns a per-request `SoulcraftSDK`, identical to calling `createSDK({ brain })`
|
|
25
|
-
* directly, but with all secrets already wired from the bundle.
|
|
26
|
-
*
|
|
27
|
-
* ## Backward compatibility
|
|
28
|
-
*
|
|
29
|
-
* `createSDK()` is unchanged — products that manage their own env vars continue to work
|
|
30
|
-
* exactly as before. `fromLicense()` is additive.
|
|
31
|
-
*
|
|
32
|
-
* ## Offline / degraded start
|
|
33
|
-
*
|
|
34
|
-
* If Portal is unreachable on first boot, the factory falls back to a cached bundle from
|
|
35
|
-
* `.soulcraft-config.json`. If no cache exists either, it throws — a product cannot start
|
|
36
|
-
* in production without a resolved config bundle.
|
|
37
|
-
*
|
|
38
|
-
* @example Academy startup
|
|
39
|
-
* ```typescript
|
|
40
|
-
* import { createServerSDK, BrainyInstancePool } from '@soulcraft/sdk/server'
|
|
41
|
-
*
|
|
42
|
-
* const server = await createServerSDK.fromLicense({ product: 'academy' })
|
|
43
|
-
*
|
|
44
|
-
* const pool = new BrainyInstancePool({
|
|
45
|
-
* storage: 'mmap-filesystem',
|
|
46
|
-
* dataPath: '/mnt/brainy-data',
|
|
47
|
-
* strategy: 'per-user',
|
|
48
|
-
* })
|
|
49
|
-
*
|
|
50
|
-
* // Per-request:
|
|
51
|
-
* app.get('/api/brainy', requireAuth, async (c) => {
|
|
52
|
-
* const brain = await pool.forUser(user.emailHash, 'main')
|
|
53
|
-
* const sdk = server.createSDK(brain)
|
|
54
|
-
* const items = await sdk.brainy.find({ query: 'candle inventory' })
|
|
55
|
-
* return c.json({ items })
|
|
56
|
-
* })
|
|
57
|
-
*
|
|
58
|
-
* // On shutdown:
|
|
59
|
-
* process.on('SIGTERM', () => server.shutdown())
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
import type { Brainy } from '@soulcraft/brainy';
|
|
63
|
-
import type { HallModule } from '../modules/hall/types.js';
|
|
64
|
-
import type { SoulcraftSDK, SoulcraftProduct } from '../types.js';
|
|
65
|
-
/**
|
|
66
|
-
* Per-org billing configuration for Venue, distributed via the Portal activate response.
|
|
67
|
-
*
|
|
68
|
-
* Stored in Portal's Firestore license document under `venueOrgConfig[orgSlug]` and
|
|
69
|
-
* returned at boot time so Venue cannot self-modify its own platform fee rate.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const cfg = server.venueOrgConfig['canvas-and-corks']
|
|
74
|
-
* // { platformFeeRate: 0.065, feeMode: 'online-only', billingModel: 'per-transaction' }
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export interface VenueOrgBillingConfig {
|
|
78
|
-
/** Platform fee rate as a decimal (e.g. `0.065` for 6.5%). */
|
|
79
|
-
platformFeeRate?: number;
|
|
80
|
-
/** Which channels the fee applies to. */
|
|
81
|
-
feeMode?: 'online-only' | 'all-channels' | 'none';
|
|
82
|
-
/** Billing model for this org. */
|
|
83
|
-
billingModel?: 'per-transaction' | 'subscription' | 'hybrid';
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Config bundle returned by the Portal `licenseActivate` endpoint.
|
|
87
|
-
* Only non-null fields are included in the response.
|
|
88
|
-
*/
|
|
89
|
-
export interface LicenseConfigBundle {
|
|
90
|
-
/** Anthropic API key for `sdk.ai.*` calls. */
|
|
91
|
-
anthropicApiKey?: string;
|
|
92
|
-
/** Shared secret for the Portal credit API (`sdk.billing.*`). */
|
|
93
|
-
portalCreditSecret?: string;
|
|
94
|
-
/** WebSocket URL of the Hall server (e.g. `wss://hall.soulcraft.com`). */
|
|
95
|
-
hallUrl?: string;
|
|
96
|
-
/** Per-product shared secret for Hall authentication. */
|
|
97
|
-
hallSecret?: string;
|
|
98
|
-
/** Stripe secret key for `sdk.billing.*` Stripe operations. */
|
|
99
|
-
stripeSecretKey?: string;
|
|
100
|
-
/** Stripe webhook signing secret. */
|
|
101
|
-
stripeWebhookSecret?: string;
|
|
102
|
-
/** Workshop deploy bearer token secret. */
|
|
103
|
-
workshopDeploySecret?: string;
|
|
104
|
-
/** Academy publish bearer token secret. */
|
|
105
|
-
academyPublishSecret?: string;
|
|
106
|
-
/** Venue RPC capability token secret. */
|
|
107
|
-
venueRpcSecret?: string;
|
|
108
|
-
/** Postmark server token for email notifications. */
|
|
109
|
-
postmarkToken?: string;
|
|
110
|
-
/** From-address for Postmark email. */
|
|
111
|
-
postmarkFromEmail?: string;
|
|
112
|
-
/** Twilio account SID for SMS notifications. */
|
|
113
|
-
twilioSid?: string;
|
|
114
|
-
/** Twilio auth token for SMS notifications. */
|
|
115
|
-
twilioToken?: string;
|
|
116
|
-
/** Twilio from-number for SMS. */
|
|
117
|
-
twilioFromNumber?: string;
|
|
118
|
-
/**
|
|
119
|
-
* Internal Cortex Ed25519 JWT license key for this product.
|
|
120
|
-
* Written to `.soulcraft.json` before Brainy/Cortex initializes so that
|
|
121
|
-
* Cortex validates offline without a separate activation step.
|
|
122
|
-
*/
|
|
123
|
-
cortexLicenseKey?: string;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Options for `createServerSDK.fromLicense()`.
|
|
127
|
-
*/
|
|
128
|
-
export interface FromLicenseOptions {
|
|
129
|
-
/**
|
|
130
|
-
* The Soulcraft product name.
|
|
131
|
-
* Used to retrieve the correct per-product secrets (e.g. Hall secret, deploy secret)
|
|
132
|
-
* from the Portal config bundle.
|
|
133
|
-
*
|
|
134
|
-
* @example `'workshop'` | `'venue'` | `'academy'`
|
|
135
|
-
*/
|
|
136
|
-
product: SoulcraftProduct;
|
|
137
|
-
/**
|
|
138
|
-
* Override the license key.
|
|
139
|
-
* When not provided, `SOULCRAFT_LICENSE_KEY` is read from the environment.
|
|
140
|
-
*/
|
|
141
|
-
licenseKey?: string;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* A long-lived server SDK object returned by `createServerSDK.fromLicense()`.
|
|
145
|
-
*
|
|
146
|
-
* Wraps the Portal config bundle and exposes `createSDK(brain)` for per-request SDK
|
|
147
|
-
* construction. The Hall module (if configured) is available as `server.hall`.
|
|
148
|
-
*/
|
|
149
|
-
export interface ServerSDK {
|
|
150
|
-
/**
|
|
151
|
-
* Create a per-request `SoulcraftSDK` wrapping a live Brainy instance.
|
|
152
|
-
*
|
|
153
|
-
* All secrets are already injected from the license bundle — pass the resolved
|
|
154
|
-
* Brainy instance and the SDK is ready to use.
|
|
155
|
-
*
|
|
156
|
-
* @param brain - A Brainy instance from a `BrainyInstancePool`.
|
|
157
|
-
* @returns A fully assembled `SoulcraftSDK`.
|
|
158
|
-
*/
|
|
159
|
-
createSDK(brain: Brainy): SoulcraftSDK;
|
|
160
|
-
/**
|
|
161
|
-
* The Hall module, connected to the Hall server at startup.
|
|
162
|
-
* Present only when the license bundle includes `hallSecret` and `hallUrl`.
|
|
163
|
-
*/
|
|
164
|
-
readonly hall: HallModule | undefined;
|
|
165
|
-
/**
|
|
166
|
-
* The resolved license config bundle.
|
|
167
|
-
* Contains all secrets injected into the environment at startup.
|
|
168
|
-
*/
|
|
169
|
-
readonly config: LicenseConfigBundle;
|
|
170
|
-
/**
|
|
171
|
-
* The product tier from the license response.
|
|
172
|
-
* `'free'` | `'pro'` | `'enterprise'` | `'internal'`
|
|
173
|
-
*/
|
|
174
|
-
readonly tier: string;
|
|
175
|
-
/**
|
|
176
|
-
* Per-org billing configuration for Venue, keyed by org slug.
|
|
177
|
-
*
|
|
178
|
-
* Always present — empty object `{}` for non-Venue licenses. Populated from
|
|
179
|
-
* the Portal activate response and refreshed on the 4-hour re-validation cycle.
|
|
180
|
-
* Venue reads this at booking time rather than storing fee config in tenant Brainy,
|
|
181
|
-
* ensuring operators cannot self-modify their own platform fee rate.
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const cfg = server.venueOrgConfig['canvas-and-corks']
|
|
186
|
-
* const rate = cfg?.platformFeeRate ?? 0.065
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
readonly venueOrgConfig: Record<string, VenueOrgBillingConfig>;
|
|
190
|
-
/**
|
|
191
|
-
* Gracefully shut down the server SDK.
|
|
192
|
-
*
|
|
193
|
-
* Stops the background re-validation timer and disconnects the Hall module.
|
|
194
|
-
*/
|
|
195
|
-
shutdown(): void;
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Activate the SDK from a Soulcraft license key.
|
|
199
|
-
*
|
|
200
|
-
* Calls Portal's `licenseActivate` endpoint, injects the returned config bundle
|
|
201
|
-
* into `process.env`, and returns a `ServerSDK` ready for per-request use.
|
|
202
|
-
*
|
|
203
|
-
* Falls back to a cached bundle (`.soulcraft-config.json`) if Portal is unreachable.
|
|
204
|
-
* Throws if neither Portal nor a valid cache is available.
|
|
205
|
-
*
|
|
206
|
-
* @param options - Product name and optional license key override.
|
|
207
|
-
* @returns A `ServerSDK` instance, fully wired from the license bundle.
|
|
208
|
-
*
|
|
209
|
-
* @throws {Error} If the license key is invalid, expired, or Portal is unreachable with no cache.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* ```typescript
|
|
213
|
-
* const server = await createServerSDK.fromLicense({ product: 'academy' })
|
|
214
|
-
* const pool = new BrainyInstancePool({ storage: 'mmap-filesystem', dataPath: '/mnt/brainy-data', strategy: 'per-user' })
|
|
215
|
-
*
|
|
216
|
-
* app.use(requireAuth)
|
|
217
|
-
* app.get('/api/brainy', async (c) => {
|
|
218
|
-
* const brain = await pool.forUser(c.get('user').emailHash, 'main')
|
|
219
|
-
* const sdk = server.createSDK(brain)
|
|
220
|
-
* return c.json(await sdk.brainy.find({ query: c.req.query('q') ?? '' }))
|
|
221
|
-
* })
|
|
222
|
-
*
|
|
223
|
-
* process.on('SIGTERM', () => server.shutdown())
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
declare function fromLicense(options: FromLicenseOptions): Promise<ServerSDK>;
|
|
227
|
-
/**
|
|
228
|
-
* Server SDK factory namespace.
|
|
229
|
-
*
|
|
230
|
-
* The primary entry point is `createServerSDK.fromLicense({ product })`.
|
|
231
|
-
* For lower-level control (custom Brainy instance, no license key), use
|
|
232
|
-
* `createSDK({ brain })` directly.
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* ```typescript
|
|
236
|
-
* import { createServerSDK, BrainyInstancePool } from '@soulcraft/sdk/server'
|
|
237
|
-
*
|
|
238
|
-
* const server = await createServerSDK.fromLicense({ product: 'workshop' })
|
|
239
|
-
* const pool = new BrainyInstancePool({ storage: 'mmap-filesystem', dataPath: '/mnt/data', strategy: 'per-user' })
|
|
240
|
-
*
|
|
241
|
-
* app.get('/api/brainy', requireAuth, async (c) => {
|
|
242
|
-
* const brain = await pool.forUser(c.get('user').emailHash, 'main')
|
|
243
|
-
* const sdk = server.createSDK(brain)
|
|
244
|
-
* return c.json(await sdk.brainy.find({ query: c.req.query('q') ?? '' }))
|
|
245
|
-
* })
|
|
246
|
-
* ```
|
|
247
|
-
*/
|
|
248
|
-
export declare const createServerSDK: {
|
|
249
|
-
fromLicense: typeof fromLicense;
|
|
250
|
-
};
|
|
251
|
-
export {};
|
|
252
|
-
//# sourceMappingURL=from-license.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"from-license.d.ts","sourceRoot":"","sources":["../../src/server/from-license.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AA2BjE;;;;;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