0.2.4 • Published 11 months ago

@jup-ag/notification-sdk v0.2.4

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Notification SDK

Install

npm i @jup-ag/notification-sdk

Subscribing to message updates

import { CreateNotificationClient, Status } from "@jup-ag/notification-sdk";

const workerEndpoint = "http://127.0.0.1:8787"

function handler(key: string, status: Status, code: string, description: string) {
  console.log(`Got new message for ${key}; Status: ${status}; Code: ${code}; Description: ${description}`)
}

function main() {
  const notificationClient = CreateNotificationClient(workerEndpoint)
  const key = "SomePositionRequestPubKeyBase58"
  notificationClient.onUpdate(key, handler)
}

Set new message

import { CreateNotificationClient, Status, Message } from "@jup-ag/notification-sdk";

const workerEndpoint = "http://127.0.0.1:8787"

async function main() {
  const notificationClient = CreateNotificationClient(workerEndpoint)
  const key = "SomePositionRequestPubKeyBase58"

  const message: Message = {
    status: Status.Error,
    code: "6001",
    description: "Something went wrong"
  }

  const ok = await notificationClient.updateMessage(key, message)

  if (!ok) {
    throw new Error("Failed to update status")
  }

  const res = await notificationClient.getMessage(key)
  console.log({ res })
}

About Message

Message is a JSON serializable object containing 3 properties

  • status: status is an enum with 4 possibilities -> Pending, Error, Success, Failed
  • code: this can be an error code as a string ie '6001' or 'MAX_ATTEMPTS'
  • description: this can be a user friendlier description of the error code

About Status

While you can use it very flexibly, this is how we intend to use it:

  • Status.Pending -> indicate that it is still in process
  • Status.Error -> error messages but might not indicate finality aka retries might be on the way
  • Status.Failed -> this indicate finality. no more retries
  • Status.Success -> everything is good
0.2.4

11 months ago

0.2.3

11 months ago

0.2.2

11 months ago

0.2.1

11 months ago

0.2.0

11 months ago

0.1.9

12 months ago

0.1.8

12 months ago

0.1.7

12 months ago

0.1.6

12 months ago