Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@transak/transak-sdk

Package Overview
Dependencies
Maintainers
4
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transak/transak-sdk - npm Package Compare versions

Comparing version 1.0.111 to 1.1.0

src/example/index.js

708

dist/sdk.js

@@ -527,2 +527,596 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.TransakSDK = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){

},{}],2:[function(require,module,exports){
'use strict';
var token = '%[a-f0-9]{2}';
var singleMatcher = new RegExp(token, 'gi');
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
function decodeComponents(components, split) {
try {
// Try to decode the entire string first
return decodeURIComponent(components.join(''));
} catch (err) {
// Do nothing
}
if (components.length === 1) {
return components;
}
split = split || 1;
// Split the array in 2 parts
var left = components.slice(0, split);
var right = components.slice(split);
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
}
function decode(input) {
try {
return decodeURIComponent(input);
} catch (err) {
var tokens = input.match(singleMatcher);
for (var i = 1; i < tokens.length; i++) {
input = decodeComponents(tokens, i).join('');
tokens = input.match(singleMatcher);
}
return input;
}
}
function customDecodeURIComponent(input) {
// Keep track of all the replacements and prefill the map with the `BOM`
var replaceMap = {
'%FE%FF': '\uFFFD\uFFFD',
'%FF%FE': '\uFFFD\uFFFD'
};
var match = multiMatcher.exec(input);
while (match) {
try {
// Decode as big chunks as possible
replaceMap[match[0]] = decodeURIComponent(match[0]);
} catch (err) {
var result = decode(match[0]);
if (result !== match[0]) {
replaceMap[match[0]] = result;
}
}
match = multiMatcher.exec(input);
}
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
replaceMap['%C2'] = '\uFFFD';
var entries = Object.keys(replaceMap);
for (var i = 0; i < entries.length; i++) {
// Replace all decoded components
var key = entries[i];
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
}
return input;
}
module.exports = function (encodedURI) {
if (typeof encodedURI !== 'string') {
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
}
try {
encodedURI = encodedURI.replace(/\+/g, ' ');
// Try the built in decoder first
return decodeURIComponent(encodedURI);
} catch (err) {
// Fallback to a more advanced decoder
return customDecodeURIComponent(encodedURI);
}
};
},{}],3:[function(require,module,exports){
'use strict';
module.exports = function (obj, predicate) {
var ret = {};
var keys = Object.keys(obj);
var isArr = Array.isArray(predicate);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var val = obj[key];
if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
ret[key] = val;
}
}
return ret;
};
},{}],4:[function(require,module,exports){
'use strict';
const strictUriEncode = require('strict-uri-encode');
const decodeComponent = require('decode-uri-component');
const splitOnFirst = require('split-on-first');
const filterObject = require('filter-obj');
const isNullOrUndefined = value => value === null || value === undefined;
function encoderForArrayFormat(options) {
switch (options.arrayFormat) {
case 'index':
return key => (result, value) => {
const index = result.length;
if (
value === undefined ||
(options.skipNull && value === null) ||
(options.skipEmptyString && value === '')
) {
return result;
}
if (value === null) {
return [...result, [encode(key, options), '[', index, ']'].join('')];
}
return [
...result,
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')
];
};
case 'bracket':
return key => (result, value) => {
if (
value === undefined ||
(options.skipNull && value === null) ||
(options.skipEmptyString && value === '')
) {
return result;
}
if (value === null) {
return [...result, [encode(key, options), '[]'].join('')];
}
return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
};
case 'comma':
case 'separator':
return key => (result, value) => {
if (value === null || value === undefined || value.length === 0) {
return result;
}
if (result.length === 0) {
return [[encode(key, options), '=', encode(value, options)].join('')];
}
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
};
default:
return key => (result, value) => {
if (
value === undefined ||
(options.skipNull && value === null) ||
(options.skipEmptyString && value === '')
) {
return result;
}
if (value === null) {
return [...result, encode(key, options)];
}
return [...result, [encode(key, options), '=', encode(value, options)].join('')];
};
}
}
function parserForArrayFormat(options) {
let result;
switch (options.arrayFormat) {
case 'index':
return (key, value, accumulator) => {
result = /\[(\d*)\]$/.exec(key);
key = key.replace(/\[\d*\]$/, '');
if (!result) {
accumulator[key] = value;
return;
}
if (accumulator[key] === undefined) {
accumulator[key] = {};
}
accumulator[key][result[1]] = value;
};
case 'bracket':
return (key, value, accumulator) => {
result = /(\[\])$/.exec(key);
key = key.replace(/\[\]$/, '');
if (!result) {
accumulator[key] = value;
return;
}
if (accumulator[key] === undefined) {
accumulator[key] = [value];
return;
}
accumulator[key] = [].concat(accumulator[key], value);
};
case 'comma':
case 'separator':
return (key, value, accumulator) => {
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
value = isEncodedArray ? decode(value, options) : value;
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
accumulator[key] = newValue;
};
default:
return (key, value, accumulator) => {
if (accumulator[key] === undefined) {
accumulator[key] = value;
return;
}
accumulator[key] = [].concat(accumulator[key], value);
};
}
}
function validateArrayFormatSeparator(value) {
if (typeof value !== 'string' || value.length !== 1) {
throw new TypeError('arrayFormatSeparator must be single character string');
}
}
function encode(value, options) {
if (options.encode) {
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
}
return value;
}
function decode(value, options) {
if (options.decode) {
return decodeComponent(value);
}
return value;
}
function keysSorter(input) {
if (Array.isArray(input)) {
return input.sort();
}
if (typeof input === 'object') {
return keysSorter(Object.keys(input))
.sort((a, b) => Number(a) - Number(b))
.map(key => input[key]);
}
return input;
}
function removeHash(input) {
const hashStart = input.indexOf('#');
if (hashStart !== -1) {
input = input.slice(0, hashStart);
}
return input;
}
function getHash(url) {
let hash = '';
const hashStart = url.indexOf('#');
if (hashStart !== -1) {
hash = url.slice(hashStart);
}
return hash;
}
function extract(input) {
input = removeHash(input);
const queryStart = input.indexOf('?');
if (queryStart === -1) {
return '';
}
return input.slice(queryStart + 1);
}
function parseValue(value, options) {
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
value = Number(value);
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
value = value.toLowerCase() === 'true';
}
return value;
}
function parse(query, options) {
options = Object.assign({
decode: true,
sort: true,
arrayFormat: 'none',
arrayFormatSeparator: ',',
parseNumbers: false,
parseBooleans: false
}, options);
validateArrayFormatSeparator(options.arrayFormatSeparator);
const formatter = parserForArrayFormat(options);
// Create an object with no prototype
const ret = Object.create(null);
if (typeof query !== 'string') {
return ret;
}
query = query.trim().replace(/^[?#&]/, '');
if (!query) {
return ret;
}
for (const param of query.split('&')) {
if (param === '') {
continue;
}
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
// Missing `=` should be `null`:
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
formatter(decode(key, options), value, ret);
}
for (const key of Object.keys(ret)) {
const value = ret[key];
if (typeof value === 'object' && value !== null) {
for (const k of Object.keys(value)) {
value[k] = parseValue(value[k], options);
}
} else {
ret[key] = parseValue(value, options);
}
}
if (options.sort === false) {
return ret;
}
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => {
const value = ret[key];
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
// Sort object keys, not values
result[key] = keysSorter(value);
} else {
result[key] = value;
}
return result;
}, Object.create(null));
}
exports.extract = extract;
exports.parse = parse;
exports.stringify = (object, options) => {
if (!object) {
return '';
}
options = Object.assign({
encode: true,
strict: true,
arrayFormat: 'none',
arrayFormatSeparator: ','
}, options);
validateArrayFormatSeparator(options.arrayFormatSeparator);
const shouldFilter = key => (
(options.skipNull && isNullOrUndefined(object[key])) ||
(options.skipEmptyString && object[key] === '')
);
const formatter = encoderForArrayFormat(options);
const objectCopy = {};
for (const key of Object.keys(object)) {
if (!shouldFilter(key)) {
objectCopy[key] = object[key];
}
}
const keys = Object.keys(objectCopy);
if (options.sort !== false) {
keys.sort(options.sort);
}
return keys.map(key => {
const value = object[key];
if (value === undefined) {
return '';
}
if (value === null) {
return encode(key, options);
}
if (Array.isArray(value)) {
return value
.reduce(formatter(key), [])
.join('&');
}
return encode(key, options) + '=' + encode(value, options);
}).filter(x => x.length > 0).join('&');
};
exports.parseUrl = (url, options) => {
options = Object.assign({
decode: true
}, options);
const [url_, hash] = splitOnFirst(url, '#');
return Object.assign(
{
url: url_.split('?')[0] || '',
query: parse(extract(url), options)
},
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
);
};
exports.stringifyUrl = (object, options) => {
options = Object.assign({
encode: true,
strict: true
}, options);
const url = removeHash(object.url).split('?')[0] || '';
const queryFromUrl = exports.extract(object.url);
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
const query = Object.assign(parsedQueryFromUrl, object.query);
let queryString = exports.stringify(query, options);
if (queryString) {
queryString = `?${queryString}`;
}
let hash = getHash(object.url);
if (object.fragmentIdentifier) {
hash = `#${encode(object.fragmentIdentifier, options)}`;
}
return `${url}${queryString}${hash}`;
};
exports.pick = (input, filter, options) => {
options = Object.assign({
parseFragmentIdentifier: true
}, options);
const {url, query, fragmentIdentifier} = exports.parseUrl(input, options);
return exports.stringifyUrl({
url,
query: filterObject(query, filter),
fragmentIdentifier
}, options);
};
exports.exclude = (input, filter, options) => {
const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
return exports.pick(input, exclusionFilter, options);
};
},{"decode-uri-component":2,"filter-obj":3,"split-on-first":5,"strict-uri-encode":6}],5:[function(require,module,exports){
'use strict';
module.exports = (string, separator) => {
if (!(typeof string === 'string' && typeof separator === 'string')) {
throw new TypeError('Expected the arguments to be of type `string`');
}
if (separator === '') {
return [string];
}
const separatorIndex = string.indexOf(separator);
if (separatorIndex === -1) {
return [string];
}
return [
string.slice(0, separatorIndex),
string.slice(separatorIndex + separator.length)
];
};
},{}],6:[function(require,module,exports){
'use strict';
module.exports = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
},{}],7:[function(require,module,exports){
module.exports={
"name": "@transak/transak-sdk",
"version": "1.1.0",
"description": "Transak SDK that allows you to easily integrate the fiat on/ramp",
"main": "dist/sdk.js",
"scripts": {
"build": "browserify ./src/index.js -o ./dist/sdk.js -p esmify -s TransakSDK"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Transak/transak-sdk.git"
},
"keywords": [
"fiat",
"ramp",
"on",
"off",
"cryptocurrency"
],
"author": "Transak",
"license": "ISC",
"dependencies": {
"events": "^3.1.0",
"query-string": "^6.12.1",
"request": "^2.88.2"
},
"devDependencies": {
"browserify": "^16.5.0",
"esmify": "^2.1.1"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
},{}],8:[function(require,module,exports){
"use strict";

@@ -663,3 +1257,3 @@

},{}],3:[function(require,module,exports){
},{}],9:[function(require,module,exports){
"use strict";

@@ -687,3 +1281,3 @@

},{}],4:[function(require,module,exports){
},{}],10:[function(require,module,exports){
"use strict";

@@ -702,3 +1296,3 @@

},{}],5:[function(require,module,exports){
},{}],11:[function(require,module,exports){
"use strict";

@@ -717,2 +1311,3 @@

TRANSAK_ORDER_CANCELLED: 'TRANSAK_ORDER_CANCELLED',
TRANSAK_ORDER_FAILED: 'TRANSAK_ORDER_FAILED',
TRANSAK_ORDER_SUCCESSFUL: 'TRANSAK_ORDER_SUCCESSFUL'

@@ -722,3 +1317,3 @@ };

},{}],6:[function(require,module,exports){
},{}],12:[function(require,module,exports){
"use strict";

@@ -737,5 +1332,10 @@

},
LOCAL_DEVELOPMENT: {
FRONTEND: 'http://localhost:3000',
BACKEND: 'http://localhost:8292/api/v2',
NAME: 'LOCAL_DEVELOPMENT'
},
DEVELOPMENT: {
FRONTEND: 'http://localhost:3000',
BACKEND: 'http://localhost:8292/api/v1',
FRONTEND: 'https://development-global.transak.com',
BACKEND: 'https://development-api.transak.com/api/v2',
NAME: 'DEVELOPMENT'

@@ -745,3 +1345,3 @@ },

FRONTEND: 'https://global.transak.com',
BACKEND: 'https://api.transak.com/api/v1',
BACKEND: 'https://api.transak.com/api/v2',
NAME: 'PRODUCTION'

@@ -757,3 +1357,3 @@ }

},{}],7:[function(require,module,exports){
},{}],13:[function(require,module,exports){
"use strict";

@@ -764,2 +1364,8 @@

});
Object.defineProperty(exports, "EVENTS", {
enumerable: true,
get: function () {
return _events.default;
}
});
Object.defineProperty(exports, "config", {

@@ -777,8 +1383,2 @@ enumerable: true,

});
Object.defineProperty(exports, "EVENTS", {
enumerable: true,
get: function () {
return _events.default;
}
});

