@slates/provider-handler 1.0.0-rc.7 → 1.0.0-rc.8
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 +48 -2
- package/dist/index.module.js +48 -2
- package/package.json +3 -3
- package/src/index.ts +72 -2
package/dist/index.cjs
CHANGED
|
@@ -182,6 +182,47 @@ var State = class {
|
|
|
182
182
|
// src/index.ts
|
|
183
183
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
184
184
|
var getObjectKeyCount = (value) => isRecord(value) ? Object.keys(value).length : void 0;
|
|
185
|
+
var DOWNLOAD_ATTACHMENT_URL_KEYS = /* @__PURE__ */ new Set([
|
|
186
|
+
"downloadUrl",
|
|
187
|
+
"fileUrl",
|
|
188
|
+
"temporaryDownloadUrl",
|
|
189
|
+
"webContentLink"
|
|
190
|
+
]);
|
|
191
|
+
var isAttachmentUrl = (value) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
192
|
+
var collectOutputUrlAttachments = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
193
|
+
if (Array.isArray(value)) {
|
|
194
|
+
return value.flatMap((item) => collectOutputUrlAttachments(item, seen));
|
|
195
|
+
}
|
|
196
|
+
if (!isRecord(value)) {
|
|
197
|
+
return [];
|
|
198
|
+
}
|
|
199
|
+
let attachments = [];
|
|
200
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
201
|
+
if (DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) && typeof nestedValue === "string" && nestedValue.length > 0 && isAttachmentUrl(nestedValue) && !seen.has(nestedValue)) {
|
|
202
|
+
seen.add(nestedValue);
|
|
203
|
+
attachments.push({
|
|
204
|
+
content: {
|
|
205
|
+
type: "url",
|
|
206
|
+
url: nestedValue
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
212
|
+
}
|
|
213
|
+
return attachments;
|
|
214
|
+
};
|
|
215
|
+
var mergeAttachments = (explicitAttachments, output) => {
|
|
216
|
+
let attachments = [...explicitAttachments ?? []];
|
|
217
|
+
let seen = new Set(attachments.map((attachment) => JSON.stringify(attachment)));
|
|
218
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
219
|
+
let key = JSON.stringify(attachment);
|
|
220
|
+
if (seen.has(key)) continue;
|
|
221
|
+
seen.add(key);
|
|
222
|
+
attachments.push(attachment);
|
|
223
|
+
}
|
|
224
|
+
return attachments.length > 0 ? attachments : void 0;
|
|
225
|
+
};
|
|
185
226
|
var toErrorMetadata = (error) => {
|
|
186
227
|
if (error instanceof Error) {
|
|
187
228
|
return {
|
|
@@ -735,12 +776,17 @@ var createProviderHandler = (slate, listeners) => (0, import_proto.createSlatesP
|
|
|
735
776
|
onSuccess: (result) => ({
|
|
736
777
|
hasMessage: !!result.message,
|
|
737
778
|
actionResultMessage: result.message,
|
|
738
|
-
outputKeyCount: getObjectKeyCount(result.output)
|
|
779
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
780
|
+
attachmentCount: result.attachments?.length
|
|
739
781
|
})
|
|
740
782
|
},
|
|
741
783
|
() => (0, import_provider2.runWithContext)(context, () => action.handleInvocation(context))
|
|
742
784
|
);
|
|
743
|
-
return withRequestTraces(context, {
|
|
785
|
+
return withRequestTraces(context, {
|
|
786
|
+
output: res.output,
|
|
787
|
+
message: res.message,
|
|
788
|
+
attachments: mergeAttachments(res.attachments, res.output)
|
|
789
|
+
});
|
|
744
790
|
});
|
|
745
791
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
746
792
|
let ctx = getContextFull();
|
package/dist/index.module.js
CHANGED
|
@@ -155,6 +155,47 @@ var State = class {
|
|
|
155
155
|
// src/index.ts
|
|
156
156
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
157
157
|
var getObjectKeyCount = (value) => isRecord(value) ? Object.keys(value).length : void 0;
|
|
158
|
+
var DOWNLOAD_ATTACHMENT_URL_KEYS = /* @__PURE__ */ new Set([
|
|
159
|
+
"downloadUrl",
|
|
160
|
+
"fileUrl",
|
|
161
|
+
"temporaryDownloadUrl",
|
|
162
|
+
"webContentLink"
|
|
163
|
+
]);
|
|
164
|
+
var isAttachmentUrl = (value) => /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
165
|
+
var collectOutputUrlAttachments = (value, seen = /* @__PURE__ */ new Set()) => {
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
return value.flatMap((item) => collectOutputUrlAttachments(item, seen));
|
|
168
|
+
}
|
|
169
|
+
if (!isRecord(value)) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
let attachments = [];
|
|
173
|
+
for (let [key, nestedValue] of Object.entries(value)) {
|
|
174
|
+
if (DOWNLOAD_ATTACHMENT_URL_KEYS.has(key) && typeof nestedValue === "string" && nestedValue.length > 0 && isAttachmentUrl(nestedValue) && !seen.has(nestedValue)) {
|
|
175
|
+
seen.add(nestedValue);
|
|
176
|
+
attachments.push({
|
|
177
|
+
content: {
|
|
178
|
+
type: "url",
|
|
179
|
+
url: nestedValue
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
attachments.push(...collectOutputUrlAttachments(nestedValue, seen));
|
|
185
|
+
}
|
|
186
|
+
return attachments;
|
|
187
|
+
};
|
|
188
|
+
var mergeAttachments = (explicitAttachments, output) => {
|
|
189
|
+
let attachments = [...explicitAttachments ?? []];
|
|
190
|
+
let seen = new Set(attachments.map((attachment) => JSON.stringify(attachment)));
|
|
191
|
+
for (let attachment of collectOutputUrlAttachments(output)) {
|
|
192
|
+
let key = JSON.stringify(attachment);
|
|
193
|
+
if (seen.has(key)) continue;
|
|
194
|
+
seen.add(key);
|
|
195
|
+
attachments.push(attachment);
|
|
196
|
+
}
|
|
197
|
+
return attachments.length > 0 ? attachments : void 0;
|
|
198
|
+
};
|
|
158
199
|
var toErrorMetadata = (error) => {
|
|
159
200
|
if (error instanceof Error) {
|
|
160
201
|
return {
|
|
@@ -708,12 +749,17 @@ var createProviderHandler = (slate, listeners) => createSlatesProviderProtoHandl
|
|
|
708
749
|
onSuccess: (result) => ({
|
|
709
750
|
hasMessage: !!result.message,
|
|
710
751
|
actionResultMessage: result.message,
|
|
711
|
-
outputKeyCount: getObjectKeyCount(result.output)
|
|
752
|
+
outputKeyCount: getObjectKeyCount(result.output),
|
|
753
|
+
attachmentCount: result.attachments?.length
|
|
712
754
|
})
|
|
713
755
|
},
|
|
714
756
|
() => runWithContext(context, () => action.handleInvocation(context))
|
|
715
757
|
);
|
|
716
|
-
return withRequestTraces(context, {
|
|
758
|
+
return withRequestTraces(context, {
|
|
759
|
+
output: res.output,
|
|
760
|
+
message: res.message,
|
|
761
|
+
attachments: mergeAttachments(res.attachments, res.output)
|
|
762
|
+
});
|
|
717
763
|
});
|
|
718
764
|
manager.onRequest("slates/action.trigger.map_event", async ({ params }) => {
|
|
719
765
|
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.8",
|
|
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.9",
|
|
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 }) => {
|