@agnostack/next-shopify 1.3.2-alpha.9 → 1.4.0

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.
Files changed (63) hide show
  1. package/CHANGELOG.md +40 -49
  2. package/dist/{apiHandlers.d.ts → handlers/api.d.ts} +0 -0
  3. package/dist/{apiHandlers.js → handlers/api.js} +8 -8
  4. package/dist/handlers/api.js.map +1 -0
  5. package/dist/handlers/index.d.ts +2 -0
  6. package/dist/handlers/index.js +15 -0
  7. package/dist/handlers/index.js.map +1 -0
  8. package/dist/{protectRoute.d.ts → handlers/ssr.d.ts} +7 -0
  9. package/dist/{protectRoute.js → handlers/ssr.js} +24 -10
  10. package/dist/handlers/ssr.js.map +1 -0
  11. package/dist/helpers/auth.d.ts +14 -0
  12. package/dist/helpers/auth.js +25 -0
  13. package/dist/helpers/auth.js.map +1 -0
  14. package/dist/helpers/callback.d.ts +9 -0
  15. package/dist/helpers/callback.js +71 -0
  16. package/dist/helpers/callback.js.map +1 -0
  17. package/dist/helpers/error.d.ts +13 -0
  18. package/dist/helpers/error.js +18 -0
  19. package/dist/helpers/error.js.map +1 -0
  20. package/dist/helpers/graph.d.ts +7 -0
  21. package/dist/helpers/graph.js +76 -0
  22. package/dist/helpers/graph.js.map +1 -0
  23. package/dist/helpers/index.d.ts +6 -0
  24. package/dist/helpers/index.js +19 -0
  25. package/dist/helpers/index.js.map +1 -0
  26. package/dist/helpers/rest.d.ts +7 -0
  27. package/dist/helpers/rest.js +70 -0
  28. package/dist/helpers/rest.js.map +1 -0
  29. package/dist/helpers/uninstall.d.ts +8 -0
  30. package/dist/helpers/uninstall.js +28 -0
  31. package/dist/helpers/uninstall.js.map +1 -0
  32. package/dist/index.d.ts +2 -3
  33. package/dist/index.js +2 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/utils/billing.d.ts +0 -5
  36. package/dist/utils/billing.js +20 -138
  37. package/dist/utils/billing.js.map +1 -1
  38. package/dist/utils/constants.d.ts +21 -0
  39. package/dist/utils/constants.js +97 -0
  40. package/dist/utils/constants.js.map +1 -0
  41. package/dist/utils/firebase.d.ts +6 -12
  42. package/dist/utils/firebase.js +27 -29
  43. package/dist/utils/firebase.js.map +1 -1
  44. package/dist/utils/index.d.ts +1 -0
  45. package/dist/utils/index.js +1 -0
  46. package/dist/utils/index.js.map +1 -1
  47. package/dist/utils/shopify-api-node/beginAuth.d.ts +9 -0
  48. package/dist/utils/shopify-api-node/beginAuth.js +37 -0
  49. package/dist/utils/shopify-api-node/beginAuth.js.map +1 -0
  50. package/dist/utils/shopify-api-node/index.d.ts +1 -0
  51. package/dist/utils/shopify-api-node/index.js +15 -0
  52. package/dist/utils/shopify-api-node/index.js.map +1 -0
  53. package/dist/utils/shopify.d.ts +1 -10
  54. package/dist/utils/shopify.js +16 -61
  55. package/dist/utils/shopify.js.map +1 -1
  56. package/dist/withShopify.js +3 -36
  57. package/dist/withShopify.js.map +1 -1
  58. package/package.json +1 -1
  59. package/dist/apiHandlers.js.map +0 -1
  60. package/dist/apiHelpers.d.ts +0 -70
  61. package/dist/apiHelpers.js +0 -251
  62. package/dist/apiHelpers.js.map +0 -1
  63. package/dist/protectRoute.js.map +0 -1
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const shopify_api_1 = require("@shopify/shopify-api");
15
+ const utils_1 = require("../utils");
16
+ const error_1 = require("./error");
17
+ const restHelper = async ({ req, res, params: _params, serverRuntimeConfig }) => {
18
+ const { query: _query, method: _method, body: _body } = req;
19
+ const { shop } = _query !== null && _query !== void 0 ? _query : {};
20
+ const _a = _params !== null && _params !== void 0 ? _params : {}, { method: methodParam, query: queryParam, body: bodyParam, path } = _a, params = __rest(_a, ["method", "query", "body", "path"]);
21
+ let query = queryParam !== null && queryParam !== void 0 ? queryParam : _query;
22
+ const body = bodyParam !== null && bodyParam !== void 0 ? bodyParam : _body;
23
+ const method = utils_1.ensureString(methodParam !== null && methodParam !== void 0 ? methodParam : _method).toLowerCase();
24
+ if (utils_1.isType(query, 'string')) {
25
+ query = utils_1.querystringToObject(query);
26
+ }
27
+ if (!shop || !path) {
28
+ return {
29
+ statusCode: 400,
30
+ message: 'Invalid arguments',
31
+ };
32
+ }
33
+ try {
34
+ const session = await utils_1.getVerifiedSession({ req, res, shop, serverRuntimeConfig });
35
+ const shopify = utils_1.getInitializedShopify(serverRuntimeConfig, shop, '2021-04');
36
+ const client = new shopify.Clients.Rest(shop, session === null || session === void 0 ? void 0 : session.accessToken);
37
+ const response = await client[method](Object.assign({ path,
38
+ query,
39
+ body, type: shopify_api_1.DataType.JSON }, params));
40
+ return {
41
+ statusCode: 200,
42
+ response,
43
+ };
44
+ }
45
+ catch (error) {
46
+ const errorMessage = 'Error handling rest call';
47
+ switch (true) {
48
+ case error instanceof utils_1.ShopifyAuthenticationError: {
49
+ console.error(`${errorMessage}. Authentication Error`, error);
50
+ return error_1.authenticationErrorHelper({ error, shop, serverRuntimeConfig });
51
+ }
52
+ case error instanceof shopify_api_1.Shopify.Errors.BillingError: {
53
+ console.error(`${errorMessage}. Billing Error - ${error.message}`, error.errorData);
54
+ return {
55
+ statusCode: 500,
56
+ message: errorMessage,
57
+ };
58
+ }
59
+ default: {
60
+ console.error(errorMessage, error);
61
+ return {
62
+ statusCode: 500,
63
+ message: errorMessage,
64
+ };
65
+ }
66
+ }
67
+ }
68
+ };
69
+ exports.default = restHelper;
70
+ //# sourceMappingURL=r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AAU,CAAA"}
@@ -0,0 +1,8 @@
1
+ export default uninstallHelper;
2
+ declare function uninstallHelper({ req, serverRuntimeConfig }: {
3
+ req: any;
4
+ serverRuntimeConfig: any;
5
+ }): Promise<{
6
+ statusCode: number;
7
+ message: string;
8
+ }>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("../utils");
4
+ const uninstallHelper = async ({ req, serverRuntimeConfig }) => {
5
+ var _a, _b, _c, _d;
6
+ try {
7
+ const { domain } = req.body;
8
+ const shopify = utils_1.getInitializedShopify(serverRuntimeConfig, domain);
9
+ const existingSessions = await ((_b = (_a = shopify.Context.SESSION_STORAGE) === null || _a === void 0 ? void 0 : _a.findSessionsByShop) === null || _b === void 0 ? void 0 : _b.call(_a, domain));
10
+ if (utils_1.arrayNotEmpty(existingSessions)) {
11
+ await ((_d = (_c = shopify.Context.SESSION_STORAGE) === null || _c === void 0 ? void 0 : _c.deleteSessions) === null || _d === void 0 ? void 0 : _d.call(_c, existingSessions.map((session) => session.id)));
12
+ }
13
+ return {
14
+ statusCode: 200,
15
+ message: 'success',
16
+ };
17
+ }
18
+ catch (error) {
19
+ const errorMessage = 'Error handling uninstall route';
20
+ console.error(errorMessage, error);
21
+ return {
22
+ statusCode: 500,
23
+ message: errorMessage,
24
+ };
25
+ }
26
+ };
27
+ exports.default = uninstallHelper;
28
+ //# sourceMappingURL=uninstall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uninstall.js","sourceRoot":"","sources":["../../src/helpers/uninstall.js"],"names":[],"mappings":";;AAAA,oCAA+D;AAE/D,MAAM,eAAe,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,EAAE;;IAC7D,IAAI;QACF,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAA;QAC3B,MAAM,OAAO,GAAG,6BAAqB,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAA;QAElE,MAAM,gBAAgB,GAAG,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,kBAAkB,mDAAG,MAAM,CAAC,CAAA,CAAA;QAC5F,IAAI,qBAAa,CAAC,gBAAgB,CAAC,EAAE;YACnC,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,cAAc,mDAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA,CAAA;SACvG;QAED,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,SAAS;SACnB,CAAA;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,gCAAgC,CAAA;QACrD,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;QAElC,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE,YAAY;SACtB,CAAA;KACF;AACH,CAAC,CAAA;AAED,kBAAe,eAAe,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export * from './apiHelpers';
2
- export * from './apiHandlers';
3
- export * from './protectRoute';
1
+ export * from './handlers';
2
+ export * from './helpers';
4
3
  export * from './withShopify';