@@ -793,3 +1393,3 @@ var _globalConfig = _interopRequireDefault(require("./globalConfig"));

},{"./errors":4,"./events":5,"./globalConfig":6}],8:[function(require,module,exports){
},{"./errors":10,"./events":11,"./globalConfig":12}],14:[function(require,module,exports){
"use strict";

@@ -812,2 +1412,6 @@

var _queryString = _interopRequireDefault(require("query-string"));
var _package = require("../package.json");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -818,2 +1422,3 @@

function TransakSDK(partnerData) {
this.sdkVersion = _package.version;
this.partnerData = partnerData;

@@ -843,5 +1448,8 @@ this.isInitialised = false;

let modal = document.getElementById("transakFiatOnOffRamp");
modal.style.display = "none";
modal.innerHTML = "";
await modal.remove();
if (modal && modal.style) {
modal.style.display = "none";
modal.innerHTML = "";
await modal.remove();
}
};

@@ -865,6 +1473,8 @@

partnerData
} = await generateURL(this.partnerData);
} = await generateURL({ ...this.partnerData,
sdkVersion: this.sdkVersion
});
let wrapper = document.createElement('div');
wrapper.id = "transakFiatOnOffRamp";
wrapper.innerHTML = `<div class="transak_modal-overlay" id="transak_modal-overlay"></div><div class="transak_modal" id="transak_modal"><div class="transak_modal-content"><span class="transak_close">${_svg.closeSVGIcon}</span><div class="transakContainer"><iframe id="transakOnOffRampWidget" src="${url}" style="width: ${width}; height: ${height}"></iframe></div></div></div>`;
wrapper.innerHTML = `<div class="transak_modal-overlay" id="transak_modal-overlay"></div><div class="transak_modal" id="transak_modal"><div class="transak_modal-content"><span class="transak_close">${_svg.closeSVGIcon}</span><div class="transakContainer"><iframe id="transakOnOffRampWidget" allow="camera;fullscreen;accelerometer;gyroscope;magnetometer" allowFullScreen src="${url}" style="width: ${width}; height: ${height}"></iframe></div></div></div>`;
let container = document.getElementsByTagName("body");

