@chevre/domain 28.1.0-alpha.2 → 28.1.0-alpha.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/lib/chevre/service/notification/triggerWebhook/processInformAction.d.ts +24 -0
- package/lib/chevre/service/notification/triggerWebhook/processInformAction.js +202 -0
- package/lib/chevre/service/notification/triggerWebhook.d.ts +7 -11
- package/lib/chevre/service/notification/triggerWebhook.js +42 -196
- package/lib/chevre/service/notification.d.ts +2 -2
- package/lib/chevre/service/notification.js +2 -1
- package/lib/chevre/service/offer/onEventChanged.js +1 -1
- package/lib/chevre/service/task/informHub.d.ts +6 -0
- package/lib/chevre/service/task/informHub.js +24 -0
- package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +1 -1
- package/lib/chevre/service/task/onResourceUpdated.js +8 -8
- package/package.json +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { factory } from '../../../factory';
|
|
2
|
+
import type { InformActionRepo } from '../../../repo/action/inform';
|
|
3
|
+
import type { PotentialActionRepo } from '../../../repo/potentialAction';
|
|
4
|
+
import type { ISetting, SettingRepo } from '../../../repo/setting';
|
|
5
|
+
interface ITriggerWebhookRepos {
|
|
6
|
+
actions: {
|
|
7
|
+
inform: InformActionRepo;
|
|
8
|
+
};
|
|
9
|
+
potentialAction: PotentialActionRepo;
|
|
10
|
+
setting: SettingRepo;
|
|
11
|
+
}
|
|
12
|
+
declare function processInformAction(params: (factory.task.triggerWebhook.IData | factory.task.informHub.IData) & {
|
|
13
|
+
project: {
|
|
14
|
+
id: string;
|
|
15
|
+
};
|
|
16
|
+
}, settings: Pick<ISetting, 'triggerWebhook'>, options: {
|
|
17
|
+
useIAP: boolean;
|
|
18
|
+
}): (repos: {
|
|
19
|
+
actions: {
|
|
20
|
+
inform: InformActionRepo;
|
|
21
|
+
};
|
|
22
|
+
potentialAction: PotentialActionRepo;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
export { ITriggerWebhookRepos, processInformAction };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.processInformAction = processInformAction;
|
|
37
|
+
const crypto = __importStar(require("crypto"));
|
|
38
|
+
const http_status_1 = require("http-status");
|
|
39
|
+
const factory_1 = require("../../../factory");
|
|
40
|
+
const getGoogleIdTokenClient_1 = require("./getGoogleIdTokenClient");
|
|
41
|
+
const USERNAME_ARGUMENT_REQUIRED_MESSAGE = 'Missing required key \'Username\' in params';
|
|
42
|
+
function createInformActionAttributes(params) {
|
|
43
|
+
return async (repos) => {
|
|
44
|
+
const { about, object, purpose, recipient, project, id, typeOf } = params;
|
|
45
|
+
// redefine recipient(2025-02-15~)
|
|
46
|
+
let informRecipient;
|
|
47
|
+
if (recipient?.typeOf === factory_1.factory.creativeWorkType.WebApplication) {
|
|
48
|
+
informRecipient = {
|
|
49
|
+
name: recipient.name,
|
|
50
|
+
typeOf: recipient.typeOf
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
let target;
|
|
54
|
+
if (typeOf === factory_1.factory.actionType.InformAction && typeof id === 'string' && id !== '') {
|
|
55
|
+
// find target from potentialAction(2025-02-06~)
|
|
56
|
+
const potentialInformAction = (await repos.potentialAction.projectFields({
|
|
57
|
+
limit: 1,
|
|
58
|
+
page: 1,
|
|
59
|
+
id: { $eq: id },
|
|
60
|
+
typeOf: { $eq: typeOf }
|
|
61
|
+
}, ['target', 'recipient'])).shift();
|
|
62
|
+
if (potentialInformAction === undefined) {
|
|
63
|
+
throw new factory_1.factory.errors.NotFound(factory_1.factory.actionType.InformAction);
|
|
64
|
+
}
|
|
65
|
+
if (typeof potentialInformAction.recipient?.name === 'string') {
|
|
66
|
+
informRecipient = { name: potentialInformAction.recipient.name, typeOf: potentialInformAction.recipient.typeOf };
|
|
67
|
+
}
|
|
68
|
+
target = potentialInformAction.target;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
if (params.target?.typeOf === 'EntryPoint') {
|
|
72
|
+
target = params.target;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (informRecipient === undefined) {
|
|
76
|
+
throw new factory_1.factory.errors.ArgumentNull('recipient');
|
|
77
|
+
}
|
|
78
|
+
if (target === undefined) {
|
|
79
|
+
throw new factory_1.factory.errors.ArgumentNull('target');
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
agent: { id: project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
83
|
+
object,
|
|
84
|
+
project: { id: project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
85
|
+
recipient: informRecipient,
|
|
86
|
+
typeOf: factory_1.factory.actionType.InformAction,
|
|
87
|
+
target, // add(2025-02-06~)
|
|
88
|
+
...(typeof purpose?.typeOf === 'string') ? { purpose } : undefined,
|
|
89
|
+
...(typeof about?.typeOf === 'string') ? { about } : undefined, // add(2025-01-23~)
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function signRequest(params) {
|
|
94
|
+
const { requestBody, timestamp, secretKey } = params;
|
|
95
|
+
const payload = `${requestBody}${timestamp.toString()}`;
|
|
96
|
+
return crypto.createHmac('sha256', secretKey)
|
|
97
|
+
.update(payload)
|
|
98
|
+
.digest('hex');
|
|
99
|
+
}
|
|
100
|
+
async function makeRequestHeaders(action, settings, requestBody, options) {
|
|
101
|
+
const { useIAP } = options;
|
|
102
|
+
const secretKey = settings?.triggerWebhook?.secretKey;
|
|
103
|
+
const headerIdentifier = settings?.triggerWebhook?.headerIdentifier;
|
|
104
|
+
const googleTargetAudience = settings?.triggerWebhook?.googleTargetAudience;
|
|
105
|
+
const timestamp = action.startDate.valueOf();
|
|
106
|
+
// sign request(2024-10-28~)
|
|
107
|
+
let signature;
|
|
108
|
+
if (typeof secretKey === 'string' && secretKey !== ''
|
|
109
|
+
&& typeof headerIdentifier === 'string' && headerIdentifier !== '') {
|
|
110
|
+
signature = signRequest({ requestBody, timestamp, secretKey });
|
|
111
|
+
}
|
|
112
|
+
const headers = new Headers({ 'Content-Type': 'application/json' });
|
|
113
|
+
if (typeof headerIdentifier === 'string' && headerIdentifier !== '') {
|
|
114
|
+
headers.append(`X-${headerIdentifier}-Webhook-Timestamp`, String(timestamp));
|
|
115
|
+
if (typeof signature === 'string') {
|
|
116
|
+
headers.append(`X-${headerIdentifier}-Webhook-Signature`, signature);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// support googleAuth(2026-10-30~)
|
|
120
|
+
if (useIAP) {
|
|
121
|
+
if (typeof googleTargetAudience === 'string' && googleTargetAudience !== '') {
|
|
122
|
+
const idTokenClient = await (0, getGoogleIdTokenClient_1.getGoogleIdTokenClient)(googleTargetAudience);
|
|
123
|
+
// getRequestHeaders() からキャッシュ済みの "Bearer eyJhbG..." を取得
|
|
124
|
+
const requestHeaders = await idTokenClient.getRequestHeaders();
|
|
125
|
+
const idToken = requestHeaders.get('authorization'); // "Bearer eyJhbG..."
|
|
126
|
+
if (typeof idToken === 'string') {
|
|
127
|
+
// IAPを通過するための認証(Googleが認識するヘッダー)
|
|
128
|
+
headers.append('Proxy-Authorization', idToken);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return headers;
|
|
133
|
+
}
|
|
134
|
+
function processInformAction(params, settings, options) {
|
|
135
|
+
return async (repos) => {
|
|
136
|
+
const timeout = settings?.triggerWebhook?.timeout;
|
|
137
|
+
const { identifier } = params;
|
|
138
|
+
const informActionAttributes = await createInformActionAttributes(params)(repos);
|
|
139
|
+
const action = await repos.actions.inform.startInformAction(informActionAttributes);
|
|
140
|
+
let result = {};
|
|
141
|
+
try {
|
|
142
|
+
const urlTemplate = informActionAttributes.target?.urlTemplate;
|
|
143
|
+
if (typeof urlTemplate === 'string') {
|
|
144
|
+
const requestBody = JSON.stringify({
|
|
145
|
+
data: informActionAttributes.object,
|
|
146
|
+
id: action.id, // support informAction ID(2025-02-20~)
|
|
147
|
+
// 通知識別子を追加(2024-10-24~)
|
|
148
|
+
...(typeof identifier === 'string' && identifier !== '')
|
|
149
|
+
? { identifier }
|
|
150
|
+
: undefined
|
|
151
|
+
});
|
|
152
|
+
const headers = await makeRequestHeaders(action, settings, requestBody, options);
|
|
153
|
+
const res = await fetch(urlTemplate, {
|
|
154
|
+
method: 'POST',
|
|
155
|
+
headers,
|
|
156
|
+
body: requestBody, // body data type must match "Content-Type" header
|
|
157
|
+
...(typeof timeout === 'number')
|
|
158
|
+
? { signal: AbortSignal.timeout(timeout) }
|
|
159
|
+
: undefined
|
|
160
|
+
});
|
|
161
|
+
let body;
|
|
162
|
+
try {
|
|
163
|
+
body = await res.text();
|
|
164
|
+
}
|
|
165
|
+
catch (_error) {
|
|
166
|
+
// no op
|
|
167
|
+
}
|
|
168
|
+
switch (res.status) {
|
|
169
|
+
case http_status_1.status.OK:
|
|
170
|
+
case http_status_1.status.CREATED:
|
|
171
|
+
case http_status_1.status.ACCEPTED:
|
|
172
|
+
case http_status_1.status.NO_CONTENT: {
|
|
173
|
+
result = {
|
|
174
|
+
statusCode: res.status,
|
|
175
|
+
useFetchAPI: true
|
|
176
|
+
};
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
default: {
|
|
180
|
+
// プロジェクト固有の特別対応
|
|
181
|
+
const ignoreUnexpectedResponse = res.status === http_status_1.status.INTERNAL_SERVER_ERROR
|
|
182
|
+
&& typeof body === 'string'
|
|
183
|
+
&& body.includes(USERNAME_ARGUMENT_REQUIRED_MESSAGE);
|
|
184
|
+
if (!ignoreUnexpectedResponse) {
|
|
185
|
+
throw new factory_1.factory.errors.Internal(`statusCode: ${res.status} body: ${body}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
try {
|
|
193
|
+
await repos.actions.inform.giveUpInformAction({ typeOf: action.typeOf, id: action.id, error });
|
|
194
|
+
}
|
|
195
|
+
catch (__) {
|
|
196
|
+
// 失敗したら仕方ない
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
await repos.actions.inform.completeInformAction({ typeOf: action.typeOf, id: action.id, result: result });
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { factory } from '../../factory';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
actions: {
|
|
7
|
-
inform: InformActionRepo;
|
|
2
|
+
import { ITriggerWebhookRepos } from './triggerWebhook/processInformAction';
|
|
3
|
+
declare function triggerWebhook(params: factory.task.triggerWebhook.IData & {
|
|
4
|
+
project: {
|
|
5
|
+
id: string;
|
|
8
6
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook> & {
|
|
7
|
+
}): (repos: ITriggerWebhookRepos) => Promise<void>;
|
|
8
|
+
declare function informHub(params: factory.task.informHub.IData & {
|
|
13
9
|
project: {
|
|
14
10
|
id: string;
|
|
15
11
|
};
|
|
16
12
|
}): (repos: ITriggerWebhookRepos) => Promise<void>;
|
|
17
|
-
export { ITriggerWebhookRepos, triggerWebhook };
|
|
13
|
+
export { ITriggerWebhookRepos, triggerWebhook, informHub };
|
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.triggerWebhook = triggerWebhook;
|
|
37
|
-
|
|
38
|
-
const http_status_1 = require("http-status");
|
|
4
|
+
exports.informHub = informHub;
|
|
39
5
|
const factory_1 = require("../../factory");
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
function triggerWebhook(params) {
|
|
6
|
+
const processInformAction_1 = require("./triggerWebhook/processInformAction");
|
|
7
|
+
function findSettings() {
|
|
43
8
|
return async (repos) => {
|
|
44
9
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['triggerWebhook']);
|
|
10
|
+
if (setting === null) {
|
|
11
|
+
throw new factory_1.factory.errors.NotFound('settings.triggerWebhook');
|
|
12
|
+
}
|
|
45
13
|
const retryCountMax = setting?.triggerWebhook?.retryCountMax;
|
|
46
14
|
const retryIntervalInMS = setting?.triggerWebhook?.retryIntervalInMS;
|
|
47
15
|
if (typeof retryCountMax !== 'number') {
|
|
@@ -50,6 +18,12 @@ function triggerWebhook(params) {
|
|
|
50
18
|
if (typeof retryIntervalInMS !== 'number') {
|
|
51
19
|
throw new factory_1.factory.errors.NotFound('setting.triggerWebhook.retryIntervalInMS');
|
|
52
20
|
}
|
|
21
|
+
return { setting, retryCountMax, retryIntervalInMS };
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function triggerWebhook(params) {
|
|
25
|
+
return async (repos) => {
|
|
26
|
+
const { setting, retryCountMax, retryIntervalInMS } = await findSettings()(repos);
|
|
53
27
|
// retryableにする(2023-05-12~)
|
|
54
28
|
let retry = true;
|
|
55
29
|
let numberOfTry = 0;
|
|
@@ -63,7 +37,7 @@ function triggerWebhook(params) {
|
|
|
63
37
|
if (numberOfTry > 1) {
|
|
64
38
|
await sleep(retryIntervalInMS * (numberOfTry - 1));
|
|
65
39
|
}
|
|
66
|
-
await processInformAction(params, setting)(repos);
|
|
40
|
+
await (0, processInformAction_1.processInformAction)(params, setting, { useIAP: false })(repos);
|
|
67
41
|
break;
|
|
68
42
|
}
|
|
69
43
|
catch (error) {
|
|
@@ -77,168 +51,40 @@ function triggerWebhook(params) {
|
|
|
77
51
|
}
|
|
78
52
|
};
|
|
79
53
|
}
|
|
80
|
-
|
|
81
|
-
return new Promise((resolve) => {
|
|
82
|
-
setTimeout(() => {
|
|
83
|
-
resolve();
|
|
84
|
-
}, waitTime);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
function createInformActionAttributes(params) {
|
|
88
|
-
return async (repos) => {
|
|
89
|
-
const { about, object, purpose, recipient, project, id, typeOf } = params;
|
|
90
|
-
// redefine recipient(2025-02-15~)
|
|
91
|
-
let informRecipient;
|
|
92
|
-
if (recipient?.typeOf === factory_1.factory.creativeWorkType.WebApplication) {
|
|
93
|
-
informRecipient = {
|
|
94
|
-
name: recipient.name,
|
|
95
|
-
typeOf: recipient.typeOf
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
let target;
|
|
99
|
-
if (typeOf === factory_1.factory.actionType.InformAction && typeof id === 'string' && id !== '') {
|
|
100
|
-
// find target from potentialAction(2025-02-06~)
|
|
101
|
-
const potentialInformAction = (await repos.potentialAction.projectFields({
|
|
102
|
-
limit: 1,
|
|
103
|
-
page: 1,
|
|
104
|
-
id: { $eq: id },
|
|
105
|
-
typeOf: { $eq: typeOf }
|
|
106
|
-
}, ['target', 'recipient'])).shift();
|
|
107
|
-
if (potentialInformAction === undefined) {
|
|
108
|
-
throw new factory_1.factory.errors.NotFound(factory_1.factory.actionType.InformAction);
|
|
109
|
-
}
|
|
110
|
-
if (typeof potentialInformAction.recipient?.name === 'string') {
|
|
111
|
-
informRecipient = { name: potentialInformAction.recipient.name, typeOf: potentialInformAction.recipient.typeOf };
|
|
112
|
-
}
|
|
113
|
-
target = potentialInformAction.target;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
if (params.target?.typeOf === 'EntryPoint') {
|
|
117
|
-
target = params.target;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (informRecipient === undefined) {
|
|
121
|
-
throw new factory_1.factory.errors.ArgumentNull('recipient');
|
|
122
|
-
}
|
|
123
|
-
if (target === undefined) {
|
|
124
|
-
throw new factory_1.factory.errors.ArgumentNull('target');
|
|
125
|
-
}
|
|
126
|
-
return {
|
|
127
|
-
agent: { id: project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
128
|
-
object,
|
|
129
|
-
project: { id: project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
130
|
-
recipient: informRecipient,
|
|
131
|
-
typeOf: factory_1.factory.actionType.InformAction,
|
|
132
|
-
target, // add(2025-02-06~)
|
|
133
|
-
...(typeof purpose?.typeOf === 'string') ? { purpose } : undefined,
|
|
134
|
-
...(typeof about?.typeOf === 'string') ? { about } : undefined, // add(2025-01-23~)
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function signRequest(params) {
|
|
139
|
-
const { requestBody, timestamp, secretKey } = params;
|
|
140
|
-
const payload = `${requestBody}${timestamp.toString()}`;
|
|
141
|
-
return crypto.createHmac('sha256', secretKey)
|
|
142
|
-
.update(payload)
|
|
143
|
-
.digest('hex');
|
|
144
|
-
}
|
|
145
|
-
async function makeRequestHeaders(action, options, requestBody) {
|
|
146
|
-
const secretKey = options?.triggerWebhook?.secretKey;
|
|
147
|
-
const headerIdentifier = options?.triggerWebhook?.headerIdentifier;
|
|
148
|
-
const googleTargetAudience = options?.triggerWebhook?.googleTargetAudience;
|
|
149
|
-
const timestamp = action.startDate.valueOf();
|
|
150
|
-
// sign request(2024-10-28~)
|
|
151
|
-
let signature;
|
|
152
|
-
if (typeof secretKey === 'string' && secretKey !== ''
|
|
153
|
-
&& typeof headerIdentifier === 'string' && headerIdentifier !== '') {
|
|
154
|
-
signature = signRequest({ requestBody, timestamp, secretKey });
|
|
155
|
-
}
|
|
156
|
-
const headers = new Headers({ 'Content-Type': 'application/json' });
|
|
157
|
-
if (typeof headerIdentifier === 'string' && headerIdentifier !== '') {
|
|
158
|
-
headers.append(`X-${headerIdentifier}-Webhook-Timestamp`, String(timestamp));
|
|
159
|
-
if (typeof signature === 'string') {
|
|
160
|
-
headers.append(`X-${headerIdentifier}-Webhook-Signature`, signature);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// support googleAuth(2026-10-30~)
|
|
164
|
-
if (typeof googleTargetAudience === 'string' && googleTargetAudience !== '') {
|
|
165
|
-
const idTokenClient = await (0, getGoogleIdTokenClient_1.getGoogleIdTokenClient)(googleTargetAudience);
|
|
166
|
-
// getRequestHeaders() からキャッシュ済みの "Bearer eyJhbG..." を取得
|
|
167
|
-
const requestHeaders = await idTokenClient.getRequestHeaders();
|
|
168
|
-
const idToken = requestHeaders.get('authorization'); // "Bearer eyJhbG..."
|
|
169
|
-
if (typeof idToken === 'string') {
|
|
170
|
-
// IAPを通過するための認証(Googleが認識するヘッダー)
|
|
171
|
-
headers.append('Proxy-Authorization', idToken);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return headers;
|
|
175
|
-
}
|
|
176
|
-
function processInformAction(params, options) {
|
|
54
|
+
function informHub(params) {
|
|
177
55
|
return async (repos) => {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
data: informActionAttributes.object,
|
|
188
|
-
id: action.id, // support informAction ID(2025-02-20~)
|
|
189
|
-
// 通知識別子を追加(2024-10-24~)
|
|
190
|
-
...(typeof identifier === 'string' && identifier !== '')
|
|
191
|
-
? { identifier }
|
|
192
|
-
: undefined
|
|
193
|
-
});
|
|
194
|
-
const headers = await makeRequestHeaders(action, options, requestBody);
|
|
195
|
-
const res = await fetch(urlTemplate, {
|
|
196
|
-
method: 'POST',
|
|
197
|
-
headers,
|
|
198
|
-
body: requestBody, // body data type must match "Content-Type" header
|
|
199
|
-
...(typeof timeout === 'number')
|
|
200
|
-
? { signal: AbortSignal.timeout(timeout) }
|
|
201
|
-
: undefined
|
|
202
|
-
});
|
|
203
|
-
let body;
|
|
204
|
-
try {
|
|
205
|
-
body = await res.text();
|
|
206
|
-
}
|
|
207
|
-
catch (_error) {
|
|
208
|
-
// no op
|
|
56
|
+
const { setting, retryCountMax, retryIntervalInMS } = await findSettings()(repos);
|
|
57
|
+
// retryableにする(2023-05-12~)
|
|
58
|
+
let retry = true;
|
|
59
|
+
let numberOfTry = 0;
|
|
60
|
+
while (numberOfTry >= 0) {
|
|
61
|
+
try {
|
|
62
|
+
numberOfTry += 1;
|
|
63
|
+
if (numberOfTry > retryCountMax) {
|
|
64
|
+
retry = false;
|
|
209
65
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
case http_status_1.status.ACCEPTED:
|
|
214
|
-
case http_status_1.status.NO_CONTENT: {
|
|
215
|
-
result = {
|
|
216
|
-
statusCode: res.status,
|
|
217
|
-
useFetchAPI: true
|
|
218
|
-
};
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
default: {
|
|
222
|
-
// プロジェクト固有の特別対応
|
|
223
|
-
const ignoreUnexpectedResponse = res.status === http_status_1.status.INTERNAL_SERVER_ERROR
|
|
224
|
-
&& typeof body === 'string'
|
|
225
|
-
&& body.includes(USERNAME_ARGUMENT_REQUIRED_MESSAGE);
|
|
226
|
-
if (!ignoreUnexpectedResponse) {
|
|
227
|
-
throw new factory_1.factory.errors.Internal(`statusCode: ${res.status} body: ${body}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
66
|
+
// retryInterval
|
|
67
|
+
if (numberOfTry > 1) {
|
|
68
|
+
await sleep(retryIntervalInMS * (numberOfTry - 1));
|
|
230
69
|
}
|
|
70
|
+
await (0, processInformAction_1.processInformAction)(params, setting, { useIAP: true })(repos);
|
|
71
|
+
break;
|
|
231
72
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (retry) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
239
80
|
}
|
|
240
|
-
throw error;
|
|
241
81
|
}
|
|
242
|
-
await repos.actions.inform.completeInformAction({ typeOf: action.typeOf, id: action.id, result: result });
|
|
243
82
|
};
|
|
244
83
|
}
|
|
84
|
+
async function sleep(waitTime) {
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
setTimeout(() => {
|
|
87
|
+
resolve();
|
|
88
|
+
}, waitTime);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notifyAbortedTasksByEmail } from './notification/notifyAbortedTasksByEmail';
|
|
2
2
|
import { notifyByEmail } from './notification/notifyByEmail';
|
|
3
3
|
import { sendEmailMessage } from './notification/sendEmailMessage';
|
|
4
|
-
import { triggerWebhook } from './notification/triggerWebhook';
|
|
5
|
-
export { notifyAbortedTasksByEmail, notifyByEmail, sendEmailMessage, triggerWebhook };
|
|
4
|
+
import { triggerWebhook, informHub } from './notification/triggerWebhook';
|
|
5
|
+
export { notifyAbortedTasksByEmail, notifyByEmail, sendEmailMessage, triggerWebhook, informHub };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.triggerWebhook = exports.sendEmailMessage = exports.notifyByEmail = exports.notifyAbortedTasksByEmail = void 0;
|
|
3
|
+
exports.informHub = exports.triggerWebhook = exports.sendEmailMessage = exports.notifyByEmail = exports.notifyAbortedTasksByEmail = void 0;
|
|
4
4
|
const notifyAbortedTasksByEmail_1 = require("./notification/notifyAbortedTasksByEmail");
|
|
5
5
|
Object.defineProperty(exports, "notifyAbortedTasksByEmail", { enumerable: true, get: function () { return notifyAbortedTasksByEmail_1.notifyAbortedTasksByEmail; } });
|
|
6
6
|
const notifyByEmail_1 = require("./notification/notifyByEmail");
|
|
@@ -9,3 +9,4 @@ const sendEmailMessage_1 = require("./notification/sendEmailMessage");
|
|
|
9
9
|
Object.defineProperty(exports, "sendEmailMessage", { enumerable: true, get: function () { return sendEmailMessage_1.sendEmailMessage; } });
|
|
10
10
|
const triggerWebhook_1 = require("./notification/triggerWebhook");
|
|
11
11
|
Object.defineProperty(exports, "triggerWebhook", { enumerable: true, get: function () { return triggerWebhook_1.triggerWebhook; } });
|
|
12
|
+
Object.defineProperty(exports, "informHub", { enumerable: true, get: function () { return triggerWebhook_1.informHub; } });
|
|
@@ -206,7 +206,7 @@ function createInformTasks(params, setting) {
|
|
|
206
206
|
};
|
|
207
207
|
informTasks.push({
|
|
208
208
|
project: event4inform.project,
|
|
209
|
-
name: factory_1.factory.taskName.
|
|
209
|
+
name: factory_1.factory.taskName.InformHub,
|
|
210
210
|
status: factory_1.factory.taskStatus.Ready,
|
|
211
211
|
runsAt: taskRunsAt,
|
|
212
212
|
remainingNumberOfTries: 10,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ICallResult, IExecutableTaskKeys, IOperationExecute } from '../taskHandler';
|
|
2
|
+
import { factory } from '../../factory';
|
|
3
|
+
/**
|
|
4
|
+
* タスク実行関数
|
|
5
|
+
*/
|
|
6
|
+
export declare function call(params: Pick<factory.task.informHub.ITask, IExecutableTaskKeys>): IOperationExecute<ICallResult>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.call = call;
|
|
4
|
+
const inform_1 = require("../../repo/action/inform");
|
|
5
|
+
const potentialAction_1 = require("../../repo/potentialAction");
|
|
6
|
+
const setting_1 = require("../../repo/setting");
|
|
7
|
+
const notification_1 = require("../notification");
|
|
8
|
+
/**
|
|
9
|
+
* タスク実行関数
|
|
10
|
+
*/
|
|
11
|
+
function call(params) {
|
|
12
|
+
return async ({ connection }) => {
|
|
13
|
+
await (0, notification_1.informHub)({
|
|
14
|
+
...params.data,
|
|
15
|
+
project: { id: params.project.id }
|
|
16
|
+
})({
|
|
17
|
+
actions: {
|
|
18
|
+
inform: new inform_1.InformActionRepo(connection)
|
|
19
|
+
},
|
|
20
|
+
potentialAction: new potentialAction_1.PotentialActionRepo(connection),
|
|
21
|
+
setting: new setting_1.SettingRepo(connection)
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -39,7 +39,7 @@ function createInformOfferTasks(params, setting) {
|
|
|
39
39
|
};
|
|
40
40
|
informTasks.push({
|
|
41
41
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
42
|
-
name: factory_1.factory.taskName.
|
|
42
|
+
name: factory_1.factory.taskName.InformHub,
|
|
43
43
|
status: factory_1.factory.taskStatus.Ready,
|
|
44
44
|
runsAt: taskRunsAt,
|
|
45
45
|
remainingNumberOfTries: 10,
|
|
@@ -57,7 +57,7 @@ function createInformHasPOSTasks(params) {
|
|
|
57
57
|
};
|
|
58
58
|
informTasks.push({
|
|
59
59
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
60
|
-
name: factory_1.factory.taskName.
|
|
60
|
+
name: factory_1.factory.taskName.InformHub,
|
|
61
61
|
status: factory_1.factory.taskStatus.Ready,
|
|
62
62
|
runsAt: taskRunsAt,
|
|
63
63
|
remainingNumberOfTries: 10,
|
|
@@ -45,7 +45,7 @@ function createInformOfferCatalogTasks(params, setting) {
|
|
|
45
45
|
};
|
|
46
46
|
informTasks.push({
|
|
47
47
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
48
|
-
name: factory_1.factory.taskName.
|
|
48
|
+
name: factory_1.factory.taskName.InformHub,
|
|
49
49
|
status: factory_1.factory.taskStatus.Ready,
|
|
50
50
|
runsAt: taskRunsAt,
|
|
51
51
|
remainingNumberOfTries: 10,
|
|
@@ -210,7 +210,7 @@ function createInformNoteTasks(params, setting) {
|
|
|
210
210
|
};
|
|
211
211
|
informTasks.push({
|
|
212
212
|
project: project,
|
|
213
|
-
name: factory_1.factory.taskName.
|
|
213
|
+
name: factory_1.factory.taskName.InformHub,
|
|
214
214
|
status: factory_1.factory.taskStatus.Ready,
|
|
215
215
|
runsAt: taskRunsAt,
|
|
216
216
|
remainingNumberOfTries: 10,
|
|
@@ -258,7 +258,7 @@ function createInformMovieTasks(params, setting) {
|
|
|
258
258
|
};
|
|
259
259
|
informTasks.push({
|
|
260
260
|
project: movie4inform.project,
|
|
261
|
-
name: factory_1.factory.taskName.
|
|
261
|
+
name: factory_1.factory.taskName.InformHub,
|
|
262
262
|
status: factory_1.factory.taskStatus.Ready,
|
|
263
263
|
runsAt: taskRunsAt,
|
|
264
264
|
remainingNumberOfTries: 10,
|
|
@@ -308,7 +308,7 @@ function createInformProductTasks(params, setting) {
|
|
|
308
308
|
};
|
|
309
309
|
informTasks.push({
|
|
310
310
|
project: product4inform.project,
|
|
311
|
-
name: factory_1.factory.taskName.
|
|
311
|
+
name: factory_1.factory.taskName.InformHub,
|
|
312
312
|
status: factory_1.factory.taskStatus.Ready,
|
|
313
313
|
runsAt: taskRunsAt,
|
|
314
314
|
remainingNumberOfTries: 10,
|
|
@@ -356,7 +356,7 @@ function createInformCategoryCodeTasks(params, setting) {
|
|
|
356
356
|
};
|
|
357
357
|
informTasks.push({
|
|
358
358
|
project: categoryCode4inform.project,
|
|
359
|
-
name: factory_1.factory.taskName.
|
|
359
|
+
name: factory_1.factory.taskName.InformHub,
|
|
360
360
|
status: factory_1.factory.taskStatus.Ready,
|
|
361
361
|
runsAt: taskRunsAt,
|
|
362
362
|
remainingNumberOfTries: 10,
|
|
@@ -433,7 +433,7 @@ function createInformMovieTheaterTasks(params, setting) {
|
|
|
433
433
|
};
|
|
434
434
|
informTasks.push({
|
|
435
435
|
project: movieTheater4inform.project,
|
|
436
|
-
name: factory_1.factory.taskName.
|
|
436
|
+
name: factory_1.factory.taskName.InformHub,
|
|
437
437
|
status: factory_1.factory.taskStatus.Ready,
|
|
438
438
|
runsAt: taskRunsAt,
|
|
439
439
|
remainingNumberOfTries: 10,
|
|
@@ -494,7 +494,7 @@ function createInformRoomTasks(params, setting) {
|
|
|
494
494
|
};
|
|
495
495
|
informTasks.push({
|
|
496
496
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
497
|
-
name: factory_1.factory.taskName.
|
|
497
|
+
name: factory_1.factory.taskName.InformHub,
|
|
498
498
|
status: factory_1.factory.taskStatus.Ready,
|
|
499
499
|
runsAt: taskRunsAt,
|
|
500
500
|
remainingNumberOfTries: 10,
|
|
@@ -551,7 +551,7 @@ function createInformEntranceGateTasks(params, setting) {
|
|
|
551
551
|
};
|
|
552
552
|
informTasks.push({
|
|
553
553
|
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
554
|
-
name: factory_1.factory.taskName.
|
|
554
|
+
name: factory_1.factory.taskName.InformHub,
|
|
555
555
|
status: factory_1.factory.taskStatus.Ready,
|
|
556
556
|
runsAt: taskRunsAt,
|
|
557
557
|
remainingNumberOfTries: 10,
|
|
@@ -606,7 +606,7 @@ function createInformAccountTitleTasks(params, setting) {
|
|
|
606
606
|
};
|
|
607
607
|
informTasks.push({
|
|
608
608
|
project: accountTitle4inform.project,
|
|
609
|
-
name: factory_1.factory.taskName.
|
|
609
|
+
name: factory_1.factory.taskName.InformHub,
|
|
610
610
|
status: factory_1.factory.taskStatus.Ready,
|
|
611
611
|
runsAt: taskRunsAt,
|
|
612
612
|
remainingNumberOfTries: 10,
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.1090.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.1090.0",
|
|
14
|
-
"@chevre/factory": "11.2.0-alpha.
|
|
14
|
+
"@chevre/factory": "11.2.0-alpha.1",
|
|
15
15
|
"@motionpicture/coa-service": "10.0.0",
|
|
16
16
|
"@motionpicture/gmo-service": "6.1.0-alpha.0",
|
|
17
17
|
"@sendgrid/client": "8.1.4",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
"postversion": "git push origin --tags",
|
|
90
90
|
"prepublishOnly": "npm run clean && npm run build"
|
|
91
91
|
},
|
|
92
|
-
"version": "28.1.0-alpha.
|
|
92
|
+
"version": "28.1.0-alpha.3"
|
|
93
93
|
}
|