# @adobe/asset-compute-client

> Adobe Asset Compute Client

Latest version **5.2.1** (published 2024-10-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @adobe/asset-compute-client
pnpm add @adobe/asset-compute-client
yarn add @adobe/asset-compute-client
bun add @adobe/asset-compute-client
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.2.1 |
| Published | 2024-10-30 |
| First published | 2020-04-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 73.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Adobe Inc. |
| Maintainers | amol-anand, doten, stopp-adobe, dylandepass, djaeggi, adobehalls, fullcolorcoder, marbec, tripod, garthdb, lazd, adobe-admin, patrickfulton, trieloff, shazron, krisnye, dcpfsdk, natebaldwin, devongovett, aspro83, symanovi, dpfister, stefan-guggisberg, korra, rofe, kptdobe |
| Keywords | scripts, openwhisk, asset compute, client, adobe |

## Links

- npm: https://www.npmjs.com/package/@adobe/asset-compute-client
- Repository: https://github.com/adobe/asset-compute-client
- Homepage: https://github.com/adobe/asset-compute-client#readme
- Issues: https://github.com/adobe/asset-compute-client/issues
- npm.io page: https://npm.io/package/@adobe/asset-compute-client

## Dependencies (6)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [clone](https://npm.io/package/clone.md) ^2.1.2
- [js-yaml](https://npm.io/package/js-yaml.md) ^4.1.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [@adobe/node-fetch-retry](https://npm.io/package/@adobe/node-fetch-retry.md) ^2.0.0
- [@adobe/asset-compute-events-client](https://npm.io/package/@adobe/asset-compute-events-client.md) ^1.2.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 5.2.1 (latest) — 2024-10-30
- 5.2.0 — 2023-11-29
- 5.1.1 — 2023-11-07
- 5.1.0 — 2023-05-02
- 5.0.1 — 2023-01-30
- 5.0.0 — 2022-02-04
- 4.3.8 — 2021-10-26
- 4.3.7 — 2021-10-01
- 4.3.6 — 2021-08-17
- 4.3.5 — 2021-08-05
- 4.3.4 — 2021-03-29
- 4.3.3 — 2021-02-02
- 4.3.2 — 2020-10-08
- 4.3.1 — 2020-07-22
- 4.2.3 — 2020-07-21
- … 9 more at https://npm.io/package/@adobe/asset-compute-client/versions

## README

# Adobe Asset Compute Client

[![Version](https://img.shields.io/npm/v/@adobe/asset-compute-client.svg)](https://npmjs.org/package/@adobe/asset-compute-client)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Travis](https://travis-ci.com/adobe/asset-compute-client.svg?branch=master)](https://travis-ci.com/adobe/asset-compute-client)

## Overview

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

- [AssetCompute](lib/assetcompute.js) - A light-weight wrapper around the AssetCompute API.
- [AssetComputeEventEmitter](lib/eventemitter.js) - Listens to an I/O event journal and converts the events to `rendition_created` and `rendition_failed` events.
- [AssetComputeClient](lib/client.js) - A higher level client that provides a simpler API
    - by default, uses `node-fetch-retry` for retrying on other HTTP responses
    - by default, provides custom, smarter retry behavior on HTTP status code 429 (Too many requests).

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)

[`retry`](lib/retry.js) has the following capabilities:
- additional features to retry on 429s for `/unregister`, `/register`, and `/process`
- Looks at the `retry-after` header in the HTTP response to determine how long to wait (in seconds) before retrying
- If no `retry-after` is present, choose a random wait time between 30-60 seconds
- Configurable retry count via `max429RetryCount` option. (Defaults to 4 retries)
- Disable completely via the `disable429Retry` option. (Defaults to 4 retries)
## 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()`.
```javascript
    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:

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

Or disable any error message output:

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


### Using `AssetComputeClient.create()` for Initialization

This function creates a new instance of `AssetComputeClient` and calls the `.register()` method.
```javascript
    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)
```js
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:
```js
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);
```
### Using custom 429 retry options
By default, `AssetComputeClient` will retry 4 times (with smart backpressure) on 429s.

Retry 10 times on 429s:
```js
const assetCompute = new AssetComputeClient(integration, {
    max429RetryCount: 10
});
```
Disable retry on 429s:
```js
const assetCompute = new AssetComputeClient(integration, {
    disable429Retry: false
});
```

### @adobe/node-fetch-retry
Fetch retry options are documented [here](https://github.com/adobe/node-fetch-retry#optional-custom-parameters). The default options are used on each fetch request.

Note: these do not cover retrying on 429s since this requires the custom retry logic (retry.js) (ie, retrying every 1s with backoff could worsen the issue in a situation when the endpoint is overloaded)


### Contributing
Contributions are welcomed! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information.

### Licensing
This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

---
_Source: https://npm.io/package/@adobe/asset-compute-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
