@adobe/asset-compute-commons

中文文档
2.0.0发布于 2026/10/07Apache-2.0CommonJS近 30 天下载 6785

Common utilities needed by all Adobe Asset Compute serverless actions

原始使用文档
文档目录14 节
  1. Installation
  2. API Details
  3. Asset Compute Events
  4. Asset Compute Metrics
  5. Asset Compute Errors
  6. Asset Compute Log Utils
  7. Apache OpenWhisk Action Name
  8. Asynchronous Events
  9. Event Types
  10. Event Attributes
  11. Metadata
  12. Error Reasons
  13. Contributing
  14. Licensing

Version

asset-compute-commons

Common utilities needed by all Asset Compute serverless actions

Installation

npm install @adobe/asset-compute-commons

API Details

Asset Compute commons contains many different libraries that take care of common functionalities for workers like Adobe IO Events, New Relic metrics, and custom errors.

Asset Compute Events

Asset Compute event handler for sending Adobe IO Events

Constructor parameters

AssetComputeEvents constructor supports the following mandatory parameters:

  • params: object must contain authorization parameters:
    • auth.accessToken
    • orgId or auth.orgId
    • clientId or auth.clientId

AssetComputeEvents constructor supports the following optional parameters:

  • retry: retry options from node-fetch-retry for sending IO events. (defaults to node-fetch-retry default options)

Sending Events

The sendEvent method sends an Adobe IO Event.

AssetComputeEvents.sendEvent method takes in two required parameters: type and payload.

  • type: String containing the Adobe IO Event type (either rendition_created or rendition_failed)
  • payload: Object containing the event payload

see Asset Compute API Document: Asynchronous Events for more on this topic

Examples

Example with custom retry options:

const { AssetComputeEvents } = require('@adobe/asset-compute-commons');

const params = {
    auth: {
        accessToken: '12345',
        orgId: 'orgId',
        clientId: 'clientId`
    }
}
const retry = {
    retryMaxDuration: 1000 // in ms
}
const eventsHandler  = new AssetComputeEvents(params, retry);

await eventsHandler.sendEvent('rendition_created', {
            rendition: {
                name: 'rendition.jpg',
                fmt: 'jpg'
            }
      });

Example with a rendition_failed event type:

const { AssetComputeEvents } = require('@adobe/asset-compute-commons');

const params = {
    auth: {
        accessToken: '12345',
        orgId: 'orgId',
        clientId: 'clientId`
    }
}
const eventsHandler  = new AssetComputeEvents(params);

await eventsHandler.sendEvent('rendition_failed', {
            rendition: {
                name: 'rendition.21',
                fmt: '21'
            },
            errorReason: 'RenditionFormatUnsupported',
            errorMessage: 'Rendition format `21` is not supported'
     });

Asset Compute Metrics

Asset Compute metrics handler for sending New Relic metrics. It uses a node js agent node-openwhisk-newrelic to send metrics to New Relic.

Constructor parameters

