@agnostack/next-shopify 1.1.1-alpha.2 → 1.1.1-alpha.21

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,179 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.uninstallHelper = exports.callbackHelper = exports.authHelper = exports.queryHelper = void 0;
15
- const display_1 = require("./display");
16
- const shopify_1 = require("./shopify");
17
- const queryHelper = async (_a) => {
18
- var { req, res, params } = _a, props = __rest(_a, ["req", "res", "params"]);
19
- const { query } = req;
20
- console.log(`>>> ~ query`, query);
21
- const { shop } = query !== null && query !== void 0 ? query : {};
22
- const { query: graphQuery } = params !== null && params !== void 0 ? params : {};
23
- if (!shop || !graphQuery) {
24
- return {
25
- statusCode: 400,
26
- redirectUrl: 'Invalid arguments',
27
- };
28
- }
29
- const shopify = shopify_1.getInitializedShopify(props, shop);
30
- console.log(`>>> ~ shopify`, shopify);
31
- try {
32
- const session = await shopify.Utils.loadCurrentSession(req, res);
33
- console.log(`>>> ~ session`, session);
34
- // TODO refactor
35
- // await verifyRequest(shopify, shop, session)
36
- const client = new shopify.Clients.Graphql(shop, session === null || session === void 0 ? void 0 : session.accessToken);
37
- const data = await client.query({ data: graphQuery });
38
- return {
39
- statusCode: 200,
40
- data,
41
- };
42
- }
43
- catch (error) {
44
- // TODO determine proper catch checks
45
- const errorMessage = 'Error handling query';
46
- console.error(errorMessage, error);
47
- switch (true) {
48
- case error instanceof shopify.Errors.InvalidOAuthError: {
49
- return {
50
- statusCode: 400,
51
- message: errorMessage,
52
- };
53
- }
54
- case error instanceof shopify.Errors.CookieNotFound:
55
- case error instanceof shopify.Errors.SessionNotFound: {
56
- return {
57
- statusCode: 302,
58
- redirectUrl: shopify_1.getRedirectUrl(props, {
59
- req,
60
- res,
61
- shop,
62
- query: req.query,
63
- }),
64
- };
65
- }
66
- default: {
67
- return {
68
- statusCode: 500,
69
- message: errorMessage,
70
- };
71
- }
72
- }
73
- }
74
- };
75
- exports.queryHelper = queryHelper;
76
- const authHelper = async (_a) => {
77
- var { req, res } = _a, props = __rest(_a, ["req", "res"]);
78
- const { query } = req;
79
- const { shop } = query !== null && query !== void 0 ? query : {};
80
- try {
81
- return {
82
- statusCode: 302,
83
- redirectUrl: shopify_1.getRedirectUrl(props, {
84
- req,
85
- res,
86
- query,
87
- shop,
88
- }),
89
- };
90
- }
91
- catch (error) {
92
- const errorMessage = 'Error handling auth route';
93
- console.error(errorMessage, error);
94
- return {
95
- statusCode: 500,
96
- message: errorMessage,
97
- };
98
- }
99
- };
100
- exports.authHelper = authHelper;
101
- const callbackHelper = async (_a) => {
102
- var { req, res } = _a, props = __rest(_a, ["req", "res"]);
103
- const { PAGE_PATHS, APP_WEBHOOKS } = props;
104
- const { shop, host } = req.query;
105
- if (!shop || !host) {
106
- return {
107
- statusCode: 303,
108
- redirectUrl: `${PAGE_PATHS[shopify_1.PAGE_ROUTE_NAMES.ERROR]}?code=invalid_callback`,
109
- };
110
- }
111
- const shopify = shopify_1.getInitializedShopify(props, shop);
112
- try {
113
- const session = await shopify.Auth.validateAuthCallback(req, res, req.query);
114
- await shopify_1.registerWebhooks(props, APP_WEBHOOKS, session);
115
- // TODO check for billing redirect
116
- const redirectUrl = shopify.Utils.getEmbeddedAppUrl(req);
117
- return {
118
- statusCode: 302,
119
- redirectUrl: `${redirectUrl}?${new URLSearchParams(req.query).toString()}`,
120
- };
121
- }
122
- catch (error) {
123
- const errorMessage = 'Error handling callback route';
124
- console.error(errorMessage, error);
125
- switch (true) {
126
- case error instanceof shopify.Errors.InvalidOAuthError: {
127
- return {
128
- statusCode: 400,
129
- message: errorMessage,
130
- };
131
- }
132
- case error instanceof shopify.Errors.CookieNotFound:
133
- case error instanceof shopify.Errors.SessionNotFound: {
134
- return {
135
- statusCode: 302,
136
- redirectUrl: shopify_1.getRedirectUrl(props, {
137
- req,
138
- res,
139
- shop,
140
- query: req.query,
141
- }),
142
- };
143
- }
144
- default: {
145
- return {
146
- statusCode: 500,
147
- message: errorMessage,
148
- };
149
- }
150
- }
151
- }
152
- };
153
- exports.callbackHelper = callbackHelper;
154
- const uninstallHelper = async (_a) => {
155
- var _b, _c, _d, _e;
156
- var { req } = _a, props = __rest(_a, ["req"]);
157
- try {
158
- const { domain } = req.body;
159
- const shopify = shopify_1.getInitializedShopify(props, domain);
160
- const existingSessions = await ((_c = (_b = shopify.Context.SESSION_STORAGE) === null || _b === void 0 ? void 0 : _b.findSessionsByShop) === null || _c === void 0 ? void 0 : _c.call(_b, domain));
161
- if (display_1.arrayNotEmpty(existingSessions)) {
162
- await ((_e = (_d = shopify.Context.SESSION_STORAGE) === null || _d === void 0 ? void 0 : _d.deleteSessions) === null || _e === void 0 ? void 0 : _e.call(_d, existingSessions.map((session) => session.id)));
163
- }
164
- return {
165
- statusCode: 200,
166
- message: 'success',
167
- };
168
- }
169
- catch (error) {
170
- const errorMessage = 'Error handling uninstall route';
171
- console.error(errorMessage, error);
172
- return {
173
- statusCode: 500,
174
- message: errorMessage,
175
- };
176
- }
177
- };
178
- exports.uninstallHelper = uninstallHelper;
179
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.js"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAAyC;AACzC,uCAMkB;AAEX,MAAM,WAAW,GAAG,KAAK,EAAE,EAA8B,EAAE,EAAE;QAAlC,EAAE,G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