1.9.2 • Published 4 years ago

geom-api-ts-client v1.9.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

geom-api-ts-client

Node.js Package Lint, Test and Publish Coverage Status GitHub code size in bytes GitHub repo size npm npm NPM npm GitHub last commit npm collaborators

A TypeScript client library for accessing GeOM APIs

Install

yarn add geom-api-ts-client

# or, with npm
npm i geom-api-ts-client

Usage

import { Operator } from "geom-api-ts-client";

const result = Operator.getMe(config);
// use result ...

Go to the examples section for more.

Endpoints

Here follows the list of implemented endpoints, with reference to the latest API docs.

nnameendpoint [^1]method
1token/tokenAuthentication.login
2barcode/barcode-decodeBarcode.decode
3operator collection/operatoriOperator.collection
4operator me/operatori/meOperator.me
5operator single/operatori/{id}Operator.single
6operator activity/operatori/{id}/attivitaActivity.collectionByOperator
7machine collection/macchineMachine.collection
8machine single/macchine/{id}Machine.single
9machine activity/macchine/{id}/attivitaActivity.collectionByMachine
23article subdivisions/articoli/{id}/suddivisioniSubdivision.collectionByArticle
27article subdivision details/articoli-suddivisioni/{subdivisionId}Subdivision.single
32freshman subdivisions/articoli-matricole/{freshmanId}/suddivisioniSubdivision.collectionByFreshman
34new article subdivision/articoli-suddivisioniSubdivision.create
37movement reason collection/causali-magazzinoWarehouse.Reason.getCollection
41activity types collection/tipi-attivitaActivities.ActivityType.getCollection
44create warehouse movement/movimenti-magazzinoWarehouse.Movement.create
46check action action phase/fasi-lavorazione/{id}/check-actionJob.checkAction
48start activity/attivita/startActivity.start
49stop activity by machine/attivita-macchine/{machineActivityId}/stopActivity.stopByMachineActivity
50stop activity by machine and operator/attivita-macchine/{machineActivityId}/stopallActivity,stopAllByMachineActivity
51stop activity by operator/attivita-operatori/{operatorActivityId}/stopActivity.stopByOperatorActivity
52end job/fasi-lavorazione/{id}/fineJob.end
57shape collection/formeShape.collection
58shape details/forma/{id}Shape.single
59job phase search by name/fasi-lavorazione/fasecomune/{name}Job.byName

[^1]: version is excluded from endpoint url

Tests

yarn test
yarn lint

# or, with docker
docker-compose build  # needed the fitst time
docker-compose run yarn yarn test
docker-compose run yarn yarn lint

Examples

Functional style

import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/pipeable";
import { Operator } from "geom-api-ts-client";

pipe(
  Operator.getMe({
    token: "my-token-123",
    settings: { url: "www.myurl.com" },
  }),
  TE.fold(
    (err) => {
      // handle the error
    }),
    (operator) => {
      // handle the result
    })),
)();

Promise style

import * as TE from "fp-ts/lib/TaskEither";
import { pipe } from "fp-ts/lib/pipeable";
import { Operator } from "geom-api-ts-client";

export const toResultTask = <E, A>(te: TE.TaskEither<E, A>): T.Task<A> =>
  pipe(
    te,
    teFold(
      (err) => () => Promise.reject(err),
      (res) => tOf(res),
    ),
  );

pipe(
  Operator.getMe({
    token: "my-token-123",
    settings: { url: "www.foo.com" },
  }),
  toResultTask,
)()
  .then((operator) => {
    // handle the result
  })
  .catch((err) => {
    // handle the error
  });

Avoid callback hell

You can make related api calls with easy functional programming features.

const settings = { url: "www.foo.com" };

const activitiesByOperator = (settings: Settings) => (
  operator: Operator.Operator,
) =>
  pipe(
    {
      IdOperatore: operator.IdOperatore,
      settings: settings,
    },
    Activities.collectionByOperator,
  );

const getMe = (settings: Settings) => Operator.getMe(settings);

pipe(
  getMe({ settings: settings }),
  TE.chain(activitiesByOperator({ settings: settings })),
  // You may continue chaining calls
);

Credits

License

The project is MIT licensed. See LICENSE file.

1.9.1

4 years ago

1.9.2

4 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.4

4 years ago

1.7.3

4 years ago

1.7.2

4 years ago

1.7.1

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago