pcbway-mcp-server 0.1.0
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/LICENSE +21 -0
- package/README.md +322 -0
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +135 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +24 -0
- package/dist/config.js.map +1 -0
- package/dist/enums.d.ts +20 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +20 -0
- package/dist/enums.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +509 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/Account.d.ts +14 -0
- package/dist/resources/Account.d.ts.map +1 -0
- package/dist/resources/Account.js +22 -0
- package/dist/resources/Account.js.map +1 -0
- package/dist/resources/AssemblyQuote.d.ts +144 -0
- package/dist/resources/AssemblyQuote.d.ts.map +1 -0
- package/dist/resources/AssemblyQuote.js +102 -0
- package/dist/resources/AssemblyQuote.js.map +1 -0
- package/dist/resources/CancelOrder.d.ts +23 -0
- package/dist/resources/CancelOrder.d.ts.map +1 -0
- package/dist/resources/CancelOrder.js +21 -0
- package/dist/resources/CancelOrder.js.map +1 -0
- package/dist/resources/CancelTGroupOrder.d.ts +23 -0
- package/dist/resources/CancelTGroupOrder.d.ts.map +1 -0
- package/dist/resources/CancelTGroupOrder.js +21 -0
- package/dist/resources/CancelTGroupOrder.js.map +1 -0
- package/dist/resources/CheckGroupOrder.d.ts +23 -0
- package/dist/resources/CheckGroupOrder.d.ts.map +1 -0
- package/dist/resources/CheckGroupOrder.js +40 -0
- package/dist/resources/CheckGroupOrder.js.map +1 -0
- package/dist/resources/CheckTGroupOrder.d.ts +23 -0
- package/dist/resources/CheckTGroupOrder.d.ts.map +1 -0
- package/dist/resources/CheckTGroupOrder.js +43 -0
- package/dist/resources/CheckTGroupOrder.js.map +1 -0
- package/dist/resources/ConfirmOrder.d.ts +107 -0
- package/dist/resources/ConfirmOrder.d.ts.map +1 -0
- package/dist/resources/ConfirmOrder.js +67 -0
- package/dist/resources/ConfirmOrder.js.map +1 -0
- package/dist/resources/GetCities.d.ts +35 -0
- package/dist/resources/GetCities.d.ts.map +1 -0
- package/dist/resources/GetCities.js +33 -0
- package/dist/resources/GetCities.js.map +1 -0
- package/dist/resources/GetCountries.d.ts +14 -0
- package/dist/resources/GetCountries.d.ts.map +1 -0
- package/dist/resources/GetCountries.js +22 -0
- package/dist/resources/GetCountries.js.map +1 -0
- package/dist/resources/GetStates.d.ts +29 -0
- package/dist/resources/GetStates.d.ts.map +1 -0
- package/dist/resources/GetStates.js +31 -0
- package/dist/resources/GetStates.js.map +1 -0
- package/dist/resources/Order.d.ts +25 -0
- package/dist/resources/Order.d.ts.map +1 -0
- package/dist/resources/Order.js +59 -0
- package/dist/resources/Order.js.map +1 -0
- package/dist/resources/OrderDetails.d.ts +23 -0
- package/dist/resources/OrderDetails.d.ts.map +1 -0
- package/dist/resources/OrderDetails.js +47 -0
- package/dist/resources/OrderDetails.js.map +1 -0
- package/dist/resources/OrderProcess.d.ts +23 -0
- package/dist/resources/OrderProcess.d.ts.map +1 -0
- package/dist/resources/OrderProcess.js +36 -0
- package/dist/resources/OrderProcess.js.map +1 -0
- package/dist/resources/PayTGroupOrder.d.ts +29 -0
- package/dist/resources/PayTGroupOrder.d.ts.map +1 -0
- package/dist/resources/PayTGroupOrder.js +41 -0
- package/dist/resources/PayTGroupOrder.js.map +1 -0
- package/dist/resources/PcbQuote.d.ts +329 -0
- package/dist/resources/PcbQuote.d.ts.map +1 -0
- package/dist/resources/PcbQuote.js +111 -0
- package/dist/resources/PcbQuote.js.map +1 -0
- package/dist/resources/PlaceOrder.d.ts +173 -0
- package/dist/resources/PlaceOrder.d.ts.map +1 -0
- package/dist/resources/PlaceOrder.js +90 -0
- package/dist/resources/PlaceOrder.js.map +1 -0
- package/dist/resources/Shipping.d.ts +65 -0
- package/dist/resources/Shipping.d.ts.map +1 -0
- package/dist/resources/Shipping.js +47 -0
- package/dist/resources/Shipping.js.map +1 -0
- package/dist/resources/SmtQuote.d.ts +89 -0
- package/dist/resources/SmtQuote.d.ts.map +1 -0
- package/dist/resources/SmtQuote.js +56 -0
- package/dist/resources/SmtQuote.js.map +1 -0
- package/dist/resources/Status.d.ts +27 -0
- package/dist/resources/Status.d.ts.map +1 -0
- package/dist/resources/Status.js +47 -0
- package/dist/resources/Status.js.map +1 -0
- package/dist/resources/common.d.ts +10 -0
- package/dist/resources/common.d.ts.map +1 -0
- package/dist/resources/common.js +69 -0
- package/dist/resources/common.js.map +1 -0
- package/dist/types.d.ts +552 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nabheet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# pcbway-mcp-server
|
|
2
|
+
|
|
3
|
+
**MCP server for the PCBWay Partner API.** Full coverage of the PCBWay API — PCB/SMT quotes, order lifecycle (place, confirm, cancel, status), shipping, account, and address lookup — from any MCP-compatible client (Claude Desktop, etc.).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **PCB Quote** — Instant PCB manufacturing pricing with turn time options
|
|
8
|
+
- **SMT Quote** — SMT assembly pricing by part counts
|
|
9
|
+
- **Order Lifecycle** — Place, confirm, cancel orders; query fabrication status & details
|
|
10
|
+
- **Order Package Management** — Check, pay, and cancel awaiting-payment packages; inspect confirmed packages
|
|
11
|
+
- **Shipping** — Pre-payment freight cost estimate
|
|
12
|
+
- **Account** — Balance, coupon value, reward points
|
|
13
|
+
- **Address Lookup** — Countries, states/provinces, cities with postal codes
|
|
14
|
+
- **16 MCP tools** covering all documented PCBWay Partner API endpoints
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- Node.js >= 18
|
|
19
|
+
- A PCBWay Partner account with an **API Key**
|
|
20
|
+
|
|
21
|
+
## Setup
|
|
22
|
+
|
|
23
|
+
### 1. Get API Credentials
|
|
24
|
+
|
|
25
|
+
Log in to your [PCBWay Partner Dashboard](https://www.pcbway.com) to obtain your **API Key**.
|
|
26
|
+
|
|
27
|
+
### 2. Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install -g pcbway-mcp-server
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or run directly:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx pcbway-mcp-server
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### 3. Configure Environment
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Required:
|
|
43
|
+
export PCBWAY_API_KEY=your_api_key
|
|
44
|
+
|
|
45
|
+
# Optional overrides:
|
|
46
|
+
export PCBWAY_BASE_URL=https://api-partner.pcbway.com # API base
|
|
47
|
+
export PCBWAY_MAX_RETRIES=3 # Max retries for transient failures
|
|
48
|
+
export PCBWAY_BASE_DELAY_MS=500 # Base exponential-backoff delay (ms)
|
|
49
|
+
export PCBWAY_TIMEOUT_MS=30000 # Request timeout (ms)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Note:** The PCBWay Partner API uses a single `api-key` header for authentication. There is no App ID, HMAC signing, or timestamp required.
|
|
53
|
+
|
|
54
|
+
### 4. Run
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx pcbway-mcp-server
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## MCP Client Configuration
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"pcbway": {
|
|
66
|
+
"command": "npx",
|
|
67
|
+
"args": ["-y", "pcbway-mcp-server"],
|
|
68
|
+
"env": {
|
|
69
|
+
"PCBWAY_API_KEY": "your_api_key"
|
|
70
|
+
// Optional: PCBWAY_MAX_RETRIES, PCBWAY_BASE_DELAY_MS, PCBWAY_TIMEOUT_MS, PCBWAY_BASE_URL
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Never hardcode credentials in configs that are shared or committed.**
|
|
78
|
+
|
|
79
|
+
## Available Tools
|
|
80
|
+
|
|
81
|
+
### `pcb_quote`
|
|
82
|
+
|
|
83
|
+
PCB manufacturing price quote. Requires shipping destination and board parameters.
|
|
84
|
+
|
|
85
|
+
| Argument | Type | Required | Description |
|
|
86
|
+
|---|---|---|---|
|
|
87
|
+
| `Country` | string | ✓ | Country name (e.g. "UNITED STATES OF AMERICA") |
|
|
88
|
+
| `CountryCode` | string | ✓ | ISO country code (e.g. "US") |
|
|
89
|
+
| `ShipType` | number | ✓ | Carrier: 1=DHL, 10=FedEx IP, 4=SF Express, 6=EMS, 7=E-packet, 9=China Post, 35=Global Standard |
|
|
90
|
+
| `Postalcode` | string | ✓ | Postal / ZIP code |
|
|
91
|
+
| `City` | string | ✓ | City |
|
|
92
|
+
| `Length` | number | ✓ | Board length in mm |
|
|
93
|
+
| `Width` | number | ✓ | Board width in mm |
|
|
94
|
+
| `Qty` | number | ✓ | Quantity (5–10000) |
|
|
95
|
+
| `Layers` | number | ✓ | Layer count: 1, 2, 4, 6, 8, 10, 12, 14 |
|
|
96
|
+
|
|
97
|
+
Returns pricing by build speed (Standard / Express) with shipping cost.
|
|
98
|
+
|
|
99
|
+
### `smt_quote`
|
|
100
|
+
|
|
101
|
+
SMT assembly price quote. Uses simple part counts (not a full BOM).
|
|
102
|
+
|
|
103
|
+
| Argument | Type | Required | Description |
|
|
104
|
+
|---|---|---|---|
|
|
105
|
+
| `Country` | string | ✓ | Country name |
|
|
106
|
+
| `CountryCode` | string | ✓ | ISO country code |
|
|
107
|
+
| `ShipType` | number | ✓ | Carrier ID |
|
|
108
|
+
| `Postalcode` | string | ✓ | Postal code |
|
|
109
|
+
| `City` | string | ✓ | City |
|
|
110
|
+
| `FlexibleOption` | string | ✓ | "Turnkey", "Kitted or Consigned", "Combo" |
|
|
111
|
+
| `BoardType` | string | ✓ | "Single pieces" or "Panelized PCBs" |
|
|
112
|
+
| `AssemblySide` | string | ✓ | "Top side", "Bottom side", or "Both sides" |
|
|
113
|
+
| `Qty` | number | ✓ | Quantity to assemble |
|
|
114
|
+
| `UniqueParts` | number | | Number of unique parts (default 0) |
|
|
115
|
+
| `SMTParts` | number | | Number of SMT parts (default 0) |
|
|
116
|
+
| `HoleParts` | number | | Number of through-hole parts (default 0) |
|
|
117
|
+
|
|
118
|
+
### `order_process`
|
|
119
|
+
|
|
120
|
+
Get fabrication status — shows all required processes and which are completed.
|
|
121
|
+
|
|
122
|
+
| Argument | Type | Required | Description |
|
|
123
|
+
|---|---|---|---|
|
|
124
|
+
| `OrderNo` | string | ✓ | PCBWay order number (e.g. "W0002AS1") |
|
|
125
|
+
|
|
126
|
+
### `order_details`
|
|
127
|
+
|
|
128
|
+
Get full order details including all PCB parameters (dimensions, material, finish, audit result, delivery date, etc.)
|
|
129
|
+
|
|
130
|
+
| Argument | Type | Required | Description |
|
|
131
|
+
|---|---|---|---|
|
|
132
|
+
| `OrderNo` | string | ✓ | PCBWay order number |
|
|
133
|
+
|
|
134
|
+
### `shipping_freight`
|
|
135
|
+
|
|
136
|
+
Get shipping cost before payment (call after placing order, before confirming).
|
|
137
|
+
|
|
138
|
+
| Argument | Type | Required | Description |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| `OrderNo` | string | ✓ | Order number (comma-separated for joint shipment) |
|
|
141
|
+
| `ShipType` | number | ✓ | Carrier ID |
|
|
142
|
+
| `Country` | string | ✓ | Country name |
|
|
143
|
+
| `CountryCode` | string | ✓ | ISO country code |
|
|
144
|
+
| `Postalcode` | string | ✓ | Postal code |
|
|
145
|
+
| `City` | string | ✓ | City |
|
|
146
|
+
| `State` | string | | State / Province (optional) |
|
|
147
|
+
| `AddGroupNo` | string | | Order package number when adding to package (optional) |
|
|
148
|
+
|
|
149
|
+
### `account_balance`
|
|
150
|
+
|
|
151
|
+
Query PCBWay account balance, coupon value, and reward points. No parameters required.
|
|
152
|
+
|
|
153
|
+
### `place_order`
|
|
154
|
+
|
|
155
|
+
Add a PCB order to your cart. Requires PCB file and all board parameters.
|
|
156
|
+
|
|
157
|
+
| Argument | Type | Required | Description |
|
|
158
|
+
|---|---|---|---|
|
|
159
|
+
| `PcbFileName` | string | ✓ | PCB file name |
|
|
160
|
+
| `BuildDays` | number | ✓ | Production cycle from quote response |
|
|
161
|
+
| `Length` | number | ✓ | Board length in mm |
|
|
162
|
+
| `Width` | number | ✓ | Board width in mm |
|
|
163
|
+
| `Qty` | number | ✓ | Quantity |
|
|
164
|
+
| `Layers` | number | ✓ | Layer count |
|
|
165
|
+
| `BoardType` | string | | "Single PCB" (default), "Panel PCB as design", "Panel PCB by Supplier" |
|
|
166
|
+
| `Material` | string | | "FR-4" (default) |
|
|
167
|
+
| `Thickness` | number | | Board thickness in mm (default 1.6) |
|
|
168
|
+
| `SolderMask` | string | | "Green" (default) |
|
|
169
|
+
| `Silkscreen` | string | | "White" (default) |
|
|
170
|
+
| `SurfaceFinish` | string | | "HASL with lead" (default) |
|
|
171
|
+
| `PcbFileUrl` | string | | URL to PCB Gerber zip file |
|
|
172
|
+
| `Note` | string | | Order notes (optional) |
|
|
173
|
+
| `BuyerEmail` | string | | Email for contact |
|
|
174
|
+
|
|
175
|
+
### `confirm_order`
|
|
176
|
+
|
|
177
|
+
Confirm orders and make payment. Can confirm single or multiple orders together.
|
|
178
|
+
|
|
179
|
+
| Argument | Type | Required | Description |
|
|
180
|
+
|---|---|---|---|
|
|
181
|
+
| `OrderNo` | string | ✓ | Order number(s), comma-separated for multiple |
|
|
182
|
+
| `PayType` | number | ✓ | Payment method: 1=AccountPay, 2=PCBWayWebPay |
|
|
183
|
+
| `ShipType` | number | | Carrier (required unless adding to package) |
|
|
184
|
+
| `Country` | string | | Country name (required unless adding to package) |
|
|
185
|
+
| `CountryCode` | string | | ISO country code (required unless adding to package) |
|
|
186
|
+
| `City` | string | | City (required unless adding to package) |
|
|
187
|
+
| `Addr` | string | | Delivery address (required unless adding to package) |
|
|
188
|
+
| `Tel` | string | | Phone number (required unless adding to package) |
|
|
189
|
+
| `AddGroupNo` | string | | Order package number when adding to existing package |
|
|
190
|
+
| `State` | string | | State / Province |
|
|
191
|
+
| `Postalcode` | string | | Postal code |
|
|
192
|
+
| `ContactName` | string | | Contact person |
|
|
193
|
+
| `CompanyName` | string | | Company name |
|
|
194
|
+
| `BuyerEmail` | string | | Email for contact |
|
|
195
|
+
| `Tax` | string | | Tax ID |
|
|
196
|
+
|
|
197
|
+
### `cancel_order`
|
|
198
|
+
|
|
199
|
+
Cancel an existing PCBWay order.
|
|
200
|
+
|
|
201
|
+
| Argument | Type | Required | Description |
|
|
202
|
+
|---|---|---|---|
|
|
203
|
+
| `OrderNo` | string | ✓ | Order number to cancel |
|
|
204
|
+
|
|
205
|
+
### `check_tgroup_order`
|
|
206
|
+
|
|
207
|
+
Check awaiting-payment order package details.
|
|
208
|
+
|
|
209
|
+
| Argument | Type | Required | Description |
|
|
210
|
+
|---|---|---|---|
|
|
211
|
+
| `TGroupNo` | string | ✓ | Awaiting-payment package number |
|
|
212
|
+
|
|
213
|
+
### `pay_tgroup_order`
|
|
214
|
+
|
|
215
|
+
Pay for an awaiting-payment order package.
|
|
216
|
+
|
|
217
|
+
| Argument | Type | Required | Description |
|
|
218
|
+
|---|---|---|---|
|
|
219
|
+
| `TGroupNo` | string | ✓ | Awaiting-payment package number |
|
|
220
|
+
| `PayType` | number | ✓ | 1=AccountPay, 2=PCBWayWebPay |
|
|
221
|
+
|
|
222
|
+
### `cancel_tgroup_order`
|
|
223
|
+
|
|
224
|
+
Cancel an awaiting-payment order package.
|
|
225
|
+
|
|
226
|
+
| Argument | Type | Required | Description |
|
|
227
|
+
|---|---|---|---|
|
|
228
|
+
| `TGroupNo` | string | ✓ | Awaiting-payment package number to cancel |
|
|
229
|
+
|
|
230
|
+
### `check_group_order`
|
|
231
|
+
|
|
232
|
+
Check a confirmed (paid) order package details.
|
|
233
|
+
|
|
234
|
+
| Argument | Type | Required | Description |
|
|
235
|
+
|---|---|---|---|
|
|
236
|
+
| `GroupNo` | string | ✓ | Confirmed order package number |
|
|
237
|
+
|
|
238
|
+
### `get_countries`
|
|
239
|
+
|
|
240
|
+
List all supported countries for PCBWay ordering. No parameters required.
|
|
241
|
+
|
|
242
|
+
### `get_states`
|
|
243
|
+
|
|
244
|
+
List states/provinces for a country.
|
|
245
|
+
|
|
246
|
+
| Argument | Type | Required | Description |
|
|
247
|
+
|---|---|---|---|
|
|
248
|
+
| `Country` | string | ✓ | Country name (e.g. "UNITED STATES OF AMERICA") |
|
|
249
|
+
| `CountryCode` | string | ✓ | ISO country code (e.g. "US") |
|
|
250
|
+
|
|
251
|
+
### `get_cities`
|
|
252
|
+
|
|
253
|
+
List cities with postal codes for a country/state.
|
|
254
|
+
|
|
255
|
+
| Argument | Type | Required | Description |
|
|
256
|
+
|---|---|---|---|
|
|
257
|
+
| `Country` | string | ✓ | Country name |
|
|
258
|
+
| `CountryCode` | string | ✓ | ISO country code |
|
|
259
|
+
| `State` | string | | State/Province to filter by (optional) |
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
git clone https://github.com/nabheet/pcbway-mcp-server.git
|
|
265
|
+
cd pcbway-mcp-server
|
|
266
|
+
npm install
|
|
267
|
+
npm run build
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Architecture
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
src/
|
|
274
|
+
├── index.ts # MCP server entry point + tool registry
|
|
275
|
+
├── config.ts # Environment variable loading (PCBWAY_API_KEY only)
|
|
276
|
+
├── client.ts # Simple api-key auth, POST-only client
|
|
277
|
+
├── types.ts # Full TypeScript interfaces matching PCBWay API
|
|
278
|
+
└── resources/
|
|
279
|
+
├── PcbQuote.ts # POST /api/Pcb/PcbQuotation
|
|
280
|
+
├── SmtQuote.ts # POST /api/SMT/SMTQuotation
|
|
281
|
+
├── OrderProcess.ts # POST /api/Pcb/QueryOrderProcess
|
|
282
|
+
├── OrderDetails.ts # POST /api/Pcb/CheckOrderDetails
|
|
283
|
+
├── Shipping.ts # POST /api/Pcb/GetFreightByOrder
|
|
284
|
+
├── Account.ts # POST /api/Account/QueryBalance
|
|
285
|
+
├── PlaceOrder.ts # POST /api/Pcb/PlaceOrder
|
|
286
|
+
├── ConfirmOrder.ts # POST /api/Pcb/ConfirmOrder
|
|
287
|
+
├── CancelOrder.ts # POST /api/Pcb/CancelOrder
|
|
288
|
+
├── CheckTGroupOrder.ts # POST /api/Pcb/CheckTGroupOrder
|
|
289
|
+
├── PayTGroupOrder.ts # POST /api/Pcb/PayTGroupOrder
|
|
290
|
+
├── CancelTGroupOrder.ts # POST /api/Pcb/CancelTGroupOrder
|
|
291
|
+
├── CheckGroupOrder.ts # POST /api/Pcb/CheckGroupOrder
|
|
292
|
+
├── GetCountries.ts # POST /api/Address/GetCountry
|
|
293
|
+
├── GetStates.ts # POST /api/Address/GetState
|
|
294
|
+
└── GetCities.ts # POST /api/Address/GetCity
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
One class per resource. Input validation via Zod schemas. All endpoints use POST with JSON body and `api-key` header authentication.
|
|
298
|
+
|
|
299
|
+
## API Endpoint Coverage
|
|
300
|
+
|
|
301
|
+
| MCP Tool | PCBWay API Endpoint | Status |
|
|
302
|
+
|---|---|---|
|
|
303
|
+
| `pcb_quote` | `POST /api/Pcb/PcbQuotation` | ✅ |
|
|
304
|
+
| `smt_quote` | `POST /api/SMT/SMTQuotation` | ✅ |
|
|
305
|
+
| `order_process` | `POST /api/Pcb/QueryOrderProcess` | ✅ |
|
|
306
|
+
| `order_details` | `POST /api/Pcb/CheckOrderDetails` | ✅ |
|
|
307
|
+
| `shipping_freight` | `POST /api/Pcb/GetFreightByOrder` | ✅ |
|
|
308
|
+
| `place_order` | `POST /api/Pcb/PlaceOrder` | ✅ |
|
|
309
|
+
| `confirm_order` | `POST /api/Pcb/ConfirmOrder` | ✅ |
|
|
310
|
+
| `cancel_order` | `POST /api/Pcb/CancelOrder` | ✅ |
|
|
311
|
+
| `check_tgroup_order` | `POST /api/Pcb/CheckTGroupOrder` | ✅ |
|
|
312
|
+
| `pay_tgroup_order` | `POST /api/Pcb/PayTGroupOrder` | ✅ |
|
|
313
|
+
| `cancel_tgroup_order` | `POST /api/Pcb/CancelTGroupOrder` | ✅ |
|
|
314
|
+
| `check_group_order` | `POST /api/Pcb/CheckGroupOrder` | ✅ |
|
|
315
|
+
| `account_balance` | `POST /api/Account/QueryBalance` | ✅ |
|
|
316
|
+
| `get_countries` | `POST /api/Address/GetCountry` | ✅ |
|
|
317
|
+
| `get_states` | `POST /api/Address/GetState` | ✅ |
|
|
318
|
+
| `get_cities` | `POST /api/Address/GetCity` | ✅ |
|
|
319
|
+
|
|
320
|
+
## License
|
|
321
|
+
|
|
322
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Config } from './config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the PCBWay API returns `Status: "error"`.
|
|
4
|
+
* Preserves the API's error message and code.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PcbWayApiError extends Error {
|
|
7
|
+
readonly code: number;
|
|
8
|
+
constructor(message: string, code: number);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Thrown on network failures, timeouts, or non-200 HTTP responses.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PcbWayNetworkError extends Error {
|
|
14
|
+
readonly status?: number | undefined;
|
|
15
|
+
constructor(message: string, status?: number | undefined);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* PCBWay Partner API client.
|
|
19
|
+
* Auth is a single `api-key` header (no HMAC, no appid, no timestamp).
|
|
20
|
+
* All endpoints are POST with JSON body.
|
|
21
|
+
*/
|
|
22
|
+
export declare class PcbWayClient {
|
|
23
|
+
private config;
|
|
24
|
+
constructor(config?: Config);
|
|
25
|
+
/**
|
|
26
|
+
* Perform an authenticated POST request with timeout and retry.
|
|
27
|
+
*
|
|
28
|
+
* Retries on:
|
|
29
|
+
* - Network errors (fetch throws)
|
|
30
|
+
* - HTTP 5xx and 429 (rate limit)
|
|
31
|
+
* Does NOT retry on 4xx except 429 — those are client errors.
|
|
32
|
+
*/
|
|
33
|
+
request<T>(path: string, body: Record<string, unknown>): Promise<T>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAItD;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;aAGrB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM;CAK/B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,MAAM,CAAC,EAAE,MAAM;gBAD/B,OAAO,EAAE,MAAM,EACC,MAAM,CAAC,EAAE,MAAM,YAAA;CAKlC;AAsBD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,MAAM;IAI3B;;;;;;;OAOG;IACG,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CA2F1E"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { loadConfig } from './config.js';
|
|
2
|
+
// ── Typed error ──────────────────────────────────────────────────
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when the PCBWay API returns `Status: "error"`.
|
|
5
|
+
* Preserves the API's error message and code.
|
|
6
|
+
*/
|
|
7
|
+
export class PcbWayApiError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(message, code) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.name = 'PcbWayApiError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Thrown on network failures, timeouts, or non-200 HTTP responses.
|
|
17
|
+
*/
|
|
18
|
+
export class PcbWayNetworkError extends Error {
|
|
19
|
+
status;
|
|
20
|
+
constructor(message, status) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.status = status;
|
|
23
|
+
this.name = 'PcbWayNetworkError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// ── Helpers ──────────────────────────────────────────────────────
|
|
27
|
+
/** Sleep for `ms` milliseconds. */
|
|
28
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
29
|
+
/** Calculate delay with jitter for retry `attempt` (0-indexed). */
|
|
30
|
+
function backoffDelay(baseDelayMs, attempt) {
|
|
31
|
+
const delay = baseDelayMs * 2 ** attempt; // 500, 1000, 2000, …
|
|
32
|
+
const jitter = Math.random() * delay * 0.3; // ±30%
|
|
33
|
+
return Math.round(delay + jitter);
|
|
34
|
+
}
|
|
35
|
+
/** Returns true for status codes that are safe to retry. */
|
|
36
|
+
function isRetryable(status) {
|
|
37
|
+
return status >= 500 || status === 429;
|
|
38
|
+
}
|
|
39
|
+
// ── Client ───────────────────────────────────────────────────────
|
|
40
|
+
/**
|
|
41
|
+
* PCBWay Partner API client.
|
|
42
|
+
* Auth is a single `api-key` header (no HMAC, no appid, no timestamp).
|
|
43
|
+
* All endpoints are POST with JSON body.
|
|
44
|
+
*/
|
|
45
|
+
export class PcbWayClient {
|
|
46
|
+
config;
|
|
47
|
+
constructor(config) {
|
|
48
|
+
this.config = config ?? loadConfig();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Perform an authenticated POST request with timeout and retry.
|
|
52
|
+
*
|
|
53
|
+
* Retries on:
|
|
54
|
+
* - Network errors (fetch throws)
|
|
55
|
+
* - HTTP 5xx and 429 (rate limit)
|
|
56
|
+
* Does NOT retry on 4xx except 429 — those are client errors.
|
|
57
|
+
*/
|
|
58
|
+
async request(path, body) {
|
|
59
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
60
|
+
let lastError = null;
|
|
61
|
+
for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
|
|
62
|
+
try {
|
|
63
|
+
const controller = new AbortController();
|
|
64
|
+
const timeout = setTimeout(() => controller.abort(), this.config.timeoutMs);
|
|
65
|
+
let response;
|
|
66
|
+
try {
|
|
67
|
+
response = await fetch(url, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'application/json',
|
|
71
|
+
'api-key': this.config.apiKey,
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(body),
|
|
74
|
+
signal: controller.signal,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
finally {
|
|
78
|
+
clearTimeout(timeout);
|
|
79
|
+
}
|
|
80
|
+
// Read body once (text, so we can include it in errors)
|
|
81
|
+
const text = await response.text();
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
// Retry on 5xx / 429, bail on 4xx
|
|
84
|
+
if (isRetryable(response.status) && attempt < this.config.maxRetries) {
|
|
85
|
+
const delay = backoffDelay(this.config.baseDelayMs, attempt);
|
|
86
|
+
await sleep(delay);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
throw new PcbWayNetworkError(`HTTP ${response.status} ${response.statusText}${text ? ` — ${text}` : ''}`, response.status);
|
|
90
|
+
}
|
|
91
|
+
// Parse JSON
|
|
92
|
+
const data = JSON.parse(text);
|
|
93
|
+
// Check API-level error status if the response type has it
|
|
94
|
+
// We do a safe check on the envelope fields
|
|
95
|
+
const envelope = data;
|
|
96
|
+
if (envelope.Status === 'error') {
|
|
97
|
+
const errText = typeof envelope.ErrorText === 'string' ? envelope.ErrorText : null;
|
|
98
|
+
const code = typeof envelope.Code === 'number' ? envelope.Code : 0;
|
|
99
|
+
throw new PcbWayApiError(errText ?? 'Unknown API error', code);
|
|
100
|
+
}
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
// If it's already our typed error, re-throw immediately (no retry for API errors)
|
|
105
|
+
if (err instanceof PcbWayApiError) {
|
|
106
|
+
throw err;
|
|
107
|
+
}
|
|
108
|
+
// AbortError (timeout) — retry
|
|
109
|
+
if (err instanceof Error && err.name === 'AbortError') {
|
|
110
|
+
if (attempt < this.config.maxRetries) {
|
|
111
|
+
const delay = backoffDelay(this.config.baseDelayMs, attempt);
|
|
112
|
+
await sleep(delay);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
throw new PcbWayNetworkError('Request timed out');
|
|
116
|
+
}
|
|
117
|
+
// Fetch network error — retry
|
|
118
|
+
if (err instanceof TypeError || (err instanceof Error && 'code' in err)) {
|
|
119
|
+
lastError = err;
|
|
120
|
+
if (attempt < this.config.maxRetries) {
|
|
121
|
+
const delay = backoffDelay(this.config.baseDelayMs, attempt);
|
|
122
|
+
await sleep(delay);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
throw new PcbWayNetworkError(`Network error after ${this.config.maxRetries + 1} attempts: ${err.message}`);
|
|
126
|
+
}
|
|
127
|
+
// Unknown — re-throw immediately
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Should not reach here, but satisfy types
|
|
132
|
+
throw lastError ?? new PcbWayNetworkError('Request failed');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAe,MAAM,aAAa,CAAC;AAEtD,oEAAoE;AAEpE;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IAFlB,YACE,OAAe,EACC,IAAY;QAE5B,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,SAAI,GAAJ,IAAI,CAAQ;QAG5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ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AC,EAAE,CAAC;oBACxE,SAAS,GAAG,GAAY,CAAC;oBACzB,IAAI,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;wBACrC,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;wBAC7D,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC;wBACnB,SAAS;oBACX,CAAC;oBACD,MAAM,IAAI,kBAAkB,CAC1B,uBAAuB,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,CAAC,cAAe,GAAa,CAAC,OAAO,EAAE,CACxF,CAAC;gBACJ,CAAC;gBAED,iCAAiC;gBACjC,MAAM,GAAG,CAAC;YACZ,CAAC;QACH,CAAC;QAED,2CAA2C;QAC3C,MAAM,SAAS,IAAI,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loaded from environment variables.
|
|
3
|
+
* PCBWay Partner API uses a single api-key header — no app ID, no HMAC.
|
|
4
|
+
*
|
|
5
|
+
* Loads .env file automatically via dotenv (if present).
|
|
6
|
+
*/
|
|
7
|
+
import 'dotenv/config';
|
|
8
|
+
export interface Config {
|
|
9
|
+
apiKey: string;
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** Max retries for transient failures (network blips, 5xx). Default 3. */
|
|
12
|
+
maxRetries: number;
|
|
13
|
+
/** Base delay in ms for exponential backoff. Default 500. */
|
|
14
|
+
baseDelayMs: number;
|
|
15
|
+
/** Request timeout in ms. Default 30_000. */
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Load config from process.env.
|
|
20
|
+
* Throws clearly if PCBWAY_API_KEY is missing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function loadConfig(): Config;
|
|
23
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,eAAe,CAAC;AAEvB,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAgBnC"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration loaded from environment variables.
|
|
3
|
+
* PCBWay Partner API uses a single api-key header — no app ID, no HMAC.
|
|
4
|
+
*
|
|
5
|
+
* Loads .env file automatically via dotenv (if present).
|
|
6
|
+
*/
|
|
7
|
+
import 'dotenv/config';
|
|
8
|
+
/**
|
|
9
|
+
* Load config from process.env.
|
|
10
|
+
* Throws clearly if PCBWAY_API_KEY is missing.
|
|
11
|
+
*/
|
|
12
|
+
export function loadConfig() {
|
|
13
|
+
const apiKey = process.env.PCBWAY_API_KEY;
|
|
14
|
+
const baseUrl = process.env.PCBWAY_BASE_URL ?? 'https://api-partner.pcbway.com';
|
|
15
|
+
const maxRetries = parseInt(process.env.PCBWAY_MAX_RETRIES ?? '', 10) || 3;
|
|
16
|
+
const baseDelayMs = parseInt(process.env.PCBWAY_BASE_DELAY_MS ?? '', 10) || 500;
|
|
17
|
+
const timeoutMs = parseInt(process.env.PCBWAY_TIMEOUT_MS ?? '', 10) || 30_000;
|
|
18
|
+
if (!apiKey) {
|
|
19
|
+
throw new Error('Missing PCBWAY_API_KEY environment variable. ' +
|
|
20
|
+
'Set it to your PCBWay Partner API Key.');
|
|
21
|
+
}
|
|
22
|
+
return { apiKey, baseUrl, maxRetries, baseDelayMs, timeoutMs };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,eAAe,CAAC;AAavB;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAC1C,MAAM,OAAO,GACX,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,gCAAgC,CAAC;IAClE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3E,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;IAChF,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC;IAE9E,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,+CAA+C;YAC7C,wCAAwC,CAC3C,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC;AACjE,CAAC"}
|
package/dist/enums.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Freight_ShipType values */
|
|
2
|
+
export declare const SHIP_TYPES: {
|
|
3
|
+
readonly DHL: 1;
|
|
4
|
+
readonly FedEx_IP: 10;
|
|
5
|
+
readonly FedExFICP: 25;
|
|
6
|
+
readonly SF_Express: 4;
|
|
7
|
+
readonly Freight_Collect_Account: 5;
|
|
8
|
+
readonly EMS: 6;
|
|
9
|
+
readonly E_packet: 7;
|
|
10
|
+
readonly China_Post: 9;
|
|
11
|
+
readonly Global_Standard_Shipping: 35;
|
|
12
|
+
};
|
|
13
|
+
export type ShipType = (typeof SHIP_TYPES)[keyof typeof SHIP_TYPES];
|
|
14
|
+
/** Pcb_PayType values */
|
|
15
|
+
export declare const PAY_TYPES: {
|
|
16
|
+
readonly AccountPay: 1;
|
|
17
|
+
readonly PCBWayWebPay: 2;
|
|
18
|
+
};
|
|
19
|
+
export type PayType = (typeof PAY_TYPES)[keyof typeof PAY_TYPES];
|
|
20
|
+
//# sourceMappingURL=enums.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAEA,8BAA8B;AAC9B,eAAO,MAAM,UAAU;;;;;;;;;;CAUb,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAIpE,yBAAyB;AACzB,eAAO,MAAM,SAAS;;;CAGZ,CAAC;AAEX,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/enums.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// ── ShipType ──────────────────────────────────────────────────────
|
|
2
|
+
/** Freight_ShipType values */
|
|
3
|
+
export const SHIP_TYPES = {
|
|
4
|
+
DHL: 1,
|
|
5
|
+
FedEx_IP: 10,
|
|
6
|
+
FedExFICP: 25,
|
|
7
|
+
SF_Express: 4,
|
|
8
|
+
Freight_Collect_Account: 5,
|
|
9
|
+
EMS: 6,
|
|
10
|
+
E_packet: 7,
|
|
11
|
+
China_Post: 9,
|
|
12
|
+
Global_Standard_Shipping: 35,
|
|
13
|
+
};
|
|
14
|
+
// ── PayType ──────────────────────────────────────────────────────
|
|
15
|
+
/** Pcb_PayType values */
|
|
16
|
+
export const PAY_TYPES = {
|
|
17
|
+
AccountPay: 1,
|
|
18
|
+
PCBWayWebPay: 2,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=enums.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAErE,8BAA8B;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,EAAE;IACZ,SAAS,EAAE,EAAE;IACb,UAAU,EAAE,CAAC;IACb,uBAAuB,EAAE,CAAC;IAC1B,GAAG,EAAE,CAAC;IACN,QAAQ,EAAE,CAAC;IACX,UAAU,EAAE,CAAC;IACb,wBAAwB,EAAE,EAAE;CACpB,CAAC;AAIX,oEAAoE;AAEpE,yBAAyB;AACzB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,UAAU,EAAE,CAAC;IACb,YAAY,EAAE,CAAC;CACP,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|