Socket
Book a DemoInstallSign in
Socket

@fragment-dev/node-client

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fragment-dev/node-client

[Fragment](https://fragment.dev) is the Ledger API for engineers that move money. Stop wrangling payment tables, debugging balance errors and hacking together data pipelines. Start shipping the features that make a difference.

0.1.0
npmnpm
Version published
Weekly downloads
4.4K
52.38%
Maintainers
1
Weekly downloads
 
Created
Source

@fragment-dev/node-client

Fragment is the Ledger API for engineers that move money. Stop wrangling payment tables, debugging balance errors and hacking together data pipelines. Start shipping the features that make a difference.

Installation

Using npm:

npm install @fragment-dev/node-client

Using yarn:

yarn add @fragment-dev/node-client

Usage

To instantiate a client, call createFragmentClient. You can generate credentials using the Fragment dashboard.

import { createFragmentClient } from "@fragment-dev/node-client";

const fragment = createFragmentClient({
  apiUrl: "api url from dashboard",
  clientId: "client id from dashboard",
  clientSecret: "client secret from dashboard",
  scope: "scope from dashboard",
  authUrl: "auth url from dashboard",
});

Post a Ledger Entry

To post a Ledger Entry defined in your schema:

await fragment.addLedgerEntry({
  ik: "some-ik",
  ledgerIk: "your-ledger-ik",
  type: "user_funds_account",
  posted: "1968-01-01T16:45:00Z",
  parameters: {
    user_id: "user-1",
    funding_amount: "200",
  },
});

Sync transactions

To sync transaction using a Custom Link:

import { CurrencyCode } from "@fragment-dev/node-client";

await fragment.syncCustomAccounts({
  linkId: "custom-link-id",
  accounts: [
    {
      externalId: "operating-account",
      name: "Operating Bank Account",
      currency: {
        code: CurrencyCode.Usd,
      },
    },
  ],
});

await fragment.syncCustomTxs({
  linkId: "custom-link-id",
  txs: [
    {
      externalId: "tx-123",
      description: "Test user funding",
      account: {
        externalId: "operating-account",
        linkId: "custom-link-id",
      },
      amount: "100",
      currency: {
        code: CurrencyCode.Usd,
      },
      posted: "1968-01-01",
    },
  ],
});

Reconcile a transaction

To reconcile a transaction:

await fragment.reconcileTx({
  ledgerIk: "your-ledger-ik",
  type: "funding_settlement",
  parameters: {
    user_id: "user-1",
    net_amount: "99",
    fee_amount: "1",
    link_id: "stripe",
    link_account_id: "stripe-balance",
    link_tx_id: "tx_456",
  },
});

Get a Schema

const { schema } = await fragment.getSchema({
  key: schemaKey,
});

Get a Ledger

const { ledger } = await fragment.getLedger({
  ik: "your-ledger-ik",
});

Get a Ledger Entry

const { ledgerEntry } = await fragment.getLedgerEntry({
  ik: "card_swipe_a",
  ledgerIk: "your-ledger-ik",
});

Get a Ledger Account

To get a Ledger Account with its balances:

const { ledgerAccount } = await fragment.getLedgerAccountBalance({
  ledgerIk: "your-ledger-ik",
  path: "assets/receivables/user:user-1",
});

To get a Ledger Account with its lines:

const { ledgerAccount } = await fragment.getLedgerAccountLines({
  ledgerIk: "your-ledger-ik",
  path: "assets/receivables/user:user-1",
});

List Ledger Accounts

To retrieve the Ledger Accounts in a Ledger:

const result = await fragment.listLedgerAccounts({
  ledgerIk: "your-ledger-ik",
});

assert(result.ledger?.ledgerAccounts?.nodes, "Failed to list ledger accounts");

To retrieve Ledger Accounts with balances:

const result = await fragment.listLedgerAccountBalances({
  ledgerIk: "your-ledger-ik",
});

assert(result.ledger?.ledgerAccounts?.nodes, "Failed to list ledger accounts");

To retrieve multi-currency Ledger Accounts with balances:

const result = await fragment.listMultiCurrencyLedgerAccountBalances({
  ledgerIk: "your-ledger-ik",
});

assert(result.ledger?.ledgerAccounts?.nodes, "Failed to list ledger accounts");

FAQs

Package last updated on 23 Apr 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.