Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ManagementClient#importUsers returns Promise of IncomingMessage #467

Closed
orangain opened this issue Mar 4, 2020 · 1 comment · Fixed by #492
Closed

ManagementClient#importUsers returns Promise of IncomingMessage #467

orangain opened this issue Mar 4, 2020 · 1 comment · Fixed by #492

Comments

@orangain
Copy link
Contributor

orangain commented Mar 4, 2020

Description

exportUsers() and getJob() returns promise of job object as expected. However, importUsers() returns a promise of IncomingMessage object[1]. This seems to be inconsistent.

To wait until the import job is completed, we need to get an ID of the job from the response. To do so, we need to parse the response body like const job = JSON.parse(resImportUsers.body).

It would be great if importUsers() returns a promise of job object as exportUsers() and getJob() do.

[1] https://github.com/auth0/node-auth0/blob/v2.23.0/src/management/JobsManager.js#L214

Reproduction

// reproduce.js
const auth0 = require("auth0")
const ManagementClient = auth0.ManagementClient

const client = new ManagementClient({
  domain: "****.auth0.com",
  clientId: "*****",
  clientSecret: "****",
})

;(async () => {
  console.log("--- exportUsers ---")
  const resExportUsers = await client.exportUsers({})
  console.log(resExportUsers) // Job object as expected

  console.log("--- getJob ---")
  const resGetJob = await client.getJob({ id: resExportUsers.id })
  console.log(resGetJob) // Job object as expected

  console.log("--- importUsers ---")
  const resImportUsers = await client.importUsers({
    connection_id: "con_*******",
    users_json: `[{"email":"sample@example.com"}]`,
  })
  console.log(resImportUsers) // IncomingMessage object as not expected
  console.log("-------------------")
  console.log(JSON.parse(resImportUsers.body)) // What we actually need
})()
$ node reproduce.js
--- exportUsers ---
{ type: 'users_export',
  status: 'pending',
  format: 'csv',
  created_at: '2020-03-04T10:38:58.748Z',
  id: 'job_*****' }
--- getJob ---
{ type: 'users_export',
  status: 'completed',
  format: 'csv',
  created_at: '2020-03-04T10:38:58.748Z',
  id: 'job_*****',
  location:
   'https://user-exports.auth0.com/job_*****/...' }
--- importUsers ---
IncomingMessage {
  _readableState:
  ...
  body:
   '{"type":"users_import","status":"pending","connection_id":"con_*****","connection":"Username-Password-Authentication","created_at":"2020-03-04T10:39:00.504Z","id":"job_*****"}' }
-------------------
{ type: 'users_import',
  status: 'pending',
  connection_id: 'con_*****',
  connection: 'Username-Password-Authentication',
  created_at: '2020-03-04T10:39:00.504Z',
  id: 'job_*****' }

Environment

  • Version of this library used: auth0@2.23.0
  • Other relevant versions (language, server software, OS, browser): Node.js v10.15.3, macOS 10.14
@jpcanepa
Copy link

I'm being hit by this same problem (although I think the response is the axios response schema, so the response I actually care about is in the data field). I think it all can be fixed by doing something like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants