@sommpicks/sommpicks-shopify 24.12.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/Logger.ts +18 -0
- package/README.md +258 -0
- package/addTypings.sh +2 -0
- package/bitbucket-pipelines.yml +38 -0
- package/index.ts +132 -0
- package/package.json +57 -0
- package/publish.sh +20 -0
- package/services/CacheWrapper.ts +30 -0
- package/services/CountryCodeService.ts +507 -0
- package/shopify/ShopifyAppService.ts +109 -0
- package/shopify/ShopifyAssetService.ts +20 -0
- package/shopify/ShopifyBillingService.ts +73 -0
- package/shopify/ShopifyCartTrasnformationService.ts +207 -0
- package/shopify/ShopifyCollectionService.ts +523 -0
- package/shopify/ShopifyCustomerService.ts +472 -0
- package/shopify/ShopifyDeliveryCustomisationService.ts +220 -0
- package/shopify/ShopifyDiscountService.ts +131 -0
- package/shopify/ShopifyDraftOrderService.ts +125 -0
- package/shopify/ShopifyFulfillmentService.ts +41 -0
- package/shopify/ShopifyFunctionsProductDiscountsService.ts +166 -0
- package/shopify/ShopifyInventoryService.ts +415 -0
- package/shopify/ShopifyLocationService.ts +29 -0
- package/shopify/ShopifyOrderRefundsService.ts +138 -0
- package/shopify/ShopifyOrderRiskService.ts +19 -0
- package/shopify/ShopifyOrderService.ts +1143 -0
- package/shopify/ShopifyPageService.ts +62 -0
- package/shopify/ShopifyProductService.ts +772 -0
- package/shopify/ShopifyShippingZonesService.ts +37 -0
- package/shopify/ShopifyShopService.ts +101 -0
- package/shopify/ShopifyTemplateService.ts +30 -0
- package/shopify/ShopifyThemeService.ts +33 -0
- package/shopify/ShopifyUtils.ts +56 -0
- package/shopify/ShopifyWebhookService.ts +110 -0
- package/shopify/base/APIVersion.ts +4 -0
- package/shopify/base/AbstractService.ts +152 -0
- package/shopify/base/ErrorHelper.ts +24 -0
- package/shopify/errors/InspiraShopifyCustomError.ts +7 -0
- package/shopify/errors/InspiraShopifyError.ts +15 -0
- package/shopify/errors/InspiraShopifyUnableToReserveInventoryError.ts +7 -0
- package/shopify/helpers/ShopifyProductServiceHelper.ts +450 -0
- package/shopify/product/ShopifyProductCountService.ts +110 -0
- package/shopify/product/ShopifyProductListService.ts +333 -0
- package/shopify/product/ShopifyProductMetafieldsService.ts +405 -0
- package/shopify/product/ShopifyProductPublicationsService.ts +112 -0
- package/shopify/product/ShopifyVariantService.ts +584 -0
- package/shopify/router/ShopifyMandatoryRouter.ts +37 -0
- package/shopify/router/ShopifyRouter.ts +85 -0
- package/shopify/router/ShopifyRouterBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBisBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBisBisBis.ts +85 -0
- package/shopify/router/WebhookSkipMiddleware.ts +73 -0
- package/shopify/router/services/CryptoService.ts +26 -0
- package/shopify/router/services/HmacValidator.ts +36 -0
- package/shopify/router/services/OauthService.ts +17 -0
- package/shopify/router/services/RestUtils.ts +13 -0
- package/shopify/router/services/rateLimiter/MemoryStores.ts +46 -0
- package/shopify/router/services/rateLimiter/StoreRateLimiter.ts +46 -0
- package/test/README.md +223 -0
- package/test/router/ShopifyRouter.test.ts +71 -0
- package/test/router/WebhookSkipMiddleware.test.ts +86 -0
- package/test/router/services/HmacValidator.test.ts +24 -0
- package/test/router/services/RestUtils.test.ts +13 -0
- package/test/router/services/rateLimiter/StoreRateLimiter.test.ts +62 -0
- package/test/services/CacheWrapper.test.ts +30 -0
- package/test/shopify/ShopifyOrderService.test.ts +29 -0
- package/test/shopify/ShopifyProductService.test.ts +118 -0
- package/test/shopify/ShopifyWebhookService.test.ts +105 -0
- package/tsconfig.json +10 -0
- package/typings/axios.d.ts +8 -0
- package/typings/index.d.ts +1682 -0
package/Logger.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
export class Logger {
|
|
3
|
+
public static enableLogging = true;
|
|
4
|
+
|
|
5
|
+
public static error: any = (...args) => {
|
|
6
|
+
if(Logger.enableLogging) {
|
|
7
|
+
Logger._error(args);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
public static info: any = (...args) => {
|
|
11
|
+
if(Logger.enableLogging) {
|
|
12
|
+
Logger._info(args);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
public static _error: any = (...args) => {};
|
|
17
|
+
public static _info: any = (...args) => {};
|
|
18
|
+
}
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# inspira-shopify
|
|
2
|
+
|
|
3
|
+
Shopify Rest API calls utility
|
|
4
|
+
|
|
5
|
+
## HOW TO USE
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
npm install --save inspira-shopify
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### Use shopify rest calls
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
|
|
16
|
+
import ShopifyRest from 'inspira-shopify';
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const inspiraShopify = new ShopifyRest('<your shop>.myshopify.com','<shopify token>');
|
|
20
|
+
|
|
21
|
+
//Override default options
|
|
22
|
+
const inspiraShopify = new ShopifyRest('<your shop>.myshopify.com','<shopify token>', {timeout:4000, retries: 3, debug: true, logger: mylogger});
|
|
23
|
+
|
|
24
|
+
//Create a customer example
|
|
25
|
+
inspiraShopify.customer.create(
|
|
26
|
+
{email:'wakeeekm@gmail.com', verified_email: true, first_name:'hweweji', last_name:'eqwewwert', phone:'07470874486'})
|
|
27
|
+
.catch((err) => { console.log( err)} )
|
|
28
|
+
.then((result) => { console.log(result)});
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Use shopify express Router
|
|
33
|
+
|
|
34
|
+
Set shopify endpoints for installing your app.
|
|
35
|
+
|
|
36
|
+
```js
|
|
37
|
+
|
|
38
|
+
import { Router } from 'inspira-shopify';
|
|
39
|
+
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
const app = express();
|
|
43
|
+
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
function callback(token, shop, response, err) {
|
|
47
|
+
//manage your shopify token and send response to the client
|
|
48
|
+
if(err) { console.error(err)}
|
|
49
|
+
response.sendFile( ... );
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
app.use('/shopify', new Router( 'secret', 'key', 'scopes', 'app base url', callback).buildRoutes());
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Use Hmac utilities.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
|
|
60
|
+
import { HmacUtils } from 'inspira-shopify';
|
|
61
|
+
|
|
62
|
+
...
|
|
63
|
+
|
|
64
|
+
router.post('/<someendpoint>', HmacUtils.jsonWebhookParser, async (req, res) => {
|
|
65
|
+
const isHmacOk = await HmacUtils.checkHmac(req, 'SHOPIFY_SECRET');
|
|
66
|
+
if(!isHmacOk) throw 'Hmac not correct';
|
|
67
|
+
...
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
...
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Cache Shopify Calls
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
|
|
78
|
+
import { RestCacheWrapper } from 'inspira-shopify';
|
|
79
|
+
|
|
80
|
+
...
|
|
81
|
+
private static methodCached = new RestCacheWrapper<Response Type>(<Items to holds in cache>, <Shopify rest method to be cached>);
|
|
82
|
+
|
|
83
|
+
await methodCached.execute(...args);
|
|
84
|
+
...
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### SHOPIFY REST OPTIONS
|
|
89
|
+
|
|
90
|
+
- **timeout**(ms): timeout while perfoming rest call. Default is 3000.
|
|
91
|
+
- **retries**: How many times will the call tried. It will retry when it is a network error or a 5xx error.
|
|
92
|
+
- **debug**: When debug is set to true it will log debug data. You must specify a logger.
|
|
93
|
+
- **logger**: Logger object used for logging data.
|
|
94
|
+
|
|
95
|
+
And example of a logger can be:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
|
|
99
|
+
//using console for building my logger
|
|
100
|
+
const mylogger = {error: console.error, info: console.log};
|
|
101
|
+
|
|
102
|
+
new ShopifyRest('<your shop>.myshopify.com','<shopify token>', {timeout:4000, retries: 3, debug: true, logger: mylogger})
|
|
103
|
+
```
|
|
104
|
+
## HOW TO PUBLISH
|
|
105
|
+
|
|
106
|
+
Push a change with a new version set in package.json and bitbucket pipeline will automatically publish a new npm package.
|
|
107
|
+
|
|
108
|
+
**NOTE:** To understand when the version number needs to change refer to [npm documentation](https://docs.npmjs.com/getting-started/semantic-versioning)
|
|
109
|
+
|
|
110
|
+
## Functionalities
|
|
111
|
+
|
|
112
|
+
- Customers
|
|
113
|
+
- getInBatch
|
|
114
|
+
- getById
|
|
115
|
+
- getByEmail
|
|
116
|
+
- getByTag
|
|
117
|
+
- getByLastNameContains
|
|
118
|
+
- addAddress
|
|
119
|
+
- removeAddress
|
|
120
|
+
- updateAddress
|
|
121
|
+
- addressAsDefault
|
|
122
|
+
- replacesAddressAsDefault
|
|
123
|
+
- addAddressAsDefault
|
|
124
|
+
- create
|
|
125
|
+
- update
|
|
126
|
+
- get(numOfCustomers)
|
|
127
|
+
- getMetafields
|
|
128
|
+
- getMetafield
|
|
129
|
+
- postMetafield
|
|
130
|
+
- deleteMetafield
|
|
131
|
+
- sendInvite
|
|
132
|
+
- Inventory
|
|
133
|
+
- setItemToTrackable
|
|
134
|
+
- setQuantity
|
|
135
|
+
- getLevel
|
|
136
|
+
- getInventoryItemsOfProduct
|
|
137
|
+
- adjustQuantityOfInventoryItem
|
|
138
|
+
- adjustQuantity
|
|
139
|
+
- setItemCostAndSkuToBe
|
|
140
|
+
- setItemCostToBe
|
|
141
|
+
- getInventoryLevelsOfProduct
|
|
142
|
+
- Draft Order
|
|
143
|
+
- create
|
|
144
|
+
- createAndSendInvoice
|
|
145
|
+
- updateShippingAddress
|
|
146
|
+
- createFromCart
|
|
147
|
+
- fromCartToDraft
|
|
148
|
+
- Order
|
|
149
|
+
- getFulfillments
|
|
150
|
+
- createFulfillments
|
|
151
|
+
- completeFulfillment
|
|
152
|
+
- openFulfillment
|
|
153
|
+
- cancelFulfillment
|
|
154
|
+
- fulfillAllItems
|
|
155
|
+
- getById
|
|
156
|
+
- addAdditionalAttribute
|
|
157
|
+
- setTags
|
|
158
|
+
- getAll
|
|
159
|
+
- getInBatch
|
|
160
|
+
- create
|
|
161
|
+
- applyWeightAndCountryBasedShippingToOrder
|
|
162
|
+
- getShippingByWeight
|
|
163
|
+
- updateShippingAddress
|
|
164
|
+
- getAvailableShippingRatesByAddress
|
|
165
|
+
- getAvailableShippingRatesByCustomerDefaultAddress
|
|
166
|
+
- applyShippingToOrder
|
|
167
|
+
- duplicate
|
|
168
|
+
- OrderRisks
|
|
169
|
+
- getFromOrderById
|
|
170
|
+
- OrderRefunds
|
|
171
|
+
- getOrderRefunds
|
|
172
|
+
- createRefunds
|
|
173
|
+
- Product
|
|
174
|
+
- getAll
|
|
175
|
+
- getByTitle
|
|
176
|
+
- getByHandle
|
|
177
|
+
- getByProductType
|
|
178
|
+
- getById
|
|
179
|
+
- getCount
|
|
180
|
+
- getCountByPusblishedStatus
|
|
181
|
+
- update
|
|
182
|
+
- create
|
|
183
|
+
- delete
|
|
184
|
+
- publish
|
|
185
|
+
- unPublish
|
|
186
|
+
- get(numOfProducts)
|
|
187
|
+
- getMetafields
|
|
188
|
+
- getMetafield
|
|
189
|
+
- saveOrUpdateMetafield
|
|
190
|
+
- saveOrAddToMetafield
|
|
191
|
+
- deleteMetafield
|
|
192
|
+
- deleteMetafieldsByNamespace
|
|
193
|
+
- getUnpublishedInBatch
|
|
194
|
+
- getPublishedInBatchAfterDay
|
|
195
|
+
- getInBatch
|
|
196
|
+
- Variant
|
|
197
|
+
- create
|
|
198
|
+
- update
|
|
199
|
+
- getCount
|
|
200
|
+
- getMetafields
|
|
201
|
+
- saveOrUpdateMetafield
|
|
202
|
+
- getMetafield
|
|
203
|
+
- getById
|
|
204
|
+
- delete
|
|
205
|
+
- deleteMetafieldByKey
|
|
206
|
+
- deleteMetafield
|
|
207
|
+
- deleteMetafieldByKeys
|
|
208
|
+
- Webhook
|
|
209
|
+
- deleteAll
|
|
210
|
+
- delete (By ID)
|
|
211
|
+
- create
|
|
212
|
+
- getAll
|
|
213
|
+
- deleteByTopic
|
|
214
|
+
- updateWebhooksAPI
|
|
215
|
+
- Fulfillment Service
|
|
216
|
+
- create
|
|
217
|
+
- getAll
|
|
218
|
+
- addTrackingInfoToFulfillment
|
|
219
|
+
- Shop
|
|
220
|
+
- ShopDetails
|
|
221
|
+
- getShippingRates
|
|
222
|
+
- Collections
|
|
223
|
+
- create
|
|
224
|
+
- createCollect
|
|
225
|
+
- getAll (limit 250)
|
|
226
|
+
- delete
|
|
227
|
+
- removeCollects (With TimerQueue)
|
|
228
|
+
- Themes
|
|
229
|
+
- getAll (limit 250)
|
|
230
|
+
- getMainTheme (returns null if no theme has been found)
|
|
231
|
+
- Template
|
|
232
|
+
- get
|
|
233
|
+
- put
|
|
234
|
+
- Assets
|
|
235
|
+
- put
|
|
236
|
+
- Locations
|
|
237
|
+
- getAll
|
|
238
|
+
- Pages
|
|
239
|
+
- post
|
|
240
|
+
- put
|
|
241
|
+
- postMetafields
|
|
242
|
+
- Discounts
|
|
243
|
+
- getPercentageDiscountCodeForItem
|
|
244
|
+
- getFixedDiscountCodeForOrder
|
|
245
|
+
- removeDiscount
|
|
246
|
+
- Billing
|
|
247
|
+
- cancelBilling
|
|
248
|
+
- requestBilling
|
|
249
|
+
- getRecurringApplicationCharge
|
|
250
|
+
- getApplicationCharge
|
|
251
|
+
- singlePayment
|
|
252
|
+
- addUsage
|
|
253
|
+
- Shopify express route needed for installing the App.
|
|
254
|
+
- Shopify Hmac validation utilities.
|
|
255
|
+
- Shopify Rest Utils.
|
|
256
|
+
- Cache functionality.
|
|
257
|
+
|
|
258
|
+
|
package/addTypings.sh
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
image: node:20
|
|
2
|
+
|
|
3
|
+
pipelines:
|
|
4
|
+
branches:
|
|
5
|
+
master:
|
|
6
|
+
- step:
|
|
7
|
+
caches:
|
|
8
|
+
- node
|
|
9
|
+
script:
|
|
10
|
+
- npm install
|
|
11
|
+
- npm run lint
|
|
12
|
+
- step:
|
|
13
|
+
caches:
|
|
14
|
+
- node
|
|
15
|
+
script:
|
|
16
|
+
- npm install
|
|
17
|
+
- npm test
|
|
18
|
+
- step:
|
|
19
|
+
caches:
|
|
20
|
+
- node
|
|
21
|
+
script:
|
|
22
|
+
- npm install
|
|
23
|
+
- npm run build
|
|
24
|
+
- sh publish.sh
|
|
25
|
+
releaseBetaChannel:
|
|
26
|
+
- step:
|
|
27
|
+
caches:
|
|
28
|
+
- node
|
|
29
|
+
script:
|
|
30
|
+
- npm install
|
|
31
|
+
- npm test
|
|
32
|
+
- step:
|
|
33
|
+
caches:
|
|
34
|
+
- node
|
|
35
|
+
script:
|
|
36
|
+
- npm install
|
|
37
|
+
- npm run build
|
|
38
|
+
- sh publish.sh
|
package/index.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import CacheWrapper from './services/CacheWrapper';
|
|
2
|
+
import HmacValidator from './shopify/router/services/HmacValidator';
|
|
3
|
+
import { Logger } from './Logger';
|
|
4
|
+
import RestUtils from './shopify/router/services/RestUtils';
|
|
5
|
+
import { ShopifyAssetService } from './shopify/ShopifyAssetService';
|
|
6
|
+
import { ShopifyBillingService } from './shopify/ShopifyBillingService';
|
|
7
|
+
import { ShopifyCollectionService } from './shopify/ShopifyCollectionService';
|
|
8
|
+
import { ShopifyCustomerService } from './shopify/ShopifyCustomerService';
|
|
9
|
+
import { ShopifyDraftOrderService } from './shopify/ShopifyDraftOrderService';
|
|
10
|
+
import { ShopifyFulfillmentService } from './shopify/ShopifyFulfillmentService';
|
|
11
|
+
import { ShopifyInventoryService } from './shopify/ShopifyInventoryService';
|
|
12
|
+
import { ShopifyLocationService } from './shopify/ShopifyLocationService';
|
|
13
|
+
import { ShopifyMandatoryRouter } from './shopify/router/ShopifyMandatoryRouter';
|
|
14
|
+
import { ShopifyOrderRiskService } from './shopify/ShopifyOrderRiskService';
|
|
15
|
+
import { ShopifyOrderService } from './shopify/ShopifyOrderService';
|
|
16
|
+
import { ShopifyPageService } from './shopify/ShopifyPageService';
|
|
17
|
+
import { ShopifyProductService } from './shopify/ShopifyProductService';
|
|
18
|
+
import { ShopifyShopService } from './shopify/ShopifyShopService';
|
|
19
|
+
import { ShopifyTemplateService } from './shopify/ShopifyTemplateService';
|
|
20
|
+
import { ShopifyThemeService } from './shopify/ShopifyThemeService';
|
|
21
|
+
import { AxiosInstanceExtended, ShopifyUtils } from './shopify/ShopifyUtils';
|
|
22
|
+
import { ShopifyWebhookService } from './shopify/ShopifyWebhookService';
|
|
23
|
+
import StoreRateLimiter from './shopify/router/services/rateLimiter/StoreRateLimiter';
|
|
24
|
+
import { ShopifyDiscountService } from './shopify/ShopifyDiscountService';
|
|
25
|
+
import { ShopifyOrderRefundsService } from './shopify/ShopifyOrderRefundsService';
|
|
26
|
+
import WebhookSkipMiddleware from './shopify/router/WebhookSkipMiddleware';
|
|
27
|
+
import InspiraShopifyUnableToReserveInventoryError from './shopify/errors/InspiraShopifyUnableToReserveInventoryError';
|
|
28
|
+
import { ShopifyRouter } from './shopify/router/ShopifyRouter';
|
|
29
|
+
import ShopifyRouterBis from './shopify/router/ShopifyRouterBis';
|
|
30
|
+
import ShopifyRouterBisBis from './shopify/router/ShopifyRouterBisBis';
|
|
31
|
+
import ShopifyRouterBisBisBis from './shopify/router/ShopifyRouterBisBisBis';
|
|
32
|
+
import ShopifyRouterBisBisBisBis from './shopify/router/ShopifyRouterBisBisBisBis';
|
|
33
|
+
import { ShopifyDeliveryCustomisationService } from './shopify/ShopifyDeliveryCustomisationService';
|
|
34
|
+
import { ShopifyShippingZonesService } from './shopify/ShopifyShippingZonesService';
|
|
35
|
+
import { ShopifyCartTrasnformationService } from './shopify/ShopifyCartTrasnformationService';
|
|
36
|
+
import { ShopifyFunctionsProductDiscountsService } from './shopify/ShopifyFunctionsProductDiscountsService';
|
|
37
|
+
import { ShopifyAppService } from './shopify/ShopifyAppService';
|
|
38
|
+
|
|
39
|
+
export interface ILogger {
|
|
40
|
+
error: (...restOfName: any[]) => void;
|
|
41
|
+
info: (...restOfName: any[]) => void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IRest_Options { timeout: number, retries: number, logger: ILogger, debug: boolean; max_requests_per_sec: number; enableCache: boolean; cacheTimeInMiliseconds: number; }
|
|
45
|
+
|
|
46
|
+
export default class ShopifyRest {
|
|
47
|
+
public customer: ShopifyCustomerService;
|
|
48
|
+
public inventory: ShopifyInventoryService;
|
|
49
|
+
public order: ShopifyOrderService;
|
|
50
|
+
public product: ShopifyProductService;
|
|
51
|
+
public webhook: ShopifyWebhookService;
|
|
52
|
+
public fulfillment: ShopifyFulfillmentService;
|
|
53
|
+
public store: ShopifyShopService;
|
|
54
|
+
public collections: ShopifyCollectionService;
|
|
55
|
+
public themes: ShopifyThemeService;
|
|
56
|
+
public templates: ShopifyTemplateService;
|
|
57
|
+
public assets: ShopifyAssetService;
|
|
58
|
+
public billing: ShopifyBillingService;
|
|
59
|
+
public draftOrders: ShopifyDraftOrderService;
|
|
60
|
+
public locations: ShopifyLocationService;
|
|
61
|
+
public orderRisks: ShopifyOrderRiskService;
|
|
62
|
+
public shippingZonesService: ShopifyShippingZonesService;
|
|
63
|
+
public pages: ShopifyPageService;
|
|
64
|
+
public app: ShopifyAppService;
|
|
65
|
+
public discounts: ShopifyDiscountService;
|
|
66
|
+
public refunds: ShopifyOrderRefundsService;
|
|
67
|
+
public shopifyDeliveryCustomisationService: ShopifyDeliveryCustomisationService;
|
|
68
|
+
public shopifyCartTrasnformationService: ShopifyCartTrasnformationService;
|
|
69
|
+
public shopifyFunctionsProductDiscountsService: ShopifyFunctionsProductDiscountsService;
|
|
70
|
+
|
|
71
|
+
private instance: AxiosInstanceExtended = null;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
constructor(shop: string, token: string, privateAppApiKey: string, privateAppPassword: string, options: IRest_Options) {
|
|
75
|
+
if (options) {
|
|
76
|
+
if(options.debug) {
|
|
77
|
+
if(!options.logger) throw 'If debug mode is on then a looger must be set into options';
|
|
78
|
+
Logger._error = options.logger.error;
|
|
79
|
+
Logger._info = options.logger.info;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const instance = ShopifyUtils.getAxiosInstance(shop, token, privateAppApiKey, privateAppPassword, options);
|
|
83
|
+
this.customer = new ShopifyCustomerService(instance);
|
|
84
|
+
this.inventory = new ShopifyInventoryService(instance);
|
|
85
|
+
this.order = new ShopifyOrderService(instance);
|
|
86
|
+
this.product = new ShopifyProductService(instance);
|
|
87
|
+
this.webhook = new ShopifyWebhookService(instance);
|
|
88
|
+
this.fulfillment = new ShopifyFulfillmentService(instance);
|
|
89
|
+
this.store = new ShopifyShopService(instance);
|
|
90
|
+
this.collections = new ShopifyCollectionService(instance);
|
|
91
|
+
this.themes = new ShopifyThemeService(instance);
|
|
92
|
+
this.templates = new ShopifyTemplateService(instance);
|
|
93
|
+
this.assets = new ShopifyAssetService(instance);
|
|
94
|
+
this.billing = new ShopifyBillingService(instance);
|
|
95
|
+
this.draftOrders = new ShopifyDraftOrderService(instance);
|
|
96
|
+
this.locations = new ShopifyLocationService(instance);
|
|
97
|
+
this.orderRisks = new ShopifyOrderRiskService(instance);
|
|
98
|
+
this.pages = new ShopifyPageService(instance);
|
|
99
|
+
this.app = new ShopifyAppService(instance);
|
|
100
|
+
this.discounts = new ShopifyDiscountService(instance);
|
|
101
|
+
this.refunds = new ShopifyOrderRefundsService(instance);
|
|
102
|
+
this.shippingZonesService = new ShopifyShippingZonesService(instance);
|
|
103
|
+
this.shopifyDeliveryCustomisationService = new ShopifyDeliveryCustomisationService(instance);
|
|
104
|
+
this.shopifyCartTrasnformationService = new ShopifyCartTrasnformationService(instance);
|
|
105
|
+
this.shopifyFunctionsProductDiscountsService = new ShopifyFunctionsProductDiscountsService(instance);
|
|
106
|
+
this.instance = instance;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Enables or disables logging.
|
|
111
|
+
*/
|
|
112
|
+
public logging = async (enable: boolean): Promise<void> => {
|
|
113
|
+
Logger.enableLogging = enable;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
public getQueueInfo = () => {
|
|
117
|
+
return this.instance.getQueueInfo();
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const Router = ShopifyRouter;
|
|
122
|
+
export const RouterBis = ShopifyRouterBis;
|
|
123
|
+
export const RouterBisBis = ShopifyRouterBisBis;
|
|
124
|
+
export const RouterBisBisBis = ShopifyRouterBisBisBis;
|
|
125
|
+
export const RouterBisBisBisBis = ShopifyRouterBisBisBisBis;
|
|
126
|
+
export const MandatoryRoutes = ShopifyMandatoryRouter;
|
|
127
|
+
export const HmacUtils = HmacValidator;
|
|
128
|
+
export const ShopifyRestUtils = RestUtils;
|
|
129
|
+
export const RestCacheWrapper = CacheWrapper;
|
|
130
|
+
export const RateLimiter = StoreRateLimiter;
|
|
131
|
+
export const ShopifyWebhookSkipMiddleware = WebhookSkipMiddleware;
|
|
132
|
+
export const Error_InspiraShopifyUnableToReserveInventoryError = InspiraShopifyUnableToReserveInventoryError;
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sommpicks/sommpicks-shopify",
|
|
3
|
+
"version": "24.12.0",
|
|
4
|
+
"publishConfig": { "access": "restricted" },
|
|
5
|
+
"description": "Shopify REST API & GraphQL calls",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/indexBuild.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "jest --runInBand --forceExit --verbose",
|
|
10
|
+
"test-file": "jest --runInBand --forceExit --verbose --colors ShopifyWebhookService.test.ts",
|
|
11
|
+
"build": "rm -rf dist && tsc -p . && sh addTypings.sh",
|
|
12
|
+
"lint": "eslint -c .eslintrc.js --ext .ts,.tsx ./"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://kimy82@bitbucket.org/inspiradigital/inspira-shopify.git"
|
|
17
|
+
},
|
|
18
|
+
"author": "Inspira Digital",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"homepage": "https://bitbucket.org/inspiradigital/inspira-shopify#readme",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@sommpicks/sommpicks-shopify-rate-limit": "^2.0.0",
|
|
23
|
+
"axios-cache-interceptor": "^1.5.1",
|
|
24
|
+
"axios": "^1.6.8",
|
|
25
|
+
"axios-retry": "^4.1.0",
|
|
26
|
+
"express": "^4.17.2",
|
|
27
|
+
"graphql": "^15.4.0",
|
|
28
|
+
"graphql-tag": "^2.11.0",
|
|
29
|
+
"moment": "^2.29.1",
|
|
30
|
+
"parse-link-header": "^2.0.0",
|
|
31
|
+
"querystring": "^0.2.0",
|
|
32
|
+
"timer-queue": "^1.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/express": "^4.17.2",
|
|
36
|
+
"@types/jest": "^29.5.1",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"@types/parse-link-header": "^1.0.0",
|
|
39
|
+
"@types/sinon-express-mock": "^1.3.5",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
41
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
42
|
+
"eslint": "^8.51.0",
|
|
43
|
+
"jest": "^29.5.0",
|
|
44
|
+
"ts-jest": "^29.1.0",
|
|
45
|
+
"typescript": "^4.6.2"
|
|
46
|
+
},
|
|
47
|
+
"jest": {
|
|
48
|
+
"verbose": true,
|
|
49
|
+
"testURL": "http://localhost/",
|
|
50
|
+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(ts)$",
|
|
51
|
+
"preset": "ts-jest",
|
|
52
|
+
"moduleFileExtensions": [
|
|
53
|
+
"js",
|
|
54
|
+
"ts"
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
}
|
package/publish.sh
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Extract package information using Node.js
|
|
4
|
+
PACKAGE_VERSION=$(node -e "console.log(require('./package.json').version)")
|
|
5
|
+
IS_BETA=$(node -e "console.log(require('./package.json').version.includes('beta'))")
|
|
6
|
+
PACKAGE_NAME=$(node -e "console.log(require('./package.json').name)")
|
|
7
|
+
|
|
8
|
+
# Check if the package version already exists on npm
|
|
9
|
+
if npm show "$PACKAGE_NAME@$PACKAGE_VERSION" 2>/dev/null; then
|
|
10
|
+
echo "Skipping publish, package $PACKAGE_NAME@$PACKAGE_VERSION already published"
|
|
11
|
+
else
|
|
12
|
+
# Conditional publishing based on beta flag
|
|
13
|
+
if [ $IS_BETA = "true" ]; then
|
|
14
|
+
echo "Publishing version $PACKAGE_VERSION in channel Beta"
|
|
15
|
+
npm publish --tag beta
|
|
16
|
+
else
|
|
17
|
+
echo "Publishing version $PACKAGE_VERSION in channel Prod"
|
|
18
|
+
npm publish
|
|
19
|
+
fi
|
|
20
|
+
fi
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export default class CacheWrapper<T> {
|
|
2
|
+
|
|
3
|
+
private records: Map<string, any> = new Map<string, any>();
|
|
4
|
+
|
|
5
|
+
constructor(private maxSize: number, private call: any) { }
|
|
6
|
+
|
|
7
|
+
public execute = async (...args): Promise<T> => {
|
|
8
|
+
return new Promise<T> ((resolve) => {
|
|
9
|
+
const key = args[0];
|
|
10
|
+
if(this.records.has(key)){
|
|
11
|
+
resolve(this.records.get(key));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const value = this.call.apply(null, args);
|
|
15
|
+
this.clearEntry();
|
|
16
|
+
this.records.set(key, value);
|
|
17
|
+
resolve(value);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
public clear = () => {
|
|
22
|
+
this.records.clear();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
public clearEntry = () => {
|
|
26
|
+
if(this.records.size > this.maxSize) {
|
|
27
|
+
this.records.delete(this.records.keys().next().value);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|