@shopify/shopify-app-remix 1.0.0-rc.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 (161) hide show
  1. package/LICENSE.md +9 -0
  2. package/README.md +373 -0
  3. package/build/cjs/adapters/node/index.js +13 -0
  4. package/build/cjs/auth/admin/authenticate.js +599 -0
  5. package/build/cjs/auth/admin/graphql-client.js +57 -0
  6. package/build/cjs/auth/admin/rest-client.js +124 -0
  7. package/build/cjs/auth/const.js +17 -0
  8. package/build/cjs/auth/helpers/add-response-headers.js +69 -0
  9. package/build/cjs/auth/helpers/begin-auth.js +18 -0
  10. package/build/cjs/auth/helpers/get-session-token-header.js +10 -0
  11. package/build/cjs/auth/helpers/handle-client-error.js +37 -0
  12. package/build/cjs/auth/helpers/redirect-to-auth-page.js +22 -0
  13. package/build/cjs/auth/helpers/redirect-with-app-bridge-headers.js +31 -0
  14. package/build/cjs/auth/helpers/redirect-with-exitiframe.js +23 -0
  15. package/build/cjs/auth/helpers/reject-bot-request.js +23 -0
  16. package/build/cjs/auth/helpers/validate-session-token.js +25 -0
  17. package/build/cjs/auth/login/login.js +54 -0
  18. package/build/cjs/auth/public/authenticate.js +32 -0
  19. package/build/cjs/auth/webhooks/authenticate.js +68 -0
  20. package/build/cjs/auth/webhooks/register.js +40 -0
  21. package/build/cjs/billing/cancel.js +40 -0
  22. package/build/cjs/billing/request.js +83 -0
  23. package/build/cjs/billing/require.js +47 -0
  24. package/build/cjs/index.js +140 -0
  25. package/build/cjs/override-logger.js +55 -0
  26. package/build/cjs/types.js +25 -0
  27. package/build/cjs/version.js +7 -0
  28. package/build/ts/adapters/node/index.d.ts +2 -0
  29. package/build/ts/adapters/node/index.d.ts.map +1 -0
  30. package/build/ts/adapters/node/index.js +10 -0
  31. package/build/ts/adapters/node/index.js.map +1 -0
  32. package/build/ts/auth/admin/authenticate.d.ts +32 -0
  33. package/build/ts/auth/admin/authenticate.d.ts.map +1 -0
  34. package/build/ts/auth/admin/authenticate.js +571 -0
  35. package/build/ts/auth/admin/authenticate.js.map +1 -0
  36. package/build/ts/auth/admin/graphql-client.d.ts +22 -0
  37. package/build/ts/auth/admin/graphql-client.d.ts.map +1 -0
  38. package/build/ts/auth/admin/graphql-client.js +53 -0
  39. package/build/ts/auth/admin/graphql-client.js.map +1 -0
  40. package/build/ts/auth/admin/rest-client.d.ts +34 -0
  41. package/build/ts/auth/admin/rest-client.d.ts.map +1 -0
  42. package/build/ts/auth/admin/rest-client.js +134 -0
  43. package/build/ts/auth/admin/rest-client.js.map +1 -0
  44. package/build/ts/auth/admin/types.d.ts +100 -0
  45. package/build/ts/auth/admin/types.d.ts.map +1 -0
  46. package/build/ts/auth/admin/types.js +3 -0
  47. package/build/ts/auth/admin/types.js.map +1 -0
  48. package/build/ts/auth/const.d.ts +9 -0
  49. package/build/ts/auth/const.d.ts.map +1 -0
  50. package/build/ts/auth/const.js +12 -0
  51. package/build/ts/auth/const.js.map +1 -0
  52. package/build/ts/auth/helpers/add-response-headers.d.ts +5 -0
  53. package/build/ts/auth/helpers/add-response-headers.d.ts.map +1 -0
  54. package/build/ts/auth/helpers/add-response-headers.js +60 -0
  55. package/build/ts/auth/helpers/add-response-headers.js.map +1 -0
  56. package/build/ts/auth/helpers/begin-auth.d.ts +3 -0
  57. package/build/ts/auth/helpers/begin-auth.d.ts.map +1 -0
  58. package/build/ts/auth/helpers/begin-auth.js +24 -0
  59. package/build/ts/auth/helpers/begin-auth.js.map +1 -0
  60. package/build/ts/auth/helpers/get-session-token-header.d.ts +2 -0
  61. package/build/ts/auth/helpers/get-session-token-header.d.ts.map +1 -0
  62. package/build/ts/auth/helpers/get-session-token-header.js +9 -0
  63. package/build/ts/auth/helpers/get-session-token-header.js.map +1 -0
  64. package/build/ts/auth/helpers/handle-client-error.d.ts +11 -0
  65. package/build/ts/auth/helpers/handle-client-error.d.ts.map +1 -0
  66. package/build/ts/auth/helpers/handle-client-error.js +40 -0
  67. package/build/ts/auth/helpers/handle-client-error.js.map +1 -0
  68. package/build/ts/auth/helpers/index.d.ts +8 -0
  69. package/build/ts/auth/helpers/index.d.ts.map +1 -0
  70. package/build/ts/auth/helpers/index.js +18 -0
  71. package/build/ts/auth/helpers/index.js.map +1 -0
  72. package/build/ts/auth/helpers/redirect-to-auth-page.d.ts +3 -0
  73. package/build/ts/auth/helpers/redirect-to-auth-page.d.ts.map +1 -0
  74. package/build/ts/auth/helpers/redirect-to-auth-page.js +33 -0
  75. package/build/ts/auth/helpers/redirect-to-auth-page.js.map +1 -0
  76. package/build/ts/auth/helpers/redirect-with-app-bridge-headers.d.ts +4 -0
  77. package/build/ts/auth/helpers/redirect-with-app-bridge-headers.d.ts.map +1 -0
  78. package/build/ts/auth/helpers/redirect-with-app-bridge-headers.js +24 -0
  79. package/build/ts/auth/helpers/redirect-with-app-bridge-headers.js.map +1 -0
  80. package/build/ts/auth/helpers/redirect-with-exitiframe.d.ts +3 -0
  81. package/build/ts/auth/helpers/redirect-with-exitiframe.d.ts.map +1 -0
  82. package/build/ts/auth/helpers/redirect-with-exitiframe.js +18 -0
  83. package/build/ts/auth/helpers/redirect-with-exitiframe.js.map +1 -0
  84. package/build/ts/auth/helpers/reject-bot-request.d.ts +3 -0
  85. package/build/ts/auth/helpers/reject-bot-request.d.ts.map +1 -0
  86. package/build/ts/auth/helpers/reject-bot-request.js +14 -0
  87. package/build/ts/auth/helpers/reject-bot-request.js.map +1 -0
  88. package/build/ts/auth/helpers/validate-session-token.d.ts +4 -0
  89. package/build/ts/auth/helpers/validate-session-token.d.ts.map +1 -0
  90. package/build/ts/auth/helpers/validate-session-token.js +36 -0
  91. package/build/ts/auth/helpers/validate-session-token.js.map +1 -0
  92. package/build/ts/auth/login/login.d.ts +3 -0
  93. package/build/ts/auth/login/login.d.ts.map +1 -0
  94. package/build/ts/auth/login/login.js +56 -0
  95. package/build/ts/auth/login/login.js.map +1 -0
  96. package/build/ts/auth/public/authenticate.d.ts +4 -0
  97. package/build/ts/auth/public/authenticate.d.ts.map +1 -0
  98. package/build/ts/auth/public/authenticate.js +35 -0
  99. package/build/ts/auth/public/authenticate.js.map +1 -0
  100. package/build/ts/auth/public/types.d.ts +27 -0
  101. package/build/ts/auth/public/types.d.ts.map +1 -0
  102. package/build/ts/auth/public/types.js +3 -0
  103. package/build/ts/auth/public/types.js.map +1 -0
  104. package/build/ts/auth/webhooks/authenticate.d.ts +5 -0
  105. package/build/ts/auth/webhooks/authenticate.d.ts.map +1 -0
  106. package/build/ts/auth/webhooks/authenticate.js +71 -0
  107. package/build/ts/auth/webhooks/authenticate.js.map +1 -0
  108. package/build/ts/auth/webhooks/index.d.ts +2 -0
  109. package/build/ts/auth/webhooks/index.d.ts.map +1 -0
  110. package/build/ts/auth/webhooks/index.js +6 -0
  111. package/build/ts/auth/webhooks/index.js.map +1 -0
  112. package/build/ts/auth/webhooks/register.d.ts +4 -0
  113. package/build/ts/auth/webhooks/register.d.ts.map +1 -0
  114. package/build/ts/auth/webhooks/register.js +39 -0
  115. package/build/ts/auth/webhooks/register.js.map +1 -0
  116. package/build/ts/auth/webhooks/types.d.ts +18 -0
  117. package/build/ts/auth/webhooks/types.d.ts.map +1 -0
  118. package/build/ts/auth/webhooks/types.js +3 -0
  119. package/build/ts/auth/webhooks/types.js.map +1 -0
  120. package/build/ts/billing/cancel.d.ts +5 -0
  121. package/build/ts/billing/cancel.d.ts.map +1 -0
  122. package/build/ts/billing/cancel.js +43 -0
  123. package/build/ts/billing/cancel.js.map +1 -0
  124. package/build/ts/billing/index.d.ts +4 -0
  125. package/build/ts/billing/index.d.ts.map +1 -0
  126. package/build/ts/billing/index.js +10 -0
  127. package/build/ts/billing/index.js.map +1 -0
  128. package/build/ts/billing/request.d.ts +6 -0
  129. package/build/ts/billing/request.d.ts.map +1 -0
  130. package/build/ts/billing/request.js +84 -0
  131. package/build/ts/billing/request.js.map +1 -0
  132. package/build/ts/billing/require.d.ts +6 -0
  133. package/build/ts/billing/require.d.ts.map +1 -0
  134. package/build/ts/billing/require.js +55 -0
  135. package/build/ts/billing/require.js.map +1 -0
  136. package/build/ts/billing/types.d.ts +228 -0
  137. package/build/ts/billing/types.d.ts.map +1 -0
  138. package/build/ts/billing/types.js +3 -0
  139. package/build/ts/billing/types.js.map +1 -0
  140. package/build/ts/config-types.d.ts +325 -0
  141. package/build/ts/config-types.d.ts.map +1 -0
  142. package/build/ts/config-types.js +3 -0
  143. package/build/ts/config-types.js.map +1 -0
  144. package/build/ts/index.d.ts +29 -0
  145. package/build/ts/index.d.ts.map +1 -0
  146. package/build/ts/index.js +108 -0
  147. package/build/ts/index.js.map +1 -0
  148. package/build/ts/override-logger.d.ts +3 -0
  149. package/build/ts/override-logger.d.ts.map +1 -0
  150. package/build/ts/override-logger.js +40 -0
  151. package/build/ts/override-logger.js.map +1 -0
  152. package/build/ts/types.d.ts +353 -0
  153. package/build/ts/types.d.ts.map +1 -0
  154. package/build/ts/types.js +17 -0
  155. package/build/ts/types.js.map +1 -0
  156. package/build/ts/version.d.ts +2 -0
  157. package/build/ts/version.d.ts.map +1 -0
  158. package/build/ts/version.js +5 -0
  159. package/build/ts/version.js.map +1 -0
  160. package/build/tsconfig.tsbuildinfo +1 -0
  161. package/package.json +65 -0
@@ -0,0 +1,4 @@
1
+ export { cancelBillingFactory } from './cancel';
2
+ export { requireBillingFactory } from './require';
3
+ export { requestBillingFactory } from './request';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/billing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,oBAAoB,EAAC,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAC,qBAAqB,EAAC,MAAM,WAAW,CAAC;AAChD,OAAO,EAAC,qBAAqB,EAAC,MAAM,WAAW,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestBillingFactory = exports.requireBillingFactory = exports.cancelBillingFactory = void 0;
4
+ var cancel_1 = require("./cancel");
5
+ Object.defineProperty(exports, "cancelBillingFactory", { enumerable: true, get: function () { return cancel_1.cancelBillingFactory; } });
6
+ var require_1 = require("./require");
7
+ Object.defineProperty(exports, "requireBillingFactory", { enumerable: true, get: function () { return require_1.requireBillingFactory; } });
8
+ var request_1 = require("./request");
9
+ Object.defineProperty(exports, "requestBillingFactory", { enumerable: true, get: function () { return request_1.requestBillingFactory; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/billing/index.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAAtC,8GAAA,oBAAoB,OAAA;AAC5B,qCAAgD;AAAxC,gHAAA,qBAAqB,OAAA;AAC7B,qCAAgD;AAAxC,gHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,6 @@
1
+ import { Session } from '@shopify/shopify-api';
2
+ import type { BasicParams } from '../types';
3
+ import { AppConfigArg } from '../config-types';
4
+ import type { RequestBillingOptions } from './types';
5
+ export declare function requestBillingFactory<Config extends AppConfigArg>(params: BasicParams, request: Request, session: Session): ({ plan, isTest, returnUrl, }: RequestBillingOptions<Config>) => Promise<never>;
6
+ //# sourceMappingURL=request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/billing/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,OAAO,EACR,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAEnD,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,YAAY,EAC/D,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,kCAMb,sBAAsB,MAAM,CAAC,KAAG,QAAQ,KAAK,CAAC,CAqClD"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requestBillingFactory = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var shopify_api_1 = require("@shopify/shopify-api");
6
+ var server_runtime_1 = require("@remix-run/server-runtime");
7
+ var helpers_1 = require("../auth/helpers");
8
+ var redirect_with_app_bridge_headers_1 = require("../auth/helpers/redirect-with-app-bridge-headers");
9
+ function requestBillingFactory(params, request, session) {
10
+ return function requestBilling(_a) {
11
+ var plan = _a.plan, isTest = _a.isTest, returnUrl = _a.returnUrl;
12
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
13
+ var api, logger, result, error_1;
14
+ return tslib_1.__generator(this, function (_b) {
15
+ switch (_b.label) {
16
+ case 0:
17
+ api = params.api, logger = params.logger;
18
+ logger.info('Requesting billing', {
19
+ shop: session.shop,
20
+ plan: plan,
21
+ isTest: isTest,
22
+ returnUrl: returnUrl,
23
+ });
24
+ _b.label = 1;
25
+ case 1:
26
+ _b.trys.push([1, 3, , 7]);
27
+ return [4 /*yield*/, api.billing.request({
28
+ plan: plan,
29
+ session: session,
30
+ isTest: isTest,
31
+ returnUrl: returnUrl,
32
+ returnObject: true,
33
+ })];
34
+ case 2:
35
+ result = _b.sent();
36
+ return [3 /*break*/, 7];
37
+ case 3:
38
+ error_1 = _b.sent();
39
+ if (!(error_1 instanceof shopify_api_1.HttpResponseError && error_1.response.code === 401)) return [3 /*break*/, 5];
40
+ logger.debug('API token was invalid, redirecting to OAuth', {
41
+ shop: session.shop,
42
+ });
43
+ return [4 /*yield*/, (0, helpers_1.redirectToAuthPage)(params, request, session.shop)];
44
+ case 4: throw _b.sent();
45
+ case 5: throw error_1;
46
+ case 6: return [3 /*break*/, 7];
47
+ case 7: throw redirectOutOfApp(params, request, result.confirmationUrl, session.shop);
48
+ }
49
+ });
50
+ });
51
+ };
52
+ }
53
+ exports.requestBillingFactory = requestBillingFactory;
54
+ function redirectOutOfApp(params, request, url, shop) {
55
+ var config = params.config, logger = params.logger;
56
+ logger.debug('Redirecting out of app', { url: url });
57
+ var requestUrl = new URL(request.url);
58
+ var isEmbeddedRequest = requestUrl.searchParams.get('embedded') === '1';
59
+ var isXhrRequest = request.headers.get('authorization');
60
+ if (isXhrRequest) {
61
+ // eslint-disable-next-line no-warning-comments
62
+ // TODO Check this with the beta flag disabled (with the bounce page)
63
+ // Remix is not including the X-Shopify-API-Request-Failure-Reauthorize-Url when throwing a Response
64
+ // https://github.com/remix-run/remix/issues/5356
65
+ throw new Response(undefined, {
66
+ status: 401,
67
+ statusText: 'Unauthorized',
68
+ headers: (0, redirect_with_app_bridge_headers_1.getAppBridgeHeaders)(params, url, shop),
69
+ });
70
+ }
71
+ else if (isEmbeddedRequest) {
72
+ var params_1 = new URLSearchParams({
73
+ shop: shop,
74
+ host: requestUrl.searchParams.get('host'),
75
+ exitIframe: url,
76
+ });
77
+ throw (0, server_runtime_1.redirect)("".concat(config.auth.exitIframePath, "?").concat(params_1.toString()));
78
+ }
79
+ else {
80
+ // This will only ever happen for non-embedded apps, because the authenticator will stop before reaching this point
81
+ throw (0, server_runtime_1.redirect)(url);
82
+ }
83
+ }
84
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/billing/request.ts"],"names":[],"mappings":";;;;AAAA,oDAI8B;AAC9B,4DAAmD;AAGnD,2CAAmD;AAEnD,qGAAqF;AAIrF,SAAgB,qBAAqB,CACnC,MAAmB,EACnB,OAAgB,EAChB,OAAgB;IAEhB,OAAO,SAAe,cAAc,CAAC,EAIL;YAH9B,IAAI,UAAA,EACJ,MAAM,YAAA,EACN,SAAS,eAAA;;;;;;wBAEF,GAAG,GAAY,MAAM,IAAlB,EAAE,MAAM,GAAI,MAAM,OAAV,CAAW;wBAE7B,MAAM,CAAC,IAAI,CAAC,oBAAoB,EAAE;4BAChC,IA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O,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAE1D,IAAI,YAAY,EAAE;QAChB,+CAA+C;QAC/C,qEAAqE;QACrE,oGAAoG;QACpG,iDAAiD;QACjD,MAAM,IAAI,QAAQ,CAAC,SAAS,EAAE;YAC5B,MAAM,EAAE,GAAG;YACX,UAAU,EAAE,cAAc;YAC1B,OAAO,EAAE,IAAA,sDAAmB,EAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC;SAChD,CAAC,CAAC;KACJ;SAAM,IAAI,iBAAiB,EAAE;QAC5B,IAAM,QAAM,GAAG,IAAI,eAAe,CAAC;YACjC,IAAI,MAAA;YACJ,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAE;YAC1C,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC;QAEH,MAAM,IAAA,yBAAQ,EAAC,UAAG,MAAM,CAAC,IAAI,CAAC,cAAc,cAAI,QAAM,CAAC,QAAQ,EAAE,CAAE,CAAC,CAAC;KACtE;SAAM;QACL,mHAAmH;QACnH,MAAM,IAAA,yBAAQ,EAAC,GAAG,CAAC,CAAC;KACrB;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { BillingCheckResponseObject, Session } from '@shopify/shopify-api';
2
+ import type { BasicParams } from '../types';
3
+ import type { AppConfigArg } from '../config-types';
4
+ import type { RequireBillingOptions } from './types';
5
+ export declare function requireBillingFactory<Config extends AppConfigArg>(params: BasicParams, request: Request, session: Session): (options: RequireBillingOptions<Config>) => Promise<BillingCheckResponseObject>;
6
+ //# sourceMappingURL=require.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require.d.ts","sourceRoot":"","sources":["../../../src/billing/require.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAE1B,OAAO,EACR,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAGlD,OAAO,KAAK,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAEnD,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,YAAY,EAC/D,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,aAI8B,sBAAsB,MAAM,CAAC,yCAmC5E"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requireBillingFactory = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var shopify_api_1 = require("@shopify/shopify-api");
6
+ var helpers_1 = require("../auth/helpers");
7
+ function requireBillingFactory(params, request, session) {
8
+ var api = params.api, logger = params.logger;
9
+ return function requireBilling(options) {
10
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
11
+ var logContext, data, error_1;
12
+ return tslib_1.__generator(this, function (_a) {
13
+ switch (_a.label) {
14
+ case 0:
15
+ logContext = {
16
+ shop: session.shop,
17
+ plans: options.plans,
18
+ isTest: options.isTest,
19
+ };
20
+ logger.debug('Checking billing for the shop', logContext);
21
+ _a.label = 1;
22
+ case 1:
23
+ _a.trys.push([1, 3, , 7]);
24
+ return [4 /*yield*/, api.billing.check({
25
+ session: session,
26
+ plans: options.plans,
27
+ isTest: options.isTest,
28
+ returnObject: true,
29
+ })];
30
+ case 2:
31
+ data = _a.sent();
32
+ return [3 /*break*/, 7];
33
+ case 3:
34
+ error_1 = _a.sent();
35
+ if (!(error_1 instanceof shopify_api_1.HttpResponseError && error_1.response.code === 401)) return [3 /*break*/, 5];
36
+ logger.debug('API token was invalid, redirecting to OAuth', logContext);
37
+ return [4 /*yield*/, (0, helpers_1.redirectToAuthPage)(params, request, session.shop)];
38
+ case 4: throw _a.sent();
39
+ case 5: throw error_1;
40
+ case 6: return [3 /*break*/, 7];
41
+ case 7:
42
+ if (!!data.hasActivePayment) return [3 /*break*/, 9];
43
+ logger.debug('Billing check failed', logContext);
44
+ return [4 /*yield*/, options.onFailure(new Error('Billing check failed'))];
45
+ case 8: throw _a.sent();
46
+ case 9:
47
+ logger.debug('Billing check succeeded', logContext);
48
+ return [2 /*return*/, data];
49
+ }
50
+ });
51
+ });
52
+ };
53
+ }
54
+ exports.requireBillingFactory = requireBillingFactory;
55
+ //# sourceMappingURL=require.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"require.js","sourceRoot":"","sources":["../../../src/billing/require.ts"],"names":[],"mappings":";;;;AAAA,oDAI8B;AAI9B,2CAAmD;AAInD,SAAgB,qBAAqB,CACnC,MAAmB,EACnB,OAAgB,EAChB,OAAgB;IAET,IAAA,GAAG,GAAY,MAAM,IAAlB,EAAE,MAAM,GAAI,MAAM,OAAV,CAAW;IAE7B,OAAO,SAAe,cAAc,CAAC,OAAsC;;;;;;wBACnE,UAAU,GAAG;4BACjB,IAAI,EAAE,OAAO,CAAC,IAAI;4BAClB,KAAK,EAAE,OAAO,CAAC,KAAK;4BACpB,MAAM,EAAE,OAAO,CAAC,MAAM;yBACvB,CAAC;wBAEF,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,UAAU,CAAC,CAAC;;;;wBAIjD,qBAAM,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;gCAC7B,OAAO,SAAA;gCACP,KAAK,EAAE,OAAO,CAAC,KAAiB;gCAChC,MAAM,EAAE,OAAO,CAAC,MAAM;gCACtB,YAAY,EAAE,IAAI;6BACnB,CAAC,EAAA;;wBALF,IAAI,GAAG,SAKL,CAAC;;;;6BAEC,CAAA,OAAK,YAAY,+BAAiB,IAAI,OAAK,CAAC,QAAQ,CAAC,IAAI,KAAK,GAAG,CAAA,EAAjE,wBAAiE;wBACnE,MAAM,CAAC,KAAK,CAAC,6CAA6C,EAAE,UAAU,CAAC,CAAC;wBAClE,qBAAM,IAAA,4BAAkB,EAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,EAAA;4BAA7D,MAAM,SAAuD,CAAC;4BAE9D,MAAM,OAAK,CAAC;;;6BAIZ,CAAC,IAAI,CAAC,gBAAgB,EAAtB,wBAAsB;wBACxB,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,UAAU,CAAC,CAAC;wBAC3C,qBAAM,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,EAAA;4BAAhE,MAAM,SAA0D,CAAC;;wBAGnE,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,UAAU,CAAC,CAAC;wBAEpD,sBAAO,IAAI,EAAC;;;;KACb,CAAC;AACJ,CAAC;AA1CD,sDA0CC"}
@@ -0,0 +1,228 @@
1
+ import { AppSubscription, BillingCheckParams, BillingCheckResponseObject, BillingRequestParams } from '@shopify/shopify-api';
2
+ import type { AppConfigArg } from '../config-types';
3
+ export interface RequireBillingOptions<Config extends AppConfigArg> extends Omit<BillingCheckParams, 'session' | 'plans' | 'returnObject'> {
4
+ /**
5
+ * The plans to check for. Must be one of the values defined in the `billing` config option.
6
+ */
7
+ plans: (keyof Config['billing'])[];
8
+ /**
9
+ * How to handle the request if the shop does not have an active payment for any of the given plans.
10
+ */
11
+ onFailure: (error: any) => Promise<Response>;
12
+ }
13
+ export interface RequestBillingOptions<Config extends AppConfigArg> extends Omit<BillingRequestParams, 'session' | 'plan' | 'returnObject'> {
14
+ /**
15
+ * The plan to request. Must be one of the values defined in the `billing` config option.
16
+ */
17
+ plan: keyof Config['billing'];
18
+ }
19
+ export interface CancelBillingOptions {
20
+ /**
21
+ * The ID of the subscription to cancel.
22
+ */
23
+ subscriptionId: string;
24
+ /**
25
+ * Whether to prorate the cancellation.
26
+ *
27
+ * {@link https://shopify.dev/docs/apps/billing/subscriptions/cancel-recurring-charges}
28
+ */
29
+ prorate?: boolean;
30
+ isTest?: boolean;
31
+ }
32
+ export interface BillingContext<Config extends AppConfigArg> {
33
+ /**
34
+ * Checks if the shop has an active payment for any the given plans defined in the `billing` config option.
35
+ *
36
+ * @returns A promise that resolves to an object containing the active purchases for the shop.
37
+ *
38
+ * @example
39
+ * Requesting billing right away
40
+ * ```ts
41
+ * // shopify.server.ts
42
+ * import { shopifyApp, BillingInterval } from "@shopify/shopify-app-remix";
43
+ *
44
+ * export const MONTHLY_PLAN = 'Monthly subscription';
45
+ * export const ANNUAL_PLAN = 'Annual subscription';
46
+ *
47
+ * export const shopify = shopifyApp({
48
+ * // ...etc
49
+ * billing: {
50
+ * [MONTHLY_PLAN]: {
51
+ * amount: 5,
52
+ * currencyCode: 'USD',
53
+ * interval: BillingInterval.Every30Days,
54
+ * },
55
+ * [ANNUAL_PLAN]: {
56
+ * amount: 50,
57
+ * currencyCode: 'USD',
58
+ * interval: BillingInterval.Annual,
59
+ * },
60
+ * }
61
+ * });
62
+ *
63
+ * // app/routes/**\/.ts
64
+ * import { LoaderArgs } from "@remix-run/node";
65
+ * import { shopify, MONTHLY_PLAN } from "../shopify.server";
66
+ *
67
+ * export const loader = async ({ request }: LoaderArgs) => {
68
+ * const { billing } = await shopify.authenticate.admin(request);
69
+ * await billing.require({
70
+ * plans: [MONTHLY_PLAN],
71
+ * isTest: true,
72
+ * onFailure: async () => billing.request({ plan: MONTHLY_PLAN }),
73
+ * });
74
+ *
75
+ * // App logic
76
+ * };
77
+ * ```
78
+ *
79
+ * @example
80
+ * Redirecting to a page where the merchant can select a plan
81
+ * ```ts
82
+ * // shopify.server.ts
83
+ * import { shopifyApp, BillingInterval } from "@shopify/shopify-app-remix";
84
+ *
85
+ * export const MONTHLY_PLAN = 'Monthly subscription';
86
+ * export const ANNUAL_PLAN = 'Annual subscription';
87
+ *
88
+ * export const shopify = shopifyApp({
89
+ * // ...etc
90
+ * billing: {
91
+ * [MONTHLY_PLAN]: {
92
+ * amount: 5,
93
+ * currencyCode: 'USD',
94
+ * interval: BillingInterval.Every30Days,
95
+ * },
96
+ * [ANNUAL_PLAN]: {
97
+ * amount: 50,
98
+ * currencyCode: 'USD',
99
+ * interval: BillingInterval.Annual,
100
+ * },
101
+ * }
102
+ * });
103
+ *
104
+ * // app/routes/**\/.ts
105
+ * import { LoaderArgs, redirect } from "@remix-run/node";
106
+ * import { shopify, MONTHLY_PLAN, ANNUAL_PLAN } from "../shopify.server";
107
+ *
108
+ * export const loader = async ({ request }: LoaderArgs) => {
109
+ * const { billing } = await shopify.authenticate.admin(request);
110
+ * const billingCheck = await billing.require({
111
+ * plans: [MONTHLY_PLAN, ANNUAL_PLAN],
112
+ * isTest: true,
113
+ * onFailure: () => redirect('/select-plan'),
114
+ * });
115
+ *
116
+ * const subscription = billingCheck.appSubscriptions[0];
117
+ * console.log(`Shop is on ${subscription.name} (id ${subscription.id})`);
118
+ *
119
+ * // App logic
120
+ * };
121
+ * ```
122
+ */
123
+ require: (options: RequireBillingOptions<Config>) => Promise<BillingCheckResponseObject>;
124
+ /**
125
+ * Requests payment for the given plan.
126
+ *
127
+ * @returns Redirects to the confirmation URL for the payment.
128
+ *
129
+ * @example
130
+ * Requesting billing when there is no payment with a custom return URL
131
+ * ```ts
132
+ * // shopify.server.ts
133
+ * import { shopifyApp, BillingInterval } from "@shopify/shopify-app-remix";
134
+ *
135
+ * export const MONTHLY_PLAN = 'Monthly subscription';
136
+ * export const ANNUAL_PLAN = 'Annual subscription';
137
+ *
138
+ * export const shopify = shopifyApp({
139
+ * // ...etc
140
+ * billing: {
141
+ * [MONTHLY_PLAN]: {
142
+ * amount: 5,
143
+ * currencyCode: 'USD',
144
+ * interval: BillingInterval.Every30Days,
145
+ * },
146
+ * [ANNUAL_PLAN]: {
147
+ * amount: 50,
148
+ * currencyCode: 'USD',
149
+ * interval: BillingInterval.Annual,
150
+ * },
151
+ * }
152
+ * });
153
+ *
154
+ * // app/routes/**\/.ts
155
+ * import { LoaderArgs } from "@remix-run/node";
156
+ * import { shopify, MONTHLY_PLAN } from "../shopify.server";
157
+ *
158
+ * export const loader = async ({ request }: LoaderArgs) => {
159
+ * const { billing } = await shopify.authenticate.admin(request);
160
+ * await billing.require({
161
+ * plans: [MONTHLY_PLAN],
162
+ * onFailure: async () => billing.request({
163
+ * plan: MONTHLY_PLAN,
164
+ * isTest: true,
165
+ * returnUrl: '/billing-complete',
166
+ * }),
167
+ * });
168
+ *
169
+ * // App logic
170
+ * };
171
+ * ```
172
+ */
173
+ request: (options: RequestBillingOptions<Config>) => Promise<never>;
174
+ /**
175
+ * Cancels an ongoing subscription, given its id.
176
+ *
177
+ * @returns The cancelled subscription.
178
+ *
179
+ * @example
180
+ * Cancelling a subscription
181
+ * ```ts
182
+ * // shopify.server.ts
183
+ * import { shopifyApp, BillingInterval } from "@shopify/shopify-app-remix";
184
+ *
185
+ * export const MONTHLY_PLAN = 'Monthly subscription';
186
+ * export const ANNUAL_PLAN = 'Annual subscription';
187
+ *
188
+ * export const shopify = shopifyApp({
189
+ * // ...etc
190
+ * billing: {
191
+ * [MONTHLY_PLAN]: {
192
+ * amount: 5,
193
+ * currencyCode: 'USD',
194
+ * interval: BillingInterval.Every30Days,
195
+ * },
196
+ * [ANNUAL_PLAN]: {
197
+ * amount: 50,
198
+ * currencyCode: 'USD',
199
+ * interval: BillingInterval.Annual,
200
+ * },
201
+ * }
202
+ * });
203
+ *
204
+ * // app/routes/cancel-subscription.ts
205
+ * import { LoaderArgs } from "@remix-run/node";
206
+ * import { shopify, MONTHLY_PLAN } from "../shopify.server";
207
+ *
208
+ * export const loader = async ({ request }: LoaderArgs) => {
209
+ * const { billing } = await shopify.authenticate.admin(request);
210
+ * const billingCheck = await billing.require({
211
+ * plans: [MONTHLY_PLAN],
212
+ * onFailure: async () => billing.request({ plan: MONTHLY_PLAN }),
213
+ * });
214
+ *
215
+ * const subscription = billingCheck.appSubscriptions[0];
216
+ * const cancelledSubscription = await billing.cancel({
217
+ * subscriptionId: subscription.id,
218
+ * isTest: true,
219
+ * prorate: true,
220
+ * });
221
+ *
222
+ * // App logic
223
+ * };
224
+ * ```
225
+ */
226
+ cancel: (options: CancelBillingOptions) => Promise<AppSubscription>;
227
+ }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;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgDG;IACH,OAAO,EAAE,CAAC,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IAEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmDG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;CACrE"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/billing/types.ts"],"names":[],"mappings":""}