@mherod/get-cookie 4.0.3 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.husky/commit-msg +0 -0
  2. package/.husky/pre-commit +0 -0
  3. package/.husky/pre-push +0 -0
  4. package/.idea/prettier.xml +2 -1
  5. package/dist/chunk-3FVH4L25.js +2 -0
  6. package/dist/chunk-3FVH4L25.js.map +1 -0
  7. package/dist/chunk-7XZ7PCDJ.js +2 -0
  8. package/dist/chunk-7XZ7PCDJ.js.map +1 -0
  9. package/dist/chunk-DVWQBWUF.js +4 -0
  10. package/dist/chunk-DVWQBWUF.js.map +1 -0
  11. package/dist/{chunk-VMBA4NVU.js → chunk-I6AYGFSQ.js} +2 -2
  12. package/dist/chunk-U27I5BLR.js +2 -0
  13. package/dist/chunk-U27I5BLR.js.map +1 -0
  14. package/dist/chunk-YOZOS2YM.js +2 -0
  15. package/dist/chunk-YOZOS2YM.js.map +1 -0
  16. package/dist/cli.cjs +3 -4
  17. package/dist/cli.cjs.map +1 -1
  18. package/dist/getChromeCookie-2ROVM47V.js +2 -0
  19. package/dist/getChromeCookie-2ROVM47V.js.map +1 -0
  20. package/dist/{getChromePassword-GTIXL733.js → getChromePassword-O452VQWI.js} +2 -2
  21. package/dist/getCookie-CRE6M3GI.js +2 -0
  22. package/dist/getFirefoxCookie-5P74VDC7.js +2 -0
  23. package/dist/getFirefoxCookie-5P74VDC7.js.map +1 -0
  24. package/dist/getGroupedRenderedCookies-DFEJTTC6.js +2 -0
  25. package/dist/getGroupedRenderedCookies-DFEJTTC6.js.map +1 -0
  26. package/dist/getMergedRenderedCookies-W5GSSHQQ.js +2 -0
  27. package/dist/getMergedRenderedCookies-W5GSSHQQ.js.map +1 -0
  28. package/dist/index.cjs +3 -3
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +164 -152
  31. package/dist/index.d.ts +164 -152
  32. package/dist/index.js +1 -1
  33. package/dist/index.js.map +1 -1
  34. package/eslint.config.js +2 -1
  35. package/package.json +23 -22
  36. package/typedoc.json +3 -8
  37. package/dist/chunk-5FUMK7M3.js +0 -4
  38. package/dist/chunk-5FUMK7M3.js.map +0 -1
  39. package/dist/chunk-5ZT2G45S.js +0 -2
  40. package/dist/chunk-5ZT2G45S.js.map +0 -1
  41. package/dist/chunk-FR2MKDHT.js +0 -2
  42. package/dist/chunk-FR2MKDHT.js.map +0 -1
  43. package/dist/chunk-HMKSQBDC.js +0 -2
  44. package/dist/chunk-HMKSQBDC.js.map +0 -1
  45. package/dist/chunk-W3JALMAX.js +0 -2
  46. package/dist/chunk-W3JALMAX.js.map +0 -1
  47. package/dist/getChromeCookie-4ZWACG6M.js +0 -2
  48. package/dist/getChromeCookie-4ZWACG6M.js.map +0 -1
  49. package/dist/getCookie-43FKMQEZ.js +0 -2
  50. package/dist/getFirefoxCookie-OJYYZFZP.js +0 -2
  51. package/dist/getFirefoxCookie-OJYYZFZP.js.map +0 -1
  52. package/dist/getGroupedRenderedCookies-P5VZXZUC.js +0 -2
  53. package/dist/getGroupedRenderedCookies-P5VZXZUC.js.map +0 -1
  54. package/dist/getMergedRenderedCookies-C6TXK2I4.js +0 -2
  55. package/dist/getMergedRenderedCookies-C6TXK2I4.js.map +0 -1
  56. package/tsup.config.ts +0 -27
  57. /package/dist/{chunk-VMBA4NVU.js.map → chunk-I6AYGFSQ.js.map} +0 -0
  58. /package/dist/{getChromePassword-GTIXL733.js.map → getChromePassword-O452VQWI.js.map} +0 -0
  59. /package/dist/{getCookie-43FKMQEZ.js.map → getCookie-CRE6M3GI.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,189 +1,201 @@
1
+ import { z } from 'zod';
2
+
1
3
  /**
2
- * Type guard to check if an object matches the CookieRenderOptions interface.
3
- * Used to validate render options before processing cookie output.
4
- * @param obj - The object to check.
5
- * @returns True if the object contains valid render options.
4
+ * Schema for cookie specification parameters
5
+ * Defines the required fields for identifying a cookie
6
6
  * @example
7
7
  * ```typescript
8
- * import { isCookieRenderOptions } from 'get-cookie';
9
- *
10
- * // Valid render options
11
- * console.log(isCookieRenderOptions({ format: "json" })); // true
12
- * console.log(isCookieRenderOptions({
13
- * format: "text",
14
- * separator: "\n",
15
- * showFilePaths: true
16
- * })); // true
8
+ * // Validate a cookie specification
9
+ * const spec = {
10
+ * name: 'session',
11
+ * domain: 'example.com'
12
+ * };
13
+ * const result = CookieSpecSchema.safeParse(spec);
14
+ * if (result.success) {
15
+ * console.log('Valid cookie spec:', result.data);
16
+ * } else {
17
+ * console.error('Invalid cookie spec:', result.error);
18
+ * }
17
19
  *
18
- * // Invalid examples
19
- * console.log(isCookieRenderOptions({ format: "csv" })); // false - invalid format
20
- * console.log(isCookieRenderOptions({ separator: "\n" })); // false - missing format
21
- * console.log(isCookieRenderOptions(null)); // false
20
+ * // Invalid spec (empty name)
21
+ * const invalidSpec = {
22
+ * name: '',
23
+ * domain: 'example.com'
24
+ * };
25
+ * // Throws: "Cookie name cannot be empty"
26
+ * CookieSpecSchema.parse(invalidSpec);
22
27
  * ```
23
28
  */
24
- type RenderFormat = "merged" | "grouped";
29
+ declare const CookieSpecSchema: z.ZodObject<{
30
+ name: z.ZodEffects<z.ZodString, string, string>;
31
+ domain: z.ZodEffects<z.ZodString, string, string>;
32
+ }, "strict", z.ZodTypeAny, {
33
+ name: string;
34
+ domain: string;
35
+ }, {
36
+ name: string;
37
+ domain: string;
38
+ }>;
25
39
  /**
26
- * Options for rendering cookies.
40
+ * Type definition for cookie specification
41
+ * Used for specifying which cookie to query
27
42
  * @example
28
43
  * ```typescript
29
- * import { RenderOptions } from 'get-cookie';
30
- *
31
- * // Basic rendering options
32
- * const basicOptions: RenderOptions = {
33
- * format: 'merged',
34
- * separator: '; ',
35
- * showFilePaths: false
44
+ * // Basic cookie spec
45
+ * const spec: CookieSpec = {
46
+ * name: 'auth',
47
+ * domain: 'api.example.com'
36
48
  * };
37
49
  *
38
- * // Grouped format with file paths
39
- * const groupedOptions: RenderOptions = {
40
- * format: 'grouped',
41
- * separator: '; ',
42
- * showFilePaths: true
43
- * };
50
+ * // Use in function parameters
51
+ * function queryCookie(spec: CookieSpec): Promise<ExportedCookie[]> {
52
+ * return getCookie(spec);
53
+ * }
44
54
  *
45
- * // Custom separator
46
- * const customOptions: RenderOptions = {
47
- * format: 'merged',
48
- * separator: ' && ',
49
- * showFilePaths: false
50
- * };
55
+ * // Array of specs
56
+ * const specs: CookieSpec[] = [
57
+ * { name: 'session', domain: 'app.example.com' },
58
+ * { name: 'theme', domain: 'example.com' }
59
+ * ];
51
60
  * ```
52
61
  */
53
- interface RenderOptions {
54
- /** The format to use when rendering cookies. */
55
- format?: RenderFormat;
56
- /** The separator to use between cookies. */
57
- separator?: string;
58
- /** Whether to show file paths in the output. */
59
- showFilePaths?: boolean;
60
- }
61
-
62
+ type CookieSpec = z.infer<typeof CookieSpecSchema>;
62
63
  /**
63
- * Specification for identifying a cookie by its domain and name.
64
- * Used to query specific cookies from browser storage.
65
- * @remarks
66
- * - Domain matching is exact unless using wildcards.
67
- * - Name can be "*" to match all cookies for a domain.
68
- * - Leading dots in domains match all subdomains.
64
+ * Schema for exported cookie data
65
+ * Represents a cookie with all its properties and metadata
69
66
  * @example
70
67
  * ```typescript
71
- * import { CookieSpec } from 'get-cookie';
72
- *
73
- * // Basic cookie specification
74
- * const cookieSpec: CookieSpec = {
75
- * domain: "example.com",
76
- * name: "sessionId"
77
- * };
78
- *
79
- * // Using wildcards to match all cookies
80
- * const allCookies: CookieSpec = {
81
- * domain: "example.com",
82
- * name: "*" // Match all cookies for example.com
83
- * };
84
- *
85
- * // Subdomain specification
86
- * const apiCookies: CookieSpec = {
87
- * domain: "api.example.com",
88
- * name: "auth"
89
- * };
90
- *
91
- * // Match cookies across all subdomains
92
- * const allSubdomainCookies: CookieSpec = {
93
- * domain: ".example.com", // Note the leading dot
94
- * name: "tracking"
68
+ * // Validate an exported cookie
69
+ * const cookie = {
70
+ * domain: 'example.com',
71
+ * name: 'session',
72
+ * value: 'abc123',
73
+ * expiry: new Date('2024-12-31'),
74
+ * meta: {
75
+ * file: '/path/to/cookies.db'
76
+ * }
95
77
  * };
78
+ * const result = ExportedCookieSchema.safeParse(cookie);
79
+ * if (result.success) {
80
+ * console.log('Valid cookie:', result.data);
81
+ * } else {
82
+ * console.error('Invalid cookie:', result.error);
83
+ * }
96
84
  *
97
- * // Multiple domain levels
98
- * const deepSubdomainCookie: CookieSpec = {
99
- * domain: "dev.api.example.com",
100
- * name: "debug"
85
+ * // Cookie with infinite expiry
86
+ * const infiniteCookie = {
87
+ * ...cookie,
88
+ * expiry: "Infinity"
101
89
  * };
90
+ * ExportedCookieSchema.parse(infiniteCookie); // OK
102
91
  * ```
103
92
  */
104
- interface CookieSpec {
105
- /** The domain the cookie belongs to. */
93
+ declare const ExportedCookieSchema: z.ZodObject<{
94
+ domain: z.ZodEffects<z.ZodString, string, string>;
95
+ name: z.ZodEffects<z.ZodString, string, string>;
96
+ value: z.ZodPipeline<z.ZodEffects<z.ZodString, unknown, string>, z.ZodAny>;
97
+ expiry: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"Infinity">, z.ZodDate, z.ZodNumber]>>;
98
+ meta: z.ZodOptional<z.ZodObject<{
99
+ file: z.ZodOptional<z.ZodString>;
100
+ browser: z.ZodOptional<z.ZodString>;
101
+ decrypted: z.ZodOptional<z.ZodBoolean>;
102
+ secure: z.ZodOptional<z.ZodBoolean>;
103
+ httpOnly: z.ZodOptional<z.ZodBoolean>;
104
+ path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
105
+ }, "strict", z.ZodUnknown, z.objectOutputType<{
106
+ file: z.ZodOptional<z.ZodString>;
107
+ browser: z.ZodOptional<z.ZodString>;
108
+ decrypted: z.ZodOptional<z.ZodBoolean>;
109
+ secure: z.ZodOptional<z.ZodBoolean>;
110
+ httpOnly: z.ZodOptional<z.ZodBoolean>;
111
+ path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
112
+ }, z.ZodUnknown, "strict">, z.objectInputType<{
113
+ file: z.ZodOptional<z.ZodString>;
114
+ browser: z.ZodOptional<z.ZodString>;
115
+ decrypted: z.ZodOptional<z.ZodBoolean>;
116
+ secure: z.ZodOptional<z.ZodBoolean>;
117
+ httpOnly: z.ZodOptional<z.ZodBoolean>;
118
+ path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
119
+ }, z.ZodUnknown, "strict">>>;
120
+ }, "strict", z.ZodTypeAny, {
121
+ name: string;
106
122
  domain: string;
107
- /** The name of the cookie. */
123
+ value?: any;
124
+ expiry?: number | Date | "Infinity" | undefined;
125
+ meta?: z.objectOutputType<{
126
+ file: z.ZodOptional<z.ZodString>;
127
+ browser: z.ZodOptional<z.ZodString>;
128
+ decrypted: z.ZodOptional<z.ZodBoolean>;
129
+ secure: z.ZodOptional<z.ZodBoolean>;
130
+ httpOnly: z.ZodOptional<z.ZodBoolean>;
131
+ path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
132
+ }, z.ZodUnknown, "strict"> | undefined;
133
+ }, {
108
134
  name: string;
109
- }
110
-
135
+ value: string;
136
+ domain: string;
137
+ expiry?: number | Date | "Infinity" | undefined;
138
+ meta?: z.objectInputType<{
139
+ file: z.ZodOptional<z.ZodString>;
140
+ browser: z.ZodOptional<z.ZodString>;
141
+ decrypted: z.ZodOptional<z.ZodBoolean>;
142
+ secure: z.ZodOptional<z.ZodBoolean>;
143
+ httpOnly: z.ZodOptional<z.ZodBoolean>;
144
+ path: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>>;
145
+ }, z.ZodUnknown, "strict"> | undefined;
146
+ }>;
111
147
  /**
112
- * Interface representing a cookie that has been exported from a browser's storage.
113
- * This is the core data structure used to represent cookies after they have been
114
- * retrieved from various browser storage mechanisms (Chrome, Firefox, etc.).
115
- * @remarks
116
- * - All cookies must have domain, name, and value properties.
117
- * - Expiry is optional and can be a Date, "Infinity", or undefined.
118
- * - Meta information is useful for tracking the cookie's origin and state.
148
+ * Type definition for exported cookie data
149
+ * Represents the structure of a cookie after it has been retrieved
119
150
  * @example
120
151
  * ```typescript
121
- * import { ExportedCookie } from 'get-cookie';
122
- *
123
- * // Basic cookie with required fields
124
- * const basicCookie: ExportedCookie = {
125
- * domain: "example.com",
126
- * name: "sessionId",
127
- * value: "abc123"
128
- * };
129
- *
130
- * // Cookie with expiry and metadata
131
- * const detailedCookie: ExportedCookie = {
132
- * domain: "api.example.com",
133
- * name: "authToken",
134
- * value: "xyz789",
135
- * expiry: new Date("2024-12-31"),
152
+ * // Basic exported cookie
153
+ * const cookie: ExportedCookie = {
154
+ * domain: 'example.com',
155
+ * name: 'session',
156
+ * value: 'abc123',
157
+ * expiry: new Date('2024-12-31'),
136
158
  * meta: {
137
- * file: "Cookies.sqlite",
138
- * browser: "Firefox",
139
- * decrypted: true,
140
- * secure: true,
141
- * httpOnly: true,
142
- * path: "/"
159
+ * file: '/path/to/cookies.db'
143
160
  * }
144
161
  * };
145
162
  *
146
- * // Cookie with infinite expiry (session cookie)
147
- * const persistentCookie: ExportedCookie = {
148
- * domain: "app.example.com",
149
- * name: "preferences",
150
- * value: "theme=dark",
151
- * expiry: "Infinity"
152
- * };
163
+ * // Process exported cookies
164
+ * function processCookies(cookies: ExportedCookie[]): string[] {
165
+ * return cookies.map(cookie => `${cookie.name}=${cookie.value}`);
166
+ * }
153
167
  *
154
- * // Subdomain cookie example
155
- * const subdomainCookie: ExportedCookie = {
156
- * domain: ".example.com", // Note the leading dot for all subdomains
157
- * name: "tracking",
158
- * value: "user123",
159
- * meta: {
160
- * browser: "Chrome",
161
- * decrypted: true
162
- * }
163
- * };
168
+ * // Filter expired cookies
169
+ * function filterExpired(cookies: ExportedCookie[]): ExportedCookie[] {
170
+ * const now = new Date();
171
+ * return cookies.filter(cookie =>
172
+ * cookie.expiry === "Infinity" ||
173
+ * (cookie.expiry instanceof Date && cookie.expiry > now)
174
+ * );
175
+ * }
164
176
  * ```
165
177
  */
166
- interface ExportedCookie {
167
- /** The domain the cookie belongs to. */
168
- domain: string;
169
- /** The name of the cookie. */
170
- name: string;
171
- /** The value of the cookie. */
172
- value: string;
173
- /** When the cookie expires (Date object, "Infinity", or undefined). */
174
- expiry?: Date | "Infinity";
175
- /** Additional metadata about the cookie. */
176
- meta?: {
177
- /** Path to the file the cookie was exported from. */
178
- file?: string;
179
- /** Browser the cookie was exported from. */
180
- browser?: string;
181
- /** Whether the cookie value was decrypted. */
182
- decrypted?: boolean;
183
- /** Any additional metadata. */
184
- [key: string]: unknown;
185
- };
186
- }
178
+ type ExportedCookie = z.infer<typeof ExportedCookieSchema>;
179
+ /**
180
+ * Schema for cookie render options
181
+ */
182
+ declare const RenderOptionsSchema: z.ZodObject<{
183
+ format: z.ZodOptional<z.ZodEnum<["merged", "grouped"]>>;
184
+ separator: z.ZodOptional<z.ZodString>;
185
+ showFilePaths: z.ZodOptional<z.ZodBoolean>;
186
+ }, "strict", z.ZodTypeAny, {
187
+ format?: "merged" | "grouped" | undefined;
188
+ separator?: string | undefined;
189
+ showFilePaths?: boolean | undefined;
190
+ }, {
191
+ format?: "merged" | "grouped" | undefined;
192
+ separator?: string | undefined;
193
+ showFilePaths?: boolean | undefined;
194
+ }>;
195
+ /**
196
+ * Type definition for render options
197
+ */
198
+ type RenderOptions = z.infer<typeof RenderOptionsSchema>;
187
199
 
188
200
  /**
189
201
  * Dynamic import for the getCookie function.