@medusajs/utils 2.22.2 → 2.22.3-snapshot-20261103230838
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common/define-config.d.ts +6 -0
- package/dist/common/define-config.d.ts.map +1 -1
- package/dist/common/define-config.js +10 -9
- package/dist/common/define-config.js.map +1 -1
- package/dist/common/is-email.d.ts +5 -0
- package/dist/common/is-email.d.ts.map +1 -1
- package/dist/common/is-email.js +2 -1
- package/dist/common/is-email.js.map +1 -1
- package/dist/common/medusa-container.d.ts +2 -1
- package/dist/common/medusa-container.d.ts.map +1 -1
- package/dist/common/medusa-container.js +3 -2
- package/dist/common/medusa-container.js.map +1 -1
- package/dist/defaults/currencies.d.ts.map +1 -1
- package/dist/defaults/currencies.js +9 -0
- package/dist/defaults/currencies.js.map +1 -1
- package/dist/graphql/graphql-to-ts-types.d.ts.map +1 -1
- package/dist/graphql/graphql-to-ts-types.js +5 -36
- package/dist/graphql/graphql-to-ts-types.js.map +1 -1
- package/dist/modules-sdk/index.d.ts +0 -2
- package/dist/modules-sdk/index.d.ts.map +1 -1
- package/dist/modules-sdk/index.js +0 -2
- package/dist/modules-sdk/index.js.map +1 -1
- package/dist/policies/build-policies.d.ts +80 -0
- package/dist/policies/build-policies.d.ts.map +1 -0
- package/dist/policies/build-policies.js +31 -0
- package/dist/policies/build-policies.js.map +1 -0
- package/dist/policies/index.d.ts +2 -1
- package/dist/policies/index.d.ts.map +1 -1
- package/dist/policies/index.js +2 -1
- package/dist/policies/index.js.map +1 -1
- package/dist/policies/policy-operations.d.ts +46 -0
- package/dist/policies/policy-operations.d.ts.map +1 -0
- package/dist/policies/policy-operations.js +55 -0
- package/dist/policies/policy-operations.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/dist/modules-sdk/define-policies.d.ts +0 -67
- package/dist/modules-sdk/define-policies.d.ts.map +0 -1
- package/dist/modules-sdk/define-policies.js +0 -93
- package/dist/modules-sdk/define-policies.js.map +0 -1
- package/dist/modules-sdk/policy-to-types.d.ts +0 -12
- package/dist/modules-sdk/policy-to-types.d.ts.map +0 -1
- package/dist/modules-sdk/policy-to-types.js +0 -79
- package/dist/modules-sdk/policy-to-types.js.map +0 -1
- package/dist/policies/discover-policies.d.ts +0 -5
- package/dist/policies/discover-policies.d.ts.map +0 -1
- package/dist/policies/discover-policies.js +0 -52
- package/dist/policies/discover-policies.js.map +0 -1
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generatePolicyTypes = generatePolicyTypes;
|
|
4
|
-
const file_system_1 = require("../common/file-system");
|
|
5
|
-
const promise_all_1 = require("../common/promise-all");
|
|
6
|
-
const define_policies_1 = require("./define-policies");
|
|
7
|
-
/**
|
|
8
|
-
* Generates TypeScript type definitions for RBAC Resource, Operation, and Policy.
|
|
9
|
-
* Creates two files:
|
|
10
|
-
* - "policy-types.d.ts" - Ambient type declarations with global types
|
|
11
|
-
* - "policy-bindings.d.ts" - Module augmentation for @medusajs/framework/utils
|
|
12
|
-
*
|
|
13
|
-
* @param outputDir - Directory where the type definition files should be created
|
|
14
|
-
*/
|
|
15
|
-
async function generatePolicyTypes({ outputDir, }) {
|
|
16
|
-
const policyTypeEntries = [];
|
|
17
|
-
// Generate type entries for each named policy from Policy object
|
|
18
|
-
for (const [name, { resource, operation }] of Object.entries(define_policies_1.Policy)) {
|
|
19
|
-
policyTypeEntries.push(` ${name}: { resource: "${resource}"; operation: "${operation}" };`);
|
|
20
|
-
}
|
|
21
|
-
// If no policies are registered, create empty types
|
|
22
|
-
const policyInterface = policyTypeEntries.length > 0
|
|
23
|
-
? `{\n${policyTypeEntries.join("\n")}\n}`
|
|
24
|
-
: "{}";
|
|
25
|
-
const fileSystem = new file_system_1.FileSystem(outputDir);
|
|
26
|
-
const resourceKeys = Object.keys(define_policies_1.PolicyResource).sort();
|
|
27
|
-
const operationKeys = Object.keys(define_policies_1.PolicyOperation).sort();
|
|
28
|
-
// Generate PolicyResourceType entries
|
|
29
|
-
const resourceTypeEntries = resourceKeys
|
|
30
|
-
.map((key) => ` readonly ${key}: "${define_policies_1.PolicyResource[key]}";`)
|
|
31
|
-
.join("\n");
|
|
32
|
-
// Generate PolicyOperationType entries
|
|
33
|
-
const operationTypeEntries = operationKeys
|
|
34
|
-
.map((key) => ` readonly ${key === "*" ? `"*"` : key}: "${define_policies_1.PolicyOperation[key]}";`)
|
|
35
|
-
.join("\n");
|
|
36
|
-
// File 1: policy-types.d.ts - Ambient type declarations
|
|
37
|
-
const policyTypesContents = `/**
|
|
38
|
-
* RBAC Resource registry type
|
|
39
|
-
*/
|
|
40
|
-
type PolicyResourceType = {
|
|
41
|
-
${resourceTypeEntries}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* RBAC Operation registry type
|
|
46
|
-
*/
|
|
47
|
-
type PolicyOperationType = {
|
|
48
|
-
${operationTypeEntries}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* RBAC Policy registry type
|
|
53
|
-
*/
|
|
54
|
-
type PolicyType = ${policyInterface};
|
|
55
|
-
|
|
56
|
-
// Global declarations
|
|
57
|
-
declare const PolicyResource: PolicyResourceType;
|
|
58
|
-
declare const PolicyOperation: PolicyOperationType;
|
|
59
|
-
declare const Policy: PolicyType;
|
|
60
|
-
`;
|
|
61
|
-
// File 2: policy-bindings.d.ts - Module augmentation
|
|
62
|
-
const policyBindingsContents = `/// <reference path="./policy-types.d.ts" />
|
|
63
|
-
|
|
64
|
-
// Module augmentation for @medusajs/framework/utils
|
|
65
|
-
// Types and globals are defined in policy-types.d.ts
|
|
66
|
-
declare module "@medusajs/framework/utils" {
|
|
67
|
-
export const PolicyResource: PolicyResourceType;
|
|
68
|
-
export const PolicyOperation: PolicyOperationType;
|
|
69
|
-
export const Policy: PolicyType;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export {};
|
|
73
|
-
`;
|
|
74
|
-
await (0, promise_all_1.promiseAll)([
|
|
75
|
-
fileSystem.create("policy-types.d.ts", policyTypesContents),
|
|
76
|
-
fileSystem.create("policy-bindings.d.ts", policyBindingsContents),
|
|
77
|
-
]);
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=policy-to-types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"policy-to-types.js","sourceRoot":"","sources":["../../src/modules-sdk/policy-to-types.ts"],"names":[],"mappings":";;AAYA,kDAkFC;AA9FD,uDAAkD;AAClD,uDAAkD;AAClD,uDAA2E;AAE3E;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CAAC,EACxC,SAAS,GAGV;IACC,MAAM,iBAAiB,GAAa,EAAE,CAAA;IAEtC,iEAAiE;IACjE,KAAK,MAAM,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,wBAAM,CAAC,EAAE,CAAC;QACrE,iBAAiB,CAAC,IAAI,CACpB,KAAK,IAAI,kBAAkB,QAAQ,kBAAkB,SAAS,MAAM,CACrE,CAAA;IACH,CAAC;IAED,oDAAoD;IACpD,MAAM,eAAe,GACnB,iBAAiB,CAAC,MAAM,GAAG,CAAC;QAC1B,CAAC,CAAC,MAAM,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;QACzC,CAAC,CAAC,IAAI,CAAA;IAEV,MAAM,UAAU,GAAG,IAAI,wBAAU,CAAC,SAAS,CAAC,CAAA;IAE5C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,gCAAc,CAAC,CAAC,IAAI,EAAE,CAAA;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,iCAAe,CAAC,CAAC,IAAI,EAAE,CAAA;IAEzD,sCAAsC;IACtC,MAAM,mBAAmB,GAAG,YAAY;SACrC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,GAAG,MAAM,gCAAc,CAAC,GAAG,CAAC,IAAI,CAAC;SAC5D,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,uCAAuC;IACvC,MAAM,oBAAoB,GAAG,aAAa;SACvC,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CACN,cAAc,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,iCAAe,CAAC,GAAG,CAAC,IAAI,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,wDAAwD;IACxD,MAAM,mBAAmB,GAAG;;;;EAI5B,mBAAmB;;;;;;;EAOnB,oBAAoB;;;;;;oBAMF,eAAe;;;;;;CAMlC,CAAA;IAEC,qDAAqD;IACrD,MAAM,sBAAsB,GAAG;;;;;;;;;;;CAWhC,CAAA;IAEC,MAAM,IAAA,wBAAU,EAAC;QACf,UAAU,CAAC,MAAM,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;QAC3D,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,sBAAsB,CAAC;KAClE,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discover-policies.d.ts","sourceRoot":"","sources":["../../src/policies/discover-policies.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,CAAC,EAAE,MAAM,EACnB,QAAQ,GAAE,MAAU,GACnB,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.discoverPoliciesFromDir = discoverPoliciesFromDir;
|
|
4
|
-
const promises_1 = require("fs/promises");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const common_1 = require("../common");
|
|
7
|
-
const modules_sdk_1 = require("../modules-sdk");
|
|
8
|
-
const excludedFiles = ["index.js", "index.ts"];
|
|
9
|
-
const excludedExtensions = [".d.ts", ".d.ts.map", ".js.map"];
|
|
10
|
-
function isPolicyExport(value) {
|
|
11
|
-
return !!value && typeof value === "object" && modules_sdk_1.MedusaPolicySymbol in value;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Discover policy definitions from a directory and subdirectories
|
|
15
|
-
*/
|
|
16
|
-
async function discoverPoliciesFromDir(sourcePath, maxDepth = 2) {
|
|
17
|
-
if (!sourcePath) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const root = (0, path_1.normalize)(sourcePath);
|
|
21
|
-
const allEntries = await (0, common_1.readDirRecursive)(root, {
|
|
22
|
-
ignoreMissing: true,
|
|
23
|
-
maxDepth,
|
|
24
|
-
});
|
|
25
|
-
const policyDirs = allEntries
|
|
26
|
-
.filter((e) => e.isDirectory() && e.name === "policies")
|
|
27
|
-
.map((e) => (0, path_1.join)(e.path, e.name));
|
|
28
|
-
if (!policyDirs.length) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
await Promise.all(policyDirs.map(async (scanDir) => {
|
|
32
|
-
const entries = await (0, promises_1.readdir)(scanDir, { withFileTypes: true });
|
|
33
|
-
await Promise.all(entries.map(async (entry) => {
|
|
34
|
-
if (entry.isDirectory()) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
if (excludedExtensions.some((ext) => entry.name.endsWith(ext)) ||
|
|
38
|
-
excludedFiles.includes(entry.name)) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
// Import the file - this will execute definePolicies() calls
|
|
42
|
-
const fileExports = await (0, common_1.dynamicImport)((0, path_1.join)(scanDir, entry.name));
|
|
43
|
-
// Validate that at least one export is a policy
|
|
44
|
-
const values = Object.values(fileExports);
|
|
45
|
-
const hasPolicies = values.some((value) => isPolicyExport(value));
|
|
46
|
-
if (!hasPolicies) {
|
|
47
|
-
console.warn(`File ${entry.name} in policies directory does not export any policies`);
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=discover-policies.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discover-policies.js","sourceRoot":"","sources":["../../src/policies/discover-policies.ts"],"names":[],"mappings":";;AAeA,0DAuDC;AAtED,0CAAqC;AACrC,+BAAsC;AACtC,sCAA2D;AAC3D,gDAAmD;AAEnD,MAAM,aAAa,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAC9C,MAAM,kBAAkB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,CAAC,CAAA;AAE5D,SAAS,cAAc,CAAC,KAAc;IACpC,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,gCAAkB,IAAI,KAAK,CAAA;AAC5E,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,uBAAuB,CAC3C,UAAmB,EACnB,WAAmB,CAAC;IAEpB,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAM;IACR,CAAC;IAED,MAAM,IAAI,GAAG,IAAA,gBAAS,EAAC,UAAU,CAAC,CAAA;IAElC,MAAM,UAAU,GAAG,MAAM,IAAA,yBAAgB,EAAC,IAAI,EAAE;QAC9C,aAAa,EAAE,IAAI;QACnB,QAAQ;KACT,CAAC,CAAA;IAEF,MAAM,UAAU,GAAG,UAAU;SAC1B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC;SACvD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,WAAI,EAAE,CAAS,CAAC,IAAc,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;IAEtD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC;QACvB,OAAM;IACR,CAA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