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

@medusajs/utils

Package Overview
Dependencies
Maintainers
2
Versions
2883
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medusajs/utils - npm Package Compare versions

Comparing version 1.9.5-next-20230805153949 to 1.9.5-next-20230807094514

dist/common/object-from-string-path.d.ts

89

dist/common/build-query.js

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

exports.buildOrder = exports.buildRelations = exports.buildSelects = void 0;
var object_from_string_path_1 = require("./object-from-string-path");
function buildSelects(selectCollection) {

@@ -25,78 +26,4 @@ return buildRelationsOrSelect(selectCollection);

exports.buildRelations = buildRelations;
/**
* Convert a collection of dot string into a nested object
* @example
* input: [
* order,
* order.items,
* order.swaps,
* order.swaps.additional_items,
* order.discounts,
* order.discounts.rule,
* order.claims,
* order.claims.additional_items,
* additional_items,
* additional_items.variant,
* return_order,
* return_order.items,
* return_order.shipping_method,
* return_order.shipping_method.tax_lines
* ]
* output: {
* "order": {
* "items": true,
* "swaps": {
* "additional_items": true
* },
* "discounts": {
* "rule": true
* },
* "claims": {
* "additional_items": true
* }
* },
* "additional_items": {
* "variant": true
* },
* "return_order": {
* "items": true,
* "shipping_method": {
* "tax_lines": true
* }
* }
* }
* @param collection
*/
function buildRelationsOrSelect(collection) {
var e_1, _a;
var _b;
collection = collection.sort();
var output = {};
try {
for (var collection_1 = __values(collection), collection_1_1 = collection_1.next(); !collection_1_1.done; collection_1_1 = collection_1.next()) {
var relation = collection_1_1.value;
if (relation.indexOf(".") > -1) {
var nestedRelations = relation.split(".");
var parent_1 = output;
while (nestedRelations.length > 1) {
var nestedRelation = nestedRelations.shift();
parent_1 = parent_1[nestedRelation] = (parent_1[nestedRelation] !== true &&
typeof parent_1[nestedRelation] === "object"
? parent_1[nestedRelation]
: {});
}
parent_1[nestedRelations[0]] = true;
continue;
}
output[relation] = (_b = output[relation]) !== null && _b !== void 0 ? _b : true;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (collection_1_1 && !collection_1_1.done && (_a = collection_1.return)) _a.call(collection_1);
}
finally { if (e_1) throw e_1.error; }
}
return output;
return (0, object_from_string_path_1.objectFromStringPath)(collection);
}

@@ -119,3 +46,3 @@ /**

function buildOrder(orderBy) {
var e_2, _a;
var e_1, _a;
var _b;

@@ -129,8 +56,8 @@ var output = {};

var nestedOrder = order.split(".");
var parent_2 = output;
var parent_1 = output;
while (nestedOrder.length > 1) {
var nestedRelation = nestedOrder.shift();
parent_2 = (_b = parent_2[nestedRelation]) !== null && _b !== void 0 ? _b : (parent_2[nestedRelation] = {});
parent_1 = (_b = parent_1[nestedRelation]) !== null && _b !== void 0 ? _b : (parent_1[nestedRelation] = {});
}
parent_2[nestedOrder[0]] = orderBy[order];
parent_1[nestedOrder[0]] = orderBy[order];
continue;

@@ -141,3 +68,3 @@ }

}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {

@@ -147,3 +74,3 @@ try {

}
finally { if (e_2) throw e_2.error; }
finally { if (e_1) throw e_1.error; }
}

@@ -150,0 +77,0 @@ return output;

@@ -13,14 +13,13 @@ export * from "./build-query";

export * from "./lower-case-first";
export * from "./upper-case-first";
export * from "./map-object-to";
export * from "./medusa-container";
export * from "./object-from-string-path";
export * from "./object-to-string-path";
export * from "./set-metadata";
export * from "./simple-hash";
export * from "./wrap-handler";
export * from "./to-kebab-case";
export * from "./stringify-circular";
export * from "./to-camel-case";
export * from "./stringify-circular";
export * from "./to-kebab-case";
export * from "./to-pascal-case";
export * from "./upper-case-first";
export * from "./wrap-handler";
export * from "./map-object-to";

@@ -29,15 +29,14 @@ "use strict";

__exportStar(require("./lower-case-first"), exports);
__exportStar(require("./upper-case-first"), exports);
__exportStar(require("./map-object-to"), exports);
__exportStar(require("./medusa-container"), exports);
__exportStar(require("./object-from-string-path"), exports);
__exportStar(require("./object-to-string-path"), exports);
__exportStar(require("./set-metadata"), exports);
__exportStar(require("./simple-hash"), exports);
__exportStar(require("./wrap-handler"), exports);
__exportStar(require("./to-kebab-case"), exports);
__exportStar(require("./stringify-circular"), exports);
__exportStar(require("./to-camel-case"), exports);
__exportStar(require("./stringify-circular"), exports);
__exportStar(require("./to-kebab-case"), exports);
__exportStar(require("./to-pascal-case"), exports);
__exportStar(require("./upper-case-first"), exports);
__exportStar(require("./wrap-handler"), exports);
__exportStar(require("./map-object-to"), exports);
//# sourceMappingURL=index.js.map
export * from "./analytics";
export * from "./order-editing";
export * from "./sales-channels";
export * from "./product-categories";
export * from "./publishable-api-keys";
export * from "./sales-channels";
export * from "./tax-inclusive-pricing";
export * from "./utils";
export * from "./workflows";

@@ -19,7 +19,8 @@ "use strict";

__exportStar(require("./order-editing"), exports);
__exportStar(require("./sales-channels"), exports);
__exportStar(require("./product-categories"), exports);
__exportStar(require("./publishable-api-keys"), exports);
__exportStar(require("./sales-channels"), exports);
__exportStar(require("./tax-inclusive-pricing"), exports);
__exportStar(require("./utils"), exports);
__exportStar(require("./workflows"), exports);
//# sourceMappingURL=index.js.map
import { FeatureFlagTypes } from "@medusajs/types";
export declare class FlagRouter implements FeatureFlagTypes.IFlagRouter {
private readonly flags;
constructor(flags: Record<string, boolean>);
isFeatureEnabled(key: string): boolean;
setFlag(key: string, value?: boolean): void;
constructor(flags: Record<string, boolean | Record<string, boolean>>);
/**
* Check if a feature flag is enabled.
* There are two ways of using this method:
* 1. `isFeatureEnabled("myFeatureFlag")`
* 2. `isFeatureEnabled({ myNestedFeatureFlag: "someNestedFlag" })`
* We use 1. for top-level feature flags and 2. for nested feature flags. Almost all flags are top-level.
* An example of a nested flag is workflows. To use it, you would do:
* `isFeatureEnabled({ workflows: Workflows.CreateCart })`
* @param flag - The flag to check
* @return {boolean} - Whether the flag is enabled or not
*/
isFeatureEnabled(flag: string | Record<string, string>): boolean;
/**
* Sets a feature flag.
* Flags take two shapes:
* setFlag("myFeatureFlag", true)
* setFlag("myFeatureFlag", { nestedFlag: true })
* These shapes are used for top-level and nested flags respectively, as explained in isFeatureEnabled.
* @param key - The key of the flag to set.
* @param value - The value of the flag to set.
* @return {void} - void
*/
setFlag(key: string, value: boolean | {
[key: string]: boolean;
}): void;
listFlags(): FeatureFlagTypes.FeatureFlagsResponse;
}
"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 __read = (this && this.__read) || function (o, n) {

