@sommpicks/sommpicks-shopify 24.12.6 → 24.12.8
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.
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
class APIVersion {
|
|
4
4
|
}
|
|
5
5
|
exports.default = APIVersion;
|
|
6
|
-
APIVersion.VERSION = '
|
|
6
|
+
APIVersion.VERSION = '2024-01';
|
|
7
7
|
APIVersion.API_URL = `api/${APIVersion.VERSION}`;
|
|
8
8
|
//# sourceMappingURL=APIVersion.js.map
|
|
@@ -44,6 +44,7 @@ class ShopifyRouter {
|
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
Logger_1.Logger.info(`getOathToken From shopify ${code}`);
|
|
47
|
+
// we send the key and secret to get the access token back
|
|
47
48
|
OauthService_1.OauthService.getOathToken(shop, this.shop_key, this.shop_secret, code, (accessToken) => {
|
|
48
49
|
this.callback(accessToken, shop, host, expresResponse, secFetchDest === 'iframe', null);
|
|
49
50
|
}, (errorStatus, error) => {
|
|
@@ -61,11 +62,14 @@ class ShopifyRouter {
|
|
|
61
62
|
const scopes = res.locals.scopes;
|
|
62
63
|
const shop = expresRequest.query.shop;
|
|
63
64
|
const host = expresRequest.query.host;
|
|
65
|
+
Logger_1.Logger.info(`install route: request: ${expresRequest}, response: ${expresResponse}, scopes: ${scopes}, shop: ${shop}, host ${host}`);
|
|
64
66
|
if (shop) {
|
|
67
|
+
// when the shopify session expires we render a page on the embedded app that loads the auth URL to refresh the token
|
|
65
68
|
if (!expresRequest.query.session) {
|
|
66
69
|
expresResponse.render('session_expire', { redirectUrl: this.installUrl(shop, scopes) });
|
|
67
70
|
}
|
|
68
71
|
else {
|
|
72
|
+
// we send the session exists the app is installed. we redirect to BillingRoutes with status=already_accepted
|
|
69
73
|
expresResponse.redirect(`${this.appBaseUrl}/billing/created?host=${host}&shop=${shop}&status=already_accepted`);
|
|
70
74
|
}
|
|
71
75
|
}
|
|
@@ -74,20 +78,28 @@ class ShopifyRouter {
|
|
|
74
78
|
}
|
|
75
79
|
};
|
|
76
80
|
this.cryptoService = new CryptoService_1.CryptoService();
|
|
81
|
+
Logger_1.Logger.info(`cryptoservice: ${this.cryptoService}`);
|
|
77
82
|
}
|
|
78
83
|
buildRoutes() {
|
|
84
|
+
//initial call to /shopify
|
|
79
85
|
router.get('/', (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
Logger_1.Logger.info(`ShopifyRouter - request: ${req}`);
|
|
80
87
|
const scopes = yield this.getScopes(req.query.shop);
|
|
88
|
+
Logger_1.Logger.info(`ShopifyRouter - scopes: ${scopes}`);
|
|
81
89
|
res.locals.scopes = scopes;
|
|
82
90
|
next();
|
|
83
91
|
}), this.installRoute);
|
|
92
|
+
// endpoint when merchant accepts the installation
|
|
84
93
|
router.get('/callback', this.callBackRoute);
|
|
85
94
|
return router;
|
|
86
95
|
}
|
|
87
96
|
installUrl(shop, scopes) {
|
|
97
|
+
// this URL is used to install the app. you can get it and run it on the browser, it should install the app
|
|
98
|
+
Logger_1.Logger.info(`installURL shop: ${shop}`);
|
|
88
99
|
return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}`;
|
|
89
100
|
}
|
|
90
101
|
redirectUri() {
|
|
102
|
+
// the callback for when the merchant has approved the installation
|
|
91
103
|
return `${this.appBaseUrl}${this.endpointUri}/callback`;
|
|
92
104
|
}
|
|
93
105
|
}
|
|
@@ -1 +1 @@
|
|
|
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;IAIt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B,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IACxD,CAAC;IAEM,WAAW;QACd,0BAA0B;QAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAO,GAAG,EAAC,GAAG,EAAC,IAAI,EAAE,EAAE;YACnC,eAAM,CAAC,IAAI,CAAC,4BAA4B,GAAG,EAAE,CAAC,CAAC;YAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,IAAc,CAAC,CAAC;YAC9D,eAAM,CAAC,IAAI,CAAC,2BAA2B,MAAM,EAAE,CAAC,CAAC;YACjD,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YAC3B,IAAI,EAAE,CAAC;QACX,CAAC,CAAA,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QACtB,kDAAkD;QAClD,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5C,OAAO,MAAM,CAAC;IAClB,CAAC;IAsDO,UAAU,CAAC,IAAY,EAAE,MAAc;QAC3C,2GAA2G;QAC3G,eAAM,CAAC,IAAI,CAAC,oBAAoB,IAAI,EAAE,CAAC,CAAC;QACxC,OAAO,WAAW,IAAI,oCAAoC,IAAI,CAAC,QAAQ,UAAU,MAAM,iBAAiB,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;IACjI,CAAC;IAEO,WAAW;QACf,mEAAmE;QACnE,OAAO,GAAG,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,WAAW,CAAC;IAC5D,CAAC;CACJ;AArFD,sCAqFC;AAED,kBAAe,aAAa,CAAC"}
|
package/package.json
CHANGED
|
@@ -13,14 +13,19 @@ 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}`);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
public buildRoutes(): express.Router {
|
|
20
|
+
//initial call to /shopify
|
|
19
21
|
router.get('/', async (req,res,next) => {
|
|
22
|
+
Logger.info(`ShopifyRouter - request: ${req}`);
|
|
20
23
|
const scopes = await this.getScopes(req.query.shop as string);
|
|
24
|
+
Logger.info(`ShopifyRouter - scopes: ${scopes}`);
|
|
21
25
|
res.locals.scopes = scopes;
|
|
22
26
|
next();
|
|
23
27
|
}, this.installRoute);
|
|
28
|
+
// endpoint when merchant accepts the installation
|
|
24
29
|
router.get('/callback', this.callBackRoute);
|
|
25
30
|
return router;
|
|
26
31
|
}
|
|
@@ -32,7 +37,7 @@ export class ShopifyRouter {
|
|
|
32
37
|
const hmac = expresRequest.query.hmac as string;
|
|
33
38
|
const code = expresRequest.query.code as string;
|
|
34
39
|
const host = expresRequest.query.host as string;
|
|
35
|
-
|
|
40
|
+
Logger.info(`ShopifyRouter - callBackRoute From shopify ${code}`);
|
|
36
41
|
if (shop && hmac && code) {
|
|
37
42
|
const map = Object.assign({}, expresRequest.query);
|
|
38
43
|
delete map['signature'];
|
|
@@ -42,7 +47,8 @@ export class ShopifyRouter {
|
|
|
42
47
|
|
|
43
48
|
const hashEquals = this.cryptoService.checkHash(this.cryptoService.generateHash(message, this.shop_secret), hmac);
|
|
44
49
|
if (!hashEquals) { expresResponse.status(401).send('HMAC validation failed'); return; }
|
|
45
|
-
|
|
50
|
+
Logger.info(`getOathToken From shopify ${code}`);
|
|
51
|
+
// we send the key and secret to get the access token back
|
|
46
52
|
OauthService.getOathToken(shop, this.shop_key, this.shop_secret, code,
|
|
47
53
|
(accessToken: string) => {
|
|
48
54
|
this.callback(accessToken, shop, host, expresResponse, secFetchDest === 'iframe', null);
|
|
@@ -62,23 +68,28 @@ export class ShopifyRouter {
|
|
|
62
68
|
const scopes = res.locals.scopes;
|
|
63
69
|
const shop = expresRequest.query.shop as string;
|
|
64
70
|
const host = expresRequest.query.host;
|
|
71
|
+
Logger.info(`install route: request: ${expresRequest}, response: ${expresResponse}, scopes: ${scopes}, shop: ${shop}, host ${host}`);
|
|
65
72
|
if (shop) {
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
// when the shopify session expires we render a page on the embedded app that loads the auth URL to refresh the token
|
|
74
|
+
if(!expresRequest.query.session) {
|
|
75
|
+
expresResponse.render('session_expire', { redirectUrl: this.installUrl(shop, scopes) });
|
|
76
|
+
} else {
|
|
77
|
+
// we send the session exists the app is installed. we redirect to BillingRoutes with status=already_accepted
|
|
78
|
+
expresResponse.redirect(`${this.appBaseUrl}/billing/created?host=${host}&shop=${shop}&status=already_accepted`);
|
|
79
|
+
}
|
|
72
80
|
} else {
|
|
73
81
|
return expresResponse.status(400).send('Missing shop parameter.');
|
|
74
82
|
}
|
|
75
83
|
};
|
|
76
84
|
|
|
77
85
|
private installUrl(shop: string, scopes: string): string {
|
|
86
|
+
// this URL is used to install the app. you can get it and run it on the browser, it should install the app
|
|
87
|
+
Logger.info(`installURL shop: ${shop}`);
|
|
78
88
|
return `https://${shop}/admin/oauth/authorize?client_id=${this.shop_key}&scope=${scopes}&redirect_uri=${this.redirectUri()}`;
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
private redirectUri(): string {
|
|
92
|
+
// the callback for when the merchant has approved the installation
|
|
82
93
|
return `${this.appBaseUrl}${this.endpointUri}/callback`;
|
|
83
94
|
}
|
|
84
95
|
}
|