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