@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.22

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 (159) hide show
  1. package/autoscaling/autoscaled_pool.d.ts +296 -0
  2. package/autoscaling/autoscaled_pool.d.ts.map +1 -0
  3. package/autoscaling/autoscaled_pool.js +673 -0
  4. package/autoscaling/autoscaled_pool.js.map +1 -0
  5. package/autoscaling/index.d.ts +4 -0
  6. package/autoscaling/index.d.ts.map +1 -0
  7. package/autoscaling/index.js +7 -0
  8. package/autoscaling/index.js.map +1 -0
  9. package/autoscaling/snapshotter.d.ts +193 -0
  10. package/autoscaling/snapshotter.d.ts.map +1 -0
  11. package/autoscaling/snapshotter.js +377 -0
  12. package/autoscaling/snapshotter.js.map +1 -0
  13. package/autoscaling/system_status.d.ts +181 -0
  14. package/autoscaling/system_status.d.ts.map +1 -0
  15. package/autoscaling/system_status.js +194 -0
  16. package/autoscaling/system_status.js.map +1 -0
  17. package/cache_container.d.ts +18 -0
  18. package/cache_container.d.ts.map +1 -0
  19. package/cache_container.js +42 -0
  20. package/cache_container.js.map +1 -0
  21. package/configuration.d.ts +150 -0
  22. package/configuration.d.ts.map +1 -0
  23. package/configuration.js +284 -0
  24. package/configuration.js.map +1 -0
  25. package/constants.d.ts +3 -0
  26. package/constants.d.ts.map +1 -0
  27. package/constants.js +6 -0
  28. package/constants.js.map +1 -0
  29. package/crawlers/crawler_commons.d.ts +25 -0
  30. package/crawlers/crawler_commons.d.ts.map +1 -0
  31. package/crawlers/crawler_commons.js +3 -0
  32. package/crawlers/crawler_commons.js.map +1 -0
  33. package/crawlers/crawler_extension.d.ts +11 -0
  34. package/crawlers/crawler_extension.d.ts.map +1 -0
  35. package/crawlers/crawler_extension.js +30 -0
  36. package/crawlers/crawler_extension.js.map +1 -0
  37. package/crawlers/crawler_utils.d.ts +20 -0
  38. package/crawlers/crawler_utils.d.ts.map +1 -0
  39. package/crawlers/crawler_utils.js +61 -0
  40. package/crawlers/crawler_utils.js.map +1 -0
  41. package/crawlers/index.d.ts +5 -0
  42. package/crawlers/index.d.ts.map +1 -0
  43. package/crawlers/index.js +8 -0
  44. package/crawlers/index.js.map +1 -0
  45. package/crawlers/statistics.d.ts +147 -0
  46. package/crawlers/statistics.d.ts.map +1 -0
  47. package/crawlers/statistics.js +360 -0
  48. package/crawlers/statistics.js.map +1 -0
  49. package/enqueue_links/enqueue_links.d.ts +151 -0
  50. package/enqueue_links/enqueue_links.d.ts.map +1 -0
  51. package/enqueue_links/enqueue_links.js +152 -0
  52. package/enqueue_links/enqueue_links.js.map +1 -0
  53. package/enqueue_links/index.d.ts +3 -0
  54. package/enqueue_links/index.d.ts.map +1 -0
  55. package/enqueue_links/index.js +6 -0
  56. package/enqueue_links/index.js.map +1 -0
  57. package/enqueue_links/shared.d.ts +60 -0
  58. package/enqueue_links/shared.d.ts.map +1 -0
  59. package/enqueue_links/shared.js +148 -0
  60. package/enqueue_links/shared.js.map +1 -0
  61. package/errors.d.ts +8 -0
  62. package/errors.d.ts.map +1 -0
  63. package/errors.js +12 -0
  64. package/errors.js.map +1 -0
  65. package/events/event_manager.d.ts +41 -0
  66. package/events/event_manager.d.ts.map +1 -0
  67. package/events/event_manager.js +103 -0
  68. package/events/event_manager.js.map +1 -0
  69. package/events/index.d.ts +3 -0
  70. package/events/index.d.ts.map +1 -0
  71. package/events/index.js +6 -0
  72. package/events/index.js.map +1 -0
  73. package/events/local_event_manager.d.ts +32 -0
  74. package/events/local_event_manager.d.ts.map +1 -0
  75. package/events/local_event_manager.js +114 -0
  76. package/events/local_event_manager.js.map +1 -0
  77. package/index.d.ts +14 -0
  78. package/index.d.ts.map +1 -0
  79. package/index.js +17 -0
  80. package/index.js.map +1 -0
  81. package/index.mjs +61 -0
  82. package/log.d.ts +3 -0
  83. package/log.d.ts.map +1 -0
  84. package/log.js +12 -0
  85. package/log.js.map +1 -0
  86. package/package.json +4 -8
  87. package/proxy_configuration.d.ts +181 -0
  88. package/proxy_configuration.d.ts.map +1 -0
  89. package/proxy_configuration.js +209 -0
  90. package/proxy_configuration.js.map +1 -0
  91. package/request.d.ts +185 -0
  92. package/request.d.ts.map +1 -0
  93. package/request.js +330 -0
  94. package/request.js.map +1 -0
  95. package/serialization.d.ts +33 -0
  96. package/serialization.d.ts.map +1 -0
  97. package/serialization.js +146 -0
  98. package/serialization.js.map +1 -0
  99. package/session_pool/errors.d.ts +8 -0
  100. package/session_pool/errors.d.ts.map +1 -0
  101. package/session_pool/errors.js +20 -0
  102. package/session_pool/errors.js.map +1 -0
  103. package/session_pool/events.d.ts +3 -0
  104. package/session_pool/events.d.ts.map +1 -0
  105. package/session_pool/events.js +6 -0
  106. package/session_pool/events.js.map +1 -0
  107. package/session_pool/index.d.ts +6 -0
  108. package/session_pool/index.d.ts.map +1 -0
  109. package/session_pool/index.js +9 -0
  110. package/session_pool/index.js.map +1 -0
  111. package/session_pool/session.d.ts +212 -0
  112. package/session_pool/session.d.ts.map +1 -0
  113. package/session_pool/session.js +360 -0
  114. package/session_pool/session.js.map +1 -0
  115. package/session_pool/session_pool.d.ts +222 -0
  116. package/session_pool/session_pool.d.ts.map +1 -0
  117. package/session_pool/session_pool.js +389 -0
  118. package/session_pool/session_pool.js.map +1 -0
  119. package/session_pool/session_utils.d.ts +9 -0
  120. package/session_pool/session_utils.d.ts.map +1 -0
  121. package/session_pool/session_utils.js +19 -0
  122. package/session_pool/session_utils.js.map +1 -0
  123. package/storages/dataset.d.ts +317 -0
  124. package/storages/dataset.d.ts.map +1 -0
  125. package/storages/dataset.js +367 -0
  126. package/storages/dataset.js.map +1 -0
  127. package/storages/index.d.ts +7 -0
  128. package/storages/index.d.ts.map +1 -0
  129. package/storages/index.js +11 -0
  130. package/storages/index.js.map +1 -0
  131. package/storages/key_value_store.d.ts +242 -0
  132. package/storages/key_value_store.d.ts.map +1 -0
  133. package/storages/key_value_store.js +320 -0
  134. package/storages/key_value_store.js.map +1 -0
  135. package/storages/request_list.d.ts +469 -0
  136. package/storages/request_list.d.ts.map +1 -0
  137. package/storages/request_list.js +724 -0
  138. package/storages/request_list.js.map +1 -0
  139. package/storages/request_queue.d.ts +315 -0
  140. package/storages/request_queue.d.ts.map +1 -0
  141. package/storages/request_queue.js +730 -0
  142. package/storages/request_queue.js.map +1 -0
  143. package/storages/storage.d.ts +260 -0
  144. package/storages/storage.d.ts.map +1 -0
  145. package/storages/storage.js +3 -0
  146. package/storages/storage.js.map +1 -0
  147. package/storages/storage_manager.d.ts +40 -0
  148. package/storages/storage_manager.d.ts.map +1 -0
  149. package/storages/storage_manager.js +119 -0
  150. package/storages/storage_manager.js.map +1 -0
  151. package/tsconfig.build.tsbuildinfo +1 -0
  152. package/typedefs.d.ts +12 -0
  153. package/typedefs.d.ts.map +1 -0
  154. package/typedefs.js +15 -0
  155. package/typedefs.js.map +1 -0
  156. package/validators.d.ts +21 -0
  157. package/validators.d.ts.map +1 -0
  158. package/validators.js +26 -0
  159. package/validators.js.map +1 -0
