-
Notifications
You must be signed in to change notification settings - Fork 131
shopify plugin #111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
shopify plugin #111
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| const errorData = (await response.json()) as { errors?: string }; | ||
| return { | ||
| success: false, | ||
| error: errorData.errors || `HTTP ${response.status}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error response type is incorrectly typed as { errors?: string } but the Shopify API may return errors as an object for validation errors, causing [object Object] to appear in error messages instead of meaningful error text.
View Details
📝 Patch Details
diff --git a/plugins/shopify/steps/get-order.ts b/plugins/shopify/steps/get-order.ts
index 5b35ea2..6cef3ca 100644
--- a/plugins/shopify/steps/get-order.ts
+++ b/plugins/shopify/steps/get-order.ts
@@ -140,10 +140,14 @@ async function stepHandler(
});
if (!response.ok) {
- const errorData = (await response.json()) as { errors?: string };
+ const errorData = (await response.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
- error: errorData.errors || `HTTP ${response.status}`,
+ error: errorMessage || `HTTP ${response.status}`,
};
}
diff --git a/plugins/shopify/steps/list-orders.ts b/plugins/shopify/steps/list-orders.ts
index 01943ae..7e858ef 100644
--- a/plugins/shopify/steps/list-orders.ts
+++ b/plugins/shopify/steps/list-orders.ts
@@ -132,10 +132,14 @@ async function stepHandler(
});
if (!response.ok) {
- const errorData = (await response.json()) as { errors?: string };
+ const errorData = (await response.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
- error: errorData.errors || `HTTP ${response.status}`,
+ error: errorMessage || `HTTP ${response.status}`,
};
}
diff --git a/plugins/shopify/steps/update-inventory.ts b/plugins/shopify/steps/update-inventory.ts
index 1a90d68..58d907b 100644
--- a/plugins/shopify/steps/update-inventory.ts
+++ b/plugins/shopify/steps/update-inventory.ts
@@ -83,11 +83,15 @@ async function stepHandler(
});
if (!getResponse.ok) {
- const errorData = (await getResponse.json()) as { errors?: string };
+ const errorData = (await getResponse.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
error:
- errorData.errors ||
+ errorMessage ||
`Failed to get current inventory: HTTP ${getResponse.status}`,
};
}
Analysis
Incorrect Shopify API error response type causes "[object Object]" in error messages
What fails: Three Shopify API integration files incorrectly type the API error response as { errors?: string }, but the Shopify Admin REST API returns errors as either a string (for simple errors like "Invalid API key") or an array of strings (for validation errors). When validation errors are returned as an array, they are converted to [object Object] at runtime instead of meaningful error text.
Affected files:
plugins/shopify/steps/get-order.ts(line 143)plugins/shopify/steps/list-orders.ts(line 135)plugins/shopify/steps/update-inventory.ts(line 86)
How to reproduce:
# When the Shopify API returns a 422 Unprocessable Entity with validation errors:
# Response: { "errors": ["The fulfillment order is not in an open state."] }
# The code would display: "The fulfillment order is not in an open state." as "[object Object]"Result: Users see [object Object] error messages for validation errors instead of readable error descriptions. The bug affects all three files.
Expected: Per Shopify API documentation, validation errors (422 response) can return errors as an array. The code should check the type of errors and handle both string and array cases, identical to the pattern already correctly implemented in create-product.ts and the POST endpoint in update-inventory.ts.
Fix: Changed type from { errors?: string } to { errors?: unknown } and added runtime type checking:
const errorMessage =
typeof errorData.errors === "string"
? errorData.errors
: JSON.stringify(errorData.errors);| if (input.price || input.sku) { | ||
| const variant: Record<string, unknown> = {}; | ||
|
|
||
| if (input.price) { | ||
| variant.price = input.price; | ||
| } | ||
|
|
||
| if (input.sku) { | ||
| variant.sku = input.sku; | ||
| } | ||
|
|
||
| productPayload.variants = [variant]; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inventoryQuantity configuration field is accepted from users but never used in the product creation, causing the value to be silently ignored.
View Details
📝 Patch Details
diff --git a/plugins/shopify/index.ts b/plugins/shopify/index.ts
index 235a6a7..1d8303b 100644
--- a/plugins/shopify/index.ts
+++ b/plugins/shopify/index.ts
@@ -232,13 +232,6 @@ const shopifyPlugin: IntegrationPlugin = {
placeholder: "TSHIRT-001 or {{NodeName.sku}}",
example: "TSHIRT-001",
},
- {
- key: "inventoryQuantity",
- label: "Inventory Quantity",
- type: "number",
- min: 0,
- defaultValue: "0",
- },
],
},
{
diff --git a/plugins/shopify/steps/create-product.ts b/plugins/shopify/steps/create-product.ts
index df473ad..a665bcf 100644
--- a/plugins/shopify/steps/create-product.ts
+++ b/plugins/shopify/steps/create-product.ts
@@ -56,7 +56,6 @@ export type CreateProductCoreInput = {
status?: string;
price?: string;
sku?: string;
- inventoryQuantity?: number;
};
export type CreateProductInput = StepInput &
Analysis
Misleading inventoryQuantity field cannot be set during product creation
What fails: The create-product step accepts inventoryQuantity as a configuration field, but the value is never applied to the created product because Shopify's inventory_quantity field is read-only during product creation.
How to reproduce:
- Use the
create-productstep withinventoryQuantityset to any value (e.g., 100) - Create a product
- Check the inventory in Shopify - it will be 0, not the configured value
- The value is silently ignored
Result: Product is created successfully, but inventory quantity is not set. The UI suggests this can be configured but it has no effect.
Expected: Either:
- Remove
inventoryQuantityfrom the configuration since it cannot be used (preferred) - Or use the separate
update-inventorystep to set inventory after product creation
Technical details: Shopify's REST API 2024-01 does not allow setting inventory_quantity on variants during product creation - this field is read-only. Per Shopify documentation, "Apps can no longer set inventory using inventory_quantity. For more information, refer to the Inventory Level resource." Inventory must be managed through the separate Inventory Level API using the update-inventory step after the product is created.
Fix: Removed inventoryQuantity from:
- The
create-productconfigFields inplugins/shopify/index.ts(lines 236-240) - The
CreateProductCoreInputtype inplugins/shopify/steps/create-product.ts(line 59)
Users should use the update-inventory action to set inventory levels after creating a product.
| const errorData = (await response.json()) as { errors?: string }; | ||
| return { | ||
| success: false, | ||
| error: errorData.errors || `HTTP ${response.status}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error response type is incorrectly typed as { errors?: string } but the Shopify API may return errors as an object, causing [object Object] to appear in error messages instead of meaningful error text.
View Details
📝 Patch Details
diff --git a/plugins/shopify/steps/get-order.ts b/plugins/shopify/steps/get-order.ts
index 5b35ea2..6cef3ca 100644
--- a/plugins/shopify/steps/get-order.ts
+++ b/plugins/shopify/steps/get-order.ts
@@ -140,10 +140,14 @@ async function stepHandler(
});
if (!response.ok) {
- const errorData = (await response.json()) as { errors?: string };
+ const errorData = (await response.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
- error: errorData.errors || `HTTP ${response.status}`,
+ error: errorMessage || `HTTP ${response.status}`,
};
}
diff --git a/plugins/shopify/steps/list-orders.ts b/plugins/shopify/steps/list-orders.ts
index 01943ae..7e858ef 100644
--- a/plugins/shopify/steps/list-orders.ts
+++ b/plugins/shopify/steps/list-orders.ts
@@ -132,10 +132,14 @@ async function stepHandler(
});
if (!response.ok) {
- const errorData = (await response.json()) as { errors?: string };
+ const errorData = (await response.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
- error: errorData.errors || `HTTP ${response.status}`,
+ error: errorMessage || `HTTP ${response.status}`,
};
}
diff --git a/plugins/shopify/steps/update-inventory.ts b/plugins/shopify/steps/update-inventory.ts
index 1a90d68..58d907b 100644
--- a/plugins/shopify/steps/update-inventory.ts
+++ b/plugins/shopify/steps/update-inventory.ts
@@ -83,11 +83,15 @@ async function stepHandler(
});
if (!getResponse.ok) {
- const errorData = (await getResponse.json()) as { errors?: string };
+ const errorData = (await getResponse.json()) as { errors?: unknown };
+ const errorMessage =
+ typeof errorData.errors === "string"
+ ? errorData.errors
+ : JSON.stringify(errorData.errors);
return {
success: false,
error:
- errorData.errors ||
+ errorMessage ||
`Failed to get current inventory: HTTP ${getResponse.status}`,
};
}
Analysis
Incorrect error response type handling in Shopify API steps causes [object Object] in error messages
What fails: Multiple Shopify API steps fail to handle validation errors properly. When the Shopify Admin API returns a 422 error with validation details as nested objects, the error message becomes [object Object] instead of displaying meaningful error information. Affected files:
plugins/shopify/steps/list-orders.ts(line 135)plugins/shopify/steps/get-order.ts(line 143)plugins/shopify/steps/update-inventory.ts(line 86 - first error block only)
How to reproduce: Create/update an order or inventory item with invalid data (e.g., invalid variant ID):
// Call Shopify API with validation error
const response = await fetch(shopifyUrl, {
method: "POST",
headers: { "X-Shopify-Access-Token": token },
body: JSON.stringify({ line_items: [{ variant_id: "invalid" }] })
});When Shopify returns HTTP 422 with nested error objects like:
{
"errors": {
"line_items": {
"0": {
"variant_id": [{ "code": "invalid", "message": "is invalid" }]
}
}
}
}Result: Error message displays [object Object] instead of the actual validation error details
Expected: Error message should display JSON-stringified validation errors per Shopify REST API error documentation. Error responses can contain nested objects for validation errors, not just simple strings.
Root cause: Files typed errors as { errors?: string } and attempted direct string concatenation. The correct approach checks the type and uses JSON.stringify() for objects, matching the pattern already used in create-product.ts and the second error block in update-inventory.ts.
No description provided.