AssetComputeMetrics constructor supports the following mandatory parameters:

  • params: Object must contain New Relic metrics parameters:
    • newRelicEventsURL: New Relic Insights Events url (should be of the form: https://insights-collector.newrelic.com/v1/accounts/<YOUR_ACOUNT_ID>/events)
    • newRelicApiKey: New Relic Insights API key (see the "Register an Insert API key" section here)

AssetComputeMetrics constructor supports the following optional parameters:

Simple example

Initiates metrics handler, sends metrics and stops metrics agent:

const { AssetComputeMetrics } = require('@adobe/asset-compute-commons');

const params = {
    newRelicEventsURL: 'https://insights-collector.newrelic.com/v1/accounts/<YOUR_ACOUNT_ID>/events',
    newRelicApiKey: 'YOUR_API_KEY',
    // ... rest of the Asset Compute parameters

}
const metricsHandler = new AssetComputeMetrics(params);
const metrics = {
    downloadDuration: 200,
    size: 3000
}
await metricsHandler.sendMetrics('rendition', metrics);
await metricsHandler.activationFinished(); // see https://github.com/adobe/node-openwhisk-newrelic#usage for information about `activationFinished()`

Other additional functions

Adding custom metrics:

metricsHandler.add({
    uuid: '12345',
    count: 2
});

Get current state of metrics:

console.log(metricsHandler.get()); // should print out metrics added in `metricsHandler.add()`

Sending error metrics (sends metrics with event type error):

const location = 'upload_worker_flite';
const message = 'Invalid file format';
const metrics = {
    downloadDuration: 200,
    size: 3000
}
await metricsHandler.sendErrorMetrics(location, message, metrics);

Sending client error metrics (sends metrics with event type client_error):

const location = 'upload_worker_flite';
const message = 'Invalid file format';
const metrics = {
    downloadDuration: 200,
    size: 3000
}
await metricsHandler.sendClientErrorMetrics(location, message, metrics);

Sending error metrics by exceptions thrown (sends metrics with event type client_error or error depending on the error):

foo() {
    try {
        console.log('hello!');
    } catch (error) {
        metricsHandler.handleError(error, {
            location: "mylocation",
            message: "something failed",
            metrics: {}
        });
    }
}

Asset Compute Errors

There are several custom errors used in Asset Compute workers:

Error types

TypeDescriptionProperties
errorunexpected errors and exceptionsmessage, date, location
client_errorerrors caused by client misconfigurationmessage, date, reason

Error Properties

  • message: error message
  • date: current time in UTC of when the error was thrown
  • location: location where the error took place (only in type error)
  • reason: the reason for the error (only in client errors)
    • must be one of list: "SourceFormatUnsupported", "RenditionFormatUnsupported", "SourceUnsupported", "SourceCorrupt", "RenditionTooLarge" }

Custom Errors

NameDescriptionType
SourceFormatUnsupportedErrorThe source is of an unsupported type.client error
RenditionFormatUnsupportedErrorThe requested format is unsupported.client error
SourceUnsupportedErrorThe specific source is unsupported even though the type is supported.client error
SourceCorruptErrorThe source data is corrupt. Includes empty files.client error
RenditionTooLargeErrorThe rendition could not be uploaded using the pre-signed URL(s) provided in target. The actual rendition size is available as metadata in repo:size and can be used by the client to re-process this rendition with the right number of pre-signed URLs.client error
ArgumentErrorWrong arguments (type, structure, etc.)error
GenericErrorAny other error.error

Examples

Generic error downloading the source file in action worker-pie:

const { GenericError } = require('@adobe/asset-compute-commons');

const message = 'Error while downloading source file!'
const location = 'download_worker_pie'
throw new GenericError(message, location);

Rendition format is unsupported:

const { RenditionFormatUnsupportedError } = require('@adobe/asset-compute-commons');

const message = 'Rendition format `sdfg` is not supported'
throw new RenditionFormatUnsupportedError(message);

Asset Compute Log Utils

Utilities for removing sensitive information from Asset Compute worker logs

Examples

Redacting access token from logs:

const { AssetComputeLogUtils } = require('@adobe/asset-compute-commons');

params = {
    accessToken: '123453467',
    fmt: 200
}
console.log("Asset Compute parameters:", AssetComputeLogUtils.redactUrl(params)); // should replace access token with "[...REDACTED...]"

Prints out exact same logs using AssetComputeLogUtils.log method:

const { AssetComputeLogUtils } = require('@adobe/asset-compute-commons');

params = {
    accessToken: '123453467',
    fmt: 200
}
AssetComputeLogUtils.log(params, "Asset Compute parameters"); // should replace access token with "[...REDACTED...]"

Apache OpenWhisk Action Name

A simple way to get information about the Apache OpenWhisk action.

Properties (all default to empty strings)

  • name: base Apache OpenWhisk action name
  • package: Apache OpenWhisk package name
  • namespace: Apache OpenWhisk namespace
  • fullname: full Apache OpenWhisk action name, including namespace, package and action name from environment variable __OW_ACTION_NAME

Examples:

const actionInfo = new OpenwhiskActionName();
console.log(actionInfo.name) // prints out something like `worker-pie`
console.log(actionInfo.package) // prints package name, ex: `experimental`
console.log(actionInfo.namespace) // prints namespace, ex: `stage`
console.log(actionInfo.fullname) // prints full name, ex: /stage/experimental/worker-pie

Asynchronous Events

When processing is finished, or if errors occurred, events are sent through Adobe I/O Events. Events are JSON objects in the event field of the objects in the events array of the jorunal response.

The I/O event type for all events of the Asset Compute service is asset_compute. The journal will be automatically subscribed to this event type only, and consumers are not expected to filter based on the i/o event type.

The service specific event types are available in the type property of the event.

Event Types

EventDescription
rendition_createdSent for each successfully processed and uploaded rendition.
rendition_failedSent for each rendition that failed to process or upload.

Event Attributes

AttributeTypeEventDescription
datestring*Timestamp when event was sent in simplified extended ISO-8601 format (as defined by Javascript Date.toISOString()).
requestIdstring*The request id of the original request to /process, same as X-Request-Id header.
sourceobject*The source of the /process request.
userDataobject*The userData of the /process request if set.
renditionobjectrendition_*The corresponding rendition object passed in /process.
metadata objectrendition_createdThe metadata properties of the rendition.
errorReasonstringrendition_*Rendition failure reason if any.
errorMessagestringrendition_*Text giving more detail about the rendition failure if any.

Metadata

PropertyDescription
tiff:ImageWidthThe width of the rendition in pixels. Will not be present if the rendition is not an image.
tiff:ImageLengthThe length of the rendition in pixels. Will not be present if the rendition is not an image.
repo:sizeThe size of the rendition in bytes.
repo:sha1The sha1 digest of the rendition.

Error Reasons

ReasonDescription
SourceFormatUnsupportedThe source is of an unsupported type.
RenditionFormatUnsupportedThe requested format is unsupported.
SourceUnsupportedThe specific source is unsupported even though the type is supported.
SourceCorruptThe source data is corrupt. Includes empty files.
RenditionTooLargeThe rendition could not be uploaded using the pre-signed URL(s) provided in target. The actual rendition size is available as metadata in repo:size and can be used by the client to re-process this rendition with the right number of pre-signed URLs.
GenericErrorAny other error.

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.


版本与发布记录

@adobe/asset-compute-commons 共发布 20 个版本,首次发布于 2020/05/02;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.0latest2026/10/0730 天前
1.4.12024/11/271.9 年前
1.4.02023/12/042 年前
1.3.12023/11/282 年前
1.3.02023/11/152 年前
1.2.12023/11/082 年前

关于 @adobe/asset-compute-commons 的常见问题

@adobe/asset-compute-commons 是什么?

Common utilities needed by all Adobe Asset Compute serverless actions

如何安装 @adobe/asset-compute-commons?

在项目目录运行 npm install @adobe/asset-compute-commons,或使用 pnpm add / yarn add / bun add。

@adobe/asset-compute-commons 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__asset-compute-commons 是否存在。

@adobe/asset-compute-commons 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/asset-compute-commons 可以商用吗?

@adobe/asset-compute-commons 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/asset-compute-commons 的下载量有多少?

根据 npm 官方下载统计,@adobe/asset-compute-commons 在 2026/10/05 – 2026/11/03 这 30 天内被下载 6,785 次,日均约 226 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/asset-compute-commons 还在维护吗?

最新版本 2.0.0 发布于 2026/10/07(30 天前);至今共发布 20 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/05/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。