|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +import { FunctionInput, FunctionOptions, FunctionOutput, FunctionResult, FunctionTrigger } from './index'; |
| 5 | +import { InvocationContext } from './InvocationContext'; |
| 6 | + |
| 7 | +export type WebPubSubHandler = (message: unknown, context: InvocationContext) => FunctionResult; |
| 8 | + |
| 9 | +export interface WebPubSubFunctionOptions extends WebPubSubTriggerOptions, Partial<FunctionOptions> { |
| 10 | + handler: WebPubSubHandler; |
| 11 | + |
| 12 | + trigger?: WebPubSubTrigger; |
| 13 | +} |
| 14 | + |
| 15 | +export interface WebPubSubTriggerOptions { |
| 16 | + /** |
| 17 | + * Required - The variable name used in function code for the parameter that receives the event data |
| 18 | + */ |
| 19 | + name: string; |
| 20 | + |
| 21 | + /** |
| 22 | + * Required - The name of the hub to which the function is bound |
| 23 | + */ |
| 24 | + hub: string; |
| 25 | + |
| 26 | + /** |
| 27 | + * Required - The type of event to which the function should respond |
| 28 | + * Must be either 'user' or 'system' |
| 29 | + */ |
| 30 | + eventType: 'user' | 'system'; |
| 31 | + |
| 32 | + /** |
| 33 | + * Required - The name of the event to which the function should respond |
| 34 | + * For system event type: 'connect', 'connected', or 'disconnected' |
| 35 | + * For user-defined subprotocols: 'message' |
| 36 | + * For system supported subprotocol json.webpubsub.azure.v1: user-defined event name |
| 37 | + */ |
| 38 | + eventName: string; |
| 39 | + |
| 40 | + /** |
| 41 | + * Optional - Specifies which client protocol can trigger the Web PubSub trigger functions |
| 42 | + * Default is 'all' |
| 43 | + */ |
| 44 | + clientProtocols?: 'all' | 'webPubSub' | 'mqtt'; |
| 45 | + |
| 46 | + /** |
| 47 | + * Optional - The name of an app setting or setting collection that specifies the upstream Azure Web PubSub service |
| 48 | + * Used for signature validation |
| 49 | + * Defaults to "WebPubSubConnectionString" if not specified |
| 50 | + * Set to null to disable validation |
| 51 | + */ |
| 52 | + connection?: string | null; |
| 53 | +} |
| 54 | + |
| 55 | +export type WebPubSubTrigger = FunctionTrigger & WebPubSubTriggerOptions; |
| 56 | + |
| 57 | +export interface WebPubSubConnectionInputOptions { |
| 58 | + /** |
| 59 | + * Required - Variable name used in function code for input connection binding object. |
| 60 | + */ |
| 61 | + name: string; |
| 62 | + |
| 63 | + /** |
| 64 | + * Required - The name of the Web PubSub hub for the function to be triggered. |
| 65 | + * Can be set in the attribute (higher priority) or in app settings as a global value. |
| 66 | + */ |
| 67 | + hub: string; |
| 68 | + |
| 69 | + /** |
| 70 | + * Optional - The value of the user identifier claim to be set in the access key token. |
| 71 | + */ |
| 72 | + userId?: string; |
| 73 | + |
| 74 | + /** |
| 75 | + * Optional - The client protocol type. |
| 76 | + * Valid values are 'default' and 'mqtt'. |
| 77 | + * For MQTT clients, you must set it to 'mqtt'. |
| 78 | + * For other clients, you can omit the property or set it to 'default'. |
| 79 | + */ |
| 80 | + clientProtocol?: 'default' | 'mqtt'; |
| 81 | + |
| 82 | + /** |
| 83 | + * Optional - The name of the app setting that contains the Web PubSub Service connection string. |
| 84 | + * Defaults to "WebPubSubConnectionString". |
| 85 | + */ |
| 86 | + connection?: string; |
| 87 | +} |
| 88 | +export type WebPubSubConnectionInput = FunctionInput & WebPubSubConnectionInputOptions; |
| 89 | + |
| 90 | +export interface WebPubSubContextInputOptions { |
| 91 | + /** |
| 92 | + * Required - Variable name used in function code for input Web PubSub request. |
| 93 | + */ |
| 94 | + name: string; |
| 95 | + |
| 96 | + /** |
| 97 | + * Optional - The name of an app settings or setting collection that specifies the upstream Azure Web PubSub service. |
| 98 | + * The value is used for Abuse Protection and Signature validation. |
| 99 | + * The value is auto resolved with "WebPubSubConnectionString" by default. |
| 100 | + * Null means the validation isn't needed and always succeeds. |
| 101 | + */ |
| 102 | + connection?: string; |
| 103 | +} |
| 104 | +export type WebPubSubContextInput = FunctionInput & WebPubSubContextInputOptions; |
| 105 | + |
| 106 | +export interface WebPubSubOutputOptions { |
| 107 | + /** |
| 108 | + * Required - Variable name used in function code for output binding object. |
| 109 | + */ |
| 110 | + name: string; |
| 111 | + |
| 112 | + /** |
| 113 | + * Required - The name of the hub to which the function is bound. |
| 114 | + * Can be set in the attribute (higher priority) or in app settings as a global value. |
| 115 | + */ |
| 116 | + hub: string; |
| 117 | + |
| 118 | + /** |
| 119 | + * Optional - The name of the app setting that contains the Web PubSub Service connection string. |
| 120 | + * Defaults to "WebPubSubConnectionString". |
| 121 | + */ |
| 122 | + connection?: string; |
| 123 | +} |
| 124 | +export type WebPubSubOutput = FunctionOutput & WebPubSubOutputOptions; |
0 commit comments