Skip to content

A library designed for Azure Logic Apps, providing the capability to retrieve comprehensive details of a workflow run and allowing the execution of JSONPath queries on these details, all while ensuring complete TypeScript support.

License

Notifications You must be signed in to change notification settings

HamedStack/HamedStack.AzureLogicApps.TypeScript

Repository files navigation

HamedStack.AzureLogicApps.TypeScript

A library to access all details of a workflow run with executing JSONPath query on the details.

Usage

You have access to the following APIs.

Login

By using this API you can login and fetch the workflow details.

let alam = new AzureLogicAppsManagement(
  /*AzureAccountInfo*/
  {
    // Your Azure security info
    clientId: "",
    clientSecret: "",
    subscriptionId: "",
    tenantId: "",
  }
);
export interface AzureAccountInfo {
    tenantId: string;
    clientId: string;
    clientSecret: string;
    subscriptionId: string;
    apiVersion?: string;
}

Workflow Detail

By call it you will get all information of most recent workflow run of your workflow.

AzureWorkflowDetail details = await alam.getLastWorkflowDetail(
    /*(azureWorkflowInfo: AzureWorkflowInfo, actionsFilter: "input" | "output" | "both" = "both"): Promise<AzureWorkflowDetail | undefined>*/
    {
        // Available via Azure Portal
        workflowName: '',
        resourceGroup: '',
    });

it returns

export interface AzureWorkflowDetail {
    trigger: AzureTriggerData;
    actions: AzureWorkflowRunActionData[];
    workflowRun: WorkflowRun;
}
export interface AzureTriggerData {
    name: string | undefined;
    input: Json | undefined;
    output: Json | undefined;
    trigger: WorkflowRunTrigger | undefined;
    isSuccessful: boolean;
    status: string | undefined;
}
export interface AzureWorkflowRunActionData {
    order: number,
    name: string;
    input?: Json | undefined;
    output?: Json | undefined;
    action?: WorkflowRunAction;
    status: string | undefined;
    parents?: string[];
    isSuccessful: boolean;
}

Query Execution

// Returns any
const result = await alam.executeQueryOnWorkflowDetail(
  /* (AzureWorkflowDetail, string | undefined, JsonPathQuerySection, string): Promise<any[] | undefined> */

  details, // Workflow details

  // Action name, trigger name or undefind for WorkflowRun
  // Same name of Azure Logic App UI but with underscore instead of whitespace.
  "Initialize_variable_2",

  // Query on Action, ActionInput, ActionOutput, Trigger, TriggerInput, TriggerOutput, WorkflowRun
  // Items of Workflow details object.
  JsonPathQuerySection.ActionInput,

  "$..value" // JSONPath
);

Get First Match

This method find first match workflow among all available workflows based on conditions.

WorkflowRun wf = await alam.findWorkflowRunOnFirstMatch({
    /* (AzureWorkflowInfo, string | undefined, string, conditions: ((v: any) => boolean)[], filter?: string, top?: number): Promise<WorkflowRun | undefined>*/
    workflowName: '...',
    resourceGroup: '...'
  }, "Initialize_variable", // Action Name
    "$..value", // Json path inside your Input Action
    [x => x == ?], // array of conditions to match (if one of them matches you will get result)
    undefined // filter you can pass
    undefined // top option
    );
getWorkflowRunOnFirstMatch(azureWorkflowInfo: AzureWorkflowInfo, workflowRuns: WorkflowRun[], inputActionName: string | undefined, jsonPath: string, conditions: ((v: any) => boolean)[]): Promise<WorkflowRun | undefined>

Same as findWorkflowRunOnFirstMatch but accepts workflowRuns as a parameter to check your in-memory object.

Analysis the workflow run

analysisAzureWorkflowDetail(azureWorkflowDetail: AzureWorkflowDetail): AzureWorkflowDetailResult

To analysis and get report from an AzureWorkflowDetail you should use it.

export interface AzureWorkflowDetailResult {
    isSuccessful: boolean; //overal status
    details: AzureWorkflowDetailItemResult[];
    errors: string[] | undefined; // error messages
}
export interface AzureWorkflowDetailItemResult {
    isSuccessful: boolean;
    type: "WorkflowRun" | "Action" | "Trigger";
    object: AzureTriggerData | AzureWorkflowRunActionData | WorkflowRun
}

Sample

import {
  AzureLogicAppsManagement,
  AzureWorkflowDetail,
  JsonPathQuerySection,
} from "@hamedstack/azure-logic-apps";

let alam: AzureLogicAppManagement;
let details: AzureWorkflowDetails;
describe("Sample", () => {
  beforeAll(async () => {
    alam = new AzureLogicAppsManagement({
      clientId: "...",
      clientSecret: "...",
      subscriptionId: "...",
      tenantId: "...",
    });

    detail = await alam.getLastWorkflowDetail({
      workflowName: "my-wf",
      resourceGroup: "rg-testing",
    });
  });
  it("getting data from Logic App", async () => {

    // Always returns an array
    const result = await alam.executeQueryOnWorkflowDetail(
      detail,
      "Initialize_variable_2" /* or 'Initialize variable 2' */,
      JsonPathQuerySection.ActionInput,
      "$..value"
    );

    const report = alam.analysisAzureWorkflowDetail(detail);
    
    // Checking overal status
    expect(report.isSuccessful).toEqual(true);

    // Checking details
    expect(result[0]).toEqual(3); // value should be 3
  });
});

About

A library designed for Azure Logic Apps, providing the capability to retrieve comprehensive details of a workflow run and allowing the execution of JSONPath queries on these details, all while ensuring complete TypeScript support.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published