🚗 Drivers
Drivers are factory functions and integrations that connect NodeBlocks services to external systems — databases, email providers, cloud storage, address lookup APIs, and OAuth providers. They live under the drivers namespace in the SDK.
Import pattern
Drivers are exported as a namespace from the main package entry. There is no @nodeblocks/backend-sdk/drivers subpath.
import { drivers } from '@nodeblocks/backend-sdk';
const {
getMongoClient,
withMongo,
getSendGridClient,
setBaseUrl,
createFileStorageDriver,
createJapanPostDriver,
createGoogleOAuthDriver,
createTwitterOAuthDriver,
createLineOAuthDriver,
verifyGoogleCallback,
verifyTwitterCallback,
verifyLineCallback,
PROVIDER_GOOGLE,
PROVIDER_TWITTER,
PROVIDER_LINE,
TWITTER_CALLBACK_STATE_SESSION_KEY,
} = drivers;
Type-only exports from the same namespace (FileStorageDriver, JapanPostDriver, SendGridMail) are available in type positions — see Types below.
Wiring pattern
| Pattern | Used by | How |
|---|---|---|
| Data stores | MongoDB (getMongoClient, withMongo) | Pass collections via the service dataStores argument |
| Third-argument options | File storage, mail, address lookup, OAuth | Pass drivers via { fileStorageDriver }, { mailService }, { findAddressDriver }, { googleOAuthDriver, ... } |
Driver factories are synchronous — no await on createFileStorageDriver, getSendGridClient, OAuth factories, etc. withMongo(...) returns a Promise when fully invoked to fetch a collection.
Driver modules
| Driver | Key exports | Documentation |
|---|---|---|
| MongoDB | getMongoClient, withMongo | Database |
| SendGrid | getSendGridClient, setBaseUrl, SendGridMail | Mail Service |
| Google Cloud Storage | createFileStorageDriver, FileStorageDriver | File Storage |
| OAuth (Google, Twitter, LINE) | createGoogleOAuthDriver, createTwitterOAuthDriver, createLineOAuthDriver, verifyGoogleCallback, verifyTwitterCallback, verifyLineCallback, PROVIDER_GOOGLE, PROVIDER_TWITTER, PROVIDER_LINE, TWITTER_CALLBACK_STATE_SESSION_KEY | OAuth |
| Japan Post | createJapanPostDriver, JapanPostDriver | Japan Post |
SDK source: src/drivers/index.ts re-exports file-storage, japan-post, mongo, oauth, and sendgrid.
Consuming services
| Driver factory | Injected as | Used by |
|---|---|---|
createFileStorageDriver | fileStorageDriver | Organization Service, Profile Service, Product Service, Chat Service |
createJapanPostDriver | findAddressDriver | Address Service |
getSendGridClient | mailService | Authentication Service |
createGoogleOAuthDriver, createTwitterOAuthDriver, createLineOAuthDriver | googleOAuthDriver, twitterOAuthDriver, lineOAuthDriver | Authentication Service |
Types
types namespace — shared interfaces used with drivers (SDK source: src/types/email.ts, src/types/oauth.ts):
import { types } from '@nodeblocks/backend-sdk';
type MailService = types.MailService;
type MailData = types.MailData;
type GoogleOAuthDriver = types.GoogleOAuthDriver;
type GoogleProfile = types.GoogleProfile;
// TwitterProfile, LineProfile, OAUTH_LOGIN, OAUTH_SIGNUP, ...
blocks namespace — block-layer contracts used with driver injection (SDK source: src/blocks/address.ts):
import { blocks } from '@nodeblocks/backend-sdk';
type FindAddressDriver = blocks.FindAddressDriver;
FindAddressDriver is the contract for findAddressDriver injection on Address Service. createJapanPostDriver returns a driver that satisfies this interface.
drivers namespace types — driver return types exported alongside factories:
import type { drivers as DriverExports } from '@nodeblocks/backend-sdk';
type FileStorageDriver = DriverExports.FileStorageDriver;
type JapanPostDriver = DriverExports.JapanPostDriver;
type SendGridMail = DriverExports.SendGridMail;
| Type | Source file |
|---|---|
FileStorageDriver | src/drivers/file-storage.ts |
JapanPostDriver | src/drivers/japan-post.ts |
SendGridMail | src/drivers/sendgrid.ts |
Next Steps
- Wire drivers into services — see Authentication Service (OAuth, mail), Address Service (Japan Post), and Organization Service (file storage)
- Implement custom MongoDB persistence — Using a Custom DataStore