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Q,GAAQ,YACrF,IAAK,EACD,MAAM,IAAI,MAAM,wCAEpB,MAAM,EAAM,KAAK,gBACX,aAAmC,EAAS,EAAK,+BAC/C,iBAAiB,sBACnB,QAAgB,QAAQ,KAAK,CAC/B,MACA,KAAM,CACF,MAAO,KAGT,QAAoB,EAAQ,OAClC,IAAK,GAAqC,GAAtB,EAAY,OAC5B,MAAM,IAAI,MAAM,iDAEpB,OAAO,CACX,IASA,KAAK,4BAA+B,GAAS,UAAU,UAAM,OAAQ,GAAQ,YACzE,eACA,MAAM,EAAoB,IAAI,gBAAgB,OAAO,SAAS,QAAQ,IAAI,QAC1E,aAAa,KAAK,qBAAqB,EAAmB,EAC9D,IACA,KAAK,cAAgB,EAAM,aAC/B,EAMJ,MAAM,aAAe,KACjB,GAAsB,oBAAX,OACP,MAAM,IAAI,MAAM,8DACpB","file":"/npm/@nylas/nylas-js@0.2.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@nylas/nylas-js@0.2.0/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n    return new (P || (P = Promise))(function (resolve, reject) {\n        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n        function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n        step((generator = generator.apply(thisArg, _arguments || [])).next());\n    });\n};\nimport Request from './request';\nvar DefaultEndpoints;\n(function (DefaultEndpoints) {\n    DefaultEndpoints[\"buildAuthUrl\"] = \"/nylas/generate-auth-url\";\n    DefaultEndpoints[\"exchangeCodeForToken\"] = \"/nylas/exchange-mailbox-token\";\n})(DefaultEndpoints || (DefaultEndpoints = {}));\nexport default class Nylas {\n    constructor(props) {\n        /**\n         * Builds the URL for authenticating users to your application via Hosted Authentication\n         * @param opts Configuration for building the URL\n         * @return URL for authentication\n         * @throws If the HTTP response code is non 2xx\n         * @throws If the server doesn't respond with a URL\n         */\n        this.buildAuthUrl = (opts) => __awaiter(this, void 0, void 0, function* () {\n            const url = this.serverBaseUrl +\n                (opts.buildAuthUrlEndpoint || DefaultEndpoints.buildAuthUrl);\n            const rawResp = yield Request.post({\n                url,\n                body: {\n                    email_address: opts.emailAddress,\n                    success_url: opts.successRedirectUrl,\n                },\n            });\n            const authUrl = yield rawResp.text();\n            if (!authUrl || authUrl.length == 0) {\n                throw new Error('No auth URL was returned from the server.');\n            }\n            return authUrl;\n        });\n        /**\n         * Builds and redirects to the URL for authenticating users to your application via Hosted Authentication\n         * @param opts Configuration for building the URL\n         * @throws If window is not defined\n         * @throws If the HTTP response code is non 2xx\n         * @throws If the server doesn't respond with a URL\n         */\n        this.authWithRedirect = (opts) => __awaiter(this, void 0, void 0, function* () {\n            browserCheck();\n            window.location.href = yield this.buildAuthUrl(opts);\n        });\n        /**\n         * Exchange the Nylas authorization code for a Nylas access token\n         * @param authorizationCode Nylas authorization code\n         * @param opts Configuration for the token exchange\n         * @throws If no authorization code was provided\n         * @throws If the HTTP response code is non 2xx\n         * @throws If the server doesn't respond with an access token\n         */\n        this.exchangeCodeForToken = (authorizationCode, opts) => __awaiter(this, void 0, void 0, function* () {\n            if (!authorizationCode) {\n                throw new Error('No valid authorization code detected');\n            }\n            const url = this.serverBaseUrl +\n                ((opts === null || opts === void 0 ? void 0 : opts.exchangeCodeForTokenEndpoint) ||\n                    DefaultEndpoints.exchangeCodeForToken);\n            const rawResp = yield Request.post({\n                url,\n                body: {\n                    token: authorizationCode,\n                },\n            });\n            const accessToken = yield rawResp.text();\n            if (!accessToken || accessToken.length == 0) {\n                throw new Error('No access token was returned from the server.');\n            }\n            return accessToken;\n        });\n        /**\n         * Parses the URL for the Nylas authorization code for a Nylas access token\n         * @param opts Configuration for the token exchange\n         * @throws If window is not defined\n         * @throws If no authorization code was provided\n         * @throws If the HTTP response code is non 2xx\n         * @throws If the server doesn't respond with an access token\n         */\n        this.exchangeCodeFromUrlForToken = (opts) => __awaiter(this, void 0, void 0, function* () {\n            browserCheck();\n            const authorizationCode = new URLSearchParams(window.location.search).get('code');\n            return yield this.exchangeCodeForToken(authorizationCode, opts);\n        });\n        this.serverBaseUrl = props.serverBaseUrl;\n    }\n}\n/**\n * Simple browser check\n * @throws If window is not defined\n */\nconst browserCheck = () => {\n    if (typeof window === 'undefined') {\n        throw new Error('You are trying to use a browser function without a browser.');\n    }\n};\n"]}