@agnostack/next-shopify 1.7.0-alpha.14 → 1.7.0-alpha.16
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/dist/handlers/ssr.js +2 -4
- package/dist/handlers/ssr.js.map +1 -1
- package/dist/helpers/callback.d.ts +1 -1
- package/dist/helpers/callback.js +11 -15
- package/dist/helpers/callback.js.map +1 -1
- package/dist/helpers/graph.js +3 -6
- package/dist/helpers/graph.js.map +1 -1
- package/dist/helpers/rest.js +6 -9
- package/dist/helpers/rest.js.map +1 -1
- package/dist/helpers/uninstall.js +4 -6
- package/dist/helpers/uninstall.js.map +1 -1
- package/dist/utils/billing.d.ts +11 -20
- package/dist/utils/billing.js +49 -187
- package/dist/utils/billing.js.map +1 -1
- package/dist/utils/constants.d.ts +0 -5
- package/dist/utils/constants.js +1 -72
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/display.d.ts +1 -1
- package/dist/utils/firebase.d.ts +13 -6
- package/dist/utils/firebase.js +35 -33
- package/dist/utils/firebase.js.map +1 -1
- package/dist/utils/session.d.ts +16 -11
- package/dist/utils/session.js +43 -26
- package/dist/utils/session.js.map +1 -1
- package/dist/utils/shopify-api-node/beginAuth.js +1 -2
- package/dist/utils/shopify-api-node/beginAuth.js.map +1 -1
- package/dist/utils/shopify.d.ts +1 -1
- package/dist/utils/shopify.js +7 -15
- package/dist/utils/shopify.js.map +1 -1
- package/dist/withShopify.js +8 -15
- package/dist/withShopify.js.map +1 -1
- package/package.json +1 -1
- package/CHANGELOG.md +0 -553
package/dist/handlers/ssr.js
CHANGED
|
@@ -27,10 +27,8 @@ const protectRoute = (props) => async ({ req, res, query, locale } = {}, data) =
|
|
|
27
27
|
},
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const sessionStorage = utils_1.getSessionStorage(shopify, props, shop);
|
|
33
|
-
const existingSessions = await sessionStorage.find(shop);
|
|
30
|
+
const { shopify, findSession } = await utils_1.getShopifyHelpers(props, { shop });
|
|
31
|
+
const existingSessions = await findSession(shop);
|
|
34
32
|
if (utils_1.arrayEmpty(existingSessions)) {
|
|
35
33
|
const emptySessionUrl = await utils_1.getRedirectUrl(props, {
|
|
36
34
|
req,
|
package/dist/handlers/ssr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr.js","sourceRoot":"","sources":["../../src/handlers/ssr.js"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ssr.js","sourceRoot":"","sources":["../../src/handlers/ssr.js"],"names":[],"mappings":";;;AAAA,oCAQiB;AAEjB,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAClC,sBAAc,CAAC,IAAI,CAAC;IAClB,CAAC,CAAC,0DAA0D,IAAI,GAAG;IACnE,CAAC,CAAC,yBAAyB,CAC9B,CAAA;AAEM,MAAM,SAAS,GAAG,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE;IACnE,GAAG,CAAC,SAAS,CAAC,yBAAyB,EAAE,iBAAiB,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,CAAC,CAAC,CAAA;IAExE,OAAO;QACL,KAAK,EAAE,mBAAW,iBAChB,MAAM,IACH,IAAI,EACP;KACH,CAAA;AACH,CAAC,CAAA;AATY,QAAA,SAAS,aASrB;AAEM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE;;IACtF,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IAC5B,MAAM,IAAI,GAAG,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,mCAAI,MAAA,GA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AI,EACP;KACH,CAAA;AACH,CAAC,CAAA;AApDY,QAAA,YAAY,gBAoDxB"}
|
package/dist/helpers/callback.js
CHANGED
|
@@ -4,9 +4,7 @@ const shopify_api_1 = require("@shopify/shopify-api");
|
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const callbackHelper = async ({ req, res, serverRuntimeConfig }) => {
|
|
6
6
|
var _a;
|
|
7
|
-
|
|
8
|
-
// const { PAGE_PATHS, PAYMENT_CONFIG } = serverRuntimeConfig
|
|
9
|
-
const { PAGE_PATHS } = serverRuntimeConfig;
|
|
7
|
+
const { PAGE_PATHS, PAYMENT_CONFIG } = serverRuntimeConfig;
|
|
10
8
|
const { shop, host } = req.query;
|
|
11
9
|
if (utils_1.stringEmpty(shop) || utils_1.stringEmpty(host)) {
|
|
12
10
|
return {
|
|
@@ -16,25 +14,23 @@ const callbackHelper = async ({ req, res, serverRuntimeConfig }) => {
|
|
|
16
14
|
}
|
|
17
15
|
let redirectUrl;
|
|
18
16
|
try {
|
|
19
|
-
|
|
20
|
-
const shopify = await utils_1.getInitializedShopify(serverRuntimeConfig);
|
|
21
|
-
const sessionStorage = utils_1.getSessionStorage(shopify, serverRuntimeConfig, shop);
|
|
17
|
+
const { shopify, storeSession } = await utils_1.getShopifyHelpers(serverRuntimeConfig, { shop });
|
|
22
18
|
const authPayload = { rawRequest: req, rawResponse: res };
|
|
23
19
|
// TODO investigate Error handling callback route. Cookie Error CookieNotFound [Error]: Cannot complete OAuth process. Could not find an OAuth cookie for shop url:
|
|
24
20
|
const { session } = await shopify.auth.callback(authPayload);
|
|
25
|
-
await
|
|
21
|
+
await storeSession(session.toObject());
|
|
26
22
|
await shopify.webhooks.register({ session });
|
|
27
23
|
// TODO: explore objectToQuerystring
|
|
28
24
|
const embeddedURL = await shopify.auth.getEmbeddedAppUrl(authPayload);
|
|
29
25
|
redirectUrl = `${embeddedURL}?${new URLSearchParams(req.query).toString()}`;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
if (PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.required) {
|
|
27
|
+
// HMMM: order of params/method sig??
|
|
28
|
+
const confirmationUrl = await utils_1.ensureBilling(shopify, session, PAYMENT_CONFIG);
|
|
29
|
+
console.log(`>>> > callbackHelper > confirmationUrl:`, confirmationUrl);
|
|
30
|
+
if (utils_1.stringNotEmpty(confirmationUrl)) {
|
|
31
|
+
redirectUrl = confirmationUrl;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
38
34
|
}
|
|
39
35
|
catch (error) {
|
|
40
36
|
const errorMessage = 'Error handling callback route';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../../src/helpers/callback.js"],"names":[],"mappings":";;AAAA,sDAAyG;AAEzG,
|
|
1
|
+
{"version":3,"file":"callback.js","sourceRoot":"","sources":["../../src/helpers/callback.js"],"names":[],"mappings":";;AAAA,sDAAyG;AAEzG,oCAUiB;AAEjB,MAAM,cAAc,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;;IACjE,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,mBAAmB,CAAA;IAC1D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;IAEhC,IAAI,mBAAW,CAAC,IAAI,CAAC,IAAI,mBAAW,CAAC,IAAI,CAAC,EAAE;QAC1C,OAAO;YACL,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG,UAAU,CAAC,wBAAgB,CAAC,KAAK,CAAC,SAAS,mBAAW,CAAC,gBAAgB,EAAE;SAC1F,CAAA;KACF;IAED,IAAI,WAAW,CAAA;IAEf,IAAI;QACF,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,MA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
|
|
16
16
|
const graphHelper = async ({ req, res, params, serverRuntimeConfig }) => {
|
|
17
17
|
var _a;
|
|
18
|
-
const { body = '{}' } = req, _b = req.query, _c = _b === void 0 ? {} : _b, { shop } = _c, _query = __rest(_c, ["shop"]);
|
|
18
|
+
const { body = '{}' } = req, _b = req.query, _c = _b === void 0 ? {} : _b, { shop, apiVersion } = _c, _query = __rest(_c, ["shop", "apiVersion"]);
|
|
19
19
|
const _d = params !== null && params !== void 0 ? params : JSON.parse(body), { query: graphQuery, variables: graphVariables } = _d, graphParams = __rest(_d, ["query", "variables"]);
|
|
20
20
|
let query = _query;
|
|
21
21
|
if (utils_1.isType(query, 'string')) {
|
|
@@ -28,11 +28,8 @@ const graphHelper = async ({ req, res, params, serverRuntimeConfig }) => {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
const session = await utils_1.getVerifiedSession({ req, res, shop, shopify, serverRuntimeConfig });
|
|
34
|
-
const client = new shopify.clients.Graphql({ session });
|
|
35
|
-
const response = await client.query(Object.assign(Object.assign({ data: graphVariables ? {
|
|
31
|
+
const { Graphql } = await utils_1.getVerifiedClients(serverRuntimeConfig, { req, res, shop, apiVersion });
|
|
32
|
+
const response = await Graphql.query(Object.assign(Object.assign({ data: graphVariables ? {
|
|
36
33
|
query: graphQuery,
|
|
37
34
|
variables: graphVariables,
|
|
38
35
|
} : graphQuery }, utils_1.objectNotEmpty(query) && { query }), graphParams));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/helpers/graph.js"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sDAAsE;AAEtE,
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/helpers/graph.js"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sDAAsE;AAEtE,oCAUiB;AAEjB,MAAM,WAAW,GAAG,KAAK,EAAE,EAAE,GAA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query: _query, method: _method, body: _body } = req;
|
|
18
18
|
const { shop } = _query !== null && _query !== void 0 ? _query : {};
|
|
19
19
|
const _a = _params !== null && _params !== void 0 ? _params : {}, { method: methodParam, query: queryParam, body: bodyParam, path } = _a, params = __rest(_a, ["method", "query", "body", "path"]);
|
|
20
|
-
let
|
|
20
|
+
let queryData = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
|
|
21
21
|
const body = bodyParam !== null && bodyParam !== void 0 ? bodyParam : _body;
|
|
22
22
|
const method = utils_1.ensureString(methodParam !== null && methodParam !== void 0 ? methodParam : _method).toLowerCase();
|
|
23
|
-
if (utils_1.isType(
|
|
24
|
-
|
|
23
|
+
if (utils_1.isType(queryData, 'string')) {
|
|
24
|
+
queryData = utils_1.querystringToObject(queryData);
|
|
25
25
|
}
|
|
26
|
+
const _b = utils_1.ensureObject(queryData), { apiVersion } = _b, query = __rest(_b, ["apiVersion"]);
|
|
26
27
|
if (utils_1.stringEmpty(shop) || utils_1.stringEmpty(path)) {
|
|
27
28
|
return {
|
|
28
29
|
statusCode: 400,
|
|
@@ -30,12 +31,8 @@ const restHelper = async ({ req, res, params: _params, serverRuntimeConfig }) =>
|
|
|
30
31
|
};
|
|
31
32
|
}
|
|
32
33
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const shopify = await utils_1.getInitializedShopify(serverRuntimeConfig);
|
|
36
|
-
const session = await utils_1.getVerifiedSession({ req, res, shop, shopify, serverRuntimeConfig });
|
|
37
|
-
const client = new shopify.clients.Rest({ session });
|
|
38
|
-
const response = await client[method](Object.assign({ path,
|
|
34
|
+
const { Rest } = await utils_1.getVerifiedClients(serverRuntimeConfig, { req, res, shop, apiVersion });
|
|
35
|
+
const response = await Rest[method](Object.assign({ path,
|
|
39
36
|
query,
|
|
40
37
|
body, type: shopify_api_1.DataType.JSON }, params));
|
|
41
38
|
return {
|
package/dist/helpers/rest.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/helpers/rest.js"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sDAA6D;AAE7D,oCASiB;AAEjB,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAC9E,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;IAC7B,MAAM,KAMF,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EANX,EACJ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,OAEW,EADZ,MAAM,cALL,mCAML,CAAgB,CAAA;IACjB,IAAI,
|
|
1
|
+
{"version":3,"file":"rest.js","sourceRoot":"","sources":["../../src/helpers/rest.js"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,sDAA6D;AAE7D,oCASiB;AAEjB,MAAM,UAAU,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAC9E,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAA;IAC7B,MAAM,KAMF,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,EAAE,EANX,EACJ,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,SAAS,EACf,IAAI,OAEW,EADZ,MAAM,cALL,mCAML,CAAgB,CAAA;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AC,EAAE,KAAK,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAA;aAClE;YAED,KAAK,KAAK,YAAY,0BAAY,CAAC,CAAC;gBAClC,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,qBAAqB,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAAA;gBACnF,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;YAED,OAAO,CAAC,CAAC;gBACP,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;gBAClC,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;SACF;KACF;AACH,CAAC,CAAA;AAED,kBAAe,UAAU,CAAA"}
|
|
@@ -4,12 +4,10 @@ const utils_1 = require("../utils");
|
|
|
4
4
|
const uninstallHelper = async ({ rawBody, req, res, serverRuntimeConfig }) => {
|
|
5
5
|
try {
|
|
6
6
|
const shop = req.headers['x-shopify-shop-domain'];
|
|
7
|
-
if (
|
|
7
|
+
if (utils_1.stringEmpty(shop)) {
|
|
8
8
|
return res.status(400).send('Invalid shop');
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
const shopify = await utils_1.getInitializedShopify(serverRuntimeConfig);
|
|
12
|
-
const sessionStorage = utils_1.getSessionStorage(shopify, serverRuntimeConfig, shop);
|
|
10
|
+
const { shopify, findSession, deleteSessions } = await utils_1.getShopifyHelpers(serverRuntimeConfig, { shop });
|
|
13
11
|
let response;
|
|
14
12
|
try {
|
|
15
13
|
response = await shopify.webhooks.process({
|
|
@@ -17,9 +15,9 @@ const uninstallHelper = async ({ rawBody, req, res, serverRuntimeConfig }) => {
|
|
|
17
15
|
rawRequest: req,
|
|
18
16
|
rawResponse: res,
|
|
19
17
|
});
|
|
20
|
-
const sessionsIds = await
|
|
18
|
+
const sessionsIds = await findSession(shop);
|
|
21
19
|
if (utils_1.arrayNotEmpty(sessionsIds)) {
|
|
22
|
-
await
|
|
20
|
+
await deleteSessions(sessionsIds.map(({ id }) => id));
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/helpers/uninstall.js"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/helpers/uninstall.js"],"names":[],"mappings":";;AAAA,oCAIiB;AAEjB,MAAM,eAAe,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;IAC3E,IAAI;QACF,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA;QAEjD,IAAI,mBAAW,CAAC,IAAI,CAAC,EAAE;YACrB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;SAC5C;QAED,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,GAAG,MAAM,yBAAiB,CAAC,mBAAmB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAEvG,IAAI,QAAQ,CAAA;QACZ,IAAI;YACF,QAAQ,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACxC,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE;gBAC3B,UAAU,EAAE,GAAG;gBACf,WAAW,EAAE,GAAG;aACjB,CAAC,CAAA;YAEF,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAA;YAC3C,IAAI,qBAAa,CAAC,WAAW,CAAC,EAAE;gBAC9B,MAAM,cAAc,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;aACtD;SACF;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;YAChD,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;SAC1B;QAED,OAAO,QAAQ,CAAA;KAEhB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;QAChD,sFAAsF;QACtF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;KACxD;AACH,CAAC,CAAA;AAED,kBAAe,eAAe,CAAA"}
|
package/dist/utils/billing.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ensureBilling(): Promise<any>;
|
|
13
|
-
hasActiveRecurringPayment(): Promise<boolean>;
|
|
14
|
-
hasActiveOneTimePayment(endCursor?: any): any;
|
|
15
|
-
hasActivePayment(): Promise<any>;
|
|
16
|
-
requestPayment(): Promise<any>;
|
|
17
|
-
requestSinglePayment(returnUrl: any): Promise<any>;
|
|
18
|
-
requestRecurringPayment(returnUrl: any): Promise<any>;
|
|
19
|
-
}
|
|
20
|
-
export function generatePaymentConfig(): {};
|
|
1
|
+
export function ensureBilling(shopify: any, session: any, paymentConfig: any): Promise<any>;
|
|
2
|
+
export function generatePaymentConfig(paymentConfig: any, data: any): {
|
|
3
|
+
required: boolean;
|
|
4
|
+
test: boolean;
|
|
5
|
+
name: string;
|
|
6
|
+
config: {
|
|
7
|
+
interval: any;
|
|
8
|
+
amount: any;
|
|
9
|
+
currencyCode: any;
|
|
10
|
+
};
|
|
11
|
+
};
|
package/dist/utils/billing.js
CHANGED
|
@@ -1,210 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generatePaymentConfig = exports.
|
|
3
|
+
exports.generatePaymentConfig = exports.ensureBilling = 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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
this.shopify = shopify;
|
|
18
|
-
this.shop = session.shop;
|
|
19
|
-
this.graphClient = new shopify.clients.Graphql({ session });
|
|
20
|
-
this.session = session;
|
|
21
|
-
this.accessToken = session.accessToken;
|
|
22
|
-
this.appId = APP_ID;
|
|
23
|
-
this.appBaseUrl = APP_BASE_URL;
|
|
24
|
-
this.paymentConfig = display_1.ensureObject(PAYMENT_CONFIG);
|
|
25
|
-
this.isRecurring = constants_1.RECURRING_INTERVALS.includes(this.paymentConfig.type);
|
|
26
|
-
}
|
|
27
|
-
async ensureBilling() {
|
|
28
|
-
var _a;
|
|
29
|
-
try {
|
|
30
|
-
if (await this.hasActivePayment()) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
return this.requestPayment();
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error instanceof shopify_api_1.GraphqlQueryError) {
|
|
37
|
-
throw new shopify_api_1.BillingError({
|
|
38
|
-
message: 'Failed to verify or initialize payment',
|
|
39
|
-
errorData: display_1.ensureArray((_a = error.response) === null || _a === void 0 ? void 0 : _a.errors).map(({ message }) => display_1.ensureString(message)),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async hasActiveRecurringPayment() {
|
|
46
|
-
var _a, _b, _c;
|
|
47
|
-
const currentInstallations = await this.graphClient.query({
|
|
48
|
-
data: constants_1.RECURRING_PURCHASES_QUERY,
|
|
7
|
+
const hasValidBilling = (session, paymentConfig) => (display_1.stringNotEmpty(session === null || session === void 0 ? void 0 : session.shop) &&
|
|
8
|
+
display_1.stringNotEmpty(session === null || session === void 0 ? void 0 : session.accessToken) &&
|
|
9
|
+
display_1.stringNotEmpty(paymentConfig === null || paymentConfig === void 0 ? void 0 : paymentConfig.name) &&
|
|
10
|
+
display_1.objectNotEmpty(paymentConfig === null || paymentConfig === void 0 ? void 0 : paymentConfig.config) &&
|
|
11
|
+
Object.values(constants_1.BILLING_INTERVALS).includes(paymentConfig === null || paymentConfig === void 0 ? void 0 : paymentConfig.type));
|
|
12
|
+
const ensureBilling = async (shopify, session, paymentConfig) => {
|
|
13
|
+
if (!hasValidBilling(session, paymentConfig)) {
|
|
14
|
+
throw new shopify_api_1.BillingError({
|
|
15
|
+
message: 'Invalid billing configuration',
|
|
49
16
|
});
|
|
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
|
-
const matchingSubscription = display_1.ensureArray(subscriptions).find((node) => (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
|
|
52
|
-
&& (!display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) || this.paymentConfig.test)
|
|
53
|
-
// ORIG && (isTrue(chargeTest) === this.paymentConfig.test)
|
|
54
|
-
));
|
|
55
|
-
return display_1.objectNotEmpty(matchingSubscription);
|
|
56
17
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
});
|
|
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
|
|
67
|
-
const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find(({ node } = {}) => {
|
|
68
|
-
if (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name) && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')) {
|
|
69
|
-
// console.log(`>>> ~ node`, {
|
|
70
|
-
// node,
|
|
71
|
-
// truish: (!isTrue(node?.test) || this.paymentConfig.test),
|
|
72
|
-
// })
|
|
73
|
-
}
|
|
74
|
-
return (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
|
|
75
|
-
&& ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
|
|
76
|
-
&& (!display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) || this.paymentConfig.test)
|
|
77
|
-
// ORIG && (isTrue(node?.test) === this.paymentConfig.test)
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
if (display_1.objectNotEmpty(matchingPurchase)) {
|
|
81
|
-
return true;
|
|
18
|
+
try {
|
|
19
|
+
if (display_1.isTrue(await shopify.billing.check({
|
|
20
|
+
plans: [paymentConfig.name],
|
|
21
|
+
isTest: display_1.isTrue(paymentConfig.test),
|
|
22
|
+
session,
|
|
23
|
+
}))) {
|
|
24
|
+
return undefined;
|
|
82
25
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
async hasActivePayment() {
|
|
89
|
-
if (this.isRecurring) {
|
|
90
|
-
return this.hasActiveRecurringPayment();
|
|
91
|
-
}
|
|
92
|
-
return this.hasActiveOneTimePayment();
|
|
93
|
-
}
|
|
94
|
-
async requestPayment() {
|
|
95
|
-
// TODO: explore objectToQuerystring
|
|
96
|
-
const queryParams = [
|
|
97
|
-
`shop=${this.shop}`,
|
|
98
|
-
`host=${Buffer.from(`${this.shop}/admin`).toString('base64')}`
|
|
99
|
-
];
|
|
100
|
-
const returnUrl = `${this.appBaseUrl}?${queryParams.join('&')}`;
|
|
101
|
-
const data = this.isRecurring
|
|
102
|
-
? await this.requestRecurringPayment(returnUrl)
|
|
103
|
-
: await this.requestSinglePayment(returnUrl);
|
|
104
|
-
if (display_1.arrayNotEmpty(data === null || data === void 0 ? void 0 : data.userErrors)) {
|
|
105
|
-
throw new shopify_api_1.BillingError({
|
|
106
|
-
message: 'User error requesting payment',
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
return data === null || data === void 0 ? void 0 : data.confirmationUrl;
|
|
110
|
-
}
|
|
111
|
-
async requestSinglePayment(returnUrl) {
|
|
112
|
-
var _a, _b, _c, _d;
|
|
113
|
-
const { price, name, test, } = this.paymentConfig;
|
|
114
|
-
const mutationResponse = await this.graphClient.query({
|
|
115
|
-
data: {
|
|
116
|
-
query: constants_1.ONE_TIME_PURCHASE_MUTATION,
|
|
117
|
-
variables: {
|
|
118
|
-
test,
|
|
119
|
-
name,
|
|
120
|
-
price,
|
|
121
|
-
returnUrl,
|
|
122
|
-
},
|
|
123
|
-
},
|
|
26
|
+
return shopify.billing.request({
|
|
27
|
+
plan: paymentConfig.name,
|
|
28
|
+
isTest: display_1.isTrue(paymentConfig.test),
|
|
29
|
+
session,
|
|
124
30
|
});
|
|
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)) {
|
|
126
|
-
throw new shopify_api_1.BillingError({
|
|
127
|
-
message: 'Error executing one-time purchase',
|
|
128
|
-
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
129
|
-
});
|
|
130
|
-
}
|
|
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;
|
|
132
31
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const mutationResponse = await this.graphClient.query({
|
|
137
|
-
data: {
|
|
138
|
-
query: constants_1.RECURRING_PURCHASE_MUTATION,
|
|
139
|
-
variables: {
|
|
140
|
-
test,
|
|
141
|
-
name,
|
|
142
|
-
returnUrl,
|
|
143
|
-
lineItems: [{
|
|
144
|
-
plan: {
|
|
145
|
-
appRecurringPricingDetails: {
|
|
146
|
-
interval,
|
|
147
|
-
price,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
}],
|
|
151
|
-
},
|
|
152
|
-
},
|
|
32
|
+
catch (error) {
|
|
33
|
+
throw new shopify_api_1.BillingError({
|
|
34
|
+
message: 'Failed to verify or initialize payment',
|
|
153
35
|
});
|
|
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)) {
|
|
155
|
-
throw new shopify_api_1.BillingError({
|
|
156
|
-
message: 'Error executing recurring purchase',
|
|
157
|
-
errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
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.appSubscriptionCreate;
|
|
161
36
|
}
|
|
162
|
-
}
|
|
163
|
-
exports.
|
|
164
|
-
// TODO enable billing management
|
|
37
|
+
};
|
|
38
|
+
exports.ensureBilling = ensureBilling;
|
|
165
39
|
// eslint-disable-next-line arrow-body-style
|
|
166
|
-
const generatePaymentConfig = () => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
40
|
+
const generatePaymentConfig = (paymentConfig, data) => {
|
|
41
|
+
const { name, price, currency = 'USD', type = constants_1.BILLING_INTERVALS.ONE_TIME, } = display_1.ensureObject(paymentConfig);
|
|
42
|
+
const { debugMode, environment } = display_1.ensureObject(data);
|
|
43
|
+
if (display_1.objectEmpty(paymentConfig) || display_1.stringEmpty(environment)) {
|
|
44
|
+
return undefined;
|
|
179
45
|
}
|
|
180
|
-
|
|
181
|
-
const notProduction = (environment !== 'production')
|
|
182
|
-
|
|
46
|
+
const notProduction = (environment !== 'production');
|
|
183
47
|
// TODO ensure this logic is correct
|
|
184
|
-
let test = environment !== 'production'
|
|
48
|
+
let test = environment !== 'production';
|
|
185
49
|
if (debugMode) {
|
|
186
|
-
|
|
50
|
+
test = true;
|
|
187
51
|
}
|
|
188
|
-
|
|
52
|
+
const billingName = `${name}${notProduction ? ` - ${environment}` : ''} - ${display_1.unsnakecase(type)}`;
|
|
189
53
|
const _paymentConfig = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
54
|
+
required: (environment !== 'development'),
|
|
55
|
+
test,
|
|
56
|
+
name: billingName,
|
|
57
|
+
config: {
|
|
58
|
+
interval: type,
|
|
59
|
+
amount: price,
|
|
60
|
+
currencyCode: currency,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
199
63
|
// TODO: clean this up
|
|
200
64
|
console.log(`>>> ~ _paymentConfig`, {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
return _paymentConfig
|
|
207
|
-
*/
|
|
65
|
+
_paymentConfig,
|
|
66
|
+
debugMode,
|
|
67
|
+
debugEnv: process.env.DEBUG,
|
|
68
|
+
});
|
|
69
|
+
return _paymentConfig;
|
|
208
70
|
};
|
|
209
71
|
exports.generatePaymentConfig = generatePaymentConfig;
|
|
210
72
|
//# 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,sDAAmD;AAEnD,uCAQkB;AAClB,2CAA+C;AAE/C,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,CAAC,CAClD,wBAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC;IAC7B,wBAAc,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC;IACpC,wBAAc,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC;IACnC,wBAAc,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,MAAM,CAAC;IACrC,MAAM,CAAC,MAAM,CAAC,6BAAiB,CAAC,CAAC,QAAQ,CAAC,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,IAAI,CAAC,CAC/D,CAAA;AAEM,MAAM,aAAa,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE;IACrE,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,aAAa,CAAC,EAAE;QAC5C,MAAM,IAAI,0BAAY,CAAC;YACrB,OAAO,EAAE,+BAA+B;SACzC,CA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AC,MAAM,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,qBAAW,CAAC,IAAI,CAAC,EAAE,CAAA;IAE/F,MAAM,cAAc,GAAG;QACrB,QAAQ,EAAE,CAAC,WAAW,KAAK,aAAa,CAAC;QACzC,IAAI;QACJ,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE;YACN,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,KAAK;YACb,YAAY,EAAE,QAAQ;SACvB;KACF,CAAA;IACD,sBAAsB;IACtB,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE;QAClC,cAAc;QACd,SAAS;QACT,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK;KAC5B,CAAC,CAAA;IAEF,OAAO,cAAc,CAAA;AACvB,CAAC,CAAA;AAzCY,QAAA,qBAAqB,yBAyCjC"}
|
|
@@ -17,9 +17,4 @@ export namespace BILLING_INTERVALS {
|
|
|
17
17
|
const EVERY_30_DAYS: string;
|
|
18
18
|
const ANNUAL: string;
|
|
19
19
|
}
|
|
20
|
-
export const RECURRING_INTERVALS: string[];
|
|
21
20
|
export const SHOP_QUERY: "\n {\n shop {\n name\n }\n }\n";
|
|
22
|
-
export const RECURRING_PURCHASES_QUERY: "\n query appSubscription {\n currentAppInstallation {\n activeSubscriptions {\n name, test\n }\n }\n }\n";
|
|
23
|
-
export const ONE_TIME_PURCHASES_QUERY: "\n query appPurchases($endCursor: String) {\n currentAppInstallation {\n oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {\n edges {\n node {\n name, test, status\n }\n }\n pageInfo {\n hasNextPage, endCursor\n }\n }\n }\n }\n";
|
|
24
|
-
export const RECURRING_PURCHASE_MUTATION: "\n mutation test(\n $name: String!\n $lineItems: [AppSubscriptionLineItemInput!]!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appSubscriptionCreate(\n name: $name\n lineItems: $lineItems\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";
|
|
25
|
-
export const ONE_TIME_PURCHASE_MUTATION: "\n mutation test(\n $name: String!\n $price: MoneyInput!\n $returnUrl: URL!\n $test: Boolean\n ) {\n appPurchaseOneTimeCreate(\n name: $name\n price: $price\n returnUrl: $returnUrl\n test: $test\n ) {\n confirmationUrl\n userErrors {\n field\n message\n }\n }\n }\n";
|