|
2 | 2 |
|
3 | 3 | import { APIResource } from '../../resource'; |
4 | 4 | import * as Core from '../../core'; |
5 | | -import { V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination'; |
| 5 | +import { SinglePage, V4PagePaginationArray, type V4PagePaginationArrayParams } from '../../pagination'; |
6 | 6 |
|
7 | 7 | export class Rules extends APIResource { |
8 | 8 | /** |
@@ -82,6 +82,81 @@ export class Rules extends APIResource { |
82 | 82 | )._thenUnwrap((obj) => obj.result); |
83 | 83 | } |
84 | 84 |
|
| 85 | + /** |
| 86 | + * Create zone token validation rules. |
| 87 | + * |
| 88 | + * A request can create multiple Token Validation Rules. |
| 89 | + * |
| 90 | + * @example |
| 91 | + * ```ts |
| 92 | + * // Automatically fetches more pages as needed. |
| 93 | + * for await (const tokenValidationRule of client.tokenValidation.rules.bulkCreate( |
| 94 | + * { |
| 95 | + * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 96 | + * body: [ |
| 97 | + * { |
| 98 | + * action: 'log', |
| 99 | + * description: |
| 100 | + * 'Long description for Token Validation Rule', |
| 101 | + * enabled: true, |
| 102 | + * expression: |
| 103 | + * 'is_jwt_valid("52973293-cb04-4a97-8f55-e7d2ad1107dd") or is_jwt_valid("46eab8d1-6376-45e3-968f-2c649d77d423")', |
| 104 | + * selector: {}, |
| 105 | + * title: 'Example Token Validation Rule', |
| 106 | + * }, |
| 107 | + * ], |
| 108 | + * }, |
| 109 | + * )) { |
| 110 | + * // ... |
| 111 | + * } |
| 112 | + * ``` |
| 113 | + */ |
| 114 | + bulkCreate( |
| 115 | + params: RuleBulkCreateParams, |
| 116 | + options?: Core.RequestOptions, |
| 117 | + ): Core.PagePromise<TokenValidationRulesSinglePage, TokenValidationRule> { |
| 118 | + const { zone_id, body } = params; |
| 119 | + return this._client.getAPIList( |
| 120 | + `/zones/${zone_id}/token_validation/rules/bulk`, |
| 121 | + TokenValidationRulesSinglePage, |
| 122 | + { body: body, method: 'post', ...options }, |
| 123 | + ); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Edit token validation rules. |
| 128 | + * |
| 129 | + * A request can update multiple Token Validation Rules. |
| 130 | + * |
| 131 | + * Rules can be re-ordered using the `position` field. |
| 132 | + * |
| 133 | + * Returns all updated rules. |
| 134 | + * |
| 135 | + * @example |
| 136 | + * ```ts |
| 137 | + * // Automatically fetches more pages as needed. |
| 138 | + * for await (const tokenValidationRule of client.tokenValidation.rules.bulkEdit( |
| 139 | + * { |
| 140 | + * zone_id: '023e105f4ecef8ad9ca31a8372d0c353', |
| 141 | + * body: [{ id: '0d9bf70c-92e1-4bb3-9411-34a3bcc59003' }], |
| 142 | + * }, |
| 143 | + * )) { |
| 144 | + * // ... |
| 145 | + * } |
| 146 | + * ``` |
| 147 | + */ |
| 148 | + bulkEdit( |
| 149 | + params: RuleBulkEditParams, |
| 150 | + options?: Core.RequestOptions, |
| 151 | + ): Core.PagePromise<TokenValidationRulesSinglePage, TokenValidationRule> { |
| 152 | + const { zone_id, body } = params; |
| 153 | + return this._client.getAPIList( |
| 154 | + `/zones/${zone_id}/token_validation/rules/bulk`, |
| 155 | + TokenValidationRulesSinglePage, |
| 156 | + { body: body, method: 'patch', ...options }, |
| 157 | + ); |
| 158 | + } |
| 159 | + |
85 | 160 | /** |
86 | 161 | * Edit a zone token validation rule. |
87 | 162 | * |
@@ -136,6 +211,8 @@ export class Rules extends APIResource { |
136 | 211 |
|
137 | 212 | export class TokenValidationRulesV4PagePaginationArray extends V4PagePaginationArray<TokenValidationRule> {} |
138 | 213 |
|
| 214 | +export class TokenValidationRulesSinglePage extends SinglePage<TokenValidationRule> {} |
| 215 | + |
139 | 216 | /** |
140 | 217 | * A Token Validation rule that can enforce security policies using JWT Tokens. |
141 | 218 | */ |
@@ -357,6 +434,226 @@ export interface RuleDeleteParams { |
357 | 434 | zone_id: string; |
358 | 435 | } |
359 | 436 |
|
| 437 | +export interface RuleBulkCreateParams { |
| 438 | + /** |
| 439 | + * Path param: Identifier. |
| 440 | + */ |
| 441 | + zone_id: string; |
| 442 | + |
| 443 | + /** |
| 444 | + * Body param: |
| 445 | + */ |
| 446 | + body: Array<RuleBulkCreateParams.Body>; |
| 447 | +} |
| 448 | + |
| 449 | +export namespace RuleBulkCreateParams { |
| 450 | + /** |
| 451 | + * A Token Validation rule that can enforce security policies using JWT Tokens. |
| 452 | + */ |
| 453 | + export interface Body { |
| 454 | + /** |
| 455 | + * Action to take on requests that match operations included in `selector` and fail |
| 456 | + * `expression`. |
| 457 | + */ |
| 458 | + action: 'log' | 'block'; |
| 459 | + |
| 460 | + /** |
| 461 | + * A human-readable description that gives more details than `title`. |
| 462 | + */ |
| 463 | + description: string; |
| 464 | + |
| 465 | + /** |
| 466 | + * Toggle rule on or off. |
| 467 | + */ |
| 468 | + enabled: boolean; |
| 469 | + |
| 470 | + /** |
| 471 | + * Rule expression. Requests that fail to match this expression will be subject to |
| 472 | + * `action`. |
| 473 | + * |
| 474 | + * For details on expressions, see the |
| 475 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 476 | + */ |
| 477 | + expression: string; |
| 478 | + |
| 479 | + /** |
| 480 | + * Select operations covered by this rule. |
| 481 | + * |
| 482 | + * For details on selectors, see the |
| 483 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 484 | + */ |
| 485 | + selector: Body.Selector; |
| 486 | + |
| 487 | + /** |
| 488 | + * A human-readable name for the rule. |
| 489 | + */ |
| 490 | + title: string; |
| 491 | + } |
| 492 | + |
| 493 | + export namespace Body { |
| 494 | + /** |
| 495 | + * Select operations covered by this rule. |
| 496 | + * |
| 497 | + * For details on selectors, see the |
| 498 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 499 | + */ |
| 500 | + export interface Selector { |
| 501 | + /** |
| 502 | + * Ignore operations that were otherwise included by `include`. |
| 503 | + */ |
| 504 | + exclude?: Array<Selector.Exclude> | null; |
| 505 | + |
| 506 | + /** |
| 507 | + * Select all matching operations. |
| 508 | + */ |
| 509 | + include?: Array<Selector.Include> | null; |
| 510 | + } |
| 511 | + |
| 512 | + export namespace Selector { |
| 513 | + export interface Exclude { |
| 514 | + /** |
| 515 | + * Excluded operation IDs. |
| 516 | + */ |
| 517 | + operation_ids?: Array<string>; |
| 518 | + } |
| 519 | + |
| 520 | + export interface Include { |
| 521 | + /** |
| 522 | + * Included hostnames. |
| 523 | + */ |
| 524 | + host?: Array<string>; |
| 525 | + } |
| 526 | + } |
| 527 | + } |
| 528 | +} |
| 529 | + |
| 530 | +export interface RuleBulkEditParams { |
| 531 | + /** |
| 532 | + * Path param: Identifier. |
| 533 | + */ |
| 534 | + zone_id: string; |
| 535 | + |
| 536 | + /** |
| 537 | + * Body param: |
| 538 | + */ |
| 539 | + body: Array<RuleBulkEditParams.Body>; |
| 540 | +} |
| 541 | + |
| 542 | +export namespace RuleBulkEditParams { |
| 543 | + export interface Body { |
| 544 | + /** |
| 545 | + * Rule ID this patch applies to |
| 546 | + */ |
| 547 | + id: string; |
| 548 | + |
| 549 | + /** |
| 550 | + * Action to take on requests that match operations included in `selector` and fail |
| 551 | + * `expression`. |
| 552 | + */ |
| 553 | + action?: 'log' | 'block'; |
| 554 | + |
| 555 | + /** |
| 556 | + * A human-readable description that gives more details than `title`. |
| 557 | + */ |
| 558 | + description?: string; |
| 559 | + |
| 560 | + /** |
| 561 | + * Toggle rule on or off. |
| 562 | + */ |
| 563 | + enabled?: boolean; |
| 564 | + |
| 565 | + /** |
| 566 | + * Rule expression. Requests that fail to match this expression will be subject to |
| 567 | + * `action`. |
| 568 | + * |
| 569 | + * For details on expressions, see the |
| 570 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 571 | + */ |
| 572 | + expression?: string; |
| 573 | + |
| 574 | + /** |
| 575 | + * Update rule order among zone rules. |
| 576 | + */ |
| 577 | + position?: Body.APIShieldIndex | Body.APIShieldBefore | Body.APIShieldAfter; |
| 578 | + |
| 579 | + /** |
| 580 | + * Select operations covered by this rule. |
| 581 | + * |
| 582 | + * For details on selectors, see the |
| 583 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 584 | + */ |
| 585 | + selector?: Body.Selector; |
| 586 | + |
| 587 | + /** |
| 588 | + * A human-readable name for the rule. |
| 589 | + */ |
| 590 | + title?: string; |
| 591 | + } |
| 592 | + |
| 593 | + export namespace Body { |
| 594 | + export interface APIShieldIndex { |
| 595 | + /** |
| 596 | + * Move rule to this position |
| 597 | + */ |
| 598 | + index: number; |
| 599 | + } |
| 600 | + |
| 601 | + /** |
| 602 | + * Move rule to after rule with ID. |
| 603 | + */ |
| 604 | + export interface APIShieldBefore { |
| 605 | + /** |
| 606 | + * Move rule to before rule with this ID. |
| 607 | + */ |
| 608 | + before?: string; |
| 609 | + } |
| 610 | + |
| 611 | + /** |
| 612 | + * Move rule to before rule with ID. |
| 613 | + */ |
| 614 | + export interface APIShieldAfter { |
| 615 | + /** |
| 616 | + * Move rule to after rule with this ID. |
| 617 | + */ |
| 618 | + after?: string; |
| 619 | + } |
| 620 | + |
| 621 | + /** |
| 622 | + * Select operations covered by this rule. |
| 623 | + * |
| 624 | + * For details on selectors, see the |
| 625 | + * [Cloudflare Docs](https://developers.cloudflare.com/api-shield/security/jwt-validation/). |
| 626 | + */ |
| 627 | + export interface Selector { |
| 628 | + /** |
| 629 | + * Ignore operations that were otherwise included by `include`. |
| 630 | + */ |
| 631 | + exclude?: Array<Selector.Exclude> | null; |
| 632 | + |
| 633 | + /** |
| 634 | + * Select all matching operations. |
| 635 | + */ |
| 636 | + include?: Array<Selector.Include> | null; |
| 637 | + } |
| 638 | + |
| 639 | + export namespace Selector { |
| 640 | + export interface Exclude { |
| 641 | + /** |
| 642 | + * Excluded operation IDs. |
| 643 | + */ |
| 644 | + operation_ids?: Array<string>; |
| 645 | + } |
| 646 | + |
| 647 | + export interface Include { |
| 648 | + /** |
| 649 | + * Included hostnames. |
| 650 | + */ |
| 651 | + host?: Array<string>; |
| 652 | + } |
| 653 | + } |
| 654 | + } |
| 655 | +} |
| 656 | + |
360 | 657 | export interface RuleEditParams { |
361 | 658 | /** |
362 | 659 | * Path param: Identifier. |
@@ -478,15 +775,19 @@ export interface RuleGetParams { |
478 | 775 | } |
479 | 776 |
|
480 | 777 | Rules.TokenValidationRulesV4PagePaginationArray = TokenValidationRulesV4PagePaginationArray; |
| 778 | +Rules.TokenValidationRulesSinglePage = TokenValidationRulesSinglePage; |
481 | 779 |
|
482 | 780 | export declare namespace Rules { |
483 | 781 | export { |
484 | 782 | type TokenValidationRule as TokenValidationRule, |
485 | 783 | type RuleDeleteResponse as RuleDeleteResponse, |
486 | 784 | TokenValidationRulesV4PagePaginationArray as TokenValidationRulesV4PagePaginationArray, |
| 785 | + TokenValidationRulesSinglePage as TokenValidationRulesSinglePage, |
487 | 786 | type RuleCreateParams as RuleCreateParams, |
488 | 787 | type RuleListParams as RuleListParams, |
489 | 788 | type RuleDeleteParams as RuleDeleteParams, |
| 789 | + type RuleBulkCreateParams as RuleBulkCreateParams, |
| 790 | + type RuleBulkEditParams as RuleBulkEditParams, |
490 | 791 | type RuleEditParams as RuleEditParams, |
491 | 792 | type RuleGetParams as RuleGetParams, |
492 | 793 | }; |
|
0 commit comments