Default Adapter
The default adapter implements organization information using MongoDB to store organizations and change requests.
Features
- Organization Data Management
- Create, update and Delete business names, contact info, addresses, business times etc.
- Audit
- System admins can view all registered organizations, and choose to allow or deny them.
- Allowed organizations can be used as merchants and be used in the platform.
- Denied organizations will temporarily be removed from the platform until their restrictions are lifted.
- Attachment management
- Upload, manage and download organization file attachments
- Uploaded attachments can be used from other services
Installation
- Prerequisites
Dependency | Version |
---|---|
node | 18+ |
MongoDB | 5+ |
Nodeblocks User Service | 1.3.0+ |
- Install Package
Create your repository and add this package as a dependency
mkdir my-organization-service
npx gts init -y
npm install --save @basaldev/blocks-organization-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 {
createNodeblocksOrganizationApp,
defaultAdapter,
} from '@basaldev/blocks-organization-service';
import {crypto, security} from '@basaldev/blocks-backend-sdk';
import {getEnvString} from './helper/utilities';
async function main() {
const adapter = await defaultAdapter.createOrganizationDefaultAdapter(
{
allowedAttachmentContentTypes: ['jpeg', 'png'],
authEncSecret: getEnvString('AUTH_ENC_SECRET', ''),
authSignSecret: getEnvString('AUTH_SIGN_SECRET', ''),
authenticate: security.defaultCookieAuth,
autoApprove: true,
maxFileSizeMB: Number(getEnvString('MAX_FILE_SIZE_MB', '10')),
},
{
bucket: getEnvString('BUCKET_NAME', ''),
db: getEnvString('DATABASE_URL', ''),
userAPI: getEnvString('USER_ENDPOINT', ''),
}
);
await createNodeblocksOrganizationApp({
corsOptions: {
credentials: true,
origin: ['http://localhost'],
},
enableCookieParser: true,
}).startService({
PORT: Number(getEnvString('ORGANIZATION_PORT', '8081')),
adapter,
env: 'development',
});
}
void main();