-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebhook.js
More file actions
82 lines (79 loc) · 1.62 KB
/
Webhook.js
File metadata and controls
82 lines (79 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* Webhook model for storing webhook configurations
*/
const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');
const crypto = require('crypto');
const Webhook = sequelize.define('Webhook', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'Users',
key: 'id'
}
},
tenantId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: 'XeroTenants',
key: 'id'
}
},
name: {
type: DataTypes.STRING,
allowNull: false
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
event: {
type: DataTypes.STRING,
allowNull: false,
comment: 'Event type that triggers the webhook'
},
url: {
type: DataTypes.STRING,
allowNull: false,
comment: 'URL to send the webhook payload to'
},
secret: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: () => crypto.randomBytes(32).toString('hex'),
comment: 'Secret used to sign the webhook payload'
},
headers: {
type: DataTypes.JSON,
allowNull: true,
comment: 'Additional headers to send with the webhook'
},
isActive: {
type: DataTypes.BOOLEAN,
defaultValue: true
},
lastTriggeredAt: {
type: DataTypes.DATE,
allowNull: true
},
successCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
failureCount: {
type: DataTypes.INTEGER,
defaultValue: 0
},
lastError: {
type: DataTypes.TEXT,
allowNull: true
}
});
module.exports = Webhook;