Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@hdt-edge-products/client-pinia-vue-sdk

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@hdt-edge-products/client-pinia-vue-sdk

A wrapper of the client-entities interactions using Vue and its Pinia state management

unpublished
latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
0
Created
Source

@hdt-edge-products/client-pinia-vue-sdk

Overview

This package is an adapter which binds the FRANk change feeds / change streams to Vue and Pinia stores to assist in UI development

Usage

The SDK exports 4 items:

  • useEventActivityStore (The pinia store function for event activity)
  • useItemBiddingStore, (The pinia store function for item bidding activity)
  • EventRuntimePiniaVueSdk, (The main-level vue sdk that initializes and keeps the 2 above items up to date)
  • eventRuntimeApiSdk (The REST api singleton for writing data into the event runtime (ex: bidding))

Here is an example of how the sdk is instantiated:

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import { eventRuntimeApiSdk, EventRuntimePiniaVueSdk, useEventActivityStore, useItemBiddingStore } from '@hdt-edge-products/client-pinia-vue-sdk';

const BIDDING_SERVER_URL = 'http://localhost:4030';
const DELTA_SERVER_URL = 'ws://localhost:9001';

// NOTE: Pinia and the app must be attached prior to setup/initialization of the event runtime sdk
const pinia = createPinia();
const app = createApp(App, { BIDDING_SERVER_URL, DELTA_SERVER_URL });
app.use(pinia);
useEventActivityStore();
useItemBiddingStore();

const customAuthHeaderFn = async function(){
    return Promise.resolve({Authorization: 'Bearer jwt.token.here'});
}

// The api sdk allows the user to set an async customHeader function which will be applied for REST Api calls into the sdk.
eventRuntimeApiSdk.customHeaderFn = customAuthHeaderFn;
eventRuntimeApiSdk.baseBiddingUri = BIDDING_SERVER_URL;

const sdk = new EventRuntimePiniaVueSdk(BIDDING_SERVER_URL, DELTA_SERVER_URL);
await sdk.initialize();
await sdk.watchEvents(['event-10000', 'event-20000', 'event-30000']); 

app.mount('#app');

Reference

An example pinia item bidding store is below:

import { ref } from 'vue';
import { defineStore } from 'pinia';
import { applyPatch } from 'fast-json-patch';

export const useItemBiddingStore = defineStore('itemBiddingStore', () => {
    const items = ref({});

    function addItemBidding(itemBiddingModel) {
        this.items[itemBiddingModel.id] = itemBiddingModel;
    }

    function updateItemBidding(id, itemBiddingModel) {
        this.items[id] = itemBiddingModel;
    }

    function removeItemBidding(id) {
        delete this.items[id];
    }

    function applyJsonPatch(id, jsonPatch) {
        applyPatch(this.items[id], jsonPatch, false, true);
    }

    return {
        items,
        addItemBidding,
        updateItemBidding,
        removeItemBidding,
        applyJsonPatch
    }
})

Note that the contents of these stores match the datamodel that is in the database directly - no changes or mutation. The contents are also live updated/added as changes/inserts to the database are written.

FAQs

Package last updated on 03 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts