@sommpicks/sommpicks-shopify 24.12.8 → 24.12.10

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.
Files changed (193) hide show
  1. package/.eslintrc.js +26 -0
  2. package/dist/Logger.d.ts +1 -0
  3. package/dist/Logger.d.ts.map +1 -0
  4. package/dist/Logger.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/indexBuild.d.ts +1 -0
  9. package/dist/services/CacheWrapper.d.ts +1 -0
  10. package/dist/services/CacheWrapper.d.ts.map +1 -0
  11. package/dist/services/CacheWrapper.js.map +1 -1
  12. package/dist/services/CountryCodeService.d.ts +1 -0
  13. package/dist/services/CountryCodeService.d.ts.map +1 -0
  14. package/dist/services/CountryCodeService.js.map +1 -1
  15. package/dist/shopify/ShopifyAppService.d.ts +1 -0
  16. package/dist/shopify/ShopifyAppService.d.ts.map +1 -0
  17. package/dist/shopify/ShopifyAppService.js.map +1 -1
  18. package/dist/shopify/ShopifyAssetService.d.ts +1 -0
  19. package/dist/shopify/ShopifyAssetService.d.ts.map +1 -0
  20. package/dist/shopify/ShopifyAssetService.js.map +1 -1
  21. package/dist/shopify/ShopifyBillingService.d.ts +1 -0
  22. package/dist/shopify/ShopifyBillingService.d.ts.map +1 -0
  23. package/dist/shopify/ShopifyBillingService.js.map +1 -1
  24. package/dist/shopify/ShopifyCartTrasnformationService.d.ts +1 -0
  25. package/dist/shopify/ShopifyCartTrasnformationService.d.ts.map +1 -0
  26. package/dist/shopify/ShopifyCartTrasnformationService.js.map +1 -1
  27. package/dist/shopify/ShopifyCollectionService.d.ts +1 -0
  28. package/dist/shopify/ShopifyCollectionService.d.ts.map +1 -0
  29. package/dist/shopify/ShopifyCollectionService.js.map +1 -1
  30. package/dist/shopify/ShopifyCustomerService.d.ts +1 -0
  31. package/dist/shopify/ShopifyCustomerService.d.ts.map +1 -0
  32. package/dist/shopify/ShopifyCustomerService.js.map +1 -1
  33. package/dist/shopify/ShopifyDeliveryCustomisationService.d.ts +1 -0
  34. package/dist/shopify/ShopifyDeliveryCustomisationService.d.ts.map +1 -0
  35. package/dist/shopify/ShopifyDeliveryCustomisationService.js.map +1 -1
  36. package/dist/shopify/ShopifyDiscountService.d.ts +1 -0
  37. package/dist/shopify/ShopifyDiscountService.d.ts.map +1 -0
  38. package/dist/shopify/ShopifyDiscountService.js.map +1 -1
  39. package/dist/shopify/ShopifyDraftOrderService.d.ts +1 -0
  40. package/dist/shopify/ShopifyDraftOrderService.d.ts.map +1 -0
  41. package/dist/shopify/ShopifyDraftOrderService.js.map +1 -1
  42. package/dist/shopify/ShopifyFulfillmentService.d.ts +1 -0
  43. package/dist/shopify/ShopifyFulfillmentService.d.ts.map +1 -0
  44. package/dist/shopify/ShopifyFulfillmentService.js.map +1 -1
  45. package/dist/shopify/ShopifyFunctionsProductDiscountsService.d.ts +1 -0
  46. package/dist/shopify/ShopifyFunctionsProductDiscountsService.d.ts.map +1 -0
  47. package/dist/shopify/ShopifyFunctionsProductDiscountsService.js.map +1 -1
  48. package/dist/shopify/ShopifyInventoryService.d.ts +1 -0
  49. package/dist/shopify/ShopifyInventoryService.d.ts.map +1 -0
  50. package/dist/shopify/ShopifyInventoryService.js.map +1 -1
  51. package/dist/shopify/ShopifyLocationService.d.ts +1 -0
  52. package/dist/shopify/ShopifyLocationService.d.ts.map +1 -0
  53. package/dist/shopify/ShopifyLocationService.js.map +1 -1
  54. package/dist/shopify/ShopifyOrderRefundsService.d.ts +1 -0
  55. package/dist/shopify/ShopifyOrderRefundsService.d.ts.map +1 -0
  56. package/dist/shopify/ShopifyOrderRefundsService.js.map +1 -1
  57. package/dist/shopify/ShopifyOrderRiskService.d.ts +1 -0
  58. package/dist/shopify/ShopifyOrderRiskService.d.ts.map +1 -0
  59. package/dist/shopify/ShopifyOrderRiskService.js.map +1 -1
  60. package/dist/shopify/ShopifyOrderService.d.ts +1 -0
  61. package/dist/shopify/ShopifyOrderService.d.ts.map +1 -0
  62. package/dist/shopify/ShopifyOrderService.js.map +1 -1
  63. package/dist/shopify/ShopifyPageService.d.ts +1 -0
  64. package/dist/shopify/ShopifyPageService.d.ts.map +1 -0
  65. package/dist/shopify/ShopifyPageService.js.map +1 -1
  66. package/dist/shopify/ShopifyProductService.d.ts +1 -0
  67. package/dist/shopify/ShopifyProductService.d.ts.map +1 -0
  68. package/dist/shopify/ShopifyProductService.js.map +1 -1
  69. package/dist/shopify/ShopifyShippingZonesService.d.ts +1 -0
  70. package/dist/shopify/ShopifyShippingZonesService.d.ts.map +1 -0
  71. package/dist/shopify/ShopifyShippingZonesService.js.map +1 -1
  72. package/dist/shopify/ShopifyShopService.d.ts +1 -0
  73. package/dist/shopify/ShopifyShopService.d.ts.map +1 -0
  74. package/dist/shopify/ShopifyShopService.js.map +1 -1
  75. package/dist/shopify/ShopifyTemplateService.d.ts +1 -0
  76. package/dist/shopify/ShopifyTemplateService.d.ts.map +1 -0
  77. package/dist/shopify/ShopifyTemplateService.js.map +1 -1
  78. package/dist/shopify/ShopifyThemeService.d.ts +1 -0
  79. package/dist/shopify/ShopifyThemeService.d.ts.map +1 -0
  80. package/dist/shopify/ShopifyThemeService.js.map +1 -1
  81. package/dist/shopify/ShopifyUtils.d.ts +1 -0
  82. package/dist/shopify/ShopifyUtils.d.ts.map +1 -0
  83. package/dist/shopify/ShopifyUtils.js.map +1 -1
  84. package/dist/shopify/ShopifyWebhookService.d.ts +1 -0
  85. package/dist/shopify/ShopifyWebhookService.d.ts.map +1 -0
  86. package/dist/shopify/ShopifyWebhookService.js.map +1 -1
  87. package/dist/shopify/base/APIVersion.d.ts +1 -0
  88. package/dist/shopify/base/APIVersion.d.ts.map +1 -0
  89. package/dist/shopify/base/APIVersion.js.map +1 -1
  90. package/dist/shopify/base/AbstractService.d.ts +1 -0
  91. package/dist/shopify/base/AbstractService.d.ts.map +1 -0
  92. package/dist/shopify/base/AbstractService.js.map +1 -1
  93. package/dist/shopify/base/ErrorHelper.d.ts +1 -0
  94. package/dist/shopify/base/ErrorHelper.d.ts.map +1 -0
  95. package/dist/shopify/base/ErrorHelper.js +17 -12
  96. package/dist/shopify/base/ErrorHelper.js.map +1 -1
  97. package/dist/shopify/errors/InspiraShopifyCustomError.d.ts +1 -0
  98. package/dist/shopify/errors/InspiraShopifyCustomError.d.ts.map +1 -0
  99. package/dist/shopify/errors/InspiraShopifyCustomError.js.map +1 -1
  100. package/dist/shopify/errors/InspiraShopifyError.d.ts +1 -0
  101. package/dist/shopify/errors/InspiraShopifyError.d.ts.map +1 -0
  102. package/dist/shopify/errors/InspiraShopifyError.js.map +1 -1
  103. package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.d.ts +1 -0
  104. package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.d.ts.map +1 -0
  105. package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.js.map +1 -1
  106. package/dist/shopify/helpers/ShopifyProductServiceHelper.d.ts +1 -0
  107. package/dist/shopify/helpers/ShopifyProductServiceHelper.d.ts.map +1 -0
  108. package/dist/shopify/helpers/ShopifyProductServiceHelper.js.map +1 -1
  109. package/dist/shopify/product/ShopifyProductCountService.d.ts +1 -0
  110. package/dist/shopify/product/ShopifyProductCountService.d.ts.map +1 -0
  111. package/dist/shopify/product/ShopifyProductCountService.js.map +1 -1
  112. package/dist/shopify/product/ShopifyProductListService.d.ts +1 -0
  113. package/dist/shopify/product/ShopifyProductListService.d.ts.map +1 -0
  114. package/dist/shopify/product/ShopifyProductListService.js.map +1 -1
  115. package/dist/shopify/product/ShopifyProductMetafieldsService.d.ts +1 -0
  116. package/dist/shopify/product/ShopifyProductMetafieldsService.d.ts.map +1 -0
  117. package/dist/shopify/product/ShopifyProductMetafieldsService.js.map +1 -1
  118. package/dist/shopify/product/ShopifyProductPublicationsService.d.ts +1 -0
  119. package/dist/shopify/product/ShopifyProductPublicationsService.d.ts.map +1 -0
  120. package/dist/shopify/product/ShopifyProductPublicationsService.js.map +1 -1
  121. package/dist/shopify/product/ShopifyVariantService.d.ts +1 -0
  122. package/dist/shopify/product/ShopifyVariantService.d.ts.map +1 -0
  123. package/dist/shopify/product/ShopifyVariantService.js.map +1 -1
  124. package/dist/shopify/router/ShopifyMandatoryRouter.d.ts +1 -0
  125. package/dist/shopify/router/ShopifyMandatoryRouter.d.ts.map +1 -0
  126. package/dist/shopify/router/ShopifyMandatoryRouter.js.map +1 -1
  127. package/dist/shopify/router/ShopifyRouter.d.ts +1 -0
  128. package/dist/shopify/router/ShopifyRouter.d.ts.map +1 -0
  129. package/dist/shopify/router/ShopifyRouter.js +62 -3
  130. package/dist/shopify/router/ShopifyRouter.js.map +1 -1
  131. package/dist/shopify/router/ShopifyRouterBis.d.ts +1 -0
  132. package/dist/shopify/router/ShopifyRouterBis.d.ts.map +1 -0
  133. package/dist/shopify/router/ShopifyRouterBis.js.map +1 -1
  134. package/dist/shopify/router/ShopifyRouterBisBis.d.ts +1 -0
  135. package/dist/shopify/router/ShopifyRouterBisBis.d.ts.map +1 -0
  136. package/dist/shopify/router/ShopifyRouterBisBis.js.map +1 -1
  137. package/dist/shopify/router/ShopifyRouterBisBisBis.d.ts +1 -0
  138. package/dist/shopify/router/ShopifyRouterBisBisBis.d.ts.map +1 -0
  139. package/dist/shopify/router/ShopifyRouterBisBisBis.js.map +1 -1
  140. package/dist/shopify/router/ShopifyRouterBisBisBisBis.d.ts +1 -0
  141. package/dist/shopify/router/ShopifyRouterBisBisBisBis.d.ts.map +1 -0
  142. package/dist/shopify/router/ShopifyRouterBisBisBisBis.js.map +1 -1
  143. package/dist/shopify/router/WebhookSkipMiddleware.d.ts +1 -0
  144. package/dist/shopify/router/WebhookSkipMiddleware.d.ts.map +1 -0
  145. package/dist/shopify/router/WebhookSkipMiddleware.js.map +1 -1
  146. package/dist/shopify/router/services/CryptoService.d.ts +2 -0
  147. package/dist/shopify/router/services/CryptoService.d.ts.map +1 -0
  148. package/dist/shopify/router/services/CryptoService.js.map +1 -1
  149. package/dist/shopify/router/services/HmacValidator.d.ts +1 -0
  150. package/dist/shopify/router/services/HmacValidator.d.ts.map +1 -0
  151. package/dist/shopify/router/services/HmacValidator.js.map +1 -1
  152. package/dist/shopify/router/services/OauthService.d.ts +1 -0
  153. package/dist/shopify/router/services/OauthService.d.ts.map +1 -0
  154. package/dist/shopify/router/services/OauthService.js.map +1 -1
  155. package/dist/shopify/router/services/RestUtils.d.ts +1 -0
  156. package/dist/shopify/router/services/RestUtils.d.ts.map +1 -0
  157. package/dist/shopify/router/services/RestUtils.js.map +1 -1
  158. package/dist/shopify/router/services/rateLimiter/MemoryStores.d.ts +1 -0
  159. package/dist/shopify/router/services/rateLimiter/MemoryStores.d.ts.map +1 -0
  160. package/dist/shopify/router/services/rateLimiter/MemoryStores.js.map +1 -1
  161. package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.d.ts +1 -0
  162. package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.d.ts.map +1 -0
  163. package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.js.map +1 -1
  164. package/dist/test/router/ShopifyRouter.test.d.ts +1 -0
  165. package/dist/test/router/ShopifyRouter.test.d.ts.map +1 -0
  166. package/dist/test/router/ShopifyRouter.test.js.map +1 -1
  167. package/dist/test/router/WebhookSkipMiddleware.test.d.ts +1 -0
  168. package/dist/test/router/WebhookSkipMiddleware.test.d.ts.map +1 -0
  169. package/dist/test/router/WebhookSkipMiddleware.test.js.map +1 -1
  170. package/dist/test/router/services/HmacValidator.test.d.ts +1 -0
  171. package/dist/test/router/services/HmacValidator.test.d.ts.map +1 -0
  172. package/dist/test/router/services/HmacValidator.test.js.map +1 -1
  173. package/dist/test/router/services/RestUtils.test.d.ts +1 -0
  174. package/dist/test/router/services/RestUtils.test.d.ts.map +1 -0
  175. package/dist/test/router/services/RestUtils.test.js.map +1 -1
  176. package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.d.ts +1 -0
  177. package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.d.ts.map +1 -0
  178. package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.js.map +1 -1
  179. package/dist/test/services/CacheWrapper.test.d.ts +1 -0
  180. package/dist/test/services/CacheWrapper.test.d.ts.map +1 -0
  181. package/dist/test/services/CacheWrapper.test.js.map +1 -1
  182. package/dist/test/shopify/ShopifyOrderService.test.d.ts +1 -0
  183. package/dist/test/shopify/ShopifyOrderService.test.d.ts.map +1 -0
  184. package/dist/test/shopify/ShopifyOrderService.test.js.map +1 -1
  185. package/dist/test/shopify/ShopifyProductService.test.d.ts +1 -0
  186. package/dist/test/shopify/ShopifyProductService.test.d.ts.map +1 -0
  187. package/dist/test/shopify/ShopifyProductService.test.js.map +1 -1
  188. package/dist/test/shopify/ShopifyWebhookService.test.d.ts +1 -0
  189. package/dist/test/shopify/ShopifyWebhookService.test.d.ts.map +1 -0
  190. package/dist/test/shopify/ShopifyWebhookService.test.js.map +1 -1
  191. package/package.json +8 -1
  192. package/shopify/router/ShopifyRouter.ts +62 -4
  193. package/tsconfig.json +2 -0
