|
|
@@ -281,14 +281,14 @@ export interface ShopRenterSettings {
|
|
|
/**
|
|
|
* Fetch shop settings directly using shopname and access token.
|
|
|
* This is used during OAuth flow before a store record exists.
|
|
|
- * Endpoint: GET /settings?full=1&key=config_email,config_owner
|
|
|
+ * Endpoint: GET /settings?full=1 returns all settings with key/value in items array
|
|
|
*/
|
|
|
export async function fetchShopSettingsDirect(
|
|
|
shopname: string,
|
|
|
accessToken: string
|
|
|
): Promise<ShopRenterSettings> {
|
|
|
const hostname = `${shopname}.api2.myshoprenter.hu`
|
|
|
- const path = '/api/settings?full=1&key=config_email,config_owner'
|
|
|
+ const path = '/api/settings?full=1'
|
|
|
|
|
|
console.log(`[ShopRenter] Fetching shop settings for ${shopname}`)
|
|
|
|
|
|
@@ -308,43 +308,27 @@ export async function fetchShopSettingsDirect(
|
|
|
}
|
|
|
|
|
|
const data = JSON.parse(response.body)
|
|
|
- console.log('[ShopRenter] Settings response:', JSON.stringify(data).substring(0, 500))
|
|
|
+ console.log('[ShopRenter] Settings response keys:', Object.keys(data))
|
|
|
+ console.log('[ShopRenter] Settings items count:', data.items?.length || 0)
|
|
|
|
|
|
// Extract config_email and config_owner from the response
|
|
|
- // ShopRenter settings API returns data in various formats, handle them
|
|
|
- let settings: ShopRenterSettings = {}
|
|
|
+ // ShopRenter returns: { items: [{ id, group, key, value }, ...], ... }
|
|
|
+ const settings: ShopRenterSettings = {}
|
|
|
|
|
|
- if (Array.isArray(data)) {
|
|
|
- // If array, find the settings by key
|
|
|
- for (const item of data) {
|
|
|
- if (item.key === 'config_email') {
|
|
|
- settings.config_email = item.value
|
|
|
- } else if (item.key === 'config_owner') {
|
|
|
- settings.config_owner = item.value
|
|
|
- }
|
|
|
- }
|
|
|
- } else if (data.items && Array.isArray(data.items)) {
|
|
|
- // If paginated response with items array
|
|
|
+ if (data.items && Array.isArray(data.items)) {
|
|
|
for (const item of data.items) {
|
|
|
- if (item.key === 'config_email') {
|
|
|
+ if (item.key === 'config_email' && item.value) {
|
|
|
settings.config_email = item.value
|
|
|
- } else if (item.key === 'config_owner') {
|
|
|
+ console.log(`[ShopRenter] Found config_email: ${item.value}`)
|
|
|
+ } else if (item.key === 'config_owner' && item.value) {
|
|
|
settings.config_owner = item.value
|
|
|
+ console.log(`[ShopRenter] Found config_owner: ${item.value}`)
|
|
|
}
|
|
|
- }
|
|
|
- } else if (data.data && Array.isArray(data.data)) {
|
|
|
- // Alternative paginated format
|
|
|
- for (const item of data.data) {
|
|
|
- if (item.key === 'config_email') {
|
|
|
- settings.config_email = item.value
|
|
|
- } else if (item.key === 'config_owner') {
|
|
|
- settings.config_owner = item.value
|
|
|
+ // Stop early if we found both
|
|
|
+ if (settings.config_email && settings.config_owner) {
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
- } else if (typeof data === 'object') {
|
|
|
- // Direct object format
|
|
|
- settings.config_email = data.config_email || data.configEmail
|
|
|
- settings.config_owner = data.config_owner || data.configOwner
|
|
|
}
|
|
|
|
|
|
console.log(`[ShopRenter] Extracted settings for ${shopname}:`, settings)
|