@@ -880,3 +1490,3 @@ if (!container) container = document.getElementsByTagName("html");

document.body.scroll = "no";
modal.style.display = "block";
if (modal && modal.style) modal.style.display = "block";
this.isInitialised = true;

@@ -918,24 +1528,11 @@ eventEmitter.emit(_constants.EVENTS.TRANSAK_WIDGET_INITIALISED, {

try {
environment = environment.toUpperCase(); // let partnerDataBackend = await fetchAPIKey(configData.apiKey, config.ENVIRONMENT[environment].BACKEND);
// if (partnerDataBackend) {
partnerData.apiKey = configData.apiKey;
if (configData.cryptoCurrencyCode) partnerData.cryptoCurrencyCode = configData.cryptoCurrencyCode;
if (configData.defaultCryptoCurrency) partnerData.defaultCryptoCurrency = configData.defaultCryptoCurrency;
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.themeColor) partnerData.themeColor = configData.themeColor.replace("#", "");
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.fiatAmount) partnerData.fiatAmount = configData.fiatAmount;
if (configData.fiatCurrency) partnerData.fiatCurrency = configData.fiatCurrency;
if (configData.countryCode) partnerData.countryCode = configData.countryCode;
if (configData.defaultPaymentMethod) partnerData.defaultPaymentMethod = configData.defaultPaymentMethod;
if (configData.email) partnerData.email = configData.email;
if (configData.partnerOrderId) partnerData.partnerOrderId = configData.partnerOrderId;
if (configData.partnerCustomerId) partnerData.partnerCustomerId = configData.partnerCustomerId;
if (configData.exchangeScreenTitle) partnerData.exchangeScreenTitle = configData.exchangeScreenTitle;
if (configData.hideMenu) partnerData.hideMenu = configData.hideMenu;
if (configData.redirectURL) partnerData.redirectURL = configData.redirectURL;
if (configData.hostURL) partnerData.hostURL = configData.hostURL;
if (configData.disableWalletAddressForm) partnerData.disableWalletAddressForm = configData.disableWalletAddressForm;
queryString = (0, _generalUtil.UrlEncode)(partnerData); // }
environment = environment.toUpperCase();
Object.keys(configData).map(key => {
if (configData[key] instanceof Object) {
partnerData[key] = JSON.stringify(configData[key]);
} else partnerData[key] = configData[key];
});
queryString = _queryString.default.stringify(partnerData, {
arrayFormat: 'comma'
});
} catch (e) {

@@ -967,3 +1564,3 @@ throw e;

let environment;
if (event.origin === _constants.config.ENVIRONMENT.DEVELOPMENT.FRONTEND) environment = _constants.config.ENVIRONMENT.DEVELOPMENT.NAME;else if (event.origin === _constants.config.ENVIRONMENT.PRODUCTION.FRONTEND) environment = _constants.config.ENVIRONMENT.PRODUCTION.NAME;else if (event.origin === _constants.config.ENVIRONMENT.STAGING.FRONTEND) environment = _constants.config.ENVIRONMENT.STAGING.NAME;
if (event.origin === _constants.config.ENVIRONMENT.LOCAL_DEVELOPMENT.FRONTEND) environment = _constants.config.ENVIRONMENT.LOCAL_DEVELOPMENT.NAME;else if (event.origin === _constants.config.ENVIRONMENT.PRODUCTION.FRONTEND) environment = _constants.config.ENVIRONMENT.PRODUCTION.NAME;else if (event.origin === _constants.config.ENVIRONMENT.STAGING.FRONTEND) environment = _constants.config.ENVIRONMENT.STAGING.NAME;else if (event.origin === _constants.config.ENVIRONMENT.DEVELOPMENT.FRONTEND) environment = _constants.config.ENVIRONMENT.DEVELOPMENT.NAME;

@@ -983,5 +1580,9 @@ if (environment) {

let modal = document.getElementById("transakFiatOnOffRamp");
modal.style.display = "none";
modal.innerHTML = "";
modal.remove();
if (modal && modal.style) {
modal.style.display = "none";
modal.innerHTML = "";
modal.remove();
}
break;

@@ -1008,2 +1609,11 @@ }

case _constants.EVENTS.TRANSAK_ORDER_FAILED:
{
eventEmitter.emit(_constants.EVENTS.TRANSAK_ORDER_FAILED, {
status: event.data.data,
eventName: _constants.EVENTS.TRANSAK_ORDER_FAILED
});
break;
}
case _constants.EVENTS.TRANSAK_ORDER_SUCCESSFUL:

@@ -1037,3 +1647,3 @@ {

},{"./assets/css":2,"./assets/svg":3,"./constants":7,"./utils/generalUtil":9,"events":1}],9:[function(require,module,exports){
},{"../package.json":7,"./assets/css":8,"./assets/svg":9,"./constants":13,"./utils/generalUtil":15,"events":1,"query-string":4}],15:[function(require,module,exports){
"use strict";

@@ -1068,3 +1678,3 @@

},{}]},{},[8])(8)
},{}]},{},[14])(14)
});

