@unchainedshop/core-bookmarks 1.1.3
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/.npm/package/README +7 -0
- package/.npm/package/npm-shrinkwrap.json +40 -0
- package/.versions +17 -0
- package/README.md +3 -0
- package/package.js +21 -0
- package/package.json +41 -0
- package/src/bookmarks-index.ts +2 -0
- package/src/db/BookmarksCollection.ts +11 -0
- package/src/db/BookmarksSchema.js +11 -0
- package/src/module/configureBookmarksModule.ts +84 -0
- package/src/service/bookmarkServices.ts +6 -0
- package/src/service/migrateBookmarksService.ts +18 -0
- package/tests/bookmarks-index.test.ts +70 -0
- package/tsconfig.build.json +26 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
This directory and the files immediately inside it are automatically generated
|
|
2
|
+
when you change this package's NPM dependencies. Commit the files in this
|
|
3
|
+
directory (npm-shrinkwrap.json, .gitignore, and this README) to source control
|
|
4
|
+
so that others run the same versions of sub-dependencies.
|
|
5
|
+
|
|
6
|
+
You should NOT check in the node_modules directory that Meteor automatically
|
|
7
|
+
creates; if you are using git, the .gitignore file tells git to ignore it.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"clone": {
|
|
5
|
+
"version": "2.1.2",
|
|
6
|
+
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
|
7
|
+
"integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w=="
|
|
8
|
+
},
|
|
9
|
+
"lodash._reinterpolate": {
|
|
10
|
+
"version": "3.0.0",
|
|
11
|
+
"resolved": "https://registry.npmjs.org/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz",
|
|
12
|
+
"integrity": "sha512-xYHt68QRoYGjeeM/XOE1uJtvXQAgvszfBhjV4yvsQH0u2i9I6cI6c6/eG4Hh3UAOVn0y/xAXwmTzEay49Q//HA=="
|
|
13
|
+
},
|
|
14
|
+
"lodash.template": {
|
|
15
|
+
"version": "4.5.0",
|
|
16
|
+
"resolved": "https://registry.npmjs.org/lodash.template/-/lodash.template-4.5.0.tgz",
|
|
17
|
+
"integrity": "sha512-84vYFxIkmidUiFxidA/KjjH9pAycqW+h980j7Fuz5qxRtO9pgB7MDFTdys1N7A5mcucRiDyEq4fusljItR1T/A=="
|
|
18
|
+
},
|
|
19
|
+
"lodash.templatesettings": {
|
|
20
|
+
"version": "4.2.0",
|
|
21
|
+
"resolved": "https://registry.npmjs.org/lodash.templatesettings/-/lodash.templatesettings-4.2.0.tgz",
|
|
22
|
+
"integrity": "sha512-stgLz+i3Aa9mZgnjr/O+v9ruKZsPsndy7qPZOchbqk2cnTU1ZaldKK+v7m54WoKIyxiuMZTKT2H81F8BeAc3ZQ=="
|
|
23
|
+
},
|
|
24
|
+
"message-box": {
|
|
25
|
+
"version": "0.2.7",
|
|
26
|
+
"resolved": "https://registry.npmjs.org/message-box/-/message-box-0.2.7.tgz",
|
|
27
|
+
"integrity": "sha512-C4ccA5nHb58kTS+pLrgF/JWtr7fAIkHxRDceH7tdy5fMA783nUfbYwZ7H2XLvSeYfcnWIYCig5dWW+icK9X/Ag=="
|
|
28
|
+
},
|
|
29
|
+
"mongo-object": {
|
|
30
|
+
"version": "0.1.4",
|
|
31
|
+
"resolved": "https://registry.npmjs.org/mongo-object/-/mongo-object-0.1.4.tgz",
|
|
32
|
+
"integrity": "sha512-QtYk0gupWEn2+iB+DDRt1L+WbcNYvJRaHdih/dcqthOa1DbnREUGSs2WGcW478GNYpElflo/yybZXu0sTiRXHg=="
|
|
33
|
+
},
|
|
34
|
+
"simpl-schema": {
|
|
35
|
+
"version": "1.12.0",
|
|
36
|
+
"resolved": "https://registry.npmjs.org/simpl-schema/-/simpl-schema-1.12.0.tgz",
|
|
37
|
+
"integrity": "sha512-lzXC3L8jJbPhNXGR3cjlyIauqqrC5WUJS4O34Ym/wLIvb8K3ZieK+1OfTzs4mBpDc3Y8u53gQFAr1X37DmTcEg=="
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
package/.versions
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
babel-compiler@7.9.0
|
|
2
|
+
babel-runtime@1.5.1
|
|
3
|
+
dynamic-import@0.7.2
|
|
4
|
+
ecmascript@0.16.2
|
|
5
|
+
ecmascript-runtime@0.8.0
|
|
6
|
+
ecmascript-runtime-client@0.12.1
|
|
7
|
+
ecmascript-runtime-server@0.11.0
|
|
8
|
+
fetch@0.1.1
|
|
9
|
+
inter-process-messaging@0.1.1
|
|
10
|
+
meteor@1.10.0
|
|
11
|
+
modern-browsers@0.1.8
|
|
12
|
+
modules@0.18.0
|
|
13
|
+
modules-runtime@0.13.0
|
|
14
|
+
promise@0.12.0
|
|
15
|
+
react-fast-refresh@0.2.3
|
|
16
|
+
typescript@4.5.4
|
|
17
|
+
unchained:core-bookmarks@1.1.1
|
package/README.md
ADDED
package/package.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Package.describe({
|
|
2
|
+
name: 'unchained:core-bookmarks',
|
|
3
|
+
version: '1.1.3',
|
|
4
|
+
summary: 'Unchained Engine Core: Warehousing',
|
|
5
|
+
git: 'https://github.com/unchainedshop/unchained',
|
|
6
|
+
documentation: 'README.md',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
Npm.depends({
|
|
10
|
+
'simpl-schema': '1.12.0',
|
|
11
|
+
'@unchainedshop/utils': '1.1.3',
|
|
12
|
+
// '@unchainedshop/events': '1.1.4', // PEER
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
Package.onUse((api) => {
|
|
16
|
+
api.versionsFrom('2.7.3');
|
|
17
|
+
api.use('ecmascript');
|
|
18
|
+
api.use('typescript');
|
|
19
|
+
|
|
20
|
+
api.mainModule('src/bookmarks-index.ts', 'server');
|
|
21
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unchainedshop/core-bookmarks",
|
|
3
|
+
"version": "1.1.3",
|
|
4
|
+
"main": "lib/bookmarks-index.js",
|
|
5
|
+
"types": "lib/bookmarks-index.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"watch": "tsc --watch",
|
|
10
|
+
"link:core": "npm link @unchainedshop/types",
|
|
11
|
+
"test": "cross-env METEOR_PACKAGE_DIRS=../ TEST_CLIENT=0 TEST_WATCH=1 meteor test-packages ./ --driver-package meteortesting:mocha --port 4200"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/unchainedshop/unchained.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"unchained",
|
|
19
|
+
"ecommerce",
|
|
20
|
+
"core"
|
|
21
|
+
],
|
|
22
|
+
"author": "Joël Meiller",
|
|
23
|
+
"license": "EUPL-1.2",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@unchainedshop/events": "latest",
|
|
30
|
+
"@unchainedshop/utils": "latest",
|
|
31
|
+
"simpl-schema": "^1.12.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/chai": "^4.3.1",
|
|
35
|
+
"@types/mocha": "^9.1.1",
|
|
36
|
+
"@unchainedshop/types": "latest",
|
|
37
|
+
"chai": "^4.3.6",
|
|
38
|
+
"cross-env": "^7.0.3",
|
|
39
|
+
"typescript": "^4.7.4"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Db } from '@unchainedshop/types/common';
|
|
2
|
+
import { Bookmark } from '@unchainedshop/types/bookmarks';
|
|
3
|
+
|
|
4
|
+
export const BookmarksCollection = async (db: Db) => {
|
|
5
|
+
const Bookmarks = db.collection<Bookmark>('bookmarks');
|
|
6
|
+
|
|
7
|
+
await Bookmarks.createIndex({ userId: 1 });
|
|
8
|
+
await Bookmarks.createIndex({ productId: 1 });
|
|
9
|
+
|
|
10
|
+
return Bookmarks;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
|
|
4
|
+
export const BookmarkSchema = new SimpleSchema(
|
|
5
|
+
{
|
|
6
|
+
userId: { type: String, required: true },
|
|
7
|
+
productId: { type: String, required: true },
|
|
8
|
+
...Schemas.timestampFields,
|
|
9
|
+
},
|
|
10
|
+
{ requiredByDefault: false },
|
|
11
|
+
);
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
+
import { Bookmark, BookmarksModule } from '@unchainedshop/types/bookmarks';
|
|
3
|
+
import { ModuleInput, ModuleMutations } from '@unchainedshop/types/common';
|
|
4
|
+
import { generateDbFilterById, generateDbMutations } from '@unchainedshop/utils';
|
|
5
|
+
import { BookmarksCollection } from '../db/BookmarksCollection';
|
|
6
|
+
import { BookmarkSchema } from '../db/BookmarksSchema';
|
|
7
|
+
|
|
8
|
+
const BOOKMARK_EVENTS: string[] = ['BOOKMARK_CREATE', 'BOOKMARKS_UPDATE', 'BOOKMARK_REMOVE'];
|
|
9
|
+
|
|
10
|
+
export const configureBookmarksModule = async ({
|
|
11
|
+
db,
|
|
12
|
+
}: ModuleInput<Record<string, never>>): Promise<BookmarksModule> => {
|
|
13
|
+
registerEvents(BOOKMARK_EVENTS);
|
|
14
|
+
|
|
15
|
+
const Bookmarks = await BookmarksCollection(db);
|
|
16
|
+
|
|
17
|
+
const mutations = generateDbMutations<Bookmark>(Bookmarks, BookmarkSchema, {
|
|
18
|
+
permanentlyDeleteByDefault: true,
|
|
19
|
+
}) as ModuleMutations<Bookmark>;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
// Queries
|
|
23
|
+
...mutations,
|
|
24
|
+
findByUserId: async (userId) => Bookmarks.find({ userId }).toArray(),
|
|
25
|
+
findByUserIdAndProductId: async ({ userId, productId }) => Bookmarks.findOne({ userId, productId }),
|
|
26
|
+
findById: async (bookmarkId) => {
|
|
27
|
+
const filter = generateDbFilterById(bookmarkId);
|
|
28
|
+
return Bookmarks.findOne(filter, {});
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
find: async (query) => Bookmarks.find(query).toArray(),
|
|
32
|
+
|
|
33
|
+
existsByUserIdAndProductId: async ({ productId, userId }) => {
|
|
34
|
+
let selector = {};
|
|
35
|
+
if (productId && userId) {
|
|
36
|
+
selector = { userId, productId };
|
|
37
|
+
} else if (userId) {
|
|
38
|
+
selector = { userId };
|
|
39
|
+
}
|
|
40
|
+
const bookmarkCount = await Bookmarks.countDocuments(selector, {
|
|
41
|
+
limit: 1,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return !!bookmarkCount;
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// Mutations
|
|
48
|
+
replaceUserId: async (fromUserId, toUserId, userId) => {
|
|
49
|
+
const result = await Bookmarks.updateMany(
|
|
50
|
+
{ userId: fromUserId },
|
|
51
|
+
{
|
|
52
|
+
$set: {
|
|
53
|
+
userId: toUserId,
|
|
54
|
+
updated: new Date(),
|
|
55
|
+
updatedBy: userId,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
return result.upsertedCount;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
deleteByUserId: async (toUserId) => {
|
|
63
|
+
const result = await Bookmarks.deleteMany({ userId: toUserId });
|
|
64
|
+
|
|
65
|
+
return result.deletedCount;
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
create: async (doc: Bookmark, userId: string) => {
|
|
69
|
+
const bookmarkId = await mutations.create(doc, userId);
|
|
70
|
+
emit('BOOKMARK_CREATE', { bookmarkId });
|
|
71
|
+
return bookmarkId;
|
|
72
|
+
},
|
|
73
|
+
update: async (_id: string, doc: Bookmark, userId: string) => {
|
|
74
|
+
const bookmarkId = await mutations.update(_id, doc, userId);
|
|
75
|
+
emit('BOOKMARK_UPDATE', { bookmarkId });
|
|
76
|
+
return bookmarkId;
|
|
77
|
+
},
|
|
78
|
+
delete: async (bookmarkId, userId) => {
|
|
79
|
+
const deletedCount = await mutations.delete(bookmarkId, userId);
|
|
80
|
+
emit('BOOKMARK_REMOVE', { bookmarkId });
|
|
81
|
+
return deletedCount;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MigrateBookmarksService } from '@unchainedshop/types/bookmarks';
|
|
2
|
+
|
|
3
|
+
export const migrateBookmarksService: MigrateBookmarksService = async (
|
|
4
|
+
{ fromUser, toUser, shouldMerge },
|
|
5
|
+
{ modules, userId },
|
|
6
|
+
) => {
|
|
7
|
+
const fromBookmarks = await modules.bookmarks.find({ userId: fromUser._id });
|
|
8
|
+
if (!fromBookmarks) {
|
|
9
|
+
// No bookmarks no copy needed
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (!shouldMerge) {
|
|
13
|
+
await modules.bookmarks.deleteByUserId(toUser._id, userId);
|
|
14
|
+
}
|
|
15
|
+
await modules.bookmarks.replaceUserId(fromUser._id, toUser._id, userId);
|
|
16
|
+
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
import { initDb } from 'meteor/unchained:mongodb';
|
|
3
|
+
import { configureBookmarksModule } from 'meteor/unchained:core-bookmarks';
|
|
4
|
+
|
|
5
|
+
describe('Test exports', () => {
|
|
6
|
+
let module;
|
|
7
|
+
|
|
8
|
+
before(async () => {
|
|
9
|
+
const db = await initDb();
|
|
10
|
+
module = await configureBookmarksModule({ db });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('Check Bookmarks module', async () => {
|
|
14
|
+
assert.ok(module);
|
|
15
|
+
assert.isFunction(module.findByUserIdAndProductId);
|
|
16
|
+
assert.isFunction(module.existsByUserIdAndProductId);
|
|
17
|
+
assert.isFunction(module.create);
|
|
18
|
+
assert.isFunction(module.update);
|
|
19
|
+
assert.isFunction(module.delete);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Mutate bookmark', async () => {
|
|
23
|
+
const bookmarkId = await module.create(
|
|
24
|
+
{
|
|
25
|
+
userId: 'Test-User-1',
|
|
26
|
+
productId: 'Product-22',
|
|
27
|
+
},
|
|
28
|
+
'Test-User-1'
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
assert.ok(bookmarkId);
|
|
32
|
+
const bookmark = await module.findById(bookmarkId);
|
|
33
|
+
|
|
34
|
+
assert.ok(bookmark);
|
|
35
|
+
assert.equal(bookmark._id, bookmarkId);
|
|
36
|
+
assert.equal(bookmark.userId, 'Test-User-1');
|
|
37
|
+
assert.equal(bookmark.productId, 'Product-22');
|
|
38
|
+
assert.isDefined(bookmark.created);
|
|
39
|
+
assert.isUndefined(bookmark.updated);
|
|
40
|
+
assert.isUndefined(bookmark.updatedBy);
|
|
41
|
+
assert.equal(bookmark.createdBy, 'Test-User-1');
|
|
42
|
+
|
|
43
|
+
const deletedCount = await module.delete(bookmarkId);
|
|
44
|
+
assert.equal(deletedCount, 1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('Check backwards compatibility', async () => {
|
|
48
|
+
const Bookmarks = new Mongo.Collection<any>('bookmarks');
|
|
49
|
+
|
|
50
|
+
const meteorBookmarkId = Bookmarks.insertOne({
|
|
51
|
+
userId: 'Legacy-Test-User-1',
|
|
52
|
+
productId: 'Legacy-Product-22',
|
|
53
|
+
created: new Date(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
assert.ok(meteorBookmarkId);
|
|
57
|
+
const bookmark = await module.findById(meteorBookmarkId);
|
|
58
|
+
assert.ok(bookmark);
|
|
59
|
+
assert.equal(bookmark._id, meteorBookmarkId);
|
|
60
|
+
assert.equal(bookmark.userId, 'Legacy-Test-User-1');
|
|
61
|
+
assert.equal(bookmark.productId, 'Legacy-Product-22');
|
|
62
|
+
assert.isDefined(bookmark.created);
|
|
63
|
+
assert.isUndefined(bookmark.updated);
|
|
64
|
+
assert.isUndefined(bookmark.updatedBy);
|
|
65
|
+
assert.isUndefined(bookmark.createdBy);
|
|
66
|
+
|
|
67
|
+
const deletedCount = await module.delete(meteorBookmarkId);
|
|
68
|
+
assert.equal(deletedCount, 1);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"allowJs": true,
|
|
4
|
+
"allowSyntheticDefaultImports": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"experimentalDecorators": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"lib": ["esnext"],
|
|
10
|
+
"module": "esnext",
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noUnusedLocals": false,
|
|
14
|
+
"outDir": "lib",
|
|
15
|
+
"preserveWatchOutput": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"target": "esnext",
|
|
19
|
+
"types": ["node"],
|
|
20
|
+
"baseUrl": ".", // This must be specified if "paths" is.
|
|
21
|
+
"paths": {
|
|
22
|
+
"meteor/unchained:*": ["node_modules/@unchainedshop/types/index.d.ts"]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"include": ["src"]
|
|
26
|
+
}
|