{"_id":"@alga-psa/extension-runtime","_rev":"4-10727adfb0a430dbd1322990a460971f","name":"@alga-psa/extension-runtime","dist-tags":{"latest":"0.3.0"},"versions":{"0.2.0":{"name":"@alga-psa/extension-runtime","version":"0.2.0","_id":"@alga-psa/extension-runtime@0.2.0","maintainers":[{"name":"robert-at-nineminds","email":"robert@nineminds.com"}],"dist":{"shasum":"31bd16d1935c7193281c9041bd64befcdd2f9137","tarball":"https://registry.npmjs.org/@alga-psa/extension-runtime/-/extension-runtime-0.2.0.tgz","fileCount":4,"integrity":"sha512-yh2PypOYMcjOHpOP8JUvMM5fVi4RJdG4oLbNncdp3LqGGIKTNEO8aMY3vNbKEAkz0dwUs3Zd/vP68aQPo57u8Q==","signatures":[{"sig":"MEUCIFG/EDRytNUumr7OR0ba751IBtSAwNikOeK9MLjKiBUBAiEArabC6D632XbHAyv/9uis2K9QySubjzYQYUyJJV/WmUI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6898},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"private":false,"scripts":{"test":"vitest","build":"tsup src/index.ts --format esm --dts --out-dir dist --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"robert-at-nineminds","email":"robert@nineminds.com"},"_npmVersion":"11.6.2","description":"Utility types and helper functions for Alga extension components compiled with [`componentize-js`](https://github.com/bytecodealliance/componentize-js).","directories":{},"_nodeVersion":"25.1.0","_hasShrinkwrap":false,"devDependencies":{"tsup":"^7.2.0","vitest":"^3.0.7","typescript":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/extension-runtime_0.2.0_1764220161936_0.981320819429407","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@alga-psa/extension-runtime","version":"0.2.1","_id":"@alga-psa/extension-runtime@0.2.1","maintainers":[{"name":"robert-at-nineminds","email":"robert@nineminds.com"}],"dist":{"shasum":"199e77957baba3d5dc1cd07f951c1c3a14f696a4","tarball":"https://registry.npmjs.org/@alga-psa/extension-runtime/-/extension-runtime-0.2.1.tgz","fileCount":4,"integrity":"sha512-kixDUQ3iR4LHWYFImFcvdmFanWcntL+wWmbc3ianguaePh9uASZpZkZCuTtfXaxqaQwkwukQDDCeiSU/PiV4gw==","signatures":[{"sig":"MEUCIFueXiS5aGKvOjkp+ir/YZdtAPbgmEWmLsSI4NTc+lX0AiEA8cXDxaGtlGHD+MMEo3zDDUoWB9K98JxWeBMjO+Uhv9g=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":6947},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"private":false,"scripts":{"test":"vitest","build":"tsup src/index.ts --format esm --dts --out-dir dist --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"robert-at-nineminds","email":"robert@nineminds.com"},"_npmVersion":"11.6.2","description":"Utility types and helper functions for Alga extension components compiled with [`componentize-js`](https://github.com/bytecodealliance/componentize-js).","directories":{},"_nodeVersion":"25.1.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^7.2.0","vitest":"^3.0.7","typescript":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/extension-runtime_0.2.1_1764220471206_0.17162810288917596","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@alga-psa/extension-runtime","version":"0.3.0","_id":"@alga-psa/extension-runtime@0.3.0","maintainers":[{"name":"robert-at-nineminds","email":"robert@nineminds.com"}],"dist":{"shasum":"451e1ef4f05a0a2b6feff4d76639529f1c35a716","tarball":"https://registry.npmjs.org/@alga-psa/extension-runtime/-/extension-runtime-0.3.0.tgz","fileCount":4,"integrity":"sha512-zfpMgnomVg9DvUtQcjwlHKZWoDh7OvCE23RQvasWVVC+jnXqjUoTRhWutHeQNze71Gr3yz278Oc9KUC4LuL75g==","signatures":[{"sig":"MEUCICmHrgc40kzkO/Umk7H6bk0tfMO5BjxKFaxHiyyLR22sAiEAxDD2lBPKz1gGqQ+n2Zr28KMs6J5a+l6OHTRcCyk/Y8w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16232},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"private":false,"scripts":{"test":"vitest","build":"tsup src/index.ts --format esm --dts --out-dir dist --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"robert-at-nineminds","email":"robert@nineminds.com"},"_npmVersion":"11.6.2","description":"Utility types and helper functions for Alga extension components compiled with [`componentize-js`](https://github.com/bytecodealliance/componentize-js).","directories":{},"_nodeVersion":"25.1.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^7.2.0","vitest":"^3.0.7","typescript":"^5.4.0"},"_npmOperationalInternal":{"tmp":"tmp/extension-runtime_0.3.0_1767842169416_0.8602749773668994","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-11-27T05:09:21.843Z","modified":"2026-02-24T15:20:54.572Z","0.2.0":"2025-11-27T05:09:22.135Z","0.2.1":"2025-11-27T05:14:31.409Z","0.3.0":"2026-01-08T03:16:09.593Z"},"description":"Utility types and helper functions for Alga extension components compiled with [`componentize-js`](https://github.com/bytecodealliance/componentize-js).","maintainers":[{"email":"natallia@nineminds.com","name":"talya_b"},{"email":"robert@nineminds.com","name":"robert-at-nineminds"}],"readme":"# @alga-psa/extension-runtime\n\nUtility types and helper functions for Alga extension components compiled with [`componentize-js`](https://github.com/bytecodealliance/componentize-js).\n\n## Installation\n\n```bash\nnpm install @alga-psa/extension-runtime\n```\n\n## Usage\n\n```ts\nimport { Handler, jsonResponse } from '@alga-psa/extension-runtime';\n\nexport const handler: Handler = async (request, host) => {\n  const secret = await host.secrets.get('alga_api_key');\n  await host.logging.info(`Handling request for ${request.context.tenantId}`);\n  return jsonResponse({ ok: true, secret, path: request.http.path });\n};\n```\n\nThe helpers mirror the WIT definitions in `ee/runner/wit/extension-runner.wit`.\n\n## Host Bindings\n\nThe `HostBindings` interface provides access to host capabilities:\n\n### Context\n```typescript\nhost.context.get(): Promise<ContextData>\n```\nGet execution context (tenant, extension, request IDs).\n\n### Secrets\n```typescript\nhost.secrets.get(key: string): Promise<string>\nhost.secrets.list(): Promise<string[]>\n```\nAccess install-scoped secrets. Requires `cap:secrets.get`.\n\n### HTTP\n```typescript\nhost.http.fetch(request: HttpRequest): Promise<HttpResponse>\n```\nMake outbound HTTP requests. Requires `cap:http.fetch`.\n\n### Storage\n```typescript\nhost.storage.get(namespace: string, key: string): Promise<Uint8Array | null>\nhost.storage.put(entry: StorageEntry): Promise<void>\nhost.storage.delete(namespace: string, key: string): Promise<void>\nhost.storage.list(namespace: string): Promise<StorageEntry[]>\n```\nKey-value storage. Requires `cap:storage.kv`.\n\n### Logging\n```typescript\nhost.logging.info(message: string): Promise<void>\nhost.logging.warn(message: string): Promise<void>\nhost.logging.error(message: string): Promise<void>\n```\nEmit structured logs. Requires `cap:log.emit`.\n\n### UI Proxy\n```typescript\nhost.uiProxy.callRoute(route: string, payload?: Uint8Array): Promise<Uint8Array>\n```\nCall host-mediated proxy routes for UI flows. Requires `cap:ui.proxy`.\n\n### User\n```typescript\nhost.user.getUser(): Promise<UserData>\n```\nGet current user information. Requires `cap:user.read` (granted by default).\n\n```typescript\ninterface UserData {\n  tenantId: string;\n  clientName: string;\n  userId: string;\n  userEmail: string;\n  userName: string;\n  userType: string;  // \"internal\" or \"client\"\n}\n```\n\n### Scheduler\n```typescript\nhost.scheduler.list(): Promise<ScheduleInfo[]>\nhost.scheduler.get(scheduleId: string): Promise<ScheduleInfo | null>\nhost.scheduler.create(input: CreateScheduleInput): Promise<CreateScheduleResult>\nhost.scheduler.update(scheduleId: string, input: UpdateScheduleInput): Promise<UpdateScheduleResult>\nhost.scheduler.delete(scheduleId: string): Promise<DeleteScheduleResult>\nhost.scheduler.getEndpoints(): Promise<EndpointInfo[]>\n```\nManage scheduled tasks. Requires `cap:scheduler.manage`.\n\n## Helper Functions\n\n### jsonResponse\n```typescript\njsonResponse(body: unknown, init?: Partial<ExecuteResponse>): ExecuteResponse\n```\nCreate a JSON response with proper headers.\n\n### emptyResponse\n```typescript\nemptyResponse(status?: number): ExecuteResponse\n```\nCreate an empty response (default status 204).\n\n### createMockHostBindings\n```typescript\ncreateMockHostBindings(overrides?: Partial<HostBindings>): HostBindings\n```\nCreate mock host bindings for testing.\n\n## Using WIT Imports\n\nWhen building with jco componentize, host capabilities are imported from WIT modules. Create a wrapper `index.ts`:\n\n```typescript\n// Import WIT functions\n// @ts-ignore\nimport { getUser } from 'alga:extension/user';\n// @ts-ignore\nimport { logInfo } from 'alga:extension/logging';\n\n// Build HostBindings\nconst host: HostBindings = {\n  user: { getUser: async () => getUser() },\n  logging: { info: async (msg) => logInfo(msg), /* ... */ },\n  // ... other bindings\n};\n\nexport async function handler(request: ExecuteRequest): Promise<ExecuteResponse> {\n  return myHandler(request, host);\n}\n```\n\nSee [User Host API Guide](../docs/guides/user-host-api.md) for complete examples.\n\n## Building\n\nRun `npm run build` before publishing.\n","readmeFilename":"README.md"}