Socket
Book a DemoInstallSign in
Socket

@ogcio/building-blocks-sdk

Package Overview
Dependencies
Maintainers
7
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ogcio/building-blocks-sdk

## Overview

npmnpm
Version
0.0.2
Version published
Weekly downloads
741
4.81%
Maintainers
7
Weekly downloads
 
Created
Source

Building Blocks SDK - README

Overview

The Building Blocks SDK is the TypeScript client for integrating with the various building blocks within the OGCIO ecosystem. It helps developers interact different modules in a streamlined way, providing a unified API for seamless integration.

Features

  • Proxy Client: Acts as a middleware to interact with various services via the SDK.
  • Modular Design: Allows integration of different components (building blocks) to extend functionality as needed.
  • Enables both authenticated and non-authenticated usage

Usage

Install the package via:

npm install @ogcio/building-blocks-sdk

SDK initialization:

const sdk = getBuildingBlockSDK({
  services: {
    upload: {
      baseUrl: "http://localhost:8008",
    },
  },
});

This snippet creates the SDK with configuration for the upload API building block. The SDK accepts a configuration for each building block API.

At the present time available building blocks are:

  • payments
  • messaging
  • upload
  • profile
  • scheduler

Authentication

Access to building-blocks api is granted through access token in the Authorization header.

Users can pass the getTokenFn function to the SDK. The SDK client will call this function when it needs an access token. The SDK will provide the service name of the service for which it is requesting the token:

const sdk = getBuildingBlockSDK({
  services: {
    upload: {
      baseUrl: "http://localhost:8008",
    },
  },
  getTokenFn: async (serviceName: SERVICE_NAME) => {
    if (serviceName === UPLOAD) {
      return "TOKEN_FOR_UPLOAD";
    }
  },
});

This approach allows users of this library to plug-in their preferred authentication mechanism as long as a string is returned by the getTokenFn.

M2M Authentication

In order to use the library in your server applications you can install the peer dependency @logto/node via:

npm i @logto/node

and use the getM2MTokenFn utility function. This function accepts the M2M configuration parameters for each of the building-blocks api and returns a getTokenFn compliant function that will handle Logto m2m retrieval for you:

const sdk = getBuildingBlockSDK({
  services: {
    upload: {
      baseUrl: "http://localhost:8008",
    },
  },
  getTokenFn: await getM2MTokenFn({
    services: {
      upload: {
        getOrganizationTokenParams: {
          applicationId: "APPLICATION_ID",
          applicationSecret: "APPLICATION_SECRET",
          logtoOidcEndpoint: "http://localhost:3301/oidc",
          organizationId: "ogcio",
        },
      },
    },
  }),
});

Using the m2m utility function like this will cause the SDK to request all the scopes available for the building-block, scopes can be overridden when passed as parameter:

const sdk = getBuildingBlockSDK({
  services: {
    upload: {
      baseUrl: "http://localhost:8008",
    },
  },
  getTokenFn: await getM2MTokenFn({
    services: {
      upload: {
        getOrganizationTokenParams: {
          applicationId: "APPLICATION_ID",
          applicationSecret: "APPLICATION_SECRET",
          logtoOidcEndpoint: "http://localhost:3301/oidc",
          organizationId: "ogcio",
          scopes: ["custom:role:1", "custom:role:2"],
        },
      },
    },
  }),
});

Development

This project is built with the latest Node LTS, clone this repository and install the dependencies with:

npm install

The code is formatted and linted with biome.

The clients schemas are auto generated using open openapi-typescript.

you can update the json configuration clients for each client under: src/clients-configuration/clients-configuration.json, then run:

npm run clients:update

to update the schemas. At this point you are ready to modify clients files and use the newly generated schemas

FAQs

Package last updated on 23 Oct 2024

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