Edits history of script submission #20111 for ' Preview Destination Filter (segment)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Segment = {
      token: string;
      baseUrl: string;
    };
    /**
     * Preview Destination Filter
     * Simulates the application of a Destination filter to a provided JSON payload.
     */
    export async function main(
      auth: Segment,
      body: {
        filter: {
          if: string;
          actions: {
            type: "ALLOW_PROPERTIES" | "DROP" | "DROP_PROPERTIES" | "SAMPLE";
            fields?: {};
            percent?: number;
            path?: string;
          }[];
        };
        payload: {};
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/destination/filters/preview`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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