@deliverd/sdk 0.28.0 → 0.29.0
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/context.d.ts +7 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +11 -3
- package/dist/data-screen.d.ts.map +1 -1
- package/dist/data-screen.js +33 -2
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +4 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/purview-rules.d.ts +63 -0
- package/dist/purview-rules.d.ts.map +1 -0
- package/dist/purview-rules.js +98 -0
- package/dist/purview.d.ts +114 -0
- package/dist/purview.d.ts.map +1 -0
- package/dist/purview.js +124 -0
- package/dist/released.d.ts +1 -1
- package/dist/released.d.ts.map +1 -1
- package/dist/released.js +1458 -0
- package/dist/screen.d.ts +8 -0
- package/dist/screen.d.ts.map +1 -1
- package/dist/screen.js +2 -0
- package/dist/types.d.ts +72 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context.ts +15 -3
- package/src/data-screen.ts +33 -2
- package/src/dev.ts +4 -2
- package/src/index.ts +1 -0
- package/src/purview-rules.ts +117 -0
- package/src/purview.ts +182 -0
- package/src/released.ts +1459 -0
- package/src/screen.ts +10 -0
- package/src/types.ts +72 -2
package/dist/purview.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { purviewOutcomeFromResponse, purviewUnavailable, } from "./purview-rules.js";
|
|
2
|
+
const GRAPH = "https://graph.microsoft.com/v1.0";
|
|
3
|
+
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4
|
+
function uuid() {
|
|
5
|
+
const c = globalThis.crypto;
|
|
6
|
+
if (c?.randomUUID)
|
|
7
|
+
return c.randomUUID();
|
|
8
|
+
return "xxxxxxxx-xxxx-4xxx-8xxx-xxxxxxxxxxxx".replace(/x/g, () => Math.floor(Math.random() * 16).toString(16));
|
|
9
|
+
}
|
|
10
|
+
/** The body `processContent` takes for a prompt about to be sent to a model. */
|
|
11
|
+
export function processContentBody(text, options, sequenceNumber = 0) {
|
|
12
|
+
const now = new Date().toISOString();
|
|
13
|
+
return {
|
|
14
|
+
contentToProcess: {
|
|
15
|
+
contentEntries: [
|
|
16
|
+
{
|
|
17
|
+
"@odata.type": "microsoft.graph.processConversationMetadata",
|
|
18
|
+
identifier: uuid(),
|
|
19
|
+
content: { "@odata.type": "microsoft.graph.textContent", data: text },
|
|
20
|
+
name: `${options.app.name} prompt`,
|
|
21
|
+
correlationId: options.correlationId ?? uuid(),
|
|
22
|
+
sequenceNumber,
|
|
23
|
+
isTruncated: false,
|
|
24
|
+
createdDateTime: now,
|
|
25
|
+
modifiedDateTime: now,
|
|
26
|
+
...(options.agent
|
|
27
|
+
? {
|
|
28
|
+
agents: [
|
|
29
|
+
{
|
|
30
|
+
"@odata.type": "microsoft.graph.aiAgentInfo",
|
|
31
|
+
identifier: options.agent.id,
|
|
32
|
+
name: options.agent.name,
|
|
33
|
+
...(options.agent.version ? { version: options.agent.version } : {}),
|
|
34
|
+
...(options.agent.blueprintId ? { blueprintId: options.agent.blueprintId } : {}),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
}
|
|
38
|
+
: {}),
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
activityMetadata: { activity: "uploadText" },
|
|
42
|
+
deviceMetadata: {},
|
|
43
|
+
protectedAppMetadata: {
|
|
44
|
+
name: options.app.name,
|
|
45
|
+
version: options.app.version ?? "1.0",
|
|
46
|
+
applicationLocation: { "@odata.type": "microsoft.graph.policyLocationApplication", value: options.app.entraAppId },
|
|
47
|
+
},
|
|
48
|
+
integratedAppMetadata: { name: options.app.name, version: options.app.version ?? "1.0" },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A Microsoft Graph token for an app acting as itself (client credentials),
|
|
54
|
+
* for `purviewCheck`'s `token` where there is no signed-in user: a pipeline,
|
|
55
|
+
* a local MCP server, a back-end agent. Cached until five minutes before it
|
|
56
|
+
* expires. Use it with `userId`, the person the text is about or on behalf of.
|
|
57
|
+
*/
|
|
58
|
+
export function entraAppToken(options) {
|
|
59
|
+
if (!GUID.test(options.tenantId))
|
|
60
|
+
throw new Error("entraAppToken: tenantId is your Entra tenant id, a GUID.");
|
|
61
|
+
const doFetch = options.fetch ?? fetch;
|
|
62
|
+
let cached = null;
|
|
63
|
+
return async () => {
|
|
64
|
+
if (cached && Date.now() < cached.until)
|
|
65
|
+
return cached.token;
|
|
66
|
+
const res = await doFetch(`https://login.microsoftonline.com/${options.tenantId}/oauth2/v2.0/token`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
69
|
+
body: new URLSearchParams({
|
|
70
|
+
grant_type: "client_credentials",
|
|
71
|
+
client_id: options.clientId,
|
|
72
|
+
client_secret: options.clientSecret,
|
|
73
|
+
scope: "https://graph.microsoft.com/.default",
|
|
74
|
+
}).toString(),
|
|
75
|
+
signal: AbortSignal.timeout(10_000),
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok)
|
|
78
|
+
throw new Error(`Entra refused the token request (${res.status}).`);
|
|
79
|
+
const body = (await res.json());
|
|
80
|
+
if (!body.access_token)
|
|
81
|
+
throw new Error("Entra returned no access token.");
|
|
82
|
+
cached = { token: body.access_token, until: Date.now() + Math.max(0, (body.expires_in ?? 3600) - 300) * 1000 };
|
|
83
|
+
return cached.token;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function purviewCheck(options) {
|
|
87
|
+
if (!GUID.test(options.app.entraAppId))
|
|
88
|
+
throw new Error("purviewCheck: app.entraAppId is your Entra app's application (client) id, a GUID.");
|
|
89
|
+
if (options.userId !== undefined && !GUID.test(options.userId))
|
|
90
|
+
throw new Error("purviewCheck: userId is the user's Entra object id, a GUID.");
|
|
91
|
+
const doFetch = options.fetch ?? fetch;
|
|
92
|
+
const url = `${GRAPH}/${options.userId ? `users/${options.userId}` : "me"}/dataSecurityAndGovernance/processContent`;
|
|
93
|
+
const onUnavailable = options.onUnavailable ?? "ask";
|
|
94
|
+
let etag = null;
|
|
95
|
+
let sequence = 0;
|
|
96
|
+
return async (text) => {
|
|
97
|
+
try {
|
|
98
|
+
const token = typeof options.token === "function" ? await options.token() : options.token;
|
|
99
|
+
const res = await doFetch(url, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
headers: {
|
|
102
|
+
Authorization: `Bearer ${token}`,
|
|
103
|
+
"Content-Type": "application/json",
|
|
104
|
+
...(etag ? { "If-None-Match": etag } : {}),
|
|
105
|
+
},
|
|
106
|
+
body: JSON.stringify(processContentBody(text, options, sequence++)),
|
|
107
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 10_000),
|
|
108
|
+
});
|
|
109
|
+
if (res.status === 202 || res.status === 204)
|
|
110
|
+
return { restriction: null, actions: 0, scopeModified: false, unavailable: false };
|
|
111
|
+
if (!res.ok)
|
|
112
|
+
return purviewUnavailable(onUnavailable);
|
|
113
|
+
etag = res.headers.get("ETag") ?? etag;
|
|
114
|
+
const outcome = purviewOutcomeFromResponse(await res.json());
|
|
115
|
+
// Purview's policies changed: the next call starts from the new state.
|
|
116
|
+
if (outcome.scopeModified)
|
|
117
|
+
etag = res.headers.get("ETag");
|
|
118
|
+
return outcome;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return purviewUnavailable(onUnavailable);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/released.d.ts
CHANGED
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
* **Add the version here when you publish it, not before.** An entry is a
|
|
44
44
|
* claim that `npm install @deliverd/sdk@x` works today.
|
|
45
45
|
*/
|
|
46
|
-
export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0"];
|
|
46
|
+
export declare const PUBLISHED_TO_NPM: readonly ["0.1.0", "0.2.0", "0.3.0", "0.4.0", "0.5.0", "0.6.0", "0.6.1", "0.6.2", "0.7.0", "0.7.1", "0.8.0", "0.8.1", "0.8.2", "0.9.0", "0.10.0", "0.11.0", "0.11.1", "0.12.0", "0.13.0", "0.14.0", "0.15.0", "0.16.0", "0.17.0", "0.18.0", "0.19.0", "0.20.0", "0.21.0", "0.22.0", "0.23.0", "0.24.0", "0.24.1", "0.25.0", "0.25.1", "0.26.0", "0.27.0", "0.28.0"];
|
|
47
47
|
/**
|
|
48
48
|
* A fingerprint of what each *published* version recorded.
|
|
49
49
|
*
|
package/dist/released.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"released.d.ts","sourceRoot":"","sources":["../src/released.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,gBAAgB,qWAqCnB,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAuGzC,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CA62vBtD,CAAC"}
|