lib/stytch/b2b_organizations.rb



# frozen_string_literal: true

# !!!
# WARNING: This file is autogenerated
# Only modify code within MANUAL() sections
# or your changes may be overwritten later!
# !!!

require_relative 'request_helper'

module StytchB2B
  class Organizations
    include Stytch::RequestHelper
    attr_reader :members

    def initialize(connection)
      @connection = connection

      @members = StytchB2B::Organizations::Members.new(@connection)
    end

    # Creates an Organization. An `organization_name` and a unique `organization_slug` are required.
    #
    # By default, `email_invites` and `sso_jit_provisioning` will be set to `ALL_ALLOWED`, and `mfa_policy` will be set to `OPTIONAL` if no Organization authentication settings are explicitly defined in the request.
    #
    # *See the [Organization authentication settings](https://stytch.com/docs/b2b/api/org-auth-settings) resource to learn more about fields like `email_jit_provisioning`, `email_invites`, `sso_jit_provisioning`, etc., and their behaviors.
    #
    # == Parameters:
    # organization_name::
    #   The name of the Organization.
    #   The type of this field is +String+.
    # organization_slug::
    #   The unique URL slug of the Organization. A minimum of two characters is required. The slug only accepts alphanumeric characters and the following reserved characters: `-` `.` `_` `~`.
    #   The type of this field is nilable +String+.
    # organization_logo_url::
    #   The image URL of the Organization logo.
    #   The type of this field is nilable +String+.
    # trusted_metadata::
    #   An arbitrary JSON object for storing application-specific data or identity-provider-specific data.
    #   The type of this field is nilable +object+.
    # sso_jit_provisioning::
    #   The authentication setting that controls the JIT provisioning of Members when authenticating via SSO. The accepted values are:
    #
    #   `ALL_ALLOWED` – new Members will be automatically provisioned upon successful authentication via any of the Organization's `sso_active_connections`.
    #
    #   `RESTRICTED` – only new Members with SSO logins that comply with `sso_jit_provisioning_allowed_connections` can be provisioned upon authentication.
    #
    #   `NOT_ALLOWED` – disable JIT provisioning via SSO.
    #
    #   The type of this field is nilable +String+.
    # email_allowed_domains::
    #   An array of email domains that allow invites or JIT provisioning for new Members. This list is enforced when either `email_invites` or `email_jit_provisioning` is set to `RESTRICTED`.
    #
    #
    #     Common domains such as `gmail.com` are not allowed. See the [common email domains resource](https://stytch.com/docs/b2b/api/common-email-domains) for the full list.
    #   The type of this field is nilable list of +String+.
    # email_jit_provisioning::
    #   The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link. The accepted values are:
    #
    #   `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be provisioned upon authentication via Email Magic Link.
    #
    #   `NOT_ALLOWED` – disable JIT provisioning via Email Magic Link.
    #
    #   The type of this field is nilable +String+.
    # email_invites::
    #   The authentication setting that controls how a new Member can be invited to an organization by email. The accepted values are:
    #
    #   `ALL_ALLOWED` – any new Member can be invited to join via email.
    #
    #   `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be invited via email.
    #
    #   `NOT_ALLOWED` – disable email invites.
    #
    #   The type of this field is nilable +String+.
    # auth_methods::
    #   The setting that controls which authentication methods can be used by Members of an Organization. The accepted values are:
    #
    #   `ALL_ALLOWED` – the default setting which allows all authentication methods to be used.
    #
    #   `RESTRICTED` – only methods that comply with `allowed_auth_methods` can be used for authentication. This setting does not apply to Members with `is_breakglass` set to `true`.
    #
    #   The type of this field is nilable +String+.
    # allowed_auth_methods::
    #
    #   An array of allowed authentication methods. This list is enforced when `auth_methods` is set to `RESTRICTED`.
    #   The list's accepted values are: `sso`, `magic_link`, `password`, `google_oauth`, and `microsoft_oauth`.
    #
    #   The type of this field is nilable list of +String+.
    # mfa_policy::
    #   The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
    #
    #   `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
    #
    #   `OPTIONAL` – The default value. The Organization does not require MFA by default for all Members. Members will be required to complete MFA only if their `mfa_enrolled` status is set to true.
    #
    #   The type of this field is nilable +String+.
    #
    # == Returns:
    # An object with the following fields:
    # request_id::
    #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
    #   The type of this field is +String+.
    # organization::
    #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
    #   The type of this field is +Organization+ (+object+).
    # status_code::
    #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
    #   The type of this field is +Integer+.
    def create(
      organization_name:,
      organization_slug: nil,
      organization_logo_url: nil,
      trusted_metadata: nil,
      sso_jit_provisioning: nil,
      email_allowed_domains: nil,
      email_jit_provisioning: nil,
      email_invites: nil,
      auth_methods: nil,
      allowed_auth_methods: nil,
      mfa_policy: nil
    )
      request = {
        organization_name: organization_name
      }
      request[:organization_slug] = organization_slug unless organization_slug.nil?
      request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
      request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
      request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
      request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
      request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
      request[:email_invites] = email_invites unless email_invites.nil?
      request[:auth_methods] = auth_methods unless auth_methods.nil?
      request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
      request[:mfa_policy] = mfa_policy unless mfa_policy.nil?

      post_request('/v1/b2b/organizations', request)
    end

    # Returns an Organization specified by `organization_id`.
    #
    # == Parameters:
    # organization_id::
    #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
    #   The type of this field is +String+.
    #
    # == Returns:
    # An object with the following fields:
    # request_id::
    #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
    #   The type of this field is +String+.
    # organization::
    #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
    #   The type of this field is +Organization+ (+object+).
    # status_code::
    #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
    #   The type of this field is +Integer+.
    def get(
      organization_id:
    )
      query_params = {}
      request = request_with_query_params("/v1/b2b/organizations/#{organization_id}", query_params)
      get_request(request)
    end

    # Updates an Organization specified by `organization_id`. An Organization must always have at least one auth setting set to either `RESTRICTED` or `ALL_ALLOWED` in order to provision new Members. test
    #
    # *See the [Organization authentication settings](https://stytch.com/docs/b2b/api/org-auth-settings) resource to learn more about fields like `email_jit_provisioning`, `email_invites`, `sso_jit_provisioning`, etc., and their behaviors.
    #
    # == Parameters:
    # organization_id::
    #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
    #   The type of this field is +String+.
    # organization_name::
    #   The name of the Organization.
    #   The type of this field is nilable +String+.
    # organization_slug::
    #   The unique URL slug of the Organization. A minimum of two characters is required. The slug only accepts alphanumeric characters and the following reserved characters: `-` `.` `_` `~`.
    #   The type of this field is nilable +String+.
    # organization_logo_url::
    #   The image URL of the Organization logo.
    #   The type of this field is nilable +String+.
    # trusted_metadata::
    #   An arbitrary JSON object for storing application-specific data or identity-provider-specific data.
    #   The type of this field is nilable +object+.
    # sso_default_connection_id::
    #   The default connection used for SSO when there are multiple active connections.
    #   The type of this field is nilable +String+.
    # sso_jit_provisioning::
    #   The authentication setting that controls the JIT provisioning of Members when authenticating via SSO. The accepted values are:
    #
    #   `ALL_ALLOWED` – new Members will be automatically provisioned upon successful authentication via any of the Organization's `sso_active_connections`.
    #
    #   `RESTRICTED` – only new Members with SSO logins that comply with `sso_jit_provisioning_allowed_connections` can be provisioned upon authentication.
    #
    #   `NOT_ALLOWED` – disable JIT provisioning via SSO.
    #
    #   The type of this field is nilable +String+.
    # sso_jit_provisioning_allowed_connections::
    #   An array of `connection_id`s that reference [SAML Connection objects](https://stytch.com/docs/b2b/api/saml-connection-object).
    #   Only these connections will be allowed to JIT provision Members via SSO when `sso_jit_provisioning` is set to `RESTRICTED`.
    #   The type of this field is nilable list of +String+.
    # email_allowed_domains::
    #   An array of email domains that allow invites or JIT provisioning for new Members. This list is enforced when either `email_invites` or `email_jit_provisioning` is set to `RESTRICTED`.
    #
    #
    #     Common domains such as `gmail.com` are not allowed. See the [common email domains resource](https://stytch.com/docs/b2b/api/common-email-domains) for the full list.
    #   The type of this field is nilable list of +String+.
    # email_jit_provisioning::
    #   The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link. The accepted values are:
    #
    #   `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be provisioned upon authentication via Email Magic Link.
    #
    #   `NOT_ALLOWED` – disable JIT provisioning via Email Magic Link.
    #
    #   The type of this field is nilable +String+.
    # email_invites::
    #   The authentication setting that controls how a new Member can be invited to an organization by email. The accepted values are:
    #
    #   `ALL_ALLOWED` – any new Member can be invited to join via email.
    #
    #   `RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be invited via email.
    #
    #   `NOT_ALLOWED` – disable email invites.
    #
    #   The type of this field is nilable +String+.
    # auth_methods::
    #   The setting that controls which authentication methods can be used by Members of an Organization. The accepted values are:
    #
    #   `ALL_ALLOWED` – the default setting which allows all authentication methods to be used.
    #
    #   `RESTRICTED` – only methods that comply with `allowed_auth_methods` can be used for authentication. This setting does not apply to Members with `is_breakglass` set to `true`.
    #
    #   The type of this field is nilable +String+.
    # allowed_auth_methods::
    #
    #   An array of allowed authentication methods. This list is enforced when `auth_methods` is set to `RESTRICTED`.
    #   The list's accepted values are: `sso`, `magic_link`, `password`, `google_oauth`, and `microsoft_oauth`.
    #
    #   The type of this field is nilable list of +String+.
    # mfa_policy::
    #   The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
    #
    #   `REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in.
    #
    #   `OPTIONAL` – The default value. The Organization does not require MFA by default for all Members. Members will be required to complete MFA only if their `mfa_enrolled` status is set to true.
    #
    #   The type of this field is nilable +String+.
    #
    # == Returns:
    # An object with the following fields:
    # request_id::
    #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
    #   The type of this field is +String+.
    # organization::
    #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
    #   The type of this field is +Organization+ (+object+).
    # status_code::
    #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
    #   The type of this field is +Integer+.
    def update(
      organization_id:,
      organization_name: nil,
      organization_slug: nil,
      organization_logo_url: nil,
      trusted_metadata: nil,
      sso_default_connection_id: nil,
      sso_jit_provisioning: nil,
      sso_jit_provisioning_allowed_connections: nil,
      email_allowed_domains: nil,
      email_jit_provisioning: nil,
      email_invites: nil,
      auth_methods: nil,
      allowed_auth_methods: nil,
      mfa_policy: nil
    )
      request = {}
      request[:organization_name] = organization_name unless organization_name.nil?
      request[:organization_slug] = organization_slug unless organization_slug.nil?
      request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
      request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
      request[:sso_default_connection_id] = sso_default_connection_id unless sso_default_connection_id.nil?
      request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
      request[:sso_jit_provisioning_allowed_connections] = sso_jit_provisioning_allowed_connections unless sso_jit_provisioning_allowed_connections.nil?
      request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
      request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
      request[:email_invites] = email_invites unless email_invites.nil?
      request[:auth_methods] = auth_methods unless auth_methods.nil?
      request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
      request[:mfa_policy] = mfa_policy unless mfa_policy.nil?

      put_request("/v1/b2b/organizations/#{organization_id}", request)
    end

    # Deletes an Organization specified by `organization_id`. All Members of the Organization will also be deleted.
    #
    # == Parameters:
    # organization_id::
    #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
    #   The type of this field is +String+.
    #
    # == Returns:
    # An object with the following fields:
    # request_id::
    #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
    #   The type of this field is +String+.
    # organization_id::
    #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
    #   The type of this field is +String+.
    # status_code::
    #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
    #   The type of this field is +Integer+.
    def delete(
      organization_id:
    )
      delete_request("/v1/b2b/organizations/#{organization_id}")
    end

    # Search for Organizations. If you send a request with no body params, no filtering will be applied and the endpoint will return all Organizations. All fuzzy search filters require a minimum of three characters.
    #
    # == Parameters:
    # cursor::
    #   The `cursor` field allows you to paginate through your results. Each result array is limited to 1000 results. If your query returns more than 1000 results, you will need to paginate the responses using the `cursor`. If you receive a response that includes a non-null `next_cursor` in the `results_metadata` object, repeat the search call with the `next_cursor` value set to the `cursor` field to retrieve the next page of results. Continue to make search calls until the `next_cursor` in the response is null.
    #   The type of this field is nilable +String+.
    # limit::
    #   The number of search results to return per page. The default limit is 100. A maximum of 1000 results can be returned by a single search request. If the total size of your result set is greater than one page size, you must paginate the response. See the `cursor` field.
    #   The type of this field is nilable +Integer+.
    # query::
    #   The optional query object contains the operator, i.e. `AND` or `OR`, and the operands that will filter your results. Only an operator is required. If you include no operands, no filtering will be applied. If you include no query object, it will return all Organizations with no filtering applied.
    #   The type of this field is nilable +SearchQuery+ (+object+).
    #
    # == Returns:
    # An object with the following fields:
    # request_id::
    #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
    #   The type of this field is +String+.
    # organizations::
    #   An array of [Organization objects](https://stytch.com/docs/b2b/api/organization-object).
    #   The type of this field is list of +Organization+ (+object+).
    # results_metadata::
    #   The search `results_metadata` object contains metadata relevant to your specific query like `total` and `next_cursor`.
    #   The type of this field is +ResultsMetadata+ (+object+).
    # status_code::
    #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
    #   The type of this field is +Integer+.
    def search(
      cursor: nil,
      limit: nil,
      query: nil
    )
      request = {}
      request[:cursor] = cursor unless cursor.nil?
      request[:limit] = limit unless limit.nil?
      request[:query] = query unless query.nil?

      post_request('/v1/b2b/organizations/search', request)
    end

    class Members
      include Stytch::RequestHelper

      def initialize(connection)
        @connection = connection
      end

      # Updates a Member specified by `organization_id` and `member_id`.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
      #   The type of this field is +String+.
      # name::
      #   The name of the Member.
      #   The type of this field is nilable +String+.
      # trusted_metadata::
      #   An arbitrary JSON object for storing application-specific data or identity-provider-specific data.
      #   The type of this field is nilable +object+.
      # untrusted_metadata::
      #   An arbitrary JSON object of application-specific data. These fields can be edited directly by the
      #   frontend SDK, and should not be used to store critical information. See the [Metadata resource](https://stytch.com/docs/b2b/api/metadata)
      #   for complete field behavior details.
      #   The type of this field is nilable +object+.
      # is_breakglass::
      #   Identifies the Member as a break glass user - someone who has permissions to authenticate into an Organization by bypassing the Organization's settings. A break glass account is typically used for emergency purposes to gain access outside of normal authentication procedures. Refer to the [Organization object](organization-object) and its `auth_methods` and `allowed_auth_methods` fields for more details.
      #   The type of this field is nilable +Boolean+.
      # mfa_phone_number::
      #   Sets the Member's phone number. Throws an error if the Member already has a phone number. To change the Member's phone number, use the [Delete member phone number endpoint](https://stytch.com/docs/b2b/api/delete-member-mfa-phone-number) to delete the Member's existing phone number first.
      #   The type of this field is nilable +String+.
      # mfa_enrolled::
      #   Sets whether the Member is enrolled in MFA. If true, the Member must complete an MFA step whenever they wish to log in to their Organization. If false, the Member only needs to complete an MFA step if the Organization's MFA policy is set to `REQUIRED_FOR_ALL`.
      #   The type of this field is nilable +Boolean+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def update(
        organization_id:,
        member_id:,
        name: nil,
        trusted_metadata: nil,
        untrusted_metadata: nil,
        is_breakglass: nil,
        mfa_phone_number: nil,
        mfa_enrolled: nil
      )
        request = {}
        request[:name] = name unless name.nil?
        request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
        request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
        request[:is_breakglass] = is_breakglass unless is_breakglass.nil?
        request[:mfa_phone_number] = mfa_phone_number unless mfa_phone_number.nil?
        request[:mfa_enrolled] = mfa_enrolled unless mfa_enrolled.nil?

        put_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}", request)
      end

      # Deletes a Member specified by `organization_id` and `member_id`.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
      #   The type of this field is +String+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def delete(
        organization_id:,
        member_id:
      )
        delete_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}")
      end

      # Reactivates a deleted Member's status and its associated email status (if applicable) to active, specified by `organization_id` and `member_id`.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
      #   The type of this field is +String+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def reactivate(
        organization_id:,
        member_id:
      )
        request = {}

        put_request("/v1/b2b/organizations/#{organization_id}/members/#{member_id}/reactivate", request)
      end

      # Delete a Member's MFA phone number.
      #
      # To change a Member's phone number, you must first call this endpoint to delete the existing phone number.
      #
      # Existing Member Sessions that include a phone number authentication factor will not be revoked if the phone number is deleted, and MFA will not be enforced until the Member logs in again.
      # If you wish to enforce MFA immediately after a phone number is deleted, you can do so by prompting the Member to enter a new phone number
      # and calling the [OTP SMS send](https://stytch.com/docs/b2b/api/otp-sms-send) endpoint, then calling the [OTP SMS Authenticate](https://stytch.com/docs/b2b/api/authenticate-otp-sms) endpoint.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
      #   The type of this field is +String+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def delete_mfa_phone_number(
        organization_id:,
        member_id:
      )
        delete_request("/v1/b2b/organizations/#{organization_id}/members/mfa_phone_numbers/#{member_id}")
      end

      # Search for Members within specified Organizations. An array with at least one `organization_id` is required. Submitting an empty `query` returns all non-deleted Members within the specified Organizations.
      #
      # *All fuzzy search filters require a minimum of three characters.
      #
      # == Parameters:
      # organization_ids::
      #   An array of organization_ids. At least one value is required.
      #   The type of this field is list of +String+.
      # cursor::
      #   The `cursor` field allows you to paginate through your results. Each result array is limited to 1000 results. If your query returns more than 1000 results, you will need to paginate the responses using the `cursor`. If you receive a response that includes a non-null `next_cursor` in the `results_metadata` object, repeat the search call with the `next_cursor` value set to the `cursor` field to retrieve the next page of results. Continue to make search calls until the `next_cursor` in the response is null.
      #   The type of this field is nilable +String+.
      # limit::
      #   The number of search results to return per page. The default limit is 100. A maximum of 1000 results can be returned by a single search request. If the total size of your result set is greater than one page size, you must paginate the response. See the `cursor` field.
      #   The type of this field is nilable +Integer+.
      # query::
      #   The optional query object contains the operator, i.e. `AND` or `OR`, and the operands that will filter your results. Only an operator is required. If you include no operands, no filtering will be applied. If you include no query object, it will return all Members with no filtering applied.
      #   The type of this field is nilable +SearchQuery+ (+object+).
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # members::
      #   An array of [Member objects](member-object).
      #   The type of this field is list of +Member+ (+object+).
      # results_metadata::
      #   The search `results_metadata` object contains metadata relevant to your specific query like `total` and `next_cursor`.
      #   The type of this field is +ResultsMetadata+ (+object+).
      # organizations::
      #   A map from `organization_id` to [Organization object](https://stytch.com/docs/b2b/api/organization-object). The map only contains the Organizations that the Members belongs to.
      #   The type of this field is map of +String+ to +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def search(
        organization_ids:,
        cursor: nil,
        limit: nil,
        query: nil
      )
        request = {
          organization_ids: organization_ids
        }
        request[:cursor] = cursor unless cursor.nil?
        request[:limit] = limit unless limit.nil?
        request[:query] = query unless query.nil?

        post_request('/v1/b2b/organizations/members/search', request)
      end

      # Delete a Member's password.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_password_id::
      #   Globally unique UUID that identifies a Member's password.
      #   The type of this field is +String+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def delete_password(
        organization_id:,
        member_password_id:
      )
        delete_request("/v1/b2b/organizations/#{organization_id}/members/passwords/#{member_password_id}")
      end

      # Creates a Member. An `organization_id` and `email_address` are required.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # email_address::
      #   The email address of the Member.
      #   The type of this field is +String+.
      # name::
      #   The name of the Member.
      #   The type of this field is nilable +String+.
      # trusted_metadata::
      #   An arbitrary JSON object for storing application-specific data or identity-provider-specific data.
      #   The type of this field is nilable +object+.
      # untrusted_metadata::
      #   An arbitrary JSON object of application-specific data. These fields can be edited directly by the
      #   frontend SDK, and should not be used to store critical information. See the [Metadata resource](https://stytch.com/docs/b2b/api/metadata)
      #   for complete field behavior details.
      #   The type of this field is nilable +object+.
      # create_member_as_pending::
      #   Flag for whether or not to save a Member as `pending` or `active` in Stytch. It defaults to false. If true, new Members will be created with status `pending` in Stytch's backend. Their status will remain `pending` and they will continue to receive signup email templates for every Email Magic Link until that Member authenticates and becomes `active`. If false, new Members will be created with status `active`.
      #   The type of this field is nilable +Boolean+.
      # is_breakglass::
      #   Identifies the Member as a break glass user - someone who has permissions to authenticate into an Organization by bypassing the Organization's settings. A break glass account is typically used for emergency purposes to gain access outside of normal authentication procedures. Refer to the [Organization object](organization-object) and its `auth_methods` and `allowed_auth_methods` fields for more details.
      #   The type of this field is nilable +Boolean+.
      # mfa_phone_number::
      #   The Member's phone number. A Member may only have one phone number.
      #   The type of this field is nilable +String+.
      # mfa_enrolled::
      #   Sets whether the Member is enrolled in MFA. If true, the Member must complete an MFA step whenever they wish to log in to their Organization. If false, the Member only needs to complete an MFA step if the Organization's MFA policy is set to `REQUIRED_FOR_ALL`.
      #   The type of this field is nilable +Boolean+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def create(
        organization_id:,
        email_address:,
        name: nil,
        trusted_metadata: nil,
        untrusted_metadata: nil,
        create_member_as_pending: nil,
        is_breakglass: nil,
        mfa_phone_number: nil,
        mfa_enrolled: nil
      )
        request = {
          email_address: email_address
        }
        request[:name] = name unless name.nil?
        request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
        request[:untrusted_metadata] = untrusted_metadata unless untrusted_metadata.nil?
        request[:create_member_as_pending] = create_member_as_pending unless create_member_as_pending.nil?
        request[:is_breakglass] = is_breakglass unless is_breakglass.nil?
        request[:mfa_phone_number] = mfa_phone_number unless mfa_phone_number.nil?
        request[:mfa_enrolled] = mfa_enrolled unless mfa_enrolled.nil?

        post_request("/v1/b2b/organizations/#{organization_id}/members", request)
      end

      # Get a Member by `member_id` or `email_address`.
      #
      # == Parameters:
      # organization_id::
      #   Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
      #   The type of this field is nilable +String+.
      # email_address::
      #   The email address of the Member.
      #   The type of this field is nilable +String+.
      #
      # == Returns:
      # An object with the following fields:
      # request_id::
      #   Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
      #   The type of this field is +String+.
      # member_id::
      #   Globally unique UUID that identifies a specific Member.
      #   The type of this field is +String+.
      # member::
      #   The [Member object](https://stytch.com/docs/b2b/api/member-object)
      #   The type of this field is +Member+ (+object+).
      # organization::
      #   The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
      #   The type of this field is +Organization+ (+object+).
      # status_code::
      #   The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
      #   The type of this field is +Integer+.
      def get(
        organization_id:,
        member_id: nil,
        email_address: nil
      )
        query_params = {
          member_id: member_id,
          email_address: email_address
        }
        request = request_with_query_params("/v1/b2b/organizations/#{organization_id}/member", query_params)
        get_request(request)
      end
    end
  end
end