1.0.93 • Published 2 months ago

lagertha_js v1.0.93

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

Lagertha_js NPM Package

Overview

lagertha_js is a JavaScript client that simplifies the integration process and offers clear methods for managing connections, token verification, and authenticated API calls.

Installation

Install lagertha_js using npm or yarn:

npm install --save lagertha_js
# or
yarn add lagertha_js

Usage

Importing Lagertha Client

To use Lagertha in your project, import it as follows:

import Lagertha from 'lagertha_js';

Connection

Connect to Lagertha using the connect method:

const loginResponse = await Lagertha.connect({
    login: "<username>",
    password: "<password>",
    application_uuid: "<uuid_application>",
    code_2fa: "<optional_2fa_code>",
    env: "<api_url>",
});

This method returns an object with the necessary access tokens.

Token Verification and Renewal

Before each authenticated call, verify the token's validity and renew it if expired using the refresh method:

const refreshedTokens = await Lagertha.refresh({
    refresh_token: "refresh_token",
    application_uuid: "uuid_application",
    env: "api_url",
});

Authenticated Calls

All authenticated calls require adding a `LagerthaConfig object as the last argument:

type LagerthaConfig = {
    access_token: string;
    env: string
}

Encryption

For encryption, use Lagertha to create a group, a key chain, and then encrypt your message:

const config: LagerthaConfig = {
    access_token: '<your_lagertha_access_token>',
    env: '<https://Lagertha-api-entry-point>'
};

const group = await Lagertha.create_group({
    name: 'name of my group',
    members: []
}, config);

const key = await Lagertha.create_key_chain([group.uuid], config);
const encrypted = Lagertha.encrypt('<your message>', key.id, config);

Decryption

Decrypt a string by using the decrypt method and associating it with the string and config object:

const decrypted = await Lagertha.decrypt('<your encrypted message>', config);

API

Authentication

  • connect: Authenticates a user and returns credentials (access and refresh tokens).
  • refresh: Refreshes user credentials.
  • partner_check: Verifies partner credentials.
  • partner_connect: Authenticates a partner.
  • sso_connect: Single Sign-On authentication.

Key Chain Management

  • create_key_chain: Creates a new key chain.
  • get_key_chain: Retrieves a key chain by UUID.
  • delete_key_chain: Deletes a key chain.

Encryption and Decryption

  • encrypt, encrypt_with_key_chain: Encrypts text.
  • encrypt_file, encrypt_file_with_key_chain: Encrypts file.
  • decrypt, decrypt_with_key_chain: Decrypts text.
  • decrypt_file, decrypt_file_with_key_chain: Decrypts file.

Group Management

  • create_group: Creates a new group.
  • add_user_to_group, remove_user_from_group: Manages user membership in groups.
  • get_group_users, get_group_keys: Retrieves users or keys of a group.
  • add_key_to_group, remove_key_from_group: Manages key membership in groups.

User and Application Management

  • get_users, get_applications: Retrieves a list of users or applications.
  • create_application, update_application, delete_application: Manages applications.
  • get_user_logs, get_user_sessions: Retrieves logs or sessions of a user.

Miscellaneous

  • reset_password: Resets a user's password.
  • get_otp_code: Gets a one-time password code.
  • post_user: Creates a user
  • delete_user: Deletes a user.

Each method in the Lagertha class is designed for specific functionalities, ranging from user authentication to key chain management and encryption services. The library also includes utility functions and types for comprehensive data handling.

Types

export type CredentialOutput = {
    access_token: string;
    refresh_token: string;
    open_id: string;
    pk: string;
};

export type CredentialInput = {
    login: string;
    password: string;
    application_uuid: string;
    fingerprint: string;
    code_2fa?: string;
};

export type ErrorObject = {
    message: string;
};

export type CredentialRefreshInput = {
    refresh_token: string;
    application_uuid: string;
    fingerprint: string;
};

export type OpenIdOutput = {
    success: boolean;
};

export type OpenIdInput = {
    open_id: string;
};

export type PartnerCheckOutput = {
    partner_token: string;
};

export type PartnerCheckInput = {
    login: string;
};

export type PartnerConnectInput = {
    partner_token: string;
    fingerprint: string;
    code_2fa?: string;
};

export type UserOutput = {
    id: string;
    email: string;
    firstName: string;
    lastName: string;
    login: string;
    roles: string[];
    application: string;
    created_at: string;
};

export type UserPublicInput = {
    email: string;
    password: string;
    firstName: string;
    lastName: string;
    login: string;
    application_uuid: string;
};

export type UserInput = {
    email: string;
    password: string;
    firstName: string;
    lastName: string;
    login: string;
    application_uuid: string;
    is_admin: boolean;
};

export type UserPassword = {
    password: string;
};

export type ListDto_for_LogOutput = {
    items: LogOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type LogOutput = {
    ip: string;
    key_chain_uuid: string;
    result: string;
    created_at: string;
    user_id: string;
};

export type ListDto_for_UserOutput = {
    items: UserOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type ListDto_for_KeyChainGroupOutput = {
    items: KeyChainGroupOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type KeyChainGroupOutput = {
    uuid: string;
    name: string;
    created_at: string;
};

export type ListDto_for_DeviceSessionOutput = {
    items: DeviceSessionOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type DeviceSessionOutput = {
    user_id: string;
    fingerprint: string;
    ip: string;
    user: UserOutput | null;
    user_agent: string;
    created_at: string;
};

export type ListDto_for_KeyChainAdminOutput = {
    items: KeyChainAdminOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type KeyChainAdminOutput = {
    id: string;
    integrity: boolean;
    created_at: string;
};

export type User2faCode = {
    code: string;
};

export type User2faActivateOutput = {
    result: boolean;
};

export type User2faActivateInput = {
    is_activate: boolean;
    code: string;
};

export type UserResetPasswordOutput = {
    reset_password_token: string;
};

export type UserResetPasswordInput = {
    user_id: string;
};

export type UserUpdatePasswordInput = {
    token: string;
    new_password: string;
    validation_code?: string;
};

export type ApplicationOutput = {
    id: string;
    uuid: string;
    name: string;
    users_number: number;
    keys_number: number;
    is_system: boolean;
    contact_email: string;
    created_at: string;
};

export type ApplicationInput = {
    name: string;
    contact_email: string;
    restricted_admin_ip: string[];
};

export type ListDto_for_ApplicationOutput = {
    items: ApplicationOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type ApplicationEditInput = {
    uuid: string;
    name: string;
    contact_email: string;
};

export type ApplicationIpInput = {
    restricted_ip: string;
};

export type RestrictedIpsOutput = {
    application_uuid: string;
    restricted_ips: string[];
};

export type KeyChainOutput = {
    id: string;
    cipher_key: string;
    digest: string;
    iv?: string;
};

export type GroupListInput = {
    groups: string[];
};

export type KeyGroup = {
    group: string;
};

export type GroupInput = {
    name: string;
    members: string[];
};

export type GroupMember = {
    member: string;
};

export type ListDto_for_BlockChainValidationOutput = {
    items: BlockChainValidationOutput[];
    total_items: number;
    page: number;
    items_per_page: number;
};

export type BlockChainValidationOutput = {
    id: string;
    from_index: number;
    to_index: number;
    is_valid: boolean;
    error_index?: number;
    created_at: string;
};

export type BlockChainValidationInput = {
    from_index: number;
    to_index?: number;
};
1.0.84

2 months ago

1.0.83

2 months ago

1.0.88

2 months ago

1.0.87

2 months ago

1.0.86

2 months ago

1.0.85

2 months ago

1.0.89

2 months ago

1.0.91

2 months ago

1.0.90

2 months ago

1.0.93

2 months ago

1.0.92

2 months ago

1.0.82

4 months ago

1.0.81

4 months ago

1.0.66

4 months ago

1.0.65

4 months ago

1.0.64

4 months ago

1.0.69

4 months ago

1.0.68

4 months ago

1.0.67

4 months ago

1.0.73

4 months ago

1.0.72

4 months ago

1.0.71

4 months ago

1.0.70

4 months ago

1.0.77

4 months ago

1.0.76

4 months ago

1.0.75

4 months ago

1.0.74

4 months ago

1.0.79

4 months ago

1.0.78

4 months ago

1.0.80

4 months ago

1.0.62

5 months ago

1.0.63

5 months ago

1.0.61

5 months ago

1.0.60

5 months ago

1.0.59

5 months ago

1.0.58

6 months ago

1.0.44

6 months ago

1.0.48

6 months ago

1.0.47

6 months ago

1.0.46

6 months ago

1.0.45

6 months ago

1.0.49

6 months ago

1.0.51

6 months ago

1.0.50

6 months ago

1.0.55

6 months ago

1.0.54

6 months ago

1.0.53

6 months ago

1.0.52

6 months ago

1.0.57

6 months ago

1.0.56

6 months ago

1.0.43

7 months ago

1.0.42

7 months ago

1.0.41

7 months ago

1.0.40

7 months ago

1.0.39

7 months ago

1.0.38

7 months ago

1.0.37

7 months ago

1.0.36

7 months ago

1.0.35

7 months ago

1.0.34

7 months ago

1.0.33

7 months ago

1.0.32

7 months ago

1.0.31

7 months ago

1.0.30

7 months ago

1.0.29

7 months ago

1.0.28

7 months ago

1.0.27

7 months ago

1.0.26

7 months ago

1.0.25

7 months ago

1.0.24

7 months ago

1.0.23

7 months ago

1.0.22

7 months ago

1.0.21

7 months ago

1.0.20

7 months ago

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

7 months ago

1.0.11

7 months ago

1.0.10

7 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

7 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago