@agnostack/next-shopify 1.1.0-alpha.1 → 1.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [1.1.0-alpha.3](https://github.com/agnostack/next-shopify/compare/v1.1.0-alpha.2...v1.1.0-alpha.3) (2022-11-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * split out helper methods ([8148682](https://github.com/agnostack/next-shopify/commit/8148682f3ee940948cf01521b1428a994880c515))
7
+
8
+ # [1.1.0-alpha.2](https://github.com/agnostack/next-shopify/compare/v1.1.0-alpha.1...v1.1.0-alpha.2) (2022-11-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * small refactor on apiHandlers ([fc9315d](https://github.com/agnostack/next-shopify/commit/fc9315d4de6c69096399ae1573f8bc2d4982dffe))
14
+
1
15
  # [1.1.0-alpha.1](https://github.com/agnostack/next-shopify/compare/v1.0.1-alpha.1...v1.1.0-alpha.1) (2022-11-07)
2
16
 
3
17
 
@@ -0,0 +1,3 @@
1
+ export function handleAuth(props: any): (req: any, res: any) => Promise<any>;
2
+ export function handleCallback(props: any): (req: any, res: any) => Promise<any>;
3
+ export function handleAppUninstalled(_props: any): (shop: any) => Promise<boolean>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleAppUninstalled = exports.handleCallback = exports.handleAuth = void 0;
4
+ // NOTE: api routes do NOT work in `next export`
5
+ const utils_1 = require("./utils");
6
+ // NOTE: typically handling: "/api/auth"
7
+ const handleAuth = (props) => async (req, res) => {
8
+ const { PAGE_PATHS } = props;
9
+ const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_auth_response`, } = await utils_1.authHelper(Object.assign({ req, res }, props));
10
+ if (statusCode >= 300 && statusCode < 400) {
11
+ return res.redirect(statusCode, redirectUrl);
12
+ }
13
+ return res.send(statusCode).send(message);
14
+ };
15
+ exports.handleAuth = handleAuth;
16
+ // NOTE: typically handling: "/api/auth/callback"
17
+ const handleCallback = (props) => async (req, res) => {
18
+ const { PAGE_PATHS } = props;
19
+ const { message, statusCode = 302, redirectUrl = `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?invalid_callback_response`, } = await utils_1.callbackHelper(Object.assign({ req, res }, props));
20
+ if (statusCode >= 300 && statusCode < 400) {
21
+ return res.redirect(statusCode, redirectUrl);
22
+ }
23
+ return res.send(statusCode).send(message);
24
+ };
25
+ exports.handleCallback = handleCallback;
26
+ // NOTE: typically handling: "/api/webhooks/app/uninstalled"
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ const handleAppUninstalled = (_props) => async (shop) => {
29
+ var _a, _b, _c, _d;
30
+ const shopify = utils_1.getInitializedShopify(shop);
31
+ 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, shop));
32
+ if (utils_1.arrayNotEmpty(existingSessions)) {
33
+ 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)));
34
+ }
35
+ return true;
36
+ };
37
+ exports.handleAppUninstalled = handleAppUninstalled;
38
+ //# sourceMappingURL=apiHandlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiHandlers.js","sourceRoot":"","sources":["../src/apiHandlers.js"],"names":[],"mappings":";;;AAAA,gDAAgD;AAChD,mCAMgB;AAEhB,wCAAwC;AACjC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACtD,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAA;IAC5B,MAA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,CAAA;IAE3C,MAAM,gBAAgB,GAAG,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,kBAAkB,mDAAG,IAAI,CAAC,CAAA,CAAA;IAC1F,IAAI,qBAAa,CAAC,gBAAgB,CAAC,EAAE;QACnC,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;KACvG;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AATY,QAAA,oBAAoB,wBAShC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './handlers';
1
+ export * from './apiHandlers';
2
2
  export * from './protectRoute';
3
3
  export * from './withShopify';
package/dist/index.js CHANGED
@@ -10,7 +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("./handlers"), exports);
13
+ __exportStar(require("./apiHandlers"), exports);
14
14
  __exportStar(require("./protectRoute"), exports);
15
15
  __exportStar(require("./withShopify"), exports);
16
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,6CAA0B;AAC1B,iDAA8B;AAC9B,gDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA6B;AAC7B,iDAA8B;AAC9B,gDAA6B"}
@@ -0,0 +1,26 @@
1
+ export function authHelper({ req, res, ...props }: {
2
+ [x: string]: any;
3
+ req: any;
4
+ res: any;
5
+ }): Promise<{
6
+ statusCode: number;
7
+ redirectUrl: string;
8
+ message?: undefined;
9
+ } | {
10
+ statusCode: number;
11
+ message: string;
12
+ redirectUrl?: undefined;
13
+ }>;
14
+ export function callbackHelper({ req, res, ...props }: {
15
+ [x: string]: any;
16
+ req: any;
17
+ res: any;
18
+ }): Promise<{
19
+ statusCode: number;
20
+ redirectUrl: string;
21
+ message?: undefined;
22
+ } | {
23
+ statusCode: number;
24
+ message: string;
25
+ redirectUrl?: undefined;
26
+ }>;
@@ -0,0 +1,94 @@
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
+ exports.callbackHelper = exports.authHelper = void 0;
15
+ const shopify_1 = require("./shopify");
16
+ const authHelper = async (_a) => {
17
+ var { req, res } = _a, props = __rest(_a, ["req", "res"]);
18
+ const { query } = req;
19
+ const { shop } = query !== null && query !== void 0 ? query : {};
20
+ try {
21
+ return {
22
+ statusCode: 302,
23
+ redirectUrl: shopify_1.getRedirectUrl(props, {
24
+ req,
25
+ res,
26
+ query,
27
+ shop,
28
+ }),
29
+ };
30
+ }
31
+ catch (error) {
32
+ const errorMessage = 'Error handling auth route';
33
+ console.error(errorMessage, error);
34
+ return {
35
+ statusCode: 500,
36
+ message: errorMessage,
37
+ };
38
+ }
39
+ };
40
+ exports.authHelper = authHelper;
41
+ const callbackHelper = async (_a) => {
42
+ var { req, res } = _a, props = __rest(_a, ["req", "res"]);
43
+ const { PAGE_PATHS, APP_WEBHOOKS } = props;
44
+ const { shop, host } = req.query;
45
+ if (!shop || !host) {
46
+ return {
47
+ statusCode: 303,
48
+ redirectUrl: `${PAGE_PATHS[shopify_1.PAGE_ROUTE_NAMES.ERROR]}?code=invalid_callback`,
49
+ };
50
+ }
51
+ const shopify = shopify_1.getInitializedShopify(props, shop);
52
+ try {
53
+ const session = await shopify.Auth.validateAuthCallback(req, res, req.query);
54
+ await shopify_1.registerWebhooks(props, APP_WEBHOOKS, session);
55
+ // TODO check for billing redirect
56
+ const redirectUrl = shopify.Utils.getEmbeddedAppUrl(req);
57
+ return {
58
+ statusCode: 302,
59
+ redirectUrl: `${redirectUrl}?${new URLSearchParams(req.query).toString()}`,
60
+ };
61
+ }
62
+ catch (error) {
63
+ const errorMessage = 'Error handling callback route';
64
+ console.error(errorMessage, error);
65
+ switch (true) {
66
+ case error instanceof shopify.Errors.InvalidOAuthError: {
67
+ return {
68
+ statusCode: 400,
69
+ message: errorMessage,
70
+ };
71
+ }
72
+ case error instanceof shopify.Errors.CookieNotFound:
73
+ case error instanceof shopify.Errors.SessionNotFound: {
74
+ return {
75
+ statusCode: 302,
76
+ redirectUrl: shopify_1.getRedirectUrl(props, {
77
+ req,
78
+ res,
79
+ shop,
80
+ query: req.query,
81
+ }),
82
+ };
83
+ }
84
+ default: {
85
+ return {
86
+ statusCode: 500,
87
+ message: errorMessage,
88
+ };
89
+ }
90
+ }
91
+ }
92
+ };
93
+ exports.callbackHelper = callbackHelper;
94
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.js"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,uCAKkB;AAEX,MAAM,UAAU,GAAG,KAAK,EAAE,EAAsB,EAAE,EAAE;QAA1B,EAAE,GAAG,EAAE,GAAG,OAAY,EAAP,KAAK,cAApB,cAAsB,CAAF;IACnD,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IACrB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AAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAExD,OAAO;YACL,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,GAAG,WAAW,IAAI,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,EAAE;SAC3E,CAAA;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,+BAA+B,CAAA;QACpD,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAA;QAElC,QAAQ,IAAI,EAAE;YACZ,KAAK,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;gBACtD,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;YAED,KAAK,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;YACpD,KAAK,KAAK,YAAY,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;gBACpD,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,WAAW,EAAE,wBAAc,CAAC,KAAK,EAAE;wBACjC,GAAG;wBACH,GAAG;wBACH,IAAI;wBACJ,KAAK,EAAE,GAAG,CAAC,KAAK;qBACjB,CAAC;iBACH,CAAA;aACF;YAED,OAAO,CAAC,CAAC;gBACP,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;SACF;KACF;AACH,CAAC,CAAA;AA3DY,QAAA,cAAc,kBA2D1B"}
@@ -1,3 +1,4 @@
1
+ export * from "./helpers";
1
2
  export * from "./display";
2
3
  export * from "./firebase";
3
4
  export * from "./shopify";
@@ -10,6 +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("./helpers"), exports);
13
14
  __exportStar(require("./display"), exports);
14
15
  __exportStar(require("./firebase"), exports);
15
16
  __exportStar(require("./shopify"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,6CAA0B;AAC1B,4CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAAyB;AACzB,4CAAyB;AACzB,6CAA0B;AAC1B,4CAAyB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agnostack/next-shopify",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.1.0-alpha.3",
4
4
  "author": "agnoStack Dev <developers@agnostack.com> (https://agnostack.com)",
5
5
  "owner": "agnoStack",
6
6
  "description": "Please contact agnoStack via info@agnostack.com for any questions",
@@ -1 +0,0 @@
1
- export function handleAppUninstalled(_props: any): (shop: any) => Promise<boolean>;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleAppUninstalled = void 0;
4
- // NOTE: typically handling: "/api/webhooks/app/uninstalled"
5
- const utils_1 = require("../utils");
6
- // NOTE /api/webhooks/app/uninstalled
7
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
8
- const handleAppUninstalled = (_props) => async (shop) => {
9
- var _a, _b, _c, _d;
10
- const shopify = utils_1.getInitializedShopify(shop);
11
- 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, shop));
12
- if (utils_1.arrayNotEmpty(existingSessions)) {
13
- 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)));
14
- }
15
- return true;
16
- };
17
- exports.handleAppUninstalled = handleAppUninstalled;
18
- //# sourceMappingURL=appUninstalledHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appUninstalledHandler.js","sourceRoot":"","sources":["../../src/handlers/appUninstalledHandler.js"],"names":[],"mappings":";;;AAAA,4DAA4D;AAC5D,oCAGiB;AAEjB,qCAAqC;AACrC,6DAA6D;AACtD,MAAM,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;;IAC7D,MAAM,OAAO,GAAG,6BAAqB,CAAC,IAAI,CAAC,CAAA;IAE3C,MAAM,gBAAgB,GAAG,MAAM,CAAA,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,eAAe,0CAAE,kBAAkB,mDAAG,IAAI,CAAC,CAAA,CAAA;IAC1F,IAAI,qBAAa,CAAC,gBAAgB,CAAC,EAAE;QACnC,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;KACvG;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AATY,QAAA,oBAAoB,wBAShC"}
@@ -1,9 +0,0 @@
1
- export function handleCallback(props: any): (req: any, res: any) => Promise<{
2
- statusCode: number;
3
- redirectUrl: string;
4
- message?: undefined;
5
- } | {
6
- statusCode: number;
7
- message: string;
8
- redirectUrl?: undefined;
9
- }>;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleCallback = void 0;
4
- // NOTE: typically handling: "/api/auth/callback"
5
- const utils_1 = require("../utils");
6
- // NOTE: api routes do NOT work in `next export`
7
- const handleCallback = (props) => async (req, res) => {
8
- const { PAGE_PATHS, APP_WEBHOOKS } = props;
9
- const { shop, host } = req.query;
10
- if (!shop || !host) {
11
- return {
12
- statusCode: 303,
13
- redirectUrl: `${PAGE_PATHS[utils_1.PAGE_ROUTE_NAMES.ERROR]}?code=invalid_callback`,
14
- };
15
- }
16
- const shopify = utils_1.getInitializedShopify(props, shop);
17
- try {
18
- const session = await shopify.Auth.validateAuthCallback(req, res, req.query);
19
- await utils_1.registerWebhooks(props, APP_WEBHOOKS, session);
20
- // TODO check for billing redirect
21
- const redirectUrl = shopify.Utils.getEmbeddedAppUrl(req);
22
- return {
23
- statusCode: 302,
24
- redirectUrl: `${redirectUrl}?${new URLSearchParams(req.query).toString()}`,
25
- };
26
- }
27
- catch (error) {
28
- const errorMessage = 'Error handling callback route';
29
- console.error(errorMessage, error);
30
- switch (true) {
31
- case error instanceof shopify.Errors.InvalidOAuthError: {
32
- return {
33
- statusCode: 400,
34
- message: errorMessage,
35
- };
36
- }
37
- case error instanceof shopify.Errors.CookieNotFound:
38
- case error instanceof shopify.Errors.SessionNotFound: {
39
- return {
40
- statusCode: 302,
41
- redirectUrl: utils_1.getRedirectUrl(props, {
42
- req,
43
- res,
44
- shop,
45
- query: req.query,
46
- }),
47
- };
48
- }
49
- default: {
50
- return {
51
- statusCode: 500,
52
- message: errorMessage,
53
- };
54
- }
55
- }
56
- }
57
- };
58
- exports.handleCallback = handleCallback;
59
- //# sourceMappingURL=authCallbackHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authCallbackHandler.js","sourceRoot":"","sources":["../../src/handlers/authCallbackHandler.js"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,oCAKiB;AAEjB,gDAAgD;AACzC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IAC1D,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,KAAK,CAAA;IAC1C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAA;IAEhC,IAAI,CA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AE,GAAG,CAAC,KAAK;qBACjB,CAAC;iBACH,CAAA;aACF;YAED,OAAO,CAAC,CAAC;gBACP,OAAO;oBACL,UAAU,EAAE,GAAG;oBACf,OAAO,EAAE,YAAY;iBACtB,CAAA;aACF;SACF;KACF;AACH,CAAC,CAAA;AA3DY,QAAA,cAAc,kBA2D1B"}
@@ -1,9 +0,0 @@
1
- export function handleAuth(props: any): (req: any, res: any) => Promise<{
2
- statusCode: number;
3
- redirectUrl: string;
4
- message?: undefined;
5
- } | {
6
- statusCode: number;
7
- message: string;
8
- redirectUrl?: undefined;
9
- }>;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleAuth = void 0;
4
- // NOTE: typically handling: "/api/auth"
5
- const utils_1 = require("../utils");
6
- // NOTE: api routes do NOT work in `next export`
7
- const handleAuth = (props) => async (req, res) => {
8
- const { query } = req;
9
- const { shop } = query !== null && query !== void 0 ? query : {};
10
- try {
11
- return {
12
- statusCode: 302,
13
- redirectUrl: utils_1.getRedirectUrl(props, {
14
- req,
15
- res,
16
- query,
17
- shop,
18
- }),
19
- };
20
- }
21
- catch (error) {
22
- const errorMessage = 'Error handling auth route';
23
- console.error(errorMessage, error);
24
- return {
25
- statusCode: 500,
26
- message: errorMessage,
27
- };
28
- }
29
- };
30
- exports.handleAuth = handleAuth;
31
- //# sourceMappingURL=authHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authHandler.js","sourceRoot":"","sources":["../../src/handlers/authHandler.js"],"names":[],"mappings":";;;AAAA,wCAAwC;AACxC,oCAAyC;AAEzC,gDAAgD;AACzC,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;IACtD,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAA;IACrB,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAA;IAE5B,IAAI;QACF,OAAO;YACL,UAAU,EAAE,GAAG;YACf,WAAW,EAAE,sBAAc,CAAC,KAAK,EAAE;gBACjC,GAAG;gBACH,GAAG;gBACH,KAAK;gBACL,IAAI;aACL,CAAC;SACH,CAAA;KACF;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,2BAA2B,CAAA;QAChD,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;AAvBY,QAAA,UAAU,cAuBtB"}
@@ -1,3 +0,0 @@
1
- export * from "./appUninstalledHandler";
2
- export * from "./authCallbackHandler";
3
- export * from "./authHandler";
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./appUninstalledHandler"), exports);
14
- __exportStar(require("./authCallbackHandler"), exports);
15
- __exportStar(require("./authHandler"), exports);
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handlers/index.js"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAuC;AACvC,wDAAqC;AACrC,gDAA6B"}