← back to Sku Check Skill
initial scaffold (gitify-all 2026-05-06)
5f2d8841f8674a9782ebb2bf4dde838299c4f707 · 2026-05-06 10:25:48 -0700 · Steve Abrams
Files touched
A .gitignoreA ecosystem.config.jsA package-lock.jsonA package.jsonA public/favicon.svgA public/index.htmlA server.js
Diff
commit 5f2d8841f8674a9782ebb2bf4dde838299c4f707
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Wed May 6 10:25:48 2026 -0700
initial scaffold (gitify-all 2026-05-06)
---
.gitignore | 12 +
ecosystem.config.js | 13 +
package-lock.json | 1027 ++++++++++++++++++++++++++++++++++++++++++++++
package.json | 15 +
public/favicon.svg | 4 +
public/index.html | 648 +++++++++++++++++++++++++++++
server.js | 1132 +++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 2851 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7e6a9c3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,12 @@
+node_modules/
+.env
+.env.local
+.env.*.local
+.env.*
+tmp/
+*.log
+.DS_Store
+dist/
+build/
+.next/
+*.bak
diff --git a/ecosystem.config.js b/ecosystem.config.js
new file mode 100644
index 0000000..7637857
--- /dev/null
+++ b/ecosystem.config.js
@@ -0,0 +1,13 @@
+module.exports = {
+ apps: [{
+ name: 'sku-check-skill',
+ script: 'server.js',
+ cwd: '/root/DW-Agents/sku-check-skill',
+ env: {
+ PORT: 9963,
+ NODE_ENV: 'production'
+ },
+ max_memory_restart: '300M',
+ autorestart: true
+ }]
+};
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..ca02d3f
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,1027 @@
+{
+ "name": "sku-check-skill",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "sku-check-skill",
+ "version": "1.0.0",
+ "dependencies": {
+ "express": "^4.18.2",
+ "helmet": "^8.1.0",
+ "node-fetch": "^2.7.0",
+ "pg": "^8.11.3"
+ }
+ },
+ "node_modules/accepts": {
+ "version": "1.3.8",
+ "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
+ "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-types": "~2.1.34",
+ "negotiator": "0.6.3"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/array-flatten": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
+ "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==",
+ "license": "MIT"
+ },
+ "node_modules/body-parser": {
+ "version": "1.20.4",
+ "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz",
+ "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "content-type": "~1.0.5",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "~1.2.0",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "on-finished": "~2.4.1",
+ "qs": "~6.14.0",
+ "raw-body": "~2.5.3",
+ "type-is": "~1.6.18",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/bytes": {
+ "version": "3.1.2",
+ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
+ "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/call-bind-apply-helpers": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
+ "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/call-bound": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz",
+ "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "get-intrinsic": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/content-disposition": {
+ "version": "0.5.4",
+ "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
+ "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==",
+ "license": "MIT",
+ "dependencies": {
+ "safe-buffer": "5.2.1"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/content-type": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
+ "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie": {
+ "version": "0.7.2",
+ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
+ "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/cookie-signature": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz",
+ "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==",
+ "license": "MIT"
+ },
+ "node_modules/debug": {
+ "version": "2.6.9",
+ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
+ "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
+ "license": "MIT",
+ "dependencies": {
+ "ms": "2.0.0"
+ }
+ },
+ "node_modules/depd": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
+ "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/destroy": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz",
+ "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8",
+ "npm": "1.2.8000 || >= 1.4.16"
+ }
+ },
+ "node_modules/dunder-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
+ "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "gopd": "^1.2.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/ee-first": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
+ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==",
+ "license": "MIT"
+ },
+ "node_modules/encodeurl": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz",
+ "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/es-define-property": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz",
+ "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-errors": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
+ "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/es-object-atoms": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz",
+ "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/escape-html": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
+ "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==",
+ "license": "MIT"
+ },
+ "node_modules/etag": {
+ "version": "1.8.1",
+ "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
+ "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/express": {
+ "version": "4.22.1",
+ "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz",
+ "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==",
+ "license": "MIT",
+ "dependencies": {
+ "accepts": "~1.3.8",
+ "array-flatten": "1.1.1",
+ "body-parser": "~1.20.3",
+ "content-disposition": "~0.5.4",
+ "content-type": "~1.0.4",
+ "cookie": "~0.7.1",
+ "cookie-signature": "~1.0.6",
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "finalhandler": "~1.3.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.0",
+ "merge-descriptors": "1.0.3",
+ "methods": "~1.1.2",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "path-to-regexp": "~0.1.12",
+ "proxy-addr": "~2.0.7",
+ "qs": "~6.14.0",
+ "range-parser": "~1.2.1",
+ "safe-buffer": "5.2.1",
+ "send": "~0.19.0",
+ "serve-static": "~1.16.2",
+ "setprototypeof": "1.2.0",
+ "statuses": "~2.0.1",
+ "type-is": "~1.6.18",
+ "utils-merge": "1.0.1",
+ "vary": "~1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.10.0"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/finalhandler": {
+ "version": "1.3.2",
+ "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz",
+ "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "on-finished": "~2.4.1",
+ "parseurl": "~1.3.3",
+ "statuses": "~2.0.2",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/forwarded": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
+ "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/fresh": {
+ "version": "0.5.2",
+ "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
+ "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/function-bind": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
+ "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-intrinsic": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz",
+ "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bind-apply-helpers": "^1.0.2",
+ "es-define-property": "^1.0.1",
+ "es-errors": "^1.3.0",
+ "es-object-atoms": "^1.1.1",
+ "function-bind": "^1.1.2",
+ "get-proto": "^1.0.1",
+ "gopd": "^1.2.0",
+ "has-symbols": "^1.1.0",
+ "hasown": "^2.0.2",
+ "math-intrinsics": "^1.1.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/get-proto": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz",
+ "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==",
+ "license": "MIT",
+ "dependencies": {
+ "dunder-proto": "^1.0.1",
+ "es-object-atoms": "^1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/gopd": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz",
+ "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/has-symbols": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz",
+ "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/hasown": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz",
+ "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
+ "license": "MIT",
+ "dependencies": {
+ "function-bind": "^1.1.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/helmet": {
+ "version": "8.1.0",
+ "resolved": "https://registry.npmjs.org/helmet/-/helmet-8.1.0.tgz",
+ "integrity": "sha512-jOiHyAZsmnr8LqoPGmCjYAaiuWwjAPLgY8ZX2XrmHawt99/u1y6RgrZMTeoPfpUbV96HOalYgz1qzkRbw54Pmg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=18.0.0"
+ }
+ },
+ "node_modules/http-errors": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz",
+ "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==",
+ "license": "MIT",
+ "dependencies": {
+ "depd": "~2.0.0",
+ "inherits": "~2.0.4",
+ "setprototypeof": "~1.2.0",
+ "statuses": "~2.0.2",
+ "toidentifier": "~1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ },
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/express"
+ }
+ },
+ "node_modules/iconv-lite": {
+ "version": "0.4.24",
+ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
+ "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
+ "license": "MIT",
+ "dependencies": {
+ "safer-buffer": ">= 2.1.2 < 3"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
+ "license": "ISC"
+ },
+ "node_modules/ipaddr.js": {
+ "version": "1.9.1",
+ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
+ "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/math-intrinsics": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
+ "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ }
+ },
+ "node_modules/media-typer": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
+ "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/merge-descriptors": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz",
+ "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==",
+ "license": "MIT",
+ "funding": {
+ "url": "https://github.com/sponsors/sindresorhus"
+ }
+ },
+ "node_modules/methods": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
+ "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
+ "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
+ "license": "MIT",
+ "bin": {
+ "mime": "cli.js"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/mime-db": {
+ "version": "1.52.0",
+ "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
+ "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/mime-types": {
+ "version": "2.1.35",
+ "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
+ "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
+ "license": "MIT",
+ "dependencies": {
+ "mime-db": "1.52.0"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/ms": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
+ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==",
+ "license": "MIT"
+ },
+ "node_modules/negotiator": {
+ "version": "0.6.3",
+ "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz",
+ "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/node-fetch": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
+ "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
+ "license": "MIT",
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/object-inspect": {
+ "version": "1.13.4",
+ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz",
+ "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/on-finished": {
+ "version": "2.4.1",
+ "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz",
+ "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==",
+ "license": "MIT",
+ "dependencies": {
+ "ee-first": "1.1.1"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/parseurl": {
+ "version": "1.3.3",
+ "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
+ "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/path-to-regexp": {
+ "version": "0.1.12",
+ "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz",
+ "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==",
+ "license": "MIT"
+ },
+ "node_modules/pg": {
+ "version": "8.18.0",
+ "resolved": "https://registry.npmjs.org/pg/-/pg-8.18.0.tgz",
+ "integrity": "sha512-xqrUDL1b9MbkydY/s+VZ6v+xiMUmOUk7SS9d/1kpyQxoJ6U9AO1oIJyUWVZojbfe5Cc/oluutcgFG4L9RDP1iQ==",
+ "license": "MIT",
+ "dependencies": {
+ "pg-connection-string": "^2.11.0",
+ "pg-pool": "^3.11.0",
+ "pg-protocol": "^1.11.0",
+ "pg-types": "2.2.0",
+ "pgpass": "1.0.5"
+ },
+ "engines": {
+ "node": ">= 16.0.0"
+ },
+ "optionalDependencies": {
+ "pg-cloudflare": "^1.3.0"
+ },
+ "peerDependencies": {
+ "pg-native": ">=3.0.1"
+ },
+ "peerDependenciesMeta": {
+ "pg-native": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pg-cloudflare": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.3.0.tgz",
+ "integrity": "sha512-6lswVVSztmHiRtD6I8hw4qP/nDm1EJbKMRhf3HCYaqud7frGysPv7FYJ5noZQdhQtN2xJnimfMtvQq21pdbzyQ==",
+ "license": "MIT",
+ "optional": true
+ },
+ "node_modules/pg-connection-string": {
+ "version": "2.11.0",
+ "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.11.0.tgz",
+ "integrity": "sha512-kecgoJwhOpxYU21rZjULrmrBJ698U2RxXofKVzOn5UDj61BPj/qMb7diYUR1nLScCDbrztQFl1TaQZT0t1EtzQ==",
+ "license": "MIT"
+ },
+ "node_modules/pg-int8": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
+ "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
+ "license": "ISC",
+ "engines": {
+ "node": ">=4.0.0"
+ }
+ },
+ "node_modules/pg-pool": {
+ "version": "3.11.0",
+ "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.11.0.tgz",
+ "integrity": "sha512-MJYfvHwtGp870aeusDh+hg9apvOe2zmpZJpyt+BMtzUWlVqbhFmMK6bOBXLBUPd7iRtIF9fZplDc7KrPN3PN7w==",
+ "license": "MIT",
+ "peerDependencies": {
+ "pg": ">=8.0"
+ }
+ },
+ "node_modules/pg-protocol": {
+ "version": "1.11.0",
+ "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.11.0.tgz",
+ "integrity": "sha512-pfsxk2M9M3BuGgDOfuy37VNRRX3jmKgMjcvAcWqNDpZSf4cUmv8HSOl5ViRQFsfARFn0KuUQTgLxVMbNq5NW3g==",
+ "license": "MIT"
+ },
+ "node_modules/pg-types": {
+ "version": "2.2.0",
+ "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
+ "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
+ "license": "MIT",
+ "dependencies": {
+ "pg-int8": "1.0.1",
+ "postgres-array": "~2.0.0",
+ "postgres-bytea": "~1.0.0",
+ "postgres-date": "~1.0.4",
+ "postgres-interval": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/pgpass": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
+ "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
+ "license": "MIT",
+ "dependencies": {
+ "split2": "^4.1.0"
+ }
+ },
+ "node_modules/postgres-array": {
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
+ "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=4"
+ }
+ },
+ "node_modules/postgres-bytea": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz",
+ "integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-date": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
+ "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/postgres-interval": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
+ "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
+ "license": "MIT",
+ "dependencies": {
+ "xtend": "^4.0.0"
+ },
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/proxy-addr": {
+ "version": "2.0.7",
+ "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz",
+ "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==",
+ "license": "MIT",
+ "dependencies": {
+ "forwarded": "0.2.0",
+ "ipaddr.js": "1.9.1"
+ },
+ "engines": {
+ "node": ">= 0.10"
+ }
+ },
+ "node_modules/qs": {
+ "version": "6.14.1",
+ "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.1.tgz",
+ "integrity": "sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==",
+ "license": "BSD-3-Clause",
+ "dependencies": {
+ "side-channel": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=0.6"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/range-parser": {
+ "version": "1.2.1",
+ "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
+ "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/raw-body": {
+ "version": "2.5.3",
+ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz",
+ "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==",
+ "license": "MIT",
+ "dependencies": {
+ "bytes": "~3.1.2",
+ "http-errors": "~2.0.1",
+ "iconv-lite": "~0.4.24",
+ "unpipe": "~1.0.0"
+ },
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/safe-buffer": {
+ "version": "5.2.1",
+ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
+ "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/feross"
+ },
+ {
+ "type": "patreon",
+ "url": "https://www.patreon.com/feross"
+ },
+ {
+ "type": "consulting",
+ "url": "https://feross.org/support"
+ }
+ ],
+ "license": "MIT"
+ },
+ "node_modules/safer-buffer": {
+ "version": "2.1.2",
+ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
+ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
+ "license": "MIT"
+ },
+ "node_modules/send": {
+ "version": "0.19.2",
+ "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz",
+ "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==",
+ "license": "MIT",
+ "dependencies": {
+ "debug": "2.6.9",
+ "depd": "2.0.0",
+ "destroy": "1.2.0",
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "etag": "~1.8.1",
+ "fresh": "~0.5.2",
+ "http-errors": "~2.0.1",
+ "mime": "1.6.0",
+ "ms": "2.1.3",
+ "on-finished": "~2.4.1",
+ "range-parser": "~1.2.1",
+ "statuses": "~2.0.2"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/send/node_modules/ms": {
+ "version": "2.1.3",
+ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
+ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
+ "license": "MIT"
+ },
+ "node_modules/serve-static": {
+ "version": "1.16.3",
+ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz",
+ "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==",
+ "license": "MIT",
+ "dependencies": {
+ "encodeurl": "~2.0.0",
+ "escape-html": "~1.0.3",
+ "parseurl": "~1.3.3",
+ "send": "~0.19.1"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/setprototypeof": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
+ "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
+ "license": "ISC"
+ },
+ "node_modules/side-channel": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz",
+ "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3",
+ "side-channel-list": "^1.0.0",
+ "side-channel-map": "^1.0.1",
+ "side-channel-weakmap": "^1.0.2"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-list": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz",
+ "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==",
+ "license": "MIT",
+ "dependencies": {
+ "es-errors": "^1.3.0",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-map": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz",
+ "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/side-channel-weakmap": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz",
+ "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==",
+ "license": "MIT",
+ "dependencies": {
+ "call-bound": "^1.0.2",
+ "es-errors": "^1.3.0",
+ "get-intrinsic": "^1.2.5",
+ "object-inspect": "^1.13.3",
+ "side-channel-map": "^1.0.1"
+ },
+ "engines": {
+ "node": ">= 0.4"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/ljharb"
+ }
+ },
+ "node_modules/split2": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
+ "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
+ "license": "ISC",
+ "engines": {
+ "node": ">= 10.x"
+ }
+ },
+ "node_modules/statuses": {
+ "version": "2.0.2",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz",
+ "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/toidentifier": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
+ "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.6"
+ }
+ },
+ "node_modules/tr46": {
+ "version": "0.0.3",
+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
+ "license": "MIT"
+ },
+ "node_modules/type-is": {
+ "version": "1.6.18",
+ "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
+ "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
+ "license": "MIT",
+ "dependencies": {
+ "media-typer": "0.3.0",
+ "mime-types": "~2.1.24"
+ },
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
+ "node_modules/unpipe": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
+ "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/utils-merge": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
+ "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.4.0"
+ }
+ },
+ "node_modules/vary": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+ "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==",
+ "license": "MIT",
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
+ "node_modules/webidl-conversions": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
+ "license": "BSD-2-Clause"
+ },
+ "node_modules/whatwg-url": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
+ "license": "MIT",
+ "dependencies": {
+ "tr46": "~0.0.3",
+ "webidl-conversions": "^3.0.0"
+ }
+ },
+ "node_modules/xtend": {
+ "version": "4.0.2",
+ "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
+ "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
+ "license": "MIT",
+ "engines": {
+ "node": ">=0.4"
+ }
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..07ce34f
--- /dev/null
+++ b/package.json
@@ -0,0 +1,15 @@
+{
+ "name": "sku-check-skill",
+ "version": "1.0.0",
+ "description": "SKU Check Skill - Cross-reference DW SKUs with vendor websites",
+ "main": "server.js",
+ "scripts": {
+ "start": "node server.js"
+ },
+ "dependencies": {
+ "express": "^4.18.2",
+ "helmet": "^8.1.0",
+ "node-fetch": "^2.7.0",
+ "pg": "^8.11.3"
+ }
+}
diff --git a/public/favicon.svg b/public/favicon.svg
new file mode 100644
index 0000000..b3e6dbe
--- /dev/null
+++ b/public/favicon.svg
@@ -0,0 +1,4 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
+<rect width="32" height="32" rx="6" fill="#10b981"/>
+<text x="50%" y="55%" text-anchor="middle" dominant-baseline="middle" font-size="20" font-family="Apple Color Emoji, Segoe UI Emoji, sans-serif" fill="white">S</text>
+</svg>
\ No newline at end of file
diff --git a/public/index.html b/public/index.html
new file mode 100644
index 0000000..bb532c0
--- /dev/null
+++ b/public/index.html
@@ -0,0 +1,648 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>SKU Check Skill - Designer Wallcoverings</title>
+ <style>
+ * { box-sizing: border-box; margin: 0; padding: 0; }
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0f1117; color: #e1e4e8; min-height: 100vh; }
+
+ .agent-avatar { width: 56px; height: 56px; border-radius: 50%; border: 2px solid #EC4899; object-fit: cover; }
+ .agent-avatar-fallback { width: 56px; height: 56px; border-radius: 50%; border: 2px solid #EC4899; background: #EC4899; color: #fff; font-size: 22px; font-weight: 700; display: none; align-items: center; justify-content: center; }
+
+ .header { background: linear-gradient(135deg, #1a1f2e 0%, #0d1117 100%); border-bottom: 1px solid #30363d; padding: 16px 24px; display: flex; align-items: center; justify-content: space-between; }
+ .header h1 { font-size: 20px; font-weight: 600; color: #58a6ff; }
+ .header .subtitle { font-size: 13px; color: #8b949e; margin-top: 2px; }
+
+ .container { max-width: 1600px; margin: 0 auto; padding: 20px; }
+
+ .stats-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
+ .stat-card { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 14px 16px; text-align: center; }
+ .stat-card .value { font-size: 28px; font-weight: 700; }
+ .stat-card .label { font-size: 12px; color: #8b949e; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
+ .stat-card.found .value { color: #3fb950; }
+ .stat-card.not-found .value { color: #f85149; }
+ .stat-card.error .value { color: #d29922; }
+ .stat-card.total .value { color: #58a6ff; }
+ .stat-card.tagged .value { color: #bc8cff; }
+
+ .panels { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; margin-bottom: 20px; }
+ @media (max-width: 900px) { .panels { grid-template-columns: 1fr; } }
+ .panel { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 16px; }
+ .panel h3 { font-size: 14px; color: #58a6ff; margin-bottom: 12px; font-weight: 600; }
+ .panel label { display: block; font-size: 12px; color: #8b949e; margin-bottom: 4px; }
+ .panel input, .panel select { width: 100%; padding: 8px 10px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: #e1e4e8; font-size: 14px; margin-bottom: 10px; }
+ .panel input:focus, .panel select:focus { border-color: #58a6ff; outline: none; }
+ .row { display: flex; gap: 8px; }
+ .row input { flex: 1; }
+
+ .btn { padding: 6px 12px; border: none; border-radius: 5px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
+ .btn-primary { background: #238636; color: #fff; }
+ .btn-primary:hover { background: #2ea043; }
+ .btn-danger { background: #da3633; color: #fff; }
+ .btn-danger:hover { background: #f85149; }
+ .btn-secondary { background: #30363d; color: #e1e4e8; }
+ .btn-secondary:hover { background: #484f58; }
+ .btn-sm { padding: 3px 8px; font-size: 11px; }
+ .btn:disabled { opacity: 0.5; cursor: not-allowed; }
+
+ /* Action button colors */
+ .btn-specs { background: #0d9488; color: #fff; }
+ .btn-specs:hover { background: #14b8a6; }
+ .btn-images { background: #2563eb; color: #fff; }
+ .btn-images:hover { background: #3b82f6; }
+ .btn-ai { background: #7c3aed; color: #fff; }
+ .btn-ai:hover { background: #8b5cf6; }
+ .btn-tags { background: #d97706; color: #fff; }
+ .btn-tags:hover { background: #f59e0b; }
+ .btn-meta { background: #4f46e5; color: #fff; }
+ .btn-meta:hover { background: #6366f1; }
+ .btn-title { background: #16a34a; color: #fff; }
+ .btn-title:hover { background: #22c55e; }
+ .btn-sample { background: #db2777; color: #fff; }
+ .btn-sample:hover { background: #ec4899; }
+ .btn-all { background: #dc2626; color: #fff; font-weight: 700; }
+ .btn-all:hover { background: #ef4444; }
+ .btn-vendor { background: #0891b2; color: #fff; }
+ .btn-vendor:hover { background: #06b6d4; }
+
+ .job-bar { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 14px 16px; margin-bottom: 20px; display: none; }
+ .job-bar.active { display: block; }
+ .job-bar .job-title { font-size: 14px; font-weight: 600; color: #58a6ff; margin-bottom: 8px; }
+ .progress-track { height: 6px; background: #21262d; border-radius: 3px; overflow: hidden; }
+ .progress-fill { height: 100%; background: #238636; border-radius: 3px; transition: width 0.3s; }
+ .job-stats { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; color: #8b949e; }
+ .job-stats span { display: flex; align-items: center; gap: 4px; }
+ .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
+ .dot.green { background: #3fb950; }
+ .dot.red { background: #f85149; }
+ .dot.yellow { background: #d29922; }
+
+ .filters { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
+ .filters select, .filters input { padding: 6px 10px; background: #0d1117; border: 1px solid #30363d; border-radius: 6px; color: #e1e4e8; font-size: 13px; }
+
+ /* Bulk action bar */
+ .bulk-bar { background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%); border: 1px solid #334155; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
+ .bulk-bar .bulk-label { font-size: 13px; font-weight: 600; color: #94a3b8; }
+
+ .table-wrap { background: #161b22; border: 1px solid #30363d; border-radius: 8px; overflow-x: auto; }
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
+ thead th { background: #21262d; padding: 10px 12px; text-align: left; font-weight: 600; color: #8b949e; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #30363d; white-space: nowrap; }
+ tbody td { padding: 8px 10px; border-bottom: 1px solid #21262d; vertical-align: top; }
+ tbody tr:hover { background: #1c2128; }
+ .status-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; text-transform: uppercase; }
+ .status-found { background: rgba(63, 185, 80, 0.15); color: #3fb950; }
+ .status-not_found { background: rgba(248, 81, 73, 0.15); color: #f85149; }
+ .status-error { background: rgba(210, 153, 34, 0.15); color: #d29922; }
+ .status-pending { background: rgba(139, 148, 158, 0.15); color: #8b949e; }
+
+ a { color: #58a6ff; text-decoration: none; }
+ a:hover { text-decoration: underline; }
+
+ .empty-state { text-align: center; padding: 40px 20px; color: #8b949e; }
+ .empty-state h3 { font-size: 16px; margin-bottom: 8px; color: #e1e4e8; }
+
+ /* Action button row */
+ .action-btns { display: flex; gap: 3px; flex-wrap: wrap; max-width: 500px; }
+
+ /* Detail panel that slides open below a row */
+ .detail-row td { padding: 0 !important; border: none !important; }
+ .detail-panel { background: #1c2128; border: 1px solid #30363d; border-radius: 0 0 8px 8px; margin: 0 8px 8px 8px; padding: 16px; display: none; }
+ .detail-panel.open { display: block; animation: slideDown 0.2s ease-out; }
+ @keyframes slideDown { from { opacity: 0; max-height: 0; } to { opacity: 1; max-height: 600px; } }
+ .detail-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
+ @media (max-width: 1200px) { .detail-grid { grid-template-columns: 1fr 1fr; } }
+ .detail-section { background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 12px; }
+ .detail-section h4 { font-size: 12px; color: #58a6ff; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
+ .detail-section .field { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; border-bottom: 1px solid #21262d; }
+ .detail-section .field .fk { color: #8b949e; }
+ .detail-section .field .fv { color: #e1e4e8; font-weight: 500; text-align: right; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
+ .detail-images { display: flex; gap: 8px; flex-wrap: wrap; }
+ .detail-images img { width: 80px; height: 80px; object-fit: cover; border-radius: 4px; border: 1px solid #30363d; cursor: pointer; }
+ .detail-images img:hover { border-color: #58a6ff; }
+ .ai-tag { display: inline-block; padding: 2px 6px; background: rgba(124, 58, 237, 0.2); color: #a78bfa; border-radius: 4px; font-size: 11px; margin: 2px; }
+ .ai-color { display: inline-block; padding: 2px 6px; background: rgba(59, 130, 246, 0.2); color: #93c5fd; border-radius: 4px; font-size: 11px; margin: 2px; }
+ .step-status { display: inline-block; font-size: 11px; margin-left: 4px; }
+ .step-ok { color: #3fb950; }
+ .step-fail { color: #f85149; }
+ .step-spin { color: #d29922; }
+ .spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #30363d; border-top-color: #58a6ff; border-radius: 50%; animation: spin 0.6s linear infinite; }
+ @keyframes spin { to { transform: rotate(360deg); } }
+
+ .toast { position: fixed; bottom: 20px; right: 20px; background: #238636; color: #fff; padding: 10px 20px; border-radius: 8px; font-size: 13px; display: none; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,0.4); max-width: 400px; }
+ .toast.error { background: #da3633; }
+ .toast.show { display: block; animation: fadeIn 0.3s; }
+ @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
+
+ .pagination { display: flex; justify-content: center; gap: 8px; margin-top: 12px; padding: 12px; }
+ </style>
+</head>
+<body>
+ <div class="header">
+ <img class="agent-avatar" src="http://45.61.58.125/agent-avatars/the-stager.png" onerror="this.style.display='none';this.nextElementSibling.style.display='flex'">
+ <div class="agent-avatar-fallback">S</div>
+ <div>
+ <h1>SKU Check Skill</h1>
+ <div class="subtitle">Cross-reference DW SKUs with vendor websites • Fetch specs, AI analysis, update Shopify</div>
+ </div>
+ <div style="display: flex; gap: 8px;">
+ <button class="btn btn-secondary btn-sm" onclick="loadStats()">Refresh Stats</button>
+ </div>
+ </div>
+
+ <div class="container">
+ <div class="stats-bar" id="statsBar">
+ <div class="stat-card total"><div class="value" id="statTotal">0</div><div class="label">Total Checked</div></div>
+ <div class="stat-card found"><div class="value" id="statFound">0</div><div class="label">Found</div></div>
+ <div class="stat-card not-found"><div class="value" id="statNotFound">0</div><div class="label">Not Found</div></div>
+ <div class="stat-card error"><div class="value" id="statErrors">0</div><div class="label">Errors</div></div>
+ <div class="stat-card tagged"><div class="value" id="statTagged">0</div><div class="label">Tagged Review</div></div>
+ </div>
+
+ <div class="panels">
+ <div class="panel">
+ <h3>Check Single SKU</h3>
+ <label>DW SKU (e.g. GGA-82668)</label>
+ <input type="text" id="singleSku" placeholder="GGA-82668" />
+ <button class="btn btn-primary" onclick="checkSingle()" id="btnSingle">Check SKU</button>
+ </div>
+ <div class="panel">
+ <h3>Check Range</h3>
+ <label>Prefix (e.g. GGA)</label>
+ <input type="text" id="rangePrefix" placeholder="GGA" />
+ <div class="row">
+ <div><label>From</label><input type="number" id="rangeFrom" placeholder="82000" /></div>
+ <div><label>To</label><input type="number" id="rangeTo" placeholder="83000" /></div>
+ </div>
+ <button class="btn btn-primary" onclick="checkRange()" id="btnRange">Check Range</button>
+ </div>
+ <div class="panel">
+ <h3>Check by Vendor</h3>
+ <label>Vendor</label>
+ <select id="vendorSelect"><option value="">Loading vendors...</option></select>
+ <label>Limit</label>
+ <input type="number" id="vendorLimit" value="500" placeholder="500" />
+ <button class="btn btn-primary" onclick="checkVendor()" id="btnVendor">Check Vendor</button>
+ </div>
+ </div>
+
+ <div class="job-bar" id="jobBar">
+ <div class="job-title" id="jobTitle">Processing...</div>
+ <div class="progress-track"><div class="progress-fill" id="jobProgress" style="width:0%"></div></div>
+ <div class="job-stats">
+ <span><span class="dot green"></span> Found: <b id="jobFound">0</b></span>
+ <span><span class="dot red"></span> Not Found: <b id="jobNotFound">0</b></span>
+ <span><span class="dot yellow"></span> Errors: <b id="jobErrors">0</b></span>
+ <span>Progress: <b id="jobChecked">0</b>/<b id="jobTotal">0</b></span>
+ <button class="btn btn-danger btn-sm" onclick="stopJob()">Stop</button>
+ </div>
+ </div>
+
+ <div class="filters">
+ <select id="filterStatus" onchange="loadResults()">
+ <option value="">All Statuses</option>
+ <option value="found">Found</option>
+ <option value="not_found">Not Found</option>
+ <option value="error">Error</option>
+ </select>
+ <select id="filterVendor" onchange="loadResults()">
+ <option value="">All Vendors</option>
+ </select>
+ <button class="btn btn-secondary btn-sm" onclick="loadResults()">Refresh</button>
+ </div>
+
+ <!-- Bulk actions -->
+ <div class="bulk-bar">
+ <span class="bulk-label">Bulk:</span>
+ <button class="btn btn-all btn-sm" onclick="bulkRunAll()">Run ALL on Visible</button>
+ <button class="btn btn-specs btn-sm" onclick="bulkAction('fetch-specs')">Fetch All Specs</button>
+ <button class="btn btn-ai btn-sm" onclick="bulkAction('ai-analyze')">AI All</button>
+ <button class="btn btn-tags btn-sm" onclick="bulkAction('update-tags')">Tags All</button>
+ <button class="btn btn-meta btn-sm" onclick="bulkAction('update-metafields')">Meta All</button>
+ <button class="btn btn-sample btn-sm" onclick="bulkAction('fix-sample')">Fix All Samples</button>
+ <span id="bulkProgress" style="font-size:12px;color:#8b949e;margin-left:8px;"></span>
+ </div>
+
+ <div class="table-wrap">
+ <table>
+ <thead>
+ <tr>
+ <th>DW SKU</th>
+ <th>MFR SKU</th>
+ <th>Vendor</th>
+ <th>Status</th>
+ <th>Actions</th>
+ </tr>
+ </thead>
+ <tbody id="resultsBody">
+ <tr><td colspan="5" class="empty-state"><h3>No results yet</h3>Check a SKU, range, or vendor to get started</td></tr>
+ </tbody>
+ </table>
+ </div>
+
+ <div class="pagination" id="pagination"></div>
+ </div>
+
+ <div class="toast" id="toast"></div>
+
+ <script>
+function xfetch(url,opts){return new Promise(function(resolve,reject){var x=new XMLHttpRequest();x.open((opts&&opts.method)||"GET",url,true);x.setRequestHeader("Authorization","Basic "+btoa("admin:DWSecure2024!"));if(opts&&opts.body){x.setRequestHeader("Content-Type","application/json");}x.onload=function(){try{resolve({ok:x.status>=200&&x.status<300,status:x.status,json:function(){return Promise.resolve(JSON.parse(x.responseText))},text:function(){return Promise.resolve(x.responseText)}})}catch(e){reject(e)}};x.onerror=function(){reject(new Error("XHR failed"))};x.send(opts&&opts.body?JSON.stringify(opts.body):null)})};
+ const API = '';
+ let currentPage = 0;
+ const PAGE_SIZE = 50;
+ let jobPollInterval = null;
+ let currentResults = [];
+
+ function showToast(msg, isError) {
+ const t = document.getElementById('toast');
+ t.textContent = msg;
+ t.className = 'toast show' + (isError ? ' error' : '');
+ setTimeout(() => t.className = 'toast', 4000);
+ }
+
+ async function api(method, path, body) {
+ const opts = { method, headers: { 'Content-Type': 'application/json' } };
+ if (body) opts.body = JSON.stringify(body);
+ const r = await xfetch(API + path, opts);
+ return r.json();
+ }
+
+ async function loadStats() {
+ try {
+ const data = await api('GET', '/api/stats');
+ if (data.overall) {
+ document.getElementById('statTotal').textContent = data.overall.total || 0;
+ document.getElementById('statFound').textContent = data.overall.found || 0;
+ document.getElementById('statNotFound').textContent = data.overall.not_found || 0;
+ document.getElementById('statErrors').textContent = data.overall.errors || 0;
+ document.getElementById('statTagged').textContent = data.overall.tagged || 0;
+ }
+ } catch (e) { console.error('Stats error:', e); }
+ }
+
+ async function loadVendors() {
+ try {
+ const data = await api('GET', '/api/vendors');
+ const sel = document.getElementById('vendorSelect');
+ const filter = document.getElementById('filterVendor');
+ sel.innerHTML = '<option value="">Select vendor...</option>';
+ data.forEach(v => {
+ sel.innerHTML += `<option value="${v.vendor_code}">${v.vendor_name || v.vendor_code} (${v.sku_count})</option>`;
+ filter.innerHTML += `<option value="${v.vendor_code}">${v.vendor_name || v.vendor_code}</option>`;
+ });
+ } catch (e) { console.error('Vendors error:', e); }
+ }
+
+ async function loadResults() {
+ const status = document.getElementById('filterStatus').value;
+ const vendor = document.getElementById('filterVendor').value;
+ let qs = `?limit=${PAGE_SIZE}&offset=${currentPage * PAGE_SIZE}`;
+ if (status) qs += `&status=${status}`;
+ if (vendor) qs += `&vendor=${vendor}`;
+
+ try {
+ const data = await api('GET', '/api/results' + qs);
+ currentResults = data.results || [];
+ const tbody = document.getElementById('resultsBody');
+
+ if (!data.results || data.results.length === 0) {
+ tbody.innerHTML = '<tr><td colspan="5" class="empty-state"><h3>No results</h3>Check a SKU to get started</td></tr>';
+ document.getElementById('pagination').innerHTML = '';
+ return;
+ }
+
+ tbody.innerHTML = data.results.map((r, idx) => `
+ <tr id="row-${r.dw_sku}">
+ <td>
+ <strong style="font-size:14px">${r.dw_sku_dash || r.dw_sku}</strong>
+ ${r.shopify_handle ? `<br><a href="https://www.designerwallcoverings.com/products/${r.shopify_handle}" target="_blank" style="font-size:11px">View on site</a>` : ''}
+ ${r.shopify_product_id ? `<br><a href="https://admin.shopify.com/store/designer-laboratory-sandbox/products/${r.shopify_product_id}" target="_blank" style="font-size:11px;color:#d29922">Admin</a>` : ''}
+ ${r.vendor_url ? `<br><a href="${r.vendor_url}" target="_blank" style="font-size:11px;color:#0891b2" title="View ${r.mfr_sku} on manufacturer website">MFR Site</a>` : ''}
+ </td>
+ <td>
+ <span style="font-weight:600">${r.mfr_sku || '-'}</span>
+ <br><span style="font-size:11px;color:#8b949e">${r.checked_at ? new Date(r.checked_at).toLocaleDateString() : ''}</span>
+ </td>
+ <td>
+ ${r.vendor_name || r.vendor_code || '-'}
+ <br><a href="#" onclick="openVendorSite('${r.dw_sku}');return false" style="font-size:11px" class="btn-vendor-link">Vendor Site</a>
+ </td>
+ <td><span class="status-badge status-${r.check_status}">${r.check_status}</span></td>
+ <td>
+ <div class="action-btns">
+ <button class="btn btn-specs btn-sm" onclick="doAction('fetch-specs','${r.dw_sku}')" title="Fetch specs from vendor catalog">Specs</button>
+ <button class="btn btn-images btn-sm" onclick="doAction('fetch-images','${r.dw_sku}')" title="Fetch images from catalog">Imgs</button>
+ <button class="btn btn-ai btn-sm" onclick="doAction('ai-analyze','${r.dw_sku}')" title="Run Gemini AI analysis">AI</button>
+ <button class="btn btn-tags btn-sm" onclick="doAction('update-tags','${r.dw_sku}')" title="Update Shopify tags">Tags</button>
+ <button class="btn btn-meta btn-sm" onclick="doAction('update-metafields','${r.dw_sku}')" title="Push metafields to Shopify">Meta</button>
+ <button class="btn btn-title btn-sm" onclick="doAction('fix-title','${r.dw_sku}')" title="Fix title format">Title</button>
+ <button class="btn btn-sample btn-sm" onclick="doAction('fix-sample','${r.dw_sku}')" title="Fix sample variant $4.25">Sample</button>
+ <button class="btn btn-all btn-sm" onclick="doAction('run-all','${r.dw_sku}')" title="Run full pipeline">ALL</button>
+ ${r.check_status === 'not_found' && !r.tagged_review ? `<button class="btn btn-danger btn-sm" onclick="tagReview('${r.dw_sku}')">Review</button>` : ''}
+ ${r.tagged_review ? '<span style="color:#bc8cff;font-size:10px">Tagged</span>' : ''}
+ </div>
+ <div id="detail-${r.dw_sku}" class="detail-panel"></div>
+ </td>
+ </tr>
+ `).join('');
+
+ const totalPages = Math.ceil(data.total / PAGE_SIZE);
+ const pag = document.getElementById('pagination');
+ if (totalPages > 1) {
+ let html = '';
+ if (currentPage > 0) html += `<button class="btn btn-secondary btn-sm" onclick="goPage(${currentPage - 1})">Prev</button>`;
+ html += `<span style="font-size:13px;color:#8b949e">Page ${currentPage + 1} of ${totalPages} (${data.total} total)</span>`;
+ if (currentPage < totalPages - 1) html += `<button class="btn btn-secondary btn-sm" onclick="goPage(${currentPage + 1})">Next</button>`;
+ pag.innerHTML = html;
+ } else {
+ pag.innerHTML = data.total > 0 ? `<span style="font-size:13px;color:#8b949e">${data.total} results</span>` : '';
+ }
+ } catch (e) { console.error('Results error:', e); }
+ }
+
+ function goPage(p) { currentPage = p; loadResults(); }
+
+ // === ACTION HANDLER ===
+ async function doAction(action, dwSku) {
+ const panel = document.getElementById(`detail-${dwSku}`);
+ panel.classList.add('open');
+ panel.innerHTML = `<div style="text-align:center;padding:16px"><span class="spinner"></span> Running ${action}...</div>`;
+
+ try {
+ const data = await api('POST', `/api/action/${action}`, { dw_sku: dwSku });
+
+ if (action === 'run-all') {
+ panel.innerHTML = renderRunAllResult(data, dwSku);
+ } else if (action === 'fetch-specs') {
+ panel.innerHTML = renderSpecsResult(data);
+ } else if (action === 'fetch-images') {
+ panel.innerHTML = renderImagesResult(data);
+ } else if (action === 'ai-analyze') {
+ panel.innerHTML = renderAiResult(data);
+ } else if (action === 'update-tags') {
+ panel.innerHTML = renderTagsResult(data);
+ } else if (action === 'update-metafields') {
+ panel.innerHTML = renderMetaResult(data);
+ } else if (action === 'fix-title') {
+ panel.innerHTML = renderTitleResult(data);
+ } else if (action === 'fix-sample') {
+ panel.innerHTML = renderSampleResult(data);
+ } else {
+ panel.innerHTML = `<pre style="font-size:11px;color:#8b949e;white-space:pre-wrap">${JSON.stringify(data, null, 2)}</pre>`;
+ }
+
+ if (data.error) showToast(`${action}: ${data.error}`, true);
+ else showToast(`${action} done for ${dwSku}`);
+ } catch (e) {
+ panel.innerHTML = `<div style="color:#f85149;padding:8px">Error: ${e.message}</div>`;
+ showToast(e.message, true);
+ }
+ }
+
+ function renderSpecsResult(data) {
+ if (!data.specs) return `<div style="color:#f85149;padding:8px">${data.message || 'No specs found'}</div>`;
+ const s = data.specs;
+ const fields = [
+ ['Pattern', s.patternName], ['Color', s.colorName], ['Collection', s.collection],
+ ['Width', s.width], ['Length', s.length], ['Repeat', s.repeat],
+ ['Composition', s.composition], ['Backing', s.backing], ['Fire Rating', s.fireRating],
+ ['Match', s.matchType], ['Country', s.country],
+ ['Retail', s.retailPrice], ['Trade', s.tradePrice], ['Cost', s.costPrice],
+ ].filter(([,v]) => v);
+ let html = `<div class="detail-section"><h4>Specs from Catalog</h4>`;
+ fields.forEach(([k,v]) => { html += `<div class="field"><span class="fk">${k}</span><span class="fv">${v}</span></div>`; });
+ if (s.productUrl) html += `<div style="margin-top:8px"><a href="${s.productUrl}" target="_blank" style="font-size:11px">View on vendor site</a></div>`;
+ if (s.imageUrl) html += `<div style="margin-top:8px"><img src="${s.imageUrl}" style="max-width:120px;border-radius:4px;border:1px solid #30363d" /></div>`;
+ html += `</div>`;
+ return html;
+ }
+
+ function renderImagesResult(data) {
+ if (!data.images || data.images.length === 0) return `<div style="color:#8b949e;padding:8px">${data.message || 'No images found'}</div>`;
+ let html = `<div class="detail-section"><h4>Images (${data.images.length})</h4><div class="detail-images">`;
+ data.images.forEach(url => { html += `<a href="${url}" target="_blank"><img src="${url}" /></a>`; });
+ html += '</div>';
+ if (data.productUrl) html += `<div style="margin-top:8px"><a href="${data.productUrl}" target="_blank" style="font-size:11px">Vendor product page</a></div>`;
+ html += '</div>';
+ return html;
+ }
+
+ function renderAiResult(data) {
+ if (!data.analysis) return `<div style="color:#f85149;padding:8px">${data.message || 'AI analysis failed'}</div>`;
+ const a = data.analysis;
+ let html = `<div class="detail-section"><h4>AI Analysis (Gemini)</h4>`;
+ html += `<div class="field"><span class="fk">Background</span><span class="fv">${a.backgroundColor || '-'}</span></div>`;
+ html += `<div class="field"><span class="fk">Material</span><span class="fv">${a.material || '-'}</span></div>`;
+ if (a.colors) html += `<div style="margin:6px 0"><span class="fk" style="font-size:11px">Colors: </span>${a.colors.map(c => `<span class="ai-color">${c}</span>`).join('')}</div>`;
+ if (a.styles) html += `<div style="margin:4px 0"><span class="fk" style="font-size:11px">Styles: </span>${a.styles.map(s => `<span class="ai-tag">${s}</span>`).join('')}</div>`;
+ if (a.patterns) html += `<div style="margin:4px 0"><span class="fk" style="font-size:11px">Patterns: </span>${a.patterns.map(p => `<span class="ai-tag">${p}</span>`).join('')}</div>`;
+ if (a.tags) html += `<div style="margin:4px 0"><span class="fk" style="font-size:11px">Tags: </span>${a.tags.map(t => `<span class="ai-tag">${t}</span>`).join('')}</div>`;
+ if (a.description) html += `<div style="margin-top:8px;font-size:12px;color:#d1d5db;line-height:1.4">${a.description}</div>`;
+ html += '</div>';
+ return html;
+ }
+
+ function renderTagsResult(data) {
+ let html = `<div class="detail-section"><h4>Tags Updated</h4>`;
+ if (data.error) { html += `<div style="color:#f85149">${data.error}</div>`; }
+ else { html += `<div class="field"><span class="fk">Total Tags</span><span class="fv">${data.tagCount || 0}</span></div>`; }
+ html += `<div style="margin-top:4px;font-size:11px;color:#8b949e">${data.message || ''}</div></div>`;
+ return html;
+ }
+
+ function renderMetaResult(data) {
+ let html = `<div class="detail-section"><h4>Metafields</h4>`;
+ if (data.error) { html += `<div style="color:#f85149">${data.error}</div>`; }
+ else { html += `<div class="field"><span class="fk">Set</span><span class="fv" style="color:#3fb950">${data.metafieldsSet}/${data.total}</span></div>`; }
+ html += `<div style="margin-top:4px;font-size:11px;color:#8b949e">${data.message || ''}</div></div>`;
+ return html;
+ }
+
+ function renderTitleResult(data) {
+ let html = `<div class="detail-section"><h4>Title</h4>`;
+ if (data.error) { html += `<div style="color:#f85149">${data.error}</div>`; }
+ else {
+ html += `<div class="field"><span class="fk">Old</span><span class="fv" style="color:#f85149">${data.oldTitle || '-'}</span></div>`;
+ html += `<div class="field"><span class="fk">New</span><span class="fv" style="color:#3fb950">${data.newTitle || '-'}</span></div>`;
+ }
+ html += '</div>';
+ return html;
+ }
+
+ function renderSampleResult(data) {
+ let html = `<div class="detail-section"><h4>Sample Variant</h4>`;
+ if (data.error) { html += `<div style="color:#f85149">${data.error}</div>`; }
+ else {
+ if (data.oldVariant) html += `<div class="field"><span class="fk">Was</span><span class="fv">${data.oldVariant.title} @ $${data.oldVariant.price}</span></div>`;
+ if (data.newVariant) html += `<div class="field"><span class="fk">Now</span><span class="fv" style="color:#3fb950">${data.newVariant.title} @ $${data.newVariant.price} (${data.newVariant.sku})</span></div>`;
+ html += `<div style="font-size:11px;color:#8b949e;margin-top:4px">${data.message || ''}</div>`;
+ }
+ html += '</div>';
+ return html;
+ }
+
+ function renderRunAllResult(data, dwSku) {
+ if (data.error) return `<div style="color:#f85149;padding:8px">${data.error}</div>`;
+ const steps = data.steps || {};
+ let html = `<div class="detail-grid">`;
+
+ // Specs
+ html += `<div class="detail-section"><h4>Specs ${steps.specs?.done ? '<span class="step-status step-ok">OK</span>' : '<span class="step-status step-fail">MISS</span>'}</h4>`;
+ if (steps.specs?.data) {
+ const s = steps.specs.data;
+ [['Pattern', s.patternName], ['Color', s.colorName], ['Collection', s.collection], ['Width', s.width], ['Repeat', s.repeat]].filter(([,v]) => v).forEach(([k,v]) => {
+ html += `<div class="field"><span class="fk">${k}</span><span class="fv">${v}</span></div>`;
+ });
+ } else { html += `<div style="color:#8b949e;font-size:11px">${steps.specs?.message || 'No data'}</div>`; }
+ html += '</div>';
+
+ // AI
+ html += `<div class="detail-section"><h4>AI ${steps.ai?.done ? '<span class="step-status step-ok">OK</span>' : '<span class="step-status step-fail">MISS</span>'}</h4>`;
+ if (steps.ai?.data) {
+ const a = steps.ai.data;
+ if (a.backgroundColor) html += `<div class="field"><span class="fk">BG</span><span class="fv">${a.backgroundColor}</span></div>`;
+ if (a.colors) html += `<div style="margin:4px 0">${a.colors.map(c => `<span class="ai-color">${c}</span>`).join('')}</div>`;
+ if (a.styles) html += `<div style="margin:4px 0">${a.styles.map(s => `<span class="ai-tag">${s}</span>`).join('')}</div>`;
+ if (a.description) html += `<div style="font-size:11px;color:#d1d5db;margin-top:4px">${a.description.substring(0,150)}...</div>`;
+ } else { html += `<div style="color:#8b949e;font-size:11px">${steps.ai?.message || 'No data'}</div>`; }
+ html += '</div>';
+
+ // Updates summary
+ html += `<div class="detail-section"><h4>Updates</h4>`;
+ html += `<div class="field"><span class="fk">Title</span><span class="fv">${steps.title?.done ? '<span class="step-ok">Updated</span>' : '<span class="step-fail">Failed</span>'}</span></div>`;
+ html += `<div class="field"><span class="fk">Tags</span><span class="fv">${steps.tags?.count || 0} tags</span></div>`;
+ html += `<div class="field"><span class="fk">Metafields</span><span class="fv">${steps.metafields?.set || 0}/${steps.metafields?.total || 0}</span></div>`;
+ html += `<div class="field"><span class="fk">Sample</span><span class="fv">${steps.sample?.done ? '<span class="step-ok">OK</span>' : '<span class="step-fail">Failed</span>'}</span></div>`;
+ if (steps.title?.newTitle) html += `<div style="font-size:11px;color:#3fb950;margin-top:6px">${steps.title.newTitle}</div>`;
+ html += '</div>';
+
+ html += '</div>';
+ html += `<div style="text-align:center;margin-top:8px;font-size:12px;color:#3fb950;font-weight:600">${data.summary || 'Complete'}</div>`;
+ return html;
+ }
+
+ // Open vendor website for a SKU
+ async function openVendorSite(dwSku) {
+ try {
+ const data = await api('POST', '/api/action/vendor-url', { dw_sku: dwSku });
+ if (data.searchUrl) window.open(data.searchUrl, '_blank');
+ else if (data.vendorWebsite) window.open(data.vendorWebsite, '_blank');
+ else showToast('No vendor URL found', true);
+ } catch (e) { showToast(e.message, true); }
+ }
+
+ // Bulk actions
+ async function bulkRunAll() {
+ if (currentResults.length === 0) return showToast('No results to process', true);
+ const prog = document.getElementById('bulkProgress');
+ prog.textContent = `Processing 0/${currentResults.length}...`;
+ for (let i = 0; i < currentResults.length; i++) {
+ prog.textContent = `Processing ${i + 1}/${currentResults.length}...`;
+ await doAction('run-all', currentResults[i].dw_sku);
+ await new Promise(r => setTimeout(r, 500));
+ }
+ prog.textContent = `Done! ${currentResults.length} processed`;
+ showToast(`Bulk Run ALL complete: ${currentResults.length} SKUs`);
+ }
+
+ async function bulkAction(action) {
+ if (currentResults.length === 0) return showToast('No results to process', true);
+ const prog = document.getElementById('bulkProgress');
+ for (let i = 0; i < currentResults.length; i++) {
+ prog.textContent = `${action} ${i + 1}/${currentResults.length}...`;
+ await doAction(action, currentResults[i].dw_sku);
+ await new Promise(r => setTimeout(r, 300));
+ }
+ prog.textContent = `Done! ${currentResults.length} processed`;
+ showToast(`Bulk ${action} complete`);
+ }
+
+ // Existing functions
+ async function checkSingle() {
+ const sku = document.getElementById('singleSku').value.trim();
+ if (!sku) return showToast('Enter a DW SKU', true);
+ document.getElementById('btnSingle').disabled = true;
+ document.getElementById('btnSingle').textContent = 'Checking...';
+ try {
+ const data = await api('POST', '/api/check/sku', { dw_sku: sku });
+ if (data.error) showToast(data.error, true);
+ else {
+ const st = data.result?.check_status || data.vendorCheck?.status;
+ showToast(`${sku}: ${st?.toUpperCase()} (MFR: ${data.crossref?.mfr_sku})`);
+ loadResults(); loadStats();
+ }
+ } catch (e) { showToast('Error: ' + e.message, true); }
+ document.getElementById('btnSingle').disabled = false;
+ document.getElementById('btnSingle').textContent = 'Check SKU';
+ }
+
+ async function checkRange() {
+ const prefix = document.getElementById('rangePrefix').value.trim();
+ const from = parseInt(document.getElementById('rangeFrom').value);
+ const to = parseInt(document.getElementById('rangeTo').value);
+ if (!prefix || !from || !to) return showToast('Fill in prefix, from, and to', true);
+ try {
+ const data = await api('POST', '/api/check/range', { prefix, from, to });
+ if (data.error) return showToast(data.error, true);
+ showToast(`Job started: ${data.total} SKUs`);
+ startJobPolling();
+ } catch (e) { showToast('Error: ' + e.message, true); }
+ }
+
+ async function checkVendor() {
+ const vendor_code = document.getElementById('vendorSelect').value;
+ const limit = parseInt(document.getElementById('vendorLimit').value) || 500;
+ if (!vendor_code) return showToast('Select a vendor', true);
+ try {
+ const data = await api('POST', '/api/check/vendor', { vendor_code, limit });
+ if (data.error) return showToast(data.error, true);
+ showToast(`Job started: ${data.total} SKUs`);
+ startJobPolling();
+ } catch (e) { showToast('Error: ' + e.message, true); }
+ }
+
+ function startJobPolling() {
+ document.getElementById('jobBar').classList.add('active');
+ if (jobPollInterval) clearInterval(jobPollInterval);
+ jobPollInterval = setInterval(pollJob, 2000);
+ pollJob();
+ }
+
+ async function pollJob() {
+ try {
+ const data = await api('GET', '/api/job');
+ if (data.status === 'idle') { clearInterval(jobPollInterval); document.getElementById('jobBar').classList.remove('active'); loadResults(); loadStats(); return; }
+ document.getElementById('jobTitle').textContent = `${data.type === 'vendor' ? 'Vendor' : 'Range'} Check: ${data.vendor_code || data.prefix || ''}`;
+ document.getElementById('jobFound').textContent = data.found || 0;
+ document.getElementById('jobNotFound').textContent = data.notFound || 0;
+ document.getElementById('jobErrors').textContent = data.errors || 0;
+ document.getElementById('jobChecked').textContent = data.checked || 0;
+ document.getElementById('jobTotal').textContent = data.total || 0;
+ document.getElementById('jobProgress').style.width = (data.total > 0 ? (data.checked / data.total * 100) : 0) + '%';
+ if (data.status === 'complete' || data.status === 'stopped') {
+ clearInterval(jobPollInterval);
+ setTimeout(() => { document.getElementById('jobBar').classList.remove('active'); loadResults(); loadStats(); }, 3000);
+ showToast(`Job ${data.status}: ${data.checked} checked, ${data.notFound} not found`);
+ }
+ } catch (e) {}
+ }
+
+ async function stopJob() { await api('POST', '/api/job/stop'); showToast('Job stop requested'); }
+
+ async function tagReview(dwSku) {
+ try {
+ const data = await api('POST', '/api/tag-review', { dw_sku: dwSku });
+ showToast(data.success ? `Tagged ${dwSku} as Review` : (data.error || data.message), !data.success);
+ loadResults();
+ } catch (e) { showToast('Error: ' + e.message, true); }
+ }
+
+ // Init
+ loadStats();
+ loadVendors();
+ loadResults();
+ setInterval(() => { loadStats(); }, 30000);
+ </script>
+</body>
+</html>
diff --git a/server.js b/server.js
new file mode 100644
index 0000000..2597b9f
--- /dev/null
+++ b/server.js
@@ -0,0 +1,1132 @@
+try { require('dotenv').config({ path: '/root/.env' }); } catch (_) {}
+const express = require('express');
+const helmet = require('helmet');
+const { Pool } = require('pg');
+const fetch = require('node-fetch');
+const path = require('path');
+
+const app = express();
+// Security headers via helmet (added 2026-05-04 overnight YOLO loop)
+app.use(helmet({ contentSecurityPolicy: false }));
+const PORT = process.env.PORT || 9894;
+const AGENT_COLOR = '#84CC16'; // Lime
+
+const pool = new Pool({
+ connectionString: 'postgresql://dw_admin:DW2024SecurePass@127.0.0.1:5432/dw_unified'
+});
+
+const SHOPIFY_TOKEN = process.env.SHOPIFY_ADMIN_TOKEN;
+const SHOPIFY_SHOP = 'designer-laboratory-sandbox.myshopify.com';
+const SHOPIFY_API = `https://${SHOPIFY_SHOP}/admin/api/2024-01`;
+const SHOPIFY_HEADERS = {
+ 'X-Shopify-Access-Token': SHOPIFY_TOKEN,
+ 'Content-Type': 'application/json'
+};
+
+const SLACK_WEBHOOK = 'https://hooks.slack.com/services/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';
+
+const GEMINI_API_KEY = 'AIzaSyAO0rLKwtJUKcf3zVmKstBS4udct4QejMo';
+const GEMINI_ENDPOINT = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent';
+
+// Brewster / York trade portal credentials (same parent company, shared login)
+const YORKWALL_LOGIN_URL = 'https://www.yorkwall.com/Login/';
+const YORKWALL_USERNAME = '6003784';
+const YORKWALL_PASSWORD = '*Brewsteraccess911*';
+
+// Vendor catalog table mapping (vendor_code -> PostgreSQL table info)
+const VENDOR_CATALOG = {
+ 'BRE': { table: 'brewster_catalog', skuCol: 'mfr_sku', name: 'Brewster', website: 'brewsterwallcovering.com', tradePortal: 'yorkwall.com' },
+ 'Thib': { table: 'thibaut_catalog', skuCol: 'mfr_sku', name: 'Thibaut', website: 'thibautdesign.com' },
+ 'yor': { table: 'york_catalog', skuCol: 'mfr_sku', name: 'York', website: 'yorkwallcoverings.com', tradePortal: 'yorkwall.com' },
+ 'YOR': { table: 'york_catalog', skuCol: 'mfr_sku', name: 'York', website: 'yorkwallcoverings.com', tradePortal: 'yorkwall.com' },
+ 'WQ': { table: 'wallquest_catalog', skuCol: 'mfr_sku', name: 'WallQuest', website: 'wallquest.com' },
+ 'SCH': { table: 'schumacher_catalog', skuCol: 'mfr_sku', name: 'Schumacher', website: 'fschumacher.com' },
+ 'Sch': { table: 'schumacher_catalog', skuCol: 'mfr_sku', name: 'Schumacher', website: 'fschumacher.com' },
+ 'PJ': { table: 'pj_catalog', skuCol: 'mfr_sku', name: 'Phillip Jeffries', website: 'phillipjeffries.com' },
+ 'kra': { table: 'kravet_catalog', skuCol: 'mfr_sku', name: 'Kravet', website: 'kravet.com' },
+ 'SCA': { table: 'scalamandre_catalog', skuCol: 'mfr_sku', name: 'Scalamandre', website: 'scalamandre.com' },
+ 'jf': { table: 'jf_catalog', skuCol: 'mfr_sku', name: 'JF Fabrics', website: 'jffabrics.com' },
+ 'Mom': { table: 'momeni_catalog', skuCol: 'mfr_sku', name: 'Momeni', website: 'momeni.com' },
+ 'OSB': { table: 'osborne_catalog', skuCol: 'mfr_sku', name: 'Osborne & Little', website: 'osborneandlittle.com' },
+ 'Arte': { table: 'arte_catalog', skuCol: 'arte_sku', name: 'Arte International', website: 'arte-international.com' },
+ 'KOR': { table: 'koroseal_catalog', skuCol: 'mfr_sku', name: 'Koroseal', website: 'koroseal.com' },
+ 'MR': { table: 'maya_catalog', skuCol: 'mfr_sku', name: 'Maya Romanoff', website: 'mayaromanoff.com' },
+ 'RL': { table: 'rlf_catalog', skuCol: 'mfr_sku', name: 'Ralph Lauren', website: 'ralphlaurenhome.com' },
+ 'INN': { table: 'innovations_catalog', skuCol: 'mfr_sku', name: 'Innovations', website: 'innovationsusa.com' },
+ 'CT': { table: 'cowtan_catalog', skuCol: 'mfr_sku', name: 'Cowtan & Tout', website: 'cowtan.com' },
+ 'CS': { table: 'coleson_catalog', skuCol: 'mfr_sku', name: 'Cole & Son', website: 'cole-and-son.com' },
+ 'EL': { table: 'elitis_catalog', skuCol: 'mfr_sku', name: 'Elitis', website: 'elitis.fr' },
+};
+
+// Also map by vendor name for fallback
+const VENDOR_NAME_MAP = {
+ 'Brewster': 'BRE', 'Thibaut': 'Thib', 'York': 'yor', 'WallQuest': 'WQ',
+ 'Schumacher': 'SCH', 'Schumacher Wallcoverings': 'SCH', 'Phillip Jeffries': 'PJ',
+ 'Kravet': 'kra', 'Scalamandre': 'SCA', 'JF Fabrics': 'jf', 'Momeni': 'Mom',
+ 'Osborne & Little': 'OSB', 'Arte': 'Arte', 'Arte International': 'Arte',
+ 'Koroseal': 'KOR', 'Koroseal Wallcoverings': 'KOR', 'Maya Romanoff': 'MR',
+ 'Ralph Lauren': 'RL', 'Innovations': 'INN', 'Innovationsusa': 'INN',
+ 'Cowtan & Tout': 'CT', 'Cole & Son': 'CS', 'Elitis': 'EL',
+};
+
+function findVendorCatalog(vendorCode, vendorName) {
+ if (VENDOR_CATALOG[vendorCode]) return VENDOR_CATALOG[vendorCode];
+ if (vendorName && VENDOR_NAME_MAP[vendorName]) return VENDOR_CATALOG[VENDOR_NAME_MAP[vendorName]];
+ // Fuzzy match
+ const lv = (vendorName || '').toLowerCase();
+ for (const [code, config] of Object.entries(VENDOR_CATALOG)) {
+ if (config.name.toLowerCase().includes(lv) || lv.includes(config.name.toLowerCase())) return config;
+ }
+ return null;
+}
+
+function toTitleCase(str) {
+ if (!str) return '';
+ const small = new Set(['a','an','the','and','but','or','for','nor','in','on','at','to','by','of','up']);
+ return str.replace(/\w\S*/g, (txt, i) => {
+ if (i > 0 && small.has(txt.toLowerCase())) return txt.toLowerCase();
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
+ });
+}
+
+function cleanWallpaper(str) {
+ if (!str) return str;
+ return str.replace(/\bWallpaper\b/gi, 'Wallcovering').replace(/\bWallpapers\b/gi, 'Wallcoverings');
+}
+
+// Fetch specs from PostgreSQL vendor catalog
+async function fetchSpecsFromCatalog(mfrSku, vendorCode, vendorName) {
+ const vc = findVendorCatalog(vendorCode, vendorName);
+ if (!vc) return { specs: null, vendor: null, message: `No catalog mapping for ${vendorCode}/${vendorName}` };
+ try {
+ const result = await pool.query(`SELECT * FROM ${vc.table} WHERE ${vc.skuCol} = $1 LIMIT 1`, [mfrSku.trim()]);
+ if (result.rows.length === 0) return { specs: null, vendor: vc, message: `${mfrSku} not found in ${vc.table}` };
+ const c = result.rows[0];
+ return {
+ specs: {
+ patternName: c.pattern_name || c.name || c.design_name || '',
+ colorName: c.color_name || c.color || c.colorway || '',
+ collection: c.collection || c.collection_name || c.book_name || '',
+ width: c.width || c.roll_width || '',
+ length: c.roll_length || c.length || '',
+ repeat: c.pattern_repeat || c.repeat || '',
+ composition: c.composition || c.content || c.material || '',
+ backing: c.backing || '',
+ fireRating: c.fire_rating || c.fire_rating_us || '',
+ matchType: c.match_type || '',
+ country: c.country_of_origin || c.country || '',
+ productUrl: c.product_url || c.url || '',
+ imageUrl: c.image_url || c.packshot_url || '',
+ roomSettingUrl: c.room_setting_url || c.room_image_url || '',
+ retailPrice: c.retail_price || c.price || null,
+ tradePrice: c.trade_price || c.wholesale_price || null,
+ costPrice: c.cost_price || null,
+ },
+ rawCatalog: c,
+ vendor: vc,
+ message: `Found in ${vc.table}`
+ };
+ } catch (e) {
+ return { specs: null, vendor: vc, message: `Error querying ${vc.table}: ${e.message}` };
+ }
+}
+
+// Fetch images from vendor catalog
+async function fetchImagesFromCatalog(mfrSku, vendorCode, vendorName) {
+ const vc = findVendorCatalog(vendorCode, vendorName);
+ if (!vc) return { images: [], message: `No catalog for ${vendorCode}` };
+ try {
+ const result = await pool.query(`SELECT * FROM ${vc.table} WHERE ${vc.skuCol} = $1 LIMIT 1`, [mfrSku.trim()]);
+ if (result.rows.length === 0) return { images: [], message: 'Not found' };
+ const c = result.rows[0];
+ const images = [c.image_url, c.packshot_url, c.color_image_url, c.room_setting_url, c.room_image_url].filter(Boolean);
+ return { images, productUrl: c.product_url || c.url || '', message: `${images.length} images found` };
+ } catch (e) {
+ return { images: [], message: e.message };
+ }
+}
+
+// Run Gemini AI analysis on product image
+async function analyzeWithGemini(imageUrl, productTitle) {
+ if (!imageUrl) return { analysis: null, message: 'No image URL' };
+ try {
+ // Fetch image and convert to base64
+ const imgResp = await fetch(imageUrl, {
+ headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' },
+ timeout: 15000
+ });
+ if (!imgResp.ok) return { analysis: null, message: `Image fetch failed: HTTP ${imgResp.status}` };
+ const imgBuf = await imgResp.buffer();
+ const base64 = imgBuf.toString('base64');
+ const mimeType = imgResp.headers.get('content-type') || 'image/jpeg';
+
+ const geminiResp = await fetch(`${GEMINI_ENDPOINT}?key=${GEMINI_API_KEY}`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({
+ contents: [{
+ parts: [
+ { inlineData: { mimeType, data: base64 } },
+ { text: `As an expert interior designer, analyze this wallcovering "${productTitle || ''}".
+Return ONLY valid JSON:
+{
+ "backgroundColor": "<single dominant background color>",
+ "colors": ["<max 3 visible colors>"],
+ "styles": ["<1-2 from: Traditional, Contemporary, Coastal, Tropical, Art Deco, Mid-Century, Bohemian, Transitional, Victorian, Chinoiserie>"],
+ "patterns": ["<1-2 from: Botanical, Floral, Geometric, Damask, Palm, Trellis, Stripe, Abstract, Toile, Scenic, Solid, Texture>"],
+ "material": "<Paper, Vinyl, Grasscloth, or Non-woven>",
+ "description": "<2-3 sentence professional interior designer description for commercial applications>",
+ "tags": ["<3-5 interior design tags>"]
+}` }
+ ]
+ }],
+ generationConfig: { temperature: 0.1, maxOutputTokens: 800 }
+ })
+ });
+
+ const geminiData = await geminiResp.json();
+ const text = geminiData?.candidates?.[0]?.content?.parts?.[0]?.text || '';
+ const jsonMatch = text.match(/\{[\s\S]*\}/);
+ if (!jsonMatch) return { analysis: null, message: 'Gemini returned no JSON' };
+ const analysis = JSON.parse(jsonMatch[0]);
+ return { analysis, message: 'AI analysis complete' };
+ } catch (e) {
+ return { analysis: null, message: `Gemini error: ${e.message}` };
+ }
+}
+
+// Get full Shopify product with variants
+async function getShopifyProductFull(productId) {
+ try {
+ const r = await fetch(`${SHOPIFY_API}/products/${productId}.json`, {
+ headers: { 'X-Shopify-Access-Token': SHOPIFY_TOKEN }
+ });
+ const data = await r.json();
+ return data.product || null;
+ } catch (e) { return null; }
+}
+
+// Basic auth
+const AUTH_USER = 'admin';
+const AUTH_PASS = 'DWSecure2024!';
+
+function basicAuth(req, res, next) {
+ if (req.path === '/health') return next();
+ const auth = req.headers.authorization;
+ if (!auth || !auth.startsWith('Basic ')) {
+ res.setHeader('WWW-Authenticate', 'Basic realm="SKU Check Skill"');
+ return res.status(401).send('Authentication required');
+ }
+ const decoded = Buffer.from(auth.split(' ')[1], 'base64').toString();
+ const [user, pass] = decoded.split(':');
+ if (user === AUTH_USER && pass === AUTH_PASS) return next();
+ res.setHeader('WWW-Authenticate', 'Basic realm="SKU Check Skill"');
+ return res.status(401).send('Invalid credentials');
+}
+
+app.use(basicAuth);
+app.use(express.json());
+app.use(express.static(path.join(__dirname, 'public')));
+
+// Vendor URL mapping
+const VENDOR_URLS = {
+ 'BRE': { name: 'Brewster', url: 'https://www.brewsterwallcovering.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'Thib': { name: 'Thibaut', url: 'https://www.thibautdesign.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'yor': { name: 'York', url: 'https://www.yorkwallcoverings.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'WQ': { name: 'WallQuest', url: 'https://www.wallquest.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'SCH': { name: 'Schumacher', url: 'https://www.fschumacher.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'Sch': { name: 'Schumacher', url: 'https://www.fschumacher.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'PJ': { name: 'Phillip Jeffries', url: 'https://www.phillipjeffries.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'kra': { name: 'Kravet', url: 'https://www.kravet.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'SCA': { name: 'Scalamandre', url: 'https://www.scalamandre.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'jf': { name: 'JF Fabrics', url: 'https://www.jffabrics.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'Mom': { name: 'Momeni', url: 'https://www.momeni.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i },
+ 'Fol': { name: 'Followers', url: 'https://www.google.com/search?q={MFR_SKU}+site:{VENDOR}', noResultsPattern: /did not match/i },
+ 'RAD': { name: 'Radici', url: 'https://www.google.com/search?q={MFR_SKU}+Radici', noResultsPattern: /did not match/i },
+ 'OSB': { name: 'Osborne & Little', url: 'https://www.osborneandlittle.com/search?q={MFR_SKU}', noResultsPattern: /no results|no products|0 results|nothing found/i }
+};
+
+// Active batch job tracking
+let activeJob = null;
+
+// Health endpoint
+app.get('/health', (req, res) => res.json({ status: 'ok', port: PORT }));
+
+// Lookup SKU in crossref
+async function lookupSku(dwSku) {
+ const clean = dwSku.replace(/-/g, '');
+ const dash = dwSku.includes('-') ? dwSku : null;
+ const result = await pool.query(
+ `SELECT dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name
+ FROM dw_mfr_crossref
+ WHERE dw_sku = $1 OR dw_sku_dash = $1 OR dw_sku = $2 OR dw_sku_dash = $2
+ LIMIT 1`,
+ [dwSku, clean]
+ );
+ return result.rows[0] || null;
+}
+
+// Find Shopify product by handle/SKU
+async function findShopifyProduct(dwSkuDash) {
+ if (!dwSkuDash) return null;
+ const handle = dwSkuDash.toLowerCase();
+
+ // Try exact handle match first
+ try {
+ const r = await fetch(`${SHOPIFY_API}/products.json?handle=${handle}&fields=id,handle,tags`, {
+ headers: { 'X-Shopify-Access-Token': SHOPIFY_TOKEN }
+ });
+ const data = await r.json();
+ if (data.products && data.products.length > 0) return data.products[0];
+ } catch (e) { /* ignore */ }
+
+ // Try GraphQL search to find product with SKU in handle or title
+ try {
+ const query = `{
+ products(first: 3, query: "${handle}") {
+ edges { node { id legacyResourceId handle tags } }
+ }
+ }`;
+ const r = await fetch(`https://${SHOPIFY_SHOP}/admin/api/2024-01/graphql.json`, {
+ method: 'POST',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ query })
+ });
+ const data = await r.json();
+ const edges = data?.data?.products?.edges;
+ if (edges && edges.length > 0) {
+ const node = edges[0].node;
+ return { id: node.legacyResourceId, handle: node.handle, tags: node.tags.join(', ') };
+ }
+ } catch (e) { /* ignore */ }
+
+ return null;
+}
+
+// Check vendor website for MFR SKU
+async function checkVendorWebsite(mfrSku, vendorCode) {
+ const vendor = VENDOR_URLS[vendorCode];
+ if (!vendor) {
+ return { status: 'error', httpStatus: 0, url: '', message: `Unknown vendor code: ${vendorCode}` };
+ }
+
+ const url = vendor.url.replace('{MFR_SKU}', encodeURIComponent(mfrSku));
+
+ try {
+ const r = await fetch(url, {
+ timeout: 15000,
+ headers: {
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
+ },
+ redirect: 'follow'
+ });
+
+ const httpStatus = r.status;
+
+ if (httpStatus === 404) {
+ return { status: 'not_found', httpStatus, url };
+ }
+
+ if (httpStatus !== 200) {
+ return { status: 'error', httpStatus, url, message: `HTTP ${httpStatus}` };
+ }
+
+ const body = await r.text();
+
+ // Check if page contains the MFR SKU (product exists)
+ if (body.includes(mfrSku) || body.includes(mfrSku.replace(/-/g, ''))) {
+ return { status: 'found', httpStatus, url };
+ }
+
+ // Check for "no results" patterns
+ if (vendor.noResultsPattern && vendor.noResultsPattern.test(body)) {
+ return { status: 'not_found', httpStatus, url };
+ }
+
+ // If we got a 200 but can't confirm the SKU is there, mark as found (conservative)
+ // The search page returned results but we couldn't verify the exact SKU
+ return { status: 'found', httpStatus, url, message: 'Search returned results but exact SKU not confirmed in body' };
+
+ } catch (e) {
+ return { status: 'error', httpStatus: 0, url, message: e.message };
+ }
+}
+
+// Add "Review" tag to Shopify product
+async function tagReview(productId) {
+ try {
+ // Get current tags
+ const r1 = await fetch(`${SHOPIFY_API}/products/${productId}.json?fields=id,tags`, {
+ headers: { 'X-Shopify-Access-Token': SHOPIFY_TOKEN }
+ });
+ const data = await r1.json();
+ const currentTags = data.product?.tags || '';
+
+ if (currentTags.includes('Review')) return { success: true, message: 'Already tagged' };
+
+ const newTags = currentTags ? `${currentTags}, Review` : 'Review';
+
+ const r2 = await fetch(`${SHOPIFY_API}/products/${productId}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ product: { id: parseInt(productId), tags: newTags } })
+ });
+
+ if (r2.status === 200) return { success: true, message: 'Tagged Review' };
+ return { success: false, message: `HTTP ${r2.status}` };
+ } catch (e) {
+ return { success: false, message: e.message };
+ }
+}
+
+// Send Slack notification
+async function slackNotify(message) {
+ try {
+ await fetch(SLACK_WEBHOOK, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ text: message })
+ });
+ return true;
+ } catch (e) {
+ console.error('Slack error:', e.message);
+ return false;
+ }
+}
+
+// Delay helper
+function delay(ms) { return new Promise(r => setTimeout(r, ms)); }
+
+// ===== API ROUTES =====
+
+// Check single SKU
+app.post('/api/check/sku', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+
+ try {
+ const crossref = await lookupSku(dw_sku);
+ if (!crossref) {
+ return res.json({ error: 'SKU not found in crossref', dw_sku });
+ }
+
+ const shopify = await findShopifyProduct(crossref.dw_sku_dash);
+ const vendorResult = await checkVendorWebsite(crossref.mfr_sku, crossref.vendor_code);
+
+ // Store result
+ const insertResult = await pool.query(
+ `INSERT INTO sku_check_results
+ (dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name, shopify_product_id, shopify_handle, check_status, http_status, vendor_url, checked_at)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, NOW())
+ ON CONFLICT (dw_sku) DO UPDATE SET
+ check_status = EXCLUDED.check_status, http_status = EXCLUDED.http_status,
+ vendor_url = EXCLUDED.vendor_url, checked_at = NOW(),
+ shopify_product_id = COALESCE(EXCLUDED.shopify_product_id, sku_check_results.shopify_product_id),
+ shopify_handle = COALESCE(EXCLUDED.shopify_handle, sku_check_results.shopify_handle)
+ RETURNING *`,
+ [
+ crossref.dw_sku, crossref.dw_sku_dash, crossref.mfr_sku,
+ crossref.vendor_code, crossref.vendor_name,
+ shopify?.id?.toString() || null, shopify?.handle || null,
+ vendorResult.status, vendorResult.httpStatus, vendorResult.url
+ ]
+ );
+
+ const result = insertResult.rows[0];
+
+ // If not found, tag and slack
+ if (vendorResult.status === 'not_found' && shopify?.id) {
+ const tagResult = await tagReview(shopify.id);
+ if (tagResult.success) {
+ await pool.query('UPDATE sku_check_results SET tagged_review = true WHERE id = $1', [result.id]);
+ result.tagged_review = true;
+ }
+
+ const slackMsg = `🔍 SKU not found: ${crossref.dw_sku_dash} (${crossref.vendor_name}) → tagged Review`;
+
+ const slacked = await slackNotify(slackMsg);
+ if (slacked) {
+ await pool.query('UPDATE sku_check_results SET slacked = true WHERE id = $1', [result.id]);
+ result.slacked = true;
+ }
+ }
+
+ res.json({ result, crossref, shopify: shopify ? { id: shopify.id, handle: shopify.handle } : null, vendorCheck: vendorResult });
+
+ } catch (e) {
+ console.error('Check SKU error:', e);
+ res.status(500).json({ error: e.message });
+ }
+});
+
+// Check range of SKUs
+app.post('/api/check/range', async (req, res) => {
+ const { prefix, from, to } = req.body;
+ if (!prefix || !from || !to) return res.status(400).json({ error: 'prefix, from, to required' });
+
+ // Query DB for actual SKUs matching this prefix in the number range
+ const skus = await pool.query(
+ `SELECT dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name
+ FROM dw_mfr_crossref
+ WHERE dw_sku LIKE $1
+ AND CAST(SUBSTRING(dw_sku FROM '[0-9]+$') AS INTEGER) BETWEEN $2 AND $3
+ ORDER BY dw_sku`,
+ [prefix + '%', from, to]
+ );
+
+ if (skus.rows.length === 0) {
+ return res.json({ error: `No SKUs found for prefix ${prefix} in range ${from}-${to}` });
+ }
+
+ // Start async job
+ const jobId = Date.now().toString();
+ activeJob = { id: jobId, type: 'range', prefix, from, to, total: skus.rows.length, checked: 0, found: 0, notFound: 0, errors: 0, status: 'running' };
+
+ res.json({ jobId, message: `Checking ${skus.rows.length} ${prefix} SKUs in range ${from}-${to}`, total: skus.rows.length });
+
+ // Process in background
+ (async () => {
+ for (const row of skus.rows) {
+ if (activeJob.status === 'stopped') break;
+
+ try {
+ await delay(1000); // Rate limit
+
+ const shopify = await findShopifyProduct(row.dw_sku_dash);
+ const vendorResult = await checkVendorWebsite(row.mfr_sku, row.vendor_code);
+
+ await pool.query(
+ `INSERT INTO sku_check_results
+ (dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name, shopify_product_id, shopify_handle, check_status, http_status, vendor_url, checked_at)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, NOW())
+ ON CONFLICT (dw_sku) DO UPDATE SET
+ check_status = EXCLUDED.check_status, http_status = EXCLUDED.http_status,
+ vendor_url = EXCLUDED.vendor_url, checked_at = NOW(),
+ shopify_product_id = COALESCE(EXCLUDED.shopify_product_id, sku_check_results.shopify_product_id),
+ shopify_handle = COALESCE(EXCLUDED.shopify_handle, sku_check_results.shopify_handle)`,
+ [row.dw_sku, row.dw_sku_dash, row.mfr_sku, row.vendor_code, row.vendor_name,
+ shopify?.id?.toString() || null, shopify?.handle || null,
+ vendorResult.status, vendorResult.httpStatus, vendorResult.url]
+ );
+
+ if (vendorResult.status === 'found') activeJob.found++;
+ else if (vendorResult.status === 'not_found') {
+ activeJob.notFound++;
+ if (shopify?.id) {
+ await tagReview(shopify.id);
+ await pool.query('UPDATE sku_check_results SET tagged_review = true WHERE dw_sku = $1', [row.dw_sku]);
+ }
+ }
+ else activeJob.errors++;
+
+ } catch (e) {
+ activeJob.errors++;
+ }
+
+ activeJob.checked++;
+ }
+
+ activeJob.status = 'complete';
+
+ // Slack summary
+ await slackNotify(`🔍 SKU range ${prefix} ${from}-${to}: ${activeJob.found} found, ${activeJob.notFound} missing`);
+ })();
+});
+
+// Check all SKUs for a vendor
+app.post('/api/check/vendor', async (req, res) => {
+ const { vendor_code, limit } = req.body;
+ if (!vendor_code) return res.status(400).json({ error: 'vendor_code required' });
+
+ const maxLimit = limit || 500;
+
+ const skus = await pool.query(
+ `SELECT dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name
+ FROM dw_mfr_crossref
+ WHERE vendor_code = $1
+ ORDER BY dw_sku
+ LIMIT $2`,
+ [vendor_code, maxLimit]
+ );
+
+ if (skus.rows.length === 0) {
+ return res.json({ error: 'No SKUs found for vendor', vendor_code });
+ }
+
+ const jobId = Date.now().toString();
+ activeJob = { id: jobId, type: 'vendor', vendor_code, total: skus.rows.length, checked: 0, found: 0, notFound: 0, errors: 0, status: 'running' };
+
+ res.json({ jobId, message: `Checking ${skus.rows.length} ${vendor_code} SKUs`, total: skus.rows.length });
+
+ // Process in background
+ (async () => {
+ for (const row of skus.rows) {
+ if (activeJob.status === 'stopped') break;
+
+ try {
+ await delay(1000);
+
+ const shopify = await findShopifyProduct(row.dw_sku_dash);
+ const vendorResult = await checkVendorWebsite(row.mfr_sku, row.vendor_code);
+
+ await pool.query(
+ `INSERT INTO sku_check_results
+ (dw_sku, dw_sku_dash, mfr_sku, vendor_code, vendor_name, shopify_product_id, shopify_handle, check_status, http_status, vendor_url, checked_at)
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, NOW())
+ ON CONFLICT (dw_sku) DO UPDATE SET
+ check_status = EXCLUDED.check_status, http_status = EXCLUDED.http_status,
+ vendor_url = EXCLUDED.vendor_url, checked_at = NOW()`,
+ [row.dw_sku, row.dw_sku_dash, row.mfr_sku, row.vendor_code, row.vendor_name,
+ shopify?.id?.toString() || null, shopify?.handle || null,
+ vendorResult.status, vendorResult.httpStatus, vendorResult.url]
+ );
+
+ if (vendorResult.status === 'found') activeJob.found++;
+ else if (vendorResult.status === 'not_found') {
+ activeJob.notFound++;
+ if (shopify?.id) {
+ await tagReview(shopify.id);
+ await pool.query('UPDATE sku_check_results SET tagged_review = true WHERE dw_sku = $1', [row.dw_sku]);
+ }
+ }
+ else activeJob.errors++;
+
+ } catch (e) {
+ activeJob.errors++;
+ }
+
+ activeJob.checked++;
+ }
+
+ activeJob.status = 'complete';
+
+ await slackNotify(`🔍 SKU vendor ${vendor_code}: ${activeJob.found} found, ${activeJob.notFound} missing`);
+ })();
+});
+
+// Get job status
+app.get('/api/job', (req, res) => {
+ if (!activeJob) return res.json({ status: 'idle' });
+ res.json(activeJob);
+});
+
+// Stop active job
+app.post('/api/job/stop', (req, res) => {
+ if (activeJob) {
+ activeJob.status = 'stopped';
+ res.json({ message: 'Job stopped' });
+ } else {
+ res.json({ message: 'No active job' });
+ }
+});
+
+// Get results with filters
+app.get('/api/results', async (req, res) => {
+ const { status, vendor, limit, offset } = req.query;
+ let where = [];
+ let params = [];
+ let idx = 1;
+
+ if (status) { where.push(`check_status = $${idx++}`); params.push(status); }
+ if (vendor) { where.push(`vendor_code = $${idx++}`); params.push(vendor); }
+
+ const whereStr = where.length > 0 ? `WHERE ${where.join(' AND ')}` : '';
+ const lim = parseInt(limit) || 100;
+ const off = parseInt(offset) || 0;
+
+ const total = await pool.query(`SELECT COUNT(*) as count FROM sku_check_results ${whereStr}`, params);
+ const results = await pool.query(
+ `SELECT * FROM sku_check_results ${whereStr} ORDER BY checked_at DESC NULLS LAST LIMIT ${lim} OFFSET ${off}`,
+ params
+ );
+
+ res.json({ total: parseInt(total.rows[0].count), results: results.rows });
+});
+
+// Get stats
+app.get('/api/stats', async (req, res) => {
+ const overall = await pool.query(`
+ SELECT
+ COUNT(*) as total,
+ COUNT(*) FILTER (WHERE check_status = 'found') as found,
+ COUNT(*) FILTER (WHERE check_status = 'not_found') as not_found,
+ COUNT(*) FILTER (WHERE check_status = 'error') as errors,
+ COUNT(*) FILTER (WHERE check_status = 'pending') as pending,
+ COUNT(*) FILTER (WHERE tagged_review = true) as tagged,
+ COUNT(*) FILTER (WHERE slacked = true) as slacked
+ FROM sku_check_results
+ `);
+
+ const byVendor = await pool.query(`
+ SELECT vendor_code, vendor_name,
+ COUNT(*) as total,
+ COUNT(*) FILTER (WHERE check_status = 'found') as found,
+ COUNT(*) FILTER (WHERE check_status = 'not_found') as not_found,
+ COUNT(*) FILTER (WHERE check_status = 'error') as errors
+ FROM sku_check_results
+ GROUP BY vendor_code, vendor_name
+ ORDER BY total DESC
+ `);
+
+ res.json({ overall: overall.rows[0], byVendor: byVendor.rows });
+});
+
+// Get vendors list from crossref
+app.get('/api/vendors', async (req, res) => {
+ const vendors = await pool.query(`
+ SELECT vendor_code, vendor_name, COUNT(*) as sku_count
+ FROM dw_mfr_crossref
+ WHERE vendor_code IS NOT NULL AND vendor_code != ''
+ GROUP BY vendor_code, vendor_name
+ ORDER BY sku_count DESC
+ `);
+ res.json(vendors.rows);
+});
+
+// Manually tag a product as Review
+app.post('/api/tag-review', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+
+ const crossref = await lookupSku(dw_sku);
+ if (!crossref) return res.status(404).json({ error: 'SKU not found in crossref' });
+
+ const shopify = await findShopifyProduct(crossref.dw_sku_dash);
+ if (!shopify) return res.status(404).json({ error: 'Shopify product not found' });
+
+ const result = await tagReview(shopify.id);
+
+ if (result.success) {
+ await pool.query('UPDATE sku_check_results SET tagged_review = true WHERE dw_sku = $1', [crossref.dw_sku]);
+ }
+
+ res.json(result);
+});
+
+// Send Slack notification for a specific SKU
+app.post('/api/slack-notify', async (req, res) => {
+ const { dw_sku, message } = req.body;
+
+ if (message) {
+ const result = await slackNotify(message);
+ return res.json({ sent: result });
+ }
+
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku or message required' });
+
+ const row = await pool.query('SELECT * FROM sku_check_results WHERE dw_sku = $1 OR dw_sku_dash = $1', [dw_sku]);
+ if (row.rows.length === 0) return res.status(404).json({ error: 'No check result for this SKU' });
+
+ const r = row.rows[0];
+ const msg = `🔍 ${r.dw_sku_dash || r.dw_sku}: ${r.check_status.toUpperCase()} (${r.vendor_name})`;
+
+ const sent = await slackNotify(msg);
+ if (sent) {
+ await pool.query('UPDATE sku_check_results SET slacked = true WHERE id = $1', [r.id]);
+ }
+
+ res.json({ sent });
+});
+
+// ===== ACTION ENDPOINTS =====
+
+// Helper: resolve dw_sku to full context (crossref + shopify + vendor catalog)
+async function resolveSkuContext(dw_sku) {
+ const crossref = await lookupSku(dw_sku);
+ if (!crossref) return { error: 'SKU not found in crossref' };
+
+ // Get Shopify product
+ let shopifyProduct = null;
+ const checkRow = await pool.query('SELECT shopify_product_id, shopify_handle FROM sku_check_results WHERE dw_sku = $1 OR dw_sku_dash = $1', [crossref.dw_sku]);
+ if (checkRow.rows[0]?.shopify_product_id) {
+ shopifyProduct = await getShopifyProductFull(checkRow.rows[0].shopify_product_id);
+ }
+ if (!shopifyProduct) {
+ const sp = await findShopifyProduct(crossref.dw_sku_dash);
+ if (sp?.id) shopifyProduct = await getShopifyProductFull(sp.id);
+ }
+
+ const vc = findVendorCatalog(crossref.vendor_code, crossref.vendor_name);
+ return { crossref, shopifyProduct, vendorCatalog: vc };
+}
+
+// 1. Fetch Specs from PostgreSQL vendor catalog
+app.post('/api/action/fetch-specs', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ const result = await fetchSpecsFromCatalog(ctx.crossref.mfr_sku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ res.json({ ...result, crossref: ctx.crossref, shopifyId: ctx.shopifyProduct?.id });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 2. Fetch Images from vendor catalog
+app.post('/api/action/fetch-images', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ const result = await fetchImagesFromCatalog(ctx.crossref.mfr_sku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ res.json(result);
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 3. AI Analyze - run Gemini on product image
+app.post('/api/action/ai-analyze', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ const imageUrl = ctx.shopifyProduct?.image?.src || ctx.shopifyProduct?.images?.[0]?.src;
+ const title = ctx.shopifyProduct?.title || '';
+ const result = await analyzeWithGemini(imageUrl, title);
+ res.json(result);
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 4. Update Tags - merge AI + specs tags into Shopify product
+app.post('/api/action/update-tags', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ if (!ctx.shopifyProduct) return res.json({ error: 'No Shopify product found' });
+
+ // Get specs + AI analysis
+ const specsResult = await fetchSpecsFromCatalog(ctx.crossref.mfr_sku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ const imageUrl = ctx.shopifyProduct.image?.src || ctx.shopifyProduct.images?.[0]?.src;
+ const aiResult = await analyzeWithGemini(imageUrl, ctx.shopifyProduct.title);
+
+ // Build tag set
+ const existingTags = (ctx.shopifyProduct.tags || '').split(',').map(t => t.trim()).filter(Boolean);
+ const tagSet = new Set(existingTags);
+
+ // Add AI tags
+ if (aiResult.analysis) {
+ const a = aiResult.analysis;
+ if (a.styles) a.styles.forEach(s => tagSet.add(s));
+ if (a.patterns) a.patterns.forEach(p => tagSet.add(p));
+ if (a.colors) a.colors.forEach(c => tagSet.add(c));
+ if (a.backgroundColor) tagSet.add(`Background Color ${a.backgroundColor}`);
+ if (a.material) tagSet.add(a.material);
+ if (a.tags) a.tags.forEach(t => tagSet.add(t));
+ }
+
+ // Add spec tags
+ if (specsResult.specs) {
+ if (specsResult.specs.collection) tagSet.add(specsResult.specs.collection);
+ if (specsResult.specs.composition) tagSet.add(specsResult.specs.composition);
+ }
+
+ const newTags = Array.from(tagSet).join(', ');
+
+ // Update Shopify
+ const r = await fetch(`${SHOPIFY_API}/products/${ctx.shopifyProduct.id}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ product: { id: ctx.shopifyProduct.id, tags: newTags } })
+ });
+
+ const updated = await r.json();
+ res.json({ success: r.status === 200, tags: newTags, tagCount: tagSet.size, aiAnalysis: aiResult.analysis, message: `Updated ${tagSet.size} tags` });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 5. Update Metafields - push specs + AI data as Shopify metafields
+app.post('/api/action/update-metafields', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ if (!ctx.shopifyProduct) return res.json({ error: 'No Shopify product found' });
+
+ const specsResult = await fetchSpecsFromCatalog(ctx.crossref.mfr_sku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ const imageUrl = ctx.shopifyProduct.image?.src || ctx.shopifyProduct.images?.[0]?.src;
+ const aiResult = await analyzeWithGemini(imageUrl, ctx.shopifyProduct.title);
+ const specs = specsResult.specs || {};
+ const ai = aiResult.analysis || {};
+
+ const metafields = [];
+ // Specs metafields (global namespace)
+ if (specs.width) metafields.push({ namespace: 'global', key: 'width', value: specs.width, type: 'single_line_text_field' });
+ if (specs.length) metafields.push({ namespace: 'global', key: 'length', value: specs.length, type: 'single_line_text_field' });
+ if (specs.repeat) metafields.push({ namespace: 'global', key: 'repeat', value: specs.repeat, type: 'single_line_text_field' });
+ if (specs.composition) metafields.push({ namespace: 'global', key: 'Contents', value: specs.composition, type: 'single_line_text_field' });
+ if (specs.fireRating) metafields.push({ namespace: 'global', key: 'FLAMMABILITY', value: specs.fireRating, type: 'single_line_text_field' });
+ if (specs.matchType) metafields.push({ namespace: 'global', key: 'MATCH', value: specs.matchType, type: 'single_line_text_field' });
+ if (specs.country) metafields.push({ namespace: 'global', key: 'Country', value: specs.country, type: 'single_line_text_field' });
+ if (specs.collection) metafields.push({ namespace: 'global', key: 'Collection', value: specs.collection, type: 'single_line_text_field' });
+ if (specs.colorName) metafields.push({ namespace: 'global', key: 'Color-Way', value: specs.colorName, type: 'single_line_text_field' });
+ if (specs.backing) metafields.push({ namespace: 'global', key: 'Construction', value: specs.backing, type: 'single_line_text_field' });
+ // MFR SKU
+ metafields.push({ namespace: 'custom', key: 'manufacturer_sku', value: ctx.crossref.mfr_sku, type: 'single_line_text_field' });
+ metafields.push({ namespace: 'dwc', key: 'manufacturer_sku', value: ctx.crossref.mfr_sku, type: 'single_line_text_field' });
+ // AI metafields (dwc namespace)
+ if (ai.colors) metafields.push({ namespace: 'dwc', key: 'ai_generated_colors', value: JSON.stringify(ai.colors), type: 'json' });
+ if (ai.tags) metafields.push({ namespace: 'dwc', key: 'ai_generated_tags', value: JSON.stringify(ai.tags), type: 'json' });
+ if (ai.backgroundColor) metafields.push({ namespace: 'dwc', key: 'background_color', value: ai.backgroundColor, type: 'single_line_text_field' });
+ if (ai.styles?.[0]) metafields.push({ namespace: 'custom', key: 'design_style', value: ai.styles[0], type: 'single_line_text_field' });
+ if (specs.colorName) metafields.push({ namespace: 'dwc', key: 'color', value: specs.colorName, type: 'single_line_text_field' });
+ if (specs.patternName) metafields.push({ namespace: 'dwc', key: 'pattern_name', value: specs.patternName, type: 'single_line_text_field' });
+
+ // Push each metafield with rate limiting
+ let success = 0, errors = 0;
+ for (const mf of metafields) {
+ try {
+ const r = await fetch(`${SHOPIFY_API}/products/${ctx.shopifyProduct.id}/metafields.json`, {
+ method: 'POST',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ metafield: mf })
+ });
+ if (r.status === 200 || r.status === 201) success++;
+ else errors++;
+ await delay(300);
+ } catch { errors++; }
+ }
+
+ res.json({ success: true, metafieldsSet: success, metafieldsError: errors, total: metafields.length, message: `Set ${success}/${metafields.length} metafields` });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 6. Fix Title - proper format: "Pattern Color | Vendor"
+app.post('/api/action/fix-title', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ if (!ctx.shopifyProduct) return res.json({ error: 'No Shopify product found' });
+
+ const specsResult = await fetchSpecsFromCatalog(ctx.crossref.mfr_sku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ const specs = specsResult.specs || {};
+ const vc = ctx.vendorCatalog;
+
+ let pattern = specs.patternName || '';
+ let color = specs.colorName || '';
+ let vendor = vc?.name || ctx.crossref.vendor_name || '';
+
+ // Build title
+ let newTitle = '';
+ if (pattern && color) {
+ newTitle = `${toTitleCase(pattern)} ${toTitleCase(color)} | ${vendor}`;
+ } else if (pattern) {
+ newTitle = `${toTitleCase(pattern)} | ${vendor}`;
+ } else {
+ // Keep existing title but fix wallpaper and title case
+ newTitle = ctx.shopifyProduct.title;
+ }
+ newTitle = cleanWallpaper(newTitle);
+
+ const r = await fetch(`${SHOPIFY_API}/products/${ctx.shopifyProduct.id}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ product: { id: ctx.shopifyProduct.id, title: newTitle } })
+ });
+
+ res.json({ success: r.status === 200, oldTitle: ctx.shopifyProduct.title, newTitle, message: r.status === 200 ? 'Title updated' : `HTTP ${r.status}` });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 7. Fix Sample Variant - ensure "Sample" variant at $4.25
+app.post('/api/action/fix-sample', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ if (!ctx.shopifyProduct) return res.json({ error: 'No Shopify product found' });
+
+ const product = ctx.shopifyProduct;
+ const variant = product.variants?.[0];
+ if (!variant) return res.json({ error: 'No variants found' });
+
+ const dwSkuDash = ctx.crossref.dw_sku_dash || dw_sku;
+
+ // Check if already correct
+ if (variant.title === 'Sample' && variant.price === '4.25') {
+ return res.json({ success: true, message: 'Sample variant already correct', variant: { title: variant.title, price: variant.price, sku: variant.sku } });
+ }
+
+ // Update product to have Sample variant
+ const r = await fetch(`${SHOPIFY_API}/products/${product.id}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({
+ product: {
+ id: product.id,
+ options: [{ name: 'Type', values: ['Sample'] }],
+ variants: [{
+ id: variant.id,
+ option1: 'Sample',
+ price: '4.25',
+ sku: `${dwSkuDash}-Sample`
+ }]
+ }
+ })
+ });
+
+ const updated = await r.json();
+ const uv = updated.product?.variants?.[0];
+ res.json({
+ success: r.status === 200,
+ oldVariant: { title: variant.title, price: variant.price, sku: variant.sku },
+ newVariant: uv ? { title: uv.title, price: uv.price, sku: uv.sku } : null,
+ message: r.status === 200 ? 'Sample variant fixed' : `HTTP ${r.status}`
+ });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// 8. Run ALL - execute full pipeline on a SKU
+app.post('/api/action/run-all', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const ctx = await resolveSkuContext(dw_sku);
+ if (ctx.error) return res.json({ error: ctx.error });
+ if (!ctx.shopifyProduct) return res.json({ error: 'No Shopify product found' });
+
+ const results = { steps: {} };
+ const productId = ctx.shopifyProduct.id;
+ const mfrSku = ctx.crossref.mfr_sku;
+ const vc = ctx.vendorCatalog;
+
+ // Step 1: Fetch specs
+ const specsResult = await fetchSpecsFromCatalog(mfrSku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ results.steps.specs = { done: !!specsResult.specs, message: specsResult.message, data: specsResult.specs };
+
+ // Step 2: Fetch images
+ const imagesResult = await fetchImagesFromCatalog(mfrSku, ctx.crossref.vendor_code, ctx.crossref.vendor_name);
+ results.steps.images = { done: imagesResult.images.length > 0, count: imagesResult.images.length, message: imagesResult.message };
+
+ // Step 3: AI analyze
+ const imageUrl = ctx.shopifyProduct.image?.src || ctx.shopifyProduct.images?.[0]?.src;
+ const aiResult = await analyzeWithGemini(imageUrl, ctx.shopifyProduct.title);
+ results.steps.ai = { done: !!aiResult.analysis, message: aiResult.message, data: aiResult.analysis };
+
+ // Step 4: Fix title
+ const specs = specsResult.specs || {};
+ let newTitle = ctx.shopifyProduct.title;
+ if (specs.patternName) {
+ newTitle = specs.colorName
+ ? `${toTitleCase(specs.patternName)} ${toTitleCase(specs.colorName)} | ${vc?.name || ctx.crossref.vendor_name}`
+ : `${toTitleCase(specs.patternName)} | ${vc?.name || ctx.crossref.vendor_name}`;
+ newTitle = cleanWallpaper(newTitle);
+ }
+
+ // Step 5: Update tags
+ const existingTags = (ctx.shopifyProduct.tags || '').split(',').map(t => t.trim()).filter(Boolean);
+ const tagSet = new Set(existingTags);
+ if (aiResult.analysis) {
+ const a = aiResult.analysis;
+ (a.styles || []).forEach(s => tagSet.add(s));
+ (a.patterns || []).forEach(p => tagSet.add(p));
+ (a.colors || []).forEach(c => tagSet.add(c));
+ if (a.backgroundColor) tagSet.add(`Background Color ${a.backgroundColor}`);
+ if (a.material) tagSet.add(a.material);
+ (a.tags || []).forEach(t => tagSet.add(t));
+ }
+ if (specs.collection) tagSet.add(specs.collection);
+
+ // Push title + tags in one call
+ const titleTagResp = await fetch(`${SHOPIFY_API}/products/${productId}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({ product: { id: productId, title: newTitle, tags: Array.from(tagSet).join(', ') } })
+ });
+ results.steps.title = { done: titleTagResp.status === 200, oldTitle: ctx.shopifyProduct.title, newTitle };
+ results.steps.tags = { done: titleTagResp.status === 200, count: tagSet.size };
+ await delay(500);
+
+ // Step 6: Metafields
+ const ai = aiResult.analysis || {};
+ const metafields = [];
+ if (specs.width) metafields.push({ namespace: 'global', key: 'width', value: specs.width, type: 'single_line_text_field' });
+ if (specs.length) metafields.push({ namespace: 'global', key: 'length', value: specs.length, type: 'single_line_text_field' });
+ if (specs.repeat) metafields.push({ namespace: 'global', key: 'repeat', value: specs.repeat, type: 'single_line_text_field' });
+ if (specs.composition) metafields.push({ namespace: 'global', key: 'Contents', value: specs.composition, type: 'single_line_text_field' });
+ if (specs.fireRating) metafields.push({ namespace: 'global', key: 'FLAMMABILITY', value: specs.fireRating, type: 'single_line_text_field' });
+ if (specs.matchType) metafields.push({ namespace: 'global', key: 'MATCH', value: specs.matchType, type: 'single_line_text_field' });
+ if (specs.country) metafields.push({ namespace: 'global', key: 'Country', value: specs.country, type: 'single_line_text_field' });
+ if (specs.collection) metafields.push({ namespace: 'global', key: 'Collection', value: specs.collection, type: 'single_line_text_field' });
+ if (specs.colorName) metafields.push({ namespace: 'global', key: 'Color-Way', value: specs.colorName, type: 'single_line_text_field' });
+ metafields.push({ namespace: 'custom', key: 'manufacturer_sku', value: mfrSku, type: 'single_line_text_field' });
+ metafields.push({ namespace: 'dwc', key: 'manufacturer_sku', value: mfrSku, type: 'single_line_text_field' });
+ if (ai.colors) metafields.push({ namespace: 'dwc', key: 'ai_generated_colors', value: JSON.stringify(ai.colors), type: 'json' });
+ if (ai.tags) metafields.push({ namespace: 'dwc', key: 'ai_generated_tags', value: JSON.stringify(ai.tags), type: 'json' });
+ if (ai.backgroundColor) metafields.push({ namespace: 'dwc', key: 'background_color', value: ai.backgroundColor, type: 'single_line_text_field' });
+
+ let mfSuccess = 0;
+ for (const mf of metafields) {
+ try {
+ const r = await fetch(`${SHOPIFY_API}/products/${productId}/metafields.json`, { method: 'POST', headers: SHOPIFY_HEADERS, body: JSON.stringify({ metafield: mf }) });
+ if (r.status === 200 || r.status === 201) mfSuccess++;
+ await delay(300);
+ } catch {}
+ }
+ results.steps.metafields = { done: true, set: mfSuccess, total: metafields.length };
+
+ // Step 7: Fix sample variant
+ const variant = ctx.shopifyProduct.variants?.[0];
+ if (variant && (variant.title !== 'Sample' || variant.price !== '4.25')) {
+ const dwSkuDash = ctx.crossref.dw_sku_dash || dw_sku;
+ await delay(500);
+ const sampleResp = await fetch(`${SHOPIFY_API}/products/${productId}.json`, {
+ method: 'PUT',
+ headers: SHOPIFY_HEADERS,
+ body: JSON.stringify({
+ product: { id: productId, options: [{ name: 'Type', values: ['Sample'] }], variants: [{ id: variant.id, option1: 'Sample', price: '4.25', sku: `${dwSkuDash}-Sample` }] }
+ })
+ });
+ results.steps.sample = { done: sampleResp.status === 200, message: 'Sample variant fixed' };
+ } else {
+ results.steps.sample = { done: true, message: 'Already correct' };
+ }
+
+ // Slack notify
+ const doneSteps = Object.values(results.steps).filter(s => s.done).length;
+ await slackNotify(`🔧 Updated ${dw_sku}: ${doneSteps}/7 steps done`);
+
+ results.success = true;
+ results.summary = `${doneSteps}/7 steps completed`;
+ res.json(results);
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// Get vendor website URL for a SKU
+app.post('/api/action/vendor-url', async (req, res) => {
+ const { dw_sku } = req.body;
+ if (!dw_sku) return res.status(400).json({ error: 'dw_sku required' });
+ try {
+ const crossref = await lookupSku(dw_sku);
+ if (!crossref) return res.json({ error: 'SKU not found' });
+ const vc = findVendorCatalog(crossref.vendor_code, crossref.vendor_name);
+ const vendorUrl = VENDOR_URLS[crossref.vendor_code];
+ const searchUrl = vendorUrl ? vendorUrl.url.replace('{MFR_SKU}', encodeURIComponent(crossref.mfr_sku)) : null;
+ res.json({
+ vendorName: vc?.name || crossref.vendor_name,
+ vendorWebsite: vc?.website ? `https://www.${vc.website}` : null,
+ searchUrl,
+ mfrSku: crossref.mfr_sku
+ });
+ } catch (e) { res.status(500).json({ error: e.message }); }
+});
+
+// Add unique constraint for upsert support
+(async () => {
+ try {
+ await pool.query('ALTER TABLE sku_check_results ADD CONSTRAINT sku_check_results_dw_sku_unique UNIQUE (dw_sku)');
+ } catch (e) {
+ // Constraint may already exist
+ }
+})();
+
+app.listen(PORT, () => {
+ console.log(`SKU Check Skill running on port ${PORT}`);
+ console.log(`Dashboard: http://45.61.58.125:${PORT}`);
+});
(oldest)
·
back to Sku Check Skill
·
sku-check: log Gemini sku-image-analysis usage to cost-track 64a2269 →