@slates/test 1.0.0-rc.27 → 1.0.0-rc.29
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.
- package/dist/index.cjs +42 -7
- package/dist/index.d.cts +226 -6
- package/dist/index.d.ts +226 -6
- package/dist/index.module.js +37 -7
- package/package.json +4 -4
- package/src/optionList.test.ts +194 -0
- package/src/runtime.ts +70 -14
- package/src/triggerLifecycle.test.ts +618 -0
package/dist/index.d.ts
CHANGED
|
@@ -246,14 +246,22 @@ declare let getSlateContract: (client: SlatesTestClient) => Promise<{
|
|
|
246
246
|
type: "webhook";
|
|
247
247
|
registration: {
|
|
248
248
|
mode: "auto";
|
|
249
|
+
deliveryConfig?: {
|
|
250
|
+
userConfigSchema: Record<string, any>;
|
|
251
|
+
fullConfigSchema: Record<string, any>;
|
|
252
|
+
} | undefined;
|
|
249
253
|
} | {
|
|
250
254
|
mode: "manual";
|
|
251
255
|
userConfigSchema: Record<string, any>;
|
|
252
256
|
fullConfigSchema: Record<string, any>;
|
|
253
257
|
};
|
|
258
|
+
supportsExpansion?: boolean | undefined;
|
|
259
|
+
supportsRenewal?: boolean | undefined;
|
|
260
|
+
reconcileIntervalSeconds?: number | undefined;
|
|
254
261
|
};
|
|
255
262
|
description?: string | undefined;
|
|
256
263
|
metadata?: Record<string, any> | undefined;
|
|
264
|
+
selectionSchema?: Record<string, any> | undefined;
|
|
257
265
|
}[];
|
|
258
266
|
authMethods: {
|
|
259
267
|
id: string;
|
|
@@ -445,14 +453,22 @@ declare let expectSlateContract: (d: {
|
|
|
445
453
|
type: "webhook";
|
|
446
454
|
registration: {
|
|
447
455
|
mode: "auto";
|
|
456
|
+
deliveryConfig?: {
|
|
457
|
+
userConfigSchema: Record<string, any>;
|
|
458
|
+
fullConfigSchema: Record<string, any>;
|
|
459
|
+
} | undefined;
|
|
448
460
|
} | {
|
|
449
461
|
mode: "manual";
|
|
450
462
|
userConfigSchema: Record<string, any>;
|
|
451
463
|
fullConfigSchema: Record<string, any>;
|
|
452
464
|
};
|
|
465
|
+
supportsExpansion?: boolean | undefined;
|
|
466
|
+
supportsRenewal?: boolean | undefined;
|
|
467
|
+
reconcileIntervalSeconds?: number | undefined;
|
|
453
468
|
};
|
|
454
469
|
description?: string | undefined;
|
|
455
470
|
metadata?: Record<string, any> | undefined;
|
|
471
|
+
selectionSchema?: Record<string, any> | undefined;
|
|
456
472
|
}[];
|
|
457
473
|
authMethods: {
|
|
458
474
|
id: string;
|
|
@@ -495,13 +511,87 @@ declare let expectSlateContract: (d: {
|
|
|
495
511
|
}>;
|
|
496
512
|
declare let registerSlateTriggerGroupWebhook: (d: {
|
|
497
513
|
client: SlatesTestClient;
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
514
|
+
} & Parameters<SlatesTestClient["registerTriggerGroupWebhook"]>[0]) => Promise<{
|
|
515
|
+
webhookRegistrationIdentifier: string;
|
|
516
|
+
webhookRegistrationPayload: any;
|
|
517
|
+
expiresAt?: string | null | undefined;
|
|
518
|
+
renewAfter?: string | null | undefined;
|
|
519
|
+
routingKeys?: string[] | undefined;
|
|
520
|
+
requestTraces?: {
|
|
521
|
+
startedAt: string;
|
|
522
|
+
durationMs: number;
|
|
523
|
+
request: {
|
|
524
|
+
method: string;
|
|
525
|
+
url: string;
|
|
526
|
+
headers?: Record<string, string> | undefined;
|
|
527
|
+
body?: {
|
|
528
|
+
text: string;
|
|
529
|
+
contentType?: string | undefined;
|
|
530
|
+
truncated?: boolean | undefined;
|
|
531
|
+
} | undefined;
|
|
532
|
+
};
|
|
533
|
+
response?: {
|
|
534
|
+
status: number;
|
|
535
|
+
statusText?: string | undefined;
|
|
536
|
+
headers?: Record<string, string> | undefined;
|
|
537
|
+
body?: {
|
|
538
|
+
text: string;
|
|
539
|
+
contentType?: string | undefined;
|
|
540
|
+
truncated?: boolean | undefined;
|
|
541
|
+
} | undefined;
|
|
542
|
+
} | undefined;
|
|
543
|
+
error?: {
|
|
544
|
+
message: string;
|
|
545
|
+
code?: string | undefined;
|
|
546
|
+
} | undefined;
|
|
547
|
+
}[] | undefined;
|
|
548
|
+
}>;
|
|
549
|
+
declare let renewSlateTriggerGroupWebhook: (d: {
|
|
550
|
+
client: SlatesTestClient;
|
|
551
|
+
} & Parameters<SlatesTestClient["renewTriggerGroupWebhook"]>[0]) => Promise<{
|
|
503
552
|
webhookRegistrationIdentifier: string;
|
|
504
553
|
webhookRegistrationPayload: any;
|
|
554
|
+
expiresAt?: string | null | undefined;
|
|
555
|
+
renewAfter?: string | null | undefined;
|
|
556
|
+
routingKeys?: string[] | undefined;
|
|
557
|
+
requestTraces?: {
|
|
558
|
+
startedAt: string;
|
|
559
|
+
durationMs: number;
|
|
560
|
+
request: {
|
|
561
|
+
method: string;
|
|
562
|
+
url: string;
|
|
563
|
+
headers?: Record<string, string> | undefined;
|
|
564
|
+
body?: {
|
|
565
|
+
text: string;
|
|
566
|
+
contentType?: string | undefined;
|
|
567
|
+
truncated?: boolean | undefined;
|
|
568
|
+
} | undefined;
|
|
569
|
+
};
|
|
570
|
+
response?: {
|
|
571
|
+
status: number;
|
|
572
|
+
statusText?: string | undefined;
|
|
573
|
+
headers?: Record<string, string> | undefined;
|
|
574
|
+
body?: {
|
|
575
|
+
text: string;
|
|
576
|
+
contentType?: string | undefined;
|
|
577
|
+
truncated?: boolean | undefined;
|
|
578
|
+
} | undefined;
|
|
579
|
+
} | undefined;
|
|
580
|
+
error?: {
|
|
581
|
+
message: string;
|
|
582
|
+
code?: string | undefined;
|
|
583
|
+
} | undefined;
|
|
584
|
+
}[] | undefined;
|
|
585
|
+
}>;
|
|
586
|
+
declare let expandSlateTriggerGroupWebhook: (d: {
|
|
587
|
+
client: SlatesTestClient;
|
|
588
|
+
} & Parameters<SlatesTestClient["expandTriggerGroupWebhook"]>[0]) => Promise<{
|
|
589
|
+
events: {
|
|
590
|
+
payload: Record<string, any>;
|
|
591
|
+
triggerIds: string[];
|
|
592
|
+
idempotencyKey?: string | undefined;
|
|
593
|
+
}[];
|
|
594
|
+
updatedState?: any;
|
|
505
595
|
requestTraces?: {
|
|
506
596
|
startedAt: string;
|
|
507
597
|
durationMs: number;
|
|
@@ -535,6 +625,7 @@ declare let pollSlateTriggerGroupEvents: (d: {
|
|
|
535
625
|
client: SlatesTestClient;
|
|
536
626
|
triggerGroupId: string;
|
|
537
627
|
state?: any;
|
|
628
|
+
selection?: Record<string, any>;
|
|
538
629
|
}) => Promise<{
|
|
539
630
|
events: {
|
|
540
631
|
payload: Record<string, any>;
|
|
@@ -571,6 +662,91 @@ declare let pollSlateTriggerGroupEvents: (d: {
|
|
|
571
662
|
} | undefined;
|
|
572
663
|
}[] | undefined;
|
|
573
664
|
}>;
|
|
665
|
+
declare let listSlateTriggerGroupSelectionOptions: (d: {
|
|
666
|
+
client: SlatesTestClient;
|
|
667
|
+
triggerGroupId: string;
|
|
668
|
+
field: string;
|
|
669
|
+
query?: string | null;
|
|
670
|
+
pageToken?: any;
|
|
671
|
+
selection?: Record<string, any>;
|
|
672
|
+
}) => Promise<{
|
|
673
|
+
options: {
|
|
674
|
+
value: string | number;
|
|
675
|
+
label: string;
|
|
676
|
+
description?: string | undefined;
|
|
677
|
+
}[];
|
|
678
|
+
nextPageToken: any;
|
|
679
|
+
requestTraces?: {
|
|
680
|
+
startedAt: string;
|
|
681
|
+
durationMs: number;
|
|
682
|
+
request: {
|
|
683
|
+
method: string;
|
|
684
|
+
url: string;
|
|
685
|
+
headers?: Record<string, string> | undefined;
|
|
686
|
+
body?: {
|
|
687
|
+
text: string;
|
|
688
|
+
contentType?: string | undefined;
|
|
689
|
+
truncated?: boolean | undefined;
|
|
690
|
+
} | undefined;
|
|
691
|
+
};
|
|
692
|
+
response?: {
|
|
693
|
+
status: number;
|
|
694
|
+
statusText?: string | undefined;
|
|
695
|
+
headers?: Record<string, string> | undefined;
|
|
696
|
+
body?: {
|
|
697
|
+
text: string;
|
|
698
|
+
contentType?: string | undefined;
|
|
699
|
+
truncated?: boolean | undefined;
|
|
700
|
+
} | undefined;
|
|
701
|
+
} | undefined;
|
|
702
|
+
error?: {
|
|
703
|
+
message: string;
|
|
704
|
+
code?: string | undefined;
|
|
705
|
+
} | undefined;
|
|
706
|
+
}[] | undefined;
|
|
707
|
+
}>;
|
|
708
|
+
declare let listSlateOptionListOptions: (d: {
|
|
709
|
+
client: SlatesTestClient;
|
|
710
|
+
optionListId: string;
|
|
711
|
+
query?: string | null;
|
|
712
|
+
pageToken?: any;
|
|
713
|
+
params?: Record<string, any>;
|
|
714
|
+
}) => Promise<{
|
|
715
|
+
options: {
|
|
716
|
+
value: string | number;
|
|
717
|
+
label: string;
|
|
718
|
+
description?: string | undefined;
|
|
719
|
+
}[];
|
|
720
|
+
nextPageToken: any;
|
|
721
|
+
requestTraces?: {
|
|
722
|
+
startedAt: string;
|
|
723
|
+
durationMs: number;
|
|
724
|
+
request: {
|
|
725
|
+
method: string;
|
|
726
|
+
url: string;
|
|
727
|
+
headers?: Record<string, string> | undefined;
|
|
728
|
+
body?: {
|
|
729
|
+
text: string;
|
|
730
|
+
contentType?: string | undefined;
|
|
731
|
+
truncated?: boolean | undefined;
|
|
732
|
+
} | undefined;
|
|
733
|
+
};
|
|
734
|
+
response?: {
|
|
735
|
+
status: number;
|
|
736
|
+
statusText?: string | undefined;
|
|
737
|
+
headers?: Record<string, string> | undefined;
|
|
738
|
+
body?: {
|
|
739
|
+
text: string;
|
|
740
|
+
contentType?: string | undefined;
|
|
741
|
+
truncated?: boolean | undefined;
|
|
742
|
+
} | undefined;
|
|
743
|
+
} | undefined;
|
|
744
|
+
error?: {
|
|
745
|
+
message: string;
|
|
746
|
+
code?: string | undefined;
|
|
747
|
+
} | undefined;
|
|
748
|
+
}[] | undefined;
|
|
749
|
+
}>;
|
|
574
750
|
declare let connectSlateTriggerGroupGateway: (d: {
|
|
575
751
|
client: SlatesTestClient;
|
|
576
752
|
triggerGroupId: string;
|
|
@@ -678,6 +854,7 @@ declare let processSlateTriggerGroupWebhook: (d: {
|
|
|
678
854
|
triggerIds: string[];
|
|
679
855
|
idempotencyKey?: string | undefined;
|
|
680
856
|
}[];
|
|
857
|
+
requiresExpansion?: boolean | undefined;
|
|
681
858
|
response?: {
|
|
682
859
|
status: number;
|
|
683
860
|
headers: Record<string, string>;
|
|
@@ -718,6 +895,48 @@ declare let processSlateTriggerGroupWebhook: (d: {
|
|
|
718
895
|
} | undefined;
|
|
719
896
|
}[] | undefined;
|
|
720
897
|
}>;
|
|
898
|
+
declare let authenticateSlateTriggerGroupWebhookDelivery: (d: {
|
|
899
|
+
client: SlatesTestClient;
|
|
900
|
+
triggerGroupId: string;
|
|
901
|
+
url: string;
|
|
902
|
+
method?: string;
|
|
903
|
+
headers?: Record<string, string>;
|
|
904
|
+
body?: string | Uint8Array | null;
|
|
905
|
+
deliveryConfig: unknown;
|
|
906
|
+
}) => Promise<{
|
|
907
|
+
routingKeys: string[];
|
|
908
|
+
rejected?: {
|
|
909
|
+
status: number;
|
|
910
|
+
} | null | undefined;
|
|
911
|
+
requestTraces?: {
|
|
912
|
+
startedAt: string;
|
|
913
|
+
durationMs: number;
|
|
914
|
+
request: {
|
|
915
|
+
method: string;
|
|
916
|
+
url: string;
|
|
917
|
+
headers?: Record<string, string> | undefined;
|
|
918
|
+
body?: {
|
|
919
|
+
text: string;
|
|
920
|
+
contentType?: string | undefined;
|
|
921
|
+
truncated?: boolean | undefined;
|
|
922
|
+
} | undefined;
|
|
923
|
+
};
|
|
924
|
+
response?: {
|
|
925
|
+
status: number;
|
|
926
|
+
statusText?: string | undefined;
|
|
927
|
+
headers?: Record<string, string> | undefined;
|
|
928
|
+
body?: {
|
|
929
|
+
text: string;
|
|
930
|
+
contentType?: string | undefined;
|
|
931
|
+
truncated?: boolean | undefined;
|
|
932
|
+
} | undefined;
|
|
933
|
+
} | undefined;
|
|
934
|
+
error?: {
|
|
935
|
+
message: string;
|
|
936
|
+
code?: string | undefined;
|
|
937
|
+
} | undefined;
|
|
938
|
+
}[] | undefined;
|
|
939
|
+
}>;
|
|
721
940
|
declare let unregisterSlateTriggerGroupWebhook: (d: {
|
|
722
941
|
client: SlatesTestClient;
|
|
723
942
|
triggerGroupId: string;
|
|
@@ -763,6 +982,7 @@ declare let mapSlateTriggerEvent: (d: {
|
|
|
763
982
|
type: string;
|
|
764
983
|
id: string;
|
|
765
984
|
output: Record<string, any>;
|
|
985
|
+
attributes?: Record<string, string[]> | undefined;
|
|
766
986
|
requestTraces?: {
|
|
767
987
|
startedAt: string;
|
|
768
988
|
durationMs: number;
|
|
@@ -805,4 +1025,4 @@ declare let getMcpCompatibleToolSchemaCases: (source: ToolSchemaSource) => Reado
|
|
|
805
1025
|
declare let expectMcpCompatibleToolSchema: (tool: ToolSchemaTarget) => void;
|
|
806
1026
|
declare let describeMcpCompatibleToolSchemas: (name: string, source: ToolSchemaSource) => void;
|
|
807
1027
|
|
|
808
|
-
export { type ExpectedSlateAction, type ExpectedSlateTriggerGroup, type SlatesRuntimeContext, type SlatesTestClient, connectSlateTriggerGroupGateway, createLocalSlateTestClient, createSlatesTestClient, describeMcpCompatibleToolSchemas, expectMcpCompatibleToolSchema, expectSlateContract, expectSlateError, expectToolCall, getMcpCompatibleToolSchemaCases, getSlateContract, getVitestExpect, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerGroupEvents, processSlateTriggerGroupWebhook, receiveSlateTriggerGroupGatewayFrames, registerSlateTriggerGroupWebhook, unregisterSlateTriggerGroupWebhook, withSlateProfile };
|
|
1028
|
+
export { type ExpectedSlateAction, type ExpectedSlateTriggerGroup, type SlatesRuntimeContext, type SlatesTestClient, authenticateSlateTriggerGroupWebhookDelivery, connectSlateTriggerGroupGateway, createLocalSlateTestClient, createSlatesTestClient, describeMcpCompatibleToolSchemas, expandSlateTriggerGroupWebhook, expectMcpCompatibleToolSchema, expectSlateContract, expectSlateError, expectToolCall, getMcpCompatibleToolSchemaCases, getSlateContract, getVitestExpect, listSlateOptionListOptions, listSlateTriggerGroupSelectionOptions, loadSlatesProfile, loadSlatesRuntimeContext, mapSlateTriggerEvent, pollSlateTriggerGroupEvents, processSlateTriggerGroupWebhook, receiveSlateTriggerGroupGatewayFrames, registerSlateTriggerGroupWebhook, renewSlateTriggerGroupWebhook, unregisterSlateTriggerGroupWebhook, withSlateProfile };
|
package/dist/index.module.js
CHANGED
|
@@ -223,19 +223,36 @@ var expectSlateContract = async (d) => {
|
|
|
223
223
|
}
|
|
224
224
|
return contract;
|
|
225
225
|
};
|
|
226
|
-
var registerSlateTriggerGroupWebhook = async (d) =>
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
226
|
+
var registerSlateTriggerGroupWebhook = async (d) => {
|
|
227
|
+
let { client, ...input } = d;
|
|
228
|
+
return client.registerTriggerGroupWebhook(input);
|
|
229
|
+
};
|
|
230
|
+
var renewSlateTriggerGroupWebhook = async (d) => {
|
|
231
|
+
let { client, ...input } = d;
|
|
232
|
+
return client.renewTriggerGroupWebhook(input);
|
|
233
|
+
};
|
|
234
|
+
var expandSlateTriggerGroupWebhook = async (d) => {
|
|
235
|
+
let { client, ...input } = d;
|
|
236
|
+
return client.expandTriggerGroupWebhook(input);
|
|
237
|
+
};
|
|
232
238
|
var pollSlateTriggerGroupEvents = async (d) => {
|
|
233
239
|
d.client.ensureSession();
|
|
234
240
|
return d.client.pollTriggerGroup({
|
|
235
241
|
triggerGroupId: d.triggerGroupId,
|
|
236
|
-
state: d.state ?? null
|
|
242
|
+
state: d.state ?? null,
|
|
243
|
+
selection: d.selection
|
|
237
244
|
});
|
|
238
245
|
};
|
|
246
|
+
var listSlateTriggerGroupSelectionOptions = async (d) => {
|
|
247
|
+
let { client, ...input } = d;
|
|
248
|
+
client.ensureSession();
|
|
249
|
+
return client.listTriggerGroupSelectionOptions(input);
|
|
250
|
+
};
|
|
251
|
+
var listSlateOptionListOptions = async (d) => {
|
|
252
|
+
let { client, ...input } = d;
|
|
253
|
+
client.ensureSession();
|
|
254
|
+
return client.listOptionListOptions(input);
|
|
255
|
+
};
|
|
239
256
|
var connectSlateTriggerGroupGateway = async (d) => {
|
|
240
257
|
d.client.ensureSession();
|
|
241
258
|
return d.client.connectTriggerGroupGateway({
|
|
@@ -260,6 +277,14 @@ var processSlateTriggerGroupWebhook = async (d) => d.client.processTriggerGroupW
|
|
|
260
277
|
body: d.body,
|
|
261
278
|
webhookRegistrationPayload: d.webhookRegistrationPayload ?? null
|
|
262
279
|
});
|
|
280
|
+
var authenticateSlateTriggerGroupWebhookDelivery = async (d) => d.client.authenticateTriggerGroupWebhookDelivery({
|
|
281
|
+
triggerGroupId: d.triggerGroupId,
|
|
282
|
+
url: d.url,
|
|
283
|
+
method: d.method ?? "POST",
|
|
284
|
+
headers: d.headers,
|
|
285
|
+
body: d.body,
|
|
286
|
+
deliveryConfig: d.deliveryConfig
|
|
287
|
+
});
|
|
263
288
|
var unregisterSlateTriggerGroupWebhook = async (d) => d.client.unregisterTriggerGroupWebhook({
|
|
264
289
|
triggerGroupId: d.triggerGroupId,
|
|
265
290
|
webhookRegistrationIdentifier: d.webhookRegistrationIdentifier,
|
|
@@ -14852,10 +14877,12 @@ var describeMcpCompatibleToolSchemas = (name, source) => {
|
|
|
14852
14877
|
});
|
|
14853
14878
|
};
|
|
14854
14879
|
export {
|
|
14880
|
+
authenticateSlateTriggerGroupWebhookDelivery,
|
|
14855
14881
|
connectSlateTriggerGroupGateway,
|
|
14856
14882
|
createLocalSlateTestClient,
|
|
14857
14883
|
createSlatesTestClient,
|
|
14858
14884
|
describeMcpCompatibleToolSchemas,
|
|
14885
|
+
expandSlateTriggerGroupWebhook,
|
|
14859
14886
|
expectMcpCompatibleToolSchema,
|
|
14860
14887
|
expectSlateContract,
|
|
14861
14888
|
expectSlateError,
|
|
@@ -14863,6 +14890,8 @@ export {
|
|
|
14863
14890
|
getMcpCompatibleToolSchemaCases,
|
|
14864
14891
|
getSlateContract,
|
|
14865
14892
|
getVitestExpect,
|
|
14893
|
+
listSlateOptionListOptions,
|
|
14894
|
+
listSlateTriggerGroupSelectionOptions,
|
|
14866
14895
|
loadSlatesProfile,
|
|
14867
14896
|
loadSlatesRuntimeContext,
|
|
14868
14897
|
mapSlateTriggerEvent,
|
|
@@ -14870,6 +14899,7 @@ export {
|
|
|
14870
14899
|
processSlateTriggerGroupWebhook,
|
|
14871
14900
|
receiveSlateTriggerGroupGatewayFrames,
|
|
14872
14901
|
registerSlateTriggerGroupWebhook,
|
|
14902
|
+
renewSlateTriggerGroupWebhook,
|
|
14873
14903
|
unregisterSlateTriggerGroupWebhook,
|
|
14874
14904
|
withSlateProfile
|
|
14875
14905
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/test",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.29",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@lowerdeck/testing-tools": "latest",
|
|
43
|
-
"@slates/client": "1.0.0-rc.
|
|
44
|
-
"@slates/profiles": "1.0.0-rc.
|
|
43
|
+
"@slates/client": "1.0.0-rc.34",
|
|
44
|
+
"@slates/profiles": "1.0.0-rc.30"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@slates/provider": "1.0.0-rc.
|
|
47
|
+
"@slates/provider": "1.0.0-rc.35",
|
|
48
48
|
"@slates/tsconfig": "1.0.0-rc.1",
|
|
49
49
|
"typescript": "5.8.2",
|
|
50
50
|
"vitest": "^3.1.2",
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
optionList,
|
|
3
|
+
Slate,
|
|
4
|
+
SlateAuth,
|
|
5
|
+
SlateConfig,
|
|
6
|
+
SlateSpecification,
|
|
7
|
+
triggerGroup
|
|
8
|
+
} from '@slates/provider';
|
|
9
|
+
import { describe, expect, it } from 'vitest';
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
import {
|
|
12
|
+
createLocalSlateTestClient,
|
|
13
|
+
listSlateOptionListOptions,
|
|
14
|
+
listSlateTriggerGroupSelectionOptions
|
|
15
|
+
} from './index';
|
|
16
|
+
|
|
17
|
+
let fixture = () => {
|
|
18
|
+
let calls: { auth: unknown; config: unknown; input: any }[] = [];
|
|
19
|
+
let auth = SlateAuth.create<{ token: string }>()
|
|
20
|
+
.output(z.object({ token: z.string() }))
|
|
21
|
+
.addTokenAuth({
|
|
22
|
+
type: 'auth.token',
|
|
23
|
+
key: 'token',
|
|
24
|
+
name: 'Token',
|
|
25
|
+
inputSchema: z.object({ token: z.string() }),
|
|
26
|
+
getOutput: async ctx => ({ output: ctx.input })
|
|
27
|
+
});
|
|
28
|
+
let spec = SlateSpecification.create({
|
|
29
|
+
key: 'files',
|
|
30
|
+
name: 'Files',
|
|
31
|
+
description: 'Option list contract',
|
|
32
|
+
auth,
|
|
33
|
+
config: SlateConfig.create(z.object({ tenant: z.string() }))
|
|
34
|
+
});
|
|
35
|
+
let files = optionList(spec, {
|
|
36
|
+
key: 'files',
|
|
37
|
+
paramsSchema: z.object({
|
|
38
|
+
kind: z.enum(['sheet', 'doc']),
|
|
39
|
+
limit: z.number().int().default(10)
|
|
40
|
+
}),
|
|
41
|
+
list: async ctx => {
|
|
42
|
+
calls.push({ auth: ctx.auth, config: ctx.config, input: ctx.input });
|
|
43
|
+
return {
|
|
44
|
+
options: [
|
|
45
|
+
{
|
|
46
|
+
value: `${ctx.input.params.kind}-1`,
|
|
47
|
+
label: `${ctx.auth.token} ${ctx.config.tenant}`
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
nextPageToken: ctx.input.pageToken ? undefined : { offset: 1 }
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
let folders = optionList(spec, {
|
|
55
|
+
key: 'folders',
|
|
56
|
+
list: async ctx => {
|
|
57
|
+
calls.push({ auth: ctx.auth, config: ctx.config, input: ctx.input });
|
|
58
|
+
return { options: [] };
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
let watch = triggerGroup(spec, {
|
|
62
|
+
key: 'watch',
|
|
63
|
+
name: 'Watch',
|
|
64
|
+
selectionSchema: z.object({ fileId: z.string(), folderId: z.string() })
|
|
65
|
+
})
|
|
66
|
+
.polling({ pollEvents: async () => ({ events: [] }) })
|
|
67
|
+
.routingMatchers(async () => [])
|
|
68
|
+
.selectionOptions({
|
|
69
|
+
fileId: {
|
|
70
|
+
list: async () => ({ options: [{ value: 'own', label: 'Own' }] }),
|
|
71
|
+
linked: { slate: 'acme/drive', optionList: 'files', params: { kind: 'sheet' } }
|
|
72
|
+
},
|
|
73
|
+
folderId: { linked: { slate: 'acme/drive', optionList: 'folders' } }
|
|
74
|
+
})
|
|
75
|
+
.build();
|
|
76
|
+
let slate = Slate.create({
|
|
77
|
+
spec,
|
|
78
|
+
tools: [],
|
|
79
|
+
triggers: [],
|
|
80
|
+
triggerGroups: [watch],
|
|
81
|
+
optionLists: [files, folders]
|
|
82
|
+
});
|
|
83
|
+
let client = createLocalSlateTestClient({
|
|
84
|
+
slate,
|
|
85
|
+
state: {
|
|
86
|
+
config: { tenant: 'tenant' },
|
|
87
|
+
auth: { authenticationMethodId: 'token', output: { token: 'credential' } }
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return { client, calls };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
describe('option list protocol helpers', () => {
|
|
95
|
+
it('lists an exported option list with parsed params, auth and config', async () => {
|
|
96
|
+
let { client, calls } = fixture();
|
|
97
|
+
|
|
98
|
+
let first = await listSlateOptionListOptions({
|
|
99
|
+
client,
|
|
100
|
+
optionListId: 'files',
|
|
101
|
+
query: ' budget ',
|
|
102
|
+
params: { kind: 'sheet' }
|
|
103
|
+
});
|
|
104
|
+
expect(first).toEqual({
|
|
105
|
+
options: [{ value: 'sheet-1', label: 'credential tenant' }],
|
|
106
|
+
nextPageToken: { offset: 1 }
|
|
107
|
+
});
|
|
108
|
+
expect(calls.at(-1)).toEqual({
|
|
109
|
+
auth: { token: 'credential' },
|
|
110
|
+
config: { tenant: 'tenant' },
|
|
111
|
+
input: { query: 'budget', pageToken: null, params: { kind: 'sheet', limit: 10 } }
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
let last = await listSlateOptionListOptions({
|
|
115
|
+
client,
|
|
116
|
+
optionListId: 'files',
|
|
117
|
+
query: ' ',
|
|
118
|
+
pageToken: { offset: 1 },
|
|
119
|
+
params: { kind: 'doc', limit: 5 }
|
|
120
|
+
});
|
|
121
|
+
expect(last.nextPageToken).toBeNull();
|
|
122
|
+
expect(calls.at(-1)?.input).toEqual({
|
|
123
|
+
query: null,
|
|
124
|
+
pageToken: { offset: 1 },
|
|
125
|
+
params: { kind: 'doc', limit: 5 }
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
await listSlateOptionListOptions({ client, optionListId: 'folders' });
|
|
129
|
+
expect(calls.at(-1)?.input).toEqual({ query: null, pageToken: null, params: {} });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('rejects unknown option lists, invalid params and unknown param keys', async () => {
|
|
133
|
+
let { client, calls } = fixture();
|
|
134
|
+
|
|
135
|
+
await expect(
|
|
136
|
+
listSlateOptionListOptions({ client, optionListId: 'missing' })
|
|
137
|
+
).rejects.toThrow('Invalid option list ID: missing');
|
|
138
|
+
await expect(
|
|
139
|
+
listSlateOptionListOptions({ client, optionListId: 'files', params: { kind: 'pdf' } })
|
|
140
|
+
).rejects.toThrow('Invalid params for option list "files"');
|
|
141
|
+
await expect(
|
|
142
|
+
listSlateOptionListOptions({ client, optionListId: 'files' })
|
|
143
|
+
).rejects.toThrow('Invalid params for option list "files"');
|
|
144
|
+
await expect(
|
|
145
|
+
listSlateOptionListOptions({
|
|
146
|
+
client,
|
|
147
|
+
optionListId: 'files',
|
|
148
|
+
params: { kind: 'sheet', mimeType: 'sheet' }
|
|
149
|
+
})
|
|
150
|
+
).rejects.toThrow('Invalid params for option list "files"');
|
|
151
|
+
await expect(
|
|
152
|
+
listSlateOptionListOptions({
|
|
153
|
+
client,
|
|
154
|
+
optionListId: 'folders',
|
|
155
|
+
params: { kind: 'sheet' }
|
|
156
|
+
})
|
|
157
|
+
).rejects.toThrow('Invalid params for option list "folders"');
|
|
158
|
+
expect(calls).toEqual([]);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('advertises linked sources and only lists fields with their own list', async () => {
|
|
162
|
+
let { client } = fixture();
|
|
163
|
+
let schema = (await client.getTriggerGroup('watch')).triggerGroup.selectionSchema;
|
|
164
|
+
|
|
165
|
+
expect(schema?.properties.fileId).toMatchObject({
|
|
166
|
+
'x-slates-options': true,
|
|
167
|
+
'x-slates-options-linked': {
|
|
168
|
+
slate: 'acme/drive',
|
|
169
|
+
optionList: 'files',
|
|
170
|
+
params: { kind: 'sheet' }
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
expect(schema?.properties.folderId).not.toHaveProperty('x-slates-options');
|
|
174
|
+
expect(schema?.properties.folderId['x-slates-options-linked']).toEqual({
|
|
175
|
+
slate: 'acme/drive',
|
|
176
|
+
optionList: 'folders',
|
|
177
|
+
params: {}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
let own = await listSlateTriggerGroupSelectionOptions({
|
|
181
|
+
client,
|
|
182
|
+
triggerGroupId: 'watch',
|
|
183
|
+
field: 'fileId'
|
|
184
|
+
});
|
|
185
|
+
expect(own.options).toEqual([{ value: 'own', label: 'Own' }]);
|
|
186
|
+
await expect(
|
|
187
|
+
listSlateTriggerGroupSelectionOptions({
|
|
188
|
+
client,
|
|
189
|
+
triggerGroupId: 'watch',
|
|
190
|
+
field: 'folderId'
|
|
191
|
+
})
|
|
192
|
+
).rejects.toThrow('has no options for selection field: folderId');
|
|
193
|
+
});
|
|
194
|
+
});
|