azure-sdk-for-js/sdk/purview/purview-workflow-rest
Jeremy Meng 3a68e456b2 [Samples] update "src/**.ts" to "src/**/*.ts" in tsconfig.json
Previously dev-tool has been fixed to generate correct include path in samples
tsconfig.json but samples were not updated.

This PR fixes the samples tsconfig.json in one run; otherwise with the recent
branch protection policy changes, when individual packages re-publish samples,
js-core team would have to approve the tsconfig.json changes.

***NO_CI***
2024-07-24 13:53:00 +00:00
..
review Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
samples/v1-beta [Samples] update "src/**.ts" to "src/**/*.ts" in tsconfig.json 2024-07-24 13:53:00 +00:00
samples-dev [EngSys] upgrade to prettier v3 2024-01-10 18:45:01 -05:00
src [EngSys] upgrade to prettier v3 2024-01-10 18:45:01 -05:00
swagger Post release automated changes for purview releases (#25184) 2023-03-20 13:12:37 -07:00
test/public [EngSys] upgrade to prettier v3 2024-01-10 18:45:01 -05:00
.eslintrc.json Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
CHANGELOG.md Post release automated changes for purview releases (#25184) 2023-03-20 13:12:37 -07:00
LICENSE Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
README.md Increment minimum supported node version to 16 2023-10-09 21:09:54 +00:00
api-extractor.json Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
assets.json migrate rlc recording (#26430) 2023-07-11 15:52:20 +08:00
karma.conf.js Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
package.json [EngSys] upgrade dev dependency `typescript` version to `~5.5.3` 2024-07-03 22:24:35 +00:00
sample.env Add purview workflow (#24744) 2023-03-09 15:50:28 +08:00
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.