@slates/provider-handler 1.0.0-rc.7 → 1.0.0-rc.9
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 +50 -3
- package/dist/index.module.js +50 -3
- package/package.json +3 -3
- package/src/index.ts +72 -2
- package/src/spec.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -94,7 +94,8 @@ var mapAuthMethod = (slate, m) => ({
|
|
|
94
94
|
scopes: "scopes" in m ? m.scopes.map((s) => ({
|
|
95
95
|
id: s.scope,
|
|
96
96
|
title: s.title,
|
|
97
|
-
description: s.description
|
|
97
|
+
description: s.description,
|
|
98
|
+
defaultChecked: s.defaultChecked
|
|
98
99
|
})) : void 0,
|
|
99
100
|
inputSchema: toJsonSchema(m.inputSchema ?? import_zod.default.object({})),
|
|
100
101
|
outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
|
|
@@ -182,6 +183,47 @@ var State = class {
|
|
|
182
183
|
// src/index.ts
|
|
183
184
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
184
185
|
var getObjectKeyCount = (value) => isRecord(value) ? Object.keys(value).length : void 0;
|
|
186
|
+
var DOWNLOAD_ATTACHMENT_URL_KEYS = /* @__PURE__ */ new Set([
|
|
187
|
+
"downloadUrl",
|
|
188
|
+
"fileUrl",
|
|
189
|
+
"temporaryDownloadUrl",
|
|
190
|
+
"webContentLink"
|
|
191
|
+
]);
|
|
192
|
+
var isAttachmentUrl = (value) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
193
|
+
var collectOutputUrlAttachments = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
194
|
+
if (Array.isArray(value)) {
|
|
195
|
+
return value.flatMap((item) => collectOutputUrlAttachments(item, seen));
|
|
196
|
+
}
|
|
197
|
+
if (!isRecord(value)) {
|
|
198
|
+
return [];
|
|
199
|
+
}
|
|
200
|
+
let attachments = [];
|
|
201
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
202
|
+
if (DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) && typeof nestedValue === "string" && nestedValue.length > 0 && isAttachmentUrl(nestedValue) && !seen.has(nestedValue)) {
|
|
203
|
+
seen.add(nestedValue);
|
|
204
|
+
attachments.push({
|
|
205
|
+
content: {
|
|
206
|
+
type: "url",
|
|
207
|
+
url: nestedValue
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
213
|
+
}
|
|
214
|
+
return attachments;
|
|
215
|
+
};
|
|
216
|
+
var mergeAttachments = (explicitAttachments, output) => {
|
|
217
|
+
let attachments = [...explicitAttachments ?? []];
|
|
218
|
+
let seen = new Set(attachments.map((attachment) => JSON.stringify(attachment)));
|
|
219
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
220
|
+
let key = JSON.stringify(attachment);
|
|
221
|
+
if (seen.has(key)) continue;
|
|
222
|
+
seen.add(key);
|
|
223
|
+
attachments.push(attachment);
|
|
224
|
+
}
|
|
225
|
+
return attachments.length > 0 ? attachments : void 0;
|
|
226
|
+
};
|
|
185
227
|
var toErrorMetadata = (error) => {
|
|
186
228
|
if (error instanceof Error) {
|
|
187
229
|
return {
|
|
@@ -735,12 +777,17 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
735
777
|
onSuccess: (result) => ({
|
|
736
778
|
hasMessage: !!result.message,
|
|
737
779
|
actionResultMessage: result.message,
|
|
738
|
-
outputKeyCount: getObjectKeyCount(result.output)
|
|
780
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
781
|
+
attachmentCount: result.attachments?.length
|
|
739
782
|
})
|
|
740
783
|
},
|
|
741
784
|
() => (0, import_provider2.runWithContext)(context, () => action.handleInvocation(context))
|
|
742
785
|
);
|
|
743
|
-
return withRequestTraces(context, {
|
|
786
|
+
return withRequestTraces(context, {
|
|
787
|
+
output: res.output,
|
|
788
|
+
message: res.message,
|
|
789
|
+
attachments: mergeAttachments(res.attachments, res.output)
|
|
790
|
+
});
|
|
744
791
|
});
|
|
745
792
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
746
793
|
let ctx = getContextFull();
|
package/dist/index.module.js
CHANGED
|
@@ -67,7 +67,8 @@ var mapAuthMethod = (slate, m) => ({
|
|
|
67
67
|
scopes: "scopes" in m ? m.scopes.map((s) => ({
|
|
68
68
|
id: s.scope,
|
|
69
69
|
title: s.title,
|
|
70
|
-
description: s.description
|
|
70
|
+
description: s.description,
|
|
71
|
+
defaultChecked: s.defaultChecked
|
|
71
72
|
})) : void 0,
|
|
72
73
|
inputSchema: toJsonSchema(m.inputSchema ?? z.object({})),
|
|
73
74
|
outputSchema: toJsonSchema(slate.spec.auth.outputSchema),
|
|
@@ -155,6 +156,47 @@ var State = class {
|
|
|
155
156
|
// src/index.ts
|
|
156
157
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
157
158
|
var getObjectKeyCount = (value) => isRecord(value) ? Object.keys(value).length : void 0;
|
|
159
|
+
var DOWNLOAD_ATTACHMENT_URL_KEYS = /* @__PURE__ */ new Set([
|
|
160
|
+
"downloadUrl",
|
|
161
|
+
"fileUrl",
|
|
162
|
+
"temporaryDownloadUrl",
|
|
163
|
+
"webContentLink"
|
|
164
|
+
]);
|
|
165
|
+
var isAttachmentUrl = (value) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
166
|
+
var collectOutputUrlAttachments = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
167
|
+
if (Array.isArray(value)) {
|
|
168
|
+
return value.flatMap((item) => collectOutputUrlAttachments(item, seen));
|
|
169
|
+
}
|
|
170
|
+
if (!isRecord(value)) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
let attachments = [];
|
|
174
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
175
|
+
if (DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) && typeof nestedValue === "string" && nestedValue.length > 0 && isAttachmentUrl(nestedValue) && !seen.has(nestedValue)) {
|
|
176
|
+
seen.add(nestedValue);
|
|
177
|
+
attachments.push({
|
|
178
|
+
content: {
|
|
179
|
+
type: "url",
|
|
180
|
+
url: nestedValue
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
186
|
+
}
|
|
187
|
+
return attachments;
|
|
188
|
+
};
|
|
189
|
+
var mergeAttachments = (explicitAttachments, output) => {
|
|
190
|
+
let attachments = [...explicitAttachments ?? []];
|
|
191
|
+
let seen = new Set(attachments.map((attachment) => JSON.stringify(attachment)));
|
|
192
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
193
|
+
let key = JSON.stringify(attachment);
|
|
194
|
+
if (seen.has(key)) continue;
|
|
195
|
+
seen.add(key);
|
|
196
|
+
attachments.push(attachment);
|
|
197
|
+
}
|
|
198
|
+
return attachments.length > 0 ? attachments : void 0;
|
|
199
|
+
};
|
|
158
200
|
var toErrorMetadata = (error) => {
|
|
159
201
|
if (error instanceof Error) {
|
|
160
202
|
return {
|
|
@@ -708,12 +750,17 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
708
750
|
onSuccess: (result) => ({
|
|
709
751
|
hasMessage: !!result.message,
|
|
710
752
|
actionResultMessage: result.message,
|
|
711
|
-
outputKeyCount: getObjectKeyCount(result.output)
|
|
753
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
754
|
+
attachmentCount: result.attachments?.length
|
|
712
755
|
})
|
|
713
756
|
},
|
|
714
757
|
() => runWithContext(context, () => action.handleInvocation(context))
|
|
715
758
|
);
|
|
716
|
-
return withRequestTraces(context, {
|
|
759
|
+
return withRequestTraces(context, {
|
|
760
|
+
output: res.output,
|
|
761
|
+
message: res.message,
|
|
762
|
+
attachments: mergeAttachments(res.attachments, res.output)
|
|
763
|
+
});
|
|
717
764
|
});
|
|
718
765
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
719
766
|
let ctx = getContextFull();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slates/provider-handler",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@lowerdeck/error": "^1.1.0",
|
|
35
|
-
"@slates/proto": "1.0.0-rc.
|
|
36
|
-
"@slates/provider": "1.0.0-rc.
|
|
35
|
+
"@slates/proto": "1.0.0-rc.8",
|
|
36
|
+
"@slates/provider": "1.0.0-rc.10",
|
|
37
37
|
"zod": "^4.2.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
runWithContext,
|
|
9
9
|
type Slate,
|
|
10
|
+
type SlateAttachment,
|
|
10
11
|
SlateContext,
|
|
11
12
|
SlateLogger,
|
|
12
13
|
type SlateLogListener
|
|
@@ -21,6 +22,70 @@ let isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
|
21
22
|
let getObjectKeyCount = (value: unknown) =>
|
|
22
23
|
isRecord(value) ? Object.keys(value).length : undefined;
|
|
23
24
|
|
|
25
|
+
let DOWNLOAD_ATTACHMENT_URL_KEYS = new Set([
|
|
26
|
+
'downloadUrl',
|
|
27
|
+
'fileUrl',
|
|
28
|
+
'temporaryDownloadUrl',
|
|
29
|
+
'webContentLink'
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
let isAttachmentUrl = (value: string) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
33
|
+
|
|
34
|
+
let collectOutputUrlAttachments = (
|
|
35
|
+
value: unknown,
|
|
36
|
+
seen = new Set<string>()
|
|
37
|
+
): SlateAttachment[] => {
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
return value.flatMap(item => collectOutputUrlAttachments(item, seen));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!isRecord(value)) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let attachments: SlateAttachment[] = [];
|
|
47
|
+
|
|
48
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
49
|
+
if (
|
|
50
|
+
DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) &&
|
|
51
|
+
typeof nestedValue === 'string' &&
|
|
52
|
+
nestedValue.length > 0 &&
|
|
53
|
+
isAttachmentUrl(nestedValue) &&
|
|
54
|
+
!seen.has(nestedValue)
|
|
55
|
+
) {
|
|
56
|
+
seen.add(nestedValue);
|
|
57
|
+
attachments.push({
|
|
58
|
+
content: {
|
|
59
|
+
type: 'url',
|
|
60
|
+
url: nestedValue
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return attachments;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
let mergeAttachments = (
|
|
73
|
+
explicitAttachments: SlateAttachment[] | undefined,
|
|
74
|
+
output: unknown
|
|
75
|
+
): SlateAttachment[] | undefined => {
|
|
76
|
+
let attachments = [...(explicitAttachments ?? [])];
|
|
77
|
+
let seen = new Set(attachments.map(attachment => JSON.stringify(attachment)));
|
|
78
|
+
|
|
79
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
80
|
+
let key = JSON.stringify(attachment);
|
|
81
|
+
if (seen.has(key)) continue;
|
|
82
|
+
seen.add(key);
|
|
83
|
+
attachments.push(attachment);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return attachments.length > 0 ? attachments : undefined;
|
|
87
|
+
};
|
|
88
|
+
|
|
24
89
|
let toErrorMetadata = (error: unknown) => {
|
|
25
90
|
if (error instanceof Error) {
|
|
26
91
|
return {
|
|
@@ -684,13 +749,18 @@ export let createProviderHandler = <ConfigType extends {}, AuthType extends {}>(
|
|
|
684
749
|
onSuccess: result => ({
|
|
685
750
|
hasMessage: !!result.message,
|
|
686
751
|
actionResultMessage: result.message,
|
|
687
|
-
outputKeyCount: getObjectKeyCount(result.output)
|
|
752
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
753
|
+
attachmentCount: result.attachments?.length
|
|
688
754
|
})
|
|
689
755
|
},
|
|
690
756
|
() => runWithContext(context, () => action.handleInvocation(context))
|
|
691
757
|
);
|
|
692
758
|
|
|
693
|
-
return withRequestTraces(context, {
|
|
759
|
+
return withRequestTraces(context, {
|
|
760
|
+
output: res.output,
|
|
761
|
+
message: res.message,
|
|
762
|
+
attachments: mergeAttachments(res.attachments, res.output)
|
|
763
|
+
});
|
|
694
764
|
});
|
|
695
765
|
|
|
696
766
|
manager.onRequest('slates/action.trigger.map_event', async ({ params }) => {
|
package/src/spec.ts
CHANGED