Functional Weave
Code in Rust

logistics.incoterm-responsibility@1.0.0

impl/typescript.ts

1,670 bytes · the TypeScript implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

import { INCOTERMS } from "./logistics_incoterm_responsibility_data.ts";  ← this capability’s own data, compiled from data/incoterms.json into the same file by fune build
import { type IncotermResponsibility, type Party } from "./logistics_incoterm_responsibility_types.ts";

/**
 * Where the seller delivers (and risk passes) under an Incoterms rule, and
 * which party pays for each stage, from the ICC rules for the edition named.
 */
export function incotermResponsibility(rule: string, edition: number): IncotermResponsibility {
  if (!Number.isInteger(edition)) throw new TypeError(`edition must be a year, received ${edition}`);
  if (!INCOTERMS.some((r) => r.edition === edition)) {
    const editions = [...new Set(INCOTERMS.map((r) => r.edition))].join(", ");
    throw new RangeError(`no data for Incoterms ${edition}: this version covers ${editions}`);
  }
  const row = INCOTERMS.find((r) => r.edition === edition && r.rule === rule);
  if (row === undefined) {
    const rules = INCOTERMS.filter((r) => r.edition === edition).map((r) => r.rule).join(", ");
    throw new RangeError(`unknown Incoterms ${edition} rule "${rule}": expected one of ${rules}`);
  }
  return {
    rule: row.rule,
    edition: row.edition,
    name: row.name,
    anyMode: row.anyMode,
    delivery: row.delivery,
    riskPassesAtDestination: row.riskPassesAtDestination,
    loadingAtOrigin: row.loadingAtOrigin as Party,
    exportClearance: row.exportClearance as Party,
    mainCarriage: row.mainCarriage as Party,
    insuranceBy: row.insuranceBy as Party | null,
    insuranceCover: row.insuranceCover,
    unloadingAtDestination: row.unloadingAtDestination as Party,
    importClearance: row.importClearance as Party,
    importDuties: row.importDuties as Party,
  };
}