@agnostack/next-shopify 1.6.0 → 1.7.0-alpha.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.
- package/CHANGELOG.md +141 -4
- package/dist/handlers/api.d.ts +5 -0
- package/dist/handlers/api.js +24 -7
- package/dist/handlers/api.js.map +1 -1
- package/dist/handlers/ssr.js +10 -6
- package/dist/handlers/ssr.js.map +1 -1
- package/dist/helpers/auth.js +3 -5
- package/dist/helpers/auth.js.map +1 -1
- package/dist/helpers/callback.d.ts +1 -1
- package/dist/helpers/callback.js +27 -19
- package/dist/helpers/callback.js.map +1 -1
- package/dist/helpers/graph.js +6 -4
- package/dist/helpers/graph.js.map +1 -1
- package/dist/helpers/rest.js +6 -4
- package/dist/helpers/rest.js.map +1 -1
- package/dist/helpers/uninstall.d.ts +4 -5
- package/dist/helpers/uninstall.js +32 -17
- package/dist/helpers/uninstall.js.map +1 -1
- package/dist/utils/billing.d.ts +9 -5
- package/dist/utils/billing.js +75 -27
- package/dist/utils/billing.js.map +1 -1
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.js +43 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/errors.d.ts +12 -0
- package/dist/utils/errors.js +16 -1
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/session.d.ts +14 -0
- package/dist/utils/session.js +80 -0
- package/dist/utils/session.js.map +1 -0
- package/dist/utils/shopify-api-node/beginAuth.d.ts +2 -5
- package/dist/utils/shopify-api-node/beginAuth.js +18 -10
- package/dist/utils/shopify-api-node/beginAuth.js.map +1 -1
- package/dist/utils/shopify.d.ts +3 -83
- package/dist/utils/shopify.js +39 -98
- package/dist/utils/shopify.js.map +1 -1
- package/dist/withShopify.js +24 -9
- package/dist/withShopify.js.map +1 -1
- package/package.json +4 -3
package/dist/utils/billing.d.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
export class BillingManager {
|
|
2
|
-
constructor(session: any, serverRuntimeConfig: any);
|
|
2
|
+
constructor(shopify: any, session: any, serverRuntimeConfig: any);
|
|
3
|
+
shopify: any;
|
|
3
4
|
shop: any;
|
|
5
|
+
graphClient: any;
|
|
6
|
+
session: any;
|
|
4
7
|
accessToken: any;
|
|
5
8
|
appId: any;
|
|
6
9
|
appBaseUrl: any;
|
|
7
10
|
paymentConfig: any;
|
|
8
11
|
isRecurring: boolean;
|
|
9
12
|
ensureBilling(): Promise<any>;
|
|
10
|
-
hasActiveRecurringPayment(
|
|
11
|
-
hasActiveOneTimePayment(
|
|
13
|
+
hasActiveRecurringPayment(): Promise<boolean>;
|
|
14
|
+
hasActiveOneTimePayment(endCursor?: any): any;
|
|
12
15
|
hasActivePayment(): Promise<any>;
|
|
13
16
|
requestPayment(): Promise<any>;
|
|
14
|
-
requestSinglePayment(
|
|
15
|
-
requestRecurringPayment(
|
|
17
|
+
requestSinglePayment(returnUrl: any): Promise<any>;
|
|
18
|
+
requestRecurringPayment(returnUrl: any): Promise<any>;
|
|
16
19
|
}
|
|
20
|
+
export function generatePaymentConfig(): {};
|
package/dist/utils/billing.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BillingManager = void 0;
|
|
3
|
+
exports.generatePaymentConfig = exports.BillingManager = void 0;
|
|
4
4
|
const shopify_api_1 = require("@shopify/shopify-api");
|
|
5
5
|
const display_1 = require("./display");
|
|
6
6
|
const constants_1 = require("./constants");
|
|
7
7
|
class BillingManager {
|
|
8
|
-
constructor(session, serverRuntimeConfig) {
|
|
8
|
+
constructor(shopify, session, serverRuntimeConfig) {
|
|
9
9
|
const { APP_ID, APP_BASE_URL, PAYMENT_CONFIG } = serverRuntimeConfig;
|
|
10
10
|
if (display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.shop) ||
|
|
11
11
|
display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.accessToken) ||
|
|
12
12
|
!Object.values(constants_1.BILLING_INTERVALS).includes(PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.type)) {
|
|
13
|
-
throw new shopify_api_1.
|
|
13
|
+
throw new shopify_api_1.BillingError({
|
|
14
14
|
message: 'Invalid billing configuration',
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
+
this.shopify = shopify;
|
|
17
18
|
this.shop = session.shop;
|
|
19
|
+
this.graphClient = new shopify.clients.Graphql({ session });
|
|
20
|
+
this.session = session;
|
|
18
21
|
this.accessToken = session.accessToken;
|
|
19
22
|
this.appId = APP_ID;
|
|
20
23
|
this.appBaseUrl = APP_BASE_URL;
|
|
@@ -30,8 +33,8 @@ class BillingManager {
|
|
|
30
33
|
return this.requestPayment();
|
|
31
34
|
}
|
|
32
35
|
catch (error) {
|
|
33
|
-
if (error instanceof shopify_api_1.
|
|
34
|
-
throw new shopify_api_1.
|
|
36
|
+
if (error instanceof shopify_api_1.GraphqlQueryError) {
|
|
37
|
+
throw new shopify_api_1.BillingError({
|
|
35
38
|
message: 'Failed to verify or initialize payment',
|
|
36
39
|
errorData: display_1.ensureArray((_a = error.response) === null || _a === void 0 ? void 0 : _a.errors).map(({ message }) => display_1.ensureString(message)),
|
|
37
40
|
});
|
|
@@ -39,9 +42,9 @@ class BillingManager {
|
|
|
39
42
|
throw error;
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
|
-
async hasActiveRecurringPayment(
|
|
45
|
+
async hasActiveRecurringPayment() {
|
|
43
46
|
var _a, _b, _c;
|
|
44
|
-
const currentInstallations = await
|
|
47
|
+
const currentInstallations = await this.graphClient.query({
|
|
45
48
|
data: constants_1.RECURRING_PURCHASES_QUERY,
|
|
46
49
|
});
|
|
47
50
|
const subscriptions = (_c = (_b = (_a = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.currentAppInstallation) === null || _c === void 0 ? void 0 : _c.activeSubscriptions;
|
|
@@ -51,21 +54,22 @@ class BillingManager {
|
|
|
51
54
|
));
|
|
52
55
|
return display_1.objectNotEmpty(matchingSubscription);
|
|
53
56
|
}
|
|
54
|
-
async hasActiveOneTimePayment(
|
|
57
|
+
async hasActiveOneTimePayment(endCursor = null) {
|
|
55
58
|
var _a, _b, _c, _d, _e;
|
|
56
|
-
const currentInstallations = await
|
|
59
|
+
const currentInstallations = await this.graphClient.query({
|
|
57
60
|
data: {
|
|
58
61
|
query: constants_1.ONE_TIME_PURCHASES_QUERY,
|
|
59
62
|
variables: { endCursor },
|
|
60
63
|
},
|
|
61
64
|
});
|
|
62
65
|
const purchases = (_c = (_b = (_a = currentInstallations === null || currentInstallations === void 0 ? void 0 : currentInstallations.body) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.currentAppInstallation) === null || _c === void 0 ? void 0 : _c.oneTimePurchases;
|
|
66
|
+
// TODO: clean this up
|
|
63
67
|
const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find(({ node } = {}) => {
|
|
64
68
|
if (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name) && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')) {
|
|
65
|
-
console.log(`>>> ~ node`, {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
})
|
|
69
|
+
// console.log(`>>> ~ node`, {
|
|
70
|
+
// node,
|
|
71
|
+
// truish: (!isTrue(node?.test) || this.paymentConfig.test),
|
|
72
|
+
// })
|
|
69
73
|
}
|
|
70
74
|
return (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
|
|
71
75
|
&& ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
|
|
@@ -77,19 +81,17 @@ class BillingManager {
|
|
|
77
81
|
return true;
|
|
78
82
|
}
|
|
79
83
|
if ((_d = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _d === void 0 ? void 0 : _d.hasNextPage) {
|
|
80
|
-
return this.hasActiveOneTimePayment(
|
|
84
|
+
return this.hasActiveOneTimePayment((_e = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _e === void 0 ? void 0 : _e.endCursor);
|
|
81
85
|
}
|
|
82
86
|
return false;
|
|
83
87
|
}
|
|
84
88
|
async hasActivePayment() {
|
|
85
|
-
const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
|
|
86
89
|
if (this.isRecurring) {
|
|
87
|
-
return this.hasActiveRecurringPayment(
|
|
90
|
+
return this.hasActiveRecurringPayment();
|
|
88
91
|
}
|
|
89
|
-
return this.hasActiveOneTimePayment(
|
|
92
|
+
return this.hasActiveOneTimePayment();
|
|
90
93
|
}
|
|
91
94
|
async requestPayment() {
|
|
92
|
-
const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
|
|
93
95
|
// TODO: explore objectToQuerystring
|
|
94
96
|
const queryParams = [
|
|
95
97
|
`shop=${this.shop}`,
|
|
@@ -97,19 +99,19 @@ class BillingManager {
|
|
|
97
99
|
];
|
|
98
100
|
const returnUrl = `${this.appBaseUrl}?${queryParams.join('&')}`;
|
|
99
101
|
const data = this.isRecurring
|
|
100
|
-
? await this.requestRecurringPayment(
|
|
101
|
-
: await this.requestSinglePayment(
|
|
102
|
+
? await this.requestRecurringPayment(returnUrl)
|
|
103
|
+
: await this.requestSinglePayment(returnUrl);
|
|
102
104
|
if (display_1.arrayNotEmpty(data === null || data === void 0 ? void 0 : data.userErrors)) {
|
|
103
|
-
throw new shopify_api_1.
|
|
105
|
+
throw new shopify_api_1.BillingError({
|
|
104
106
|
message: 'User error requesting payment',
|
|
105
107
|
});
|
|
106
108
|
}
|
|
107
109
|
return data === null || data === void 0 ? void 0 : data.confirmationUrl;
|
|
108
110
|
}
|
|
109
|
-
async requestSinglePayment(
|
|
111
|
+
async requestSinglePayment(returnUrl) {
|
|
110
112
|
var _a, _b, _c, _d;
|
|
111
113
|
const { price, name, test, } = this.paymentConfig;
|
|
112
|
-
const mutationResponse = await
|
|
114
|
+
const mutationResponse = await this.graphClient.query({
|
|
113
115
|
data: {
|
|
114
116
|
query: constants_1.ONE_TIME_PURCHASE_MUTATION,
|
|
115
117
|
variables: {
|
|
@@ -121,17 +123,17 @@ class BillingManager {
|
|
|
121
123
|
},
|
|
122
124
|
});
|
|
123
125
|
if (((_a = mutationResponse === null || mutationResponse === void 0 ? void 0 : mutationResponse.body) === null || _a === void 0 ? void 0 : _a.errors) && display_1.arrayNotEmpty((_b = mutationResponse === null || mutationResponse === void 0 ? void 0 : mutationResponse.body) === null || _b === void 0 ? void 0 : _b.errors)) {
|
|
124
|
-
throw new shopify_api_1.
|
|
126
|
+
throw new shopify_api_1.BillingError({
|
|
125
127
|
message: 'Error executing one-time purchase',
|
|
126
128
|
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
127
129
|
});
|
|
128
130
|
}
|
|
129
131
|
return (_d = (_c = mutationResponse === null || mutationResponse === void 0 ? void 0 : mutationResponse.body) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.appPurchaseOneTimeCreate;
|
|
130
132
|
}
|
|
131
|
-
async requestRecurringPayment(
|
|
133
|
+
async requestRecurringPayment(returnUrl) {
|
|
132
134
|
var _a, _b, _c, _d;
|
|
133
135
|
const { price, name, test, type: interval, } = this.paymentConfig;
|
|
134
|
-
const mutationResponse = await
|
|
136
|
+
const mutationResponse = await this.graphClient.query({
|
|
135
137
|
data: {
|
|
136
138
|
query: constants_1.RECURRING_PURCHASE_MUTATION,
|
|
137
139
|
variables: {
|
|
@@ -150,7 +152,7 @@ class BillingManager {
|
|
|
150
152
|
},
|
|
151
153
|
});
|
|
152
154
|
if (((_a = mutationResponse === null || mutationResponse === void 0 ? void 0 : mutationResponse.body) === null || _a === void 0 ? void 0 : _a.errors) && display_1.arrayNotEmpty((_b = mutationResponse === null || mutationResponse === void 0 ? void 0 : mutationResponse.body) === null || _b === void 0 ? void 0 : _b.errors)) {
|
|
153
|
-
throw new shopify_api_1.
|
|
155
|
+
throw new shopify_api_1.BillingError({
|
|
154
156
|
message: 'Error executing recurring purchase',
|
|
155
157
|
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
156
158
|
});
|
|
@@ -159,4 +161,50 @@ class BillingManager {
|
|
|
159
161
|
}
|
|
160
162
|
}
|
|
161
163
|
exports.BillingManager = BillingManager;
|
|
164
|
+
// TODO enable billing management
|
|
165
|
+
// eslint-disable-next-line arrow-body-style
|
|
166
|
+
const generatePaymentConfig = () => {
|
|
167
|
+
return {};
|
|
168
|
+
/*
|
|
169
|
+
const {
|
|
170
|
+
name,
|
|
171
|
+
price,
|
|
172
|
+
currency = 'USD',
|
|
173
|
+
type = BILLING_INTERVALS.ONE_TIME,
|
|
174
|
+
} = ensureObject(paymentConfig)
|
|
175
|
+
const { debugMode, environment } = ensureObject(data)
|
|
176
|
+
|
|
177
|
+
if (objectEmpty(paymentConfig) || stringEmpty(environment)) {
|
|
178
|
+
return undefined
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const notProduction = (environment !== 'production')
|
|
182
|
+
|
|
183
|
+
// TODO ensure this logic is correct
|
|
184
|
+
let test = environment !== 'production'
|
|
185
|
+
if (debugMode) {
|
|
186
|
+
test = true
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const _paymentConfig = {
|
|
190
|
+
type,
|
|
191
|
+
required: (environment !== 'development'),
|
|
192
|
+
test,
|
|
193
|
+
name: `${name}${notProduction ? ` - ${environment}` : ''} - ${unsnakecase(type)}`,
|
|
194
|
+
price: {
|
|
195
|
+
amount: price,
|
|
196
|
+
currencyCode: currency,
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
// TODO: clean this up
|
|
200
|
+
console.log(`>>> ~ _paymentConfig`, {
|
|
201
|
+
_paymentConfig,
|
|
202
|
+
debugMode,
|
|
203
|
+
debugEnv: process.env.DEBUG,
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
return _paymentConfig
|
|
207
|
+
*/
|
|
208
|
+
};
|
|
209
|
+
exports.generatePaymentConfig = generatePaymentConfig;
|
|
162
210
|
//# sourceMappingURL=billing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/utils/billing.js"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/utils/billing.js"],"names":[],"mappings":";;;AAAA,sDAAsE;AAEtE,uCAQkB;AAClB,2CAOoB;AAEpB,MAAa,cAAc;IACzB,YAAY,OAAO,EAAE,OAAO,EAAE,mBAAmB;QAC/C,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,mBAAmB,CAAA;QAEpE,IACE,qBAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC;YAC1B,qBAAW,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC;YACjC,CAAC,MAAM,CAAC,MAAM,CAAC,6BAAiB,CAAC,CAAC,QAAQ,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,EAChE;YACA,MAAM,IAAI,0BAAY,CAAC;gBACrB,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAA;SACH;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QAC3D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IA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 +8,10 @@ export namespace API_ROUTE_NAMES {
|
|
|
8
8
|
const AUTH_CALLBACK: string;
|
|
9
9
|
const APP_UNINSTALLED: string;
|
|
10
10
|
}
|
|
11
|
+
export namespace API_WEBHOOK_TOPICS {
|
|
12
|
+
const APP_UNINSTALLED_1: string;
|
|
13
|
+
export { APP_UNINSTALLED_1 as APP_UNINSTALLED };
|
|
14
|
+
}
|
|
11
15
|
export namespace BILLING_INTERVALS {
|
|
12
16
|
const ONE_TIME: string;
|
|
13
17
|
const EVERY_30_DAYS: string;
|
package/dist/utils/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ONE_TIME_PURCHASE_MUTATION = exports.RECURRING_PURCHASE_MUTATION = exports.ONE_TIME_PURCHASES_QUERY = exports.RECURRING_PURCHASES_QUERY = exports.SHOP_QUERY = exports.RECURRING_INTERVALS = exports.BILLING_INTERVALS = exports.API_ROUTE_NAMES = exports.PAGE_ROUTE_NAMES = exports.COLLECTION_ROOT = void 0;
|
|
3
|
+
exports.ONE_TIME_PURCHASE_MUTATION = exports.RECURRING_PURCHASE_MUTATION = exports.ONE_TIME_PURCHASES_QUERY = exports.RECURRING_PURCHASES_QUERY = exports.SHOP_QUERY = exports.RECURRING_INTERVALS = exports.BILLING_INTERVALS = exports.API_WEBHOOK_TOPICS = exports.API_ROUTE_NAMES = exports.PAGE_ROUTE_NAMES = exports.COLLECTION_ROOT = void 0;
|
|
4
4
|
exports.COLLECTION_ROOT = 'oauth-data';
|
|
5
5
|
exports.PAGE_ROUTE_NAMES = {
|
|
6
6
|
EXIT: 'pageRouteExit',
|
|
@@ -11,6 +11,9 @@ exports.API_ROUTE_NAMES = {
|
|
|
11
11
|
AUTH_CALLBACK: 'apiRouteAuthCallback',
|
|
12
12
|
APP_UNINSTALLED: 'apiRouteAppUninstalled',
|
|
13
13
|
};
|
|
14
|
+
exports.API_WEBHOOK_TOPICS = {
|
|
15
|
+
APP_UNINSTALLED: 'APP_UNINSTALLED',
|
|
16
|
+
};
|
|
14
17
|
exports.BILLING_INTERVALS = {
|
|
15
18
|
ONE_TIME: 'ONE_TIME',
|
|
16
19
|
EVERY_30_DAYS: 'EVERY_30_DAYS',
|
|
@@ -20,6 +23,45 @@ exports.RECURRING_INTERVALS = [
|
|
|
20
23
|
exports.BILLING_INTERVALS.EVERY_30_DAYS,
|
|
21
24
|
exports.BILLING_INTERVALS.ANNUAL
|
|
22
25
|
];
|
|
26
|
+
// TODO can we remove?
|
|
27
|
+
/*
|
|
28
|
+
export const SHOP_DATA_QUERY = `
|
|
29
|
+
{
|
|
30
|
+
shop {
|
|
31
|
+
url
|
|
32
|
+
name
|
|
33
|
+
myshopifyDomain
|
|
34
|
+
checkoutApiSupported
|
|
35
|
+
taxesIncluded
|
|
36
|
+
taxShipping
|
|
37
|
+
orderNumberFormatPrefix
|
|
38
|
+
orderNumberFormatSuffix
|
|
39
|
+
orderTags (first: 100) {
|
|
40
|
+
edges {
|
|
41
|
+
node
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
productVendors (first: 100) {
|
|
45
|
+
edges {
|
|
46
|
+
node
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
customerTags (first: 100) {
|
|
50
|
+
edges {
|
|
51
|
+
node
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
features {
|
|
55
|
+
giftCards
|
|
56
|
+
}
|
|
57
|
+
plan {
|
|
58
|
+
shopifyPlus
|
|
59
|
+
partnerDevelopment
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`
|
|
64
|
+
*/
|
|
23
65
|
exports.SHOP_QUERY = `
|
|
24
66
|
{
|
|
25
67
|
shop {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.js"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GA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evC,CAAA;AAEY,QAAA,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;CAoB1C,CAAA;AAEY,QAAA,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;CAoBzC,CAAA"}
|
package/dist/utils/errors.d.ts
CHANGED
|
@@ -10,3 +10,15 @@ export namespace ERROR_CODES {
|
|
|
10
10
|
const MISSING_SHOP: string;
|
|
11
11
|
const INVALID_CALLBACK: string;
|
|
12
12
|
}
|
|
13
|
+
export function getAuthErrorResponse({ error, shop, serverRuntimeConfig }: {
|
|
14
|
+
error: any;
|
|
15
|
+
shop: any;
|
|
16
|
+
serverRuntimeConfig: any;
|
|
17
|
+
}): {
|
|
18
|
+
statusCode: number;
|
|
19
|
+
message: any;
|
|
20
|
+
headers: {
|
|
21
|
+
'X-Shopify-API-Request-Failure-Reauthorize': string;
|
|
22
|
+
'X-Shopify-API-Request-Failure-Reauthorize-Url': any;
|
|
23
|
+
};
|
|
24
|
+
};
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ERROR_CODES = exports.ShopifyAuthenticationError = void 0;
|
|
3
|
+
exports.getAuthErrorResponse = exports.ERROR_CODES = exports.ShopifyAuthenticationError = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
4
5
|
class ShopifyAuthenticationError extends Error {
|
|
5
6
|
constructor(message, data) {
|
|
6
7
|
super(message);
|
|
@@ -18,4 +19,18 @@ exports.ERROR_CODES = {
|
|
|
18
19
|
MISSING_SHOP: 'no_shop_provided',
|
|
19
20
|
INVALID_CALLBACK: 'invalid_callback',
|
|
20
21
|
};
|
|
22
|
+
const getAuthErrorResponse = ({ error, shop, serverRuntimeConfig }) => {
|
|
23
|
+
const { message, data } = error;
|
|
24
|
+
const { API_URLS } = serverRuntimeConfig;
|
|
25
|
+
const reauthorizationUrl = (data === null || data === void 0 ? void 0 : data.redirectUrl) || `${API_URLS[constants_1.API_ROUTE_NAMES.AUTH]}?shop=${shop}`;
|
|
26
|
+
return {
|
|
27
|
+
statusCode: 403,
|
|
28
|
+
message,
|
|
29
|
+
headers: {
|
|
30
|
+
'X-Shopify-API-Request-Failure-Reauthorize': '1',
|
|
31
|
+
'X-Shopify-API-Request-Failure-Reauthorize-Url': reauthorizationUrl,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.getAuthErrorResponse = getAuthErrorResponse;
|
|
21
36
|
//# sourceMappingURL=errors.js.map
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.js"],"names":[],"mappings":";;;AAAA,MAAa,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAO,EAAE,IAAI;QACvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAA;IACnE,CAAC;CACF;AAPD,gEAOC;AAEY,QAAA,WAAW,GAAG;IACzB,QAAQ,EAAE,gBAAgB;IAC1B,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,eAAe;IACxB,KAAK,EAAE,aAAa;IACpB,YAAY,EAAE,kBAAkB;IAChC,gBAAgB,EAAE,kBAAkB;CACrC,CAAA"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/utils/errors.js"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,MAAa,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAO,EAAE,IAAI;QACvB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;QACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,0BAA0B,CAAC,SAAS,CAAC,CAAA;IACnE,CAAC;CACF;AAPD,gEAOC;AAEY,QAAA,WAAW,GAAG;IACzB,QAAQ,EAAE,gBAAgB;IAC1B,KAAK,EAAE,aAAa;IACpB,OAAO,EAAE,eAAe;IACxB,KAAK,EAAE,aAAa;IACpB,YAAY,EAAE,kBAAkB;IAChC,gBAAgB,EAAE,kBAAkB;CACrC,CAAA;AAEM,MAAM,oBAAoB,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAC3E,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAC/B,MAAM,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAA;IACxC,MAAM,kBAAkB,GAAG,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,WAAW,KAAI,GAAG,QAAQ,CAAC,2BAAe,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAA;IAEhG,OAAO;QACL,UAAU,EAAE,GAAG;QACf,OAAO;QACP,OAAO,EAAE;YACP,2CAA2C,EAAE,GAAG;YAChD,+CAA+C,EAAE,kBAAkB;SACpE;KACF,CAAA;AACH,CAAC,CAAA;AAbY,QAAA,oBAAoB,wBAahC"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -15,5 +15,6 @@ __exportStar(require("./constants"), exports);
|
|
|
15
15
|
__exportStar(require("./display"), exports);
|
|
16
16
|
__exportStar(require("./errors"), exports);
|
|
17
17
|
__exportStar(require("./firebase"), exports);
|
|
18
|
+
__exportStar(require("./session"), exports);
|
|
18
19
|
__exportStar(require("./shopify"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,4CAAyB;AACzB,2CAAwB;AACxB,6CAA0B;AAC1B,4CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,8CAA2B;AAC3B,4CAAyB;AACzB,2CAAwB;AACxB,6CAA0B;AAC1B,4CAAyB;AACzB,4CAAyB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function getSessionStorage(shopify: any, serverRuntimeConfig: any, _shop: any): {
|
|
2
|
+
store: (session: any) => Promise<boolean>;
|
|
3
|
+
load: (id: any) => Promise<any>;
|
|
4
|
+
delete: (id: any) => Promise<void>;
|
|
5
|
+
deleteMany: (ids: any) => Promise<void>;
|
|
6
|
+
find: (__shop: any) => Promise<any[]>;
|
|
7
|
+
};
|
|
8
|
+
export function getVerifiedSession({ req, res, shop, shopify, serverRuntimeConfig }: {
|
|
9
|
+
req: any;
|
|
10
|
+
res: any;
|
|
11
|
+
shop: any;
|
|
12
|
+
shopify: any;
|
|
13
|
+
serverRuntimeConfig: any;
|
|
14
|
+
}): Promise<any>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVerifiedSession = exports.getSessionStorage = void 0;
|
|
4
|
+
const shopify_api_1 = require("@shopify/shopify-api");
|
|
5
|
+
const display_1 = require("./display");
|
|
6
|
+
const billing_1 = require("./billing");
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
const firebase_1 = require("./firebase");
|
|
10
|
+
// TODO cleanup/consolidate getSessionStorage and getInitializedShopify
|
|
11
|
+
const getSessionStorage = (shopify, serverRuntimeConfig, _shop) => {
|
|
12
|
+
const { FB_CONFIG, FB_ROOT_COLLECTION, APP_ID } = serverRuntimeConfig;
|
|
13
|
+
const data = { app: APP_ID, shop: shopify.utils.sanitizeShop(_shop) };
|
|
14
|
+
console.log(`>>> > getSessionStorage > data:`, data);
|
|
15
|
+
const sessionHandler = firebase_1.FirebaseSessionHandler.getInstance(FB_CONFIG, FB_ROOT_COLLECTION);
|
|
16
|
+
return {
|
|
17
|
+
store: async (session) => firebase_1.storeCallback(session, data, sessionHandler),
|
|
18
|
+
load: async (id) => firebase_1.loadCallback(id, data, sessionHandler),
|
|
19
|
+
delete: async (id) => firebase_1.deleteSessionsCallback(id, data, sessionHandler),
|
|
20
|
+
deleteMany: async (ids) => firebase_1.deleteSessionsCallback(ids, data, sessionHandler),
|
|
21
|
+
find: async (__shop) => firebase_1.findSessionsByShop(shopify.utils.sanitizeShop(__shop), data, sessionHandler),
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
exports.getSessionStorage = getSessionStorage;
|
|
25
|
+
// TODO re-enable (check scopes and expiration)
|
|
26
|
+
const isSessionActive = (session, config) => {
|
|
27
|
+
console.log(`>>> > isSessionActive > TODO: re-enable`, { session, config });
|
|
28
|
+
return true;
|
|
29
|
+
// const scopesUnchanged = true
|
|
30
|
+
// if (
|
|
31
|
+
// scopesUnchanged &&
|
|
32
|
+
// (!session.expires || session.expires >= new Date())
|
|
33
|
+
// ) {
|
|
34
|
+
// return true
|
|
35
|
+
// }
|
|
36
|
+
// return false
|
|
37
|
+
};
|
|
38
|
+
const getVerifiedSession = async ({ req, res, shop, shopify, serverRuntimeConfig }) => {
|
|
39
|
+
try {
|
|
40
|
+
const sessionStorage = exports.getSessionStorage(shopify, serverRuntimeConfig, shop);
|
|
41
|
+
console.log(`>>> > getVerifiedSession > sessionStorage:`, sessionStorage);
|
|
42
|
+
const { PAYMENT_CONFIG } = serverRuntimeConfig !== null && serverRuntimeConfig !== void 0 ? serverRuntimeConfig : {};
|
|
43
|
+
const sessionId = await shopify.session.getCurrentId({
|
|
44
|
+
isOnline: true,
|
|
45
|
+
rawRequest: req,
|
|
46
|
+
rawResponse: res,
|
|
47
|
+
});
|
|
48
|
+
const session = await sessionStorage.load(sessionId);
|
|
49
|
+
if (!isSessionActive(session, shopify.config)) {
|
|
50
|
+
throw new errors_1.ShopifyAuthenticationError('Inactive session');
|
|
51
|
+
}
|
|
52
|
+
if (shop && (session === null || session === void 0 ? void 0 : session.shop) !== shop) {
|
|
53
|
+
throw new errors_1.ShopifyAuthenticationError('Invalid shop');
|
|
54
|
+
}
|
|
55
|
+
if (PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.required) {
|
|
56
|
+
const billingManager = new billing_1.BillingManager(shopify, session, serverRuntimeConfig);
|
|
57
|
+
// TODO: clean up
|
|
58
|
+
const confirmationUrl = await billingManager.ensureBilling();
|
|
59
|
+
console.log(`>>> > getVerifiedSession > confirmationUrl:`, confirmationUrl);
|
|
60
|
+
if (display_1.stringNotEmpty(confirmationUrl)) {
|
|
61
|
+
throw new errors_1.ShopifyAuthenticationError('Invalid payment status', { redirectUrl: confirmationUrl });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// NOTE making a test call to ensure a valid session for free apps
|
|
66
|
+
const client = new shopify.clients.Graphql({ session });
|
|
67
|
+
await client.query({ data: constants_1.SHOP_QUERY });
|
|
68
|
+
}
|
|
69
|
+
return session;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof shopify_api_1.HttpResponseError &&
|
|
73
|
+
error.response.code === 401) {
|
|
74
|
+
throw new errors_1.ShopifyAuthenticationError('Not authenticated');
|
|
75
|
+
}
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
exports.getVerifiedSession = getVerifiedSession;
|
|
80
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.js"],"names":[],"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,CAAC,OAAO,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAA;YAChF,iBAAiB;YACjB,MAAM,eAAe,GAAG,MAAM,cAAc,CAAC,aAAa,EAAE,CAAA;YAC5D,OAAO,CAAC,GAAG,CAAC,6CAA6C,EAAE,eAAe,CAAC,CAAA;YAE3E,IAAI,wBAAc,CAAC,eAAe,CAAC,EAAE;gBACnC,MAAM,IAAI,mCAA0B,CAClC,wBAAwB,EACxB,EAAE,WAAW,EAAE,eAAe,EAAE,CACjC,CAAA;aACF;SACF;aAAM;YACL,kEAAkE;YAClE,MAAM,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;YACvD,MAAM,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,sBAAU,EAAE,CAAC,CAAA;SACzC;QAED,OAAO,OAAO,CAAA;KACf;IAAC,OAAO,KAAK,EAAE;QACd,IACE,KAAK,YAAY,+BAAiB;YAClC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG,EAC3B;YACA,MAAM,IAAI,mCAA0B,CAAC,mBAAmB,CAAC,CAAA;SAC1D;QAED,MAAM,KAAK,CAAA;KACZ;AACH,CAAC,CAAA;AApDY,QAAA,kBAAkB,sBAoD9B"}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
export function beginAuth({
|
|
2
|
-
APP_CONFIG: any;
|
|
3
|
-
API_URLS: any;
|
|
4
|
-
}, { req, res, shop: _shop, isOnline, }: {
|
|
1
|
+
export function beginAuth(props: any, { req, res, shop: shopProp, isOnline, }: {
|
|
5
2
|
req: any;
|
|
6
3
|
res: any;
|
|
7
4
|
shop: any;
|
|
8
5
|
isOnline?: boolean;
|
|
9
|
-
}): string
|
|
6
|
+
}): Promise<string>;
|
|
@@ -4,29 +4,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.beginAuth = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
8
|
const cookies_1 = __importDefault(require("cookies"));
|
|
8
9
|
const shopify_api_1 = require("@shopify/shopify-api");
|
|
9
10
|
const display_1 = require("../display");
|
|
10
11
|
const constants_1 = require("../constants");
|
|
12
|
+
const shopify_1 = require("../shopify");
|
|
11
13
|
// NOTE this is a custom implementation of the @shopify/shopify-api beginAuth method... see NOTE below
|
|
12
|
-
const beginAuth = (
|
|
14
|
+
const beginAuth = async (props, { req, res, shop: shopProp, isOnline = true, }) => {
|
|
13
15
|
var _a;
|
|
14
|
-
const
|
|
16
|
+
const { APP_CONFIG, API_URLS } = props;
|
|
17
|
+
const _shop = shopProp || ((_a = req.query) === null || _a === void 0 ? void 0 : _a.shop);
|
|
18
|
+
// TODO: do we need to pass along apiVersion here?
|
|
19
|
+
const shopify = shopify_1.getInitializedShopify(props);
|
|
20
|
+
const shop = shopify.utils.sanitizeShop(_shop);
|
|
15
21
|
const state = `${isOnline ? 'online' : 'offline'}_${display_1.getGUID()}`;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
cookies.set(shopify_api_1.Shopify.Auth.STATE_COOKIE_NAME, state, {
|
|
22
|
+
const keys = [APP_CONFIG.apiSecretKey];
|
|
23
|
+
const cookies = new cookies_1.default(req, res, { keys, secure: true });
|
|
24
|
+
const cookieOptions = {
|
|
21
25
|
sameSite: 'none',
|
|
22
26
|
expires: new Date(Date.now() + 60000),
|
|
23
27
|
signed: true,
|
|
24
28
|
secure: true,
|
|
25
|
-
}
|
|
29
|
+
};
|
|
30
|
+
const sigName = `${shopify_api_1.STATE_COOKIE_NAME}.sig`;
|
|
31
|
+
const signature = await crypto_1.default.createHmac('sha256', keys[0]).update(state).digest('base64');
|
|
32
|
+
cookies.set(shopify_api_1.STATE_COOKIE_NAME, state, cookieOptions);
|
|
33
|
+
cookies.set(sigName, signature, cookieOptions);
|
|
26
34
|
// TODO: explore objectToQuerystring
|
|
27
35
|
const queryParams = new URLSearchParams({
|
|
28
|
-
client_id: APP_CONFIG.
|
|
29
|
-
scope: APP_CONFIG.
|
|
36
|
+
client_id: APP_CONFIG.apiKey,
|
|
37
|
+
scope: APP_CONFIG.scopes,
|
|
30
38
|
redirect_uri: API_URLS[constants_1.API_ROUTE_NAMES.AUTH_CALLBACK],
|
|
31
39
|
state,
|
|
32
40
|
'grant_options[]': isOnline ? 'per-user' : '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beginAuth.js","sourceRoot":"","sources":["../../../src/utils/shopify-api-node/beginAuth.js"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"beginAuth.js","sourceRoot":"","sources":["../../../src/utils/shopify-api-node/beginAuth.js"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,sDAA6B;AAC7B,sDAAwD;AAExD,wCAAoC;AACpC,4CAA8C;AAC9C,wCAAkD;AAElD,sGAAsG;AAC/F,MAAM,SAAS,GAAG,KAAK,EAAE,KAAK,EAAE,EACrC,GAAG,EACH,GAAG,EACH,IAAI,EAAE,QAAQ,EACd,QAAQ,GAAG,IAAI,GAChB,EAAE,EAAE;;IACH,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IACtC,MAAM,KAAK,GAAG,QAAQ,KAAI,MAAA,GAAG,CAAC,KAAK,0CAAE,IAAI,CAAA,CAAA;IACzC,kDAAkD;IAClD,MAAM,OAAO,GAAG,+BAAqB,CAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;IAC9C,MAAM,KAAK,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,IAAI,iBAAO,EAAE,EAAE,CAAA;IAC/D,MAAM,I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