@flexops/sdk 2.0.0 → 3.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/README.md +210 -119
- package/dist/index.d.mts +1123 -420
- package/dist/index.d.ts +1123 -420
- package/dist/index.js +827 -405
- package/dist/index.mjs +818 -402
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,52 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/types.ts
|
|
9
|
+
var WorkspaceRole = {
|
|
10
|
+
Owner: 0,
|
|
11
|
+
Admin: 1,
|
|
12
|
+
Member: 2,
|
|
13
|
+
Merchant: 3
|
|
14
|
+
};
|
|
15
|
+
var HazmatClassification = {
|
|
16
|
+
None: 0,
|
|
17
|
+
LimitedQuantity: 1,
|
|
18
|
+
LithiumBatteryContainedInEquipment: 2,
|
|
19
|
+
LithiumBatteryPackedWithEquipment: 3,
|
|
20
|
+
LithiumBatteryStandalone: 4,
|
|
21
|
+
OtherRestricted: 5,
|
|
22
|
+
LithiumBatteryUsedDevice: 6
|
|
23
|
+
};
|
|
24
|
+
var WebhookEventType = {
|
|
25
|
+
LabelCreated: "LabelCreated",
|
|
26
|
+
LabelCanceled: "LabelCanceled",
|
|
27
|
+
BatchCompleted: "BatchCompleted",
|
|
28
|
+
TrackingUpdated: "TrackingUpdated",
|
|
29
|
+
TrackingDelivered: "TrackingDelivered"
|
|
30
|
+
};
|
|
31
|
+
var RecurrenceInterval = {
|
|
32
|
+
Daily: 0,
|
|
33
|
+
Weekly: 1,
|
|
34
|
+
Biweekly: 2,
|
|
35
|
+
Monthly: 3,
|
|
36
|
+
Custom: 4
|
|
37
|
+
};
|
|
38
|
+
var ReportFormat = {
|
|
39
|
+
Csv: 0,
|
|
40
|
+
Json: 1
|
|
41
|
+
};
|
|
42
|
+
var ReportFrequency = {
|
|
43
|
+
Daily: 0,
|
|
44
|
+
Weekly: 1,
|
|
45
|
+
Monthly: 2
|
|
46
|
+
};
|
|
47
|
+
var TrackingEmailEvent = {
|
|
48
|
+
LabelCreated: 0,
|
|
49
|
+
InTransit: 1,
|
|
50
|
+
OutForDelivery: 2,
|
|
51
|
+
Delivered: 3,
|
|
52
|
+
Exception: 4,
|
|
53
|
+
ReturnToSender: 5
|
|
54
|
+
};
|
|
9
55
|
var FlexOpsError = class extends Error {
|
|
10
56
|
constructor(message, status, code, errors) {
|
|
11
57
|
super(message);
|
|
@@ -14,6 +60,9 @@ var FlexOpsError = class extends Error {
|
|
|
14
60
|
this.errors = errors;
|
|
15
61
|
this.name = "FlexOpsError";
|
|
16
62
|
}
|
|
63
|
+
status;
|
|
64
|
+
code;
|
|
65
|
+
errors;
|
|
17
66
|
};
|
|
18
67
|
var FlexOpsRateLimitError = class extends FlexOpsError {
|
|
19
68
|
constructor(message, retryAfter) {
|
|
@@ -21,6 +70,7 @@ var FlexOpsRateLimitError = class extends FlexOpsError {
|
|
|
21
70
|
this.retryAfter = retryAfter;
|
|
22
71
|
this.name = "FlexOpsRateLimitError";
|
|
23
72
|
}
|
|
73
|
+
retryAfter;
|
|
24
74
|
};
|
|
25
75
|
var FlexOpsAuthError = class extends FlexOpsError {
|
|
26
76
|
constructor(message) {
|
|
@@ -29,6 +79,20 @@ var FlexOpsAuthError = class extends FlexOpsError {
|
|
|
29
79
|
}
|
|
30
80
|
};
|
|
31
81
|
|
|
82
|
+
// src/node-crypto.ts
|
|
83
|
+
function loadNodeCrypto(purpose) {
|
|
84
|
+
const fromProcess = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
85
|
+
if (fromProcess) return fromProcess;
|
|
86
|
+
if (typeof __require === "function") {
|
|
87
|
+
return __require("crypto");
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`${purpose} needs node:crypto (Node.js 20.16+ for the ES module build).`);
|
|
90
|
+
}
|
|
91
|
+
function randomUuid() {
|
|
92
|
+
const webCrypto = globalThis.crypto;
|
|
93
|
+
return webCrypto?.randomUUID ? webCrypto.randomUUID() : loadNodeCrypto("Generating an Idempotency-Key").randomUUID();
|
|
94
|
+
}
|
|
95
|
+
|
|
32
96
|
// src/http.ts
|
|
33
97
|
var DEFAULT_BASE_URL = "https://gateway.flexops.io";
|
|
34
98
|
var DEFAULT_TIMEOUT = 3e4;
|
|
@@ -37,6 +101,9 @@ var DEFAULT_RETRY = {
|
|
|
37
101
|
baseDelay: 1e3,
|
|
38
102
|
retryableStatusCodes: [429, 500, 502, 503, 504]
|
|
39
103
|
};
|
|
104
|
+
var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
105
|
+
var WRITE_RETRYABLE_STATUSES = /* @__PURE__ */ new Set([502, 503, 504]);
|
|
106
|
+
var IDEMPOTENCY_CONFLICT = "IDEMPOTENCY_CONFLICT";
|
|
40
107
|
var HttpClient = class {
|
|
41
108
|
baseUrl;
|
|
42
109
|
timeout;
|
|
@@ -57,6 +124,10 @@ var HttpClient = class {
|
|
|
57
124
|
setAccessToken(token) {
|
|
58
125
|
this.accessToken = token;
|
|
59
126
|
}
|
|
127
|
+
/** The JWT access token in use, if any. */
|
|
128
|
+
getAccessToken() {
|
|
129
|
+
return this.accessToken;
|
|
130
|
+
}
|
|
60
131
|
setApiKey(key) {
|
|
61
132
|
this.apiKey = key;
|
|
62
133
|
}
|
|
@@ -65,6 +136,10 @@ var HttpClient = class {
|
|
|
65
136
|
const headers = this.buildHeaders(options?.headers);
|
|
66
137
|
const body = options?.body ? JSON.stringify(options.body) : void 0;
|
|
67
138
|
const timeout = options?.timeout ?? this.timeout;
|
|
139
|
+
const verb = method.toUpperCase();
|
|
140
|
+
if (WRITE_METHODS.has(verb) && !Object.keys(headers).some((h) => h.toLowerCase() === "idempotency-key")) {
|
|
141
|
+
headers["Idempotency-Key"] = randomUuid();
|
|
142
|
+
}
|
|
68
143
|
let lastError;
|
|
69
144
|
for (let attempt = 0; attempt <= this.retry.maxRetries; attempt++) {
|
|
70
145
|
if (attempt > 0) {
|
|
@@ -73,65 +148,60 @@ var HttpClient = class {
|
|
|
73
148
|
}
|
|
74
149
|
const controller = new AbortController();
|
|
75
150
|
const timer = setTimeout(() => controller.abort(), timeout);
|
|
151
|
+
let response;
|
|
76
152
|
try {
|
|
77
|
-
|
|
153
|
+
response = await this.fetchFn(url, {
|
|
78
154
|
method,
|
|
79
155
|
headers,
|
|
80
156
|
body,
|
|
81
157
|
signal: controller.signal
|
|
82
158
|
});
|
|
83
|
-
clearTimeout(timer);
|
|
84
|
-
if (response.ok) {
|
|
85
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
86
|
-
if (contentType.includes("application/json")) {
|
|
87
|
-
return await response.json();
|
|
88
|
-
}
|
|
89
|
-
return response;
|
|
90
|
-
}
|
|
91
|
-
if (response.status === 429) {
|
|
92
|
-
const retryAfter = parseInt(response.headers.get("retry-after") ?? "0", 10);
|
|
93
|
-
lastError = new FlexOpsRateLimitError(
|
|
94
|
-
`Rate limited. Retry after ${retryAfter}s`,
|
|
95
|
-
retryAfter
|
|
96
|
-
);
|
|
97
|
-
if (this.retry.retryableStatusCodes.includes(429)) continue;
|
|
98
|
-
throw lastError;
|
|
99
|
-
}
|
|
100
|
-
if (response.status === 401) {
|
|
101
|
-
throw new FlexOpsAuthError("Authentication required. Check your access token or API key.");
|
|
102
|
-
}
|
|
103
|
-
if (response.status === 403) {
|
|
104
|
-
throw new FlexOpsError("Access denied. Check your plan tier and feature entitlements.", 403, "FORBIDDEN");
|
|
105
|
-
}
|
|
106
|
-
let errorBody = {};
|
|
107
|
-
try {
|
|
108
|
-
errorBody = await response.json();
|
|
109
|
-
} catch {
|
|
110
|
-
}
|
|
111
|
-
const error = new FlexOpsError(
|
|
112
|
-
errorBody.message ?? `HTTP ${response.status}: ${response.statusText}`,
|
|
113
|
-
response.status,
|
|
114
|
-
errorBody.code ?? errorBody.errorCode,
|
|
115
|
-
errorBody.errors
|
|
116
|
-
);
|
|
117
|
-
if (this.retry.retryableStatusCodes.includes(response.status)) {
|
|
118
|
-
lastError = error;
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
throw error;
|
|
122
159
|
} catch (err) {
|
|
160
|
+
lastError = err instanceof DOMException && err.name === "AbortError" ? new FlexOpsError(`Request timed out after ${timeout}ms`, 0, "TIMEOUT") : err instanceof Error ? err : new Error(String(err));
|
|
161
|
+
if (verb === "DELETE") throw lastError;
|
|
162
|
+
continue;
|
|
163
|
+
} finally {
|
|
123
164
|
clearTimeout(timer);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
165
|
+
}
|
|
166
|
+
if (response.ok) {
|
|
167
|
+
if (response.status === 204 || response.headers.get("content-length") === "0") {
|
|
168
|
+
return void 0;
|
|
127
169
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
170
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
171
|
+
if (contentType.includes("application/json")) {
|
|
172
|
+
return await response.json();
|
|
131
173
|
}
|
|
132
|
-
|
|
133
|
-
if (attempt < this.retry.maxRetries) continue;
|
|
174
|
+
return response;
|
|
134
175
|
}
|
|
176
|
+
if (response.status === 429) {
|
|
177
|
+
const retryAfter = parseInt(response.headers.get("retry-after") ?? "0", 10);
|
|
178
|
+
lastError = new FlexOpsRateLimitError(
|
|
179
|
+
`Rate limited. Retry after ${retryAfter}s`,
|
|
180
|
+
retryAfter
|
|
181
|
+
);
|
|
182
|
+
if (this.retry.retryableStatusCodes.includes(429)) continue;
|
|
183
|
+
throw lastError;
|
|
184
|
+
}
|
|
185
|
+
if (response.status === 401) {
|
|
186
|
+
throw new FlexOpsAuthError("Authentication required. Check your access token or API key.");
|
|
187
|
+
}
|
|
188
|
+
let errorBody = {};
|
|
189
|
+
try {
|
|
190
|
+
errorBody = await response.json();
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
const code = errorBody.code ?? errorBody.errorCode;
|
|
194
|
+
const error = new FlexOpsError(
|
|
195
|
+
errorBody.message ?? `HTTP ${response.status}: ${response.statusText}`,
|
|
196
|
+
response.status,
|
|
197
|
+
code ?? (response.status === 403 ? "FORBIDDEN" : void 0),
|
|
198
|
+
errorBody.errors
|
|
199
|
+
);
|
|
200
|
+
if (this.isRetryable(verb, response.status, code)) {
|
|
201
|
+
lastError = error;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
throw error;
|
|
135
205
|
}
|
|
136
206
|
throw lastError ?? new FlexOpsError("Request failed after retries", 0, "RETRY_EXHAUSTED");
|
|
137
207
|
}
|
|
@@ -175,6 +245,17 @@ var HttpClient = class {
|
|
|
175
245
|
}
|
|
176
246
|
return headers;
|
|
177
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* GETs retry on every configured status. A write retries only where the Gateway either did not
|
|
250
|
+
* run it or will replay it for the same Idempotency-Key: never after a 500, whose response the
|
|
251
|
+
* Gateway does not cache, so a retry would run the write again. A DELETE retries only on 429.
|
|
252
|
+
*/
|
|
253
|
+
isRetryable(verb, status, code) {
|
|
254
|
+
if (verb === "GET" || verb === "HEAD") return this.retry.retryableStatusCodes.includes(status);
|
|
255
|
+
if (verb === "DELETE") return false;
|
|
256
|
+
if (status === 409) return code === IDEMPOTENCY_CONFLICT;
|
|
257
|
+
return WRITE_RETRYABLE_STATUSES.has(status) && this.retry.retryableStatusCodes.includes(status);
|
|
258
|
+
}
|
|
178
259
|
calculateBackoff(attempt) {
|
|
179
260
|
const jitter = Math.random() * 0.3 + 0.85;
|
|
180
261
|
return Math.min(this.retry.baseDelay * Math.pow(2, attempt - 1) * jitter, 3e4);
|
|
@@ -189,30 +270,35 @@ var AuthResource = class {
|
|
|
189
270
|
constructor(http) {
|
|
190
271
|
this.http = http;
|
|
191
272
|
}
|
|
192
|
-
|
|
273
|
+
http;
|
|
274
|
+
/**
|
|
275
|
+
* Authenticate with email and password. On success the returned access token (`data.token`) is
|
|
276
|
+
* used for later requests. When `data.requiresTwoFactor` is true no token is issued yet.
|
|
277
|
+
*/
|
|
193
278
|
async login(request) {
|
|
194
279
|
const result = await this.http.post(
|
|
195
280
|
"/api/Account/login",
|
|
196
281
|
request
|
|
197
282
|
);
|
|
198
|
-
if (result.data?.
|
|
199
|
-
this.http.setAccessToken(result.data.
|
|
283
|
+
if (result.data?.token) {
|
|
284
|
+
this.http.setAccessToken(result.data.token);
|
|
200
285
|
}
|
|
201
286
|
return result;
|
|
202
287
|
}
|
|
203
|
-
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Exchange a refresh token for a new access token. The Gateway needs the expired access token
|
|
290
|
+
* too; it defaults to the one this client holds.
|
|
291
|
+
*/
|
|
292
|
+
async refreshToken(refreshToken, accessToken = this.http.getAccessToken()) {
|
|
293
|
+
if (!accessToken) {
|
|
294
|
+
throw new FlexOpsAuthError("refreshToken needs the expired access token; log in first or pass it.");
|
|
295
|
+
}
|
|
296
|
+
const response = await this.http.post(
|
|
211
297
|
"/api/Account/refresh-token",
|
|
212
|
-
{
|
|
298
|
+
{ token: accessToken, refreshToken }
|
|
213
299
|
);
|
|
214
|
-
if (response.data?.
|
|
215
|
-
this.http.setAccessToken(response.data.
|
|
300
|
+
if (response.data?.token) {
|
|
301
|
+
this.http.setAccessToken(response.data.token);
|
|
216
302
|
}
|
|
217
303
|
return response;
|
|
218
304
|
}
|
|
@@ -220,33 +306,6 @@ var AuthResource = class {
|
|
|
220
306
|
async logout() {
|
|
221
307
|
return this.http.post("/api/Account/logout");
|
|
222
308
|
}
|
|
223
|
-
/** Get the current user's profile. */
|
|
224
|
-
async getProfile() {
|
|
225
|
-
return this.http.get("/api/Account/profile");
|
|
226
|
-
}
|
|
227
|
-
/** Update the current user's profile. */
|
|
228
|
-
async updateProfile(data) {
|
|
229
|
-
return this.http.put("/api/Account/profile", data);
|
|
230
|
-
}
|
|
231
|
-
/** Change the current user's password. */
|
|
232
|
-
async changePassword(currentPassword, newPassword) {
|
|
233
|
-
return this.http.post("/api/Account/change-password", {
|
|
234
|
-
currentPassword,
|
|
235
|
-
newPassword
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
/** Request a password reset email. */
|
|
239
|
-
async forgotPassword(email) {
|
|
240
|
-
return this.http.post("/api/Account/forgot-password", { email });
|
|
241
|
-
}
|
|
242
|
-
/** Reset password using a reset token. */
|
|
243
|
-
async resetPassword(token, newPassword) {
|
|
244
|
-
return this.http.post("/api/Account/reset-password", { token, newPassword });
|
|
245
|
-
}
|
|
246
|
-
/** Verify email with the verification token. */
|
|
247
|
-
async verifyEmail(token) {
|
|
248
|
-
return this.http.post("/api/Account/verify-email", { token });
|
|
249
|
-
}
|
|
250
309
|
};
|
|
251
310
|
|
|
252
311
|
// src/resources/workspaces.ts
|
|
@@ -255,6 +314,8 @@ var WorkspacesResource = class {
|
|
|
255
314
|
this.http = http;
|
|
256
315
|
this.getWorkspaceId = getWorkspaceId;
|
|
257
316
|
}
|
|
317
|
+
http;
|
|
318
|
+
getWorkspaceId;
|
|
258
319
|
wsPath(suffix) {
|
|
259
320
|
const id = this.getWorkspaceId();
|
|
260
321
|
if (!id) throw new Error("workspaceId is required. Set it via client.workspaceId or config.");
|
|
@@ -269,29 +330,21 @@ var WorkspacesResource = class {
|
|
|
269
330
|
const id = workspaceId ?? this.getWorkspaceId();
|
|
270
331
|
return this.http.get(`/api/workspaces/${id}`);
|
|
271
332
|
}
|
|
272
|
-
/**
|
|
273
|
-
async create(request) {
|
|
274
|
-
return this.http.post("/api/workspaces", request);
|
|
275
|
-
}
|
|
276
|
-
/** Update workspace settings. */
|
|
277
|
-
async update(data) {
|
|
278
|
-
return this.http.put(this.wsPath(), data);
|
|
279
|
-
}
|
|
280
|
-
/** List members of the current workspace. */
|
|
333
|
+
/** List the current workspace's members and pending invites. */
|
|
281
334
|
async listMembers() {
|
|
282
335
|
return this.http.get(this.wsPath("members"));
|
|
283
336
|
}
|
|
284
337
|
/** Invite a user to the workspace. */
|
|
285
|
-
async inviteMember(email, role =
|
|
338
|
+
async inviteMember(email, role = WorkspaceRole.Member) {
|
|
286
339
|
return this.http.post(this.wsPath("members/invite"), { email, role });
|
|
287
340
|
}
|
|
288
341
|
/** Remove a member from the workspace. */
|
|
289
342
|
async removeMember(userId) {
|
|
290
343
|
return this.http.delete(this.wsPath(`members/${userId}`));
|
|
291
344
|
}
|
|
292
|
-
/**
|
|
345
|
+
/** Change a member's role. */
|
|
293
346
|
async updateMemberRole(userId, role) {
|
|
294
|
-
return this.http.put(this.wsPath(`members/${userId}/role`), { role });
|
|
347
|
+
return this.http.put(this.wsPath(`members/${userId}/role`), { newRole: role });
|
|
295
348
|
}
|
|
296
349
|
};
|
|
297
350
|
|
|
@@ -301,6 +354,8 @@ var ShippingResource = class {
|
|
|
301
354
|
this.http = http;
|
|
302
355
|
this.getWorkspaceId = getWorkspaceId;
|
|
303
356
|
}
|
|
357
|
+
http;
|
|
358
|
+
getWorkspaceId;
|
|
304
359
|
wsPath(suffix) {
|
|
305
360
|
const id = this.getWorkspaceId();
|
|
306
361
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -311,15 +366,15 @@ var ShippingResource = class {
|
|
|
311
366
|
// -----------------------------------------------------------------------
|
|
312
367
|
/** Get shipping rates from all configured carriers. */
|
|
313
368
|
async getRates(request) {
|
|
314
|
-
return this.http.post("/api/shipping/rates", request);
|
|
369
|
+
return this.http.post("/api/shipping/rates", toRateWire(request));
|
|
315
370
|
}
|
|
316
371
|
/** Get the single cheapest rate across all carriers. */
|
|
317
372
|
async getCheapestRate(request) {
|
|
318
|
-
return this.http.post("/api/shipping/rates/cheapest", request);
|
|
373
|
+
return this.http.post("/api/shipping/rates/cheapest", toRateWire(request));
|
|
319
374
|
}
|
|
320
375
|
/** Get the single fastest rate across all carriers. */
|
|
321
376
|
async getFastestRate(request) {
|
|
322
|
-
return this.http.post("/api/shipping/rates/fastest", request);
|
|
377
|
+
return this.http.post("/api/shipping/rates/fastest", toRateWire(request));
|
|
323
378
|
}
|
|
324
379
|
// -----------------------------------------------------------------------
|
|
325
380
|
// Labels
|
|
@@ -330,7 +385,11 @@ var ShippingResource = class {
|
|
|
330
385
|
* server-side and postage is settled atomically. Returns the raw label (HTTP 201).
|
|
331
386
|
*/
|
|
332
387
|
async createLabel(request) {
|
|
333
|
-
const
|
|
388
|
+
const { body, idempotencyKey } = toLabelWire(request);
|
|
389
|
+
const result = await this.http.request("POST", "/api/shipping/labels", {
|
|
390
|
+
body,
|
|
391
|
+
...idempotencyKey ? { headers: { "Idempotency-Key": idempotencyKey } } : {}
|
|
392
|
+
});
|
|
334
393
|
if ("status" in result) throw new FlexOpsError("Approval required. Use prepareLabel, review its preview, then purchaseLabel.", 400, "ApprovalRequired");
|
|
335
394
|
return result;
|
|
336
395
|
}
|
|
@@ -380,16 +439,20 @@ var ShippingResource = class {
|
|
|
380
439
|
// -----------------------------------------------------------------------
|
|
381
440
|
/** Validate and correct a shipping address. */
|
|
382
441
|
async validateAddress(address) {
|
|
383
|
-
|
|
442
|
+
const a = toShippingAddress(address);
|
|
443
|
+
return this.http.post("/api/addresses/validate", {
|
|
444
|
+
name: a.name,
|
|
445
|
+
line1: a.addressLine1,
|
|
446
|
+
line2: a.addressLine2,
|
|
447
|
+
city: a.city,
|
|
448
|
+
state: a.stateProvince,
|
|
449
|
+
postalCode: a.postalCode,
|
|
450
|
+
country: a.countryCode ?? "US"
|
|
451
|
+
});
|
|
384
452
|
}
|
|
385
|
-
// -----------------------------------------------------------------------
|
|
386
|
-
// Batch Labels
|
|
387
|
-
// -----------------------------------------------------------------------
|
|
388
|
-
/** Create labels in batch. */
|
|
389
453
|
async createBatch(request) {
|
|
390
454
|
return this.http.post(this.wsPath("labels/batch"), request);
|
|
391
455
|
}
|
|
392
|
-
/** Preview a batch without purchasing (dry-run). */
|
|
393
456
|
async previewBatch(request) {
|
|
394
457
|
return this.http.post(this.wsPath("labels/batch/preview"), request);
|
|
395
458
|
}
|
|
@@ -424,12 +487,55 @@ var ShippingResource = class {
|
|
|
424
487
|
return this.http.get("/api/shipping/savings");
|
|
425
488
|
}
|
|
426
489
|
};
|
|
490
|
+
function unsupported(message) {
|
|
491
|
+
return new FlexOpsError(message, 400, "UnsupportedRequestShape");
|
|
492
|
+
}
|
|
493
|
+
function toShippingAddress(address) {
|
|
494
|
+
if (!("street1" in address)) return address;
|
|
495
|
+
return {
|
|
496
|
+
name: address.name,
|
|
497
|
+
company: address.company,
|
|
498
|
+
addressLine1: address.street1,
|
|
499
|
+
addressLine2: address.street2,
|
|
500
|
+
city: address.city,
|
|
501
|
+
stateProvince: address.state,
|
|
502
|
+
postalCode: address.zip,
|
|
503
|
+
countryCode: address.country,
|
|
504
|
+
phone: address.phone,
|
|
505
|
+
email: address.email
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function toRateWire(request) {
|
|
509
|
+
if ("fromZip" in request)
|
|
510
|
+
throw unsupported("The Gateway needs full origin and destination addresses. Use origin, destination and package.");
|
|
511
|
+
return request;
|
|
512
|
+
}
|
|
513
|
+
function isLegacyLabelRequest(request) {
|
|
514
|
+
return "fromAddress" in request && !("origin" in request);
|
|
515
|
+
}
|
|
516
|
+
function toLabelWire(request) {
|
|
517
|
+
if (!isLegacyLabelRequest(request)) return { body: request };
|
|
518
|
+
if (request.returnLabel)
|
|
519
|
+
throw unsupported("createLabel cannot buy return labels. Use the returns API.");
|
|
520
|
+
const body = {
|
|
521
|
+
carrierCode: request.carrier,
|
|
522
|
+
serviceCode: request.service,
|
|
523
|
+
origin: toShippingAddress(request.fromAddress),
|
|
524
|
+
destination: toShippingAddress(request.toAddress),
|
|
525
|
+
package: { ...request.parcel },
|
|
526
|
+
labelFormat: request.labelFormat,
|
|
527
|
+
orderId: request.orderId,
|
|
528
|
+
hazmatClassification: request.hazmatClassification
|
|
529
|
+
};
|
|
530
|
+
return { body, idempotencyKey: request.idempotencyKey };
|
|
531
|
+
}
|
|
427
532
|
|
|
428
533
|
// src/resources/carriers.ts
|
|
429
534
|
var CarriersResource = class {
|
|
430
535
|
constructor(http) {
|
|
431
536
|
this.http = http;
|
|
432
537
|
}
|
|
538
|
+
http;
|
|
433
539
|
proxy(path) {
|
|
434
540
|
return `/api/ApiProxy/${path.replace(/^\//, "")}`;
|
|
435
541
|
}
|
|
@@ -443,38 +549,94 @@ var CarriersResource = class {
|
|
|
443
549
|
cityStateLookup: (zipCode) => this.http.get(this.proxy("api/v3/AddressValidation/getUspsCityStateLookupByZipCode"), { zipCode }),
|
|
444
550
|
/** ZIP code lookup by address. */
|
|
445
551
|
zipCodeLookup: (params) => this.http.get(this.proxy("api/v3/AddressValidation/getUspsZipCodeLookupByAddress"), params),
|
|
446
|
-
/**
|
|
552
|
+
/**
|
|
553
|
+
* Search domestic shipping rates.
|
|
554
|
+
*
|
|
555
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
556
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
557
|
+
* cover this.
|
|
558
|
+
*/
|
|
447
559
|
getDomesticRates: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchDomesticBaseRates"), body),
|
|
448
|
-
/**
|
|
560
|
+
/**
|
|
561
|
+
* Search domestic product eligibility.
|
|
562
|
+
*
|
|
563
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
564
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
565
|
+
* cover this.
|
|
566
|
+
*/
|
|
449
567
|
getDomesticProducts: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchEligibleDomesticProducts"), body),
|
|
450
|
-
/**
|
|
568
|
+
/**
|
|
569
|
+
* Search domestic prices.
|
|
570
|
+
*
|
|
571
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
572
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
573
|
+
* cover this.
|
|
574
|
+
*/
|
|
451
575
|
getDomesticPrices: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchEligibleDomesticPrices"), body),
|
|
452
|
-
/**
|
|
576
|
+
/**
|
|
577
|
+
* Search international rates.
|
|
578
|
+
*
|
|
579
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
580
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
581
|
+
* cover this.
|
|
582
|
+
*/
|
|
453
583
|
getInternationalRates: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchInternationalBaseRates"), body),
|
|
454
|
-
/**
|
|
584
|
+
/**
|
|
585
|
+
* Search international prices.
|
|
586
|
+
*
|
|
587
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
588
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
589
|
+
* cover this.
|
|
590
|
+
*/
|
|
455
591
|
getInternationalPrices: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchEligibleInternationalPrices"), body),
|
|
456
592
|
/** Generate a domestic shipping label. */
|
|
457
593
|
// Domestic USPS labels go through the reliable order-based Gateway path
|
|
458
594
|
// (POST /api/shipping/labels): pass a LabelRequest body with carrierCode:'USPS'
|
|
459
595
|
// and orderId set — server-side order validation + atomic postage settlement.
|
|
460
596
|
createDomesticLabel: (body) => new ShippingResource(this.http, () => void 0).createLabel(body),
|
|
461
|
-
/**
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
597
|
+
/**
|
|
598
|
+
* Cancel a domestic label.
|
|
599
|
+
*
|
|
600
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
601
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
602
|
+
* cover this.
|
|
603
|
+
*/
|
|
466
604
|
cancelDomesticLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsDomesticShipmentLabel")),
|
|
467
|
-
/**
|
|
605
|
+
/**
|
|
606
|
+
* Cancel an international label.
|
|
607
|
+
*
|
|
608
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
609
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
610
|
+
* cover this.
|
|
611
|
+
*/
|
|
468
612
|
cancelInternationalLabel: () => this.http.delete(this.proxy("api/v3/Shipping/cancelUspsInternationalShipmentLabel")),
|
|
469
613
|
/** Get tracking summary. */
|
|
470
614
|
trackSummary: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingSummaryInformation"), params),
|
|
471
615
|
/** Get detailed tracking info. */
|
|
472
616
|
trackDetail: (params) => this.http.get(this.proxy("api/v3/Tracking/getUspsTrackingDetailInformation"), params),
|
|
473
|
-
/**
|
|
617
|
+
/**
|
|
618
|
+
* Schedule a carrier pickup.
|
|
619
|
+
*
|
|
620
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
621
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
622
|
+
* cover this.
|
|
623
|
+
*/
|
|
474
624
|
createPickup: (body) => this.http.post(this.proxy("api/v3/CarrierPickup/postUspsCreateCarrierPickupSchedule"), body),
|
|
475
|
-
/**
|
|
625
|
+
/**
|
|
626
|
+
* Cancel a pickup.
|
|
627
|
+
*
|
|
628
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
629
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
630
|
+
* cover this.
|
|
631
|
+
*/
|
|
476
632
|
cancelPickup: () => this.http.delete(this.proxy("api/v3/CarrierPickup/cancelUspsCarrierPickupSchedule")),
|
|
477
|
-
/**
|
|
633
|
+
/**
|
|
634
|
+
* Create a scan form.
|
|
635
|
+
*
|
|
636
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
637
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
638
|
+
* cover this.
|
|
639
|
+
*/
|
|
478
640
|
createScanForm: (body) => this.http.post(this.proxy("api/v3/ScanForm/postUspsCreateScanFormLabelShipment"), body),
|
|
479
641
|
/** Get delivery standards estimates. */
|
|
480
642
|
deliveryStandards: (params) => this.http.get(this.proxy("api/v3/ServiceStandards/getUspsGetDeliveryStandardsEstimates"), params),
|
|
@@ -487,77 +649,245 @@ var CarriersResource = class {
|
|
|
487
649
|
// UPS (V2 endpoints)
|
|
488
650
|
// -----------------------------------------------------------------------
|
|
489
651
|
ups = {
|
|
490
|
-
/**
|
|
652
|
+
/**
|
|
653
|
+
* Verify an address via UPS.
|
|
654
|
+
*
|
|
655
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
656
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
657
|
+
* cover this.
|
|
658
|
+
*/
|
|
491
659
|
validateAddress: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsVerifyAddress"), body),
|
|
492
|
-
/**
|
|
660
|
+
/**
|
|
661
|
+
* Get UPS rate quotes.
|
|
662
|
+
*
|
|
663
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
664
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
665
|
+
* cover this.
|
|
666
|
+
*/
|
|
493
667
|
getRates: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsRateCheck"), body),
|
|
494
|
-
/** Generate a UPS shipping label. */
|
|
495
|
-
createLabel: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/generateNewUpsShipLabel"), body),
|
|
496
668
|
/** Track a UPS shipment. */
|
|
497
669
|
track: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getSingleUpsTrackingDetail"), params),
|
|
498
|
-
/**
|
|
670
|
+
/**
|
|
671
|
+
* Create a UPS pickup.
|
|
672
|
+
*
|
|
673
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
674
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
675
|
+
* cover this.
|
|
676
|
+
*/
|
|
499
677
|
createPickup: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsCreatePickup"), body),
|
|
500
|
-
/**
|
|
678
|
+
/**
|
|
679
|
+
* Cancel a UPS pickup.
|
|
680
|
+
*
|
|
681
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
682
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
683
|
+
* cover this.
|
|
684
|
+
*/
|
|
501
685
|
cancelPickup: () => this.http.delete(this.proxy("api/v2/ShippingLabel/deleteUpsPickup")),
|
|
502
|
-
/**
|
|
686
|
+
/**
|
|
687
|
+
* Get UPS transit times.
|
|
688
|
+
*
|
|
689
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
690
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
691
|
+
* cover this.
|
|
692
|
+
*/
|
|
503
693
|
getTransitTimes: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsGetTransitTimes"), body),
|
|
504
|
-
/**
|
|
694
|
+
/**
|
|
695
|
+
* Get UPS landed cost quote (international).
|
|
696
|
+
*
|
|
697
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
698
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
699
|
+
* cover this.
|
|
700
|
+
*/
|
|
505
701
|
getLandedCost: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsGetLandedCostQuote"), body),
|
|
506
|
-
/**
|
|
702
|
+
/**
|
|
703
|
+
* Search UPS locations.
|
|
704
|
+
*
|
|
705
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
706
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
707
|
+
* cover this.
|
|
708
|
+
*/
|
|
507
709
|
searchLocations: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsSearchLocations"), body),
|
|
508
|
-
/**
|
|
710
|
+
/**
|
|
711
|
+
* Upload paperless trade document.
|
|
712
|
+
*
|
|
713
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
714
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
715
|
+
* cover this.
|
|
716
|
+
*/
|
|
509
717
|
uploadDocument: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsUploadPaperlessDocument"), body),
|
|
510
|
-
/**
|
|
718
|
+
/**
|
|
719
|
+
* Create UPS freight shipment.
|
|
720
|
+
*
|
|
721
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
722
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
723
|
+
* cover this.
|
|
724
|
+
*/
|
|
511
725
|
createFreightShipment: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsCreateFreightShipment"), body),
|
|
512
|
-
/**
|
|
726
|
+
/**
|
|
727
|
+
* Get UPS freight rate.
|
|
728
|
+
*
|
|
729
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
730
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
731
|
+
* cover this.
|
|
732
|
+
*/
|
|
513
733
|
getFreightRate: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postUpsGetFreightRate"), body)
|
|
514
734
|
};
|
|
515
735
|
// -----------------------------------------------------------------------
|
|
516
736
|
// FedEx (V3 endpoints)
|
|
517
737
|
// -----------------------------------------------------------------------
|
|
518
738
|
fedex = {
|
|
519
|
-
/**
|
|
739
|
+
/**
|
|
740
|
+
* Validate a domestic address via FedEx.
|
|
741
|
+
*
|
|
742
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
743
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
744
|
+
* cover this.
|
|
745
|
+
*/
|
|
520
746
|
validateAddress: (body) => this.http.post(this.proxy("api/v3/AddressValidation/postFedExValidateAndCorrectDomesticAddress"), body),
|
|
521
|
-
/**
|
|
747
|
+
/**
|
|
748
|
+
* Validate a postal code.
|
|
749
|
+
*
|
|
750
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
751
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
752
|
+
* cover this.
|
|
753
|
+
*/
|
|
522
754
|
validatePostalCode: (body) => this.http.post(this.proxy("api/v3/AddressValidation/postFedExValidatePostalCode"), body),
|
|
523
|
-
/**
|
|
755
|
+
/**
|
|
756
|
+
* Get FedEx rate and transit times.
|
|
757
|
+
*
|
|
758
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
759
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
760
|
+
* cover this.
|
|
761
|
+
*/
|
|
524
762
|
getRates: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postRetrieveFedExRateAndTransitTimesAsync"), body),
|
|
525
|
-
/**
|
|
526
|
-
|
|
527
|
-
|
|
763
|
+
/**
|
|
764
|
+
* Cancel a FedEx shipment.
|
|
765
|
+
*
|
|
766
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
767
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
768
|
+
* cover this.
|
|
769
|
+
*/
|
|
528
770
|
cancelShipment: (body) => this.http.put(this.proxy("api/v3/Shipping/putFedExCancelShipment"), body),
|
|
529
|
-
/**
|
|
771
|
+
/**
|
|
772
|
+
* Validate a shipment (dry run).
|
|
773
|
+
*
|
|
774
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
775
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
776
|
+
* cover this.
|
|
777
|
+
*/
|
|
530
778
|
validateShipment: (body) => this.http.post(this.proxy("api/v3/Shipping/postFedExValidateShipment"), body),
|
|
531
|
-
/**
|
|
532
|
-
|
|
533
|
-
|
|
779
|
+
/**
|
|
780
|
+
* Track by tracking number.
|
|
781
|
+
*
|
|
782
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
783
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
784
|
+
* cover this.
|
|
785
|
+
*/
|
|
534
786
|
track: (body) => this.http.post(this.proxy("api/v3/Tracking/postFedExRetrieveTrackingInfoByTrackingNumber"), body),
|
|
535
|
-
/**
|
|
787
|
+
/**
|
|
788
|
+
* Track multi-piece shipment.
|
|
789
|
+
*
|
|
790
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
791
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
792
|
+
* cover this.
|
|
793
|
+
*/
|
|
536
794
|
trackMultiPiece: (body) => this.http.post(this.proxy("api/v3/Tracking/postFedExRetrieveTrackingInfoForMultiPieceShipment"), body),
|
|
537
|
-
/**
|
|
795
|
+
/**
|
|
796
|
+
* Register for tracking notifications.
|
|
797
|
+
*
|
|
798
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
799
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
800
|
+
* cover this.
|
|
801
|
+
*/
|
|
538
802
|
registerTrackingNotification: (body) => this.http.post(this.proxy("api/v3/Tracking/postFedExRegisterForTrackingNotification"), body),
|
|
539
|
-
/**
|
|
803
|
+
/**
|
|
804
|
+
* Create a carrier pickup.
|
|
805
|
+
*
|
|
806
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
807
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
808
|
+
* cover this.
|
|
809
|
+
*/
|
|
540
810
|
createPickup: (body) => this.http.post(this.proxy("api/v3/CarrierPickup/postFedExCreateCarrierPickupRequest"), body),
|
|
541
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
* Cancel a pickup.
|
|
813
|
+
*
|
|
814
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
815
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
816
|
+
* cover this.
|
|
817
|
+
*/
|
|
542
818
|
cancelPickup: (body) => this.http.put(this.proxy("api/v3/CarrierPickup/putFedExCancelCarrierPickupRequest"), body),
|
|
543
|
-
/**
|
|
819
|
+
/**
|
|
820
|
+
* Search valid locations.
|
|
821
|
+
*
|
|
822
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
823
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
824
|
+
* cover this.
|
|
825
|
+
*/
|
|
544
826
|
searchLocations: (body) => this.http.post(this.proxy("api/v3/LocationSearch/postFedExSearchValidLocations"), body),
|
|
545
|
-
/**
|
|
827
|
+
/**
|
|
828
|
+
* Get service standards and transit times.
|
|
829
|
+
*
|
|
830
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
831
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
832
|
+
* cover this.
|
|
833
|
+
*/
|
|
546
834
|
getServiceStandards: (body) => this.http.post(this.proxy("api/v3/ServiceStandards/postFedExRetrieveServicesAndTransitTimes"), body),
|
|
547
|
-
/**
|
|
835
|
+
/**
|
|
836
|
+
* Get freight rate quote.
|
|
837
|
+
*
|
|
838
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
839
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
840
|
+
* cover this.
|
|
841
|
+
*/
|
|
548
842
|
getFreightRate: (body) => this.http.post(this.proxy("api/v3/Freight/postFedExGetFreightRateQuote"), body),
|
|
549
|
-
/**
|
|
843
|
+
/**
|
|
844
|
+
* Create freight shipment.
|
|
845
|
+
*
|
|
846
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
847
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
848
|
+
* cover this.
|
|
849
|
+
*/
|
|
550
850
|
createFreightShipment: (body) => this.http.post(this.proxy("api/v3/Freight/postFedExCreateFreightShipment"), body),
|
|
551
|
-
/**
|
|
851
|
+
/**
|
|
852
|
+
* Ground close with documents.
|
|
853
|
+
*
|
|
854
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
855
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
856
|
+
* cover this.
|
|
857
|
+
*/
|
|
552
858
|
groundClose: (body) => this.http.post(this.proxy("api/v3/GroundClose/postFedExCloseWithDocuments"), body),
|
|
553
|
-
/**
|
|
859
|
+
/**
|
|
860
|
+
* Upload trade documents.
|
|
861
|
+
*
|
|
862
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
863
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
864
|
+
* cover this.
|
|
865
|
+
*/
|
|
554
866
|
uploadTradeDocuments: (body) => this.http.post(this.proxy("api/v3/Trade/postFedExUploadTradeDocuments"), body),
|
|
555
867
|
// --- Open Ship (multi-package) ---
|
|
556
|
-
/**
|
|
868
|
+
/**
|
|
869
|
+
* Create an open shipment.
|
|
870
|
+
*
|
|
871
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
872
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
873
|
+
* cover this.
|
|
874
|
+
*/
|
|
557
875
|
createOpenShipment: (body) => this.http.post(this.proxy("api/v3/OpenShip/postFedExCreateOpenShipment"), body),
|
|
558
|
-
/**
|
|
876
|
+
/**
|
|
877
|
+
* Add packages to an open shipment.
|
|
878
|
+
*
|
|
879
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
880
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
881
|
+
* cover this.
|
|
882
|
+
*/
|
|
559
883
|
addPackagesToOpenShipment: (body) => this.http.post(this.proxy("api/v3/OpenShip/postFedExAddPackagesToOpenShipment"), body),
|
|
560
|
-
/**
|
|
884
|
+
/**
|
|
885
|
+
* Confirm and finalize an open shipment.
|
|
886
|
+
*
|
|
887
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
888
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
889
|
+
* cover this.
|
|
890
|
+
*/
|
|
561
891
|
confirmOpenShipment: (body) => this.http.post(this.proxy("api/v3/OpenShip/postFedExConfirmOpenShipment"), body)
|
|
562
892
|
};
|
|
563
893
|
// -----------------------------------------------------------------------
|
|
@@ -568,27 +898,59 @@ var CarriersResource = class {
|
|
|
568
898
|
validateAddress: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlValidateAddress"), params),
|
|
569
899
|
/** Get DHL shipping rates. */
|
|
570
900
|
getRates: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlRates"), params),
|
|
571
|
-
/**
|
|
901
|
+
/**
|
|
902
|
+
* Get multi-piece rates.
|
|
903
|
+
*
|
|
904
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
905
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
906
|
+
* cover this.
|
|
907
|
+
*/
|
|
572
908
|
getMultiPieceRates: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlMultiPieceRates"), body),
|
|
573
909
|
/** Get DHL products/services. */
|
|
574
910
|
getProducts: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlProducts"), params),
|
|
575
|
-
/** Create a DHL shipment (label). */
|
|
576
|
-
createShipment: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlCreateShipment"), body),
|
|
577
911
|
/** Track a DHL shipment. */
|
|
578
912
|
track: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlTrackSingleShipment"), params),
|
|
579
913
|
/** Track multiple DHL shipments. */
|
|
580
914
|
trackMultiple: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlTrackMultipleShipments"), params),
|
|
581
|
-
/**
|
|
915
|
+
/**
|
|
916
|
+
* Create a DHL pickup.
|
|
917
|
+
*
|
|
918
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
919
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
920
|
+
* cover this.
|
|
921
|
+
*/
|
|
582
922
|
createPickup: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlCreatePickup"), body),
|
|
583
|
-
/**
|
|
584
|
-
|
|
585
|
-
|
|
923
|
+
/**
|
|
924
|
+
* Cancel a DHL pickup.
|
|
925
|
+
*
|
|
926
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
927
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
928
|
+
* cover this.
|
|
929
|
+
*/
|
|
586
930
|
cancelPickup: () => this.http.delete(this.proxy("api/v2/ShippingLabel/deleteDhlPickup")),
|
|
587
|
-
/**
|
|
931
|
+
/**
|
|
932
|
+
* Calculate landed cost (duties/taxes).
|
|
933
|
+
*
|
|
934
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
935
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
936
|
+
* cover this.
|
|
937
|
+
*/
|
|
588
938
|
calculateLandedCost: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlCalculateLandedCost"), body),
|
|
589
|
-
/**
|
|
939
|
+
/**
|
|
940
|
+
* Screen a shipment for compliance.
|
|
941
|
+
*
|
|
942
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
943
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
944
|
+
* cover this.
|
|
945
|
+
*/
|
|
590
946
|
screenShipment: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlScreenShipment"), body),
|
|
591
|
-
/**
|
|
947
|
+
/**
|
|
948
|
+
* Upload an invoice.
|
|
949
|
+
*
|
|
950
|
+
* @deprecated Legacy carrier proxy (sunset 2027-06-30). Needs a user token: API keys get 403
|
|
951
|
+
* `API_KEY_SCOPE_REQUIRED`. Use `client.shipping` / `client.pickups` / `client.scanForms` where they
|
|
952
|
+
* cover this.
|
|
953
|
+
*/
|
|
592
954
|
uploadInvoice: (body) => this.http.post(this.proxy("api/v2/ShippingLabel/postDhlUploadInvoice"), body),
|
|
593
955
|
/** Get electronic proof of delivery. */
|
|
594
956
|
getProofOfDelivery: (params) => this.http.get(this.proxy("api/v2/ShippingLabel/getDhlElectronicProofOfDelivery"), params),
|
|
@@ -605,6 +967,8 @@ var WebhooksResource = class {
|
|
|
605
967
|
this.http = http;
|
|
606
968
|
this.getWorkspaceId = getWorkspaceId;
|
|
607
969
|
}
|
|
970
|
+
http;
|
|
971
|
+
getWorkspaceId;
|
|
608
972
|
wsPath(suffix) {
|
|
609
973
|
const id = this.getWorkspaceId();
|
|
610
974
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -614,21 +978,25 @@ var WebhooksResource = class {
|
|
|
614
978
|
async list() {
|
|
615
979
|
return this.http.get(this.wsPath(""));
|
|
616
980
|
}
|
|
617
|
-
/**
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
981
|
+
/**
|
|
982
|
+
* Create a webhook subscription. `events` is sent as the Gateway's comma-separated `eventTypes`;
|
|
983
|
+
* omit it to receive every event. The result's `data.secret` is the signing secret, returned only here.
|
|
984
|
+
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
985
|
+
*/
|
|
622
986
|
async create(request) {
|
|
623
|
-
|
|
987
|
+
const body = await this.http.post(this.wsPath(""), toWireRequest(request));
|
|
988
|
+
return toEnvelope(body);
|
|
624
989
|
}
|
|
625
|
-
/**
|
|
990
|
+
/**
|
|
991
|
+
* Update a webhook subscription. `events`, when given, replaces the subscribed events.
|
|
992
|
+
* @throws FlexOpsError (`UnknownWebhookEvent`) when `events` is empty or names an event FlexOps does not send.
|
|
993
|
+
*/
|
|
626
994
|
async update(webhookId, data) {
|
|
627
|
-
return this.http.put(this.wsPath(webhookId), data);
|
|
995
|
+
return this.http.put(this.wsPath(webhookId), toWireRequest(data));
|
|
628
996
|
}
|
|
629
|
-
/** Delete a webhook subscription. */
|
|
997
|
+
/** Delete a webhook subscription. The Gateway answers 204 No Content, so there is no result. */
|
|
630
998
|
async delete(webhookId) {
|
|
631
|
-
|
|
999
|
+
await this.http.delete(this.wsPath(webhookId));
|
|
632
1000
|
}
|
|
633
1001
|
/** Rotate the signing secret for a webhook. */
|
|
634
1002
|
async rotateSecret(webhookId) {
|
|
@@ -638,23 +1006,80 @@ var WebhooksResource = class {
|
|
|
638
1006
|
async listDeliveryLogs(webhookId) {
|
|
639
1007
|
return this.http.get(this.wsPath(`${webhookId}/deliveries`));
|
|
640
1008
|
}
|
|
1009
|
+
/** Send a test event to a webhook's endpoint. */
|
|
1010
|
+
async test(webhookId) {
|
|
1011
|
+
return this.http.post(this.wsPath(`${webhookId}/test`));
|
|
1012
|
+
}
|
|
641
1013
|
/**
|
|
642
|
-
* Verify
|
|
643
|
-
*
|
|
1014
|
+
* Verify that an incoming request is a genuine FlexOps webhook delivery.
|
|
1015
|
+
*
|
|
1016
|
+
* FlexOps signs `{X-FlexOps-Timestamp}.{raw body}` with HMAC-SHA256, keyed with the
|
|
1017
|
+
* subscription secret (the whole `whsec_...` string), and sends
|
|
1018
|
+
* `X-FlexOps-Signature: sha256=<lowercase hex>`.
|
|
1019
|
+
*
|
|
1020
|
+
* @param payload The raw request body exactly as received (string or bytes). Do not pass
|
|
1021
|
+
* re-serialized JSON: `JSON.stringify(req.body)` will not reproduce the signed bytes.
|
|
1022
|
+
* @param signature The `X-FlexOps-Signature` header. `sha256=<hex>` and bare `<hex>` are accepted.
|
|
1023
|
+
* @param secret The subscription signing secret.
|
|
1024
|
+
* @param timestamp The `X-FlexOps-Timestamp` header (Unix seconds).
|
|
1025
|
+
* @param options `toleranceSeconds` (default 300) bounds how far the timestamp may be from now
|
|
1026
|
+
* in either direction; `now` (Unix seconds) overrides the clock, for tests.
|
|
1027
|
+
* @returns `true` only when the signature matches and the timestamp is within tolerance.
|
|
1028
|
+
* @throws TypeError when `secret` is empty or `payload` is not a string or bytes.
|
|
644
1029
|
*/
|
|
645
|
-
static verifySignature(payload, signature, secret) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
Buffer.from(expected, "hex")
|
|
652
|
-
);
|
|
653
|
-
} catch {
|
|
654
|
-
return false;
|
|
1030
|
+
static verifySignature(payload, signature, secret, timestamp, options = {}) {
|
|
1031
|
+
if (typeof secret !== "string" || secret.length === 0) {
|
|
1032
|
+
throw new TypeError("A webhook signing secret is required.");
|
|
1033
|
+
}
|
|
1034
|
+
if (typeof payload !== "string" && !(payload instanceof Uint8Array)) {
|
|
1035
|
+
throw new TypeError("payload must be the raw request body as a string or bytes.");
|
|
655
1036
|
}
|
|
1037
|
+
const toleranceSeconds = options.toleranceSeconds ?? DEFAULT_TOLERANCE_SECONDS;
|
|
1038
|
+
if (!Number.isFinite(toleranceSeconds) || toleranceSeconds < 0) {
|
|
1039
|
+
throw new TypeError("toleranceSeconds must be a non-negative number.");
|
|
1040
|
+
}
|
|
1041
|
+
if (typeof signature !== "string" || typeof timestamp !== "string") return false;
|
|
1042
|
+
const ts = timestamp.trim();
|
|
1043
|
+
if (!/^[0-9]+$/.test(ts)) return false;
|
|
1044
|
+
const now = options.now ?? Date.now() / 1e3;
|
|
1045
|
+
if (!(Math.abs(now - Number(ts)) <= toleranceSeconds)) return false;
|
|
1046
|
+
let hex = signature.trim();
|
|
1047
|
+
if (hex.slice(0, SIGNATURE_PREFIX.length).toLowerCase() === SIGNATURE_PREFIX) {
|
|
1048
|
+
hex = hex.slice(SIGNATURE_PREFIX.length);
|
|
1049
|
+
}
|
|
1050
|
+
hex = hex.toLowerCase();
|
|
1051
|
+
if (!/^[0-9a-f]{64}$/.test(hex)) return false;
|
|
1052
|
+
const crypto = loadNodeCrypto("Webhook signature verification");
|
|
1053
|
+
const expected = crypto.createHmac("sha256", secret).update(`${ts}.`, "utf8").update(payload).digest();
|
|
1054
|
+
return crypto.timingSafeEqual(Buffer.from(hex, "hex"), expected);
|
|
656
1055
|
}
|
|
657
1056
|
};
|
|
1057
|
+
var DEFAULT_TOLERANCE_SECONDS = 300;
|
|
1058
|
+
var SIGNATURE_PREFIX = "sha256=";
|
|
1059
|
+
var KNOWN_EVENTS = new Set(Object.values(WebhookEventType));
|
|
1060
|
+
function toWireRequest(request) {
|
|
1061
|
+
const { events, ...rest } = request;
|
|
1062
|
+
if (events === void 0) return rest;
|
|
1063
|
+
if (!Array.isArray(events) || events.length === 0) {
|
|
1064
|
+
throw new FlexOpsError("events must name at least one event; omit it to receive every event.", 400, "UnknownWebhookEvent");
|
|
1065
|
+
}
|
|
1066
|
+
const unknown = events.filter((name) => !KNOWN_EVENTS.has(name));
|
|
1067
|
+
if (unknown.length > 0) {
|
|
1068
|
+
throw new FlexOpsError(
|
|
1069
|
+
`Unknown webhook event: ${unknown.join(", ")}. FlexOps sends ${[...KNOWN_EVENTS].join(", ")}.`,
|
|
1070
|
+
400,
|
|
1071
|
+
"UnknownWebhookEvent"
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
return { ...rest, eventTypes: [...new Set(events)].join(",") };
|
|
1075
|
+
}
|
|
1076
|
+
function toEnvelope(body) {
|
|
1077
|
+
if (isObject(body) && isObject(body.data)) return body;
|
|
1078
|
+
return { success: true, data: body };
|
|
1079
|
+
}
|
|
1080
|
+
function isObject(value) {
|
|
1081
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1082
|
+
}
|
|
658
1083
|
|
|
659
1084
|
// src/resources/wallet.ts
|
|
660
1085
|
var WalletResource = class {
|
|
@@ -662,29 +1087,13 @@ var WalletResource = class {
|
|
|
662
1087
|
this.http = http;
|
|
663
1088
|
this.getWorkspaceId = getWorkspaceId;
|
|
664
1089
|
}
|
|
665
|
-
|
|
1090
|
+
http;
|
|
1091
|
+
getWorkspaceId;
|
|
1092
|
+
/** Get the configured workspace's wallet balance. */
|
|
1093
|
+
async getBalance() {
|
|
666
1094
|
const id = this.getWorkspaceId();
|
|
667
1095
|
if (!id) throw new Error("workspaceId is required.");
|
|
668
|
-
return
|
|
669
|
-
}
|
|
670
|
-
/** Get the current wallet balance. */
|
|
671
|
-
async getBalance() {
|
|
672
|
-
return this.http.get(this.wsPath("balance"));
|
|
673
|
-
}
|
|
674
|
-
/** Add funds to the wallet. */
|
|
675
|
-
async addFunds(amount) {
|
|
676
|
-
return this.http.post(this.wsPath("add-funds"), { amount });
|
|
677
|
-
}
|
|
678
|
-
/** List wallet transactions. */
|
|
679
|
-
async listTransactions(query) {
|
|
680
|
-
return this.http.get(
|
|
681
|
-
this.wsPath("transactions"),
|
|
682
|
-
query
|
|
683
|
-
);
|
|
684
|
-
}
|
|
685
|
-
/** Configure auto-reload settings. */
|
|
686
|
-
async configureAutoReload(config) {
|
|
687
|
-
return this.http.put(this.wsPath("auto-reload"), config);
|
|
1096
|
+
return this.http.request("GET", "/api/wallet/my-balance", { headers: { "X-Workspace-Id": id } });
|
|
688
1097
|
}
|
|
689
1098
|
};
|
|
690
1099
|
|
|
@@ -694,6 +1103,8 @@ var InsuranceResource = class {
|
|
|
694
1103
|
this.http = http;
|
|
695
1104
|
this.getWorkspaceId = getWorkspaceId;
|
|
696
1105
|
}
|
|
1106
|
+
http;
|
|
1107
|
+
getWorkspaceId;
|
|
697
1108
|
wsPath(suffix) {
|
|
698
1109
|
const id = this.getWorkspaceId();
|
|
699
1110
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -707,17 +1118,27 @@ var InsuranceResource = class {
|
|
|
707
1118
|
async getQuote(request) {
|
|
708
1119
|
return this.http.post(this.wsPath("quote"), request);
|
|
709
1120
|
}
|
|
710
|
-
/**
|
|
711
|
-
|
|
712
|
-
|
|
1121
|
+
/**
|
|
1122
|
+
* Purchase insurance for a shipment. The premium is charged to the workspace wallet. A shipment
|
|
1123
|
+
* that already has a policy in force is refused with 409 `ALREADY_EXISTS`.
|
|
1124
|
+
*
|
|
1125
|
+
* Pass an `idempotencyKey` you store with the purchase to make your own retry safe: after an error or
|
|
1126
|
+
* a timeout, retry with the same key and the Gateway returns the first result instead of buying again.
|
|
1127
|
+
* Without one, the SDK's own retries still share a key, but a new call gets a new key.
|
|
1128
|
+
*/
|
|
1129
|
+
async purchase(request, idempotencyKey) {
|
|
1130
|
+
return this.http.request("POST", this.wsPath("policies"), {
|
|
1131
|
+
body: request,
|
|
1132
|
+
headers: idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0
|
|
1133
|
+
});
|
|
713
1134
|
}
|
|
714
|
-
/** Void an insurance policy. */
|
|
1135
|
+
/** Void (cancel) an insurance policy. */
|
|
715
1136
|
async void(policyId) {
|
|
716
1137
|
return this.http.delete(this.wsPath(`policies/${policyId}`));
|
|
717
1138
|
}
|
|
718
|
-
/** File
|
|
719
|
-
async fileClaim(
|
|
720
|
-
return this.http.post(this.wsPath(
|
|
1139
|
+
/** File a claim against a policy. */
|
|
1140
|
+
async fileClaim(claim) {
|
|
1141
|
+
return this.http.post(this.wsPath("claims"), claim);
|
|
721
1142
|
}
|
|
722
1143
|
};
|
|
723
1144
|
|
|
@@ -727,12 +1148,14 @@ var ReturnsResource = class {
|
|
|
727
1148
|
this.http = http;
|
|
728
1149
|
this.getWorkspaceId = getWorkspaceId;
|
|
729
1150
|
}
|
|
1151
|
+
http;
|
|
1152
|
+
getWorkspaceId;
|
|
730
1153
|
wsPath(suffix) {
|
|
731
1154
|
const id = this.getWorkspaceId();
|
|
732
1155
|
if (!id) throw new Error("workspaceId is required.");
|
|
733
|
-
return `/api/workspaces/${id}/returns
|
|
1156
|
+
return `/api/workspaces/${id}/returns${suffix ? `/${suffix}` : ""}`;
|
|
734
1157
|
}
|
|
735
|
-
/** List
|
|
1158
|
+
/** List return authorizations, optionally created between `startDate` and `endDate` (ISO 8601). */
|
|
736
1159
|
async list(query) {
|
|
737
1160
|
return this.http.get(
|
|
738
1161
|
this.wsPath(""),
|
|
@@ -743,62 +1166,24 @@ var ReturnsResource = class {
|
|
|
743
1166
|
async get(returnId) {
|
|
744
1167
|
return this.http.get(this.wsPath(returnId));
|
|
745
1168
|
}
|
|
746
|
-
/** Create a return authorization (RMA). */
|
|
1169
|
+
/** Create a return authorization (RMA) for an order. */
|
|
747
1170
|
async create(request) {
|
|
748
|
-
return this.http.post(this.wsPath(""), request);
|
|
749
|
-
}
|
|
750
|
-
/** Approve a return authorization. */
|
|
751
|
-
async approve(returnId) {
|
|
752
|
-
return this.http.post(this.wsPath(`${returnId}/approve`));
|
|
753
|
-
}
|
|
754
|
-
/** Reject a return authorization. */
|
|
755
|
-
async reject(returnId, reason) {
|
|
756
|
-
return this.http.post(this.wsPath(`${returnId}/reject`), { reason });
|
|
1171
|
+
return this.http.post(this.wsPath("rma"), request);
|
|
757
1172
|
}
|
|
758
|
-
/**
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
return this.http.post(this.wsPath(`${returnId}/receive`), { items });
|
|
769
|
-
}
|
|
770
|
-
/** Process refund for a return. */
|
|
771
|
-
async processRefund(returnId) {
|
|
772
|
-
return this.http.post(this.wsPath(`${returnId}/refund`));
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
// src/resources/api-keys.ts
|
|
777
|
-
var ApiKeysResource = class {
|
|
778
|
-
constructor(http, getWorkspaceId) {
|
|
779
|
-
this.http = http;
|
|
780
|
-
this.getWorkspaceId = getWorkspaceId;
|
|
781
|
-
}
|
|
782
|
-
wsPath(suffix) {
|
|
783
|
-
const id = this.getWorkspaceId();
|
|
784
|
-
if (!id) throw new Error("workspaceId is required.");
|
|
785
|
-
return `/api/workspaces/${id}/api-keys${suffix ? `/${suffix}` : ""}`;
|
|
786
|
-
}
|
|
787
|
-
/** List all API keys for the workspace. */
|
|
788
|
-
async list() {
|
|
789
|
-
return this.http.get(this.wsPath(""));
|
|
790
|
-
}
|
|
791
|
-
/** Create a new API key. The full key is only returned once. */
|
|
792
|
-
async create(request) {
|
|
793
|
-
return this.http.post(this.wsPath(""), request);
|
|
794
|
-
}
|
|
795
|
-
/** Revoke an API key. */
|
|
796
|
-
async revoke(keyId) {
|
|
797
|
-
return this.http.delete(this.wsPath(keyId));
|
|
1173
|
+
/**
|
|
1174
|
+
* Generate a return label for an approved RMA.
|
|
1175
|
+
*
|
|
1176
|
+
* The Gateway binds a required request body, so one is always sent (`{}` when `request` is
|
|
1177
|
+
* omitted). Pass `weightOz`, `lengthIn`, `widthIn` and `heightIn`: a workspace with no default
|
|
1178
|
+
* shipping preset has nothing else to take the package from and the call fails with a 400 that
|
|
1179
|
+
* names the missing fields.
|
|
1180
|
+
*/
|
|
1181
|
+
async generateLabel(rmaNumber, request = {}) {
|
|
1182
|
+
return this.http.post(this.wsPath(`${rmaNumber}/label`), request);
|
|
798
1183
|
}
|
|
799
|
-
/**
|
|
800
|
-
async
|
|
801
|
-
return this.http.post(this.wsPath(`${
|
|
1184
|
+
/** Record the inspected items of a returned package at a warehouse. */
|
|
1185
|
+
async markReceived(rmaId, request) {
|
|
1186
|
+
return this.http.post(this.wsPath(`${rmaId}/receive`), request);
|
|
802
1187
|
}
|
|
803
1188
|
};
|
|
804
1189
|
|
|
@@ -807,6 +1192,7 @@ var AnalyticsResource = class {
|
|
|
807
1192
|
constructor(http) {
|
|
808
1193
|
this.http = http;
|
|
809
1194
|
}
|
|
1195
|
+
http;
|
|
810
1196
|
path(endpoint) {
|
|
811
1197
|
return `/api/ApiProxy/api/v4/Analytics/${endpoint}`;
|
|
812
1198
|
}
|
|
@@ -877,13 +1263,10 @@ var OrdersResource = class {
|
|
|
877
1263
|
constructor(http) {
|
|
878
1264
|
this.http = http;
|
|
879
1265
|
}
|
|
1266
|
+
http;
|
|
880
1267
|
path(endpoint) {
|
|
881
1268
|
return `/api/ApiProxy/api/v1/Order/${endpoint}`;
|
|
882
1269
|
}
|
|
883
|
-
/** Create a new order. */
|
|
884
|
-
async create(order) {
|
|
885
|
-
return this.http.post(this.path("postNewOrder"), order);
|
|
886
|
-
}
|
|
887
1270
|
/** Get new orders awaiting processing. */
|
|
888
1271
|
async getNewOrders(params) {
|
|
889
1272
|
return this.http.get(this.path("getNewOrderList"), params);
|
|
@@ -904,10 +1287,6 @@ var OrdersResource = class {
|
|
|
904
1287
|
async getStatus(orderNumber) {
|
|
905
1288
|
return this.http.get(this.path("getIndividualOrderStatusByOrderNumber"), { orderNumber });
|
|
906
1289
|
}
|
|
907
|
-
/** Cancel an order. */
|
|
908
|
-
async cancel(orderNumber) {
|
|
909
|
-
return this.http.post(this.path("cancelOrderByOrderNumber"), { orderNumber });
|
|
910
|
-
}
|
|
911
1290
|
/** Get all items for an order. */
|
|
912
1291
|
async getItems(orderNumber) {
|
|
913
1292
|
return this.http.get(this.path("getAllOrderItemsByOrderNumber"), { orderNumber });
|
|
@@ -935,10 +1314,7 @@ var InventoryResource = class {
|
|
|
935
1314
|
constructor(http) {
|
|
936
1315
|
this.http = http;
|
|
937
1316
|
}
|
|
938
|
-
|
|
939
|
-
async postAsnReceipt(receipt) {
|
|
940
|
-
return this.http.post("/api/ApiProxy/api/v1/Inventory/postNewAsnReceipt", receipt);
|
|
941
|
-
}
|
|
1317
|
+
http;
|
|
942
1318
|
/** Get a warehouse inventory snapshot. */
|
|
943
1319
|
async getWarehouseSnapshot(params) {
|
|
944
1320
|
return this.http.get("/api/ApiProxy/api/v1/Inventory/getWarehouseInventorySnapshot", params);
|
|
@@ -951,10 +1327,6 @@ var InventoryResource = class {
|
|
|
951
1327
|
async getPartNumbers(params) {
|
|
952
1328
|
return this.http.get("/api/ApiProxy/api/v1/Inventory/getPartNumberList", params);
|
|
953
1329
|
}
|
|
954
|
-
/** Update customer inventory (V2). */
|
|
955
|
-
async updateInventory(data) {
|
|
956
|
-
return this.http.post("/api/ApiProxy/api/v2/Inventory/postCustomerInventoryUpdate", data);
|
|
957
|
-
}
|
|
958
1330
|
};
|
|
959
1331
|
|
|
960
1332
|
// src/resources/pickups.ts
|
|
@@ -963,6 +1335,8 @@ var PickupsResource = class {
|
|
|
963
1335
|
this.http = http;
|
|
964
1336
|
this.getWorkspaceId = getWorkspaceId;
|
|
965
1337
|
}
|
|
1338
|
+
http;
|
|
1339
|
+
getWorkspaceId;
|
|
966
1340
|
wsPath(suffix) {
|
|
967
1341
|
const id = this.getWorkspaceId();
|
|
968
1342
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -974,11 +1348,11 @@ var PickupsResource = class {
|
|
|
974
1348
|
}
|
|
975
1349
|
/** List scheduled pickups. */
|
|
976
1350
|
async list() {
|
|
977
|
-
return this.http.get(this.wsPath(""));
|
|
1351
|
+
return this.http.get(this.wsPath("scheduled"));
|
|
978
1352
|
}
|
|
979
|
-
/** Get pickup details. */
|
|
980
|
-
async get(pickupId) {
|
|
981
|
-
return this.http.get(this.wsPath(pickupId));
|
|
1353
|
+
/** Get pickup details. The carrier defaults to `usps` on the Gateway. */
|
|
1354
|
+
async get(pickupId, carrierCode) {
|
|
1355
|
+
return this.http.get(this.wsPath(pickupId), { carrierCode });
|
|
982
1356
|
}
|
|
983
1357
|
/** Cancel a scheduled pickup. */
|
|
984
1358
|
async cancel(pickupId) {
|
|
@@ -992,6 +1366,8 @@ var ScanFormsResource = class {
|
|
|
992
1366
|
this.http = http;
|
|
993
1367
|
this.getWorkspaceId = getWorkspaceId;
|
|
994
1368
|
}
|
|
1369
|
+
http;
|
|
1370
|
+
getWorkspaceId;
|
|
995
1371
|
wsPath(suffix) {
|
|
996
1372
|
const id = this.getWorkspaceId();
|
|
997
1373
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -1017,6 +1393,8 @@ var RulesResource = class {
|
|
|
1017
1393
|
this.http = http;
|
|
1018
1394
|
this.getWorkspaceId = getWorkspaceId;
|
|
1019
1395
|
}
|
|
1396
|
+
http;
|
|
1397
|
+
getWorkspaceId;
|
|
1020
1398
|
wsPath(suffix) {
|
|
1021
1399
|
const id = this.getWorkspaceId();
|
|
1022
1400
|
if (!id) throw new Error("workspaceId is required.");
|
|
@@ -1034,70 +1412,76 @@ var RulesResource = class {
|
|
|
1034
1412
|
async create(rule) {
|
|
1035
1413
|
return this.http.post(this.wsPath(""), rule);
|
|
1036
1414
|
}
|
|
1037
|
-
/**
|
|
1415
|
+
/** Replace a shipping rule. */
|
|
1038
1416
|
async update(ruleId, rule) {
|
|
1039
1417
|
return this.http.put(this.wsPath(ruleId), rule);
|
|
1040
1418
|
}
|
|
1041
|
-
/** Delete a shipping rule. */
|
|
1419
|
+
/** Delete a shipping rule. The Gateway answers 204 No Content, so there is no result. */
|
|
1042
1420
|
async delete(ruleId) {
|
|
1043
|
-
|
|
1421
|
+
await this.http.delete(this.wsPath(ruleId));
|
|
1044
1422
|
}
|
|
1045
|
-
/** Reorder rules (
|
|
1423
|
+
/** Reorder rules: each listed rule gets its position in `ruleIds` as its priority (0 first). */
|
|
1046
1424
|
async reorder(ruleIds) {
|
|
1047
|
-
return this.http.
|
|
1425
|
+
return this.http.post(this.wsPath("reorder"), {
|
|
1426
|
+
rules: ruleIds.map((ruleId, priority) => ({ ruleId, priority }))
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
/** Dry-run the workspace's rules against a sample shipment, without changing anything. */
|
|
1430
|
+
async test(request) {
|
|
1431
|
+
return this.http.post(this.wsPath("test"), { tags: [], ...request });
|
|
1048
1432
|
}
|
|
1049
1433
|
};
|
|
1050
1434
|
|
|
1051
|
-
// src/resources/offsets.ts
|
|
1052
|
-
var
|
|
1435
|
+
// src/resources/carbon-offsets.ts
|
|
1436
|
+
var CarbonOffsetsResource = class {
|
|
1053
1437
|
constructor(http, getWorkspaceId) {
|
|
1054
1438
|
this.http = http;
|
|
1055
1439
|
this.getWorkspaceId = getWorkspaceId;
|
|
1056
1440
|
}
|
|
1057
|
-
|
|
1441
|
+
http;
|
|
1442
|
+
getWorkspaceId;
|
|
1443
|
+
wsPath(suffix = "") {
|
|
1058
1444
|
const id = this.getWorkspaceId();
|
|
1059
1445
|
if (!id) throw new Error("workspaceId is required.");
|
|
1060
|
-
return `/api/workspaces/${id}
|
|
1446
|
+
return `/api/workspaces/${id}/carbon-offsets${suffix ? `/${suffix}` : ""}`;
|
|
1061
1447
|
}
|
|
1062
|
-
/**
|
|
1063
|
-
async
|
|
1064
|
-
return this.http.post(this.wsPath(
|
|
1448
|
+
/** Quote an offset for a shipment without buying it. */
|
|
1449
|
+
async quote(request) {
|
|
1450
|
+
return this.http.post(this.wsPath("quote"), request);
|
|
1065
1451
|
}
|
|
1066
|
-
/**
|
|
1067
|
-
|
|
1068
|
-
|
|
1452
|
+
/**
|
|
1453
|
+
* Buy an offset for a shipment. The cost is charged to the workspace wallet and refunded if the
|
|
1454
|
+
* offset provider fails.
|
|
1455
|
+
*
|
|
1456
|
+
* Pass an `idempotencyKey` you store with the purchase to make your own retry safe: after an error or
|
|
1457
|
+
* a timeout, retry with the same key and the Gateway returns the first result instead of buying again.
|
|
1458
|
+
* Without one, the SDK's own retries still share a key, but a new call gets a new key.
|
|
1459
|
+
*/
|
|
1460
|
+
async purchase(request, idempotencyKey) {
|
|
1461
|
+
return this.http.request("POST", this.wsPath("purchase"), {
|
|
1462
|
+
body: request,
|
|
1463
|
+
headers: idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0
|
|
1464
|
+
});
|
|
1069
1465
|
}
|
|
1070
|
-
/**
|
|
1071
|
-
async
|
|
1072
|
-
return this.http.
|
|
1466
|
+
/** List the workspace's offsets, newest first. */
|
|
1467
|
+
async list(query) {
|
|
1468
|
+
return this.http.get(this.wsPath(), query);
|
|
1073
1469
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
var HsCodesResource = class {
|
|
1078
|
-
constructor(http, getWorkspaceId) {
|
|
1079
|
-
this.http = http;
|
|
1080
|
-
this.getWorkspaceId = getWorkspaceId;
|
|
1470
|
+
/** Get one offset. */
|
|
1471
|
+
async get(offsetId) {
|
|
1472
|
+
return this.http.get(this.wsPath(offsetId));
|
|
1081
1473
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
return `/api/workspaces/${id}/${suffix}`;
|
|
1474
|
+
/** Totals across the workspace's offsets. */
|
|
1475
|
+
async getSummary() {
|
|
1476
|
+
return this.http.get(this.wsPath("summary"));
|
|
1086
1477
|
}
|
|
1087
|
-
/**
|
|
1088
|
-
async
|
|
1089
|
-
return this.http.get(this.wsPath("
|
|
1090
|
-
query,
|
|
1091
|
-
...options
|
|
1092
|
-
});
|
|
1478
|
+
/** Get the automatic-offset setting. */
|
|
1479
|
+
async getSettings() {
|
|
1480
|
+
return this.http.get(this.wsPath("settings"));
|
|
1093
1481
|
}
|
|
1094
|
-
/**
|
|
1095
|
-
async
|
|
1096
|
-
return this.http.
|
|
1097
|
-
}
|
|
1098
|
-
/** Estimate the total landed cost (duty + tax + shipping) for a shipment. Requires Enterprise plan. */
|
|
1099
|
-
async estimateLandedCost(request) {
|
|
1100
|
-
return this.http.post(this.wsPath("shipping/landed-cost"), request);
|
|
1482
|
+
/** Turn automatic offsets on or off. */
|
|
1483
|
+
async updateSettings(settings) {
|
|
1484
|
+
return this.http.put(this.wsPath("settings"), settings);
|
|
1101
1485
|
}
|
|
1102
1486
|
};
|
|
1103
1487
|
|
|
@@ -1107,115 +1491,143 @@ var RecurringShipmentsResource = class {
|
|
|
1107
1491
|
this.http = http;
|
|
1108
1492
|
this.getWorkspaceId = getWorkspaceId;
|
|
1109
1493
|
}
|
|
1110
|
-
|
|
1494
|
+
http;
|
|
1495
|
+
getWorkspaceId;
|
|
1496
|
+
wsPath(suffix = "") {
|
|
1111
1497
|
const id = this.getWorkspaceId();
|
|
1112
1498
|
if (!id) throw new Error("workspaceId is required.");
|
|
1113
|
-
return `/api/workspaces/${id}/recurring-shipments
|
|
1499
|
+
return `/api/workspaces/${id}/recurring-shipments${suffix ? `/${suffix}` : ""}`;
|
|
1114
1500
|
}
|
|
1115
|
-
/** List
|
|
1116
|
-
async list(
|
|
1117
|
-
return this.http.get(
|
|
1118
|
-
this.wsPath(""),
|
|
1119
|
-
query
|
|
1120
|
-
);
|
|
1501
|
+
/** List the workspace's recurring shipments. */
|
|
1502
|
+
async list() {
|
|
1503
|
+
return this.http.get(this.wsPath());
|
|
1121
1504
|
}
|
|
1122
|
-
/** Get
|
|
1505
|
+
/** Get one recurring shipment. */
|
|
1123
1506
|
async get(id) {
|
|
1124
1507
|
return this.http.get(this.wsPath(id));
|
|
1125
1508
|
}
|
|
1126
|
-
/** Create a recurring shipment
|
|
1509
|
+
/** Create a recurring shipment. The first run is at `firstRunUtc`. */
|
|
1127
1510
|
async create(request) {
|
|
1128
|
-
return this.http.post(this.wsPath(
|
|
1511
|
+
return this.http.post(this.wsPath(), request);
|
|
1129
1512
|
}
|
|
1130
|
-
/**
|
|
1513
|
+
/** Change a recurring shipment. Fields left out stay as they are. */
|
|
1131
1514
|
async update(id, request) {
|
|
1132
1515
|
return this.http.put(this.wsPath(id), request);
|
|
1133
1516
|
}
|
|
1134
|
-
/** Delete a recurring shipment
|
|
1517
|
+
/** Delete a recurring shipment. */
|
|
1135
1518
|
async delete(id) {
|
|
1136
|
-
|
|
1519
|
+
await this.http.delete(this.wsPath(id));
|
|
1137
1520
|
}
|
|
1138
|
-
/**
|
|
1521
|
+
/** Stop scheduled runs until `resume` is called. */
|
|
1139
1522
|
async pause(id) {
|
|
1140
|
-
|
|
1523
|
+
await this.http.post(this.wsPath(`${id}/pause`));
|
|
1141
1524
|
}
|
|
1142
|
-
/**
|
|
1525
|
+
/** Restart scheduled runs. */
|
|
1143
1526
|
async resume(id) {
|
|
1144
|
-
|
|
1527
|
+
await this.http.post(this.wsPath(`${id}/resume`));
|
|
1145
1528
|
}
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
|
|
1529
|
+
/**
|
|
1530
|
+
* Run a recurring shipment now, which creates an order. Pass your own `idempotencyKey` to make a
|
|
1531
|
+
* retry from your side safe too; the SDK's own retries always reuse one key.
|
|
1532
|
+
*/
|
|
1533
|
+
async trigger(id, idempotencyKey) {
|
|
1534
|
+
await this.http.request("POST", this.wsPath(`${id}/trigger`), {
|
|
1535
|
+
headers: idempotencyKey ? { "Idempotency-Key": idempotencyKey } : void 0
|
|
1536
|
+
});
|
|
1149
1537
|
}
|
|
1150
1538
|
};
|
|
1151
1539
|
|
|
1152
|
-
// src/resources/
|
|
1153
|
-
var
|
|
1540
|
+
// src/resources/report-schedules.ts
|
|
1541
|
+
var ReportSchedulesResource = class {
|
|
1154
1542
|
constructor(http, getWorkspaceId) {
|
|
1155
1543
|
this.http = http;
|
|
1156
1544
|
this.getWorkspaceId = getWorkspaceId;
|
|
1157
1545
|
}
|
|
1158
|
-
|
|
1546
|
+
http;
|
|
1547
|
+
getWorkspaceId;
|
|
1548
|
+
wsPath(suffix = "") {
|
|
1159
1549
|
const id = this.getWorkspaceId();
|
|
1160
1550
|
if (!id) throw new Error("workspaceId is required.");
|
|
1161
|
-
return `/api/workspaces/${id}/
|
|
1551
|
+
return `/api/workspaces/${id}/report-schedules${suffix ? `/${suffix}` : ""}`;
|
|
1162
1552
|
}
|
|
1163
|
-
/** List
|
|
1553
|
+
/** List the workspace's report schedules. */
|
|
1164
1554
|
async list() {
|
|
1165
|
-
return this.http.get(this.wsPath(
|
|
1555
|
+
return this.http.get(this.wsPath());
|
|
1166
1556
|
}
|
|
1167
|
-
/** Get
|
|
1557
|
+
/** Get one report schedule. */
|
|
1168
1558
|
async get(id) {
|
|
1169
1559
|
return this.http.get(this.wsPath(id));
|
|
1170
1560
|
}
|
|
1171
|
-
/** Create
|
|
1561
|
+
/** Create a report schedule. */
|
|
1172
1562
|
async create(request) {
|
|
1173
|
-
return this.http.post(this.wsPath(
|
|
1563
|
+
return this.http.post(this.wsPath(), request);
|
|
1174
1564
|
}
|
|
1175
|
-
/**
|
|
1565
|
+
/** Change a report schedule. Fields left out stay as they are. */
|
|
1176
1566
|
async update(id, request) {
|
|
1177
1567
|
return this.http.put(this.wsPath(id), request);
|
|
1178
1568
|
}
|
|
1179
|
-
/** Delete
|
|
1569
|
+
/** Delete a report schedule. */
|
|
1180
1570
|
async delete(id) {
|
|
1181
|
-
|
|
1571
|
+
await this.http.delete(this.wsPath(id));
|
|
1182
1572
|
}
|
|
1183
|
-
/**
|
|
1184
|
-
async
|
|
1185
|
-
return this.http.post(this.wsPath(`${id}/
|
|
1573
|
+
/** Turn a schedule on or off (flips `isEnabled`). */
|
|
1574
|
+
async toggle(id) {
|
|
1575
|
+
return this.http.post(this.wsPath(`${id}/toggle`));
|
|
1186
1576
|
}
|
|
1187
1577
|
};
|
|
1188
1578
|
|
|
1189
|
-
// src/resources/
|
|
1190
|
-
var
|
|
1579
|
+
// src/resources/email-templates.ts
|
|
1580
|
+
var EmailTemplatesResource = class {
|
|
1191
1581
|
constructor(http, getWorkspaceId) {
|
|
1192
1582
|
this.http = http;
|
|
1193
1583
|
this.getWorkspaceId = getWorkspaceId;
|
|
1194
1584
|
}
|
|
1195
|
-
|
|
1585
|
+
http;
|
|
1586
|
+
getWorkspaceId;
|
|
1587
|
+
wsPath(suffix = "") {
|
|
1196
1588
|
const id = this.getWorkspaceId();
|
|
1197
1589
|
if (!id) throw new Error("workspaceId is required.");
|
|
1198
|
-
return `/api/workspaces/${id}/
|
|
1590
|
+
return `/api/workspaces/${id}/email-templates${suffix ? `/${suffix}` : ""}`;
|
|
1199
1591
|
}
|
|
1200
|
-
/** List
|
|
1592
|
+
/** List the workspace's templates. */
|
|
1201
1593
|
async list() {
|
|
1202
|
-
return this.http.get(this.wsPath(
|
|
1594
|
+
return this.http.get(this.wsPath());
|
|
1203
1595
|
}
|
|
1204
|
-
/** Get
|
|
1205
|
-
async get(
|
|
1206
|
-
return this.http.get(this.wsPath(
|
|
1596
|
+
/** Get one template. */
|
|
1597
|
+
async get(templateId) {
|
|
1598
|
+
return this.http.get(this.wsPath(templateId));
|
|
1207
1599
|
}
|
|
1208
|
-
/** Create
|
|
1209
|
-
async
|
|
1210
|
-
return this.http.
|
|
1600
|
+
/** Create or replace the template for `request.eventType`. */
|
|
1601
|
+
async upsert(request) {
|
|
1602
|
+
return this.http.put(this.wsPath(), request);
|
|
1211
1603
|
}
|
|
1212
|
-
/**
|
|
1213
|
-
async
|
|
1214
|
-
|
|
1604
|
+
/** Delete a template; that event then uses the FlexOps default email. */
|
|
1605
|
+
async delete(templateId) {
|
|
1606
|
+
await this.http.delete(this.wsPath(templateId));
|
|
1215
1607
|
}
|
|
1216
|
-
/**
|
|
1217
|
-
async
|
|
1218
|
-
return this.http.
|
|
1608
|
+
/** Render a subject and body with sample shipment data, without saving anything. */
|
|
1609
|
+
async preview(request) {
|
|
1610
|
+
return this.http.post(this.wsPath("preview"), request);
|
|
1611
|
+
}
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// src/resources/hs-codes.ts
|
|
1615
|
+
var HsCodesResource = class {
|
|
1616
|
+
constructor(http) {
|
|
1617
|
+
this.http = http;
|
|
1618
|
+
}
|
|
1619
|
+
http;
|
|
1620
|
+
/** Search for HS codes by product description. Requires Enterprise plan. */
|
|
1621
|
+
async search(query, options) {
|
|
1622
|
+
return this.http.get("/api/shipping/hs-codes/search", { query, ...options });
|
|
1623
|
+
}
|
|
1624
|
+
/** Look up a specific HS code by its tariff number. Requires Enterprise plan. */
|
|
1625
|
+
async lookup(code) {
|
|
1626
|
+
return this.http.get(`/api/shipping/hs-codes/${encodeURIComponent(code)}`);
|
|
1627
|
+
}
|
|
1628
|
+
/** Estimate the total landed cost (duty + tax + shipping) for a shipment. Requires Enterprise plan. */
|
|
1629
|
+
async estimateLandedCost(request) {
|
|
1630
|
+
return this.http.post("/api/shipping/landed-cost", request);
|
|
1219
1631
|
}
|
|
1220
1632
|
};
|
|
1221
1633
|
|
|
@@ -1232,18 +1644,17 @@ var FlexOps = class {
|
|
|
1232
1644
|
wallet;
|
|
1233
1645
|
insurance;
|
|
1234
1646
|
returns;
|
|
1235
|
-
apiKeys;
|
|
1236
1647
|
analytics;
|
|
1237
1648
|
orders;
|
|
1238
1649
|
inventory;
|
|
1239
1650
|
pickups;
|
|
1240
1651
|
scanForms;
|
|
1241
1652
|
rules;
|
|
1242
|
-
|
|
1243
|
-
hsCodes;
|
|
1653
|
+
carbonOffsets;
|
|
1244
1654
|
recurringShipments;
|
|
1655
|
+
reportSchedules;
|
|
1245
1656
|
emailTemplates;
|
|
1246
|
-
|
|
1657
|
+
hsCodes;
|
|
1247
1658
|
constructor(config = {}) {
|
|
1248
1659
|
this.http = new HttpClient(config);
|
|
1249
1660
|
this._workspaceId = config.workspaceId;
|
|
@@ -1256,18 +1667,17 @@ var FlexOps = class {
|
|
|
1256
1667
|
this.wallet = new WalletResource(this.http, getWsId);
|
|
1257
1668
|
this.insurance = new InsuranceResource(this.http, getWsId);
|
|
1258
1669
|
this.returns = new ReturnsResource(this.http, getWsId);
|
|
1259
|
-
this.apiKeys = new ApiKeysResource(this.http, getWsId);
|
|
1260
1670
|
this.analytics = new AnalyticsResource(this.http);
|
|
1261
1671
|
this.orders = new OrdersResource(this.http);
|
|
1262
1672
|
this.inventory = new InventoryResource(this.http);
|
|
1263
1673
|
this.pickups = new PickupsResource(this.http, getWsId);
|
|
1264
1674
|
this.scanForms = new ScanFormsResource(this.http, getWsId);
|
|
1265
1675
|
this.rules = new RulesResource(this.http, getWsId);
|
|
1266
|
-
this.
|
|
1267
|
-
this.hsCodes = new HsCodesResource(this.http, getWsId);
|
|
1676
|
+
this.carbonOffsets = new CarbonOffsetsResource(this.http, getWsId);
|
|
1268
1677
|
this.recurringShipments = new RecurringShipmentsResource(this.http, getWsId);
|
|
1678
|
+
this.reportSchedules = new ReportSchedulesResource(this.http, getWsId);
|
|
1269
1679
|
this.emailTemplates = new EmailTemplatesResource(this.http, getWsId);
|
|
1270
|
-
this.
|
|
1680
|
+
this.hsCodes = new HsCodesResource(this.http);
|
|
1271
1681
|
}
|
|
1272
1682
|
/** Get or set the active workspace ID. */
|
|
1273
1683
|
get workspaceId() {
|
|
@@ -1287,27 +1697,33 @@ var FlexOps = class {
|
|
|
1287
1697
|
};
|
|
1288
1698
|
export {
|
|
1289
1699
|
AnalyticsResource,
|
|
1290
|
-
ApiKeysResource,
|
|
1291
1700
|
AuthResource,
|
|
1701
|
+
CarbonOffsetsResource,
|
|
1292
1702
|
CarriersResource,
|
|
1293
1703
|
EmailTemplatesResource,
|
|
1294
1704
|
FlexOps,
|
|
1295
1705
|
FlexOpsAuthError,
|
|
1296
1706
|
FlexOpsError,
|
|
1297
1707
|
FlexOpsRateLimitError,
|
|
1708
|
+
HazmatClassification,
|
|
1298
1709
|
HsCodesResource,
|
|
1299
1710
|
InsuranceResource,
|
|
1300
1711
|
InventoryResource,
|
|
1301
|
-
OffsetResource,
|
|
1302
1712
|
OrdersResource,
|
|
1303
1713
|
PickupsResource,
|
|
1714
|
+
RecurrenceInterval,
|
|
1304
1715
|
RecurringShipmentsResource,
|
|
1305
|
-
|
|
1716
|
+
ReportFormat,
|
|
1717
|
+
ReportFrequency,
|
|
1718
|
+
ReportSchedulesResource,
|
|
1306
1719
|
ReturnsResource,
|
|
1307
1720
|
RulesResource,
|
|
1308
1721
|
ScanFormsResource,
|
|
1309
1722
|
ShippingResource,
|
|
1723
|
+
TrackingEmailEvent,
|
|
1310
1724
|
WalletResource,
|
|
1725
|
+
WebhookEventType,
|
|
1311
1726
|
WebhooksResource,
|
|
1727
|
+
WorkspaceRole,
|
|
1312
1728
|
WorkspacesResource
|
|
1313
1729
|
};
|