@temps-sdk/plugin 0.1.0-beta.1

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 (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/dist/api.d.ts +33 -0
  4. package/dist/api.d.ts.map +1 -0
  5. package/dist/api.js +96 -0
  6. package/dist/api.js.map +1 -0
  7. package/dist/auth.d.ts +41 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/auth.js +102 -0
  10. package/dist/auth.js.map +1 -0
  11. package/dist/client.d.ts +29 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +141 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/context.d.ts +26 -0
  16. package/dist/context.d.ts.map +1 -0
  17. package/dist/context.js +52 -0
  18. package/dist/context.js.map +1 -0
  19. package/dist/errors.d.ts +61 -0
  20. package/dist/errors.d.ts.map +1 -0
  21. package/dist/errors.js +115 -0
  22. package/dist/errors.js.map +1 -0
  23. package/dist/index.d.ts +14 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +13 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/manifest-builder.d.ts +57 -0
  28. package/dist/manifest-builder.d.ts.map +1 -0
  29. package/dist/manifest-builder.js +118 -0
  30. package/dist/manifest-builder.js.map +1 -0
  31. package/dist/protocol.d.ts +22 -0
  32. package/dist/protocol.d.ts.map +1 -0
  33. package/dist/protocol.js +120 -0
  34. package/dist/protocol.js.map +1 -0
  35. package/dist/runtime.d.ts +14 -0
  36. package/dist/runtime.d.ts.map +1 -0
  37. package/dist/runtime.js +511 -0
  38. package/dist/runtime.js.map +1 -0
  39. package/dist/types.d.ts +252 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +7 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/ui.d.ts +26 -0
  44. package/dist/ui.d.ts.map +1 -0
  45. package/dist/ui.js +186 -0
  46. package/dist/ui.js.map +1 -0
  47. package/package.json +55 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Temps Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # @temps-sdk/plugin
2
+
3
+ Build external [Temps](https://temps.sh) plugins in TypeScript and compile them
4
+ to standalone executables with Bun. The resulting binary is installed like a
5
+ Rust plugin; the Temps host does not need Node.js or Bun at runtime.
6
+
7
+ ## Requirements
8
+
9
+ - Bun 1.3 or newer for development and compilation
10
+ - Temps external-plugin protocol v2
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ bun add @temps-sdk/plugin@beta
16
+ ```
17
+
18
+ The SDK uses independent semantic versions. During the prerelease period, pin
19
+ an exact beta such as `@temps-sdk/plugin@0.1.0-beta.1`; prereleases are also
20
+ available through npm's `beta` dist-tag. SDK compatibility is defined by the
21
+ Temps external-plugin protocol version rather than the Temps application
22
+ version.
23
+
24
+ ## Minimal plugin
25
+
26
+ ```ts
27
+ import {
28
+ createManifest,
29
+ extractAuthContext,
30
+ runPlugin,
31
+ type TempsPlugin,
32
+ } from "@temps-sdk/plugin";
33
+
34
+ const plugin: TempsPlugin = {
35
+ manifest: () =>
36
+ createManifest("hello-typescript", "0.1.0")
37
+ .displayName("Hello TypeScript")
38
+ .description("A minimal TypeScript plugin for Temps")
39
+ .build(),
40
+
41
+ handler: (context) => (request, response) => {
42
+ const caller = extractAuthContext(request);
43
+ response.writeHead(200, { "Content-Type": "application/json" });
44
+ response.end(
45
+ JSON.stringify({
46
+ message: `Hello ${caller?.userEmail ?? "system"}`,
47
+ plugin: context.pluginName,
48
+ })
49
+ );
50
+ },
51
+ };
52
+
53
+ await runPlugin(plugin);
54
+ ```
55
+
56
+ Compile it into one executable:
57
+
58
+ ```bash
59
+ bun build src/index.ts --compile --outfile dist/temps-hello-typescript-plugin
60
+ chmod +x dist/temps-hello-typescript-plugin
61
+ cp dist/temps-hello-typescript-plugin ~/.temps/plugins/
62
+ ```
63
+
64
+ Then open **Settings → Plugins** in Temps and reload plugins, or restart Temps.
65
+
66
+ ## Platform data
67
+
68
+ Read-only platform queries are available through `context.temps`:
69
+
70
+ ```ts
71
+ const projects = await context.temps.listProjects();
72
+ const deployments = await context.temps.listDeployments(projectId, { limit: 20 });
73
+ ```
74
+
75
+ ## Calling the platform API
76
+
77
+ Declare the narrowest capability your plugin needs, then bind each call to the
78
+ authenticated caller. Temps applies that caller's normal permissions again.
79
+
80
+ ```ts
81
+ const manifest = createManifest("project-helper", "0.1.0")
82
+ .capability("api_read")
83
+ .build();
84
+
85
+ const caller = extractAuthContext(request);
86
+ if (!caller) {
87
+ response.writeHead(401).end();
88
+ return;
89
+ }
90
+
91
+ const api = context.apiAsCaller(caller);
92
+ const projects = await api.get<{ projects: unknown[] }>("/projects");
93
+ ```
94
+
95
+ Use `.capability("api_write")` only when the plugin needs mutating API calls.
96
+ The SDK rejects caller-scoped calls when Temps did not provide an actor token.
97
+
98
+ ## Host access
99
+
100
+ Plugins receive a private persistent `context.dataDir`. Direct database and
101
+ host-data access are opt-in manifest declarations:
102
+
103
+ ```ts
104
+ createManifest("trusted-plugin", "0.1.0")
105
+ .requiresDb(true)
106
+ .requiresHostDataAccess(true)
107
+ .build();
108
+ ```
109
+
110
+ These privileges expose host-owned state and should not be requested by
111
+ ordinary plugins.
112
+
113
+ ## Authentication model
114
+
115
+ `extractAuthContext(request)` returns only a caller verified by the SDK's
116
+ per-process assertion middleware. It never trusts raw `x-temps-*` headers.
117
+ Unsigned direct requests to plugin routes, events, and the platform channel
118
+ are rejected.
119
+
120
+ ## Full example
121
+
122
+ See `sdks/node/examples/node-hello-plugin` in the Temps repository for a
123
+ compiled TypeScript plugin with a React UI and protocol integration test.
package/dist/api.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type { AuthenticatedCaller } from "./auth.js";
2
+ import type { TempsClient } from "./client.js";
3
+ import type { CallBody, HttpMethod, MultipartPart } from "./types.js";
4
+ export interface PlatformApiResponse<T> {
5
+ status: number;
6
+ body: T;
7
+ ok: boolean;
8
+ }
9
+ export interface PlatformApiRequestOptions {
10
+ query?: string | URLSearchParams;
11
+ body?: CallBody;
12
+ }
13
+ /** Caller-scoped access to the platform's own HTTP API over the plugin channel. */
14
+ export declare class PlatformApi {
15
+ #private;
16
+ constructor(client: TempsClient, caller: AuthenticatedCaller);
17
+ get<T>(path: string, query?: string | URLSearchParams): Promise<PlatformApiResponse<T>>;
18
+ post<T>(path: string, body?: CallBody): Promise<PlatformApiResponse<T>>;
19
+ put<T>(path: string, body?: CallBody): Promise<PlatformApiResponse<T>>;
20
+ patch<T>(path: string, body?: CallBody): Promise<PlatformApiResponse<T>>;
21
+ delete<T>(path: string, body?: CallBody): Promise<PlatformApiResponse<T>>;
22
+ request<T>(method: HttpMethod, path: string, options?: PlatformApiRequestOptions): Promise<PlatformApiResponse<T>>;
23
+ static json(value: unknown): CallBody;
24
+ static multipart(parts: MultipartPart[]): CallBody;
25
+ static textPart(name: string, value: string): MultipartPart;
26
+ static binaryPart(options: {
27
+ name: string;
28
+ bytes: Uint8Array;
29
+ filename?: string;
30
+ contentType?: string;
31
+ }): MultipartPart;
32
+ }
33
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAEV,QAAQ,EACR,UAAU,EACV,aAAa,EACd,MAAM,YAAY,CAAC;AAGpB,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;CACb;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC;IACjC,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAED,mFAAmF;AACnF,qBAAa,WAAW;;gBAIV,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB;IAO5D,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAIvF,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAIvE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAItE,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAIxE,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAInE,OAAO,CAAC,CAAC,EACb,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAoClC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ;IAIrC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,QAAQ;IAIlD,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa;IAI3D,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,UAAU,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,GAAG,aAAa;CAalB"}
package/dist/api.js ADDED
@@ -0,0 +1,96 @@
1
+ // SPDX-FileCopyrightText: 2024-2026 Temps Contributors
2
+ // SPDX-License-Identifier: MIT OR Apache-2.0
3
+ import { ActorTokenRequiredError, CallBodyTooLargeError, PluginSdkError } from "./errors.js";
4
+ import { MAX_CALL_BODY_BYTES } from "./types.js";
5
+ /** Caller-scoped access to the platform's own HTTP API over the plugin channel. */
6
+ export class PlatformApi {
7
+ #client;
8
+ #actorToken;
9
+ constructor(client, caller) {
10
+ const actorToken = caller.actorToken();
11
+ if (!actorToken)
12
+ throw new ActorTokenRequiredError();
13
+ this.#client = client;
14
+ this.#actorToken = actorToken;
15
+ }
16
+ get(path, query) {
17
+ return this.request("GET", path, { query });
18
+ }
19
+ post(path, body) {
20
+ return this.request("POST", path, { body });
21
+ }
22
+ put(path, body) {
23
+ return this.request("PUT", path, { body });
24
+ }
25
+ patch(path, body) {
26
+ return this.request("PATCH", path, { body });
27
+ }
28
+ delete(path, body) {
29
+ return this.request("DELETE", path, { body });
30
+ }
31
+ async request(method, path, options = {}) {
32
+ if (!path.startsWith("/") || path.startsWith("/api/") || path.includes("..")) {
33
+ throw new PluginSdkError(`Platform API path must be absolute below /api and cannot contain traversal segments: ${path}`);
34
+ }
35
+ if (options.body)
36
+ assertBodySize(options.body);
37
+ const call = {
38
+ method,
39
+ path,
40
+ actor: this.#actorToken,
41
+ ...(options.query === undefined
42
+ ? {}
43
+ : { query: options.query.toString().replace(/^\?/, "") }),
44
+ ...(options.body === undefined ? {} : { body: options.body }),
45
+ };
46
+ const result = await this.#client.apiCall(call);
47
+ let body;
48
+ try {
49
+ body = (result.body === "" ? undefined : JSON.parse(result.body));
50
+ }
51
+ catch (error) {
52
+ throw new PluginSdkError(`Failed to decode ${result.body.length}-byte platform API response as JSON: ${error instanceof Error ? error.message : String(error)}`);
53
+ }
54
+ return {
55
+ status: result.status,
56
+ body,
57
+ ok: result.status >= 200 && result.status < 300,
58
+ };
59
+ }
60
+ static json(value) {
61
+ return { kind: "json", body: JSON.stringify(value) };
62
+ }
63
+ static multipart(parts) {
64
+ return { kind: "multipart", body: parts };
65
+ }
66
+ static textPart(name, value) {
67
+ return { name, content: { kind: "text", value } };
68
+ }
69
+ static binaryPart(options) {
70
+ return {
71
+ name: options.name,
72
+ ...(options.filename === undefined ? {} : { filename: options.filename }),
73
+ ...(options.contentType === undefined
74
+ ? {}
75
+ : { content_type: options.contentType }),
76
+ content: {
77
+ kind: "binary",
78
+ value: Buffer.from(options.bytes).toString("base64"),
79
+ },
80
+ };
81
+ }
82
+ }
83
+ function assertBodySize(body) {
84
+ const bytes = body.kind === "json"
85
+ ? Buffer.byteLength(body.body)
86
+ : body.body.reduce((total, part) => {
87
+ const contentBytes = part.content.kind === "text"
88
+ ? Buffer.byteLength(part.content.value)
89
+ : Buffer.from(part.content.value, "base64").byteLength;
90
+ return total + contentBytes;
91
+ }, 0);
92
+ if (bytes > MAX_CALL_BODY_BYTES) {
93
+ throw new CallBodyTooLargeError(bytes, MAX_CALL_BODY_BYTES);
94
+ }
95
+ }
96
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAI7C,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAajD,mFAAmF;AACnF,MAAM,OAAO,WAAW;IACb,OAAO,CAAc;IACrB,WAAW,CAAS;IAE7B,YAAY,MAAmB,EAAE,MAA2B;QAC1D,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,uBAAuB,EAAE,CAAC;QACrD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,GAAG,CAAI,IAAY,EAAE,KAAgC;QACnD,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,CAAI,IAAY,EAAE,IAAe;QACnC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED,GAAG,CAAI,IAAY,EAAE,IAAe;QAClC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;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AAW,KAAK,SAAS;gBACnC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;YAC1C,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;aACrD;SACF,CAAC;IACJ,CAAC;CACF;AAED,SAAS,cAAc,CAAC,IAAc;IACpC,MAAM,KAAK,GACT,IAAI,CAAC,IAAI,KAAK,MAAM;QAClB,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9B,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC/B,MAAM,YAAY,GAChB,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM;gBAC1B,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;gBACvC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC;YAC3D,OAAO,KAAK,GAAG,YAAY,CAAC;QAC9B,CAAC,EAAE,CAAC,CAAC,CAAC;IAEZ,IAAI,KAAK,GAAG,mBAAmB,EAAE,CAAC;QAChC,MAAM,IAAI,qBAAqB,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
package/dist/auth.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { IncomingMessage } from "node:http";
2
+ import type { PluginRole, TempsUserContext } from "./types.js";
3
+ export declare class AuthenticatedCaller implements TempsUserContext {
4
+ #private;
5
+ readonly userId: number;
6
+ readonly userEmail: string;
7
+ readonly role: PluginRole;
8
+ readonly permissions: ReadonlySet<string>;
9
+ readonly requestId: string;
10
+ constructor(options: {
11
+ userId: number;
12
+ userEmail: string;
13
+ role: PluginRole;
14
+ permissions: Iterable<string>;
15
+ requestId: string;
16
+ actorToken?: string;
17
+ });
18
+ isAdmin(): boolean;
19
+ hasPermission(permission: string): boolean;
20
+ /** @internal Used by PluginContext to bind platform calls to this caller. */
21
+ actorToken(): string | undefined;
22
+ toJSON(): Record<string, unknown>;
23
+ }
24
+ export type ProxyVerification = {
25
+ verified: true;
26
+ caller?: AuthenticatedCaller;
27
+ } | {
28
+ verified: false;
29
+ reason: string;
30
+ };
31
+ /** Verify the per-process assertion before trusting any x-temps-* identity. */
32
+ export declare function verifyProxyHeaders(headers: Headers, expectedSecret: string): ProxyVerification;
33
+ export declare function secureSecretMatches(provided: string, expected: string): boolean;
34
+ /** @internal Associate a verified caller with the SDK-owned request object. */
35
+ export declare function attachVerifiedCaller(request: IncomingMessage, caller: AuthenticatedCaller | undefined): void;
36
+ /**
37
+ * Return only the caller previously verified by the SDK runtime.
38
+ * Raw request headers are deliberately never parsed here.
39
+ */
40
+ export declare function extractAuthContext(request: IncomingMessage): AuthenticatedCaller | undefined;
41
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAuB/D,qBAAa,mBAAoB,YAAW,gBAAgB;;IAC1D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAGf,OAAO,EAAE;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,UAAU,CAAC;QACjB,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC9B,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IASD,OAAO,IAAI,OAAO;IAIlB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAI1C,6EAA6E;IAC7E,UAAU,IAAI,MAAM,GAAG,SAAS;IAIhC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CASlC;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,QAAQ,EAAE,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,mBAAmB,CAAA;CAAE,GAChD;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,iBAAiB,CAwCnB;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO/E;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,mBAAmB,GAAG,SAAS,GACtC,IAAI,CAEN;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,eAAe,GACvB,mBAAmB,GAAG,SAAS,CAEjC"}
package/dist/auth.js ADDED
@@ -0,0 +1,102 @@
1
+ // SPDX-FileCopyrightText: 2024-2026 Temps Contributors
2
+ // SPDX-License-Identifier: MIT OR Apache-2.0
3
+ import { timingSafeEqual } from "node:crypto";
4
+ import { HEADER_ACTOR_TOKEN, HEADER_AUTH_SIGNATURE, HEADER_REQUEST_ID, HEADER_USER_EMAIL, HEADER_USER_ID, HEADER_USER_PERMISSIONS, HEADER_USER_ROLE, } from "./protocol.js";
5
+ const ROLES = new Set([
6
+ "admin",
7
+ "platform_admin",
8
+ "user",
9
+ "reader",
10
+ "api_reader",
11
+ "custom",
12
+ "metrics_ingest",
13
+ ]);
14
+ const verifiedCallers = new WeakMap();
15
+ export class AuthenticatedCaller {
16
+ userId;
17
+ userEmail;
18
+ role;
19
+ permissions;
20
+ requestId;
21
+ #actorToken;
22
+ constructor(options) {
23
+ this.userId = options.userId;
24
+ this.userEmail = options.userEmail;
25
+ this.role = options.role;
26
+ this.permissions = new Set(options.permissions);
27
+ this.requestId = options.requestId;
28
+ this.#actorToken = options.actorToken;
29
+ }
30
+ isAdmin() {
31
+ return this.role === "admin";
32
+ }
33
+ hasPermission(permission) {
34
+ return this.permissions.has(permission);
35
+ }
36
+ /** @internal Used by PluginContext to bind platform calls to this caller. */
37
+ actorToken() {
38
+ return this.#actorToken;
39
+ }
40
+ toJSON() {
41
+ return {
42
+ userId: this.userId,
43
+ userEmail: this.userEmail,
44
+ role: this.role,
45
+ permissions: [...this.permissions],
46
+ requestId: this.requestId,
47
+ };
48
+ }
49
+ }
50
+ /** Verify the per-process assertion before trusting any x-temps-* identity. */
51
+ export function verifyProxyHeaders(headers, expectedSecret) {
52
+ const providedSecret = headers.get(HEADER_AUTH_SIGNATURE);
53
+ if (!providedSecret || !secureSecretMatches(providedSecret, expectedSecret)) {
54
+ return { verified: false, reason: "missing or invalid platform assertion" };
55
+ }
56
+ const userIdRaw = headers.get(HEADER_USER_ID);
57
+ const userEmail = headers.get(HEADER_USER_EMAIL);
58
+ const roleRaw = headers.get(HEADER_USER_ROLE);
59
+ if (!userIdRaw && !userEmail && !roleRaw) {
60
+ return { verified: true };
61
+ }
62
+ const userId = userIdRaw === null ? Number.NaN : Number(userIdRaw);
63
+ if (!Number.isSafeInteger(userId) ||
64
+ !userEmail ||
65
+ !roleRaw ||
66
+ !ROLES.has(roleRaw)) {
67
+ return { verified: false, reason: "incomplete or invalid caller assertion" };
68
+ }
69
+ const permissions = (headers.get(HEADER_USER_PERMISSIONS) ?? "")
70
+ .split(",")
71
+ .map((permission) => permission.trim())
72
+ .filter((permission) => /^[a-z_:]+$/.test(permission));
73
+ return {
74
+ verified: true,
75
+ caller: new AuthenticatedCaller({
76
+ userId,
77
+ userEmail,
78
+ role: roleRaw,
79
+ permissions,
80
+ requestId: headers.get(HEADER_REQUEST_ID) ?? "",
81
+ actorToken: headers.get(HEADER_ACTOR_TOKEN) ?? undefined,
82
+ }),
83
+ };
84
+ }
85
+ export function secureSecretMatches(provided, expected) {
86
+ const providedBytes = Buffer.from(provided);
87
+ const expectedBytes = Buffer.from(expected);
88
+ return (providedBytes.length === expectedBytes.length &&
89
+ timingSafeEqual(providedBytes, expectedBytes));
90
+ }
91
+ /** @internal Associate a verified caller with the SDK-owned request object. */
92
+ export function attachVerifiedCaller(request, caller) {
93
+ verifiedCallers.set(request, caller);
94
+ }
95
+ /**
96
+ * Return only the caller previously verified by the SDK runtime.
97
+ * Raw request headers are deliberately never parsed here.
98
+ */
99
+ export function extractAuthContext(request) {
100
+ return verifiedCallers.get(request);
101
+ }
102
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,GACjB,MAAM,eAAe,CAAC;AAEvB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAa;IAChC,OAAO;IACP,gBAAgB;IAChB,MAAM;IACN,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,gBAAgB;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,IAAI,OAAO,EAAoD,C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ACX,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE;YAC/C,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,SAAS;SACzD,CAAC;KACH,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAgB,EAAE,QAAgB;IACpE,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,OAAO,CACL,aAAa,CAAC,MAAM,KAAK,aAAa,CAAC,MAAM;QAC7C,eAAe,CAAC,aAAa,EAAE,aAAa,CAAC,CAC9C,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,oBAAoB,CAClC,OAAwB,EACxB,MAAuC;IAEvC,eAAe,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAwB;IAExB,OAAO,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { ApiCall, ApiCallResult, DeploymentInfo, EnvironmentInfo, PlatformCallMap, PlatformMethod, PluginEvent, ProjectInfo } from "./types.js";
2
+ export interface WsLike {
3
+ on(event: "message", fn: (data: unknown) => void): void;
4
+ on(event: "close", fn: () => void): void;
5
+ on(event: "error", fn: (error: unknown) => void): void;
6
+ send(data: string, callback?: (error?: Error) => void): void;
7
+ close(): void;
8
+ }
9
+ export declare class TempsClient {
10
+ #private;
11
+ constructor(ws: WsLike, options?: {
12
+ timeoutMs?: number;
13
+ });
14
+ onEvent(handler: (event: PluginEvent) => void | Promise<void>): void;
15
+ getProject(projectId: number): Promise<ProjectInfo>;
16
+ listProjects(): Promise<ProjectInfo[]>;
17
+ getEnvironment(environmentId: number): Promise<EnvironmentInfo>;
18
+ listEnvironments(projectId: number): Promise<EnvironmentInfo[]>;
19
+ getDeployment(deploymentId: number): Promise<DeploymentInfo>;
20
+ getLastDeployment(projectId: number, environmentId?: number): Promise<DeploymentInfo>;
21
+ listDeployments(projectId: number, options?: {
22
+ environmentId?: number;
23
+ limit?: number;
24
+ }): Promise<DeploymentInfo[]>;
25
+ apiCall(call: ApiCall): Promise<ApiCallResult>;
26
+ call<Method extends PlatformMethod>(method: Method, params: PlatformCallMap[Method]["params"]): Promise<PlatformCallMap[Method]["result"]>;
27
+ close(): void;
28
+ }
29
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EAIb,cAAc,EACd,eAAe,EACf,eAAe,EAEf,cAAc,EACd,WAAW,EACX,WAAW,EACZ,MAAM,YAAY,CAAC;AAUpB,MAAM,WAAW,MAAM;IACrB,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACxD,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACzC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACvD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IAC7D,KAAK,IAAI,IAAI,CAAC;CACf;AASD,qBAAa,WAAW;;gBAQV,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAWxD,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAIpE,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAInD,YAAY,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAItC,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAI/D,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAI/D,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI5D,iBAAiB,CACf,SAAS,EAAE,MAAM,EACjB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,cAAc,CAAC;IAO1B,eAAe,CACb,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACnD,OAAO,CAAC,cAAc,EAAE,CAAC;IAQ5B,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IAI9C,IAAI,CAAC,MAAM,SAAS,cAAc,EAChC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,GACxC,OAAO,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;IAgC7C,KAAK,IAAI,IAAI;CAsDd"}
package/dist/client.js ADDED
@@ -0,0 +1,141 @@
1
+ // SPDX-FileCopyrightText: 2024-2026 Temps Contributors
2
+ // SPDX-License-Identifier: MIT OR Apache-2.0
3
+ import { ChannelClosedError, ChannelTimeoutError, PlatformError, ProtocolMismatchError, } from "./errors.js";
4
+ const DEFAULT_TIMEOUT_MS = 10_000;
5
+ export class TempsClient {
6
+ #ws;
7
+ #pending = new Map();
8
+ #timeoutMs;
9
+ #nextId = 1;
10
+ #closed = false;
11
+ #eventHandler;
12
+ constructor(ws, options) {
13
+ this.#ws = ws;
14
+ this.#timeoutMs = options?.timeoutMs ?? DEFAULT_TIMEOUT_MS;
15
+ ws.on("message", (data) => this.#handleMessage(data));
16
+ ws.on("close", () => this.#closePending());
17
+ ws.on("error", (error) => {
18
+ this.#closePending(error instanceof Error ? error : new ChannelClosedError());
19
+ });
20
+ }
21
+ onEvent(handler) {
22
+ this.#eventHandler = handler;
23
+ }
24
+ getProject(projectId) {
25
+ return this.call("get_project", { project_id: projectId });
26
+ }
27
+ listProjects() {
28
+ return this.call("list_projects", {});
29
+ }
30
+ getEnvironment(environmentId) {
31
+ return this.call("get_environment", { environment_id: environmentId });
32
+ }
33
+ listEnvironments(projectId) {
34
+ return this.call("list_environments", { project_id: projectId });
35
+ }
36
+ getDeployment(deploymentId) {
37
+ return this.call("get_deployment", { deployment_id: deploymentId });
38
+ }
39
+ getLastDeployment(projectId, environmentId) {
40
+ return this.call("get_last_deployment", compact({
41
+ project_id: projectId,
42
+ environment_id: environmentId,
43
+ }));
44
+ }
45
+ listDeployments(projectId, options) {
46
+ return this.call("list_deployments", compact({
47
+ project_id: projectId,
48
+ environment_id: options?.environmentId,
49
+ limit: options?.limit,
50
+ }));
51
+ }
52
+ apiCall(call) {
53
+ return this.call("api_call", call);
54
+ }
55
+ call(method, params) {
56
+ if (this.#closed)
57
+ return Promise.reject(new ChannelClosedError());
58
+ const id = this.#nextId++;
59
+ const message = {
60
+ type: "request",
61
+ id,
62
+ call: { method, params },
63
+ };
64
+ return new Promise((resolve, reject) => {
65
+ const timer = setTimeout(() => {
66
+ this.#pending.delete(id);
67
+ reject(new ChannelTimeoutError(method, this.#timeoutMs));
68
+ }, this.#timeoutMs);
69
+ this.#pending.set(id, {
70
+ method,
71
+ resolve: (value) => resolve(value),
72
+ reject,
73
+ timer,
74
+ });
75
+ this.#ws.send(JSON.stringify(message), (error) => {
76
+ if (!error)
77
+ return;
78
+ clearTimeout(timer);
79
+ this.#pending.delete(id);
80
+ reject(error);
81
+ });
82
+ });
83
+ }
84
+ close() {
85
+ this.#closed = true;
86
+ this.#ws.close();
87
+ this.#closePending();
88
+ }
89
+ #handleMessage(data) {
90
+ let message;
91
+ try {
92
+ message = JSON.parse(normalizeMessage(data));
93
+ }
94
+ catch {
95
+ return;
96
+ }
97
+ if (message.type === "response") {
98
+ this.#handleResponse(message);
99
+ return;
100
+ }
101
+ if (message.type === "event") {
102
+ void Promise.resolve(this.#eventHandler?.(message.event)).catch(() => undefined);
103
+ }
104
+ }
105
+ #handleResponse(message) {
106
+ const pending = this.#pending.get(message.id);
107
+ if (!pending)
108
+ return;
109
+ clearTimeout(pending.timer);
110
+ this.#pending.delete(message.id);
111
+ if ("err" in message.outcome) {
112
+ pending.reject(new PlatformError(message.outcome.err.code, message.outcome.err.message));
113
+ return;
114
+ }
115
+ const response = message.outcome.ok;
116
+ if (response.method !== pending.method) {
117
+ pending.reject(new ProtocolMismatchError(pending.method, response.method));
118
+ return;
119
+ }
120
+ pending.resolve(response.result);
121
+ }
122
+ #closePending(reason = new ChannelClosedError()) {
123
+ this.#closed = true;
124
+ for (const pending of this.#pending.values()) {
125
+ clearTimeout(pending.timer);
126
+ pending.reject(reason);
127
+ }
128
+ this.#pending.clear();
129
+ }
130
+ }
131
+ function normalizeMessage(data) {
132
+ if (typeof data === "string")
133
+ return data;
134
+ if (data instanceof Uint8Array)
135
+ return Buffer.from(data).toString("utf8");
136
+ return String(data);
137
+ }
138
+ function compact(value) {
139
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== undefined));
140
+ }
141
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,6CAA6C;AAgB7C,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,qBAAqB,GACtB,MAAM,aAAa,C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,CAAC,CAAC;YAC5B,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,IAAa;IACrC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC1C,IAAI,IAAI,YAAY,UAAU;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,OAAO,CAAoC,KAAQ;IAC1D,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAC5D,CAAC;AACT,CAAC"}
@@ -0,0 +1,26 @@
1
+ import { PlatformApi } from "./api.js";
2
+ import type { AuthenticatedCaller } from "./auth.js";
3
+ import type { TempsClient } from "./client.js";
4
+ export declare class PluginContext {
5
+ #private;
6
+ constructor(options: {
7
+ pluginName: string;
8
+ dataDir: string;
9
+ databaseUrl?: string;
10
+ hostDataDir?: string;
11
+ hostApiUrl?: string;
12
+ authSecret: string;
13
+ client: TempsClient;
14
+ });
15
+ get temps(): TempsClient;
16
+ apiAsCaller(caller: AuthenticatedCaller): PlatformApi;
17
+ get pluginName(): string;
18
+ get dataDir(): string;
19
+ get databaseUrl(): string | undefined;
20
+ get hostDataDir(): string | undefined;
21
+ get hostApiUrl(): string | undefined;
22
+ get mountUrl(): string | undefined;
23
+ /** Per-process assertion secret. Prefer extractAuthContext over manual use. */
24
+ get authSecret(): string;
25
+ }
26
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,qBAAa,aAAa;;gBASZ,OAAO,EAAE;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,WAAW,CAAC;KACrB;IAUD,IAAI,KAAK,IAAI,WAAW,CAEvB;IAED,WAAW,CAAC,MAAM,EAAE,mBAAmB,GAAG,WAAW;IAIrD,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,WAAW,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED,IAAI,QAAQ,IAAI,MAAM,GAAG,SAAS,CAIjC;IAED,+EAA+E;IAC/E,IAAI,UAAU,IAAI,MAAM,CAEvB;CACF"}