Edits history of script submission #20132 for ' Update Schema Settings in Source (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Update Schema Settings in Source
     * Updates the schema configuration for a Source. If Protocols is not enabled for the Source, any updates to Protocols-specific configurations will not be applied.
    
          Config API omitted fields:
    - `updateMask`
          
     */
    export async function main(
      auth: Segment,
      sourceId: string,
      body: {
        track?: {
          allowUnplannedEvents?: false | true;
          allowUnplannedEventProperties?: false | true;
          allowEventOnViolations?: false | true;
          allowPropertiesOnViolations?: false | true;
          commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_PROPERTIES";
        };
        identify?: {
          allowUnplannedTraits?: false | true;
          allowTraitsOnViolations?: false | true;
          commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_TRAITS";
        };
        group?: {
          allowUnplannedTraits?: false | true;
          allowTraitsOnViolations?: false | true;
          commonEventOnViolations?: "ALLOW" | "BLOCK" | "OMIT_TRAITS";
        };
        forwardingViolationsTo?: string;
        forwardingBlockedEventsTo?: string;
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/sources/${sourceId}/settings`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago