npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@janiscommerce/account-process

v3.0.0

Published

Creates or Updates a Process of Janis Commerce Service Account

Downloads

70

Readme

Account Process

Build Status Coverage Status npm version

Creates or Updates a Process of Janis Commerce Service Account

:arrow_down: Installation

npm install @janiscommerce/account-process

:new: Changes from v3.0.0

Using @janiscommerce/lambda with version 6.x.y to use AWS SDK in V3.

:new: Changes from v2.0.0

service field

Env variable JANIS_SERVICE_NAME is required for saving and AccountProcess.

Using Lambda instead of Api

Now the package uses Commerce Lambda function SaveAccountProcess instead of old Api.

Response

The response of send() has changed cause now we are using lambda instead of microservice-call.

Previous response

{
    "statusCode": 200,
    "body": {
        "id": "5dea9fc691240d0008408000",
    }
}

Current response

{
    "statusCode": 200,
    "payload": {
        "code": 200,
        "accountProcess": {
            "id": "5dea9fc691240d0008408000",
            "service": "my-service-name",
            "process": "import-readme",
            "accountId": "5dea9fc691240d00084083f8",
            "status": "pending"
        }
    }
}

Previous response

{
    "statusCode": 404,
    "body": {
        "message": "Account not found",
    }
}

Current response

{
    "statusCode": 200,
    "payload": {
        "code": 404,
        "errorMessage": "Account not found for ID '5dea9fc691240d0008408000'"
    }
}

:wrench: Configuration

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

JANIS_SERVICE_NAME (required): The name of the service that will create the AccountProcess.

:x: Wrong:

const { AccountProcess } = require('@janiscommerce/account-process');
const accountProcess = new AccountProcess();

:heavy_check_mark: Good:

const { AccountProcess } = require('@janiscommerce/account-process');
const { ApiSession } = require('@janiscommerce/api-session');

const accountProcess = session.getSessionInstance(AccountProcess);

:calling: API

  • send(accountId, processName, status, content, options)
    • Async
    • Description: Update processName for accountId in Commerce with status.
    • Parameters:
      • accountId : ObjectId Account ID in 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.
        • dateStart: Boolean true or Date Object
        • dateEnd: Boolean true or Date Object
    • Returns: Object
      • statusCode: Status code response from the Commerce Lambda SaveAccountProcess
      • payload: Object
        • code: Number. Status code with the process response
        • accountProcess: Object. The AccountProcess saved in Commerce Service

:spades: Statuses

You can get the valid Statuses using:

  • statuses
    • static getter
    • Returns: Object
      • pending
      • processing
      • success
      • error

| Status | Using package | View in Commerce Service | |------|-----------------|-----------------------| | pending | AccountProcess.statuses.pending | account-process-status-pending | | processing | AccountProcess.statuses.processing | account-process-status-processing | | success | AccountProcess.statuses.success | account-process-status-success | | error | AccountProcess.statuses.error | account-process-status-error |

Content

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

In the process:

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

In Commerce:

account-process-content

:clock1: Options

Now, there are 2 options

  • startDate: Boolean true or specific Date Object, to add an Date-Now ISO-String, to indicate the start of the process
  • endDate: Boolean true or specific Date Object, 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:


const accountProcess = this.session.getSessionInstance(AccountProcess);

// Start the process in current date
await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.pending,
    null,
    { startDate: true }
);

// Start the process in a specific date
await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.pending,
    null,
    { startDate: myStoredStartDate }
);

// Finish the process in current date
await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.success,
    null,
    { endDate: true }
);

// Finish the process in specific date
await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.success,
    null,
    { endDate: myStoredEndDate }
);

:arrow_forward: Usage

  • Send with minimal data, and pending status, and create a process in Commerce

const accountProcess = this.session.getSessionInstance(AccountProcess);

const response = await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.pending
)

/*
Response: {
    statusCode: 200,
    payload: {
        code: 200,
        accountProcess: {
            id: '5dea9fc691240d0008408000', // the id of the AccountProcess created or updated
            service: 'my-service-name',
            process: 'import-readme',
            accountId: '5dea9fc691240d00084083f8',
            status: 'pending'
        }
    }
}

*/
  • Send with content, and processing status, and Account is not found in Commerce

const accountProcess = this.session.getSessionInstance(AccountProcess);

const response = await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.processing,
    { itemsImported: 10, itemsNotModified: 1 }
);

/*
Response: {
    statusCode: 200,
    payload: {
        code: 404,
        errorMessage: 'Account not found for ID \'5dea9fc691240d00084083f8\''
    }
}

*/
  • Send with a Start Date and error status, and Commerce is failing

const accountProcess = this.session.getSessionInstance(AccountProcess);

const response = await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.error,
    null // No Content,
    { startDate: true }
);

/*
Response: {
    statusCode: 503
}

*/
  • Send with an End Date, and success status, and update an existing process in Commerce

const accountProcess = this.session.getSessionInstance(AccountProcess);

const response = await accountProcess.send(
    '5dea9fc691240d00084083f8',
    'import-readme',
    AccountProcess.statuses.success,
    { importedCount: 56400 },
    { endDate: true }
);

/*
Response: {
    statusCode: 200,
    payload: {
        code: 200,
        accountProcess: {
            id: '5dea9fc691240d0008408000',
            service: 'my-service-name',
            process: 'import-readme',
            accountId: '5dea9fc691240d00084083f8',
            status: 'success'
            endDate: '2022-05-13T13:26:25.414Z',
            content: { importedCount: 56400 }
        }
    }
}

*/

:x: Errors

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

| Code | Description | |------|------------------------| | 1 | No Session | | 2 | Invalid Account Id | | 3 | Invalid Process Name | | 4 | Invalid Status | | 5 | Invalid Content | | 6 | Invalid Options |