adobe / adobe/target-nodejs-sdk

problem using in akamai edgworkers

Open
#54 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
26
Forks
22
PR merge metrics
No merged PRs in 30d

Description

### Expected Behaviour
I expect I can use the sdk in an akamai edgeworker

### Actual Behaviour
Edgeworker static validation fails

### Reproduce Scenario (including but not limited to)

#### Steps to Reproduce
import sdk version > 2.1.1 to an akamai edgworker js file
Upload edgworker using cli (eg `akamai ew upload --codeDir ./ [workerID]`
reported error:
```
{
"type": "/edgeworkers/error-types/edgeworkers-invalid-argument",
"title": "Invalid Argument.",
"detail": "Tarball validation failed: static validation failed : main.js::12:24 Unknown built-in module: \"crypto\".",
"instance": "/edgeworkers/error-instances/124d6da6-ebb0-4153-a145-ca67704ae8fc",
"status": 400,
"errorCode": "EW1108",
"traceId": "f01b60cc2d1f1c55"
}
```

#### Platform and Version
akamai edgeworker

#### Sample Code that illustrates the problem
main.js :
```
import { httpRequest } from "http-request";
import { createResponse } from "create-response";
import { logger } from "log";
import { Cookies } from "cookies";
/** end provided modules */
import TargetClient from "@adobe/target-nodejs-sdk";

const clientCode = "xxxx";
const organizationId = "xxxx;
const rulesUrl = `https://assets.adobetarget.com/${clientCode}/production/v1/rules.json`;

function createTargetClient(rules) {
return new Promise((resolve) => {
const result = TargetClient.create({
client: clientCode,
organizationId: organizationId,
decisioningMethod: "on-device",
artifactPayload: rules,
pollingInterval: 0, // "0" prevents polling, if artifactPayload is provided
targetLocationHint: "", // prevent cluster discovery
logger: logger, // use Akamai EdgeWorker provided logger
fetchApi: httpRequest,
events: {
clientReady: () => resolve(result),
},
});
});
}

export async function responseProvider(request) {
try {
const deliveryRequest = {
execute: {
mboxes: [
{
address: { url: request.host + request.url },
name: "a1-serverside-ab",
},
],
},
};

const rules = await httpRequest(rulesUrl).then((response) => response.json());
const client = await createTargetClient(rules);
const cookies = new Cookies(request.getHeader("Cookie"));
const visitorCookie = cookies.get(TargetClient.getVisitorCookieName(organizationId));
const targetCookie = cookies.get(TargetClient.TargetCookieName);
const { response } = await client.getOffers({ request: deliveryRequest, visitorCookie, targetCookie });

return createResponse(200, {}, JSON.stringify(response));
} catch (e) {
logger.log(e);
return createResponse(400, {}, JSON.stringify(e));
}
}

```

i'm working from this example: https://github.com/artur-ciocanu/odd-akamai-edge-workers/

if I pin my version to 2.1.1 then I can avoid the issue

#### Logs taken while reproducing problem

Contributor guide

Open the contributing guide

Research direction

Start with the provided main.js reproduction and compare SDK version 2.1.1 with versions after 2.1.1. Check which dependency change introduces the crypto import rejected by Akamai EdgeWorker static validation. Done means the SDK can be imported and uploaded through the shown Akamai CLI flow without the validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.