npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@redonvn/shipping-ems

v0.2.0

Published

TypeScript SDK for EMS Vietnam domestic and international APIs

Readme

@redai/shipping-ems

TypeScript SDK cho EMS Vietnam: nội địa qua CustomerConnect và quốc tế qua gateway hoặc CustomerConnect. Hỗ trợ Node.js 18 trở lên.

Trạng thái: bản đầu (draft), chưa kiểm thử bằng tài khoản EMS thật. Các endpoint và ví dụ được lấy từ tài liệu EMS; hợp đồng vẫn cần được chốt bằng fixture/tài khoản kiểm tra trước khi dùng production.

Cài đặt

npm install @redai/shipping-ems
import { EmsClient } from '@redai/shipping-ems';

const ems = new EmsClient({
  username: process.env.EMS_USERNAME,
  password: process.env.EMS_PASSWORD,
  environment: 'staging',
});

Biến môi trường

Sao chép .env.example sang .env và điền giá trị thực. Không commit .env lên git.

| Biến | Mô tả | Bắt buộc | |------|-------|----------| | EMS_USERNAME | Tên đăng nhập khách hàng EMS | Có (nếu không truyền token sẵn) | | EMS_PASSWORD | Mật khẩu khách hàng EMS | Có (nếu không truyền token sẵn) | | EMS_CUSTOMER_CODE | Mã khách hàng dùng khi ước tính cước | Có cho ví dụ tính cước | | EMS_TOKEN | Token đã có sẵn (bypass login) | Không | | EMS_INTERNATIONAL_API_KEY | API key gateway quốc tế | Có khi dùng gateway | | EMS_INTERNATIONAL_BASE_URL | Override host gateway quốc tế | Không | | EMS_BASE_URL | Base URL tuỳ chọn, override host mặc định | Không | | EMS_TIMEOUT_MS | Timeout mỗi request, ms (mặc định 15000) | Không | | EMS_MAX_RETRIES | Số lần retry GET (mặc định 2) | Không |

Host

Nội địa và quốc tế Bearer mặc định https://customerconnect.ems.com.vn; quốc tế API key mặc định https://gatewayapi.ems.com.vn. EMS chưa chỉ ra sandbox riêng.

Xác thực

ems.auth.login() gửi POST /api/User_Customer/Login với { Username, Password }. Token thành công (Code=1) được cache theo tenant (username). Các request sau gắn header Authorization: Bearer <token>.

const login = await ems.auth.login();
console.log(ems.getCachedToken()); // token đã cache

Lỗi đăng nhập (Code khác 1: -1 sai mật khẩu, -2 user không tồn tại, -3 hết hiệu lực) ném EmsApiError.

Resources

  • auth.login() — đăng nhập, cache token theo tenant.
  • services.listMain() — danh sách dịch vụ chính.
  • services.listAdded(mainService) — dịch vụ cộng thêm.
  • categories.listProvinces() / listDistricts() / listCommunes() / listPostalCodes() — danh mục địa chính bưu chính.
  • fees.estimateDomestic() — ước tính cước (giữ thành phần: Cuoc_Chinh, Cuoc_PPXD, ...).
  • fees.estimateTime() — chỉ tiêu vận chuyển (cần mã tỉnh và huyện hai đầu; EstimatedTime là chuỗi, đơn vị chưa xác định).
  • shipments.create() — tạo bưu gửi (payload UPPER_CASE, ném EmsApiError nếu phần tử listResponse lỗi).
  • shipments.cancel() — hủy bằng ORDER_CODE (mã đơn khách hàng, không phải mã vận đơn).
  • webhook.parseDomestic() / webhook.ack() — parse callback và trả mẫu ACK.

Quốc tế

import { EmsInternationalClient, EmsInternationalCustomerConnectClient } from '@redai/shipping-ems';

const gateway = new EmsInternationalClient({ apiKey: process.env.EMS_INTERNATIONAL_API_KEY! });
const countries = await gateway.categories.listCountries();
const fee = await gateway.fees.estimate({ CountryCode: 'GB', CustomerCode: 'KH01', Weight: '500' });

// Các endpoint quốc tế trên CustomerConnect dùng Bearer token riêng.
const bearer = new EmsInternationalCustomerConnectClient({ token: process.env.EMS_TOKEN! });

Gateway có categories, fees, shipments.create, labels.get và webhook.parseStatus. Client CustomerConnect quốc tế có categories và fees. Xem hướng dẫn quốc tế để biết endpoint, mã đơn, nhãn và giới hạn hợp đồng.

Giới hạn capability (chưa xác nhận)

| Tính năng | Trạng thái | |-----------|------------| | Tracking pull nội địa | Chưa xác nhận endpoint → getOrderTracking() ném lỗi | | In nhãn nội địa | Chưa xác nhận endpoint → getPrintUrl() ném lỗi | | Callback nội địa | Parser có sẵn, nhưng URL/method/auth/ACK/retry/timezone cần EMS xác nhận | | Tracking pull / hủy quốc tế | Chưa có endpoint được xác nhận trong tài liệu đã đọc | | Nhãn quốc tế | Có endpoint; content type và body thực cần xác minh bằng tài khoản EMS | | Callback quốc tế | Có parser A-Tracking; auth, ACK, retry và timezone chưa được tài liệu mô tả |

Nội địa không tự ghép URL tracking/nhãn, không trả mã vận đơn hoặc phí giả.

Tài liệu

Tài liệu API nguồn: EMS và mục lục.