tiltcamp / outseta-api-client

Typed API client for Outseta.
https://www.npmjs.com/package/outseta-api-client
MIT License
17 stars 1 forks source link

OutsetaApiClient is not a constructor #16

Closed mwilliams1188 closed 3 years ago

mwilliams1188 commented 3 years ago

I'm getting the error 'OutsetaApiClient is not a constructor' when trying to initialize in firebase. Is this library ready to go? Below is my code:

`var OutsetaApiClient = require('outseta-api-client')

const outseta = new OutsetaApiClient({ subdomain: 'mycompany', apiKey: functions.config().outseta.key, secretKey: functions.config().outseta.secret })`

mattwebbio commented 3 years ago

Hey Mike!

I'm using this library in my own app, but I'm using ES6 imports in a browser runtime. Here's a working example that I just tested in Node 14; notice the .default on the require statement and the fetch polyfill - I'll update the example in the readme to reflect these.

globalThis.fetch = require('node-fetch');
var OutsetaApiClient = require('outseta-api-client').default;

const outseta = new OutsetaApiClient({
  subdomain: 'mycompany',
  apiKey: functions.config().outseta.key,
  secretKey: functions.config().outseta.secret
});

outseta.crm.accounts.getAll().then((accounts) => {
  console.log(accounts);
});
mattwebbio commented 3 years ago

Closing - let me know if you encounter any other issues!

ap1969 commented 2 years ago

Hi, That's weird, I'm getting this in an ES6 import:

import OutsetaApiClient from 'outseta-api-client';
const client = new OutsetaApiClient({
    subdomain: 'admin-tool',
    apiKey: process.env.OUTSETA_KEY,
    secretKey: process.env.OUTSETA_SECRET,
});

Same error: "OutsetaApiClient is not a constructor"

ap1969 commented 2 years ago

@mattwebbio In fact, even using your code in Node 14 results in "Must use import to load ES Module" for node-fetch

ap1969 commented 2 years ago

Ah. I had to downgrade to node-fetch v2.x.x for it to work in ES5.