Edits history of script submission #16765 for ' Update a workflow based on the ID (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Update a workflow based on the ID
     * Updates a workflow based on the Workflow ID.
     */
    export async function main(
      auth: Kustomer,
      id: string,
      body: {
        name?: string;
        replaces?: string;
        description?: string;
        meta?: {};
        trigger?:
          | {
              id: string;
              eventName?: string;
              callable: false | true;
              schema: {};
              meta?: {};
              transitions: {
                meta?: {};
                target: string;
                condition: {
                  op:
                    | "and"
                    | "or"
                    | "exists"
                    | "dne"
                    | "true"
                    | "false"
                    | "eq"
                    | "neq"
                    | "gt"
                    | "gte"
                    | "lt"
                    | "lte"
                    | "lt-date"
                    | "gt-date"
                    | "contains"
                    | "not-contains";
                  values: unknown[];
                };
              }[];
            }
          | {
              id: string;
              appVersion?: string;
              meta?: {};
              eventName: string;
              transitions: {
                meta?: {};
                target: string;
                condition: {
                  op:
                    | "and"
                    | "or"
                    | "exists"
                    | "dne"
                    | "true"
                    | "false"
                    | "eq"
                    | "neq"
                    | "gt"
                    | "gte"
                    | "lt"
                    | "lte"
                    | "lt-date"
                    | "gt-date"
                    | "contains"
                    | "not-contains";
                  values: unknown[];
                };
              }[];
            };
        steps?: {
          id: string;
          appVersion?: string;
          meta?: {};
          action?: string;
          params?: {};
          transitions: {
            meta?: {};
            target: string;
            condition: {
              op:
                | "and"
                | "or"
                | "exists"
                | "dne"
                | "true"
                | "false"
                | "eq"
                | "neq"
                | "gt"
                | "gte"
                | "lt"
                | "lte"
                | "lt-date"
                | "gt-date"
                | "contains"
                | "not-contains";
              values: unknown[];
            };
          }[];
          errorCases?: {
            condition: { op: "and" | "or"; values: unknown[] };
            errorAction: {
              type?:
                | "continue"
                | "retry-workflow"
                | "retry-action"
                | "stop-processing";
            };
          }[];
        }[];
        enabled?: false | true;
        logging?: false | true;
      },
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/workflows/${id}`);
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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