@lbflow/lighttable

中文文档
1.0.6发布于 2026/11/02MITESM + CJS

通用SDK访问LightTable(兼容Node.js, React, Next.js, Vite)。

中文使用文档
文档目录12 节
  1. 安装
  2. 使用
  3. Node.js / Vite / Next.js / React
  4. 功能
  5. node . js函数
  6. 例如:结账
  7. 兼容性
  8. 依赖关系
  9. HTML的用法
  10. 示例:使用OTP进行身份验证
  11. 许可证
  12. 存储库

@lbflow / lighttable

通用SDK来访问LightTable(兼容Node.js, React, Next.js, Vite)。

安装

npm install @lbflow/lighttable

使用

Node.js / Vite / Next.js / React

import LightTable from '@lbflow/lighttable';
// or in CommonJS:
// const LightTable = require('@lbflow/lighttable');

// Node.js < 18 : fournissez un fetch polyfill
// import fetch from 'node-fetch';
// const lightTable = new LightTable({ ..., fetch });

const lightTable = new LightTable({
  baseUrl: 'https://lb01.genielabel.com/



sdk/v1/lighttable',
  store: 'YOUR_STORE_ID',
});

// Example of a chainable query
const data = await lightTable
  .collection('myCollection')
  .find()
  .filter({ status: 'active' })
  .sort({ createdAt: -1 })
  .limit(10)
  .skip(20)
  .select('name age')
  .lean()
  .exec();

console.log(data);





const products = await lightTable
  .products()
  .findOne({ slug: 't-shirt-nike17991579' })
  .limit(2)
  .thumbnailSize('200x200')
  .mainImageSize('500x500')
  .lean();   // chainables: sort, skip, filter, select, lean, etc.

/* returns
{
  "images": [
    {
      "thumbnail": "https://images.labelflow.cloud/c_thumb,w_400,h_400/ytaxnmhsbtolzrhhu3t1.jpg",
      "url": "https://images.labelflow.cloud/c_fill,w_1000,h_1000/ytaxnmhsbtolzrhhu3t1.jpg",
      "orginal": "https://images.labelflow.cloud/v1769473983/ytaxnmhsbtolzrhhu3t1.jpg"
    }
  ],
  "price": 34.99,
  "collections": [],
  "_id": "6978065d940c34525c2106e0",
  "name": "Shirt one",
  "description": "Montrer fièrement que tu y es passé avec cette t-shirt à l'effigie de la capitale Kinshasa. Design moderne et chic qui attire tout le monde.",
  "slug": "shortny",
  "weight": 0.5,
  "store": "6967a16aac0f7817f0870619",
  "deliverable": true,
  "taxable": true,
  "unity": "pièce",
  "weight_unit": "kg",
  "variants": [
    {
      "options": [
        "black"
      ],
      "images": [],
      "price": 34.99,
      "_id": "69c62580bbe292e4375bcfbc",
      "title": "black"
    },
    {
      "options": [
        "white"
      ],
      "images":[
        {
          "thumbnail": "https://images.labelflow.cloud/c_thumb,w_400,h_400/ytaxnmhsbtolzrhhu3t1.jpg",
          "url": "https://images.labelflow.cloud/c_fill,w_1000,h_1000/ytaxnmhsbtolzrhhu3t1.jpg",
          "orginal": "https://images.labelflow.cloud/v1769473983/ytaxnmhsbtolzrhhu3t1.jpg"
        }
      ],
      "price": 34.99,
      "_id": "69c62580bbe292e4375bcfc2",
      "title": "white"
    }
  ],
  "formaterPrice": "34,99 CDF"
}
*/

功能

  • 可链API(如Mongo或Mongoose)
  • 支持所有Mongoose查询选项: filter, sort, limit, skip, select, lean等。
  • 支持Node.js, React, Next.js, Vite (SSR和浏览器)
  • 令牌管理(JWT)
  • 文件上传和签名URL支持
  • 通过沙箱调用存储作用域的Node.js函数

node . js函数

调用创建的函数 lighttable-cli function create. 中接收JSON对象 env 它的返回值由SDK调用返回。

const result = await lightTable.function('calculate-total', {
  env: { items: [{ price: 12, quantity: 2 }] }
});

函数结果也可以是私有文件描述符。返回的对象有 type: 'lighttable-file', name, mimeType, size, downloadUrl, expiresAt;存储密钥未公开。下载url默认持续7小时。集 downloadUrlTtlSeconds 每个电话从60秒到7天。沙箱流文件高达1gb直接到私人文件系统;应用服务器不读取或解析文件字节。下载是强制的 application/octet-stream 和 Content-Disposition: attachment; mimeType 是信息。

const report = await lightTable.function('export-report', {
  env: { collection: 'orders' },
  downloadUrlTtlSeconds: 3600
});

if (report.type === 'lighttable-file') {
  const link = document.createElement('a');
  link.href = report.downloadUrl;
  link.download = report.name;
  link.click();
}

函数执行使用唯一的存储范围内的LightTable令牌,该令牌将在30分钟后过期。功能被拒绝给SDK客户,除非他们 public 或者 user 角色显式启用。这个 user 角色不包括限制 rules 管理员; public 有意配置时允许每个调用者。函数源和npm依赖项应该被视为可信代码。

在函数内部,注入的令牌可以初始化此SDK以查询相同的存储:

