@shopify/app-bridge
Version:
**[Join our team and work on libraries like this one.](https://www.shopify.ca/careers)**
1,191 lines (1,149 loc) • 486 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define("app-bridge", [], factory);
else if(typeof exports === 'object')
exports["app-bridge"] = factory();
else
root["app-bridge"] = factory();
})(window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 68);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateActionFromPayload = exports.isValidOptionalString = exports.isValidOptionalNumber = exports.forEachInEnum = exports.getMergedProps = exports.findMatchInEnum = exports.getEventNameSpace = exports.NonSnakeCaseGroup = exports.actionWrapper = void 0;
var merge_1 = __importDefault(__webpack_require__(71));
var constants_1 = __webpack_require__(38);
var types_1 = __webpack_require__(1);
function actionWrapper(action) {
return action;
}
exports.actionWrapper = actionWrapper;
exports.NonSnakeCaseGroup = [
types_1.Group.AuthCode,
types_1.Group.Button,
types_1.Group.ButtonGroup,
types_1.Group.Cart,
types_1.Group.Error,
types_1.Group.Features,
types_1.Group.Fullscreen,
types_1.Group.Link,
types_1.Group.Loading,
types_1.Group.Menu,
types_1.Group.Modal,
types_1.Group.Navigation,
types_1.Group.Pos,
types_1.Group.Print,
types_1.Group.ResourcePicker,
types_1.Group.Scanner,
types_1.Group.SessionToken,
types_1.Group.Share,
types_1.Group.TitleBar,
types_1.Group.Toast,
types_1.Group.unstable_Picker,
];
function camelCaseToSnakeCase(value) {
return value.replace(/([A-Z])/g, function (matcher, _val, index) {
return "" + (index === 0 ? '' : '_') + matcher[0].toLowerCase();
});
}
/**
* Maps the group name to its event name
* @internal
* @remarks - This method is necessary for the new pattern of using snake case
* which makes it more readable and easier to reconstruct the group from an event name.
* Example: `ContextualSaveBar` becomes `CONTEXTUAL_SAVE_BAR`
* */
function groupToEventNameSpace(group) {
if (exports.NonSnakeCaseGroup.includes(group)) {
return group.toUpperCase();
}
return camelCaseToSnakeCase(group).toUpperCase();
}
/**
* Returns full event name with prefix, group, subgroups and type formatted with separators
* @internal
* */
function getEventNameSpace(group, eventName, component) {
if (eventName.startsWith("" + constants_1.PREFIX + constants_1.SEPARATOR)) {
return eventName;
}
var eventNameSpace = groupToEventNameSpace(group);
if (component) {
var subgroups_1 = component.subgroups, type = component.type;
if (subgroups_1 && subgroups_1.length > 0) {
eventNameSpace += eventNameSpace.length > 0 ? constants_1.SEPARATOR : '';
subgroups_1.forEach(function (subgroup, index) {
eventNameSpace += "" + subgroup.toUpperCase() + (index < subgroups_1.length - 1 ? constants_1.SEPARATOR : '');
});
}
if (type !== group && type) {
eventNameSpace += "" + (eventNameSpace.length > 0 ? constants_1.SEPARATOR : '') + type.toUpperCase();
}
}
if (eventNameSpace) {
eventNameSpace += "" + (eventNameSpace.length > 0 ? constants_1.SEPARATOR : '') + eventName.toUpperCase();
}
return "" + constants_1.PREFIX + constants_1.SEPARATOR + eventNameSpace;
}
exports.getEventNameSpace = getEventNameSpace;
function findMatchInEnum(types, lookup) {
var match = Object.keys(types).find(function (key) {
return lookup === types[key];
});
return match ? types[match] : undefined;
}
exports.findMatchInEnum = findMatchInEnum;
function getMergedProps(props, newProps) {
var merged = merge_1.default(props, newProps);
if (!merged) {
// tslint:disable-next-line:prefer-object-spread
var cloned = Object.assign(props, newProps);
return cloned;
}
return merged;
}
exports.getMergedProps = getMergedProps;
function forEachInEnum(types, callback) {
Object.keys(types).forEach(function (key) {
callback(types[key]);
});
}
exports.forEachInEnum = forEachInEnum;
function isValidOptionalNumber(value) {
return value === null || value === undefined || typeof value === 'number';
}
exports.isValidOptionalNumber = isValidOptionalNumber;
function isValidOptionalString(value) {
return value === null || value === undefined || typeof value === 'string';
}
exports.isValidOptionalString = isValidOptionalString;
function updateActionFromPayload(action, newProps) {
var id = action.id;
if (id === newProps.id) {
// Merge new properties
Object.assign(action, getMergedProps(action, newProps));
return true;
}
return false;
}
exports.updateActionFromPayload = updateActionFromPayload;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComponentType = exports.Group = void 0;
/**
* Various action groups.
* @public
*/
var Group;
(function (Group) {
Group["AuthCode"] = "AuthCode";
Group["Button"] = "Button";
Group["ButtonGroup"] = "ButtonGroup";
Group["Cart"] = "Cart";
Group["Client"] = "Client";
Group["ContextualSaveBar"] = "ContextualSaveBar";
Group["Error"] = "Error";
Group["Features"] = "Features";
Group["FeedbackModal"] = "FeedbackModal";
Group["Fullscreen"] = "Fullscreen";
Group["LeaveConfirmation"] = "LeaveConfirmation";
Group["Link"] = "Link";
Group["Loading"] = "Loading";
Group["Menu"] = "Menu";
Group["Modal"] = "Modal";
Group["Navigation"] = "Navigation";
Group["Performance"] = "Performance";
Group["Pos"] = "Pos";
Group["Print"] = "Print";
Group["ResourcePicker"] = "Resource_Picker";
/**
* @unstable This API may be updated without warning in the future
*/
Group["unstable_Picker"] = "unstable_Picker";
Group["Scanner"] = "Scanner";
Group["SessionToken"] = "SessionToken";
Group["Share"] = "Share";
Group["TitleBar"] = "TitleBar";
Group["Toast"] = "Toast";
Group["MarketingExternalActivityTopBar"] = "MarketingExternalActivityTopBar";
Group["WebVitals"] = "WebVitals";
})(Group = exports.Group || (exports.Group = {}));
/**
* @internal
*/
var ComponentType;
(function (ComponentType) {
ComponentType["Button"] = "Button";
ComponentType["ButtonGroup"] = "ButtonGroup";
})(ComponentType = exports.ComponentType || (exports.ComponentType = {}));
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.unsubscribeActions = exports.ActionSetWithChildren = exports.ActionSet = void 0;
var types_1 = __webpack_require__(13);
var collection_1 = __webpack_require__(23);
var Error_1 = __webpack_require__(12);
var types_2 = __webpack_require__(1);
var uuid_1 = __importDefault(__webpack_require__(44));
var helper_1 = __webpack_require__(0);
var ActionSet = /** @class */ (function () {
function ActionSet(app, type, group, id) {
var _this = this;
this.app = app;
this.type = type;
this.group = group;
this.subgroups = [];
this.subscriptions = [];
if (!app) {
Error_1.throwError(Error_1.Action.INVALID_ACTION, 'Missing required `app`');
}
this.id = id || uuid_1.default();
this.defaultGroup = group;
var defaultSet = this.set;
this.set = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (!_this.app.hooks) {
return defaultSet.apply(_this, args);
}
return (_a = _this.app.hooks).run.apply(_a, __spreadArray([types_1.LifecycleHook.UpdateAction, defaultSet, _this], args));
};
}
ActionSet.prototype.set = function () {
var _ = [];
for (var _i = 0; _i < arguments.length; _i++) {
_[_i] = arguments[_i];
}
};
Object.defineProperty(ActionSet.prototype, "component", {
get: function () {
return {
id: this.id,
subgroups: this.subgroups,
type: this.type,
};
},
enumerable: false,
configurable: true
});
ActionSet.prototype.updateSubscription = function (subscriptionToRemove, group, subgroups) {
var eventType = subscriptionToRemove.eventType, callback = subscriptionToRemove.callback, component = subscriptionToRemove.component;
var currentIndex;
currentIndex = this.subscriptions.findIndex(function (subscription) { return subscription === subscriptionToRemove; });
if (currentIndex >= 0) {
this.subscriptions[currentIndex].unsubscribe();
}
else {
currentIndex = undefined;
}
this.group = group;
this.subgroups = subgroups;
Object.assign(component, { subgroups: this.subgroups });
return this.subscribe(eventType, callback, component, currentIndex);
};
ActionSet.prototype.error = function (callback) {
var _this = this;
var subscriptionIndices = [];
helper_1.forEachInEnum(Error_1.Action, function (eventNameSpace) {
// Keep track of subscription index so we can call unsubscribe later
// This ensure it will continue to work even when the subscription has been updated
subscriptionIndices.push(_this.subscriptions.length);
_this.subscribe(eventNameSpace, callback);
});
return function () {
var subscriptionsToRemove = subscriptionIndices.map(function (index) { return _this.subscriptions[index]; });
subscriptionsToRemove.forEach(function (toRemove) {
collection_1.removeFromCollection(_this.subscriptions, toRemove, function (removed) {
removed.unsubscribe();
});
});
};
};
ActionSet.prototype.subscribe = function (eventName, callback, component, currentIndex) {
var _this = this;
var eventComponent = component || this.component;
var eventType = eventName.toUpperCase();
var boundedCallback = typeof currentIndex === 'number' ? callback : callback.bind(this);
var eventNameSpace;
if (Error_1.isErrorEventName(eventName)) {
eventNameSpace = helper_1.getEventNameSpace(types_2.Group.Error, eventName, __assign(__assign({}, eventComponent), { type: '' }));
}
else {
eventNameSpace = helper_1.getEventNameSpace(this.group, eventName, eventComponent);
}
var unsubscribe = this.app.subscribe(eventNameSpace, boundedCallback, component ? component.id : this.id);
var subscription = {
eventType: eventType,
unsubscribe: unsubscribe,
callback: boundedCallback,
component: eventComponent,
updateSubscribe: function (group, subgroups) {
return _this.updateSubscription(subscription, group, subgroups);
},
};
if (typeof currentIndex === 'number' &&
currentIndex >= 0 &&
currentIndex < this.subscriptions.length) {
this.subscriptions[currentIndex] = subscription;
}
else {
this.subscriptions.push(subscription);
}
return unsubscribe;
};
ActionSet.prototype.unsubscribe = function (resetOnly) {
if (resetOnly === void 0) { resetOnly = false; }
unsubscribeActions(this.subscriptions, this.defaultGroup, resetOnly);
return this;
};
return ActionSet;
}());
exports.ActionSet = ActionSet;
var ActionSetWithChildren = /** @class */ (function (_super) {
__extends(ActionSetWithChildren, _super);
function ActionSetWithChildren() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.children = [];
return _this;
}
ActionSetWithChildren.prototype.unsubscribe = function (unsubscribeChildren, resetParentOnly) {
if (unsubscribeChildren === void 0) { unsubscribeChildren = true; }
if (resetParentOnly === void 0) { resetParentOnly = false; }
unsubscribeActions(this.subscriptions, this.defaultGroup, resetParentOnly);
this.children.forEach(function (child) {
if (child instanceof ActionSetWithChildren) {
child.unsubscribe(unsubscribeChildren, !unsubscribeChildren);
}
else {
child.unsubscribe(!unsubscribeChildren);
}
});
return this;
};
ActionSetWithChildren.prototype.getChild = function (id) {
var childIndex = this.children.findIndex(function (child) { return child.id === id; });
return childIndex >= 0 ? this.children[childIndex] : undefined;
};
ActionSetWithChildren.prototype.getChildIndex = function (id) {
return this.children.findIndex(function (child) { return child.id === id; });
};
ActionSetWithChildren.prototype.getChildSubscriptions = function (id, eventType) {
return this.subscriptions.filter(function (sub) { return sub.component.id === id && (!eventType || eventType === sub.eventType); });
};
ActionSetWithChildren.prototype.addChild = function (child, group, subgroups) {
var _this = this;
var subscriptions = child.subscriptions;
var existingChild = this.getChild(child.id);
// Add child if it doesn't already exist
if (!existingChild) {
this.children.push(child);
}
if (!subscriptions || (group === child.group && subgroups === child.subgroups)) {
return this;
}
subscriptions.forEach(function (subscription) {
var updateSubscribe = subscription.updateSubscribe;
updateSubscribe(group, subgroups);
});
// Update child's group and subgroups
Object.assign(child, { group: group, subgroups: subgroups });
// Update child's children subscriptions
if (child instanceof ActionSetWithChildren) {
child.children.forEach(function (childIter) {
return _this.addChild(childIter, group, subgroups);
});
}
return this;
};
ActionSetWithChildren.prototype.removeChild = function (id) {
var _this = this;
collection_1.removeFromCollection(this.children, this.getChild(id), function () {
var toBeRemoved = _this.subscriptions.filter(function (subs) { return subs.component.id === id; });
toBeRemoved.forEach(function (toRemove) {
collection_1.removeFromCollection(_this.subscriptions, toRemove, function (removed) {
removed.unsubscribe();
});
});
});
return this;
};
ActionSetWithChildren.prototype.subscribeToChild = function (child, eventName, callback) {
var _this = this;
var boundedCallback = callback.bind(this);
if (eventName instanceof Array) {
eventName.forEach(function (eventNameIter) { return _this.subscribeToChild(child, eventNameIter, callback); });
return this;
}
if (typeof eventName !== 'string') {
return this;
}
var eventType = eventName.toUpperCase();
var currentSubscriptions = this.getChildSubscriptions(child.id, eventType);
if (currentSubscriptions.length > 0) {
// Subscription is already there, simply update it
currentSubscriptions.forEach(function (subs) { return subs.updateSubscribe(_this.group, child.subgroups); });
}
else {
var childComponent = {
id: child.id,
subgroups: child.subgroups,
type: child.type,
};
this.subscribe(eventType, boundedCallback, childComponent);
}
return this;
};
ActionSetWithChildren.prototype.getUpdatedChildActions = function (newActions, currentActions) {
if (newActions.length === 0) {
while (currentActions.length > 0) {
var action = currentActions.pop();
if (!action) {
break;
}
this.removeChild(action.id);
}
return undefined;
}
// Only allow unique actions
var uniqueActions = newActions.filter(function (action, index, actionsArr) { return index === actionsArr.indexOf(action); });
var newActionIds = uniqueActions.map(function (action) { return action.id; });
// Remove unused actions
var unusedActions = currentActions.filter(function (action) {
return newActionIds.indexOf(action.id) < 0;
});
while (unusedActions.length > 0) {
var action = unusedActions.pop();
if (!action) {
break;
}
this.removeChild(action.id);
}
return uniqueActions;
};
return ActionSetWithChildren;
}(ActionSet));
exports.ActionSetWithChildren = ActionSetWithChildren;
function unsubscribeActions(subscriptions, defaultGroup, reassign) {
if (reassign === void 0) { reassign = false; }
subscriptions.forEach(function (subscription) {
if (reassign) {
var updateSubscribe = subscription.updateSubscribe;
// eslint-disable-next-line no-warning-comments
// TODO: Support cases where we don't wipe out group and subgroups to defaults
updateSubscribe(defaultGroup, []);
}
else {
var unsubscribe = subscription.unsubscribe;
unsubscribe();
}
});
if (!reassign) {
subscriptions.length = 0;
}
}
exports.unsubscribeActions = unsubscribeActions;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validate = exports.matchesPositiveInteger = exports.matchesBoolean = exports.makeOptional = exports.matchesString = exports.matchesObject = exports.getErrors = exports.oneOf = exports.matchesArray = exports.matchesEnum = exports.composeSchemas = exports.TYPE_ERROR = void 0;
exports.TYPE_ERROR = 'type_error_expected';
function composeSchemas() {
var validators = [];
for (var _i = 0; _i < arguments.length; _i++) {
validators[_i] = arguments[_i];
}
return function (val) {
var error;
var i = 0;
var len = validators.length;
while (!error && i < len) {
error = validators[i](val);
if (error) {
return error;
}
i++;
}
};
}
exports.composeSchemas = composeSchemas;
/**
* Returns a validator that matches values in the given enum
* @param type - enum to use for match values
* @public
*/
function matchesEnum(types, options) {
return function (value) {
var values = Object.keys(types).map(function (key) { return types[key]; });
var message = (options && options.message) || "expected:" + values.map(function (val) { return "`" + val + "`"; }).join(' or ');
return values.includes(value)
? undefined
: constructErrors(value, 'invalid_enum_value', __assign(__assign({}, options), { message: message }));
};
}
exports.matchesEnum = matchesEnum;
function matchesArray(validator, options) {
return function (value) {
if (!Array.isArray(value)) {
return constructErrors(value, exports.TYPE_ERROR + "_array", options);
}
if (!validator) {
return;
}
var errors = [];
value.forEach(function (val, key) {
var objectError = validator(val);
if (objectError) {
errors = errors.concat(objectError.map(function (error) { return (__assign(__assign({}, error), { path: "['" + key + "']" + (error.path || '') })); }));
}
});
return errors.length ? errors : undefined;
};
}
exports.matchesArray = matchesArray;
function oneOf() {
var validators = [];
for (var _i = 0; _i < arguments.length; _i++) {
validators[_i] = arguments[_i];
}
return function (val) {
var errors = [];
for (var _i = 0, validators_1 = validators; _i < validators_1.length; _i++) {
var validator = validators_1[_i];
var result = validator(val);
if (result == null)
return result;
errors.push.apply(errors, result);
}
return errors;
};
}
exports.oneOf = oneOf;
function constructErrors(value, error, options) {
if (options === void 0) { options = { message: undefined }; }
return [
{
value: value,
error: error,
message: typeof options.message === 'function' ? options.message(error, value) : options.message,
},
];
}
function getErrors(obj, validator, key) {
var value = key ? obj[key] : obj;
var path = key ? "['" + key + "']" : undefined;
var error = validator(value);
if (!error) {
return;
}
return error.map(function (errorObj) { return (__assign(__assign({}, errorObj), { path: "" + (path || '') + (errorObj.path || '') || undefined })); });
}
exports.getErrors = getErrors;
function matchesObject(schema, options) {
return function (val) {
if (typeof val !== 'object' || !val || Array.isArray(val)) {
return constructErrors(val, exports.TYPE_ERROR + "_object", options);
}
var flattened = Object.keys(schema).reduce(function (acc, key) {
return __spreadArray(__spreadArray([], acc), (getErrors(val, schema[key], key) || []));
}, []);
return flattened.length ? flattened : undefined;
};
}
exports.matchesObject = matchesObject;
function matchesString(options) {
return function (value) {
return typeof value === 'string' ? undefined : constructErrors(value, exports.TYPE_ERROR + "_string", options);
};
}
exports.matchesString = matchesString;
function makeOptional(validator) {
return function (value) {
if (value === undefined || value === null) {
return undefined;
}
return validator(value);
};
}
exports.makeOptional = makeOptional;
function matchesBoolean(options) {
return function (value) {
return typeof value === 'boolean'
? undefined
: constructErrors(value, exports.TYPE_ERROR + "_boolean", options);
};
}
exports.matchesBoolean = matchesBoolean;
function matchesPositiveInteger(options) {
return function (value) {
return !Number.isInteger(value) || value < 0
? constructErrors(value, exports.TYPE_ERROR + "_integer", options)
: undefined;
};
}
exports.matchesPositiveInteger = matchesPositiveInteger;
function validate(obj, validator) {
return getErrors(obj, validator);
}
exports.validate = validate;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.relativePathSchema = exports.relativeUrlSchema = exports.isValidRelativePath = exports.createActionValidator = void 0;
var type_validate_1 = __webpack_require__(3);
function createActionValidator(type, payloadSchema, payloadRequired, idRequired) {
if (payloadSchema === void 0) { payloadSchema = undefined; }
if (payloadRequired === void 0) { payloadRequired = false; }
if (idRequired === void 0) { idRequired = false; }
var idSchema = type_validate_1.matchesObject({
id: idRequired ? type_validate_1.matchesString() : type_validate_1.makeOptional(type_validate_1.matchesString()),
});
var schema = payloadSchema ? type_validate_1.composeSchemas(idSchema, payloadSchema) : idSchema;
return type_validate_1.matchesObject({
type: type_validate_1.matchesEnum(type, {
message: function (_, val) { return "The action type `" + val + "` is invalid or unsupported"; },
}),
payload: payloadRequired ? schema : type_validate_1.makeOptional(schema),
});
}
exports.createActionValidator = createActionValidator;
function isValidRelativePath(path) {
return typeof path === 'string' && (path === '' || path.startsWith('/'));
}
exports.isValidRelativePath = isValidRelativePath;
exports.relativeUrlSchema = type_validate_1.composeSchemas(type_validate_1.matchesString(), function (value) {
return isValidRelativePath(value)
? undefined
: [{ error: 'invalid_relative_path', value: value, message: 'expected string to start with `/`' }];
});
exports.relativePathSchema = type_validate_1.matchesObject({
path: exports.relativeUrlSchema,
});
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = exports.update = exports.clickButton = exports.Style = exports.Icon = exports.Action = void 0;
var helper_1 = __webpack_require__(0);
var ActionSet_1 = __webpack_require__(2);
var types_1 = __webpack_require__(1);
var Action;
(function (Action) {
Action["CLICK"] = "CLICK";
Action["UPDATE"] = "UPDATE";
})(Action = exports.Action || (exports.Action = {}));
var Icon;
(function (Icon) {
Icon["Print"] = "print";
})(Icon = exports.Icon || (exports.Icon = {}));
var Style;
(function (Style) {
Style["Danger"] = "danger";
})(Style = exports.Style || (exports.Style = {}));
function clickButton(group, component, payload) {
var id = component.id;
var action = helper_1.getEventNameSpace(group, Action.CLICK, component);
var buttonPayload = {
id: id,
payload: payload,
};
return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
}
exports.clickButton = clickButton;
function update(group, component, props) {
var id = component.id;
var label = props.label;
var action = helper_1.getEventNameSpace(group, Action.UPDATE, component);
var buttonPayload = __assign(__assign({}, props), { id: id, label: label });
return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
}
exports.update = update;
var Button = /** @class */ (function (_super) {
__extends(Button, _super);
function Button(app, options) {
var _this = _super.call(this, app, types_1.ComponentType.Button, types_1.Group.Button) || this;
_this.disabled = false;
_this.loading = false;
_this.plain = false;
_this.set(options, false);
return _this;
}
Object.defineProperty(Button.prototype, "options", {
get: function () {
return {
disabled: this.disabled,
icon: this.icon,
label: this.label,
style: this.style,
loading: this.loading,
plain: this.plain,
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(Button.prototype, "payload", {
get: function () {
return __assign(__assign({}, this.options), { id: this.id });
},
enumerable: false,
configurable: true
});
Button.prototype.set = function (options, shouldUpdate) {
if (shouldUpdate === void 0) { shouldUpdate = true; }
var mergedOptions = helper_1.getMergedProps(this.options, options);
var label = mergedOptions.label, disabled = mergedOptions.disabled, icon = mergedOptions.icon, style = mergedOptions.style, loading = mergedOptions.loading, plain = mergedOptions.plain;
this.label = label;
this.disabled = Boolean(disabled);
this.icon = icon;
this.style = style;
this.loading = Boolean(loading);
this.plain = Boolean(plain);
if (shouldUpdate) {
this.dispatch(Action.UPDATE);
}
return this;
};
Button.prototype.dispatch = function (action, payload) {
switch (action) {
case Action.CLICK:
this.app.dispatch(clickButton(this.group, this.component, payload));
break;
case Action.UPDATE: {
var updateAction = update(this.group, this.component, this.payload);
this.app.dispatch(updateAction);
break;
}
}
return this;
};
return Button;
}(ActionSet_1.ActionSet));
exports.Button = Button;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPackageName = exports.getVersion = exports.getMergedProps = exports.updateActionFromPayload = exports.isValidOptionalString = exports.isValidOptionalNumber = exports.NonSnakeCaseGroup = exports.getEventNameSpace = exports.forEachInEnum = exports.findMatchInEnum = exports.actionWrapper = void 0;
var helper_1 = __webpack_require__(0);
Object.defineProperty(exports, "actionWrapper", { enumerable: true, get: function () { return helper_1.actionWrapper; } });
Object.defineProperty(exports, "findMatchInEnum", { enumerable: true, get: function () { return helper_1.findMatchInEnum; } });
Object.defineProperty(exports, "forEachInEnum", { enumerable: true, get: function () { return helper_1.forEachInEnum; } });
Object.defineProperty(exports, "getEventNameSpace", { enumerable: true, get: function () { return helper_1.getEventNameSpace; } });
Object.defineProperty(exports, "NonSnakeCaseGroup", { enumerable: true, get: function () { return helper_1.NonSnakeCaseGroup; } });
Object.defineProperty(exports, "isValidOptionalNumber", { enumerable: true, get: function () { return helper_1.isValidOptionalNumber; } });
Object.defineProperty(exports, "isValidOptionalString", { enumerable: true, get: function () { return helper_1.isValidOptionalString; } });
Object.defineProperty(exports, "updateActionFromPayload", { enumerable: true, get: function () { return helper_1.updateActionFromPayload; } });
Object.defineProperty(exports, "getMergedProps", { enumerable: true, get: function () { return helper_1.getMergedProps; } });
// eslint-disable-next-line @typescript-eslint/no-var-requires
var packageJson = __webpack_require__(72);
function getVersion() {
return packageJson.version;
}
exports.getVersion = getVersion;
function getPackageName() {
return packageJson.name;
}
exports.getPackageName = getPackageName;
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionSetPayload = exports.ComplexDispatch = exports.DispatchAction = exports.ClickAction = exports.ComponentType = exports.ActionSetProps = exports.ActionSetOptions = exports.Dispatch = exports.ErrorCallback = exports.UpdateSubscribe = exports.ActionSubscription = exports.ErrorSubscriber = exports.UpdateSubscription = exports.ActionSetInterface = exports.Component = exports.Group = exports.ClientInterface = exports.SimpleDispatch = exports.Unsubscribe = exports.MetaAction = exports.AnyAction = exports.ActionCallback = void 0;
var types_1 = __webpack_require__(1);
Object.defineProperty(exports, "ActionCallback", { enumerable: true, get: function () { return types_1.ActionCallback; } });
Object.defineProperty(exports, "AnyAction", { enumerable: true, get: function () { return types_1.AnyAction; } });
Object.defineProperty(exports, "MetaAction", { enumerable: true, get: function () { return types_1.MetaAction; } });
Object.defineProperty(exports, "Unsubscribe", { enumerable: true, get: function () { return types_1.Unsubscribe; } });
Object.defineProperty(exports, "SimpleDispatch", { enumerable: true, get: function () { return types_1.SimpleDispatch; } });
Object.defineProperty(exports, "ClientInterface", { enumerable: true, get: function () { return types_1.ClientInterface; } });
Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return types_1.Group; } });
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return types_1.Component; } });
Object.defineProperty(exports, "ActionSetInterface", { enumerable: true, get: function () { return types_1.ActionSetInterface; } });
Object.defineProperty(exports, "UpdateSubscription", { enumerable: true, get: function () { return types_1.UpdateSubscription; } });
Object.defineProperty(exports, "ErrorSubscriber", { enumerable: true, get: function () { return types_1.ErrorSubscriber; } });
Object.defineProperty(exports, "ActionSubscription", { enumerable: true, get: function () { return types_1.ActionSubscription; } });
Object.defineProperty(exports, "UpdateSubscribe", { enumerable: true, get: function () { return types_1.UpdateSubscribe; } });
Object.defineProperty(exports, "ErrorCallback", { enumerable: true, get: function () { return types_1.ErrorCallback; } });
Object.defineProperty(exports, "Dispatch", { enumerable: true, get: function () { return types_1.Dispatch; } });
Object.defineProperty(exports, "ActionSetOptions", { enumerable: true, get: function () { return types_1.ActionSetOptions; } });
Object.defineProperty(exports, "ActionSetProps", { enumerable: true, get: function () { return types_1.ActionSetProps; } });
Object.defineProperty(exports, "ComponentType", { enumerable: true, get: function () { return types_1.ComponentType; } });
Object.defineProperty(exports, "ClickAction", { enumerable: true, get: function () { return types_1.ClickAction; } });
Object.defineProperty(exports, "DispatchAction", { enumerable: true, get: function () { return types_1.DispatchAction; } });
Object.defineProperty(exports, "ComplexDispatch", { enumerable: true, get: function () { return types_1.ComplexDispatch; } });
Object.defineProperty(exports, "ActionSetPayload", { enumerable: true, get: function () { return types_1.ActionSetPayload; } });
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mixedAppClientCheck = exports.actionMessage = exports.relativePathSchema = exports.relativeUrlSchema = exports.isValidRelativePath = exports.createActionValidator = void 0;
var utils_1 = __webpack_require__(4);
Object.defineProperty(exports, "createActionValidator", { enumerable: true, get: function () { return utils_1.createActionValidator; } });
Object.defineProperty(exports, "isValidRelativePath", { enumerable: true, get: function () { return utils_1.isValidRelativePath; } });
Object.defineProperty(exports, "relativeUrlSchema", { enumerable: true, get: function () { return utils_1.relativeUrlSchema; } });
Object.defineProperty(exports, "relativePathSchema", { enumerable: true, get: function () { return utils_1.relativePathSchema; } });
function actionMessage(errors) {
return errors
.map(function (err) {
var path = err.path, error = err.error, message = err.message, value = err.value;
var valueStr = typeof value === 'object' ? JSON.stringify(value) : value;
return "`" + error + "` thrown for" + (path ? " path: " + path + " and" : '') + " value: `" + valueStr + "`" + (message ? " with message: " + message : '');
})
.join(' | ');
}
exports.actionMessage = actionMessage;
function mixedAppClientCheck(window) {
window.addEventListener('DOMContentLoaded', function () {
if (!Object.prototype.hasOwnProperty.call(window, 'ShopifyApp')) {
return;
}
// eslint-disable-next-line no-console
console.error("%cException Detected \uD83D\uDEAB\n\n%cAn instance of the EASDK client was detected while initializing Shopify App Bridge. Using Shopify App Bridge and the EASDK simultaneously is not supported.\n\nIf you're migrating an existing app that was built with the shopify_app gem, then the EASDK client might have been included in the home page view template. In this case, remove it from your app before initializing Shopify App Bridge again.", 'font-size: large;', 'font-size: normal;');
}, { once: true });
}
exports.mixedAppClientCheck = mixedAppClientCheck;
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = exports.ButtonGroup = exports.isGroupedButtonPayload = exports.isGroupedButton = exports.update = exports.Action = void 0;
var buttonHelper_1 = __webpack_require__(17);
var helper_1 = __webpack_require__(0);
var ActionSet_1 = __webpack_require__(2);
var types_1 = __webpack_require__(1);
var Action;
(function (Action) {
Action["UPDATE"] = "UPDATE";
})(Action = exports.Action || (exports.Action = {}));
function update(group, component, props) {
return buttonActionWrapper(group, component, Action.UPDATE, props);
}
exports.update = update;
function isGroupedButton(options) {
var castOptions = options;
return castOptions.buttons && castOptions.buttons.length > 0 && castOptions.label !== undefined;
}
exports.isGroupedButton = isGroupedButton;
function isGroupedButtonPayload(payload) {
var castOptions = payload;
return (Array.isArray(castOptions.buttons) &&
typeof castOptions.id === 'string' &&
typeof castOptions.label === 'string');
}
exports.isGroupedButtonPayload = isGroupedButtonPayload;
var ButtonGroup = /** @class */ (function (_super) {
__extends(ButtonGroup, _super);
function ButtonGroup(app, options) {
var _this = _super.call(this, app, types_1.ComponentType.ButtonGroup, types_1.Group.ButtonGroup) || this;
_this.disabled = false;
_this.plain = false;
_this.buttonsOptions = [];
_this.buttons = [];
_this.set(options, false);
return _this;
}
Object.defineProperty(ButtonGroup.prototype, "options", {
get: function () {
return {
buttons: this.buttonsOptions,
disabled: this.disabled,
label: this.label,
plain: this.plain,
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(ButtonGroup.prototype, "payload", {
get: function () {
return __assign(__assign({}, this.options), { buttons: this.buttons, id: this.id });
},
enumerable: false,
configurable: true
});
ButtonGroup.prototype.set = function (options, shouldUpdate) {
if (shouldUpdate === void 0) { shouldUpdate = true; }
var mergedOptions = helper_1.getMergedProps(this.options, options);
var label = mergedOptions.label, disabled = mergedOptions.disabled, buttons = mergedOptions.buttons, plain = mergedOptions.plain;
this.label = label;
this.disabled = Boolean(disabled);
this.buttons = this.getButtons(buttons);
this.plain = Boolean(plain);
if (shouldUpdate) {
this.dispatch(Action.UPDATE);
}
return this;
};
ButtonGroup.prototype.dispatch = function (action) {
switch (action) {
case Action.UPDATE: {
var updateAction = update(this.group, this.component, this.payload);
this.app.dispatch(updateAction);
break;
}
}
return this;
};
ButtonGroup.prototype.updateButtons = function (newPayload) {
if (!this.buttons || this.buttons.length === 0) {
return;
}
var updated;
for (var _i = 0, _a = this.buttons; _i < _a.length; _i++) {
var action = _a[_i];
updated = helper_1.updateActionFromPayload(action, newPayload);
if (updated) {
break;
}
}
if (updated) {
this.dispatch(Action.UPDATE);
}
};
ButtonGroup.prototype.getSingleButton = function (button) {
return buttonHelper_1.getSingleButton(this, button, this.subgroups, this.updateButtons);
};
ButtonGroup.prototype.getButtons = function (buttonOptions) {
var _this = this;
var buttons = [];
if (!buttonOptions) {
return [];
}
buttonOptions.forEach(function (button) {
var singleButton = buttonHelper_1.getSingleButton(_this, button, _this.subgroups, _this.updateButtons);
buttons.push(singleButton);
});
this.buttonsOptions = buttonOptions;
return buttons;
};
return ButtonGroup;
}(ActionSet_1.ActionSetWithChildren));
exports.ButtonGroup = ButtonGroup;
function create(app, options) {
return new ButtonGroup(app, options);
}
exports.create = create;
function buttonActionWrapper(group, component, eventName, props, payload) {
var id = component.id;
var label = props.label;
var action = helper_1.getEventNameSpace(group, eventName, component);
var buttonPayload = __assign(__assign({}, props), { id: id, label: label, payload: payload });
return helper_1.actionWrapper({ type: action, group: group, payload: buttonPayload });
}
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesPositiveNumber = exports.TYPE_ERROR = exports.Options = exports.ValidationError = exports.Validator = exports.oneOf = exports.matchesArray = exports.validate = exports.matchesPositiveInteger = exports.matchesBoolean = exports.