Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import NodeRSA from "node-rsa";
const keyData = {
consumerId: "CONSUMER_ID",
privateKey: `-----BEGIN RSA PRIVATE KEY-----
MY PRIVATE KEY
-----END RSA PRIVATE KEY-----`,
keyVer: 1,
impactId: "YOUR IMPACT AFFILIATE ID" // not required
},
const generateWalmartHeaders = () => {
const { privateKey, consumerId, keyVer } = keyData;
const hashList = {
"WM_CONSUMER.ID": consumerId,
"WM_CONSUMER.INTIMESTAMP": Date.now().toString(),
"WM_SEC.KEY_VERSION": keyVer,
};
const sortedHashString = `${hashList["WM_CONSUMER.ID"]}\n${hashList["WM_CONSUMER.INTIMESTAMP"]}\n${hashList["WM_SEC.KEY_VERSION"]}\n`;
const signer = new NodeRSA(privateKey, "pkcs1");
const signature = signer.sign(sortedHashString);
const signature_enc = signature.toString("base64");
return {
"WM_SEC.AUTH_SIGNATURE": signature_enc,
"WM_CONSUMER.INTIMESTAMP": hashList["WM_CONSUMER.INTIMESTAMP"],
"WM_CONSUMER.ID": hashList["WM_CONSUMER.ID"],
"WM_SEC.KEY_VERSION": hashList["WM_SEC.KEY_VERSION"],
};
};
export const getProductById = async (productId) => {
const options = {
method: "GET",
headers: generateWalmartHeaders(),
};
const res = await fetch(
`https://developer.api.walmart.com/api-proxy/service/affil/product/v2/items/${productId}?publisherId=${keyData.impactId}`,
options
);
return await res.json()
};
@dosstx
Copy link

dosstx commented May 3, 2022

I tried to use this but Im getting a weird error :
Error: error:25078067:DSO support routines:win32_load:could not load the shared library

Ever seen this error? More details about my issue: https://stackoverflow.com/questions/72100029/node-rsa-and-firebase-function-why-the-error-dso-support-routineswin32-load

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment