@chevre/domain 22.8.0 → 22.9.0-alpha.1

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,65 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+ const IDENTIFIER = 'https://example.com';
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const providerRepo = await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
13
+
14
+ let providers = await providerRepo.projectFields(
15
+ {
16
+ project: { id: { $eq: project.id } },
17
+ identifier: { $eq: IDENTIFIER }
18
+ },
19
+ ['identifier', 'typeOf', 'verified', 'project']
20
+ );
21
+ console.log('providers:', providers);
22
+ console.log(providers.length, 'providers found');
23
+
24
+ if (providers.length > 0) {
25
+ await providerRepo.deleteById({
26
+ project: { id: providers[0].project.id },
27
+ id: providers[0].id
28
+ });
29
+ console.log('application deleted', providers[0].id);
30
+ }
31
+
32
+ await providerRepo.projectFields(
33
+ {
34
+ project: { id: { $eq: project.id } },
35
+ identifier: { $eq: IDENTIFIER }
36
+ },
37
+ ['identifier', 'typeOf', 'verified', 'project']
38
+ );
39
+ console.log('providers:', providers);
40
+ console.log(providers.length, 'providers found');
41
+
42
+ await providerRepo.save({
43
+ attributes: {
44
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
45
+ typeOf: chevre.factory.organizationType.Organization,
46
+ identifier: IDENTIFIER,
47
+ verified: false
48
+ }
49
+ });
50
+ console.log('application created');
51
+
52
+ providers = await await providerRepo.projectFields(
53
+ {
54
+ project: { id: { $eq: project.id } },
55
+ identifier: { $eq: IDENTIFIER }
56
+ },
57
+ ['identifier', 'typeOf', 'verified', 'project']
58
+ );
59
+ console.log('providers:', providers);
60
+ console.log(providers.length, 'providers found');
61
+ }
62
+
63
+ main()
64
+ .then()
65
+ .catch(console.error);
@@ -0,0 +1,36 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { IApplication, ISearchConditions } from './mongoose/schemas/application';
3
+ export type ISavingApplication = Pick<IApplication, 'clientId' | 'issuer' | 'project' | 'typeOf' | 'verified'> & {
4
+ id?: never;
5
+ };
6
+ interface IUnset {
7
+ $unset?: {
8
+ [key: string]: 1;
9
+ };
10
+ }
11
+ type IApplicationWithId = IApplication & {
12
+ id: string;
13
+ };
14
+ type IKeyOfProjection = keyof IApplicationWithId;
15
+ /**
16
+ * アプリケーションリポジトリ
17
+ */
18
+ export declare class ApplicationRepo {
19
+ private readonly applicationModel;
20
+ constructor(connection: Connection);
21
+ static CREATE_FILTER_QUERY(params: ISearchConditions): FilterQuery<IApplication>[];
22
+ save(params: {
23
+ id?: string;
24
+ attributes: ISavingApplication & IUnset;
25
+ }): Promise<{
26
+ id: string;
27
+ }>;
28
+ projectFields(conditions: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IApplicationWithId[]>;
29
+ deleteById(params: {
30
+ id: string;
31
+ project: {
32
+ id: string;
33
+ };
34
+ }): Promise<void>;
35
+ }
36
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
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
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.ApplicationRepo = void 0;
24
+ const factory = require("../factory");
25
+ const settings_1 = require("../settings");
26
+ const application_1 = require("./mongoose/schemas/application");
27
+ /**
28
+ * アプリケーションリポジトリ
29
+ */
30
+ class ApplicationRepo {
31
+ constructor(connection) {
32
+ this.applicationModel = connection.model(application_1.modelName, (0, application_1.createSchema)());
33
+ }
34
+ // tslint:disable-next-line:max-func-body-length
35
+ static CREATE_FILTER_QUERY(params) {
36
+ var _a, _b, _c, _d, _e, _f, _g;
37
+ const andConditions = [];
38
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
39
+ if (typeof projectIdEq === 'string') {
40
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
41
+ }
42
+ const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
43
+ if (typeof idEq === 'string') {
44
+ andConditions.push({ _id: { $eq: idEq } });
45
+ }
46
+ const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
47
+ if (Array.isArray(idIn)) {
48
+ andConditions.push({ _id: { $in: idIn } });
49
+ }
50
+ const clientIdEq = (_e = params.clientId) === null || _e === void 0 ? void 0 : _e.$eq;
51
+ if (typeof clientIdEq === 'string') {
52
+ andConditions.push({ clientId: { $eq: clientIdEq } });
53
+ }
54
+ const clientIdIn = (_f = params.clientId) === null || _f === void 0 ? void 0 : _f.$in;
55
+ if (Array.isArray(clientIdIn)) {
56
+ andConditions.push({ clientId: { $in: clientIdIn } });
57
+ }
58
+ const clientIdRegex = (_g = params.clientId) === null || _g === void 0 ? void 0 : _g.$regex;
59
+ if (typeof clientIdRegex === 'string' && clientIdRegex.length > 0) {
60
+ andConditions.push({ clientId: { $regex: new RegExp(clientIdRegex) } });
61
+ }
62
+ const verified = params.verified;
63
+ if (typeof verified === 'boolean') {
64
+ andConditions.push({ verified: verified });
65
+ }
66
+ return andConditions;
67
+ }
68
+ save(params) {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ var _a, _b;
71
+ let doc;
72
+ let savedId;
73
+ const savingId = params.id;
74
+ if (typeof savingId === 'string') {
75
+ if (savingId === '') {
76
+ throw new factory.errors.ArgumentNull('id');
77
+ }
78
+ const _c = params.attributes, { id, clientId, project, typeOf, $unset } = _c, updateFields = __rest(_c, ["id", "clientId", "project", "typeOf", "$unset"]);
79
+ const filter = {
80
+ _id: { $eq: savingId },
81
+ 'project.id': { $eq: project.id }
82
+ };
83
+ const update = Object.assign({ $set: updateFields }, ($unset !== undefined && $unset !== null) ? { $unset } : undefined);
84
+ const options = {
85
+ upsert: false,
86
+ new: true,
87
+ projection: { _id: 1, id: { $toString: '$_id' } }
88
+ };
89
+ doc = yield this.applicationModel.findOneAndUpdate(filter, update, options)
90
+ .lean()
91
+ .exec();
92
+ if (doc === null) {
93
+ throw new factory.errors.NotFound(this.applicationModel.modelName);
94
+ }
95
+ savedId = savingId;
96
+ }
97
+ else {
98
+ const _d = params.attributes, { $unset, id } = _d, createParams = __rest(_d, ["$unset", "id"]);
99
+ const result = yield this.applicationModel.insertMany(createParams, { rawResult: true });
100
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
101
+ if (typeof insertedId !== 'string') {
102
+ throw new factory.errors.Internal(`seller not saved unexpectedly. result:${JSON.stringify(result)}`);
103
+ }
104
+ savedId = insertedId;
105
+ }
106
+ return { id: savedId };
107
+ });
108
+ }
109
+ projectFields(conditions, inclusion) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ var _a;
112
+ const andConditions = ApplicationRepo.CREATE_FILTER_QUERY(conditions);
113
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(inclusion.map((key) => ([key, 1]))));
114
+ const query = this.applicationModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
115
+ if (typeof conditions.limit === 'number' && conditions.limit > 0) {
116
+ const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
117
+ query.limit(conditions.limit)
118
+ .skip(conditions.limit * (page - 1));
119
+ }
120
+ if (typeof ((_a = conditions.sort) === null || _a === void 0 ? void 0 : _a.clientId) === 'number') {
121
+ query.sort({ clientId: conditions.sort.clientId });
122
+ }
123
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
124
+ .lean()
125
+ .exec();
126
+ });
127
+ }
128
+ deleteById(params) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ yield this.applicationModel.findOneAndDelete({
131
+ _id: { $eq: params.id },
132
+ 'project.id': { $eq: params.project.id }
133
+ }, { projection: { _id: 1 } })
134
+ .exec();
135
+ });
136
+ }
137
+ }
138
+ exports.ApplicationRepo = ApplicationRepo;
@@ -0,0 +1,36 @@
1
+ import { Connection, FilterQuery } from 'mongoose';
2
+ import { IIdentityProvider, ISearchConditions } from './mongoose/schemas/identityProvider';
3
+ export type ISavingIdentityProvider = Pick<IIdentityProvider, 'identifier' | 'project' | 'typeOf' | 'verified'> & {
4
+ id?: never;
5
+ };
6
+ interface IUnset {
7
+ $unset?: {
8
+ [key: string]: 1;
9
+ };
10
+ }
11
+ type IIdentityProviderWithId = IIdentityProvider & {
12
+ id: string;
13
+ };
14
+ type IKeyOfProjection = keyof IIdentityProvider;
15
+ /**
16
+ * IDPリポジトリ
17
+ */
18
+ export declare class IdentityProviderRepo {
19
+ private readonly identityProviderModel;
20
+ constructor(connection: Connection);
21
+ static CREATE_FILTER_QUERY(params: ISearchConditions): FilterQuery<IIdentityProvider>[];
22
+ save(params: {
23
+ id?: string;
24
+ attributes: ISavingIdentityProvider & IUnset;
25
+ }): Promise<{
26
+ id: string;
27
+ }>;
28
+ projectFields(conditions: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IIdentityProviderWithId[]>;
29
+ deleteById(params: {
30
+ id: string;
31
+ project: {
32
+ id: string;
33
+ };
34
+ }): Promise<void>;
35
+ }
36
+ export {};
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
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
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.IdentityProviderRepo = void 0;
24
+ const factory = require("../factory");
25
+ const settings_1 = require("../settings");
26
+ const identityProvider_1 = require("./mongoose/schemas/identityProvider");
27
+ /**
28
+ * IDPリポジトリ
29
+ */
30
+ class IdentityProviderRepo {
31
+ constructor(connection) {
32
+ this.identityProviderModel = connection.model(identityProvider_1.modelName, (0, identityProvider_1.createSchema)());
33
+ }
34
+ // tslint:disable-next-line:max-func-body-length
35
+ static CREATE_FILTER_QUERY(params) {
36
+ var _a, _b, _c, _d, _e, _f;
37
+ const andConditions = [];
38
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
39
+ if (typeof projectIdEq === 'string') {
40
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
41
+ }
42
+ const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
43
+ if (typeof idEq === 'string') {
44
+ andConditions.push({ _id: { $eq: idEq } });
45
+ }
46
+ const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
47
+ if (Array.isArray(idIn)) {
48
+ andConditions.push({ _id: { $in: idIn } });
49
+ }
50
+ const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
51
+ if (typeof identifierEq === 'string') {
52
+ andConditions.push({ identifier: { $eq: identifierEq } });
53
+ }
54
+ const identifierRegex = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$regex;
55
+ if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
56
+ andConditions.push({ identifier: { $regex: new RegExp(identifierRegex) } });
57
+ }
58
+ const verified = params.verified;
59
+ if (typeof verified === 'boolean') {
60
+ andConditions.push({ verified: verified });
61
+ }
62
+ return andConditions;
63
+ }
64
+ save(params) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ var _a, _b;
67
+ let doc;
68
+ let savedId;
69
+ const savingId = params.id;
70
+ if (typeof savingId === 'string') {
71
+ if (savingId === '') {
72
+ throw new factory.errors.ArgumentNull('id');
73
+ }
74
+ const _c = params.attributes, { id, identifier, project, typeOf, $unset } = _c, updateFields = __rest(_c, ["id", "identifier", "project", "typeOf", "$unset"]);
75
+ const filter = {
76
+ _id: { $eq: savingId },
77
+ 'project.id': { $eq: project.id }
78
+ };
79
+ const update = Object.assign({ $set: updateFields }, ($unset !== undefined && $unset !== null) ? { $unset } : undefined);
80
+ const options = {
81
+ upsert: false,
82
+ new: true,
83
+ projection: { _id: 1, id: { $toString: '$_id' } }
84
+ };
85
+ doc = yield this.identityProviderModel.findOneAndUpdate(filter, update, options)
86
+ .lean()
87
+ .exec();
88
+ if (doc === null) {
89
+ throw new factory.errors.NotFound(this.identityProviderModel.modelName);
90
+ }
91
+ savedId = savingId;
92
+ }
93
+ else {
94
+ const _d = params.attributes, { $unset, id } = _d, createParams = __rest(_d, ["$unset", "id"]);
95
+ const result = yield this.identityProviderModel.insertMany(createParams, { rawResult: true });
96
+ const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
97
+ if (typeof insertedId !== 'string') {
98
+ throw new factory.errors.Internal(`not saved unexpectedly. result:${JSON.stringify(result)}`);
99
+ }
100
+ savedId = insertedId;
101
+ }
102
+ return { id: savedId };
103
+ });
104
+ }
105
+ projectFields(conditions, inclusion) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ var _a;
108
+ const andConditions = IdentityProviderRepo.CREATE_FILTER_QUERY(conditions);
109
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(inclusion.map((key) => ([key, 1]))));
110
+ const query = this.identityProviderModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
111
+ if (typeof conditions.limit === 'number' && conditions.limit > 0) {
112
+ const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
113
+ query.limit(conditions.limit)
114
+ .skip(conditions.limit * (page - 1));
115
+ }
116
+ if (typeof ((_a = conditions.sort) === null || _a === void 0 ? void 0 : _a.identifier) === 'number') {
117
+ query.sort({ identifier: conditions.sort.identifier });
118
+ }
119
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
120
+ .lean()
121
+ .exec();
122
+ });
123
+ }
124
+ deleteById(params) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ yield this.identityProviderModel.findOneAndDelete({
127
+ _id: { $eq: params.id },
128
+ 'project.id': { $eq: params.project.id }
129
+ }, { projection: { _id: 1 } })
130
+ .exec();
131
+ });
132
+ }
133
+ }
134
+ exports.IdentityProviderRepo = IdentityProviderRepo;
@@ -0,0 +1,40 @@
1
+ import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
+ import * as factory from '../../../factory';
3
+ export interface ISearchConditions {
4
+ limit?: number;
5
+ page?: number;
6
+ sort?: {
7
+ clientId?: factory.sortType;
8
+ };
9
+ project?: {
10
+ id?: {
11
+ $eq?: string;
12
+ };
13
+ };
14
+ id?: {
15
+ $eq?: string;
16
+ $in?: string[];
17
+ };
18
+ clientId?: {
19
+ $eq?: string;
20
+ $in?: string[];
21
+ $regex?: string;
22
+ };
23
+ verified?: boolean;
24
+ }
25
+ export interface IApplication {
26
+ id?: string;
27
+ issuer: string;
28
+ clientId: string;
29
+ project: Pick<factory.project.IProject, 'id' | 'typeOf'>;
30
+ typeOf: factory.creativeWorkType.WebApplication;
31
+ verified: boolean;
32
+ }
33
+ type IDocType = Omit<IApplication, 'id'>;
34
+ type IModel = Model<IDocType>;
35
+ type ISchemaDefinition = SchemaDefinition<IDocType>;
36
+ type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
37
+ declare const modelName = "Application";
38
+ declare const indexes: [d: IndexDefinition, o: IndexOptions][];
39
+ declare function createSchema(): ISchema;
40
+ export { createSchema, IModel, indexes, modelName };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelName = exports.indexes = void 0;
4
+ exports.createSchema = createSchema;
5
+ const mongoose_1 = require("mongoose");
6
+ const writeConcern_1 = require("../writeConcern");
7
+ const settings_1 = require("../../../settings");
8
+ const modelName = 'Application';
9
+ exports.modelName = modelName;
10
+ const schemaDefinition = {
11
+ project: {
12
+ type: mongoose_1.SchemaTypes.Mixed,
13
+ required: true
14
+ },
15
+ typeOf: {
16
+ type: String,
17
+ required: true
18
+ },
19
+ issuer: {
20
+ type: String,
21
+ required: true
22
+ },
23
+ clientId: {
24
+ type: String,
25
+ required: true
26
+ },
27
+ verified: {
28
+ type: Boolean,
29
+ required: true
30
+ }
31
+ };
32
+ const schemaOptions = {
33
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
34
+ autoCreate: false,
35
+ collection: 'applications',
36
+ id: true,
37
+ read: settings_1.MONGO_READ_PREFERENCE,
38
+ writeConcern: writeConcern_1.writeConcern,
39
+ strict: true,
40
+ strictQuery: false,
41
+ timestamps: false,
42
+ versionKey: false,
43
+ toJSON: {
44
+ getters: false,
45
+ virtuals: false,
46
+ minimize: false,
47
+ versionKey: false
48
+ },
49
+ toObject: {
50
+ getters: false,
51
+ virtuals: true,
52
+ minimize: false,
53
+ versionKey: false
54
+ }
55
+ };
56
+ const indexes = [
57
+ [
58
+ { 'project.id': 1, clientId: 1 },
59
+ {
60
+ name: 'uniqueClientId',
61
+ unique: true
62
+ }
63
+ ]
64
+ ];
65
+ exports.indexes = indexes;
66
+ /**
67
+ * アプリケーションスキーマ
68
+ */
69
+ let schema;
70
+ function createSchema() {
71
+ if (schema === undefined) {
72
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
73
+ if (settings_1.MONGO_AUTO_INDEX) {
74
+ indexes.forEach((indexParams) => {
75
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
76
+ });
77
+ }
78
+ }
79
+ return schema;
80
+ }
@@ -0,0 +1,38 @@
1
+ import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
+ import * as factory from '../../../factory';
3
+ export interface ISearchConditions {
4
+ limit?: number;
5
+ page?: number;
6
+ sort?: {
7
+ identifier?: factory.sortType;
8
+ };
9
+ project?: {
10
+ id?: {
11
+ $eq?: string;
12
+ };
13
+ };
14
+ id?: {
15
+ $eq?: string;
16
+ $in?: string[];
17
+ };
18
+ identifier?: {
19
+ $eq?: string;
20
+ $regex?: string;
21
+ };
22
+ verified?: boolean;
23
+ }
24
+ export interface IIdentityProvider {
25
+ id: string;
26
+ identifier: string;
27
+ project: Pick<factory.project.IProject, 'id' | 'typeOf'>;
28
+ typeOf: factory.organizationType.Organization;
29
+ verified: boolean;
30
+ }
31
+ type IDocType = Omit<IIdentityProvider, 'id'>;
32
+ type IModel = Model<IDocType>;
33
+ type ISchemaDefinition = SchemaDefinition<IDocType>;
34
+ type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
35
+ declare const modelName = "IdentityProvider";
36
+ declare const indexes: [d: IndexDefinition, o: IndexOptions][];
37
+ declare function createSchema(): ISchema;
38
+ export { createSchema, IModel, indexes, modelName };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelName = exports.indexes = void 0;
4
+ exports.createSchema = createSchema;
5
+ const mongoose_1 = require("mongoose");
6
+ const writeConcern_1 = require("../writeConcern");
7
+ const settings_1 = require("../../../settings");
8
+ const modelName = 'IdentityProvider';
9
+ exports.modelName = modelName;
10
+ const schemaDefinition = {
11
+ project: {
12
+ type: mongoose_1.SchemaTypes.Mixed,
13
+ required: true
14
+ },
15
+ typeOf: {
16
+ type: String,
17
+ required: true
18
+ },
19
+ identifier: {
20
+ type: String,
21
+ required: true
22
+ },
23
+ verified: {
24
+ type: Boolean,
25
+ required: true
26
+ }
27
+ };
28
+ const schemaOptions = {
29
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
30
+ autoCreate: false,
31
+ collection: 'identityProviders',
32
+ id: true,
33
+ read: settings_1.MONGO_READ_PREFERENCE,
34
+ writeConcern: writeConcern_1.writeConcern,
35
+ strict: true,
36
+ strictQuery: false,
37
+ timestamps: false,
38
+ versionKey: false,
39
+ toJSON: {
40
+ getters: false,
41
+ virtuals: false,
42
+ minimize: false,
43
+ versionKey: false
44
+ },
45
+ toObject: {
46
+ getters: false,
47
+ virtuals: true,
48
+ minimize: false,
49
+ versionKey: false
50
+ }
51
+ };
52
+ const indexes = [
53
+ [
54
+ { 'project.id': 1, identifier: 1 },
55
+ {
56
+ name: 'uniqueIdentifier',
57
+ unique: true
58
+ }
59
+ ]
60
+ ];
61
+ exports.indexes = indexes;
62
+ /**
63
+ * IDPスキーマ
64
+ */
65
+ let schema;
66
+ function createSchema() {
67
+ if (schema === undefined) {
68
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
69
+ if (settings_1.MONGO_AUTO_INDEX) {
70
+ indexes.forEach((indexParams) => {
71
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
72
+ });
73
+ }
74
+ }
75
+ return schema;
76
+ }
@@ -11,6 +11,7 @@ import type { AdditionalPropertyRepo } from './repo/additionalProperty';
11
11
  import type { AggregateOfferRepo } from './repo/aggregateOffer';
