@medusajs/admin-sdk 0.0.1

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.
File without changes
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # extensions-sdk
package/bin/index.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/cli/index.js")
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare function createCli(): Promise<Command>;
3
+ //# sourceMappingURL=create-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-cli.d.ts","sourceRoot":"","sources":["../../src/cli/create-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAGnC,wBAAsB,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,CAUlD"}
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createCli = void 0;
40
+ var commander_1 = require("commander");
41
+ var build_1 = require("../lib/build");
42
+ function createCli() {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ var program, buildCommand;
45
+ return __generator(this, function (_a) {
46
+ program = new commander_1.Command();
47
+ buildCommand = program.command("build");
48
+ buildCommand.description("Build the admin dashboard");
49
+ buildCommand.option("-w, --watch", "Watch for changes");
50
+ buildCommand.option("-m, --minify", "Minify the output");
51
+ buildCommand.action(build_1.build);
52
+ return [2 /*return*/, program];
53
+ });
54
+ });
55
+ }
56
+ exports.createCli = createCli;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var create_cli_1 = require("./create-cli");
40
+ (0, create_cli_1.createCli)()
41
+ .then(function (cli) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
42
+ return [2 /*return*/, cli.parseAsync(process.argv)];
43
+ }); }); })
44
+ .catch(function (err) {
45
+ console.error(err);
46
+ process.exit(1);
47
+ });
@@ -0,0 +1,3 @@
1
+ import type { Extension, ExtensionConfig } from "@medusajs/types";
2
+ export declare function extend(config: ExtensionConfig): Extension;
3
+ //# sourceMappingURL=extend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extend.d.ts","sourceRoot":"","sources":["../../src/extensions/extend.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjE,wBAAgB,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,SAAS,CAUzD"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extend = void 0;
4
+ function extend(config) {
5
+ var identifier = config.identifier, widgets = config.widgets;
6
+ return {
7
+ setup: function (app) {
8
+ if (widgets) {
9
+ app.registerWidgets(identifier, widgets);
10
+ }
11
+ },
12
+ };
13
+ }
14
+ exports.extend = extend;
@@ -0,0 +1,2 @@
1
+ export { extend } from "./extend";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extend = void 0;
4
+ var extend_1 = require("./extend");
5
+ Object.defineProperty(exports, "extend", { enumerable: true, get: function () { return extend_1.extend; } });
@@ -0,0 +1,3 @@
1
+ export * from "./extensions";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./extensions"), exports);
18
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,7 @@
1
+ type BuildOptions = {
2
+ watch?: boolean;
3
+ minify?: boolean;
4
+ };
5
+ export declare function build({ watch, minify }: BuildOptions): Promise<void>;
6
+ export {};
7
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/lib/build.ts"],"names":[],"mappings":"AAsBA,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAeD,wBAAsB,KAAK,CAAC,EAAE,KAAK,EAAE,MAAa,EAAE,EAAE,YAAY,iBAkFjE"}
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __generator = (this && this.__generator) || function (thisArg, body) {
46
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
47
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
48
+ function verb(n) { return function (v) { return step([n, v]); }; }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
52
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
53
+ if (y = 0, t) op = [op[0] & 2, t.value];
54
+ switch (op[0]) {
55
+ case 0: case 1: t = op; break;
56
+ case 4: _.label++; return { value: op[1], done: false };
57
+ case 5: _.label++; y = op[1]; op = [0]; continue;
58
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
59
+ default:
60
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
61
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
62
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
63
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
64
+ if (t[2]) _.ops.pop();
65
+ _.trys.pop(); continue;
66
+ }
67
+ op = body.call(thisArg, _);
68
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
69
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
70
+ }
71
+ };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
75
+ Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.build = void 0;
77
+ var plugin_alias_1 = __importDefault(require("@rollup/plugin-alias"));
78
+ var plugin_commonjs_1 = __importDefault(require("@rollup/plugin-commonjs"));
79
+ var plugin_json_1 = __importDefault(require("@rollup/plugin-json"));
80
+ var plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
81
+ var plugin_replace_1 = __importDefault(require("@rollup/plugin-replace"));
82
+ var plugin_terser_1 = __importDefault(require("@rollup/plugin-terser"));
83
+ var fs_extra_1 = __importDefault(require("fs-extra"));
84
+ var path_1 = __importDefault(require("path"));
85
+ var picocolors_1 = __importDefault(require("picocolors"));
86
+ var rollup_plugin_esbuild_1 = __importDefault(require("rollup-plugin-esbuild"));
87
+ var SHARED_DEPENDENCIES = [
88
+ "@tanstack/react-query",
89
+ "@tanstack/react-table",
90
+ "@medusajs/medusa-js",
91
+ ];
92
+ var env = process.env.NODE_ENV;
93
+ var onwarn = function (warning, warn) {
94
+ var _a;
95
+ if (warning.code === "CIRCULAR_DEPENDENCY" &&
96
+ ((_a = warning.ids) === null || _a === void 0 ? void 0 : _a.every(function (id) { return /\bnode_modules\b/.test(id); }))) {
97
+ return;
98
+ }
99
+ warn(warning);
100
+ };
101
+ function build(_a) {
102
+ var watch = _a.watch, _b = _a.minify, minify = _b === void 0 ? true : _b;
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var indexFilePath, language, entry, plugins, dist, rollupOptions, rollupWatch, watcher_1, rollup, bundle;
105
+ return __generator(this, function (_c) {
106
+ switch (_c.label) {
107
+ case 0:
108
+ indexFilePath = path_1.default.join(process.cwd(), "src", "admin", "index");
109
+ language = "js";
110
+ if (fs_extra_1.default.existsSync("".concat(indexFilePath, ".ts"))) {
111
+ language = "ts";
112
+ }
113
+ entry = "".concat(indexFilePath, ".").concat(language);
114
+ plugins = [
115
+ (0, rollup_plugin_esbuild_1.default)({ include: /\.tsx?$/, sourceMap: true }),
116
+ (0, plugin_node_resolve_1.nodeResolve)({ preferBuiltins: true, browser: true }),
117
+ (0, plugin_commonjs_1.default)({
118
+ extensions: [".mjs", ".js", ".json", ".node", ".jsx", ".ts", ".tsx"],
119
+ }),
120
+ (0, plugin_json_1.default)(),
121
+ (0, plugin_replace_1.default)({
122
+ values: {
123
+ "process.env.NODE_ENV": JSON.stringify(env),
124
+ },
125
+ preventAssignment: true,
126
+ }),
127
+ (0, plugin_alias_1.default)({
128
+ entries: SHARED_DEPENDENCIES.reduce(function (acc, dep) {
129
+ acc[dep] = require.resolve(dep);
130
+ return acc;
131
+ }, {}),
132
+ }),
133
+ ];
134
+ if (minify) {
135
+ plugins.push((0, plugin_terser_1.default)());
136
+ }
137
+ dist = path_1.default.resolve(process.cwd(), "dist", "admin");
138
+ rollupOptions = {
139
+ input: entry,
140
+ output: {
141
+ dir: dist,
142
+ chunkFileNames: "[name].js",
143
+ format: "esm",
144
+ exports: "named",
145
+ },
146
+ plugins: plugins,
147
+ onwarn: onwarn,
148
+ external: SHARED_DEPENDENCIES,
149
+ };
150
+ if (!watch) return [3 /*break*/, 2];
151
+ return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("rollup")); })];
152
+ case 1:
153
+ rollupWatch = (_c.sent()).watch;
154
+ watcher_1 = rollupWatch(__assign(__assign({}, rollupOptions), { watch: {
155
+ clearScreen: true,
156
+ } }));
157
+ process.on("SIGTERM", function () {
158
+ watcher_1.close();
159
+ });
160
+ watcher_1.on("event", function (event) {
161
+ if (event.code === "BUNDLE_END") {
162
+ console.log(picocolors_1.default.green("[@medusajs/admin-sdk]: Extension bundle updated"));
163
+ }
164
+ });
165
+ return [3 /*break*/, 6];
166
+ case 2: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require("rollup")); })];
167
+ case 3:
168
+ rollup = (_c.sent()).rollup;
169
+ return [4 /*yield*/, rollup(rollupOptions)];
170
+ case 4:
171
+ bundle = _c.sent();
172
+ return [4 /*yield*/, bundle.write({
173
+ dir: dist,
174
+ })];
175
+ case 5:
176
+ _c.sent();
177
+ _c.label = 6;
178
+ case 6: return [2 /*return*/];
179
+ }
180
+ });
181
+ });
182
+ }
183
+ exports.build = build;
@@ -0,0 +1,2 @@
1
+ export * from "./widget";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./widget"), exports);
@@ -0,0 +1,16 @@
1
+ import type { Customer, Order, Product, ProductCollection } from "@medusajs/medusa";
2
+ import type { WidgetProps } from "@medusajs/types";
3
+ export interface OrderWidgetProps extends WidgetProps {
4
+ order: Order;
5
+ }
6
+ export interface ProductWidgetProps extends WidgetProps {
7
+ product: Product;
8
+ }
9
+ export interface ProductCollectionWidgetProps extends WidgetProps {
10
+ productCollection: ProductCollection;
11
+ }
12
+ export interface CustomerWidgetProps extends WidgetProps {
13
+ customer: Customer;
14
+ }
15
+ export type { WidgetProps };
16
+ //# sourceMappingURL=widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.d.ts","sourceRoot":"","sources":["../../src/types/widget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,KAAK,EACL,OAAO,EACP,iBAAiB,EAClB,MAAM,kBAAkB,CAAA;AACzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,KAAK,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,MAAM,WAAW,4BAA6B,SAAQ,WAAW;IAC/D,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AAED,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,YAAY,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@medusajs/admin-sdk",
3
+ "version": "0.0.1",
4
+ "description": "SDK for building admin extensions for Medusa",
5
+ "author": "Kasper Kristensen <kasper@medusajs.com>",
6
+ "bin": {
7
+ "extension": "./bin/index.js"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "scripts": {
11
+ "build": "tsc"
12
+ },
13
+ "dependencies": {
14
+ "@rollup/plugin-alias": "^5.0.0",
15
+ "@rollup/plugin-commonjs": "^24.1.0",
16
+ "@rollup/plugin-json": "^6.0.0",
17
+ "@rollup/plugin-node-resolve": "^15.0.2",
18
+ "@rollup/plugin-replace": "^5.0.2",
19
+ "@rollup/plugin-terser": "^0.4.1",
20
+ "@rollup/plugin-typescript": "^11.1.0",
21
+ "esbuild": "^0.17.18",
22
+ "fs-extra": "^11.1.1",
23
+ "picocolors": "^1.0.0",
24
+ "rollup": "^3.20.7",
25
+ "rollup-plugin-esbuild": "^5.0.0",
26
+ "tslib": "^2.5.0"
27
+ },
28
+ "devDependencies": {
29
+ "@medusajs/medusa": "*",
30
+ "@medusajs/types": "*",
31
+ "@types/fs-extra": "^11.0.1",
32
+ "typescript": "^5.0.4"
33
+ },
34
+ "packageManager": "yarn@3.2.1"
35
+ }
@@ -0,0 +1,14 @@
1
+ import { Command } from "commander"
2
+ import { build } from "../lib/build"
3
+
4
+ export async function createCli(): Promise<Command> {
5
+ const program = new Command()
6
+
7
+ const buildCommand = program.command("build")
8
+ buildCommand.description("Build the admin dashboard")
9
+ buildCommand.option("-w, --watch", "Watch for changes")
10
+ buildCommand.option("-m, --minify", "Minify the output")
11
+ buildCommand.action(build)
12
+
13
+ return program
14
+ }
@@ -0,0 +1,8 @@
1
+ import { createCli } from "./create-cli"
2
+
3
+ createCli()
4
+ .then(async (cli) => cli.parseAsync(process.argv))
5
+ .catch((err) => {
6
+ console.error(err)
7
+ process.exit(1)
8
+ })
@@ -0,0 +1,13 @@
1
+ import type { Extension, ExtensionConfig } from "@medusajs/types"
2
+
3
+ export function extend(config: ExtensionConfig): Extension {
4
+ const { identifier, widgets } = config
5
+
6
+ return {
7
+ setup(app) {
8
+ if (widgets) {
9
+ app.registerWidgets(identifier, widgets)
10
+ }
11
+ },
12
+ }
13
+ }
@@ -0,0 +1 @@
1
+ export { extend } from "./extend"
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./extensions"
2
+ export * from "./types"
@@ -0,0 +1,123 @@
1
+ import alias from "@rollup/plugin-alias"
2
+ import commonjs from "@rollup/plugin-commonjs"
3
+ import json from "@rollup/plugin-json"
4
+ import { nodeResolve } from "@rollup/plugin-node-resolve"
5
+ import replace from "@rollup/plugin-replace"
6
+ import terser from "@rollup/plugin-terser"
7
+ import fse from "fs-extra"
8
+ import path from "path"
9
+ import colors from "picocolors"
10
+ import type {
11
+ InputPluginOption,
12
+ RollupOptions,
13
+ WarningHandlerWithDefault,
14
+ } from "rollup"
15
+ import esbuild from "rollup-plugin-esbuild"
16
+
17
+ const SHARED_DEPENDENCIES = [
18
+ "@tanstack/react-query",
19
+ "@tanstack/react-table",
20
+ "@medusajs/medusa-js",
21
+ ]
22
+
23
+ type BuildOptions = {
24
+ watch?: boolean
25
+ minify?: boolean
26
+ }
27
+
28
+ const env = process.env.NODE_ENV
29
+
30
+ const onwarn: WarningHandlerWithDefault = (warning, warn) => {
31
+ if (
32
+ warning.code === "CIRCULAR_DEPENDENCY" &&
33
+ warning.ids?.every((id) => /\bnode_modules\b/.test(id))
34
+ ) {
35
+ return
36
+ }
37
+
38
+ warn(warning)
39
+ }
40
+
41
+ export async function build({ watch, minify = true }: BuildOptions) {
42
+ const indexFilePath = path.join(process.cwd(), "src", "admin", "index")
43
+
44
+ let language: "ts" | "js" = "js"
45
+
46
+ if (fse.existsSync(`${indexFilePath}.ts`)) {
47
+ language = "ts"
48
+ }
49
+
50
+ const entry = `${indexFilePath}.${language}`
51
+
52
+ const plugins: InputPluginOption = [
53
+ esbuild({ include: /\.tsx?$/, sourceMap: true }),
54
+ nodeResolve({ preferBuiltins: true, browser: true }),
55
+ commonjs({
56
+ extensions: [".mjs", ".js", ".json", ".node", ".jsx", ".ts", ".tsx"],
57
+ }),
58
+ json(),
59
+ replace({
60
+ values: {
61
+ "process.env.NODE_ENV": JSON.stringify(env),
62
+ },
63
+ preventAssignment: true,
64
+ }),
65
+ alias({
66
+ entries: SHARED_DEPENDENCIES.reduce((acc, dep) => {
67
+ acc[dep] = require.resolve(dep)
68
+
69
+ return acc
70
+ }, {} as { [key: string]: string }),
71
+ }),
72
+ ]
73
+
74
+ if (minify) {
75
+ plugins.push(terser())
76
+ }
77
+
78
+ const dist = path.resolve(process.cwd(), "dist", "admin")
79
+
80
+ const rollupOptions: RollupOptions = {
81
+ input: entry,
82
+ output: {
83
+ dir: dist,
84
+ chunkFileNames: "[name].js",
85
+ format: "esm",
86
+ exports: "named",
87
+ },
88
+ plugins,
89
+ onwarn,
90
+ external: SHARED_DEPENDENCIES,
91
+ }
92
+
93
+ if (watch) {
94
+ const { watch: rollupWatch } = await import("rollup")
95
+
96
+ const watcher = rollupWatch({
97
+ ...rollupOptions,
98
+ watch: {
99
+ clearScreen: true,
100
+ },
101
+ })
102
+
103
+ process.on("SIGTERM", () => {
104
+ watcher.close()
105
+ })
106
+
107
+ watcher.on("event", (event) => {
108
+ if (event.code === "BUNDLE_END") {
109
+ console.log(
110
+ colors.green("[@medusajs/admin-sdk]: Extension bundle updated")
111
+ )
112
+ }
113
+ })
114
+ } else {
115
+ const { rollup } = await import("rollup")
116
+
117
+ const bundle = await rollup(rollupOptions)
118
+
119
+ await bundle.write({
120
+ dir: dist,
121
+ })
122
+ }
123
+ }
@@ -0,0 +1 @@
1
+ export * from "./widget"
@@ -0,0 +1,25 @@
1
+ import type {
2
+ Customer,
3
+ Order,
4
+ Product,
5
+ ProductCollection,
6
+ } from "@medusajs/medusa"
7
+ import type { WidgetProps } from "@medusajs/types"
8
+
9
+ export interface OrderWidgetProps extends WidgetProps {
10
+ order: Order
11
+ }
12
+
13
+ export interface ProductWidgetProps extends WidgetProps {
14
+ product: Product
15
+ }
16
+
17
+ export interface ProductCollectionWidgetProps extends WidgetProps {
18
+ productCollection: ProductCollection
19
+ }
20
+
21
+ export interface CustomerWidgetProps extends WidgetProps {
22
+ customer: Customer
23
+ }
24
+
25
+ export type { WidgetProps }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": true,
4
+ "declarationMap": true,
5
+ "experimentalDecorators": true,
6
+ "emitDecoratorMetadata": true,
7
+ "module": "commonjs",
8
+ "moduleResolution": "node",
9
+ "noEmit": false,
10
+ "resolveJsonModule": true,
11
+ "esModuleInterop": true,
12
+ "outDir": "dist",
13
+ "rootDir": "src",
14
+ "skipLibCheck": true
15
+ },
16
+ "include": ["src"],
17
+ "exclude": ["**/node_modules"]
18
+ }