|
| 1 | +import { BARCODING_BASE_PATH, PACKING_LIST_BASE_PATH } from "./constants"; |
| 2 | +import type { |
| 3 | + components as BarcodingComponents, |
| 4 | + operations as BarcodingOperations, |
| 5 | +} from "./generated/barcoding-v3"; |
| 6 | +import type { |
| 7 | + components as PackingListComponents, |
| 8 | + operations as PackingListOperations, |
| 9 | +} from "./generated/packing-list-v1"; |
| 10 | +import { |
| 11 | + type DigiKeyHttpClient, |
| 12 | + positiveInteger, |
| 13 | + type QueryParameters, |
| 14 | + splitRequestOptions, |
| 15 | +} from "./http"; |
| 16 | +import type { DigiKeyRequestOptions, JsonResponse, OperationQuery, ResponseContent } from "./types"; |
| 17 | + |
| 18 | +export type BarcodingSchemas = BarcodingComponents["schemas"]; |
| 19 | +export type BarcodingOperationsMap = BarcodingOperations; |
| 20 | +export type PackingListSchemas = PackingListComponents["schemas"]; |
| 21 | +export type PackingListOperationsMap = PackingListOperations; |
| 22 | + |
| 23 | +export type ProductBarcodeResponse = JsonResponse<BarcodingOperations["ProductBarcode"]>; |
| 24 | +export type Product2DBarcodeResponse = JsonResponse<BarcodingOperations["Product2DBarcode"]>; |
| 25 | +export type PackListBarcodeResponse = JsonResponse<BarcodingOperations["PackListBarcode"]>; |
| 26 | +export type PackList2DBarcodeResponse = JsonResponse<BarcodingOperations["PackList2DBarcode"]>; |
| 27 | +export type GetPackingListResponse = ResponseContent<PackingListOperations["GetPackingList"]>; |
| 28 | +export type GetPackingListBySalesOrderIdResponse = ResponseContent< |
| 29 | + PackingListOperations["GetPackingListBySalesOrderId"] |
| 30 | +>; |
| 31 | +export type GetPackingListByPoNumberResponse = ResponseContent< |
| 32 | + PackingListOperations["GetPackingListByPoNumber"] |
| 33 | +>; |
| 34 | + |
| 35 | +export type BarcodeOptions = DigiKeyRequestOptions & |
| 36 | + OperationQuery<BarcodingOperations["ProductBarcode"]>; |
| 37 | +export type PackingListOptions = DigiKeyRequestOptions & |
| 38 | + OperationQuery<PackingListOperations["GetPackingList"]>; |
| 39 | + |
| 40 | +export class BarcodingClient { |
| 41 | + constructor(private readonly http: DigiKeyHttpClient) {} |
| 42 | + |
| 43 | + productBarcode(barcode: string, options?: BarcodeOptions): Promise<ProductBarcodeResponse> { |
| 44 | + const [requestOptions, query] = splitRequestOptions(options); |
| 45 | + |
| 46 | + return this.http.request<ProductBarcodeResponse>({ |
| 47 | + method: "GET", |
| 48 | + basePath: BARCODING_BASE_PATH, |
| 49 | + path: `/ProductBarcodes/${encodeURIComponent(barcode)}`, |
| 50 | + query: query as QueryParameters, |
| 51 | + requestOptions, |
| 52 | + includeAccountId: false, |
| 53 | + requiredOAuthFlow: "authorizationCode", |
| 54 | + }); |
| 55 | + } |
| 56 | + |
| 57 | + product2DBarcode(barcode: string, options?: BarcodeOptions): Promise<Product2DBarcodeResponse> { |
| 58 | + const [requestOptions, query] = splitRequestOptions(options); |
| 59 | + |
| 60 | + return this.http.request<Product2DBarcodeResponse>({ |
| 61 | + method: "GET", |
| 62 | + basePath: BARCODING_BASE_PATH, |
| 63 | + path: `/Product2DBarcodes/${encodeURIComponent(barcode)}`, |
| 64 | + query: query as QueryParameters, |
| 65 | + requestOptions, |
| 66 | + includeAccountId: false, |
| 67 | + requiredOAuthFlow: "authorizationCode", |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + packListBarcode(barcode: string, options?: BarcodeOptions): Promise<PackListBarcodeResponse> { |
| 72 | + const [requestOptions, query] = splitRequestOptions(options); |
| 73 | + |
| 74 | + return this.http.request<PackListBarcodeResponse>({ |
| 75 | + method: "GET", |
| 76 | + basePath: BARCODING_BASE_PATH, |
| 77 | + path: `/PackListBarcodes/${encodeURIComponent(barcode)}`, |
| 78 | + query: query as QueryParameters, |
| 79 | + requestOptions, |
| 80 | + includeAccountId: false, |
| 81 | + requiredOAuthFlow: "authorizationCode", |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + packList2DBarcode(barcode: string, options?: BarcodeOptions): Promise<PackList2DBarcodeResponse> { |
| 86 | + const [requestOptions, query] = splitRequestOptions(options); |
| 87 | + |
| 88 | + return this.http.request<PackList2DBarcodeResponse>({ |
| 89 | + method: "GET", |
| 90 | + basePath: BARCODING_BASE_PATH, |
| 91 | + path: `/PackList2DBarcodes/${encodeURIComponent(barcode)}`, |
| 92 | + query: query as QueryParameters, |
| 93 | + requestOptions, |
| 94 | + includeAccountId: false, |
| 95 | + requiredOAuthFlow: "authorizationCode", |
| 96 | + }); |
| 97 | + } |
| 98 | + |
| 99 | + getPackingList(invoiceId: number, options?: PackingListOptions): Promise<GetPackingListResponse> { |
| 100 | + const [requestOptions, query] = splitRequestOptions(options); |
| 101 | + |
| 102 | + return this.http.request<GetPackingListResponse>({ |
| 103 | + method: "GET", |
| 104 | + basePath: PACKING_LIST_BASE_PATH, |
| 105 | + path: `/v1/invoice/${positiveInteger(invoiceId, "invoiceId")}`, |
| 106 | + query: query as QueryParameters, |
| 107 | + requestOptions, |
| 108 | + includeAccountId: false, |
| 109 | + requiredOAuthFlow: "authorizationCode", |
| 110 | + }); |
| 111 | + } |
| 112 | + |
| 113 | + getPackingListBySalesOrderId( |
| 114 | + salesOrderId: number, |
| 115 | + options?: PackingListOptions, |
| 116 | + ): Promise<GetPackingListBySalesOrderIdResponse> { |
| 117 | + const [requestOptions, query] = splitRequestOptions(options); |
| 118 | + |
| 119 | + return this.http.request<GetPackingListBySalesOrderIdResponse>({ |
| 120 | + method: "GET", |
| 121 | + basePath: PACKING_LIST_BASE_PATH, |
| 122 | + path: `/v1/salesorderid/${positiveInteger(salesOrderId, "salesOrderId")}`, |
| 123 | + query: query as QueryParameters, |
| 124 | + requestOptions, |
| 125 | + includeAccountId: false, |
| 126 | + requiredOAuthFlow: "authorizationCode", |
| 127 | + }); |
| 128 | + } |
| 129 | + |
| 130 | + getPackingListByPoNumber( |
| 131 | + purchaseOrderNumber: string, |
| 132 | + options?: PackingListOptions, |
| 133 | + ): Promise<GetPackingListByPoNumberResponse> { |
| 134 | + const [requestOptions, query] = splitRequestOptions(options); |
| 135 | + |
| 136 | + return this.http.request<GetPackingListByPoNumberResponse>({ |
| 137 | + method: "GET", |
| 138 | + basePath: PACKING_LIST_BASE_PATH, |
| 139 | + path: `/v1/purchaseordernumber/${encodeURIComponent(purchaseOrderNumber)}`, |
| 140 | + query: query as QueryParameters, |
| 141 | + requestOptions, |
| 142 | + includeAccountId: false, |
| 143 | + requiredOAuthFlow: "authorizationCode", |
| 144 | + }); |
| 145 | + } |
| 146 | +} |
0 commit comments