@@ -0,0 +1,212 @@
1
+ /// <reference types="node" />
2
+ import { Log } from '@apify/log';
3
+ import { Cookie as BrowserPoolCookie } from '@crawlee/browser-pool';
4
+ import { IncomingMessage } from 'http';
5
+ import { HTTPResponse, Protocol } from 'puppeteer';
6
+ import { Cookie, CookieJar } from 'tough-cookie';
7
+ import { Dictionary } from '../typedefs';
8
+ import { SessionPool } from './session_pool';
9
+ export declare type PuppeteerCookie = Protocol.Network.Cookie | BrowserPoolCookie;
10
+ /**
11
+ * Persistable {@link Session} state.
12
+ */
13
+ export interface SessionState {
14
+ id: string;
15
+ cookieJar: CookieJar.Serialized;
16
+ userData: object;
17
+ errorScore: number;
18
+ maxErrorScore: number;
19
+ errorScoreDecrement: number;
20
+ usageCount: number;
21
+ maxUsageCount: number;
22
+ expiresAt: string;
23
+ createdAt: string;
24
+ }
25
+ export interface SessionOptions {
26
+ /** Id of session used for generating fingerprints. It is used as proxy session name. */
27
+ id?: string;
28
+ /**
29
+ * Number of seconds after which the session is considered as expired.
30
+ * @default 3000
31
+ */
32
+ maxAgeSecs?: number;
33
+ /** Object where custom user data can be stored. For example custom headers. */
34
+ userData?: Dictionary;
35
+ /**
36
+ * Maximum number of marking session as blocked usage.
37
+ * If the `errorScore` reaches the `maxErrorScore` session is marked as block and it is thrown away.
38
+ * It starts at 0. Calling the `markBad` function increases the `errorScore` by 1.
39
+ * Calling the `markGood` will decrease the `errorScore` by `errorScoreDecrement`
40
+ * @default 3
41
+ */
42
+ maxErrorScore?: number;
43
+ /**
44
+ * It is used for healing the session.
45
+ * For example: if your session is marked bad two times, but it is successful on the third attempt it's errorScore
46
+ * is decremented by this number.
47
+ * @default 0.5
48
+ */
49
+ errorScoreDecrement?: number;
50
+ /** Date of creation. */
51
+ createdAt?: Date;
52
+ /** Date of expiration. */
53
+ expiresAt?: Date;
54
+ /**
55
+ * Indicates how many times the session has been used.
56
+ * @default 0
57
+ */
58
+ usageCount?: number;
59
+ /**
60
+ * Session should be used only a limited amount of times.
61
+ * This number indicates how many times the session is going to be used, before it is thrown away.
62
+ * @default 50
63
+ */
64
+ maxUsageCount?: number;
65
+ /** SessionPool instance. Session will emit the `sessionRetired` event on this instance. */
66
+ sessionPool?: SessionPool;
67
+ log?: Log;
68
+ errorScore?: number;
69
+ cookieJar?: CookieJar;
70
+ }
71
+ /**
72
+ * Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
73
+ * You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
74
+ * Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
75
+ * @category Scaling
76
+ */
77
+ export declare class Session {
78
+ readonly id: string;
79
+ private maxAgeSecs;
80
+ userData: Dictionary;
81
+ private maxErrorScore;
82
+ private errorScoreDecrement;
83
+ private createdAt;
84
+ private expiresAt;
85
+ private usageCount;
86
+ private maxUsageCount;
87
+ private sessionPool;
88
+ private errorScore;
89
+ private cookieJar;
90
+ private log;
91
+ /**
92
+ * Session configuration.
93
+ */
94
+ constructor(options: SessionOptions);
95
+ /**
96
+ * Indicates whether the session is blocked.
97
+ * Session is blocked once it reaches the `maxErrorScore`.
98
+ */
99
+ isBlocked(): boolean;
100
+ /**
101
+ * Indicates whether the session is expired.
102
+ * Session expiration is determined by the `maxAgeSecs`.
103
+ * Once the session is older than `createdAt + maxAgeSecs` the session is considered expired.
104
+ */
105
+ isExpired(): boolean;
106
+ /**
107
+ * Indicates whether the session is used maximum number of times.
108
+ * Session maximum usage count can be changed by `maxUsageCount` parameter.
109
+ */
110
+ isMaxUsageCountReached(): boolean;
111
+ /**
112
+ * Indicates whether the session can be used for next requests.
113
+ * Session is usable when it is not expired, not blocked and the maximum usage count has not be reached.
114
+ */
115
+ isUsable(): boolean;
116
+ /**
117
+ * This method should be called after a successful session usage.
118
+ * It increases `usageCount` and potentially lowers the `errorScore` by the `errorScoreDecrement`.
119
+ */
120
+ markGood(): void;
121
+ /**
122
+ * Gets session state for persistence in KeyValueStore.
123
+ * @returns Represents session internal state.
124
+ */
125
+ getState(): SessionState;
126
+ /**
127
+ * Marks session as blocked and emits event on the `SessionPool`
128
+ * This method should be used if the session usage was unsuccessful
129
+ * and you are sure that it is because of the session configuration and not any external matters.
130
+ * For example when server returns 403 status code.
131
+ * If the session does not work due to some external factors as server error such as 5XX you probably want to use `markBad` method.
132
+ */
133
+ retire(): void;
134
+ /**
135
+ * Increases usage and error count.
136
+ * Should be used when the session has been used unsuccessfully. For example because of timeouts.
137
+ */
138
+ markBad(): void;
139
+ /**
140
+ * With certain status codes: `401`, `403` or `429` we can be certain
141
+ * that the target website is blocking us. This function helps to do this conveniently
142
+ * by retiring the session when such code is received. Optionally the default status
143
+ * codes can be extended in the second parameter.
144
+ * @param statusCode HTTP status code.
145
+ * @param [blockedStatusCodes] Custom HTTP status codes that means blocking on particular website.
146
+ * @returns Whether the session was retired.
147
+ */
148
+ retireOnBlockedStatusCodes(statusCode: number, blockedStatusCodes?: number[]): boolean;
149
+ /**
150
+ * Saves cookies from an HTTP response to be used with the session.
151
+ * It expects an object with a `headers` property that's either an `Object`
152
+ * (typical Node.js responses) or a `Function` (Puppeteer Response).
153
+ *
154
+ * It then parses and saves the cookies from the `set-cookie` header, if available.
155
+ */
156
+ setCookiesFromResponse(response: IncomingMessage | HTTPResponse | {
157
+ headers: Dictionary<string | string[]>;
158
+ url: string;
159
+ }): void;
160
+ /**
161
+ * Saves an array with cookie objects to be used with the session.
162
+ * The objects should be in the format that
163
+ * [Puppeteer uses](https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagecookiesurls),
164
+ * but you can also use this function to set cookies manually:
165
+ *
166
+ * ```
167
+ * [
168
+ * { name: 'cookie1', value: 'my-cookie' },
169
+ * { name: 'cookie2', value: 'your-cookie' }
170
+ * ]
171
+ * ```
172
+ */
173
+ setPuppeteerCookies(cookies: PuppeteerCookie[], url: string): void;
174
+ /**
175
+ * Returns cookies in a format compatible with puppeteer and ready to be used with `page.setCookie`.
176
+ * @param url website url. Only cookies stored for this url will be returned
177
+ */
178
+ getPuppeteerCookies(url: string): PuppeteerCookie[];
179
+ /**
180
+ * Returns cookies saved with the session in the typical
181
+ * key1=value1; key2=value2 format, ready to be used in
182
+ * a cookie header or elsewhere.
183
+ * @returns Represents `Cookie` header.
184
+ */
185
+ getCookieString(url: string): string;
186
+ /**
187
+ * Transforms puppeteer cookie to tough-cookie.
188
+ * @param puppeteerCookie Cookie from puppeteer `page.cookies` method.
189
+ */
190
+ protected _puppeteerCookieToTough(puppeteerCookie: PuppeteerCookie): Cookie;
191
+ /**
192
+ * Transforms tough-cookie to puppeteer cookie.
193
+ * @param toughCookie Cookie from CookieJar
194
+ * @return Cookie from Puppeteer
195
+ */
196
+ protected _toughCookieToPuppeteer(toughCookie: Cookie): PuppeteerCookie;
197
+ /**
198
+ * Sets cookies.
199
+ */
200
+ protected _setCookies(cookies: Cookie[], url: string): void;
201
+ /**
202
+ * Calculate cookie expiration date
203
+ * @param maxAgeSecs
204
+ * @returns Calculated date by session max age seconds.
205
+ */
206
+ protected _getDefaultCookieExpirationDate(maxAgeSecs: number): Date;
207
+ /**
208
+ * Checks if session is not usable. if it is not retires the session.
209
+ */
210
+ protected _maybeSelfRetire(): void;
211
+ }
212
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session_pool/session.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,EAAE,MAAM,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,oBAAY,eAAe,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,iBAAiB,CAAC;AAK1E;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAE3B,wFAAwF;IACxF,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,+EAA+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YAAY;IAexB;;;;;;OAMG;IACH,MAAM;IASN;;;OAGG;IACH,OAAO;IAOP;;;;;;;;OAQG;IACH,0BAA0B,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,GAAE,MAAM,EAAO,GAAG,OAAO;IAQ1F;;;;;;OAMG;IACH,sBAAsB,CAAC,QAAQ,EAAE,eAAe,GAAG,YAAY,GAAG;QAAE,OAAO,EAAE,UAAU,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;IAWzH;;;;;;;;;;;;OAYG;IACH,mBAAmB,CAAC,OAAO,EAAE,eAAe,EAAE,EAAE,GAAG,EAAE,MAAM;IAK3D;;;OAGG;IACH,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,EAAE;IAKnD;;;;;OAKG;IACH,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIpC;;;OAGG;IACH,SAAS,CAAC,uBAAuB,CAAC,eAAe,EAAE,eAAe,GAAG,MAAM;IAkB3E;;;;OAIG;IACH,SAAS,CAAC,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe;IAavE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;IAkB3D;;;;OAIG;IACH,SAAS,CAAC,+BAA+B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAInE;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;CAKrC"}
@@ -0,0 +1,360 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Session = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utilities_1 = require("@apify/utilities");
6
+ const ow_1 = tslib_1.__importDefault(require("ow"));
7
+ const tough_cookie_1 = require("tough-cookie");
8
+ const constants_1 = require("../constants");
9
+ const log_1 = require("../log");
10
+ const events_1 = require("./events");
11
+ const session_pool_1 = require("./session_pool");
12
+ const session_utils_1 = require("./session_utils");
13
+ // CONSTANTS
14
+ const DEFAULT_SESSION_MAX_AGE_SECS = 3000;
15
+ /**
16
+ * Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions.
17
+ * You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint.
18
+ * Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.
19
+ * @category Scaling
20
+ */
21
+ class Session {
22
+ /**
23
+ * Session configuration.
24
+ */
25
+ constructor(options) {
26
+ Object.defineProperty(this, "id", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ Object.defineProperty(this, "maxAgeSecs", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "userData", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "maxErrorScore", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "errorScoreDecrement", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
56
+ Object.defineProperty(this, "createdAt", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ Object.defineProperty(this, "expiresAt", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ Object.defineProperty(this, "usageCount", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ Object.defineProperty(this, "maxUsageCount", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
80
+ Object.defineProperty(this, "sessionPool", {
81
+ enumerable: true,
82
+ configurable: true,
83
+ writable: true,
84
+ value: void 0
85
+ });
86
+ Object.defineProperty(this, "errorScore", {
87
+ enumerable: true,
88
+ configurable: true,
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+ Object.defineProperty(this, "cookieJar", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: void 0
97
+ });
98
+ Object.defineProperty(this, "log", {
99
+ enumerable: true,
100
+ configurable: true,
101
+ writable: true,
102
+ value: void 0
103
+ });
104
+ (0, ow_1.default)(options, ow_1.default.object.exactShape({
105
+ sessionPool: ow_1.default.object.instanceOf(session_pool_1.SessionPool),
106
+ id: ow_1.default.optional.string,
107
+ cookieJar: ow_1.default.optional.object,
108
+ maxAgeSecs: ow_1.default.optional.number,
109
+ userData: ow_1.default.optional.object,
110
+ maxErrorScore: ow_1.default.optional.number,
111
+ errorScoreDecrement: ow_1.default.optional.number,
112
+ createdAt: ow_1.default.optional.date,
113
+ expiresAt: ow_1.default.optional.date,
114
+ usageCount: ow_1.default.optional.number,
115
+ errorScore: ow_1.default.optional.number,
116
+ maxUsageCount: ow_1.default.optional.number,
117
+ log: ow_1.default.optional.object,
118
+ }));
119
+ const { sessionPool, id = `session_${(0, utilities_1.cryptoRandomObjectId)(10)}`, cookieJar = new tough_cookie_1.CookieJar(), maxAgeSecs = DEFAULT_SESSION_MAX_AGE_SECS, userData = {}, maxErrorScore = 3, errorScoreDecrement = 0.5, createdAt = new Date(), usageCount = 0, errorScore = 0, maxUsageCount = 50, log = log_1.log, } = options;
120
+ const { expiresAt = this._getDefaultCookieExpirationDate(maxAgeSecs) } = options;
121
+ this.log = log.child({ prefix: 'Session' });
122
+ this.cookieJar = cookieJar.setCookie ? cookieJar : tough_cookie_1.CookieJar.fromJSON(JSON.stringify(cookieJar));
123
+ this.id = id;
124
+ this.maxAgeSecs = maxAgeSecs;
125
+ this.userData = userData;
126
+ this.maxErrorScore = maxErrorScore;
127
+ this.errorScoreDecrement = errorScoreDecrement;
128
+ // Internal
129
+ this.expiresAt = expiresAt;
130
+ this.createdAt = createdAt;
131
+ this.usageCount = usageCount; // indicates how many times the session has been used
132
+ this.errorScore = errorScore; // indicates number of markBaded request with the session
133
+ this.maxUsageCount = maxUsageCount;
134
+ this.sessionPool = sessionPool;
135
+ this._puppeteerCookieToTough = this._puppeteerCookieToTough.bind(this);
136
+ }
137
+ /**
138
+ * Indicates whether the session is blocked.
139
+ * Session is blocked once it reaches the `maxErrorScore`.
140
+ */
141
+ isBlocked() {
142
+ return this.errorScore >= this.maxErrorScore;
143
+ }
144
+ /**
145
+ * Indicates whether the session is expired.
146
+ * Session expiration is determined by the `maxAgeSecs`.
147
+ * Once the session is older than `createdAt + maxAgeSecs` the session is considered expired.
148
+ */
149
+ isExpired() {
150
+ return this.expiresAt <= new Date();
151
+ }
152
+ /**
153
+ * Indicates whether the session is used maximum number of times.
154
+ * Session maximum usage count can be changed by `maxUsageCount` parameter.
155
+ */
156
+ isMaxUsageCountReached() {
157
+ return this.usageCount >= this.maxUsageCount;
158
+ }
159
+ /**
160
+ * Indicates whether the session can be used for next requests.
161
+ * Session is usable when it is not expired, not blocked and the maximum usage count has not be reached.
162
+ */
163
+ isUsable() {
164
+ return !this.isBlocked() && !this.isExpired() && !this.isMaxUsageCountReached();
165
+ }
166
+ /**
167
+ * This method should be called after a successful session usage.
168
+ * It increases `usageCount` and potentially lowers the `errorScore` by the `errorScoreDecrement`.
169
+ */
170
+ markGood() {
171
+ this.usageCount += 1;
172
+ if (this.errorScore > 0) {
173
+ this.errorScore -= this.errorScoreDecrement;
174
+ }
175
+ this._maybeSelfRetire();
176
+ }
177
+ /**
178
+ * Gets session state for persistence in KeyValueStore.
179
+ * @returns Represents session internal state.
180
+ */
181
+ getState() {
182
+ return {
183
+ id: this.id,
184
+ cookieJar: this.cookieJar.toJSON(),
185
+ userData: this.userData,
186
+ maxErrorScore: this.maxErrorScore,
187
+ errorScoreDecrement: this.errorScoreDecrement,
188
+ expiresAt: this.expiresAt.toISOString(),
189
+ createdAt: this.createdAt.toISOString(),
190
+ usageCount: this.usageCount,
191
+ maxUsageCount: this.maxUsageCount,
192
+ errorScore: this.errorScore,
193
+ };
194
+ }
195
+ /**
196
+ * Marks session as blocked and emits event on the `SessionPool`
197
+ * This method should be used if the session usage was unsuccessful
198
+ * and you are sure that it is because of the session configuration and not any external matters.
199
+ * For example when server returns 403 status code.
200
+ * If the session does not work due to some external factors as server error such as 5XX you probably want to use `markBad` method.
201
+ */
202
+ retire() {
203
+ // mark it as an invalid by increasing the error score count.
204
+ this.errorScore += this.maxErrorScore;
205
+ this.usageCount += 1;
206
+ // emit event so we can retire browser in puppeteer pool
207
+ this.sessionPool.emit(events_1.EVENT_SESSION_RETIRED, this);
208
+ }
209
+ /**
210
+ * Increases usage and error count.
211
+ * Should be used when the session has been used unsuccessfully. For example because of timeouts.
212
+ */
213
+ markBad() {
214
+ this.errorScore += 1;
215
+ this.usageCount += 1;
216
+ this._maybeSelfRetire();
217
+ }
218
+ /**
219
+ * With certain status codes: `401`, `403` or `429` we can be certain
220
+ * that the target website is blocking us. This function helps to do this conveniently
221
+ * by retiring the session when such code is received. Optionally the default status
222
+ * codes can be extended in the second parameter.
223
+ * @param statusCode HTTP status code.
224
+ * @param [blockedStatusCodes] Custom HTTP status codes that means blocking on particular website.
225
+ * @returns Whether the session was retired.
226
+ */
227
+ retireOnBlockedStatusCodes(statusCode, blockedStatusCodes = []) {
228
+ const isBlocked = constants_1.STATUS_CODES_BLOCKED.concat(blockedStatusCodes).includes(statusCode);
229
+ if (isBlocked) {
230
+ this.retire();
231
+ }
232
+ return isBlocked;
233
+ }
234
+ /**
235
+ * Saves cookies from an HTTP response to be used with the session.
236
+ * It expects an object with a `headers` property that's either an `Object`
237
+ * (typical Node.js responses) or a `Function` (Puppeteer Response).
238
+ *
239
+ * It then parses and saves the cookies from the `set-cookie` header, if available.
240
+ */
241
+ setCookiesFromResponse(response) {
242
+ try {
243
+ const cookies = (0, session_utils_1.getCookiesFromResponse)(response).filter((c) => c);
244
+ this._setCookies(cookies, typeof response.url === 'function' ? response.url() : response.url);
245
+ }
246
+ catch (e) {
247
+ const err = e;
248
+ // if invalid Cookie header is provided just log the exception.
249
+ this.log.exception(err, 'Could not get cookies from response');
250
+ }
251
+ }
252
+ /**
253
+ * Saves an array with cookie objects to be used with the session.
254
+ * The objects should be in the format that
255
+ * [Puppeteer uses](https://pptr.dev/#?product=Puppeteer&version=v2.0.0&show=api-pagecookiesurls),
256
+ * but you can also use this function to set cookies manually:
257
+ *
258
+ * ```
259
+ * [
260
+ * { name: 'cookie1', value: 'my-cookie' },
261
+ * { name: 'cookie2', value: 'your-cookie' }
262
+ * ]
263
+ * ```
264
+ */
265
+ setPuppeteerCookies(cookies, url) {
266
+ const normalizedCookies = cookies.map(this._puppeteerCookieToTough);
267
+ this._setCookies(normalizedCookies, url);
268
+ }
269
+ /**
270
+ * Returns cookies in a format compatible with puppeteer and ready to be used with `page.setCookie`.
271
+ * @param url website url. Only cookies stored for this url will be returned
272
+ */
273
+ getPuppeteerCookies(url) {
274
+ const cookies = this.cookieJar.getCookiesSync(url);
275
+ return cookies.map(this._toughCookieToPuppeteer);
276
+ }
277
+ /**
278
+ * Returns cookies saved with the session in the typical
279
+ * key1=value1; key2=value2 format, ready to be used in
280
+ * a cookie header or elsewhere.
281
+ * @returns Represents `Cookie` header.
282
+ */
283
+ getCookieString(url) {
284
+ return this.cookieJar.getCookieStringSync(url, {});
285
+ }
286
+ /**
287
+ * Transforms puppeteer cookie to tough-cookie.
288
+ * @param puppeteerCookie Cookie from puppeteer `page.cookies` method.
289
+ */
290
+ _puppeteerCookieToTough(puppeteerCookie) {
291
+ const isExpiresValid = puppeteerCookie.expires && typeof puppeteerCookie.expires === 'number' && puppeteerCookie.expires > 0;
292
+ const expires = isExpiresValid ? new Date(puppeteerCookie.expires * 1000) : this._getDefaultCookieExpirationDate(this.maxAgeSecs);
293
+ const domain = typeof puppeteerCookie.domain === 'string' && puppeteerCookie.domain.startsWith('.')
294
+ ? puppeteerCookie.domain.slice(1)
295
+ : puppeteerCookie.domain;
296
+ return new tough_cookie_1.Cookie({
297
+ key: puppeteerCookie.name,
298
+ value: puppeteerCookie.value,
299
+ expires,
300
+ domain,
301
+ path: puppeteerCookie.path,
302
+ secure: puppeteerCookie.secure,
303
+ httpOnly: puppeteerCookie.httpOnly,
304
+ });
305
+ }
306
+ /**
307
+ * Transforms tough-cookie to puppeteer cookie.
308
+ * @param toughCookie Cookie from CookieJar
309
+ * @return Cookie from Puppeteer
310
+ */
311
+ _toughCookieToPuppeteer(toughCookie) {
312
+ return {
313
+ name: toughCookie.key,
314
+ value: toughCookie.value,
315
+ // Puppeteer and Playwright expect 'expires' to be 'Unix time in seconds', not ms
316
+ expires: new Date(toughCookie.expires).getTime() / 1000,
317
+ domain: toughCookie.domain,
318
+ path: toughCookie.path,
319
+ secure: toughCookie.secure,
320
+ httpOnly: toughCookie.httpOnly,
321
+ };
322
+ }
323
+ /**
324
+ * Sets cookies.
325
+ */
326
+ _setCookies(cookies, url) {
327
+ const errorMessages = [];
328
+ for (const cookie of cookies) {
329
+ try {
330
+ this.cookieJar.setCookieSync(cookie, url, { ignoreError: false });
331
+ }
332
+ catch (e) {
333
+ const err = e;
334
+ errorMessages.push(err.message);
335
+ }
336
+ }
337
+ // if invalid cookies are provided just log the exception. No need to retry the request automatically.
338
+ if (errorMessages.length) {
339
+ this.log.debug('Could not set cookies.', { errorMessages });
340
+ }
341
+ }
342
+ /**
343
+ * Calculate cookie expiration date
344
+ * @param maxAgeSecs
345
+ * @returns Calculated date by session max age seconds.
346
+ */
347
+ _getDefaultCookieExpirationDate(maxAgeSecs) {
348
+ return new Date(Date.now() + (maxAgeSecs * 1000));
349
+ }
350
+ /**
351
+ * Checks if session is not usable. if it is not retires the session.
352
+ */
353
+ _maybeSelfRetire() {
354
+ if (!this.isUsable()) {
355
+ this.retire();
356
+ }
357
+ }
358
+ }
359
+ exports.Session = Session;
360
+ //# sourceMappingURL=session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.js","sourceRoot":"","sources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