Skip to content

Commit

Permalink
Merge pull request #10 from vvorld/non-polyfill-launcher
Browse files Browse the repository at this point in the history
feat: added non polyfills launccher
  • Loading branch information
pitrew authored Sep 25, 2023
2 parents 1afb9ad + 8ca8147 commit 82bca9c
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions lib/getid-web-sdk-launcher-non-polyfills.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/getid-web-sdk-launcher-v7.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 102 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -17,6 +23,7 @@ const config = [
}],
plugins: [
typescript({ declaration: true }),
replace(defaultEnvVariables),
babel({
babelHelpers: 'runtime',
skipPreflightCheck: true,
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ let getScriptLink = async (apiUrl: string, flowName?: string, experimentalKey?:
return result;
};

function init (config: PageSideConfig): Promise<GetIdWebSdkComponent> {
const defaultLink = 'https://cdn.getid.cloud/sdk/getid-web-sdk-v6.min.js';
function init(config: PageSideConfig): Promise<GetIdWebSdkComponent> {
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;
Expand Down

0 comments on commit 82bca9c

Please sign in to comment.