1.0.16 • Published 3 years ago

@huz-com/subscription-sdk v1.0.16

Weekly downloads
409
License
ISC
Repository
gitlab
Last release
3 years ago

Huz.com / Subscription SDK

Subscription microservices can connect to huz api

Standards

  • Language: TS
  • Eslint: Yes
  • Static Code Analysis: Yes IntelliJ Code Inspections
  • DDD - Document Driven: Yes
  • EDD - Exception Driven: Yes
  • TDD - Test Driven: Yes go to simulate page
  • Standards Complied: Huz Standards

Commands

  • npm run clear // clears "dist" folder
  • npm run lint // runs eslint for static code analysis
  • npm run test // runs test files in "test" folder
  • npm run build // builds JS files at "dist" folder
  • npm publish or npm run publix // publishes "dist" folder to npm

Install

npm i @huz-com/subscription-sdk

Usage

Sample

import {connector, orderService, planService, profileService, projectService, subscriptionService, userService} from "@huz-com/subscription-sdk";


// Init system
await connector.initAsync({
    auth0Domain: 'auth0.com - domain',
    auth0Audience: 'auth0.com - audience',
    auth0ClientId: 'auth0.com - client-id',
    auth0ClientSecret: 'auth0.com - secret',
    apiInterval: 60 * 10, // as seconds, refresh token interval
    apiUrl: 'huz-api-url'
});

let projectDoc;

// get project by id
projectDoc = await projectService.getByIdAsync(req, 'project-id');


// get project by code
projectDoc = await projectService.getByCodeAsync(req, 'project-code');

let planDoc, planDocs;

// list assigned plans by project
planDocs = await planService.listAsync(req, 'project-id');

// get plan by id
planDoc = await planService.getByIdAsync(req, 'plan-id', 'project-id');

// get plan by code
planDoc = await planService.getByCodeAsync(req, 'plan-code', 'project-id');

let userDoc;

// get user by iam id
userDoc = await userService.getByIamId(req, 'iam-id');

// upsert user with iam-id and project id
userDoc = await userService.upsertAsync(req, 'iam-id', 'project-id', 'email-address');

// get user by id
userDoc = await userService.getByIdAsync(req, 'user-id');

let profileDoc;

// get profile by user and project
profileDoc = await profileService.getByUserAsync(req, 'user-id', 'project-id');

// upsert profile with user and project
profileDoc = await profileService.upsertAsync(req, 'user-id', 'project-id');

// get profile by id and project
profileDoc = await profileService.getByIdAsync(req, 'profile-id', 'project-id');

// log login history
profileDoc = await profileService.loginAsync(req, 'profile-id', 'reason');

// log logout history
profileDoc = await profileService.logoutAsync(req, 'profile-id', 'reason');

// subscribe to a subscription
profileDoc = await profileService.subscribeAsync(req, 'profile-id', 'subscription-id', 'reason');

// cancel current subscription of profile
profileDoc = await profileService.cancelSubscriptionAsync(req, 'profile-id', 'reason');

// unsubscribe from current subscription of profile
profileDoc = await profileService.unsubscribeAsync(req, 'profile-id', 'status', 'reason');

let subscriptionDoc, subscriptionDetailDoc, subscriptionDocs;

// get subscription of profile
subscriptionDoc = await subscriptionService.getByProfileAsync(req, 'profile-id');

// get subscription details of profile
subscriptionDetailDoc = await subscriptionService.getDetailedByProfileAsync(req, 'profile-id');

// get subscription by id
subscriptionDoc = await subscriptionService.getByIdAsync(req, 'subscription-id');

// create subscription
subscriptionDoc = await subscriptionService.createAsync(req, 'profile-id', 'plan-id', 'order-id', 'started-at');

// lists subscriptions of profile
subscriptionDocs = await subscriptionService.listAsync(req, 'profile-id');

// lists subscription history of profile
const historyItems = await subscriptionService.historyAsync(req, 'profile-id');

let orderDoc;

// create an order
orderDoc = await orderService.createAsync(req, 'profile-id', 'plan-id', {key1: 'value-1'});

// Assign a subscription to an order
orderDoc = await orderService.updateSubscriptionAsync(req, 'order-id', 'subscription-id', {key1: 'value-1'});

// Set order state as active
orderDoc = await orderService.setStatusActiveAsync(req, 'order-id', {key1: 'value-1'});

// Set order state as cancelled
orderDoc = await orderService.setStatusCancelAsync(req, 'order-id', {key1: 'value-1'});

// Set order state as idle
orderDoc = await orderService.setStatusIdleAsync(req, 'order-id', {key1: 'value-1'});

// Set order state as timeout
orderDoc = await orderService.setStatusTimeoutAsync(req, 'order-id', {key1: 'value-1'});

// Set order state as error
orderDoc = await orderService.setStatusErrorAsync(req, 'order-id', {key1: 'value-1'});

// Get order by id
orderDoc = await orderService.getByIdAsync(req, 'order-id');
1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago