// 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 createWaasPolicyDetails = {
      compartmentId: "ocid1.test.oc1..<unique_ID>EXAMPLE-compartmentId-Value",
      displayName: "EXAMPLE-displayName-Value",
      domain: "EXAMPLE-domain-Value",
      additionalDomains: ["EXAMPLE--Value"],
      origins: {
        EXAMPLE_KEY_l3gVh: {
          uri: "EXAMPLE-uri-Value",
          httpPort: 48,
          httpsPort: 436,
          customHeaders: [
            {
              name: "EXAMPLE-name-Value",
              value: "EXAMPLE-value-Value"
            }
          ]
        }
      },
      originGroups: {
        EXAMPLE_KEY_IotRu: {
          origins: [
            {
              origin: "EXAMPLE-origin-Value",
              weight: 88
            }
          ]
        }
      },
      policyConfig: {
        certificateId: "ocid1.test.oc1..<unique_ID>EXAMPLE-certificateId-Value",
        isHttpsEnabled: false,
        isHttpsForced: false,
        tlsProtocols: [waas.models.PolicyConfig.TlsProtocols.TlsV13],
        isOriginCompressionEnabled: false,
        isBehindCdn: false,
        clientAddressHeader: waas.models.PolicyConfig.ClientAddressHeader.XRealIp,
        isCacheControlRespected: true,
        isResponseBufferingEnabled: true,
        cipherGroup: waas.models.PolicyConfig.CipherGroup.Default,
        loadBalancingMethod: {
          method: "IP_HASH"
        },
        websocketPathPrefixes: ["EXAMPLE--Value"],
        isSniEnabled: false,
        healthChecks: {
          isEnabled: true,
          method: waas.models.HealthCheck.Method.Post,
          path: "EXAMPLE-path-Value",
          headers: {
            EXAMPLE_KEY_Nc6hh: "EXAMPLE_VALUE_a8oaC0rFY2h2R98c07Ls"
          },
          expectedResponseCodeGroup: [waas.models.HealthCheck.ExpectedResponseCodeGroup._3Xx],
          isResponseTextCheckEnabled: true,
          expectedResponseText: "EXAMPLE-expectedResponseText-Value",
          intervalInSeconds: 695,
          timeoutInSeconds: 171,
          healthyThreshold: 408,
          unhealthyThreshold: 500
        }
      },
      wafConfig: {
        accessRules: [
          {
            name: "EXAMPLE-name-Value",
            criteria: [
              {
                condition: waas.models.AccessRuleCriteria.Condition.CountryIsNot,
                value: "EXAMPLE-value-Value",
                isCaseSensitive: true
              }
            ],
            action: waas.models.AccessRule.Action.Redirect,
            blockAction: waas.models.AccessRule.BlockAction.SetResponseCode,
            blockResponseCode: 414,
            blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
            blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
            blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
            bypassChallenges: [waas.models.AccessRule.BypassChallenges.DeviceFingerprintChallenge],
            redirectUrl: "EXAMPLE-redirectUrl-Value",
            redirectResponseCode: waas.models.AccessRule.RedirectResponseCode.Found,
            captchaTitle: "EXAMPLE-captchaTitle-Value",
            captchaHeader: "EXAMPLE-captchaHeader-Value",
            captchaFooter: "EXAMPLE-captchaFooter-Value",
            captchaSubmitLabel: "EXAMPLE-captchaSubmitLabel-Value",
            responseHeaderManipulation: [
              {
                action: "EXTEND_HTTP_RESPONSE_HEADER",
                header: "EXAMPLE-header-Value",
                value: "EXAMPLE-value-Value"
              }
            ]
          }
        ],
        addressRateLimiting: {
          isEnabled: false,
          allowedRatePerAddress: 819,
          maxDelayedCountPerAddress: 126,
          blockResponseCode: 278
        },
        captchas: [
          {
            url: "EXAMPLE-url-Value",
            sessionExpirationInSeconds: 495,
            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: 258,
          actionExpirationInSeconds: 113,
          failureThresholdExpirationInSeconds: 320,
          maxAddressCount: 93,
          maxAddressCountExpirationInSeconds: 709,
          challengeSettings: {
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowErrorPage,
            blockResponseCode: 272,
            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"
          }
        },
        humanInteractionChallenge: {
          isEnabled: false,
          action: waas.models.HumanInteractionChallenge.Action.Block,
          failureThreshold: 879,
          actionExpirationInSeconds: 129,
          failureThresholdExpirationInSeconds: 873,
          interactionThreshold: 130,
          recordingPeriodInSeconds: 55,
          setHttpHeader: {
            name: "EXAMPLE-name-Value",
            value: "EXAMPLE-value-Value"
          },
          challengeSettings: {
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowCaptcha,
            blockResponseCode: 276,
            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: false
        },
        jsChallenge: {
          isEnabled: true,
          action: waas.models.JsChallenge.Action.Block,
          failureThreshold: 555,
          actionExpirationInSeconds: 626,
          setHttpHeader: {
            name: "EXAMPLE-name-Value",
            value: "EXAMPLE-value-Value"
          },
          challengeSettings: {
            blockAction: waas.models.BlockChallengeSettings.BlockAction.ShowErrorPage,
            blockResponseCode: 732,
            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: true,
          criteria: [
            {
              condition: waas.models.AccessRuleCriteria.Condition.UrlPartEndsWith,
              value: "EXAMPLE-value-Value",
              isCaseSensitive: true
            }
          ],
          isNatEnabled: false
        },
        origin: "EXAMPLE-origin-Value",
        cachingRules: [
          {
            key: "EXAMPLE-key-Value",
            name: "EXAMPLE-name-Value",
            action: waas.models.CachingRule.Action.Cache,
            cachingDuration: "EXAMPLE-cachingDuration-Value",
            isClientCachingEnabled: true,
            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.Block,
            exclusions: [
              {
                target: waas.models.ProtectionRuleExclusion.Target.RequestCookieNames,
                exclusions: ["EXAMPLE--Value"]
              }
            ]
          }
        ],
        originGroups: ["EXAMPLE--Value"],
        protectionSettings: {
          blockAction: waas.models.ProtectionSettings.BlockAction.SetResponseCode,
          blockResponseCode: 18,
          blockErrorPageMessage: "EXAMPLE-blockErrorPageMessage-Value",
          blockErrorPageCode: "EXAMPLE-blockErrorPageCode-Value",
          blockErrorPageDescription: "EXAMPLE-blockErrorPageDescription-Value",
          maxArgumentCount: 605,
          maxNameLengthPerArgument: 694,
          maxTotalNameLengthOfArguments: 992,
          recommendationsPeriodInDays: 911,
          isResponseInspected: true,
          maxResponseSizeInKiB: 870,
          allowedHttpMethods: [waas.models.ProtectionSettings.AllowedHttpMethods.Connect],
          mediaTypes: ["EXAMPLE--Value"]
        },
        whitelists: [
          {
            name: "EXAMPLE-name-Value",
            addresses: ["EXAMPLE--Value"],
            addressLists: ["EXAMPLE--Value"]
          }
        ]
      },
      freeformTags: {
        EXAMPLE_KEY_iNN0w: "EXAMPLE_VALUE_UDth7IrxCd4bSuQg2VC3"
      },
      definedTags: {
        EXAMPLE_KEY_dUOfj: {
          EXAMPLE_KEY_ygyrt: "EXAMPLE--Value"
        }
      }
    };

    const createWaasPolicyRequest: waas.requests.CreateWaasPolicyRequest = {
      createWaasPolicyDetails: createWaasPolicyDetails,
      opcRequestId: "PBJOVBIEQRDPOMDOC2TQ<unique_ID>",
      opcRetryToken: "EXAMPLE-opcRetryToken-Value"
    };

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