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

@formsort/custom-question-api

Package Overview
Dependencies
Maintainers
6
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formsort/custom-question-api - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

7

lib/index.d.ts
import { AnswerSemanticType } from '@formsort/constants';
declare type AnswerPrimitiveType = number | string | boolean | object;
declare type AnswerType = AnswerPrimitiveType | AnswerPrimitiveType[];
export declare type AnswerPrimitiveType = number | string | boolean | object;
export declare type AnswerType = AnswerPrimitiveType | AnswerPrimitiveType[];
export declare const setQuestionSize: (width?: string | number | undefined, height?: string | number | undefined) => void;

@@ -8,3 +8,3 @@ export declare const getAnswerValue: <T extends AnswerType = AnswerType>() => Promise<T | undefined>;

export declare const getAllAnswerValues: () => Promise<{
[key: string]: string | number | boolean | object | AnswerPrimitiveType[] | undefined;
[key: string]: AnswerType | undefined;
}>;

@@ -14,2 +14,1 @@ export declare const getResponderUuid: () => Promise<string>;

export declare const setAnswerValue: (value: AnswerType) => void;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var constants_1 = require("@formsort/constants");
var utils_1 = require("./utils");
exports.setQuestionSize = function (width, height) {
utils_1.sendMessageToWindowParent(constants_1.CustomQuestionMessage.SET_QUESTION_SIZE_MSG, {
width: width,
height: height,
exports.setAnswerValue = exports.clearAnswerValue = exports.getResponderUuid = exports.getAllAnswerValues = exports.getSemanticAnswerValue = exports.getAnswerValue = exports.setQuestionSize = void 0;
const constants_1 = require("@formsort/constants");
const utils_1 = require("./utils");
const setQuestionSize = (width, height) => {
(0, utils_1.sendMessageToWindowParent)(constants_1.CustomQuestionMessage.SET_QUESTION_SIZE_MSG, {
width,
height,
});
};
exports.getAnswerValue = function () {
return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_ANSWER_VALUE_MSG, constants_1.CustomQuestionMessage.SET_ANSWER_VALUE_MSG);
exports.setQuestionSize = setQuestionSize;
const getAnswerValue = () => (0, utils_1.getValueFromWindowParent)(constants_1.CustomQuestionMessage.REQUEST_ANSWER_VALUE_MSG, constants_1.CustomQuestionMessage.SET_ANSWER_VALUE_MSG);
exports.getAnswerValue = getAnswerValue;
const getSemanticAnswerValue = (semanticType) => (0, utils_1.getValueFromWindowParent)(constants_1.CustomQuestionMessage.REQUEST_SEMANTIC_ANSWER_VALUE_MSG, constants_1.CustomQuestionMessage.SET_SEMANTIC_ANSWER_VALUE_MSG, semanticType);
exports.getSemanticAnswerValue = getSemanticAnswerValue;
const getAllAnswerValues = () => (0, utils_1.getValueFromWindowParent)(constants_1.CustomQuestionMessage.REQUEST_ANSWERS_MSG, constants_1.CustomQuestionMessage.SET_ANSWERS_MSG);
exports.getAllAnswerValues = getAllAnswerValues;
const getResponderUuid = () => (0, utils_1.getValueFromWindowParent)(constants_1.CustomQuestionMessage.REQUEST_RESPONDER_UUID_MSG, constants_1.CustomQuestionMessage.SET_RESPONDER_UUID_MSG);
exports.getResponderUuid = getResponderUuid;
const clearAnswerValue = () => {
(0, utils_1.sendMessageToWindowParent)(constants_1.CustomQuestionMessage.CLEAR_ANSWER_VALUE_MSG);
};
exports.getSemanticAnswerValue = function (semanticType) {
return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_SEMANTIC_ANSWER_VALUE_MSG, constants_1.CustomQuestionMessage.SET_SEMANTIC_ANSWER_VALUE_MSG, semanticType);
exports.clearAnswerValue = clearAnswerValue;
const setAnswerValue = (value) => {
(0, utils_1.sendMessageToWindowParent)(constants_1.CustomQuestionMessage.SET_ANSWER_VALUE_MSG, value);
};
exports.getAllAnswerValues = function () {
return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_ANSWERS_MSG, constants_1.CustomQuestionMessage.SET_ANSWERS_MSG);
};
exports.getResponderUuid = function () {
return utils_1.getValueFromWindowParent(constants_1.CustomQuestionMessage.REQUEST_RESPONDER_UUID_MSG, constants_1.CustomQuestionMessage.SET_RESPONDER_UUID_MSG);
};
exports.clearAnswerValue = function () {
utils_1.sendMessageToWindowParent(constants_1.CustomQuestionMessage.CLEAR_ANSWER_VALUE_MSG);
};
exports.setAnswerValue = function (value) {
utils_1.sendMessageToWindowParent(constants_1.CustomQuestionMessage.SET_ANSWER_VALUE_MSG, value);
};
exports.setAnswerValue = setAnswerValue;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var WindowMessageEmitter_1 = require("./WindowMessageEmitter");
var emitterSingleton;
exports.getEmitter = function () {
exports.getValueFromWindowParent = exports.sendMessageToWindowParent = exports.getEmitter = void 0;
const tslib_1 = require("tslib");
const WindowMessageEmitter_1 = tslib_1.__importDefault(require("./WindowMessageEmitter"));
let emitterSingleton;
const getEmitter = () => {
if (!emitterSingleton) {

@@ -11,3 +13,4 @@ emitterSingleton = new WindowMessageEmitter_1.default();

};
exports.sendMessageToWindowParent = function (type, payload, requestId) {
exports.getEmitter = getEmitter;
const sendMessageToWindowParent = (type, payload, requestId) => {
if (!window.parent) {

@@ -17,19 +20,21 @@ throw new Error('Custom questions must run within a Formsort flow custom question to work.');

window.parent.postMessage({
type: type,
payload: payload,
requestId: requestId,
type,
payload,
requestId,
}, '*');
};
exports.getValueFromWindowParent = function (requestEventType, responseEventType, requestPayload) {
var requestId = Math.random().toString();
return new Promise(function (resolve) {
var onMessage = function (value, returningRequestId) {
exports.sendMessageToWindowParent = sendMessageToWindowParent;
const getValueFromWindowParent = (requestEventType, responseEventType, requestPayload) => {
const requestId = Math.random().toString();
return new Promise((resolve) => {
const onMessage = (value, returningRequestId) => {
if (requestId === returningRequestId) {
resolve(value);
exports.getEmitter().removeListener(responseEventType, onMessage);
resolve(value); // eslint-disable-line @typescript-eslint/no-unsafe-argument
(0, exports.getEmitter)().removeListener(responseEventType, onMessage);
}
};
exports.getEmitter().on(responseEventType, onMessage);
exports.sendMessageToWindowParent(requestEventType, requestPayload, requestId);
(0, exports.getEmitter)().on(responseEventType, onMessage);
(0, exports.sendMessageToWindowParent)(requestEventType, requestPayload, requestId);
});
};
exports.getValueFromWindowParent = getValueFromWindowParent;
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var events_1 = require("events");
var constants_1 = require("@formsort/constants");
var EVENTS_TO_EMIT = new Set([
const events_1 = require("events");
const constants_1 = require("@formsort/constants");
const EVENTS_TO_EMIT = new Set([
constants_1.CustomQuestionMessage.SET_ANSWERS_MSG,

@@ -24,18 +11,16 @@ constants_1.CustomQuestionMessage.SET_ANSWER_VALUE_MSG,

]);
var WindowMessageEventsEmitter = /** @class */ (function (_super) {
__extends(WindowMessageEventsEmitter, _super);
function WindowMessageEventsEmitter() {
var _this = _super.call(this) || this;
_this.onWindowMessage = function (e) {
var _a = e.data, type = _a.type, payload = _a.payload, requestId = _a.requestId;
if (!type || !EVENTS_TO_EMIT.has(type)) {
class WindowMessageEventsEmitter extends events_1.EventEmitter {
constructor() {
super();
this.onWindowMessage = (e) => {
const { type, payload, requestId } = e.data;
if (typeof type !== 'string' ||
!EVENTS_TO_EMIT.has(type)) {
return;
}
_this.emit(type, payload, requestId);
this.emit(type, payload, requestId);
};
window.addEventListener('message', _this.onWindowMessage);
return _this;
window.addEventListener('message', this.onWindowMessage);
}
return WindowMessageEventsEmitter;
}(events_1.EventEmitter));
}
exports.default = WindowMessageEventsEmitter;
{
"name": "@formsort/custom-question-api",
"version": "0.1.0",
"version": "0.1.1",
"description": "Helpers for implementing custom questions in Formsort",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "tsc",
"format": "eslint -c .eslintrc.js --ext .ts,.tsx src --fix",
"lint": "eslint -c .eslintrc.js --ext .ts,.tsx src",
"pretty-check": "prettier --check src",
"prepare": "npm run build",
"prepublishOnly": "npm run lint",
"preversion": "npm run lint",
"version": "npm run format && git add -A src",
"postversion": "git push && git push --tags"
"build": "tsc --project tsconfig.build.json",
"format": "eslint --ext .ts,.tsx src --fix",
"lint": "eslint --ext .ts,.tsx src",
"test": "yarn lint",
"pack": "yarn pack",
"release": "craft prepare --publish"
},
"prepare": "npm run build",
"files": [

@@ -30,3 +30,3 @@ "lib/**/*"

],
"author": "Fil Zembowicz <fil@formsort.com>",
"author": "Formsort Engineering <engineering@formsort.com>",
"license": "MIT",

@@ -40,4 +40,4 @@ "bugs": {

"@types/events": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^4.11.0",
"eslint": "^7.16.0",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"eslint": "^8.12.0",
"eslint-plugin-import": "^2.22.1",

@@ -48,8 +48,8 @@ "eslint-plugin-jsdoc": "^30.7.9",

"prettier": "^2.2.1",
"typescript": "^3.8.3"
"typescript": "^4.6.3"
},
"dependencies": {
"@formsort/constants": "^1.5.0",
"@formsort/constants": "^1.7.0",
"events": "^3.2.0"
}
}

@@ -28,2 +28,8 @@ # @formsort/custom-question-api

```shell
yarn add @formsort/custom-question-api
```
or
```shell
npm install --save @formsort/custom-question-api

@@ -30,0 +36,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