Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@janiscommerce/account-process
Advanced tools
Creates or Updates a Process of Janis Commerce Service Account
Creates or Updates a Process of Janis Commerce Service Account
npm install @janiscommerce/account-process
Using @janiscommerce/lambda
with version 6.x.y
to use AWS SDK
in V3
.
service
fieldEnv variable JANIS_SERVICE_NAME
is required for saving and AccountProcess.
Now the package uses Commerce Lambda function SaveAccountProcess
instead of old Api.
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'"
}
}
: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);
send(accountId, processName, status, content, options)
processName
for accountId
in Commerce with status
.accountId
: ObjectId Account ID in CommerceprocessName
: String name of the processstatus
: String new Status for that processcontent
: 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 ObjectdateEnd
: Boolean true
or Date ObjectstatusCode
: Status code response from the Commerce Lambda SaveAccountProcess
payload
: Object
code
: Number. Status code with the process responseaccountProcess
: Object. The AccountProcess saved in Commerce ServiceYou can get the valid Statuses using:
statuses
pending
processing
success
error
Status | Using package | View in Commerce Service |
---|---|---|
pending | AccountProcess.statuses.pending | |
processing | AccountProcess.statuses.processing | |
success | AccountProcess.statuses.success | |
error | AccountProcess.statuses.error |
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:
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 processendDate
: Boolean true
or specific Date Object
, to add an Date-Now ISO-String, to indicate the end of the processThis 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 }
);
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'
}
}
}
*/
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\''
}
}
*/
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
}
*/
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 }
}
}
}
*/
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 |
[3.0.0] - 2023-07-13
@janiscommerce/lambda
dependency to v6FAQs
Creates or Updates a Process of Janis Commerce Service Account
We found that @janiscommerce/account-process demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.