@amboras-dev/aliexpress-dropshipping 1.1.0

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @amboras-dev/aliexpress-dropshipping
2
+
3
+ Thin shell package for the Amboras AliExpress Dropshipping integration.
4
+ Class B (backend-heavy) - this package only exports shared TypeScript
5
+ types and the React admin settings form. All AliExpress OAuth, signing
6
+ (MD5 for `/sync`, HMAC-SHA256 for `/rest/auth/token/*`), category
7
+ browsing, product import, and token refresh live in the Medusa backend
8
+ module.
9
+
10
+ See the plugin admin page for connect / test-connection / disconnect
11
+ UI and the merchant OAuth flow.
@@ -0,0 +1,171 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Public types for @amboras-dev/aliexpress-dropshipping.
5
+ *
6
+ * These are the single source of truth for the wire shape between the
7
+ * Amboras admin settings form and the medusa-backend-orchestrator
8
+ * Store API routes under `/store/aliexpress-dropshipping/*`. The DTO
9
+ * files on the medusa side must stay byte-compatible with these.
10
+ */
11
+ /**
12
+ * Sentinel returned in place of a stored secret when the settings form
13
+ * reads back current config. Matches the pattern used by meta-ads and
14
+ * pinterest so the admin never sees the plaintext secret after write.
15
+ */
16
+ declare const SECRET_SET_SENTINEL: "__SECRET_SET__";
17
+ type SecretSetSentinel = typeof SECRET_SET_SENTINEL;
18
+ /**
19
+ * Per-store AliExpress plugin configuration.
20
+ *
21
+ * - `appKey` / `appSecret` are per-store developer app credentials
22
+ * supplied by the merchant. The admin form receives
23
+ * `SECRET_SET_SENTINEL` for `appSecret` on read, and only sends a
24
+ * real value on user edit.
25
+ * - `connectedSellerId` is populated after the merchant completes the
26
+ * OAuth flow to `/rest/auth/token/create`.
27
+ * - `needsReauth` is flipped by the backend runtime detector when it
28
+ * sees `MissingParameter access_token` or `IllegalAccessToken`
29
+ * sub-codes on any envelope.
30
+ * - `lastSuccessfulCallAt` is an ISO-8601 timestamp for the status card.
31
+ */
32
+ interface AliExpressPluginConfig {
33
+ enabled: boolean;
34
+ appKey: string | null;
35
+ appSecret: string | SecretSetSentinel | null;
36
+ connectedSellerId: string | null;
37
+ needsReauth: boolean;
38
+ lastSuccessfulCallAt: string | null;
39
+ }
40
+ /**
41
+ * Reasons the backend surfaces when a merchant token becomes invalid.
42
+ * Kept narrow so the admin banner can render a specific message.
43
+ */
44
+ declare enum AliExpressReauthReason {
45
+ MissingAccessToken = "missing_access_token",
46
+ IllegalAccessToken = "illegal_access_token",
47
+ RefreshFailed = "refresh_failed",
48
+ Disconnected = "disconnected"
49
+ }
50
+ /**
51
+ * Category node returned by `aliexpress.ds.category.get`. The API
52
+ * returns a flat list; the admin renders it as a tree by walking
53
+ * `parentCategoryId`.
54
+ */
55
+ interface AliExpressCategoryDto {
56
+ categoryId: string;
57
+ categoryName: string;
58
+ parentCategoryId: string | null;
59
+ }
60
+ /**
61
+ * Product summary shape returned by `aliexpress.ds.recommend.feed.get`.
62
+ * Used by the "browse products" admin surface.
63
+ */
64
+ interface AliExpressProductSummaryDto {
65
+ productId: string;
66
+ title: string;
67
+ imageUrl: string | null;
68
+ minPrice: number | null;
69
+ maxPrice: number | null;
70
+ currency: string | null;
71
+ productDetailUrl: string | null;
72
+ }
73
+ /**
74
+ * Full product shape returned by `aliexpress.ds.product.get`. Consumed
75
+ * by the medusa-side mapper `aliexpressProductToMedusaDraft`.
76
+ */
77
+ interface AliExpressProductDto {
78
+ productId: string;
79
+ title: string;
80
+ description: string | null;
81
+ images: string[];
82
+ variants: AliExpressProductVariantDto[];
83
+ weightGrams: number | null;
84
+ sourceUrl: string | null;
85
+ }
86
+ interface AliExpressProductVariantDto {
87
+ skuId: string;
88
+ title: string | null;
89
+ price: number;
90
+ currency: string;
91
+ stock: number | null;
92
+ attributes: Record<string, string>;
93
+ }
94
+ /**
95
+ * Return shape from `POST /store/aliexpress-dropshipping/products/:id/import`.
96
+ */
97
+ interface AliExpressImportResultDto {
98
+ medusaProductId: string;
99
+ sourceProductId: string;
100
+ importedVariants: number;
101
+ }
102
+ /**
103
+ * Return shape from `GET /store/aliexpress-dropshipping/status` - drives
104
+ * the admin status card.
105
+ */
106
+ interface AliExpressConnectionStatusDto {
107
+ connected: boolean;
108
+ sellerId: string | null;
109
+ needsReauth: boolean;
110
+ reauthReason: AliExpressReauthReason | null;
111
+ lastSuccessfulCallAt: string | null;
112
+ }
113
+ /**
114
+ * Return shape from `POST /store/aliexpress-dropshipping/test-connection`.
115
+ */
116
+ type AliExpressTestConnectionResult = {
117
+ ok: true;
118
+ categoryCount: number;
119
+ } | {
120
+ ok: false;
121
+ code: string;
122
+ msg: string;
123
+ };
124
+
125
+ /**
126
+ * Admin settings form for the AliExpress Dropshipping integration.
127
+ *
128
+ * Class B: this component owns the UI and talks to the Medusa Store API
129
+ * under `/store/aliexpress-dropshipping/*`. It does NOT embed any
130
+ * AliExpress SDK, does not sign requests, and does not touch OAuth
131
+ * tokens directly - the backend does all of that.
132
+ *
133
+ * The component is intentionally dependency-light (no external UI kit,
134
+ * no @tanstack/react-query peer) so the admin bundle can drop it in
135
+ * without extra peer dep resolution.
136
+ */
137
+
138
+ interface AliExpressDropshippingSettingsFormProps {
139
+ /** Current config for this store (fetched by the parent server component). */
140
+ initialConfig: AliExpressPluginConfig;
141
+ /** Current connection status (from `GET /status`). */
142
+ initialStatus: AliExpressConnectionStatusDto;
143
+ /**
144
+ * Persist non-secret + optionally new secret values. The parent maps
145
+ * this onto `PATCH /store/aliexpress-dropshipping/config` (or
146
+ * equivalent) and then re-fetches config on success.
147
+ *
148
+ * `appSecret` is only sent when the merchant actually typed a new
149
+ * value; if they leave the field untouched, this method receives
150
+ * `undefined` for that key so the backend keeps the existing secret.
151
+ */
152
+ onSaveConfig: (patch: {
153
+ appKey?: string;
154
+ appSecret?: string;
155
+ enabled?: boolean;
156
+ }) => Promise<void>;
157
+ /** Kick off `POST /oauth/start` and redirect to the returned URL. */
158
+ onConnect: () => Promise<void>;
159
+ /** Kick off `POST /oauth/disconnect` and clear merchant credentials. */
160
+ onDisconnect: () => Promise<void>;
161
+ /** Call `POST /test-connection` and return the result. */
162
+ onTestConnection: () => Promise<AliExpressTestConnectionResult>;
163
+ }
164
+ /**
165
+ * Amboras admin settings surface for AliExpress Dropshipping.
166
+ * Renders AppKey + AppSecret inputs, Test / Connect / Disconnect
167
+ * buttons, status card, and a "Coming soon" order-forwarding block.
168
+ */
169
+ declare function AliExpressDropshippingSettingsForm(props: AliExpressDropshippingSettingsFormProps): React.ReactElement;
170
+
171
+ export { type AliExpressCategoryDto, type AliExpressConnectionStatusDto, AliExpressDropshippingSettingsForm, type AliExpressDropshippingSettingsFormProps, type AliExpressImportResultDto, type AliExpressPluginConfig, type AliExpressProductDto, type AliExpressProductSummaryDto, type AliExpressProductVariantDto, AliExpressReauthReason, type AliExpressTestConnectionResult, SECRET_SET_SENTINEL, type SecretSetSentinel };
@@ -0,0 +1,171 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Public types for @amboras-dev/aliexpress-dropshipping.
5
+ *
6
+ * These are the single source of truth for the wire shape between the
7
+ * Amboras admin settings form and the medusa-backend-orchestrator
8
+ * Store API routes under `/store/aliexpress-dropshipping/*`. The DTO
9
+ * files on the medusa side must stay byte-compatible with these.
10
+ */
11
+ /**
12
+ * Sentinel returned in place of a stored secret when the settings form
13
+ * reads back current config. Matches the pattern used by meta-ads and
14
+ * pinterest so the admin never sees the plaintext secret after write.
15
+ */
16
+ declare const SECRET_SET_SENTINEL: "__SECRET_SET__";
17
+ type SecretSetSentinel = typeof SECRET_SET_SENTINEL;
18
+ /**
19
+ * Per-store AliExpress plugin configuration.
20
+ *
21
+ * - `appKey` / `appSecret` are per-store developer app credentials
22
+ * supplied by the merchant. The admin form receives
23
+ * `SECRET_SET_SENTINEL` for `appSecret` on read, and only sends a
24
+ * real value on user edit.
25
+ * - `connectedSellerId` is populated after the merchant completes the
26
+ * OAuth flow to `/rest/auth/token/create`.
27
+ * - `needsReauth` is flipped by the backend runtime detector when it
28
+ * sees `MissingParameter access_token` or `IllegalAccessToken`
29
+ * sub-codes on any envelope.
30
+ * - `lastSuccessfulCallAt` is an ISO-8601 timestamp for the status card.
31
+ */
32
+ interface AliExpressPluginConfig {
33
+ enabled: boolean;
34
+ appKey: string | null;
35
+ appSecret: string | SecretSetSentinel | null;
36
+ connectedSellerId: string | null;
37
+ needsReauth: boolean;
38
+ lastSuccessfulCallAt: string | null;
39
+ }
40
+ /**
41
+ * Reasons the backend surfaces when a merchant token becomes invalid.
42
+ * Kept narrow so the admin banner can render a specific message.
43
+ */
44
+ declare enum AliExpressReauthReason {
45
+ MissingAccessToken = "missing_access_token",
46
+ IllegalAccessToken = "illegal_access_token",
47
+ RefreshFailed = "refresh_failed",
48
+ Disconnected = "disconnected"
49
+ }
50
+ /**
51
+ * Category node returned by `aliexpress.ds.category.get`. The API
52
+ * returns a flat list; the admin renders it as a tree by walking
53
+ * `parentCategoryId`.
54
+ */
55
+ interface AliExpressCategoryDto {
56
+ categoryId: string;
57
+ categoryName: string;
58
+ parentCategoryId: string | null;
59
+ }
60
+ /**
61
+ * Product summary shape returned by `aliexpress.ds.recommend.feed.get`.
62
+ * Used by the "browse products" admin surface.
63
+ */
64
+ interface AliExpressProductSummaryDto {
65
+ productId: string;
66
+ title: string;
67
+ imageUrl: string | null;
68
+ minPrice: number | null;
69
+ maxPrice: number | null;
70
+ currency: string | null;
71
+ productDetailUrl: string | null;
72
+ }
73
+ /**
74
+ * Full product shape returned by `aliexpress.ds.product.get`. Consumed
75
+ * by the medusa-side mapper `aliexpressProductToMedusaDraft`.
76
+ */
77
+ interface AliExpressProductDto {
78
+ productId: string;
79
+ title: string;
80
+ description: string | null;
81
+ images: string[];
82
+ variants: AliExpressProductVariantDto[];
83
+ weightGrams: number | null;
84
+ sourceUrl: string | null;
85
+ }
86
+ interface AliExpressProductVariantDto {
87
+ skuId: string;
88
+ title: string | null;
89
+ price: number;
90
+ currency: string;
91
+ stock: number | null;
92
+ attributes: Record<string, string>;
93
+ }
94
+ /**
95
+ * Return shape from `POST /store/aliexpress-dropshipping/products/:id/import`.
96
+ */
97
+ interface AliExpressImportResultDto {
98
+ medusaProductId: string;
99
+ sourceProductId: string;
100
+ importedVariants: number;
101
+ }
102
+ /**
103
+ * Return shape from `GET /store/aliexpress-dropshipping/status` - drives
104
+ * the admin status card.
105
+ */
106
+ interface AliExpressConnectionStatusDto {
107
+ connected: boolean;
108
+ sellerId: string | null;
109
+ needsReauth: boolean;
110
+ reauthReason: AliExpressReauthReason | null;
111
+ lastSuccessfulCallAt: string | null;
112
+ }
113
+ /**
114
+ * Return shape from `POST /store/aliexpress-dropshipping/test-connection`.
115
+ */
116
+ type AliExpressTestConnectionResult = {
117
+ ok: true;
118
+ categoryCount: number;
119
+ } | {
120
+ ok: false;
121
+ code: string;
122
+ msg: string;
123
+ };
124
+
125
+ /**
126
+ * Admin settings form for the AliExpress Dropshipping integration.
127
+ *
128
+ * Class B: this component owns the UI and talks to the Medusa Store API
129
+ * under `/store/aliexpress-dropshipping/*`. It does NOT embed any
130
+ * AliExpress SDK, does not sign requests, and does not touch OAuth
131
+ * tokens directly - the backend does all of that.
132
+ *
133
+ * The component is intentionally dependency-light (no external UI kit,
134
+ * no @tanstack/react-query peer) so the admin bundle can drop it in
135
+ * without extra peer dep resolution.
136
+ */
137
+
138
+ interface AliExpressDropshippingSettingsFormProps {
139
+ /** Current config for this store (fetched by the parent server component). */
140
+ initialConfig: AliExpressPluginConfig;
141
+ /** Current connection status (from `GET /status`). */
142
+ initialStatus: AliExpressConnectionStatusDto;
143
+ /**
144
+ * Persist non-secret + optionally new secret values. The parent maps
145
+ * this onto `PATCH /store/aliexpress-dropshipping/config` (or
146
+ * equivalent) and then re-fetches config on success.
147
+ *
148
+ * `appSecret` is only sent when the merchant actually typed a new
149
+ * value; if they leave the field untouched, this method receives
150
+ * `undefined` for that key so the backend keeps the existing secret.
151
+ */
152
+ onSaveConfig: (patch: {
153
+ appKey?: string;
154
+ appSecret?: string;
155
+ enabled?: boolean;
156
+ }) => Promise<void>;
157
+ /** Kick off `POST /oauth/start` and redirect to the returned URL. */
158
+ onConnect: () => Promise<void>;
159
+ /** Kick off `POST /oauth/disconnect` and clear merchant credentials. */
160
+ onDisconnect: () => Promise<void>;
161
+ /** Call `POST /test-connection` and return the result. */
162
+ onTestConnection: () => Promise<AliExpressTestConnectionResult>;
163
+ }
164
+ /**
165
+ * Amboras admin settings surface for AliExpress Dropshipping.
166
+ * Renders AppKey + AppSecret inputs, Test / Connect / Disconnect
167
+ * buttons, status card, and a "Coming soon" order-forwarding block.
168
+ */
169
+ declare function AliExpressDropshippingSettingsForm(props: AliExpressDropshippingSettingsFormProps): React.ReactElement;
170
+
171
+ export { type AliExpressCategoryDto, type AliExpressConnectionStatusDto, AliExpressDropshippingSettingsForm, type AliExpressDropshippingSettingsFormProps, type AliExpressImportResultDto, type AliExpressPluginConfig, type AliExpressProductDto, type AliExpressProductSummaryDto, type AliExpressProductVariantDto, AliExpressReauthReason, type AliExpressTestConnectionResult, SECRET_SET_SENTINEL, type SecretSetSentinel };
package/dist/index.js ADDED
@@ -0,0 +1,265 @@
1
+ "use client";
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ AliExpressDropshippingSettingsForm: () => AliExpressDropshippingSettingsForm,
35
+ AliExpressReauthReason: () => AliExpressReauthReason,
36
+ SECRET_SET_SENTINEL: () => SECRET_SET_SENTINEL
37
+ });
38
+ module.exports = __toCommonJS(src_exports);
39
+
40
+ // src/settings-form.tsx
41
+ var React = __toESM(require("react"));
42
+
43
+ // src/types.ts
44
+ var SECRET_SET_SENTINEL = "__SECRET_SET__";
45
+ var AliExpressReauthReason = /* @__PURE__ */ ((AliExpressReauthReason2) => {
46
+ AliExpressReauthReason2["MissingAccessToken"] = "missing_access_token";
47
+ AliExpressReauthReason2["IllegalAccessToken"] = "illegal_access_token";
48
+ AliExpressReauthReason2["RefreshFailed"] = "refresh_failed";
49
+ AliExpressReauthReason2["Disconnected"] = "disconnected";
50
+ return AliExpressReauthReason2;
51
+ })(AliExpressReauthReason || {});
52
+
53
+ // src/settings-form.tsx
54
+ var import_jsx_runtime = require("react/jsx-runtime");
55
+ function AliExpressDropshippingSettingsForm(props) {
56
+ const {
57
+ initialConfig,
58
+ initialStatus,
59
+ onSaveConfig,
60
+ onConnect,
61
+ onDisconnect,
62
+ onTestConnection
63
+ } = props;
64
+ const [appKey, setAppKey] = React.useState(
65
+ initialConfig.appKey ?? ""
66
+ );
67
+ const secretPreset = initialConfig.appSecret === SECRET_SET_SENTINEL || typeof initialConfig.appSecret === "string" && initialConfig.appSecret.length > 0;
68
+ const [appSecret, setAppSecret] = React.useState("");
69
+ const [secretDirty, setSecretDirty] = React.useState(false);
70
+ const [saveState, setSaveState] = React.useState("idle");
71
+ const [saveError, setSaveError] = React.useState(null);
72
+ const [testState, setTestState] = React.useState({ kind: "idle" });
73
+ const [testEverSucceeded, setTestEverSucceeded] = React.useState(
74
+ initialStatus.connected
75
+ );
76
+ const [busyOAuth, setBusyOAuth] = React.useState(false);
77
+ const hasStoredSecret = secretPreset || secretDirty;
78
+ const canTest = appKey.trim().length > 0 && hasStoredSecret;
79
+ const canConnect = testEverSucceeded && !initialStatus.connected;
80
+ const canDisconnect = initialStatus.connected;
81
+ const handleSave = React.useCallback(async () => {
82
+ setSaveState("saving");
83
+ setSaveError(null);
84
+ try {
85
+ const patch = {};
86
+ if (appKey.trim() !== (initialConfig.appKey ?? "")) {
87
+ patch.appKey = appKey.trim();
88
+ }
89
+ if (secretDirty && appSecret.length > 0) {
90
+ patch.appSecret = appSecret;
91
+ }
92
+ await onSaveConfig(patch);
93
+ setSaveState("saved");
94
+ setSecretDirty(false);
95
+ setAppSecret("");
96
+ } catch (err) {
97
+ setSaveState("error");
98
+ setSaveError(err instanceof Error ? err.message : "Save failed");
99
+ }
100
+ }, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig]);
101
+ const handleTest = React.useCallback(async () => {
102
+ setTestState({ kind: "running" });
103
+ try {
104
+ const result = await onTestConnection();
105
+ if (result.ok) {
106
+ setTestState({ kind: "ok", categoryCount: result.categoryCount });
107
+ setTestEverSucceeded(true);
108
+ } else {
109
+ setTestState({ kind: "err", code: result.code, msg: result.msg });
110
+ }
111
+ } catch (err) {
112
+ setTestState({
113
+ kind: "err",
114
+ code: "UNKNOWN",
115
+ msg: err instanceof Error ? err.message : "Test failed"
116
+ });
117
+ }
118
+ }, [onTestConnection]);
119
+ const handleConnect = React.useCallback(async () => {
120
+ setBusyOAuth(true);
121
+ try {
122
+ await onConnect();
123
+ } finally {
124
+ setBusyOAuth(false);
125
+ }
126
+ }, [onConnect]);
127
+ const handleDisconnect = React.useCallback(async () => {
128
+ setBusyOAuth(true);
129
+ try {
130
+ await onDisconnect();
131
+ } finally {
132
+ setBusyOAuth(false);
133
+ }
134
+ }, [onDisconnect]);
135
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "aliexpress-dropshipping-settings", children: [
136
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-credentials-heading", children: [
137
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-credentials-heading", children: "Developer app credentials" }),
138
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Enter your AliExpress Open Platform app credentials. These are stored encrypted at rest and used to sign every AliExpress API call for this store." }),
139
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
140
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "App Key" }),
141
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
142
+ "input",
143
+ {
144
+ type: "text",
145
+ value: appKey,
146
+ onChange: (e) => setAppKey(e.target.value),
147
+ autoComplete: "off",
148
+ spellCheck: false
149
+ }
150
+ )
151
+ ] }),
152
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
153
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "App Secret" }),
154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
155
+ "input",
156
+ {
157
+ type: "password",
158
+ value: appSecret,
159
+ placeholder: secretPreset ? "(secret set - leave blank to keep)" : "",
160
+ onChange: (e) => {
161
+ setAppSecret(e.target.value);
162
+ setSecretDirty(true);
163
+ },
164
+ autoComplete: "off",
165
+ spellCheck: false
166
+ }
167
+ )
168
+ ] }),
169
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "actions", children: [
170
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
171
+ "button",
172
+ {
173
+ type: "button",
174
+ onClick: handleSave,
175
+ disabled: saveState === "saving" || appKey.trim().length === 0,
176
+ children: saveState === "saving" ? "Saving..." : "Save credentials"
177
+ }
178
+ ),
179
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
180
+ "button",
181
+ {
182
+ type: "button",
183
+ onClick: handleTest,
184
+ disabled: !canTest || testState.kind === "running",
185
+ children: testState.kind === "running" ? "Testing..." : "Test connection"
186
+ }
187
+ )
188
+ ] }),
189
+ saveState === "saved" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "status", children: "Saved." }) : null,
190
+ saveState === "error" && saveError ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", children: [
191
+ "Save failed: ",
192
+ saveError
193
+ ] }) : null,
194
+ testState.kind === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "status", children: [
195
+ "Connected to AliExpress. Found ",
196
+ testState.categoryCount,
197
+ " categories."
198
+ ] }) : null,
199
+ testState.kind === "err" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", children: [
200
+ "Test failed (",
201
+ testState.code,
202
+ "): ",
203
+ testState.msg
204
+ ] }) : null
205
+ ] }),
206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-oauth-heading", children: [
207
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-oauth-heading", children: "Merchant account connection" }),
208
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Connect a specific AliExpress seller account to enable product import into this store. This is separate from the developer app credentials above." }),
209
+ initialStatus.needsReauth ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: "reauth-banner", children: "Re-authentication required. Please reconnect your AliExpress account." }) : null,
210
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "status-card", children: [
211
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
212
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Status:" }),
213
+ " ",
214
+ initialStatus.connected ? "Connected" : "Not connected"
215
+ ] }),
216
+ initialStatus.sellerId ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Seller ID:" }),
218
+ " ",
219
+ initialStatus.sellerId
220
+ ] }) : null,
221
+ initialStatus.lastSuccessfulCallAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
222
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Last successful call:" }),
223
+ " ",
224
+ initialStatus.lastSuccessfulCallAt
225
+ ] }) : null
226
+ ] }),
227
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "actions", children: [
228
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
229
+ "button",
230
+ {
231
+ type: "button",
232
+ onClick: handleConnect,
233
+ disabled: !canConnect || busyOAuth,
234
+ children: busyOAuth ? "Working..." : "Connect merchant AliExpress account"
235
+ }
236
+ ),
237
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
238
+ "button",
239
+ {
240
+ type: "button",
241
+ onClick: handleDisconnect,
242
+ disabled: !canDisconnect || busyOAuth,
243
+ children: "Disconnect"
244
+ }
245
+ )
246
+ ] }),
247
+ !testEverSucceeded ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
248
+ "Run ",
249
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: "Test connection" }),
250
+ " once with your AppKey/AppSecret before connecting a merchant account."
251
+ ] }) : null
252
+ ] }),
253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-coming-soon-heading", children: [
254
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-coming-soon-heading", children: "Order forwarding" }),
255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Coming soon. Automatic order forwarding to AliExpress requires our app to be approved out of Test status by AliExpress. Product import and browsing work today." })
256
+ ] })
257
+ ] });
258
+ }
259
+ // Annotate the CommonJS export names for ESM import in node:
260
+ 0 && (module.exports = {
261
+ AliExpressDropshippingSettingsForm,
262
+ AliExpressReauthReason,
263
+ SECRET_SET_SENTINEL
264
+ });
265
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/settings-form.tsx","../src/types.ts"],"sourcesContent":["// Admin settings form (Class B - the only React surface).\nexport {\n AliExpressDropshippingSettingsForm,\n type AliExpressDropshippingSettingsFormProps,\n} from './settings-form'\n\n// Shared wire types - kept in sync with the medusa-backend-orchestrator DTOs.\nexport {\n SECRET_SET_SENTINEL,\n AliExpressReauthReason,\n} from './types'\nexport type {\n SecretSetSentinel,\n AliExpressPluginConfig,\n AliExpressCategoryDto,\n AliExpressProductSummaryDto,\n AliExpressProductDto,\n AliExpressProductVariantDto,\n AliExpressImportResultDto,\n AliExpressConnectionStatusDto,\n AliExpressTestConnectionResult,\n} from './types'\n","/**\n * Admin settings form for the AliExpress Dropshipping integration.\n *\n * Class B: this component owns the UI and talks to the Medusa Store API\n * under `/store/aliexpress-dropshipping/*`. It does NOT embed any\n * AliExpress SDK, does not sign requests, and does not touch OAuth\n * tokens directly - the backend does all of that.\n *\n * The component is intentionally dependency-light (no external UI kit,\n * no @tanstack/react-query peer) so the admin bundle can drop it in\n * without extra peer dep resolution.\n */\n\nimport * as React from 'react'\nimport type {\n AliExpressPluginConfig,\n AliExpressConnectionStatusDto,\n AliExpressTestConnectionResult,\n} from './types'\nimport { SECRET_SET_SENTINEL } from './types'\n\nexport interface AliExpressDropshippingSettingsFormProps {\n /** Current config for this store (fetched by the parent server component). */\n initialConfig: AliExpressPluginConfig\n /** Current connection status (from `GET /status`). */\n initialStatus: AliExpressConnectionStatusDto\n /**\n * Persist non-secret + optionally new secret values. The parent maps\n * this onto `PATCH /store/aliexpress-dropshipping/config` (or\n * equivalent) and then re-fetches config on success.\n *\n * `appSecret` is only sent when the merchant actually typed a new\n * value; if they leave the field untouched, this method receives\n * `undefined` for that key so the backend keeps the existing secret.\n */\n onSaveConfig: (patch: {\n appKey?: string\n appSecret?: string\n enabled?: boolean\n }) => Promise<void>\n /** Kick off `POST /oauth/start` and redirect to the returned URL. */\n onConnect: () => Promise<void>\n /** Kick off `POST /oauth/disconnect` and clear merchant credentials. */\n onDisconnect: () => Promise<void>\n /** Call `POST /test-connection` and return the result. */\n onTestConnection: () => Promise<AliExpressTestConnectionResult>\n}\n\ntype SaveState = 'idle' | 'saving' | 'saved' | 'error'\ntype TestState =\n | { kind: 'idle' }\n | { kind: 'running' }\n | { kind: 'ok'; categoryCount: number }\n | { kind: 'err'; code: string; msg: string }\n\n/**\n * Amboras admin settings surface for AliExpress Dropshipping.\n * Renders AppKey + AppSecret inputs, Test / Connect / Disconnect\n * buttons, status card, and a \"Coming soon\" order-forwarding block.\n */\nexport function AliExpressDropshippingSettingsForm(\n props: AliExpressDropshippingSettingsFormProps,\n): React.ReactElement {\n const {\n initialConfig,\n initialStatus,\n onSaveConfig,\n onConnect,\n onDisconnect,\n onTestConnection,\n } = props\n\n const [appKey, setAppKey] = React.useState<string>(\n initialConfig.appKey ?? '',\n )\n const secretPreset =\n initialConfig.appSecret === SECRET_SET_SENTINEL ||\n (typeof initialConfig.appSecret === 'string' &&\n initialConfig.appSecret.length > 0)\n const [appSecret, setAppSecret] = React.useState<string>('')\n const [secretDirty, setSecretDirty] = React.useState<boolean>(false)\n\n const [saveState, setSaveState] = React.useState<SaveState>('idle')\n const [saveError, setSaveError] = React.useState<string | null>(null)\n\n const [testState, setTestState] = React.useState<TestState>({ kind: 'idle' })\n const [testEverSucceeded, setTestEverSucceeded] = React.useState<boolean>(\n initialStatus.connected,\n )\n\n const [busyOAuth, setBusyOAuth] = React.useState<boolean>(false)\n\n const hasStoredSecret = secretPreset || secretDirty\n const canTest = appKey.trim().length > 0 && hasStoredSecret\n const canConnect = testEverSucceeded && !initialStatus.connected\n const canDisconnect = initialStatus.connected\n\n const handleSave = React.useCallback(async () => {\n setSaveState('saving')\n setSaveError(null)\n try {\n const patch: {\n appKey?: string\n appSecret?: string\n enabled?: boolean\n } = {}\n if (appKey.trim() !== (initialConfig.appKey ?? '')) {\n patch.appKey = appKey.trim()\n }\n if (secretDirty && appSecret.length > 0) {\n patch.appSecret = appSecret\n }\n await onSaveConfig(patch)\n setSaveState('saved')\n setSecretDirty(false)\n setAppSecret('')\n } catch (err) {\n setSaveState('error')\n setSaveError(err instanceof Error ? err.message : 'Save failed')\n }\n }, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig])\n\n const handleTest = React.useCallback(async () => {\n setTestState({ kind: 'running' })\n try {\n const result = await onTestConnection()\n if (result.ok) {\n setTestState({ kind: 'ok', categoryCount: result.categoryCount })\n setTestEverSucceeded(true)\n } else {\n setTestState({ kind: 'err', code: result.code, msg: result.msg })\n }\n } catch (err) {\n setTestState({\n kind: 'err',\n code: 'UNKNOWN',\n msg: err instanceof Error ? err.message : 'Test failed',\n })\n }\n }, [onTestConnection])\n\n const handleConnect = React.useCallback(async () => {\n setBusyOAuth(true)\n try {\n await onConnect()\n } finally {\n setBusyOAuth(false)\n }\n }, [onConnect])\n\n const handleDisconnect = React.useCallback(async () => {\n setBusyOAuth(true)\n try {\n await onDisconnect()\n } finally {\n setBusyOAuth(false)\n }\n }, [onDisconnect])\n\n return (\n <div className=\"aliexpress-dropshipping-settings\">\n <section aria-labelledby=\"ae-credentials-heading\">\n <h2 id=\"ae-credentials-heading\">Developer app credentials</h2>\n <p>\n Enter your AliExpress Open Platform app credentials. These are\n stored encrypted at rest and used to sign every AliExpress API\n call for this store.\n </p>\n\n <label>\n <span>App Key</span>\n <input\n type=\"text\"\n value={appKey}\n onChange={(e) => setAppKey(e.target.value)}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n\n <label>\n <span>App Secret</span>\n <input\n type=\"password\"\n value={appSecret}\n placeholder={secretPreset ? '(secret set - leave blank to keep)' : ''}\n onChange={(e) => {\n setAppSecret(e.target.value)\n setSecretDirty(true)\n }}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n\n <div className=\"actions\">\n <button\n type=\"button\"\n onClick={handleSave}\n disabled={saveState === 'saving' || appKey.trim().length === 0}\n >\n {saveState === 'saving' ? 'Saving...' : 'Save credentials'}\n </button>\n <button\n type=\"button\"\n onClick={handleTest}\n disabled={!canTest || testState.kind === 'running'}\n >\n {testState.kind === 'running' ? 'Testing...' : 'Test connection'}\n </button>\n </div>\n\n {saveState === 'saved' ? <p role=\"status\">Saved.</p> : null}\n {saveState === 'error' && saveError ? (\n <p role=\"alert\">Save failed: {saveError}</p>\n ) : null}\n\n {testState.kind === 'ok' ? (\n <p role=\"status\">\n Connected to AliExpress. Found {testState.categoryCount} categories.\n </p>\n ) : null}\n {testState.kind === 'err' ? (\n <p role=\"alert\">\n Test failed ({testState.code}): {testState.msg}\n </p>\n ) : null}\n </section>\n\n <section aria-labelledby=\"ae-oauth-heading\">\n <h2 id=\"ae-oauth-heading\">Merchant account connection</h2>\n <p>\n Connect a specific AliExpress seller account to enable product\n import into this store. This is separate from the developer app\n credentials above.\n </p>\n\n {initialStatus.needsReauth ? (\n <p role=\"alert\" className=\"reauth-banner\">\n Re-authentication required. Please reconnect your AliExpress account.\n </p>\n ) : null}\n\n <div className=\"status-card\">\n <div>\n <strong>Status:</strong>{' '}\n {initialStatus.connected ? 'Connected' : 'Not connected'}\n </div>\n {initialStatus.sellerId ? (\n <div>\n <strong>Seller ID:</strong> {initialStatus.sellerId}\n </div>\n ) : null}\n {initialStatus.lastSuccessfulCallAt ? (\n <div>\n <strong>Last successful call:</strong>{' '}\n {initialStatus.lastSuccessfulCallAt}\n </div>\n ) : null}\n </div>\n\n <div className=\"actions\">\n <button\n type=\"button\"\n onClick={handleConnect}\n disabled={!canConnect || busyOAuth}\n >\n {busyOAuth ? 'Working...' : 'Connect merchant AliExpress account'}\n </button>\n <button\n type=\"button\"\n onClick={handleDisconnect}\n disabled={!canDisconnect || busyOAuth}\n >\n Disconnect\n </button>\n </div>\n\n {!testEverSucceeded ? (\n <p>\n Run <em>Test connection</em> once with your AppKey/AppSecret before\n connecting a merchant account.\n </p>\n ) : null}\n </section>\n\n <section aria-labelledby=\"ae-coming-soon-heading\">\n <h2 id=\"ae-coming-soon-heading\">Order forwarding</h2>\n <p>\n Coming soon. Automatic order forwarding to AliExpress requires\n our app to be approved out of Test status by AliExpress. Product\n import and browsing work today.\n </p>\n </section>\n </div>\n )\n}\n\nexport default AliExpressDropshippingSettingsForm\n","/**\n * Public types for @amboras-dev/aliexpress-dropshipping.\n *\n * These are the single source of truth for the wire shape between the\n * Amboras admin settings form and the medusa-backend-orchestrator\n * Store API routes under `/store/aliexpress-dropshipping/*`. The DTO\n * files on the medusa side must stay byte-compatible with these.\n */\n\n/**\n * Sentinel returned in place of a stored secret when the settings form\n * reads back current config. Matches the pattern used by meta-ads and\n * pinterest so the admin never sees the plaintext secret after write.\n */\nexport const SECRET_SET_SENTINEL = '__SECRET_SET__' as const\nexport type SecretSetSentinel = typeof SECRET_SET_SENTINEL\n\n/**\n * Per-store AliExpress plugin configuration.\n *\n * - `appKey` / `appSecret` are per-store developer app credentials\n * supplied by the merchant. The admin form receives\n * `SECRET_SET_SENTINEL` for `appSecret` on read, and only sends a\n * real value on user edit.\n * - `connectedSellerId` is populated after the merchant completes the\n * OAuth flow to `/rest/auth/token/create`.\n * - `needsReauth` is flipped by the backend runtime detector when it\n * sees `MissingParameter access_token` or `IllegalAccessToken`\n * sub-codes on any envelope.\n * - `lastSuccessfulCallAt` is an ISO-8601 timestamp for the status card.\n */\nexport interface AliExpressPluginConfig {\n enabled: boolean\n appKey: string | null\n appSecret: string | SecretSetSentinel | null\n connectedSellerId: string | null\n needsReauth: boolean\n lastSuccessfulCallAt: string | null\n}\n\n/**\n * Reasons the backend surfaces when a merchant token becomes invalid.\n * Kept narrow so the admin banner can render a specific message.\n */\nexport enum AliExpressReauthReason {\n MissingAccessToken = 'missing_access_token',\n IllegalAccessToken = 'illegal_access_token',\n RefreshFailed = 'refresh_failed',\n Disconnected = 'disconnected',\n}\n\n/**\n * Category node returned by `aliexpress.ds.category.get`. The API\n * returns a flat list; the admin renders it as a tree by walking\n * `parentCategoryId`.\n */\nexport interface AliExpressCategoryDto {\n categoryId: string\n categoryName: string\n parentCategoryId: string | null\n}\n\n/**\n * Product summary shape returned by `aliexpress.ds.recommend.feed.get`.\n * Used by the \"browse products\" admin surface.\n */\nexport interface AliExpressProductSummaryDto {\n productId: string\n title: string\n imageUrl: string | null\n minPrice: number | null\n maxPrice: number | null\n currency: string | null\n productDetailUrl: string | null\n}\n\n/**\n * Full product shape returned by `aliexpress.ds.product.get`. Consumed\n * by the medusa-side mapper `aliexpressProductToMedusaDraft`.\n */\nexport interface AliExpressProductDto {\n productId: string\n title: string\n description: string | null\n images: string[]\n variants: AliExpressProductVariantDto[]\n weightGrams: number | null\n sourceUrl: string | null\n}\n\nexport interface AliExpressProductVariantDto {\n skuId: string\n title: string | null\n price: number\n currency: string\n stock: number | null\n attributes: Record<string, string>\n}\n\n/**\n * Return shape from `POST /store/aliexpress-dropshipping/products/:id/import`.\n */\nexport interface AliExpressImportResultDto {\n medusaProductId: string\n sourceProductId: string\n importedVariants: number\n}\n\n/**\n * Return shape from `GET /store/aliexpress-dropshipping/status` - drives\n * the admin status card.\n */\nexport interface AliExpressConnectionStatusDto {\n connected: boolean\n sellerId: string | null\n needsReauth: boolean\n reauthReason: AliExpressReauthReason | null\n lastSuccessfulCallAt: string | null\n}\n\n/**\n * Return shape from `POST /store/aliexpress-dropshipping/test-connection`.\n */\nexport type AliExpressTestConnectionResult =\n | { ok: true; categoryCount: number }\n | { ok: false; code: string; msg: string }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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F;AAAA,KACF;AAEJ;","names":["AliExpressReauthReason"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,227 @@
1
+ "use client";
2
+
3
+ // src/settings-form.tsx
4
+ import * as React from "react";
5
+
6
+ // src/types.ts
7
+ var SECRET_SET_SENTINEL = "__SECRET_SET__";
8
+ var AliExpressReauthReason = /* @__PURE__ */ ((AliExpressReauthReason2) => {
9
+ AliExpressReauthReason2["MissingAccessToken"] = "missing_access_token";
10
+ AliExpressReauthReason2["IllegalAccessToken"] = "illegal_access_token";
11
+ AliExpressReauthReason2["RefreshFailed"] = "refresh_failed";
12
+ AliExpressReauthReason2["Disconnected"] = "disconnected";
13
+ return AliExpressReauthReason2;
14
+ })(AliExpressReauthReason || {});
15
+
16
+ // src/settings-form.tsx
17
+ import { jsx, jsxs } from "react/jsx-runtime";
18
+ function AliExpressDropshippingSettingsForm(props) {
19
+ const {
20
+ initialConfig,
21
+ initialStatus,
22
+ onSaveConfig,
23
+ onConnect,
24
+ onDisconnect,
25
+ onTestConnection
26
+ } = props;
27
+ const [appKey, setAppKey] = React.useState(
28
+ initialConfig.appKey ?? ""
29
+ );
30
+ const secretPreset = initialConfig.appSecret === SECRET_SET_SENTINEL || typeof initialConfig.appSecret === "string" && initialConfig.appSecret.length > 0;
31
+ const [appSecret, setAppSecret] = React.useState("");
32
+ const [secretDirty, setSecretDirty] = React.useState(false);
33
+ const [saveState, setSaveState] = React.useState("idle");
34
+ const [saveError, setSaveError] = React.useState(null);
35
+ const [testState, setTestState] = React.useState({ kind: "idle" });
36
+ const [testEverSucceeded, setTestEverSucceeded] = React.useState(
37
+ initialStatus.connected
38
+ );
39
+ const [busyOAuth, setBusyOAuth] = React.useState(false);
40
+ const hasStoredSecret = secretPreset || secretDirty;
41
+ const canTest = appKey.trim().length > 0 && hasStoredSecret;
42
+ const canConnect = testEverSucceeded && !initialStatus.connected;
43
+ const canDisconnect = initialStatus.connected;
44
+ const handleSave = React.useCallback(async () => {
45
+ setSaveState("saving");
46
+ setSaveError(null);
47
+ try {
48
+ const patch = {};
49
+ if (appKey.trim() !== (initialConfig.appKey ?? "")) {
50
+ patch.appKey = appKey.trim();
51
+ }
52
+ if (secretDirty && appSecret.length > 0) {
53
+ patch.appSecret = appSecret;
54
+ }
55
+ await onSaveConfig(patch);
56
+ setSaveState("saved");
57
+ setSecretDirty(false);
58
+ setAppSecret("");
59
+ } catch (err) {
60
+ setSaveState("error");
61
+ setSaveError(err instanceof Error ? err.message : "Save failed");
62
+ }
63
+ }, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig]);
64
+ const handleTest = React.useCallback(async () => {
65
+ setTestState({ kind: "running" });
66
+ try {
67
+ const result = await onTestConnection();
68
+ if (result.ok) {
69
+ setTestState({ kind: "ok", categoryCount: result.categoryCount });
70
+ setTestEverSucceeded(true);
71
+ } else {
72
+ setTestState({ kind: "err", code: result.code, msg: result.msg });
73
+ }
74
+ } catch (err) {
75
+ setTestState({
76
+ kind: "err",
77
+ code: "UNKNOWN",
78
+ msg: err instanceof Error ? err.message : "Test failed"
79
+ });
80
+ }
81
+ }, [onTestConnection]);
82
+ const handleConnect = React.useCallback(async () => {
83
+ setBusyOAuth(true);
84
+ try {
85
+ await onConnect();
86
+ } finally {
87
+ setBusyOAuth(false);
88
+ }
89
+ }, [onConnect]);
90
+ const handleDisconnect = React.useCallback(async () => {
91
+ setBusyOAuth(true);
92
+ try {
93
+ await onDisconnect();
94
+ } finally {
95
+ setBusyOAuth(false);
96
+ }
97
+ }, [onDisconnect]);
98
+ return /* @__PURE__ */ jsxs("div", { className: "aliexpress-dropshipping-settings", children: [
99
+ /* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-credentials-heading", children: [
100
+ /* @__PURE__ */ jsx("h2", { id: "ae-credentials-heading", children: "Developer app credentials" }),
101
+ /* @__PURE__ */ jsx("p", { children: "Enter your AliExpress Open Platform app credentials. These are stored encrypted at rest and used to sign every AliExpress API call for this store." }),
102
+ /* @__PURE__ */ jsxs("label", { children: [
103
+ /* @__PURE__ */ jsx("span", { children: "App Key" }),
104
+ /* @__PURE__ */ jsx(
105
+ "input",
106
+ {
107
+ type: "text",
108
+ value: appKey,
109
+ onChange: (e) => setAppKey(e.target.value),
110
+ autoComplete: "off",
111
+ spellCheck: false
112
+ }
113
+ )
114
+ ] }),
115
+ /* @__PURE__ */ jsxs("label", { children: [
116
+ /* @__PURE__ */ jsx("span", { children: "App Secret" }),
117
+ /* @__PURE__ */ jsx(
118
+ "input",
119
+ {
120
+ type: "password",
121
+ value: appSecret,
122
+ placeholder: secretPreset ? "(secret set - leave blank to keep)" : "",
123
+ onChange: (e) => {
124
+ setAppSecret(e.target.value);
125
+ setSecretDirty(true);
126
+ },
127
+ autoComplete: "off",
128
+ spellCheck: false
129
+ }
130
+ )
131
+ ] }),
132
+ /* @__PURE__ */ jsxs("div", { className: "actions", children: [
133
+ /* @__PURE__ */ jsx(
134
+ "button",
135
+ {
136
+ type: "button",
137
+ onClick: handleSave,
138
+ disabled: saveState === "saving" || appKey.trim().length === 0,
139
+ children: saveState === "saving" ? "Saving..." : "Save credentials"
140
+ }
141
+ ),
142
+ /* @__PURE__ */ jsx(
143
+ "button",
144
+ {
145
+ type: "button",
146
+ onClick: handleTest,
147
+ disabled: !canTest || testState.kind === "running",
148
+ children: testState.kind === "running" ? "Testing..." : "Test connection"
149
+ }
150
+ )
151
+ ] }),
152
+ saveState === "saved" ? /* @__PURE__ */ jsx("p", { role: "status", children: "Saved." }) : null,
153
+ saveState === "error" && saveError ? /* @__PURE__ */ jsxs("p", { role: "alert", children: [
154
+ "Save failed: ",
155
+ saveError
156
+ ] }) : null,
157
+ testState.kind === "ok" ? /* @__PURE__ */ jsxs("p", { role: "status", children: [
158
+ "Connected to AliExpress. Found ",
159
+ testState.categoryCount,
160
+ " categories."
161
+ ] }) : null,
162
+ testState.kind === "err" ? /* @__PURE__ */ jsxs("p", { role: "alert", children: [
163
+ "Test failed (",
164
+ testState.code,
165
+ "): ",
166
+ testState.msg
167
+ ] }) : null
168
+ ] }),
169
+ /* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-oauth-heading", children: [
170
+ /* @__PURE__ */ jsx("h2", { id: "ae-oauth-heading", children: "Merchant account connection" }),
171
+ /* @__PURE__ */ jsx("p", { children: "Connect a specific AliExpress seller account to enable product import into this store. This is separate from the developer app credentials above." }),
172
+ initialStatus.needsReauth ? /* @__PURE__ */ jsx("p", { role: "alert", className: "reauth-banner", children: "Re-authentication required. Please reconnect your AliExpress account." }) : null,
173
+ /* @__PURE__ */ jsxs("div", { className: "status-card", children: [
174
+ /* @__PURE__ */ jsxs("div", { children: [
175
+ /* @__PURE__ */ jsx("strong", { children: "Status:" }),
176
+ " ",
177
+ initialStatus.connected ? "Connected" : "Not connected"
178
+ ] }),
179
+ initialStatus.sellerId ? /* @__PURE__ */ jsxs("div", { children: [
180
+ /* @__PURE__ */ jsx("strong", { children: "Seller ID:" }),
181
+ " ",
182
+ initialStatus.sellerId
183
+ ] }) : null,
184
+ initialStatus.lastSuccessfulCallAt ? /* @__PURE__ */ jsxs("div", { children: [
185
+ /* @__PURE__ */ jsx("strong", { children: "Last successful call:" }),
186
+ " ",
187
+ initialStatus.lastSuccessfulCallAt
188
+ ] }) : null
189
+ ] }),
190
+ /* @__PURE__ */ jsxs("div", { className: "actions", children: [
191
+ /* @__PURE__ */ jsx(
192
+ "button",
193
+ {
194
+ type: "button",
195
+ onClick: handleConnect,
196
+ disabled: !canConnect || busyOAuth,
197
+ children: busyOAuth ? "Working..." : "Connect merchant AliExpress account"
198
+ }
199
+ ),
200
+ /* @__PURE__ */ jsx(
201
+ "button",
202
+ {
203
+ type: "button",
204
+ onClick: handleDisconnect,
205
+ disabled: !canDisconnect || busyOAuth,
206
+ children: "Disconnect"
207
+ }
208
+ )
209
+ ] }),
210
+ !testEverSucceeded ? /* @__PURE__ */ jsxs("p", { children: [
211
+ "Run ",
212
+ /* @__PURE__ */ jsx("em", { children: "Test connection" }),
213
+ " once with your AppKey/AppSecret before connecting a merchant account."
214
+ ] }) : null
215
+ ] }),
216
+ /* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-coming-soon-heading", children: [
217
+ /* @__PURE__ */ jsx("h2", { id: "ae-coming-soon-heading", children: "Order forwarding" }),
218
+ /* @__PURE__ */ jsx("p", { children: "Coming soon. Automatic order forwarding to AliExpress requires our app to be approved out of Test status by AliExpress. Product import and browsing work today." })
219
+ ] })
220
+ ] });
221
+ }
222
+ export {
223
+ AliExpressDropshippingSettingsForm,
224
+ AliExpressReauthReason,
225
+ SECRET_SET_SENTINEL
226
+ };
227
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/settings-form.tsx","../src/types.ts"],"sourcesContent":["/**\n * Admin settings form for the AliExpress Dropshipping integration.\n *\n * Class B: this component owns the UI and talks to the Medusa Store API\n * under `/store/aliexpress-dropshipping/*`. It does NOT embed any\n * AliExpress SDK, does not sign requests, and does not touch OAuth\n * tokens directly - the backend does all of that.\n *\n * The component is intentionally dependency-light (no external UI kit,\n * no @tanstack/react-query peer) so the admin bundle can drop it in\n * without extra peer dep resolution.\n */\n\nimport * as React from 'react'\nimport type {\n AliExpressPluginConfig,\n AliExpressConnectionStatusDto,\n AliExpressTestConnectionResult,\n} from './types'\nimport { SECRET_SET_SENTINEL } from './types'\n\nexport interface AliExpressDropshippingSettingsFormProps {\n /** Current config for this store (fetched by the parent server component). */\n initialConfig: AliExpressPluginConfig\n /** Current connection status (from `GET /status`). */\n initialStatus: AliExpressConnectionStatusDto\n /**\n * Persist non-secret + optionally new secret values. The parent maps\n * this onto `PATCH /store/aliexpress-dropshipping/config` (or\n * equivalent) and then re-fetches config on success.\n *\n * `appSecret` is only sent when the merchant actually typed a new\n * value; if they leave the field untouched, this method receives\n * `undefined` for that key so the backend keeps the existing secret.\n */\n onSaveConfig: (patch: {\n appKey?: string\n appSecret?: string\n enabled?: boolean\n }) => Promise<void>\n /** Kick off `POST /oauth/start` and redirect to the returned URL. */\n onConnect: () => Promise<void>\n /** Kick off `POST /oauth/disconnect` and clear merchant credentials. */\n onDisconnect: () => Promise<void>\n /** Call `POST /test-connection` and return the result. */\n onTestConnection: () => Promise<AliExpressTestConnectionResult>\n}\n\ntype SaveState = 'idle' | 'saving' | 'saved' | 'error'\ntype TestState =\n | { kind: 'idle' }\n | { kind: 'running' }\n | { kind: 'ok'; categoryCount: number }\n | { kind: 'err'; code: string; msg: string }\n\n/**\n * Amboras admin settings surface for AliExpress Dropshipping.\n * Renders AppKey + AppSecret inputs, Test / Connect / Disconnect\n * buttons, status card, and a \"Coming soon\" order-forwarding block.\n */\nexport function AliExpressDropshippingSettingsForm(\n props: AliExpressDropshippingSettingsFormProps,\n): React.ReactElement {\n const {\n initialConfig,\n initialStatus,\n onSaveConfig,\n onConnect,\n onDisconnect,\n onTestConnection,\n } = props\n\n const [appKey, setAppKey] = React.useState<string>(\n initialConfig.appKey ?? '',\n )\n const secretPreset =\n initialConfig.appSecret === SECRET_SET_SENTINEL ||\n (typeof initialConfig.appSecret === 'string' &&\n initialConfig.appSecret.length > 0)\n const [appSecret, setAppSecret] = React.useState<string>('')\n const [secretDirty, setSecretDirty] = React.useState<boolean>(false)\n\n const [saveState, setSaveState] = React.useState<SaveState>('idle')\n const [saveError, setSaveError] = React.useState<string | null>(null)\n\n const [testState, setTestState] = React.useState<TestState>({ kind: 'idle' })\n const [testEverSucceeded, setTestEverSucceeded] = React.useState<boolean>(\n initialStatus.connected,\n )\n\n const [busyOAuth, setBusyOAuth] = React.useState<boolean>(false)\n\n const hasStoredSecret = secretPreset || secretDirty\n const canTest = appKey.trim().length > 0 && hasStoredSecret\n const canConnect = testEverSucceeded && !initialStatus.connected\n const canDisconnect = initialStatus.connected\n\n const handleSave = React.useCallback(async () => {\n setSaveState('saving')\n setSaveError(null)\n try {\n const patch: {\n appKey?: string\n appSecret?: string\n enabled?: boolean\n } = {}\n if (appKey.trim() !== (initialConfig.appKey ?? '')) {\n patch.appKey = appKey.trim()\n }\n if (secretDirty && appSecret.length > 0) {\n patch.appSecret = appSecret\n }\n await onSaveConfig(patch)\n setSaveState('saved')\n setSecretDirty(false)\n setAppSecret('')\n } catch (err) {\n setSaveState('error')\n setSaveError(err instanceof Error ? err.message : 'Save failed')\n }\n }, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig])\n\n const handleTest = React.useCallback(async () => {\n setTestState({ kind: 'running' })\n try {\n const result = await onTestConnection()\n if (result.ok) {\n setTestState({ kind: 'ok', categoryCount: result.categoryCount })\n setTestEverSucceeded(true)\n } else {\n setTestState({ kind: 'err', code: result.code, msg: result.msg })\n }\n } catch (err) {\n setTestState({\n kind: 'err',\n code: 'UNKNOWN',\n msg: err instanceof Error ? err.message : 'Test failed',\n })\n }\n }, [onTestConnection])\n\n const handleConnect = React.useCallback(async () => {\n setBusyOAuth(true)\n try {\n await onConnect()\n } finally {\n setBusyOAuth(false)\n }\n }, [onConnect])\n\n const handleDisconnect = React.useCallback(async () => {\n setBusyOAuth(true)\n try {\n await onDisconnect()\n } finally {\n setBusyOAuth(false)\n }\n }, [onDisconnect])\n\n return (\n <div className=\"aliexpress-dropshipping-settings\">\n <section aria-labelledby=\"ae-credentials-heading\">\n <h2 id=\"ae-credentials-heading\">Developer app credentials</h2>\n <p>\n Enter your AliExpress Open Platform app credentials. These are\n stored encrypted at rest and used to sign every AliExpress API\n call for this store.\n </p>\n\n <label>\n <span>App Key</span>\n <input\n type=\"text\"\n value={appKey}\n onChange={(e) => setAppKey(e.target.value)}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n\n <label>\n <span>App Secret</span>\n <input\n type=\"password\"\n value={appSecret}\n placeholder={secretPreset ? '(secret set - leave blank to keep)' : ''}\n onChange={(e) => {\n setAppSecret(e.target.value)\n setSecretDirty(true)\n }}\n autoComplete=\"off\"\n spellCheck={false}\n />\n </label>\n\n <div className=\"actions\">\n <button\n type=\"button\"\n onClick={handleSave}\n disabled={saveState === 'saving' || appKey.trim().length === 0}\n >\n {saveState === 'saving' ? 'Saving...' : 'Save credentials'}\n </button>\n <button\n type=\"button\"\n onClick={handleTest}\n disabled={!canTest || testState.kind === 'running'}\n >\n {testState.kind === 'running' ? 'Testing...' : 'Test connection'}\n </button>\n </div>\n\n {saveState === 'saved' ? <p role=\"status\">Saved.</p> : null}\n {saveState === 'error' && saveError ? (\n <p role=\"alert\">Save failed: {saveError}</p>\n ) : null}\n\n {testState.kind === 'ok' ? (\n <p role=\"status\">\n Connected to AliExpress. Found {testState.categoryCount} categories.\n </p>\n ) : null}\n {testState.kind === 'err' ? (\n <p role=\"alert\">\n Test failed ({testState.code}): {testState.msg}\n </p>\n ) : null}\n </section>\n\n <section aria-labelledby=\"ae-oauth-heading\">\n <h2 id=\"ae-oauth-heading\">Merchant account connection</h2>\n <p>\n Connect a specific AliExpress seller account to enable product\n import into this store. This is separate from the developer app\n credentials above.\n </p>\n\n {initialStatus.needsReauth ? (\n <p role=\"alert\" className=\"reauth-banner\">\n Re-authentication required. Please reconnect your AliExpress account.\n </p>\n ) : null}\n\n <div className=\"status-card\">\n <div>\n <strong>Status:</strong>{' '}\n {initialStatus.connected ? 'Connected' : 'Not connected'}\n </div>\n {initialStatus.sellerId ? (\n <div>\n <strong>Seller ID:</strong> {initialStatus.sellerId}\n </div>\n ) : null}\n {initialStatus.lastSuccessfulCallAt ? (\n <div>\n <strong>Last successful call:</strong>{' '}\n {initialStatus.lastSuccessfulCallAt}\n </div>\n ) : null}\n </div>\n\n <div className=\"actions\">\n <button\n type=\"button\"\n onClick={handleConnect}\n disabled={!canConnect || busyOAuth}\n >\n {busyOAuth ? 'Working...' : 'Connect merchant AliExpress account'}\n </button>\n <button\n type=\"button\"\n onClick={handleDisconnect}\n disabled={!canDisconnect || busyOAuth}\n >\n Disconnect\n </button>\n </div>\n\n {!testEverSucceeded ? (\n <p>\n Run <em>Test connection</em> once with your AppKey/AppSecret before\n connecting a merchant account.\n </p>\n ) : null}\n </section>\n\n <section aria-labelledby=\"ae-coming-soon-heading\">\n <h2 id=\"ae-coming-soon-heading\">Order forwarding</h2>\n <p>\n Coming soon. Automatic order forwarding to AliExpress requires\n our app to be approved out of Test status by AliExpress. Product\n import and browsing work today.\n </p>\n </section>\n </div>\n )\n}\n\nexport default AliExpressDropshippingSettingsForm\n","/**\n * Public types for @amboras-dev/aliexpress-dropshipping.\n *\n * These are the single source of truth for the wire shape between the\n * Amboras admin settings form and the medusa-backend-orchestrator\n * Store API routes under `/store/aliexpress-dropshipping/*`. The DTO\n * files on the medusa side must stay byte-compatible with these.\n */\n\n/**\n * Sentinel returned in place of a stored secret when the settings form\n * reads back current config. Matches the pattern used by meta-ads and\n * pinterest so the admin never sees the plaintext secret after write.\n */\nexport const SECRET_SET_SENTINEL = '__SECRET_SET__' as const\nexport type SecretSetSentinel = typeof SECRET_SET_SENTINEL\n\n/**\n * Per-store AliExpress plugin configuration.\n *\n * - `appKey` / `appSecret` are per-store developer app credentials\n * supplied by the merchant. The admin form receives\n * `SECRET_SET_SENTINEL` for `appSecret` on read, and only sends a\n * real value on user edit.\n * - `connectedSellerId` is populated after the merchant completes the\n * OAuth flow to `/rest/auth/token/create`.\n * - `needsReauth` is flipped by the backend runtime detector when it\n * sees `MissingParameter access_token` or `IllegalAccessToken`\n * sub-codes on any envelope.\n * - `lastSuccessfulCallAt` is an ISO-8601 timestamp for the status card.\n */\nexport interface AliExpressPluginConfig {\n enabled: boolean\n appKey: string | null\n appSecret: string | SecretSetSentinel | null\n connectedSellerId: string | null\n needsReauth: boolean\n lastSuccessfulCallAt: string | null\n}\n\n/**\n * Reasons the backend surfaces when a merchant token becomes invalid.\n * Kept narrow so the admin banner can render a specific message.\n */\nexport enum AliExpressReauthReason {\n MissingAccessToken = 'missing_access_token',\n IllegalAccessToken = 'illegal_access_token',\n RefreshFailed = 'refresh_failed',\n Disconnected = 'disconnected',\n}\n\n/**\n * Category node returned by `aliexpress.ds.category.get`. The API\n * returns a flat list; the admin renders it as a tree by walking\n * `parentCategoryId`.\n */\nexport interface AliExpressCategoryDto {\n categoryId: string\n categoryName: string\n parentCategoryId: string | null\n}\n\n/**\n * Product summary shape returned by `aliexpress.ds.recommend.feed.get`.\n * Used by the \"browse products\" admin surface.\n */\nexport interface AliExpressProductSummaryDto {\n productId: string\n title: string\n imageUrl: string | null\n minPrice: number | null\n maxPrice: number | null\n currency: string | null\n productDetailUrl: string | null\n}\n\n/**\n * Full product shape returned by `aliexpress.ds.product.get`. Consumed\n * by the medusa-side mapper `aliexpressProductToMedusaDraft`.\n */\nexport interface AliExpressProductDto {\n productId: string\n title: string\n description: string | null\n images: string[]\n variants: AliExpressProductVariantDto[]\n weightGrams: number | null\n sourceUrl: string | null\n}\n\nexport interface AliExpressProductVariantDto {\n skuId: string\n title: string | null\n price: number\n currency: string\n stock: number | null\n attributes: Record<string, string>\n}\n\n/**\n * Return shape from `POST /store/aliexpress-dropshipping/products/:id/import`.\n */\nexport interface AliExpressImportResultDto {\n medusaProductId: string\n sourceProductId: string\n importedVariants: number\n}\n\n/**\n * Return shape from `GET /store/aliexpress-dropshipping/status` - drives\n * the admin status card.\n */\nexport interface AliExpressConnectionStatusDto {\n connected: boolean\n sellerId: string | null\n needsReauth: boolean\n reauthReason: AliExpressReauthReason | null\n lastSuccessfulCallAt: string | null\n}\n\n/**\n * Return shape from `POST /store/aliexpress-dropshipping/test-connection`.\n */\nexport type AliExpressTestConnectionResult =\n | { ok: true; categoryCount: number }\n | { ok: false; code: string; msg: string }\n"],"mappings":";;;AAaA,YAAY,WAAW;;;ACChB,IAAM,sBAAsB;AA8B5B,IAAK,yBAAL,kBAAKA,4BAAL;AACL,EAAAA,wBAAA,wBAAqB;AACrB,EAAAA,wBAAA,wBAAqB;AACrB,EAAAA,wBAAA,mBAAgB;AAChB,EAAAA,wBAAA,kBAAe;AAJL,SAAAA;AAAA,GAAA;;;ADsHJ,cAOA,YAPA;AAtGD,SAAS,mCACd,OACoB;AACpB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,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AAU,iBAAgB,mFAE1C,IACE;AAAA,MAEJ,qBAAC,SAAI,WAAU,eACb;AAAA,6BAAC,SACC;AAAA,8BAAC,YAAO,qBAAO;AAAA,UAAU;AAAA,UACxB,cAAc,YAAY,cAAc;AAAA,WAC3C;AAAA,QACC,cAAc,WACb,qBAAC,SACC;AAAA,8BAAC,YAAO,wBAAU;AAAA,UAAS;AAAA,UAAE,cAAc;AAAA,WAC7C,IACE;AAAA,QACH,cAAc,uBACb,qBAAC,SACC;AAAA,8BAAC,YAAO,mCAAqB;AAAA,UAAU;AAAA,UACtC,cAAc;AAAA,WACjB,IACE;AAAA,SACN;AAAA,MAEA,qBAAC,SAAI,WAAU,WACb;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAU,CAAC,cAAc;AAAA,YAExB,sBAAY,eAAe;AAAA;AAAA,QAC9B;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAU,CAAC,iBAAiB;AAAA,YAC7B;AAAA;AAAA,QAED;AAAA,SACF;AAAA,MAEC,CAAC,oBACA,qBAAC,OAAE;AAAA;AAAA,QACG,oBAAC,QAAG,6BAAe;AAAA,QAAK;AAAA,SAE9B,IACE;AAAA,OACN;AAAA,IAEA,qBAAC,aAAQ,mBAAgB,0BACvB;AAAA,0BAAC,QAAG,IAAG,0BAAyB,8BAAgB;AAAA,MAChD,oBAAC,OAAE,6KAIH;AAAA,OACF;AAAA,KACF;AAEJ;","names":["AliExpressReauthReason"]}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@amboras-dev/aliexpress-dropshipping",
3
+ "version": "1.1.0",
4
+ "description": "AliExpress Dropshipping integration shell for Amboras - shared types + admin settings form",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "peerDependencies": {
20
+ "react": ">=18",
21
+ "next": ">=15"
22
+ },
23
+ "dependencies": {},
24
+ "devDependencies": {
25
+ "@types/node": "^20.0.0",
26
+ "@types/react": "^19.0.0",
27
+ "next": "^15.0.0",
28
+ "react": "^19.0.0",
29
+ "tsup": "^8.0.0",
30
+ "typescript": "^5.0.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsup",
37
+ "typecheck": "tsc --noEmit"
38
+ }
39
+ }