@castleio/sdk 3.0.0 → 3.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.
- package/README.md +2 -2
- package/dist/index.js +4 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ const castle = new Castle({ apiSecret: process.env.CASTLE_API_SECRET });
|
|
|
44
44
|
|
|
45
45
|
const context = ContextPrepareService.call(
|
|
46
46
|
req,
|
|
47
|
-
|
|
47
|
+
undefined,
|
|
48
48
|
castle.configuration
|
|
49
49
|
);
|
|
50
50
|
|
|
@@ -74,7 +74,7 @@ With CommonJS:
|
|
|
74
74
|
const { Castle, ContextPrepareService } = require('@castleio/sdk');
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
`ContextPrepareService.call(request, options, configuration)` extracts the IP
|
|
77
|
+
`ContextPrepareService.call(request, options, configuration)` extracts the IP and headers that Castle needs from a Node `request` object. See [Advanced configuration](#advanced-configuration) for how header allow/deny lists and proxy chains are resolved.
|
|
78
78
|
|
|
79
79
|
## Configuration
|
|
80
80
|
|
package/dist/index.js
CHANGED
|
@@ -392,28 +392,6 @@ var HeadersExtractService = {
|
|
|
392
392
|
}
|
|
393
393
|
};
|
|
394
394
|
|
|
395
|
-
// src/headers/services/headers-get-cookie.service.ts
|
|
396
|
-
var HeadersGetCookieService = {
|
|
397
|
-
call: (cookies, name) => {
|
|
398
|
-
if (!cookies) {
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
const pattern = new RegExp(`(?:^|\\s+)\\s?${name}=(.*?)(?:;|$)`);
|
|
402
|
-
const results = cookies.toString().match(pattern);
|
|
403
|
-
if (results && results.length === 2) {
|
|
404
|
-
return results[1];
|
|
405
|
-
}
|
|
406
|
-
return;
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
|
|
410
|
-
// src/client-id/services/client-id-extract.service.ts
|
|
411
|
-
var ClientIdExtractService = {
|
|
412
|
-
call: (headers = {}, cookies) => {
|
|
413
|
-
return headers["x-castle-client-id"] || HeadersGetCookieService.call(cookies, "__cid") || "";
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
|
|
417
395
|
// src/constants.ts
|
|
418
396
|
var DEFAULT_API_URL = "https://api.castle.io/v1";
|
|
419
397
|
var DEFAULT_TIMEOUT = 1500;
|
|
@@ -507,25 +485,22 @@ var IPsExtractService = {
|
|
|
507
485
|
};
|
|
508
486
|
|
|
509
487
|
// package.json
|
|
510
|
-
var version = "3.
|
|
488
|
+
var version = "3.1.0";
|
|
511
489
|
|
|
512
490
|
// src/context/services/context-get-default.service.ts
|
|
513
|
-
var requestContextData = (request,
|
|
491
|
+
var requestContextData = (request, configuration) => {
|
|
514
492
|
if (isEmpty(request)) {
|
|
515
493
|
return {};
|
|
516
494
|
}
|
|
517
|
-
const cookiesForClientId = cookies || request.headers?.cookies;
|
|
518
495
|
return {
|
|
519
|
-
client_id: ClientIdExtractService.call(request.headers, cookiesForClientId) || false,
|
|
520
|
-
active: true,
|
|
521
496
|
headers: HeadersExtractService.call(request.headers, configuration),
|
|
522
497
|
ip: IPsExtractService.call(request.headers, configuration)
|
|
523
498
|
};
|
|
524
499
|
};
|
|
525
500
|
var ContextGetDefaultService = {
|
|
526
|
-
call: (request,
|
|
501
|
+
call: (request, configuration) => {
|
|
527
502
|
return {
|
|
528
|
-
...pickByTruthy(requestContextData(request,
|
|
503
|
+
...pickByTruthy(requestContextData(request, configuration)),
|
|
529
504
|
library: {
|
|
530
505
|
name: "castle-node",
|
|
531
506
|
version
|
|
@@ -539,7 +514,6 @@ var ContextPrepareService = {
|
|
|
539
514
|
call: (request, options, configuration) => {
|
|
540
515
|
const defaultContext = ContextGetDefaultService.call(
|
|
541
516
|
request,
|
|
542
|
-
options?.cookies,
|
|
543
517
|
configuration
|
|
544
518
|
);
|
|
545
519
|
return deepMerge(defaultContext, options?.context);
|