@sommpicks/sommpicks-shopify 24.12.7 → 24.12.9
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/.eslintrc.js +26 -0
- package/dist/Logger.d.ts +1 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/indexBuild.d.ts +1 -0
- package/dist/services/CacheWrapper.d.ts +1 -0
- package/dist/services/CacheWrapper.d.ts.map +1 -0
- package/dist/services/CacheWrapper.js.map +1 -1
- package/dist/services/CountryCodeService.d.ts +1 -0
- package/dist/services/CountryCodeService.d.ts.map +1 -0
- package/dist/services/CountryCodeService.js.map +1 -1
- package/dist/shopify/ShopifyAppService.d.ts +1 -0
- package/dist/shopify/ShopifyAppService.d.ts.map +1 -0
- package/dist/shopify/ShopifyAppService.js.map +1 -1
- package/dist/shopify/ShopifyAssetService.d.ts +1 -0
- package/dist/shopify/ShopifyAssetService.d.ts.map +1 -0
- package/dist/shopify/ShopifyAssetService.js.map +1 -1
- package/dist/shopify/ShopifyBillingService.d.ts +1 -0
- package/dist/shopify/ShopifyBillingService.d.ts.map +1 -0
- package/dist/shopify/ShopifyBillingService.js.map +1 -1
- package/dist/shopify/ShopifyCartTrasnformationService.d.ts +1 -0
- package/dist/shopify/ShopifyCartTrasnformationService.d.ts.map +1 -0
- package/dist/shopify/ShopifyCartTrasnformationService.js.map +1 -1
- package/dist/shopify/ShopifyCollectionService.d.ts +1 -0
- package/dist/shopify/ShopifyCollectionService.d.ts.map +1 -0
- package/dist/shopify/ShopifyCollectionService.js.map +1 -1
- package/dist/shopify/ShopifyCustomerService.d.ts +1 -0
- package/dist/shopify/ShopifyCustomerService.d.ts.map +1 -0
- package/dist/shopify/ShopifyCustomerService.js.map +1 -1
- package/dist/shopify/ShopifyDeliveryCustomisationService.d.ts +1 -0
- package/dist/shopify/ShopifyDeliveryCustomisationService.d.ts.map +1 -0
- package/dist/shopify/ShopifyDeliveryCustomisationService.js.map +1 -1
- package/dist/shopify/ShopifyDiscountService.d.ts +1 -0
- package/dist/shopify/ShopifyDiscountService.d.ts.map +1 -0
- package/dist/shopify/ShopifyDiscountService.js.map +1 -1
- package/dist/shopify/ShopifyDraftOrderService.d.ts +1 -0
- package/dist/shopify/ShopifyDraftOrderService.d.ts.map +1 -0
- package/dist/shopify/ShopifyDraftOrderService.js.map +1 -1
- package/dist/shopify/ShopifyFulfillmentService.d.ts +1 -0
- package/dist/shopify/ShopifyFulfillmentService.d.ts.map +1 -0
- package/dist/shopify/ShopifyFulfillmentService.js.map +1 -1
- package/dist/shopify/ShopifyFunctionsProductDiscountsService.d.ts +1 -0
- package/dist/shopify/ShopifyFunctionsProductDiscountsService.d.ts.map +1 -0
- package/dist/shopify/ShopifyFunctionsProductDiscountsService.js.map +1 -1
- package/dist/shopify/ShopifyInventoryService.d.ts +1 -0
- package/dist/shopify/ShopifyInventoryService.d.ts.map +1 -0
- package/dist/shopify/ShopifyInventoryService.js.map +1 -1
- package/dist/shopify/ShopifyLocationService.d.ts +1 -0
- package/dist/shopify/ShopifyLocationService.d.ts.map +1 -0
- package/dist/shopify/ShopifyLocationService.js.map +1 -1
- package/dist/shopify/ShopifyOrderRefundsService.d.ts +1 -0
- package/dist/shopify/ShopifyOrderRefundsService.d.ts.map +1 -0
- package/dist/shopify/ShopifyOrderRefundsService.js.map +1 -1
- package/dist/shopify/ShopifyOrderRiskService.d.ts +1 -0
- package/dist/shopify/ShopifyOrderRiskService.d.ts.map +1 -0
- package/dist/shopify/ShopifyOrderRiskService.js.map +1 -1
- package/dist/shopify/ShopifyOrderService.d.ts +1 -0
- package/dist/shopify/ShopifyOrderService.d.ts.map +1 -0
- package/dist/shopify/ShopifyOrderService.js.map +1 -1
- package/dist/shopify/ShopifyPageService.d.ts +1 -0
- package/dist/shopify/ShopifyPageService.d.ts.map +1 -0
- package/dist/shopify/ShopifyPageService.js.map +1 -1
- package/dist/shopify/ShopifyProductService.d.ts +1 -0
- package/dist/shopify/ShopifyProductService.d.ts.map +1 -0
- package/dist/shopify/ShopifyProductService.js.map +1 -1
- package/dist/shopify/ShopifyShippingZonesService.d.ts +1 -0
- package/dist/shopify/ShopifyShippingZonesService.d.ts.map +1 -0
- package/dist/shopify/ShopifyShippingZonesService.js.map +1 -1
- package/dist/shopify/ShopifyShopService.d.ts +1 -0
- package/dist/shopify/ShopifyShopService.d.ts.map +1 -0
- package/dist/shopify/ShopifyShopService.js.map +1 -1
- package/dist/shopify/ShopifyTemplateService.d.ts +1 -0
- package/dist/shopify/ShopifyTemplateService.d.ts.map +1 -0
- package/dist/shopify/ShopifyTemplateService.js.map +1 -1
- package/dist/shopify/ShopifyThemeService.d.ts +1 -0
- package/dist/shopify/ShopifyThemeService.d.ts.map +1 -0
- package/dist/shopify/ShopifyThemeService.js.map +1 -1
- package/dist/shopify/ShopifyUtils.d.ts +1 -0
- package/dist/shopify/ShopifyUtils.d.ts.map +1 -0
- package/dist/shopify/ShopifyUtils.js.map +1 -1
- package/dist/shopify/ShopifyWebhookService.d.ts +1 -0
- package/dist/shopify/ShopifyWebhookService.d.ts.map +1 -0
- package/dist/shopify/ShopifyWebhookService.js.map +1 -1
- package/dist/shopify/base/APIVersion.d.ts +1 -0
- package/dist/shopify/base/APIVersion.d.ts.map +1 -0
- package/dist/shopify/base/APIVersion.js +1 -1
- package/dist/shopify/base/APIVersion.js.map +1 -1
- package/dist/shopify/base/AbstractService.d.ts +1 -0
- package/dist/shopify/base/AbstractService.d.ts.map +1 -0
- package/dist/shopify/base/AbstractService.js.map +1 -1
- package/dist/shopify/base/ErrorHelper.d.ts +1 -0
- package/dist/shopify/base/ErrorHelper.d.ts.map +1 -0
- package/dist/shopify/base/ErrorHelper.js.map +1 -1
- package/dist/shopify/errors/InspiraShopifyCustomError.d.ts +1 -0
- package/dist/shopify/errors/InspiraShopifyCustomError.d.ts.map +1 -0
- package/dist/shopify/errors/InspiraShopifyCustomError.js.map +1 -1
- package/dist/shopify/errors/InspiraShopifyError.d.ts +1 -0
- package/dist/shopify/errors/InspiraShopifyError.d.ts.map +1 -0
- package/dist/shopify/errors/InspiraShopifyError.js.map +1 -1
- package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.d.ts +1 -0
- package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.d.ts.map +1 -0
- package/dist/shopify/errors/InspiraShopifyUnableToReserveInventoryError.js.map +1 -1
- package/dist/shopify/helpers/ShopifyProductServiceHelper.d.ts +1 -0
- package/dist/shopify/helpers/ShopifyProductServiceHelper.d.ts.map +1 -0
- package/dist/shopify/helpers/ShopifyProductServiceHelper.js.map +1 -1
- package/dist/shopify/product/ShopifyProductCountService.d.ts +1 -0
- package/dist/shopify/product/ShopifyProductCountService.d.ts.map +1 -0
- package/dist/shopify/product/ShopifyProductCountService.js.map +1 -1
- package/dist/shopify/product/ShopifyProductListService.d.ts +1 -0
- package/dist/shopify/product/ShopifyProductListService.d.ts.map +1 -0
- package/dist/shopify/product/ShopifyProductListService.js.map +1 -1
- package/dist/shopify/product/ShopifyProductMetafieldsService.d.ts +1 -0
- package/dist/shopify/product/ShopifyProductMetafieldsService.d.ts.map +1 -0
- package/dist/shopify/product/ShopifyProductMetafieldsService.js.map +1 -1
- package/dist/shopify/product/ShopifyProductPublicationsService.d.ts +1 -0
- package/dist/shopify/product/ShopifyProductPublicationsService.d.ts.map +1 -0
- package/dist/shopify/product/ShopifyProductPublicationsService.js.map +1 -1
- package/dist/shopify/product/ShopifyVariantService.d.ts +1 -0
- package/dist/shopify/product/ShopifyVariantService.d.ts.map +1 -0
- package/dist/shopify/product/ShopifyVariantService.js.map +1 -1
- package/dist/shopify/router/ShopifyMandatoryRouter.d.ts +1 -0
- package/dist/shopify/router/ShopifyMandatoryRouter.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyMandatoryRouter.js.map +1 -1
- package/dist/shopify/router/ShopifyRouter.d.ts +1 -0
- package/dist/shopify/router/ShopifyRouter.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyRouter.js +72 -1
- package/dist/shopify/router/ShopifyRouter.js.map +1 -1
- package/dist/shopify/router/ShopifyRouterBis.d.ts +1 -0
- package/dist/shopify/router/ShopifyRouterBis.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyRouterBis.js.map +1 -1
- package/dist/shopify/router/ShopifyRouterBisBis.d.ts +1 -0
- package/dist/shopify/router/ShopifyRouterBisBis.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyRouterBisBis.js.map +1 -1
- package/dist/shopify/router/ShopifyRouterBisBisBis.d.ts +1 -0
- package/dist/shopify/router/ShopifyRouterBisBisBis.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyRouterBisBisBis.js.map +1 -1
- package/dist/shopify/router/ShopifyRouterBisBisBisBis.d.ts +1 -0
- package/dist/shopify/router/ShopifyRouterBisBisBisBis.d.ts.map +1 -0
- package/dist/shopify/router/ShopifyRouterBisBisBisBis.js.map +1 -1
- package/dist/shopify/router/WebhookSkipMiddleware.d.ts +1 -0
- package/dist/shopify/router/WebhookSkipMiddleware.d.ts.map +1 -0
- package/dist/shopify/router/WebhookSkipMiddleware.js.map +1 -1
- package/dist/shopify/router/services/CryptoService.d.ts +2 -0
- package/dist/shopify/router/services/CryptoService.d.ts.map +1 -0
- package/dist/shopify/router/services/CryptoService.js.map +1 -1
- package/dist/shopify/router/services/HmacValidator.d.ts +1 -0
- package/dist/shopify/router/services/HmacValidator.d.ts.map +1 -0
- package/dist/shopify/router/services/HmacValidator.js.map +1 -1
- package/dist/shopify/router/services/OauthService.d.ts +1 -0
- package/dist/shopify/router/services/OauthService.d.ts.map +1 -0
- package/dist/shopify/router/services/OauthService.js.map +1 -1
- package/dist/shopify/router/services/RestUtils.d.ts +1 -0
- package/dist/shopify/router/services/RestUtils.d.ts.map +1 -0
- package/dist/shopify/router/services/RestUtils.js.map +1 -1
- package/dist/shopify/router/services/rateLimiter/MemoryStores.d.ts +1 -0
- package/dist/shopify/router/services/rateLimiter/MemoryStores.d.ts.map +1 -0
- package/dist/shopify/router/services/rateLimiter/MemoryStores.js.map +1 -1
- package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.d.ts +1 -0
- package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.d.ts.map +1 -0
- package/dist/shopify/router/services/rateLimiter/StoreRateLimiter.js.map +1 -1
- package/dist/test/router/ShopifyRouter.test.d.ts +1 -0
- package/dist/test/router/ShopifyRouter.test.d.ts.map +1 -0
- package/dist/test/router/ShopifyRouter.test.js.map +1 -1
- package/dist/test/router/WebhookSkipMiddleware.test.d.ts +1 -0
- package/dist/test/router/WebhookSkipMiddleware.test.d.ts.map +1 -0
- package/dist/test/router/WebhookSkipMiddleware.test.js.map +1 -1
- package/dist/test/router/services/HmacValidator.test.d.ts +1 -0
- package/dist/test/router/services/HmacValidator.test.d.ts.map +1 -0
- package/dist/test/router/services/HmacValidator.test.js.map +1 -1
- package/dist/test/router/services/RestUtils.test.d.ts +1 -0
- package/dist/test/router/services/RestUtils.test.d.ts.map +1 -0
- package/dist/test/router/services/RestUtils.test.js.map +1 -1
- package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.d.ts +1 -0
- package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.d.ts.map +1 -0
- package/dist/test/router/services/rateLimiter/StoreRateLimiter.test.js.map +1 -1
- package/dist/test/services/CacheWrapper.test.d.ts +1 -0
- package/dist/test/services/CacheWrapper.test.d.ts.map +1 -0
- package/dist/test/services/CacheWrapper.test.js.map +1 -1
- package/dist/test/shopify/ShopifyOrderService.test.d.ts +1 -0
- package/dist/test/shopify/ShopifyOrderService.test.d.ts.map +1 -0
- package/dist/test/shopify/ShopifyOrderService.test.js.map +1 -1
- package/dist/test/shopify/ShopifyProductService.test.d.ts +1 -0
- package/dist/test/shopify/ShopifyProductService.test.d.ts.map +1 -0
- package/dist/test/shopify/ShopifyProductService.test.js.map +1 -1
- package/dist/test/shopify/ShopifyWebhookService.test.d.ts +1 -0
- package/dist/test/shopify/ShopifyWebhookService.test.d.ts.map +1 -0
- package/dist/test/shopify/ShopifyWebhookService.test.js.map +1 -1
- package/package.json +8 -1
- package/shopify/base/APIVersion.ts +2 -2
- package/shopify/router/ShopifyRouter.ts +72 -2
- package/tsconfig.json +2 -0
|
@@ -16,12 +16,41 @@ export class ShopifyRouter {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
public buildRoutes(): express.Router {
|
|
19
|
+
//initial call to /shopify
|
|
19
20
|
router.get('/', async (req,res,next) => {
|
|
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 */ }
|
|
20
33
|
const scopes = await this.getScopes(req.query.shop as string);
|
|
34
|
+
Logger.info(`ShopifyRouter - scopes: ${scopes}`);
|
|
21
35
|
res.locals.scopes = scopes;
|
|
22
36
|
next();
|
|
23
37
|
}, this.installRoute);
|
|
38
|
+
// endpoint when merchant accepts the installation
|
|
24
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 */ }
|
|
25
54
|
return router;
|
|
26
55
|
}
|
|
27
56
|
|
|
@@ -32,17 +61,23 @@ export class ShopifyRouter {
|
|
|
32
61
|
const hmac = expresRequest.query.hmac as string;
|
|
33
62
|
const code = expresRequest.query.code as string;
|
|
34
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');
|
|
35
66
|
Logger.info(`ShopifyRouter - callBackRoute From shopify ${code}`);
|
|
36
67
|
if (shop && hmac && code) {
|
|
37
68
|
const map = Object.assign({}, expresRequest.query);
|
|
38
69
|
delete map['signature'];
|
|
39
70
|
delete map['hmac'];
|
|
40
71
|
const secFetchDest = req.headers['sec-fetch-dest'];
|
|
41
|
-
const
|
|
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);
|
|
42
76
|
|
|
43
77
|
const hashEquals = this.cryptoService.checkHash(this.cryptoService.generateHash(message, this.shop_secret), hmac);
|
|
44
78
|
if (!hashEquals) { expresResponse.status(401).send('HMAC validation failed'); return; }
|
|
45
79
|
Logger.info(`getOathToken From shopify ${code}`);
|
|
80
|
+
// we send the key and secret to get the access token back
|
|
46
81
|
OauthService.getOathToken(shop, this.shop_key, this.shop_secret, code,
|
|
47
82
|
(accessToken: string) => {
|
|
48
83
|
this.callback(accessToken, shop, host, expresResponse, secFetchDest === 'iframe', null);
|
|
@@ -62,10 +97,13 @@ export class ShopifyRouter {
|
|
|
62
97
|
const scopes = res.locals.scopes;
|
|
63
98
|
const shop = expresRequest.query.shop as string;
|
|
64
99
|
const host = expresRequest.query.host;
|
|
100
|
+
Logger.info(`install route: request: ${expresRequest}, response: ${expresResponse}, scopes: ${scopes}, shop: ${shop}, host ${host}`);
|
|
65
101
|
if (shop) {
|
|
102
|
+
// when the shopify session expires we render a page on the embedded app that loads the auth URL to refresh the token
|
|
66
103
|
if(!expresRequest.query.session) {
|
|
67
104
|
expresResponse.render('session_expire', { redirectUrl: this.installUrl(shop, scopes) });
|
|
68
105
|
} else {
|
|
106
|
+
// we send the session exists the app is installed. we redirect to BillingRoutes with status=already_accepted
|
|
69
107
|
expresResponse.redirect(`${this.appBaseUrl}/billing/created?host=${host}&shop=${shop}&status=already_accepted`);
|
|
70
108
|
}
|
|
71
109
|
} else {
|
|
@@ -74,12 +112,44 @@ export class ShopifyRouter {
|
|
|
74
112
|
};
|
|
75
113
|
|
|
76
114
|
private installUrl(shop: string, scopes: string): string {
|
|
77
|
-
|
|
115
|
+
// this URL is used to install the app. you can get it and run it on the browser, it should install the app
|
|
116
|
+
Logger.info(`installURL shop: ${shop}`);
|
|
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`;
|
|
78
119
|
}
|
|
79
120
|
|
|
80
121
|
private redirectUri(): string {
|
|
122
|
+
// the callback for when the merchant has approved the request
|
|
81
123
|
return `${this.appBaseUrl}${this.endpointUri}/callback`;
|
|
82
124
|
}
|
|
83
125
|
}
|
|
84
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
|
+
|
|
85
155
|
export default ShopifyRouter;
|