4

package.json
{
"name": "@transak/transak-sdk",
"version": "1.0.111",
"version": "1.1.0",
"description": "Transak SDK that allows you to easily integrate the fiat on/ramp",
"main": "dist/sdk.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "browserify ./src/index.js -o ./dist/sdk.js -p esmify -s TransakSDK"

@@ -25,2 +24,3 @@ },

"events": "^3.1.0",
"query-string": "^6.12.1",
"request": "^2.88.2"

@@ -27,0 +27,0 @@ },

# Transak SDK
[![Build](https://travis-ci.org/joemccann/dillinger.svg)]()
A JavaScript library for decentralised applications to onboard their global user base with fiat currency.

@@ -14,2 +13,5 @@ ### Installation

```
For the advance customization, view our [query parameter documentation.](https://integrate.transak.com/Query-Parameters-9ec523df3b874ec58cef4fa3a906f238)
### Example usage

@@ -20,11 +22,10 @@ ```sh

let transak = new transakSDK({
apiKey: '4fcd6904-706b-4aff-bd9d-77422813bbb7', // Your API Key
environment: 'STAGING', // STAGING/PRODUCTION
apiKey: '4fcd6904-706b-4aff-bd9d-77422813bbb7', // Your API Key (Required)
environment: 'STAGING', // STAGING/PRODUCTION (Required)
defaultCryptoCurrency: 'ETH',
walletAddress: '', // Your customer wallet address
themeColor: '000000', // App theme color in hex
fiatCurrency: '', // INR/GBP
email: '', // Your customer email address
email: '', // Your customer email address (Optional)
redirectURL: '',
hostURL: window.location.origin,
hostURL: window.location.origin, // Required field
widgetHeight: '550px',

@@ -41,2 +42,7 @@ widgetWidth: '450px'

// This will trigger when the user closed the widget
transak.on(transak.EVENTS.TRANSAK_WIDGET_CLOSE, (orderData) => {
transak.close();
});
// This will trigger when the user marks payment is made.

@@ -49,2 +55,2 @@ transak.on(transak.EVENTS.TRANSAK_ORDER_SUCCESSFUL, (orderData) => {

For in-depth instructions on integrating Transak, view [our complete documentation.](https://transak.com/integrate)
For in-depth instructions on integrating Transak, view [our complete documentation.](https://integrate.transak.com)

@@ -8,3 +8,4 @@ export default {

TRANSAK_ORDER_CANCELLED: 'TRANSAK_ORDER_CANCELLED',
TRANSAK_ORDER_FAILED: 'TRANSAK_ORDER_FAILED',
TRANSAK_ORDER_SUCCESSFUL: 'TRANSAK_ORDER_SUCCESSFUL'
}

@@ -8,5 +8,10 @@ export default {

},
LOCAL_DEVELOPMENT: {
FRONTEND: 'http://localhost:3000',
BACKEND: 'http://localhost:8292/api/v2',
NAME: 'LOCAL_DEVELOPMENT'
},
DEVELOPMENT: {
FRONTEND: 'http://localhost:3000',
BACKEND: 'http://localhost:8292/api/v1',
FRONTEND: 'https://development-global.transak.com',
BACKEND: 'https://development-api.transak.com/api/v2',
NAME: 'DEVELOPMENT'

@@ -16,3 +21,3 @@ },

FRONTEND: 'https://global.transak.com',
BACKEND: 'https://api.transak.com/api/v1',
BACKEND: 'https://api.transak.com/api/v2',
NAME: 'PRODUCTION'

@@ -19,0 +24,0 @@ }

import events from 'events';
import {config, errorsLang, EVENTS} from "./constants";
import {UrlEncode} from "./utils/generalUtil";
import {closeSVGIcon} from './assets/svg';
import {getCSS} from './assets/css';
import { config, errorsLang, EVENTS } from "./constants";
import { UrlEncode } from "./utils/generalUtil";
import { closeSVGIcon } from './assets/svg';
import { getCSS } from './assets/css';
import queryStringLib from 'query-string'
import { version } from "../package.json"

@@ -10,2 +12,3 @@ const eventEmitter = new events.EventEmitter();

function TransakSDK(partnerData) {
this.sdkVersion = version;
this.partnerData = partnerData;

@@ -32,5 +35,7 @@ this.isInitialised = false;

let modal = document.getElementById("transakFiatOnOffRamp");
modal.style.display = "none";
modal.innerHTML = "";
await modal.remove();
if (modal && modal.style) {
modal.style.display = "none";
modal.innerHTML = "";
await modal.remove();
}
}

@@ -47,6 +52,6 @@ TransakSDK.prototype.closeRequest = function () {

if (this.partnerData) {
let {url, width, height, partnerData} = await generateURL(this.partnerData);
let { url, width, height, partnerData } = await generateURL({ ...this.partnerData, sdkVersion: this.sdkVersion });
let wrapper = document.createElement('div');
wrapper.id = "transakFiatOnOffRamp";
wrapper.innerHTML = `<div class="transak_modal-overlay" id="transak_modal-overlay"></div><div class="transak_modal" id="transak_modal"><div class="transak_modal-content"><span class="transak_close">${closeSVGIcon}</span><div class="transakContainer"><iframe id="transakOnOffRampWidget" src="${url}" style="width: ${width}; height: ${height}"></iframe></div></div></div>`;
wrapper.innerHTML = `<div class="transak_modal-overlay" id="transak_modal-overlay"></div><div class="transak_modal" id="transak_modal"><div class="transak_modal-content"><span class="transak_close">${closeSVGIcon}</span><div class="transakContainer"><iframe id="transakOnOffRampWidget" allow="camera;fullscreen;accelerometer;gyroscope;magnetometer" allowFullScreen src="${url}" style="width: ${width}; height: ${height}"></iframe></div></div></div>`;
let container = document.getElementsByTagName("body");

@@ -64,3 +69,3 @@ if (!container) container = document.getElementsByTagName("html");

modal.style.display = "block";
if (modal && modal.style) modal.style.display = "block";
this.isInitialised = true;

@@ -83,3 +88,3 @@ eventEmitter.emit(EVENTS.TRANSAK_WIDGET_INITIALISED, {

} catch (e) {
throw(e)
throw (e)
}

@@ -97,32 +102,17 @@ }

environment = environment.toUpperCase();
// let partnerDataBackend = await fetchAPIKey(configData.apiKey, config.ENVIRONMENT[environment].BACKEND);
// if (partnerDataBackend) {
partnerData.apiKey = configData.apiKey;
if (configData.cryptoCurrencyCode) partnerData.cryptoCurrencyCode = configData.cryptoCurrencyCode;
if (configData.defaultCryptoCurrency) partnerData.defaultCryptoCurrency = configData.defaultCryptoCurrency;
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.themeColor) partnerData.themeColor = configData.themeColor.replace("#", "");
if (configData.walletAddress) partnerData.walletAddress = configData.walletAddress;
if (configData.fiatAmount) partnerData.fiatAmount = configData.fiatAmount;
if (configData.fiatCurrency) partnerData.fiatCurrency = configData.fiatCurrency;
if (configData.countryCode) partnerData.countryCode = configData.countryCode;
if (configData.defaultPaymentMethod) partnerData.defaultPaymentMethod = configData.defaultPaymentMethod;
if (configData.email) partnerData.email = configData.email;
if (configData.partnerOrderId) partnerData.partnerOrderId = configData.partnerOrderId;
if (configData.partnerCustomerId) partnerData.partnerCustomerId = configData.partnerCustomerId;
if (configData.exchangeScreenTitle) partnerData.exchangeScreenTitle = configData.exchangeScreenTitle;
if (configData.hideMenu) partnerData.hideMenu = configData.hideMenu;
if (configData.redirectURL) partnerData.redirectURL = configData.redirectURL;
if (configData.hostURL) partnerData.hostURL = configData.hostURL;
if (configData.disableWalletAddressForm) partnerData.disableWalletAddressForm = configData.disableWalletAddressForm;
queryString = UrlEncode(partnerData);
// }
Object.keys(configData).map((key) => {
if (configData[key] instanceof Object) {
partnerData[key] = JSON.stringify(configData[key]);
} else partnerData[key] = configData[key];
});
queryString = queryStringLib.stringify(partnerData, { arrayFormat: 'comma' });
} catch (e) {
throw(e)
throw (e)
}
} else throw(errorsLang.ENTER_API_KEY);
}
else throw (errorsLang.ENTER_API_KEY);
if (configData.widgetWidth) width = configData.widgetWidth;
if (configData.widgetHeight) height = configData.widgetHeight;
}
return {width, height, partnerData, url: `${config.ENVIRONMENT[environment].FRONTEND}?${queryString}`}
return { width, height, partnerData, url: `${config.ENVIRONMENT[environment].FRONTEND}?${queryString}` }
}

@@ -139,5 +129,7 @@

let environment;
if (event.origin === config.ENVIRONMENT.DEVELOPMENT.FRONTEND) environment = config.ENVIRONMENT.DEVELOPMENT.NAME;
if (event.origin === config.ENVIRONMENT.LOCAL_DEVELOPMENT.FRONTEND) environment = config.ENVIRONMENT.LOCAL_DEVELOPMENT.NAME;
else if (event.origin === config.ENVIRONMENT.PRODUCTION.FRONTEND) environment = config.ENVIRONMENT.PRODUCTION.NAME;
else if (event.origin === config.ENVIRONMENT.STAGING.FRONTEND) environment = config.ENVIRONMENT.STAGING.NAME;
else if (event.origin === config.ENVIRONMENT.DEVELOPMENT.FRONTEND) environment = config.ENVIRONMENT.DEVELOPMENT.NAME;
if (environment) {

@@ -155,7 +147,8 @@ if (event && event.data && event.data.event_id) {

document.body.scroll = "yes";
let modal = document.getElementById("transakFiatOnOffRamp");
modal.style.display = "none";
modal.innerHTML = "";
modal.remove();
if (modal && modal.style) {
modal.style.display = "none";
modal.innerHTML = "";
modal.remove();
}
break;

@@ -177,2 +170,9 @@ }

}
case EVENTS.TRANSAK_ORDER_FAILED: {
eventEmitter.emit(EVENTS.TRANSAK_ORDER_FAILED, {
status: event.data.data,
eventName: EVENTS.TRANSAK_ORDER_FAILED
});
break;
}
case EVENTS.TRANSAK_ORDER_SUCCESSFUL: {

@@ -192,3 +192,3 @@ eventEmitter.emit(EVENTS.TRANSAK_ORDER_SUCCESSFUL, {

}
default : {
default: {
}

@@ -195,0 +195,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc