@castleio/sdk 3.0.0 → 3.2.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 +3 -2
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +13 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
|
@@ -342,6 +342,7 @@ All HTTP/API exceptions inherit from `APIError`. `ConfigurationError` (setup pro
|
|
|
342
342
|
| `InvalidParametersError` | `422` response with validation details. |
|
|
343
343
|
| `InvalidRequestTokenError` | `422` — the `request_token` is missing or invalid. |
|
|
344
344
|
| `RateLimitError` | `429` — back off and retry. |
|
|
345
|
+
| `PaymentRequiredError` | `402` response. |
|
|
345
346
|
| `InternalServerError` | `5xx` response from Castle. |
|
|
346
347
|
| `WebhookVerificationError` | A webhook signature did not match. |
|
|
347
348
|
|
package/dist/index.d.mts
CHANGED
|
@@ -940,6 +940,9 @@ declare class InvalidRequestTokenError extends InvalidParametersError {
|
|
|
940
940
|
declare class RateLimitError extends APIError {
|
|
941
941
|
constructor(message: string);
|
|
942
942
|
}
|
|
943
|
+
declare class PaymentRequiredError extends APIError {
|
|
944
|
+
constructor(message: string);
|
|
945
|
+
}
|
|
943
946
|
declare class InternalServerError extends APIError {
|
|
944
947
|
constructor(message: string);
|
|
945
948
|
}
|
|
@@ -963,4 +966,4 @@ declare const SecureModeService: {
|
|
|
963
966
|
call: (userId: string, configuration: Configuration) => string;
|
|
964
967
|
};
|
|
965
968
|
|
|
966
|
-
export { APIError, Action, type AddressPayload, BadRequestError, type BatchUpsertListItemsPayload, type Bucket, Castle, type ConfigurationProperties as CastleConfiguration, ConfigurationError, ContextPrepareService, type CountBucket, type CountListItemsPayload, type CreateListItemPayload, type CreateListPayload, DEFAULT_ALLOWLIST, DEFAULT_API_URL, DEFAULT_TIMEOUT, type DataType, type DateHistogramBucket, type DeleteUserDataPayload, type Device, type Event, EventAuthenticationMethod, EventSignal, EventStatus, EventType, FailoverStrategy, type FilterPayload, ForbiddenError, type FullListItemPayload, type Func, type GetEventsSchemaResponse, type GroupEvent, type GroupEventsPayload, type GroupEventsResponse, InternalServerError, InvalidParametersError, InvalidRequestTokenError, type List, type ListItem, type ListItemAuthorType, type ListItemMode, type ListItemPayload, type ListPayload, type LogPayload, NotFoundError, type NumberLike, type Op, PayloadPrepareService, type RangeBucket, RateLimitError, type RequestUserDataPayload, type RiskPayload, type RiskPolicy, type RiskPolicyFailover, type SearchEventsExistsQueryFilter, type SearchEventsOrQueryFilter, type SearchEventsPayload, type SearchEventsQueryFilter, SearchEventsQueryFilterOperator, SearchEventsQueryType, type SearchEventsRangeQueryFilter, type SearchEventsRelativeRangeQueryFilter, type SearchEventsResponse, type SearchField, type SearchListItemsPayload, type SearchListsPayload, SecureModeService, type Signals, type Source, TRUSTED_PROXIES, type TransactionPayload, type Transform, UnauthorizedError, type UpdateListItemPayload, type UpdateListPayload, UserUnauthorizedError, WebhookVerificationError, WebhookVerifyService };
|
|
969
|
+
export { APIError, Action, type AddressPayload, BadRequestError, type BatchUpsertListItemsPayload, type Bucket, Castle, type ConfigurationProperties as CastleConfiguration, ConfigurationError, ContextPrepareService, type CountBucket, type CountListItemsPayload, type CreateListItemPayload, type CreateListPayload, DEFAULT_ALLOWLIST, DEFAULT_API_URL, DEFAULT_TIMEOUT, type DataType, type DateHistogramBucket, type DeleteUserDataPayload, type Device, type Event, EventAuthenticationMethod, EventSignal, EventStatus, EventType, FailoverStrategy, type FilterPayload, ForbiddenError, type FullListItemPayload, type Func, type GetEventsSchemaResponse, type GroupEvent, type GroupEventsPayload, type GroupEventsResponse, InternalServerError, InvalidParametersError, InvalidRequestTokenError, type List, type ListItem, type ListItemAuthorType, type ListItemMode, type ListItemPayload, type ListPayload, type LogPayload, NotFoundError, type NumberLike, type Op, PayloadPrepareService, PaymentRequiredError, type RangeBucket, RateLimitError, type RequestUserDataPayload, type RiskPayload, type RiskPolicy, type RiskPolicyFailover, type SearchEventsExistsQueryFilter, type SearchEventsOrQueryFilter, type SearchEventsPayload, type SearchEventsQueryFilter, SearchEventsQueryFilterOperator, SearchEventsQueryType, type SearchEventsRangeQueryFilter, type SearchEventsRelativeRangeQueryFilter, type SearchEventsResponse, type SearchField, type SearchListItemsPayload, type SearchListsPayload, SecureModeService, type Signals, type Source, TRUSTED_PROXIES, type TransactionPayload, type Transform, UnauthorizedError, type UpdateListItemPayload, type UpdateListPayload, UserUnauthorizedError, WebhookVerificationError, WebhookVerifyService };
|
package/dist/index.d.ts
CHANGED
|
@@ -940,6 +940,9 @@ declare class InvalidRequestTokenError extends InvalidParametersError {
|
|
|
940
940
|
declare class RateLimitError extends APIError {
|
|
941
941
|
constructor(message: string);
|
|
942
942
|
}
|
|
943
|
+
declare class PaymentRequiredError extends APIError {
|
|
944
|
+
constructor(message: string);
|
|
945
|
+
}
|
|
943
946
|
declare class InternalServerError extends APIError {
|
|
944
947
|
constructor(message: string);
|
|
945
948
|
}
|
|
@@ -963,4 +966,4 @@ declare const SecureModeService: {
|
|
|
963
966
|
call: (userId: string, configuration: Configuration) => string;
|
|
964
967
|
};
|
|
965
968
|
|
|
966
|
-
export { APIError, Action, type AddressPayload, BadRequestError, type BatchUpsertListItemsPayload, type Bucket, Castle, type ConfigurationProperties as CastleConfiguration, ConfigurationError, ContextPrepareService, type CountBucket, type CountListItemsPayload, type CreateListItemPayload, type CreateListPayload, DEFAULT_ALLOWLIST, DEFAULT_API_URL, DEFAULT_TIMEOUT, type DataType, type DateHistogramBucket, type DeleteUserDataPayload, type Device, type Event, EventAuthenticationMethod, EventSignal, EventStatus, EventType, FailoverStrategy, type FilterPayload, ForbiddenError, type FullListItemPayload, type Func, type GetEventsSchemaResponse, type GroupEvent, type GroupEventsPayload, type GroupEventsResponse, InternalServerError, InvalidParametersError, InvalidRequestTokenError, type List, type ListItem, type ListItemAuthorType, type ListItemMode, type ListItemPayload, type ListPayload, type LogPayload, NotFoundError, type NumberLike, type Op, PayloadPrepareService, type RangeBucket, RateLimitError, type RequestUserDataPayload, type RiskPayload, type RiskPolicy, type RiskPolicyFailover, type SearchEventsExistsQueryFilter, type SearchEventsOrQueryFilter, type SearchEventsPayload, type SearchEventsQueryFilter, SearchEventsQueryFilterOperator, SearchEventsQueryType, type SearchEventsRangeQueryFilter, type SearchEventsRelativeRangeQueryFilter, type SearchEventsResponse, type SearchField, type SearchListItemsPayload, type SearchListsPayload, SecureModeService, type Signals, type Source, TRUSTED_PROXIES, type TransactionPayload, type Transform, UnauthorizedError, type UpdateListItemPayload, type UpdateListPayload, UserUnauthorizedError, WebhookVerificationError, WebhookVerifyService };
|
|
969
|
+
export { APIError, Action, type AddressPayload, BadRequestError, type BatchUpsertListItemsPayload, type Bucket, Castle, type ConfigurationProperties as CastleConfiguration, ConfigurationError, ContextPrepareService, type CountBucket, type CountListItemsPayload, type CreateListItemPayload, type CreateListPayload, DEFAULT_ALLOWLIST, DEFAULT_API_URL, DEFAULT_TIMEOUT, type DataType, type DateHistogramBucket, type DeleteUserDataPayload, type Device, type Event, EventAuthenticationMethod, EventSignal, EventStatus, EventType, FailoverStrategy, type FilterPayload, ForbiddenError, type FullListItemPayload, type Func, type GetEventsSchemaResponse, type GroupEvent, type GroupEventsPayload, type GroupEventsResponse, InternalServerError, InvalidParametersError, InvalidRequestTokenError, type List, type ListItem, type ListItemAuthorType, type ListItemMode, type ListItemPayload, type ListPayload, type LogPayload, NotFoundError, type NumberLike, type Op, PayloadPrepareService, PaymentRequiredError, type RangeBucket, RateLimitError, type RequestUserDataPayload, type RiskPayload, type RiskPolicy, type RiskPolicyFailover, type SearchEventsExistsQueryFilter, type SearchEventsOrQueryFilter, type SearchEventsPayload, type SearchEventsQueryFilter, SearchEventsQueryFilterOperator, SearchEventsQueryType, type SearchEventsRangeQueryFilter, type SearchEventsRelativeRangeQueryFilter, type SearchEventsResponse, type SearchField, type SearchListItemsPayload, type SearchListsPayload, SecureModeService, type Signals, type Source, TRUSTED_PROXIES, type TransactionPayload, type Transform, UnauthorizedError, type UpdateListItemPayload, type UpdateListPayload, UserUnauthorizedError, WebhookVerificationError, WebhookVerifyService };
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ __export(index_exports, {
|
|
|
50
50
|
InvalidRequestTokenError: () => InvalidRequestTokenError,
|
|
51
51
|
NotFoundError: () => NotFoundError,
|
|
52
52
|
PayloadPrepareService: () => PayloadPrepareService,
|
|
53
|
+
PaymentRequiredError: () => PaymentRequiredError,
|
|
53
54
|
RateLimitError: () => RateLimitError,
|
|
54
55
|
SearchEventsQueryFilterOperator: () => SearchEventsQueryFilterOperator,
|
|
55
56
|
SearchEventsQueryType: () => SearchEventsQueryType,
|
|
@@ -145,6 +146,12 @@ var RateLimitError = class extends APIError {
|
|
|
145
146
|
this.name = "RateLimitError";
|
|
146
147
|
}
|
|
147
148
|
};
|
|
149
|
+
var PaymentRequiredError = class extends APIError {
|
|
150
|
+
constructor(message) {
|
|
151
|
+
super(message);
|
|
152
|
+
this.name = "PaymentRequiredError";
|
|
153
|
+
}
|
|
154
|
+
};
|
|
148
155
|
var InternalServerError = class extends APIError {
|
|
149
156
|
constructor(message) {
|
|
150
157
|
super(message);
|
|
@@ -210,6 +217,7 @@ var LoggerService = {
|
|
|
210
217
|
var RESPONSE_ERRORS = {
|
|
211
218
|
"400": BadRequestError,
|
|
212
219
|
"401": UnauthorizedError,
|
|
220
|
+
"402": PaymentRequiredError,
|
|
213
221
|
"403": ForbiddenError,
|
|
214
222
|
"404": NotFoundError,
|
|
215
223
|
"419": UserUnauthorizedError,
|
|
@@ -392,28 +400,6 @@ var HeadersExtractService = {
|
|
|
392
400
|
}
|
|
393
401
|
};
|
|
394
402
|
|
|
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
403
|
// src/constants.ts
|
|
418
404
|
var DEFAULT_API_URL = "https://api.castle.io/v1";
|
|
419
405
|
var DEFAULT_TIMEOUT = 1500;
|
|
@@ -507,25 +493,22 @@ var IPsExtractService = {
|
|
|
507
493
|
};
|
|
508
494
|
|
|
509
495
|
// package.json
|
|
510
|
-
var version = "3.
|
|
496
|
+
var version = "3.2.0";
|
|
511
497
|
|
|
512
498
|
// src/context/services/context-get-default.service.ts
|
|
513
|
-
var requestContextData = (request,
|
|
499
|
+
var requestContextData = (request, configuration) => {
|
|
514
500
|
if (isEmpty(request)) {
|
|
515
501
|
return {};
|
|
516
502
|
}
|
|
517
|
-
const cookiesForClientId = cookies || request.headers?.cookies;
|
|
518
503
|
return {
|
|
519
|
-
client_id: ClientIdExtractService.call(request.headers, cookiesForClientId) || false,
|
|
520
|
-
active: true,
|
|
521
504
|
headers: HeadersExtractService.call(request.headers, configuration),
|
|
522
505
|
ip: IPsExtractService.call(request.headers, configuration)
|
|
523
506
|
};
|
|
524
507
|
};
|
|
525
508
|
var ContextGetDefaultService = {
|
|
526
|
-
call: (request,
|
|
509
|
+
call: (request, configuration) => {
|
|
527
510
|
return {
|
|
528
|
-
...pickByTruthy(requestContextData(request,
|
|
511
|
+
...pickByTruthy(requestContextData(request, configuration)),
|
|
529
512
|
library: {
|
|
530
513
|
name: "castle-node",
|
|
531
514
|
version
|
|
@@ -539,7 +522,6 @@ var ContextPrepareService = {
|
|
|
539
522
|
call: (request, options, configuration) => {
|
|
540
523
|
const defaultContext = ContextGetDefaultService.call(
|
|
541
524
|
request,
|
|
542
|
-
options?.cookies,
|
|
543
525
|
configuration
|
|
544
526
|
);
|
|
545
527
|
return deepMerge(defaultContext, options?.context);
|
|
@@ -1551,6 +1533,7 @@ var PayloadPrepareService = {
|
|
|
1551
1533
|
InvalidRequestTokenError,
|
|
1552
1534
|
NotFoundError,
|
|
1553
1535
|
PayloadPrepareService,
|
|
1536
|
+
PaymentRequiredError,
|
|
1554
1537
|
RateLimitError,
|
|
1555
1538
|
SearchEventsQueryFilterOperator,
|
|
1556
1539
|
SearchEventsQueryType,
|