@flexops/sdk 1.0.4 → 1.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/dist/index.d.mts CHANGED
@@ -89,12 +89,20 @@ interface RateRequest {
89
89
  carriers?: string[];
90
90
  }
91
91
  interface ShippingRate {
92
- carrier: string;
93
- service: string;
92
+ carrierCode: string;
93
+ carrierName: string;
94
+ serviceCode: string;
95
+ serviceName: string;
94
96
  rate: number;
95
97
  currency: string;
96
- estimatedDays: number;
97
- deliveryDate?: string;
98
+ estimatedDays?: number;
99
+ estimatedDeliveryDate?: string;
100
+ trackingIncluded?: boolean;
101
+ }
102
+ /** Response from a rate-shopping request (raw Gateway `RateShoppingResponse`). */
103
+ interface RateShoppingResponse {
104
+ rates: ShippingRate[];
105
+ currency: string;
98
106
  }
99
107
  interface CreateLabelRequest {
100
108
  carrier: string;
@@ -108,12 +116,15 @@ interface CreateLabelRequest {
108
116
  }
109
117
  interface Label {
110
118
  labelId: string;
119
+ carrierCode: string;
111
120
  trackingNumber: string;
112
- carrier: string;
113
- service: string;
114
121
  labelData: string;
115
122
  labelFormat: string;
116
123
  rate: number;
124
+ currency: string;
125
+ returnLabelData?: string;
126
+ orderId?: number;
127
+ isSandbox: boolean;
117
128
  createdAt: string;
118
129
  }
119
130
  interface Address {
@@ -574,19 +585,23 @@ declare class ShippingResource {
574
585
  constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
575
586
  private wsPath;
576
587
  /** Get shipping rates from all configured carriers. */
577
- getRates(request: RateRequest): Promise<ApiResponse<ShippingRate[]>>;
588
+ getRates(request: RateRequest): Promise<RateShoppingResponse>;
578
589
  /** Get the single cheapest rate across all carriers. */
579
- getCheapestRate(request: RateRequest): Promise<ApiResponse<ShippingRate>>;
590
+ getCheapestRate(request: RateRequest): Promise<ShippingRate>;
580
591
  /** Get the single fastest rate across all carriers. */
581
- getFastestRate(request: RateRequest): Promise<ApiResponse<ShippingRate>>;
582
- /** Create a shipping label. */
583
- createLabel(request: CreateLabelRequest): Promise<ApiResponse<Label>>;
584
- /** Cancel (void) a shipping label. */
585
- cancelLabel(labelId: string): Promise<ApiResponse<unknown>>;
592
+ getFastestRate(request: RateRequest): Promise<ShippingRate>;
593
+ /**
594
+ * Create a shipping label. Supply a `CreateLabelRequest` with `orderId` set to buy against an
595
+ * existing order — the order's ownership, status, ship-method and addresses are validated
596
+ * server-side and postage is settled atomically. Returns the raw label (HTTP 201).
597
+ */
598
+ createLabel(request: CreateLabelRequest): Promise<Label>;
599
+ /** Cancel (void) a shipping label. `carrierCode` is required. */
600
+ cancelLabel(labelId: string, carrierCode: string): Promise<unknown>;
586
601
  /** Track a shipment by tracking number. */
587
- track(trackingNumber: string): Promise<ApiResponse<TrackingInfo>>;
602
+ track(trackingNumber: string): Promise<TrackingInfo>;
588
603
  /** Validate and correct a shipping address. */
589
- validateAddress(address: Address): Promise<ApiResponse<AddressValidationResult>>;
604
+ validateAddress(address: Address): Promise<AddressValidationResult>;
590
605
  /** Create labels in batch. */
591
606
  createBatch(request: BatchLabelRequest): Promise<ApiResponse<BatchLabelJob>>;
592
607
  /** Preview a batch without purchasing (dry-run). */
@@ -596,13 +611,13 @@ declare class ShippingResource {
596
611
  /** Download a label from a batch job. */
597
612
  downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
598
613
  /** List available carriers and their services. */
599
- getCarriers(): Promise<ApiResponse<unknown>>;
614
+ getCarriers(): Promise<unknown>;
600
615
  /** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
601
- getRecommendations(request: CarrierRecommendationRequest): Promise<ApiResponse<CarrierRecommendationResponse>>;
616
+ getRecommendations(request: CarrierRecommendationRequest): Promise<CarrierRecommendationResponse>;
602
617
  /** Predict delivery dates (P25/P50/P75/P95) for a carrier/service/lane combination. */
603
- predictDelivery(request: DeliveryPredictionRequest): Promise<ApiResponse<DeliveryPredictionResponse>>;
618
+ predictDelivery(request: DeliveryPredictionRequest): Promise<DeliveryPredictionResponse>;
604
619
  /** Get cost-saving opportunities: lanes where switching carriers saves money without sacrificing reliability. */
605
- getSavings(): Promise<ApiResponse<CostSavingsSummary>>;
620
+ getSavings(): Promise<CostSavingsSummary>;
606
621
  }
607
622
 
608
623
  /**
@@ -635,7 +650,7 @@ declare class CarriersResource {
635
650
  /** Search international prices. */
636
651
  getInternationalPrices: (body: unknown) => Promise<unknown>;
637
652
  /** Generate a domestic shipping label. */
638
- createDomesticLabel: (body: unknown) => Promise<unknown>;
653
+ createDomesticLabel: (body: unknown) => Promise<Label>;
639
654
  /** Generate a domestic return label. */
640
655
  createReturnLabel: (body: unknown) => Promise<unknown>;
641
656
  /** Generate an international shipping label. */
package/dist/index.d.ts CHANGED
@@ -89,12 +89,20 @@ interface RateRequest {
89
89
  carriers?: string[];
90
90
  }
91
91
  interface ShippingRate {
92
- carrier: string;
93
- service: string;
92
+ carrierCode: string;
93
+ carrierName: string;
94
+ serviceCode: string;
95
+ serviceName: string;
94
96
  rate: number;
95
97
  currency: string;
96
- estimatedDays: number;
97
- deliveryDate?: string;
98
+ estimatedDays?: number;
99
+ estimatedDeliveryDate?: string;
100
+ trackingIncluded?: boolean;
101
+ }
102
+ /** Response from a rate-shopping request (raw Gateway `RateShoppingResponse`). */
103
+ interface RateShoppingResponse {
104
+ rates: ShippingRate[];
105
+ currency: string;
98
106
  }
99
107
  interface CreateLabelRequest {
100
108
  carrier: string;
@@ -108,12 +116,15 @@ interface CreateLabelRequest {
108
116
  }
109
117
  interface Label {
110
118
  labelId: string;
119
+ carrierCode: string;
111
120
  trackingNumber: string;
112
- carrier: string;
113
- service: string;
114
121
  labelData: string;
115
122
  labelFormat: string;
116
123
  rate: number;
124
+ currency: string;
125
+ returnLabelData?: string;
126
+ orderId?: number;
127
+ isSandbox: boolean;
117
128
  createdAt: string;
118
129
  }
119
130
  interface Address {
@@ -574,19 +585,23 @@ declare class ShippingResource {
574
585
  constructor(http: HttpClient, getWorkspaceId: () => string | undefined);
575
586
  private wsPath;
576
587
  /** Get shipping rates from all configured carriers. */
577
- getRates(request: RateRequest): Promise<ApiResponse<ShippingRate[]>>;
588
+ getRates(request: RateRequest): Promise<RateShoppingResponse>;
578
589
  /** Get the single cheapest rate across all carriers. */
579
- getCheapestRate(request: RateRequest): Promise<ApiResponse<ShippingRate>>;
590
+ getCheapestRate(request: RateRequest): Promise<ShippingRate>;
580
591
  /** Get the single fastest rate across all carriers. */
581
- getFastestRate(request: RateRequest): Promise<ApiResponse<ShippingRate>>;
582
- /** Create a shipping label. */
583
- createLabel(request: CreateLabelRequest): Promise<ApiResponse<Label>>;
584
- /** Cancel (void) a shipping label. */
585
- cancelLabel(labelId: string): Promise<ApiResponse<unknown>>;
592
+ getFastestRate(request: RateRequest): Promise<ShippingRate>;
593
+ /**
594
+ * Create a shipping label. Supply a `CreateLabelRequest` with `orderId` set to buy against an
595
+ * existing order — the order's ownership, status, ship-method and addresses are validated
596
+ * server-side and postage is settled atomically. Returns the raw label (HTTP 201).
597
+ */
598
+ createLabel(request: CreateLabelRequest): Promise<Label>;
599
+ /** Cancel (void) a shipping label. `carrierCode` is required. */
600
+ cancelLabel(labelId: string, carrierCode: string): Promise<unknown>;
586
601
  /** Track a shipment by tracking number. */
587
- track(trackingNumber: string): Promise<ApiResponse<TrackingInfo>>;
602
+ track(trackingNumber: string): Promise<TrackingInfo>;
588
603
  /** Validate and correct a shipping address. */
589
- validateAddress(address: Address): Promise<ApiResponse<AddressValidationResult>>;
604
+ validateAddress(address: Address): Promise<AddressValidationResult>;
590
605
  /** Create labels in batch. */
591
606
  createBatch(request: BatchLabelRequest): Promise<ApiResponse<BatchLabelJob>>;
592
607
  /** Preview a batch without purchasing (dry-run). */
@@ -596,13 +611,13 @@ declare class ShippingResource {
596
611
  /** Download a label from a batch job. */
597
612
  downloadBatchLabel(jobId: string, itemId: string): Promise<Response>;
598
613
  /** List available carriers and their services. */
599
- getCarriers(): Promise<ApiResponse<unknown>>;
614
+ getCarriers(): Promise<unknown>;
600
615
  /** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
601
- getRecommendations(request: CarrierRecommendationRequest): Promise<ApiResponse<CarrierRecommendationResponse>>;
616
+ getRecommendations(request: CarrierRecommendationRequest): Promise<CarrierRecommendationResponse>;
602
617
  /** Predict delivery dates (P25/P50/P75/P95) for a carrier/service/lane combination. */
603
- predictDelivery(request: DeliveryPredictionRequest): Promise<ApiResponse<DeliveryPredictionResponse>>;
618
+ predictDelivery(request: DeliveryPredictionRequest): Promise<DeliveryPredictionResponse>;
604
619
  /** Get cost-saving opportunities: lanes where switching carriers saves money without sacrificing reliability. */
605
- getSavings(): Promise<ApiResponse<CostSavingsSummary>>;
620
+ getSavings(): Promise<CostSavingsSummary>;
606
621
  }
607
622
 
608
623
  /**
@@ -635,7 +650,7 @@ declare class CarriersResource {
635
650
  /** Search international prices. */
636
651
  getInternationalPrices: (body: unknown) => Promise<unknown>;
637
652
  /** Generate a domestic shipping label. */
638
- createDomesticLabel: (body: unknown) => Promise<unknown>;
653
+ createDomesticLabel: (body: unknown) => Promise<Label>;
639
654
  /** Generate a domestic return label. */
640
655
  createReturnLabel: (body: unknown) => Promise<unknown>;
641
656
  /** Generate an international shipping label. */
package/dist/index.js CHANGED
@@ -353,40 +353,46 @@ var ShippingResource = class {
353
353
  // -----------------------------------------------------------------------
354
354
  /** Get shipping rates from all configured carriers. */
355
355
  async getRates(request) {
356
- return this.http.post(this.wsPath("shipping/rates"), request);
356
+ return this.http.post("/api/shipping/rates", request);
357
357
  }
358
358
  /** Get the single cheapest rate across all carriers. */
359
359
  async getCheapestRate(request) {
360
- return this.http.post(this.wsPath("shipping/rates/cheapest"), request);
360
+ return this.http.post("/api/shipping/rates/cheapest", request);
361
361
  }
362
362
  /** Get the single fastest rate across all carriers. */
363
363
  async getFastestRate(request) {
364
- return this.http.post(this.wsPath("shipping/rates/fastest"), request);
364
+ return this.http.post("/api/shipping/rates/fastest", request);
365
365
  }
366
366
  // -----------------------------------------------------------------------
367
367
  // Labels
368
368
  // -----------------------------------------------------------------------
369
- /** Create a shipping label. */
369
+ /**
370
+ * Create a shipping label. Supply a `CreateLabelRequest` with `orderId` set to buy against an
371
+ * existing order — the order's ownership, status, ship-method and addresses are validated
372
+ * server-side and postage is settled atomically. Returns the raw label (HTTP 201).
373
+ */
370
374
  async createLabel(request) {
371
- return this.http.post(this.wsPath("shipping/labels"), request, void 0);
375
+ return this.http.post("/api/shipping/labels", request, void 0);
372
376
  }
373
- /** Cancel (void) a shipping label. */
374
- async cancelLabel(labelId) {
375
- return this.http.delete(this.wsPath(`shipping/labels/${labelId}`));
377
+ /** Cancel (void) a shipping label. `carrierCode` is required. */
378
+ async cancelLabel(labelId, carrierCode) {
379
+ return this.http.delete(
380
+ `/api/shipping/labels/${labelId}?carrierCode=${encodeURIComponent(carrierCode)}`
381
+ );
376
382
  }
377
383
  // -----------------------------------------------------------------------
378
384
  // Tracking
379
385
  // -----------------------------------------------------------------------
380
386
  /** Track a shipment by tracking number. */
381
387
  async track(trackingNumber) {
382
- return this.http.get(this.wsPath(`shipping/track/${trackingNumber}`));
388
+ return this.http.get(`/api/shipping/track/${encodeURIComponent(trackingNumber)}`);
383
389
  }
384
390
  // -----------------------------------------------------------------------
385
391
  // Address Validation
386
392
  // -----------------------------------------------------------------------
387
393
  /** Validate and correct a shipping address. */
388
394
  async validateAddress(address) {
389
- return this.http.post(this.wsPath("shipping/addresses/validate"), address);
395
+ return this.http.post("/api/shipping/addresses/validate", address);
390
396
  }
391
397
  // -----------------------------------------------------------------------
392
398
  // Batch Labels
@@ -412,22 +418,22 @@ var ShippingResource = class {
412
418
  // -----------------------------------------------------------------------
413
419
  /** List available carriers and their services. */
414
420
  async getCarriers() {
415
- return this.http.get(this.wsPath("shipping/carriers"));
421
+ return this.http.get("/api/shipping/carriers");
416
422
  }
417
423
  // -----------------------------------------------------------------------
418
424
  // AI Shipping — requires Professional plan or higher
419
425
  // -----------------------------------------------------------------------
420
426
  /** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
421
427
  async getRecommendations(request) {
422
- return this.http.post(this.wsPath("shipping/recommendations"), request);
428
+ return this.http.post("/api/shipping/recommendations", request);
423
429
  }
424
430
  /** Predict delivery dates (P25/P50/P75/P95) for a carrier/service/lane combination. */
425
431
  async predictDelivery(request) {
426
- return this.http.post(this.wsPath("shipping/predictions/delivery"), request);
432
+ return this.http.post("/api/shipping/predictions/delivery", request);
427
433
  }
428
434
  /** Get cost-saving opportunities: lanes where switching carriers saves money without sacrificing reliability. */
429
435
  async getSavings() {
430
- return this.http.get(this.wsPath("shipping/savings"));
436
+ return this.http.get("/api/shipping/savings");
431
437
  }
432
438
  };
433
439
 
@@ -460,7 +466,10 @@ var CarriersResource = class {
460
466
  /** Search international prices. */
461
467
  getInternationalPrices: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchEligibleInternationalPrices"), body),
462
468
  /** Generate a domestic shipping label. */
463
- createDomesticLabel: (body) => this.http.post(this.proxy("api/v3/Shipping/postUspsGenerateDomesticShippingLabel"), body),
469
+ // Domestic USPS labels go through the reliable order-based Gateway path
470
+ // (POST /api/shipping/labels): pass a LabelRequest body with carrierCode:'USPS'
471
+ // and orderId set — server-side order validation + atomic postage settlement.
472
+ createDomesticLabel: (body) => this.http.post("/api/shipping/labels", body),
464
473
  /** Generate a domestic return label. */
465
474
  createReturnLabel: (body) => this.http.post(this.proxy("api/v3/Shipping/postUspsGenerateDomesticReturnsShippingLabel"), body),
466
475
  /** Generate an international shipping label. */
package/dist/index.mjs CHANGED
@@ -311,40 +311,46 @@ var ShippingResource = class {
311
311
  // -----------------------------------------------------------------------
312
312
  /** Get shipping rates from all configured carriers. */
313
313
  async getRates(request) {
314
- return this.http.post(this.wsPath("shipping/rates"), request);
314
+ return this.http.post("/api/shipping/rates", request);
315
315
  }
316
316
  /** Get the single cheapest rate across all carriers. */
317
317
  async getCheapestRate(request) {
318
- return this.http.post(this.wsPath("shipping/rates/cheapest"), request);
318
+ return this.http.post("/api/shipping/rates/cheapest", request);
319
319
  }
320
320
  /** Get the single fastest rate across all carriers. */
321
321
  async getFastestRate(request) {
322
- return this.http.post(this.wsPath("shipping/rates/fastest"), request);
322
+ return this.http.post("/api/shipping/rates/fastest", request);
323
323
  }
324
324
  // -----------------------------------------------------------------------
325
325
  // Labels
326
326
  // -----------------------------------------------------------------------
327
- /** Create a shipping label. */
327
+ /**
328
+ * Create a shipping label. Supply a `CreateLabelRequest` with `orderId` set to buy against an
329
+ * existing order — the order's ownership, status, ship-method and addresses are validated
330
+ * server-side and postage is settled atomically. Returns the raw label (HTTP 201).
331
+ */
328
332
  async createLabel(request) {
329
- return this.http.post(this.wsPath("shipping/labels"), request, void 0);
333
+ return this.http.post("/api/shipping/labels", request, void 0);
330
334
  }
331
- /** Cancel (void) a shipping label. */
332
- async cancelLabel(labelId) {
333
- return this.http.delete(this.wsPath(`shipping/labels/${labelId}`));
335
+ /** Cancel (void) a shipping label. `carrierCode` is required. */
336
+ async cancelLabel(labelId, carrierCode) {
337
+ return this.http.delete(
338
+ `/api/shipping/labels/${labelId}?carrierCode=${encodeURIComponent(carrierCode)}`
339
+ );
334
340
  }
335
341
  // -----------------------------------------------------------------------
336
342
  // Tracking
337
343
  // -----------------------------------------------------------------------
338
344
  /** Track a shipment by tracking number. */
339
345
  async track(trackingNumber) {
340
- return this.http.get(this.wsPath(`shipping/track/${trackingNumber}`));
346
+ return this.http.get(`/api/shipping/track/${encodeURIComponent(trackingNumber)}`);
341
347
  }
342
348
  // -----------------------------------------------------------------------
343
349
  // Address Validation
344
350
  // -----------------------------------------------------------------------
345
351
  /** Validate and correct a shipping address. */
346
352
  async validateAddress(address) {
347
- return this.http.post(this.wsPath("shipping/addresses/validate"), address);
353
+ return this.http.post("/api/shipping/addresses/validate", address);
348
354
  }
349
355
  // -----------------------------------------------------------------------
350
356
  // Batch Labels
@@ -370,22 +376,22 @@ var ShippingResource = class {
370
376
  // -----------------------------------------------------------------------
371
377
  /** List available carriers and their services. */
372
378
  async getCarriers() {
373
- return this.http.get(this.wsPath("shipping/carriers"));
379
+ return this.http.get("/api/shipping/carriers");
374
380
  }
375
381
  // -----------------------------------------------------------------------
376
382
  // AI Shipping — requires Professional plan or higher
377
383
  // -----------------------------------------------------------------------
378
384
  /** Get AI-ranked carrier recommendations for a lane, scored by cost, speed, and reliability. */
379
385
  async getRecommendations(request) {
380
- return this.http.post(this.wsPath("shipping/recommendations"), request);
386
+ return this.http.post("/api/shipping/recommendations", request);
381
387
  }
382
388
  /** Predict delivery dates (P25/P50/P75/P95) for a carrier/service/lane combination. */
383
389
  async predictDelivery(request) {
384
- return this.http.post(this.wsPath("shipping/predictions/delivery"), request);
390
+ return this.http.post("/api/shipping/predictions/delivery", request);
385
391
  }
386
392
  /** Get cost-saving opportunities: lanes where switching carriers saves money without sacrificing reliability. */
387
393
  async getSavings() {
388
- return this.http.get(this.wsPath("shipping/savings"));
394
+ return this.http.get("/api/shipping/savings");
389
395
  }
390
396
  };
391
397
 
@@ -418,7 +424,10 @@ var CarriersResource = class {
418
424
  /** Search international prices. */
419
425
  getInternationalPrices: (body) => this.http.post(this.proxy("api/v3/RateCalculator/postUspsSearchEligibleInternationalPrices"), body),
420
426
  /** Generate a domestic shipping label. */
421
- createDomesticLabel: (body) => this.http.post(this.proxy("api/v3/Shipping/postUspsGenerateDomesticShippingLabel"), body),
427
+ // Domestic USPS labels go through the reliable order-based Gateway path
428
+ // (POST /api/shipping/labels): pass a LabelRequest body with carrierCode:'USPS'
429
+ // and orderId set — server-side order validation + atomic postage settlement.
430
+ createDomesticLabel: (body) => this.http.post("/api/shipping/labels", body),
422
431
  /** Generate a domestic return label. */
423
432
  createReturnLabel: (body) => this.http.post(this.proxy("api/v3/Shipping/postUspsGenerateDomesticReturnsShippingLabel"), body),
424
433
  /** Generate an international shipping label. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexops/sdk",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Official FlexOps Platform Node.js/TypeScript SDK — multi-carrier shipping, order management, and logistics API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest",
26
- "lint": "eslint src/ --ext .ts",
26
+ "lint": "eslint src/",
27
27
  "typecheck": "tsc --noEmit",
28
28
  "prepublishOnly": "npm run build"
29
29
  },
@@ -53,11 +53,13 @@
53
53
  "node": ">=18.0.0"
54
54
  },
55
55
  "devDependencies": {
56
+ "@eslint/js": "^10.0.1",
56
57
  "@openapitools/openapi-generator-cli": "^2.16.3",
57
- "@types/node": "^22.0.0",
58
- "eslint": "^9.0.0",
58
+ "@types/node": "^26.1.2",
59
+ "eslint": "^10.8.0",
59
60
  "tsup": "^8.4.0",
60
61
  "typescript": "^5.8.0",
61
- "vitest": "^3.1.0"
62
+ "typescript-eslint": "^8.65.0",
63
+ "vitest": "^4.1.10"
62
64
  }
63
65
  }