@miso.ai/doggoganger 0.9.0-beta.9 → 0.9.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +1 -0
- package/bin/data.js +15 -0
- package/cli/index.js +8 -7
- package/cli/server.js +1 -1
- package/dist/umd/doggoganger-browser.min.js +1 -0
- package/package.json +14 -4
- package/rollup.config.dev.mjs +3 -0
- package/rollup.config.mjs +3 -0
- package/rollup.util.mjs +42 -0
- package/src/api/ask.js +47 -78
- package/src/api/index.js +14 -17
- package/src/api/interactions.js +10 -6
- package/src/api/products.js +28 -0
- package/src/api/recommendation.js +18 -6
- package/src/api/search.js +12 -5
- package/src/browser.js +5 -0
- package/src/data/answers.js +33 -0
- package/src/data/fields.js +19 -3
- package/src/data/index.js +2 -0
- package/src/data/lorem.js +18 -20
- package/src/data/markdown/index.js +49 -21
- package/src/data/markdown/languages.js +101 -0
- package/src/data/questions.js +11 -0
- package/src/data/utils.js +21 -0
- package/src/data/words.js +182 -0
- package/src/doggoganger.js +54 -0
- package/src/index.js +3 -28
- package/src/middleware/error.js +29 -0
- package/src/middleware/index.js +2 -0
- package/src/middleware/latency.js +39 -0
- package/src/route/ask.js +37 -0
- package/src/route/index.js +26 -0
- package/src/route/interactions.js +17 -0
- package/src/route/products.js +33 -0
- package/src/route/recommendation.js +22 -0
- package/src/route/search.js +15 -0
- package/src/route/utils.js +6 -0
- package/src/utils.js +17 -0
- package/src/api/handlers.js +0 -10
- /package/{src/data → data}/words.yaml +0 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import ask from './ask.js';
|
|
3
|
+
import recommendation from './recommendation.js';
|
|
4
|
+
import search from './search.js';
|
|
5
|
+
import interactions from './interactions.js';
|
|
6
|
+
import products from './products.js';
|
|
7
|
+
import { latency, error } from '../middleware/index.js';
|
|
8
|
+
|
|
9
|
+
function use(router, path, middleware) {
|
|
10
|
+
router.use(path, middleware.routes(), middleware.allowedMethods());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default function(api, options) {
|
|
14
|
+
const router = new Router();
|
|
15
|
+
|
|
16
|
+
router.use(latency(options.latency));
|
|
17
|
+
//router.use(error(options.error));
|
|
18
|
+
|
|
19
|
+
use(router, '/ask', ask(api));
|
|
20
|
+
use(router, '/recommendation', recommendation(api));
|
|
21
|
+
use(router, '/search', search(api));
|
|
22
|
+
use(router, '/interactions', interactions(api));
|
|
23
|
+
use(router, '/products', products(api));
|
|
24
|
+
|
|
25
|
+
return router;
|
|
26
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { parseBodyIfNecessary } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export default function(api) {
|
|
5
|
+
const router = new Router();
|
|
6
|
+
|
|
7
|
+
router.post('/', (ctx) => {
|
|
8
|
+
const { data } = parseBodyIfNecessary(ctx.request.body);
|
|
9
|
+
ctx.body = {
|
|
10
|
+
took: 5,
|
|
11
|
+
errors: false,
|
|
12
|
+
data: api.interactions.upload(data),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return router;
|
|
17
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { parseBodyIfNecessary } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export default function(api) {
|
|
5
|
+
const router = new Router();
|
|
6
|
+
|
|
7
|
+
router.post('/', (ctx) => {
|
|
8
|
+
const { data } = parseBodyIfNecessary(ctx.request.body);
|
|
9
|
+
ctx.body = {
|
|
10
|
+
took: 5,
|
|
11
|
+
errors: false,
|
|
12
|
+
data: api.products.upload(data),
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
router.get('/_ids', (ctx) => {
|
|
17
|
+
ctx.body = {
|
|
18
|
+
message: 'success',
|
|
19
|
+
data: api.products.ids(),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
router.get('/_status/:taskId', (ctx) => {
|
|
24
|
+
ctx.body = {
|
|
25
|
+
took: 100,
|
|
26
|
+
errors: false,
|
|
27
|
+
data: [],
|
|
28
|
+
code: 200,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return router;
|
|
33
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { parseBodyIfNecessary } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export default function(api) {
|
|
5
|
+
const router = new Router();
|
|
6
|
+
|
|
7
|
+
router.post('/user_to_products', (ctx) => {
|
|
8
|
+
const { rows = 5 } = parseBodyIfNecessary(ctx.request.body);
|
|
9
|
+
ctx.body = {
|
|
10
|
+
data: api.recommendation.user_to_products({ rows }),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
router.post('/product_to_products', (ctx) => {
|
|
15
|
+
const { rows = 5 } = parseBodyIfNecessary(ctx.request.body);
|
|
16
|
+
ctx.body = {
|
|
17
|
+
data: api.recommendation.product_to_products({ rows }),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return router;
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Router from '@koa/router';
|
|
2
|
+
import { parseBodyIfNecessary } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export default function(api) {
|
|
5
|
+
const router = new Router();
|
|
6
|
+
|
|
7
|
+
router.post('/search', (ctx) => {
|
|
8
|
+
const { rows = 5 } = parseBodyIfNecessary(ctx.request.body);
|
|
9
|
+
ctx.body = {
|
|
10
|
+
data: api.search.search({ rows }),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return router;
|
|
15
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -24,3 +24,20 @@ export async function exclusion(ctx, next) {
|
|
|
24
24
|
ctx.status = 404;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export async function delay(time) {
|
|
29
|
+
return new Promise(resolve => setTimeout(resolve, time));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function trimObj(obj) {
|
|
33
|
+
if (typeof obj !== 'object') {
|
|
34
|
+
return obj;
|
|
35
|
+
}
|
|
36
|
+
const trimmed = {};
|
|
37
|
+
for (const k in obj) {
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(obj, k) && obj[k] !== undefined) {
|
|
39
|
+
trimmed[k] = obj[k];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return trimmed;
|
|
43
|
+
}
|
package/src/api/handlers.js
DELETED
|
File without changes
|