@miosa/sdk 1.1.0 → 1.2.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.
- package/dist/index.d.ts +26 -229
- package/dist/index.js +25 -276
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +0 -5
- package/src/index.ts +0 -10
- package/src/resources/admin.ts +11 -0
- package/src/resources/api-keys.ts +17 -5
- package/src/resources/cron-jobs.ts +0 -7
- package/src/resources/custom_domains.ts +0 -7
- package/src/resources/deployments.ts +2 -13
- package/src/resources/flat-custom-domains.ts +0 -7
- package/src/resources/functions.ts +0 -7
- package/src/resources/governance.test.ts +355 -0
- package/src/resources/governance.ts +528 -0
- package/src/resources/storage.ts +0 -7
- package/src/resources/tenant.ts +3 -82
- package/src/resources/volumes.ts +0 -7
- package/src/resources/webhooks.ts +0 -55
- package/src/types.ts +0 -7
|
@@ -2,48 +2,10 @@
|
|
|
2
2
|
* Webhooks resource — tenant outgoing event delivery.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
6
5
|
import { randomUUID } from "node:crypto";
|
|
7
6
|
|
|
8
7
|
import type { HttpClient } from "../http.js";
|
|
9
8
|
|
|
10
|
-
const MAX_TIMESTAMP_AGE_MS = 5 * 60 * 1000;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Verify an incoming ``X-Miosa-Signature`` header.
|
|
14
|
-
* Header format: ``t=<unix_ts>,v1=<hex_hmac>``
|
|
15
|
-
*/
|
|
16
|
-
export function verifySignature(
|
|
17
|
-
payload: string | Uint8Array,
|
|
18
|
-
signatureHeader: string,
|
|
19
|
-
secret: string,
|
|
20
|
-
): boolean {
|
|
21
|
-
const parts: Record<string, string> = {};
|
|
22
|
-
for (const part of signatureHeader.split(",")) {
|
|
23
|
-
const idx = part.indexOf("=");
|
|
24
|
-
if (idx > 0) parts[part.slice(0, idx).trim()] = part.slice(idx + 1).trim();
|
|
25
|
-
}
|
|
26
|
-
const tsStr = parts["t"];
|
|
27
|
-
const sig = parts["v1"];
|
|
28
|
-
if (!tsStr || !sig) return false;
|
|
29
|
-
|
|
30
|
-
const ts = parseInt(tsStr, 10);
|
|
31
|
-
if (isNaN(ts)) return false;
|
|
32
|
-
if (Date.now() - ts * 1000 > MAX_TIMESTAMP_AGE_MS) {
|
|
33
|
-
throw new Error(`Webhook timestamp is too old: ${ts}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const body =
|
|
37
|
-
payload instanceof Uint8Array ? payload : Buffer.from(payload, "utf-8");
|
|
38
|
-
const signed = Buffer.concat([Buffer.from(`${tsStr}.`, "utf-8"), body]);
|
|
39
|
-
const expected = createHmac("sha256", secret).update(signed).digest("hex");
|
|
40
|
-
|
|
41
|
-
return timingSafeEqual(
|
|
42
|
-
Buffer.from(expected, "utf-8"),
|
|
43
|
-
Buffer.from(sig, "utf-8"),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
9
|
// ── Branded IDs ──────────────────────────────────────────────────────────────
|
|
48
10
|
|
|
49
11
|
export type WebhookId = string & { readonly __brand: "WebhookId" };
|
|
@@ -206,21 +168,4 @@ export class Webhooks {
|
|
|
206
168
|
"items",
|
|
207
169
|
]);
|
|
208
170
|
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Verify an incoming ``X-Miosa-Signature`` header.
|
|
212
|
-
*
|
|
213
|
-
* Header format: ``t=<unix_ts>,v1=<hex_hmac>``
|
|
214
|
-
* HMAC body: ``<t>.<raw_payload>``
|
|
215
|
-
*
|
|
216
|
-
* Throws if timestamp is older than 5 minutes.
|
|
217
|
-
* Returns true if signature matches.
|
|
218
|
-
*/
|
|
219
|
-
static verifySignature(
|
|
220
|
-
payload: string | Uint8Array,
|
|
221
|
-
signatureHeader: string,
|
|
222
|
-
secret: string,
|
|
223
|
-
): boolean {
|
|
224
|
-
return verifySignature(payload, signatureHeader, secret);
|
|
225
|
-
}
|
|
226
171
|
}
|
package/src/types.ts
CHANGED
|
@@ -66,13 +66,6 @@ export interface ComputerCreateParams {
|
|
|
66
66
|
size?: ComputerSize;
|
|
67
67
|
visibility?: ComputerVisibility;
|
|
68
68
|
metadata?: Record<string, string>;
|
|
69
|
-
// White-label attribution
|
|
70
|
-
externalWorkspaceId?: string;
|
|
71
|
-
external_workspace_id?: string;
|
|
72
|
-
externalUserId?: string;
|
|
73
|
-
external_user_id?: string;
|
|
74
|
-
externalProjectId?: string;
|
|
75
|
-
external_project_id?: string;
|
|
76
69
|
}
|
|
77
70
|
|
|
78
71
|
export interface ComputerUpdateParams {
|