orders-sdk-rn-client
v0.1.44
Published
React native client for Orders SDK
Downloads
148
Maintainers
Readme
orders-sdk-rn-client
React Native client for Orders SDK, providing a way to interact with order events and synchronize them with cloud-based services.
Installation
To install the package:
npm install @oolio-group/rn-orders-sdkor with Yarn:
yarn add @oolio-group/rn-orders-sdkLinking the Native Module
Ensure that the package is properly linked to your React Native project. If you're using React Native 0.60 or higher, this should be done automatically.
For iOS, run:
cd ios
pod installRequirements
- Android Only: This SDK currently supports only Android. For iOS support, future updates will be required.
Usage
Initializing the SDK
To initialize the SDK, call the initOrdersSDK() function.
import { initOrdersSDK } from 'orders-sdk-rn-client';
initOrdersSDK();Subscribing to Order Events
You can subscribe to order events using the subscribeOrderEvents function. This function accepts a filter (EventsFilter) and returns an OrderEventEmitter for handling event subscriptions.
import { subscribeOrderEvents } from 'orders-sdk-rn-client';
const filter = {
orderId: '12345',
status: 'confirmed'
};
const orderEventEmitter = await subscribeOrderEvents(filter);
orderEventEmitter.addListener('event', (event) => {
console.log('Received event: ', event);
});Adding Order Events
To add events to the SDK, use the addOrderEvents function. You can pass an array of events in JSON format.
import { addOrderEvents } from 'orders-sdk-rn-client';
const events = [
{ id: '1', orderId: '12345', event: 'ORDER_CONFIRMED' },
{ id: '2', orderId: '12345', event: 'ORDER_DISPATCHED' },
];
addOrderEvents(events);Retrieving Order Events
To get the stored events based on a filter, use getOrderEvents.
import { getOrderEvents } from 'orders-sdk-rn-client';
const filter = {
orderId: '12345',
};
const events = await getOrderEvents(JSON.stringify(filter));
console.log('Events: ', events);Clearing Order Events
To clear all events from the SDK:
import { clearOrderEvents } from 'orders-sdk-rn-client';
clearOrderEvents();Syncing Events with Cloud
To sync events with the cloud using a custom configuration, call syncCloudEvents.
import { syncCloudEvents } from 'orders-sdk-rn-client';
const config = {
url: 'https://example.com/api/sync',
headers: {
'Authorization': 'Bearer token',
'Content-Type': 'application/json',
},
body: {
orderId: '12345',
},
};
syncCloudEvents(config);Error Handling for Unsupported Platforms
This SDK currently supports Android. If you call any functions on unsupported platforms, the SDK will not perform any actions. You can use the isSupported() method to check if the SDK is supported on the current platform.
import { isSupported } from 'orders-sdk-rn-client';
if (!isSupported()) {
console.warn('Orders SDK is only supported on Android');
}Types
EventsFilter
The EventsFilter object allows you to filter events based on criteria like orderId, status, etc.
interface EventsFilter {
orderId?: string;
status?: string;
}CloudSyncConfiguration
The CloudSyncConfiguration object is used to configure cloud synchronization.
interface CloudSyncConfiguration {
url: string;
headers: Record<string, string>;
body: any;
}Contributing
Contributions are welcome! See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
