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

@shopify/app-bridge

Package Overview
Dependencies
Maintainers
11
Versions
322
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/app-bridge - npm Package Compare versions

Comparing version 1.0.0-1 to 1.0.0-3

actions/Features/actions.d.ts

4

actions/Button/actions.d.ts

@@ -7,3 +7,2 @@ /**

import { ActionSetProps, ClickAction, Component, MetaAction } from '../types';
import { ErrorAction } from '../Error';
import { Action, ClickPayload, Icon, Options, Payload, Style } from './types';

@@ -15,6 +14,4 @@ export interface ButtonUpdateAction extends MetaAction {

export declare type ButtonAction = ButtonUpdateAction | ClickAction | MetaAction;
export declare function getSafeButtonProps(props: Payload): Pick<Payload, "disabled" | "label" | "style" | "id" | "icon">;
export declare function clickButton(group: string, component: Component, payload?: ClickPayload): ClickAction;
export declare function update(group: string, component: Component, props: Payload): ButtonUpdateAction;
export declare function validationError(action: ButtonUpdateAction | ClickAction | MetaAction): undefined | ErrorAction;
export declare function isValidButtonProps(button: Payload): boolean;

@@ -32,4 +29,3 @@ export declare class Button extends ActionSet implements ActionSetProps<Options, Payload> {

dispatch(action: Action.CLICK, payload?: any): ActionSet;
private validateOptions;
}
export declare function create(app: ClientApplication<any>, options: Options): Button;

@@ -32,8 +32,3 @@ "use strict";

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");
function getSafeButtonProps(props) {
return helper_1.sanitizeProps(props, ['label', 'disabled', 'id', 'icon', 'style']);
}
exports.getSafeButtonProps = getSafeButtonProps;
function clickButton(group, component, payload) {

@@ -54,25 +49,6 @@ var id = component.id;

var buttonPayload = __assign({ id: id,
label: label }, getSafeButtonProps(props));
label: label }, props);
return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
}
exports.update = update;
function validationError(action) {
if (!action.hasOwnProperty('payload')) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
var payload;
switch (action.type) {
case types_2.ActionType.CLICK:
payload = action.payload;
return typeof payload.id === 'string'
? undefined
: Error_1.invalidPayload(action, Error_1.Message.INVALID_PAYLOAD_ID);
case types_2.ActionType.UPDATE:
payload = action.payload;
return isValidButtonProps(payload) ? undefined : Error_1.invalidPayload(action);
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
function isValidButtonProps(button) {

@@ -113,5 +89,2 @@ return typeof button.id === 'string' && typeof button.label === 'string';

var label = mergedOptions.label, disabled = mergedOptions.disabled, icon = mergedOptions.icon, style = mergedOptions.style;
if (!this.validateOptions(mergedOptions)) {
return this;
}
this.label = label;

@@ -135,20 +108,5 @@ this.disabled = !!disabled;

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
payload: this.payload,
type: action,
}));
}
return this;
};
Button.prototype.validateOptions = function (options) {
var buttonProps = __assign({ id: this.id }, options);
if (!isValidButtonProps(buttonProps)) {
var errorAction = update(this.group, this.component, buttonProps);
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
return false;
}
return true;
};
return Button;

@@ -155,0 +113,0 @@ }(helper_1.ActionSet));

@@ -8,3 +8,2 @@ /**

import { Button, Payload as ButtonPayload } from '../Button';
import { ErrorAction } from '../Error';
import { Action, Options, Payload } from './types';

@@ -19,5 +18,2 @@ export interface ButtonGroupUpdateAction extends MetaAction {

export declare function isGroupedButtonPayload(payload: Payload | object): payload is Payload;
export declare function getSafeButtonGroupProps(props: Payload): Pick<Payload, "disabled" | "label" | "id" | "buttons">;
export declare function validationError(action: ButtonGroupUpdateAction | MetaAction): undefined | ErrorAction;
export declare function isValidButtonGroupProps(buttonGroup: Payload): boolean;
export declare class ButtonGroup extends ActionSetWithChildren implements ActionSetProps<Options, Payload> {

@@ -36,4 +32,3 @@ label: string;

protected getButtons(buttonOptions?: Button[]): ButtonPayload[];
private validateOptions;
}
export declare function create(app: ClientApplication<any>, options: Options): ButtonGroup;

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

var types_1 = require("../types");
var Button_1 = require("../Button");
var Error_1 = require("../Error");
var types_2 = require("./types");

@@ -53,34 +51,2 @@ function update(group, component, props) {

exports.isGroupedButtonPayload = isGroupedButtonPayload;
function getSafeButtonGroupProps(props) {
return helper_1.sanitizeProps(props, ['label', 'disabled', 'buttons', 'id']);
}
exports.getSafeButtonGroupProps = getSafeButtonGroupProps;
function validationError(action) {
if (!action.hasOwnProperty('payload')) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
switch (action.type) {
case types_2.ActionType.UPDATE:
var payload = action.payload;
return isValidButtonGroupProps(payload) ? undefined : Error_1.invalidPayload(action);
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
function isValidButtonGroupProps(buttonGroup) {
if (typeof buttonGroup.id !== 'string' ||
typeof buttonGroup.label !== 'string' ||
!Array.isArray(buttonGroup.buttons)) {
return false;
}
for (var _i = 0, _a = buttonGroup.buttons; _i < _a.length; _i++) {
var button = _a[_i];
if (!Button_1.isValidButtonProps(button)) {
return false;
}
}
return true;
}
exports.isValidButtonGroupProps = isValidButtonGroupProps;
var ButtonGroup = /** @class */ (function (_super) {

@@ -118,5 +84,2 @@ __extends(ButtonGroup, _super);

var label = mergedOptions.label, disabled = mergedOptions.disabled, buttons = mergedOptions.buttons;
if (!this.validateOptions(mergedOptions)) {
return this;
}
this.label = label;

@@ -136,7 +99,2 @@ this.disabled = !!disabled;

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -152,3 +110,3 @@ return this;

var action = _a[_i];
updated = helper_1.updateActionFromPayload(action, Button_1.getSafeButtonProps(newPayload));
updated = helper_1.updateActionFromPayload(action, newPayload);
if (updated) {

@@ -178,11 +136,2 @@ break;

};
ButtonGroup.prototype.validateOptions = function (options) {
var buttonGroupProps = __assign({ id: this.id }, options);
if (!isValidButtonGroupProps(buttonGroupProps)) {
var errorAction = update(this.group, this.component, buttonGroupProps);
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
return false;
}
return true;
};
return ButtonGroup;

@@ -200,5 +149,5 @@ }(helper_1.ActionSetWithChildren));

var buttonPayload = __assign({ id: id,
label: label }, getSafeButtonGroupProps(props), { payload: payload });
label: label }, props, { payload: payload });
return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
}
//# sourceMappingURL=actions.js.map

