@vencav/shoptet-client 0.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.
@@ -0,0 +1,244 @@
1
+ import { Result } from '@vencav/result';
2
+ export { Result } from '@vencav/result';
3
+
4
+ interface ShoptetWebhookPayload {
5
+ readonly event: ShoptetEventType;
6
+ readonly eventCreated: string;
7
+ readonly eventInstance: string;
8
+ readonly eshopId: number;
9
+ }
10
+ type ShoptetEventType = "order:create" | "order:update" | "order:delete" | "stock:update" | "product:create" | "product:update";
11
+ interface ShoptetOrder {
12
+ readonly code: string;
13
+ readonly guid: string;
14
+ readonly creationTime: string;
15
+ readonly changeTime: string;
16
+ readonly status: ShoptetOrderStatus;
17
+ readonly paid: boolean;
18
+ readonly currency: string;
19
+ readonly price: ShoptetPrice;
20
+ readonly customer: ShoptetCustomer;
21
+ readonly billingAddress: ShoptetAddress;
22
+ readonly deliveryAddress?: ShoptetAddress;
23
+ readonly shippingMethod: ShoptetShippingMethod;
24
+ readonly paymentMethod: ShoptetPaymentMethod;
25
+ readonly items: ReadonlyArray<ShoptetOrderItem>;
26
+ readonly notes?: string;
27
+ readonly adminNotes?: string;
28
+ }
29
+ interface ShoptetOrderStatus {
30
+ readonly id: number;
31
+ readonly name: string;
32
+ }
33
+ interface ShoptetPrice {
34
+ readonly withVat: number;
35
+ readonly withoutVat: number;
36
+ readonly vat: number;
37
+ readonly toPay: number;
38
+ readonly currencyCode: string;
39
+ readonly exchangeRate: number;
40
+ }
41
+ interface ShoptetCustomer {
42
+ readonly guid?: string;
43
+ readonly email: string;
44
+ readonly phone?: string;
45
+ readonly remark?: string;
46
+ }
47
+ interface ShoptetAddress {
48
+ readonly company?: string;
49
+ readonly fullName: string;
50
+ readonly street: string;
51
+ readonly houseNumber?: string;
52
+ readonly city: string;
53
+ readonly district?: string;
54
+ readonly zip: string;
55
+ readonly countryCode: string;
56
+ readonly regionName?: string;
57
+ readonly additional?: string;
58
+ readonly companyId?: string;
59
+ readonly vatId?: string;
60
+ }
61
+ interface ShoptetShippingMethod {
62
+ readonly guid: string;
63
+ readonly name: string;
64
+ }
65
+ interface ShoptetPaymentMethod {
66
+ readonly guid: string;
67
+ readonly name: string;
68
+ }
69
+ type ItemType = "product" | "shipping" | "billing" | "discount" | "gift";
70
+ interface ShoptetOrderItem {
71
+ readonly productGuid?: string;
72
+ readonly code: string;
73
+ readonly ean?: string;
74
+ readonly name: string;
75
+ readonly variantName?: string;
76
+ readonly amount: number;
77
+ readonly amountUnit: string;
78
+ readonly weight?: number;
79
+ readonly remark?: string;
80
+ readonly itemPrice: ShoptetItemPrice;
81
+ readonly itemType: ItemType;
82
+ }
83
+ interface ShoptetItemPrice {
84
+ readonly withVat: number;
85
+ readonly withoutVat: number;
86
+ readonly vat: number;
87
+ readonly vatRate: number;
88
+ }
89
+ interface ShoptetStockItem {
90
+ readonly guid: string;
91
+ readonly code: string;
92
+ readonly ean?: string;
93
+ readonly stock: number;
94
+ readonly minStockSupply?: number;
95
+ }
96
+ type CreateOrderItemType = "product" | "shipping" | "billing" | "discount-coupon" | "volume-discount" | "gift" | "gift-certificate" | "generic-item" | "service" | "deposit";
97
+ interface CreateOrderItem {
98
+ readonly itemType: CreateOrderItemType;
99
+ readonly productGuid?: string;
100
+ /** Product/variant code – max 64 chars */
101
+ readonly code?: string;
102
+ /** Item name – max 250 chars */
103
+ readonly name?: string;
104
+ readonly variantName?: string;
105
+ readonly brand?: string;
106
+ readonly supplierName?: string;
107
+ readonly remark?: string;
108
+ readonly warrantyDescription?: string;
109
+ readonly additionalField?: string;
110
+ /** Quantity, e.g. "1.000" */
111
+ readonly amount?: string;
112
+ /** Unit, e.g. "ks" – max 16 chars */
113
+ readonly amountUnit?: string;
114
+ readonly weight?: string;
115
+ readonly priceRatio?: string;
116
+ /** VAT rate, e.g. "21.00" */
117
+ readonly vatRate?: string;
118
+ /** Total item price with VAT */
119
+ readonly itemPriceWithVat?: string;
120
+ /** Total item price without VAT */
121
+ readonly itemPriceWithoutVat?: string;
122
+ /** Unit price with VAT */
123
+ readonly unitPriceWithVat?: string;
124
+ /** Unit price without VAT */
125
+ readonly unitPriceWithoutVat?: string;
126
+ readonly buyPriceWithVat?: string;
127
+ readonly buyPriceWithoutVat?: string;
128
+ readonly buyPriceVatRate?: string;
129
+ readonly statusId?: number;
130
+ readonly amountCompleted?: string;
131
+ readonly recyclingFeeId?: number;
132
+ readonly consumptionTaxId?: number;
133
+ }
134
+ interface CreateOrderAddress {
135
+ readonly company?: string;
136
+ readonly fullName?: string;
137
+ readonly street?: string;
138
+ readonly streetWithNr?: string;
139
+ readonly houseNumber?: string;
140
+ readonly city?: string;
141
+ readonly district?: string;
142
+ readonly additional?: string;
143
+ readonly zip?: string;
144
+ readonly countryCode?: string;
145
+ readonly regionName?: string;
146
+ readonly regionShortcut?: string;
147
+ readonly companyId?: string;
148
+ readonly vatId?: string;
149
+ readonly taxId?: string;
150
+ }
151
+ interface CreateOrderCurrency {
152
+ readonly code: string;
153
+ readonly exchangeRate?: string;
154
+ }
155
+ interface CreateOrderRequest {
156
+ /** ISO 8601 datetime */
157
+ readonly creationTime?: string;
158
+ /** Order code – max 10 chars, must be unique */
159
+ readonly code?: string;
160
+ readonly language?: string;
161
+ /** External system identifier – max 255 chars, required & unique */
162
+ readonly externalCode: string;
163
+ readonly cashDeskOrder?: boolean;
164
+ readonly statusId?: number;
165
+ readonly sourceId?: number | null;
166
+ readonly salesChannelGuid?: string | null;
167
+ /** Customer email – max 100 chars */
168
+ readonly email?: string;
169
+ /** Phone – max 32 chars */
170
+ readonly phone?: string | null;
171
+ readonly birthDate?: string | null;
172
+ readonly vatPayer?: boolean;
173
+ readonly paymentMethodGuid?: string | null;
174
+ readonly shippingGuid?: string | null;
175
+ readonly shippingDetails?: Record<string, unknown> | null;
176
+ readonly paid?: boolean | null;
177
+ readonly billingMethodCode?: number;
178
+ readonly clientIPAddress?: string | null;
179
+ readonly customerGuid?: string | null;
180
+ readonly billingAddress?: CreateOrderAddress;
181
+ readonly addressesEqual?: boolean | null;
182
+ readonly deliveryAddress?: CreateOrderAddress | null;
183
+ readonly notes?: Record<string, unknown> | null;
184
+ readonly stockId?: number;
185
+ readonly currency: CreateOrderCurrency;
186
+ readonly vatMode?: "Normal" | "One Stop Shop" | "Reverse charge" | "Outside the EU";
187
+ readonly items: ReadonlyArray<CreateOrderItem>;
188
+ }
189
+ interface CreateOrderOptions {
190
+ readonly suppressDocumentGeneration?: boolean;
191
+ readonly suppressEmailSending?: boolean;
192
+ readonly suppressProductChecking?: boolean;
193
+ readonly suppressStockMovements?: boolean;
194
+ readonly suppressHistoricalMandatoryFields?: boolean;
195
+ readonly suppressHistoricalPaymentChecking?: boolean;
196
+ readonly suppressHistoricalShippingChecking?: boolean;
197
+ }
198
+ interface ShoptetApiResponse<T> {
199
+ readonly data: T;
200
+ readonly errors: ReadonlyArray<ShoptetError> | null;
201
+ }
202
+ interface ShoptetError {
203
+ readonly errorCode: string;
204
+ readonly instance: string;
205
+ readonly message: string;
206
+ }
207
+
208
+ interface ShoptetCredentials {
209
+ readonly oauthAccessToken: string;
210
+ readonly apiUrl: string;
211
+ readonly webhookSecret: string;
212
+ }
213
+ interface ShoptetClientOptions {
214
+ /** Maximum items per batch request. Shoptet API hard limit is 300. Default: 300. */
215
+ readonly maxBatchSize?: number;
216
+ /** Request timeout in milliseconds. Default: 30000. */
217
+ readonly timeoutMs?: number;
218
+ }
219
+ type BatchUpdateResult = {
220
+ readonly success: number;
221
+ readonly failed: number;
222
+ readonly errors: ReadonlyArray<{
223
+ readonly code: string;
224
+ readonly error: string;
225
+ }>;
226
+ };
227
+ type ShoptetClient = ReturnType<typeof createShoptetClient>;
228
+ declare const createShoptetClient: (credentials: ShoptetCredentials, options?: ShoptetClientOptions) => {
229
+ validateWebhookSignature: (payload: string, signature: string) => boolean;
230
+ getOrder: (orderCode: string) => Promise<Result<ShoptetOrder>>;
231
+ getDefaultStockId: () => Promise<Result<number>>;
232
+ batchUpdateStock: (items: Array<{
233
+ productCode: string;
234
+ quantity: number;
235
+ }>) => Promise<Result<BatchUpdateResult>>;
236
+ getDefaultPricelistId: () => Promise<Result<number>>;
237
+ batchUpdatePrices: (items: Array<{
238
+ code: string;
239
+ price: number;
240
+ }>) => Promise<Result<BatchUpdateResult>>;
241
+ createOrder: (order: CreateOrderRequest, orderOptions?: CreateOrderOptions) => Promise<Result<ShoptetOrder>>;
242
+ };
243
+
244
+ export { type BatchUpdateResult, type CreateOrderAddress, type CreateOrderCurrency, type CreateOrderItem, type CreateOrderItemType, type CreateOrderOptions, type CreateOrderRequest, type ItemType, type ShoptetAddress, type ShoptetApiResponse, type ShoptetClient, type ShoptetClientOptions, type ShoptetCredentials, type ShoptetCustomer, type ShoptetError, type ShoptetEventType, type ShoptetOrder, type ShoptetOrderItem, type ShoptetOrderStatus, type ShoptetPaymentMethod, type ShoptetPrice, type ShoptetShippingMethod, type ShoptetStockItem, type ShoptetWebhookPayload, createShoptetClient };
@@ -0,0 +1,244 @@
1
+ import { Result } from '@vencav/result';
2
+ export { Result } from '@vencav/result';
3
+
4
+ interface ShoptetWebhookPayload {
5
+ readonly event: ShoptetEventType;
6
+ readonly eventCreated: string;
7
+ readonly eventInstance: string;
8
+ readonly eshopId: number;
9
+ }
10
+ type ShoptetEventType = "order:create" | "order:update" | "order:delete" | "stock:update" | "product:create" | "product:update";
11
+ interface ShoptetOrder {
12
+ readonly code: string;
13
+ readonly guid: string;
14
+ readonly creationTime: string;
15
+ readonly changeTime: string;
16
+ readonly status: ShoptetOrderStatus;
17
+ readonly paid: boolean;
18
+ readonly currency: string;
19
+ readonly price: ShoptetPrice;
20
+ readonly customer: ShoptetCustomer;
21
+ readonly billingAddress: ShoptetAddress;
22
+ readonly deliveryAddress?: ShoptetAddress;
23
+ readonly shippingMethod: ShoptetShippingMethod;
24
+ readonly paymentMethod: ShoptetPaymentMethod;
25
+ readonly items: ReadonlyArray<ShoptetOrderItem>;
26
+ readonly notes?: string;
27
+ readonly adminNotes?: string;
28
+ }
29
+ interface ShoptetOrderStatus {
30
+ readonly id: number;
31
+ readonly name: string;
32
+ }
33
+ interface ShoptetPrice {
34
+ readonly withVat: number;
35
+ readonly withoutVat: number;
36
+ readonly vat: number;
37
+ readonly toPay: number;
38
+ readonly currencyCode: string;
39
+ readonly exchangeRate: number;
40
+ }
41
+ interface ShoptetCustomer {
42
+ readonly guid?: string;
43
+ readonly email: string;
44
+ readonly phone?: string;
45
+ readonly remark?: string;
46
+ }
47
+ interface ShoptetAddress {
48
+ readonly company?: string;
49
+ readonly fullName: string;
50
+ readonly street: string;
51
+ readonly houseNumber?: string;
52
+ readonly city: string;
53
+ readonly district?: string;
54
+ readonly zip: string;
55
+ readonly countryCode: string;
56
+ readonly regionName?: string;
57
+ readonly additional?: string;
58
+ readonly companyId?: string;
59
+ readonly vatId?: string;
60
+ }
61
+ interface ShoptetShippingMethod {
62
+ readonly guid: string;
63
+ readonly name: string;
64
+ }
65
+ interface ShoptetPaymentMethod {
66
+ readonly guid: string;
67
+ readonly name: string;
68
+ }
69
+ type ItemType = "product" | "shipping" | "billing" | "discount" | "gift";
70
+ interface ShoptetOrderItem {
71
+ readonly productGuid?: string;
72
+ readonly code: string;
73
+ readonly ean?: string;
74
+ readonly name: string;
75
+ readonly variantName?: string;
76
+ readonly amount: number;
77
+ readonly amountUnit: string;
78
+ readonly weight?: number;
79
+ readonly remark?: string;
80
+ readonly itemPrice: ShoptetItemPrice;
81
+ readonly itemType: ItemType;
82
+ }
83
+ interface ShoptetItemPrice {
84
+ readonly withVat: number;
85
+ readonly withoutVat: number;
86
+ readonly vat: number;
87
+ readonly vatRate: number;
88
+ }
89
+ interface ShoptetStockItem {
90
+ readonly guid: string;
91
+ readonly code: string;
92
+ readonly ean?: string;
93
+ readonly stock: number;
94
+ readonly minStockSupply?: number;
95
+ }
96
+ type CreateOrderItemType = "product" | "shipping" | "billing" | "discount-coupon" | "volume-discount" | "gift" | "gift-certificate" | "generic-item" | "service" | "deposit";
97
+ interface CreateOrderItem {
98
+ readonly itemType: CreateOrderItemType;
99
+ readonly productGuid?: string;
100
+ /** Product/variant code – max 64 chars */
101
+ readonly code?: string;
102
+ /** Item name – max 250 chars */
103
+ readonly name?: string;
104
+ readonly variantName?: string;
105
+ readonly brand?: string;
106
+ readonly supplierName?: string;
107
+ readonly remark?: string;
108
+ readonly warrantyDescription?: string;
109
+ readonly additionalField?: string;
110
+ /** Quantity, e.g. "1.000" */
111
+ readonly amount?: string;
112
+ /** Unit, e.g. "ks" – max 16 chars */
113
+ readonly amountUnit?: string;
114
+ readonly weight?: string;
115
+ readonly priceRatio?: string;
116
+ /** VAT rate, e.g. "21.00" */
117
+ readonly vatRate?: string;
118
+ /** Total item price with VAT */
119
+ readonly itemPriceWithVat?: string;
120
+ /** Total item price without VAT */
121
+ readonly itemPriceWithoutVat?: string;
122
+ /** Unit price with VAT */
123
+ readonly unitPriceWithVat?: string;
124
+ /** Unit price without VAT */
125
+ readonly unitPriceWithoutVat?: string;
126
+ readonly buyPriceWithVat?: string;
127
+ readonly buyPriceWithoutVat?: string;
128
+ readonly buyPriceVatRate?: string;
129
+ readonly statusId?: number;
130
+ readonly amountCompleted?: string;
131
+ readonly recyclingFeeId?: number;
132
+ readonly consumptionTaxId?: number;
133
+ }
134
+ interface CreateOrderAddress {
135
+ readonly company?: string;
136
+ readonly fullName?: string;
137
+ readonly street?: string;
138
+ readonly streetWithNr?: string;
139
+ readonly houseNumber?: string;
140
+ readonly city?: string;
141
+ readonly district?: string;
142
+ readonly additional?: string;
143
+ readonly zip?: string;
144
+ readonly countryCode?: string;
145
+ readonly regionName?: string;
146
+ readonly regionShortcut?: string;
147
+ readonly companyId?: string;
148
+ readonly vatId?: string;
149
+ readonly taxId?: string;
150
+ }
151
+ interface CreateOrderCurrency {
152
+ readonly code: string;
153
+ readonly exchangeRate?: string;
154
+ }
155
+ interface CreateOrderRequest {
156
+ /** ISO 8601 datetime */
157
+ readonly creationTime?: string;
158
+ /** Order code – max 10 chars, must be unique */
159
+ readonly code?: string;
160
+ readonly language?: string;
161
+ /** External system identifier – max 255 chars, required & unique */
162
+ readonly externalCode: string;
163
+ readonly cashDeskOrder?: boolean;
164
+ readonly statusId?: number;
165
+ readonly sourceId?: number | null;
166
+ readonly salesChannelGuid?: string | null;
167
+ /** Customer email – max 100 chars */
168
+ readonly email?: string;
169
+ /** Phone – max 32 chars */
170
+ readonly phone?: string | null;
171
+ readonly birthDate?: string | null;
172
+ readonly vatPayer?: boolean;
173
+ readonly paymentMethodGuid?: string | null;
174
+ readonly shippingGuid?: string | null;
175
+ readonly shippingDetails?: Record<string, unknown> | null;
176
+ readonly paid?: boolean | null;
177
+ readonly billingMethodCode?: number;
178
+ readonly clientIPAddress?: string | null;
179
+ readonly customerGuid?: string | null;
180
+ readonly billingAddress?: CreateOrderAddress;
181
+ readonly addressesEqual?: boolean | null;
182
+ readonly deliveryAddress?: CreateOrderAddress | null;
183
+ readonly notes?: Record<string, unknown> | null;
184
+ readonly stockId?: number;
185
+ readonly currency: CreateOrderCurrency;
186
+ readonly vatMode?: "Normal" | "One Stop Shop" | "Reverse charge" | "Outside the EU";
187
+ readonly items: ReadonlyArray<CreateOrderItem>;
188
+ }
189
+ interface CreateOrderOptions {
190
+ readonly suppressDocumentGeneration?: boolean;
191
+ readonly suppressEmailSending?: boolean;
192
+ readonly suppressProductChecking?: boolean;
193
+ readonly suppressStockMovements?: boolean;
194
+ readonly suppressHistoricalMandatoryFields?: boolean;
195
+ readonly suppressHistoricalPaymentChecking?: boolean;
196
+ readonly suppressHistoricalShippingChecking?: boolean;
197
+ }
198
+ interface ShoptetApiResponse<T> {
199
+ readonly data: T;
200
+ readonly errors: ReadonlyArray<ShoptetError> | null;
201
+ }
202
+ interface ShoptetError {
203
+ readonly errorCode: string;
204
+ readonly instance: string;
205
+ readonly message: string;
206
+ }
207
+
208
+ interface ShoptetCredentials {
209
+ readonly oauthAccessToken: string;
210
+ readonly apiUrl: string;
211
+ readonly webhookSecret: string;
212
+ }
213
+ interface ShoptetClientOptions {
214
+ /** Maximum items per batch request. Shoptet API hard limit is 300. Default: 300. */
215
+ readonly maxBatchSize?: number;
216
+ /** Request timeout in milliseconds. Default: 30000. */
217
+ readonly timeoutMs?: number;
218
+ }
219
+ type BatchUpdateResult = {
220
+ readonly success: number;
221
+ readonly failed: number;
222
+ readonly errors: ReadonlyArray<{
223
+ readonly code: string;
224
+ readonly error: string;
225
+ }>;
226
+ };
227
+ type ShoptetClient = ReturnType<typeof createShoptetClient>;
228
+ declare const createShoptetClient: (credentials: ShoptetCredentials, options?: ShoptetClientOptions) => {
229
+ validateWebhookSignature: (payload: string, signature: string) => boolean;
230
+ getOrder: (orderCode: string) => Promise<Result<ShoptetOrder>>;
231
+ getDefaultStockId: () => Promise<Result<number>>;
232
+ batchUpdateStock: (items: Array<{
233
+ productCode: string;
234
+ quantity: number;
235
+ }>) => Promise<Result<BatchUpdateResult>>;
236
+ getDefaultPricelistId: () => Promise<Result<number>>;
237
+ batchUpdatePrices: (items: Array<{
238
+ code: string;
239
+ price: number;
240
+ }>) => Promise<Result<BatchUpdateResult>>;
241
+ createOrder: (order: CreateOrderRequest, orderOptions?: CreateOrderOptions) => Promise<Result<ShoptetOrder>>;
242
+ };
243
+
244
+ export { type BatchUpdateResult, type CreateOrderAddress, type CreateOrderCurrency, type CreateOrderItem, type CreateOrderItemType, type CreateOrderOptions, type CreateOrderRequest, type ItemType, type ShoptetAddress, type ShoptetApiResponse, type ShoptetClient, type ShoptetClientOptions, type ShoptetCredentials, type ShoptetCustomer, type ShoptetError, type ShoptetEventType, type ShoptetOrder, type ShoptetOrderItem, type ShoptetOrderStatus, type ShoptetPaymentMethod, type ShoptetPrice, type ShoptetShippingMethod, type ShoptetStockItem, type ShoptetWebhookPayload, createShoptetClient };