fix: supprimer variables inutilisées bloquant le build ESLint
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -127,9 +127,6 @@ export default function DashboardPage() {
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const lastSync = stats?.lastSync
|
const lastSync = stats?.lastSync
|
||||||
const syncStatusColor =
|
|
||||||
lastSync?.status === 'success' ? 'text-green-400' :
|
|
||||||
lastSync?.status === 'error' ? 'text-red-400' : 'text-slate-400'
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
import type { MetafieldDefinition, MetafieldResolution } from '@/types/creation'
|
import type { MetafieldDefinition, MetafieldResolution } from '@/types/creation'
|
||||||
|
|
||||||
const API_VERSION = '2024-01'
|
|
||||||
|
|
||||||
function getConfig() {
|
|
||||||
const domain = process.env.SHOPIFY_STORE_DOMAIN
|
|
||||||
const token = process.env.SHOPIFY_ADMIN_API_TOKEN
|
|
||||||
if (!domain || !token) throw new Error('SHOPIFY_STORE_DOMAIN et SHOPIFY_ADMIN_API_TOKEN requis')
|
|
||||||
return {
|
|
||||||
baseUrl: `https://${domain}/admin/api/${API_VERSION}`,
|
|
||||||
headers: { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function normalizeMetafieldKey(header: string): string {
|
export function normalizeMetafieldKey(header: string): string {
|
||||||
return header
|
return header
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
@@ -144,16 +132,46 @@ export async function setProductMetafield(
|
|||||||
value: string,
|
value: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (resolution.action === 'skip' || !value.trim()) return
|
if (resolution.action === 'skip' || !value.trim()) return
|
||||||
const { baseUrl, headers } = getConfig()
|
|
||||||
const res = await fetch(`${baseUrl}/products/${shopifyProductId}/metafields.json`, {
|
const domain = process.env.SHOPIFY_STORE_DOMAIN
|
||||||
|
const token = process.env.SHOPIFY_ADMIN_API_TOKEN
|
||||||
|
if (!domain || !token) throw new Error('SHOPIFY_STORE_DOMAIN et SHOPIFY_ADMIN_API_TOKEN requis')
|
||||||
|
|
||||||
|
const gid = `gid://shopify/Product/${shopifyProductId}`
|
||||||
|
const type = resolution.type ?? 'single_line_text_field'
|
||||||
|
|
||||||
|
const mutation = `mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
|
||||||
|
metafieldsSet(metafields: $metafields) {
|
||||||
|
metafields { key namespace value }
|
||||||
|
userErrors { field message }
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
const res = await fetch(`https://${domain}/admin/api/2024-01/graphql.json`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers,
|
headers: { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
metafield: { namespace: resolution.namespace, key: resolution.key, value, type: resolution.type ?? 'single_line_text_field' },
|
query: mutation,
|
||||||
|
variables: {
|
||||||
|
metafields: [{
|
||||||
|
ownerId: gid,
|
||||||
|
namespace: resolution.namespace,
|
||||||
|
key: resolution.key,
|
||||||
|
value,
|
||||||
|
type,
|
||||||
|
}],
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const err = await res.text()
|
const err = await res.text()
|
||||||
throw new Error(`Shopify set metafield error: ${res.status} — ${err}`)
|
throw new Error(`Shopify metafieldsSet HTTP error: ${res.status} — ${err}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await res.json()
|
||||||
|
const errors = data.data?.metafieldsSet?.userErrors ?? []
|
||||||
|
if (errors.length > 0) {
|
||||||
|
throw new Error(`Shopify metafieldsSet error: ${errors.map((e: { message: string }) => e.message).join(', ')}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user