开发者社区> 镜像站> NPM> @adobe/asset-compute-client
@adobe/asset-compute-client
Adobe Asset Compute Client
Last updated 2 months ago by adobe-admin .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @adobe/asset-compute-client 
SYNC missed versions from official npm registry.

Adobe Asset Compute Client

Version License Travis

Overview

Javascript client for the Adobe Asset Compute Service. Currently only tested with Nodejs. The Javascript API is separated in 3 parts:

  • AssetCompute - A light-weight wrapper around the AssetCompute API.
  • AssetComputeEventEmitter - Listens to an I/O event journal and converts the events to rendition_created and rendition_failed events.
  • AssetComputeClient - A higher level client that provides a simpler API

AssetComputeClient has the following capabilities:

  • Fully initialize Asset Compute through a previously provisioned integration
  • Listens to I/O events on the integration
  • Invoke Asset Compute process asynchronously
  • Wait for a single Asset Compute process request to finish (default timeout is 60s)
  • Wait for all Asset Compute process requests to finish (default timeout is 60s)

Installation

npm i @adobe/asset-compute-client

Usage

Using the Class Initialization

After the client is set up, you must call .register() once before the first call to .process().

If the integration does not already have an I/O Events journal registered, it may take some time after calling .register() to be able to recieve and send I/O Events so it is recommended to add some wait time before calling .process().

If the integration already has an I/O Events journal registered, it is recommended to not wait before calling .process().

    const { AssetComputeClient, getIntegrationConfiguration } = require("@adobe/asset-compute-client");
    const sleep = require('util').promisify(setTimeout);

    //If integration file is json, a private key file must also be provided
    const integrationFilePath = "/path/to/integration/file"; // Either json or yaml format
    const integration = await getIntegrationConfiguration(integrationFilePath[, privateKeyFile]);
    const assetCompute = new AssetComputeClient(integration);

    // Call register before first call the process
    await assetCompute.register();

    // add wait time for events provider to set up
    await sleep(45000); // 30s

    const { requestId } = await assetCompute.process(
        "https://presigned-source-url", [
            {
                name: "rendition.png",
                url: "https://presigned-target-url",
                fmt: "png",
                width: 200,
                height: 200
            }
        ]
    )
    const events = await assetCompute.waitActivation(requestId);
    if (events[0].type === "rendition_created") {
        // use the rendition
    } else {
        // failed to process
    }

Error message printing

Note that any errors while polling the I/O Event journal will be logged before it retries:

Error polling event journal: request to https://events-va6.adobe.io/.... failed, reason: connect ECONNREFUSED 54.81.231.29:443

To add custom error message handling, listen for the error event:

assetCompute.on("error", error => console.log("custom error message", error.message));

Or disable any error message output:

assetCompute.on("error", () => {});

Using AssetComputeClient.create() for Initialization

This function creates a new instance of AssetComputeClient and calls the .register() method.

    const { AssetComputeClient, getIntegrationConfiguration } = require("@adobe/asset-compute-client");

    //If integration file is json, a private key file must also be provided
    const integrationFilePath = "/path/to/integration/file"; // Either json or yaml format
    const integration = await getIntegrationConfiguration(integrationFilePath[, privateKeyFile]);
    const assetCompute = await AssetComputeClient.create(integration);
    // add wait time if needed
    const { requestId } = await assetCompute.process(
        "https://presigned-source-url", [
            {
                name: "rendition.png",
                url: "https://presigned-target-url",
                fmt: "png",
                width: 200,
                height: 200
            }
        ]
    )
    const events = await assetCompute.waitActivation(requestId);
    if (events[0].type === "rendition_created") {
        // use the rendition
    } else {
        // failed to process
    }

Register

After setting up the client, it is necessary to call .register() once before calling .process().

If the integration already has an I/O Events journal registered, you still must call register. The journal url returned from register is necessary for the client to retrieve I/O Events.

If the integration does not have an I/O Events journal registered, make sure to add some wait time after calling .register() before calling .process(). (It is recommended to wait around ~45 seconds)

const assetCompute = new AssetComputeClient(integration);
await assetCompute.register();

Unregister

The unregister method will remove the I/O Events Journal created in .register(). It is necessary to call .register() again before attempting to use the client after unregistering.

Example usage:

const assetCompute = new AssetComputeClient(integration);
await assetCompute.register();
await assetCompute.process(..renditions);

// unregister journal
await assetCompute.unregister();

// call to process will fail, must call `register()` again first
try {
    await assetCompute.process(..renditions);
} catch (e) {
    // expected error, must call `register()` first
}

await assetCompute.register();
sleep(45000); // sleep after registering to give time for journal to set up
await assetCompute.process(..renditions);

@adobe/node-fetch-retry

Fetch retry options are documented here.

Contributing

Contributions are welcomed! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

Current Tags

  • 4.3.2                                ...           latest (2 months ago)

12 Versions

  • 4.3.2                                ...           2 months ago
  • 4.3.1                                ...           4 months ago
  • 4.2.3                                ...           4 months ago
  • 4.2.2                                ...           4 months ago
  • 4.3.0                                ...           5 months ago
  • 4.2.1                                ...           6 months ago
  • 4.2.0                                ...           6 months ago
  • 4.1.2                                ...           6 months ago
  • 4.1.1                                ...           6 months ago
  • 4.1.0                                ...           6 months ago
  • 1.0.1                                ...           7 months ago
  • 1.0.0                                ...           7 months ago