@inyourarea/subscription-service
v0.5.0
Published
A client library to interact with the subscription service
Downloads
199
Readme
@inyourarea/subscription-service
A client package to interact with the subscription service.
Install
npm i @inyourarea/subscription-service
Usage
import { init } from '@inyourarea/subscription-service';
const client = init({ env: 'prod' });
let key = 'someKey'; // The users key that is stored in cookies
const SUBSCRIPTION = Subscription.MEMORYLANE_WEEKLY; // Subscriptions are exported as an enum
const { data, status } = await client.createSubscriptions({ userIid: 'someIid', subscription: SUBSCRIPTION, key });
expect(status).toEqual(200);
expect(data).toEqual({
created: ['memorylane:newsletter:weekly'],
failed: [],
});
const client = init({
env: 'dev', // Defaults to stag
retry: true // Defaults to retry 3 times and back off at 500ms
instanceSettings: { // Corresponds to axios instance settings for extra customisation
validateStatus: (status) => status === 200 || status === 400 || status === 401,
},
});
const { data, status } = await client.getSubscriptions({ userIid: 'someIid', sig});
let sig = await getSig(); // A signature generated using the user store secret
expect(status).toEqual(401);
expect(data.message).toEqual('Unauthorized');