@slates/provider 1.0.0-rc.22 → 1.0.0-rc.24

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.
@@ -1,4 +1,4 @@
1
- import type { SlateTool, SlateTrigger } from '../action';
1
+ import type { SlateTool, SlateTrigger, SlateTriggerGroup } from '../action';
2
2
  import type { SlateAdapter } from '../adapter';
3
3
  import { SlateDeclarationError } from '../error';
4
4
  import type { SlateSpecification } from './specification';
@@ -10,7 +10,8 @@ export class Slate<ConfigType extends {}, AuthType extends {}> {
10
10
  | SlateTrigger<ConfigType, AuthType, any, any>
11
11
  | SlateTool<ConfigType, AuthType, any, any>
12
12
  )[],
13
- private readonly _adapters: SlateAdapter<ConfigType, AuthType>[]
13
+ private readonly _adapters: SlateAdapter<ConfigType, AuthType>[],
14
+ private readonly _triggerGroups: SlateTriggerGroup<ConfigType, AuthType>[]
14
15
  ) {}
15
16
 
16
17
  static create<ConfigType extends {}, AuthType extends {}>(params: {
@@ -18,6 +19,7 @@ export class Slate<ConfigType extends {}, AuthType extends {}> {
18
19
  triggers: SlateTrigger<ConfigType, AuthType, any, any>[];
19
20
  tools: SlateTool<ConfigType, AuthType, any, any>[];
20
21
  adapters?: SlateAdapter<ConfigType, AuthType>[];
22
+ triggerGroups?: SlateTriggerGroup<ConfigType, AuthType>[];
21
23
  }) {
22
24
  let adapters = params.adapters ?? [];
23
25
  let actions = [...params.triggers, ...params.tools];
@@ -47,7 +49,29 @@ export class Slate<ConfigType extends {}, AuthType extends {}> {
47
49
  }
48
50
  }
49
51
 
50
- return new Slate(params.spec, actions, adapters);
52
+ let triggerGroups = params.triggerGroups ?? [];
53
+ let seenTriggerGroupKeys = new Set<string>();
54
+ for (let group of triggerGroups) {
55
+ if (seenTriggerGroupKeys.has(group.key)) {
56
+ throw new SlateDeclarationError(
57
+ `Trigger group "${group.key}" is registered more than once`
58
+ );
59
+ }
60
+ seenTriggerGroupKeys.add(group.key);
61
+ }
62
+
63
+ let manualWebhookTriggerGroups = triggerGroups.filter(
64
+ group => group.source === 'webhook' && group.webhook?.manualRegistration
65
+ );
66
+ if (manualWebhookTriggerGroups.length > 1) {
67
+ throw new SlateDeclarationError(
68
+ `Only one trigger group may use manual webhook registration, but found: ${manualWebhookTriggerGroups
69
+ .map(group => group.key)
70
+ .join(', ')}`
71
+ );
72
+ }
73
+
74
+ return new Slate(params.spec, actions, adapters, triggerGroups);
51
75
  }
52
76
 
53
77
  get spec() {
@@ -61,4 +85,8 @@ export class Slate<ConfigType extends {}, AuthType extends {}> {
61
85
  get adapters() {
62
86
  return this._adapters;
63
87
  }
88
+
89
+ get triggerGroups() {
90
+ return this._triggerGroups;
91
+ }
64
92
  }
@@ -1,4 +1,4 @@
1
- import type { SlateWebhookHttpOptions, SlateWebhookHttpResponseInit } from '../action';
1
+ import type { SlateWebhookHttpResponseInit } from '../action';
2
2
 
3
3
  export const graphWebhookHttp = {
4
4
  methods: ['POST'],
@@ -6,7 +6,7 @@ export const graphWebhookHttp = {
6
6
  mode: 'match',
7
7
  match: [{ hasQueryParam: 'validationToken' }]
8
8
  }
9
- } satisfies SlateWebhookHttpOptions;
9
+ };
10
10
 
11
11
  export let getGraphWebhookValidationResponse = (
12
12
  request: Request
@@ -1,4 +1,4 @@
1
- import type { SlateWebhookHttpOptions, SlateWebhookHttpResponseInit } from '../action';
1
+ import type { SlateWebhookHttpResponseInit } from '../action';
2
2
 
3
3
  export const metaWebhookHttp = {
4
4
  methods: ['GET', 'POST'],
@@ -6,7 +6,7 @@ export const metaWebhookHttp = {
6
6
  mode: 'match',
7
7
  match: [{ method: 'GET', hasQueryParam: 'hub.mode' }]
8
8
  }
9
- } satisfies SlateWebhookHttpOptions;
9
+ };
10
10
 
11
11
  export let getMetaWebhookVerificationResponse = (
12
12
  request: Request,