@agnostack/next-shopify 1.6.0 → 1.7.0-alpha.2
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 +85 -4
- package/dist/handlers/api.d.ts +5 -0
- package/dist/handlers/api.js +19 -7
- package/dist/handlers/api.js.map +1 -1
- package/dist/handlers/ssr.js +7 -6
- package/dist/handlers/ssr.js.map +1 -1
- package/dist/helpers/auth.js +2 -5
- package/dist/helpers/auth.js.map +1 -1
- package/dist/helpers/callback.d.ts +1 -1
- package/dist/helpers/callback.js +25 -19
- package/dist/helpers/callback.js.map +1 -1
- package/dist/helpers/graph.js +5 -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 +31 -17
- package/dist/helpers/uninstall.js.map +1 -1
- package/dist/utils/billing.d.ts +9 -5
- package/dist/utils/billing.js +70 -23
- package/dist/utils/billing.js.map +1 -1
- package/dist/utils/constants.js +39 -0
- 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/firebase.js +6 -0
- package/dist/utils/firebase.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/session.d.ts +14 -0
- package/dist/utils/session.js +86 -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 +17 -10
- package/dist/utils/shopify-api-node/beginAuth.js.map +1 -1
- package/dist/utils/shopify.d.ts +2 -83
- package/dist/utils/shopify.js +13 -99
- package/dist/utils/shopify.js.map +1 -1
- package/dist/utils/webhooks.d.ts +1 -0
- package/dist/utils/webhooks.js +22 -0
- package/dist/utils/webhooks.js.map +1 -0
- package/dist/withShopify.js +12 -8
- package/dist/withShopify.js.map +1 -1
- package/package.json +4 -3
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,9 +54,9 @@ 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 },
|
|
@@ -77,19 +80,17 @@ class BillingManager {
|
|
|
77
80
|
return true;
|
|
78
81
|
}
|
|
79
82
|
if ((_d = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _d === void 0 ? void 0 : _d.hasNextPage) {
|
|
80
|
-
return this.hasActiveOneTimePayment(
|
|
83
|
+
return this.hasActiveOneTimePayment((_e = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _e === void 0 ? void 0 : _e.endCursor);
|
|
81
84
|
}
|
|
82
85
|
return false;
|
|
83
86
|
}
|
|
84
87
|
async hasActivePayment() {
|
|
85
|
-
const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
|
|
86
88
|
if (this.isRecurring) {
|
|
87
|
-
return this.hasActiveRecurringPayment(
|
|
89
|
+
return this.hasActiveRecurringPayment();
|
|
88
90
|
}
|
|
89
|
-
return this.hasActiveOneTimePayment(
|
|
91
|
+
return this.hasActiveOneTimePayment();
|
|
90
92
|
}
|
|
91
93
|
async requestPayment() {
|
|
92
|
-
const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
|
|
93
94
|
// TODO: explore objectToQuerystring
|
|
94
95
|
const queryParams = [
|
|
95
96
|
`shop=${this.shop}`,
|
|
@@ -97,19 +98,19 @@ class BillingManager {
|
|
|
97
98
|
];
|
|
98
99
|
const returnUrl = `${this.appBaseUrl}?${queryParams.join('&')}`;
|
|
99
100
|
const data = this.isRecurring
|
|
100
|
-
? await this.requestRecurringPayment(
|
|
101
|
-
: await this.requestSinglePayment(
|
|
101
|
+
? await this.requestRecurringPayment(returnUrl)
|
|
102
|
+
: await this.requestSinglePayment(returnUrl);
|
|
102
103
|
if (display_1.arrayNotEmpty(data === null || data === void 0 ? void 0 : data.userErrors)) {
|
|
103
|
-
throw new shopify_api_1.
|
|
104
|
+
throw new shopify_api_1.BillingError({
|
|
104
105
|
message: 'User error requesting payment',
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
return data === null || data === void 0 ? void 0 : data.confirmationUrl;
|
|
108
109
|
}
|
|
109
|
-
async requestSinglePayment(
|
|
110
|
+
async requestSinglePayment(returnUrl) {
|
|
110
111
|
var _a, _b, _c, _d;
|
|
111
112
|
const { price, name, test, } = this.paymentConfig;
|
|
112
|
-
const mutationResponse = await
|
|
113
|
+
const mutationResponse = await this.graphClient.query({
|
|
113
114
|
data: {
|
|
114
115
|
query: constants_1.ONE_TIME_PURCHASE_MUTATION,
|
|
115
116
|
variables: {
|
|
@@ -121,17 +122,17 @@ class BillingManager {
|
|
|
121
122
|
},
|
|
122
123
|
});
|
|
123
124
|
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.
|
|
125
|
+
throw new shopify_api_1.BillingError({
|
|
125
126
|
message: 'Error executing one-time purchase',
|
|
126
127
|
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
130
|
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
131
|
}
|
|
131
|
-
async requestRecurringPayment(
|
|
132
|
+
async requestRecurringPayment(returnUrl) {
|
|
132
133
|
var _a, _b, _c, _d;
|
|
133
134
|
const { price, name, test, type: interval, } = this.paymentConfig;
|
|
134
|
-
const mutationResponse = await
|
|
135
|
+
const mutationResponse = await this.graphClient.query({
|
|
135
136
|
data: {
|
|
136
137
|
query: constants_1.RECURRING_PURCHASE_MUTATION,
|
|
137
138
|
variables: {
|
|
@@ -150,7 +151,7 @@ class BillingManager {
|
|
|
150
151
|
},
|
|
151
152
|
});
|
|
152
153
|
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.
|
|
154
|
+
throw new shopify_api_1.BillingError({
|
|
154
155
|
message: 'Error executing recurring purchase',
|
|
155
156
|
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
156
157
|
});
|
|
@@ -159,4 +160,50 @@ class BillingManager {
|
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
exports.BillingManager = BillingManager;
|
|
163
|
+
// TODO enable billing management
|
|
164
|
+
// eslint-disable-next-line arrow-body-style
|
|
165
|
+
const generatePaymentConfig = () => {
|
|
166
|
+
return {};
|
|
167
|
+
/*
|
|
168
|
+
const {
|
|
169
|
+
name,
|
|
170
|
+
price,
|
|
171
|
+
currency = 'USD',
|
|
172
|
+
type = BILLING_INTERVALS.ONE_TIME,
|
|
173
|
+
} = ensureObject(paymentConfig)
|
|
174
|
+
const { debugMode, environment } = ensureObject(data)
|
|
175
|
+
|
|
176
|
+
if (objectEmpty(paymentConfig) || stringEmpty(environment)) {
|
|
177
|
+
return undefined
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const notProduction = (environment !== 'production')
|
|
181
|
+
|
|
182
|
+
// TODO ensure this logic is correct
|
|
183
|
+
let test = environment !== 'production'
|
|
184
|
+
if (debugMode) {
|
|
185
|
+
test = true
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const _paymentConfig = {
|
|
189
|
+
type,
|
|
190
|
+
required: (environment !== 'development'),
|
|
191
|
+
test,
|
|
192
|
+
name: `${name}${notProduction ? ` - ${environment}` : ''} - ${unsnakecase(type)}`,
|
|
193
|
+
price: {
|
|
194
|
+
amount: price,
|
|
195
|
+
currencyCode: currency,
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
console.log(`>>> ~ _paymentConfig`, {
|
|
200
|
+
_paymentConfig,
|
|
201
|
+
debugMode,
|
|
202
|
+
debugEnv: process.env.DEBUG,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
return _paymentConfig
|
|
206
|
+
*/
|
|
207
|
+
};
|
|
208
|
+
exports.generatePaymentConfig = generatePaymentConfig;
|
|
162
209
|
//# 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,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;QACtC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAA;QACnB,IAAI,CAAC,UAAU,GAAG,YAAY,CAAA;QAC9B,IAAI,CAAC,aAAa,GAAG,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,6 +20,45 @@ exports.RECURRING_INTERVALS = [
|
|
|
20
20
|
exports.BILLING_INTERVALS.EVERY_30_DAYS,
|
|
21
21
|
exports.BILLING_INTERVALS.ANNUAL
|
|
22
22
|
];
|
|
23
|
+
// TODO can we remove?
|
|
24
|
+
/*
|
|
25
|
+
export const SHOP_DATA_QUERY = `
|
|
26
|
+
{
|
|
27
|
+
shop {
|
|
28
|
+
url
|
|
29
|
+
name
|
|
30
|
+
myshopifyDomain
|
|
31
|
+
checkoutApiSupported
|
|
32
|
+
taxesIncluded
|
|
33
|
+
taxShipping
|
|
34
|
+
orderNumberFormatPrefix
|
|
35
|
+
orderNumberFormatSuffix
|
|
36
|
+
orderTags (first: 100) {
|
|
37
|
+
edges {
|
|
38
|
+
node
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
productVendors (first: 100) {
|
|
42
|
+
edges {
|
|
43
|
+
node
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
customerTags (first: 100) {
|
|
47
|
+
edges {
|
|
48
|
+
node
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
features {
|
|
52
|
+
giftCards
|
|
53
|
+
}
|
|
54
|
+
plan {
|
|
55
|
+
shopifyPlus
|
|
56
|
+
partnerDevelopment
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`
|
|
61
|
+
*/
|
|
23
62
|
exports.SHOP_QUERY = `
|
|
24
63
|
{
|
|
25
64
|
shop {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.js"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,YAAY,CAAA;AAE9B,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,gBAAgB;CACxB,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc;IACpB,aAAa,EAAE,sBAAsB;IACrC,eAAe,EAAE,wBAAwB;CAC1C,CAAA;AAEY,QAAA,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;CACjB,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,yBAAiB,CAAC,aAAa;IAC/B,yBAAiB,CAAC,MAAM;CACzB,CAAA;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/utils/constants.js"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,YAAY,CAAA;AAE9B,QAAA,gBAAgB,GAAG;IAC9B,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,gBAAgB;CACxB,CAAA;AAEY,QAAA,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc;IACpB,aAAa,EAAE,sBAAsB;IACrC,eAAe,EAAE,wBAAwB;CAC1C,CAAA;AAEY,QAAA,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;CACjB,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,yBAAiB,CAAC,aAAa;IAC/B,yBAAiB,CAAC,MAAM;CACzB,CAAA;AAED,sBAAsB;AACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCE;AAEW,QAAA,UAAU,GAAG;;;;;;CAMzB,CAAA;AAEY,QAAA,yBAAyB,GAAG;;;;;;;;CAQxC,CAAA;AAEY,QAAA,wBAAwB,GAAG;;;;;;;;;;;;;;;CAevC,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/firebase.js
CHANGED
|
@@ -112,19 +112,25 @@ const deleteSessionsCallback = async (sessionIds, data, instance) => {
|
|
|
112
112
|
};
|
|
113
113
|
exports.deleteSessionsCallback = deleteSessionsCallback;
|
|
114
114
|
const findSessionsByShop = async (shop, data, instance) => {
|
|
115
|
+
console.log('data:', data);
|
|
116
|
+
console.log('shop:', shop);
|
|
115
117
|
if (display_1.stringEmpty(shop)) {
|
|
116
118
|
return [];
|
|
117
119
|
}
|
|
118
120
|
try {
|
|
121
|
+
console.log('try:');
|
|
119
122
|
const collectionRef = instance.firestore
|
|
120
123
|
.collection(instance.collection)
|
|
121
124
|
.doc(shop)
|
|
122
125
|
.collection(data.app);
|
|
126
|
+
console.log('collectionRef:', collectionRef);
|
|
123
127
|
const querySnapshot = await collectionRef.get();
|
|
128
|
+
console.log('querySnapshot:', querySnapshot);
|
|
124
129
|
const sessions = [];
|
|
125
130
|
querySnapshot.forEach((_doc) => {
|
|
126
131
|
sessions.push(_doc.data());
|
|
127
132
|
});
|
|
133
|
+
console.log('sessions:', sessions);
|
|
128
134
|
return sessions;
|
|
129
135
|
}
|
|
130
136
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"firebase.js","sourceRoot":"","sources":["../../src/utils/firebase.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oEAAkC;AAElC,uCAIkB;AAClB,2CAA6C;AAE7C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAA;AACrC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAErD,MAAa,sBAAsB;IACjC,YAAY,QAAQ,EAAE,UAAU,GAAG,2BAAe;QAChD,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;QACpC,IAAI,QAAQ,KAAK,iBAAiB,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAA;SAChG;QACD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAED,IAAI,aAAa;QACf,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,CAAA;IACtC,CAAC;IAED,mBAAmB,CAAE,cAAc;QACjC,IAAI,wBAAc,CAAC,cAAc,CAAC,EAAE;YAClC,MAAM,OAAO,GAAG,CAAC,wBAAK,CAAC,IAAI,CAAC,MAAM;gBAChC,CAAC,CAAC,wBAAK,CAAC,aAAa,CAAC;oBACpB,UAAU,EAAE,wBAAK,CAAC,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;oBACjD,WAAW,EAAE,WAAW,cAAc,CAAC,UAAU,iBAAiB;iBACnE,CAAC,CAAC,CAAC,CAAC,wBAAK,CAAC,GAAG,EAAE,CAAA;YAElB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA;SACrC;IACH,CAAC;IAED,MAAM,CAAC,WAAW,CAAE,cAAc,EAAE,UAAU;QAC5C,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YACpB,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C,CAAA;IAC1B,IAAI,qBAAW,CAAC,IAAI,CAAC,EAAE;QACrB,OAAO,EAAE,CAAA;KACV;IAED,IAAI;QACF,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACnB,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS;aACrC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC;aAC/B,GAAG,CAAC,IAAI,CAAC;aACT,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEvB,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;QAC5C,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,CAAA;QAC/C,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,aAAa,CAAC,CAAA;QAC5C,MAAM,QAAQ,GAAG,EAAE,CAAA;QACnB,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC7B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;QAClC,OAAO,QAAQ,CAAA;KAChB;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,GAAG,CAAC,CAAA;QACrE,MAAM,GAAG,CAAA;KACV;AACH,CAAC,CAAA;AA5BY,QAAA,kBAAkB,sBA4B9B"}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -15,5 +15,7 @@ __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);
|
|
20
|
+
__exportStar(require("./webhooks"), exports);
|
|
19
21
|
//# 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;AACzB,6CAA0B"}
|
|
@@ -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,86 @@
|
|
|
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
|
+
console.log('FB_CONFIG');
|
|
14
|
+
console.log('FB_CONFIG ID', FB_CONFIG.project_id);
|
|
15
|
+
const data = { app: APP_ID, shop: shopify.utils.sanitizeShop(_shop) };
|
|
16
|
+
console.log('data:', data);
|
|
17
|
+
const sessionHandler = firebase_1.FirebaseSessionHandler.getInstance(FB_CONFIG, FB_ROOT_COLLECTION);
|
|
18
|
+
return {
|
|
19
|
+
store: async (session) => firebase_1.storeCallback(session, data, sessionHandler),
|
|
20
|
+
load: async (id) => firebase_1.loadCallback(id, data, sessionHandler),
|
|
21
|
+
delete: async (id) => firebase_1.deleteSessionsCallback(id, data, sessionHandler),
|
|
22
|
+
deleteMany: async (ids) => firebase_1.deleteSessionsCallback(ids, data, sessionHandler),
|
|
23
|
+
find: async (__shop) => firebase_1.findSessionsByShop(shopify.utils.sanitizeShop(__shop), data, sessionHandler),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
exports.getSessionStorage = getSessionStorage;
|
|
27
|
+
// TODO re-enable (check scopes and expiration)
|
|
28
|
+
const isSessionActive = (session, config) => {
|
|
29
|
+
console.log('isSessionActive:', { session, config });
|
|
30
|
+
return true;
|
|
31
|
+
// const scopesUnchanged = true
|
|
32
|
+
// if (
|
|
33
|
+
// scopesUnchanged &&
|
|
34
|
+
// (!session.expires || session.expires >= new Date())
|
|
35
|
+
// ) {
|
|
36
|
+
// return true
|
|
37
|
+
// }
|
|
38
|
+
// return false
|
|
39
|
+
};
|
|
40
|
+
const getVerifiedSession = async ({ req, res, shop, shopify, serverRuntimeConfig }) => {
|
|
41
|
+
try {
|
|
42
|
+
const sessionStorage = exports.getSessionStorage(shopify, serverRuntimeConfig, shop);
|
|
43
|
+
if (sessionStorage) {
|
|
44
|
+
console.log('have sessionStorage');
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
console.log('have NO sessionStorage');
|
|
48
|
+
}
|
|
49
|
+
const { PAYMENT_CONFIG } = serverRuntimeConfig !== null && serverRuntimeConfig !== void 0 ? serverRuntimeConfig : {};
|
|
50
|
+
const sessionId = await shopify.session.getCurrentId({
|
|
51
|
+
isOnline: true,
|
|
52
|
+
rawRequest: req,
|
|
53
|
+
rawResponse: res,
|
|
54
|
+
});
|
|
55
|
+
const session = await sessionStorage.load(sessionId);
|
|
56
|
+
if (!isSessionActive(session, shopify.config)) {
|
|
57
|
+
throw new errors_1.ShopifyAuthenticationError('Inactive session');
|
|
58
|
+
}
|
|
59
|
+
if (shop && (session === null || session === void 0 ? void 0 : session.shop) !== shop) {
|
|
60
|
+
throw new errors_1.ShopifyAuthenticationError('Invalid shop');
|
|
61
|
+
}
|
|
62
|
+
if (PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.required) {
|
|
63
|
+
const billingManager = new billing_1.BillingManager(shopify, session, serverRuntimeConfig);
|
|
64
|
+
const confirmationUrl = await billingManager.ensureBilling();
|
|
65
|
+
console.log('confirmationUrl:', confirmationUrl);
|
|
66
|
+
if (display_1.stringNotEmpty(confirmationUrl)) {
|
|
67
|
+
throw new errors_1.ShopifyAuthenticationError('Invalid payment status', { redirectUrl: confirmationUrl });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// NOTE making a test call to ensure a valid session for free apps
|
|
72
|
+
const client = new shopify.clients.Graphql({ session });
|
|
73
|
+
await client.query({ data: constants_1.SHOP_QUERY });
|
|
74
|
+
}
|
|
75
|
+
return session;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
if (error instanceof shopify_api_1.HttpResponseError &&
|
|
79
|
+
error.response.code === 401) {
|
|
80
|
+
throw new errors_1.ShopifyAuthenticationError('Not authenticated');
|
|
81
|
+
}
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
exports.getVerifiedSession = getVerifiedSession;
|
|
86
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/utils/session.js"],"names":[],"mappings":";;;AAAA,sDAAwD;AAExD,uCAA0C;AAC1C,uCAA0C;AAC1C,qCAAqD;AACrD,2CAAwC;AACxC,yCAMmB;AAEnB,uEAAuE;AAChE,MAAM,iBAAiB,GAAG,CAAC,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,EAAE;IACvE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAG,mBAAmB,CAAA;IACrE,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;IACxB,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,SAAS,CAAC,UAAU,CAAC,CAAA;IAEjD,MAAM,IAAI,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,EAAC,CAAA;IACpE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IAE1B,MAAM,cAAc,GAAG,iCAAsB,CAAC,WAAW,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAA;IAExF,OAAO;QACL,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,wBAAa,CAAC,OAAO,EAAE,IAAI,EAAE,cAAc,CAAC;QACtE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,uBAAY,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC;QAC1D,MAAM,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,iCAAsB,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC;QACtE,UAAU,EAAE,KAAK,EAAE,GAA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@
|
|
|
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,36 @@ 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
|
+
const shopify = await shopify_1.getInitializedShopify(props, _shop);
|
|
19
|
+
const shop = shopify.utils.sanitizeShop(_shop);
|
|
15
20
|
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, {
|
|
21
|
+
const keys = [APP_CONFIG.apiSecretKey];
|
|
22
|
+
const cookies = new cookies_1.default(req, res, { keys, secure: true });
|
|
23
|
+
const cookieOptions = {
|
|
21
24
|
sameSite: 'none',
|
|
22
25
|
expires: new Date(Date.now() + 60000),
|
|
23
26
|
signed: true,
|
|
24
27
|
secure: true,
|
|
25
|
-
}
|
|
28
|
+
};
|
|
29
|
+
const sigName = `${shopify_api_1.STATE_COOKIE_NAME}.sig`;
|
|
30
|
+
const signature = await crypto_1.default.createHmac('sha256', keys[0]).update(state).digest('base64');
|
|
31
|
+
cookies.set(shopify_api_1.STATE_COOKIE_NAME, state, cookieOptions);
|
|
32
|
+
cookies.set(sigName, signature, cookieOptions);
|
|
26
33
|
// TODO: explore objectToQuerystring
|
|
27
34
|
const queryParams = new URLSearchParams({
|
|
28
|
-
client_id: APP_CONFIG.
|
|
29
|
-
scope: APP_CONFIG.
|
|
35
|
+
client_id: APP_CONFIG.apiKey,
|
|
36
|
+
scope: APP_CONFIG.scopes,
|
|
30
37
|
redirect_uri: API_URLS[constants_1.API_ROUTE_NAMES.AUTH_CALLBACK],
|
|
31
38
|
state,
|
|
32
39
|
'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;I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