@deliverart/sdk-js-global-types

中文文档
3.0.1发布于 2026/11/11TypeScriptESM + CJS近 30 天下载 6563

Global types for Deliverart SDK in JavaScript

原始使用文档
文档目录15 节
  1. Installation
  2. Exported Types
  3. Common Schemas
  4. Utility Types
  5. IRI Helpers
  6. Utility Functions
  7. Usage Examples
  8. Using Address Schema
  9. Using Pagination
  10. Using IRI Validators
  11. Constants
  12. Countries
  13. Locales
  14. License
  15. Order sub-partners

@deliverart/sdk-js-global-types

Shared types and utilities package for the DeliverArt JavaScript SDK.

Installation

npm install @deliverart/sdk-js-global-types

Exported Types

Common Schemas

Address

interface Address {
  street: string
  city: string
  postalCode: string
  country: string
  state?: string
  province?: string
  line1?: string
  line2?: string
}

Location

interface Location {
  latitude: number
  longitude: number
}

BillingData

interface BillingData {
  email: string
  pec?: string
  sdi?: string
  phone?: string
}

Pagination

interface Pagination {
  currentPage: number
  itemsPerPage: number
  totalItems: number
  totalPages: number
}

Paginated

interface Paginated<T> {
  data: T[]
  pagination: Pagination
}

Utility Types

SortDir

type SortDir = 'asc' | 'desc'

DatetimeFilter

interface DatetimeFilter {
  before?: string
  after?: string
  strictly_before?: string
  strictly_after?: string
}

IRI Helpers

iriSchema

Creates a schema for API resource IRIs.

import { iriSchema } from '@deliverart/sdk-js-global-types';

const userIriSchema = iriSchema('/users/:id');
// Validates strings like: /users/123

iriNullableSchema

Creates a schema for nullable API resource IRIs.

import { iriNullableSchema } from '@deliverart/sdk-js-global-types';

const userNullableIriSchema = iriNullableSchema('/users/:id');
// Validates strings like: /users/123 or null

Utility Functions

createPaginatedSchema

Creates a Zod schema for paginated responses.

import { createPaginatedSchema } from '@deliverart/sdk-js-global-types';
import { z } from 'zod';

const userSchema = z.object({
  id: z.string(),
  name: z.string()
});

const paginatedUsersSchema = createPaginatedSchema(userSchema);
// Type: Paginated<User>

responseToPagination

Extracts pagination info from API response headers.

import { responseToPagination } from '@deliverart/sdk-js-global-types';

parseResponse(data: unknown, rawResponse: Response): Paginated<User> {
  const users = z.array(userSchema).parse(data);
  
  return {
    data: users,
    pagination: responseToPagination(rawResponse)
  };
}

Usage Examples

Using Address Schema

import { addressSchema } from '@deliverart/sdk-js-global-types';
import { z } from 'zod';

const createOrderSchema = z.object({
  customerAddress: addressSchema.required(),
  billingAddress: addressSchema.optional()
});

Using Pagination

import { Paginated } from '@deliverart/sdk-js-global-types';

function displayUsers(result: Paginated<User>) {
  console.log(`Page ${result.pagination.currentPage} of ${result.pagination.totalPages}`);
  console.log(`Total items: ${result.pagination.totalItems}`);
  
  result.data.forEach(user => {
    console.log(user.name);
  });
}

Using IRI Validators

import { iriSchema } from '@deliverart/sdk-js-global-types';

const productIriSchema = iriSchema('/products/:id');

// Valid
productIriSchema.parse('/products/123'); // ✓

// Invalid
productIriSchema.parse('/users/123'); // ✗ Throws validation error
productIriSchema.parse('invalid'); // ✗ Throws validation error

Constants

Countries

export const COUNTRIES = ['IT', 'US', 'UK', /* ... */] as const;

Locales

export const LOCALES = ['it_IT', 'en_US', 'en_GB', /* ... */] as const;

License

MIT

Order sub-partners

orderSubPartnerSchema exposes the five supported Elephant marketplace identities. getOrderSubPartners(partner) returns permitted values independently of connection activation. isOrderSubPartnerAllowed(partner, subPartner) validates a pair. getOrderSubPartnerPresentation(order) returns marketplace/principal display data or null for unknown provenance; clients translate the connecting word "via". matchesOrderProvenance(order, filter) matches API-equivalent parent, marketplace, and hasSubPartner filters for client-side realtime views. Null and omitted values are both unspecified. This metadata does not replace server authorization or Restaurant write-eligibility checks.

版本与发布记录

@deliverart/sdk-js-global-types 共发布 334 个版本,首次发布于 2025/06/16;过去 12 个月发布了 230 个版本。

版本发布日期距今
3.0.1latest2026/11/111 天前
3.0.02026/11/092 天前
3.0.0-dev.1dev2026/11/092 天前
2.48.12026/10/2518 天前
2.48.02026/10/2319 天前
2.47.02026/10/2319 天前

关于 @deliverart/sdk-js-global-types 的常见问题

@deliverart/sdk-js-global-types 是什么?

Global types for Deliverart SDK in JavaScript

如何安装 @deliverart/sdk-js-global-types?

在项目目录运行 npm install @deliverart/sdk-js-global-types,或使用 pnpm add / yarn add / bun add。

@deliverart/sdk-js-global-types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@deliverart/sdk-js-global-types 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deliverart/sdk-js-global-types 可以商用吗?

@deliverart/sdk-js-global-types 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@deliverart/sdk-js-global-types 的下载量有多少?

根据 npm 官方下载统计,@deliverart/sdk-js-global-types 在 2026/10/12 – 2026/11/10 这 30 天内被下载 6,563 次,日均约 219 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deliverart/sdk-js-global-types 还在维护吗?

最新版本 3.0.1 发布于 2026/11/11(1 天前);至今共发布 334 个版本,其中过去 12 个月发布了 230 个;首次发布于 2025/06/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。