DynamicsWebApi returning empty object but only in Wix

I’m making a connector I can use to access Microsoft Dynamics 365 data within a Wix site. I made a .JSW for the backend code, and it is supposed to return an object with a dynamicsWebApi property which I can then make calls to the API on. This code is 100% working in my IDE, but putting it on Wix breaks it.

dynamics.jsw:

/*
* This service retrieves access token from 
* microsoft and then instantiates the dynamics web-api 
* service
*/

import DynamicsWebApi from 'dynamics-web-api';
import adal from 'adal-node';
let getSecret = require('wix-secrets-backend').getSecret;

class DynamicsConnector {
 constructor(tenantId, resource, clientId, clientSecret) {
 this.authorityUrl = null; // Redacted as I cannot post links with this account yet -- but this is working in my code and not null
 this.resource = `https://${resource}/`;
 this.apiUrl = resource;
 this.clientId = clientId;
 this.clientSecret = clientSecret;

 //create DynamicsWebApi object
 this.dynamicsWebApi = new DynamicsWebApi({
      webApiUrl: `https://${this.apiUrl}/api/data/v9.1/`,
      onTokenRefresh: (cb) => this.acquireTokens(cb),
 });
 this.adalContext = new adal.AuthenticationContext(this.authorityUrl);
 }

  acquireTokens(dynamicsCallback) {
 const adalCallback = (error, token) => {
 if (!error) {
 //call DynamicsWebApi callback only when a token has been retrieved
        dynamicsCallback(token);
 } else {
        console.log('Token has not been retrieved. Error: ' + error.stack);
 }
 };
 this.adalContext.acquireTokenWithClientCredentials(this.resource, this.clientId, this.clientSecret, adalCallback);
 }
}

export async function dynamicsWorker() {
 let creds = await Promise.all([
    getSecret('TENANT_ID'),
    getSecret('CRM_ORG_URL'),
    getSecret('CLIENT_ID'),
    getSecret('CLIENT_SECRET'),
 ]);

 //instantiate the service
 let connector = new DynamicsConnector(
    creds[0], // TENANT_ID
    creds[1], // CRM_ORG_URL
    creds[2], // CLIENT_ID
    creds[3], // CLIENT_SECRET
 );

 return connector;
}

Frontend code:

import { dynamicsWorker } from ‘backend/dynamics’;

$w.onReady(async function () {
let dynamics = (await dynamicsWorker()).dynamicsWebApi;
// console.log(dynamics.retrieveMultiple);
let result = await dynamics.retrieveMultiple(““, [””], “statecode eq 0”);

console.log(result);
});


The code throws the following error:
TypeError: n.retrieveMultiple is not a function. (In ‘n.retrieveMultiple(“c9_memberships”,[“c9_name”],“statecode eq 0”)’, ‘n.retrieveMultiple’ is undefined)

On further inspection, when I console.log the dynamics object from the frontend code, I get an object with all of the properties I would expect, except the .dynamicsWebApi object, which is present, but is just an empty object: {}.

Since this code works just fine on my machine with node.js, and we added dynamics-web-api from node manually via requesting the package from NPM, I’m wondering whether I’m doing something wrong when passing the object through to the frontend, or if there’s just something about the package itself that can’t run in Velo. Would very much appreciate any help and suggestions!

Thank you.