@kne/fastify-webhook 0.1.3-alpha.4 → 0.1.3-alpha.5

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.
@@ -134,6 +134,7 @@ module.exports = fp(async (fastify, options) => {
134
134
  type: 'object',
135
135
  properties: {
136
136
  id: { type: 'string' },
137
+ type: { type: 'string' },
137
138
  currentPage: { type: 'number', default: 1 },
138
139
  perPage: { type: 'number', default: 10 }
139
140
  }
@@ -15,6 +15,10 @@ module.exports = ({ DataTypes, options }) => {
15
15
  type: DataTypes.JSON,
16
16
  comment: '调用参数'
17
17
  },
18
+ type: {
19
+ type: DataTypes.STRING,
20
+ comment: '调用类型'
21
+ },
18
22
  status: {
19
23
  type: DataTypes.ENUM('success', 'failed'),
20
24
  comment: '调用返回状态'
@@ -63,12 +63,12 @@ module.exports = fp(async (fastify, options) => {
63
63
  );
64
64
  };
65
65
 
66
- const invokeRecord = async ({ id, currentPage, perPage }) => {
66
+ const invokeRecord = async ({ id, type, currentPage, perPage }) => {
67
67
  const { rows, count } = await models.invocation.findAndCountAll({
68
68
  where: id
69
69
  ? { webhookClientId: id }
70
70
  : {
71
- webhookClientId: { [Op.is]: null }
71
+ webhookClientId: { [Op.is]: null, type }
72
72
  },
73
73
  limit: perPage,
74
74
  offset: (currentPage - 1) * perPage
@@ -133,6 +133,7 @@ module.exports = fp(async (fastify, options) => {
133
133
  rawBody,
134
134
  query
135
135
  },
136
+ type,
136
137
  status: 'failed',
137
138
  startTime,
138
139
  endTime: new Date()
@@ -144,6 +145,7 @@ module.exports = fp(async (fastify, options) => {
144
145
  const result = await options.hooks[currentWebhook.type]({ input });
145
146
  await models.invocation.create({
146
147
  input,
148
+ type,
147
149
  result,
148
150
  webhookClientId: currentWebhook.id,
149
151
  status: 'success',
@@ -154,6 +156,7 @@ module.exports = fp(async (fastify, options) => {
154
156
  } catch (e) {
155
157
  await models.invocation.create({
156
158
  input,
159
+ type,
157
160
  result: e.toString(),
158
161
  webhookClientId: currentWebhook.id,
159
162
  status: 'failed',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kne/fastify-webhook",
3
- "version": "0.1.3-alpha.4",
3
+ "version": "0.1.3-alpha.5",
4
4
  "description": "实现一个webhook功能.",
5
5
  "main": "index.js",
6
6
  "scripts": {