@rei-standard/amsg-shared 0.4.0-next.0 → 0.4.0-next.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/LICENSE +21 -0
- package/dist/index.cjs +517 -28
- package/dist/index.d.cts +13 -17
- package/dist/index.d.ts +13 -17
- package/dist/index.mjs +515 -28
- package/dist/llm-call.d.cts +113 -0
- package/dist/llm-call.d.ts +113 -0
- package/dist/llm-messages.d.cts +66 -0
- package/dist/llm-messages.d.ts +66 -0
- package/dist/protocol.d.cts +57 -0
- package/dist/protocol.d.ts +57 -0
- package/dist/webcrypto-utils.d.cts +42 -0
- package/dist/webcrypto-utils.d.ts +42 -0
- package/dist/webpush.d.cts +69 -0
- package/dist/webpush.d.ts +69 -0
- package/package.json +2 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Send a single Web Push notification.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args
|
|
5
|
+
* @param {Object} args.subscription - Standard PushSubscription JSON.
|
|
6
|
+
* @param {string} args.subscription.endpoint
|
|
7
|
+
* @param {Object} args.subscription.keys
|
|
8
|
+
* @param {string} args.subscription.keys.p256dh - base64url, 65 B uncompressed P-256 point.
|
|
9
|
+
* @param {string} args.subscription.keys.auth - base64url, 16 B auth secret.
|
|
10
|
+
* @param {string} args.payload - Already-stringified JSON to deliver.
|
|
11
|
+
* @param {Object} args.vapid
|
|
12
|
+
* @param {string} args.vapid.email - VAPID `sub` (mailto: auto-prepended if missing).
|
|
13
|
+
* @param {string} args.vapid.publicKey - base64url, 65 B uncompressed P-256 point.
|
|
14
|
+
* @param {string} args.vapid.privateKey - base64url, 32 B scalar.
|
|
15
|
+
* @param {number} [args.ttl=60] - Push service TTL header, seconds.
|
|
16
|
+
* @param {typeof fetch} [args.fetch] - Override fetch impl (testing / proxy).
|
|
17
|
+
* @returns {Promise<{ statusCode: number, body: string, headers: Headers }>}
|
|
18
|
+
* @throws {Error} err.code = 'PUSH_SEND_FAILED' on push-service error.
|
|
19
|
+
*/
|
|
20
|
+
export function sendWebPush({ subscription, payload, vapid, ttl, fetch: fetchImpl }: {
|
|
21
|
+
subscription: {
|
|
22
|
+
endpoint: string;
|
|
23
|
+
keys: {
|
|
24
|
+
p256dh: string;
|
|
25
|
+
auth: string;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
payload: string;
|
|
29
|
+
vapid: {
|
|
30
|
+
email: string;
|
|
31
|
+
publicKey: string;
|
|
32
|
+
privateKey: string;
|
|
33
|
+
};
|
|
34
|
+
ttl?: number;
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
statusCode: number;
|
|
38
|
+
body: string;
|
|
39
|
+
headers: Headers;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Build a VAPID `Authorization` JWT for a single push.
|
|
43
|
+
*
|
|
44
|
+
* @param {Object} args
|
|
45
|
+
* @param {string} args.audience - Origin of the push endpoint (e.g. https://fcm.googleapis.com).
|
|
46
|
+
* @param {string} args.subject - VAPID `sub` claim, typically `mailto:you@example.com`.
|
|
47
|
+
* @param {string} args.publicKey - base64url, 65 B uncompressed P-256 point.
|
|
48
|
+
* @param {string} args.privateKey - base64url, 32 B scalar.
|
|
49
|
+
* @returns {Promise<string>} compact JWS (three base64url segments).
|
|
50
|
+
*/
|
|
51
|
+
export function buildVapidJwt({ audience, subject, publicKey, privateKey }: {
|
|
52
|
+
audience: string;
|
|
53
|
+
subject: string;
|
|
54
|
+
publicKey: string;
|
|
55
|
+
privateKey: string;
|
|
56
|
+
}): Promise<string>;
|
|
57
|
+
/**
|
|
58
|
+
* Verify a VAPID JWT signature. Exported for tests / advanced consumers.
|
|
59
|
+
* Returns the decoded payload if the signature and `exp` are valid.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} jwt
|
|
62
|
+
* @param {string} publicKey - VAPID public key (base64url, 65 B).
|
|
63
|
+
* @returns {Promise<{ aud: string, exp: number, sub: string }>}
|
|
64
|
+
*/
|
|
65
|
+
export function verifyVapidJwt(jwt: string, publicKey: string): Promise<{
|
|
66
|
+
aud: string;
|
|
67
|
+
exp: number;
|
|
68
|
+
sub: string;
|
|
69
|
+
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rei-standard/amsg-shared",
|
|
3
|
-
"version": "0.4.0-next.
|
|
3
|
+
"version": "0.4.0-next.2",
|
|
4
4
|
"description": "ReiStandard Active Messaging shared types and push builders — the lowest layer (no deps on other amsg packages)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "tsup && tsc -p tsconfig.json && node -e \"require('fs').
|
|
30
|
+
"build": "tsup && tsc -p tsconfig.json && node -e \"const fs=require('fs');for(const f of fs.readdirSync('dist'))if(f.endsWith('.d.ts'))fs.copyFileSync('dist/'+f,'dist/'+f.slice(0,-5)+'.d.cts')\"",
|
|
31
31
|
"test": "node --test test/*.test.mjs"
|
|
32
32
|
},
|
|
33
33
|
"engines": {
|