npm.io
3.1.7 • Published 4 weeks ago

@product-live/api-sdk

Licence
ISC
Version
3.1.7
Deps
6
Size
5.2 MB
Vulns
0
Weekly
0

Product-live sdk

This sdk aims at simplifying access to the Product-Live public API.

Generation

The following section describe the necessary steps to generate and publish a new version of the sdk. All action are performed through the github web interface.

Generation

A new version of the sdk can be generated through the github action Generate sdk. This action will generate the necessary code on a new branch and open a PR for verification. A dry publication is performed to ensure basic npm compliance.

Generate sdk

Note that running the same action multiple times will result in as many branches and PR being opened, that should be closed manually.

OPTIONS:

  • "OpenApi specification location": url for the targeted API. The default value is the production API and should be used in most cases.
  • "Should perform a dry run": if checked, the changes will not be committed. This option may be used to test generation beforehand.
PR validation

The pull request opened should be reviewed, and merged once validated.

Release creation

The preparation of a new release is handled automatically by release-please. A PR is created and maintained whenever the main branch is updated.
Once ready to publish the new version, said PR should be merged. All necessary actions are then handled automatically.

Publication

Once a new release is created, it should then be published through the Publish sdk github action. Except in some edge cases, it should be executed on the 'main' branch.
This action will build and publish the sdk to npm repository.

Publish sdk

OPTIONS:

  • "dry run": if checked, performs a test publication without the actual upload. This may be used to test publication

Installing

Install the library with the following command: npm i @product-live/sdk

Usage

Instantiation

For its creation, the apiClient must be provided with an AuthenticationProvider and a RequestAdapter

import {ApiKeyAuthenticationProvider, ApiKeyLocation} from '@microsoft/kiota-abstractions';
import {FetchRequestAdapter} from '@microsoft/kiota-http-fetchlibrary';
import {createApiClient} from './index';

const authenticationProvider = new ApiKeyAuthenticationProvider(
    key,
    'X-Api-Key',
    ApiKeyLocation.Header
);
const requestAdapter = new FetchRequestAdapter(authenticationProvider);
requestAdapter.baseUrl = url;
const apiClient = createApiClient(requestAdapter);

The library provides a simplified entry point for the most usual case

import {setup} from './index';

const apiClient = setup(key, url);

It is currently recommended to use the latter method when the project is of "type": "module"

Call

Once instantiated, the client may be called on any API available. The methods use will always reflect the targeted url and the http verb. For instance, to obtain a list of audit logs, we need a GET request on url /v1/audit_logs. The corresponding call will be:

const auditLogsList = await apiClient.v1.audit_logs.get();
Additional parameters

Additional parameters may be provided depending on the targeted API

  • url parameters: a method byId(id: string) will be available in the functions chain
const item = await apiClient.v1.items.byId(itemId).get();
  • body: for API calls requiring it, a body will be expected as the call function first argument
const newVariable = await apiClient.v1.data_factory.variables.post({
    key: 'some-key',
    name: 'explicit-name',
    value: 'value'
});
  • headers and query parameters: all calling methods accept a RequestConfiguration as a last argument. This object is a json containing a headers and/or queryParameters object, with the necessary values inside. Note that the autocomplete is not available for the content of headers
const patitionsList = await apiClient.v1.partitions.get({
    queryParameters: { tableId: tableId },
    headers: { 'X-Context': contextAccountId }
});

Compatibility

The library provides both cjs and esm version.