12
12
  import type { AggregateReservationRepo } from './repo/aggregateReservation';
13
13
  import type { AggregationRepo } from './repo/aggregation';
14
+ import type { ApplicationRepo } from './repo/application';
14
15
  import type { AssetTransactionRepo } from './repo/assetTransaction';
15
16
  import type { AuthorizationRepo } from './repo/authorization';
16
17
  import type { CategoryCodeRepo } from './repo/categoryCode';
@@ -23,6 +24,7 @@ import type { EmailMessageRepo } from './repo/emailMessage';
23
24
  import type { EventRepo } from './repo/event';
24
25
  import type { EventSellerMakesOfferRepo } from './repo/eventSellerMakesOffer';
25
26
  import type { EventSeriesRepo } from './repo/eventSeries';
27
+ import type { IdentityProviderRepo } from './repo/identityProvider';
26
28
  import type { InterfaceRepo } from './repo/interface';
27
29
  import type { IssuerRepo } from './repo/issuer';
28
30
  import type { MemberRepo } from './repo/member';
@@ -116,6 +118,10 @@ export type Aggregation = AggregationRepo;
116
118
  export declare namespace Aggregation {
117
119
  function createInstance(...params: ConstructorParameters<typeof AggregationRepo>): Promise<AggregationRepo>;
118
120
  }
121
+ export type Application = ApplicationRepo;
122
+ export declare namespace Application {
123
+ function createInstance(...params: ConstructorParameters<typeof ApplicationRepo>): Promise<ApplicationRepo>;
124
+ }
119
125
  export type AssetTransaction = AssetTransactionRepo;
120
126
  export declare namespace AssetTransaction {
121
127
  function createInstance(...params: ConstructorParameters<typeof AssetTransactionRepo>): Promise<AssetTransactionRepo>;
@@ -168,6 +174,10 @@ export type EventSeries = EventSeriesRepo;
168
174
  export declare namespace EventSeries {
169
175
  function createInstance(...params: ConstructorParameters<typeof EventSeriesRepo>): Promise<EventSeriesRepo>;
170
176
  }
177
+ export type IdentityProvider = IdentityProviderRepo;
178
+ export declare namespace IdentityProvider {
179
+ function createInstance(...params: ConstructorParameters<typeof IdentityProviderRepo>): Promise<IdentityProviderRepo>;
180
+ }
171
181
  export type Interface = InterfaceRepo;
172
182
  export declare namespace Interface {
173
183
  function createInstance(...params: ConstructorParameters<typeof InterfaceRepo>): Promise<InterfaceRepo>;
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.Interface = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
- exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.Seller = exports.Schedule = exports.Role = exports.Reservation = exports.ProjectMakesOffer = void 0;
12
+ exports.ProductModel = exports.Product = exports.PriceSpecification = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.Interface = exports.IdentityProvider = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Application = exports.Aggregation = exports.AggregateReservation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
+ exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.Seller = exports.Schedule = exports.Role = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = void 0;
14
14
  var AcceptedOffer;
15
15
  (function (AcceptedOffer) {
16
16
  let repo;
@@ -141,6 +141,19 @@ var Aggregation;
141
141
  }
142
142
  Aggregation.createInstance = createInstance;
143
143
  })(Aggregation || (exports.Aggregation = Aggregation = {}));
144
+ var Application;
145
+ (function (Application) {
146
+ let repo;
147
+ function createInstance(...params) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (repo === undefined) {
150
+ repo = (yield Promise.resolve().then(() => require('./repo/application'))).ApplicationRepo;
151
+ }
152
+ return new repo(...params);
153
+ });
154
+ }
155
+ Application.createInstance = createInstance;
156
+ })(Application || (exports.Application = Application = {}));
144
157
  var AssetTransaction;
