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

@ramp-network/ramp-instant-sdk

Package Overview
Dependencies
Maintainers
3
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ramp-network/ramp-instant-sdk - npm Package Compare versions

Comparing version 2.5.2 to 3.0.0

115

dist/lib/ramp-instant-sdk.js

@@ -13,42 +13,5 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
var body_scroll_lock_1 = require("body-scroll-lock");
var consts_1 = require("./consts");
var event_polling_1 = require("./event-polling");
var init_helpers_1 = require("./init-helpers");

@@ -64,4 +27,2 @@ var init_helpers_2 = require("./init-helpers");

this._isVisible = false;
this._isPollingForSwapStatus = false;
this._purchasePollingCredentials = null;
init_helpers_2.importFonts();

@@ -75,5 +36,3 @@ this.unsubscribe = this.unsubscribe.bind(this);

this._on = this._on.bind(this);
this._processPurchasePollingLoop = this._processPurchasePollingLoop.bind(this);
this._registerSdkEventHandlers = this._registerSdkEventHandlers.bind(this);
this._runPostSubscribeHooks = this._runPostSubscribeHooks.bind(this);
this._subscribeToWidgetEvents = this._subscribeToWidgetEvents.bind(this);

@@ -136,3 +95,2 @@ this._rawNormalizedConfig = utils_1.normalizeConfigAndLogErrorsOnInvalidFields(__assign({ variant: 'desktop' }, config));

}
this._runPostSubscribeHooks(type, internal);
};

@@ -217,11 +175,2 @@ RampInstantSDK.prototype.close = function () {

}, true);
this._on(types_1.WidgetEventTypes.PURCHASE_CREATED, function (event) {
_this._purchasePollingCredentials = {
apiUrl: event.payload.apiUrl,
purchaseExternalId: event.payload.purchase.id,
token: event.payload.purchaseViewToken,
};
// tslint:disable-next-line:no-floating-promises
_this._processPurchasePollingLoop(_this._purchasePollingCredentials);
}, true);
};

@@ -248,66 +197,2 @@ RampInstantSDK.prototype._dispatchEvent = function (event) {

};
RampInstantSDK.prototype._processPurchasePollingLoop = function (_a) {
var apiUrl = _a.apiUrl, purchaseExternalId = _a.purchaseExternalId, token = _a.token;
var _b, _c;
return __awaiter(this, void 0, void 0, function () {
var purchase;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this._isPollingForSwapStatus = true;
_d.label = 1;
case 1:
if (!(utils_1.countListenersForEvent(this._listeners, types_1.WidgetEventTypes.PURCHASE_SUCCESSFUL) > 0 ||
utils_1.countListenersForEvent(this._listeners, types_1.WidgetEventTypes.PURCHASE_FAILED) > 0)) return [3 /*break*/, 4];
// tslint:disable-next-line:no-magic-numbers
return [4 /*yield*/, event_polling_1.delay(1000)];
case 2:
// tslint:disable-next-line:no-magic-numbers
_d.sent();
return [4 /*yield*/, event_polling_1.doFetchPurchase(apiUrl, purchaseExternalId, token)];
case 3:
purchase = _d.sent();
if (!purchase) {
return [3 /*break*/, 1];
}
if ((_b = purchase.actions) === null || _b === void 0 ? void 0 : _b.find(function (action) { return action.newStatus === 'RELEASED'; })) {
this._dispatchEvent({
type: types_1.WidgetEventTypes.PURCHASE_SUCCESSFUL,
payload: {
purchase: purchase,
},
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
if ((_c = purchase.actions) === null || _c === void 0 ? void 0 : _c.find(function (action) { return action.newStatus === 'ERROR'; })) {
this._dispatchEvent({
type: types_1.WidgetEventTypes.PURCHASE_FAILED,
payload: null,
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
return [3 /*break*/, 1];
case 4:
this._isPollingForSwapStatus = false;
return [2 /*return*/];
}
});
});
};
RampInstantSDK.prototype._runPostSubscribeHooks = function (eventType, isHandlerInternal) {
/*
* Handles a case where a host subscribes to these events after
* the `PURCHASE_CREATED` event is fired
*/
if ((eventType === '*' ||
eventType === types_1.WidgetEventTypes.PURCHASE_SUCCESSFUL ||
types_1.WidgetEventTypes.PURCHASE_FAILED) &&
this._purchasePollingCredentials &&
!this._isPollingForSwapStatus) {
// tslint:disable-next-line:no-floating-promises
this._processPurchasePollingLoop(this._purchasePollingCredentials);
}
};
RampInstantSDK.prototype._showUsingEmbeddedMode = function () {

@@ -314,0 +199,0 @@ var _a, _b;

21

dist/lib/types.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var PaymentMethodName;
(function (PaymentMethodName) {
PaymentMethodName["MANUAL_BANK_TRANSFER"] = "MANUAL_BANK_TRANSFER";
PaymentMethodName["AUTO_BANK_TRANSFER"] = "AUTO_BANK_TRANSFER";
PaymentMethodName["CARD_PAYMENT"] = "CARD_PAYMENT";
PaymentMethodName["APPLE_PAY"] = "APPLE_PAY";
})(PaymentMethodName = exports.PaymentMethodName || (exports.PaymentMethodName = {}));
var PurchaseStatus;
(function (PurchaseStatus) {
PurchaseStatus["INITIALIZED"] = "INITIALIZED";
PurchaseStatus["PAYMENT_STARTED"] = "PAYMENT_STARTED";
PurchaseStatus["PAYMENT_IN_PROGRESS"] = "PAYMENT_IN_PROGRESS";
PurchaseStatus["PAYMENT_FAILED"] = "PAYMENT_FAILED";
PurchaseStatus["PAYMENT_EXECUTED"] = "PAYMENT_EXECUTED";
PurchaseStatus["FIAT_RECEIVED"] = "FIAT_RECEIVED";
PurchaseStatus["FIAT_SENT"] = "FIAT_SENT";
PurchaseStatus["EXPIRED"] = "EXPIRED";
PurchaseStatus["CANCELLED"] = "CANCELLED";
PurchaseStatus["RELEASING"] = "RELEASING";
PurchaseStatus["RELEASED"] = "RELEASED";
})(PurchaseStatus = exports.PurchaseStatus || (exports.PurchaseStatus = {}));
var EventSeverity;

@@ -4,0 +25,0 @@ (function (EventSeverity) {

@@ -93,7 +93,2 @@ "use strict";

exports.initEventListenersDict = initEventListenersDict;
function countListenersForEvent(listeners, event, internal) {
if (internal === void 0) { internal = false; }
return listeners[event].filter(function (handler) { return handler.internal === internal; }).length;
}
exports.countListenersForEvent = countListenersForEvent;
function determineWidgetVariant(config) {

@@ -100,0 +95,0 @@ var _a;

192

dist/ramp-instant-sdk.es5.js

@@ -39,39 +39,2 @@ /*! *****************************************************************************

function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __spreadArrays() {

@@ -103,2 +66,23 @@ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;

var PaymentMethodName;
(function (PaymentMethodName) {
PaymentMethodName["MANUAL_BANK_TRANSFER"] = "MANUAL_BANK_TRANSFER";
PaymentMethodName["AUTO_BANK_TRANSFER"] = "AUTO_BANK_TRANSFER";
PaymentMethodName["CARD_PAYMENT"] = "CARD_PAYMENT";
PaymentMethodName["APPLE_PAY"] = "APPLE_PAY";
})(PaymentMethodName || (PaymentMethodName = {}));
var PurchaseStatus;
(function (PurchaseStatus) {
PurchaseStatus["INITIALIZED"] = "INITIALIZED";
PurchaseStatus["PAYMENT_STARTED"] = "PAYMENT_STARTED";
PurchaseStatus["PAYMENT_IN_PROGRESS"] = "PAYMENT_IN_PROGRESS";
PurchaseStatus["PAYMENT_FAILED"] = "PAYMENT_FAILED";
PurchaseStatus["PAYMENT_EXECUTED"] = "PAYMENT_EXECUTED";
PurchaseStatus["FIAT_RECEIVED"] = "FIAT_RECEIVED";
PurchaseStatus["FIAT_SENT"] = "FIAT_SENT";
PurchaseStatus["EXPIRED"] = "EXPIRED";
PurchaseStatus["CANCELLED"] = "CANCELLED";
PurchaseStatus["RELEASING"] = "RELEASING";
PurchaseStatus["RELEASED"] = "RELEASED";
})(PurchaseStatus || (PurchaseStatus = {}));
var EventSeverity;

@@ -197,6 +181,2 @@ (function (EventSeverity) {

}
function countListenersForEvent(listeners, event, internal) {
if (internal === void 0) { internal = false; }
return listeners[event].filter(function (handler) { return handler.internal === internal; }).length;
}
function determineWidgetVariant(config) {

@@ -251,55 +231,3 @@ var _a;

}
/**
* Concatenates `base` with `path`, always treating `path` as a relative path. Ignores:
* - trailing slash in `base`
* - leading slash in `path`
* @param base base URL, e.g.: 'http://example.com/api' or 'http://example.com/service/api/'
* @param path path to append, e.g.: 'user/getByEmail' or '/swap'
*/
function concatRelativePath(base, path) {
var normalizedBase = urlWithoutTrailingSlash(base instanceof URL ? base.href : base);
var normalizedPath = path.startsWith('/') ? path.substr(1) : path;
return new URL(normalizedBase + "/" + normalizedPath);
}
function urlWithoutTrailingSlash(url) {
return url.endsWith('/') ? url.slice(0, -1) : url;
}
function doFetchPurchase(apiUrl, purchaseExternalId, token) {
return __awaiter(this, void 0, void 0, function () {
var rawResponse, response, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 3, , 4]);
return [4 /*yield*/, fetch(concatRelativePath(apiUrl, "/host-api/purchase/" + purchaseExternalId + "?secret=" + token).href, {
headers: {
'Content-Type': 'application/json',
},
})];
case 1:
rawResponse = _b.sent();
if (!rawResponse.ok) {
throw new Error("Request for purchase #" + purchaseExternalId + " failed");
}
return [4 /*yield*/, rawResponse.json()];
case 2:
response = _b.sent();
return [2 /*return*/, response];
case 3:
_a = _b.sent();
return [2 /*return*/, null];
case 4: return [2 /*return*/];
}
});
});
}
function delay(ms) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
});
});
}
function initWidgetIframeUrl(config) {

@@ -484,4 +412,2 @@ var baseUrl = new URL(config.url || baseWidgetUrl);

this._isVisible = false;
this._isPollingForSwapStatus = false;
this._purchasePollingCredentials = null;
importFonts();

@@ -495,5 +421,3 @@ this.unsubscribe = this.unsubscribe.bind(this);

this._on = this._on.bind(this);
this._processPurchasePollingLoop = this._processPurchasePollingLoop.bind(this);
this._registerSdkEventHandlers = this._registerSdkEventHandlers.bind(this);
this._runPostSubscribeHooks = this._runPostSubscribeHooks.bind(this);
this._subscribeToWidgetEvents = this._subscribeToWidgetEvents.bind(this);

@@ -556,3 +480,2 @@ this._rawNormalizedConfig = normalizeConfigAndLogErrorsOnInvalidFields(__assign({ variant: 'desktop' }, config));

}
this._runPostSubscribeHooks(type, internal);
};

@@ -637,11 +560,2 @@ RampInstantSDK.prototype.close = function () {

}, true);
this._on(WidgetEventTypes.PURCHASE_CREATED, function (event) {
_this._purchasePollingCredentials = {
apiUrl: event.payload.apiUrl,
purchaseExternalId: event.payload.purchase.id,
token: event.payload.purchaseViewToken,
};
// tslint:disable-next-line:no-floating-promises
_this._processPurchasePollingLoop(_this._purchasePollingCredentials);
}, true);
};

@@ -668,66 +582,2 @@ RampInstantSDK.prototype._dispatchEvent = function (event) {

};
RampInstantSDK.prototype._processPurchasePollingLoop = function (_a) {
var apiUrl = _a.apiUrl, purchaseExternalId = _a.purchaseExternalId, token = _a.token;
var _b, _c;
return __awaiter(this, void 0, void 0, function () {
var purchase;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this._isPollingForSwapStatus = true;
_d.label = 1;
case 1:
if (!(countListenersForEvent(this._listeners, WidgetEventTypes.PURCHASE_SUCCESSFUL) > 0 ||
countListenersForEvent(this._listeners, WidgetEventTypes.PURCHASE_FAILED) > 0)) return [3 /*break*/, 4];
// tslint:disable-next-line:no-magic-numbers
return [4 /*yield*/, delay(1000)];
case 2:
// tslint:disable-next-line:no-magic-numbers
_d.sent();
return [4 /*yield*/, doFetchPurchase(apiUrl, purchaseExternalId, token)];
case 3:
purchase = _d.sent();
if (!purchase) {
return [3 /*break*/, 1];
}
if ((_b = purchase.actions) === null || _b === void 0 ? void 0 : _b.find(function (action) { return action.newStatus === 'RELEASED'; })) {
this._dispatchEvent({
type: WidgetEventTypes.PURCHASE_SUCCESSFUL,
payload: {
purchase: purchase,
},
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
if ((_c = purchase.actions) === null || _c === void 0 ? void 0 : _c.find(function (action) { return action.newStatus === 'ERROR'; })) {
this._dispatchEvent({
type: WidgetEventTypes.PURCHASE_FAILED,
payload: null,
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
return [3 /*break*/, 1];
case 4:
this._isPollingForSwapStatus = false;
return [2 /*return*/];
}
});
});
};
RampInstantSDK.prototype._runPostSubscribeHooks = function (eventType, isHandlerInternal) {
/*
* Handles a case where a host subscribes to these events after
* the `PURCHASE_CREATED` event is fired
*/
if ((eventType === '*' ||
eventType === WidgetEventTypes.PURCHASE_SUCCESSFUL ||
WidgetEventTypes.PURCHASE_FAILED) &&
this._purchasePollingCredentials &&
!this._isPollingForSwapStatus) {
// tslint:disable-next-line:no-floating-promises
this._processPurchasePollingLoop(this._purchasePollingCredentials);
}
};
RampInstantSDK.prototype._showUsingEmbeddedMode = function () {

@@ -734,0 +584,0 @@ var _a, _b;

@@ -45,39 +45,2 @@ (function (global, factory) {

function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __spreadArrays() {

@@ -109,2 +72,23 @@ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;

var PaymentMethodName;
(function (PaymentMethodName) {
PaymentMethodName["MANUAL_BANK_TRANSFER"] = "MANUAL_BANK_TRANSFER";
PaymentMethodName["AUTO_BANK_TRANSFER"] = "AUTO_BANK_TRANSFER";
PaymentMethodName["CARD_PAYMENT"] = "CARD_PAYMENT";
PaymentMethodName["APPLE_PAY"] = "APPLE_PAY";
})(PaymentMethodName || (PaymentMethodName = {}));
var PurchaseStatus;
(function (PurchaseStatus) {
PurchaseStatus["INITIALIZED"] = "INITIALIZED";
PurchaseStatus["PAYMENT_STARTED"] = "PAYMENT_STARTED";
PurchaseStatus["PAYMENT_IN_PROGRESS"] = "PAYMENT_IN_PROGRESS";
PurchaseStatus["PAYMENT_FAILED"] = "PAYMENT_FAILED";
PurchaseStatus["PAYMENT_EXECUTED"] = "PAYMENT_EXECUTED";
PurchaseStatus["FIAT_RECEIVED"] = "FIAT_RECEIVED";
PurchaseStatus["FIAT_SENT"] = "FIAT_SENT";
PurchaseStatus["EXPIRED"] = "EXPIRED";
PurchaseStatus["CANCELLED"] = "CANCELLED";
PurchaseStatus["RELEASING"] = "RELEASING";
PurchaseStatus["RELEASED"] = "RELEASED";
})(PurchaseStatus || (PurchaseStatus = {}));
var EventSeverity;

@@ -202,6 +186,2 @@ (function (EventSeverity) {

}
function countListenersForEvent(listeners, event, internal) {
if (internal === void 0) { internal = false; }
return listeners[event].filter(function (handler) { return handler.internal === internal; }).length;
}
function determineWidgetVariant(config) {

@@ -256,55 +236,3 @@ var _a;

}
/**
* Concatenates `base` with `path`, always treating `path` as a relative path. Ignores:
* - trailing slash in `base`
* - leading slash in `path`
* @param base base URL, e.g.: 'http://example.com/api' or 'http://example.com/service/api/'
* @param path path to append, e.g.: 'user/getByEmail' or '/swap'
*/
function concatRelativePath(base, path) {
var normalizedBase = urlWithoutTrailingSlash(base instanceof URL ? base.href : base);
var normalizedPath = path.startsWith('/') ? path.substr(1) : path;
return new URL(normalizedBase + "/" + normalizedPath);
}
function urlWithoutTrailingSlash(url) {
return url.endsWith('/') ? url.slice(0, -1) : url;
}
function doFetchPurchase(apiUrl, purchaseExternalId, token) {
return __awaiter(this, void 0, void 0, function () {
var rawResponse, response, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_b.trys.push([0, 3, , 4]);
return [4 /*yield*/, fetch(concatRelativePath(apiUrl, "/host-api/purchase/" + purchaseExternalId + "?secret=" + token).href, {
headers: {
'Content-Type': 'application/json',
},
})];
case 1:
rawResponse = _b.sent();
if (!rawResponse.ok) {
throw new Error("Request for purchase #" + purchaseExternalId + " failed");
}
return [4 /*yield*/, rawResponse.json()];
case 2:
response = _b.sent();
return [2 /*return*/, response];
case 3:
_a = _b.sent();
return [2 /*return*/, null];
case 4: return [2 /*return*/];
}
});
});
}
function delay(ms) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, new Promise(function (resolve) { return setTimeout(resolve, ms); })];
});
});
}
function initWidgetIframeUrl(config) {

@@ -489,4 +417,2 @@ var baseUrl = new URL(config.url || baseWidgetUrl);

this._isVisible = false;
this._isPollingForSwapStatus = false;
this._purchasePollingCredentials = null;
importFonts();

@@ -500,5 +426,3 @@ this.unsubscribe = this.unsubscribe.bind(this);

this._on = this._on.bind(this);
this._processPurchasePollingLoop = this._processPurchasePollingLoop.bind(this);
this._registerSdkEventHandlers = this._registerSdkEventHandlers.bind(this);
this._runPostSubscribeHooks = this._runPostSubscribeHooks.bind(this);
this._subscribeToWidgetEvents = this._subscribeToWidgetEvents.bind(this);

@@ -561,3 +485,2 @@ this._rawNormalizedConfig = normalizeConfigAndLogErrorsOnInvalidFields(__assign({ variant: 'desktop' }, config));

}
this._runPostSubscribeHooks(type, internal);
};

