e.gateway

Connector SDK

Construa conectores próprios com o contrato do e.gateway.

npm i @eworks/gateway-sdk

connector.ts

import { defineConnector } from "@eworks/gateway-sdk";

export default defineConnector({
  id: "acme-crm",
  category: "crm",
  auth: { type: "oauth2", scopes: ["records.read"] },

  async discover(ctx) {
    const objects = await ctx.http.get("/api/objects");
    return objects.map((o) => ({ id: o.name, label: o.label }));
  },

  async schema(ctx, datasetId) {
    const fields = await ctx.http.get(`/api/objects/${datasetId}/fields`);
    return fields.map((f) => ({
      name: f.api_name,
      type: ctx.types.map(f.type),
      pii: f.is_personal ? "mask" : "none",
    }));
  },

  async *read(ctx, { datasetId, cursor }) {
    for await (const page of ctx.paginate(datasetId, cursor)) {
      yield {
        records: page.items,
        acl: page.items.map((i) => ctx.acl.fromGroups(i.sharing_groups)),
        cursor: page.nextCursor,
      };
    }
  },
});

Ciclo de vida

  1. 1

    discover()

    Descobre objetos disponíveis na origem.

  2. 2

    schema()

    Infere tipos e marca campos de PII.

  3. 3

    read()

    Leitura incremental com cursor retomável.

  4. 4

    acl()

    Mapeia permissões da origem para princípios eworks.

  5. 5

    health()

    Reporta saúde, cotas e atraso ao e.gateway.