@heossi/qnsi 0.3.3 → 0.4.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/CHANGELOG.md +1 -1
- package/README.md +12 -12
- package/dist/_activation/activation-client.d.ts +2 -2
- package/dist/_activation/activation-client.js +4 -4
- package/dist/_internal.d.ts +6 -6
- package/dist/_internal.js +8 -8
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +26 -2
- package/dist/audit.js.map +1 -1
- package/dist/autogen/executor.d.ts +7 -7
- package/dist/autogen/executor.js +5 -5
- package/dist/autogen/index.d.ts +4 -4
- package/dist/autogen/index.js +3 -3
- package/dist/browser/provider-setup.d.ts +2 -2
- package/dist/browser/sdk-package-version.d.ts +1 -1
- package/dist/browser/sdk-package-version.js +1 -1
- package/dist/cli/commands/test-utils.js +1 -1
- package/dist/cli/config.js +1 -1
- package/dist/cli/utils/backend-validator.js +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.js +1 -1
- package/dist/errors.d.ts +5 -5
- package/dist/errors.js +10 -10
- package/dist/index.d.ts +24 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/kms.js +4 -4
- package/dist/langchain/index.d.ts +9 -9
- package/dist/langchain/index.js +6 -6
- package/dist/langchain/toolkit.d.ts +7 -7
- package/dist/langchain/toolkit.js +13 -13
- package/dist/langchain/tools/audit.d.ts +4 -4
- package/dist/langchain/tools/audit.js +1 -1
- package/dist/langchain/tools/kms.d.ts +6 -6
- package/dist/langchain/tools/kms.js +2 -2
- package/dist/langchain/tools/vault.d.ts +3 -3
- package/dist/langchain/tools/vault.js +3 -3
- package/dist/langchain/vault-client.d.ts +1 -1
- package/dist/langchain/vault-client.js +3 -3
- package/dist/llamaindex/index.d.ts +4 -4
- package/dist/llamaindex/index.js +3 -3
- package/dist/llamaindex/vector-store.d.ts +7 -7
- package/dist/llamaindex/vector-store.js +5 -5
- package/dist/storage.d.ts +1 -1
- package/dist/storage.js +3 -3
- package/dist/webhooks.d.ts +5 -5
- package/dist/webhooks.js +15 -15
- package/package.json +5 -5
package/dist/storage.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class StorageClient {
|
|
|
20
20
|
constructor(internal: Internal);
|
|
21
21
|
putObject(bucket: string, key: string, input: PutObjectInput, opts?: Pick<RequestOptions, "idempotencyKey">): Promise<Record<string, unknown>>;
|
|
22
22
|
/**
|
|
23
|
-
* Returns `[plaintext bytes, descriptor JSON]`. Throws `
|
|
23
|
+
* Returns `[plaintext bytes, descriptor JSON]`. Throws `QnsiApiError`
|
|
24
24
|
* if the descriptor is missing the dataB64 field.
|
|
25
25
|
*/
|
|
26
26
|
getObject(bucket: string, key: string): Promise<readonly [Uint8Array, GetObjectResponse]>;
|
package/dist/storage.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* (apps/storage-service/src/routes/bucket-objects.ts) and reached via the edge gateway's
|
|
5
5
|
* `/proxy/storage` prefix (rewritten to `/storage`).
|
|
6
6
|
*/
|
|
7
|
-
import {
|
|
7
|
+
import { QnsiApiError } from "./errors.js";
|
|
8
8
|
// Edge gateway rewrites /proxy/storage -> /storage, so this resolves to the backend's
|
|
9
9
|
// /storage/v1/buckets/* routes. (Was /proxy/storage/storage/v1 — a double "storage" that
|
|
10
10
|
// rewrote to /storage/storage/v1, which the backend never served, so every call 404'd.)
|
|
@@ -27,13 +27,13 @@ export class StorageClient {
|
|
|
27
27
|
return this.internal.request("PUT", `${PATH_PREFIX}/buckets/${bucket}/objects/${key}`, body, opts);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Returns `[plaintext bytes, descriptor JSON]`. Throws `
|
|
30
|
+
* Returns `[plaintext bytes, descriptor JSON]`. Throws `QnsiApiError`
|
|
31
31
|
* if the descriptor is missing the dataB64 field.
|
|
32
32
|
*/
|
|
33
33
|
async getObject(bucket, key) {
|
|
34
34
|
const resp = await this.internal.request("GET", `${PATH_PREFIX}/buckets/${bucket}/objects/${key}`);
|
|
35
35
|
if (!resp.dataB64) {
|
|
36
|
-
throw new
|
|
36
|
+
throw new QnsiApiError("storage.getObject: response missing dataB64", 200);
|
|
37
37
|
}
|
|
38
38
|
return [decodeB64(resp.dataB64), resp];
|
|
39
39
|
}
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/** Default replay-protection window — 5 minutes. */
|
|
8
8
|
export declare const MAX_WEBHOOK_SKEW_MS: number;
|
|
9
|
-
export interface
|
|
9
|
+
export interface QnsiWebhookEvent {
|
|
10
10
|
readonly eventType: string;
|
|
11
11
|
readonly eventId: string;
|
|
12
12
|
readonly occurredAt: string;
|
|
@@ -16,17 +16,17 @@ export interface QnspWebhookEvent {
|
|
|
16
16
|
* Constant-time HMAC-SHA-256 verification. The header must be of the
|
|
17
17
|
* form `sha256=<hex>`.
|
|
18
18
|
*/
|
|
19
|
-
export declare function
|
|
19
|
+
export declare function verifyQnsiWebhookSignature(body: Uint8Array | string, signatureHeader: string, secret: string): void;
|
|
20
20
|
/**
|
|
21
21
|
* Verify the HMAC, enforce replay protection, parse the JSON body, and
|
|
22
|
-
* return a typed `
|
|
22
|
+
* return a typed `QnsiWebhookEvent`.
|
|
23
23
|
*/
|
|
24
|
-
export declare function
|
|
24
|
+
export declare function parseQnsiWebhook(input: {
|
|
25
25
|
readonly body: Uint8Array | string;
|
|
26
26
|
readonly signatureHeader: string;
|
|
27
27
|
readonly timestampHeader?: string;
|
|
28
28
|
readonly secret: string;
|
|
29
29
|
readonly maxSkewMs?: number;
|
|
30
30
|
readonly now?: Date;
|
|
31
|
-
}):
|
|
31
|
+
}): QnsiWebhookEvent;
|
|
32
32
|
//# sourceMappingURL=webhooks.d.ts.map
|
package/dist/webhooks.js
CHANGED
|
@@ -5,46 +5,46 @@
|
|
|
5
5
|
* body. Always verify the **raw bytes** before parsing JSON.
|
|
6
6
|
*/
|
|
7
7
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
8
|
-
import {
|
|
8
|
+
import { QnsiWebhookError } from "./errors.js";
|
|
9
9
|
/** Default replay-protection window — 5 minutes. */
|
|
10
10
|
export const MAX_WEBHOOK_SKEW_MS = 5 * 60 * 1000;
|
|
11
11
|
/**
|
|
12
12
|
* Constant-time HMAC-SHA-256 verification. The header must be of the
|
|
13
13
|
* form `sha256=<hex>`.
|
|
14
14
|
*/
|
|
15
|
-
export function
|
|
15
|
+
export function verifyQnsiWebhookSignature(body, signatureHeader, secret) {
|
|
16
16
|
if (!signatureHeader.startsWith("sha256=")) {
|
|
17
|
-
throw new
|
|
17
|
+
throw new QnsiWebhookError("signature header must start with 'sha256='");
|
|
18
18
|
}
|
|
19
19
|
const expectedHex = signatureHeader.slice("sha256=".length);
|
|
20
20
|
const expected = Buffer.from(expectedHex, "hex");
|
|
21
21
|
if (expected.length === 0) {
|
|
22
|
-
throw new
|
|
22
|
+
throw new QnsiWebhookError("signature is not valid hex");
|
|
23
23
|
}
|
|
24
24
|
const bodyBytes = typeof body === "string" ? Buffer.from(body, "utf8") : Buffer.from(body);
|
|
25
25
|
const actual = createHmac("sha256", secret).update(bodyBytes).digest();
|
|
26
26
|
if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new QnsiWebhookError("signature mismatch");
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
31
|
* Verify the HMAC, enforce replay protection, parse the JSON body, and
|
|
32
|
-
* return a typed `
|
|
32
|
+
* return a typed `QnsiWebhookEvent`.
|
|
33
33
|
*/
|
|
34
|
-
export function
|
|
35
|
-
|
|
34
|
+
export function parseQnsiWebhook(input) {
|
|
35
|
+
verifyQnsiWebhookSignature(input.body, input.signatureHeader, input.secret);
|
|
36
36
|
const skewMs = input.maxSkewMs ?? MAX_WEBHOOK_SKEW_MS;
|
|
37
37
|
if (input.timestampHeader !== undefined && input.timestampHeader.length > 0) {
|
|
38
38
|
const ts = Date.parse(input.timestampHeader);
|
|
39
39
|
if (Number.isNaN(ts)) {
|
|
40
|
-
throw new
|
|
40
|
+
throw new QnsiWebhookError("timestamp header is not RFC3339");
|
|
41
41
|
}
|
|
42
42
|
const reference = input.now ? input.now.getTime() : Date.now();
|
|
43
43
|
const delta = reference - ts;
|
|
44
44
|
if (delta > skewMs)
|
|
45
|
-
throw new
|
|
45
|
+
throw new QnsiWebhookError("timestamp is too old");
|
|
46
46
|
if (-delta > skewMs)
|
|
47
|
-
throw new
|
|
47
|
+
throw new QnsiWebhookError("timestamp is in the future");
|
|
48
48
|
}
|
|
49
49
|
const text = typeof input.body === "string" ? input.body : Buffer.from(input.body).toString("utf8");
|
|
50
50
|
let raw;
|
|
@@ -52,19 +52,19 @@ export function parseQnspWebhook(input) {
|
|
|
52
52
|
raw = JSON.parse(text);
|
|
53
53
|
}
|
|
54
54
|
catch {
|
|
55
|
-
throw new
|
|
55
|
+
throw new QnsiWebhookError("body is not valid JSON");
|
|
56
56
|
}
|
|
57
57
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
58
|
-
throw new
|
|
58
|
+
throw new QnsiWebhookError("body is not a JSON object");
|
|
59
59
|
}
|
|
60
60
|
const obj = raw;
|
|
61
61
|
const eventType = obj["event_type"];
|
|
62
62
|
const eventId = obj["event_id"];
|
|
63
63
|
if (typeof eventType !== "string") {
|
|
64
|
-
throw new
|
|
64
|
+
throw new QnsiWebhookError("missing event_type");
|
|
65
65
|
}
|
|
66
66
|
if (typeof eventId !== "string") {
|
|
67
|
-
throw new
|
|
67
|
+
throw new QnsiWebhookError("missing event_id");
|
|
68
68
|
}
|
|
69
69
|
const occurredAtRaw = obj["occurred_at"];
|
|
70
70
|
const occurredAt = typeof occurredAtRaw === "string" ? occurredAtRaw : "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heossi/qnsi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -96,12 +96,12 @@
|
|
|
96
96
|
],
|
|
97
97
|
"repository": {
|
|
98
98
|
"type": "git",
|
|
99
|
-
"url": "https://github.com/heossi-hq/
|
|
100
|
-
"directory": "packages/
|
|
99
|
+
"url": "https://github.com/heossi-hq/qnsi-public",
|
|
100
|
+
"directory": "packages/qnsi"
|
|
101
101
|
},
|
|
102
|
-
"homepage": "https://cloud.
|
|
102
|
+
"homepage": "https://cloud.qnsi.heossi.com",
|
|
103
103
|
"bugs": {
|
|
104
|
-
"url": "https://github.com/heossi-hq/
|
|
104
|
+
"url": "https://github.com/heossi-hq/qnsi-public/issues"
|
|
105
105
|
},
|
|
106
106
|
"files": [
|
|
107
107
|
"dist/**/*",
|