npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ozone-typescript-client

v6.3.6

Published

[![NPM version][npm-image]][npm-url] # ozone-typescript-client

Downloads

633

Readme

NPM version

ozone-typescript-client

ozone-typescript-client is a typescript module that manage connection and communication to ozone v3 API.

State machine

client State machine

Interface

export interface OzoneClient extends StateMachine<ClientState> {

	/* Get the client config */
	readonly config: ClientConfiguration

	/* Get the current Authentication if available */
	readonly authInfo?: AuthInfo

	/* Get the last failed login call if any */
	readonly lastFailedLogin?: Response<AuthInfo>

	/*
        Convenience props for getting the status of the client.
    */
	readonly isAuthenticated: boolean
	readonly isConnected: boolean

	/*
        Start the client. To be called once
    */
	start(): Promise<void>

	/*
        The array of filters to apply to all HTTP calls
        BEFORE this OzoneClient's own internal filters.
        This array can be modified at any time to add/remove filters
     */
	readonly preFilters: InstalledFilter[]

	/*
        The array of filters to apply to all HTTP calls
        AFTER this OzoneClient's own internal filters.
        This array can be modified at any time to add/remove filters
     */
	readonly postFilters: InstalledFilter[]

	/*
        Update the WS URL.
        The client will attempt to connect automatically to the new URL.
    */
	updateWSURL(url: string): void

	/*
        Update the Ozone credentials.
        The client will attempt to login automatically.
    */
	updateCredentials(ozoneCredentials: OzoneCredentials): void

	/*
        Stop the client. To be called once
    */
	stop(): Promise<void>

	/*
        Perform a low-level call
        All calls towards Ozone or other Microservices secured by Ozone should use those calls
    */
	callForResponse<T>(request: Request): Promise<Response<T>>

	call<T>(request: Request): Promise<T>

	/*
        Register a message listener.

        @param messageType The type of message to register for
        @param callBack The callBack that will be called
    */
	onMessage<M extends DeviceMessage>(messageType: string, callBack: (message: M) => void): ListenerRegistration

	onAnyMessage(callBack: (message: DeviceMessage) => void): ListenerRegistration

	/*
        Send a message
    */
	send(message: DeviceMessage): void

	// BEGIN HIGH LEVEL CALLS

	/*
        Get a client for working with items of the given type
    */
	itemClient<T extends Item>(typeIdentifier: string): ItemClient<T>
	/*
        Get a ``lob`` for working with blob
    */
	blobClient(): BlobClient

	/*
    	Get a client for working with role
	*/
	roleClient(): RoleClient

	/**
	 * get client to work with type
	 */
	typeClient(): TypeClient

	/**
	 * get task client to wait manage task
	 */
	taskClient(): TaskClient

	/**
	 * get client to work with permission
	 */
	permissionClient(): PermissionClient

	/**
	 * get client to work with permission
	 */
	importExportClient(): ImportExportClient

	/**
	 *  file file type client
	 */
	fileTypeClient(): FileTypeClient

	/*
        Insert the current Ozone session ID in the given URL ("/dsid=...).
        This call throws an error if there is no session available.
        The given string may or may not contain the host part.
        Example input strings :
        "/rest/v3/blob"
        "https://taktik.io/rest/v2/media/view/org.taktik.filetype.original/123"
    */
	insertSessionIdInURL(url: string): string
}

Usage

Initialization example:

import { OzoneClient } from 'ozone-typescript-client'
import UserCredentials = OzoneClient.UserCredentials
import OzoneCredentials = OzoneClient.OzoneCredentials
import ClientConfiguration = OzoneClient.ClientConfiguration
import newOzoneClient = OzoneClient.newOzoneClient

let client: OzoneClient.OzoneClient
async function init() {
const credentials = new UserCredentials('ozoneUser', 'ozonePassword')
		const config: ClientConfiguration = {
			ozoneURL: `http://my.ozone.domain/ozone`,
			ozoneCredentials: credentials
		}
		client = newOzoneClient(config)
		await client.start()
}

Using API client example:

import { OzoneClient } from 'ozone-typescript-client'
import { Video, toPatch } from 'ozone-type'

declare function getClient(): OzoneClient.OzoneClient

const videoClient = getClient().itemClient<Video>('video')
const myOriginalVideo = await videoClient.findOne('uuid-yyyy-zzz')
const videoToUpdate = toPatch(myOriginalVideo)
videoToUpdate.name = 'a new name'
const updatedVideo = await videoClient.save(videoToUpdate)

login application example

import { OzoneClient } from 'ozone-typescript-client'
import UserCredentials = OzoneClient.UserCredentials
import ClientStates = OzoneClient.states
import { getDefaultClient } from 'ozone-default-client'
import once from 'ozone-components-utils/once'

export class PageLoginDefault extends Polymer.Element {
  /* ... */

  ready(): void {
     super.ready()
     const defaultClient = getDefaultClient()
     defaultClient.onEnterState(ClientStates.STOPPED,() => {
        this.set('isConnected', false)
     })
     defaultClient.onEnterState(ClientStates.AUTHENTICATED,() => {
        this.set('isConnected', true)
     })
     if (defaultClient.authInfo) {
        this.set('isConnected', true) // client is already logged
     }
  }

  public async submitForm(e: Event): Promise<void> {
        /* ... */
     const updateMessagesOnError = once(() => {
        this.set('isConnected', false)
        const err = defaultClient.lastFailedLogin
        if (err && err.status === 400) {
           this.set('errorMessage', this.localized.msgEmptyCredentials)
        } else if (err && err.status === 403) {
           this.set('errorMessage', this.localized.msgInvalidCredentials)
        } else {
           this.set('errorMessage', this.localized.msgUnknownError)
        }
     })

     const defaultClient = getDefaultClient()
     defaultClient.onEnterState(ClientStates.AUTHENTICATION_ERROR, updateMessagesOnError)
     const userCredentials: UserCredentials = new UserCredentials(this.username, this.password)
     defaultClient.updateCredentials(userCredentials)
     try {
           // start if needed
        await defaultClient.start()
     } catch (err) {
           // error are handle inside the client state machine
     }
  }
}

Install

$ npm install --save ozone-typescript-client