@amboras-dev/aliexpress-dropshipping 1.1.0 → 1.2.2
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 +7 -3
- package/dist/admin/index.d.mts +50 -0
- package/dist/admin/index.d.ts +50 -0
- package/dist/admin/index.js +253 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/index.mjs +7 -0
- package/dist/admin/index.mjs.map +1 -0
- package/dist/chunk-65TJ4JF6.mjs +224 -0
- package/dist/chunk-65TJ4JF6.mjs.map +1 -0
- package/dist/chunk-FPBGH4MH.mjs +89 -0
- package/dist/chunk-FPBGH4MH.mjs.map +1 -0
- package/dist/client/index.d.mts +46 -0
- package/dist/client/index.d.ts +46 -0
- package/dist/client/index.js +116 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/index.mjs +9 -0
- package/dist/client/index.mjs.map +1 -0
- package/dist/index.d.mts +5 -171
- package/dist/index.d.ts +5 -171
- package/dist/index.js +90 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -222
- package/dist/index.mjs.map +1 -1
- package/dist/types-CLTkhq_u.d.mts +151 -0
- package/dist/types-CLTkhq_u.d.ts +151 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# @amboras-dev/aliexpress-dropshipping
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Hybrid package for the Amboras AliExpress Dropshipping integration.
|
|
4
|
+
It exports the React admin settings form and optional storefront preflight
|
|
5
|
+
hooks/guards. All AliExpress OAuth, signing
|
|
6
6
|
(MD5 for `/sync`, HMAC-SHA256 for `/rest/auth/token/*`), category
|
|
7
7
|
browsing, product import, and token refresh live in the Medusa backend
|
|
8
8
|
module.
|
|
9
9
|
|
|
10
10
|
See the plugin admin page for connect / test-connection / disconnect
|
|
11
11
|
UI and the merchant OAuth flow.
|
|
12
|
+
|
|
13
|
+
Storefront checkout integrations can import `useAliexpressPreflight` from
|
|
14
|
+
`@amboras-dev/aliexpress-dropshipping/client` and block payment when the
|
|
15
|
+
orchestrator reports a hard fulfillment failure.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { c as AliExpressPluginConfig, a as AliExpressConnectionStatusDto, h as AliExpressTestConnectionResult } from '../types-CLTkhq_u.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Admin settings form for the AliExpress Dropshipping integration.
|
|
6
|
+
*
|
|
7
|
+
* Class B: this component owns the UI and talks to the Medusa Store API
|
|
8
|
+
* under `/store/aliexpress-dropshipping/*`. It does NOT embed any
|
|
9
|
+
* AliExpress SDK, does not sign requests, and does not touch OAuth
|
|
10
|
+
* tokens directly - the backend does all of that.
|
|
11
|
+
*
|
|
12
|
+
* The component is intentionally dependency-light (no external UI kit,
|
|
13
|
+
* no @tanstack/react-query peer) so the admin bundle can drop it in
|
|
14
|
+
* without extra peer dep resolution.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface AliExpressDropshippingSettingsFormProps {
|
|
18
|
+
/** Current config for this store (fetched by the parent server component). */
|
|
19
|
+
initialConfig: AliExpressPluginConfig;
|
|
20
|
+
/** Current connection status (from `GET /status`). */
|
|
21
|
+
initialStatus: AliExpressConnectionStatusDto;
|
|
22
|
+
/**
|
|
23
|
+
* Persist non-secret + optionally new secret values. The parent maps
|
|
24
|
+
* this onto `PATCH /store/aliexpress-dropshipping/config` (or
|
|
25
|
+
* equivalent) and then re-fetches config on success.
|
|
26
|
+
*
|
|
27
|
+
* `appSecret` is only sent when the merchant actually typed a new
|
|
28
|
+
* value; if they leave the field untouched, this method receives
|
|
29
|
+
* `undefined` for that key so the backend keeps the existing secret.
|
|
30
|
+
*/
|
|
31
|
+
onSaveConfig: (patch: {
|
|
32
|
+
appKey?: string;
|
|
33
|
+
appSecret?: string;
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
/** Kick off `POST /oauth/start` and redirect to the returned URL. */
|
|
37
|
+
onConnect: () => Promise<void>;
|
|
38
|
+
/** Kick off `POST /oauth/disconnect` and clear merchant credentials. */
|
|
39
|
+
onDisconnect: () => Promise<void>;
|
|
40
|
+
/** Call `POST /test-connection` and return the result. */
|
|
41
|
+
onTestConnection: () => Promise<AliExpressTestConnectionResult>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Amboras admin settings surface for AliExpress Dropshipping.
|
|
45
|
+
* Renders AppKey + AppSecret inputs, Test / Connect / Disconnect
|
|
46
|
+
* buttons, status card, and a "Coming soon" order-forwarding block.
|
|
47
|
+
*/
|
|
48
|
+
declare function AliExpressDropshippingSettingsForm(props: AliExpressDropshippingSettingsFormProps): React.ReactElement;
|
|
49
|
+
|
|
50
|
+
export { AliExpressDropshippingSettingsForm, type AliExpressDropshippingSettingsFormProps };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { c as AliExpressPluginConfig, a as AliExpressConnectionStatusDto, h as AliExpressTestConnectionResult } from '../types-CLTkhq_u.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Admin settings form for the AliExpress Dropshipping integration.
|
|
6
|
+
*
|
|
7
|
+
* Class B: this component owns the UI and talks to the Medusa Store API
|
|
8
|
+
* under `/store/aliexpress-dropshipping/*`. It does NOT embed any
|
|
9
|
+
* AliExpress SDK, does not sign requests, and does not touch OAuth
|
|
10
|
+
* tokens directly - the backend does all of that.
|
|
11
|
+
*
|
|
12
|
+
* The component is intentionally dependency-light (no external UI kit,
|
|
13
|
+
* no @tanstack/react-query peer) so the admin bundle can drop it in
|
|
14
|
+
* without extra peer dep resolution.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
interface AliExpressDropshippingSettingsFormProps {
|
|
18
|
+
/** Current config for this store (fetched by the parent server component). */
|
|
19
|
+
initialConfig: AliExpressPluginConfig;
|
|
20
|
+
/** Current connection status (from `GET /status`). */
|
|
21
|
+
initialStatus: AliExpressConnectionStatusDto;
|
|
22
|
+
/**
|
|
23
|
+
* Persist non-secret + optionally new secret values. The parent maps
|
|
24
|
+
* this onto `PATCH /store/aliexpress-dropshipping/config` (or
|
|
25
|
+
* equivalent) and then re-fetches config on success.
|
|
26
|
+
*
|
|
27
|
+
* `appSecret` is only sent when the merchant actually typed a new
|
|
28
|
+
* value; if they leave the field untouched, this method receives
|
|
29
|
+
* `undefined` for that key so the backend keeps the existing secret.
|
|
30
|
+
*/
|
|
31
|
+
onSaveConfig: (patch: {
|
|
32
|
+
appKey?: string;
|
|
33
|
+
appSecret?: string;
|
|
34
|
+
enabled?: boolean;
|
|
35
|
+
}) => Promise<void>;
|
|
36
|
+
/** Kick off `POST /oauth/start` and redirect to the returned URL. */
|
|
37
|
+
onConnect: () => Promise<void>;
|
|
38
|
+
/** Kick off `POST /oauth/disconnect` and clear merchant credentials. */
|
|
39
|
+
onDisconnect: () => Promise<void>;
|
|
40
|
+
/** Call `POST /test-connection` and return the result. */
|
|
41
|
+
onTestConnection: () => Promise<AliExpressTestConnectionResult>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Amboras admin settings surface for AliExpress Dropshipping.
|
|
45
|
+
* Renders AppKey + AppSecret inputs, Test / Connect / Disconnect
|
|
46
|
+
* buttons, status card, and a "Coming soon" order-forwarding block.
|
|
47
|
+
*/
|
|
48
|
+
declare function AliExpressDropshippingSettingsForm(props: AliExpressDropshippingSettingsFormProps): React.ReactElement;
|
|
49
|
+
|
|
50
|
+
export { AliExpressDropshippingSettingsForm, type AliExpressDropshippingSettingsFormProps };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/admin/index.ts
|
|
31
|
+
var admin_exports = {};
|
|
32
|
+
__export(admin_exports, {
|
|
33
|
+
AliExpressDropshippingSettingsForm: () => AliExpressDropshippingSettingsForm
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(admin_exports);
|
|
36
|
+
|
|
37
|
+
// src/settings-form.tsx
|
|
38
|
+
var React = __toESM(require("react"));
|
|
39
|
+
|
|
40
|
+
// src/types.ts
|
|
41
|
+
var SECRET_SET_SENTINEL = "__SECRET_SET__";
|
|
42
|
+
|
|
43
|
+
// src/settings-form.tsx
|
|
44
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
+
function AliExpressDropshippingSettingsForm(props) {
|
|
46
|
+
const {
|
|
47
|
+
initialConfig,
|
|
48
|
+
initialStatus,
|
|
49
|
+
onSaveConfig,
|
|
50
|
+
onConnect,
|
|
51
|
+
onDisconnect,
|
|
52
|
+
onTestConnection
|
|
53
|
+
} = props;
|
|
54
|
+
const [appKey, setAppKey] = React.useState(
|
|
55
|
+
initialConfig.appKey ?? ""
|
|
56
|
+
);
|
|
57
|
+
const secretPreset = initialConfig.appSecret === SECRET_SET_SENTINEL || typeof initialConfig.appSecret === "string" && initialConfig.appSecret.length > 0;
|
|
58
|
+
const [appSecret, setAppSecret] = React.useState("");
|
|
59
|
+
const [secretDirty, setSecretDirty] = React.useState(false);
|
|
60
|
+
const [saveState, setSaveState] = React.useState("idle");
|
|
61
|
+
const [saveError, setSaveError] = React.useState(null);
|
|
62
|
+
const [testState, setTestState] = React.useState({ kind: "idle" });
|
|
63
|
+
const [testEverSucceeded, setTestEverSucceeded] = React.useState(
|
|
64
|
+
initialStatus.connected
|
|
65
|
+
);
|
|
66
|
+
const [busyOAuth, setBusyOAuth] = React.useState(false);
|
|
67
|
+
const hasStoredSecret = secretPreset || secretDirty;
|
|
68
|
+
const canTest = appKey.trim().length > 0 && hasStoredSecret;
|
|
69
|
+
const canConnect = testEverSucceeded && !initialStatus.connected;
|
|
70
|
+
const canDisconnect = initialStatus.connected;
|
|
71
|
+
const handleSave = React.useCallback(async () => {
|
|
72
|
+
setSaveState("saving");
|
|
73
|
+
setSaveError(null);
|
|
74
|
+
try {
|
|
75
|
+
const patch = {};
|
|
76
|
+
if (appKey.trim() !== (initialConfig.appKey ?? "")) {
|
|
77
|
+
patch.appKey = appKey.trim();
|
|
78
|
+
}
|
|
79
|
+
if (secretDirty && appSecret.length > 0) {
|
|
80
|
+
patch.appSecret = appSecret;
|
|
81
|
+
}
|
|
82
|
+
await onSaveConfig(patch);
|
|
83
|
+
setSaveState("saved");
|
|
84
|
+
setSecretDirty(false);
|
|
85
|
+
setAppSecret("");
|
|
86
|
+
} catch (err) {
|
|
87
|
+
setSaveState("error");
|
|
88
|
+
setSaveError(err instanceof Error ? err.message : "Save failed");
|
|
89
|
+
}
|
|
90
|
+
}, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig]);
|
|
91
|
+
const handleTest = React.useCallback(async () => {
|
|
92
|
+
setTestState({ kind: "running" });
|
|
93
|
+
try {
|
|
94
|
+
const result = await onTestConnection();
|
|
95
|
+
if (result.ok) {
|
|
96
|
+
setTestState({ kind: "ok", categoryCount: result.categoryCount });
|
|
97
|
+
setTestEverSucceeded(true);
|
|
98
|
+
} else {
|
|
99
|
+
setTestState({ kind: "err", code: result.code, msg: result.msg });
|
|
100
|
+
}
|
|
101
|
+
} catch (err) {
|
|
102
|
+
setTestState({
|
|
103
|
+
kind: "err",
|
|
104
|
+
code: "UNKNOWN",
|
|
105
|
+
msg: err instanceof Error ? err.message : "Test failed"
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, [onTestConnection]);
|
|
109
|
+
const handleConnect = React.useCallback(async () => {
|
|
110
|
+
setBusyOAuth(true);
|
|
111
|
+
try {
|
|
112
|
+
await onConnect();
|
|
113
|
+
} finally {
|
|
114
|
+
setBusyOAuth(false);
|
|
115
|
+
}
|
|
116
|
+
}, [onConnect]);
|
|
117
|
+
const handleDisconnect = React.useCallback(async () => {
|
|
118
|
+
setBusyOAuth(true);
|
|
119
|
+
try {
|
|
120
|
+
await onDisconnect();
|
|
121
|
+
} finally {
|
|
122
|
+
setBusyOAuth(false);
|
|
123
|
+
}
|
|
124
|
+
}, [onDisconnect]);
|
|
125
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "aliexpress-dropshipping-settings", children: [
|
|
126
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-credentials-heading", children: [
|
|
127
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-credentials-heading", children: "Developer app credentials" }),
|
|
128
|
+
/* @__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." }),
|
|
129
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
|
|
130
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "App Key" }),
|
|
131
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
132
|
+
"input",
|
|
133
|
+
{
|
|
134
|
+
type: "text",
|
|
135
|
+
value: appKey,
|
|
136
|
+
onChange: (e) => setAppKey(e.target.value),
|
|
137
|
+
autoComplete: "off",
|
|
138
|
+
spellCheck: false
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
] }),
|
|
142
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { children: [
|
|
143
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "App Secret" }),
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
145
|
+
"input",
|
|
146
|
+
{
|
|
147
|
+
type: "password",
|
|
148
|
+
value: appSecret,
|
|
149
|
+
placeholder: secretPreset ? "(secret set - leave blank to keep)" : "",
|
|
150
|
+
onChange: (e) => {
|
|
151
|
+
setAppSecret(e.target.value);
|
|
152
|
+
setSecretDirty(true);
|
|
153
|
+
},
|
|
154
|
+
autoComplete: "off",
|
|
155
|
+
spellCheck: false
|
|
156
|
+
}
|
|
157
|
+
)
|
|
158
|
+
] }),
|
|
159
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "actions", children: [
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
161
|
+
"button",
|
|
162
|
+
{
|
|
163
|
+
type: "button",
|
|
164
|
+
onClick: handleSave,
|
|
165
|
+
disabled: saveState === "saving" || appKey.trim().length === 0,
|
|
166
|
+
children: saveState === "saving" ? "Saving..." : "Save credentials"
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
170
|
+
"button",
|
|
171
|
+
{
|
|
172
|
+
type: "button",
|
|
173
|
+
onClick: handleTest,
|
|
174
|
+
disabled: !canTest || testState.kind === "running",
|
|
175
|
+
children: testState.kind === "running" ? "Testing..." : "Test connection"
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
] }),
|
|
179
|
+
saveState === "saved" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "status", children: "Saved." }) : null,
|
|
180
|
+
saveState === "error" && saveError ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", children: [
|
|
181
|
+
"Save failed: ",
|
|
182
|
+
saveError
|
|
183
|
+
] }) : null,
|
|
184
|
+
testState.kind === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "status", children: [
|
|
185
|
+
"Connected to AliExpress. Found ",
|
|
186
|
+
testState.categoryCount,
|
|
187
|
+
" categories."
|
|
188
|
+
] }) : null,
|
|
189
|
+
testState.kind === "err" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { role: "alert", children: [
|
|
190
|
+
"Test failed (",
|
|
191
|
+
testState.code,
|
|
192
|
+
"): ",
|
|
193
|
+
testState.msg
|
|
194
|
+
] }) : null
|
|
195
|
+
] }),
|
|
196
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-oauth-heading", children: [
|
|
197
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-oauth-heading", children: "Merchant account connection" }),
|
|
198
|
+
/* @__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." }),
|
|
199
|
+
initialStatus.needsReauth ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { role: "alert", className: "reauth-banner", children: "Re-authentication required. Please reconnect your AliExpress account." }) : null,
|
|
200
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "status-card", children: [
|
|
201
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
202
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Status:" }),
|
|
203
|
+
" ",
|
|
204
|
+
initialStatus.connected ? "Connected" : "Not connected"
|
|
205
|
+
] }),
|
|
206
|
+
initialStatus.sellerId ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
207
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Seller ID:" }),
|
|
208
|
+
" ",
|
|
209
|
+
initialStatus.sellerId
|
|
210
|
+
] }) : null,
|
|
211
|
+
initialStatus.lastSuccessfulCallAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
|
|
212
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Last successful call:" }),
|
|
213
|
+
" ",
|
|
214
|
+
initialStatus.lastSuccessfulCallAt
|
|
215
|
+
] }) : null
|
|
216
|
+
] }),
|
|
217
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "actions", children: [
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
219
|
+
"button",
|
|
220
|
+
{
|
|
221
|
+
type: "button",
|
|
222
|
+
onClick: handleConnect,
|
|
223
|
+
disabled: !canConnect || busyOAuth,
|
|
224
|
+
children: busyOAuth ? "Working..." : "Connect merchant AliExpress account"
|
|
225
|
+
}
|
|
226
|
+
),
|
|
227
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
228
|
+
"button",
|
|
229
|
+
{
|
|
230
|
+
type: "button",
|
|
231
|
+
onClick: handleDisconnect,
|
|
232
|
+
disabled: !canDisconnect || busyOAuth,
|
|
233
|
+
children: "Disconnect"
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
] }),
|
|
237
|
+
!testEverSucceeded ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
|
|
238
|
+
"Run ",
|
|
239
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: "Test connection" }),
|
|
240
|
+
" once with your AppKey/AppSecret before connecting a merchant account."
|
|
241
|
+
] }) : null
|
|
242
|
+
] }),
|
|
243
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { "aria-labelledby": "ae-coming-soon-heading", children: [
|
|
244
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "ae-coming-soon-heading", children: "Order forwarding" }),
|
|
245
|
+
/* @__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." })
|
|
246
|
+
] })
|
|
247
|
+
] });
|
|
248
|
+
}
|
|
249
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
250
|
+
0 && (module.exports = {
|
|
251
|
+
AliExpressDropshippingSettingsForm
|
|
252
|
+
});
|
|
253
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/index.ts","../../src/settings-form.tsx","../../src/types.ts"],"sourcesContent":["export {\n AliExpressDropshippingSettingsForm,\n type AliExpressDropshippingSettingsFormProps,\n} from '../settings-form'\n","'use client'\n\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\nexport interface PreflightMerchantError {\n code: string\n message: string\n}\n\nexport interface PreflightAddressError {\n code: string\n message: string\n field: string\n}\n\nexport interface PreflightItemError {\n variantId: string\n productTitle: string\n code: 'CORRUPT_METADATA' | 'PRODUCT_OFFLINE' | 'OUT_OF_STOCK' | 'CANNOT_SHIP' | 'PRICE_DRIFT'\n message: string\n removable: boolean\n}\n\nexport interface PreflightResult {\n ok: boolean\n merchantErrors: PreflightMerchantError[]\n addressErrors: PreflightAddressError[]\n itemErrors: PreflightItemError[]\n warnings: Array<{ code: string; message: string }>\n degraded?: boolean\n warning?: string\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACeA,YAAuB;;;ACDhB,IAAM,sBAAsB;;;ADsJ3B;AAtGD,SAAS,mCACd,OACoB;AACpB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,QAAM,CAAC,QAAQ,SAAS,IAAU;AAAA,IAChC,cAAc,UAAU;AAAA,EAC1B;AACA,QAAM,eACJ,cAAc,cAAc,uBAC3B,OAAO,cAAc,cAAc,YAClC,cAAc,UAAU,SAAS;AACrC,QAAM,CAAC,WAAW,YAAY,IAAU,eAAiB,EAAE;AAC3D,QAAM,CAAC,aAAa,cAAc,IAAU,eAAkB,KAAK;AAEnE,QAAM,CAAC,WAAW,YAAY,IAAU,eAAoB,MAAM;AAClE,QAAM,CAAC,WAAW,YAAY,IAAU,eAAwB,IAAI;AAEpE,QAAM,CAAC,WAAW,YAAY,IAAU,eAAoB,EAAE,MAAM,OAAO,CAAC;AA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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,6CAAC,OAAE;AAAA;AAAA,QACG,4CAAC,QAAG,6BAAe;AAAA,QAAK;AAAA,SAE9B,IACE;AAAA,OACN;AAAA,IAEA,6CAAC,aAAQ,mBAAgB,0BACvB;AAAA,kDAAC,QAAG,IAAG,0BAAyB,8BAAgB;AAAA,MAChD,4CAAC,OAAE,6KAIH;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
var SECRET_SET_SENTINEL = "__SECRET_SET__";
|
|
3
|
+
var AliExpressReauthReason = /* @__PURE__ */ ((AliExpressReauthReason2) => {
|
|
4
|
+
AliExpressReauthReason2["MissingAccessToken"] = "missing_access_token";
|
|
5
|
+
AliExpressReauthReason2["IllegalAccessToken"] = "illegal_access_token";
|
|
6
|
+
AliExpressReauthReason2["RefreshFailed"] = "refresh_failed";
|
|
7
|
+
AliExpressReauthReason2["Disconnected"] = "disconnected";
|
|
8
|
+
return AliExpressReauthReason2;
|
|
9
|
+
})(AliExpressReauthReason || {});
|
|
10
|
+
|
|
11
|
+
// src/settings-form.tsx
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
function AliExpressDropshippingSettingsForm(props) {
|
|
15
|
+
const {
|
|
16
|
+
initialConfig,
|
|
17
|
+
initialStatus,
|
|
18
|
+
onSaveConfig,
|
|
19
|
+
onConnect,
|
|
20
|
+
onDisconnect,
|
|
21
|
+
onTestConnection
|
|
22
|
+
} = props;
|
|
23
|
+
const [appKey, setAppKey] = React.useState(
|
|
24
|
+
initialConfig.appKey ?? ""
|
|
25
|
+
);
|
|
26
|
+
const secretPreset = initialConfig.appSecret === SECRET_SET_SENTINEL || typeof initialConfig.appSecret === "string" && initialConfig.appSecret.length > 0;
|
|
27
|
+
const [appSecret, setAppSecret] = React.useState("");
|
|
28
|
+
const [secretDirty, setSecretDirty] = React.useState(false);
|
|
29
|
+
const [saveState, setSaveState] = React.useState("idle");
|
|
30
|
+
const [saveError, setSaveError] = React.useState(null);
|
|
31
|
+
const [testState, setTestState] = React.useState({ kind: "idle" });
|
|
32
|
+
const [testEverSucceeded, setTestEverSucceeded] = React.useState(
|
|
33
|
+
initialStatus.connected
|
|
34
|
+
);
|
|
35
|
+
const [busyOAuth, setBusyOAuth] = React.useState(false);
|
|
36
|
+
const hasStoredSecret = secretPreset || secretDirty;
|
|
37
|
+
const canTest = appKey.trim().length > 0 && hasStoredSecret;
|
|
38
|
+
const canConnect = testEverSucceeded && !initialStatus.connected;
|
|
39
|
+
const canDisconnect = initialStatus.connected;
|
|
40
|
+
const handleSave = React.useCallback(async () => {
|
|
41
|
+
setSaveState("saving");
|
|
42
|
+
setSaveError(null);
|
|
43
|
+
try {
|
|
44
|
+
const patch = {};
|
|
45
|
+
if (appKey.trim() !== (initialConfig.appKey ?? "")) {
|
|
46
|
+
patch.appKey = appKey.trim();
|
|
47
|
+
}
|
|
48
|
+
if (secretDirty && appSecret.length > 0) {
|
|
49
|
+
patch.appSecret = appSecret;
|
|
50
|
+
}
|
|
51
|
+
await onSaveConfig(patch);
|
|
52
|
+
setSaveState("saved");
|
|
53
|
+
setSecretDirty(false);
|
|
54
|
+
setAppSecret("");
|
|
55
|
+
} catch (err) {
|
|
56
|
+
setSaveState("error");
|
|
57
|
+
setSaveError(err instanceof Error ? err.message : "Save failed");
|
|
58
|
+
}
|
|
59
|
+
}, [appKey, appSecret, secretDirty, initialConfig.appKey, onSaveConfig]);
|
|
60
|
+
const handleTest = React.useCallback(async () => {
|
|
61
|
+
setTestState({ kind: "running" });
|
|
62
|
+
try {
|
|
63
|
+
const result = await onTestConnection();
|
|
64
|
+
if (result.ok) {
|
|
65
|
+
setTestState({ kind: "ok", categoryCount: result.categoryCount });
|
|
66
|
+
setTestEverSucceeded(true);
|
|
67
|
+
} else {
|
|
68
|
+
setTestState({ kind: "err", code: result.code, msg: result.msg });
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
setTestState({
|
|
72
|
+
kind: "err",
|
|
73
|
+
code: "UNKNOWN",
|
|
74
|
+
msg: err instanceof Error ? err.message : "Test failed"
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, [onTestConnection]);
|
|
78
|
+
const handleConnect = React.useCallback(async () => {
|
|
79
|
+
setBusyOAuth(true);
|
|
80
|
+
try {
|
|
81
|
+
await onConnect();
|
|
82
|
+
} finally {
|
|
83
|
+
setBusyOAuth(false);
|
|
84
|
+
}
|
|
85
|
+
}, [onConnect]);
|
|
86
|
+
const handleDisconnect = React.useCallback(async () => {
|
|
87
|
+
setBusyOAuth(true);
|
|
88
|
+
try {
|
|
89
|
+
await onDisconnect();
|
|
90
|
+
} finally {
|
|
91
|
+
setBusyOAuth(false);
|
|
92
|
+
}
|
|
93
|
+
}, [onDisconnect]);
|
|
94
|
+
return /* @__PURE__ */ jsxs("div", { className: "aliexpress-dropshipping-settings", children: [
|
|
95
|
+
/* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-credentials-heading", children: [
|
|
96
|
+
/* @__PURE__ */ jsx("h2", { id: "ae-credentials-heading", children: "Developer app credentials" }),
|
|
97
|
+
/* @__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." }),
|
|
98
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
99
|
+
/* @__PURE__ */ jsx("span", { children: "App Key" }),
|
|
100
|
+
/* @__PURE__ */ jsx(
|
|
101
|
+
"input",
|
|
102
|
+
{
|
|
103
|
+
type: "text",
|
|
104
|
+
value: appKey,
|
|
105
|
+
onChange: (e) => setAppKey(e.target.value),
|
|
106
|
+
autoComplete: "off",
|
|
107
|
+
spellCheck: false
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
] }),
|
|
111
|
+
/* @__PURE__ */ jsxs("label", { children: [
|
|
112
|
+
/* @__PURE__ */ jsx("span", { children: "App Secret" }),
|
|
113
|
+
/* @__PURE__ */ jsx(
|
|
114
|
+
"input",
|
|
115
|
+
{
|
|
116
|
+
type: "password",
|
|
117
|
+
value: appSecret,
|
|
118
|
+
placeholder: secretPreset ? "(secret set - leave blank to keep)" : "",
|
|
119
|
+
onChange: (e) => {
|
|
120
|
+
setAppSecret(e.target.value);
|
|
121
|
+
setSecretDirty(true);
|
|
122
|
+
},
|
|
123
|
+
autoComplete: "off",
|
|
124
|
+
spellCheck: false
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ jsxs("div", { className: "actions", children: [
|
|
129
|
+
/* @__PURE__ */ jsx(
|
|
130
|
+
"button",
|
|
131
|
+
{
|
|
132
|
+
type: "button",
|
|
133
|
+
onClick: handleSave,
|
|
134
|
+
disabled: saveState === "saving" || appKey.trim().length === 0,
|
|
135
|
+
children: saveState === "saving" ? "Saving..." : "Save credentials"
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
/* @__PURE__ */ jsx(
|
|
139
|
+
"button",
|
|
140
|
+
{
|
|
141
|
+
type: "button",
|
|
142
|
+
onClick: handleTest,
|
|
143
|
+
disabled: !canTest || testState.kind === "running",
|
|
144
|
+
children: testState.kind === "running" ? "Testing..." : "Test connection"
|
|
145
|
+
}
|
|
146
|
+
)
|
|
147
|
+
] }),
|
|
148
|
+
saveState === "saved" ? /* @__PURE__ */ jsx("p", { role: "status", children: "Saved." }) : null,
|
|
149
|
+
saveState === "error" && saveError ? /* @__PURE__ */ jsxs("p", { role: "alert", children: [
|
|
150
|
+
"Save failed: ",
|
|
151
|
+
saveError
|
|
152
|
+
] }) : null,
|
|
153
|
+
testState.kind === "ok" ? /* @__PURE__ */ jsxs("p", { role: "status", children: [
|
|
154
|
+
"Connected to AliExpress. Found ",
|
|
155
|
+
testState.categoryCount,
|
|
156
|
+
" categories."
|
|
157
|
+
] }) : null,
|
|
158
|
+
testState.kind === "err" ? /* @__PURE__ */ jsxs("p", { role: "alert", children: [
|
|
159
|
+
"Test failed (",
|
|
160
|
+
testState.code,
|
|
161
|
+
"): ",
|
|
162
|
+
testState.msg
|
|
163
|
+
] }) : null
|
|
164
|
+
] }),
|
|
165
|
+
/* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-oauth-heading", children: [
|
|
166
|
+
/* @__PURE__ */ jsx("h2", { id: "ae-oauth-heading", children: "Merchant account connection" }),
|
|
167
|
+
/* @__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." }),
|
|
168
|
+
initialStatus.needsReauth ? /* @__PURE__ */ jsx("p", { role: "alert", className: "reauth-banner", children: "Re-authentication required. Please reconnect your AliExpress account." }) : null,
|
|
169
|
+
/* @__PURE__ */ jsxs("div", { className: "status-card", children: [
|
|
170
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
171
|
+
/* @__PURE__ */ jsx("strong", { children: "Status:" }),
|
|
172
|
+
" ",
|
|
173
|
+
initialStatus.connected ? "Connected" : "Not connected"
|
|
174
|
+
] }),
|
|
175
|
+
initialStatus.sellerId ? /* @__PURE__ */ jsxs("div", { children: [
|
|
176
|
+
/* @__PURE__ */ jsx("strong", { children: "Seller ID:" }),
|
|
177
|
+
" ",
|
|
178
|
+
initialStatus.sellerId
|
|
179
|
+
] }) : null,
|
|
180
|
+
initialStatus.lastSuccessfulCallAt ? /* @__PURE__ */ jsxs("div", { children: [
|
|
181
|
+
/* @__PURE__ */ jsx("strong", { children: "Last successful call:" }),
|
|
182
|
+
" ",
|
|
183
|
+
initialStatus.lastSuccessfulCallAt
|
|
184
|
+
] }) : null
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ jsxs("div", { className: "actions", children: [
|
|
187
|
+
/* @__PURE__ */ jsx(
|
|
188
|
+
"button",
|
|
189
|
+
{
|
|
190
|
+
type: "button",
|
|
191
|
+
onClick: handleConnect,
|
|
192
|
+
disabled: !canConnect || busyOAuth,
|
|
193
|
+
children: busyOAuth ? "Working..." : "Connect merchant AliExpress account"
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
/* @__PURE__ */ jsx(
|
|
197
|
+
"button",
|
|
198
|
+
{
|
|
199
|
+
type: "button",
|
|
200
|
+
onClick: handleDisconnect,
|
|
201
|
+
disabled: !canDisconnect || busyOAuth,
|
|
202
|
+
children: "Disconnect"
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
] }),
|
|
206
|
+
!testEverSucceeded ? /* @__PURE__ */ jsxs("p", { children: [
|
|
207
|
+
"Run ",
|
|
208
|
+
/* @__PURE__ */ jsx("em", { children: "Test connection" }),
|
|
209
|
+
" once with your AppKey/AppSecret before connecting a merchant account."
|
|
210
|
+
] }) : null
|
|
211
|
+
] }),
|
|
212
|
+
/* @__PURE__ */ jsxs("section", { "aria-labelledby": "ae-coming-soon-heading", children: [
|
|
213
|
+
/* @__PURE__ */ jsx("h2", { id: "ae-coming-soon-heading", children: "Order forwarding" }),
|
|
214
|
+
/* @__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." })
|
|
215
|
+
] })
|
|
216
|
+
] });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export {
|
|
220
|
+
SECRET_SET_SENTINEL,
|
|
221
|
+
AliExpressReauthReason,
|
|
222
|
+
AliExpressDropshippingSettingsForm
|
|
223
|
+
};
|
|
224
|
+
//# sourceMappingURL=chunk-65TJ4JF6.mjs.map
|