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