145
158
  (function (AssetTransaction) {
146
159
  let repo;
@@ -310,6 +323,19 @@ var EventSeries;
310
323
  }
311
324
  EventSeries.createInstance = createInstance;
312
325
  })(EventSeries || (exports.EventSeries = EventSeries = {}));
326
+ var IdentityProvider;
327
+ (function (IdentityProvider) {
328
+ let repo;
329
+ function createInstance(...params) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ if (repo === undefined) {
332
+ repo = (yield Promise.resolve().then(() => require('./repo/identityProvider'))).IdentityProviderRepo;
333
+ }
334
+ return new repo(...params);
335
+ });
336
+ }
337
+ IdentityProvider.createInstance = createInstance;
338
+ })(IdentityProvider || (exports.IdentityProvider = IdentityProvider = {}));
313
339
  var Interface;
314
340
  (function (Interface) {
315
341
  let repo;
package/package.json CHANGED
@@ -112,5 +112,5 @@
112
112
  "postversion": "git push origin --tags",
113
113
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
114
114
  },
115
- "version": "22.8.0"
115
+ "version": "22.9.0-alpha.1"
116
116
  }
@@ -1,102 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- const project = { id: String(process.env.PROJECT_ID) };
7
- const IDENTIFIER = 'SellerReturnPolicy:20250117045254:0';
8
-
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const sellerReturnPolicyRepo = await chevre.repository.SellerReturnPolicy.createInstance(mongoose.connection);
13
-
14
- let policies = await sellerReturnPolicyRepo.projectFields(
15
- {
16
- project: { id: { $eq: project.id } },
17
- identifier: { $eq: IDENTIFIER }
18
- },
19
- ['applicablePaymentMethod', 'identifier', 'itemCondition', 'merchantReturnDays', 'name', 'restockingFee', 'typeOf']
20
- );
21
- console.log('policies:', policies);
22
- console.log(policies.length, 'policies found');
23
-
24
- if (policies.length > 0) {
25
- try {
26
- await sellerReturnPolicyRepo.deleteById({
27
- project: { id: policies[0].project.id },
28
- id: policies[0].id
29
- });
30
- console.log('policy deleted', policies[0].id);
31
- } catch (error) {
32
- console.error(error);
33
- }
34
- }
35
-
36
- policies = await sellerReturnPolicyRepo.projectFields(
37
- {
38
- project: { id: { $eq: project.id } },
39
- identifier: { $eq: IDENTIFIER }
40
- },
41
- ['applicablePaymentMethod', 'identifier', 'itemCondition', 'merchantReturnDays', 'name', 'restockingFee', 'typeOf']
42
- );
43
- console.log('policies:', policies);
44
- console.log(policies.length, 'programs found');
45
-
46
- await sellerReturnPolicyRepo.save({
47
- attributes: {
48
- project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
49
- name: { ja: 'イベント2日前0時まで10円' },
50
- typeOf: 'MerchantReturnPolicy',
51
- restockingFee: {
52
- typeOf: 'MonetaryAmount',
53
- currency: 'JPY',
54
- value: 10
55
- },
56
- identifier: IDENTIFIER,
57
- // url: 'https://example.com',
58
- itemCondition: {
59
- id: '6466c23f8e7f569b623d876b',
60
- name: {
61
- ja: 'イベント2日前0時まで'
62
- },
63
- typeOf: 'OfferItemCondition'
64
- },
65
- merchantReturnDays: 100,
66
- applicablePaymentMethod: [
67
- 'au',
68
- 'CreditCard',
69
- 'CreditCardBySPS',
70
- 'MGTicket',
71
- 'MovieTicket',
72
- 'PayPay',
73
- 'CreditCard3DS'
74
- ]
75
- }
76
- });
77
- console.log('program created');
78
-
79
- policies = await sellerReturnPolicyRepo.projectFields(
80
- {
81
- project: { id: { $eq: project.id } },
82
- identifier: { $eq: IDENTIFIER }
83
- },
84
- ['applicablePaymentMethod', 'identifier', 'itemCondition', 'merchantReturnDays', 'name', 'restockingFee', 'typeOf']
85
- );
86
- console.log('policies:', policies);
87
- console.log(policies.length, 'policies found');
88
-
89
- policies = await sellerReturnPolicyRepo.projectFields(
90
- {
91
- project: { id: { $eq: project.id } },
92
- restockingFee: { value: { $eq: 10 } }
93
- },
94
- ['applicablePaymentMethod', 'identifier', 'itemCondition', 'merchantReturnDays', 'name', 'restockingFee', 'typeOf']
95
- );
96
- console.log('policies:', policies);
97
- console.log(policies.length, 'policies found');
98
- }
99
-
100
- main()
101
- .then()
102
- .catch(console.error);