@@ -642,11 +565,2 @@ RampInstantSDK.prototype.close = function () {

}, true);
this._on(exports.RampInstantEventTypes.PURCHASE_CREATED, function (event) {
_this._purchasePollingCredentials = {
apiUrl: event.payload.apiUrl,
purchaseExternalId: event.payload.purchase.id,
token: event.payload.purchaseViewToken,
};
// tslint:disable-next-line:no-floating-promises
_this._processPurchasePollingLoop(_this._purchasePollingCredentials);
}, true);
};

@@ -673,66 +587,2 @@ RampInstantSDK.prototype._dispatchEvent = function (event) {

};
RampInstantSDK.prototype._processPurchasePollingLoop = function (_a) {
var apiUrl = _a.apiUrl, purchaseExternalId = _a.purchaseExternalId, token = _a.token;
var _b, _c;
return __awaiter(this, void 0, void 0, function () {
var purchase;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this._isPollingForSwapStatus = true;
_d.label = 1;
case 1:
if (!(countListenersForEvent(this._listeners, exports.RampInstantEventTypes.PURCHASE_SUCCESSFUL) > 0 ||
countListenersForEvent(this._listeners, exports.RampInstantEventTypes.PURCHASE_FAILED) > 0)) return [3 /*break*/, 4];
// tslint:disable-next-line:no-magic-numbers
return [4 /*yield*/, delay(1000)];
case 2:
// tslint:disable-next-line:no-magic-numbers
_d.sent();
return [4 /*yield*/, doFetchPurchase(apiUrl, purchaseExternalId, token)];
case 3:
purchase = _d.sent();
if (!purchase) {
return [3 /*break*/, 1];
}
if ((_b = purchase.actions) === null || _b === void 0 ? void 0 : _b.find(function (action) { return action.newStatus === 'RELEASED'; })) {
this._dispatchEvent({
type: exports.RampInstantEventTypes.PURCHASE_SUCCESSFUL,
payload: {
purchase: purchase,
},
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
if ((_c = purchase.actions) === null || _c === void 0 ? void 0 : _c.find(function (action) { return action.newStatus === 'ERROR'; })) {
this._dispatchEvent({
type: exports.RampInstantEventTypes.PURCHASE_FAILED,
payload: null,
widgetInstanceId: this._config.widgetInstanceId,
});
return [2 /*return*/];
}
return [3 /*break*/, 1];
case 4:
this._isPollingForSwapStatus = false;
return [2 /*return*/];
}
});
});
};
RampInstantSDK.prototype._runPostSubscribeHooks = function (eventType, isHandlerInternal) {
/*
* Handles a case where a host subscribes to these events after
* the `PURCHASE_CREATED` event is fired
*/
if ((eventType === '*' ||
eventType === exports.RampInstantEventTypes.PURCHASE_SUCCESSFUL ||
exports.RampInstantEventTypes.PURCHASE_FAILED) &&
this._purchasePollingCredentials &&
!this._isPollingForSwapStatus) {
// tslint:disable-next-line:no-floating-promises
this._processPurchasePollingLoop(this._purchasePollingCredentials);
}
};
RampInstantSDK.prototype._showUsingEmbeddedMode = function () {

@@ -739,0 +589,0 @@ var _a, _b;

@@ -16,4 +16,2 @@ import { IHostConfig, TAllEvents } from './types';

private _isVisible;
private _isPollingForSwapStatus;
private _purchasePollingCredentials;
constructor(config: IHostConfig);

@@ -30,4 +28,2 @@ show(): RampInstantSDK;

private _teardownEventSubscriptions;
private _processPurchasePollingLoop;
private _runPostSubscribeHooks;
private _showUsingEmbeddedMode;

@@ -34,0 +30,0 @@ private _showUsingOverlayMode;

@@ -14,6 +14,4 @@ declare type TAsset = string;

declare type TCryptoAmount = string;
declare type TPoolFee = number;
declare type TRampFee = number;
declare type TAssetExchangeRate = number;
declare type TPurchaseHash = string;
declare type TFinalTxHash = string;
declare type TActionID = string;

@@ -26,2 +24,21 @@ declare type TNewActionStatus = string;

declare type TContainerNode = HTMLElement;
export declare enum PaymentMethodName {
MANUAL_BANK_TRANSFER = "MANUAL_BANK_TRANSFER",
AUTO_BANK_TRANSFER = "AUTO_BANK_TRANSFER",
CARD_PAYMENT = "CARD_PAYMENT",
APPLE_PAY = "APPLE_PAY"
}
export declare enum PurchaseStatus {
INITIALIZED = "INITIALIZED",
PAYMENT_STARTED = "PAYMENT_STARTED",
PAYMENT_IN_PROGRESS = "PAYMENT_IN_PROGRESS",
PAYMENT_FAILED = "PAYMENT_FAILED",
PAYMENT_EXECUTED = "PAYMENT_EXECUTED",
FIAT_RECEIVED = "FIAT_RECEIVED",
FIAT_SENT = "FIAT_SENT",
EXPIRED = "EXPIRED",
CANCELLED = "CANCELLED",
RELEASING = "RELEASING",
RELEASED = "RELEASED"
}
export declare type TPurchaseExternalId = string;

@@ -46,7 +63,2 @@ export interface IHostConfig {

}
export interface IPurchasePollingCredentials {
token: string;
apiUrl: string;
purchaseExternalId: TPurchaseExternalId;
}
export interface IHostConfigWithWidgetInstanceId extends IHostConfig {

@@ -59,2 +71,3 @@ widgetInstanceId: string;

symbol: string;
type: string;
name: string;

@@ -66,19 +79,16 @@ decimals: number;

endTime: TDateString | null;
/** @deprecated use `asset.address` */
tokenAddress: TAddress | null;
asset: IAssetInfo;
escrowAddress?: TAddress;
receiverAddress: TAddress;
cryptoAmount: TCryptoAmount;
/** @deprecated use `cryptoAmount` */
ethAmount?: TCryptoAmount;
/** @deprecated use `cryptoAmount` */
tokenAmount?: TCryptoAmount;
fiatCurrency: TFiatCurrency;
fiatValue: TFiatValue;
assetExchangeRate: TAssetExchangeRate;
poolFee: TPoolFee;
rampFee: TRampFee;
purchaseHash: TPurchaseHash;
actions: IAction[] | undefined;
baseRampFee: TFiatValue;
networkFee: TFiatValue;
appliedFee: TFiatValue;
paymentMethodType: PaymentMethodName;
finalTxHash?: TFinalTxHash;
createdAt: TDateString;
updatedAt: TDateString;
status: PurchaseStatus;
}

@@ -85,0 +95,0 @@ export interface IAction {

@@ -1,2 +0,2 @@

import { AllWidgetVariants, IHostConfig, TAllEventTypes, TEventListenerDict } from './types';
import { AllWidgetVariants, IHostConfig, TEventListenerDict } from './types';
export declare function getRandomIntString(): string;

@@ -9,3 +9,2 @@ export declare const widgetDesktopWidth = 895;

export declare function initEventListenersDict(): TEventListenerDict;
export declare function countListenersForEvent(listeners: TEventListenerDict, event: TAllEventTypes, internal?: boolean): number;
export declare function determineWidgetVariant(config: IHostConfig): AllWidgetVariants;

@@ -12,0 +11,0 @@ export declare function isHtmlElement(element: Element): element is HTMLElement;

{
"name": "@ramp-network/ramp-instant-sdk",
"version": "2.5.2",
"version": "3.0.0",
"description": "SDK for Ramp Instant",

@@ -5,0 +5,0 @@ "keywords": [],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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