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

appsemble

Package Overview
Dependencies
Maintainers
1
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

appsemble - npm Package Compare versions

Comparing version 0.0.0-alpha.0 to 0.0.0-alpha.1

16

index.js

@@ -8,2 +8,3 @@ 'use strict';

exports.ready = ready;
exports.isBootstrap = isBootstrap;

@@ -13,2 +14,3 @@ var _communication = require('./lib/communication');

var readyPromise = void 0;
var bootstrap = void 0;

@@ -45,2 +47,3 @@ /**

readyPromise = (0, _communication.makeRPC)('core#ready').then(function (result) {
bootstrap = result.isBootstrap;
Object.assign(app, result.app);

@@ -52,2 +55,15 @@ Object.assign(part, result.part);

return readyPromise;
}
/**
* Check whether or not the extension is running in the Appsemble bootstrap app.
*
* @returns {Boolean} True if the extension is running in the bootstrap app, otherwise false.
* @throws If the promise from {@link ready} has not been resolved yet.
*/
function isBootstrap() {
if (bootstrap === undefined) {
throw new Error('The Appsemble SDK hasn’t been initialized yet. Make sure to call ‘ready’ first.');
}
return bootstrap;
}

27

lib/communication.js

@@ -23,6 +23,17 @@ 'use strict';

var host = '*';
var rpcCounter = 0;
var resolvers = new Map();
var target = document.referrer;
try {
// After a refresh document.referrer won't match the parent window anymore. Any target is allowed
// when not in production.
if (process.env.NODE_ENV !== 'production') {
target = '*';
}
} catch (e) {}
// Setting process.env.NODE_ENV to 'production' or 'development' is a common practice. However,
// in environments where this isn't used, process is undefined. For this reason the check is
// wrapped in a try-catch statement.
/**

@@ -43,3 +54,6 @@ * @ignore This is exported for testing purposes.

}
var id = rpcCounter += 1;
// Use an immediate assignment of the incremented counter. This prevents an unlikely, yet possible
// race condition error.
// eslint-disable-next-line no-plusplus
var id = rpcCounter++;
parent.postMessage({

@@ -49,3 +63,3 @@ name: name,

args: args
}, host);
}, target);
return new Promise(function (resolve, reject) {

@@ -94,6 +108,7 @@ resolvers.set(id, { resolve: resolve, reject: reject });

addEventListener('message', function (event) {
// The message is from a source which isn't Appsemble.
if (event.source !== window.parent) {
return;
}
event.stopImmediatePropagation();
if (host === '*') {
host = event.origin;
}
if (event.data.type === 'rpc') {

@@ -100,0 +115,0 @@ handleRPCResponse(event.data);

{
"name": "appsemble",
"description": "The JavaScript SDK for communication with the Appsemble extension host.",
"version": "0.0.0-alpha.0",
"version": "0.0.0-alpha.1",
"license": "MIT",
"author": "Appsemble <support@appsemble.com> (https://www.appsemble.com)"
}
}

@@ -5,5 +5,6 @@ import { rpc } from './lib/communication'

/**
* Retrieve an instance of the set resource based on its id.
* Retrieve an entity of a resource model based on its id.
*
* @param {string} name - The name of the resource to retrieve.
* @param {Object} context - The context of the running extension.
* @param {string} name - The name of the resource model.
* @param {string} id - The id of data to retrieve.

@@ -17,5 +18,6 @@ *

/**
* Create an instance of the set resource in the backend.
* Create an entity of a resource model.
*
* @param {string} name - The name of the resource to push.
* @param {Object} context - The context of the running extension.
* @param {string} name - The name of the resource model.
* @param {Object} payload - The data to store in the backend.

@@ -29,7 +31,10 @@ *

/**
* Update an existing resource in the backend.
* Update an existing resource entity.
*
* @todo Update the payload by its id.
*
* @param {Object} context - The context of the running extension.
* @param {string} name - The name of the resource model.
* @param {string} id - The id of the resource that should be changed.
* @param {Object} payload - The new data to go into the backend.
* @param {string} id - The id of the entity to update.
*

@@ -42,6 +47,7 @@ * @returns {Object} A copy of the updated entity.

/**
* Remove a resource in the backend.
* Remove a resource entity.
*
* @param {Object} context - The context of the running extension.
* @param {string} name - The name of the resource model.
* @param {string} id - The id of the resource that should be changed.
* @param {string} id - The id of the entity to delete.
*

@@ -54,5 +60,7 @@ * @returns {null} - Resolves when the entity has been deleted successfully.

/**
* Retrieve all instances of specified resource.
* Retrieve all entities of specified resource model.
*
* @param {Object} context - The context of the running extension.
* @param {string} name - The name of the resource model.
* @param {...*} queryParams - The parameters for the query method.
*

@@ -59,0 +67,0 @@ * @returns {Array<Object>} - A list of entities matching the given name.

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