0.0.40 • Published 4 years ago

@shipengine/integration-platform-loader v0.0.40

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

ShipEngine Integration Platform App Loader

Cross-Platform Compatibility Build Status

Coverage Status Dependencies

npm License

This library loads a ShipEngine Integration Platform app from an NPM package. Regardless of whether the app is written in JavaScript, TypeScript, JSON, YAML, or a mix of them all, the loader reads those files, validates them, and returns the app object.

Installation

You can install the ShipEngine Integration Platform App Loader via npm.

npm install @shipengine/integration-platform-loader

Example

This example shows you how to use the loader to load an app, inspect its data, and call its methods.

import loader from "@shipengine/integration-platform-loader";

async function main() {
  // Load the ShipEngine Integration Platform app
  let app = await loader.loadApp("/path/to/the/app");

  // Display the app's info
  console.log(`
    Successfully loaded ${app.manifest.name} v${app.manifest.version}

    This is a ${app.type} app that uses v${app.sdkVersion} of the SDK
  `);

  if (app.type === "carrier") {
    // Display the delivery services this carrier offers
    displayCarrierServices(app);

    // Create a shipment
    await createShipment(app);
  }
}


function displayCarrierServices(app) {
  console.log(`
    This carrier supports the following ${app.deliveryServices.length} delivery services:
  `);

  for (let deliveryService of app.deliveryServices) {
    console.log(`
      - ${deliveryService.name}
        class: ${deliveryService.class}
        grade: ${deliveryService.grade}
        service area: ${deliveryService.serviceArea}
        insurable?: ${deliveryService.isInsurable? "yes" : "no"}
        trackable?: ${deliveryService.isTrackable? "yes" : "no"}
    `);
  }
}


async function createShipment(app) {
  console.log(`
    Creating a shipment...
  `);

  let transaction = {
    id: "12345678-1234-1234-1234-123456789012",
    session: {
      foo: "bar",
    }
  };

  let shipment = await app.createShipment(transaction, {
    deliveryService: app.deliveryServices[0],
    shipFrom: {
      name: "John Doe",
      phoneNumber: "555-555-5555",
      company: "Example Corp",
      addressLines: ["4009 Marathon Blvd"],
      cityLocality: "Austin",
      stateProvince: "TX",
      postalCode: "78756",
      country: "US",
      timeZone: "America/Chicago",
      isResidential: false,
    },
    shipTo: {
      name: "Amanda Miller",
      phoneNumber: "111-111-1111",
      addressLines: ["525 S Winchester Blvd."],
      cityLocality: "San Jose",
      stateProvince: "CA",
      postalCode: "95128",
      country: "US",
      timeZone: "America/Los_Angeles",
      isResidential: true,
    },
    shipDateTime: {
      value: "2020-06-01T12:00:00",
      timeZone: "America/Chicago",
    },
    packages: [{
      packaging: app.packaging[0],
      label: {
        format: "pdf",
        size: "4x6",
      }
    }]
  });

  console.log(`
    Successfully created a shipment!

      tracking number: ${shipment.trackingNumber}
      delivery date: ${shipment.deliveryDateTime}
      total cost: ${shipment.totalAmount.value} ${shipment.totalAmount.currency}
  `)
}

main();
0.0.40

4 years ago

0.0.39

4 years ago

0.0.38

4 years ago

0.0.37

4 years ago

0.0.36

4 years ago

0.0.33

4 years ago

0.0.34

4 years ago

0.0.35

4 years ago

0.0.32

4 years ago

0.0.31

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago