@mybambu/account-service-sdk
v1.0.0
Published
TypeScript SDK for MyBambu Account Service
Downloads
5
Maintainers
Readme
MyBambu Account Service SDK
TypeScript SDK for interacting with the MyBambu Account Service API.
Table of Contents
Installation
npm install @mybambu/account-service-sdkQuick Start
import { AccountServiceClient } from '@mybambu/account-service-sdk';
// Initialize the client
const client = new AccountServiceClient({
baseURL: 'http://localhost:3000',
apiPrefix: 'api/v1', // optional, defaults to 'api/v1'
timeout: 30000, // optional, defaults to 30000ms
});
// Register a new user
const { access_token, user } = await client.register({
email: '[email protected]',
password: 'SecurePassword123!',
firstName: 'John',
lastName: 'Doe',
});
// The token is automatically set after registration/login
console.log('Logged in as:', user.email);
// Make authenticated requests
const profile = await client.getUserProfile();Configuration
AccountServiceConfig
| Property | Type | Required | Default | Description | |----------|------|----------|---------|-------------| | baseURL | string | Yes | - | Base URL of the Account Service | | apiPrefix | string | No | 'api/v1' | API prefix path | | timeout | number | No | 30000 | Request timeout in milliseconds | | headers | Record<string, string> | No | {} | Additional headers to include |
Authentication
The SDK automatically handles JWT token management. After successful login or registration, the token is stored and included in all subsequent requests.
Manual Token Management
// Set token manually
client.setToken('your-jwt-token');
// Get current token
const token = client.getToken();
// Clear token
client.clearToken();Token Auto-Clear on 401
The SDK automatically clears the stored token when a 401 Unauthorized response is received.
API Reference
Authentication
register(data: RegisterDto): Promise
Register a new user account.
const response = await client.register({
email: '[email protected]',
password: 'SecurePassword123!',
firstName: 'John',
lastName: 'Doe',
phoneNumber: '+1234567890', // optional
dateOfBirth: '1990-01-01', // optional
});login(data: LoginDto): Promise
Login with email and password.
const response = await client.login({
email: '[email protected]',
password: 'SecurePassword123!',
});getCurrentUser(): Promise
Get the current authenticated user's profile.
const user = await client.getCurrentUser();logout(): Promise<{ message: string }>
Logout the current user.
await client.logout();User Management
getUserProfile(): Promise
Get detailed user profile.
const profile = await client.getUserProfile();updateProfile(data: UpdateProfileDto): Promise
Update user profile information.
const updatedProfile = await client.updateProfile({
firstName: 'Jane',
lastName: 'Smith',
phoneNumber: '+1987654321',
});updatePassword(data: UpdatePasswordDto): Promise<{ message: string }>
Change user password.
await client.updatePassword({
currentPassword: 'OldPassword123!',
newPassword: 'NewPassword123!',
});getUserPreferences(): Promise
Get user preferences.
const preferences = await client.getUserPreferences();updatePreferences(data: any): Promise
Update user preferences.
const updated = await client.updatePreferences({
theme: 'dark',
notifications: true,
});deactivateAccount(): Promise<{ message: string }>
Deactivate user account.
await client.deactivateAccount();PIN Management
// Set PIN
await client.setPin('1234');
// Verify PIN
const { valid } = await client.verifyPin('1234');
// Update PIN
await client.updatePin('1234', '5678');Address Management
getAddress(): Promise
Get user's address.
const address = await client.getAddress();createAddress(data: CreateAddressDto): Promise
Create a new address.
const address = await client.createAddress({
street: '123 Main St',
city: 'New York',
state: 'NY',
postalCode: '10001',
country: 'USA',
});updateAddress(data: UpdateAddressDto): Promise
Update existing address.
const updated = await client.updateAddress({
street: '456 Oak Ave',
});deleteAddress(): Promise
Delete user's address.
await client.deleteAddress();Address Validation
// Get pending address
const pending = await client.getPendingAddress();
// Submit for validation
await client.submitAddressForValidation({
street: '123 Main St',
city: 'New York',
state: 'NY',
postalCode: '10001',
country: 'USA',
});
// Approve pending address
const approved = await client.approvePendingAddress();Device Management
registerDevice(data: RegisterDeviceDto): Promise
Register a new device.
const device = await client.registerDevice({
deviceId: 'unique-device-id',
deviceType: 'ios',
deviceModel: 'iPhone 14',
osVersion: '16.0',
appVersion: '1.0.0',
pushToken: 'fcm-token',
});getUserDevices(): Promise<DeviceResponse[]>
Get all user devices.
const devices = await client.getUserDevices();getDevice(deviceId: string): Promise
Get specific device.
const device = await client.getDevice('device-id');updateDevice(deviceId: string, data: UpdateDeviceDto): Promise
Update device information.
const updated = await client.updateDevice('device-id', {
appVersion: '1.1.0',
osVersion: '16.1',
});deleteDevice(deviceId: string): Promise<{ message: string }>
Delete a device.
await client.deleteDevice('device-id');deactivateDevice(deviceId: string): Promise
Deactivate a device.
await client.deactivateDevice('device-id');updateDevicePushToken(deviceId: string, pushToken: string): Promise
Update device push notification token.
await client.updateDevicePushToken('device-id', 'new-fcm-token');Security Questions
getAvailableSecurityQuestions(): Promise<SecurityQuestionResponse[]>
Get list of available security questions.
const questions = await client.getAvailableSecurityQuestions();getUserSecurityQuestions(): Promise<any[]>
Get user's configured security questions.
const userQuestions = await client.getUserSecurityQuestions();setSecurityQuestion(data: SetSecurityQuestionDto): Promise
Set a security question.
await client.setSecurityQuestion({
questionId: 'question-uuid',
answer: 'My Answer',
});verifySecurityAnswer(data: VerifySecurityAnswerDto): Promise<{ valid: boolean }>
Verify a security answer.
const { valid } = await client.verifySecurityAnswer({
questionId: 'question-uuid',
answer: 'My Answer',
});deleteSecurityQuestion(questionId: string): Promise<{ message: string }>
Delete a security question.
await client.deleteSecurityQuestion('question-uuid');Verification
sendVerification(data: SendVerificationDto): Promise
Send verification code via email or phone.
// Send email verification
await client.sendVerification({
type: 'email',
});
// Send phone verification
await client.sendVerification({
type: 'phone',
target: '+1234567890', // optional
});verifyCode(data: VerifyCodeDto): Promise<{ verified: boolean }>
Verify a code.
const { verified } = await client.verifyCode({
type: 'email',
code: '123456',
});getVerificationStatus(): Promise
Get user's verification status.
const status = await client.getVerificationStatus();
console.log('Email verified:', status.emailVerified);
console.log('Phone verified:', status.phoneVerified);Password Reset
requestPasswordReset(email: string): Promise<{ sent: boolean; expiresAt: Date }>
Request a password reset.
const response = await client.requestPasswordReset('[email protected]');
console.log('Reset email sent:', response.sent);
console.log('Expires at:', response.expiresAt);resetPassword(data: ResetPasswordDto): Promise<{ message: string }>
Reset password with token.
await client.resetPassword({
token: 'reset-token-from-email',
newPassword: 'NewSecurePassword123!',
});Disclosures
getCurrentDisclosures(): Promise<DisclosureResponse[]>
Get all current disclosures.
const disclosures = await client.getCurrentDisclosures();getPendingDisclosures(): Promise<DisclosureResponse[]>
Get disclosures pending user acceptance.
const pending = await client.getPendingDisclosures();getUserAcceptedDisclosures(): Promise<any[]>
Get user's accepted disclosures.
const accepted = await client.getUserAcceptedDisclosures();getDisclosureById(id: string): Promise
Get specific disclosure by ID.
const disclosure = await client.getDisclosureById('disclosure-uuid');acceptDisclosure(data: AcceptDisclosureDto): Promise
Accept a disclosure.
await client.acceptDisclosure({
disclosureId: 'disclosure-uuid',
version: '1.0',
});Error Handling
The SDK uses Axios for HTTP requests. All errors are Axios errors with response data.
try {
await client.login({
email: '[email protected]',
password: 'wrong-password',
});
} catch (error) {
if (error.response) {
// Server responded with error
console.error('Status:', error.response.status);
console.error('Message:', error.response.data.message);
} else if (error.request) {
// Request made but no response
console.error('No response received');
} else {
// Error setting up request
console.error('Error:', error.message);
}
}Common HTTP Status Codes
200- Success201- Created400- Bad Request401- Unauthorized (token cleared automatically)404- Not Found409- Conflict (e.g., user already exists)500- Internal Server Error
Examples
See the examples directory for complete working examples:
TypeScript Support
This SDK is written in TypeScript and includes type definitions. You get full IntelliSense and type checking out of the box.
import { AccountServiceClient, UserResponse, LoginResponse } from '@mybambu/account-service-sdk';
const client = new AccountServiceClient({ baseURL: 'http://localhost:3000' });
// TypeScript knows the shape of the response
const loginResponse: LoginResponse = await client.login({
email: '[email protected]',
password: 'password',
});
// Type-safe access to properties
console.log(loginResponse.access_token);
console.log(loginResponse.user.email);License
MIT
