@emporix/api-calls 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -28,17 +28,17 @@ Obtain a service access token with the [OAuth Service](https://developer.emporix
|
|
|
28
28
|
|
|
29
29
|
## Client configuration
|
|
30
30
|
|
|
31
|
-
| Function
|
|
32
|
-
|
|
|
33
|
-
| `createApiClient(config)` | Creates axios with interceptors and registers it globally.
|
|
34
|
-
| `setApiClient(instance)`
|
|
35
|
-
| `getApiClient()`
|
|
36
|
-
| `resetApiClient()`
|
|
31
|
+
| Function | Description |
|
|
32
|
+
| ------------------------- | ----------------------------------------------------------- |
|
|
33
|
+
| `createApiClient(config)` | Creates axios with interceptors and registers it globally. |
|
|
34
|
+
| `setApiClient(instance)` | Registers a preconfigured axios instance. |
|
|
35
|
+
| `getApiClient()` | Returns the registered instance (throws if not configured). |
|
|
36
|
+
| `resetApiClient()` | Clears the singleton (tests only). |
|
|
37
37
|
|
|
38
38
|
`createApiClient` automatically adds these headers to every request:
|
|
39
39
|
|
|
40
40
|
- `Authorization: Bearer <token>` (empty string when no token is available)
|
|
41
|
-
- `Emporix-Tenant: <tenant>`
|
|
41
|
+
- `Emporix-Tenant: <tenant>` (only when a non-empty tenant is configured; otherwise the header is removed)
|
|
42
42
|
- `Accept-Language: *`
|
|
43
43
|
- `Content-Language: *`
|
|
44
44
|
|
|
@@ -48,78 +48,78 @@ Official documentation lives on the [Emporix Documentation Portal](https://devel
|
|
|
48
48
|
|
|
49
49
|
### Getting started
|
|
50
50
|
|
|
51
|
-
| Topic
|
|
52
|
-
|
|
|
53
|
-
| Documentation portal | [developer.emporix.io](https://developer.emporix.io)
|
|
54
|
-
| API overview
|
|
55
|
-
| API references hub
|
|
56
|
-
| List of API services | [List of API Services](https://developer.emporix.io/api-references/quickstart/list-of-api-services)
|
|
57
|
-
| Developer Portal
|
|
51
|
+
| Topic | Link |
|
|
52
|
+
| -------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
53
|
+
| Documentation portal | [developer.emporix.io](https://developer.emporix.io) |
|
|
54
|
+
| API overview | [Emporix API introduction](https://developer.emporix.io/api-references/quickstart/api-intro) |
|
|
55
|
+
| API references hub | [API Documentation](https://developer.emporix.io/api-references) |
|
|
56
|
+
| List of API services | [List of API Services](https://developer.emporix.io/api-references/quickstart/list-of-api-services) |
|
|
57
|
+
| Developer Portal | [Developer Portal guide](https://developer.emporix.io/ce/getting-started/developer-portal) |
|
|
58
58
|
| Management Dashboard | [Management Dashboard introduction](https://developer.emporix.io/ce/management-dashboard/introduction) |
|
|
59
|
-
| API base URL
|
|
60
|
-
| API status
|
|
59
|
+
| API base URL | `https://api.emporix.io` |
|
|
60
|
+
| API status | [Emporix Status Page](https://status.emporix.io) |
|
|
61
61
|
|
|
62
62
|
### Authentication and authorization
|
|
63
63
|
|
|
64
|
-
| Topic
|
|
65
|
-
|
|
|
66
|
-
| Tokens and scopes
|
|
67
|
-
| OAuth service access tokens
|
|
64
|
+
| Topic | Link |
|
|
65
|
+
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
66
|
+
| Tokens and scopes | [Tokens and Scopes](https://developer.emporix.io/api-references/quickstart/authentication-and-authorization/tokens-and-scopes) |
|
|
67
|
+
| OAuth service access tokens | [OAuth Tutorial](https://developer.emporix.io/api-references/api-guides/authentication/oauth-service/oauth) |
|
|
68
68
|
| Customer authentication overview | [Customer Authentication](https://developer.emporix.io/api-references/quickstart/authentication-and-authorization/customer-authentication) |
|
|
69
|
-
| Manage API keys
|
|
69
|
+
| Manage API keys | [Manage API Keys](https://developer.emporix.io/ce/getting-started/developer-portal/manage-apikeys) |
|
|
70
70
|
|
|
71
71
|
### Standard practices
|
|
72
72
|
|
|
73
73
|
Many helpers in this package use Emporix pagination, filtering, and sorting conventions:
|
|
74
74
|
|
|
75
|
-
| Topic
|
|
76
|
-
|
|
|
75
|
+
| Topic | Link |
|
|
76
|
+
| --------------------- | -------------------------------------------------------------------------------------------------------------- |
|
|
77
77
|
| Query parameter (`q`) | [Standard Practices — Query parameter](https://developer.emporix.io/api-references/standard-practices/q-param) |
|
|
78
|
-
| Mixins
|
|
78
|
+
| Mixins | [Standard Practices — Mixins](https://developer.emporix.io/api-references/standard-practices/mixins) |
|
|
79
79
|
|
|
80
80
|
### Package modules and API guides
|
|
81
81
|
|
|
82
82
|
Each file under `src/calls/` maps to one or more Emporix API services. Use the guides below for endpoint details, required scopes, request/response schemas, and tutorials.
|
|
83
83
|
|
|
84
|
-
| Package module
|
|
85
|
-
|
|
|
86
|
-
| `ai.ts`
|
|
87
|
-
| `authAdapter.ts`
|
|
88
|
-
| `automation.ts`
|
|
89
|
-
| `availability.ts`
|
|
90
|
-
| `brands.ts`
|
|
91
|
-
| `carts.ts`
|
|
92
|
-
| `catalogs.ts`
|
|
93
|
-
| `categories.ts`
|
|
94
|
-
| `configuration.ts`
|
|
95
|
-
| `countries.ts`
|
|
96
|
-
| `coupons.ts`
|
|
97
|
-
| `currencies.ts`
|
|
98
|
-
| `customEntities.ts`, `customInstances.ts`, `mixins.ts`, `schema.ts` | Schema Service
|
|
99
|
-
| `customerManagement.ts`
|
|
100
|
-
| `customers.ts`
|
|
101
|
-
| `delivery.ts`, `shipping.ts`
|
|
102
|
-
| `globalConfig.ts`
|
|
103
|
-
| `iam.ts`
|
|
104
|
-
| `invoice.ts`
|
|
105
|
-
| `labels.ts`
|
|
106
|
-
| `mediaAssets.ts`
|
|
107
|
-
| `orders.ts`
|
|
108
|
-
| `paymentGateway.ts`
|
|
109
|
-
| `picklists.ts`
|
|
110
|
-
| `priceLists.ts`, `priceModels.ts`, `prices.ts`, `prices_v2.ts`
|
|
111
|
-
| `products.ts`, `productsMedia.ts`
|
|
112
|
-
| `quotes.ts`
|
|
113
|
-
| `returns.ts`
|
|
114
|
-
| `segments.ts`
|
|
115
|
-
| `sepa.ts`
|
|
116
|
-
| `sites.ts`
|
|
117
|
-
| `statistics.ts`
|
|
118
|
-
| `suppliers.ts`
|
|
119
|
-
| `taxes.ts`
|
|
120
|
-
| `units.ts`
|
|
121
|
-
| `vendors.ts`
|
|
122
|
-
| `webhooks.ts`
|
|
84
|
+
| Package module | Emporix service | Documentation |
|
|
85
|
+
| ------------------------------------------------------------------- | --------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
86
|
+
| `ai.ts` | AI Service | [AI Tutorials](https://developer.emporix.io/api-references/api-guides/artificial-intelligence/ai-service/ai-tutorial) |
|
|
87
|
+
| `authAdapter.ts` | Developer Portal / tenant auth | [Developer Portal](https://developer.emporix.io/ce/getting-started/developer-portal) |
|
|
88
|
+
| `automation.ts` | Automation (newsletter) | [Developer Portal](https://developer.emporix.io/ce/getting-started/developer-portal) |
|
|
89
|
+
| `availability.ts` | Availability Service | [Availability Service](https://developer.emporix.io/api-references/api-guides/orders/availability) |
|
|
90
|
+
| `brands.ts` | Brand Service | [Brand Tutorial](https://developer.emporix.io/api-references/api-guides/products-labels-and-brands/brand-service/brand) |
|
|
91
|
+
| `carts.ts` | Cart Service | [Cart Tutorial](https://developer.emporix.io/api-references/api-guides/checkout/cart/cart) |
|
|
92
|
+
| `catalogs.ts` | Catalog Service | [Catalog Tutorial](https://developer.emporix.io/api-references/api-guides/catalogs-and-categories/catalog/catalog) |
|
|
93
|
+
| `categories.ts` | Category Service | [Category Tutorial](https://developer.emporix.io/api-references/api-guides/catalogs-and-categories/category-tree/category) |
|
|
94
|
+
| `configuration.ts` | Configuration Service | [Configuration Service Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/configuration-service/configuration-service-tutorial) |
|
|
95
|
+
| `countries.ts` | Country Service | [Country Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/country-service/country) |
|
|
96
|
+
| `coupons.ts` | Coupon Service | [Coupon Tutorial](https://developer.emporix.io/api-references/api-guides/rewards-and-promotions/coupon/coupon) |
|
|
97
|
+
| `currencies.ts` | Currency Service | [Currency Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/currency-service/currency) |
|
|
98
|
+
| `customEntities.ts`, `customInstances.ts`, `mixins.ts`, `schema.ts` | Schema Service | [Schema Tutorial](https://developer.emporix.io/api-references/api-guides/utilities/schema/schema) |
|
|
99
|
+
| `customerManagement.ts` | Client Management Service | [Customer Management Tutorial](https://developer.emporix.io/api-references/api-guides/companies-and-customers/client-management/customer-management) |
|
|
100
|
+
| `customers.ts` | Customer Service (tenant-managed) | [Customer Service (Tenant Managed) Tutorial](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-service/customer-service-tenant) |
|
|
101
|
+
| `delivery.ts`, `shipping.ts` | Delivery & Shipping | [Delivery and Shipping Tutorial](https://developer.emporix.io/api-references/api-guides/delivery-and-shipping/shipping) |
|
|
102
|
+
| `globalConfig.ts` | Configuration Service | [Configuration Service Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/configuration-service/configuration-service-tutorial) |
|
|
103
|
+
| `iam.ts` | IAM Service | [IAM Tutorial](https://developer.emporix.io/api-references/api-guides/users-and-permissions/iam/iam) |
|
|
104
|
+
| `invoice.ts` | Invoice Service | [Invoice Tutorial](https://developer.emporix.io/api-references/api-guides/orders/invoice/invoice) |
|
|
105
|
+
| `labels.ts` | Label Service | [Label Service](https://developer.emporix.io/api-references/api-guides/products-labels-and-brands/label-service) |
|
|
106
|
+
| `mediaAssets.ts` | Media Service | [Media Tutorial](https://developer.emporix.io/api-references/api-guides/media/media/media) |
|
|
107
|
+
| `orders.ts` | Order Service | [Order Tutorial](https://developer.emporix.io/api-references/api-guides/orders/order/order) |
|
|
108
|
+
| `paymentGateway.ts` | Payment Gateway Service | [Payment-gateway Service](https://developer.emporix.io/api-references/api-guides/checkout/payment-gateway) |
|
|
109
|
+
| `picklists.ts` | Pick-Pack Service | [Pick-pack Service](https://developer.emporix.io/api-references/api-guides/orders/pick-pack) |
|
|
110
|
+
| `priceLists.ts`, `priceModels.ts`, `prices.ts`, `prices_v2.ts` | Price Service | [Price Tutorials](https://developer.emporix.io/api-references/api-guides/prices-and-taxes/price-service/price) |
|
|
111
|
+
| `products.ts`, `productsMedia.ts` | Product Service | [Product Tutorial](https://developer.emporix.io/api-references/api-guides/products-labels-and-brands/product-service/product) |
|
|
112
|
+
| `quotes.ts` | Quote Service | [Quote Tutorial](https://developer.emporix.io/api-references/api-guides/quotes/quote/quote) |
|
|
113
|
+
| `returns.ts` | Returns Service | [Returns Tutorial](https://developer.emporix.io/api-references/api-guides/orders/returns/returns) |
|
|
114
|
+
| `segments.ts` | Customer Segments Service | [Segments Tutorial](https://developer.emporix.io/api-references/api-guides/companies-and-customers/customer-segments/segments) |
|
|
115
|
+
| `sepa.ts` | SEPA Export Service | [SEPA Export Service](https://developer.emporix.io/api-references/api-guides/orders/sepa-export) |
|
|
116
|
+
| `sites.ts` | Site-Settings Service | [Site Settings Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/site-settings-service/site-settings) |
|
|
117
|
+
| `statistics.ts` | Dashboard analytics / IAM | [IAM Tutorial](https://developer.emporix.io/api-references/api-guides/users-and-permissions/iam/iam) |
|
|
118
|
+
| `suppliers.ts` | Supplier API | [List of API Services](https://developer.emporix.io/api-references/quickstart/list-of-api-services) |
|
|
119
|
+
| `taxes.ts` | Tax Service | [Tax Service](https://developer.emporix.io/api-references/api-guides/prices-and-taxes/tax-service) |
|
|
120
|
+
| `units.ts` | Unit-Handling Service | [Unit Handling Tutorial](https://developer.emporix.io/api-references/api-guides/configuration/unit-handling-service/unit-handling) |
|
|
121
|
+
| `vendors.ts` | Vendor Service | [Vendor Tutorial](https://developer.emporix.io/api-references/api-guides/companies-and-customers/vendor-service/vendor) |
|
|
122
|
+
| `webhooks.ts` | Webhook Service | [Webhook Service](https://developer.emporix.io/api-references/api-guides/webhooks/webhook-service) |
|
|
123
123
|
|
|
124
124
|
OpenAPI specifications for all services are listed on the [List of API Services](https://developer.emporix.io/api-references/quickstart/list-of-api-services) page and in the [Emporix GitHub repository](https://github.com/emporix).
|
|
125
125
|
|
|
@@ -134,19 +134,6 @@ npm run build
|
|
|
134
134
|
npm run pack:verify
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
-
## Syncing from management dashboard (Phase 1 staging)
|
|
138
|
-
|
|
139
|
-
The source calls are generated in the management dashboard repo:
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
# in management-dashboard
|
|
143
|
-
node scripts/stage-api-calls-package.mjs
|
|
144
|
-
rsync -a --delete --exclude node_modules --exclude dist \
|
|
145
|
-
tmp/api-calls-package/src/ ../emporix-api-calls/src/
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
Re-run lint, typecheck, test, and build after syncing.
|
|
149
|
-
|
|
150
137
|
## Publishing
|
|
151
138
|
|
|
152
139
|
Releases are published to npm automatically when a version tag is pushed to GitHub. The workflow is defined in [`.github/workflows/publish.yml`](.github/workflows/publish.yml).
|
|
@@ -236,10 +223,10 @@ npm pack --dry-run
|
|
|
236
223
|
|
|
237
224
|
### Common issues
|
|
238
225
|
|
|
239
|
-
| Problem
|
|
240
|
-
|
|
|
241
|
-
| Tag validation failed
|
|
242
|
-
| Publish failed with 403
|
|
226
|
+
| Problem | Likely cause |
|
|
227
|
+
| ----------------------------- | ----------------------------------------------------------------------------- |
|
|
228
|
+
| Tag validation failed | Tag is not `v{version}` or does not match `package.json`. |
|
|
229
|
+
| Publish failed with 403 | Trusted publishing is not configured for this repo/workflow. |
|
|
243
230
|
| Version already exists on npm | Bump `package.json` and create a new tag; npm versions cannot be overwritten. |
|
|
244
231
|
|
|
245
232
|
## CI
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiClient.d.ts","sourceRoot":"","sources":["../../src/client/createApiClient.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IAChD,SAAS,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;CAC5C;AAED,eAAO,MAAM,eAAe,GAAI,QAAQ,qBAAqB,
|
|
1
|
+
{"version":3,"file":"createApiClient.d.ts","sourceRoot":"","sources":["../../src/client/createApiClient.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IAChD,SAAS,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;CAC5C;AAED,eAAO,MAAM,eAAe,GAAI,QAAQ,qBAAqB,kCA6B5D,CAAA"}
|
|
@@ -6,14 +6,22 @@ export const createApiClient = (config) => {
|
|
|
6
6
|
});
|
|
7
7
|
api.interceptors.request.use((req) => {
|
|
8
8
|
const token = config.getAccessToken?.();
|
|
9
|
-
const
|
|
9
|
+
const rawTenant = config.getTenant?.();
|
|
10
|
+
const tenant = typeof rawTenant === 'string'
|
|
11
|
+
? rawTenant.trim() || undefined
|
|
12
|
+
: (rawTenant ?? undefined);
|
|
10
13
|
const { headers } = req;
|
|
11
14
|
if (headers) {
|
|
12
15
|
headers['Authorization'] =
|
|
13
16
|
token != null && token !== '' ? `Bearer ${token}` : '';
|
|
14
17
|
headers['Accept-Language'] = headers['Accept-Language'] || '*';
|
|
15
18
|
headers['Content-Language'] = '*';
|
|
16
|
-
|
|
19
|
+
if (tenant) {
|
|
20
|
+
headers.set('Emporix-Tenant', tenant);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
headers.delete('Emporix-Tenant');
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
return req;
|
|
19
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiClient.js","sourceRoot":"","sources":["../../src/client/createApiClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAqC,MAAM,OAAO,CAAA;AACzD,OAAO,EAAE,YA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