import LightTable from '@lbflow/lighttable';

export default async ({ env }) => {
  const lightTable = new LightTable({
    baseUrl: process.env.LIGHTTABLE_BASE_URL,
    store: process.env.LIGHTTABLE_STORE,
    token: process.env.LIGHTTABLE_TOKEN
  });
  return lightTable.collection(env.collection).findOne(env.filter).exec();
};

要从函数返回一个文件,如下所示 /workspace/output/ 然后返回 file() 作为处理程序的第二个参数提供的帮助程序。沙盒将其直接流式传输到私有文件系统;应用服务器只处理元数据。文件限制为1gb,签名URL默认持续7小时。

import { writeFile } from 'node:fs/promises';

export default async ({ env }, { file }) => {
  const outputPath = '/workspace/output/report.csv';
  await writeFile(outputPath, env.csv);
  return file({ path: outputPath, name: 'report.csv', mimeType: 'text/csv' });
};

这些文件阻止了上传者的指令,而这些文件的管理人员也不知道如何处理这些文件。Le fichier peut être un File, Blob, Buffer, Uint8Array 欧 ArrayBuffer.

const products = lightTable.collection('products');
await products.create(
  { name: 'Produit avec image', image: file }
);
await products.updateOne(
  { _id: productId },
  { $set: { name: 'Produit modifié', image: file } }
);
await products.save({ ...document, image: file });
await products.saveMany([
  { ...document1, image: file1 },
  { ...document2, image: file2 }
]);

例如:结账

import LightTable from '@lbflow/lighttable';
// or in CommonJS:
// const LightTable = require('@lbflow/lighttable');

const lightTable = new LightTable({
  baseUrl: 'https://mfumu.labelflow.co/sdk/v1/lighttable',
  store: 'YOUR_STORE_ID',
});

// Example: Create a checkout link for a product or service
const checkoutResult = await lightTable.checkout({
  isInvoice: false,   // false: does not automatically create an invoice after payment
  no_auth: true,      // true: customer can pay without authentication
  items: [
    {
      product_reference: "_id:YOUR_PRODUCT_ID", // ID of the product or service
      quantity: 1,
      variant_id:"variant id "
    }
  ]
});

console.log(checkoutResult);

/* Example output:
{
  "checkout": {
    "taxable": 0,
    "close": false,
    "checkoutType": "order",
    "lineItemQuantity": 1,
    "subTotal": 3000,
    "taxPercentage": 0,

    "discountValue": null,
    "shippingPrice": 0,
    "tax": 0,
    "deliverable": false,
    "comments": [],
    "_id": "68ec95c225fcba531f7d0752",
    "reference": "5337390961",
    "currency": "CDF",
    "items": [
      {
        "modifiers": [],
        "choises": [],
        "_id": "68ec95c225fcba531f7d0753",
        "currency": "CDF",
        "name": "Consultancy 1",
        "price": 3000,
        "quantity": 1
      }
    ],
    "orderId": null,
    "checkoutId": "a37945c4-7094-46c5-9244-068f943fa7c3",
    "paid": false,
    "store": "67894cd67908d7b5057e75d4",
    "total": 3000,
    "created": "2025-10-13T06:01:38.226Z",
    "__v": 0
  },
  "link": "https://example.com/checkout/a37945c4-7094-46c5-9244-068f943fa7c3"
}
*/

console.log("Link for customer to proceed with payment:", checkoutResult.link);
// The `link` field contains the URL you can send to the customer to complete payment.

兼容性

  • Node.js >= 14
  • 反应>= 17
  • Next.js >= 12
  • Vite >= 2
  • 获取API请求(原生en Node.js >= 18 / navigateurs modernes)

依赖关系

  • 没有任何(利用 fetch)

HTML的用法

<script src="lighttable.js"></script>
<script>
  const lightTable = new LightTable({
    baseUrl: 'https://lb01.genielabel.com/sdk/v1/lighttable',
    store: 'YOUR_STORE_ID',
  });

  lightTable.getMe().then(console.log);
</script>

示例:使用OTP进行身份验证

await lightTable.authOtp({ type: 'email', email: '[email protected]' });
// ...user receives OTP...
const result = await lightTable.verifyOtp({ code: '1234', email: '[email protected]' });
console.log(result.token); // JWT token

许可证

麻省理工学院

存储库

https://github.com/genielabel/lightTable

版本与发布记录

@lbflow/lighttable 共发布 7 个版本,首次发布于 2026/08/07;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.0.6latest2026/11/021 天前
1.0.52026/09/211 个月前
1.0.42026/08/082 个月前
1.0.32026/08/082 个月前
1.0.22026/08/072 个月前
1.0.12026/08/072 个月前

关于 @lbflow/lighttable 的常见问题

@lbflow/lighttable 是什么?

通用SDK访问LightTable(兼容Node.js, React, Next.js, Vite)。

如何安装 @lbflow/lighttable?

在项目目录运行 npm install @lbflow/lighttable,或使用 pnpm add / yarn add / bun add。

@lbflow/lighttable 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/lbflow__lighttable 是否存在。

@lbflow/lighttable 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@lbflow/lighttable 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@lbflow/lighttable 可以商用吗?

@lbflow/lighttable 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@lbflow/lighttable 还在维护吗?

最新版本 1.0.6 发布于 2026/11/02(1 天前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。