@@ -13,13 +13,23 @@ export class ShopifyRouter {
13
13
 
14
14
  constructor( private shop_secret: string, private shop_key: string, private appBaseUrl: string, private endpointUri: string, private getScopes: (shop: string) => string | Promise<string>, private callback: (accessToken: string, shop: string, host: string, expresResponse: Response, secFetchDest: boolean, error: any) => void) {
15
15
  this.cryptoService = new CryptoService();
16
- Logger.info(`cryptoservice: ${this.cryptoService}`);
17
16
  }
18
17
 
19
18
  public buildRoutes(): express.Router {
20
19
  //initial call to /shopify
21
20
  router.get('/', async (req,res,next) => {
22
21
  Logger.info(`ShopifyRouter - request: ${req}`);
22
+ try {
23
+ if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {
24
+ // eslint-disable-next-line no-console
25
+ console.info('[sommpicks-shopify][ShopifyRouter][/shopify request]', {
26
+ method: req.method,
27
+ path: (req as any).path,
28
+ query: (req as any).query,
29
+ headers: { 'sec-fetch-dest': (req as any).headers?.['sec-fetch-dest'] }
30
+ });
31
+ }
32
+ } catch { /* ignore debug logging errors */ }
23
33
  const scopes = await this.getScopes(req.query.shop as string);
24
34
  Logger.info(`ShopifyRouter - scopes: ${scopes}`);
25
35
  res.locals.scopes = scopes;
@@ -27,6 +37,20 @@ export class ShopifyRouter {
27
37
  }, this.installRoute);
28
38
  // endpoint when merchant accepts the installation
29
39
  router.get('/callback', this.callBackRoute);
40
+ router.get('/auth/callback', this.callBackRoute);
41
+ Logger.info('build routes was hit!');
42
+ try {
43
+ if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {
44
+ const r: any = router as any;
45
+ const routes = Array.isArray(r?.stack)
46
+ ? r.stack
47
+ .filter((l: any) => l && l.route)
48
+ .map((l: any) => ({ path: l.route.path, methods: Object.keys(l.route.methods || {}) }))
49
+ : [];
50
+ // eslint-disable-next-line no-console
51
+ console.info('[sommpicks-shopify][ShopifyRouter][routes]', routes);
52
+ }
53
+ } catch { /* ignore debug logging errors */ }
30
54
  return router;
31
55
  }
32
56
 
@@ -37,13 +61,18 @@ export class ShopifyRouter {
37
61
  const hmac = expresRequest.query.hmac as string;
38
62
  const code = expresRequest.query.code as string;
39
63
  const host = expresRequest.query.host as string;
64
+ Logger.info('we are using the updated version');
65
+ console.log('we are console logging the updated version');
40
66
  Logger.info(`ShopifyRouter - callBackRoute From shopify ${code}`);
41
67
  if (shop && hmac && code) {
42
68
  const map = Object.assign({}, expresRequest.query);
43
69
  delete map['signature'];
44
70
  delete map['hmac'];
45
71
  const secFetchDest = req.headers['sec-fetch-dest'];
46
- const message = querystring.stringify(map as any);
72
+ const sortedKeys = Object.keys(map).sort();
73
+ const sortedMap: any = {};
74
+ sortedKeys.forEach(key => sortedMap[key] = map[key]);
75
+ const message = querystring.stringify(sortedMap);
47
76
 
48
77
  const hashEquals = this.cryptoService.checkHash(this.cryptoService.generateHash(message, this.shop_secret), hmac);
49
78
  if (!hashEquals) { expresResponse.status(401).send('HMAC validation failed'); return; }
@@ -85,13 +114,42 @@ export class ShopifyRouter {
85
114
  private installUrl(shop: string, scopes: string): string {
86
115
  // this URL is used to install the app. you can get it and run it on the browser, it should install the app
87
116
  Logger.info(`installURL shop: ${shop}`);
88
- return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}`;
117
+ // Explicitly request offline (permanent) access tokens
118
+ return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}&access_mode=offline`;
89
119
  }
90
120
 
91
121
  private redirectUri(): string {
92
- // the callback for when the merchant has approved the installation
122
+ // the callback for when the merchant has approved the request
93
123
  return `${this.appBaseUrl}${this.endpointUri}/callback`;
94
124
  }
95
125
  }
96
126
 
127
+ // Debug export and router shape when enabled via env
128
+ try {
129
+ if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {
130
+ const exportMeta = {
131
+ classType: typeof ShopifyRouter,
132
+ className: (ShopifyRouter as any)?.name,
133
+ prototypeMethods: Object.getOwnPropertyNames((ShopifyRouter as any)?.prototype || {}).filter(m => m !== 'constructor')
134
+ };
135
+ // eslint-disable-next-line no-console
136
+ console.info('[sommpicks-shopify][ShopifyRouter][export-meta]', exportMeta);
137
+
138
+ const r: any = router as any;
139
+ const routerMeta = {
140
+ type: typeof router,
141
+ isMiddleware: typeof router === 'function',
142
+ keys: Object.keys(r || {}),
143
+ stackLength: Array.isArray(r?.stack) ? r.stack.length : undefined,
144
+ props: {
145
+ caseSensitive: r?.caseSensitive,
146
+ mergeParams: r?.mergeParams,
147
+ strict: r?.strict
148
+ }
149
+ };
150
+ // eslint-disable-next-line no-console
151
+ console.info('[sommpicks-shopify][ShopifyRouter][express-router-meta]', routerMeta);
152
+ }
153
+ } catch { /* ignore debug logging errors */ }
154
+
97
155
  export default ShopifyRouter;
package/tsconfig.json CHANGED
@@ -4,6 +4,8 @@
4
4
  "target": "es6",
5
5
  "module": "commonjs",
6
6
  "sourceMap": true,
7
+ "inlineSources": true,
8
+ "declarationMap": true,
7
9
  "typeRoots": ["./node_modules/@types", "./typings"],
8
10
  "declaration": true
9
11
  }