sanity-plugin-ga-dashboard 1.0.0 → 1.0.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/api/index.cjs +1543 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/{index.d.mts → index.d.cts} +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1304 -45
- package/dist/api/index.js.map +1 -1
- package/dist/index.cjs +893 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +198 -205
- package/dist/index.js.map +1 -1
- package/package.json +47 -17
- package/dist/api/index.esm.js +0 -235
- package/dist/api/index.esm.js.map +0 -1
- package/dist/index.esm.js +0 -880
- package/dist/index.esm.js.map +0 -1
|
@@ -0,0 +1,1543 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
for (var name in all)
|
|
28
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
29
|
+
};
|
|
30
|
+
var __copyProps = (to, from, except, desc) => {
|
|
31
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
32
|
+
for (let key of __getOwnPropNames(from))
|
|
33
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
34
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
35
|
+
}
|
|
36
|
+
return to;
|
|
37
|
+
};
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
41
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
42
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
43
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
44
|
+
|
|
45
|
+
// src/api/index.ts
|
|
46
|
+
var api_exports = {};
|
|
47
|
+
__export(api_exports, {
|
|
48
|
+
GET: () => GET
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(api_exports);
|
|
51
|
+
|
|
52
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
53
|
+
var encoder = new TextEncoder();
|
|
54
|
+
var decoder = new TextDecoder();
|
|
55
|
+
var MAX_INT32 = 2 ** 32;
|
|
56
|
+
function concat(...buffers) {
|
|
57
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
58
|
+
const buf = new Uint8Array(size);
|
|
59
|
+
let i = 0;
|
|
60
|
+
for (const buffer of buffers) {
|
|
61
|
+
buf.set(buffer, i);
|
|
62
|
+
i += buffer.length;
|
|
63
|
+
}
|
|
64
|
+
return buf;
|
|
65
|
+
}
|
|
66
|
+
function encode(string) {
|
|
67
|
+
const bytes = new Uint8Array(string.length);
|
|
68
|
+
for (let i = 0; i < string.length; i++) {
|
|
69
|
+
const code = string.charCodeAt(i);
|
|
70
|
+
if (code > 127) {
|
|
71
|
+
throw new TypeError("non-ASCII string encountered in encode()");
|
|
72
|
+
}
|
|
73
|
+
bytes[i] = code;
|
|
74
|
+
}
|
|
75
|
+
return bytes;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/base64.js
|
|
79
|
+
function encodeBase64(input) {
|
|
80
|
+
if (Uint8Array.prototype.toBase64) {
|
|
81
|
+
return input.toBase64();
|
|
82
|
+
}
|
|
83
|
+
const CHUNK_SIZE = 32768;
|
|
84
|
+
const arr = [];
|
|
85
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
86
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
87
|
+
}
|
|
88
|
+
return btoa(arr.join(""));
|
|
89
|
+
}
|
|
90
|
+
function decodeBase64(encoded) {
|
|
91
|
+
if (Uint8Array.fromBase64) {
|
|
92
|
+
return Uint8Array.fromBase64(encoded);
|
|
93
|
+
}
|
|
94
|
+
const binary = atob(encoded);
|
|
95
|
+
const bytes = new Uint8Array(binary.length);
|
|
96
|
+
for (let i = 0; i < binary.length; i++) {
|
|
97
|
+
bytes[i] = binary.charCodeAt(i);
|
|
98
|
+
}
|
|
99
|
+
return bytes;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/base64url.js
|
|
103
|
+
function decode(input) {
|
|
104
|
+
if (Uint8Array.fromBase64) {
|
|
105
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
106
|
+
alphabet: "base64url"
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
let encoded = input;
|
|
110
|
+
if (encoded instanceof Uint8Array) {
|
|
111
|
+
encoded = decoder.decode(encoded);
|
|
112
|
+
}
|
|
113
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
114
|
+
try {
|
|
115
|
+
return decodeBase64(encoded);
|
|
116
|
+
} catch (e) {
|
|
117
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function encode2(input) {
|
|
121
|
+
let unencoded = input;
|
|
122
|
+
if (typeof unencoded === "string") {
|
|
123
|
+
unencoded = encoder.encode(unencoded);
|
|
124
|
+
}
|
|
125
|
+
if (Uint8Array.prototype.toBase64) {
|
|
126
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
127
|
+
}
|
|
128
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
132
|
+
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
133
|
+
var isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
134
|
+
function getHashLength(hash) {
|
|
135
|
+
return parseInt(hash.name.slice(4), 10);
|
|
136
|
+
}
|
|
137
|
+
function checkHashLength(algorithm, expected) {
|
|
138
|
+
const actual = getHashLength(algorithm.hash);
|
|
139
|
+
if (actual !== expected)
|
|
140
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
141
|
+
}
|
|
142
|
+
function getNamedCurve(alg) {
|
|
143
|
+
switch (alg) {
|
|
144
|
+
case "ES256":
|
|
145
|
+
return "P-256";
|
|
146
|
+
case "ES384":
|
|
147
|
+
return "P-384";
|
|
148
|
+
case "ES512":
|
|
149
|
+
return "P-521";
|
|
150
|
+
default:
|
|
151
|
+
throw new Error("unreachable");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function checkUsage(key, usage) {
|
|
155
|
+
if (usage && !key.usages.includes(usage)) {
|
|
156
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
160
|
+
switch (alg) {
|
|
161
|
+
case "HS256":
|
|
162
|
+
case "HS384":
|
|
163
|
+
case "HS512": {
|
|
164
|
+
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
165
|
+
throw unusable("HMAC");
|
|
166
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "RS256":
|
|
170
|
+
case "RS384":
|
|
171
|
+
case "RS512": {
|
|
172
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
173
|
+
throw unusable("RSASSA-PKCS1-v1_5");
|
|
174
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "PS256":
|
|
178
|
+
case "PS384":
|
|
179
|
+
case "PS512": {
|
|
180
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
181
|
+
throw unusable("RSA-PSS");
|
|
182
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case "Ed25519":
|
|
186
|
+
case "EdDSA": {
|
|
187
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
188
|
+
throw unusable("Ed25519");
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case "ML-DSA-44":
|
|
192
|
+
case "ML-DSA-65":
|
|
193
|
+
case "ML-DSA-87": {
|
|
194
|
+
if (!isAlgorithm(key.algorithm, alg))
|
|
195
|
+
throw unusable(alg);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
case "ES256":
|
|
199
|
+
case "ES384":
|
|
200
|
+
case "ES512": {
|
|
201
|
+
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
202
|
+
throw unusable("ECDSA");
|
|
203
|
+
const expected = getNamedCurve(alg);
|
|
204
|
+
const actual = key.algorithm.namedCurve;
|
|
205
|
+
if (actual !== expected)
|
|
206
|
+
throw unusable(expected, "algorithm.namedCurve");
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
default:
|
|
210
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
211
|
+
}
|
|
212
|
+
checkUsage(key, usage);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
216
|
+
function message(msg, actual, ...types) {
|
|
217
|
+
var _a2;
|
|
218
|
+
types = types.filter(Boolean);
|
|
219
|
+
if (types.length > 2) {
|
|
220
|
+
const last = types.pop();
|
|
221
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
222
|
+
} else if (types.length === 2) {
|
|
223
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
224
|
+
} else {
|
|
225
|
+
msg += `of type ${types[0]}.`;
|
|
226
|
+
}
|
|
227
|
+
if (actual == null) {
|
|
228
|
+
msg += ` Received ${actual}`;
|
|
229
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
230
|
+
msg += ` Received function ${actual.name}`;
|
|
231
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
232
|
+
if ((_a2 = actual.constructor) == null ? void 0 : _a2.name) {
|
|
233
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return msg;
|
|
237
|
+
}
|
|
238
|
+
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
239
|
+
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
240
|
+
|
|
241
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/util/errors.js
|
|
242
|
+
var JOSEError = class extends Error {
|
|
243
|
+
constructor(message2, options) {
|
|
244
|
+
var _a2;
|
|
245
|
+
super(message2, options);
|
|
246
|
+
__publicField(this, "code", "ERR_JOSE_GENERIC");
|
|
247
|
+
this.name = this.constructor.name;
|
|
248
|
+
(_a2 = Error.captureStackTrace) == null ? void 0 : _a2.call(Error, this, this.constructor);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
__publicField(JOSEError, "code", "ERR_JOSE_GENERIC");
|
|
252
|
+
var JOSENotSupported = class extends JOSEError {
|
|
253
|
+
constructor() {
|
|
254
|
+
super(...arguments);
|
|
255
|
+
__publicField(this, "code", "ERR_JOSE_NOT_SUPPORTED");
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
__publicField(JOSENotSupported, "code", "ERR_JOSE_NOT_SUPPORTED");
|
|
259
|
+
var JWSInvalid = class extends JOSEError {
|
|
260
|
+
constructor() {
|
|
261
|
+
super(...arguments);
|
|
262
|
+
__publicField(this, "code", "ERR_JWS_INVALID");
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
__publicField(JWSInvalid, "code", "ERR_JWS_INVALID");
|
|
266
|
+
var JWTInvalid = class extends JOSEError {
|
|
267
|
+
constructor() {
|
|
268
|
+
super(...arguments);
|
|
269
|
+
__publicField(this, "code", "ERR_JWT_INVALID");
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
__publicField(JWTInvalid, "code", "ERR_JWT_INVALID");
|
|
273
|
+
var _a, _b;
|
|
274
|
+
var JWKSMultipleMatchingKeys = class extends (_b = JOSEError, _a = Symbol.asyncIterator, _b) {
|
|
275
|
+
constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
276
|
+
super(message2, options);
|
|
277
|
+
__publicField(this, _a);
|
|
278
|
+
__publicField(this, "code", "ERR_JWKS_MULTIPLE_MATCHING_KEYS");
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
__publicField(JWKSMultipleMatchingKeys, "code", "ERR_JWKS_MULTIPLE_MATCHING_KEYS");
|
|
282
|
+
|
|
283
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
284
|
+
var isCryptoKey = (key) => {
|
|
285
|
+
if ((key == null ? void 0 : key[Symbol.toStringTag]) === "CryptoKey")
|
|
286
|
+
return true;
|
|
287
|
+
try {
|
|
288
|
+
return key instanceof CryptoKey;
|
|
289
|
+
} catch (e) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
var isKeyObject = (key) => (key == null ? void 0 : key[Symbol.toStringTag]) === "KeyObject";
|
|
294
|
+
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
295
|
+
|
|
296
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/helpers.js
|
|
297
|
+
function assertNotSet(value, name) {
|
|
298
|
+
if (value) {
|
|
299
|
+
throw new TypeError(`${name} can only be called once`);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/type_checks.js
|
|
304
|
+
var isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
305
|
+
function isObject(input) {
|
|
306
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
let proto = input;
|
|
313
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
314
|
+
proto = Object.getPrototypeOf(proto);
|
|
315
|
+
}
|
|
316
|
+
return Object.getPrototypeOf(input) === proto;
|
|
317
|
+
}
|
|
318
|
+
function isDisjoint(...headers) {
|
|
319
|
+
const sources = headers.filter(Boolean);
|
|
320
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
let acc;
|
|
324
|
+
for (const header of sources) {
|
|
325
|
+
const parameters = Object.keys(header);
|
|
326
|
+
if (!acc || acc.size === 0) {
|
|
327
|
+
acc = new Set(parameters);
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
for (const parameter of parameters) {
|
|
331
|
+
if (acc.has(parameter)) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
acc.add(parameter);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
var isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
340
|
+
var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
341
|
+
var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
342
|
+
var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
343
|
+
|
|
344
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/signing.js
|
|
345
|
+
function checkKeyLength(alg, key) {
|
|
346
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
347
|
+
const { modulusLength } = key.algorithm;
|
|
348
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
349
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
354
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
355
|
+
switch (alg) {
|
|
356
|
+
case "HS256":
|
|
357
|
+
case "HS384":
|
|
358
|
+
case "HS512":
|
|
359
|
+
return { hash, name: "HMAC" };
|
|
360
|
+
case "PS256":
|
|
361
|
+
case "PS384":
|
|
362
|
+
case "PS512":
|
|
363
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
364
|
+
case "RS256":
|
|
365
|
+
case "RS384":
|
|
366
|
+
case "RS512":
|
|
367
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
368
|
+
case "ES256":
|
|
369
|
+
case "ES384":
|
|
370
|
+
case "ES512":
|
|
371
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
372
|
+
case "Ed25519":
|
|
373
|
+
case "EdDSA":
|
|
374
|
+
return { name: "Ed25519" };
|
|
375
|
+
case "ML-DSA-44":
|
|
376
|
+
case "ML-DSA-65":
|
|
377
|
+
case "ML-DSA-87":
|
|
378
|
+
return { name: alg };
|
|
379
|
+
default:
|
|
380
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async function getSigKey(alg, key, usage) {
|
|
384
|
+
if (key instanceof Uint8Array) {
|
|
385
|
+
if (!alg.startsWith("HS")) {
|
|
386
|
+
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
387
|
+
}
|
|
388
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
|
|
389
|
+
}
|
|
390
|
+
checkSigCryptoKey(key, alg, usage);
|
|
391
|
+
return key;
|
|
392
|
+
}
|
|
393
|
+
async function sign(alg, key, data) {
|
|
394
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
395
|
+
checkKeyLength(alg, cryptoKey);
|
|
396
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
397
|
+
return new Uint8Array(signature);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
401
|
+
var unsupportedAlg = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
|
|
402
|
+
function subtleMapping(jwk) {
|
|
403
|
+
let algorithm;
|
|
404
|
+
let keyUsages;
|
|
405
|
+
switch (jwk.kty) {
|
|
406
|
+
case "AKP": {
|
|
407
|
+
switch (jwk.alg) {
|
|
408
|
+
case "ML-DSA-44":
|
|
409
|
+
case "ML-DSA-65":
|
|
410
|
+
case "ML-DSA-87":
|
|
411
|
+
algorithm = { name: jwk.alg };
|
|
412
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
413
|
+
break;
|
|
414
|
+
default:
|
|
415
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
416
|
+
}
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case "RSA": {
|
|
420
|
+
switch (jwk.alg) {
|
|
421
|
+
case "PS256":
|
|
422
|
+
case "PS384":
|
|
423
|
+
case "PS512":
|
|
424
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
425
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
426
|
+
break;
|
|
427
|
+
case "RS256":
|
|
428
|
+
case "RS384":
|
|
429
|
+
case "RS512":
|
|
430
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
431
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
432
|
+
break;
|
|
433
|
+
case "RSA-OAEP":
|
|
434
|
+
case "RSA-OAEP-256":
|
|
435
|
+
case "RSA-OAEP-384":
|
|
436
|
+
case "RSA-OAEP-512":
|
|
437
|
+
algorithm = {
|
|
438
|
+
name: "RSA-OAEP",
|
|
439
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
440
|
+
};
|
|
441
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
442
|
+
break;
|
|
443
|
+
default:
|
|
444
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
445
|
+
}
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
case "EC": {
|
|
449
|
+
switch (jwk.alg) {
|
|
450
|
+
case "ES256":
|
|
451
|
+
case "ES384":
|
|
452
|
+
case "ES512":
|
|
453
|
+
algorithm = {
|
|
454
|
+
name: "ECDSA",
|
|
455
|
+
namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[jwk.alg]
|
|
456
|
+
};
|
|
457
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
458
|
+
break;
|
|
459
|
+
case "ECDH-ES":
|
|
460
|
+
case "ECDH-ES+A128KW":
|
|
461
|
+
case "ECDH-ES+A192KW":
|
|
462
|
+
case "ECDH-ES+A256KW":
|
|
463
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
464
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
465
|
+
break;
|
|
466
|
+
default:
|
|
467
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
468
|
+
}
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case "OKP": {
|
|
472
|
+
switch (jwk.alg) {
|
|
473
|
+
case "Ed25519":
|
|
474
|
+
case "EdDSA":
|
|
475
|
+
algorithm = { name: "Ed25519" };
|
|
476
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
477
|
+
break;
|
|
478
|
+
case "ECDH-ES":
|
|
479
|
+
case "ECDH-ES+A128KW":
|
|
480
|
+
case "ECDH-ES+A192KW":
|
|
481
|
+
case "ECDH-ES+A256KW":
|
|
482
|
+
algorithm = { name: jwk.crv };
|
|
483
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
484
|
+
break;
|
|
485
|
+
default:
|
|
486
|
+
throw new JOSENotSupported(unsupportedAlg);
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
default:
|
|
491
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
492
|
+
}
|
|
493
|
+
return { algorithm, keyUsages };
|
|
494
|
+
}
|
|
495
|
+
async function jwkToKey(jwk) {
|
|
496
|
+
var _a2, _b2;
|
|
497
|
+
if (!jwk.alg) {
|
|
498
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
499
|
+
}
|
|
500
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
501
|
+
const keyData = __spreadValues({}, jwk);
|
|
502
|
+
if (keyData.kty !== "AKP") {
|
|
503
|
+
delete keyData.alg;
|
|
504
|
+
}
|
|
505
|
+
delete keyData.use;
|
|
506
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, (_a2 = jwk.ext) != null ? _a2 : jwk.d || jwk.priv ? false : true, (_b2 = jwk.key_ops) != null ? _b2 : keyUsages);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
510
|
+
var unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
511
|
+
var cache;
|
|
512
|
+
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
513
|
+
cache || (cache = /* @__PURE__ */ new WeakMap());
|
|
514
|
+
let cached = cache.get(key);
|
|
515
|
+
if (cached == null ? void 0 : cached[alg]) {
|
|
516
|
+
return cached[alg];
|
|
517
|
+
}
|
|
518
|
+
const cryptoKey = await jwkToKey(__spreadProps(__spreadValues({}, jwk), { alg }));
|
|
519
|
+
if (freeze)
|
|
520
|
+
Object.freeze(key);
|
|
521
|
+
if (!cached) {
|
|
522
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
523
|
+
} else {
|
|
524
|
+
cached[alg] = cryptoKey;
|
|
525
|
+
}
|
|
526
|
+
return cryptoKey;
|
|
527
|
+
};
|
|
528
|
+
var handleKeyObject = (keyObject, alg) => {
|
|
529
|
+
var _a2;
|
|
530
|
+
cache || (cache = /* @__PURE__ */ new WeakMap());
|
|
531
|
+
let cached = cache.get(keyObject);
|
|
532
|
+
if (cached == null ? void 0 : cached[alg]) {
|
|
533
|
+
return cached[alg];
|
|
534
|
+
}
|
|
535
|
+
const isPublic = keyObject.type === "public";
|
|
536
|
+
const extractable = isPublic ? true : false;
|
|
537
|
+
let cryptoKey;
|
|
538
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
539
|
+
switch (alg) {
|
|
540
|
+
case "ECDH-ES":
|
|
541
|
+
case "ECDH-ES+A128KW":
|
|
542
|
+
case "ECDH-ES+A192KW":
|
|
543
|
+
case "ECDH-ES+A256KW":
|
|
544
|
+
break;
|
|
545
|
+
default:
|
|
546
|
+
throw new TypeError(unusableForAlg);
|
|
547
|
+
}
|
|
548
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
549
|
+
}
|
|
550
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
551
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
552
|
+
throw new TypeError(unusableForAlg);
|
|
553
|
+
}
|
|
554
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
555
|
+
isPublic ? "verify" : "sign"
|
|
556
|
+
]);
|
|
557
|
+
}
|
|
558
|
+
switch (keyObject.asymmetricKeyType) {
|
|
559
|
+
case "ml-dsa-44":
|
|
560
|
+
case "ml-dsa-65":
|
|
561
|
+
case "ml-dsa-87": {
|
|
562
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) {
|
|
563
|
+
throw new TypeError(unusableForAlg);
|
|
564
|
+
}
|
|
565
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
566
|
+
isPublic ? "verify" : "sign"
|
|
567
|
+
]);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
571
|
+
let hash;
|
|
572
|
+
switch (alg) {
|
|
573
|
+
case "RSA-OAEP":
|
|
574
|
+
hash = "SHA-1";
|
|
575
|
+
break;
|
|
576
|
+
case "RS256":
|
|
577
|
+
case "PS256":
|
|
578
|
+
case "RSA-OAEP-256":
|
|
579
|
+
hash = "SHA-256";
|
|
580
|
+
break;
|
|
581
|
+
case "RS384":
|
|
582
|
+
case "PS384":
|
|
583
|
+
case "RSA-OAEP-384":
|
|
584
|
+
hash = "SHA-384";
|
|
585
|
+
break;
|
|
586
|
+
case "RS512":
|
|
587
|
+
case "PS512":
|
|
588
|
+
case "RSA-OAEP-512":
|
|
589
|
+
hash = "SHA-512";
|
|
590
|
+
break;
|
|
591
|
+
default:
|
|
592
|
+
throw new TypeError(unusableForAlg);
|
|
593
|
+
}
|
|
594
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
595
|
+
return keyObject.toCryptoKey({
|
|
596
|
+
name: "RSA-OAEP",
|
|
597
|
+
hash
|
|
598
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
599
|
+
}
|
|
600
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
601
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
602
|
+
hash
|
|
603
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
604
|
+
}
|
|
605
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
606
|
+
const nist = /* @__PURE__ */ new Map([
|
|
607
|
+
["prime256v1", "P-256"],
|
|
608
|
+
["secp384r1", "P-384"],
|
|
609
|
+
["secp521r1", "P-521"]
|
|
610
|
+
]);
|
|
611
|
+
const namedCurve = nist.get((_a2 = keyObject.asymmetricKeyDetails) == null ? void 0 : _a2.namedCurve);
|
|
612
|
+
if (!namedCurve) {
|
|
613
|
+
throw new TypeError(unusableForAlg);
|
|
614
|
+
}
|
|
615
|
+
const expectedCurve = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
616
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) {
|
|
617
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
618
|
+
name: "ECDSA",
|
|
619
|
+
namedCurve
|
|
620
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
621
|
+
}
|
|
622
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
623
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
624
|
+
name: "ECDH",
|
|
625
|
+
namedCurve
|
|
626
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (!cryptoKey) {
|
|
630
|
+
throw new TypeError(unusableForAlg);
|
|
631
|
+
}
|
|
632
|
+
if (!cached) {
|
|
633
|
+
cache.set(keyObject, { [alg]: cryptoKey });
|
|
634
|
+
} else {
|
|
635
|
+
cached[alg] = cryptoKey;
|
|
636
|
+
}
|
|
637
|
+
return cryptoKey;
|
|
638
|
+
};
|
|
639
|
+
async function normalizeKey(key, alg) {
|
|
640
|
+
if (key instanceof Uint8Array) {
|
|
641
|
+
return key;
|
|
642
|
+
}
|
|
643
|
+
if (isCryptoKey(key)) {
|
|
644
|
+
return key;
|
|
645
|
+
}
|
|
646
|
+
if (isKeyObject(key)) {
|
|
647
|
+
if (key.type === "secret") {
|
|
648
|
+
return key.export();
|
|
649
|
+
}
|
|
650
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
651
|
+
try {
|
|
652
|
+
return handleKeyObject(key, alg);
|
|
653
|
+
} catch (err) {
|
|
654
|
+
if (err instanceof TypeError) {
|
|
655
|
+
throw err;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
let jwk = key.export({ format: "jwk" });
|
|
660
|
+
return handleJWK(key, jwk, alg);
|
|
661
|
+
}
|
|
662
|
+
if (isJWK(key)) {
|
|
663
|
+
if (key.k) {
|
|
664
|
+
return decode(key.k);
|
|
665
|
+
}
|
|
666
|
+
return handleJWK(key, key, alg, true);
|
|
667
|
+
}
|
|
668
|
+
throw new Error("unreachable");
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/asn1.js
|
|
672
|
+
var bytesEqual = (a, b) => {
|
|
673
|
+
if (a.byteLength !== b.length)
|
|
674
|
+
return false;
|
|
675
|
+
for (let i = 0; i < a.byteLength; i++) {
|
|
676
|
+
if (a[i] !== b[i])
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
return true;
|
|
680
|
+
};
|
|
681
|
+
var createASN1State = (data) => ({ data, pos: 0 });
|
|
682
|
+
var parseLength = (state) => {
|
|
683
|
+
const first = state.data[state.pos++];
|
|
684
|
+
if (first & 128) {
|
|
685
|
+
const lengthOfLen = first & 127;
|
|
686
|
+
let length = 0;
|
|
687
|
+
for (let i = 0; i < lengthOfLen; i++) {
|
|
688
|
+
length = length << 8 | state.data[state.pos++];
|
|
689
|
+
}
|
|
690
|
+
return length;
|
|
691
|
+
}
|
|
692
|
+
return first;
|
|
693
|
+
};
|
|
694
|
+
var expectTag = (state, expectedTag, errorMessage) => {
|
|
695
|
+
if (state.data[state.pos++] !== expectedTag) {
|
|
696
|
+
throw new Error(errorMessage);
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
var getSubarray = (state, length) => {
|
|
700
|
+
const result = state.data.subarray(state.pos, state.pos + length);
|
|
701
|
+
state.pos += length;
|
|
702
|
+
return result;
|
|
703
|
+
};
|
|
704
|
+
var parseAlgorithmOID = (state) => {
|
|
705
|
+
expectTag(state, 6, "Expected algorithm OID");
|
|
706
|
+
const oidLen = parseLength(state);
|
|
707
|
+
return getSubarray(state, oidLen);
|
|
708
|
+
};
|
|
709
|
+
function parsePKCS8Header(state) {
|
|
710
|
+
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
711
|
+
parseLength(state);
|
|
712
|
+
expectTag(state, 2, "Expected version field");
|
|
713
|
+
const verLen = parseLength(state);
|
|
714
|
+
state.pos += verLen;
|
|
715
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
716
|
+
const algIdLen = parseLength(state);
|
|
717
|
+
const algIdStart = state.pos;
|
|
718
|
+
return { algIdStart, algIdLength: algIdLen };
|
|
719
|
+
}
|
|
720
|
+
var parseECAlgorithmIdentifier = (state) => {
|
|
721
|
+
const algOid = parseAlgorithmOID(state);
|
|
722
|
+
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
723
|
+
return "X25519";
|
|
724
|
+
}
|
|
725
|
+
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
726
|
+
throw new Error("Unsupported key algorithm");
|
|
727
|
+
}
|
|
728
|
+
expectTag(state, 6, "Expected curve OID");
|
|
729
|
+
const curveOidLen = parseLength(state);
|
|
730
|
+
const curveOid = getSubarray(state, curveOidLen);
|
|
731
|
+
for (const { name, oid } of [
|
|
732
|
+
{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] },
|
|
733
|
+
{ name: "P-384", oid: [43, 129, 4, 0, 34] },
|
|
734
|
+
{ name: "P-521", oid: [43, 129, 4, 0, 35] }
|
|
735
|
+
]) {
|
|
736
|
+
if (bytesEqual(curveOid, oid)) {
|
|
737
|
+
return name;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
throw new Error("Unsupported named curve");
|
|
741
|
+
};
|
|
742
|
+
var genericImport = async (keyFormat, keyData, alg, options) => {
|
|
743
|
+
var _a2;
|
|
744
|
+
let algorithm;
|
|
745
|
+
let keyUsages;
|
|
746
|
+
const isPublic = keyFormat === "spki";
|
|
747
|
+
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
748
|
+
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
749
|
+
switch (alg) {
|
|
750
|
+
case "PS256":
|
|
751
|
+
case "PS384":
|
|
752
|
+
case "PS512":
|
|
753
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
|
|
754
|
+
keyUsages = getSigUsages();
|
|
755
|
+
break;
|
|
756
|
+
case "RS256":
|
|
757
|
+
case "RS384":
|
|
758
|
+
case "RS512":
|
|
759
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
|
|
760
|
+
keyUsages = getSigUsages();
|
|
761
|
+
break;
|
|
762
|
+
case "RSA-OAEP":
|
|
763
|
+
case "RSA-OAEP-256":
|
|
764
|
+
case "RSA-OAEP-384":
|
|
765
|
+
case "RSA-OAEP-512":
|
|
766
|
+
algorithm = {
|
|
767
|
+
name: "RSA-OAEP",
|
|
768
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
769
|
+
};
|
|
770
|
+
keyUsages = getEncUsages();
|
|
771
|
+
break;
|
|
772
|
+
case "ES256":
|
|
773
|
+
case "ES384":
|
|
774
|
+
case "ES512": {
|
|
775
|
+
const curveMap = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
|
|
776
|
+
algorithm = { name: "ECDSA", namedCurve: curveMap[alg] };
|
|
777
|
+
keyUsages = getSigUsages();
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
case "ECDH-ES":
|
|
781
|
+
case "ECDH-ES+A128KW":
|
|
782
|
+
case "ECDH-ES+A192KW":
|
|
783
|
+
case "ECDH-ES+A256KW": {
|
|
784
|
+
try {
|
|
785
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
786
|
+
algorithm = namedCurve === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve };
|
|
787
|
+
} catch (cause) {
|
|
788
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
789
|
+
}
|
|
790
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
791
|
+
break;
|
|
792
|
+
}
|
|
793
|
+
case "Ed25519":
|
|
794
|
+
case "EdDSA":
|
|
795
|
+
algorithm = { name: "Ed25519" };
|
|
796
|
+
keyUsages = getSigUsages();
|
|
797
|
+
break;
|
|
798
|
+
case "ML-DSA-44":
|
|
799
|
+
case "ML-DSA-65":
|
|
800
|
+
case "ML-DSA-87":
|
|
801
|
+
algorithm = { name: alg };
|
|
802
|
+
keyUsages = getSigUsages();
|
|
803
|
+
break;
|
|
804
|
+
default:
|
|
805
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
|
|
806
|
+
}
|
|
807
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, (_a2 = options == null ? void 0 : options.extractable) != null ? _a2 : isPublic ? true : false, keyUsages);
|
|
808
|
+
};
|
|
809
|
+
var processPEMData = (pem, pattern) => {
|
|
810
|
+
return decodeBase64(pem.replace(pattern, ""));
|
|
811
|
+
};
|
|
812
|
+
var fromPKCS8 = (pem, alg, options) => {
|
|
813
|
+
var _a2;
|
|
814
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
815
|
+
let opts = options;
|
|
816
|
+
if ((_a2 = alg == null ? void 0 : alg.startsWith) == null ? void 0 : _a2.call(alg, "ECDH-ES")) {
|
|
817
|
+
opts || (opts = {});
|
|
818
|
+
opts.getNamedCurve = (keyData2) => {
|
|
819
|
+
const state = createASN1State(keyData2);
|
|
820
|
+
parsePKCS8Header(state);
|
|
821
|
+
return parseECAlgorithmIdentifier(state);
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/key/import.js
|
|
828
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
829
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
830
|
+
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
831
|
+
}
|
|
832
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
836
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
837
|
+
if (joseHeader.crit !== void 0 && (protectedHeader == null ? void 0 : protectedHeader.crit) === void 0) {
|
|
838
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
839
|
+
}
|
|
840
|
+
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
841
|
+
return /* @__PURE__ */ new Set();
|
|
842
|
+
}
|
|
843
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
844
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
845
|
+
}
|
|
846
|
+
let recognized;
|
|
847
|
+
if (recognizedOption !== void 0) {
|
|
848
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
849
|
+
} else {
|
|
850
|
+
recognized = recognizedDefault;
|
|
851
|
+
}
|
|
852
|
+
for (const parameter of protectedHeader.crit) {
|
|
853
|
+
if (!recognized.has(parameter)) {
|
|
854
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
855
|
+
}
|
|
856
|
+
if (joseHeader[parameter] === void 0) {
|
|
857
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
858
|
+
}
|
|
859
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
860
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
return new Set(protectedHeader.crit);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
867
|
+
var tag = (key) => key == null ? void 0 : key[Symbol.toStringTag];
|
|
868
|
+
var jwkMatchesOp = (alg, key, usage) => {
|
|
869
|
+
var _a2, _b2;
|
|
870
|
+
if (key.use !== void 0) {
|
|
871
|
+
let expected;
|
|
872
|
+
switch (usage) {
|
|
873
|
+
case "sign":
|
|
874
|
+
case "verify":
|
|
875
|
+
expected = "sig";
|
|
876
|
+
break;
|
|
877
|
+
case "encrypt":
|
|
878
|
+
case "decrypt":
|
|
879
|
+
expected = "enc";
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
if (key.use !== expected) {
|
|
883
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (key.alg !== void 0 && key.alg !== alg) {
|
|
887
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
888
|
+
}
|
|
889
|
+
if (Array.isArray(key.key_ops)) {
|
|
890
|
+
let expectedKeyOp;
|
|
891
|
+
switch (true) {
|
|
892
|
+
case (usage === "sign" || usage === "verify"):
|
|
893
|
+
case alg === "dir":
|
|
894
|
+
case alg.includes("CBC-HS"):
|
|
895
|
+
expectedKeyOp = usage;
|
|
896
|
+
break;
|
|
897
|
+
case alg.startsWith("PBES2"):
|
|
898
|
+
expectedKeyOp = "deriveBits";
|
|
899
|
+
break;
|
|
900
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
901
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
902
|
+
expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
903
|
+
} else {
|
|
904
|
+
expectedKeyOp = usage;
|
|
905
|
+
}
|
|
906
|
+
break;
|
|
907
|
+
case (usage === "encrypt" && alg.startsWith("RSA")):
|
|
908
|
+
expectedKeyOp = "wrapKey";
|
|
909
|
+
break;
|
|
910
|
+
case usage === "decrypt":
|
|
911
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
912
|
+
break;
|
|
913
|
+
}
|
|
914
|
+
if (expectedKeyOp && ((_b2 = (_a2 = key.key_ops) == null ? void 0 : _a2.includes) == null ? void 0 : _b2.call(_a2, expectedKeyOp)) === false) {
|
|
915
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
return true;
|
|
919
|
+
};
|
|
920
|
+
var symmetricTypeCheck = (alg, key, usage) => {
|
|
921
|
+
if (key instanceof Uint8Array)
|
|
922
|
+
return;
|
|
923
|
+
if (isJWK(key)) {
|
|
924
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
925
|
+
return;
|
|
926
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
927
|
+
}
|
|
928
|
+
if (!isKeyLike(key)) {
|
|
929
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
930
|
+
}
|
|
931
|
+
if (key.type !== "secret") {
|
|
932
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
var asymmetricTypeCheck = (alg, key, usage) => {
|
|
936
|
+
if (isJWK(key)) {
|
|
937
|
+
switch (usage) {
|
|
938
|
+
case "decrypt":
|
|
939
|
+
case "sign":
|
|
940
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
941
|
+
return;
|
|
942
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
943
|
+
case "encrypt":
|
|
944
|
+
case "verify":
|
|
945
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
|
|
946
|
+
return;
|
|
947
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
if (!isKeyLike(key)) {
|
|
951
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
952
|
+
}
|
|
953
|
+
if (key.type === "secret") {
|
|
954
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
955
|
+
}
|
|
956
|
+
if (key.type === "public") {
|
|
957
|
+
switch (usage) {
|
|
958
|
+
case "sign":
|
|
959
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
960
|
+
case "decrypt":
|
|
961
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (key.type === "private") {
|
|
965
|
+
switch (usage) {
|
|
966
|
+
case "verify":
|
|
967
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
968
|
+
case "encrypt":
|
|
969
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
function checkKeyType(alg, key, usage) {
|
|
974
|
+
switch (alg.substring(0, 2)) {
|
|
975
|
+
case "A1":
|
|
976
|
+
case "A2":
|
|
977
|
+
case "di":
|
|
978
|
+
case "HS":
|
|
979
|
+
case "PB":
|
|
980
|
+
symmetricTypeCheck(alg, key, usage);
|
|
981
|
+
break;
|
|
982
|
+
default:
|
|
983
|
+
asymmetricTypeCheck(alg, key, usage);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
988
|
+
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
989
|
+
var minute = 60;
|
|
990
|
+
var hour = minute * 60;
|
|
991
|
+
var day = hour * 24;
|
|
992
|
+
var week = day * 7;
|
|
993
|
+
var year = day * 365.25;
|
|
994
|
+
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
995
|
+
function secs(str) {
|
|
996
|
+
const matched = REGEX.exec(str);
|
|
997
|
+
if (!matched || matched[4] && matched[1]) {
|
|
998
|
+
throw new TypeError("Invalid time period format");
|
|
999
|
+
}
|
|
1000
|
+
const value = parseFloat(matched[2]);
|
|
1001
|
+
const unit = matched[3].toLowerCase();
|
|
1002
|
+
let numericDate;
|
|
1003
|
+
switch (unit) {
|
|
1004
|
+
case "sec":
|
|
1005
|
+
case "secs":
|
|
1006
|
+
case "second":
|
|
1007
|
+
case "seconds":
|
|
1008
|
+
case "s":
|
|
1009
|
+
numericDate = Math.round(value);
|
|
1010
|
+
break;
|
|
1011
|
+
case "minute":
|
|
1012
|
+
case "minutes":
|
|
1013
|
+
case "min":
|
|
1014
|
+
case "mins":
|
|
1015
|
+
case "m":
|
|
1016
|
+
numericDate = Math.round(value * minute);
|
|
1017
|
+
break;
|
|
1018
|
+
case "hour":
|
|
1019
|
+
case "hours":
|
|
1020
|
+
case "hr":
|
|
1021
|
+
case "hrs":
|
|
1022
|
+
case "h":
|
|
1023
|
+
numericDate = Math.round(value * hour);
|
|
1024
|
+
break;
|
|
1025
|
+
case "day":
|
|
1026
|
+
case "days":
|
|
1027
|
+
case "d":
|
|
1028
|
+
numericDate = Math.round(value * day);
|
|
1029
|
+
break;
|
|
1030
|
+
case "week":
|
|
1031
|
+
case "weeks":
|
|
1032
|
+
case "w":
|
|
1033
|
+
numericDate = Math.round(value * week);
|
|
1034
|
+
break;
|
|
1035
|
+
default:
|
|
1036
|
+
numericDate = Math.round(value * year);
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
1040
|
+
return -numericDate;
|
|
1041
|
+
}
|
|
1042
|
+
return numericDate;
|
|
1043
|
+
}
|
|
1044
|
+
function validateInput(label, input) {
|
|
1045
|
+
if (!Number.isFinite(input)) {
|
|
1046
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
1047
|
+
}
|
|
1048
|
+
return input;
|
|
1049
|
+
}
|
|
1050
|
+
var _payload;
|
|
1051
|
+
var JWTClaimsBuilder = class {
|
|
1052
|
+
constructor(payload) {
|
|
1053
|
+
__privateAdd(this, _payload);
|
|
1054
|
+
if (!isObject(payload)) {
|
|
1055
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
1056
|
+
}
|
|
1057
|
+
__privateSet(this, _payload, structuredClone(payload));
|
|
1058
|
+
}
|
|
1059
|
+
data() {
|
|
1060
|
+
return encoder.encode(JSON.stringify(__privateGet(this, _payload)));
|
|
1061
|
+
}
|
|
1062
|
+
get iss() {
|
|
1063
|
+
return __privateGet(this, _payload).iss;
|
|
1064
|
+
}
|
|
1065
|
+
set iss(value) {
|
|
1066
|
+
__privateGet(this, _payload).iss = value;
|
|
1067
|
+
}
|
|
1068
|
+
get sub() {
|
|
1069
|
+
return __privateGet(this, _payload).sub;
|
|
1070
|
+
}
|
|
1071
|
+
set sub(value) {
|
|
1072
|
+
__privateGet(this, _payload).sub = value;
|
|
1073
|
+
}
|
|
1074
|
+
get aud() {
|
|
1075
|
+
return __privateGet(this, _payload).aud;
|
|
1076
|
+
}
|
|
1077
|
+
set aud(value) {
|
|
1078
|
+
__privateGet(this, _payload).aud = value;
|
|
1079
|
+
}
|
|
1080
|
+
set jti(value) {
|
|
1081
|
+
__privateGet(this, _payload).jti = value;
|
|
1082
|
+
}
|
|
1083
|
+
set nbf(value) {
|
|
1084
|
+
if (typeof value === "number") {
|
|
1085
|
+
__privateGet(this, _payload).nbf = validateInput("setNotBefore", value);
|
|
1086
|
+
} else if (value instanceof Date) {
|
|
1087
|
+
__privateGet(this, _payload).nbf = validateInput("setNotBefore", epoch(value));
|
|
1088
|
+
} else {
|
|
1089
|
+
__privateGet(this, _payload).nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
set exp(value) {
|
|
1093
|
+
if (typeof value === "number") {
|
|
1094
|
+
__privateGet(this, _payload).exp = validateInput("setExpirationTime", value);
|
|
1095
|
+
} else if (value instanceof Date) {
|
|
1096
|
+
__privateGet(this, _payload).exp = validateInput("setExpirationTime", epoch(value));
|
|
1097
|
+
} else {
|
|
1098
|
+
__privateGet(this, _payload).exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
set iat(value) {
|
|
1102
|
+
if (value === void 0) {
|
|
1103
|
+
__privateGet(this, _payload).iat = epoch(/* @__PURE__ */ new Date());
|
|
1104
|
+
} else if (value instanceof Date) {
|
|
1105
|
+
__privateGet(this, _payload).iat = validateInput("setIssuedAt", epoch(value));
|
|
1106
|
+
} else if (typeof value === "string") {
|
|
1107
|
+
__privateGet(this, _payload).iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
1108
|
+
} else {
|
|
1109
|
+
__privateGet(this, _payload).iat = validateInput("setIssuedAt", value);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
_payload = new WeakMap();
|
|
1114
|
+
|
|
1115
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
1116
|
+
var _payload2, _protectedHeader, _unprotectedHeader;
|
|
1117
|
+
var FlattenedSign = class {
|
|
1118
|
+
constructor(payload) {
|
|
1119
|
+
__privateAdd(this, _payload2);
|
|
1120
|
+
__privateAdd(this, _protectedHeader);
|
|
1121
|
+
__privateAdd(this, _unprotectedHeader);
|
|
1122
|
+
if (!(payload instanceof Uint8Array)) {
|
|
1123
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
1124
|
+
}
|
|
1125
|
+
__privateSet(this, _payload2, payload);
|
|
1126
|
+
}
|
|
1127
|
+
setProtectedHeader(protectedHeader) {
|
|
1128
|
+
assertNotSet(__privateGet(this, _protectedHeader), "setProtectedHeader");
|
|
1129
|
+
__privateSet(this, _protectedHeader, protectedHeader);
|
|
1130
|
+
return this;
|
|
1131
|
+
}
|
|
1132
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
1133
|
+
assertNotSet(__privateGet(this, _unprotectedHeader), "setUnprotectedHeader");
|
|
1134
|
+
__privateSet(this, _unprotectedHeader, unprotectedHeader);
|
|
1135
|
+
return this;
|
|
1136
|
+
}
|
|
1137
|
+
async sign(key, options) {
|
|
1138
|
+
if (!__privateGet(this, _protectedHeader) && !__privateGet(this, _unprotectedHeader)) {
|
|
1139
|
+
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
1140
|
+
}
|
|
1141
|
+
if (!isDisjoint(__privateGet(this, _protectedHeader), __privateGet(this, _unprotectedHeader))) {
|
|
1142
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1143
|
+
}
|
|
1144
|
+
const joseHeader = __spreadValues(__spreadValues({}, __privateGet(this, _protectedHeader)), __privateGet(this, _unprotectedHeader));
|
|
1145
|
+
const extensions = validateCrit(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options == null ? void 0 : options.crit, __privateGet(this, _protectedHeader), joseHeader);
|
|
1146
|
+
let b64 = true;
|
|
1147
|
+
if (extensions.has("b64")) {
|
|
1148
|
+
b64 = __privateGet(this, _protectedHeader).b64;
|
|
1149
|
+
if (typeof b64 !== "boolean") {
|
|
1150
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const { alg } = joseHeader;
|
|
1154
|
+
if (typeof alg !== "string" || !alg) {
|
|
1155
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
1156
|
+
}
|
|
1157
|
+
checkKeyType(alg, key, "sign");
|
|
1158
|
+
let payloadS;
|
|
1159
|
+
let payloadB;
|
|
1160
|
+
if (b64) {
|
|
1161
|
+
payloadS = encode2(__privateGet(this, _payload2));
|
|
1162
|
+
payloadB = encode(payloadS);
|
|
1163
|
+
} else {
|
|
1164
|
+
payloadB = __privateGet(this, _payload2);
|
|
1165
|
+
payloadS = "";
|
|
1166
|
+
}
|
|
1167
|
+
let protectedHeaderString;
|
|
1168
|
+
let protectedHeaderBytes;
|
|
1169
|
+
if (__privateGet(this, _protectedHeader)) {
|
|
1170
|
+
protectedHeaderString = encode2(JSON.stringify(__privateGet(this, _protectedHeader)));
|
|
1171
|
+
protectedHeaderBytes = encode(protectedHeaderString);
|
|
1172
|
+
} else {
|
|
1173
|
+
protectedHeaderString = "";
|
|
1174
|
+
protectedHeaderBytes = new Uint8Array();
|
|
1175
|
+
}
|
|
1176
|
+
const data = concat(protectedHeaderBytes, encode("."), payloadB);
|
|
1177
|
+
const k = await normalizeKey(key, alg);
|
|
1178
|
+
const signature = await sign(alg, k, data);
|
|
1179
|
+
const jws = {
|
|
1180
|
+
signature: encode2(signature),
|
|
1181
|
+
payload: payloadS
|
|
1182
|
+
};
|
|
1183
|
+
if (__privateGet(this, _unprotectedHeader)) {
|
|
1184
|
+
jws.header = __privateGet(this, _unprotectedHeader);
|
|
1185
|
+
}
|
|
1186
|
+
if (__privateGet(this, _protectedHeader)) {
|
|
1187
|
+
jws.protected = protectedHeaderString;
|
|
1188
|
+
}
|
|
1189
|
+
return jws;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
_payload2 = new WeakMap();
|
|
1193
|
+
_protectedHeader = new WeakMap();
|
|
1194
|
+
_unprotectedHeader = new WeakMap();
|
|
1195
|
+
|
|
1196
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
1197
|
+
var _flattened;
|
|
1198
|
+
var CompactSign = class {
|
|
1199
|
+
constructor(payload) {
|
|
1200
|
+
__privateAdd(this, _flattened);
|
|
1201
|
+
__privateSet(this, _flattened, new FlattenedSign(payload));
|
|
1202
|
+
}
|
|
1203
|
+
setProtectedHeader(protectedHeader) {
|
|
1204
|
+
__privateGet(this, _flattened).setProtectedHeader(protectedHeader);
|
|
1205
|
+
return this;
|
|
1206
|
+
}
|
|
1207
|
+
async sign(key, options) {
|
|
1208
|
+
const jws = await __privateGet(this, _flattened).sign(key, options);
|
|
1209
|
+
if (jws.payload === void 0) {
|
|
1210
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
1211
|
+
}
|
|
1212
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
1213
|
+
}
|
|
1214
|
+
};
|
|
1215
|
+
_flattened = new WeakMap();
|
|
1216
|
+
|
|
1217
|
+
// node_modules/.pnpm/jose@6.2.1/node_modules/jose/dist/webapi/jwt/sign.js
|
|
1218
|
+
var _protectedHeader2, _jwt;
|
|
1219
|
+
var SignJWT = class {
|
|
1220
|
+
constructor(payload = {}) {
|
|
1221
|
+
__privateAdd(this, _protectedHeader2);
|
|
1222
|
+
__privateAdd(this, _jwt);
|
|
1223
|
+
__privateSet(this, _jwt, new JWTClaimsBuilder(payload));
|
|
1224
|
+
}
|
|
1225
|
+
setIssuer(issuer) {
|
|
1226
|
+
__privateGet(this, _jwt).iss = issuer;
|
|
1227
|
+
return this;
|
|
1228
|
+
}
|
|
1229
|
+
setSubject(subject) {
|
|
1230
|
+
__privateGet(this, _jwt).sub = subject;
|
|
1231
|
+
return this;
|
|
1232
|
+
}
|
|
1233
|
+
setAudience(audience) {
|
|
1234
|
+
__privateGet(this, _jwt).aud = audience;
|
|
1235
|
+
return this;
|
|
1236
|
+
}
|
|
1237
|
+
setJti(jwtId) {
|
|
1238
|
+
__privateGet(this, _jwt).jti = jwtId;
|
|
1239
|
+
return this;
|
|
1240
|
+
}
|
|
1241
|
+
setNotBefore(input) {
|
|
1242
|
+
__privateGet(this, _jwt).nbf = input;
|
|
1243
|
+
return this;
|
|
1244
|
+
}
|
|
1245
|
+
setExpirationTime(input) {
|
|
1246
|
+
__privateGet(this, _jwt).exp = input;
|
|
1247
|
+
return this;
|
|
1248
|
+
}
|
|
1249
|
+
setIssuedAt(input) {
|
|
1250
|
+
__privateGet(this, _jwt).iat = input;
|
|
1251
|
+
return this;
|
|
1252
|
+
}
|
|
1253
|
+
setProtectedHeader(protectedHeader) {
|
|
1254
|
+
__privateSet(this, _protectedHeader2, protectedHeader);
|
|
1255
|
+
return this;
|
|
1256
|
+
}
|
|
1257
|
+
async sign(key, options) {
|
|
1258
|
+
var _a2;
|
|
1259
|
+
const sig = new CompactSign(__privateGet(this, _jwt).data());
|
|
1260
|
+
sig.setProtectedHeader(__privateGet(this, _protectedHeader2));
|
|
1261
|
+
if (Array.isArray((_a2 = __privateGet(this, _protectedHeader2)) == null ? void 0 : _a2.crit) && __privateGet(this, _protectedHeader2).crit.includes("b64") && __privateGet(this, _protectedHeader2).b64 === false) {
|
|
1262
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
1263
|
+
}
|
|
1264
|
+
return sig.sign(key, options);
|
|
1265
|
+
}
|
|
1266
|
+
};
|
|
1267
|
+
_protectedHeader2 = new WeakMap();
|
|
1268
|
+
_jwt = new WeakMap();
|
|
1269
|
+
|
|
1270
|
+
// src/api/index.ts
|
|
1271
|
+
var GA_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
1272
|
+
var GA_API_BASE = "https://analyticsdata.googleapis.com/v1beta";
|
|
1273
|
+
var GA_SCOPE = "https://www.googleapis.com/auth/analytics.readonly";
|
|
1274
|
+
var cachedToken = null;
|
|
1275
|
+
async function getAccessToken() {
|
|
1276
|
+
if (cachedToken && Date.now() < cachedToken.expiresAt)
|
|
1277
|
+
return cachedToken.value;
|
|
1278
|
+
const clientEmail = process.env.GA_SERVICE_ACCOUNT_EMAIL;
|
|
1279
|
+
const privateKeyRaw = process.env.GA_PRIVATE_KEY;
|
|
1280
|
+
if (!clientEmail || !privateKeyRaw)
|
|
1281
|
+
throw new Error(
|
|
1282
|
+
"Missing GA_SERVICE_ACCOUNT_EMAIL or GA_PRIVATE_KEY env vars"
|
|
1283
|
+
);
|
|
1284
|
+
const privateKey = privateKeyRaw.replace(/\\n/g, "\n");
|
|
1285
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
1286
|
+
const key = await importPKCS8(privateKey, "RS256");
|
|
1287
|
+
const jwt = await new SignJWT({ scope: GA_SCOPE }).setProtectedHeader({ alg: "RS256" }).setIssuedAt(now).setExpirationTime(now + 3600).setIssuer(clientEmail).setAudience(GA_TOKEN_URL).sign(key);
|
|
1288
|
+
const tokenRes = await fetch(GA_TOKEN_URL, {
|
|
1289
|
+
method: "POST",
|
|
1290
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1291
|
+
body: new URLSearchParams({
|
|
1292
|
+
grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
|
|
1293
|
+
assertion: jwt
|
|
1294
|
+
})
|
|
1295
|
+
});
|
|
1296
|
+
if (!tokenRes.ok)
|
|
1297
|
+
throw new Error(`Failed to obtain access token: ${await tokenRes.text()}`);
|
|
1298
|
+
const { access_token, expires_in } = await tokenRes.json();
|
|
1299
|
+
cachedToken = {
|
|
1300
|
+
value: access_token,
|
|
1301
|
+
expiresAt: Date.now() + (expires_in - 60) * 1e3
|
|
1302
|
+
};
|
|
1303
|
+
return access_token;
|
|
1304
|
+
}
|
|
1305
|
+
async function report(propertyId, token, body) {
|
|
1306
|
+
var _a2;
|
|
1307
|
+
const res = await fetch(`${GA_API_BASE}/properties/${propertyId}:runReport`, {
|
|
1308
|
+
method: "POST",
|
|
1309
|
+
headers: {
|
|
1310
|
+
Authorization: `Bearer ${token}`,
|
|
1311
|
+
"Content-Type": "application/json"
|
|
1312
|
+
},
|
|
1313
|
+
body: JSON.stringify(body)
|
|
1314
|
+
});
|
|
1315
|
+
if (!res.ok) {
|
|
1316
|
+
const err = await res.json().catch(() => null);
|
|
1317
|
+
throw new Error(
|
|
1318
|
+
((_a2 = err == null ? void 0 : err.error) == null ? void 0 : _a2.message) || `GA API error ${res.status}: ${res.statusText}`
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
return res.json();
|
|
1322
|
+
}
|
|
1323
|
+
async function realtimeReport(propertyId, token, body) {
|
|
1324
|
+
const res = await fetch(
|
|
1325
|
+
`${GA_API_BASE}/properties/${propertyId}:runRealtimeReport`,
|
|
1326
|
+
{
|
|
1327
|
+
method: "POST",
|
|
1328
|
+
headers: {
|
|
1329
|
+
Authorization: `Bearer ${token}`,
|
|
1330
|
+
"Content-Type": "application/json"
|
|
1331
|
+
},
|
|
1332
|
+
body: JSON.stringify(body)
|
|
1333
|
+
}
|
|
1334
|
+
);
|
|
1335
|
+
if (!res.ok) return {};
|
|
1336
|
+
return res.json();
|
|
1337
|
+
}
|
|
1338
|
+
async function GET(request) {
|
|
1339
|
+
try {
|
|
1340
|
+
const propertyId = process.env.GA_PROPERTY_ID;
|
|
1341
|
+
if (!propertyId)
|
|
1342
|
+
return Response.json(
|
|
1343
|
+
{ error: "GA_PROPERTY_ID not configured" },
|
|
1344
|
+
{ status: 500 }
|
|
1345
|
+
);
|
|
1346
|
+
const { searchParams } = new URL(request.url);
|
|
1347
|
+
const dateRange = searchParams.get("range") || "30";
|
|
1348
|
+
const startDate = `${dateRange}daysAgo`;
|
|
1349
|
+
let token;
|
|
1350
|
+
try {
|
|
1351
|
+
token = await getAccessToken();
|
|
1352
|
+
} catch (authErr) {
|
|
1353
|
+
const msg = authErr instanceof Error ? authErr.message : String(authErr);
|
|
1354
|
+
console.error("[analytics] Auth error:", msg);
|
|
1355
|
+
return Response.json({ error: `Auth failed: ${msg}` }, { status: 500 });
|
|
1356
|
+
}
|
|
1357
|
+
const settled = await Promise.allSettled([
|
|
1358
|
+
// 0. Overview metrics
|
|
1359
|
+
report(propertyId, token, {
|
|
1360
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1361
|
+
metrics: [
|
|
1362
|
+
{ name: "totalUsers" },
|
|
1363
|
+
{ name: "newUsers" },
|
|
1364
|
+
{ name: "sessions" },
|
|
1365
|
+
{ name: "screenPageViews" },
|
|
1366
|
+
{ name: "averageSessionDuration" },
|
|
1367
|
+
{ name: "bounceRate" },
|
|
1368
|
+
{ name: "engagedSessions" },
|
|
1369
|
+
{ name: "engagementRate" },
|
|
1370
|
+
{ name: "screenPageViewsPerSession" },
|
|
1371
|
+
{ name: "eventsPerSession" }
|
|
1372
|
+
]
|
|
1373
|
+
}),
|
|
1374
|
+
// 1. Time series by date
|
|
1375
|
+
report(propertyId, token, {
|
|
1376
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1377
|
+
dimensions: [{ name: "date" }],
|
|
1378
|
+
metrics: [
|
|
1379
|
+
{ name: "totalUsers" },
|
|
1380
|
+
{ name: "sessions" },
|
|
1381
|
+
{ name: "screenPageViews" }
|
|
1382
|
+
],
|
|
1383
|
+
orderBys: [{ dimension: { dimensionName: "date" }, desc: false }]
|
|
1384
|
+
}),
|
|
1385
|
+
// 2. Hourly traffic (today only)
|
|
1386
|
+
report(propertyId, token, {
|
|
1387
|
+
dateRanges: [{ startDate: "today", endDate: "today" }],
|
|
1388
|
+
dimensions: [{ name: "hour" }],
|
|
1389
|
+
metrics: [{ name: "totalUsers" }, { name: "sessions" }],
|
|
1390
|
+
orderBys: [{ dimension: { dimensionName: "hour" }, desc: false }]
|
|
1391
|
+
}),
|
|
1392
|
+
// 3. Top pages
|
|
1393
|
+
report(propertyId, token, {
|
|
1394
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1395
|
+
dimensions: [{ name: "pagePath" }],
|
|
1396
|
+
metrics: [
|
|
1397
|
+
{ name: "screenPageViews" },
|
|
1398
|
+
{ name: "totalUsers" },
|
|
1399
|
+
{ name: "averageSessionDuration" }
|
|
1400
|
+
],
|
|
1401
|
+
orderBys: [{ metric: { metricName: "screenPageViews" }, desc: true }],
|
|
1402
|
+
limit: 15
|
|
1403
|
+
}),
|
|
1404
|
+
// 4. Top landing pages
|
|
1405
|
+
report(propertyId, token, {
|
|
1406
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1407
|
+
dimensions: [{ name: "landingPage" }],
|
|
1408
|
+
metrics: [
|
|
1409
|
+
{ name: "sessions" },
|
|
1410
|
+
{ name: "totalUsers" },
|
|
1411
|
+
{ name: "bounceRate" }
|
|
1412
|
+
],
|
|
1413
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
|
|
1414
|
+
limit: 10
|
|
1415
|
+
}),
|
|
1416
|
+
// 5. Device category
|
|
1417
|
+
report(propertyId, token, {
|
|
1418
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1419
|
+
dimensions: [{ name: "deviceCategory" }],
|
|
1420
|
+
metrics: [{ name: "sessions" }, { name: "totalUsers" }]
|
|
1421
|
+
}),
|
|
1422
|
+
// 6. Browser breakdown
|
|
1423
|
+
report(propertyId, token, {
|
|
1424
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1425
|
+
dimensions: [{ name: "browser" }],
|
|
1426
|
+
metrics: [{ name: "sessions" }],
|
|
1427
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
|
|
1428
|
+
limit: 8
|
|
1429
|
+
}),
|
|
1430
|
+
// 7. Operating system
|
|
1431
|
+
report(propertyId, token, {
|
|
1432
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1433
|
+
dimensions: [{ name: "operatingSystem" }],
|
|
1434
|
+
metrics: [{ name: "sessions" }],
|
|
1435
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
|
|
1436
|
+
limit: 8
|
|
1437
|
+
}),
|
|
1438
|
+
// 8. Top countries
|
|
1439
|
+
report(propertyId, token, {
|
|
1440
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1441
|
+
dimensions: [{ name: "country" }],
|
|
1442
|
+
metrics: [{ name: "totalUsers" }, { name: "sessions" }],
|
|
1443
|
+
orderBys: [{ metric: { metricName: "totalUsers" }, desc: true }],
|
|
1444
|
+
limit: 10
|
|
1445
|
+
}),
|
|
1446
|
+
// 9. Top cities
|
|
1447
|
+
report(propertyId, token, {
|
|
1448
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1449
|
+
dimensions: [{ name: "city" }, { name: "country" }],
|
|
1450
|
+
metrics: [{ name: "totalUsers" }, { name: "sessions" }],
|
|
1451
|
+
orderBys: [{ metric: { metricName: "totalUsers" }, desc: true }],
|
|
1452
|
+
limit: 10
|
|
1453
|
+
}),
|
|
1454
|
+
// 10. Traffic sources
|
|
1455
|
+
report(propertyId, token, {
|
|
1456
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1457
|
+
dimensions: [{ name: "sessionSource" }, { name: "sessionMedium" }],
|
|
1458
|
+
metrics: [{ name: "sessions" }, { name: "totalUsers" }],
|
|
1459
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
|
|
1460
|
+
limit: 10
|
|
1461
|
+
}),
|
|
1462
|
+
// 11. Channel grouping
|
|
1463
|
+
report(propertyId, token, {
|
|
1464
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1465
|
+
dimensions: [{ name: "sessionDefaultChannelGroup" }],
|
|
1466
|
+
metrics: [
|
|
1467
|
+
{ name: "sessions" },
|
|
1468
|
+
{ name: "totalUsers" },
|
|
1469
|
+
{ name: "engagementRate" }
|
|
1470
|
+
],
|
|
1471
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }]
|
|
1472
|
+
}),
|
|
1473
|
+
// 12. New vs returning users
|
|
1474
|
+
report(propertyId, token, {
|
|
1475
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1476
|
+
dimensions: [{ name: "newVsReturning" }],
|
|
1477
|
+
metrics: [{ name: "totalUsers" }]
|
|
1478
|
+
}),
|
|
1479
|
+
// 13. Top events
|
|
1480
|
+
report(propertyId, token, {
|
|
1481
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1482
|
+
dimensions: [{ name: "eventName" }],
|
|
1483
|
+
metrics: [{ name: "eventCount" }, { name: "totalUsers" }],
|
|
1484
|
+
orderBys: [{ metric: { metricName: "eventCount" }, desc: true }],
|
|
1485
|
+
limit: 15
|
|
1486
|
+
}),
|
|
1487
|
+
// 14. Top referrers
|
|
1488
|
+
report(propertyId, token, {
|
|
1489
|
+
dateRanges: [{ startDate, endDate: "today" }],
|
|
1490
|
+
dimensions: [{ name: "pageReferrer" }],
|
|
1491
|
+
metrics: [{ name: "sessions" }, { name: "totalUsers" }],
|
|
1492
|
+
orderBys: [{ metric: { metricName: "sessions" }, desc: true }],
|
|
1493
|
+
limit: 10
|
|
1494
|
+
}),
|
|
1495
|
+
// 15. Real-time active users (last 30 min)
|
|
1496
|
+
realtimeReport(propertyId, token, {
|
|
1497
|
+
metrics: [{ name: "activeUsers" }]
|
|
1498
|
+
})
|
|
1499
|
+
]);
|
|
1500
|
+
settled.forEach((s, i) => {
|
|
1501
|
+
if (s.status === "rejected")
|
|
1502
|
+
console.error(`[analytics] report[${i}] failed:`, s.reason);
|
|
1503
|
+
});
|
|
1504
|
+
const ok = (i) => {
|
|
1505
|
+
const s = settled[i];
|
|
1506
|
+
return s && s.status === "fulfilled" ? s.value : {};
|
|
1507
|
+
};
|
|
1508
|
+
return Response.json(
|
|
1509
|
+
{
|
|
1510
|
+
activeUsers: ok(15),
|
|
1511
|
+
overview: ok(0),
|
|
1512
|
+
timeSeries: ok(1),
|
|
1513
|
+
hourlyToday: ok(2),
|
|
1514
|
+
topPages: ok(3),
|
|
1515
|
+
landingPages: ok(4),
|
|
1516
|
+
devices: ok(5),
|
|
1517
|
+
browsers: ok(6),
|
|
1518
|
+
operatingSystems: ok(7),
|
|
1519
|
+
countries: ok(8),
|
|
1520
|
+
cities: ok(9),
|
|
1521
|
+
trafficSources: ok(10),
|
|
1522
|
+
channels: ok(11),
|
|
1523
|
+
newVsReturning: ok(12),
|
|
1524
|
+
topEvents: ok(13),
|
|
1525
|
+
referrers: ok(14)
|
|
1526
|
+
},
|
|
1527
|
+
{
|
|
1528
|
+
headers: {
|
|
1529
|
+
"Cache-Control": "public, s-maxage=300, stale-while-revalidate=60"
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
);
|
|
1533
|
+
} catch (err) {
|
|
1534
|
+
const message2 = err instanceof Error ? err.message : String(err);
|
|
1535
|
+
console.error("[analytics] Unhandled error:", message2);
|
|
1536
|
+
return Response.json({ error: message2 }, { status: 500 });
|
|
1537
|
+
}
|
|
1538
|
+
}
|
|
1539
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1540
|
+
0 && (module.exports = {
|
|
1541
|
+
GET
|
|
1542
|
+
});
|
|
1543
|
+
//# sourceMappingURL=index.cjs.map
|