// This is an automatically generated code sample.
// To make this code sample work in your Oracle Cloud tenancy,
// please replace the values for any parameters whose current values do not fit
// your use case (such as resource IDs, strings containing ‘EXAMPLE’ or ‘unique_id’, and
// boolean, number, and enum parameters with values not fitting your use case).

import * as waf from "oci-waf";
import common = require("oci-common");

// Create a default authentication provider that uses the DEFAULT
// profile in the configuration file.
// Refer to <see href="https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File>the public documentation</see> on how to prepare a configuration file.

const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();

(async () => {
  try {
    // Create a service client
    const client = new waf.WafClient({ authenticationDetailsProvider: provider });

    // Create a request and dependent object(s).
    const createWebAppFirewallPolicyDetails = {
      displayName: "EXAMPLE-displayName-Value",
      compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
      actions: [
        {
          type: "RETURN_HTTP_RESPONSE",
          code: 203,
          headers: [
            {
              name: "EXAMPLE-name-Value",
              value: "EXAMPLE-value-Value"
            }
          ],
          body: {
            type: "STATIC_TEXT",
            text: "EXAMPLE-text-Value"
          },
          name: "EXAMPLE-name-Value"
        }
      ],
      requestAccessControl: {
        defaultActionName: "EXAMPLE-defaultActionName-Value",
        rules: [
          {
            type: "ACCESS_CONTROL",
            name: "EXAMPLE-name-Value",
            conditionLanguage: waf.models.WebAppFirewallPolicyRule.ConditionLanguage.Jmespath,
            condition: "EXAMPLE-condition-Value",
            actionName: "EXAMPLE-actionName-Value"
          }
        ]
      },
      requestRateLimiting: {
        rules: [
          {
            type: "REQUEST_RATE_LIMITING",
            configurations: [
              {
                periodInSeconds: 804,
                requestsLimit: 761,
                actionDurationInSeconds: 71995
              }
            ],
            name: "EXAMPLE-name-Value",
            conditionLanguage: waf.models.WebAppFirewallPolicyRule.ConditionLanguage.Jmespath,
            condition: "EXAMPLE-condition-Value",
            actionName: "EXAMPLE-actionName-Value"
          }
        ]
      },
      requestProtection: {
        rules: [
          {
            type: "PROTECTION",
            protectionCapabilities: [
              {
                key: "EXAMPLE-key-Value",
                version: 729,
                exclusions: {
                  requestCookies: ["EXAMPLE--Value"],
                  args: ["EXAMPLE--Value"]
                },
                actionName: "EXAMPLE-actionName-Value",
                collaborativeActionThreshold: 324,
                collaborativeWeights: [
                  {
                    key: "EXAMPLE-key-Value",
                    weight: 922
                  }
                ]
              }
            ],
            protectionCapabilitySettings: {
              maxNumberOfArguments: 7800,
              maxSingleArgumentLength: 652013,
              maxTotalArgumentLength: 5344678,
              maxHttpRequestHeaders: 518,
              maxHttpRequestHeaderLength: 28082,
              allowedHttpMethods: ["EXAMPLE--Value"]
            },
            isBodyInspectionEnabled: true,
            name: "EXAMPLE-name-Value",
            conditionLanguage: waf.models.WebAppFirewallPolicyRule.ConditionLanguage.Jmespath,
            condition: "EXAMPLE-condition-Value",
            actionName: "EXAMPLE-actionName-Value"
          }
        ],
        bodyInspectionSizeLimitInBytes: 740,
        bodyInspectionSizeLimitExceededActionName:
          "EXAMPLE-bodyInspectionSizeLimitExceededActionName-Value"
      },
      responseAccessControl: {
        rules: [
          {
            type: "ACCESS_CONTROL",
            name: "EXAMPLE-name-Value",
            conditionLanguage: waf.models.WebAppFirewallPolicyRule.ConditionLanguage.Jmespath,
            condition: "EXAMPLE-condition-Value",
            actionName: "EXAMPLE-actionName-Value"
          }
        ]
      },
      responseProtection: {
        rules: [
          {
            type: "PROTECTION",
            protectionCapabilities: [
              {
                key: "EXAMPLE-key-Value",
                version: 506,
                exclusions: {
                  requestCookies: ["EXAMPLE--Value"],
                  args: ["EXAMPLE--Value"]
                },
                actionName: "EXAMPLE-actionName-Value",
                collaborativeActionThreshold: 137,
                collaborativeWeights: [
                  {
                    key: "EXAMPLE-key-Value",
                    weight: 945
                  }
                ]
              }
            ],
            protectionCapabilitySettings: {
              maxNumberOfArguments: 2075,
              maxSingleArgumentLength: 182259,
              maxTotalArgumentLength: 30935969,
              maxHttpRequestHeaders: 23,
              maxHttpRequestHeaderLength: 394513,
              allowedHttpMethods: ["EXAMPLE--Value"]
            },
            isBodyInspectionEnabled: true,
            name: "EXAMPLE-name-Value",
            conditionLanguage: waf.models.WebAppFirewallPolicyRule.ConditionLanguage.Jmespath,
            condition: "EXAMPLE-condition-Value",
            actionName: "EXAMPLE-actionName-Value"
          }
        ]
      },
      freeformTags: {
        EXAMPLE_KEY_JwyfE: "EXAMPLE_VALUE_DG9sHdYtQhnmR3omQLE8"
      },
      definedTags: {
        EXAMPLE_KEY_SaA53: {
          EXAMPLE_KEY_tOhJs: "EXAMPLE--Value"
        }
      },
      systemTags: {
        EXAMPLE_KEY_6OaRl: {
          EXAMPLE_KEY_axD2N: "EXAMPLE--Value"
        }
      }
    };

    const createWebAppFirewallPolicyRequest: waf.requests.CreateWebAppFirewallPolicyRequest = {
      createWebAppFirewallPolicyDetails: createWebAppFirewallPolicyDetails,
      opcRetryToken: "EXAMPLE-opcRetryToken-Value",
      opcRequestId: "5ONYFZETKXCUW6BLQNRP<unique_ID>"
    };

    // Send request to the Client.
    const createWebAppFirewallPolicyResponse = await client.createWebAppFirewallPolicy(
      createWebAppFirewallPolicyRequest
    );
  } catch (error) {
    console.log("createWebAppFirewallPolicy Failed with error  " + error);
  }
})();