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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/handlers/api.js +31 -14
  2. package/dist/handlers/api.js.map +1 -1
  3. package/dist/handlers/ssr.d.ts +1 -10
  4. package/dist/handlers/ssr.js +18 -15
  5. package/dist/handlers/ssr.js.map +1 -1
  6. package/dist/helpers/auth.d.ts +1 -9
  7. package/dist/helpers/auth.js +19 -11
  8. package/dist/helpers/auth.js.map +1 -1
  9. package/dist/helpers/callback.d.ts +1 -4
  10. package/dist/helpers/callback.js +35 -28
  11. package/dist/helpers/callback.js.map +1 -1
  12. package/dist/helpers/graph.d.ts +1 -1
  13. package/dist/helpers/graph.js +3 -5
  14. package/dist/helpers/graph.js.map +1 -1
  15. package/dist/helpers/rest.js +6 -9
  16. package/dist/helpers/rest.js.map +1 -1
  17. package/dist/helpers/uninstall.js +10 -16
  18. package/dist/helpers/uninstall.js.map +1 -1
  19. package/dist/utils/billing.d.ts +11 -20
  20. package/dist/utils/billing.js +52 -190
  21. package/dist/utils/billing.js.map +1 -1
  22. package/dist/utils/constants.d.ts +4 -5
  23. package/dist/utils/constants.js +4 -72
  24. package/dist/utils/constants.js.map +1 -1
  25. package/dist/utils/display.d.ts +1 -1
  26. package/dist/utils/firebase.d.ts +13 -6
  27. package/dist/utils/firebase.js +35 -39
  28. package/dist/utils/firebase.js.map +1 -1
  29. package/dist/utils/index.d.ts +0 -1
  30. package/dist/utils/index.js +0 -1
  31. package/dist/utils/index.js.map +1 -1
  32. package/dist/utils/session.d.ts +16 -11
  33. package/dist/utils/session.js +45 -34
  34. package/dist/utils/session.js.map +1 -1
  35. package/dist/utils/shopify-api-node/beginAuth.js +3 -2
  36. package/dist/utils/shopify-api-node/beginAuth.js.map +1 -1
  37. package/dist/utils/shopify.d.ts +4 -3
  38. package/dist/utils/shopify.js +49 -15
  39. package/dist/utils/shopify.js.map +1 -1
  40. package/dist/withShopify.js +15 -17
  41. package/dist/withShopify.js.map +1 -1
  42. package/package.json +1 -1
  43. package/CHANGELOG.md +0 -469
  44. package/dist/utils/webhooks.d.ts +0 -1
  45. package/dist/utils/webhooks.js +0 -22
  46. package/dist/utils/webhooks.js.map +0 -1
@@ -1,209 +1,71 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generatePaymentConfig = exports.BillingManager = void 0;
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
- class BillingManager {
8
- constructor(shopify, session, serverRuntimeConfig) {
9
- const { APP_ID, APP_BASE_URL, PAYMENT_CONFIG } = serverRuntimeConfig;
10
- if (display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.shop) ||
11
- display_1.stringEmpty(session === null || session === void 0 ? void 0 : session.accessToken) ||
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.BillingError({
14
- message: 'Invalid billing configuration',
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
+ // TODO: minor update to handle if no paymentConfig or !paymentConfig.req'd return undefined??
13
+ const ensureBilling = async (shopify, session, paymentConfig) => {
14
+ if (!hasValidBilling(session, paymentConfig)) {
15
+ throw new shopify_api_1.BillingError({
16
+ message: 'Invalid billing configuration',
49
17
  });
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
- }
57
- async hasActiveOneTimePayment(endCursor = null) {
58
- var _a, _b, _c, _d, _e;
59
- const currentInstallations = await this.graphClient.query({
60
- data: {
61
- query: constants_1.ONE_TIME_PURCHASES_QUERY,
62
- variables: { endCursor },
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
- const matchingPurchase = display_1.ensureArray(purchases === null || purchases === void 0 ? void 0 : purchases.edges).find(({ node } = {}) => {
67
- if (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name) && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')) {
68
- console.log(`>>> ~ node`, {
69
- node,
70
- truish: (!display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) || this.paymentConfig.test),
71
- });
72
- }
73
- return (((node === null || node === void 0 ? void 0 : node.name) === this.paymentConfig.name)
74
- && ((node === null || node === void 0 ? void 0 : node.status) === 'ACTIVE')
75
- && (!display_1.isTrue(node === null || node === void 0 ? void 0 : node.test) || this.paymentConfig.test)
76
- // ORIG && (isTrue(node?.test) === this.paymentConfig.test)
77
- );
78
- });
79
- if (display_1.objectNotEmpty(matchingPurchase)) {
80
- return true;
81
- }
82
- if ((_d = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _d === void 0 ? void 0 : _d.hasNextPage) {
83
- return this.hasActiveOneTimePayment((_e = purchases === null || purchases === void 0 ? void 0 : purchases.pageInfo) === null || _e === void 0 ? void 0 : _e.endCursor);
84
- }
85
- return false;
86
- }
87
- async hasActivePayment() {
88
- if (this.isRecurring) {
89
- return this.hasActiveRecurringPayment();
90
- }
91
- return this.hasActiveOneTimePayment();
92
18
  }
93
- async requestPayment() {
94
- // TODO: explore objectToQuerystring
95
- const queryParams = [
96
- `shop=${this.shop}`,
97
- `host=${Buffer.from(`${this.shop}/admin`).toString('base64')}`
98
- ];
99
- const returnUrl = `${this.appBaseUrl}?${queryParams.join('&')}`;
100
- const data = this.isRecurring
101
- ? await this.requestRecurringPayment(returnUrl)
102
- : await this.requestSinglePayment(returnUrl);
103
- if (display_1.arrayNotEmpty(data === null || data === void 0 ? void 0 : data.userErrors)) {
104
- throw new shopify_api_1.BillingError({
105
- message: 'User error requesting payment',
106
- });
19
+ try {
20
+ if (display_1.isTrue(await shopify.billing.check({
21
+ plans: [paymentConfig.name],
22
+ isTest: display_1.isTrue(paymentConfig.test),
23
+ session,
24
+ }))) {
25
+ return undefined;
107
26
  }
108
- return data === null || data === void 0 ? void 0 : data.confirmationUrl;
109
- }
110
- async requestSinglePayment(returnUrl) {
111
- var _a, _b, _c, _d;
112
- const { price, name, test, } = this.paymentConfig;
113
- const mutationResponse = await this.graphClient.query({
114
- data: {
115
- query: constants_1.ONE_TIME_PURCHASE_MUTATION,
116
- variables: {
117
- test,
118
- name,
119
- price,
120
- returnUrl,
121
- },
122
- },
27
+ return shopify.billing.request({
28
+ plan: paymentConfig.name,
29
+ isTest: display_1.isTrue(paymentConfig.test),
30
+ session,
123
31
  });
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)) {
125
- throw new shopify_api_1.BillingError({
126
- message: 'Error executing one-time purchase',
127
- errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
128
- });
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;
131
32
  }
132
- async requestRecurringPayment(returnUrl) {
133
- var _a, _b, _c, _d;
134
- const { price, name, test, type: interval, } = this.paymentConfig;
135
- const mutationResponse = await this.graphClient.query({
136
- data: {
137
- query: constants_1.RECURRING_PURCHASE_MUTATION,
138
- variables: {
139
- test,
140
- name,
141
- returnUrl,
142
- lineItems: [{
143
- plan: {
144
- appRecurringPricingDetails: {
145
- interval,
146
- price,
147
- },
148
- },
149
- }],
150
- },
151
- },
33
+ catch (error) {
34
+ throw new shopify_api_1.BillingError({
35
+ message: 'Failed to verify or initialize payment',
152
36
  });
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)) {
154
- throw new shopify_api_1.BillingError({
155
- message: 'Error executing recurring purchase',
156
- errorData: display_1.ensureArray(mutationResponse.body.errors).map(({ message }) => display_1.ensureString(message)).join('. '),
157
- });
158
- }
159
- 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;
160
37
  }
161
- }
162
- exports.BillingManager = BillingManager;
163
- // TODO enable billing management
38
+ };
39
+ exports.ensureBilling = ensureBilling;
164
40
  // 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
41
+ const generatePaymentConfig = (data) => {
42
+ const { debugMode, environment, paymentConfig, SHOPIFY_RUN_MODE, } = display_1.ensureObject(data);
43
+ const { name, price, currency = 'USD', type = constants_1.BILLING_INTERVALS.ONE_TIME, } = display_1.ensureObject(paymentConfig);
44
+ if (display_1.objectEmpty(paymentConfig) || display_1.stringEmpty(environment)) {
45
+ return undefined;
178
46
  }
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
-
47
+ const isProduction = (environment === 'production');
48
+ const notProduction = !isProduction;
49
+ const billingName = `${name}${notProduction ? ` - ${environment}` : ''} - ${display_1.unsnakecase(type)}`;
188
50
  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
-
51
+ required: (isProduction || (SHOPIFY_RUN_MODE === 'cli')),
52
+ test: (notProduction || debugMode),
53
+ name: billingName,
54
+ config: {
55
+ interval: type,
56
+ amount: price,
57
+ currencyCode: currency,
58
+ },
59
+ };
60
+ // TODO: clean this up
199
61
  console.log(`>>> ~ _paymentConfig`, {
200
- _paymentConfig,
201
- debugMode,
202
- debugEnv: process.env.DEBUG,
203
- })
204
-
205
- return _paymentConfig
206
- */
62
+ _paymentConfig,
63
+ SHOPIFY_RUN_MODE,
64
+ notProduction,
65
+ debugMode,
66
+ debugEnv: process.env.DEBUG,
67
+ });
68
+ return _paymentConfig;
207
69
  };
208
70
  exports.generatePaymentConfig = generatePaymentConfig;
209
71
  //# sourceMappingURL=billing.js.map
@@ -1 +1 @@
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,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CAAC,CAAC,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,qBAAW,CAAC,IAAI,CAAC,EAAE,CAAA;IAE/F,MAAM,cAAc,GAAG;QACrB,QAAQ,EAAE,CAAC,YAAY,IAAI,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC;QACxD,IAAI,EAAE,CAAC,aAAa,IAAI,SAAS,CAAC;QAClC,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,gBAAgB;QAChB,aAAa;QACb,SAAS;QACT,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK;KAC5B,CAAC,CAAA;IAEF,OAAO,cAAc,CAAA;AACvB,CAAC,CAAA;AA1CY,QAAA,qBAAqB,yBA0CjC"}
@@ -8,14 +8,13 @@ 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;
14
18
  const ANNUAL: string;
15
19
  }
16
- export const RECURRING_INTERVALS: string[];
17
20
  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";
@@ -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.SHOP_QUERY = 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,15 +11,14 @@ 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',
17
20
  ANNUAL: 'ANNUAL',
18
21
  };
19
- exports.RECURRING_INTERVALS = [
20
- exports.BILLING_INTERVALS.EVERY_30_DAYS,
21
- exports.BILLING_INTERVALS.ANNUAL
22
- ];
23
22
  // TODO can we remove?
24
23
  /*
25
24
  export const SHOP_DATA_QUERY = `
@@ -66,71 +65,4 @@ exports.SHOP_QUERY = `
66
65
  }
67
66
  }
68
67
  `;
69
- exports.RECURRING_PURCHASES_QUERY = `
70
- query appSubscription {
71
- currentAppInstallation {
72
- activeSubscriptions {
73
- name, test
74
- }
75
- }
76
- }
77
- `;
78
- exports.ONE_TIME_PURCHASES_QUERY = `
79
- query appPurchases($endCursor: String) {
80
- currentAppInstallation {
81
- oneTimePurchases(first: 250, sortKey: CREATED_AT, after: $endCursor) {
82
- edges {
83
- node {
84
- name, test, status
85
- }
86
- }
87
- pageInfo {
88
- hasNextPage, endCursor
89
- }
90
- }
91
- }
92
- }
93
- `;
94
- exports.RECURRING_PURCHASE_MUTATION = `
95
- mutation test(
96
- $name: String!
97
- $lineItems: [AppSubscriptionLineItemInput!]!
98
- $returnUrl: URL!
99
- $test: Boolean
100
- ) {
101
- appSubscriptionCreate(
102
- name: $name
103
- lineItems: $lineItems
104
- returnUrl: $returnUrl
105
- test: $test
106
- ) {
107
- confirmationUrl
108
- userErrors {
109
- field
110
- message
111
- }
112
- }
113
- }
114
- `;
115
- exports.ONE_TIME_PURCHASE_MUTATION = `
116
- mutation test(
117
- $name: String!
118
- $price: MoneyInput!
119
- $returnUrl: URL!
120
- $test: Boolean
121
- ) {
122
- appPurchaseOneTimeCreate(
123
- name: $name
124
- price: $price
125
- returnUrl: $returnUrl
126
- test: $test
127
- ) {
128
- confirmationUrl
129
- userErrors {
130
- field
131
- message
132
- }
133
- }
134
- }
135
- `;
136
68
  //# sourceMappingURL=constants.js.map
@@ -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;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"}
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,kBAAkB,GAAG;IAChC,eAAe,EAAE,iBAAiB;CACnC,CAAA;AAEY,QAAA,iBAAiB,GAAG;IAC/B,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,sBAAsB;AACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqCE;AAEW,QAAA,UAAU,GAAG;;;;;;CAMzB,CAAA"}
@@ -1,7 +1,7 @@
1
1
  export function getGUID(): any;
2
2
  export function getInteger(): any;
3
3
  export function querystringToObject(queryString: any): {
4
- [k: string]: any;
4
+ [k: string]: string;
5
5
  };
6
6
  export function isType(value: any, type: any): boolean;
7
7
  export function ensureObject(object: any): any;
@@ -1,16 +1,23 @@
1
1
  export class FirebaseSessionHandler {
2
- static getInstance(firebaseConfig: any, collection: any): any;
3
- constructor(enforcer: any, collection?: string);
2
+ static getInstance(firebaseConfig: any, { collection, config }: {
3
+ collection: any;
4
+ config: any;
5
+ }): any;
6
+ constructor(enforcer: any, { config, collection }: {
7
+ config: any;
8
+ collection?: string;
9
+ });
4
10
  type: string;
11
+ config: any;
5
12
  collection: string;
6
13
  get isInitialized(): boolean;
7
14
  initializeFireStore(firebaseConfig: any): void;
8
15
  firestore: any;
9
16
  [singleton]: FirebaseSessionHandler;
10
17
  }
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[]>;
18
+ export function storeCallback(instance: any, session: any): Promise<boolean>;
19
+ export function loadCallback(instance: any, sessionId: any): Promise<any>;
20
+ export function deleteSessionsCallback(instance: any, sessionIds: any): Promise<void>;
21
+ export function findSessionsByShop(instance: any, shop: any): Promise<any[]>;
15
22
  declare const singleton: unique symbol;
16
23
  export {};
@@ -21,11 +21,12 @@ const constants_1 = require("./constants");
21
21
  const singleton = Symbol('singleton');
22
22
  const singletonEnforcer = Symbol('singletonEnforcer');
23
23
  class FirebaseSessionHandler {
24
- constructor(enforcer, collection = constants_1.COLLECTION_ROOT) {
24
+ constructor(enforcer, { config, collection = constants_1.COLLECTION_ROOT }) {
25
25
  this.type = 'FirebaseSessionHandler';
26
26
  if (enforcer !== singletonEnforcer) {
27
27
  throw new Error('Cannot instantiate FirebaseSessionHandler directly, please use getInstance()');
28
28
  }
29
+ this.config = config;
29
30
  this.collection = collection;
30
31
  }
31
32
  get isInitialized() {
@@ -41,9 +42,9 @@ class FirebaseSessionHandler {
41
42
  this.firestore = project.firestore();
42
43
  }
43
44
  }
44
- static getInstance(firebaseConfig, collection) {
45
+ static getInstance(firebaseConfig, { collection, config }) {
45
46
  if (!this[singleton]) {
46
- this[singleton] = new FirebaseSessionHandler(singletonEnforcer, collection);
47
+ this[singleton] = new FirebaseSessionHandler(singletonEnforcer, { collection, config });
47
48
  }
48
49
  if (!this[singleton].isInitialized) {
49
50
  this[singleton].initializeFireStore(firebaseConfig);
@@ -52,12 +53,12 @@ class FirebaseSessionHandler {
52
53
  }
53
54
  }
54
55
  exports.FirebaseSessionHandler = FirebaseSessionHandler;
55
- const storeCallback = async (session, data, instance) => {
56
+ const storeCallback = async (instance, session) => {
56
57
  try {
57
58
  const docRef = instance.firestore
58
59
  .collection(instance.collection)
59
- .doc(data.shop)
60
- .collection(data.app)
60
+ .doc(instance.config.shop)
61
+ .collection(instance.config.configurationId)
61
62
  .doc(session.id);
62
63
  const _a = JSON.parse(JSON.stringify(session)), { onlineAccessInfo: _onlineAccessInfo } = _a, docData = __rest(_a, ["onlineAccessInfo"]);
63
64
  // NOTE: destructuring out associated_user for DPA compliance
@@ -67,18 +68,18 @@ const storeCallback = async (session, data, instance) => {
67
68
  await docRef.set(payload);
68
69
  return true;
69
70
  }
70
- catch (err) {
71
- console.error('FirebaseSessionHandler.storeCallback error', err);
72
- throw err;
71
+ catch (error) {
72
+ console.error('FirebaseSessionHandler.storeCallback error', error);
73
+ throw error;
73
74
  }
74
75
  };
75
76
  exports.storeCallback = storeCallback;
76
- const loadCallback = async (sessionId, data, instance) => {
77
+ const loadCallback = async (instance, sessionId) => {
77
78
  try {
78
79
  const docRef = instance.firestore
79
80
  .collection(instance.collection)
80
- .doc(data.shop)
81
- .collection(data.app)
81
+ .doc(instance.config.shop)
82
+ .collection(instance.config.configurationId)
82
83
  .doc(sessionId);
83
84
  const document = await docRef.get();
84
85
  if (document.exists) {
@@ -86,56 +87,51 @@ const loadCallback = async (sessionId, data, instance) => {
86
87
  }
87
88
  return undefined;
88
89
  }
89
- catch (err) {
90
- console.error('FirebaseSessionHandler.loadCallback error', err);
91
- throw err;
90
+ catch (error) {
91
+ console.error('FirebaseSessionHandler.loadCallback error', error);
92
+ throw error;
92
93
  }
93
94
  };
94
95
  exports.loadCallback = loadCallback;
95
- const deleteSessionsCallback = async (sessionIds, data, instance) => {
96
+ const deleteSessionsCallback = async (instance, sessionIds) => {
97
+ const collectionRef = instance.firestore
98
+ .collection(instance.collection)
99
+ .doc(instance.config.shop)
100
+ .collection(instance.config.configurationId);
96
101
  const _deleteSessionCallback = async (_sessionId) => {
97
102
  try {
98
- const docRef = instance.firestore
99
- .collection(instance.collection)
100
- .doc(data.shop)
101
- .collection(data.app)
102
- .doc(_sessionId);
103
+ const docRef = collectionRef.doc(_sessionId);
103
104
  await docRef.delete();
104
105
  return true;
105
106
  }
106
- catch (err) {
107
- console.error('FirebaseSessionHandler.deleteSessionsCallback error', err);
108
- throw err;
107
+ catch (error) {
108
+ console.error('FirebaseSessionHandler.deleteSessionsCallback error', error);
109
+ throw error;
109
110
  }
110
111
  };
111
112
  await Promise.all(display_1.ensureArray(sessionIds).map((sessionId) => _deleteSessionCallback(sessionId)));
112
113
  };
113
114
  exports.deleteSessionsCallback = deleteSessionsCallback;
114
- const findSessionsByShop = async (shop, data, instance) => {
115
- console.log('data:', data);
116
- console.log('shop:', shop);
117
- if (display_1.stringEmpty(shop)) {
115
+ const findSessionsByShop = async (instance, shop) => {
116
+ if (display_1.stringEmpty(shop) || (shop !== instance.config.shop)) {
117
+ console.warn('FirebaseSessionHandler.findSessionsByShop warn', shop);
118
118
  return [];
119
119
  }
120
120
  try {
121
- console.log('try:');
122
- const collectionRef = instance.firestore
121
+ const collection = await instance.firestore
123
122
  .collection(instance.collection)
124
123
  .doc(shop)
125
- .collection(data.app);
126
- console.log('collectionRef:', collectionRef);
127
- const querySnapshot = await collectionRef.get();
128
- console.log('querySnapshot:', querySnapshot);
124
+ .collection(instance.config.configurationId)
125
+ .get();
129
126
  const sessions = [];
130
- querySnapshot.forEach((_doc) => {
127
+ collection.forEach((_doc) => {
131
128
  sessions.push(_doc.data());
132
129
  });
133
- console.log('sessions:', sessions);
134
130
  return sessions;
135
131
  }
136
- catch (err) {
137
- console.error('FirebaseSessionHandler.findSessionsByShop error', err);
138
- throw err;
132
+ catch (error) {
133
+ console.error('FirebaseSessionHandler.findSessionsByShop error', error);
134
+ throw error;
139
135
  }
140
136
  };
141
137
  exports.findSessionsByShop = findSessionsByShop;
@@ -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,C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C,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC;aAC/B,GAAG,CAAC,IAAI,CAAC;aACT,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;aAC3C,GAAG,EAAE,CAAA;QAER,MAAM,QAAQ,GAAG,EAAE,CAAA;QACnB,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC1B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QAEF,OAAO,QAAQ,CAAA;KAChB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,KAAK,CAAC,iDAAiD,EAAE,KAAK,CAAC,CAAA;QACvE,MAAM,KAAK,CAAA;KACZ;AACH,CAAC,CAAA;AAvBY,QAAA,kBAAkB,sBAuB9B"}
@@ -5,4 +5,3 @@ export * from "./errors";
5
5
  export * from "./firebase";
6
6
  export * from "./session";
7
7
  export * from "./shopify";
8
- export * from "./webhooks";
@@ -17,5 +17,4 @@ __exportStar(require("./errors"), exports);
17
17
  __exportStar(require("./firebase"), exports);
18
18
  __exportStar(require("./session"), exports);
19
19
  __exportStar(require("./shopify"), exports);
20
- __exportStar(require("./webhooks"), exports);
21
20
  //# sourceMappingURL=index.js.map