azure-sdk-for-js/sdk/purview/purview-workflow-rest
Jeremy Meng a28e8f0795 [EngSys] move to vendored version of cross-env via dev-tool
***NO_CI***

- apply the transformation

- update samples' README
2024-11-02 00:48:06 +00:00
..
review [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
samples/v1-beta [EngSys] move to vendored version of cross-env via dev-tool 2024-11-02 00:48:06 +00:00
samples-dev [EngSys] standardize OSS copyright header 2024-08-27 13:01:38 -07:00
src [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
swagger
test/public [eslint-plugin] add rule "@typescript-eslint/consistent-type-imports": "warn" 2024-10-30 15:48:52 +00:00
CHANGELOG.md
LICENSE
README.md Increment minimum supported node version to 16 2023-10-09 21:09:54 +00:00
api-extractor.json
assets.json migrate rlc recording (#26430) 2023-07-11 15:52:20 +08:00
eslint.config.mjs Apply automated migration to eslint flat config 2024-08-22 11:43:19 -07:00
karma.conf.js [EngSys] standardize OSS copyright header 2024-08-27 13:01:38 -07:00
package.json [EngSys] move to vendored version of cross-env via dev-tool 2024-11-02 00:48:06 +00:00
sample.env
tsconfig.json [EngSys] remove tsconfig.package.json 2024-07-16 13:27:25 +00:00

README.md

Azure Purview Workflow Rest-Level client library for JavaScript

Workflows are automated, repeatable business processes that users can create within Microsoft Purview to validate and orchestrate CUD (create, update, delete) operations on their data entities. Enabling these processes allow organizations to track changes, enforce policy compliance, and ensure quality data across their data landscape.

Use the client library for Purview Workflow to:

  • Manage workflows
  • Submit user requests and monitor workflow runs
  • View and respond to workflow tasks

For more details about how to use workflow, please refer to the service documentation

Getting started

Currently supported environments

Prerequisites

Create and authenticate a PurviewWorkflowClient

Since the Workflow service uses an Azure Active Directory (AAD) bearer token for authentication and identification, an email address should be encoded into the token to allow for notification when using Workflow. It is recommended that the Azure Identity library be used with a the UsernamePasswordCredential. Before using the Azure Identity library with Workflow, an application should be registered and used for the clientId passed to the UsernamePasswordCredential. Set the values of the client ID, tenant ID, username and password as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, USERNAME, PASSWORD

import PurviewWorkflow from "@azure-rest/purview-workflow";
import { UsernamePasswordCredential } from "@azure/identity";
import * as dotenv from "dotenv";

dotenv.config();

const endpoint = process.env["ENDPOINT"];
const tenantId = process.env["AZURE_TENANT_ID"];
const clientId = process.env["AZURE_CLIENT_ID"];
const username = process.env["USERNAME"];
const password = process.env["PASSWORD"];
const client = PurviewWorkflow(
  endpoint,
  new UsernamePasswordCredential(
        tenantId,
        clientId,
        username,
        password
      )
  );

Examples

The following section provides several code snippets covering some of the most common scenarios, including:

Submit user requests

import createPurviewWorkflowClient, {
  SubmitUserRequestsParameters
} from "@azure-rest/purview-workflow";
import { UsernamePasswordCredential } from "@azure/identity";
import * as dotenv from "dotenv";

dotenv.config();

async function userRequestsSubmit() {
  const endpoint = process.env["ENDPOINT"];
  const tenantId = process.env["AZURE_TENANT_ID"];
  const clientId = process.env["AZURE_CLIENT_ID"];
  const username = process.env["USERNAME"];
  const password = process.env["PASSWORD"];

  const credential = new UsernamePasswordCredential(tenantId , clientId, username, password);
  const client = createPurviewWorkflowClient(endpoint, credential);
  const options: SubmitUserRequestsParameters = {
    body: {
      comment: "Thanks!",
      operations: [
        {
          type: "CreateTerm",
          payload: {
            glossaryTerm: {
              name: "term",
              anchor: { glossaryGuid: "20031e20-b4df-4a66-a61d-1b0716f3fa48" },
              nickName: "term",
              status: "Approved"
            }
          }
        }
      ]
    }
  };
  const result = await client.path("/userrequests").post(options);
  if (isUnexpected(result)) {
    throw result.body.error;
  }
  console.log(result);
}

userRequestsSubmit().catch(console.error);

Approve workflow task

// This taskId represents an existing workflow task. The id can be obtained by calling GET /workflowtasks API.
import createPurviewWorkflowClient, {
  SubmitUserRequestsParameters
} from "@azure-rest/purview-workflow";
import { UsernamePasswordCredential } from "@azure/identity";
import * as dotenv from "dotenv";

dotenv.config();
async function approvalTaskApprove() {
  const endpoint = process.env["ENDPOINT"];
  const tenantId = process.env["AZURE_TENANT_ID"];
  const clientId = process.env["AZURE_CLIENT_ID"];
  const username = process.env["USERNAME"];
  const password = process.env["PASSWORD"];
  const credential = new UsernamePasswordCredential(tenantId, clientId, username, password);
  const client = createPurviewWorkflowClient(endpoint, credential);
  const taskId = "98d98e2c-23fa-4157-a3f8-ff8ce5cc095c";
  const options: ApproveApprovalTaskParameters = {
    body: { comment: "Thanks for raising this!" }
  };
  const result = await client
    .path("/workflowtasks/{taskId}/approve-approval", taskId)
    .post(options);
  if (isUnexpected(result)) {
    throw result.body.error;
  }
  console.log(result);
}

approvalTaskApprove().catch(console.error);

Troubleshooting

Logging

Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the AZURE_LOG_LEVEL environment variable to info. Alternatively, logging can be enabled at runtime by calling setLogLevel in the @azure/logger:

const { setLogLevel } = require("@azure/logger");

setLogLevel("info");

For more detailed instructions on how to enable logs, you can look at the @azure/logger package docs.