6.2.6 • Published 7 months ago

ozone-typescript-client v6.2.6

Weekly downloads
728
License
ISC
Repository
github
Last release
7 months ago

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
6.2.6

7 months ago

6.2.5

11 months ago

6.2.4

11 months ago

6.2.1

12 months ago

6.2.3

11 months ago

6.2.2

12 months ago

6.2.0

1 year ago

6.1.11

2 years ago

6.1.10

2 years ago

6.1.4

2 years ago

6.0.7

2 years ago

6.0.6

2 years ago

6.1.6

2 years ago

6.1.5

2 years ago

6.1.8

2 years ago

6.1.7

2 years ago

6.0.5-sha

2 years ago

6.0.5

2 years ago

6.1.0

2 years ago

6.1.2

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.4

2 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.9.2

3 years ago

5.9.1

3 years ago

5.9.0

3 years ago

5.8.0

3 years ago

5.7.2

3 years ago

5.7.1

3 years ago

5.7.0

3 years ago

5.6.0

3 years ago

5.5.11

3 years ago

5.5.10

3 years ago

5.5.9

3 years ago

5.5.8

3 years ago

5.5.7

3 years ago

5.5.6

3 years ago

5.4.61

3 years ago

5.4.51

3 years ago

5.4.58

3 years ago

5.4.59

3 years ago

5.4.56

3 years ago

5.4.54

3 years ago

5.4.55

3 years ago

5.4.52

3 years ago

5.4.53

3 years ago

5.5.1

3 years ago

5.4.50

3 years ago

5.4.47

3 years ago

5.4.45

3 years ago

5.4.46

3 years ago

5.4.43

3 years ago

5.4.44

3 years ago

5.4.41

3 years ago

5.4.40

3 years ago

5.4.39

3 years ago

5.4.38

3 years ago

5.4.36

3 years ago

5.4.37

3 years ago

5.4.34

3 years ago

5.4.35

3 years ago

5.4.32

3 years ago

5.4.33

3 years ago

5.4.30

3 years ago

5.4.29

3 years ago

5.4.27

3 years ago

5.4.28

3 years ago

5.4.26

3 years ago

5.4.22

3 years ago

5.4.21

3 years ago

5.4.20

3 years ago

5.4.19

4 years ago

5.4.18

4 years ago

5.4.17

4 years ago

5.4.16

4 years ago

5.4.15

4 years ago

5.4.14

4 years ago

5.4.13

4 years ago

5.4.12

4 years ago

5.4.11

4 years ago

5.4.10

4 years ago

5.4.9

4 years ago

5.4.8

4 years ago

5.4.1

4 years ago

5.4.0

4 years ago

5.3.2

4 years ago

5.3.1

4 years ago

5.3.0

4 years ago

5.2.3

4 years ago

5.2.2

4 years ago

5.2.1

4 years ago

5.2.1-alpha.0

4 years ago

5.2.0

4 years ago

5.2.0-alpha.0

4 years ago

5.1.6

4 years ago

5.1.5

5 years ago

5.1.4

5 years ago

5.1.3

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.8

5 years ago

5.0.6

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.5.1

5 years ago

4.5.0

5 years ago

4.4.7

5 years ago

4.4.6

5 years ago

4.4.5

5 years ago

4.4.3

5 years ago

4.4.2

5 years ago

0.9.32

5 years ago

4.4.1

5 years ago

0.9.31

5 years ago

0.9.29

5 years ago

0.9.28

5 years ago

0.9.27

5 years ago

0.9.26

5 years ago

0.9.25

5 years ago

0.9.24

5 years ago

0.9.23

5 years ago

0.9.22

5 years ago

0.9.21

5 years ago

0.9.20

5 years ago

0.9.19

5 years ago

0.9.18

5 years ago

0.9.17

5 years ago

0.9.16

5 years ago

0.9.15

5 years ago

0.9.14

5 years ago

0.9.13

5 years ago

0.9.12

5 years ago

0.9.11

5 years ago

0.9.10

5 years ago

0.9.9

5 years ago

0.9.8

6 years ago

0.9.6

6 years ago

0.9.5

6 years ago

0.9.4

6 years ago

0.9.3

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago