1.0.0 • Published 4 years ago

@janiscommerce/vtex-account-processes v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Vtex Account Processes

Build Status Coverage Status npm version

Update Process for VTEX Account in VTEX-Commerce

:arrow_down: Installation

npm install @janiscommerce/vtex-account-processes

:wrench: Configuration

:warning: This package need to be instance with API-Session, before use.

:x: Wrong:

const { VtexAccountProcesses } = require('@janiscommerce/vtex-account-processes');

const vtexAccountProcess = new VtexAccountProcesses();

:heavy_check_mark: Good:

const { VtexAccountProcesses } = require('@janiscommerce/vtex-account-processes');
const { ApiSession } = require('@janiscommerce/api-session');

const vtexAccountProcess = session.getSessionInstance(VtexAccountProcesses);

:calling: API

  • send(accountId, processName, status, content, options)
    • Async
    • Description: Update processName for accountId in VTEX-Commerce with status.
    • Parameters:
      • accountId : OBJECT-ID VTEX Account ID in VTEX-Commerce
      • processName : STRING name of the process
      • status : STRING new Status for that process
      • content : OBJECT, OPTIONAL, Extra Data you want to add for that process, whatever you want to save, for example a message, or an error stack, etc.
      • options : OBJECT, OPTIONAL, To add the Start Date or an End Date
    • Returns: OBJECT
      • statusCode: HTTP Status code of the call to VTEX-Commerce
      • body: Body response

:spades: Statuses

You can get the valid Statuses using:

  • statuses
    • static getter
    • Returns: OBJECT
      • pending
      • processing
      • success
      • error
statususing packageview in vtex-commerce
pendingVtexAccountProcesses.statuses.pendingaccount-process-status-pending
processingVtexAccountProcesses.statuses.processingaccount-process-status-processing
successVtexAccountProcesses.statuses.successaccount-process-status-success
errorVtexAccountProcesses.statuses.erroraccount-process-status-error

Content

This is used to keep an extra information in Account Process API, like a log.

In the process:

await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.pending,
    { message: 'Start Importing Categories from VTEX' } // CONTENT
);

In Vtex-Commerce:

account-process-content

:clock1: Options

Now, there are 2 options

  • startDate: BOOLEAN, to add an Date-Now ISO-String, to indicate the start of the process
  • endDate: BOOLEAN, to add an Date-Now ISO-String, to indicate the end of the process

This is use to set in Account-Process API these properties.

In the process:

// Start the process in 31/12/1969 21:00hs
await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.pending,
    null,
    { startDate: true }
);

// Finish the process in 05/08/2020 11:57hs
await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.success,
    null,
    { endDate: true }
);

In Vtex-Commerce:

account-process-dates

:arrow_forward: Usage

  • Send with minimal data, and pending status, and create a process in VTEX-Commerce
const response = await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.pending
)

/*
Response: {
    statusCode: 200,
    body: {
        id: '5dea9fc691240d0008408000'
    }
}

*/
  • Send with content, and processing status, and Account is not found in VTEX-Commerce
const response = await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.processing,
    { itemsImported: 10, itemsNotModified: 1 }
);

/*
Response: {
    statusCode: 404,
    body: {
        message: 'Account not found'
    }
}

*/
  • Send with a Start Date, and error status, and VTEX-Commerce is failing
const response = await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.error,
    null // No Content,
    { startDate: true }
);

/*
Response: {
    statusCode: 503,
    body: {
        message: 'Timeout'
    }
}

*/
  • Send with an End Date, and success status, and update an existing process in VTEX-Commerce
const response = await vtexAccountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    VtexAccountProcesses.statuses.success,
    null // No Content,
    { endDate: true }
);

/*
Response: {
    statusCode: 200,
    body: {
        id: '5dea9fc691240d0008408000'
    }
}

*/

:x: Errors

The errors are informed with a VtexAccountProcessesError. This object has a code that can be useful for a debugging or error handling. The codes are the following:

CodeDescription
1No Session
2Invalid Account Id
3Invalid Process Name
4Invalid Status
5Invalid Content
6Invalid Options