@@ -20,2 +31,3 @@ var m = typeof Symbol === "function" && o[Symbol.iterator];

exports.FlagRouter = void 0;
var common_1 = require("../../common");
var FlagRouter = /** @class */ (function () {

@@ -26,7 +38,47 @@ function FlagRouter(flags) {

}
FlagRouter.prototype.isFeatureEnabled = function (key) {
return !!this.flags[key];
/**
* Check if a feature flag is enabled.
* There are two ways of using this method:
* 1. `isFeatureEnabled("myFeatureFlag")`
* 2. `isFeatureEnabled({ myNestedFeatureFlag: "someNestedFlag" })`
* We use 1. for top-level feature flags and 2. for nested feature flags. Almost all flags are top-level.
* An example of a nested flag is workflows. To use it, you would do:
* `isFeatureEnabled({ workflows: Workflows.CreateCart })`
* @param flag - The flag to check
* @return {boolean} - Whether the flag is enabled or not
*/
FlagRouter.prototype.isFeatureEnabled = function (flag) {
var _a;
if ((0, common_1.isString)(flag)) {
return !!this.flags[flag];
}
if ((0, common_1.isObject)(flag)) {
var _b = __read(Object.entries(flag)[0], 2), nestedFlag = _b[0], value = _b[1];
if (typeof this.flags[nestedFlag] === "boolean") {
return this.flags[nestedFlag];
}
return !!((_a = this.flags[nestedFlag]) === null || _a === void 0 ? void 0 : _a[value]);
}
throw Error("Flag must be a string or an object");
};
/**
* Sets a feature flag.
* Flags take two shapes:
* setFlag("myFeatureFlag", true)
* setFlag("myFeatureFlag", { nestedFlag: true })
* These shapes are used for top-level and nested flags respectively, as explained in isFeatureEnabled.
* @param key - The key of the flag to set.
* @param value - The value of the flag to set.
* @return {void} - void
*/
FlagRouter.prototype.setFlag = function (key, value) {
if (value === void 0) { value = true; }
if ((0, common_1.isObject)(value)) {
var existing = this.flags[key];
if (!existing) {
this.flags[key] = value;
return;
}
this.flags[key] = __assign(__assign({}, this.flags[key]), value);
return;
}
this.flags[key] = value;

@@ -33,0 +85,0 @@ };

{
"name": "@medusajs/utils",
"version": "1.9.5-next-20230805153949",
"version": "1.9.5-next-20230807094514",
"description": "Medusa utilities functions shared by Medusa core and Modules",

@@ -21,3 +21,3 @@ "main": "dist/index.js",

"devDependencies": {
"@medusajs/types": "1.10.1-next-20230805153949",
"@medusajs/types": "1.10.1-next-20230807094514",
"@types/express": "^4.17.17",

@@ -24,0 +24,0 @@ "cross-env": "^5.2.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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