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

forage-js-sdk

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forage-js-sdk - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

2

package.json
{
"name": "forage-js-sdk",
"version": "1.0.2",
"version": "1.0.3",
"private": false,

@@ -5,0 +5,0 @@ "engines": {

@@ -58,3 +58,12 @@ import { EnvironmentOptions } from '../../types/internal';

protected _getCommonIframeConfig: () => IframeConfig;
/**
* @description We wait for the forage-input-iframe to send an INPUT_HELLO signal
* before we send the INITIALIZE_IFRAME command
* We log a warning if it takes longer than MOUNT_TIMEOUT_WARNING_MS seconds
*
* @throws {ForageError} We reject with timeout error if it takes
* longer than MOUNT_TIMEOUT_FATAL_ERROR_MS seconds
* to receive the INPUT_HELLO command
*/
private _waitForHelloCmd;
}

@@ -53,2 +53,4 @@ "use strict";

var mappings_1 = require("./mappings");
var MOUNT_TIMEOUT_WARNING_MS = 7 * 1000; // 7 seconds
var MOUNT_TIMEOUT_FATAL_ERROR_MS = 30 * 1000; // 30 seconds
var ForageElement = /** @class */ (function () {

@@ -94,4 +96,5 @@ function ForageElement(_a) {

_this._htmlContainerElement = htmlContainerElement;
// we send before appending the iframe to the DOM to guarantee that we are listening
// for INPUT_HELLO before the iframe sends it
// we call _waitForHelloCmd before appending the iframe to the DOM
// to guarantee that we are listening for the INPUT_HELLO command
// before the input iframe sends the INPUT_HELLO command
_this._waitForHelloCmd()

@@ -105,2 +108,7 @@ // Now we can send then initialize command

console.error('Failed to initialize iframe', err);
})
.finally(function () {
// a last-ditch attempt: we try to send the initialize command even
// even if we fail to receive the hello command
_this._sendInitializeIframeCmd(_this._getCommonIframeConfig());
});

@@ -161,10 +169,15 @@ _this._htmlContainerElement.appendChild(_this._forageInputIframe);

};
// we wait for the forage-input-iframe to send a HELLO signal
// before we send the initialize command
// rejects with timeout error if it takes longer than 6 seconds
// to receive the signal
/**
* @description We wait for the forage-input-iframe to send an INPUT_HELLO signal
* before we send the INITIALIZE_IFRAME command
* We log a warning if it takes longer than MOUNT_TIMEOUT_WARNING_MS seconds
*
* @throws {ForageError} We reject with timeout error if it takes
* longer than MOUNT_TIMEOUT_FATAL_ERROR_MS seconds
* to receive the INPUT_HELLO command
*/
this._waitForHelloCmd = function () { return __awaiter(_this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_a) {
return [2 /*return*/, (0, promise_1.promiseTimeout)(new Promise(function (res) {
return [2 /*return*/, (0, promise_1.promiseTimeoutWithLogWarning)(new Promise(function (res) {
// wait for child iframe to be ready to listen

@@ -189,3 +202,7 @@ window.addEventListener('message', function (event) {

});
}), 6000, 'load-iframe')];
}), {
event: 'load-input-iframe',
warningTimeoutMs: MOUNT_TIMEOUT_WARNING_MS,
fatalDeadlineMs: MOUNT_TIMEOUT_FATAL_ERROR_MS
})];
});

@@ -192,0 +209,0 @@ }); };

@@ -17,11 +17,11 @@ import { EnvironmentOptions } from '../../types/internal';

/**
* @docs https://docs.joinforage.app/reference/store-an-ebt-card#submit-the-element
* @docs https://docs.joinforage.app/reference/store-an-ebt-card#submit-a-forageebtcardnumberelement
*/
tokenizeEbtCardNumber(element: ForageEbtCardNumberElement): Promise<TokenizedEbtCardResult>;
/**
* @docs https://docs.joinforage.app/reference/check-the-balance-of-an-ebt-card#submit-the-element
* @docs https://docs.joinforage.app/reference/check-the-balance-of-an-ebt-card#submit-a-forageebtbalanceelement
*/
createEbtPinBalanceCheck(element: ForageEbtBalanceElement, paymentMethodRef: string): Promise<EbtBalanceResult>;
/**
* @docs https://docs.joinforage.app/reference/accept-ebt-tender#submit-the-element
* @docs https://docs.joinforage.app/reference/capture-ebt-payment#submit-a-forageebtpaymentelement
*/

@@ -31,2 +31,5 @@ captureEbtPinPayment(element: ForageEbtPaymentElement, paymentRef: string): Promise<EbtPaymentCaptureResult>;

export interface ForageConfig {
/**
* @docs https://docs.joinforage.app/reference/initialize-forage-js#forageconfig-fields
*/
fnsNumber: string;

@@ -33,0 +36,0 @@ sessionToken: SessionToken;

@@ -23,3 +23,3 @@ export declare enum StatusCode {

*
* @docs https://docs.joinforage.app/docs/error-codes#error-codes
* @docs https://docs.joinforage.app/reference/errors-1#error-codes
*/

@@ -26,0 +26,0 @@ code: string;

/**
* Returns a new promise that rejects with a timeout error if the provided promise
* Returns a new promise that rejects with a 500 ForageError if the provided promise
* does not resolve or reject within the given timeframe.

@@ -11,1 +11,28 @@ *

export declare const promiseTimeout: <T>(promise: Promise<T>, deadlineMs: number, event: string) => Promise<T>;
/**
* @description Logs an error if the promise takes longer than `deadlineMs` to resolve
* or reject.
*
* @param promise - the promise that we're attempting to resolve
* @param deadlineMs - the deadline/timeout in milliseconds
* @param event - the name of the event associated with the promise
* @returns the promise that we're attempting to resolve
*/
export declare const promiseTimeoutLogWarning: <T>(promise: Promise<T>, deadlineMs: number, event: string) => Promise<T>;
/**
* Returns a new promise that rejects with a 504 ForageError if the provided promise
* does not resolve or reject within the given timeframe. Logs an error if the promise
* takes longer than `warningTimeoutMs` to resolve or reject.
*
* @description equivalent to wrapping a promise in a promiseTimeout and promiseTimeoutLogWarning
* @param promise - the promise that we're attempting to resolve
* @param options.warningTimeoutMs - the warning timeout in milliseconds for the promise
* @param options.fatalDeadlineMs - the fatal timeout in milliseconds for the promise
* @param options.event - the name of the event associated with the promise
* @returns the promise that we're attempting to resolve
*/
export declare const promiseTimeoutWithLogWarning: <T>(promise: Promise<T>, options: {
warningTimeoutMs: number;
fatalDeadlineMs: number;
event: string;
}) => Promise<T>;

@@ -39,5 +39,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.promiseTimeout = void 0;
exports.promiseTimeoutWithLogWarning = exports.promiseTimeoutLogWarning = exports.promiseTimeout = void 0;
var interfaces_1 = require("../interfaces");
/**
* Returns a new promise that rejects with a timeout error if the provided promise
* Returns a new promise that rejects with a 500 ForageError if the provided promise
* does not resolve or reject within the given timeframe.

@@ -55,3 +56,12 @@ *

timeoutHandle = setTimeout(function () {
reject(new Error("TimeoutError: Failed to fullfil or reject promise after ".concat(deadlineMs / 1000, "s for event ").concat(event)));
var forageError = {
errors: [
{
code: 'unknown_server_error',
httpStatusCode: interfaces_1.StatusCode.ServerErrors,
message: "TimeoutError: Failed to fullfil or reject promise after ".concat(deadlineMs / 1000, "s for event ").concat(event)
}
]
};
reject(forageError);
}, deadlineMs);

@@ -66,2 +76,55 @@ });

exports.promiseTimeout = promiseTimeout;
/**
* @description Logs an error if the promise takes longer than `deadlineMs` to resolve
* or reject.
*
* @param promise - the promise that we're attempting to resolve
* @param deadlineMs - the deadline/timeout in milliseconds
* @param event - the name of the event associated with the promise
* @returns the promise that we're attempting to resolve
*/
var promiseTimeoutLogWarning = function (promise, deadlineMs, event) { return __awaiter(void 0, void 0, void 0, function () {
var timeout;
return __generator(this, function (_a) {
timeout = setTimeout(function () {
// We use the `console.error` function instead of `console.warn` because we want to
// make sure that we get notified of these errors in Sentry.
// eslint-disable-next-line no-console
console.error("Timeout warning: ".concat(event, " is taking longer than ").concat(deadlineMs / 1000, "s"));
}, deadlineMs);
return [2 /*return*/, new Promise(function (res, rej) {
promise
.then(function (result) {
clearTimeout(timeout);
res(result);
})
.catch(function (err) {
clearTimeout(timeout);
rej(err);
});
})];
});
}); };
exports.promiseTimeoutLogWarning = promiseTimeoutLogWarning;
/**
* Returns a new promise that rejects with a 504 ForageError if the provided promise
* does not resolve or reject within the given timeframe. Logs an error if the promise
* takes longer than `warningTimeoutMs` to resolve or reject.
*
* @description equivalent to wrapping a promise in a promiseTimeout and promiseTimeoutLogWarning
* @param promise - the promise that we're attempting to resolve
* @param options.warningTimeoutMs - the warning timeout in milliseconds for the promise
* @param options.fatalDeadlineMs - the fatal timeout in milliseconds for the promise
* @param options.event - the name of the event associated with the promise
* @returns the promise that we're attempting to resolve
*/
var promiseTimeoutWithLogWarning = function (promise, options) { return __awaiter(void 0, void 0, void 0, function () {
var warningTimeoutMs, fatalDeadlineMs, event, warningTimeoutPromise;
return __generator(this, function (_a) {
warningTimeoutMs = options.warningTimeoutMs, fatalDeadlineMs = options.fatalDeadlineMs, event = options.event;
warningTimeoutPromise = (0, exports.promiseTimeoutLogWarning)(promise, warningTimeoutMs, event);
return [2 /*return*/, (0, exports.promiseTimeout)(warningTimeoutPromise, fatalDeadlineMs, event)];
});
}); };
exports.promiseTimeoutWithLogWarning = promiseTimeoutWithLogWarning;
//# sourceMappingURL=promise.js.map

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