@temps-sdk/plugin 0.1.0-beta.1 → 0.1.0-beta.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/ai.d.ts +32 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +38 -0
- package/dist/ai.js.map +1 -0
- package/dist/client.d.ts +41 -10
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +146 -89
- package/dist/client.js.map +1 -1
- package/dist/context.d.ts +21 -12
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +25 -36
- package/dist/context.js.map +1 -1
- package/dist/errors.d.ts +0 -23
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +0 -46
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +36 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -6
- package/dist/index.js.map +1 -1
- package/dist/launch.d.ts +9 -0
- package/dist/launch.d.ts.map +1 -0
- package/dist/launch.js +96 -0
- package/dist/launch.js.map +1 -0
- package/dist/manifest-builder.d.ts +4 -9
- package/dist/manifest-builder.d.ts.map +1 -1
- package/dist/manifest-builder.js +7 -26
- package/dist/manifest-builder.js.map +1 -1
- package/dist/protocol.d.ts +28 -14
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +49 -94
- package/dist/protocol.js.map +1 -1
- package/dist/runtime.d.ts +21 -12
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +318 -426
- package/dist/runtime.js.map +1 -1
- package/dist/types.d.ts +147 -151
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -4
- package/dist/types.js.map +1 -1
- package/dist/ui.d.ts.map +1 -1
- package/dist/ui.js +7 -26
- package/dist/ui.js.map +1 -1
- package/package.json +10 -19
- package/LICENSE +0 -21
- package/README.md +0 -123
- package/dist/api.d.ts +0 -33
- package/dist/api.d.ts.map +0 -1
- package/dist/api.js +0 -96
- package/dist/api.js.map +0 -1
- package/dist/auth.d.ts +0 -41
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -102
- package/dist/auth.js.map +0 -1
package/README.md
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
package/dist/api.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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;KACtB,GAAG,aAAa;CAalB"}
|
package/dist/api.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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
|
package/dist/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;IAED,KAAK,CAAI,IAAY,EAAE,IAAe;QACpC,OAAO,IAAI,CAAC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AC,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
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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
|
package/dist/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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C,OAAO,EAAE,eAAe,GACvB,mBAAmB,GAAG,SAAS,CAEjC"}
|
package/dist/auth.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
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
|
package/dist/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,CAAC;AAExF,MAAM,OAAO,mBAAmB;IACrB,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,IAAI,CAAa;IACjB,WAAW,CAAsB;IACjC,SAAS,CAAS;IAClB,WAAW,CAAU;IAE9B,YAAY,OAOX;QACC,IA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