@mherod/get-cookie 4.1.0 → 4.2.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/.env.example +5 -0
- package/.husky/commit-msg +6 -2
- package/.husky/pre-commit +6 -4
- package/.husky/pre-push +6 -4
- package/README.md +76 -117
- package/dist/cli.cjs +1 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +1 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +220 -41
- package/dist/index.d.ts +220 -41
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/eslint.config.js +8 -18
- package/examples/README.md +37 -0
- package/examples/advanced-usage.ts +56 -0
- package/examples/basic-usage.ts +43 -0
- package/examples/cli-examples.sh +51 -0
- package/package.json +13 -4
- package/tsconfig.build.json +2 -2
- package/tsconfig.cli.json +12 -0
- package/tsconfig.tsup.json +12 -0
- package/tsup.cli.ts +1 -0
- package/tsup.lib.ts +1 -0
- package/dist/chunk-3FVH4L25.js +0 -2
- package/dist/chunk-3FVH4L25.js.map +0 -1
- package/dist/chunk-56Z35D5R.js +0 -2
- package/dist/chunk-56Z35D5R.js.map +0 -1
- package/dist/chunk-7XZ7PCDJ.js +0 -2
- package/dist/chunk-7XZ7PCDJ.js.map +0 -1
- package/dist/chunk-DVWQBWUF.js +0 -4
- package/dist/chunk-DVWQBWUF.js.map +0 -1
- package/dist/chunk-I6AYGFSQ.js +0 -2
- package/dist/chunk-I6AYGFSQ.js.map +0 -1
- package/dist/chunk-U27I5BLR.js +0 -2
- package/dist/chunk-U27I5BLR.js.map +0 -1
- package/dist/chunk-YOZOS2YM.js +0 -2
- package/dist/chunk-YOZOS2YM.js.map +0 -1
- package/dist/getChromeCookie-2ROVM47V.js +0 -2
- package/dist/getChromeCookie-2ROVM47V.js.map +0 -1
- package/dist/getChromePassword-O452VQWI.js +0 -2
- package/dist/getChromePassword-O452VQWI.js.map +0 -1
- package/dist/getCookie-CRE6M3GI.js +0 -2
- package/dist/getCookie-CRE6M3GI.js.map +0 -1
- package/dist/getFirefoxCookie-5P74VDC7.js +0 -2
- package/dist/getFirefoxCookie-5P74VDC7.js.map +0 -1
- package/dist/getGroupedRenderedCookies-DFEJTTC6.js +0 -2
- package/dist/getGroupedRenderedCookies-DFEJTTC6.js.map +0 -1
- package/dist/getMergedRenderedCookies-W5GSSHQQ.js +0 -2
- package/dist/getMergedRenderedCookies-W5GSSHQQ.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -12,9 +12,9 @@ import { z } from 'zod';
|
|
|
12
12
|
* };
|
|
13
13
|
* const result = CookieSpecSchema.safeParse(spec);
|
|
14
14
|
* if (result.success) {
|
|
15
|
-
*
|
|
15
|
+
* logger.info('Valid cookie spec:', result.data);
|
|
16
16
|
* } else {
|
|
17
|
-
*
|
|
17
|
+
* logger.error('Invalid cookie spec:', result.error);
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
20
|
* // Invalid spec (empty name)
|
|
@@ -77,9 +77,9 @@ type CookieSpec = z.infer<typeof CookieSpecSchema>;
|
|
|
77
77
|
* };
|
|
78
78
|
* const result = ExportedCookieSchema.safeParse(cookie);
|
|
79
79
|
* if (result.success) {
|
|
80
|
-
*
|
|
80
|
+
* logger.info('Valid cookie:', result.data);
|
|
81
81
|
* } else {
|
|
82
|
-
*
|
|
82
|
+
* logger.error('Invalid cookie:', result.error);
|
|
83
83
|
* }
|
|
84
84
|
*
|
|
85
85
|
* // Cookie with infinite expiry
|
|
@@ -196,69 +196,248 @@ declare const RenderOptionsSchema: z.ZodObject<{
|
|
|
196
196
|
* Type definition for render options
|
|
197
197
|
*/
|
|
198
198
|
type RenderOptions = z.infer<typeof RenderOptionsSchema>;
|
|
199
|
+
/**
|
|
200
|
+
* Schema for browser names
|
|
201
|
+
*/
|
|
202
|
+
declare const BrowserNameSchema: z.ZodEnum<["Chrome", "Firefox", "Safari", "internal", "unknown"]>;
|
|
203
|
+
/**
|
|
204
|
+
* Type definition for browser names
|
|
205
|
+
*/
|
|
206
|
+
type BrowserName = z.infer<typeof BrowserNameSchema>;
|
|
207
|
+
/**
|
|
208
|
+
* Schema for cookie query strategy
|
|
209
|
+
*/
|
|
210
|
+
declare const CookieQueryStrategySchema: z.ZodObject<{
|
|
211
|
+
browserName: z.ZodEnum<["Chrome", "Firefox", "Safari", "internal", "unknown"]>;
|
|
212
|
+
queryCookies: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodOptional<z.ZodString>], z.ZodUnknown>, z.ZodPromise<z.ZodArray<z.ZodObject<{
|
|
213
|
+
domain: z.ZodEffects<z.ZodString, string, string>;
|
|
214
|
+
name: z.ZodEffects<z.ZodString, string, string>;
|
|
215
|
+
value: z.ZodPipeline<z.ZodEffects<z.ZodString, unknown, string>, z.ZodAny>;
|
|
216
|
+
expiry: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
|
|
217
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
218
|
+
file: z.ZodOptional<z.ZodString>;
|
|
219
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
220
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
221
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
224
|
+
}, "strict", z.ZodUnknown, z.objectOutputType<{
|
|
225
|
+
file: z.ZodOptional<z.ZodString>;
|
|
226
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
227
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
228
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
231
|
+
}, z.ZodUnknown, "strict">, z.objectInputType<{
|
|
232
|
+
file: z.ZodOptional<z.ZodString>;
|
|
233
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
234
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
235
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
236
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
238
|
+
}, z.ZodUnknown, "strict">>>;
|
|
239
|
+
}, "strict", z.ZodTypeAny, {
|
|
240
|
+
name: string;
|
|
241
|
+
domain: string;
|
|
242
|
+
value?: any;
|
|
243
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
244
|
+
meta?: z.objectOutputType<{
|
|
245
|
+
file: z.ZodOptional<z.ZodString>;
|
|
246
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
247
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
248
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
249
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
250
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
251
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
252
|
+
}, {
|
|
253
|
+
name: string;
|
|
254
|
+
value: string;
|
|
255
|
+
domain: string;
|
|
256
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
257
|
+
meta?: z.objectInputType<{
|
|
258
|
+
file: z.ZodOptional<z.ZodString>;
|
|
259
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
260
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
261
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
262
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
263
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
264
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
265
|
+
}>, "many">>>;
|
|
266
|
+
}, "strict", z.ZodTypeAny, {
|
|
267
|
+
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
268
|
+
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, ...args: unknown[]) => Promise<{
|
|
269
|
+
name: string;
|
|
270
|
+
domain: string;
|
|
271
|
+
value?: any;
|
|
272
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
273
|
+
meta?: z.objectOutputType<{
|
|
274
|
+
file: z.ZodOptional<z.ZodString>;
|
|
275
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
276
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
277
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
278
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
280
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
281
|
+
}[]>;
|
|
282
|
+
}, {
|
|
283
|
+
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
284
|
+
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, ...args: unknown[]) => Promise<{
|
|
285
|
+
name: string;
|
|
286
|
+
value: string;
|
|
287
|
+
domain: string;
|
|
288
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
289
|
+
meta?: z.objectInputType<{
|
|
290
|
+
file: z.ZodOptional<z.ZodString>;
|
|
291
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
292
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
293
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
294
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
295
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
296
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
297
|
+
}[]>;
|
|
298
|
+
}>;
|
|
299
|
+
/**
|
|
300
|
+
* Type definition for cookie query strategy
|
|
301
|
+
*/
|
|
302
|
+
type CookieQueryStrategy = z.infer<typeof CookieQueryStrategySchema>;
|
|
303
|
+
/**
|
|
304
|
+
* Type representing either a single cookie specification or an array of specifications.
|
|
305
|
+
* Useful when you need to query multiple cookies in a single operation.
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* // Single cookie spec
|
|
309
|
+
* const single: MultiCookieSpec = {
|
|
310
|
+
* domain: "example.com",
|
|
311
|
+
* name: "sessionId"
|
|
312
|
+
* };
|
|
313
|
+
*
|
|
314
|
+
* // Multiple cookie specs
|
|
315
|
+
* const multiple: MultiCookieSpec = [
|
|
316
|
+
* { domain: "example.com", name: "sessionId" },
|
|
317
|
+
* { domain: "api.example.com", name: "authToken" }
|
|
318
|
+
* ];
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
199
322
|
|
|
200
323
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
324
|
+
* Retrieves browser cookies that match the specified cookie name and domain criteria.
|
|
325
|
+
* This function provides a way to search and filter cookies based on given specifications.
|
|
326
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
327
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
328
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
329
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
330
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
331
|
+
* to the console without throwing to the caller
|
|
204
332
|
* @example
|
|
205
333
|
* ```typescript
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* //
|
|
334
|
+
* import { getCookie } from "@mherod/get-cookie";
|
|
335
|
+
*
|
|
336
|
+
* // Get all cookies named "sessionId"
|
|
337
|
+
* const cookies = await getCookie({ name: "sessionId" });
|
|
338
|
+
* // Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
|
|
339
|
+
*
|
|
340
|
+
* // Get cookies named "userPref" from specific domain
|
|
341
|
+
* const domainCookies = await getCookie({
|
|
342
|
+
* name: "userPref",
|
|
343
|
+
* domain: "example.com"
|
|
344
|
+
* });
|
|
345
|
+
* // Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]
|
|
209
346
|
* ```
|
|
210
347
|
*/
|
|
211
|
-
declare
|
|
348
|
+
declare function getCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
349
|
+
|
|
212
350
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @
|
|
215
|
-
* @
|
|
351
|
+
* Retrieves cookies from Chrome browser storage that match the specified criteria.
|
|
352
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
353
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
354
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
355
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
356
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
357
|
+
* to the console without throwing to the caller
|
|
216
358
|
* @example
|
|
217
359
|
* ```typescript
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* //
|
|
360
|
+
* import { getChromeCookie } from "@mherod/get-cookie";
|
|
361
|
+
*
|
|
362
|
+
* // Get all cookies named "sessionId" from Chrome
|
|
363
|
+
* const cookies = await getChromeCookie({ name: "sessionId" });
|
|
364
|
+
*
|
|
365
|
+
* // Get cookies named "userPref" from specific domain in Chrome
|
|
366
|
+
* const domainCookies = await getChromeCookie({
|
|
367
|
+
* name: "userPref",
|
|
368
|
+
* domain: "example.com"
|
|
369
|
+
* });
|
|
221
370
|
* ```
|
|
222
371
|
*/
|
|
223
|
-
declare
|
|
372
|
+
declare function getChromeCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
373
|
+
|
|
224
374
|
/**
|
|
225
|
-
*
|
|
226
|
-
* @
|
|
227
|
-
* @
|
|
375
|
+
* Retrieves cookies from Firefox browser storage that match the specified criteria.
|
|
376
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
377
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
378
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
379
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
380
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
381
|
+
* to the console without throwing to the caller
|
|
228
382
|
* @example
|
|
229
383
|
* ```typescript
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* //
|
|
384
|
+
* import { getFirefoxCookie } from "@mherod/get-cookie";
|
|
385
|
+
*
|
|
386
|
+
* // Get all cookies named "sessionId" from Firefox
|
|
387
|
+
* const cookies = await getFirefoxCookie({ name: "sessionId" });
|
|
388
|
+
*
|
|
389
|
+
* // Get cookies named "userPref" from specific domain in Firefox
|
|
390
|
+
* const domainCookies = await getFirefoxCookie({
|
|
391
|
+
* name: "userPref",
|
|
392
|
+
* domain: "example.com"
|
|
393
|
+
* });
|
|
233
394
|
* ```
|
|
234
395
|
*/
|
|
235
|
-
declare
|
|
396
|
+
declare function getFirefoxCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
397
|
+
|
|
236
398
|
/**
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
239
|
-
* @
|
|
399
|
+
* Retrieves and renders cookies in a grouped format based on their source files.
|
|
400
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
401
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
402
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
403
|
+
* @param options - Options for rendering the cookies
|
|
404
|
+
* @param options.showFilePaths - Whether to include file paths in the output
|
|
405
|
+
* @param options.separator - Custom separator for cookie values
|
|
406
|
+
* @returns An array of strings, each representing a group of cookies from a source file
|
|
240
407
|
* @example
|
|
241
408
|
* ```typescript
|
|
242
|
-
*
|
|
243
|
-
* const
|
|
244
|
-
*
|
|
409
|
+
* // Basic usage - get all cookies named "sessionId" grouped by source file
|
|
410
|
+
* const cookies = await getGroupedRenderedCookies({ name: "sessionId" });
|
|
411
|
+
*
|
|
412
|
+
* // Get cookies with domain filter and custom rendering options
|
|
413
|
+
* const domainCookies = await getGroupedRenderedCookies(
|
|
414
|
+
* {
|
|
415
|
+
* name: "userPref",
|
|
416
|
+
* domain: "example.com"
|
|
417
|
+
* },
|
|
418
|
+
* {
|
|
419
|
+
* showFilePaths: true,
|
|
420
|
+
* separator: " | "
|
|
421
|
+
* }
|
|
422
|
+
* );
|
|
245
423
|
* ```
|
|
246
424
|
*/
|
|
247
|
-
declare
|
|
425
|
+
declare function getGroupedRenderedCookies(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">): Promise<string[]>;
|
|
426
|
+
|
|
248
427
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @
|
|
251
|
-
* @
|
|
428
|
+
* Retrieves and renders cookies in a merged format
|
|
429
|
+
* @param cookieSpec - The cookie specification to query
|
|
430
|
+
* @param options - Optional rendering options
|
|
431
|
+
* @returns Promise resolving to rendered cookie string
|
|
252
432
|
* @example
|
|
253
433
|
* ```typescript
|
|
254
|
-
* const
|
|
255
|
-
*
|
|
256
|
-
* { domain: 'example.com' },
|
|
434
|
+
* const cookieString = await getMergedRenderedCookies(
|
|
435
|
+
* { name: 'session', domain: 'example.com' },
|
|
257
436
|
* { separator: '; ' }
|
|
258
437
|
* );
|
|
259
|
-
* //
|
|
438
|
+
* console.log(cookieString); // "session=abc123; auth=xyz789"
|
|
260
439
|
* ```
|
|
261
440
|
*/
|
|
262
|
-
declare
|
|
441
|
+
declare function getMergedRenderedCookies(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">): Promise<string>;
|
|
263
442
|
|
|
264
|
-
export { getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|
|
443
|
+
export { type BrowserName, type CookieQueryStrategy, type CookieSpec, type ExportedCookie, type MultiCookieSpec, type RenderOptions, getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ import { z } from 'zod';
|
|
|
12
12
|
* };
|
|
13
13
|
* const result = CookieSpecSchema.safeParse(spec);
|
|
14
14
|
* if (result.success) {
|
|
15
|
-
*
|
|
15
|
+
* logger.info('Valid cookie spec:', result.data);
|
|
16
16
|
* } else {
|
|
17
|
-
*
|
|
17
|
+
* logger.error('Invalid cookie spec:', result.error);
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
20
|
* // Invalid spec (empty name)
|
|
@@ -77,9 +77,9 @@ type CookieSpec = z.infer<typeof CookieSpecSchema>;
|
|
|
77
77
|
* };
|
|
78
78
|
* const result = ExportedCookieSchema.safeParse(cookie);
|
|
79
79
|
* if (result.success) {
|
|
80
|
-
*
|
|
80
|
+
* logger.info('Valid cookie:', result.data);
|
|
81
81
|
* } else {
|
|
82
|
-
*
|
|
82
|
+
* logger.error('Invalid cookie:', result.error);
|
|
83
83
|
* }
|
|
84
84
|
*
|
|
85
85
|
* // Cookie with infinite expiry
|
|
@@ -196,69 +196,248 @@ declare const RenderOptionsSchema: z.ZodObject<{
|
|
|
196
196
|
* Type definition for render options
|
|
197
197
|
*/
|
|
198
198
|
type RenderOptions = z.infer<typeof RenderOptionsSchema>;
|
|
199
|
+
/**
|
|
200
|
+
* Schema for browser names
|
|
201
|
+
*/
|
|
202
|
+
declare const BrowserNameSchema: z.ZodEnum<["Chrome", "Firefox", "Safari", "internal", "unknown"]>;
|
|
203
|
+
/**
|
|
204
|
+
* Type definition for browser names
|
|
205
|
+
*/
|
|
206
|
+
type BrowserName = z.infer<typeof BrowserNameSchema>;
|
|
207
|
+
/**
|
|
208
|
+
* Schema for cookie query strategy
|
|
209
|
+
*/
|
|
210
|
+
declare const CookieQueryStrategySchema: z.ZodObject<{
|
|
211
|
+
browserName: z.ZodEnum<["Chrome", "Firefox", "Safari", "internal", "unknown"]>;
|
|
212
|
+
queryCookies: z.ZodFunction<z.ZodTuple<[z.ZodString, z.ZodString, z.ZodOptional<z.ZodString>], z.ZodUnknown>, z.ZodPromise<z.ZodArray<z.ZodObject<{
|
|
213
|
+
domain: z.ZodEffects<z.ZodString, string, string>;
|
|
214
|
+
name: z.ZodEffects<z.ZodString, string, string>;
|
|
215
|
+
value: z.ZodPipeline<z.ZodEffects<z.ZodString, unknown, string>, z.ZodAny>;
|
|
216
|
+
expiry: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
|
|
217
|
+
meta: z.ZodOptional<z.ZodObject<{
|
|
218
|
+
file: z.ZodOptional<z.ZodString>;
|
|
219
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
220
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
221
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
224
|
+
}, "strict", z.ZodUnknown, z.objectOutputType<{
|
|
225
|
+
file: z.ZodOptional<z.ZodString>;
|
|
226
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
227
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
228
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
231
|
+
}, z.ZodUnknown, "strict">, z.objectInputType<{
|
|
232
|
+
file: z.ZodOptional<z.ZodString>;
|
|
233
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
234
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
235
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
236
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
237
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
238
|
+
}, z.ZodUnknown, "strict">>>;
|
|
239
|
+
}, "strict", z.ZodTypeAny, {
|
|
240
|
+
name: string;
|
|
241
|
+
domain: string;
|
|
242
|
+
value?: any;
|
|
243
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
244
|
+
meta?: z.objectOutputType<{
|
|
245
|
+
file: z.ZodOptional<z.ZodString>;
|
|
246
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
247
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
248
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
249
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
250
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
251
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
252
|
+
}, {
|
|
253
|
+
name: string;
|
|
254
|
+
value: string;
|
|
255
|
+
domain: string;
|
|
256
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
257
|
+
meta?: z.objectInputType<{
|
|
258
|
+
file: z.ZodOptional<z.ZodString>;
|
|
259
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
260
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
261
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
262
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
263
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
264
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
265
|
+
}>, "many">>>;
|
|
266
|
+
}, "strict", z.ZodTypeAny, {
|
|
267
|
+
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
268
|
+
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, ...args: unknown[]) => Promise<{
|
|
269
|
+
name: string;
|
|
270
|
+
domain: string;
|
|
271
|
+
value?: any;
|
|
272
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
273
|
+
meta?: z.objectOutputType<{
|
|
274
|
+
file: z.ZodOptional<z.ZodString>;
|
|
275
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
276
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
277
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
278
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
279
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
280
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
281
|
+
}[]>;
|
|
282
|
+
}, {
|
|
283
|
+
browserName: "unknown" | "Chrome" | "Firefox" | "Safari" | "internal";
|
|
284
|
+
queryCookies: (args_0: string, args_1: string, args_2: string | undefined, ...args: unknown[]) => Promise<{
|
|
285
|
+
name: string;
|
|
286
|
+
value: string;
|
|
287
|
+
domain: string;
|
|
288
|
+
expiry?: number | Date | "Infinity" | undefined;
|
|
289
|
+
meta?: z.objectInputType<{
|
|
290
|
+
file: z.ZodOptional<z.ZodString>;
|
|
291
|
+
browser: z.ZodOptional<z.ZodString>;
|
|
292
|
+
decrypted: z.ZodOptional<z.ZodBoolean>;
|
|
293
|
+
secure: z.ZodOptional<z.ZodBoolean>;
|
|
294
|
+
httpOnly: z.ZodOptional<z.ZodBoolean>;
|
|
295
|
+
path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
|
|
296
|
+
}, z.ZodUnknown, "strict"> | undefined;
|
|
297
|
+
}[]>;
|
|
298
|
+
}>;
|
|
299
|
+
/**
|
|
300
|
+
* Type definition for cookie query strategy
|
|
301
|
+
*/
|
|
302
|
+
type CookieQueryStrategy = z.infer<typeof CookieQueryStrategySchema>;
|
|
303
|
+
/**
|
|
304
|
+
* Type representing either a single cookie specification or an array of specifications.
|
|
305
|
+
* Useful when you need to query multiple cookies in a single operation.
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* // Single cookie spec
|
|
309
|
+
* const single: MultiCookieSpec = {
|
|
310
|
+
* domain: "example.com",
|
|
311
|
+
* name: "sessionId"
|
|
312
|
+
* };
|
|
313
|
+
*
|
|
314
|
+
* // Multiple cookie specs
|
|
315
|
+
* const multiple: MultiCookieSpec = [
|
|
316
|
+
* { domain: "example.com", name: "sessionId" },
|
|
317
|
+
* { domain: "api.example.com", name: "authToken" }
|
|
318
|
+
* ];
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
type MultiCookieSpec = CookieSpec | CookieSpec[];
|
|
199
322
|
|
|
200
323
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
* @
|
|
324
|
+
* Retrieves browser cookies that match the specified cookie name and domain criteria.
|
|
325
|
+
* This function provides a way to search and filter cookies based on given specifications.
|
|
326
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
327
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
328
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
329
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
330
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
331
|
+
* to the console without throwing to the caller
|
|
204
332
|
* @example
|
|
205
333
|
* ```typescript
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
* //
|
|
334
|
+
* import { getCookie } from "@mherod/get-cookie";
|
|
335
|
+
*
|
|
336
|
+
* // Get all cookies named "sessionId"
|
|
337
|
+
* const cookies = await getCookie({ name: "sessionId" });
|
|
338
|
+
* // Returns: [{ name: "sessionId", value: "abc123", domain: ".example.com", ... }]
|
|
339
|
+
*
|
|
340
|
+
* // Get cookies named "userPref" from specific domain
|
|
341
|
+
* const domainCookies = await getCookie({
|
|
342
|
+
* name: "userPref",
|
|
343
|
+
* domain: "example.com"
|
|
344
|
+
* });
|
|
345
|
+
* // Returns: [{ name: "userPref", value: "darkMode", domain: "example.com", ... }]
|
|
209
346
|
* ```
|
|
210
347
|
*/
|
|
211
|
-
declare
|
|
348
|
+
declare function getCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
349
|
+
|
|
212
350
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @
|
|
215
|
-
* @
|
|
351
|
+
* Retrieves cookies from Chrome browser storage that match the specified criteria.
|
|
352
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
353
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
354
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
355
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
356
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
357
|
+
* to the console without throwing to the caller
|
|
216
358
|
* @example
|
|
217
359
|
* ```typescript
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* //
|
|
360
|
+
* import { getChromeCookie } from "@mherod/get-cookie";
|
|
361
|
+
*
|
|
362
|
+
* // Get all cookies named "sessionId" from Chrome
|
|
363
|
+
* const cookies = await getChromeCookie({ name: "sessionId" });
|
|
364
|
+
*
|
|
365
|
+
* // Get cookies named "userPref" from specific domain in Chrome
|
|
366
|
+
* const domainCookies = await getChromeCookie({
|
|
367
|
+
* name: "userPref",
|
|
368
|
+
* domain: "example.com"
|
|
369
|
+
* });
|
|
221
370
|
* ```
|
|
222
371
|
*/
|
|
223
|
-
declare
|
|
372
|
+
declare function getChromeCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
373
|
+
|
|
224
374
|
/**
|
|
225
|
-
*
|
|
226
|
-
* @
|
|
227
|
-
* @
|
|
375
|
+
* Retrieves cookies from Firefox browser storage that match the specified criteria.
|
|
376
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
377
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
378
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
379
|
+
* @returns An array of ExportedCookie objects that match the specification
|
|
380
|
+
* @throws Will catch and handle any errors during cookie querying, logging a warning
|
|
381
|
+
* to the console without throwing to the caller
|
|
228
382
|
* @example
|
|
229
383
|
* ```typescript
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* //
|
|
384
|
+
* import { getFirefoxCookie } from "@mherod/get-cookie";
|
|
385
|
+
*
|
|
386
|
+
* // Get all cookies named "sessionId" from Firefox
|
|
387
|
+
* const cookies = await getFirefoxCookie({ name: "sessionId" });
|
|
388
|
+
*
|
|
389
|
+
* // Get cookies named "userPref" from specific domain in Firefox
|
|
390
|
+
* const domainCookies = await getFirefoxCookie({
|
|
391
|
+
* name: "userPref",
|
|
392
|
+
* domain: "example.com"
|
|
393
|
+
* });
|
|
233
394
|
* ```
|
|
234
395
|
*/
|
|
235
|
-
declare
|
|
396
|
+
declare function getFirefoxCookie(cookieSpec: CookieSpec): Promise<ExportedCookie[]>;
|
|
397
|
+
|
|
236
398
|
/**
|
|
237
|
-
*
|
|
238
|
-
* @
|
|
239
|
-
* @
|
|
399
|
+
* Retrieves and renders cookies in a grouped format based on their source files.
|
|
400
|
+
* @param cookieSpec - The cookie specification containing search criteria
|
|
401
|
+
* @param cookieSpec.name - The name of the cookie to search for
|
|
402
|
+
* @param cookieSpec.domain - (optional) The domain to filter cookies by
|
|
403
|
+
* @param options - Options for rendering the cookies
|
|
404
|
+
* @param options.showFilePaths - Whether to include file paths in the output
|
|
405
|
+
* @param options.separator - Custom separator for cookie values
|
|
406
|
+
* @returns An array of strings, each representing a group of cookies from a source file
|
|
240
407
|
* @example
|
|
241
408
|
* ```typescript
|
|
242
|
-
*
|
|
243
|
-
* const
|
|
244
|
-
*
|
|
409
|
+
* // Basic usage - get all cookies named "sessionId" grouped by source file
|
|
410
|
+
* const cookies = await getGroupedRenderedCookies({ name: "sessionId" });
|
|
411
|
+
*
|
|
412
|
+
* // Get cookies with domain filter and custom rendering options
|
|
413
|
+
* const domainCookies = await getGroupedRenderedCookies(
|
|
414
|
+
* {
|
|
415
|
+
* name: "userPref",
|
|
416
|
+
* domain: "example.com"
|
|
417
|
+
* },
|
|
418
|
+
* {
|
|
419
|
+
* showFilePaths: true,
|
|
420
|
+
* separator: " | "
|
|
421
|
+
* }
|
|
422
|
+
* );
|
|
245
423
|
* ```
|
|
246
424
|
*/
|
|
247
|
-
declare
|
|
425
|
+
declare function getGroupedRenderedCookies(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">): Promise<string[]>;
|
|
426
|
+
|
|
248
427
|
/**
|
|
249
|
-
*
|
|
250
|
-
* @
|
|
251
|
-
* @
|
|
428
|
+
* Retrieves and renders cookies in a merged format
|
|
429
|
+
* @param cookieSpec - The cookie specification to query
|
|
430
|
+
* @param options - Optional rendering options
|
|
431
|
+
* @returns Promise resolving to rendered cookie string
|
|
252
432
|
* @example
|
|
253
433
|
* ```typescript
|
|
254
|
-
* const
|
|
255
|
-
*
|
|
256
|
-
* { domain: 'example.com' },
|
|
434
|
+
* const cookieString = await getMergedRenderedCookies(
|
|
435
|
+
* { name: 'session', domain: 'example.com' },
|
|
257
436
|
* { separator: '; ' }
|
|
258
437
|
* );
|
|
259
|
-
* //
|
|
438
|
+
* console.log(cookieString); // "session=abc123; auth=xyz789"
|
|
260
439
|
* ```
|
|
261
440
|
*/
|
|
262
|
-
declare
|
|
441
|
+
declare function getMergedRenderedCookies(cookieSpec: CookieSpec, options?: Omit<RenderOptions, "format">): Promise<string>;
|
|
263
442
|
|
|
264
|
-
export { getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|
|
443
|
+
export { type BrowserName, type CookieQueryStrategy, type CookieSpec, type ExportedCookie, type MultiCookieSpec, type RenderOptions, getChromeCookie, getCookie, getFirefoxCookie, getGroupedRenderedCookies, getMergedRenderedCookies };
|