diff --git a/.env.test b/.env.test index f2aa6a1..9818cd2 100644 --- a/.env.test +++ b/.env.test @@ -1,2 +1,5 @@ -PUBLIC_URL="http://127.0.0.1:8055" +ADMIN_EMAIL="test@test.com" +ADMIN_PASSWORD="test" ADMIN_TOKEN="test" +PUBLIC_URL="http://127.0.0.1:8055" +IMAGGA_API="http://imagga:1080" diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 0e10d99..99aa30b 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -6,3 +6,13 @@ services: volumes: - ./:/directus/extensions/imagga env_file: ".env.test" + imagga: + image: mockserver/mockserver:5.15.0 + ports: + - 1080:1080 + environment: + MOCKSERVER_PROPERTY_FILE: /mocks/mockserver.properties + MOCKSERVER_INITIALIZATION_JSON_PATH: /mocks/imagga.json + MOCKSERVER_WATCH_INITIALIZATION_JSON: "true" + volumes: + - ./mocks:/mocks diff --git a/mocks/imagga.json b/mocks/imagga.json new file mode 100644 index 0000000..ea2b659 --- /dev/null +++ b/mocks/imagga.json @@ -0,0 +1,199 @@ +[ + { + "httpRequest": { + "method": "POST", + "path": "/uploads" + }, + "httpResponse": { + "statusCode": 200, + "body": { + "result": { + "upload_id": "i05e132196706b94b1d85efb5f3SaM1j" + }, + "status": { + "text": "", + "type": "success" + } + } + } + }, + { + "httpRequest": { + "method": "GET", + "path": "/tags", + "query": { + "image_upload_id": "i05e132196706b94b1d85efb5f3SaM1j" + } + }, + "httpResponse": { + "statusCode": 200, + "body": { + "result": { + "tags": [ + { + "confidence": 61.4116096496582, + "tag": { + "en": "mountain" + } + }, + { + "confidence": 54.3507270812988, + "tag": { + "en": "landscape" + } + } + ] + }, + "status": { + "text": "", + "type": "success" + } + } + } + }, + { + "httpRequest": { + "method": "GET", + "path": "/colors", + "query": { + "image_upload_id": "i05e132196706b94b1d85efb5f3SaM1j" + } + }, + "httpResponse": { + "statusCode": 200, + "body": { + "result": { + "colors": { + "background_colors": [ + { + "b": 47, + "closest_palette_color": "light bronze", + "closest_palette_color_html_code": "#8c5e37", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 1.70506228322597, + "g": 92, + "html_code": "#8c5c2f", + "percent": 48.0033950805664, + "r": 140 + }, + { + "b": 146, + "closest_palette_color": "cerulean", + "closest_palette_color_html_code": "#0074a8", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 5.53350780052479, + "g": 116, + "html_code": "#467492", + "percent": 39.0454025268555, + "r": 70 + }, + { + "b": 30, + "closest_palette_color": "dark bronze", + "closest_palette_color_html_code": "#542e0c", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 5.47689735887696, + "g": 48, + "html_code": "#4f301e", + "percent": 12.9512014389038, + "r": 79 + } + ], + "color_percent_threshold": 1.75, + "color_variance": 36, + "foreground_colors": [ + { + "b": 147, + "closest_palette_color": "larkspur", + "closest_palette_color_html_code": "#6e7e99", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 8.60114706674971, + "g": 125, + "html_code": "#577d93", + "percent": 52.3429222106934, + "r": 87 + }, + { + "b": 145, + "closest_palette_color": "pewter", + "closest_palette_color_html_code": "#84898c", + "closest_palette_color_parent": "grey", + "closest_palette_distance": 1.75501013175431, + "g": 142, + "html_code": "#898e91", + "percent": 30.0293598175049, + "r": 137 + }, + { + "b": 42, + "closest_palette_color": "brownie", + "closest_palette_color_html_code": "#584039", + "closest_palette_color_parent": "brown", + "closest_palette_distance": 4.99189248709017, + "g": 58, + "html_code": "#593a2a", + "percent": 17.6277160644531, + "r": 89 + } + ], + "image_colors": [ + { + "b": 146, + "closest_palette_color": "cerulean", + "closest_palette_color_html_code": "#0074a8", + "closest_palette_color_parent": "blue", + "closest_palette_distance": 7.85085588656478, + "g": 121, + "html_code": "#547992", + "percent": 48.3686981201172, + "r": 84 + }, + { + "b": 46, + "closest_palette_color": "light bronze", + "closest_palette_color_html_code": "#8c5e37", + "closest_palette_color_parent": "skin", + "closest_palette_distance": 3.05634270891355, + "g": 86, + "html_code": "#83562e", + "percent": 47.9353446960449, + "r": 131 + }, + { + "b": 46, + "closest_palette_color": "navy blue", + "closest_palette_color_html_code": "#2b2e43", + "closest_palette_color_parent": "navy blue", + "closest_palette_distance": 6.62790662069936, + "g": 27, + "html_code": "#1f1b2e", + "percent": 3.60131478309631, + "r": 31 + } + ], + "object_percentage": 20.790994644165 + } + }, + "status": { + "text": "", + "type": "success" + } + } + } + }, + { + "httpRequest": { + "method": "DELETE", + "path": "/uploads/i05e132196706b94b1d85efb5f3SaM1j" + }, + "httpResponse": { + "statusCode": 200, + "body": { + "status": { + "text": "", + "type": "success" + } + } + } + } +] diff --git a/mocks/mockserver.properties b/mocks/mockserver.properties new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index f8fbda2..4e74749 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "dotenv": "16.4.5", "eslint": "9.15.0", "eslint-plugin-unicorn": "56.0.1", + "mockserver-client": "5.15.0", "rollup-plugin-node-externals": "7.1.3", "typescript": "5.6.3", "typescript-eslint": "8.15.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d9c78f7..c5fcb6c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,7 +23,7 @@ importers: version: 2.27.10 '@directus/api': specifier: 23.1.3 - version: 23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)) + version: 23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(bufferutil@4.0.8)(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.11(typescript@5.6.3)) '@directus/env': specifier: 4.0.0 version: 4.0.0(vue@3.5.11(typescript@5.6.3)) @@ -51,6 +51,9 @@ importers: eslint-plugin-unicorn: specifier: 56.0.1 version: 56.0.1(eslint@9.15.0) + mockserver-client: + specifier: 5.15.0 + version: 5.15.0 rollup-plugin-node-externals: specifier: 7.1.3 version: 7.1.3(rollup@3.29.4) @@ -2367,6 +2370,9 @@ packages: resolution: {integrity: sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==} engines: {node: '>=8'} + asap@2.0.6: + resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==} + asn1@0.2.6: resolution: {integrity: sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==} @@ -2467,6 +2473,9 @@ packages: resolution: {integrity: sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==} engines: {node: '>=8'} + browser-or-node@2.1.1: + resolution: {integrity: sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==} + browserslist@4.24.2: resolution: {integrity: sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -2487,6 +2496,10 @@ packages: buffer@6.0.3: resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==} + bufferutil@4.0.8: + resolution: {integrity: sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==} + engines: {node: '>=6.14.2'} + builtin-modules@3.3.0: resolution: {integrity: sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==} engines: {node: '>=6'} @@ -2957,6 +2970,10 @@ packages: custom-error-instance@2.1.1: resolution: {integrity: sha512-p6JFxJc3M4OTD2li2qaHkDCw9SfMw82Ldr6OC9Je1aXiGfhx2W8p3GaoeaGrPJTUN9NirTM/KTxHWMUdR1rsUg==} + d@1.0.2: + resolution: {integrity: sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==} + engines: {node: '>=0.12'} + dataloader@1.4.0: resolution: {integrity: sha512-68s5jYdlvasItOJnCuI2Q9s4q98g0pCyL3HrcKJu8KNugUl8ahgmZYg38ysLTgQjjXX3H8CJLkAvWrclWfcalw==} @@ -3173,6 +3190,17 @@ packages: es-module-lexer@1.5.4: resolution: {integrity: sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==} + es5-ext@0.10.64: + resolution: {integrity: sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==} + engines: {node: '>=0.10'} + + es6-iterator@2.0.3: + resolution: {integrity: sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==} + + es6-symbol@3.1.4: + resolution: {integrity: sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==} + engines: {node: '>=0.12'} + esbuild@0.17.19: resolution: {integrity: sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==} engines: {node: '>=12'} @@ -3240,6 +3268,10 @@ packages: resolution: {integrity: sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==} engines: {node: '>=6'} + esniff@2.0.1: + resolution: {integrity: sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==} + engines: {node: '>=0.10'} + espree@10.3.0: resolution: {integrity: sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -3275,6 +3307,9 @@ packages: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} + event-emitter@0.3.5: + resolution: {integrity: sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==} + event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -3315,6 +3350,9 @@ packages: resolution: {integrity: sha512-pLdae7I6QqShF5PnNTCVn4hI91Dx0Grkn2+IAsMTgMIKuQVte2dN9PeGSSAME2FR8anOhVA62QDIUaWVfEXVLw==} engines: {node: '>= 0.10.0'} + ext@1.7.0: + resolution: {integrity: sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==} + extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} @@ -3832,6 +3870,9 @@ packages: resolution: {integrity: sha512-2AT6j+gXe/1ueqbW6fLZJiIw3F8iXGJtt0yDrZaBhAZEG1raiTxKWU+IPqMCzQAXOUCKdA4UDMgacKH25XG2Cw==} engines: {node: '>=4'} + is-typedarray@1.0.0: + resolution: {integrity: sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==} + is-unicode-supported@1.3.0: resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} engines: {node: '>=12'} @@ -4295,6 +4336,10 @@ packages: mnemonist@0.39.8: resolution: {integrity: sha512-vyWo2K3fjrUw8YeeZ1zF0fy6Mu59RHokURlld8ymdUPjMlD9EC9ov1/YPqTgqRvUN9nTr3Gqfz29LYAmu0PHPQ==} + mockserver-client@5.15.0: + resolution: {integrity: sha512-t0DiypyKH60cX1L9ubUMNnJz+XxmwTYHVdFePQMUNnrwBgERcA5WNqKyuttxRMf7P/WiWO3nWHNHSlPirIFEPw==} + engines: {node: '>= 0.8.0'} + mri@1.1.4: resolution: {integrity: sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w==} engines: {node: '>=4'} @@ -4356,6 +4401,9 @@ packages: resolution: {integrity: sha512-myRT3DiWPHqho5PrJaIRyaMv2kgYf0mUVgBNOYMuCH5Ki1yEiQaf/ZJuQ62nvpc44wL5WDbTX7yGJi1Neevw8w==} engines: {node: '>= 0.6'} + next-tick@1.1.0: + resolution: {integrity: sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==} + node-abi@3.71.0: resolution: {integrity: sha512-SZ40vRiy/+wRTf21hxkkEjPJZpARzUMVcJoQse2EF8qkUWbbO2z7vd5oA/H6bVH6SZQ5STGcu0KRDS7biNRfxw==} engines: {node: '>=10'} @@ -4767,6 +4815,9 @@ packages: resolution: {integrity: sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==} engines: {node: '>=4'} + pop-iterate@1.0.1: + resolution: {integrity: sha512-HRCx4+KJE30JhX84wBN4+vja9bNfysxg1y28l0DuJmkoaICiv2ZSilKddbS48pq50P8d2erAhqDLbp47yv3MbQ==} + postcss-calc@8.2.4: resolution: {integrity: sha512-SmWMSJmB8MRnnULldx0lQIyhSNvuDl9HfrZkaqqE/WHAhToYsAvDq+yAsA/kIyINDszOp3Rh0GFoNuH5Ypsm3Q==} peerDependencies: @@ -5044,6 +5095,13 @@ packages: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} + q@2.0.3: + resolution: {integrity: sha512-gv6vLGcmAOg96/fgo3d9tvA4dJNZL3fMyBqVRrGxQ+Q/o4k9QzbJ3NQF9cOO/71wRodoXhaPgphvMFU68qVAJQ==} + deprecated: |- + You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other. + + (For a CapTP with native promises, see @endo/eventual-send and @endo/captp) + qs@6.11.0: resolution: {integrity: sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==} engines: {node: '>=0.6'} @@ -5670,6 +5728,12 @@ packages: resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==} engines: {node: '>= 0.6'} + type@2.7.3: + resolution: {integrity: sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ==} + + typedarray-to-buffer@3.1.5: + resolution: {integrity: sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==} + typedarray@0.0.7: resolution: {integrity: sha512-ueeb9YybpjhivjbHP2LdFDAjbS948fGEPj+ACAMs4xCMmh72OCOMQWBQKlaN4ZNQ04yfLSDLSx1tGRIoWimObQ==} @@ -5731,6 +5795,10 @@ packages: url-parse@1.5.10: resolution: {integrity: sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==} + utf-8-validate@5.0.10: + resolution: {integrity: sha512-Z6czzLq4u8fPOyx7TU6X3dvUZVvoJmxSQ+IcrlmagKhilxlhZgxPK6C5Jqbkw1IDUmFTM+cz9QDnnLTwDz/2gQ==} + engines: {node: '>=6.14.2'} + util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} @@ -5885,9 +5953,16 @@ packages: wcwidth@1.0.1: resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==} + weak-map@1.0.8: + resolution: {integrity: sha512-lNR9aAefbGPpHO7AEnY0hCFjz1eTkWCXYvkTRrTHs9qv8zJp+SkVYpzfLIFXQQiG3tVvbNFQgVg2bQS8YGgxyw==} + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} + websocket@1.0.35: + resolution: {integrity: sha512-/REy6amwPZl44DDzvRCkaI1q1bIiQB0mEFQLUrhz3z2EK91cp3n72rAjUlrTP0zV22HJIUOVHQGPxhFRjxjt+Q==} + engines: {node: '>=4.0.0'} + wellknown@0.5.0: resolution: {integrity: sha512-za5vTLuPF9nmrVOovYQwNEWE/PwJCM+yHMAj4xN1WWUvtq9OElsvKiPL0CR9rO8xhrYqL7NpI7IknqR8r6eYOg==} hasBin: true @@ -5965,6 +6040,10 @@ packages: resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==} engines: {node: '>=0.4'} + yaeti@0.0.6: + resolution: {integrity: sha512-MvQa//+KcZCUkBTIC9blM+CU9J2GzuTytsOUwf2lidtvkx/6gnEp1QvJv34t9vdjhFmha/mUiNDbN0D0mJWdug==} + engines: {node: '>=0.10.32'} + yallist@4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} @@ -6918,7 +6997,7 @@ snapshots: human-id: 1.0.2 prettier: 2.8.8 - '@directus/api@23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3))': + '@directus/api@23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(bufferutil@4.0.8)(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.11(typescript@5.6.3))': dependencies: '@authenio/samlify-node-xmllint': 2.0.0(samlify@2.8.10) '@aws-sdk/client-ses': 3.668.0 @@ -6969,7 +7048,7 @@ snapshots: date-fns: 4.1.0 deep-diff: 1.0.2 destroy: 1.2.0 - directus: 11.2.2(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)) + directus: 11.2.2(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(bufferutil@4.0.8)(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.11(typescript@5.6.3)) dotenv: 16.4.5 encodeurl: 2.0.0 eventemitter2: 6.4.9 @@ -7031,7 +7110,7 @@ snapshots: tar: 7.4.3 tsx: 4.19.1 wellknown: 0.5.0 - ws: 8.18.0 + ws: 8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) zod: 3.23.8 zod-validation-error: 3.4.0(zod@3.23.8) optionalDependencies: @@ -9134,6 +9213,8 @@ snapshots: arrify@2.0.1: {} + asap@2.0.6: {} + asn1@0.2.6: dependencies: safer-buffer: 2.1.2 @@ -9262,6 +9343,8 @@ snapshots: dependencies: fill-range: 7.1.1 + browser-or-node@2.1.1: {} + browserslist@4.24.2: dependencies: caniuse-lite: 1.0.30001680 @@ -9288,6 +9371,10 @@ snapshots: base64-js: 1.5.1 ieee754: 1.2.1 + bufferutil@4.0.8: + dependencies: + node-gyp-build: 4.8.3 + builtin-modules@3.3.0: {} busboy@1.6.0: @@ -9615,6 +9702,11 @@ snapshots: custom-error-instance@2.1.1: {} + d@1.0.2: + dependencies: + es5-ext: 0.10.64 + type: 2.7.3 + dataloader@1.4.0: {} date-fns@4.1.0: {} @@ -9685,9 +9777,9 @@ snapshots: dependencies: path-type: 4.0.0 - directus@11.2.2(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)): + directus@11.2.2(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(bufferutil@4.0.8)(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.11(typescript@5.6.3)): dependencies: - '@directus/api': 23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)) + '@directus/api': 23.1.3(@types/node@20.17.6)(@unhead/vue@1.11.7(vue@3.5.11(typescript@5.6.3)))(bufferutil@4.0.8)(encoding@0.1.13)(lodash@4.17.21)(pinia@2.2.4(typescript@5.6.3)(vue@3.5.11(typescript@5.6.3)))(terser@5.36.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.11(typescript@5.6.3)) '@directus/update-check': 12.0.2 transitivePeerDependencies: - '@types/node' @@ -9867,6 +9959,24 @@ snapshots: es-module-lexer@1.5.4: {} + es5-ext@0.10.64: + dependencies: + es6-iterator: 2.0.3 + es6-symbol: 3.1.4 + esniff: 2.0.1 + next-tick: 1.1.0 + + es6-iterator@2.0.3: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + es6-symbol: 3.1.4 + + es6-symbol@3.1.4: + dependencies: + d: 1.0.2 + ext: 1.7.0 + esbuild@0.17.19: optionalDependencies: '@esbuild/android-arm': 0.17.19 @@ -10048,6 +10158,13 @@ snapshots: esm@3.2.25: {} + esniff@2.0.1: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + event-emitter: 0.3.5 + type: 2.7.3 + espree@10.3.0: dependencies: acorn: 8.14.0 @@ -10076,6 +10193,11 @@ snapshots: etag@1.8.1: {} + event-emitter@0.3.5: + dependencies: + d: 1.0.2 + es5-ext: 0.10.64 + event-target-shim@5.0.1: {} eventemitter2@6.4.9: {} @@ -10152,6 +10274,10 @@ snapshots: transitivePeerDependencies: - supports-color + ext@1.7.0: + dependencies: + type: 2.7.3 + extend@3.0.2: {} extendable-error@0.1.7: {} @@ -10699,6 +10825,8 @@ snapshots: dependencies: better-path-resolve: 1.0.0 + is-typedarray@1.0.0: {} + is-unicode-supported@1.3.0: {} is-unicode-supported@2.1.0: {} @@ -11149,6 +11277,14 @@ snapshots: dependencies: obliterator: 2.0.4 + mockserver-client@5.15.0: + dependencies: + browser-or-node: 2.1.1 + q: 2.0.3 + websocket: 1.0.35 + transitivePeerDependencies: + - supports-color + mri@1.1.4: {} mri@1.2.0: {} @@ -11203,6 +11339,8 @@ snapshots: negotiator@0.6.4: optional: true + next-tick@1.1.0: {} + node-abi@3.71.0: dependencies: semver: 7.6.3 @@ -11710,6 +11848,8 @@ snapshots: pluralize@8.0.0: {} + pop-iterate@1.0.1: {} + postcss-calc@8.2.4(postcss@8.4.49): dependencies: postcss: 8.4.49 @@ -11971,6 +12111,12 @@ snapshots: punycode@2.3.1: {} + q@2.0.3: + dependencies: + asap: 2.0.6 + pop-iterate: 1.0.1 + weak-map: 1.0.8 + qs@6.11.0: dependencies: side-channel: 1.0.6 @@ -12762,6 +12908,12 @@ snapshots: media-typer: 0.3.0 mime-types: 2.1.35 + type@2.7.3: {} + + typedarray-to-buffer@3.1.5: + dependencies: + is-typedarray: 1.0.0 + typedarray@0.0.7: {} typescript-eslint@8.15.0(eslint@9.15.0)(typescript@5.6.3): @@ -12822,6 +12974,10 @@ snapshots: querystringify: 2.2.0 requires-port: 1.0.0 + utf-8-validate@5.0.10: + dependencies: + node-gyp-build: 4.8.3 + util-deprecate@1.0.2: {} utils-merge@1.0.1: {} @@ -12956,8 +13112,21 @@ snapshots: dependencies: defaults: 1.0.4 + weak-map@1.0.8: {} + webidl-conversions@3.0.1: {} + websocket@1.0.35: + dependencies: + bufferutil: 4.0.8 + debug: 2.6.9 + es5-ext: 0.10.64 + typedarray-to-buffer: 3.1.5 + utf-8-validate: 5.0.10 + yaeti: 0.0.6 + transitivePeerDependencies: + - supports-color + wellknown@0.5.0: dependencies: concat-stream: 1.5.2 @@ -13014,7 +13183,10 @@ snapshots: wrappy@1.0.2: {} - ws@8.18.0: {} + ws@8.18.0(bufferutil@4.0.8)(utf-8-validate@5.0.10): + optionalDependencies: + bufferutil: 4.0.8 + utf-8-validate: 5.0.10 xml-crypto@3.2.0: dependencies: @@ -13030,6 +13202,8 @@ snapshots: xtend@4.0.2: optional: true + yaeti@0.0.6: {} + yallist@4.0.0: {} yallist@5.0.0: {} diff --git a/src/index.ts b/src/index.ts index cd7dcde..33d37e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,11 +4,6 @@ import { AssetsService, FilesService } from '@directus/api/services/index' import axios from 'axios' import FormData from 'form-data' -/** - * Imagga API endpoint - */ -const IMAGGA_API = 'https://api.imagga.com/v2' - /** * Imagga API response base */ @@ -93,6 +88,11 @@ function mapColorData(input: ColorData[]) { export default defineHook(({ action }, { services, logger }) => { const environment = useEnv() + /** + * Imagga API endpoint + */ + const IMAGGA_API = (environment['IMAGGA_API'] as string) ?? 'https://api.imagga.com/v2' + /** * Imagga API key */ diff --git a/tests/extension.test.ts b/tests/extension.test.ts index d25231e..30ce7db 100644 --- a/tests/extension.test.ts +++ b/tests/extension.test.ts @@ -1,16 +1,43 @@ import { describe, it, expect } from 'vitest' -import { createDirectus, rest, staticToken, readExtensions } from '@directus/sdk' +import { createDirectus, rest, staticToken, readExtensions, uploadFiles, readFile } from "@directus/sdk"; import { name } from '../package.json' +import { readFile as readFileFs } from 'node:fs/promises' +import { mockServerClient } from 'mockserver-client'; describe('extension', () => { const client = createDirectus(process.env.PUBLIC_URL as string) .with(rest()) .with(staticToken(process.env.ADMIN_TOKEN as string)) + const mockClient = mockServerClient('localhost', 1080) + it('register correctly in directus', async () => { const extensions = await client.request(readExtensions()) expect(extensions).toBeDefined() expect(extensions.map(extension => extension.schema?.name)).toContain(name) }) + + /* + it('triggers when image is uploaded', async () => { + const data = new FormData() + const paris = await readFileFs(`${import.meta.dirname}/paris.jpeg`) + data.append('file', new Blob([paris], { type: 'image/jpeg' })) + + const files = await client.request(uploadFiles(data)) + expect(files).toBeDefined() + + console.log(files) + await new Promise(resolve => setTimeout(resolve, 1000)) + + const mockTags = await mockClient.verify({ path: '/uploads' }); + + const file = await client.request(readFile(files.id)) + expect(file).toBeDefined() + + console.log(file) + }, { + timeout: 100_000 + }) + */ }) diff --git a/tests/paris.jpeg b/tests/paris.jpeg new file mode 100644 index 0000000..d7f9d79 Binary files /dev/null and b/tests/paris.jpeg differ