@@ -6,6 +6,3 @@ /**

import { ActionSet } from '../helper';
import { MetaAction } from '../types';
import { ErrorAction } from '../Error';
import { Action, AddCustomerAddressPayload, AddLineItemPayload, Options, Payload, RemoveLineItemDiscountPayload, RemoveLineItemPayload, RemoveLineItemPropertiesPayload, RemovePropertiesPayload, SetCustomerPayload, SetDiscountPayload, SetLineItemDiscountPayload, SetLineItemPropertiesPayload, SetPropertiesPayload, UpdateCustomerAddressPayload, UpdateLineItemPayload } from './types';
export declare function validationError(action: MetaAction): undefined | ErrorAction;
/**

@@ -12,0 +9,0 @@ * Cart

@@ -32,178 +32,4 @@ "use strict";

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");
/**
* Validation
*/
function isValidAddress(address) {
return (helper_1.isValidOptionalString(address.address1) &&
helper_1.isValidOptionalString(address.address2) &&
helper_1.isValidOptionalString(address.city) &&
helper_1.isValidOptionalString(address.company) &&
helper_1.isValidOptionalString(address.firstName) &&
helper_1.isValidOptionalString(address.lastName) &&
helper_1.isValidOptionalString(address.phone) &&
helper_1.isValidOptionalString(address.provice) &&
helper_1.isValidOptionalString(address.country) &&
helper_1.isValidOptionalString(address.zip) &&
helper_1.isValidOptionalString(address.name) &&
helper_1.isValidOptionalString(address.proviceCode) &&
helper_1.isValidOptionalString(address.countryCode));
}
function isValidAddresses(addresses) {
if (!addresses) {
return true;
}
return Array.isArray(addresses) && addresses.every(isValidAddress);
}
function isValidCart(cart) {
return ((cart.cartDiscount === undefined || isValidDiscount(cart.cartDiscount)) &&
(cart.customer === undefined ||
isValidCustomer(cart.customer) ||
isValidAddresses(cart.customer.addresses)) &&
helper_1.isValidOptionalString(cart.grandTotal) &&
(cart.lineItems === undefined || isValidLineItems(cart.lineItems)) &&
isValidNoteAttributes(cart.noteAttributes) &&
helper_1.isValidOptionalString(cart.subTotal) &&
helper_1.isValidOptionalString(cart.taxTotal));
}
function isValidCustomer(customer) {
return (helper_1.isValidOptionalNumber(customer.id) &&
helper_1.isValidOptionalString(customer.email) &&
helper_1.isValidOptionalString(customer.firstName) &&
helper_1.isValidOptionalString(customer.lastName) &&
helper_1.isValidOptionalString(customer.note));
}
function isValidDiscount(discount) {
return (helper_1.isValidOptionalNumber(discount.amount) &&
helper_1.isValidOptionalString(discount.discountDescription) &&
helper_1.isValidOptionalString(discount.type) &&
helper_1.isValidOptionalString(discount.discountCode));
}
function isValidLineItemDiscount(discount) {
return (helper_1.isValidOptionalNumber(discount.amount) &&
helper_1.isValidOptionalString(discount.discountDescription) &&
helper_1.isValidOptionalString(discount.type));
}
function isValidLineItem(lineItem) {
return (helper_1.isValidOptionalNumber(lineItem.price) &&
typeof lineItem.quantity === 'number' &&
helper_1.isValidOptionalString(lineItem.title) &&
helper_1.isValidOptionalNumber(lineItem.variantId));
}
function isValidLineItems(lineItems) {
if (!lineItems) {
return true;
}
return Array.isArray(lineItems) && lineItems.every(isValidLineItem);
}
function isValidNoteAttributes(noteAttributes) {
return (noteAttributes === undefined ||
(Array.isArray(noteAttributes) &&
noteAttributes.every(function (note) { return typeof note.name === 'string' && typeof note.value === 'string'; })));
}
function isValidProperties(properties) {
return (typeof properties === 'object' &&
!Array.isArray(properties) &&
Object.keys(properties).every(function (key) { return typeof properties[key] === 'string'; }));
}
function isValidPropertiesKey(keys) {
return Array.isArray(keys) && keys.every(function (key) { return typeof key === 'string'; });
}
function validationError(action) {
if (!action.payload || typeof action.payload.id !== 'string') {
return Error_1.invalidPayload(action, 'Missing payload id');
}
var payload;
switch (action.type) {
case types_2.ActionType.FETCH:
return undefined;
case types_2.ActionType.UPDATE:
payload = action.payload;
return !payload.data || !isValidCart(payload.data)
? Error_1.invalidPayload(action, 'Invalid update payload')
: undefined;
case types_2.ActionType.SET_CUSTOMER:
payload = action.payload;
return !payload.data || !isValidCustomer(payload.data)
? Error_1.invalidPayload(action, 'Invalid set customer payload')
: undefined;
case types_2.ActionType.REMOVE_CUSTOMER:
return undefined;
case types_2.ActionType.ADD_CUSTOMER_ADDRESS:
payload = action.payload;
return !payload.data || !isValidAddress(payload.data)
? Error_1.invalidPayload(action, 'Invalid add customer address payload')
: undefined;
case types_2.ActionType.UPDATE_CUSTOMER_ADDRESS:
payload = action.payload;
return !payload.data || typeof payload.index !== 'number' || !isValidAddress(payload.data)
? Error_1.invalidPayload(action, 'Invalid update customer address payload')
: undefined;
case types_2.ActionType.SET_DISCOUNT:
payload = action.payload;
return !payload.data || !isValidDiscount(payload.data)
? Error_1.invalidPayload(action, 'Invalid set discount payload')
: undefined;
case types_2.ActionType.REMOVE_DISCOUNT:
return undefined;
case types_2.ActionType.SET_PROPERTIES:
payload = action.payload;
return !payload.data || !isValidProperties(payload.data)
? Error_1.invalidPayload(action, 'Invalid add properties payload')
: undefined;
case types_2.ActionType.REMOVE_PROPERTIES:
payload = action.payload;
return !payload.data || !isValidPropertiesKey(payload.data)
? Error_1.invalidPayload(action, 'Invalid remove properties payload')
: undefined;
case types_2.ActionType.CLEAR:
return undefined;
case types_2.ActionType.ADD_LINE_ITEM:
payload = action.payload;
return !payload.data || !isValidLineItem(payload.data)
? Error_1.invalidPayload(action, 'Invalid add line item payload')
: undefined;
case types_2.ActionType.UPDATE_LINE_ITEM:
payload = action.payload;
return !payload.data ||
typeof payload.index !== 'number' ||
typeof payload.data.quantity !== 'number'
? Error_1.invalidPayload(action, 'Invalid update line item payload')
: undefined;
case types_2.ActionType.REMOVE_LINE_ITEM:
payload = action.payload;
return typeof payload.index !== 'number'
? Error_1.invalidPayload(action, 'Invalid remove line item payload')
: undefined;
case types_2.ActionType.SET_LINE_ITEM_DISCOUNT:
payload = action.payload;
return !payload.data ||
typeof payload.index !== 'number' ||
!isValidLineItemDiscount(payload.data)
? Error_1.invalidPayload(action, 'Invalid set line item discount payload')
: undefined;
case types_2.ActionType.REMOVE_LINE_ITEM_DISCOUNT:
payload = action.payload;
return typeof payload.index !== 'number'
? Error_1.invalidPayload(action, 'Invalid remove line item discount payload')
: undefined;
case types_2.ActionType.SET_LINE_ITEM_PROPERTIES:
payload = action.payload;
return !payload.data || typeof payload.index !== 'number' || !isValidProperties(payload.data)
? Error_1.invalidPayload(action, 'Invalid add line item properties payload')
: undefined;
case types_2.ActionType.REMOVE_LINE_ITEM_PROPERTIES:
payload = action.payload;
return !payload.data ||
typeof payload.index !== 'number' ||
!isValidPropertiesKey(payload.data)
? Error_1.invalidPayload(action, 'Invalid remove line item properties payload')
: undefined;
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
/**
* Cart

@@ -272,7 +98,2 @@ */

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -279,0 +100,0 @@ return this;

@@ -7,5 +7,5 @@ /**

import { Options } from '../Toast/types';
export { ActionBase, clear, ClearAction, show, ShowAction, ToastAction as FlashAction, validationError, } from '../Toast';
export { ActionBase, clear, ClearAction, show, ShowAction, ToastAction as FlashAction, } from '../Toast';
export declare class Flash extends Toast {
}
export declare function create(app: ClientApplication<any>, options: Options): Flash;

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

exports.show = Toast_2.show;
exports.validationError = Toast_2.validationError;
var Flash = /** @class */ (function (_super) {

@@ -26,0 +25,0 @@ __extends(Flash, _super);

@@ -5,3 +5,3 @@ import { ClientApplication } from '../client';

export declare function actionWrapper(action: any): any;
export declare function getVersion(): string;
export declare function getVersion(): any;
export declare function getEventNameSpace(group: string, eventName: string, component?: Component): string;

@@ -11,10 +11,11 @@ export declare function isValidOptionalNumber(value?: number): boolean;

export declare abstract class ActionSet implements ActionSetInterface {
app: ClientApplication<any>;
type: string;
group: string;
readonly id: string;
readonly type: string;
readonly app: ClientApplication<any>;
readonly defaultGroup: string;
group: string;
subgroups: string[];
subscriptions: ActionSubscription[];
constructor(app: ClientApplication<any>, type: string, group: string, id?: string);
set(..._: any): void;
readonly component: Component;

@@ -38,3 +39,2 @@ updateSubscription(subscriptionToRemove: ActionSubscription, group: string, subgroups: string[]): Unsubscribe;

export declare type ActionSetChildAction = ActionSet | ActionSetWithChildren;
export declare function sanitizeProps<Prop, Key extends keyof Prop>(obj: Prop, keys: Key[]): Pick<Prop, Key>;
export declare function updateActionFromPayload<A extends Partial<ActionSetInterface>>(action: A, newProps: A): boolean;

@@ -41,0 +41,0 @@ export declare function getMergedProps<Prop extends Indexable>(props: Prop, newProps: Partial<Prop>): Prop;

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

var Error_1 = require("../actions/Error");
var client_1 = require("../client");
var collection_1 = require("../util/collection");

@@ -37,3 +38,3 @@ var constants_1 = require("./constants");

var uuid_1 = __importDefault(require("./uuid"));
var packageJson = require("../package.json");
var packageJson = require('../package.json');
var SEPARATOR = '::';

@@ -78,2 +79,6 @@ function actionWrapper(action) {

function ActionSet(app, type, group, id) {
var _this = this;
this.app = app;
this.type = type;
this.group = group;
this.subgroups = [];

@@ -85,7 +90,19 @@ this.subscriptions = [];

this.id = id || uuid_1.default();
this.app = app;
this.type = type;
this.group = group;
this.defaultGroup = group;
var defaultSet = this.set;
this.set = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _a;
return (_a = _this.app.hooks).run.apply(_a, [client_1.LifecycleHook.UpdateAction, defaultSet, _this].concat(args));
};
}
ActionSet.prototype.set = function () {
var _ = [];
for (var _i = 0; _i < arguments.length; _i++) {
_[_i] = arguments[_i];
}
};
Object.defineProperty(ActionSet.prototype, "component", {

@@ -314,12 +331,2 @@ get: function () {

}
function sanitizeProps(obj, keys) {
var newObj = {};
keys.forEach(function (key) {
if (obj.hasOwnProperty(key)) {
newObj[key] = obj[key];
}
});
return newObj;
}
exports.sanitizeProps = sanitizeProps;
function updateActionFromPayload(action, newProps) {

@@ -326,0 +333,0 @@ var id = action.id;

@@ -7,5 +7,5 @@ export * from './types';

import * as Flash from './Flash';
import * as Features from './Features';
import * as Loading from './Loading';
import * as Modal from './Modal';
import * as Navigation from './Navigation';
import * as History from './Navigation/History';

@@ -18,2 +18,2 @@ import * as Redirect from './Navigation/Redirect';

import { isAppBridgeAction } from './validator';
export { isAppBridgeAction, Button, ButtonGroup, Cart, Error, Flash, Toast, Navigation, History, Loading, Modal, Print, Redirect, ResourcePicker, TitleBar, };
export { isAppBridgeAction, Button, ButtonGroup, Cart, Error, Flash, Features, Toast, History, Loading, Modal, Print, Redirect, ResourcePicker, TitleBar, };

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

exports.Flash = Flash;
var Features = __importStar(require("./Features"));
exports.Features = Features;
var Loading = __importStar(require("./Loading"));

@@ -29,4 +31,2 @@ exports.Loading = Loading;

exports.Modal = Modal;
var Navigation = __importStar(require("./Navigation"));
exports.Navigation = Navigation;
var History = __importStar(require("./Navigation/History"));

@@ -33,0 +33,0 @@ exports.History = History;

@@ -7,3 +7,2 @@ /**

import { ActionSetPayload, MetaAction } from '../types';
import { ErrorAction } from '../Error';
import { Action, Payload } from './types';

@@ -13,3 +12,2 @@ export declare type LoadingAction = MetaAction;

export declare function stop(payload?: Payload): LoadingAction;
export declare function validationError<A extends MetaAction>(action: A): undefined | ErrorAction;
export declare class Loading extends ActionSet implements ActionSetPayload<Payload> {

@@ -16,0 +14,0 @@ constructor(app: ClientApplication<any>);

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

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");

@@ -40,13 +39,2 @@ function start(payload) {

exports.stop = stop;
function validationError(action) {
switch (action.type) {
case types_2.ActionType.START:
case types_2.ActionType.STOP:
// No validation since there should not be a payload
return undefined;
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
var Loading = /** @class */ (function (_super) {

@@ -72,7 +60,2 @@ __extends(Loading, _super);

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -79,0 +62,0 @@ return this;

@@ -7,4 +7,5 @@ "use strict";

}
// If setting to a different object type, don't merge any props
if (!Object.getPrototypeOf(obj).isPrototypeOf(newObj)) {
// If setting to a different prototype or a non-object or non-array, don't merge any props
if (!Object.getPrototypeOf(obj).isPrototypeOf(newObj) ||
(newObj.constructor.name !== 'Object' && newObj.constructor.name !== 'Array')) {
return newObj;

@@ -11,0 +12,0 @@ }

@@ -8,3 +8,2 @@ /**

import { Button, Payload as ButtonPayload } from '../Button';
import { ErrorAction } from '../Error';
import { Action, ActionType, ClosePayload, Footer, FooterOptions, IframeOptions, IframePayload, MessageOptions, MessagePayload, Size } from './types';

@@ -27,7 +26,2 @@ export interface ActionBase extends MetaAction {

export declare function update(payload: MessagePayload | IframePayload): UpdateAction;
export declare function isValidSrc(options: Partial<IframeOptions | IframePayload>, localOrigin?: string): boolean;
export declare function validationError(action: OpenAction | UpdateAction | CloseAction | ClickAction | MetaAction, localOrigin?: string): undefined | ErrorAction;
export declare function isValidModalProps(props: (MessageOptions | IframeOptions) | (MessagePayload | IframePayload) | undefined, localOrigin?: string): boolean;
export declare function isValidModalFooter(footer?: Footer): boolean;
export declare function isValidModalSize(size?: string): boolean;
export declare function isIframeModal(options: MessagePayload | IframePayload | object): options is IframePayload;

@@ -50,3 +44,2 @@ export declare function isMessageModal(options: MessagePayload | IframePayload | object): options is MessagePayload;

protected updateSecondaryFooterButton(newPayload: ButtonPayload, updateCb: () => void): void;
protected validateOptions(options: MessageOptions | IframeOptions): boolean;
}

@@ -53,0 +46,0 @@ export declare class ModalMessage extends Modal implements ActionSetProps<MessageOptions, MessagePayload> {

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

Object.defineProperty(exports, "__esModule", { value: true });
var safe_redirect_1 = require("../../util/@shopify/safe-redirect");
var buttonHelper_1 = require("../buttonHelper");

@@ -33,4 +32,2 @@ var helper_1 = require("../helper");

var Button_1 = require("../Button");
var Error_1 = require("../Error");
var helper_2 = require("../Navigation/helper");
var types_2 = require("./types");

@@ -71,125 +68,2 @@ var FOOTER_BUTTON_PROPS = {

exports.update = update;
function isValidSrc(options, localOrigin) {
var url = options.url, path = options.path;
if (!url && !path) {
return false;
}
if (path && !helper_2.isValidRelativePath(path)) {
return false;
}
if (url) {
if (!localOrigin) {
return false;
}
if (!helper_2.isValidAbsolutePath(url)) {
return false;
}
var hostName = void 0;
try {
hostName = new URL(localOrigin).hostname;
}
catch (error) {
return false;
}
var isSafeSrc = safe_redirect_1.isSafe(url, {
requireAbsolute: true,
requireSSL: true,
whitelist: [hostName],
});
if (!isSafeSrc) {
return false;
}
}
return true;
}
exports.isValidSrc = isValidSrc;
function validationError(action, localOrigin) {
var payload;
switch (action.type) {
case types_2.ActionType.OPEN:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
if (payload.id && typeof payload.id !== 'string') {
return Error_1.invalidPayload(action, Error_1.Message.INVALID_PAYLOAD_ID);
}
return isValidModalProps(payload, localOrigin) ? undefined : Error_1.invalidPayload(action);
case types_2.ActionType.UPDATE:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
if (typeof payload.id !== 'string') {
return Error_1.invalidPayload(action, Error_1.Message.INVALID_PAYLOAD_ID);
}
// Id is always required when updating
return isValidModalProps(payload, localOrigin) ? undefined : Error_1.invalidPayload(action);
case types_2.ActionType.CLOSE:
payload = action.payload;
if (payload && payload.id && typeof payload.id !== 'string') {
return Error_1.invalidPayload(action, Error_1.Message.INVALID_PAYLOAD_ID);
}
return undefined;
case types_2.FooterActionType.FOOTER_BUTTON_CLICK:
return Button_1.validationError(__assign({}, action, { type: Button_1.ActionType.CLICK }));
case types_2.FooterActionType.FOOTER_BUTTON_UPDATE:
return Button_1.validationError(__assign({}, action, { type: Button_1.ActionType.UPDATE }));
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
function isValidModalProps(props, localOrigin) {
if (props === undefined) {
return false;
}
if (isIframeModal(props) &&
(typeof localOrigin !== 'string' || !isValidSrc(props, localOrigin))) {
return false;
}
return ((isMessageModal(props) || isIframeModal(props)) &&
isValidModalFooter(props.footer) &&
isValidModalSize(props.size));
}
exports.isValidModalProps = isValidModalProps;
function isValidModalFooter(footer) {
if (footer === undefined || !footer.hasOwnProperty('buttons')) {
return true;
}
if (footer.hasOwnProperty('buttons') &&
(Array.isArray(footer.buttons) || typeof footer.buttons !== 'object')) {
return false;
}
var _a = footer.buttons, secondary = _a.secondary, primary = _a.primary;
if (primary && !Button_1.isValidButtonProps(primary)) {
return false;
}
if (secondary && !Array.isArray(secondary)) {
return false;
}
else if (Array.isArray(secondary)) {
for (var _i = 0, secondary_1 = secondary; _i < secondary_1.length; _i++) {
var button = secondary_1[_i];
if (!Button_1.isValidButtonProps(button)) {
return false;
}
}
}
return true;
}
exports.isValidModalFooter = isValidModalFooter;
function isValidModalSize(size) {
if (size === undefined) {
return true;
}
var valid = false;
helper_1.forEachInEnum(types_2.Size, function (sizeOption) {
if (size === sizeOption) {
valid = true;
}
});
return valid;
}
exports.isValidModalSize = isValidModalSize;
function isIframeModal(options) {

@@ -278,3 +152,3 @@ return (typeof options.url === 'string' ||

}
if (helper_1.updateActionFromPayload(this.footer.buttons.primary, Button_1.getSafeButtonProps(newPayload))) {
if (helper_1.updateActionFromPayload(this.footer.buttons.primary, newPayload)) {
updateCb();

@@ -290,3 +164,3 @@ }

var action = _a[_i];
updated = helper_1.updateActionFromPayload(action, Button_1.getSafeButtonProps(newPayload));
updated = helper_1.updateActionFromPayload(action, newPayload);
if (updated) {

@@ -300,11 +174,2 @@ break;

};
Modal.prototype.validateOptions = function (options) {
var props = __assign({ id: this.id }, options);
if (!isValidModalProps(options, this.app.localOrigin)) {
var errorAction = update(props);
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
return false;
}
return true;
};
return Modal;

@@ -344,5 +209,2 @@ }(helper_1.ActionSetWithChildren));

var title = mergedOptions.title, footer = mergedOptions.footer, message = mergedOptions.message, size = mergedOptions.size;
if (!this.validateOptions(mergedOptions)) {
return this;
}
this.title = title;

@@ -373,7 +235,2 @@ this.message = message;

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -417,5 +274,2 @@ return this;

var title = mergedOptions.title, footer = mergedOptions.footer, path = mergedOptions.path, url = mergedOptions.url, size = mergedOptions.size;
if (!this.validateOptions(mergedOptions)) {
return this;
}
this.title = title;

@@ -447,7 +301,2 @@ this.url = url;

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -454,0 +303,0 @@ return this;

@@ -13,5 +13,3 @@ /**

CLOSE = "APP::MODAL::CLOSE",
UPDATE = "APP::MODAL::UPDATE"
}
export declare enum FooterActionType {
UPDATE = "APP::MODAL::UPDATE",
FOOTER_BUTTON_CLICK = "APP::MODAL::FOOTER::BUTTON::CLICK",

@@ -18,0 +16,0 @@ FOOTER_BUTTON_UPDATE = "APP::MODAL::FOOTER::BUTTON::UPDATE"

@@ -17,8 +17,5 @@ "use strict";

ActionType["UPDATE"] = "APP::MODAL::UPDATE";
ActionType["FOOTER_BUTTON_CLICK"] = "APP::MODAL::FOOTER::BUTTON::CLICK";
ActionType["FOOTER_BUTTON_UPDATE"] = "APP::MODAL::FOOTER::BUTTON::UPDATE";
})(ActionType = exports.ActionType || (exports.ActionType = {}));
var FooterActionType;
(function (FooterActionType) {
FooterActionType["FOOTER_BUTTON_CLICK"] = "APP::MODAL::FOOTER::BUTTON::CLICK";
FooterActionType["FOOTER_BUTTON_UPDATE"] = "APP::MODAL::FOOTER::BUTTON::UPDATE";
})(FooterActionType = exports.FooterActionType || (exports.FooterActionType = {}));
var Size;

@@ -25,0 +22,0 @@ (function (Size) {

@@ -7,3 +7,2 @@ /**

import { ComplexDispatch, MetaAction } from '../../types';
import { ErrorAction } from '../../Error';
import { Action, Payload } from './types';

@@ -15,3 +14,2 @@ export interface HistoryAction extends MetaAction {

export declare function replace(payload: Payload): HistoryAction;
export declare function validationError(action: HistoryAction | MetaAction): undefined | ErrorAction;
export declare class History extends ActionSet implements ComplexDispatch<string> {

@@ -18,0 +16,0 @@ constructor(app: ClientApplication<any>);

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

var types_1 = require("../../types");
var Error_1 = require("../../Error");
var helper_2 = require("../helper");
var types_2 = require("./types");

@@ -49,19 +47,2 @@ function push(payload) {

exports.replace = replace;
function validationError(action) {
var payload;
switch (action.type) {
case types_2.ActionType.REPLACE:
case types_2.ActionType.PUSH:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
return helper_2.isValidAbsolutePath(payload.path) || helper_2.isValidRelativePath(payload.path)
? undefined
: Error_1.invalidPayload(action, 'Invalid path provided. Expected a relative or absolute https or http path');
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
var History = /** @class */ (function (_super) {

@@ -88,7 +69,2 @@ __extends(History, _super);

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
type: type,
group: this.group,
}));
}

@@ -95,0 +71,0 @@ return this;

@@ -7,3 +7,2 @@ /**

import { ComplexDispatch, Group, MetaAction } from '../../types';
import { ErrorAction } from '../../Error';
import { Action, ActionType, AdminPathPayload, AdminSectionPayload, AppPayload, CreateResource, ProductVariantResource, RemotePayload, ResourceInfo, Section } from './types';

@@ -40,4 +39,2 @@ export interface ActionBase extends MetaAction {

export declare function toApp(payload: AppPayload): AppAction;
export declare function isValidAdminResource(section?: Section): boolean;
export declare function validationError(action: RedirectAction): undefined | ErrorAction;
export declare class Redirect extends ActionSet implements ComplexDispatch<Section | string> {

@@ -44,0 +41,0 @@ constructor(app: ClientApplication<any>);

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

var types_1 = require("../../types");
var Error_1 = require("../../Error");
var helper_2 = require("../helper");
var types_2 = require("./types");

@@ -91,66 +89,2 @@ function isResourcePayload(resource) {

exports.toApp = toApp;
function isValidAdminResource(section) {
if (section === undefined) {
return false;
}
var name = section.name, resource = section.resource;
if (!name) {
return false;
}
var valid = false;
helper_1.forEachInEnum(types_2.ResourceType, function (resourceName) {
if (name === resourceName) {
valid = true;
}
});
if (!valid) {
return false;
}
return (resource === undefined ||
isProductVariantResourcePayload(resource) ||
isProductVariantCreateResourcePayload(resource) ||
isCreateResourcePayload(resource) ||
isResourcePayload(resource));
}
exports.isValidAdminResource = isValidAdminResource;
function validationError(action) {
var payload;
switch (action.type) {
case types_2.ActionType.ADMIN_PATH:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
return helper_2.isValidRelativePath(payload.path)
? undefined
: Error_1.invalidPayload(action, 'Path is invalid. Expecting relative path');
case types_2.ActionType.REMOTE:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
return helper_2.isValidAbsolutePath(payload.url)
? undefined
: Error_1.invalidPayload(action, 'Url is invalid. Expecting absolute url');
case types_2.ActionType.APP:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
return helper_2.isValidRelativePath(payload.path)
? undefined
: Error_1.invalidPayload(action, 'Path is invalid. Expecting relative path');
case types_2.ActionType.ADMIN_SECTION:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
return isValidAdminResource(payload.section)
? undefined
: Error_1.invalidPayload(action, 'Invalid admin section resource');
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
function isAdminPathPayload(payload) {

@@ -198,7 +132,2 @@ return typeof payload === 'object' && payload.hasOwnProperty('path');

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -205,0 +134,0 @@ return this;

@@ -5,5 +5,3 @@ /**

import { MetaAction } from '../types';
import { ErrorAction } from '../Error';
export declare type PrintAction = MetaAction;
export declare function app(): PrintAction;
export declare function validationError(action: MetaAction): undefined | ErrorAction;

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

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");

@@ -18,12 +17,2 @@ function app() {

exports.app = app;
function validationError(action) {
switch (action.type) {
case types_2.ActionType.APP:
// No validation since there should not be a payload
return undefined;
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
//# sourceMappingURL=actions.js.map

@@ -5,3 +5,2 @@ /**

import { ClientApplication } from '../../client';
import { ErrorAction } from '../Error';
import { ActionSet } from '../helper';

@@ -35,3 +34,2 @@ import { ActionSetProps, Group, MetaAction } from '../types';

export declare function update(payload: Payload): UpdateAction;
export declare function validationError(action: ResourcePickerAction): undefined | ErrorAction;
export declare class ResourcePicker extends ActionSet implements ActionSetProps<Options | ProductOptions, Payload> {

@@ -38,0 +36,0 @@ readonly resourceType: ResourceType;

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

Object.defineProperty(exports, "__esModule", { value: true });
var Error_1 = require("../Error");
var helper_1 = require("../helper");

@@ -75,33 +74,2 @@ var types_1 = require("../types");

exports.update = update;
function isValidResourceType(resourceType) {
return helper_1.findMatchInEnum(types_2.ResourceType, resourceType);
}
function validationError(action) {
var payload;
switch (action.type) {
case types_2.ActionType.UPDATE:
case types_2.ActionType.OPEN:
payload = action.payload;
return payload !== undefined &&
payload.id !== undefined &&
typeof payload.id === 'string' &&
isValidResourceType(payload.resourceType)
? undefined
: Error_1.invalidPayload(action);
case types_2.ActionType.SELECT:
payload = action.payload;
return payload !== undefined &&
payload.id !== undefined &&
typeof payload.id === 'string' &&
Array.isArray(payload.selection)
? undefined
: Error_1.invalidPayload(action);
case types_2.ActionType.CANCEL:
case types_2.ActionType.CLOSE:
return undefined;
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
var ResourcePicker = /** @class */ (function (_super) {

@@ -112,9 +80,2 @@ __extends(ResourcePicker, _super);

_this.selection = [];
if (!isValidResourceType(resourceType)) {
var errorAction = helper_1.actionWrapper({
group: types_1.Group.ResourcePicker,
payload: __assign({ id: _this.id }, options, { resourceType: resourceType }),
});
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
}
_this.resourceType = resourceType;

@@ -174,8 +135,2 @@ _this.set(options, false);

}
else {
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}
return this;

@@ -182,0 +137,0 @@ };

@@ -9,3 +9,2 @@ /**

import { ActionSetProps, ClickAction, Group, MetaAction } from '../types';
import { ErrorAction } from '../Error';
import { Action, ButtonsOptions as TitleBarButtonsOptions, ButtonsPayload as TitleBarButtonsPayload, Options, Payload } from './types';

@@ -20,7 +19,2 @@ export interface UpdateAction extends MetaAction {

export declare function update(payload: Payload): UpdateAction;
export declare function isValidTitleBarPayload(payload: Payload): boolean;
export declare function isValidTitleBarProps(props: Payload | Options): boolean;
export declare function isValidTitleBarButtons(buttons?: TitleBarButtonsPayload): boolean;
export declare function isValidTitleBarBreadcrumbs(button?: ButtonPayload): boolean;
export declare function validationError(action: TitleBarAction): undefined | ErrorAction;
export declare class TitleBar extends ActionSetWithChildren implements ActionSetProps<Options, Payload> {

@@ -49,4 +43,3 @@ title?: string;

protected getChildButton(newAction: undefined | Button, currentAction: undefined | Button): Button | undefined;
private validateOptions;
}
export declare function create(app: ClientApplication<any>, options: Options): TitleBar;

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

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");

@@ -67,77 +66,2 @@ var TITLEBAR_BUTTON_PROPS = {

exports.update = update;
function isValidTitleBarPayload(payload) {
if (!payload) {
return false;
}
return ((payload.id === undefined || typeof payload.id === 'string') && isValidTitleBarProps(payload));
}
exports.isValidTitleBarPayload = isValidTitleBarPayload;
function isValidTitleBarProps(props) {
return ((typeof props.title === 'string' || props.title === undefined) &&
isValidTitleBarButtons(props.buttons) &&
isValidTitleBarBreadcrumbs(props.breadcrumbs));
}
exports.isValidTitleBarProps = isValidTitleBarProps;
function isValidTitleBarButtons(buttons) {
if (buttons === undefined) {
return true;
}
if (typeof buttons !== 'object' || Array.isArray(buttons)) {
return false;
}
var primary = buttons.primary;
var secondary = buttons.secondary;
if (primary && !Button_1.isValidButtonProps(primary)) {
return false;
}
if (secondary !== undefined && !Array.isArray(secondary)) {
return false;
}
if (Array.isArray(secondary)) {
for (var _i = 0, secondary_1 = secondary; _i < secondary_1.length; _i++) {
var button = secondary_1[_i];
if (ButtonGroup_1.isGroupedButtonPayload(button) && ButtonGroup_1.isValidButtonGroupProps(button)) {
continue;
}
else if (!ButtonGroup_1.isGroupedButtonPayload(button) && Button_1.isValidButtonProps(button)) {
continue;
}
return false;
}
}
return true;
}
exports.isValidTitleBarButtons = isValidTitleBarButtons;
function isValidTitleBarBreadcrumbs(button) {
if (button === undefined || Button_1.isValidButtonProps(button)) {
return true;
}
return false;
}
exports.isValidTitleBarBreadcrumbs = isValidTitleBarBreadcrumbs;
function validationError(action) {
var payload;
switch (action.type) {
case types_2.ActionType.UPDATE:
payload = action.payload;
if (payload === undefined) {
return Error_1.invalidPayload(action, Error_1.Message.MISSING_PAYLOAD);
}
if (typeof payload.id !== 'string') {
return Error_1.invalidPayload(action, Error_1.Message.INVALID_PAYLOAD_ID);
}
return isValidTitleBarPayload(payload) ? undefined : Error_1.invalidPayload(action);
case types_2.ButtonsActionType.BUTTON_CLICK:
case types_2.ButtonsActionType.BREADCRUMBS_CLICK:
return Button_1.validationError(__assign({}, action, { type: Button_1.ActionType.CLICK }));
case types_2.ButtonsActionType.BUTTON_UPDATE:
case types_2.ButtonsActionType.BREADCRUMBS_UPDATE:
return Button_1.validationError(__assign({}, action, { type: Button_1.ActionType.UPDATE }));
case types_2.ButtonsActionType.BUTTON_GROUP_UPDATE:
return ButtonGroup_1.validationError(__assign({}, action, { type: ButtonGroup_1.ActionType.UPDATE }));
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
var TitleBar = /** @class */ (function (_super) {

@@ -199,5 +123,2 @@ __extends(TitleBar, _super);

var title = mergedOptions.title, buttons = mergedOptions.buttons, breadcrumbs = mergedOptions.breadcrumbs;
if (!this.validateOptions(mergedOptions)) {
return this;
}
this.title = title;

@@ -217,7 +138,2 @@ this.setBreadcrumbs(breadcrumbs);

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}

@@ -236,3 +152,3 @@ return this;

}
if (helper_1.updateActionFromPayload(this.primary, Button_1.getSafeButtonProps(newPayload))) {
if (helper_1.updateActionFromPayload(this.primary, newPayload)) {
this.dispatch(types_2.Action.UPDATE);

@@ -251,6 +167,6 @@ }

if (ButtonGroup_1.isGroupedButtonPayload(newPayload)) {
updated = helper_1.updateActionFromPayload(buttonToUpdate, ButtonGroup_1.getSafeButtonGroupProps(newPayload));
updated = helper_1.updateActionFromPayload(buttonToUpdate, newPayload);
}
else {
updated = helper_1.updateActionFromPayload(buttonToUpdate, Button_1.getSafeButtonProps(newPayload));
updated = helper_1.updateActionFromPayload(buttonToUpdate, newPayload);
}

@@ -265,3 +181,3 @@ if (updated) {

}
if (helper_1.updateActionFromPayload(this.breadcrumb, Button_1.getSafeButtonProps(newPayload))) {
if (helper_1.updateActionFromPayload(this.breadcrumb, newPayload)) {
this.dispatch(types_2.Action.UPDATE);

@@ -299,11 +215,2 @@ }

};
TitleBar.prototype.validateOptions = function (options) {
var props = __assign({ id: this.id }, options);
if (!isValidTitleBarProps(options)) {
var errorAction = update(props);
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
return false;
}
return true;
};
return TitleBar;

@@ -310,0 +217,0 @@ }(helper_1.ActionSetWithChildren));

@@ -10,5 +10,3 @@ /**

export declare enum ActionType {
UPDATE = "APP::TITLEBAR::UPDATE"
}
export declare enum ButtonsActionType {
UPDATE = "APP::TITLEBAR::UPDATE",
BUTTON_CLICK = "APP::TITLEBAR::BUTTONS::BUTTON::CLICK",

@@ -15,0 +13,0 @@ BUTTON_UPDATE = "APP::TITLEBAR::BUTTONS::BUTTON::UPDATE",

@@ -10,11 +10,8 @@ "use strict";

ActionType["UPDATE"] = "APP::TITLEBAR::UPDATE";
ActionType["BUTTON_CLICK"] = "APP::TITLEBAR::BUTTONS::BUTTON::CLICK";
ActionType["BUTTON_UPDATE"] = "APP::TITLEBAR::BUTTONS::BUTTON::UPDATE";
ActionType["BUTTON_GROUP_UPDATE"] = "APP::TITLEBAR::BUTTONS::BUTTONGROUP::UPDATE";
ActionType["BREADCRUMBS_CLICK"] = "APP::TITLEBAR::BREADCRUMBS::BUTTON::CLICK";
ActionType["BREADCRUMBS_UPDATE"] = "APP::TITLEBAR::BREADCRUMBS::BUTTON::UPDATE";
})(ActionType = exports.ActionType || (exports.ActionType = {}));
var ButtonsActionType;
(function (ButtonsActionType) {
ButtonsActionType["BUTTON_CLICK"] = "APP::TITLEBAR::BUTTONS::BUTTON::CLICK";
ButtonsActionType["BUTTON_UPDATE"] = "APP::TITLEBAR::BUTTONS::BUTTON::UPDATE";
ButtonsActionType["BUTTON_GROUP_UPDATE"] = "APP::TITLEBAR::BUTTONS::BUTTONGROUP::UPDATE";
ButtonsActionType["BREADCRUMBS_CLICK"] = "APP::TITLEBAR::BREADCRUMBS::BUTTON::CLICK";
ButtonsActionType["BREADCRUMBS_UPDATE"] = "APP::TITLEBAR::BREADCRUMBS::BUTTON::UPDATE";
})(ButtonsActionType = exports.ButtonsActionType || (exports.ButtonsActionType = {}));
//# sourceMappingURL=types.js.map

@@ -7,3 +7,2 @@ /**

import { ActionSetProps, Group, MetaAction } from '../types';
import { ErrorAction } from '../Error';
import { Action, ActionType, ClearPayload, Options, Payload } from './types';

@@ -23,6 +22,4 @@ export interface ActionBase extends MetaAction {

export declare function clear(payload: ClearPayload): ClearAction;
export declare function validationError(action: ShowAction | ClearAction | MetaAction): undefined | ErrorAction;
export declare class Toast extends ActionSet implements ActionSetProps<Options, Payload> {
message: string;
isDismissible?: boolean;
duration: number;

@@ -35,4 +32,3 @@ isError?: boolean;

dispatch(action: Action): this;
private validateOptions;
}
export declare function create(app: ClientApplication<any>, options: Options): Toast;

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

var types_1 = require("../types");
var Error_1 = require("../Error");
var types_2 = require("./types");

@@ -51,25 +50,2 @@ function show(toastMessage) {

exports.clear = clear;
function validationError(action) {
var payload;
switch (action.type) {
case types_2.ActionType.CLEAR:
payload = action.payload;
return payload === undefined || (payload.id === undefined || typeof payload.id === 'string')
? undefined
: Error_1.invalidPayload(action, 'Id in payload is invalid');
case types_2.ActionType.SHOW:
payload = action.payload;
return payload !== undefined &&
(payload.id === undefined || typeof payload.id === 'string') &&
isValidToastProps(payload)
? undefined
: Error_1.invalidPayload(action);
default:
return Error_1.invalidActionType(action);
}
}
exports.validationError = validationError;
function isValidToastProps(props) {
return typeof props.message === 'string' && typeof props.duration === 'number';
}
var Toast = /** @class */ (function (_super) {

@@ -88,3 +64,2 @@ __extends(Toast, _super);

duration: this.duration,
isDismissible: this.isDismissible,
isError: this.isError,

@@ -106,8 +81,4 @@ message: this.message,

var mergedOptions = helper_1.getMergedProps(this.options, options);
var message = mergedOptions.message, isDismissible = mergedOptions.isDismissible, duration = mergedOptions.duration, isError = mergedOptions.isError;
if (!this.validateOptions(mergedOptions)) {
return this;
}
var message = mergedOptions.message, duration = mergedOptions.duration, isError = mergedOptions.isError;
this.message = message;
this.isDismissible = isDismissible;
this.duration = duration;

@@ -126,21 +97,5 @@ this.isError = isError;

break;
default:
Error_1.throwError(Error_1.ActionType.INVALID_ACTION_TYPE, helper_1.actionWrapper({
group: this.group,
type: action,
}));
}
return this;
};
Toast.prototype.validateOptions = function (options) {
if (!isValidToastProps(options)) {
var errorAction = helper_1.actionWrapper({
group: types_1.Group.Toast,
payload: __assign({ id: this.id }, options),
});
Error_1.throwError(Error_1.ActionType.INVALID_OPTIONS, errorAction);
return false;
}
return true;
};
return Toast;

@@ -147,0 +102,0 @@ }(helper_1.ActionSet));

@@ -12,2 +12,3 @@ /**

Error = "Error",
Features = "Features",
Toast = "Toast",

@@ -14,0 +15,0 @@ Loading = "Loading",

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

Group["Error"] = "Error";
Group["Features"] = "Features";
Group["Toast"] = "Toast";

@@ -14,0 +15,0 @@ Group["Loading"] = "Loading";

import { MetaAction } from '../actions/types';
import { ErrorAction } from '../actions/Error';
import { Indexable } from './merge';
export declare function isAppBridgeAction(action: any): action is MetaAction;
export declare function isFromApp(action: any): boolean;
export declare function isAppMessage(event: any): boolean;
export declare function validatedActionPayload<A extends MetaAction>(action: A, origin?: string): ErrorAction | A;
export declare function validatedAction<A extends Indexable>(action: A, origin?: string): ErrorAction | A;
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var Actions = __importStar(require("../actions"));
var Error_1 = require("../actions/Error");
var constants_1 = require("./constants");
var MANDATORY_ACTION_PROPS = ['group', 'type', 'version'];
function isAppBridgeAction(action) {

@@ -35,44 +25,2 @@ return (action instanceof Object &&

exports.isAppMessage = isAppMessage;
function validatedActionPayload(action, origin) {
switch (action.group) {
case Actions.Group.Button:
return Actions.Button.validationError(action) || action;
case Actions.Group.ButtonGroup:
return Actions.ButtonGroup.validationError(action) || action;
case Actions.Group.Cart:
return Actions.Cart.validationError(action) || action;
case Actions.Group.Toast:
return Actions.Toast.validationError(action) || action;
case Actions.Group.Modal:
return Actions.Modal.validationError(action, origin) || action;
case Actions.Group.TitleBar:
return Actions.TitleBar.validationError(action) || action;
case Actions.Group.Navigation:
return Actions.Navigation.validationError(action) || action;
case Actions.Group.Error:
return action;
case Actions.Group.Print:
return Actions.Print.validationError(action) || action;
case Actions.Group.Loading:
return Actions.Loading.validationError(action) || action;
case Actions.Group.ResourcePicker:
return Actions.ResourcePicker.validationError(action) || action;
default:
return Error_1.invalidAction(action, 'Unknown or unsupported action group');
}
}
exports.validatedActionPayload = validatedActionPayload;
function validatedAction(action, origin) {
if (!isAppBridgeAction(action)) {
return action;
}
for (var _i = 0, MANDATORY_ACTION_PROPS_1 = MANDATORY_ACTION_PROPS; _i < MANDATORY_ACTION_PROPS_1.length; _i++) {
var prop = MANDATORY_ACTION_PROPS_1[_i];
if (!action.hasOwnProperty(prop) || typeof action[prop] !== 'string') {
return Error_1.invalidAction(action, "Missing or invalid " + prop);
}
}
return validatedActionPayload(action, origin);
}
exports.validatedAction = validatedAction;
//# sourceMappingURL=validator.js.map

@@ -6,2 +6,10 @@ # Change Log

<a name="1.0.0-3"></a>
# [1.0.0-3](https://github.com/Shopify/app-bridge/compare/v1.0.0-2...v1.0.0-3) (2018-12-19)
**Note:** Version bump only for package @shopify/app-bridge
<a name="1.0.0-1"></a>

@@ -8,0 +16,0 @@ # [1.0.0-1](https://github.com/Shopify/app-bridge/compare/v1.0.0-0...v1.0.0-1) (2018-12-03)

@@ -1,9 +0,11 @@

import { AppConfig, ClientApplication, ClientApplicationCreator, ClientApplicationTransportInjector } from './types';
export interface Params {
[key: string]: string;
}
/**
* @module client
*
* @todo Move `MessageTransport` into shared space.
*/
import { AppConfig, AppMiddleware, ClientApplication, ClientApplicationCreator, ClientApplicationTransportInjector, Params } from './types';
export declare function getUrlParams(): Params;
export declare function getShopOrigin(): string;
export declare const createClientApp: ClientApplicationTransportInjector;
export declare function createAppWrapper(frame: Window, localOrigin?: string): ClientApplicationCreator;
export declare function createAppWrapper(frame: Window, localOrigin?: string, middleware?: AppMiddleware[]): ClientApplicationCreator;
export default function (config: AppConfig): ClientApplication<any>;
"use strict";
/**
* @module client
*
* @todo Move `MessageTransport` into shared space.
*/
var __assign = (this && this.__assign) || function () {

@@ -13,10 +18,7 @@ __assign = Object.assign || function(t) {

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module client
*
* @todo Move `MessageTransport` into shared space.
*/
var helper_1 = require("../actions/helper");
var validator_1 = require("../actions/validator");
var Error_1 = require("../actions/Error");

@@ -29,2 +31,4 @@ var Print_1 = require("../actions/Print");

var redirect_1 = require("./redirect");
var types_1 = require("./types");
var Hooks_1 = __importDefault(require("./Hooks"));
var WINDOW_UNDEFINED_MESSAGE = 'window is not defined. Running an app outside a browser is not supported';

@@ -65,3 +69,4 @@ function redirectHandler(hostFrame, config) {

exports.getShopOrigin = getShopOrigin;
exports.createClientApp = function (transport) {
exports.createClientApp = function (transport, middlewares) {
if (middlewares === void 0) { middlewares = []; }
var getStateListeners = [];

@@ -117,15 +122,30 @@ var listeners = [];

redirectHandler(transport.hostFrame, config);
var dispatch = function (action) {
var augmentedAction = {
payload: action,
source: config,
type: 'dispatch',
};
handler({ data: augmentedAction });
transport.dispatch(augmentedAction);
return action;
};
var app = {
localOrigin: transport.localOrigin,
hooks: new Hooks_1.default(),
dispatch: function (action) {
var validAction = validator_1.validatedAction(action, transport.localOrigin);
var augmentedAction = {
payload: validAction,
source: config,
type: 'dispatch',
};
handler({ data: augmentedAction });
transport.dispatch(augmentedAction);
return validAction;
return app.hooks.run(types_1.LifecycleHook.DispatchAction, dispatch, app, action);
},
featuresAvailable: function (features) {
return app.getState('features').then(function (state) {
if (features) {
Object.keys(state).forEach(function (feature) {
if (!features.includes(feature)) {
delete state[feature];
}
});
}
return state;
});
},
getState: function (query) {

@@ -178,2 +198,6 @@ return new Promise(function (resolve) {

};
for (var _i = 0, middlewares_1 = middlewares; _i < middlewares_1.length; _i++) {
var middleware = middlewares_1[_i];
middleware(app.hooks, app);
}
appSetUp(app);

@@ -183,3 +207,4 @@ return app;

};
function createAppWrapper(frame, localOrigin) {
function createAppWrapper(frame, localOrigin, middleware) {
if (middleware === void 0) { middleware = []; }
if (!frame) {

@@ -194,3 +219,4 @@ throw Error_1.fromAction(WINDOW_UNDEFINED_MESSAGE, Error_1.AppActionType.WINDOW_UNDEFINED);

var transport = MessageTransport_1.fromWindow(frame, origin);
return exports.createClientApp(transport);
var appCreator = exports.createClientApp(transport, middleware);
return appCreator;
}

@@ -197,0 +223,0 @@ exports.createAppWrapper = createAppWrapper;

@@ -13,4 +13,5 @@ "use strict";

var Client_1 = __importDefault(require("./Client"));
__export(require("./types"));
exports.default = Client_1.default;
__export(require("./Client"));
//# sourceMappingURL=index.js.map

@@ -5,3 +5,3 @@ /**

*/
import { ActionCallback, AnyAction, Dispatch, ErrorSubscriber, Unsubscribe } from '../actions/types';
import { ActionCallback, AnyAction, Dispatch, ErrorSubscriber, MetaAction, Group, Unsubscribe, ActionSetInterface } from '../actions/types';
/**

@@ -16,2 +16,11 @@ * @todo Move `MessageTransport` into shared space.

}
export interface FeaturesAction {
[key: string]: boolean;
}
export interface FeaturesGroup {
[key: string]: FeaturesAction;
}
export declare type FeaturesAvailable = {
[key in Group]?: FeaturesGroup;
};
export interface ClientApplication<S> {

@@ -21,3 +30,5 @@ dispatch: Dispatch<AnyAction>;

error: ErrorSubscriber;
hooks: HooksInterface;
getState(query?: string): Promise<S>;
featuresAvailable(features?: Group[]): Promise<FeaturesAvailable>;
subscribe(callback: ActionCallback, id?: string): Unsubscribe;

@@ -33,3 +44,3 @@ subscribe(eventNameSpace: string, callback: ActionCallback, id?: string): Unsubscribe;

export interface ClientApplicationTransportInjector {
(transport: MessageTransport): ClientApplicationCreator;
(transport: MessageTransport, middleware?: AppMiddleware[]): ClientApplicationCreator;
}

@@ -48,2 +59,41 @@ export interface ActionListenersMap {

}
export interface Params {
[key: string]: string;
}
export declare enum LifecycleHook {
UpdateAction = "UpdateAction",
DispatchAction = "DispatchAction"
}
export interface Hook {
handler: LifecycleHandler;
remove: Unsubscribe;
}
export interface HookMap {
[key: string]: Hook[];
}
export interface HooksInterface {
set(hook: LifecycleHook.UpdateAction, handler: UpdateActionHook): any;
set(hook: LifecycleHook.DispatchAction, handler: DispatchActionHook): any;
set(hook: LifecycleHook, handler: LifecycleHandler): any;
get(hook: LifecycleHook): LifecycleHandler[] | undefined;
run<C>(hook: LifecycleHook, final: Function, context: C, ...arg: any[]): any;
}
export interface AppMiddleware {
(hooks: HooksInterface, app: ClientApplication<any>): void;
}
export interface LifecycleHandler {
(next: Function): (...args: any[]) => any;
}
export interface UpdateActionHandler {
<O>(this: ActionSetInterface, options: O): any;
}
export interface UpdateActionHook {
(next: Function): UpdateActionHandler;
}
export interface DispatchActionHandler {
<A extends MetaAction>(this: ClientApplication<any>, action: A): any;
}
export interface DispatchActionHook {
(next: Function): DispatchActionHandler;
}
export { AnyAction, Dispatch, Handler, HandlerData, Unsubscribe };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LifecycleHook;
(function (LifecycleHook) {
LifecycleHook["UpdateAction"] = "UpdateAction";
LifecycleHook["DispatchAction"] = "DispatchAction";
})(LifecycleHook = exports.LifecycleHook || (exports.LifecycleHook = {}));
//# sourceMappingURL=types.js.map
{
"name": "@shopify/app-bridge",
"version": "1.0.0-1",
"version": "1.0.0-3",
"types": "index.d.ts",

@@ -5,0 +5,0 @@ "main": "index.js",

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

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

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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