@myjsblock/sdk
Advanced tools
Comparing version 0.1.0-alpha.2 to 0.2.0-beta.2
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
@@ -15,5 +15,5 @@ | ||
const isInAppWebView = typeof window.flutter_inappwebview === "object"; | ||
const isInAppWebView = typeof window.flutter_inappwebview === 'object'; | ||
const messageApi = isInAppWebView ? window.myjsblock : window; | ||
console.log(`Messaging API: ${isInAppWebView ? 'in app' : 'iframe'}`); | ||
console.debug('Messaging API:', `${isInAppWebView ? 'in app' : 'iframe'}`); | ||
@@ -30,3 +30,3 @@ const DEFAULT_TIMEOUT = 10000; // 10 seconds | ||
const eventCallback = (event) => { | ||
if (event.source == window) { | ||
if (event.source === window) { | ||
return; | ||
@@ -48,3 +48,3 @@ } | ||
error: MessageApiErrors.TIMEOUT_EXCEEDED, | ||
message: 'Timeout exceeded, no response from the App' | ||
message: 'Timeout exceeded, no response from the App', | ||
}); | ||
@@ -57,5 +57,5 @@ messageApi.removeEventListener('message', eventCallback); | ||
const postMessage = (message) => { | ||
if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
} | ||
// if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
// } | ||
const messageStringified = JSON.stringify(message); | ||
@@ -70,18 +70,2 @@ if (isInAppWebView) { | ||
var FunctionName; | ||
(function (FunctionName) { | ||
/* Core */ | ||
FunctionName["getProperty"] = "getProperty"; | ||
FunctionName["showLoader"] = "showLoader"; | ||
FunctionName["getImageUrl"] = "getImageUrl"; | ||
FunctionName["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
FunctionName["getRecords"] = "getRecords"; | ||
FunctionName["getCurrentRecord"] = "getCurrentRecord"; | ||
FunctionName["setCurrentRecordById"] = "setCurrentRecordById"; | ||
// setCurrentRecord = 'setCurrentRecord', | ||
/* Notification */ | ||
FunctionName["showAlert"] = "showAlert"; | ||
FunctionName["goBack"] = "goBack"; | ||
})(FunctionName || (FunctionName = {})); | ||
const callRemoteFunction = (functionName, args) => new Promise((resolve, reject) => { | ||
@@ -101,6 +85,6 @@ const requestId = uid(); | ||
} | ||
else if (!response.value) { | ||
else if (!('value' in response)) { | ||
const error = new Error('No response value returned.'); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED, | ||
reject(error); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED; | ||
reject(error); | ||
} | ||
@@ -118,2 +102,50 @@ else { | ||
var BridgeFunction; | ||
(function (BridgeFunction) { | ||
/* Core */ | ||
BridgeFunction["getBlockName"] = "getBlockName"; | ||
BridgeFunction["getProperty"] = "getProperty"; | ||
BridgeFunction["getImageUrl"] = "getImageUrl"; | ||
BridgeFunction["showLoader"] = "showLoader"; | ||
BridgeFunction["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
BridgeFunction["getRecords"] = "getRecords"; | ||
BridgeFunction["getCurrentRecord"] = "getCurrentRecord"; | ||
// setCurrentRecordById = 'setCurrentRecordById', | ||
/* Notification */ | ||
BridgeFunction["showAlert"] = "showAlert"; | ||
/* Navigation */ | ||
BridgeFunction["goBack"] = "goBack"; | ||
BridgeFunction["navigate"] = "navigate"; | ||
/* Media */ | ||
BridgeFunction["pickImage"] = "pickImage"; | ||
})(BridgeFunction || (BridgeFunction = {})); | ||
var BridgeFunction$1 = BridgeFunction; | ||
var GetBlockNameErrors; | ||
(function (GetBlockNameErrors) { | ||
GetBlockNameErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetBlockNameErrors["PROPERTY_NOT_FOUND"] = "PROPERTY_NOT_FOUND"; | ||
})(GetBlockNameErrors || (GetBlockNameErrors = {})); | ||
/** | ||
* Get the name of the current block. | ||
* @public | ||
* @returns {Promise<GetBlockNameResult>} Name of the block | ||
* @throws {Error} If an unknown error occurs | ||
* | ||
* ```js | ||
* import { getBlockName } from '@myjsblock/sdk' | ||
* | ||
* const myProperty = await getBlockName() | ||
* //or | ||
* getBlockName().then(property => { | ||
* console.log(property) | ||
* }) | ||
* | ||
* ``` | ||
*/ | ||
const getBlockName = () => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name: 'caption', | ||
}); | ||
var GetPropertyErrors; | ||
@@ -125,11 +157,9 @@ (function (GetPropertyErrors) { | ||
})(GetPropertyErrors || (GetPropertyErrors = {})); | ||
// Errors that can be thrown: <code, string> | ||
// 10100, UNKNOWN_ERROR, Unknown error fetching property. | ||
// 10101, PROPERTY_NOT_FOUND, provided propertyKey is not found. | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -147,6 +177,25 @@ * ```js | ||
*/ | ||
const getProperty = (name) => callRemoteFunction(FunctionName.getProperty, { | ||
name | ||
const getProperty = (name) => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name, | ||
}); | ||
var GetImageUrlErrors; | ||
(function (GetImageUrlErrors) { | ||
GetImageUrlErrors["NO_IMAGE_ID_PROVIDED"] = "NO_IMAGE_ID_PROVIDED"; | ||
GetImageUrlErrors["INVALID_ARGUMENTS"] = "INVALID_ARGUMENTS"; | ||
})(GetImageUrlErrors || (GetImageUrlErrors = {})); | ||
/** | ||
* Get an image URL based on an image ID | ||
* @public | ||
* @param {string} imageId | ||
* @param {object<ImageDimensions>} imageDimensions An object containing a width and a height. | ||
* @returns {Promise<string>} Promise with url of an image. | ||
* @throws {Error} If no valid imageId has been specified. | ||
*/ | ||
const getImageUrl = (imageId, { width = null, height = null }) => callRemoteFunction(BridgeFunction$1.getImageUrl, { | ||
imageId, | ||
width, | ||
height, | ||
}); | ||
var ShowLoaderErrors; | ||
@@ -157,7 +206,7 @@ (function (ShowLoaderErrors) { | ||
/** | ||
* Show a native loader overlay. | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
*/ | ||
const showLoader = () => callRemoteFunction(FunctionName.showLoader); | ||
const showLoader = () => callRemoteFunction(BridgeFunction$1.showLoader); | ||
@@ -169,8 +218,22 @@ var HideLoaderErrors; | ||
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* @public | ||
* @returns {Promise<void>} | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
const hideLoader = () => callRemoteFunction(BridgeFunction$1.hideLoader); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
GetRecordsErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
const hideLoader = () => callRemoteFunction(FunctionName.hideLoader); | ||
const getRecords = () => callRemoteFunction(BridgeFunction$1.getRecords); | ||
@@ -180,22 +243,13 @@ var GetCurrentRecordErrors; | ||
GetCurrentRecordErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetCurrentRecordErrors["FETCH_DATA_ERROR"] = "FETCH_DATA_ERROR"; | ||
GetCurrentRecordErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetCurrentRecordErrors || (GetCurrentRecordErrors = {})); | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
const getCurrentRecord = () => callRemoteFunction(FunctionName.getCurrentRecord); | ||
const getCurrentRecord = () => callRemoteFunction(BridgeFunction$1.getCurrentRecord); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
*/ | ||
const getRecords = () => callRemoteFunction(FunctionName.getRecords); | ||
var ShowAlertErrors; | ||
@@ -217,14 +271,59 @@ (function (ShowAlertErrors) { | ||
*/ | ||
const showAlert = (title, message = '', buttons = ['ok']) => callRemoteFunction(FunctionName.showAlert, { | ||
const showAlert = (title, message = '', buttons = ['OK']) => callRemoteFunction(BridgeFunction$1.showAlert, { | ||
title, | ||
message, | ||
buttons | ||
buttons, | ||
}); | ||
var GoBackErrors; | ||
(function (GoBackErrors) { | ||
GoBackErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
})(GoBackErrors || (GoBackErrors = {})); | ||
/** | ||
* Will go back to the parent block of this javascript block. | ||
* @name goBack | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
const goBack = () => callRemoteFunction(BridgeFunction$1.goBack); | ||
var GoToBlockErrors; | ||
(function (GoToBlockErrors) { | ||
GoToBlockErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GoToBlockErrors["VARIABLE_NAME_NOT_FOUND"] = "VARIABLE_NAME_NOT_FOUND"; | ||
})(GoToBlockErrors || (GoToBlockErrors = {})); | ||
/** | ||
* Will navigate to a block matching the given block id. | ||
* @public | ||
* @param {String} variableName The identifier of the block, this can be the caption, variable name or id. | ||
* @throws {Error} If the block identifier is not of type string or is undefined. | ||
*/ | ||
const navigate = (variableName, properties) => callRemoteFunction(BridgeFunction$1.navigate, { | ||
variableName, | ||
properties, | ||
}); | ||
var PickImageErrors; | ||
(function (PickImageErrors) { | ||
PickImageErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
PickImageErrors["PERMISSION_ERROR"] = "PERMISSION_ERROR"; | ||
})(PickImageErrors || (PickImageErrors = {})); | ||
/** | ||
* Open native media picker for images. | ||
* @public | ||
* @returns {Promise<string>} Promise with string of base46 image. | ||
*/ | ||
const pickImage = () => callRemoteFunction(BridgeFunction$1.pickImage); | ||
exports.getBlockName = getBlockName; | ||
exports.getCurrentRecord = getCurrentRecord; | ||
exports.getImageUrl = getImageUrl; | ||
exports.getProperty = getProperty; | ||
exports.getRecords = getRecords; | ||
exports.goBack = goBack; | ||
exports.hideLoader = hideLoader; | ||
exports.navigate = navigate; | ||
exports.pickImage = pickImage; | ||
exports.showAlert = showAlert; | ||
exports.showLoader = showLoader; | ||
//# sourceMappingURL=myjsblock-sdk.js.map |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
@@ -11,5 +11,5 @@ | ||
const isInAppWebView = typeof window.flutter_inappwebview === "object"; | ||
const isInAppWebView = typeof window.flutter_inappwebview === 'object'; | ||
const messageApi = isInAppWebView ? window.myjsblock : window; | ||
console.log(`Messaging API: ${isInAppWebView ? 'in app' : 'iframe'}`); | ||
console.debug('Messaging API:', `${isInAppWebView ? 'in app' : 'iframe'}`); | ||
@@ -26,3 +26,3 @@ const DEFAULT_TIMEOUT = 10000; // 10 seconds | ||
const eventCallback = (event) => { | ||
if (event.source == window) { | ||
if (event.source === window) { | ||
return; | ||
@@ -44,3 +44,3 @@ } | ||
error: MessageApiErrors.TIMEOUT_EXCEEDED, | ||
message: 'Timeout exceeded, no response from the App' | ||
message: 'Timeout exceeded, no response from the App', | ||
}); | ||
@@ -53,5 +53,5 @@ messageApi.removeEventListener('message', eventCallback); | ||
const postMessage = (message) => { | ||
if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
} | ||
// if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
// } | ||
const messageStringified = JSON.stringify(message); | ||
@@ -66,18 +66,2 @@ if (isInAppWebView) { | ||
var FunctionName; | ||
(function (FunctionName) { | ||
/* Core */ | ||
FunctionName["getProperty"] = "getProperty"; | ||
FunctionName["showLoader"] = "showLoader"; | ||
FunctionName["getImageUrl"] = "getImageUrl"; | ||
FunctionName["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
FunctionName["getRecords"] = "getRecords"; | ||
FunctionName["getCurrentRecord"] = "getCurrentRecord"; | ||
FunctionName["setCurrentRecordById"] = "setCurrentRecordById"; | ||
// setCurrentRecord = 'setCurrentRecord', | ||
/* Notification */ | ||
FunctionName["showAlert"] = "showAlert"; | ||
FunctionName["goBack"] = "goBack"; | ||
})(FunctionName || (FunctionName = {})); | ||
const callRemoteFunction = (functionName, args) => new Promise((resolve, reject) => { | ||
@@ -97,6 +81,6 @@ const requestId = uid(); | ||
} | ||
else if (!response.value) { | ||
else if (!('value' in response)) { | ||
const error = new Error('No response value returned.'); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED, | ||
reject(error); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED; | ||
reject(error); | ||
} | ||
@@ -114,2 +98,50 @@ else { | ||
var BridgeFunction; | ||
(function (BridgeFunction) { | ||
/* Core */ | ||
BridgeFunction["getBlockName"] = "getBlockName"; | ||
BridgeFunction["getProperty"] = "getProperty"; | ||
BridgeFunction["getImageUrl"] = "getImageUrl"; | ||
BridgeFunction["showLoader"] = "showLoader"; | ||
BridgeFunction["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
BridgeFunction["getRecords"] = "getRecords"; | ||
BridgeFunction["getCurrentRecord"] = "getCurrentRecord"; | ||
// setCurrentRecordById = 'setCurrentRecordById', | ||
/* Notification */ | ||
BridgeFunction["showAlert"] = "showAlert"; | ||
/* Navigation */ | ||
BridgeFunction["goBack"] = "goBack"; | ||
BridgeFunction["navigate"] = "navigate"; | ||
/* Media */ | ||
BridgeFunction["pickImage"] = "pickImage"; | ||
})(BridgeFunction || (BridgeFunction = {})); | ||
var BridgeFunction$1 = BridgeFunction; | ||
var GetBlockNameErrors; | ||
(function (GetBlockNameErrors) { | ||
GetBlockNameErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetBlockNameErrors["PROPERTY_NOT_FOUND"] = "PROPERTY_NOT_FOUND"; | ||
})(GetBlockNameErrors || (GetBlockNameErrors = {})); | ||
/** | ||
* Get the name of the current block. | ||
* @public | ||
* @returns {Promise<GetBlockNameResult>} Name of the block | ||
* @throws {Error} If an unknown error occurs | ||
* | ||
* ```js | ||
* import { getBlockName } from '@myjsblock/sdk' | ||
* | ||
* const myProperty = await getBlockName() | ||
* //or | ||
* getBlockName().then(property => { | ||
* console.log(property) | ||
* }) | ||
* | ||
* ``` | ||
*/ | ||
const getBlockName = () => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name: 'caption', | ||
}); | ||
var GetPropertyErrors; | ||
@@ -121,11 +153,9 @@ (function (GetPropertyErrors) { | ||
})(GetPropertyErrors || (GetPropertyErrors = {})); | ||
// Errors that can be thrown: <code, string> | ||
// 10100, UNKNOWN_ERROR, Unknown error fetching property. | ||
// 10101, PROPERTY_NOT_FOUND, provided propertyKey is not found. | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -143,6 +173,25 @@ * ```js | ||
*/ | ||
const getProperty = (name) => callRemoteFunction(FunctionName.getProperty, { | ||
name | ||
const getProperty = (name) => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name, | ||
}); | ||
var GetImageUrlErrors; | ||
(function (GetImageUrlErrors) { | ||
GetImageUrlErrors["NO_IMAGE_ID_PROVIDED"] = "NO_IMAGE_ID_PROVIDED"; | ||
GetImageUrlErrors["INVALID_ARGUMENTS"] = "INVALID_ARGUMENTS"; | ||
})(GetImageUrlErrors || (GetImageUrlErrors = {})); | ||
/** | ||
* Get an image URL based on an image ID | ||
* @public | ||
* @param {string} imageId | ||
* @param {object<ImageDimensions>} imageDimensions An object containing a width and a height. | ||
* @returns {Promise<string>} Promise with url of an image. | ||
* @throws {Error} If no valid imageId has been specified. | ||
*/ | ||
const getImageUrl = (imageId, { width = null, height = null }) => callRemoteFunction(BridgeFunction$1.getImageUrl, { | ||
imageId, | ||
width, | ||
height, | ||
}); | ||
var ShowLoaderErrors; | ||
@@ -153,7 +202,7 @@ (function (ShowLoaderErrors) { | ||
/** | ||
* Show a native loader overlay. | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
*/ | ||
const showLoader = () => callRemoteFunction(FunctionName.showLoader); | ||
const showLoader = () => callRemoteFunction(BridgeFunction$1.showLoader); | ||
@@ -165,8 +214,22 @@ var HideLoaderErrors; | ||
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* @public | ||
* @returns {Promise<void>} | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
const hideLoader = () => callRemoteFunction(BridgeFunction$1.hideLoader); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
GetRecordsErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
const hideLoader = () => callRemoteFunction(FunctionName.hideLoader); | ||
const getRecords = () => callRemoteFunction(BridgeFunction$1.getRecords); | ||
@@ -176,22 +239,13 @@ var GetCurrentRecordErrors; | ||
GetCurrentRecordErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetCurrentRecordErrors["FETCH_DATA_ERROR"] = "FETCH_DATA_ERROR"; | ||
GetCurrentRecordErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetCurrentRecordErrors || (GetCurrentRecordErrors = {})); | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
const getCurrentRecord = () => callRemoteFunction(FunctionName.getCurrentRecord); | ||
const getCurrentRecord = () => callRemoteFunction(BridgeFunction$1.getCurrentRecord); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
*/ | ||
const getRecords = () => callRemoteFunction(FunctionName.getRecords); | ||
var ShowAlertErrors; | ||
@@ -213,9 +267,49 @@ (function (ShowAlertErrors) { | ||
*/ | ||
const showAlert = (title, message = '', buttons = ['ok']) => callRemoteFunction(FunctionName.showAlert, { | ||
const showAlert = (title, message = '', buttons = ['OK']) => callRemoteFunction(BridgeFunction$1.showAlert, { | ||
title, | ||
message, | ||
buttons | ||
buttons, | ||
}); | ||
export { getCurrentRecord, getProperty, getRecords, hideLoader, showAlert, showLoader }; | ||
var GoBackErrors; | ||
(function (GoBackErrors) { | ||
GoBackErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
})(GoBackErrors || (GoBackErrors = {})); | ||
/** | ||
* Will go back to the parent block of this javascript block. | ||
* @name goBack | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
const goBack = () => callRemoteFunction(BridgeFunction$1.goBack); | ||
var GoToBlockErrors; | ||
(function (GoToBlockErrors) { | ||
GoToBlockErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GoToBlockErrors["VARIABLE_NAME_NOT_FOUND"] = "VARIABLE_NAME_NOT_FOUND"; | ||
})(GoToBlockErrors || (GoToBlockErrors = {})); | ||
/** | ||
* Will navigate to a block matching the given block id. | ||
* @public | ||
* @param {String} variableName The identifier of the block, this can be the caption, variable name or id. | ||
* @throws {Error} If the block identifier is not of type string or is undefined. | ||
*/ | ||
const navigate = (variableName, properties) => callRemoteFunction(BridgeFunction$1.navigate, { | ||
variableName, | ||
properties, | ||
}); | ||
var PickImageErrors; | ||
(function (PickImageErrors) { | ||
PickImageErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
PickImageErrors["PERMISSION_ERROR"] = "PERMISSION_ERROR"; | ||
})(PickImageErrors || (PickImageErrors = {})); | ||
/** | ||
* Open native media picker for images. | ||
* @public | ||
* @returns {Promise<string>} Promise with string of base46 image. | ||
*/ | ||
const pickImage = () => callRemoteFunction(BridgeFunction$1.pickImage); | ||
export { getBlockName, getCurrentRecord, getImageUrl, getProperty, getRecords, goBack, hideLoader, navigate, pickImage, showAlert, showLoader }; | ||
//# sourceMappingURL=myjsblock-sdk.js.map |
interface GetBlockNameResult { | ||
name: string; | ||
} | ||
/** | ||
* Get the name of the current block. | ||
* @public | ||
* @returns {Promise<GetBlockNameResult>} Name of the block | ||
* @throws {Error} If an unknown error occurs | ||
* | ||
* ```js | ||
* import { getBlockName } from '@myjsblock/sdk' | ||
* | ||
* const myProperty = await getBlockName() | ||
* //or | ||
* getBlockName().then(property => { | ||
* console.log(property) | ||
* }) | ||
* | ||
* ``` | ||
*/ | ||
declare const getBlockName: () => Promise<GetBlockNameResult>; | ||
export default getBlockName; |
declare type GetImageUrlResult = string; | ||
export declare type ImageDimensions = { | ||
width: number | null; | ||
height: number | null; | ||
}; | ||
/** | ||
* Allows you to get an image url based on an image id | ||
* Get an image URL based on an image ID | ||
* @public | ||
* @param {string} imageId | ||
* @returns {Promise<string>} Promise with url of an image | ||
* @param {object<ImageDimensions>} imageDimensions An object containing a width and a height. | ||
* @returns {Promise<string>} Promise with url of an image. | ||
* @throws {Error} If no valid imageId has been specified. | ||
*/ | ||
declare const getImageUrl: (imageId: string) => Promise<GetImageUrlResult>; | ||
declare const getImageUrl: (imageId: string, { width, height }: ImageDimensions) => Promise<GetImageUrlResult>; | ||
export default getImageUrl; |
declare type GetPropertyResult = string; | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -9,0 +10,0 @@ * ```js |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -13,11 +14,9 @@ var GetPropertyErrors; | ||
})(GetPropertyErrors || (GetPropertyErrors = {})); | ||
// Errors that can be thrown: <code, string> | ||
// 10100, UNKNOWN_ERROR, Unknown error fetching property. | ||
// 10101, PROPERTY_NOT_FOUND, provided propertyKey is not found. | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -35,4 +34,4 @@ * ```js | ||
*/ | ||
const getProperty = (name) => callRemoteFunction(FunctionName.getProperty, { | ||
name | ||
const getProperty = (name) => callRemoteFunction(BridgeFunction.getProperty, { | ||
name, | ||
}); | ||
@@ -39,0 +38,0 @@ |
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
declare const hideLoader: () => Promise<void>; | ||
export default hideLoader; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import '../../messenging/addMessageListener.js'; | ||
import '../../messenging/messageApi.js'; | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import '../../messaging/addMessageListener.js'; | ||
import '../../messaging/messageApi.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -14,10 +15,9 @@ var HideLoaderErrors; | ||
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
const hideLoader = () => callRemoteFunction(FunctionName.hideLoader); | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
const hideLoader = () => callRemoteFunction(BridgeFunction.hideLoader); | ||
export { hideLoader as default }; | ||
//# sourceMappingURL=hideLoader.js.map |
/** | ||
* Share content using the Native share functionality from your iOS / Android or Web Browser | ||
* @param variableName | ||
* @param newValue | ||
* Share content using the native share functionality from your iOS / Android or Web Browser | ||
* @param {string} content | ||
* @param {Array.string} imageUrls | ||
* @param {string} subject | ||
* @returns {PromiseLike<{ key: string, value: any }>} | ||
@@ -6,0 +7,0 @@ * @throws {Error} If no valid key has been specified. |
/** | ||
* Show a native loader overlay. | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import '../../messenging/addMessageListener.js'; | ||
import '../../messenging/messageApi.js'; | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import '../../messaging/addMessageListener.js'; | ||
import '../../messaging/messageApi.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -14,9 +15,9 @@ var ShowLoaderErrors; | ||
/** | ||
* Show a native loader overlay. | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
*/ | ||
const showLoader = () => callRemoteFunction(FunctionName.showLoader); | ||
const showLoader = () => callRemoteFunction(BridgeFunction.showLoader); | ||
export { showLoader as default }; | ||
//# sourceMappingURL=showLoader.js.map |
declare type GetCurrentRecordResult<DataResponse> = DataResponse; | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
declare const getCurrentRecord: <DataResponse = unknown>() => Promise<DataResponse>; | ||
export default getCurrentRecord; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import '../../messenging/addMessageListener.js'; | ||
import '../../messenging/messageApi.js'; | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import '../../messaging/addMessageListener.js'; | ||
import '../../messaging/messageApi.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -12,11 +13,14 @@ var GetCurrentRecordErrors; | ||
GetCurrentRecordErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetCurrentRecordErrors["FETCH_DATA_ERROR"] = "FETCH_DATA_ERROR"; | ||
GetCurrentRecordErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetCurrentRecordErrors || (GetCurrentRecordErrors = {})); | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
const getCurrentRecord = () => callRemoteFunction(FunctionName.getCurrentRecord); | ||
const getCurrentRecord = () => callRemoteFunction(BridgeFunction.getCurrentRecord); | ||
export { getCurrentRecord as default }; | ||
//# sourceMappingURL=getCurrentRecord.js.map |
@@ -5,7 +5,9 @@ interface GetRecordsResult<DataResponse> { | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
declare const getRecords: <DataResponse = unknown[]>() => Promise<GetRecordsResult<DataResponse>>; | ||
export default getRecords; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import '../../messenging/addMessageListener.js'; | ||
import '../../messenging/messageApi.js'; | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import '../../messaging/addMessageListener.js'; | ||
import '../../messaging/messageApi.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -13,11 +14,14 @@ var GetRecordsErrors; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
GetRecordsErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
const getRecords = () => callRemoteFunction(FunctionName.getRecords); | ||
const getRecords = () => callRemoteFunction(BridgeFunction.getRecords); | ||
export { getRecords as default }; | ||
//# sourceMappingURL=getRecords.js.map |
@@ -0,6 +1,11 @@ | ||
export { default as getBlockName } from './core/getBlockName'; | ||
export { default as getProperty } from './core/getProperty'; | ||
export { default as getImageUrl } from './core/getImageUrl'; | ||
export { default as showLoader } from './core/showLoader'; | ||
export { default as hideLoader } from './core/hideLoader'; | ||
export { default as getRecords } from './data/getRecords'; | ||
export { default as getCurrentRecord } from './data/getCurrentRecord'; | ||
export { default as getRecords } from './data/getRecords'; | ||
export { default as showAlert } from './notification/showAlert'; | ||
export { default as goBack } from './navigation/goBack'; | ||
export { default as navigate } from './navigation/navigate'; | ||
export { default as pickImage } from './media/pickImage'; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
import callRemoteFunction, { FunctionName } from '../../messenging/callRemoteFunction.js'; | ||
import callRemoteFunction from '../../messaging/callRemoteFunction.js'; | ||
import BridgeFunction from '../../types/BridgeFunction.js'; | ||
@@ -23,6 +24,6 @@ var ShowAlertErrors; | ||
*/ | ||
const showAlert = (title, message = '', buttons = ['ok']) => callRemoteFunction(FunctionName.showAlert, { | ||
const showAlert = (title, message = '', buttons = ['OK']) => callRemoteFunction(BridgeFunction.showAlert, { | ||
title, | ||
message, | ||
buttons | ||
buttons, | ||
}); | ||
@@ -29,0 +30,0 @@ |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
export { default as getBlockName } from './functions/core/getBlockName.js'; | ||
export { default as getProperty } from './functions/core/getProperty.js'; | ||
export { default as getImageUrl } from './functions/core/getImageUrl.js'; | ||
export { default as showLoader } from './functions/core/showLoader.js'; | ||
export { default as hideLoader } from './functions/core/hideLoader.js'; | ||
export { default as getRecords } from './functions/data/getRecords.js'; | ||
export { default as getCurrentRecord } from './functions/data/getCurrentRecord.js'; | ||
export { default as getRecords } from './functions/data/getRecords.js'; | ||
export { default as showAlert } from './functions/notification/showAlert.js'; | ||
export { default as goBack } from './functions/navigation/goBack.js'; | ||
export { default as navigate } from './functions/navigation/navigate.js'; | ||
export { default as pickImage } from './functions/media/pickImage.js'; | ||
//# sourceMappingURL=sdk.js.map |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
@@ -4,0 +4,0 @@ |
@@ -0,8 +1,31 @@ | ||
interface GetBlockNameResult { | ||
name: string; | ||
} | ||
/** | ||
* Get the name of the current block. | ||
* @public | ||
* @returns {Promise<GetBlockNameResult>} Name of the block | ||
* @throws {Error} If an unknown error occurs | ||
* | ||
* ```js | ||
* import { getBlockName } from '@myjsblock/sdk' | ||
* | ||
* const myProperty = await getBlockName() | ||
* //or | ||
* getBlockName().then(property => { | ||
* console.log(property) | ||
* }) | ||
* | ||
* ``` | ||
*/ | ||
declare const getBlockName: () => Promise<GetBlockNameResult>; | ||
declare type GetPropertyResult = string; | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -22,22 +45,30 @@ * ```js | ||
declare type GetImageUrlResult = string; | ||
declare type ImageDimensions = { | ||
width: number | null; | ||
height: number | null; | ||
}; | ||
/** | ||
* Get an image URL based on an image ID | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
* @param {string} imageId | ||
* @param {object<ImageDimensions>} imageDimensions An object containing a width and a height. | ||
* @returns {Promise<string>} Promise with url of an image. | ||
* @throws {Error} If no valid imageId has been specified. | ||
*/ | ||
declare const showLoader: () => Promise<void>; | ||
declare const getImageUrl: (imageId: string, { width, height }: ImageDimensions) => Promise<GetImageUrlResult>; | ||
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* Show a native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
declare const hideLoader: () => Promise<void>; | ||
declare const showLoader: () => Promise<void>; | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
*/ | ||
declare const getCurrentRecord: <DataResponse = unknown>() => Promise<DataResponse>; | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
declare const hideLoader: () => Promise<void>; | ||
@@ -48,8 +79,19 @@ interface GetRecordsResult<DataResponse> { | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
declare const getRecords: <DataResponse = unknown[]>() => Promise<GetRecordsResult<DataResponse>>; | ||
/** | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
declare const getCurrentRecord: <DataResponse = unknown>() => Promise<DataResponse>; | ||
interface ShowAlertResult { | ||
@@ -70,2 +112,27 @@ clicked: string[]; | ||
export { getCurrentRecord, getProperty, getRecords, hideLoader, showAlert, showLoader }; | ||
/** | ||
* Will go back to the parent block of this javascript block. | ||
* @name goBack | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
declare const goBack: () => Promise<void>; | ||
declare type NavigateProperties = Record<string, unknown>; | ||
/** | ||
* Will navigate to a block matching the given block id. | ||
* @public | ||
* @param {String} variableName The identifier of the block, this can be the caption, variable name or id. | ||
* @throws {Error} If the block identifier is not of type string or is undefined. | ||
*/ | ||
declare const navigate: (variableName: string, properties: NavigateProperties) => Promise<void>; | ||
declare type PickImageResult = string; | ||
/** | ||
* Open native media picker for images. | ||
* @public | ||
* @returns {Promise<string>} Promise with string of base46 image. | ||
*/ | ||
declare const pickImage: () => Promise<PickImageResult>; | ||
export { getBlockName, getCurrentRecord, getImageUrl, getProperty, getRecords, goBack, hideLoader, navigate, pickImage, showAlert, showLoader }; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
@@ -17,5 +17,5 @@ | ||
const isInAppWebView = typeof window.flutter_inappwebview === "object"; | ||
const isInAppWebView = typeof window.flutter_inappwebview === 'object'; | ||
const messageApi = isInAppWebView ? window.myjsblock : window; | ||
console.log(`Messaging API: ${isInAppWebView ? 'in app' : 'iframe'}`); | ||
console.debug('Messaging API:', `${isInAppWebView ? 'in app' : 'iframe'}`); | ||
@@ -32,3 +32,3 @@ const DEFAULT_TIMEOUT = 10000; // 10 seconds | ||
const eventCallback = (event) => { | ||
if (event.source == window) { | ||
if (event.source === window) { | ||
return; | ||
@@ -50,3 +50,3 @@ } | ||
error: MessageApiErrors.TIMEOUT_EXCEEDED, | ||
message: 'Timeout exceeded, no response from the App' | ||
message: 'Timeout exceeded, no response from the App', | ||
}); | ||
@@ -59,5 +59,5 @@ messageApi.removeEventListener('message', eventCallback); | ||
const postMessage = (message) => { | ||
if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
} | ||
// if (window.debugMyjsblockSdk) { | ||
console.debug('POST:', message); | ||
// } | ||
const messageStringified = JSON.stringify(message); | ||
@@ -72,18 +72,2 @@ if (isInAppWebView) { | ||
var FunctionName; | ||
(function (FunctionName) { | ||
/* Core */ | ||
FunctionName["getProperty"] = "getProperty"; | ||
FunctionName["showLoader"] = "showLoader"; | ||
FunctionName["getImageUrl"] = "getImageUrl"; | ||
FunctionName["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
FunctionName["getRecords"] = "getRecords"; | ||
FunctionName["getCurrentRecord"] = "getCurrentRecord"; | ||
FunctionName["setCurrentRecordById"] = "setCurrentRecordById"; | ||
// setCurrentRecord = 'setCurrentRecord', | ||
/* Notification */ | ||
FunctionName["showAlert"] = "showAlert"; | ||
FunctionName["goBack"] = "goBack"; | ||
})(FunctionName || (FunctionName = {})); | ||
const callRemoteFunction = (functionName, args) => new Promise((resolve, reject) => { | ||
@@ -103,6 +87,6 @@ const requestId = uid(); | ||
} | ||
else if (!response.value) { | ||
else if (!('value' in response)) { | ||
const error = new Error('No response value returned.'); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED, | ||
reject(error); | ||
error.name = MessageApiErrors.NO_VALUE_RETURNED; | ||
reject(error); | ||
} | ||
@@ -120,2 +104,50 @@ else { | ||
var BridgeFunction; | ||
(function (BridgeFunction) { | ||
/* Core */ | ||
BridgeFunction["getBlockName"] = "getBlockName"; | ||
BridgeFunction["getProperty"] = "getProperty"; | ||
BridgeFunction["getImageUrl"] = "getImageUrl"; | ||
BridgeFunction["showLoader"] = "showLoader"; | ||
BridgeFunction["hideLoader"] = "hideLoader"; | ||
/* Data */ | ||
BridgeFunction["getRecords"] = "getRecords"; | ||
BridgeFunction["getCurrentRecord"] = "getCurrentRecord"; | ||
// setCurrentRecordById = 'setCurrentRecordById', | ||
/* Notification */ | ||
BridgeFunction["showAlert"] = "showAlert"; | ||
/* Navigation */ | ||
BridgeFunction["goBack"] = "goBack"; | ||
BridgeFunction["navigate"] = "navigate"; | ||
/* Media */ | ||
BridgeFunction["pickImage"] = "pickImage"; | ||
})(BridgeFunction || (BridgeFunction = {})); | ||
var BridgeFunction$1 = BridgeFunction; | ||
var GetBlockNameErrors; | ||
(function (GetBlockNameErrors) { | ||
GetBlockNameErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetBlockNameErrors["PROPERTY_NOT_FOUND"] = "PROPERTY_NOT_FOUND"; | ||
})(GetBlockNameErrors || (GetBlockNameErrors = {})); | ||
/** | ||
* Get the name of the current block. | ||
* @public | ||
* @returns {Promise<GetBlockNameResult>} Name of the block | ||
* @throws {Error} If an unknown error occurs | ||
* | ||
* ```js | ||
* import { getBlockName } from '@myjsblock/sdk' | ||
* | ||
* const myProperty = await getBlockName() | ||
* //or | ||
* getBlockName().then(property => { | ||
* console.log(property) | ||
* }) | ||
* | ||
* ``` | ||
*/ | ||
const getBlockName = () => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name: 'caption', | ||
}); | ||
var GetPropertyErrors; | ||
@@ -127,11 +159,9 @@ (function (GetPropertyErrors) { | ||
})(GetPropertyErrors || (GetPropertyErrors = {})); | ||
// Errors that can be thrown: <code, string> | ||
// 10100, UNKNOWN_ERROR, Unknown error fetching property. | ||
// 10101, PROPERTY_NOT_FOUND, provided propertyKey is not found. | ||
/** | ||
* @name getProperty | ||
* @description Gets the given propertyName from the current block. | ||
* Get the given propertyName from the current block. | ||
* @public | ||
* @param {string} name | ||
* @returns {Promise<string>} The value of the property | ||
* @public | ||
* @throws {Error} If unknown error occurs | ||
* @throws {Error} If given `name` property is not found | ||
* | ||
@@ -149,6 +179,25 @@ * ```js | ||
*/ | ||
const getProperty = (name) => callRemoteFunction(FunctionName.getProperty, { | ||
name | ||
const getProperty = (name) => callRemoteFunction(BridgeFunction$1.getProperty, { | ||
name, | ||
}); | ||
var GetImageUrlErrors; | ||
(function (GetImageUrlErrors) { | ||
GetImageUrlErrors["NO_IMAGE_ID_PROVIDED"] = "NO_IMAGE_ID_PROVIDED"; | ||
GetImageUrlErrors["INVALID_ARGUMENTS"] = "INVALID_ARGUMENTS"; | ||
})(GetImageUrlErrors || (GetImageUrlErrors = {})); | ||
/** | ||
* Get an image URL based on an image ID | ||
* @public | ||
* @param {string} imageId | ||
* @param {object<ImageDimensions>} imageDimensions An object containing a width and a height. | ||
* @returns {Promise<string>} Promise with url of an image. | ||
* @throws {Error} If no valid imageId has been specified. | ||
*/ | ||
const getImageUrl = (imageId, { width = null, height = null }) => callRemoteFunction(BridgeFunction$1.getImageUrl, { | ||
imageId, | ||
width, | ||
height, | ||
}); | ||
var ShowLoaderErrors; | ||
@@ -159,7 +208,7 @@ (function (ShowLoaderErrors) { | ||
/** | ||
* Show a native loader overlay. | ||
* @public | ||
* Allows you to show the native loader overlay | ||
* @returns {Promise<void>} | ||
*/ | ||
const showLoader = () => callRemoteFunction(FunctionName.showLoader); | ||
const showLoader = () => callRemoteFunction(BridgeFunction$1.showLoader); | ||
@@ -171,8 +220,22 @@ var HideLoaderErrors; | ||
/** | ||
* | ||
* Allows you to hide the native loader overlay | ||
* @public | ||
* @returns {Promise<void>} | ||
* Hide the native loader overlay. | ||
* @public | ||
* @returns {Promise<void>} Promise | ||
*/ | ||
const hideLoader = () => callRemoteFunction(BridgeFunction$1.hideLoader); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
GetRecordsErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records from the data context | ||
* @returns {Promise<GetRecordsResult<DataResponse>>} Promise of items from the data context | ||
* @throws {Error} if unknown error occurs | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If fetching the web-service fails | ||
*/ | ||
const hideLoader = () => callRemoteFunction(FunctionName.hideLoader); | ||
const getRecords = () => callRemoteFunction(BridgeFunction$1.getRecords); | ||
@@ -182,22 +245,13 @@ var GetCurrentRecordErrors; | ||
GetCurrentRecordErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetCurrentRecordErrors["FETCH_DATA_ERROR"] = "FETCH_DATA_ERROR"; | ||
GetCurrentRecordErrors["MISSING_CONTEXT"] = "MISSING_CONTEXT"; | ||
})(GetCurrentRecordErrors || (GetCurrentRecordErrors = {})); | ||
/** | ||
* Returns the current record form data web service context. | ||
* @returns {Promise<unknown>} | ||
* Get the current record from the current data web service context | ||
* @public | ||
* @returns {Promise<unknown>} Promise with the requested data object | ||
* @throws {Error} If an unknown error occurs | ||
* @throws {Error} If function is not called in a detail block context | ||
*/ | ||
const getCurrentRecord = () => callRemoteFunction(FunctionName.getCurrentRecord); | ||
const getCurrentRecord = () => callRemoteFunction(BridgeFunction$1.getCurrentRecord); | ||
var GetRecordsErrors; | ||
(function (GetRecordsErrors) { | ||
GetRecordsErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GetRecordsErrors["ERROR_FETCH_WEBSERVICE"] = "ERROR_FETCH_WEBSERVICE"; | ||
})(GetRecordsErrors || (GetRecordsErrors = {})); | ||
/** | ||
* Returns the records form the data web service context. | ||
* @returns {Array} of items from a web-service. | ||
* @throws {Error} if fetching the web-service fails | ||
*/ | ||
const getRecords = () => callRemoteFunction(FunctionName.getRecords); | ||
var ShowAlertErrors; | ||
@@ -219,12 +273,57 @@ (function (ShowAlertErrors) { | ||
*/ | ||
const showAlert = (title, message = '', buttons = ['ok']) => callRemoteFunction(FunctionName.showAlert, { | ||
const showAlert = (title, message = '', buttons = ['OK']) => callRemoteFunction(BridgeFunction$1.showAlert, { | ||
title, | ||
message, | ||
buttons | ||
buttons, | ||
}); | ||
var GoBackErrors; | ||
(function (GoBackErrors) { | ||
GoBackErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
})(GoBackErrors || (GoBackErrors = {})); | ||
/** | ||
* Will go back to the parent block of this javascript block. | ||
* @name goBack | ||
* @public | ||
* @returns {Promise<void>} | ||
*/ | ||
const goBack = () => callRemoteFunction(BridgeFunction$1.goBack); | ||
var GoToBlockErrors; | ||
(function (GoToBlockErrors) { | ||
GoToBlockErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
GoToBlockErrors["VARIABLE_NAME_NOT_FOUND"] = "VARIABLE_NAME_NOT_FOUND"; | ||
})(GoToBlockErrors || (GoToBlockErrors = {})); | ||
/** | ||
* Will navigate to a block matching the given block id. | ||
* @public | ||
* @param {String} variableName The identifier of the block, this can be the caption, variable name or id. | ||
* @throws {Error} If the block identifier is not of type string or is undefined. | ||
*/ | ||
const navigate = (variableName, properties) => callRemoteFunction(BridgeFunction$1.navigate, { | ||
variableName, | ||
properties, | ||
}); | ||
var PickImageErrors; | ||
(function (PickImageErrors) { | ||
PickImageErrors["UNKNOWN_ERROR"] = "UNKNOWN_ERROR"; | ||
PickImageErrors["PERMISSION_ERROR"] = "PERMISSION_ERROR"; | ||
})(PickImageErrors || (PickImageErrors = {})); | ||
/** | ||
* Open native media picker for images. | ||
* @public | ||
* @returns {Promise<string>} Promise with string of base46 image. | ||
*/ | ||
const pickImage = () => callRemoteFunction(BridgeFunction$1.pickImage); | ||
exports.getBlockName = getBlockName; | ||
exports.getCurrentRecord = getCurrentRecord; | ||
exports.getImageUrl = getImageUrl; | ||
exports.getProperty = getProperty; | ||
exports.getRecords = getRecords; | ||
exports.goBack = goBack; | ||
exports.hideLoader = hideLoader; | ||
exports.navigate = navigate; | ||
exports.pickImage = pickImage; | ||
exports.showAlert = showAlert; | ||
@@ -231,0 +330,0 @@ exports.showLoader = showLoader; |
/** | ||
* @myjsblock/sdk v0.1.0-alpha.2 - MIT | ||
* @myjsblock/sdk v0.2.0-beta.2 - MIT | ||
*/ | ||
"use strict";!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((e="undefined"!=typeof globalThis?globalThis:e||self)["myjsblock-sdk"]={})}(this,(function(e){let o="object"==typeof window.flutter_inappwebview,r=o?window.myjsblock:window;var t,s;console.log("Messaging API: "+(o?"in app":"iframe")),(s=t||(t={})).TIMEOUT_EXCEEDED="TIMEOUT_EXCEEDED",s.NO_VALUE_RETURNED="NO_VALUE_RETURNED",s.UNKNOWN_FUNCTION="UNKNOWN_FUNCTION";var R;!function(e){e.getProperty="getProperty",e.showLoader="showLoader",e.getImageUrl="getImageUrl",e.hideLoader="hideLoader",e.getRecords="getRecords",e.getCurrentRecord="getCurrentRecord",e.setCurrentRecordById="setCurrentRecordById",e.showAlert="showAlert",e.goBack="goBack"}(R||(R={}));let n=(e,s)=>new Promise(((R,n)=>{const N=Date.now().toString(36)+Math.random().toString(36).substring(2);((e,o,s=1e4)=>{let R;const n=t=>{t.source!=window&&(t=JSON.parse(t.data)).requestId===e&&(o(t),r.removeEventListener("message",n),R&&clearTimeout(R))};R=setTimeout((()=>{o({requestId:e,error:t.TIMEOUT_EXCEEDED,message:"Timeout exceeded, no response from the App"}),r.removeEventListener("message",n)}),s),r.addEventListener("message",n)})(N,(e=>{if(console.debug("Received:",e),"error"in e){const o=Error(e.message);o.name=String(e.error).toUpperCase(),"traceId"in e&&(o.message=`${o.message}, traceId: ${e.traceId}`),n(o)}else e.value?R(e.value):((e=Error("No response value returned.")).name=t.NO_VALUE_RETURNED,n(e))})),(e=>{window.debugMyjsblockSdk&&console.debug("POST:",e),e=JSON.stringify(e),o?r.postMessage(e):window.parent.postMessage(e,"*")})({id:N,functionName:e,arguments:s})}));var N,E,d,a,O,i;!function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.PROPERTY_NOT_FOUND="PROPERTY_NOT_FOUND",e.INVALID_ARGUMENTS="INVALID_ARGUMENTS"}(N||(N={})),(E||(E={})).UNKNOWN_ERROR="UNKNOWN_ERROR",(d||(d={})).UNKNOWN_ERROR="UNKNOWN_ERROR",function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.FETCH_DATA_ERROR="FETCH_DATA_ERROR"}(a||(a={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.ERROR_FETCH_WEBSERVICE="ERROR_FETCH_WEBSERVICE"}(O||(O={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.TITLE_IS_EMPTY="TITLE_IS_EMPTY",e.NO_BUTTONS_PROVIDED="NO_BUTTONS_PROVIDED"}(i||(i={})),e.getCurrentRecord=()=>n(R.getCurrentRecord),e.getProperty=e=>n(R.getProperty,{name:e}),e.getRecords=()=>n(R.getRecords),e.hideLoader=()=>n(R.hideLoader),e.showAlert=(e,o="",r=["ok"])=>n(R.showAlert,{title:e,message:o,buttons:r}),e.showLoader=()=>n(R.showLoader),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
"use strict";!function(e,N){"object"==typeof exports&&"undefined"!=typeof module?N(exports):"function"==typeof define&&define.amd?define(["exports"],N):N((e="undefined"!=typeof globalThis?globalThis:e||self)["myjsblock-sdk"]={})}(this,(function(e){let N="object"==typeof window.flutter_inappwebview,t=N?window.myjsblock:window;var R,o;console.debug("Messaging API:",""+(N?"in app":"iframe")),(o=R||(R={})).TIMEOUT_EXCEEDED="TIMEOUT_EXCEEDED",o.NO_VALUE_RETURNED="NO_VALUE_RETURNED",o.UNKNOWN_FUNCTION="UNKNOWN_FUNCTION";let r=(e,o)=>new Promise(((r,O)=>{const E=Date.now().toString(36)+Math.random().toString(36).substring(2);((e,N,o=1e4)=>{let r;const O=R=>{R.source!==window&&(R=JSON.parse(R.data)).requestId===e&&(N(R),t.removeEventListener("message",O),r&&clearTimeout(r))};r=setTimeout((()=>{N({requestId:e,error:R.TIMEOUT_EXCEEDED,message:"Timeout exceeded, no response from the App"}),t.removeEventListener("message",O)}),o),t.addEventListener("message",O)})(E,(e=>{if(console.debug("Received:",e),"error"in e){const N=Error(e.message);N.name=String(e.error).toUpperCase(),"traceId"in e&&(N.message=`${N.message}, traceId: ${e.traceId}`),O(N)}else"value"in e?r(e.value):((e=Error("No response value returned.")).name=R.NO_VALUE_RETURNED,O(e))})),(e=>{console.debug("POST:",e),e=JSON.stringify(e),N?t.postMessage(e):window.parent.postMessage(e,"*")})({id:E,functionName:e,arguments:o})}));var O;!function(e){e.getBlockName="getBlockName",e.getProperty="getProperty",e.getImageUrl="getImageUrl",e.showLoader="showLoader",e.hideLoader="hideLoader",e.getRecords="getRecords",e.getCurrentRecord="getCurrentRecord",e.showAlert="showAlert",e.goBack="goBack",e.navigate="navigate",e.pickImage="pickImage"}(O||(O={}));var E,n,a,s,_,i,g,d,I,c,T,U=O;!function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.PROPERTY_NOT_FOUND="PROPERTY_NOT_FOUND"}(E||(E={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.PROPERTY_NOT_FOUND="PROPERTY_NOT_FOUND",e.INVALID_ARGUMENTS="INVALID_ARGUMENTS"}(n||(n={})),function(e){e.NO_IMAGE_ID_PROVIDED="NO_IMAGE_ID_PROVIDED",e.INVALID_ARGUMENTS="INVALID_ARGUMENTS"}(a||(a={})),(s||(s={})).UNKNOWN_ERROR="UNKNOWN_ERROR",(_||(_={})).UNKNOWN_ERROR="UNKNOWN_ERROR",function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.ERROR_FETCH_WEBSERVICE="ERROR_FETCH_WEBSERVICE",e.MISSING_CONTEXT="MISSING_CONTEXT"}(i||(i={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.MISSING_CONTEXT="MISSING_CONTEXT"}(g||(g={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.TITLE_IS_EMPTY="TITLE_IS_EMPTY",e.NO_BUTTONS_PROVIDED="NO_BUTTONS_PROVIDED"}(d||(d={})),(I||(I={})).UNKNOWN_ERROR="UNKNOWN_ERROR",function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.VARIABLE_NAME_NOT_FOUND="VARIABLE_NAME_NOT_FOUND"}(c||(c={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.PERMISSION_ERROR="PERMISSION_ERROR"}(T||(T={})),e.getBlockName=()=>r(U.getProperty,{name:"caption"}),e.getCurrentRecord=()=>r(U.getCurrentRecord),e.getImageUrl=(e,{width:N=null,height:t=null})=>r(U.getImageUrl,{imageId:e,width:N,height:t}),e.getProperty=e=>r(U.getProperty,{name:e}),e.getRecords=()=>r(U.getRecords),e.goBack=()=>r(U.goBack),e.hideLoader=()=>r(U.hideLoader),e.navigate=(e,N)=>r(U.navigate,{variableName:e,properties:N}),e.pickImage=()=>r(U.pickImage),e.showAlert=(e,N="",t=["OK"])=>r(U.showAlert,{title:e,message:N,buttons:t}),e.showLoader=()=>r(U.showLoader),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=myjsblock-sdk.min.js.map |
{ | ||
"name": "@myjsblock/sdk", | ||
"version": "0.1.0-alpha.2", | ||
"version": "0.2.0-beta.2", | ||
"description": "Javascript SDK that will allow you to build your own AppMachine block", | ||
@@ -30,10 +30,12 @@ "type": "module", | ||
"scripts": { | ||
"test": "jest", | ||
"dev": "vite", | ||
"dev:app": "DEV_APP=1 vite --port 4000", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"clean": "rm -rf dist", | ||
"build:vite": "tsc && vite build", | ||
"build:app": "tsc && vite build", | ||
"build": "npm run clean && rollup -c rollup.config.js", | ||
"build:skip-typecheck": "vite build", | ||
"preview": "vite preview" | ||
"preview": "vite preview", | ||
"lint": "eslint '*/**/*.{js,ts}' --fix" | ||
}, | ||
@@ -49,3 +51,3 @@ "devDependencies": { | ||
"@rollup/plugin-typescript": "^8.3.1", | ||
"@types/jest": "^27.4.0", | ||
"@types/jest": "^27.4.1", | ||
"@types/react": "^17.0.43", | ||
@@ -56,5 +58,10 @@ "@types/react-dom": "^17.0.14", | ||
"@vitejs/plugin-react": "^1.2.0", | ||
"eslint": "^8.10.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"esbuild": "^0.14.31", | ||
"esbuild-jest": "^0.5.0", | ||
"eslint": "^8.13.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-config-airbnb-typescript": "^17.0.0", | ||
"eslint-import-resolver-alias": "^1.1.2", | ||
"eslint-import-resolver-typescript": "^2.7.1", | ||
"jest": "^27.4.7", | ||
@@ -65,3 +72,3 @@ "react": "17.0.2", | ||
"rollup-plugin-dts": "^4.2.0", | ||
"rollup-plugin-license": "^2.6.1", | ||
"rollup-plugin-license": "^2.7.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
@@ -72,5 +79,4 @@ "rollup-plugin-visualizer": "^5.6.0", | ||
"vite-plugin-windicss": "^1.8.3", | ||
"vitest": "^0.8.0", | ||
"windicss": "^3.5.1" | ||
} | ||
} |
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
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
99037
74
1767
34