Skip to main content

Default Adapter

The default adapter implements product orders using MongoDB as a data store

Features

  • Order Creation, Update, Deletion, Listing
  • Aggregation
    • Organization users can fetch counts of orders per product in their organization

Order statuses

The following order statuses exist:

  • PENDING
  • PROCESSING
  • ACCEPTED
  • CLOSED
  • CANCELLED
  • Orders are created in PENDING status
  • ACCEPTED means that the order was completed successfully

Installation

  1. Prerequisites
DependencyVersion
node18+
MongoDB5+
Nodeblocks User Service1.7.0+
Nodeblocks Organization Service1.9.0+
Nodeblocks Catalog Service1.6.0+
  1. Install Package

Create your repository and add this package as a dependency

mkdir my-order-service
npx gts init -y
npm install --save @basaldev/blocks-order-service

You will need to also set up your environment variables. Look at Quick Start Guide for a sample.

  1. Initial code
info

This example uses cookies authorization.

authenticate: security.defaultCookieAuth, // <-- Cookie authorization
info

This example enables CORS whitelist for localhost. You can add your own domains to the array.

corsOptions: {
credentials: true,
origin: ['http://localhost', 'http://your-domain.com'],
},

Place the following into src/index.ts:

import {
createNodeblocksOrderApp,
defaultAdapter,
} from '@basaldev/blocks-order-service';
import {crypto, security} from '@basaldev/blocks-backend-sdk';

import {getEnvString} from './helper/utilities';

async function main() {
const adapter = await defaultAdapter.createOrderDefaultAdapter(
{
authEncSecret: getEnvString('AUTH_ENC_SECRET', ''),
authSignSecret: getEnvString('AUTH_SIGN_SECRET', ''),
authenticate: security.defaultCookieAuth,
serviceEndpoints: {
order: getEnvString('ORDER_ENDPOINT', ''),
},
},
{
catalogAPI: getEnvString('CATALOG_ENDPOINT', ''),
db: getEnvString('DATABASE_URL', ''),
organizationAPI: getEnvString('ORGANIZATION_ENDPOINT', ''),
userAPI: getEnvString('USER_ENDPOINT', ''),
}
);

await createNodeblocksOrderApp({
corsOptions: {
credentials: true,
origin: ['http://localhost'],
},
enableCookieParser: true,
}).startService({
PORT: Number(getEnvString('ORDER_PORT', '8081')),
adapter,
env: 'development',
});
}

void main();

API Reference