@sommpicks/sommpicks-shopify 24.12.9 → 24.12.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorHelper.d.ts","sourceRoot":"","sources":["../../../shopify/base/ErrorHelper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,WAAW;IAE5B,OAAc,oBAAoB,UAAW,GAAG,KAAG,GAAG,CAoBpD;CACL"}
1
+ {"version":3,"file":"ErrorHelper.d.ts","sourceRoot":"","sources":["../../../shopify/base/ErrorHelper.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,WAAW;IAE5B,OAAc,oBAAoB,UAAW,GAAG,KAAG,GAAG,CAyBpD;CACL"}
@@ -5,24 +5,29 @@ class ErrorHelper {
5
5
  exports.default = ErrorHelper;
6
6
  ErrorHelper.getErrorFromResponse = (error) => {
7
7
  let data = '';
8
- if (error && error.response && error.response.data && error.response.data.errors) {
9
- if (typeof error.response.data.errors === 'string') {
10
- data = error.response.data.errors;
8
+ const response = error && error.response ? error.response : null;
9
+ const responseData = response && response.data ? response.data : null;
10
+ if (responseData && responseData.errors) {
11
+ if (typeof responseData.errors === 'string') {
12
+ data = responseData.errors;
11
13
  }
12
14
  else {
13
- for (const key in error.response.data.errors) {
14
- data = `${data}, ${key}: ${error.response.data.errors[key]};`;
15
+ for (const key in responseData.errors) {
16
+ data = `${data}, ${key}: ${responseData.errors[key]};`;
15
17
  }
16
18
  }
17
19
  }
18
- else if (error && error.response && error.response.statusText) {
19
- data = `${error.response.status} : ${error.response.statusText}`;
20
+ else if (response && response.statusText) {
21
+ const status = response.status !== undefined ? response.status : 'unknown';
22
+ data = `${status} : ${response.statusText}`;
20
23
  }
21
- else if (error && error.response) {
22
- data = error.response;
24
+ else if (response) {
25
+ data = response;
23
26
  }
24
- else if (error && error.message) {
25
- data = error.message;
27
+ else if (error && (error.code || error.message)) {
28
+ const code = error.code ? `code=${error.code}` : '';
29
+ const message = error.message ? `message=${error.message}` : '';
30
+ data = [code, message].filter(Boolean).join(' ');
26
31
  }
27
32
  else {
28
33
  data = error;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorHelper.js","sourceRoot":"","sources":["../../../shopify/base/ErrorHelper.ts"],"names":[],"mappings":";;AAAA,MAAqB,WAAW;;AAAhC,8BAuBC;AArBiB,gCAAoB,GAAG,CAAC,KAAU,EAAO,EAAE;IACrD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE;QAC9E,IAAG,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE;YAC/C,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;SACrC;aAAM;YACH,KAAI,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE;gBACzC,IAAI,GAAG,GAAG,IAAI,KAAK,GAAG,KAAK,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;aACjE;SACJ;KACJ;SAAM,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE;QAC7D,IAAI,GAAG,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,MAAM,KAAK,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;KACpE;SAAM,IAAI,KAAK,IAAI,KAAK,CAAC,QAAQ,EAAE;QAChC,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC;KACzB;SAAM,IAAI,KAAK,IAAI,KAAK,CAAC,OAAO,EAAE;QAC/B,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;KACxB;SAAM;QACH,IAAI,GAAG,KAAK,CAAC;KAChB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["export default class ErrorHelper {\n\n public static getErrorFromResponse = (error: any): any => {\n let data = '';\n if (error && error.response && error.response.data && error.response.data.errors) {\n if(typeof error.response.data.errors === 'string') {\n data = error.response.data.errors;\n } else {\n for(const key in error.response.data.errors) {\n data = `${data}, ${key}: ${error.response.data.errors[key]};`;\n }\n }\n } else if (error && error.response && error.response.statusText) {\n data = `${error.response.status} : ${error.response.statusText}`;\n } else if (error && error.response) {\n data = error.response;\n } else if (error && error.message) {\n data = error.message;\n } else {\n data = error;\n }\n return data;\n };\n}\n"]}
1
+ {"version":3,"file":"ErrorHelper.js","sourceRoot":"","sources":["../../../shopify/base/ErrorHelper.ts"],"names":[],"mappings":";;AAAA,MAAqB,WAAW;;AAAhC,8BA4BC;AA1BiB,gCAAoB,GAAG,CAAC,KAAU,EAAO,EAAE;IACrD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,MAAM,QAAQ,GAAG,KAAK,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACjE,MAAM,YAAY,GAAG,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACtE,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,EAAE;QACrC,IAAG,OAAO,YAAY,CAAC,MAAM,KAAK,QAAQ,EAAE;YACxC,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC;SAC9B;aAAM;YACH,KAAI,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,EAAE;gBAClC,IAAI,GAAG,GAAG,IAAI,KAAK,GAAG,KAAK,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;aAC1D;SACJ;KACJ;SAAM,IAAI,QAAQ,IAAI,QAAQ,CAAC,UAAU,EAAE;QACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3E,IAAI,GAAG,GAAG,MAAM,MAAM,QAAQ,CAAC,UAAU,EAAE,CAAC;KAC/C;SAAM,IAAI,QAAQ,EAAE;QACjB,IAAI,GAAG,QAAQ,CAAC;KACnB;SAAM,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,EAAE;QAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACpD;SAAM;QACH,IAAI,GAAG,KAAK,CAAC;KAChB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC","sourcesContent":["export default class ErrorHelper {\n\n public static getErrorFromResponse = (error: any): any => {\n let data = '';\n const response = error && error.response ? error.response : null;\n const responseData = response && response.data ? response.data : null;\n if (responseData && responseData.errors) {\n if(typeof responseData.errors === 'string') {\n data = responseData.errors;\n } else {\n for(const key in responseData.errors) {\n data = `${data}, ${key}: ${responseData.errors[key]};`;\n }\n }\n } else if (response && response.statusText) {\n const status = response.status !== undefined ? response.status : 'unknown';\n data = `${status} : ${response.statusText}`;\n } else if (response) {\n data = response;\n } else if (error && (error.code || error.message)) {\n const code = error.code ? `code=${error.code}` : '';\n const message = error.message ? `message=${error.message}` : '';\n data = [code, message].filter(Boolean).join(' ');\n } else {\n data = error;\n }\n return data;\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyRouter.d.ts","sourceRoot":"","sources":["../../../shopify/router/ShopifyRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAW,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAK9D,qBAAa,aAAa;IAIT,OAAO,CAAC,WAAW;IAAU,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,UAAU;IAAU,OAAO,CAAC,WAAW;IAAU,OAAO,CAAC,SAAS;IAA8C,OAAO,CAAC,QAAQ;IAF5M,OAAO,CAAC,aAAa,CAAgB;gBAEhB,WAAW,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,EAAU,UAAU,EAAE,MAAM,EAAU,WAAW,EAAE,MAAM,EAAU,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAAU,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI;IAI7T,WAAW,IAAI,OAAO,CAAC,MAAM;IAuC7B,aAAa,QAAS,GAAG,OAAO,GAAG,UAmCxC;IAEK,YAAY,QAAS,GAAG,OAAO,GAAG,gDAkBvC;IAEF,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;CAItB;AA8BD,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"ShopifyRouter.d.ts","sourceRoot":"","sources":["../../../shopify/router/ShopifyRouter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAW,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAK9D,qBAAa,aAAa;IAIT,OAAO,CAAC,WAAW;IAAU,OAAO,CAAC,QAAQ;IAAU,OAAO,CAAC,UAAU;IAAU,OAAO,CAAC,WAAW;IAAU,OAAO,CAAC,SAAS;IAA8C,OAAO,CAAC,QAAQ;IAF5M,OAAO,CAAC,aAAa,CAAgB;gBAEhB,WAAW,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,EAAU,UAAU,EAAE,MAAM,EAAU,WAAW,EAAE,MAAM,EAAU,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAAU,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI;IAI7T,WAAW,IAAI,OAAO,CAAC,MAAM;IAuC7B,aAAa,QAAS,GAAG,OAAO,GAAG,UAmCxC;IAEK,YAAY,QAAS,GAAG,OAAO,GAAG,gDAkBvC;IAEF,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,WAAW;CAItB;AA8BD,eAAe,aAAa,CAAC"}
@@ -128,7 +128,8 @@ class ShopifyRouter {
128
128
  installUrl(shop, scopes) {
129
129
  // this URL is used to install the app. you can get it and run it on the browser, it should install the app
130
130
  Logger_1.Logger.info(`installURL shop: ${shop}`);
131
- return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}`;
131
+ // Explicitly request offline (permanent) access tokens
132
+ return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}&access_mode=offline`;
132
133
  }
133
134
  redirectUri() {
134
135
  // the callback for when the merchant has approved the request
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyRouter.js","sourceRoot":"","sources":["../../../shopify/router/ShopifyRouter.ts"],"names":[],"mappings":";;;;;;;;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a,uBAAb,aAAa,CAAU,IAAI;YACvC,gBAAgB,EAAE,MAAM,CAAC,mBAAmB,CAAC,CAAC,aAAqB,aAArB,aAAa,uBAAb,aAAa,CAAU,SAAS,KAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,aAAa,CAAC;SACzH,CAAC;QACF,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,UAAU,CAAC,CAAC;QAE5E,MAAM,CAAC,GAAQ,MAAa,CAAC;QAC7B,MAAM,UAAU,GAAG;YACf,IAAI,EAAE,OAAO,MAAM;YACnB,YAAY,EAAE,OAAO,MAAM,KAAK,UAAU;YAC1C,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YACjE,KAAK,EAAE;gBACH,aAAa,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,aAAa;gBAC/B,WAAW,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,WAAW;gBAC3B,MAAM,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM;aACpB;SACJ,CAAC;QACF,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,yDAAyD,EAAE,UAAU,CAAC,CAAC;KACvF;CACJ;AAAC,QAAQ,iCAAiC,IAAnC,EAAE,iCAAiC,EAAE;AAE7C,kBAAe,aAAa,CAAC","sourcesContent":["import * as express from 'express';\nimport * as querystring from 'querystring';\nimport { CryptoService } from './services/CryptoService';\nimport { OauthService } from './services/OauthService';\nimport { Request, Response } from 'express-serve-static-core';\nimport { Logger } from '../../Logger';\n\nconst router = express.Router();\n\nexport class ShopifyRouter {\n\n private cryptoService: CryptoService;\n\n 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) {\n this.cryptoService = new CryptoService();\n }\n\n public buildRoutes(): express.Router {\n //initial call to /shopify\n router.get('/', async (req,res,next) => {\n Logger.info(`ShopifyRouter - request: ${req}`);\n try {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][/shopify request]', {\n method: req.method,\n path: (req as any).path,\n query: (req as any).query,\n headers: { 'sec-fetch-dest': (req as any).headers?.['sec-fetch-dest'] }\n });\n }\n } catch { /* ignore debug logging errors */ }\n const scopes = await this.getScopes(req.query.shop as string);\n Logger.info(`ShopifyRouter - scopes: ${scopes}`);\n res.locals.scopes = scopes;\n next();\n }, this.installRoute);\n // endpoint when merchant accepts the installation\n router.get('/callback', this.callBackRoute);\n router.get('/auth/callback', this.callBackRoute);\n Logger.info('build routes was hit!');\n try {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n const r: any = router as any;\n const routes = Array.isArray(r?.stack)\n ? r.stack\n .filter((l: any) => l && l.route)\n .map((l: any) => ({ path: l.route.path, methods: Object.keys(l.route.methods || {}) }))\n : [];\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][routes]', routes);\n }\n } catch { /* ignore debug logging errors */ }\n return router;\n }\n\n public callBackRoute = (req: any, res: any) => {\n const expresRequest = req as Request;\n const expresResponse = res as Response;\n const shop = expresRequest.query.shop as string;\n const hmac = expresRequest.query.hmac as string;\n const code = expresRequest.query.code as string;\n const host = expresRequest.query.host as string;\n Logger.info('we are using the updated version');\n console.log('we are console logging the updated version');\n Logger.info(`ShopifyRouter - callBackRoute From shopify ${code}`);\n if (shop && hmac && code) {\n const map = Object.assign({}, expresRequest.query);\n delete map['signature'];\n delete map['hmac'];\n const secFetchDest = req.headers['sec-fetch-dest'];\n const sortedKeys = Object.keys(map).sort();\n const sortedMap: any = {};\n sortedKeys.forEach(key => sortedMap[key] = map[key]);\n const message = querystring.stringify(sortedMap);\n\n const hashEquals = this.cryptoService.checkHash(this.cryptoService.generateHash(message, this.shop_secret), hmac);\n if (!hashEquals) { expresResponse.status(401).send('HMAC validation failed'); return; }\n Logger.info(`getOathToken From shopify ${code}`);\n // we send the key and secret to get the access token back\n OauthService.getOathToken(shop, this.shop_key, this.shop_secret, code,\n (accessToken: string) => {\n this.callback(accessToken, shop, host, expresResponse, secFetchDest === 'iframe', null);\n },\n (errorStatus: string, error: string) => {\n Logger.error(`Error while getOathToken - status: ${errorStatus} and message: ${error}`);\n this.callback(null, shop, host, expresResponse, secFetchDest === 'iframe', { error: error, errorStatus: errorStatus });\n });\n } else {\n expresResponse.status(400).send('Required parameters missing');\n }\n };\n\n public installRoute = (req: any, res: any) => {\n const expresRequest = req as Request;\n const expresResponse = res as Response;\n const scopes = res.locals.scopes;\n const shop = expresRequest.query.shop as string;\n const host = expresRequest.query.host;\n Logger.info(`install route: request: ${expresRequest}, response: ${expresResponse}, scopes: ${scopes}, shop: ${shop}, host ${host}`);\n if (shop) {\n // when the shopify session expires we render a page on the embedded app that loads the auth URL to refresh the token\n if(!expresRequest.query.session) {\n expresResponse.render('session_expire', { redirectUrl: this.installUrl(shop, scopes) });\n } else {\n // we send the session exists the app is installed. we redirect to BillingRoutes with status=already_accepted\n expresResponse.redirect(`${this.appBaseUrl}/billing/created?host=${host}&shop=${shop}&status=already_accepted`);\n }\n } else {\n return expresResponse.status(400).send('Missing shop parameter.');\n }\n };\n\n private installUrl(shop: string, scopes: string): string {\n // this URL is used to install the app. you can get it and run it on the browser, it should install the app\n Logger.info(`installURL shop: ${shop}`);\n return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}`;\n }\n\n private redirectUri(): string {\n // the callback for when the merchant has approved the request\n return `${this.appBaseUrl}${this.endpointUri}/callback`;\n }\n}\n\n// Debug export and router shape when enabled via env\ntry {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n const exportMeta = {\n classType: typeof ShopifyRouter,\n className: (ShopifyRouter as any)?.name,\n prototypeMethods: Object.getOwnPropertyNames((ShopifyRouter as any)?.prototype || {}).filter(m => m !== 'constructor')\n };\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][export-meta]', exportMeta);\n\n const r: any = router as any;\n const routerMeta = {\n type: typeof router,\n isMiddleware: typeof router === 'function',\n keys: Object.keys(r || {}),\n stackLength: Array.isArray(r?.stack) ? r.stack.length : undefined,\n props: {\n caseSensitive: r?.caseSensitive,\n mergeParams: r?.mergeParams,\n strict: r?.strict\n }\n };\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][express-router-meta]', routerMeta);\n }\n} catch { /* ignore debug logging errors */ }\n\nexport default ShopifyRouter;\n"]}
1
+ {"version":3,"file":"ShopifyRouter.js","sourceRoot":"","sources":["../../../shopify/router/ShopifyRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAmC;AACnC,2CAA2C;AAC3C,4DAAyD;AACzD,0DAAuD;AAEvD,yCAAsC;AAEtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;AAEhC,MAAa,aAAa;IAItB,YAAqB,WAAmB,EAAU,QAAgB,EAAU,UAAkB,EAAU,WAAmB,EAAU,SAAqD,EAAU,QAAgI;QAA/S,gBAAW,GAAX,WAAW,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAQ;QAAU,eAAU,GAAV,UAAU,CAAQ;QAAU,gBAAW,GAAX,WAAW,CAAQ;QAAU,cAAS,GAAT,SAAS,CAA4C;QAAU,aAAQ,GAAR,QAAQ,CAAwH;QA2C7T,kBAAa,GAAG,CAAC,GAAQ,EAAE,GAAQ,EAAE,EAAE;YAC1C,MAAM,aAAa,GAAG,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B,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YACjE,KAAK,EAAE;gBACH,aAAa,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,aAAa;gBAC/B,WAAW,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,WAAW;gBAC3B,MAAM,EAAE,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,MAAM;aACpB;SACJ,CAAC;QACF,sCAAsC;QACtC,OAAO,CAAC,IAAI,CAAC,yDAAyD,EAAE,UAAU,CAAC,CAAC;KACvF;CACJ;AAAC,QAAQ,iCAAiC,IAAnC,EAAE,iCAAiC,EAAE;AAE7C,kBAAe,aAAa,CAAC","sourcesContent":["import * as express from 'express';\nimport * as querystring from 'querystring';\nimport { CryptoService } from './services/CryptoService';\nimport { OauthService } from './services/OauthService';\nimport { Request, Response } from 'express-serve-static-core';\nimport { Logger } from '../../Logger';\n\nconst router = express.Router();\n\nexport class ShopifyRouter {\n\n private cryptoService: CryptoService;\n\n 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) {\n this.cryptoService = new CryptoService();\n }\n\n public buildRoutes(): express.Router {\n //initial call to /shopify\n router.get('/', async (req,res,next) => {\n Logger.info(`ShopifyRouter - request: ${req}`);\n try {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][/shopify request]', {\n method: req.method,\n path: (req as any).path,\n query: (req as any).query,\n headers: { 'sec-fetch-dest': (req as any).headers?.['sec-fetch-dest'] }\n });\n }\n } catch { /* ignore debug logging errors */ }\n const scopes = await this.getScopes(req.query.shop as string);\n Logger.info(`ShopifyRouter - scopes: ${scopes}`);\n res.locals.scopes = scopes;\n next();\n }, this.installRoute);\n // endpoint when merchant accepts the installation\n router.get('/callback', this.callBackRoute);\n router.get('/auth/callback', this.callBackRoute);\n Logger.info('build routes was hit!');\n try {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n const r: any = router as any;\n const routes = Array.isArray(r?.stack)\n ? r.stack\n .filter((l: any) => l && l.route)\n .map((l: any) => ({ path: l.route.path, methods: Object.keys(l.route.methods || {}) }))\n : [];\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][routes]', routes);\n }\n } catch { /* ignore debug logging errors */ }\n return router;\n }\n\n public callBackRoute = (req: any, res: any) => {\n const expresRequest = req as Request;\n const expresResponse = res as Response;\n const shop = expresRequest.query.shop as string;\n const hmac = expresRequest.query.hmac as string;\n const code = expresRequest.query.code as string;\n const host = expresRequest.query.host as string;\n Logger.info('we are using the updated version');\n console.log('we are console logging the updated version');\n Logger.info(`ShopifyRouter - callBackRoute From shopify ${code}`);\n if (shop && hmac && code) {\n const map = Object.assign({}, expresRequest.query);\n delete map['signature'];\n delete map['hmac'];\n const secFetchDest = req.headers['sec-fetch-dest'];\n const sortedKeys = Object.keys(map).sort();\n const sortedMap: any = {};\n sortedKeys.forEach(key => sortedMap[key] = map[key]);\n const message = querystring.stringify(sortedMap);\n\n const hashEquals = this.cryptoService.checkHash(this.cryptoService.generateHash(message, this.shop_secret), hmac);\n if (!hashEquals) { expresResponse.status(401).send('HMAC validation failed'); return; }\n Logger.info(`getOathToken From shopify ${code}`);\n // we send the key and secret to get the access token back\n OauthService.getOathToken(shop, this.shop_key, this.shop_secret, code,\n (accessToken: string) => {\n this.callback(accessToken, shop, host, expresResponse, secFetchDest === 'iframe', null);\n },\n (errorStatus: string, error: string) => {\n Logger.error(`Error while getOathToken - status: ${errorStatus} and message: ${error}`);\n this.callback(null, shop, host, expresResponse, secFetchDest === 'iframe', { error: error, errorStatus: errorStatus });\n });\n } else {\n expresResponse.status(400).send('Required parameters missing');\n }\n };\n\n public installRoute = (req: any, res: any) => {\n const expresRequest = req as Request;\n const expresResponse = res as Response;\n const scopes = res.locals.scopes;\n const shop = expresRequest.query.shop as string;\n const host = expresRequest.query.host;\n Logger.info(`install route: request: ${expresRequest}, response: ${expresResponse}, scopes: ${scopes}, shop: ${shop}, host ${host}`);\n if (shop) {\n // when the shopify session expires we render a page on the embedded app that loads the auth URL to refresh the token\n if(!expresRequest.query.session) {\n expresResponse.render('session_expire', { redirectUrl: this.installUrl(shop, scopes) });\n } else {\n // we send the session exists the app is installed. we redirect to BillingRoutes with status=already_accepted\n expresResponse.redirect(`${this.appBaseUrl}/billing/created?host=${host}&shop=${shop}&status=already_accepted`);\n }\n } else {\n return expresResponse.status(400).send('Missing shop parameter.');\n }\n };\n\n private installUrl(shop: string, scopes: string): string {\n // this URL is used to install the app. you can get it and run it on the browser, it should install the app\n Logger.info(`installURL shop: ${shop}`);\n // Explicitly request offline (permanent) access tokens\n return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}&access_mode=offline`;\n }\n\n private redirectUri(): string {\n // the callback for when the merchant has approved the request\n return `${this.appBaseUrl}${this.endpointUri}/callback`;\n }\n}\n\n// Debug export and router shape when enabled via env\ntry {\n if (process && process.env && process.env.SP_ROUTER_DEBUG === '1') {\n const exportMeta = {\n classType: typeof ShopifyRouter,\n className: (ShopifyRouter as any)?.name,\n prototypeMethods: Object.getOwnPropertyNames((ShopifyRouter as any)?.prototype || {}).filter(m => m !== 'constructor')\n };\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][export-meta]', exportMeta);\n\n const r: any = router as any;\n const routerMeta = {\n type: typeof router,\n isMiddleware: typeof router === 'function',\n keys: Object.keys(r || {}),\n stackLength: Array.isArray(r?.stack) ? r.stack.length : undefined,\n props: {\n caseSensitive: r?.caseSensitive,\n mergeParams: r?.mergeParams,\n strict: r?.strict\n }\n };\n // eslint-disable-next-line no-console\n console.info('[sommpicks-shopify][ShopifyRouter][express-router-meta]', routerMeta);\n }\n} catch { /* ignore debug logging errors */ }\n\nexport default ShopifyRouter;\n"]}
@@ -46,7 +46,7 @@ describe('create should,', () => {
46
46
  };
47
47
  const shopifyWebhookService = new ShopifyWebhookService_1.ShopifyWebhookService(mockAxiosInstance);
48
48
  const createwebHookFunc = () => __awaiter(void 0, void 0, void 0, function* () { yield shopifyWebhookService.create({ address: 'some_url', format: 'json', topic: 'collections/create' }); });
49
- expect(createwebHookFunc).rejects.toThrow('\\"API error\\"');
49
+ expect(createwebHookFunc).rejects.toThrow(/API error/);
50
50
  }));
51
51
  });
52
52
  describe('createStoreWebHooks should,', () => {
@@ -93,7 +93,8 @@ describe('createStoreWebHooks should,', () => {
93
93
  }
94
94
  expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);
95
95
  expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);
96
- expect(error).toBe('"\\"1 webhooks have not been created with errors \\\\\\"API error\\\\\\"\\""');
96
+ expect(error).toContain('1 webhooks have not been created with errors');
97
+ expect(error).toContain('API error');
97
98
  }));
98
99
  });
99
100
  //# sourceMappingURL=ShopifyWebhookService.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ShopifyWebhookService.test.js","sourceRoot":"","sources":["../../../test/shopify/ShopifyWebhookService.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yCAAsC;AACtC,6DAA0D;AAC1D,+EAA4E;AAC5E,kFAA2E;AAE3E,UAAU,CAAC,GAAQ,EAAE;IACjB,IAAI,CAAC,aAAa,EAAE,CAAC;IACrB,eAAM,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAC1B,eAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;AACjC,CAAC,CAAA,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,IAAI,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,mBAAmB,CAAC,SAAS,EAAE,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,wBAAwB,CAAC,CAAC,CAAC;SACpI;QAAC,OAAM,CAAC,EAAE;YACP,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC;SACrB;QAED,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;IACvG,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { Logger } from '../../Logger';\nimport { ShopifyUtils } from '../../shopify/ShopifyUtils';\nimport { ShopifyWebhookService } from '../../shopify/ShopifyWebhookService';\nimport InspiraShopifyError from '../../shopify/errors/InspiraShopifyError';\n\nbeforeEach(async() => {\n jest.clearAllMocks();\n Logger.info = console.log;\n Logger.error = console.error;\n});\n\ndescribe('deleteAll should,', () => {\n test('Delete all existing webhooks', async () => {\n const mockAxiosInstance = {\n get: jest.fn(() => {\n return new Promise<any>((resolve) => {\n resolve({\n data: {\n webhooks: [{ topic: 'orders/create', id: 1, address: 'some callaback url', format: 'json' },\n { topic: 'orders/delete', id: 2, address: 'some callaback url', format: 'json' }]\n }\n });\n });\n }),\n delete: jest.fn()\n };\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.deleteAll();\n \n expect(mockAxiosInstance.get).toHaveBeenCalledWith('/webhooks.json');\n expect(mockAxiosInstance.delete).toHaveBeenCalledTimes(2);\n });\n});\n\ndescribe('create should,', () => {\n test('throw error when API fails', async () => {\n const mockAxiosInstance = {\n post: jest.fn().mockRejectedValue(new InspiraShopifyError({ message: 'API error'}))\n };\n\n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n const createwebHookFunc = async () => { await shopifyWebhookService.create({ address: 'some_url', format: 'json', topic: 'collections/create' }); };\n expect(createwebHookFunc).rejects.toThrow('\\\\\"API error\\\\\"');\n\n });\n});\n\ndescribe('createStoreWebHooks should,', () => {\n test('create all webhooks when no webhooks are already in place', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [] }}),\n post: jest.fn().mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/collections/create', format: 'json', topic: 'collections/create' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/customers/delete', format: 'json', topic: 'customers/delete' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/inventory_items/update', format: 'json', topic: 'inventory_items/update' } });\n });\n\n test('create only webhooks that are not already in place', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [{ topic: 'customers/delete', id: 1, address: 'some callaback url', format: 'json' }] }}),\n post: jest.fn().mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(2);\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/collections/create', format: 'json', topic: 'collections/create' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/inventory_items/update', format: 'json', topic: 'inventory_items/update' } });\n });\n\n test('return error when a webhooks fail to be created', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [] }}),\n post: jest.fn().mockRejectedValueOnce('API error').mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n let error = '';\n try {\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n } catch(e) {\n error = e.message;\n }\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);\n expect(error).toBe('\"\\\\\"1 webhooks have not been created with errors \\\\\\\\\\\\\"API error\\\\\\\\\\\\\"\\\\\"\"');\n });\n});"]}
1
+ {"version":3,"file":"ShopifyWebhookService.test.js","sourceRoot":"","sources":["../../../test/shopify/ShopifyWebhookService.test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,yCAAsC;AACtC,6DAA0D;AAC1D,+EAA4E;AAC5E,kFAA2E;AAE3E,UAAU,CAAC,GAAQ,EAAE;IACjB,IAAI,CAAC,aAAa,EAAE,CAAC;IACrB,eAAM,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IAC1B,eAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;AACjC,CAAC,CAAA,CAAC,CAAC;AAEH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IAC/B,IAAI,CAAC,8BAA8B,EAAE,GAAS,EAAE;QAC5C,MAAM,iBAAiB,GAAG;YACtB,GAAG,EAAE,IAAI,CAAC,E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;QAAC,OAAM,CAAC,EAAE;YACP,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC;SACrB;QAED,MAAM,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACvD,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAAC;QACxE,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC,CAAA,CAAC,CAAC;AACP,CAAC,CAAC,CAAC","sourcesContent":["import { Logger } from '../../Logger';\nimport { ShopifyUtils } from '../../shopify/ShopifyUtils';\nimport { ShopifyWebhookService } from '../../shopify/ShopifyWebhookService';\nimport InspiraShopifyError from '../../shopify/errors/InspiraShopifyError';\n\nbeforeEach(async() => {\n jest.clearAllMocks();\n Logger.info = console.log;\n Logger.error = console.error;\n});\n\ndescribe('deleteAll should,', () => {\n test('Delete all existing webhooks', async () => {\n const mockAxiosInstance = {\n get: jest.fn(() => {\n return new Promise<any>((resolve) => {\n resolve({\n data: {\n webhooks: [{ topic: 'orders/create', id: 1, address: 'some callaback url', format: 'json' },\n { topic: 'orders/delete', id: 2, address: 'some callaback url', format: 'json' }]\n }\n });\n });\n }),\n delete: jest.fn()\n };\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.deleteAll();\n \n expect(mockAxiosInstance.get).toHaveBeenCalledWith('/webhooks.json');\n expect(mockAxiosInstance.delete).toHaveBeenCalledTimes(2);\n });\n});\n\ndescribe('create should,', () => {\n test('throw error when API fails', async () => {\n const mockAxiosInstance = {\n post: jest.fn().mockRejectedValue(new InspiraShopifyError({ message: 'API error'}))\n };\n\n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n const createwebHookFunc = async () => { await shopifyWebhookService.create({ address: 'some_url', format: 'json', topic: 'collections/create' }); };\n expect(createwebHookFunc).rejects.toThrow(/API error/);\n\n });\n});\n\ndescribe('createStoreWebHooks should,', () => {\n test('create all webhooks when no webhooks are already in place', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [] }}),\n post: jest.fn().mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/collections/create', format: 'json', topic: 'collections/create' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/customers/delete', format: 'json', topic: 'customers/delete' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/inventory_items/update', format: 'json', topic: 'inventory_items/update' } });\n });\n\n test('create only webhooks that are not already in place', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [{ topic: 'customers/delete', id: 1, address: 'some callaback url', format: 'json' }] }}),\n post: jest.fn().mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(2);\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/collections/create', format: 'json', topic: 'collections/create' } });\n expect(mockAxiosInstance.post).toHaveBeenCalledWith('/webhooks.json', { webhook: { address: 'baseURL/inventory_items/update', format: 'json', topic: 'inventory_items/update' } });\n });\n\n test('return error when a webhooks fail to be created', async () => {\n const mockAxiosInstance = {\n get: jest.fn().mockResolvedValue({ data: { webhooks: [] }}),\n post: jest.fn().mockRejectedValueOnce('API error').mockResolvedValue({ data: { webhooks: { id: 121123 }}})\n };\n \n ShopifyUtils.getAxiosInstance = (): any => mockAxiosInstance;\n \n const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);\n let error = '';\n try {\n await shopifyWebhookService.createStoreWebHooks('baseURL', ['collections/create', 'customers/delete', 'inventory_items/update']);\n } catch(e) {\n error = e.message;\n }\n\n expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);\n expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);\n expect(error).toContain('1 webhooks have not been created with errors');\n expect(error).toContain('API error');\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sommpicks/sommpicks-shopify",
3
- "version": "24.12.9",
3
+ "version": "24.12.11",
4
4
  "publishConfig": { "access": "restricted" },
5
5
  "description": "Shopify REST API & GraphQL calls",
6
6
  "main": "dist/index.js",
@@ -2,20 +2,25 @@ export default class ErrorHelper {
2
2
 
3
3
  public static getErrorFromResponse = (error: any): any => {
4
4
  let data = '';
5
- if (error && error.response && error.response.data && error.response.data.errors) {
6
- if(typeof error.response.data.errors === 'string') {
7
- data = error.response.data.errors;
5
+ const response = error && error.response ? error.response : null;
6
+ const responseData = response && response.data ? response.data : null;
7
+ if (responseData && responseData.errors) {
8
+ if(typeof responseData.errors === 'string') {
9
+ data = responseData.errors;
8
10
  } else {
9
- for(const key in error.response.data.errors) {
10
- data = `${data}, ${key}: ${error.response.data.errors[key]};`;
11
+ for(const key in responseData.errors) {
12
+ data = `${data}, ${key}: ${responseData.errors[key]};`;
11
13
  }
12
14
  }
13
- } else if (error && error.response && error.response.statusText) {
14
- data = `${error.response.status} : ${error.response.statusText}`;
15
- } else if (error && error.response) {
16
- data = error.response;
17
- } else if (error && error.message) {
18
- data = error.message;
15
+ } else if (response && response.statusText) {
16
+ const status = response.status !== undefined ? response.status : 'unknown';
17
+ data = `${status} : ${response.statusText}`;
18
+ } else if (response) {
19
+ data = response;
20
+ } else if (error && (error.code || error.message)) {
21
+ const code = error.code ? `code=${error.code}` : '';
22
+ const message = error.message ? `message=${error.message}` : '';
23
+ data = [code, message].filter(Boolean).join(' ');
19
24
  } else {
20
25
  data = error;
21
26
  }
@@ -41,7 +41,7 @@ describe('create should,', () => {
41
41
 
42
42
  const shopifyWebhookService = new ShopifyWebhookService(mockAxiosInstance as any);
43
43
  const createwebHookFunc = async () => { await shopifyWebhookService.create({ address: 'some_url', format: 'json', topic: 'collections/create' }); };
44
- expect(createwebHookFunc).rejects.toThrow('\\"API error\\"');
44
+ expect(createwebHookFunc).rejects.toThrow(/API error/);
45
45
 
46
46
  });
47
47
  });
@@ -100,6 +100,7 @@ describe('createStoreWebHooks should,', () => {
100
100
 
101
101
  expect(mockAxiosInstance.get).toHaveBeenCalledTimes(1);
102
102
  expect(mockAxiosInstance.post).toHaveBeenCalledTimes(3);
103
- expect(error).toBe('"\\"1 webhooks have not been created with errors \\\\\\"API error\\\\\\"\\""');
103
+ expect(error).toContain('1 webhooks have not been created with errors');
104
+ expect(error).toContain('API error');
104
105
  });
105
- });
106
+ });