This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
/
BasicHookOperationSchema.js
85 lines (77 loc) · 2.82 KB
/
BasicHookOperationSchema.js
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
83
84
85
'use strict';
const makeSchema = require('../utils/makeSchema');
const BasicOperationSchema = require('./BasicOperationSchema');
const FunctionSchema = require('./FunctionSchema');
const RequestSchema = require('./RequestSchema');
// TODO: would be nice to deep merge these instead
// or maybe use allOf which is built into json-schema
const BasicHookOperationSchema = JSON.parse(
JSON.stringify(BasicOperationSchema.schema)
);
const hookTechnicallyRequired =
'Note: this is required for public apps to ensure the best UX for the end-user. For private apps, you can ignore warnings about this property with the `--without-style` flag during `zapier push`.';
BasicHookOperationSchema.id = '/BasicHookOperationSchema';
BasicHookOperationSchema.description =
'Represents the inbound mechanics of hooks with optional subscribe/unsubscribe. Defers to list for fields.';
BasicHookOperationSchema.properties = {
type: {
description:
'Must be explicitly set to `"hook"` unless this hook is defined as part of a resource, in which case it\'s optional.',
type: 'string',
enum: ['hook'],
docAnnotation: {
required: {
type: 'replace',
value: '**yes** (with exceptions, see description)'
}
}
},
resource: BasicHookOperationSchema.properties.resource,
perform: {
description: 'A function that processes the inbound webhook request.',
$ref: FunctionSchema.id
},
performList: {
description:
'Can get "live" data on demand instead of waiting for a hook. If you find yourself reaching for this - consider resources and their built-in hook/list methods. ' +
hookTechnicallyRequired,
oneOf: [{ $ref: RequestSchema.id }, { $ref: FunctionSchema.id }],
docAnnotation: {
required: {
type: 'replace',
value: '**yes** (with exceptions, see description)'
}
}
},
performSubscribe: {
description:
'Takes a URL and any necessary data from the user and subscribes. ' +
hookTechnicallyRequired,
oneOf: [{ $ref: RequestSchema.id }, { $ref: FunctionSchema.id }],
docAnnotation: {
required: {
type: 'replace',
value: '**yes** (with exceptions, see description)'
}
}
},
performUnsubscribe: {
description:
'Takes a URL and data from a previous subscribe call and unsubscribes. ' +
hookTechnicallyRequired,
oneOf: [{ $ref: RequestSchema.id }, { $ref: FunctionSchema.id }],
docAnnotation: {
required: {
type: 'replace',
value: '**yes** (with exceptions, see description)'
}
}
},
inputFields: BasicHookOperationSchema.properties.inputFields,
outputFields: BasicHookOperationSchema.properties.outputFields,
sample: BasicHookOperationSchema.properties.sample
};
module.exports = makeSchema(
BasicHookOperationSchema,
BasicOperationSchema.dependencies
);