@chevre/domain 22.6.0-alpha.29 → 22.6.0-alpha.30

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.
@@ -13,29 +13,29 @@ async function main() {
13
13
  // tslint:disable-next-line:no-null-keyword
14
14
  console.dir(findOneIdResult, { depth: null });
15
15
 
16
- // const result = await interfaceRepo.findOne({ id: { $eq: '672bf38b5d6d3f5642d658fc' } });
17
- // // tslint:disable-next-line:no-null-keyword
18
- // console.dir(result, { depth: null });
16
+ const result = await interfaceRepo.findOne({});
17
+ // tslint:disable-next-line:no-null-keyword
18
+ console.dir(result, { depth: null });
19
19
 
20
20
  if (findOneIdResult === null) {
21
21
  if (typeof COA_ENDPOINT === 'string' && typeof COA_REFRESH_TOKEN === 'string') {
22
- await interfaceRepo.saveOne({
23
- project: { id: 'xxx', typeOf: chevre.factory.organizationType.Project },
24
- availableChannel: {
25
- typeOf: 'ServiceChannel',
26
- credentials: {
27
- endpoint: COA_ENDPOINT,
28
- refreshToken: COA_REFRESH_TOKEN,
29
- useFetch: true
30
- },
31
- importEventsInWeeks: 5,
32
- excludeMovieTheaters: [
33
- '007'
34
- ]
35
- },
36
- typeOf: 'WebAPI'
37
- });
38
- console.log('saved');
22
+ // await interfaceRepo.saveOne({
23
+ // project: { id: 'xxx', typeOf: chevre.factory.organizationType.Project },
24
+ // availableChannel: {
25
+ // typeOf: 'ServiceChannel',
26
+ // credentials: {
27
+ // endpoint: COA_ENDPOINT,
28
+ // refreshToken: COA_REFRESH_TOKEN,
29
+ // useFetch: true
30
+ // },
31
+ // importEventsInWeeks: 5,
32
+ // excludeMovieTheaters: [
33
+ // '007'
34
+ // ]
35
+ // },
36
+ // typeOf: 'WebAPI'
37
+ // });
38
+ // console.log('saved');
39
39
  }
40
40
  }
41
41
  }
@@ -12,19 +12,21 @@ async function main() {
12
12
  const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
13
13
  const result = await taskRepo.taskModel.updateMany(
14
14
  {
15
+ // _id: { $eq: '673b5f8f5735a0a2dc953cfc' },
16
+ 'project.id': { $eq: project.id },
15
17
  status: { $eq: chevre.factory.taskStatus.Aborted },
16
18
  lastTriedAt: {
17
19
  $gt: moment()
18
- .add(-1, 'day')
20
+ // tslint:disable-next-line:no-magic-numbers
21
+ .add(-2, 'days')
19
22
  .toDate()
20
23
  },
21
- name: { $eq: chevre.factory.taskName.TriggerWebhook },
22
- 'project.id': { $eq: project.id }
24
+ name: { $eq: chevre.factory.taskName.VoidPayment }
23
25
  },
24
26
  {
25
27
  $set: {
26
28
  status: chevre.factory.taskStatus.Ready,
27
- remainingNumberOfTries: 20
29
+ remainingNumberOfTries: 3
28
30
  }
29
31
  }
30
32
  )
@@ -0,0 +1,19 @@
1
+ import type * as COA from '@motionpicture/coa-service';
2
+ import type { RedisClientType } from 'redis';
3
+ interface IOptions {
4
+ scope: string;
5
+ expireInSeconds: number;
6
+ }
7
+ /**
8
+ * 認証情報リポジトリ
9
+ */
10
+ export declare class CredentialsRepo implements COA.auth.repo.credentials.AbstractCredentialsRepo {
11
+ static KEY_PREFIX: string;
12
+ private readonly redisClient;
13
+ private readonly options;
14
+ constructor(redisClient: RedisClientType, options: IOptions);
15
+ save(credentials: COA.auth.repo.credentials.ISaveParams): Promise<void>;
16
+ find(): Promise<COA.auth.repo.credentials.IFindResult>;
17
+ private createKey;
18
+ }
19
+ export {};
@@ -0,0 +1,66 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CredentialsRepo = void 0;
13
+ /**
14
+ * 認証情報リポジトリ
15
+ */
16
+ class CredentialsRepo {
17
+ constructor(redisClient, options) {
18
+ this.redisClient = redisClient;
19
+ this.options = options;
20
+ }
21
+ save(credentials) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const { access_token, expired_at } = credentials;
24
+ if (typeof credentials.access_token !== 'string') {
25
+ throw new Error('access_token must be string');
26
+ }
27
+ if (typeof credentials.expired_at !== 'string') {
28
+ throw new Error('expired_at must be string');
29
+ }
30
+ const key = this.createKey();
31
+ const value = JSON.stringify({ access_token, expired_at });
32
+ const multi = this.redisClient.multi();
33
+ yield multi.set(key, value)
34
+ // .expireAt(key, Number(expired_at))
35
+ .expire(key, this.options.expireInSeconds)
36
+ .exec();
37
+ // if (Array.isArray(results) && (results[0] === 1 || (<any>results)[0] === true)) {
38
+ // return true;
39
+ // } else {
40
+ // throw new Error('unexpected');
41
+ // }
42
+ });
43
+ }
44
+ find() {
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const key = this.createKey();
47
+ let credentials;
48
+ try {
49
+ const credentialsStr = yield this.redisClient.get(key);
50
+ if (typeof credentialsStr === 'string') {
51
+ credentials = JSON.parse(credentialsStr);
52
+ }
53
+ }
54
+ catch (error) {
55
+ // tslint:disable-next-line:no-console
56
+ console.error('credential parse error:', error);
57
+ }
58
+ return credentials;
59
+ });
60
+ }
61
+ createKey() {
62
+ return `${CredentialsRepo.KEY_PREFIX}:${this.options.scope}`;
63
+ }
64
+ }
65
+ CredentialsRepo.KEY_PREFIX = 'credentials';
66
+ exports.CredentialsRepo = CredentialsRepo;
@@ -16,7 +16,9 @@ export declare class InterfaceRepo {
16
16
  $eq?: string;
17
17
  };
18
18
  };
19
- }): Promise<factory.service.webAPI.IServiceWithChannel | null>;
19
+ }): Promise<(factory.service.webAPI.IServiceWithChannel & {
20
+ id: string;
21
+ }) | null>;
20
22
  findOneId(): Promise<(Pick<factory.service.webAPI.IServiceWithChannel, 'project'> & {
21
23
  id: string;
22
24
  }) | null>;
@@ -36,7 +36,13 @@ class InterfaceRepo {
36
36
  andQuery.push({ 'project.id': { $eq: projectIdEq } });
37
37
  }
38
38
  const filterQuery = Object.assign({}, (andQuery.length > 0) ? { $and: andQuery } : undefined);
39
- return this.interfaceModel.findOne(filterQuery)
39
+ return this.interfaceModel.findOne(filterQuery, {
40
+ _id: 0,
41
+ id: { $toString: '$_id' },
42
+ project: '$project',
43
+ availableChannel: '$availableChannel',
44
+ typeOf: '$typeOf'
45
+ })
40
46
  .lean()
41
47
  .exec();
42
48
  });
@@ -13,6 +13,7 @@ exports.call = void 0;
13
13
  const COA = require("@motionpicture/coa-service");
14
14
  const factory = require("../../factory");
15
15
  const action_1 = require("../../repo/action");
16
+ const credentials_1 = require("../../repo/credentials");
16
17
  const event_1 = require("../../repo/event");
17
18
  const interface_1 = require("../../repo/interface");
18
19
  const transaction_1 = require("../../repo/transaction");
@@ -23,8 +24,9 @@ let coaAuthClient;
23
24
  * タスク実行関数
24
25
  */
25
26
  function call(params) {
27
+ // tslint:disable-next-line:max-func-body-length
26
28
  return ({ connection, redisClient, settings }, options) => __awaiter(this, void 0, void 0, function* () {
27
- var _a;
29
+ var _a, _b, _c;
28
30
  if (redisClient === undefined) {
29
31
  throw new factory.errors.Argument('settings', 'redisClient required');
30
32
  }
@@ -39,7 +41,19 @@ function call(params) {
39
41
  if (typeof (credentials === null || credentials === void 0 ? void 0 : credentials.refreshToken) !== 'string') {
40
42
  throw new factory.errors.NotFound('WebAPI');
41
43
  }
42
- coaAuthClient = new COA.auth.RefreshToken(credentials);
44
+ if (typeof (coaAPI === null || coaAPI === void 0 ? void 0 : coaAPI.id) !== 'string') {
45
+ throw new factory.errors.NotFound('WebAPI');
46
+ }
47
+ let credentialsRepo;
48
+ const credentialsExpireInSeconds = (_c = (_b = coaAPI.availableChannel) === null || _b === void 0 ? void 0 : _b.credentials) === null || _c === void 0 ? void 0 : _c.expireInSeconds;
49
+ if (typeof credentialsExpireInSeconds === 'number') {
50
+ // set credentialsRepo(2024-11-20~)
51
+ credentialsRepo = new credentials_1.CredentialsRepo(redisClient, {
52
+ scope: `COA:${coaAPI.id}`,
53
+ expireInSeconds: credentialsExpireInSeconds
54
+ });
55
+ }
56
+ coaAuthClient = new COA.auth.RefreshToken(Object.assign(Object.assign({}, credentials), (credentialsRepo !== undefined) ? { credentialsRepo } : undefined));
43
57
  }
44
58
  const actionRepo = new action_1.ActionRepo(connection);
45
59
  const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepo(redisClient, { lockExpiresInSeconds: 120 });
package/package.json CHANGED
@@ -11,9 +11,9 @@
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.389.0-alpha.18",
14
+ "@chevre/factory": "4.389.0-alpha.19",
15
15
  "@cinerino/sdk": "10.16.0-alpha.9",
16
- "@motionpicture/coa-service": "9.5.0",
16
+ "@motionpicture/coa-service": "9.6.0-alpha.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
18
18
  "@sendgrid/mail": "6.4.0",
19
19
  "@surfrock/sdk": "1.3.0",
@@ -108,5 +108,5 @@
108
108
  "postversion": "git push origin --tags",
109
109
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
110
110
  },
111
- "version": "22.6.0-alpha.29"
111
+ "version": "22.6.0-alpha.30"
112
112
  }