UNPKG

3.81 kBTypeScriptView Raw
1// Copyright (c) .NET Foundation. All rights reserved.
2// Licensed under the MIT License.
3
4import { FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index';
5import { InvocationContext } from './InvocationContext';
6
7export type EventGridHandler = (event: EventGridEvent, context: InvocationContext) => FunctionResult;
8
9export interface EventGridFunctionOptions extends EventGridTriggerOptions, Partial<FunctionOptions> {
10 handler: EventGridHandler;
11
12 trigger?: EventGridTrigger;
13}
14
15/**
16 * At this point in time there are no event grid trigger-specific options
17 */
18export interface EventGridTriggerOptions {}
19export type EventGridTrigger = FunctionTrigger & EventGridTriggerOptions;
20
21export interface EventGridOutputKeyOptions {
22 /**
23 * An app setting (or environment variable) that contains the URI for the custom topic
24 */
25 topicEndpointUri: string;
26
27 /**
28 * An app setting (or environment variable) that contains an access key for the custom topic
29 */
30 topicKeySetting: string;
31}
32export interface EventGridOutputConnectionOptions {
33 /**
34 * The value of the common prefix for the app setting that contains the `topicEndpointUri`.
35 * When setting the `connection` property, the `topicEndpointUri` and `topicKeySetting` properties should NOT be set.
36 */
37 connection: string;
38}
39export type EventGridOutputOptions = EventGridOutputKeyOptions | EventGridOutputConnectionOptions;
40export type EventGridOutput = FunctionOutput & EventGridOutputOptions;
41
42/**
43 * [Link to docs and examples](https://docs.microsoft.com/azure/event-grid/event-schema)
44 * This "partial" interface is meant to be used when creating an event yourself and allows some properties to be left out
45 */
46export interface EventGridPartialEvent {
47 /**
48 * Full resource path to the event source. This field isn't writeable. Event Grid provides this value
49 * If included, must match the Event Grid topic Azure Resource Manager ID exactly. If not included, Event Grid will stamp onto the event.
50 */
51 topic?: string;
52
53 /**
54 * Publisher-defined path to the event subject
55 */
56 subject: string;
57
58 /**
59 * One of the registered event types for this event source
60 */
61 eventType: string;
62
63 /**
64 * The time the event is generated based on the provider's UTC time
65 */
66 eventTime: string;
67
68 /**
69 * Unique identifier for the event
70 */
71 id: string;
72
73 /**
74 * Event data specific to the resource provider
75 */
76 data?: Record<string, unknown>;
77
78 /**
79 * The schema version of the data object. The publisher defines the schema version.
80 * If not included, will be stamped with an empty value
81 */
82 dataVersion?: string;
83
84 /**
85 * The schema version of the event metadata. Event Grid defines the schema of the top-level properties. Event Grid provides this value.
86 * If included, must match the Event Grid Schema `metadataVersion` exactly (currently, only 1). If not included, Event Grid will stamp onto the event.
87 */
88 metadataVersion?: string;
89}
90
91/**
92 * [Link to docs and examples](https://docs.microsoft.com/azure/event-grid/event-schema)
93 */
94export interface EventGridEvent extends EventGridPartialEvent {
95 /**
96 * Full resource path to the event source. This field isn't writeable. Event Grid provides this value
97 */
98 topic: string;
99
100 /**
101 * The schema version of the data object. The publisher defines the schema version.
102 */
103 dataVersion: string;
104
105 /**
106 * The schema version of the event metadata. Event Grid defines the schema of the top-level properties. Event Grid provides this value.
107 */
108 metadataVersion: string;
109}