// 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 waas from "oci-waas";
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 waas.WaasClient({ authenticationDetailsProvider: provider });

    // Create a request and dependent object(s).
    const wafConfig = {
      accessRules: [
        {
          name: "EXAMPLE-name-Value",
          criteria: [
            {
              condition: waas.models.AccessRuleCriteria.Condition.IpInList,
              value: "EXAMPLE-value-Value",
              isCaseSensitive: false
            }
          ],
          action: waas.models.AccessRule.Action.Bypass,
          blockAction: waas.models.AccessRule.BlockAction.SetResponseCode,
          blockResponseCode: 553,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          bypassChallenges: [waas.models.AccessRule.BypassChallenges.Captcha],
          redirectUrl: "EXAMPLE-redirectUrl-Value",
          redirectResponseCode: waas.models.AccessRule.RedirectResponseCode.MovedPermanently,
          captchaTitle: "EXAMPLE-captchaTitle-Value",
          captchaHeader: "EXAMPLE-captchaHeader-Value",
          captchaFooter: "EXAMPLE-captchaFooter-Value",
          captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value",
          responseHeaderManipulation: [
            {
              action: "REMOVE_HTTP_RESPONSE_HEADER",
              header: "EXAMPLE-header-Value"
            }
          ]
        }
      ],
      addressRateLimiting: {
        isEnabled: true,
        allowedRatePerAddress: 2332,
        maxDelayedCountPerAddress: 351,
        blockResponseCode: 432
      },
      captchas: [
        {
          url: "EXAMPLE-url-Value",
          sessionExpirationInSeconds: 39032,
          title: "EXAMPLE-title-Value",
          headerText: "EXAMPLE-headerText-Value",
          footerText: "EXAMPLE-footerText-Value",
          failureMessage: "EXAMPLE-failureMessage-Value",
          submitLabel: "EXAMPLE-submitLabel-Value"
        }
      ],
      deviceFingerprintChallenge: {
        isEnabled: true,
        action: waas.models.DeviceFingerprintChallenge.Action.Detect,
        failureThreshold: 714445,
        actionExpirationInSeconds: 224166,
        failureThresholdExpirationInSeconds: 145060,
        maxAddressCount: 9481,
        maxAddressCountExpirationInSeconds: 49346,
        challengeSettings: {
          blockAction: waas.models.BlockChallengeSettings.BlockAction.SetResponseCode,
          blockResponseCode: 917,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          captchaTitle: "EXAMPLE-captchaTitle-Value",
          captchaHeader: "EXAMPLE-captchaHeader-Value",
          captchaFooter: "EXAMPLE-captchaFooter-Value",
          captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
        }
      },
      goodBots: [
        {
          key: "EXAMPLE-key-Value",
          name: "EXAMPLE-name-Value",
          isEnabled: false,
          description: "EXAMPLE-description-Value"
        }
      ],
      humanInteractionChallenge: {
        isEnabled: true,
        action: waas.models.HumanInteractionChallenge.Action.Block,
        failureThreshold: 532936,
        actionExpirationInSeconds: 225623,
        failureThresholdExpirationInSeconds: 30160,
        interactionThreshold: 90,
        recordingPeriodInSeconds: 5825,
        setHttpHeader: {
          name: "EXAMPLE-name-Value",
          value: "EXAMPLE-value-Value"
        },
        challengeSettings: {
          blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowCaptcha,
          blockResponseCode: 721,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          captchaTitle: "EXAMPLE-captchaTitle-Value",
          captchaHeader: "EXAMPLE-captchaHeader-Value",
          captchaFooter: "EXAMPLE-captchaFooter-Value",
          captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
        },
        isNatEnabled: true
      },
      jsChallenge: {
        isEnabled: true,
        action: waas.models.JsChallenge.Action.Block,
        failureThreshold: 448539,
        actionExpirationInSeconds: 349379,
        setHttpHeader: {
          name: "EXAMPLE-name-Value",
          value: "EXAMPLE-value-Value"
        },
        challengeSettings: {
          blockAction: waas.models.BlockChallengeSettings.BlockAction.SetResponseCode,
          blockResponseCode: 151,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          captchaTitle: "EXAMPLE-captchaTitle-Value",
          captchaHeader: "EXAMPLE-captchaHeader-Value",
          captchaFooter: "EXAMPLE-captchaFooter-Value",
          captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value"
        },
        areRedirectsChallenged: false,
        criteria: [
          {
            condition: waas.models.AccessRuleCriteria.Condition.CountryIs,
            value: "EXAMPLE-value-Value",
            isCaseSensitive: false
          }
        ],
        isNatEnabled: true
      },
      origin: "EXAMPLE-origin-Value",
      cachingRules: [
        {
          key: "EXAMPLE-key-Value",
          name: "EXAMPLE-name-Value",
          action: waas.models.CachingRule.Action.BypassCache,
          cachingDuration: "EXAMPLE-cachingDuration-Value",
          isClientCachingEnabled: false,
          clientCachingDuration: "EXAMPLE-clientCachingDuration-Value",
          criteria: [
            {
              condition: waas.models.CachingRuleCriteria.Condition.UrlIs,
              value: "EXAMPLE-value-Value"
            }
          ]
        }
      ],
      customProtectionRules: [
        {
          id: "ocid1.test.oc1..<unique_ID>EXAMPLE-id-Value",
          action: waas.models.CustomProtectionRuleSetting.Action.Detect,
          exclusions: [
            {
              target: waas.models.ProtectionRuleExclusion.Target.Args,
              exclusions: ["EXAMPLE--Value"]
            }
          ]
        }
      ],
      originGroups: ["EXAMPLE--Value"],
      protectionRules: [
        {
          key: "EXAMPLE-key-Value",
          modSecurityRuleIds: ["EXAMPLE--Value"],
          name: "EXAMPLE-name-Value",
          description: "EXAMPLE-description-Value",
          action: waas.models.ProtectionRule.Action.Block,
          labels: ["EXAMPLE--Value"],
          exclusions: [
            {
              target: waas.models.ProtectionRuleExclusion.Target.Args,
              exclusions: ["EXAMPLE--Value"]
            }
          ]
        }
      ],
      protectionSettings: {
        blockAction: waas.models.ProtectionSettings.BlockAction.ShowErrorPage,
        blockResponseCode: 869,
        blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
        blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
        blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
        maxArgumentCount: 8055,
        maxNameLengthPerArgument: 80120,
        maxTotalNameLengthOfArguments: 354276,
        recommendationsPeriodInDays: 92,
        isResponseInspected: false,
        maxResponseSizeInKiB: 1372,
        allowedHttpMethods: [waas.models.ProtectionSettings.AllowedHttpMethods.Connect],
        mediaTypes: ["EXAMPLE--Value"]
      },
      threatFeeds: [
        {
          key: "EXAMPLE-key-Value",
          name: "EXAMPLE-name-Value",
          action: waas.models.ThreatFeed.Action.Block,
          description: "EXAMPLE-description-Value"
        }
      ],
      whitelists: [
        {
          name: "EXAMPLE-name-Value",
          addresses: ["EXAMPLE--Value"],
          addressLists: ["EXAMPLE--Value"]
        }
      ]
    };

    const updateWafConfigRequest: waas.requests.UpdateWafConfigRequest = {
      waasPolicyId: "ocid1.test.oc1..<unique_ID>EXAMPLE-waasPolicyId-Value",
      updateWafConfigDetails: wafConfig,
      opcRequestId: "RW75SQK8LIZEGANNOKRL<unique_ID>",
      opcRetryToken: "EXAMPLE-opcRetryToken-Value",
      ifMatch: "EXAMPLE-ifMatch-Value"
    };

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