package/dist/index.js CHANGED
@@ -10,8 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./apiHelpers"), exports);
14
- __exportStar(require("./apiHandlers"), exports);
15
- __exportStar(require("./protectRoute"), exports);
13
+ __exportStar(require("./handlers"), exports);
14
+ __exportStar(require("./helpers"), exports);
16
15
  __exportStar(require("./withShopify"), exports);
17
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA4B;AAC5B,gDAA6B;AAC7B,iDAA8B;AAC9B,gDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAA0B;AAC1B,4CAAyB;AACzB,gDAA6B"}
@@ -1,8 +1,3 @@
1
- export namespace BILLING_INTERVALS {
2
- const ONE_TIME: string;
3
- const EVERY_30_DAYS: string;
4
- const ANNUAL: string;
5
- }
6
1
  export class BillingManager {
7
2
  constructor(session: any, serverRuntimeConfig: any);
8
3
  shop: any;
@@ -1,90 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BillingManager = exports.BILLING_INTERVALS = void 0;
4
- const shopify_api_1 = require("@shopify/shopify-api"); // DataType
3
+ exports.BillingManager = void 0;
4
+ const shopify_api_1 = require("@shopify/shopify-api");
5
5
  const display_1 = require("./display");
6
- exports.BILLING_INTERVALS = {
7
- ONE_TIME: 'ONE_TIME',
8
- EVERY_30_DAYS: 'EVERY_30_DAYS',
9
- ANNUAL: 'ANNUAL',
10
- };
11
- const RECURRING_INTERVALS = [
12
- exports.BILLING_INTERVALS.EVERY_30_DAYS,
13
- exports.BILLING_INTERVALS.ANNUAL
14
- ];
15
- const RECURRING_PURCHASES_QUERY = `
16
- query appSubscription {
17
- currentAppInstallation {
18
- activeSubscriptions {
19
- name, test
20
- }
21
- }
22
- }
23
- `;
24
- const ONE_TIME_PURCHASES_QUERY = `
25
- query appPurchases($endCursor: String) {
26
- currentAppInstallation {
27
- oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {
28
- edges {
29
- node {
30
- name, test, status
31
- }
32
- }
33
- pageInfo {
34
- hasNextPage, endCursor
35
- }
36
- }
37
- }
38
- }
39
- `;
40
- const RECURRING_PURCHASE_MUTATION = `
41
- mutation test(
42
- $name: String!
43
- $lineItems: [AppSubscriptionLineItemInput!]!
44
- $returnUrl: URL!
45
- $test: Boolean
46
- ) {
47
- appSubscriptionCreate(
48
- name: $name
49
- lineItems: $lineItems
50
- returnUrl: $returnUrl
51
- test: $test
52
- ) {
53
- confirmationUrl
54
- userErrors {
55
- field
56
- message
57
- }
58
- }
59
- }
60
- `;
61
- const ONE_TIME_PURCHASE_MUTATION = `
62
- mutation test(
63
- $name: String!
64
- $price: MoneyInput!
65
- $returnUrl: URL!
66
- $test: Boolean
67
- ) {
68
- appPurchaseOneTimeCreate(
69
- name: $name
70
- price: $price
71
- returnUrl: $returnUrl
72
- test: $test
73
- ) {
74
- confirmationUrl
75
- userErrors {
76
- field
77
- message
78
- }
79
- }
80
- }
81
- `;
6
+ const constants_1 = require("./constants");
82
7
  class BillingManager {
83
8
  constructor(session, serverRuntimeConfig) {
84
9
  const { APP_ID, APP_BASE_URL, PAYMENT_CONFIG } = serverRuntimeConfig;
85
10
  if (display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.shop) ||
86
11
  display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.accessToken) ||
87
- !Object.values(exports.BILLING_INTERVALS).includes(PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.type)) {
12
+ !Object.values(constants_1.BILLING_INTERVALS).includes(PAYMENT_CONFIG === null || PAYMENT_CONFIG === void 0 ? void 0 : PAYMENT_CONFIG.type)) {
88
13
  throw new shopify_api_1.Shopify.Errors.BillingError({
89
14
  message: 'Invalid billing configuration',
90
15
  });
@@ -94,7 +19,7 @@ class BillingManager {
94
19
  this.appId = APP_ID;
95
20
  this.appBaseUrl = APP_BASE_URL;
96
21
  this.paymentConfig = display_1.ensureObject(PAYMENT_CONFIG);
97
- this.isRecurring = RECURRING_INTERVALS.includes(this.paymentConfig.type);
22
+ this.isRecurring = constants_1.RECURRING_INTERVALS.includes(this.paymentConfig.type);
98
23
  }
99
24
  async ensureBilling() {
100
25
  var _a;
@@ -117,32 +42,25 @@ class BillingManager {
117
42
  async hasActiveRecurringPayment(client) {
118
43
  var _a, _b, _c;
119
44
  const currentInstallations = await client.query({
120
- data: RECURRING_PURCHASES_QUERY,
45
+ data: constants_1.RECURRING_PURCHASES_QUERY,
121
46
  });
122
47
  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;
123
- const matchingSubscription = display_1.ensureArray(subscriptions).find((sub) => {
124
- const { name: chargeName, test: chargeTest } = sub;
125
- return ((chargeName === this.paymentConfig.name)
126
- && (display_1.isTrue(chargeTest) === this.paymentConfig.test));
127
- });
48
+ const matchingSubscription = display_1.ensureArray(subscriptions).find(({ name: chargeName, test: chargeTest } = {}) => ((chargeName === this.paymentConfig.name)
49
+ && (display_1.isTrue(chargeTest) === this.paymentConfig.test)));
128
50
  return display_1.objectNotEmpty(matchingSubscription);
129
51
  }
130
52
  async hasActiveOneTimePayment(client, endCursor = null) {
131
53
  var _a, _b, _c, _d, _e;
132
- const payload = {
54
+ const currentInstallations = await client.query({
133
55
  data: {
134
- query: ONE_TIME_PURCHASES_QUERY,
56
+ query: constants_1.ONE_TIME_PURCHASES_QUERY,
135
57
  variables: { endCursor },
136
58
  },
137
- };
138
- const currentInstallations = await client.query(payload);
139
- 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;
140
- const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find((pur) => {
141
- const { node } = pur;
142
- return (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
143
- && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
144
- && (display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) === this.paymentConfig.test));
145
59
  });
60
+ 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;
61
+ const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find(({ node } = {}) => (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
62
+ && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
63
+ && (display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) === this.paymentConfig.test)));
146
64
  if (display_1.objectNotEmpty(matchingPurchase)) {
147
65
  return true;
148
66
  }
@@ -158,40 +76,6 @@ class BillingManager {
158
76
  }
159
77
  return this.hasActiveOneTimePayment(client);
160
78
  }
161
- /*
162
- // TODO ensure this logic works for recurring payments
163
- async hasActivePayment () {
164
- const client = new Shopify.Clients.Rest(this.shop, this.accessToken)
165
-
166
- // TODO: move this to match scaffold (/ensure we check !test)
167
- const { body: { application_charges } = {} } = ensureObject(await client.get({
168
- path: 'application_charges',
169
- type: DataType.JSON,
170
- }))
171
-
172
- console.log(`>>> > BillingManager > existingCharge > this.appId`, this.appId)
173
- console.log(`>>> > BillingManager > hasActivePayment > ensureArray(application_charges).length`, ensureArray(application_charges).length)
174
-
175
- const existingCharge = ensureArray(application_charges).reduce((_existingCharge, charge) => {
176
- const { api_client_id, status: chargeStatus } = ensureObject(charge)
177
- const isMatching = (stringNotEmpty(api_client_id) && (ensureString(api_client_id) === this.appId))
178
- console.log(`>>> > BillingManager > existingCharge > ${api_client_id}`, chargeStatus)
179
-
180
- if (_existingCharge.status === 'active') {
181
- return _existingCharge
182
- }
183
-
184
- if (isMatching && ['active', 'pending'].includes(chargeStatus)) {
185
- return charge
186
- }
187
-
188
- return _existingCharge
189
- }, {})
190
- console.log(`>>> > BillingManager > hasActivePayment > existingCharge`, existingCharge)
191
-
192
- return objectNotEmpty(existingCharge)
193
- }
194
- */
195
79
  async requestPayment() {
196
80
  const client = new shopify_api_1.Shopify.Clients.Graphql(this.shop, this.accessToken);
197
81
  // TODO: explore objectToQuerystring
@@ -213,9 +97,9 @@ class BillingManager {
213
97
  async requestSinglePayment(client, returnUrl) {
214
98
  var _a, _b, _c, _d;
215
99
  const { price, name, test, } = this.paymentConfig;
216
- const payload = {
100
+ const mutationResponse = await client.query({
217
101
  data: {
218
- query: ONE_TIME_PURCHASE_MUTATION,
102
+ query: constants_1.ONE_TIME_PURCHASE_MUTATION,
219
103
  variables: {
220
104
  test,
221
105
  name,
@@ -223,8 +107,7 @@ class BillingManager {
223
107
  returnUrl,
224
108
  },
225
109
  },
226
- };
227
- const mutationResponse = await client.query(payload);
110
+ });
228
111
  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)) {
229
112
  throw new shopify_api_1.Shopify.Errors.BillingError({
230
113
  message: 'Error executing one-time purchase',
@@ -236,9 +119,9 @@ class BillingManager {
236
119
  async requestRecurringPayment(client, returnUrl) {
237
120
  var _a, _b, _c, _d;
238
121
  const { price, name, test, type: interval, } = this.paymentConfig;
239
- const payload = {
122
+ const mutationResponse = await client.query({
240
123
  data: {
241
- query: RECURRING_PURCHASE_MUTATION,
124
+ query: constants_1.RECURRING_PURCHASE_MUTATION,
242
125
  variables: {
243
126
  test,
244
127
  name,
@@ -253,8 +136,7 @@ class BillingManager {
253
136
  }],
254
137
  },
255
138
  },
256
- };
257
- const mutationResponse = await client.query(payload);
139
+ });
258
140
  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)) {
259
141
  throw new shopify_api_1.Shopify.Errors.BillingError({
260
142
  message: 'Error executing recurring purchase',
@@ -1 +1 @@
1
- {"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/utils/billing.js"],"names":[],"mappings":";;;AAAA,sDAA8C,CAAC,WAAW;AAE1D,uCAUkB;AAGL,QAAA,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,MAAM,mBAAmB,GAAG;IAC1B,yBAAiB,CAAC,aAAa;IAC/B,yBAAiB,CAAC,MAAM;CACzB,CAAA;AAED,MAAM,yBAAyB,GAAG;;;;;;;;CAQjC,CAAA;AAED,MAAM,wBAAwB,GAAG;;;;;;;;;;;;;;;CAehC,CAAA;AAED,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;CAoBnC,CAAA;AAED,MAAM,0BAA0B,GAAG;;;;;;;;;;;;;;;;;;;;CAoBlC,CAAA;AAED,MAAa,cAAc;IACzB,YAAY,OAAO,EAAE,mBAAmB;QACtC,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,yBAAiB,CAAC,CAAC,QAAQ,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,EAChE;YACA,MAAM,IAAI,qBAAO,CAAC,MAAM,CAAC,YAAY,CAAC;gBACpC,OAAO,EAAE,+BAA+B;aACzC,CAAC,CAAA;SACH;QAED,IAAI,CAAC,I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BACH;aACF;SACF,CAAC,CAAA;QAEF,IAAI,CAAA,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,IAAI,0CAAE,MAAM,KAAI,uBAAa,CAAC,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,IAAI,0CAAE,MAAM,CAAC,EAAE;YACnF,MAAM,IAAI,qBAAO,CAAC,MAAM,CAAC,YAAY,CAAC;gBACpC,OAAO,EAAE,oCAAoC;gBAC7C,SAAS,EAAE,qBAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,sBAAY,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;aAC5G,CAAC,CAAA;SACH;QAED,OAAO,MAAA,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,IAAI,0CAAE,IAAI,0CAAE,qBAAqB,CAAA;IAC5D,CAAC;CACF;AApLD,wCAoLC"}
@@ -0,0 +1,21 @@
1
+ export const COLLECTION_ROOT: "oauth-data";
2
+ export namespace PAGE_ROUTE_NAMES {
3
+ const EXIT: string;
4
+ const ERROR: string;
5
+ }
6
+ export namespace API_ROUTE_NAMES {
7
+ const AUTH: string;
8
+ const AUTH_CALLBACK: string;
9
+ const APP_UNINSTALLED: string;
10
+ }
11
+ export namespace BILLING_INTERVALS {
12
+ const ONE_TIME: string;
13
+ const EVERY_30_DAYS: string;
14
+ const ANNUAL: string;
15
+ }
16
+ export const RECURRING_INTERVALS: string[];
17
+ export const SHOP_QUERY: "\n {\n shop {\n name\n }\n }\n";
18
+ export const RECURRING_PURCHASES_QUERY: "\n query appSubscription {\n currentAppInstallation {\n activeSubscriptions {\n name, test\n }\n }\n }\n";
19
+ 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";
20
+ 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";
21
+ 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";
@@ -0,0 +1,97 @@
1
+ "use strict";
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;
4
+ exports.COLLECTION_ROOT = 'oauth-data';
5
+ exports.PAGE_ROUTE_NAMES = {
6
+ EXIT: 'pageRouteExit',
7
+ ERROR: 'pageRouteError',
8
+ };
9
+ exports.API_ROUTE_NAMES = {
10
+ AUTH: 'apiRouteAuth',
11
+ AUTH_CALLBACK: 'apiRouteAuthCallback',
12
+ APP_UNINSTALLED: 'apiRouteAppUninstalled',
13
+ };
14
+ exports.BILLING_INTERVALS = {
15
+ ONE_TIME: 'ONE_TIME',
16
+ EVERY_30_DAYS: 'EVERY_30_DAYS',
17
+ ANNUAL: 'ANNUAL',
18
+ };
19
+ exports.RECURRING_INTERVALS = [
20
+ exports.BILLING_INTERVALS.EVERY_30_DAYS,
21
+ exports.BILLING_INTERVALS.ANNUAL
22
+ ];
23
+ exports.SHOP_QUERY = `
24
+ {
25
+ shop {
26
+ name
27
+ }
28
+ }
29
+ `;
30
+ exports.RECURRING_PURCHASES_QUERY = `
31
+ query appSubscription {
32
+ currentAppInstallation {
33
+ activeSubscriptions {
34
+ name, test
35
+ }
36
+ }
37
+ }
38
+ `;
39
+ exports.ONE_TIME_PURCHASES_QUERY = `
40
+ query appPurchases($endCursor: String) {
41
+ currentAppInstallation {
42
+ oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {
43
+ edges {
44
+ node {
45
+ name, test, status
46
+ }
47
+ }
48
+ pageInfo {
49
+ hasNextPage, endCursor
50
+ }
51
+ }
52
+ }
53
+ }
54
+ `;
55
+ exports.RECURRING_PURCHASE_MUTATION = `
56
+ mutation test(
57
+ $name: String!
58
+ $lineItems: [AppSubscriptionLineItemInput!]!
59
+ $returnUrl: URL!
60
+ $test: Boolean
61
+ ) {
62
+ appSubscriptionCreate(
63
+ name: $name
64
+ lineItems: $lineItems
65
+ returnUrl: $returnUrl
66
+ test: $test
67
+ ) {
68
+ confirmationUrl
69
+ userErrors {
70
+ field
71
+ message
72
+ }
73
+ }
74
+ }
75
+ `;
76
+ exports.ONE_TIME_PURCHASE_MUTATION = `
77
+ mutation test(
78
+ $name: String!
79
+ $price: MoneyInput!
80
+ $returnUrl: URL!
81
+ $test: Boolean
82
+ ) {
83
+ appPurchaseOneTimeCreate(
84
+ name: $name
85
+ price: $price
86
+ returnUrl: $returnUrl
87
+ test: $test
88
+ ) {
89
+ confirmationUrl
90
+ userErrors {
91
+ field
92
+ message
93
+ }
94
+ }
95
+ }
96
+ `;
97
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +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;AAEY,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"}
@@ -1,22 +1,16 @@
1
1
  export class FirebaseSessionHandler {
2
- static getInstance(firebaseConfig: any, data: any): any;
3
- constructor(enforcer: any, { app, shop, collection }?: {
4
- app: any;
5
- shop: any;
6
- collection?: string;
7
- });
2
+ static getInstance(firebaseConfig: any, collection: any): any;
3
+ constructor(enforcer: any, collection?: string);
8
4
  type: string;
9
- app: any;
10
- shop: any;
11
5
  collection: string;
12
6
  get isInitialized(): boolean;
13
7
  initializeFireStore(firebaseConfig: any): void;
14
8
  firestore: any;
15
9
  [singleton]: FirebaseSessionHandler;
16
10
  }
17
- export function storeCallback(session: any, handler: any): Promise<boolean>;
18
- export function loadCallback(sessionId: any, handler: any): Promise<any>;
19
- export function deleteSessionsCallback(sessionIds: any, handler: any): Promise<void>;
20
- export function findSessionsByShop(shop: any, handler: any): Promise<any[]>;
11
+ export function storeCallback(session: any, data: any, instance: any): Promise<boolean>;
12
+ export function loadCallback(sessionId: any, data: any, instance: any): Promise<any>;
13
+ export function deleteSessionsCallback(sessionIds: any, data: any, instance: any): Promise<void>;
14
+ export function findSessionsByShop(shop: any, data: any, instance: any): Promise<any[]>;
21
15
  declare const singleton: unique symbol;
22
16
  export {};