diff --git a/lib/bundle.js b/lib/bundle.js index d91af96..ebfaf6b 100644 --- a/lib/bundle.js +++ b/lib/bundle.js @@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */function n(e,n,t,i){return new(t||(t=Promise))((function(o,r){function d(e){try{s(i.next(e))}catch(e){r(e)}}function c(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(d,c)}s((i=i.apply(e,n||[])).next())}))}let t=(e,i,o)=>n(void 0,void 0,void 0,(function*(){let r={responseCode:400};try{const d={"x-web-sdk-launcher-version":"3.0.0"},c=new URL(`${e}/sdk/v2/script-link`);i&&c.searchParams.append("flowName",i),o&&c.searchParams.append("experimentalKey",o),r=yield fetch(c.toString(),{headers:d}).then((e=>e.json())),r.scriptLink&&(t=()=>n(void 0,void 0,void 0,(function*(){return r})))}catch(e){console.error(e)}return r}));e.createPublicTokenProvider=(e,t)=>()=>n(void 0,void 0,void 0,(function*(){if(!e)throw new Error("Missing api url");if(!t)throw new Error("Missing api key");return(yield fetch(`${e}/sdk/v2/token`,{method:"POST",body:JSON.stringify({}),headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*","x-sdk-key":t}})).json()})),e.init=function(e){return new Promise(((n,i)=>{t(e.apiUrl,e.flowName,e.experimentalKey).then((({scriptLink:t="https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js"})=>{const o=document.createElement("script");o.setAttribute("async",""),o.src=t,document.getElementsByTagName("body")[0].appendChild(o),o.onload=()=>{window.getidWebSdk&&window.getidWebSdk.init(e).then((e=>n(e))).catch((e=>i(e)))},o.onerror=e=>i(e)})).catch((e=>{console.log(e),i(e)}))}))},Object.defineProperty(e,"__esModule",{value:!0})})); \ No newline at end of file +***************************************************************************** */function n(e,n,t,i){return new(t||(t=Promise))((function(o,r){function d(e){try{s(i.next(e))}catch(e){r(e)}}function c(e){try{s(i.throw(e))}catch(e){r(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(d,c)}s((i=i.apply(e,n||[])).next())}))}let t=(e,i,o)=>n(void 0,void 0,void 0,(function*(){let r={responseCode:400};try{const d={"x-web-sdk-launcher-version":"3.1.0"},c=new URL(`${e}/sdk/v2/script-link`);i&&c.searchParams.append("flowName",i),o&&c.searchParams.append("experimentalKey",o),r=yield fetch(c.toString(),{headers:d}).then((e=>e.json())),r.scriptLink&&(t=()=>n(void 0,void 0,void 0,(function*(){return r})))}catch(e){console.error(e)}return r}));e.createPublicTokenProvider=(e,t)=>()=>n(void 0,void 0,void 0,(function*(){if(!e)throw new Error("Missing api url");if(!t)throw new Error("Missing api key");return(yield fetch(`${e}/sdk/v2/token`,{method:"POST",body:JSON.stringify({}),headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*","x-sdk-key":t}})).json()})),e.init=function(e){return new Promise(((n,i)=>{t(e.apiUrl,e.flowName,e.experimentalKey).then((({scriptLink:t="https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js"})=>{t=t.indexOf("")>=0?t:t.replace(".min.js",".min.js");const o=document.createElement("script");o.setAttribute("async",""),o.src=t,document.getElementsByTagName("body")[0].appendChild(o),o.onload=()=>{window.getidWebSdk&&window.getidWebSdk.init(e).then((e=>n(e))).catch((e=>i(e)))},o.onerror=e=>i(e)})).catch((e=>{console.log(e),i(e)}))}))},Object.defineProperty(e,"__esModule",{value:!0})})); \ No newline at end of file diff --git a/lib/getid-web-sdk-launcher-non-polyfills.min.js b/lib/getid-web-sdk-launcher-non-polyfills.min.js new file mode 100644 index 0000000..4e0e092 --- /dev/null +++ b/lib/getid-web-sdk-launcher-non-polyfills.min.js @@ -0,0 +1,15 @@ +!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).getidWebSdk={})}(this,(function(e){"use strict"; +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */function n(e,n,t,o){return new(t||(t=Promise))((function(i,c){function r(e){try{d(o.next(e))}catch(e){c(e)}}function s(e){try{d(o.throw(e))}catch(e){c(e)}}function d(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(r,s)}d((o=o.apply(e,n||[])).next())}))}let t=(e,o,i)=>n(void 0,void 0,void 0,(function*(){let c={responseCode:400};try{const r={"x-web-sdk-launcher-version":"3.1.0"},s=new URL(`${e}/sdk/v2/script-link`);o&&s.searchParams.append("flowName",o),i&&s.searchParams.append("experimentalKey",i),c=yield fetch(s.toString(),{headers:r}).then((e=>e.json())),c.scriptLink&&(t=()=>n(void 0,void 0,void 0,(function*(){return c})))}catch(e){console.error(e)}return c}));e.init=function(e){const n="-non-polyfills";return new Promise(((o,i)=>{t(e.apiUrl,e.flowName,e.experimentalKey).then((({scriptLink:t="https://cdn.getid.cloud/sdk/getid-web-sdk-v6.13.1-rc-non-polyfills.min.js"})=>{t=t.indexOf(n)>=0?t:t.replace(".min.js","-non-polyfills.min.js");const c=document.createElement("script");c.setAttribute("async",""),c.src=t,document.getElementsByTagName("body")[0].appendChild(c),c.onload=()=>{window.getidWebSdk&&window.getidWebSdk.init(e).then((e=>o(e))).catch((e=>i(e)))},c.onerror=e=>i(e)})).catch((e=>{console.log(e),i(e)}))}))}})); \ No newline at end of file diff --git a/lib/getid-web-sdk-launcher-v7.min.js b/lib/getid-web-sdk-launcher-v7.min.js index 427dba4..6ef0e35 100644 --- a/lib/getid-web-sdk-launcher-v7.min.js +++ b/lib/getid-web-sdk-launcher-v7.min.js @@ -12,4 +12,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */function n(e,n,t,o){return new(t||(t=Promise))((function(i,c){function r(e){try{s(o.next(e))}catch(e){c(e)}}function d(e){try{s(o.throw(e))}catch(e){c(e)}}function s(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(r,d)}s((o=o.apply(e,n||[])).next())}))}let t=(e,o,i)=>n(void 0,void 0,void 0,(function*(){let c={responseCode:400};try{const r={"x-web-sdk-launcher-version":"3.0.0"},d=new URL(`${e}/sdk/v2/script-link`);o&&d.searchParams.append("flowName",o),i&&d.searchParams.append("experimentalKey",i),c=yield fetch(d.toString(),{headers:r}).then((e=>e.json())),c.scriptLink&&(t=()=>n(void 0,void 0,void 0,(function*(){return c})))}catch(e){console.error(e)}return c}));e.init=function(e){return new Promise(((n,o)=>{t(e.apiUrl,e.flowName,e.experimentalKey).then((({scriptLink:t="https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js"})=>{const i=document.createElement("script");i.setAttribute("async",""),i.src=t,document.getElementsByTagName("body")[0].appendChild(i),i.onload=()=>{window.getidWebSdk&&window.getidWebSdk.init(e).then((e=>n(e))).catch((e=>o(e)))},i.onerror=e=>o(e)})).catch((e=>{console.log(e),o(e)}))}))}})); \ No newline at end of file +***************************************************************************** */function n(e,n,t,i){return new(t||(t=Promise))((function(o,c){function r(e){try{s(i.next(e))}catch(e){c(e)}}function d(e){try{s(i.throw(e))}catch(e){c(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(r,d)}s((i=i.apply(e,n||[])).next())}))}let t=(e,i,o)=>n(void 0,void 0,void 0,(function*(){let c={responseCode:400};try{const r={"x-web-sdk-launcher-version":"3.1.0"},d=new URL(`${e}/sdk/v2/script-link`);i&&d.searchParams.append("flowName",i),o&&d.searchParams.append("experimentalKey",o),c=yield fetch(d.toString(),{headers:r}).then((e=>e.json())),c.scriptLink&&(t=()=>n(void 0,void 0,void 0,(function*(){return c})))}catch(e){console.error(e)}return c}));e.init=function(e){return new Promise(((n,i)=>{t(e.apiUrl,e.flowName,e.experimentalKey).then((({scriptLink:t="https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js"})=>{t=t.indexOf("")>=0?t:t.replace(".min.js",".min.js");const o=document.createElement("script");o.setAttribute("async",""),o.src=t,document.getElementsByTagName("body")[0].appendChild(o),o.onload=()=>{window.getidWebSdk&&window.getidWebSdk.init(e).then((e=>n(e))).catch((e=>i(e)))},o.onerror=e=>i(e)})).catch((e=>{console.log(e),i(e)}))}))}})); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index c2caedf..1a6b569 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "getid-launcher", - "version": "3.0.0", + "version": "3.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "getid-launcher", - "version": "3.0.0", + "version": "3.1.0", "license": "MIT", "devDependencies": { "@babel/core": "^7.16.5", @@ -20,6 +20,7 @@ "@rollup/plugin-babel": "^5.3.1", "@rollup/plugin-commonjs": "^22.0.2", "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-typescript": "^8.3.4", "@types/semver": "^7.3.9", "@typescript-eslint/eslint-plugin": "^5.7.0", @@ -2004,6 +2005,67 @@ "rollup": "^1.20.0 || ^2.0.0" } }, + "node_modules/@rollup/plugin-replace": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz", + "integrity": "sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.27.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-replace/node_modules/@rollup/pluginutils": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.4.tgz", + "integrity": "sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-replace/node_modules/@types/estree": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.2.tgz", + "integrity": "sha512-VeiPZ9MMwXjO32/Xu7+OwflfmeoRwkE/qzndw42gGtgJwZopBnzy2gD//NN1+go1mADzkDcqf/KnFRSjTJ8xJA==", + "dev": true + }, + "node_modules/@rollup/plugin-replace/node_modules/magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.13" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/@rollup/plugin-typescript": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-8.3.4.tgz", @@ -11360,6 +11422,44 @@ "@rollup/pluginutils": "^3.0.8" } }, + "@rollup/plugin-replace": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.2.tgz", + "integrity": "sha512-M9YXNekv/C/iHHK+cvORzfRYfPbq0RDD8r0G+bMiTXjNGKulPnCT9O3Ss46WfhI6ZOCgApOP7xAdmCQJ+U2LAA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.27.0" + }, + "dependencies": { + "@rollup/pluginutils": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.4.tgz", + "integrity": "sha512-0KJnIoRI8A+a1dqOYLxH8vBf8bphDmty5QvIm2hqm7oFCFYKCAZWWd2hXgMibaPsNDhI0AtpYfQZJG47pt/k4g==", + "dev": true, + "requires": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + } + }, + "@types/estree": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.2.tgz", + "integrity": "sha512-VeiPZ9MMwXjO32/Xu7+OwflfmeoRwkE/qzndw42gGtgJwZopBnzy2gD//NN1+go1mADzkDcqf/KnFRSjTJ8xJA==", + "dev": true + }, + "magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "dev": true, + "requires": { + "@jridgewell/sourcemap-codec": "^1.4.13" + } + } + } + }, "@rollup/plugin-typescript": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-8.3.4.tgz", diff --git a/package.json b/package.json index 8fffab7..f29ba57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "getid-launcher", - "version": "3.0.0", + "version": "3.1.0", "main": "./lib/bundle.js", "types": "lib/bundle.d.ts", "author": "GetID", @@ -24,6 +24,7 @@ "@rollup/plugin-babel": "^5.3.1", "@rollup/plugin-commonjs": "^22.0.2", "@rollup/plugin-json": "^4.1.0", + "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-typescript": "^8.3.4", "@types/semver": "^7.3.9", "@typescript-eslint/eslint-plugin": "^5.7.0", diff --git a/rollup.config.js b/rollup.config.js index c38b2e7..ee19600 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,6 +4,12 @@ import { terser } from 'rollup-plugin-terser'; import typescript from '@rollup/plugin-typescript'; import dts from 'rollup-plugin-dts'; import json from '@rollup/plugin-json'; +import replace from '@rollup/plugin-replace'; + +const defaultEnvVariables = { + 'process.env.FALLBACK_SDK_VERSION': JSON.stringify(''), + 'process.env.SCRIPT_NAME_SUFFIX': JSON.stringify(''), +}; const config = [ { @@ -17,6 +23,7 @@ const config = [ }], plugins: [ typescript({ declaration: true }), + replace(defaultEnvVariables), babel({ babelHelpers: 'runtime', skipPreflightCheck: true, @@ -52,6 +59,38 @@ const config = [ }], plugins: [ typescript({ declaration: true }), + replace(defaultEnvVariables), + babel({ + babelHelpers: 'runtime', + skipPreflightCheck: true, + exclude: 'node_modules/**', + presets: ['@babel/env'], + }), + commonjs({ + include: 'node_modules/**', + }), + json(), + terser(), + ], + }, + { + input: 'src/lib.ts', + output: [{ + name: 'getidWebSdk', + esModule: false, + exports: 'named', + file: `${__dirname}/lib/getid-web-sdk-launcher-non-polyfills.min.js`, + format: 'umd', + compact: true, + sourcemap: false, + }], + plugins: [ + typescript({ declaration: true }), + replace({ + ...defaultEnvVariables, + 'process.env.FALLBACK_SDK_VERSION': JSON.stringify('v6.13.1-rc'), + 'process.env.SCRIPT_NAME_SUFFIX': JSON.stringify('-non-polyfills'), + }), babel({ babelHelpers: 'runtime', skipPreflightCheck: true, diff --git a/src/launcher.ts b/src/launcher.ts index dda1bbb..61b6ae5 100644 --- a/src/launcher.ts +++ b/src/launcher.ts @@ -41,11 +41,15 @@ let getScriptLink = async (apiUrl: string, flowName?: string, experimentalKey?: return result; }; -function init (config: PageSideConfig): Promise { - const defaultLink = 'https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js'; +function init(config: PageSideConfig): Promise { + const fallbackVersion = process.env.FALLBACK_SDK_VERSION || 'v6'; + const scriptSuffix = process.env.SCRIPT_NAME_SUFFIX || ''; + const defaultLink = `https://cdn.getid.cloud/sdk/getid-web-sdk-${fallbackVersion}${scriptSuffix}.min.js`; return new Promise((res, rej) => { getScriptLink(config.apiUrl, config.flowName, config.experimentalKey).then(({ scriptLink = defaultLink }) => { + scriptLink = scriptLink.indexOf(scriptSuffix) >= 0 ? scriptLink : scriptLink.replace('.min.js', `${scriptSuffix}.min.js`); + const script = document.createElement('script'); script.setAttribute('async', ''); script.src = scriptLink;