Socket
Socket
Sign inDemoInstall

@oneblink/sdk-core

Package Overview
Dependencies
Maintainers
6
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oneblink/sdk-core - npm Package Compare versions

Comparing version 0.3.6 to 0.4.0-beta.1

dist/conditionalLogicService.d.ts

53

dist/abnService.d.ts
import { ABNRecord } from '@oneblink/types/typescript/misc';
/**
* Attempts to get the most relevant business name from the data returned in an
* `ABNRecord`. Will return `undefined` if a suitable name is not found.
*
* #### Example
*
* ```js
* const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
export declare const getBusinessNameFromABNRecord: (abnRecord: ABNRecord) => string | undefined;
/**
* Get the most relevant business name from the data returned in an `ABNRecord`.
* Will return "Unknown Business Name" if a suitable name is not found.
*
* #### Example
*
* ```js
* const businessName =
* abnService.displayBusinessNameFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
export declare const displayBusinessNameFromABNRecord: (abnRecord: ABNRecord) => string;
/**
* Attempts to get the most recent ABN number from the data returned in an
* `ABNRecord`. Will return `undefined` if an ABN is not found.
*
* #### Example
*
* ```js
* const ABN = abnService.getABNNumberFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
export declare const getABNNumberFromABNRecord: (abnRecord: ABNRecord) => string | undefined;
/**
* Attempts to get the most recent ABN number from the data returned in an
* `ABNRecord`. Will return "Unknown ABN Number" if an ABN is not found.
*
* #### Example
*
* ```js
* const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
export declare const displayABNNumberFromABNRecord: (abnRecord: ABNRecord) => string;

@@ -17,2 +17,15 @@ "use strict";

};
/**
* Attempts to get the most relevant business name from the data returned in an
* `ABNRecord`. Will return `undefined` if a suitable name is not found.
*
* #### Example
*
* ```js
* const businessName = abnService.getBusinessNameFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
const getBusinessNameFromABNRecord = (abnRecord) => {

@@ -38,2 +51,16 @@ var _a, _b;

exports.getBusinessNameFromABNRecord = getBusinessNameFromABNRecord;
/**
* Get the most relevant business name from the data returned in an `ABNRecord`.
* Will return "Unknown Business Name" if a suitable name is not found.
*
* #### Example
*
* ```js
* const businessName =
* abnService.displayBusinessNameFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
const displayBusinessNameFromABNRecord = (abnRecord) => {

@@ -44,2 +71,15 @@ const businessName = (0, exports.getBusinessNameFromABNRecord)(abnRecord);

exports.displayBusinessNameFromABNRecord = displayBusinessNameFromABNRecord;
/**
* Attempts to get the most recent ABN number from the data returned in an
* `ABNRecord`. Will return `undefined` if an ABN is not found.
*
* #### Example
*
* ```js
* const ABN = abnService.getABNNumberFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
const getABNNumberFromABNRecord = (abnRecord) => {

@@ -55,2 +95,15 @@ if (!abnRecord.ABN)

exports.getABNNumberFromABNRecord = getABNNumberFromABNRecord;
/**
* Attempts to get the most recent ABN number from the data returned in an
* `ABNRecord`. Will return "Unknown ABN Number" if an ABN is not found.
*
* #### Example
*
* ```js
* const ABN = abnService.displayABNNumberFromABNRecord(abnRecord)
* ```
*
* @param abnRecord
* @returns
*/
const displayABNNumberFromABNRecord = (abnRecord) => {

@@ -57,0 +110,0 @@ const abnNumber = (0, exports.getABNNumberFromABNRecord)(abnRecord);

28

dist/conditionalLogicService/conditionallyShowElement.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const evaluationService_1 = require("./evaluationService");
const evaluateConditionalPredicate_1 = __importDefault(require("./evaluateConditionalPredicate"));
const getParentFormElements = (formElementsCtrl, childElement) => {

@@ -19,16 +22,8 @@ const parentElement = formElementsCtrl.flattenedElements.find((element) => {

const conditionallyShowByPredicate = (formElementsCtrl, predicate, elementsEvaluated) => {
const predicateElement = formElementsCtrl.flattenedElements.find((element) => {
return element.id === predicate.elementId;
const predicateElement = (0, evaluateConditionalPredicate_1.default)({
predicate,
formElementsCtrl,
});
// If we cant find the element used for the predicate,
// we can check to see if the element being evaluated
// is in a repeatable set and the predicate element is
// in a parent list of elements.
if (!predicateElement) {
if (formElementsCtrl.parentFormElementsCtrl) {
return conditionallyShowByPredicate(formElementsCtrl.parentFormElementsCtrl, predicate, elementsEvaluated);
}
else {
return false;
}
return false;
}

@@ -48,8 +43,3 @@ // Here we will also need to check if the predicate element

// Check to see if the model has one of the valid values to show the element
return (conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated) &&
(0, evaluationService_1.evaluateConditionalPredicate)({
predicate,
submission: formElementsCtrl.model,
predicateElement,
}));
return conditionallyShowElement(formElementsCtrl, predicateElement, elementsEvaluated);
};

@@ -56,0 +46,0 @@ function conditionallyShowElement(formElementsCtrl, elementToEvaluate, elementsEvaluated) {

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const evaluationService_1 = require("./evaluationService");
const evaluateConditionalOptionsPredicate_1 = __importDefault(require("./evaluateConditionalOptionsPredicate"));
const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));

@@ -18,3 +18,3 @@ const handleAttributePredicate = (predicate, model, predicateElement) => {

}
return (0, evaluationService_1.evaluateConditionalOptionsPredicate)({
return (0, evaluateConditionalOptionsPredicate_1.default)({
predicate: {

@@ -25,3 +25,3 @@ type: 'OPTIONS',

},
submission: model,
predicateValue: values,
predicateElement,

@@ -28,0 +28,0 @@ });

@@ -1,10 +0,112 @@

import { FormTypes } from '@oneblink/types';
import { FormElementsCtrl, FormElementsConditionallyShown } from '../types';
declare type ErrorCallback = (error: Error) => void;
declare const generateFormElementsConditionallyShown: ({ formElements, submission, parentFormElementsCtrl, errorCallback, }: {
import { FormTypes, SubmissionTypes } from '@oneblink/types';
export declare type FormElementsConditionallyShown = Record<string, FormElementConditionallyShown>;
export declare type FormElementConditionallyShown = undefined | {
type: 'formElement';
isHidden: boolean;
options?: import('@oneblink/types').FormTypes.ChoiceElementOption[];
} | {
type: 'formElements';
isHidden: boolean;
formElements: FormElementsConditionallyShown | undefined;
} | {
type: 'repeatableSet';
isHidden: boolean;
entries: Record<string, FormElementsConditionallyShown | undefined>;
};
export declare type ErrorCallback = (error: Error) => void;
export declare type FormElementsConditionallyShownParameters = {
/** Form elements to evaluate */
formElements: FormTypes.FormElement[];
submission: Record<string, unknown>;
parentFormElementsCtrl?: FormElementsCtrl['parentFormElementsCtrl'];
errorCallback?: ErrorCallback | undefined;
}) => FormElementsConditionallyShown;
export default generateFormElementsConditionallyShown;
/** Current submission data */
submission: SubmissionTypes.S3SubmissionData['submission'];
/** Optional callback for handling errors caught during the evaluation */
errorCallback?: ErrorCallback;
};
/**
* Given a form element and submission data, evaluate which elements are
* currently shown. The function also takes an optional errorCallback for
* handling errors caught during the evaluation.
*
* #### Example
*
* ```js
* const formElementsConditionallyShown =
* conditionalLogicService.generateFormElementsConditionallyShown({
* submission: {
* radio: ['hide'],
* text: 'hidden text',
* },
* formElements: [
* {
* name: 'radio',
* label: 'Radio',
* type: 'radio',
* required: false,
* id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
* conditionallyShow: false,
* options: [
* {
* id: '9a44e15a-5929-419d-825e-b3dc0a29591f',
* label: 'Show',
* value: 'show',
* },
* {
* id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',
* label: 'Hide',
* value: 'Hide',
* },
* ],
* readOnly: false,
* isDataLookup: false,
* isElementLookup: false,
* buttons: false,
* optionsType: 'CUSTOM',
* conditionallyShowOptions: false,
* },
* {
* name: 'text',
* label: 'Text',
* type: 'text',
* required: false,
* id: '8fbddb41-348d-494c-904b-56a2c4361f13',
* requiresAllConditionallyShowPredicates: false,
* conditionallyShow: true,
* conditionallyShowPredicates: [
* {
* elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
* optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],
* type: 'OPTIONS',
* },
* ],
* readOnly: false,
* isDataLookup: false,
* isElementLookup: false,
* },
* ],
* parentFormElementsCtrl: undefined,
* errorCallback: (error) => {
* //do something with the error here
* console.error(error)
* },
* })
* ```
*
* The above example returns an object like below
*
* ```json
* {
* "radio": {
* "isHidden": false,
* "type": "formElement"
* },
* "text": {
* "isHidden": true,
* "type": "formElement"
* }
* }
* ```
*
* @param parameters
* @returns
*/
export declare function generateFormElementsConditionallyShown(parameters: FormElementsConditionallyShownParameters): FormElementsConditionallyShown;

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.generateFormElementsConditionallyShown = void 0;
const formElementsService_1 = require("../formElementsService");

@@ -29,3 +30,3 @@ const conditionallyShowElement_1 = __importDefault(require("./conditionallyShowElement"));

};
const generateFormElementsConditionallyShown = ({ formElements, submission, parentFormElementsCtrl, errorCallback, }) => {
const generateFormElementsConditionallyShownWithParent = ({ formElements, submission, parentFormElementsCtrl, errorCallback, }) => {
const formElementsCtrl = {

@@ -80,3 +81,3 @@ flattenedElements: (0, formElementsService_1.flattenFormElements)(formElements),

isHidden: !handleConditionallyShowElement(formElementsCtrl, element, errorCallback),
formElements: generateFormElementsConditionallyShown({
formElements: generateFormElementsConditionallyShownWithParent({
formElements: element.elements || [],

@@ -99,3 +100,3 @@ submission: nestedModel || {},

result[index.toString()] =
generateFormElementsConditionallyShown({
generateFormElementsConditionallyShownWithParent({
formElements: element.elements,

@@ -141,3 +142,93 @@ submission: entry,

};
exports.default = generateFormElementsConditionallyShown;
/**
* Given a form element and submission data, evaluate which elements are
* currently shown. The function also takes an optional errorCallback for
* handling errors caught during the evaluation.
*
* #### Example
*
* ```js
* const formElementsConditionallyShown =
* conditionalLogicService.generateFormElementsConditionallyShown({
* submission: {
* radio: ['hide'],
* text: 'hidden text',
* },
* formElements: [
* {
* name: 'radio',
* label: 'Radio',
* type: 'radio',
* required: false,
* id: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
* conditionallyShow: false,
* options: [
* {
* id: '9a44e15a-5929-419d-825e-b3dc0a29591f',
* label: 'Show',
* value: 'show',
* },
* {
* id: 'd776ed42-072c-4bf8-9879-874b2bef85d3',
* label: 'Hide',
* value: 'Hide',
* },
* ],
* readOnly: false,
* isDataLookup: false,
* isElementLookup: false,
* buttons: false,
* optionsType: 'CUSTOM',
* conditionallyShowOptions: false,
* },
* {
* name: 'text',
* label: 'Text',
* type: 'text',
* required: false,
* id: '8fbddb41-348d-494c-904b-56a2c4361f13',
* requiresAllConditionallyShowPredicates: false,
* conditionallyShow: true,
* conditionallyShowPredicates: [
* {
* elementId: '5ef3beb8-8ac8-4c8d-9fd3-d8197113bf54',
* optionIds: ['9a44e15a-5929-419d-825e-b3dc0a29591f'],
* type: 'OPTIONS',
* },
* ],
* readOnly: false,
* isDataLookup: false,
* isElementLookup: false,
* },
* ],
* parentFormElementsCtrl: undefined,
* errorCallback: (error) => {
* //do something with the error here
* console.error(error)
* },
* })
* ```
*
* The above example returns an object like below
*
* ```json
* {
* "radio": {
* "isHidden": false,
* "type": "formElement"
* },
* "text": {
* "isHidden": true,
* "type": "formElement"
* }
* }
* ```
*
* @param parameters
* @returns
*/
function generateFormElementsConditionallyShown(parameters) {
return generateFormElementsConditionallyShownWithParent(parameters);
}
exports.generateFormElementsConditionallyShown = generateFormElementsConditionallyShown;
//# sourceMappingURL=generateFormElementsConditionallyShown.js.map

@@ -0,1 +1,15 @@

/**
* Attempts to get the content disposition for the header by compiling a string
* of UTF-8 formatting based on the file name.
*
* #### Example
*
* ```js
* const contentDisposition =
* fileUploadService.getContentDisposition(fileName)
* ```
*
* @param filename The name of the file being uploaded
* @returns
*/
export declare function getContentDisposition(filename: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContentDisposition = void 0;
/**
* Attempts to get the content disposition for the header by compiling a string
* of UTF-8 formatting based on the file name.
*
* #### Example
*
* ```js
* const contentDisposition =
* fileUploadService.getContentDisposition(fileName)
* ```
*
* @param filename The name of the file being uploaded
* @returns
*/
function getContentDisposition(filename) {

@@ -5,0 +19,0 @@ return `attachment; filename*=UTF-8''${encodeURIComponent(filename)}`;

import { FormTypes } from '@oneblink/types';
/**
* Iterate over all form elements, also iterating over nested form element (e.g.
* page elements).
*
* #### Example
*
* ```js
* formElementsService.forEachFormElement(form.elements, (formElement) => {
* // do something with formElement
* })
* ```
*
* @param elements The form elements to iterate over
* @param forEach Function to execute on each form element
*/
declare function forEachFormElement(elements: FormTypes.FormElement[], forEach: (element: FormTypes.FormElement, elements: FormTypes.FormElement[]) => void): void;
/**
* Iterate over all form elements that have options (e.g. `'select'` type
* elements), also iterating over nested form element (e.g. page elements).
*
* #### Example
*
* ```js
* formElementsService.forEachFormElementWithOptions(
* form.elements,
* (formElementWithOptions) => {
* // do something with formElementWithOptions
* },
* )
* ```
*
* @param elements The form elements to iterate over
* @param forEach Function to execute on each form element with options
*/
declare function forEachFormElementWithOptions(elements: FormTypes.FormElement[], forEach: (elementWithOptions: FormTypes.FormElementWithOptions, elements: FormTypes.FormElement[]) => void): void;
/**
* Iterate over all form elements and return an element that matches a
* predicate, also iterating over nested form element (e.g. page elements). Will
* return `undefined` if no matching element is found.
*
* #### Example
*
* ```js
* const formElement = formElementsService.findFormElement(
* form.elements,
* (formElement) => {
* return formElement.id === '123-abc'
* },
* )
* ```
*
* @param elements The form elements to iterate over
* @param predicate Predicate function to execute on each form element
* @param parentElements
* @returns
*/
declare function findFormElement(elements: FormTypes.FormElement[], predicate: (element: FormTypes.FormElement, elements: FormTypes.FormElement[]) => boolean, parentElements?: FormTypes.FormElement[]): FormTypes.FormElement | void;
/**
* Parse unknown data as valid options for a forms element. This will always
* return an Array of valid options.
*
* #### Example
*
* ```js
* const options = formElementsService.parseFormElementOptionsSet(data)
* // "options" are valid for a form element
* ```
*
* @param data
* @returns
*/
declare function parseFormElementOptionsSet(data: unknown): FormTypes.ChoiceElementOption[];
/**
* Takes the nested definition structure and returns all form elements as 1d array.
*
* #### Example
*
* ```js
* const flattenedElements = formElementsService.flattenFormElements(
* form.elements,
* )
* ```
*
* @param elements
* @returns
*/
declare function flattenFormElements(elements: FormTypes.FormElement[]): FormTypes.FormElement[];
declare function getRootElementValueById(formElementId: string, formElements: FormTypes.FormElement[], submission: {
readonly [key: string]: unknown;
}): unknown;
export { getRootElementValueById, forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, };
export { forEachFormElement, forEachFormElementWithOptions, findFormElement, parseFormElementOptionsSet, flattenFormElements, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = exports.getRootElementValueById = void 0;
exports.flattenFormElements = exports.parseFormElementOptionsSet = exports.findFormElement = exports.forEachFormElementWithOptions = exports.forEachFormElement = void 0;
/**
* Iterate over all form elements, also iterating over nested form element (e.g.
* page elements).
*
* #### Example
*
* ```js
* formElementsService.forEachFormElement(form.elements, (formElement) => {
* // do something with formElement
* })
* ```
*
* @param elements The form elements to iterate over
* @param forEach Function to execute on each form element
*/
function forEachFormElement(elements, forEach) {

@@ -11,2 +26,20 @@ findFormElement(elements, (formElement, parentElements) => {

exports.forEachFormElement = forEachFormElement;
/**
* Iterate over all form elements that have options (e.g. `'select'` type
* elements), also iterating over nested form element (e.g. page elements).
*
* #### Example
*
* ```js
* formElementsService.forEachFormElementWithOptions(
* form.elements,
* (formElementWithOptions) => {
* // do something with formElementWithOptions
* },
* )
* ```
*
* @param elements The form elements to iterate over
* @param forEach Function to execute on each form element with options
*/
function forEachFormElementWithOptions(elements, forEach) {

@@ -25,2 +58,23 @@ findFormElement(elements, (formElement, parentElements) => {

exports.forEachFormElementWithOptions = forEachFormElementWithOptions;
/**
* Iterate over all form elements and return an element that matches a
* predicate, also iterating over nested form element (e.g. page elements). Will
* return `undefined` if no matching element is found.
*
* #### Example
*
* ```js
* const formElement = formElementsService.findFormElement(
* form.elements,
* (formElement) => {
* return formElement.id === '123-abc'
* },
* )
* ```
*
* @param elements The form elements to iterate over
* @param predicate Predicate function to execute on each form element
* @param parentElements
* @returns
*/
function findFormElement(elements, predicate, parentElements = []) {

@@ -48,2 +102,16 @@ for (const element of elements) {

exports.findFormElement = findFormElement;
/**
* Parse unknown data as valid options for a forms element. This will always
* return an Array of valid options.
*
* #### Example
*
* ```js
* const options = formElementsService.parseFormElementOptionsSet(data)
* // "options" are valid for a form element
* ```
*
* @param data
* @returns
*/
function parseFormElementOptionsSet(data) {

@@ -85,2 +153,16 @@ if (!Array.isArray(data)) {

exports.parseFormElementOptionsSet = parseFormElementOptionsSet;
/**
* Takes the nested definition structure and returns all form elements as 1d array.
*
* #### Example
*
* ```js
* const flattenedElements = formElementsService.flattenFormElements(
* form.elements,
* )
* ```
*
* @param elements
* @returns
*/
function flattenFormElements(elements) {

@@ -99,16 +181,2 @@ return elements.reduce((flattenedElements, element) => {

exports.flattenFormElements = flattenFormElements;
function getRootElementValueById(formElementId, formElements, submission) {
for (const formElement of formElements) {
if (formElement.type === 'page' || formElement.type === 'section') {
const value = getRootElementValueById(formElementId, formElement.elements, submission);
if (value !== undefined) {
return value;
}
}
else if (formElement.id === formElementId) {
return submission[formElement.name];
}
}
}
exports.getRootElementValueById = getRootElementValueById;
//# sourceMappingURL=formElementsService.js.map

@@ -0,9 +1,91 @@

/**
* ## Form Elements Service
*
* Helper functions for handling form elements
*
* ```js
* import { formElementsService } from '@oneblink/sdk-core'
* ```
*/
export * as formElementsService from './formElementsService';
/**
* ## Conditional Logic Service
*
* Helper functions for handling conditional logic
*
* ```js
* import { conditionalLogicService } from '@oneblink/sdk-core'
* ```
*/
export * as conditionalLogicService from './conditionalLogicService';
import replaceCustomValues, { getElementSubmissionValue } from './replaceCustomValues';
/**
* ## Submission Service
*
* Helper functions for handling form submission data
*
* ```js
* import { submissionService } from '@oneblink/sdk-core'
* ```
*/
export * as submissionService from './submissionService';
/**
* ## Submission Service
*
* Helper functions for casting types
*
* ```js
* import { typeCastService } from '@oneblink/sdk-core'
* ```
*/
export * as typeCastService from './typeCastService';
/**
* ## User Service
*
* Helper functions for handling users
*
* ```js
* import { userService } from '@oneblink/sdk-core'
* ```
*/
export * as userService from './userService';
/**
* ## ABN Service
*
* Helper functions for handling ABN Records
*
* ```js
* import { abnService } from '@oneblink/sdk-core'
* ```
*/
export * as abnService from './abnService';
export { validatePaymentAmount } from './paymentAmountValidation';
export { getContentDisposition } from './fileUploadService';
export { replaceCustomValues, getElementSubmissionValue };
/**
* ## Payment Service
*
* Helper functions for payments
*
* ```js
* import { paymentService } from '@oneblink/sdk-core'
* ```
*/
export * as paymentService from './paymentService';
/**
* ## Scheduling Service
*
* Helper functions for scheduling
*
* ```js
* import { schedulingService } from '@oneblink/sdk-core'
* ```
*/
export * as schedulingService from './schedulingService';
/**
* ## File Upload Service
*
* Helper functions for handling file uploads
*
* ```js
* import { fileUploadService } from '@oneblink/sdk-core'
* ```
*/
export * as fileUploadService from './fileUploadService';
export * from '@oneblink/types';
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -21,16 +25,98 @@ if (k2 === undefined) k2 = k;

};
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getElementSubmissionValue = exports.replaceCustomValues = exports.getContentDisposition = exports.validatePaymentAmount = exports.abnService = exports.userService = exports.typeCastService = exports.conditionalLogicService = exports.formElementsService = void 0;
exports.fileUploadService = exports.schedulingService = exports.paymentService = exports.abnService = exports.userService = exports.typeCastService = exports.submissionService = exports.conditionalLogicService = exports.formElementsService = void 0;
/**
* ## Form Elements Service
*
* Helper functions for handling form elements
*
* ```js
* import { formElementsService } from '@oneblink/sdk-core'
* ```
*/
exports.formElementsService = __importStar(require("./formElementsService"));
/**
* ## Conditional Logic Service
*
* Helper functions for handling conditional logic
*
* ```js
* import { conditionalLogicService } from '@oneblink/sdk-core'
* ```
*/
exports.conditionalLogicService = __importStar(require("./conditionalLogicService"));
const replaceCustomValues_1 = __importStar(require("./replaceCustomValues"));
exports.replaceCustomValues = replaceCustomValues_1.default;
Object.defineProperty(exports, "getElementSubmissionValue", { enumerable: true, get: function () { return replaceCustomValues_1.getElementSubmissionValue; } });
/**
* ## Submission Service
*
* Helper functions for handling form submission data
*
* ```js
* import { submissionService } from '@oneblink/sdk-core'
* ```
*/
exports.submissionService = __importStar(require("./submissionService"));
/**
* ## Submission Service
*
* Helper functions for casting types
*
* ```js
* import { typeCastService } from '@oneblink/sdk-core'
* ```
*/
exports.typeCastService = __importStar(require("./typeCastService"));
/**
* ## User Service
*
* Helper functions for handling users
*
* ```js
* import { userService } from '@oneblink/sdk-core'
* ```
*/
exports.userService = __importStar(require("./userService"));
/**
* ## ABN Service
*
* Helper functions for handling ABN Records
*
* ```js
* import { abnService } from '@oneblink/sdk-core'
* ```
*/
exports.abnService = __importStar(require("./abnService"));
var paymentAmountValidation_1 = require("./paymentAmountValidation");
Object.defineProperty(exports, "validatePaymentAmount", { enumerable: true, get: function () { return paymentAmountValidation_1.validatePaymentAmount; } });
var fileUploadService_1 = require("./fileUploadService");
Object.defineProperty(exports, "getContentDisposition", { enumerable: true, get: function () { return fileUploadService_1.getContentDisposition; } });
/**
* ## Payment Service
*
* Helper functions for payments
*
* ```js
* import { paymentService } from '@oneblink/sdk-core'
* ```
*/
exports.paymentService = __importStar(require("./paymentService"));
/**
* ## Scheduling Service
*
* Helper functions for scheduling
*
* ```js
* import { schedulingService } from '@oneblink/sdk-core'
* ```
*/
exports.schedulingService = __importStar(require("./schedulingService"));
/**
* ## File Upload Service
*
* Helper functions for handling file uploads
*
* ```js
* import { fileUploadService } from '@oneblink/sdk-core'
* ```
*/
exports.fileUploadService = __importStar(require("./fileUploadService"));
__exportStar(require("@oneblink/types"), exports);
//# sourceMappingURL=index.js.map
import { FormTypes, SubmissionTypes } from '@oneblink/types';
declare type CustomValuesOptions = {
export declare type CustomValuesOptions = {
form: FormTypes.Form;

@@ -13,2 +13,46 @@ externalId?: string;

};
/**
* Function to get the display value of a property in submission
*
* #### Example
*
* ```typescript
*
* const result = submissionService.getElementSubmissionValue({
* propertyName: 'search',
* submission: {
* search: 'Entered By User',
* },
* formElements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* formatNumber: (value) => Number(value).toString(),
* formatCurrency: (value) => Number(value).toFixed(2),
* }: {
* propertyName: string
* formElements: FormTypes.FormElement[]
* submission: SubmissionTypes.S3SubmissionData['submission']
* formatDate: (value: string) => string
* formatTime: (value: string) => string
* formatNumber: (value: number) => string
* formatCurrency: (value: number) => string
* })
* ```
*
* @param options
* @returns
*/
export declare function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }: {

@@ -23,5 +67,56 @@ propertyName: string;

}): unknown;
export default function replaceCustomValues(text: string, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }: CustomValuesOptions & {
/**
* Function to replace a custom values in text
*
* #### Example
*
* ```js
* const result = submissionService.replaceCustomValues(
* 'https://example.com/path?submissionId={SUBMISSION_ID}&externalId={EXTERNAL_ID}&search{ELEMENT:search}',
* {
* submissionId: 'abc-123',
* submissionTimestamp: '2021-07-02T02:19:13.670Z',
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* submission: {
* search: 'Entered By User',
* },
* form: {
* id: 1,
* name: 'Form',
* organisationId: '',
* formsAppEnvironmentId: 1,
* formsAppIds: [],
* isAuthenticated: false,
* isMultiPage: false,
* isInfoPage: false,
* postSubmissionAction: 'FORMS_LIBRARY',
* cancelAction: 'FORMS_LIBRARY',
* submissionEvents: [],
* tags: [],
* elements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* },
* },
* )
* ```
*
* @param text
* @param options
* @returns
*/
export declare function replaceCustomValues(text: string, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }: CustomValuesOptions & {
submission: SubmissionTypes.S3SubmissionData['submission'];
}): string;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getElementSubmissionValue = void 0;
exports.replaceCustomValues = exports.getElementSubmissionValue = void 0;
const formElementsService_1 = require("./formElementsService");

@@ -49,2 +49,46 @@ const abnService_1 = require("./abnService");

];
/**
* Function to get the display value of a property in submission
*
* #### Example
*
* ```typescript
*
* const result = submissionService.getElementSubmissionValue({
* propertyName: 'search',
* submission: {
* search: 'Entered By User',
* },
* formElements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* formatNumber: (value) => Number(value).toString(),
* formatCurrency: (value) => Number(value).toFixed(2),
* }: {
* propertyName: string
* formElements: FormTypes.FormElement[]
* submission: SubmissionTypes.S3SubmissionData['submission']
* formatDate: (value: string) => string
* formatTime: (value: string) => string
* formatNumber: (value: number) => string
* formatCurrency: (value: number) => string
* })
* ```
*
* @param options
* @returns
*/
function getElementSubmissionValue({ propertyName, submission, formElements, formatDate, formatTime, formatNumber, formatCurrency, }) {

@@ -163,2 +207,54 @@ var _a, _b, _c;

}
/**
* Function to replace a custom values in text
*
* #### Example
*
* ```js
* const result = submissionService.replaceCustomValues(
* 'https://example.com/path?submissionId={SUBMISSION_ID}&externalId={EXTERNAL_ID}&search{ELEMENT:search}',
* {
* submissionId: 'abc-123',
* submissionTimestamp: '2021-07-02T02:19:13.670Z',
* formatDate: (value) => new Date(value).toDateString(),
* formatTime: (value) => new Date(value).toTimeString(),
* submission: {
* search: 'Entered By User',
* },
* form: {
* id: 1,
* name: 'Form',
* organisationId: '',
* formsAppEnvironmentId: 1,
* formsAppIds: [],
* isAuthenticated: false,
* isMultiPage: false,
* isInfoPage: false,
* postSubmissionAction: 'FORMS_LIBRARY',
* cancelAction: 'FORMS_LIBRARY',
* submissionEvents: [],
* tags: [],
* elements: [
* {
* id: 'd4135b47-9004-4d75-aeb3-d2f6232da111',
* name: 'search',
* type: 'text',
* label: 'Search',
* readOnly: false,
* required: false,
* conditionallyShow: false,
* requiresAllConditionallyShowPredicates: false,
* isElementLookup: false,
* isDataLookup: false,
* },
* ],
* },
* },
* )
* ```
*
* @param text
* @param options
* @returns
*/
function replaceCustomValues(text, { form, submission, externalId, submissionId, submissionTimestamp, formatDate, formatTime, formatNumber, formatCurrency, previousApprovalId, }) {

@@ -187,3 +283,3 @@ const string = replaceElementValues(text, {

}
exports.default = replaceCustomValues;
exports.replaceCustomValues = replaceCustomValues;
//# sourceMappingURL=replaceCustomValues.js.map
import { FormTypes, SubmissionEventTypes } from '@oneblink/types';
declare function toNamedElement(e: FormTypes.FormElement): FormTypes.FormElementWithName | undefined;
declare type NonNestedElementsFormElement = FormTypes.NonNestedElementsElement | FormTypes.FormElementWithForm;
export declare type NonNestedElementsFormElement = FormTypes.NonNestedElementsElement | FormTypes.FormElementWithForm;
declare const formElements: {

@@ -5,0 +5,0 @@ toOptionsElement: (e: FormTypes.FormElement) => FormTypes.FormElementWithOptions | undefined;

@@ -6,15 +6,1 @@ export declare type FormElementsCtrl = {

};
export declare type FormElementsConditionallyShown = Record<string, FormElementConditionallyShown>;
export declare type FormElementConditionallyShown = undefined | {
type: 'formElement';
isHidden: boolean;
options?: import('@oneblink/types').FormTypes.ChoiceElementOption[];
} | {
type: 'formElements';
isHidden: boolean;
formElements: FormElementsConditionallyShown | undefined;
} | {
type: 'repeatableSet';
isHidden: boolean;
entries: Record<string, FormElementsConditionallyShown | undefined>;
};
import { MiscTypes } from '@oneblink/types';
/**
* Parse a User Profile based on a JWT payload. Will return `undefined` if not a
* valid JWT payload
*
* #### Example
*
* ```js
* import jwtDecode from 'jwt-decode'
*
* const jwtPayload = jwtDecode('a valid token from a user')
* const userProfile = userService.parseUserProfile(jwtPayload)
* if (userProfile) {
* // continue
* }
* ```
*
* @param data An object containing all parameters to be passed to the function
*/
export declare function parseUserProfile(data: unknown): MiscTypes.UserProfile | undefined;
/**
* A friendly `string` that represents the a [User Profile](#user-profile). Uses
* first name, last name, full name, email address or username.
*
* #### Example
*
* ```js
* const userProfile = userService.parseUserProfile(jwtPayload)
* const name = userService.getUserFriendlyName(userProfile)
* if (name) {
* // Display current user's name
* }
* ```
*
* @param userProfile
* @returns
*/
export declare function getUserFriendlyName(userProfile: MiscTypes.UserProfile): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserFriendlyName = exports.parseUserProfile = void 0;
/**
* Parse a User Profile based on a JWT payload. Will return `undefined` if not a
* valid JWT payload
*
* #### Example
*
* ```js
* import jwtDecode from 'jwt-decode'
*
* const jwtPayload = jwtDecode('a valid token from a user')
* const userProfile = userService.parseUserProfile(jwtPayload)
* if (userProfile) {
* // continue
* }
* ```
*
* @param data An object containing all parameters to be passed to the function
*/
function parseUserProfile(data) {

@@ -62,2 +80,19 @@ var _a, _b, _c;

exports.parseUserProfile = parseUserProfile;
/**
* A friendly `string` that represents the a [User Profile](#user-profile). Uses
* first name, last name, full name, email address or username.
*
* #### Example
*
* ```js
* const userProfile = userService.parseUserProfile(jwtPayload)
* const name = userService.getUserFriendlyName(userProfile)
* if (name) {
* // Display current user's name
* }
* ```
*
* @param userProfile
* @returns
*/
function getUserFriendlyName(userProfile) {

@@ -64,0 +99,0 @@ if (userProfile.fullName) {

{
"name": "@oneblink/sdk-core",
"description": "OneBlink SDK for JavaScript (works in Browsers and NodeJS)",
"version": "0.3.6",
"version": "0.4.0-beta.1",
"author": "OneBlink <developers@oneblink.io> (https://oneblink.io)",

@@ -12,14 +12,16 @@ "bugs": {

"@oneblink/types": "github:oneblink/types",
"@types/jest": "^27.0.1",
"@typescript-eslint/eslint-plugin": "^4.30.0",
"@typescript-eslint/parser": "^4.30.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"@types/jest": "^27.4.1",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"eslint": "^8.13.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.0.0",
"fixpack": "^4.0.0",
"jest": "^27.1.0",
"prettier": "^2.3.2",
"ts-jest": "^27.0.5",
"tsc-watch": "^4.5.0",
"typescript": "^4.4.2"
"jest": "^27.5.1",
"prettier": "^2.6.2",
"prettier-plugin-jsdoc": "^0.3.38",
"ts-jest": "^27.1.4",
"tsc-watch": "^5.0.3",
"typedoc": "^0.22.15",
"typescript": "^4.6.3"
},

@@ -50,2 +52,3 @@ "directories": {

"build": "tsc",
"docs": "typedoc",
"eslint": "eslint --fix --cache .",

@@ -56,3 +59,3 @@ "fixpack": "fixpack",

"pretest": "npm run fixpack && npm run eslint",
"release": "oneblink-release",
"release": "typedoc && oneblink-release",
"start": "tsc-watch",

@@ -59,0 +62,0 @@ "test": "jest",

@@ -5,10 +5,4 @@ # OneBlink SDK - JavaScript Core [![npm module](https://img.shields.io/npm/v/@oneblink/sdk-core.svg)](https://www.npmjs.com/package/@oneblink/sdk-core) [![tests](https://github.com/oneblink/sdk-core-js/actions/workflows/test.yml/badge.svg)](https://github.com/oneblink/sdk-core-js/actions)

## Installation
## Documentation
```sh
npm install @oneblink/sdk-core --save
```
## Usage
- [Usage Documentation](./docs/README.md)
See the [Documentation](https://oneblink.github.io/sdk-core-js/) for more details.

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

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