Default Adapter
The default adapter implements product management using MongoDB as a data store.
Features
- Product Management
- Suppliers can create, update, delete and copy products
- Products can be batch updated and deleted
- Category Management
- Categories of products can be created, managed and organized
- Categories can be be organized by a supplier, and then used by the demand side of the organization to help locate their desired products
- System admins can manage categories
- All users can see categories
- Category Creation
- Users can create categories with a name and description of their options.
- Categories have a hierarchy and can be organized as such
- Category Editing
- Edit category names, descriptions, hierarchy and sort order
- Category Deletion
- Once a category is deleted, related products and child categories must be reorganized
- Product Attribute Management
- Attributes and tags can be assigned to products
- Attributes can contain several data types
- boolean
- number
- string
- select
- multiselect
- Attributes can be configured globally, or within a category
- Aggregation
- Totals of products can be calculated per category
- Attachments
- The Organization Block can be used to handle product attachments. Upload attachments to the organization endpoints, and use the image ID in this service.
Installation
- Prerequisites
Dependency | Version |
---|---|
node | 18+ |
MongoDB | 5+ |
Nodeblocks User Service | 1.1.0+ |
Nodeblocks Organization Service | 1.2.0+ |
- Install Package
Create your repository and add this package as a dependency
mkdir my-catalog-service
npx gts init -y
npm install --save @basaldev/blocks-catalog-service
You will need to also set up your environment variables. Look at Quick Start Guide for a sample.
- 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 'dotenv/config';
import {
createNodeblocksCatalogApp,
defaultAdapter,
} from '@basaldev/blocks-catalog-service';
import { UserDefaultAdapterRestSdk } from '@basaldev/blocks-default-adapter-api';
import {crypto, security} from '@basaldev/blocks-backend-sdk';
import {getEnvString} from './helper/utilities';
async function main() {
const server = createNodeblocksCatalogApp({
enableCookieParser: true,
corsOptions: {
credentials: true,
origin: ['http://localhost'],
},
});
const internalToken = crypto.generateAppAccessToken(
{
authEncSecret: getEnvString('AUTH_ENC_SECRET', ''),
authSignSecret: getEnvString('AUTH_SIGN_SECRET', ''),
},
'service-adapter-name'
);
const adapter = await defaultAdapter.createCatalogDefaultAdapter(
{
allowedAttachmentContentTypes: ['image/jpeg', 'image/png'],
authEncSecret: getEnvString('AUTH_ENC_SECRET', ''),
authSignSecret: getEnvString('AUTH_SIGN_SECRET', ''),
authenticate: security.defaultCookieAuth,
maxAttachmentSizeMB: Number(getEnvString('MAX_FILE_SIZE_MB', '10')),
serviceEndpoints: {
catalog: getEnvString('CATALOG_ENDPOINT', ''),
organization: getEnvString('ORGANIZATION_ENDPOINT', ''),
},
},
{
bucket: getEnvString('BUCKET_NAME', ''),
db: getEnvString('DATABASE_URL', ''),
organizationAPI: getEnvString('ORGANIZATION_ENDPOINT', ''),
userAPI: new UserDefaultAdapterRestSdk(
getEnvString('USER_ENDPOINT', ''),
internalToken,
security.defaultCookieAuth
),
}
);
await server.startService({
PORT: Number(getEnvString('CATALOG_PORT', '8081')),
adapter,
env: 'development',
});
}
void main();