@chevre/domain 22.11.0-alpha.8 → 22.11.0-alpha.9

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.
@@ -0,0 +1,46 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
+
11
+ const permissions = [
12
+ 'categoryCodes.read',
13
+ 'creativeWorks.read',
14
+ 'events.read',
15
+ 'places.read',
16
+ 'products.read',
17
+ 'sellers.read'
18
+ ];
19
+ for (const permission of permissions) {
20
+ const roles = await roleRepo.projectFields(
21
+ {
22
+ permissions: { $eq: permission },
23
+ roleName: {
24
+ $in: [
25
+ chevre.factory.role.organizationRole.RoleName.Customer,
26
+ chevre.factory.role.organizationRole.RoleName.POS,
27
+ chevre.factory.role.organizationRole.RoleName.EventsViewer
28
+ ]
29
+ }
30
+ },
31
+ ['roleName']
32
+ );
33
+ console.log('roles found.', roles, permission);
34
+ for (const { roleName } of roles) {
35
+ const result = await roleRepo.removePermissionIfExists({
36
+ roleName: { $eq: roleName },
37
+ permission
38
+ });
39
+ console.log('permission removed.', permission, result, roleName);
40
+ }
41
+ }
42
+ }
43
+
44
+ main()
45
+ .then()
46
+ .catch(console.error);
@@ -0,0 +1,39 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
+
11
+ const permissions = [
12
+ 'tokens',
13
+ 'authorizations.create',
14
+ 'permits.read',
15
+ 'tasks.read',
16
+ 'transactionNumbers.write',
17
+ 'chevre.admin'
18
+ ];
19
+ for (const permission of permissions) {
20
+ const roles = await roleRepo.projectFields(
21
+ {
22
+ permissions: { $eq: permission }
23
+ },
24
+ ['roleName']
25
+ );
26
+ console.log(roles, permission);
27
+ for (const { roleName } of roles) {
28
+ const result = await roleRepo.removePermissionIfExists({
29
+ roleName: { $eq: roleName },
30
+ permission
31
+ });
32
+ console.log('permission removed.', permission, result, roleName);
33
+ }
34
+ }
35
+ }
36
+
37
+ main()
38
+ .then()
39
+ .catch(console.error);
@@ -1,6 +1,8 @@
1
1
  import { Connection, FilterQuery, QueryOptions } from 'mongoose';
2
2
  import * as factory from '../factory';
3
- export type ISavingIdentity = Pick<factory.creativeWork.certification.webApplication.ICertification, 'about' | 'project' | 'typeOf'> & {
3
+ type ISavingSoftwareApplicationIdentity = Pick<factory.creativeWork.certification.softwareApplication.ICertification, 'about' | 'project' | 'typeOf'>;
4
+ type ISavingWebApplicationIdentity = Pick<factory.creativeWork.certification.webApplication.ICertification, 'about' | 'project' | 'typeOf'>;
5
+ export type ISavingIdentity = (ISavingSoftwareApplicationIdentity | ISavingWebApplicationIdentity) & {
4
6
  id?: never;
5
7
  dateCreated?: never;
6
8
  dateModified?: never;
@@ -11,7 +13,7 @@ interface IUnset {
11
13
  [key: string]: 1;
12
14
  };
13
15
  }
14
- type IIdentityWithId = factory.creativeWork.certification.webApplication.ICertification & {
16
+ type IIdentityWithId = (factory.creativeWork.certification.softwareApplication.ICertification | factory.creativeWork.certification.webApplication.ICertification) & {
15
17
  id: string;
16
18
  };
17
19
  type IKeyOfProjection = keyof factory.creativeWork.certification.webApplication.ICertification;
@@ -35,39 +37,15 @@ export declare class IdentityRepo {
35
37
  id: string;
36
38
  };
37
39
  }): Promise<void>;
38
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
39
- project: Pick<factory.project.IProject, "id" | "typeOf">;
40
- typeOf: factory.creativeWorkType.Certification;
41
- about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
42
- dateCreated?: Date | undefined;
43
- dateModified?: Date | undefined;
44
- issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
45
- }> & {
46
- project: Pick<factory.project.IProject, "id" | "typeOf">;
47
- typeOf: factory.creativeWorkType.Certification;
48
- about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
49
- dateCreated?: Date | undefined;
50
- dateModified?: Date | undefined;
51
- issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
52
- } & {
40
+ getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, Omit<import("@chevre/factory/lib/creativeWork/certification/softwareApplication").ICertification, "id"> | Omit<import("@chevre/factory/lib/creativeWork/certification/webApplication").ICertification, "id">> & ((Omit<import("@chevre/factory/lib/creativeWork/certification/softwareApplication").ICertification, "id"> & {
53
41
  _id: import("mongoose").Types.ObjectId;
54
- }, QueryOptions<import("mongoose").Document<unknown, {}, {
55
- project: Pick<factory.project.IProject, "id" | "typeOf">;
56
- typeOf: factory.creativeWorkType.Certification;
57
- about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
58
- dateCreated?: Date | undefined;
59
- dateModified?: Date | undefined;
60
- issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
61
- }> & {
62
- project: Pick<factory.project.IProject, "id" | "typeOf">;
63
- typeOf: factory.creativeWorkType.Certification;
64
- about: import("@chevre/factory/lib/creativeWork/certification/webApplication").IAbout;
65
- dateCreated?: Date | undefined;
66
- dateModified?: Date | undefined;
67
- issuedBy: import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy | import("@chevre/factory/lib/creativeWork/certification/webApplication").IIssuedBy[];
68
- } & {
42
+ }) | (Omit<import("@chevre/factory/lib/creativeWork/certification/webApplication").ICertification, "id"> & {
69
43
  _id: import("mongoose").Types.ObjectId;
70
- }>>;
44
+ })), QueryOptions<import("mongoose").Document<unknown, {}, Omit<import("@chevre/factory/lib/creativeWork/certification/softwareApplication").ICertification, "id"> | Omit<import("@chevre/factory/lib/creativeWork/certification/webApplication").ICertification, "id">> & ((Omit<import("@chevre/factory/lib/creativeWork/certification/softwareApplication").ICertification, "id"> & {
45
+ _id: import("mongoose").Types.ObjectId;
46
+ }) | (Omit<import("@chevre/factory/lib/creativeWork/certification/webApplication").ICertification, "id"> & {
47
+ _id: import("mongoose").Types.ObjectId;
48
+ }))>>;
71
49
  updateIssuedBy2array(params: Pick<ISavingIdentity, 'issuedBy'> & {
72
50
  id: string;
73
51
  }): Promise<void>;
@@ -8,17 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
11
  Object.defineProperty(exports, "__esModule", { value: true });
23
12
  exports.IdentityRepo = void 0;
24
13
  const factory = require("../factory");
@@ -76,12 +65,15 @@ class IdentityRepo {
76
65
  throw new factory.errors.ArgumentNull('id');
77
66
  }
78
67
  // issuedByのみ更新可能
79
- const _c = params.attributes, { id, dateCreated, about, project, typeOf, $unset } = _c, updateFields = __rest(_c, ["id", "dateCreated", "about", "project", "typeOf", "$unset"]);
68
+ const { project, $unset, issuedBy } = params.attributes;
80
69
  const filter = {
81
70
  _id: { $eq: savingId },
82
71
  'project.id': { $eq: project.id }
83
72
  };
84
- const update = Object.assign({ $set: Object.assign(Object.assign({}, updateFields), { dateModified: new Date() }) }, ($unset !== undefined && $unset !== null) ? { $unset } : undefined);
73
+ const update = Object.assign({ $set: {
74
+ issuedBy,
75
+ dateModified: new Date()
76
+ } }, ($unset !== undefined && $unset !== null) ? { $unset } : undefined);
85
77
  const options = {
86
78
  upsert: false,
87
79
  new: true,
@@ -96,8 +88,11 @@ class IdentityRepo {
96
88
  savedId = savingId;
97
89
  }
98
90
  else {
99
- const _d = params.attributes, { $unset, id, dateModified } = _d, createParams = __rest(_d, ["$unset", "id", "dateModified"]);
100
- const result = yield this.identityModel.insertMany(Object.assign(Object.assign({}, createParams), { dateCreated: new Date() }), { rawResult: true });
91
+ const { typeOf, about, project, issuedBy } = params.attributes;
92
+ const result = yield this.identityModel.insertMany({
93
+ typeOf, about, project, issuedBy,
94
+ dateCreated: new Date()
95
+ }, { rawResult: true });
101
96
  const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
102
97
  if (typeof insertedId !== 'string') {
103
98
  throw new factory.errors.Internal(`seller not saved unexpectedly. result:${JSON.stringify(result)}`);
@@ -1,6 +1,6 @@
1
1
  import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
2
  import * as factory from '../../../factory';
3
- type IDocType = Omit<factory.creativeWork.certification.webApplication.ICertification, 'id'>;
3
+ type IDocType = Omit<factory.creativeWork.certification.softwareApplication.ICertification, 'id'> | Omit<factory.creativeWork.certification.webApplication.ICertification, 'id'>;
4
4
  type IModel = Model<IDocType>;
5
5
  type ISchemaDefinition = SchemaDefinition<IDocType>;
6
6
  type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
@@ -26,6 +26,14 @@ export declare class RoleRepo {
26
26
  }): Promise<(import("mongoose").FlattenMaps<IDocType> & {
27
27
  _id: import("mongoose").Types.ObjectId;
28
28
  }) | null>;
29
+ removePermissionIfExists(params: {
30
+ roleName: {
31
+ $eq: factory.role.organizationRole.RoleName;
32
+ };
33
+ permission: string;
34
+ }): Promise<(import("mongoose").FlattenMaps<IDocType> & {
35
+ _id: import("mongoose").Types.ObjectId;
36
+ }) | null>;
29
37
  addMember(params: Pick<IRole, 'member' | 'memberOf' | 'roleName'>): Promise<(import("mongoose").FlattenMaps<IDocType> & {
30
38
  _id: import("mongoose").Types.ObjectId;
31
39
  }) | null>;
@@ -133,6 +133,23 @@ class RoleRepo {
133
133
  .exec();
134
134
  });
135
135
  }
136
+ removePermissionIfExists(params) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ return this.roleModel.findOneAndUpdate({
139
+ roleName: { $eq: params.roleName.$eq },
140
+ permissions: { $eq: params.permission }
141
+ }, {
142
+ $pull: {
143
+ permissions: params.permission
144
+ }
145
+ }, {
146
+ new: true,
147
+ projection: { _id: 1 }
148
+ })
149
+ .lean()
150
+ .exec();
151
+ });
152
+ }
136
153
  addMember(params) {
137
154
  return __awaiter(this, void 0, void 0, function* () {
138
155
  const { roleName, member, memberOf } = params;
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.395.0-alpha.3",
15
- "@cinerino/sdk": "11.0.0-alpha.4",
14
+ "@chevre/factory": "4.395.0-alpha.5",
15
+ "@cinerino/sdk": "11.0.0-alpha.6",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
18
18
  "@sendgrid/client": "8.1.4",
@@ -113,5 +113,5 @@
113
113
  "postversion": "git push origin --tags",
114
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
115
115
  },
116
- "version": "22.11.0-alpha.8"
116
+ "version": "22.11.0-alpha.9"
117
117
  }
@@ -1,75 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../../lib/index';
5
-
6
- async function main() {
7
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
-
9
- const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
10
-
11
- let roleNames = [
12
- chevre.factory.role.organizationRole.RoleName.Customer,
13
- chevre.factory.role.organizationRole.RoleName.EventsViewer,
14
- chevre.factory.role.organizationRole.RoleName.POS
15
- ];
16
- for (const roleName of roleNames) {
17
- const result = await roleRepo.addMember({
18
- roleName,
19
- member: { typeOf: chevre.factory.creativeWorkType.WebApplication },
20
- memberOf: { typeOf: chevre.factory.organizationType.Project }
21
- });
22
- console.log(result, roleName);
23
- }
24
-
25
- roleNames = [
26
- chevre.factory.role.organizationRole.RoleName.Server
27
- ];
28
- for (const roleName of roleNames) {
29
- const result = await roleRepo.addMember({
30
- roleName,
31
- member: { typeOf: chevre.factory.creativeWorkType.SoftwareApplication },
32
- memberOf: { typeOf: chevre.factory.organizationType.Project }
33
- });
34
- console.log(result, roleName);
35
- }
36
-
37
- roleNames = [
38
- chevre.factory.role.organizationRole.RoleName.Accountant,
39
- chevre.factory.role.organizationRole.RoleName.IAMRoleAdmin,
40
- chevre.factory.role.organizationRole.RoleName.InventoryManager,
41
- chevre.factory.role.organizationRole.RoleName.MemberAdmin,
42
- chevre.factory.role.organizationRole.RoleName.Owner,
43
- chevre.factory.role.organizationRole.RoleName.PaymentServiceAdmin,
44
- chevre.factory.role.organizationRole.RoleName.SellerAdmin,
45
- chevre.factory.role.organizationRole.RoleName.TicketClerk,
46
- chevre.factory.role.organizationRole.RoleName.TicketCollector,
47
- chevre.factory.role.organizationRole.RoleName.User
48
- ];
49
- for (const roleName of roleNames) {
50
- const result = await roleRepo.addMember({
51
- roleName,
52
- member: { typeOf: chevre.factory.personType.Person },
53
- memberOf: { typeOf: chevre.factory.organizationType.Project }
54
- });
55
- console.log(result, roleName);
56
- }
57
-
58
- roleNames = [
59
- chevre.factory.role.organizationRole.RoleName.SellersIAMRoleAdmin,
60
- chevre.factory.role.organizationRole.RoleName.SellersInventoryManager,
61
- chevre.factory.role.organizationRole.RoleName.SellersOwner
62
- ];
63
- for (const roleName of roleNames) {
64
- const result = await roleRepo.addMember({
65
- roleName,
66
- member: { typeOf: chevre.factory.personType.Person },
67
- memberOf: { typeOf: chevre.factory.organizationType.Corporation }
68
- });
69
- console.log(result, roleName);
70
- }
71
- }
72
-
73
- main()
74
- .then()
75
- .catch(console.error);