witnora 0.16.0 → 0.17.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.
|
@@ -12,23 +12,21 @@ export async function activateRealPathIntegrations(options) {
|
|
|
12
12
|
throw new Error(`Could not load approved real-path integrations (${response.status}).`);
|
|
13
13
|
const body = await boundedJson(response);
|
|
14
14
|
const approved = Array.isArray(body.integrations) ? body.integrations.map(parsePlan).filter((plan) => plan.status === "READY_TO_ACTIVATE") : [];
|
|
15
|
-
const plans = approved.filter((plan) => plan.generated.providerPackId
|
|
15
|
+
const plans = approved.filter((plan) => ["STRIPE_REFUND", "ZENDESK_TICKET", "SALESFORCE_RECORD", "HUBSPOT_CRM_RECORD", "POSTGRES_RECORD"].includes(plan.generated.providerPackId) && plan.environment === "sandbox" && plan.customerSummary.evaluationMode === "SHADOW");
|
|
16
16
|
if (!plans.length)
|
|
17
17
|
return { state: "NOT_CONFIGURED", created: false, activations: [], generatedFiles: [] };
|
|
18
|
-
const
|
|
19
|
-
if (!secret?.startsWith("sk_test_") || secret.length < 12)
|
|
20
|
-
throw new Error("Stripe test-mode activation requires STRIPE_SECRET_KEY to reference an sk_test_ credential in the customer environment.");
|
|
18
|
+
const environment = options.env ?? process.env;
|
|
21
19
|
const activations = [];
|
|
22
20
|
const scenarios = [];
|
|
23
21
|
for (const plan of plans) {
|
|
24
|
-
const preflight = await
|
|
22
|
+
const preflight = await providerPreflight(request, environment, plan, options.now?.() ?? new Date(), options.postgresClientFactory);
|
|
25
23
|
const acceptance = preflight.acceptance;
|
|
26
24
|
activations.push({ integrationId: plan.id, integrationDigestSha256: plan.digestSha256, taskContractId: plan.taskContractId, taskContractDigestSha256: plan.taskContractDigestSha256, agentId: plan.subject.agentId, agentVersion: plan.subject.agentVersion, environment: plan.environment, providerPackId: plan.generated.providerPackId, providerContractDigestSha256: plan.generated.providerContractDigestSha256, acceptance });
|
|
27
25
|
scenarios.push({ plan, value: [preflight.scenario] });
|
|
28
26
|
}
|
|
29
27
|
const modulePath = join(repository, "witnora.assurance-harness.mjs");
|
|
30
28
|
const manifestPath = join(repository, ".witnora", "gateway", "real-path-activations.json");
|
|
31
|
-
const source =
|
|
29
|
+
const source = generatedProviderHarness(plans);
|
|
32
30
|
const moduleDigestSha256 = sha(source);
|
|
33
31
|
let created = false;
|
|
34
32
|
const generatedFiles = [];
|
|
@@ -65,6 +63,23 @@ export async function activateRealPathIntegrations(options) {
|
|
|
65
63
|
}
|
|
66
64
|
return { state: "READY_TO_START", created, modulePath: "witnora.assurance-harness.mjs", activations, generatedFiles };
|
|
67
65
|
}
|
|
66
|
+
async function providerPreflight(request, env, plan, now, postgresClientFactory) {
|
|
67
|
+
if (plan.generated.providerPackId === "STRIPE_REFUND") {
|
|
68
|
+
const secret = env.STRIPE_SECRET_KEY;
|
|
69
|
+
if (!secret?.startsWith("sk_test_") || secret.length < 12)
|
|
70
|
+
throw new Error("Stripe test-mode activation requires STRIPE_SECRET_KEY to reference an sk_test_ credential in the customer environment.");
|
|
71
|
+
return stripePreflight(request, secret, plan, now);
|
|
72
|
+
}
|
|
73
|
+
if (plan.generated.providerPackId === "ZENDESK_TICKET")
|
|
74
|
+
return zendeskPreflight(request, env, plan, now);
|
|
75
|
+
if (plan.generated.providerPackId === "SALESFORCE_RECORD")
|
|
76
|
+
return salesforcePreflight(request, env, plan, now);
|
|
77
|
+
if (plan.generated.providerPackId === "HUBSPOT_CRM_RECORD")
|
|
78
|
+
return hubspotPreflight(request, env, plan, now);
|
|
79
|
+
if (plan.generated.providerPackId === "POSTGRES_RECORD")
|
|
80
|
+
return postgresPreflight(env, plan, now, postgresClientFactory);
|
|
81
|
+
throw new Error(`${plan.generated.providerPackId} activation is not implemented by this CLI version.`);
|
|
82
|
+
}
|
|
68
83
|
async function stripePreflight(request, secret, plan, now) {
|
|
69
84
|
const response = await request("https://api.stripe.com/v1/refunds?limit=1", { headers: { authorization: `Bearer ${secret}` }, redirect: "error", signal: AbortSignal.timeout(5_000) });
|
|
70
85
|
if (!response.ok)
|
|
@@ -82,9 +97,113 @@ async function stripePreflight(request, secret, plan, now) {
|
|
|
82
97
|
const resultDigest = sha(canonical(observation));
|
|
83
98
|
return { acceptance: { kind: "READ_ONLY_PROVIDER_PREFLIGHT", passedAt: now.toISOString(), productionWrites: 0, observationDigestSha256: resultDigest }, scenario: { id: `stripe:${sha(first.id).slice(0, 16)}`, source: "LIVE_SHADOW", sanitized: true, input: { resourceId: first.id }, inputDigestSha256: sha(canonical({ resourceId: first.id })), baseline: { resultDigestSha256: resultDigest, actionIntents: plan.generated.actionPathBindings.map((item) => ({ pathId: item.actionPathId, parametersDigestSha256: parameterDigest })) } } };
|
|
84
99
|
}
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
100
|
+
async function zendeskPreflight(request, env, plan, now) {
|
|
101
|
+
const token = env.ZENDESK_API_TOKEN;
|
|
102
|
+
if (!token || token.length < 8)
|
|
103
|
+
throw new Error("Zendesk activation requires the read-only ZENDESK_API_TOKEN in the customer environment.");
|
|
104
|
+
const origin = providerOrigin(plan, "Zendesk", ".zendesk.com");
|
|
105
|
+
const response = await request(`${origin}/api/v2/tickets.json?per_page=1&sort_by=updated_at&sort_order=desc`, { method: "GET", headers: { accept: "application/json", authorization: `Bearer ${token}` }, redirect: "error", signal: AbortSignal.timeout(5_000) });
|
|
106
|
+
if (!response.ok)
|
|
107
|
+
throw new Error(`Zendesk read-only preflight failed (${response.status}).`);
|
|
108
|
+
const body = await boundedJson(response);
|
|
109
|
+
const tickets = Array.isArray(body.tickets) ? body.tickets : [];
|
|
110
|
+
const first = record(tickets[0], "Zendesk ticket");
|
|
111
|
+
const id = first.id;
|
|
112
|
+
if (typeof id !== "number" && typeof id !== "string")
|
|
113
|
+
throw new Error("Zendesk preflight requires one existing sandbox ticket.");
|
|
114
|
+
const observation = pick(first, ["status", "priority", "type", "via.channel"]);
|
|
115
|
+
assertCriterion(plan, observation);
|
|
116
|
+
return preflightResult(plan, now, "zendesk", id, observation);
|
|
117
|
+
}
|
|
118
|
+
async function salesforcePreflight(request, env, plan, now) {
|
|
119
|
+
const token = env.SALESFORCE_ACCESS_TOKEN;
|
|
120
|
+
if (!token || token.length < 8)
|
|
121
|
+
throw new Error("Salesforce activation requires the read-only SALESFORCE_ACCESS_TOKEN in the customer environment.");
|
|
122
|
+
const origin = providerOrigin(plan, "Salesforce", ".my.salesforce.com");
|
|
123
|
+
const resourceType = providerIdentifier(plan.generated.providerConfiguration?.resourceType, "Salesforce record type");
|
|
124
|
+
const field = providerIdentifier(plan.generated.criterion.field, "Salesforce criterion field");
|
|
125
|
+
const query = `SELECT Id,${field} FROM ${resourceType} ORDER BY LastModifiedDate DESC LIMIT 1`;
|
|
126
|
+
const response = await request(`${origin}/services/data/v61.0/query?${new URLSearchParams({ q: query })}`, { method: "GET", headers: { accept: "application/json", authorization: `Bearer ${token}` }, redirect: "error", signal: AbortSignal.timeout(5_000) });
|
|
127
|
+
if (!response.ok)
|
|
128
|
+
throw new Error(`Salesforce read-only preflight failed (${response.status}).`);
|
|
129
|
+
const body = await boundedJson(response);
|
|
130
|
+
const records = Array.isArray(body.records) ? body.records : [];
|
|
131
|
+
const first = record(records[0], "Salesforce record");
|
|
132
|
+
const id = first.Id;
|
|
133
|
+
if (typeof id !== "string")
|
|
134
|
+
throw new Error("Salesforce preflight requires one existing sandbox record.");
|
|
135
|
+
const observation = pick(first, [field]);
|
|
136
|
+
assertCriterion(plan, observation);
|
|
137
|
+
return preflightResult(plan, now, "salesforce", id, observation);
|
|
138
|
+
}
|
|
139
|
+
async function hubspotPreflight(request, env, plan, now) {
|
|
140
|
+
const token = env.HUBSPOT_ACCESS_TOKEN;
|
|
141
|
+
if (!token || token.length < 8)
|
|
142
|
+
throw new Error("HubSpot activation requires the read-only HUBSPOT_ACCESS_TOKEN in the customer environment.");
|
|
143
|
+
const resourceType = providerIdentifier(plan.generated.providerConfiguration?.resourceType, "HubSpot record type");
|
|
144
|
+
const field = providerIdentifier(plan.generated.criterion.field, "HubSpot criterion field");
|
|
145
|
+
const url = `https://api.hubapi.com/crm/v3/objects/${encodeURIComponent(resourceType)}?${new URLSearchParams({ limit: "1", properties: field })}`;
|
|
146
|
+
const response = await request(url, { method: "GET", headers: { accept: "application/json", authorization: `Bearer ${token}` }, redirect: "error", signal: AbortSignal.timeout(5_000) });
|
|
147
|
+
if (!response.ok)
|
|
148
|
+
throw new Error(`HubSpot read-only preflight failed (${response.status}).`);
|
|
149
|
+
const body = await boundedJson(response);
|
|
150
|
+
const results = Array.isArray(body.results) ? body.results : [];
|
|
151
|
+
const first = record(results[0], "HubSpot record");
|
|
152
|
+
const id = first.id;
|
|
153
|
+
if (typeof id !== "string")
|
|
154
|
+
throw new Error("HubSpot preflight requires one existing sandbox record.");
|
|
155
|
+
const properties = record(first.properties, "HubSpot properties");
|
|
156
|
+
const observation = pick(properties, [field]);
|
|
157
|
+
assertCriterion(plan, observation);
|
|
158
|
+
return preflightResult(plan, now, "hubspot", id, observation);
|
|
159
|
+
}
|
|
160
|
+
async function postgresPreflight(env, plan, now, clientFactory) {
|
|
161
|
+
const connectionString = env.WITNORA_POSTGRES_READ_URL;
|
|
162
|
+
if (!connectionString)
|
|
163
|
+
throw new Error("PostgreSQL activation requires WITNORA_POSTGRES_READ_URL in the customer environment.");
|
|
164
|
+
const view = providerIdentifier(plan.generated.providerConfiguration?.viewName, "PostgreSQL approved view");
|
|
165
|
+
const idColumn = providerIdentifier(plan.generated.providerConfiguration?.idColumn, "PostgreSQL record ID column");
|
|
166
|
+
const field = providerIdentifier(plan.generated.criterion.field, "PostgreSQL criterion field");
|
|
167
|
+
const client = clientFactory ? clientFactory(connectionString) : await defaultPostgresClient(connectionString);
|
|
168
|
+
await client.connect();
|
|
169
|
+
let first;
|
|
170
|
+
try {
|
|
171
|
+
await client.query("BEGIN READ ONLY");
|
|
172
|
+
const result = await client.query({ text: `SELECT "${idColumn}", "${field}" FROM "${view}" ORDER BY "${idColumn}" DESC LIMIT 1` });
|
|
173
|
+
first = result.rows[0];
|
|
174
|
+
await client.query("ROLLBACK");
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
await client.query("ROLLBACK").catch(() => undefined);
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
await client.end();
|
|
182
|
+
}
|
|
183
|
+
if (!first)
|
|
184
|
+
throw new Error("PostgreSQL preflight requires one existing record in the approved read-only view.");
|
|
185
|
+
const id = first[idColumn];
|
|
186
|
+
if (typeof id !== "string" && typeof id !== "number")
|
|
187
|
+
throw new Error("PostgreSQL preflight returned an invalid record ID.");
|
|
188
|
+
const observation = pick(first, [field]);
|
|
189
|
+
assertCriterion(plan, observation);
|
|
190
|
+
return preflightResult(plan, now, "postgres", id, observation);
|
|
191
|
+
}
|
|
192
|
+
async function defaultPostgresClient(connectionString) { const imported = await import("pg"); return new imported.Client({ connectionString, application_name: "witnora-read-only-preflight" }); }
|
|
193
|
+
function generatedProviderHarness(plans) {
|
|
194
|
+
const contracts = plans.map((plan) => ({ taskContractId: plan.taskContractId, providerPackId: plan.generated.providerPackId, providerConfiguration: plan.generated.providerConfiguration ?? {}, criterion: plan.generated.criterion, actionPathIds: plan.generated.actionPathBindings.map((item) => item.actionPathId) }));
|
|
195
|
+
return `import {createHash} from "node:crypto";
|
|
196
|
+
import {readFile} from "node:fs/promises";
|
|
197
|
+
import {join} from "node:path";
|
|
198
|
+
const contracts=${JSON.stringify(contracts)};
|
|
199
|
+
const sha=(value)=>createHash("sha256").update(typeof value==="string"?value:JSON.stringify(value)).digest("hex");
|
|
200
|
+
const request=async(url,key)=>{const response=await fetch(url,{method:"GET",headers:{accept:"application/json",authorization:"Bearer "+key},redirect:"error",signal:AbortSignal.timeout(5000)});if(!response.ok)throw new Error("Provider read-only observation failed ("+response.status+").");return response.json();};
|
|
201
|
+
const observe=async(contract,resourceId)=>{if(contract.providerPackId==="STRIPE_REFUND"){const key=process.env.STRIPE_SECRET_KEY;if(!key?.startsWith("sk_test_"))throw new Error("Stripe test-mode credential is unavailable.");return request("https://api.stripe.com/v1/refunds/"+encodeURIComponent(resourceId),key);}if(contract.providerPackId==="ZENDESK_TICKET"){const key=process.env.ZENDESK_API_TOKEN;if(!key)throw new Error("Zendesk read-only credential is unavailable.");return (await request(contract.providerConfiguration.origin+"/api/v2/tickets/"+encodeURIComponent(resourceId)+".json",key)).ticket;}if(contract.providerPackId==="SALESFORCE_RECORD"){const key=process.env.SALESFORCE_ACCESS_TOKEN;if(!key)throw new Error("Salesforce read-only credential is unavailable.");return request(contract.providerConfiguration.origin+"/services/data/v61.0/sobjects/"+encodeURIComponent(contract.providerConfiguration.resourceType)+"/"+encodeURIComponent(resourceId),key);}if(contract.providerPackId==="HUBSPOT_CRM_RECORD"){const key=process.env.HUBSPOT_ACCESS_TOKEN;if(!key)throw new Error("HubSpot read-only credential is unavailable.");return (await request("https://api.hubapi.com/crm/v3/objects/"+encodeURIComponent(contract.providerConfiguration.resourceType)+"/"+encodeURIComponent(resourceId)+"?properties="+encodeURIComponent(contract.criterion.field),key)).properties;}if(contract.providerPackId==="POSTGRES_RECORD"){const url=process.env.WITNORA_POSTGRES_READ_URL;if(!url)throw new Error("PostgreSQL read-only credential is unavailable.");for(const name of [contract.providerConfiguration.viewName,contract.providerConfiguration.idColumn,contract.criterion.field])if(!/^[A-Za-z][A-Za-z0-9_]{0,99}$/.test(name))throw new Error("PostgreSQL identifier is invalid.");const {Client}=await import("pg");const client=new Client({connectionString:url,application_name:"witnora-read-only-probe"});await client.connect();try{await client.query("BEGIN READ ONLY");const result=await client.query({name:"witnora-provider-observe",text:'SELECT "'+contract.criterion.field+'" FROM "'+contract.providerConfiguration.viewName+'" WHERE "'+contract.providerConfiguration.idColumn+'" = $1 LIMIT 1',values:[resourceId]});await client.query("ROLLBACK");return result.rows[0]??{};}catch(error){await client.query("ROLLBACK").catch(()=>{});throw error;}finally{await client.end();}}throw new Error("Provider Harness contract is unsupported.");};
|
|
202
|
+
export function createWitnoraBusinessTaskEvaluatorOptions(context){return {
|
|
203
|
+
loadShadowObservations:async(task)=>{const contract=contracts.find((item)=>item.taskContractId===task.id);if(!contract)throw new Error("No exact real-path contract.");const path=join(context.repository,".witnora","scenarios",task.id+".json");const value=JSON.parse(await readFile(path,"utf8"));if(!Array.isArray(value)||value.length>100)throw new Error("Local scenario file is invalid.");return value;},
|
|
204
|
+
evaluateShadowCandidate:async(candidate,task)=>{const contract=contracts.find((item)=>item.taskContractId===task.id);if(!contract)throw new Error("No exact real-path contract.");const resourceId=String(candidate.input?.resourceId??"");if(!/^[A-Za-z0-9._:-]{1,200}$/.test(resourceId))throw new Error("Provider resourceId is invalid.");for(const pathId of contract.actionPathIds)candidate.propose({pathId,parametersDigestSha256:sha(resourceId)});const raw=await observe(contract,resourceId);const actual=raw?.[contract.criterion.field];const observed=actual===undefined?{}:{[contract.criterion.field]:actual};return {resultDigestSha256:sha(observed),criteria:[{id:contract.criterion.id,passed:actual===contract.criterion.expected}]};}
|
|
205
|
+
};}
|
|
206
|
+
`;
|
|
88
207
|
}
|
|
89
208
|
function parsePlan(value) { if (!value || typeof value !== "object" || Array.isArray(value))
|
|
90
209
|
throw new Error("Real-path integration response is invalid."); const plan = value; if (plan.schemaVersion !== "witnora.real_path_integration.v0.1" || !plan.id || !plan.taskContractId || !plan.subject?.agentId || !plan.subject.agentVersion || !plan.generated || plan.generated.boundaries?.rawPayloadUpload !== false || plan.generated.boundaries.rawCredentialUpload !== false || plan.generated.boundaries.evaluatorWrites !== false || plan.generated.boundaries.firstAcceptanceProductionWrites !== 0 || !digest(plan.digestSha256) || !digest(plan.taskContractDigestSha256) || !digest(plan.generated.providerContractDigestSha256))
|
|
@@ -93,6 +212,23 @@ async function boundedJson(response) { const text = await response.text(); if (t
|
|
|
93
212
|
throw new Error("Real-path response exceeded the size limit."); const value = JSON.parse(text); if (!value || typeof value !== "object" || Array.isArray(value))
|
|
94
213
|
throw new Error("Real-path response is invalid."); return value; }
|
|
95
214
|
function scalar(value) { return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean"; }
|
|
215
|
+
function providerOrigin(plan, provider, suffix) { const value = plan.generated.providerConfiguration?.origin; try {
|
|
216
|
+
const url = new URL(value ?? "");
|
|
217
|
+
if (url.protocol !== "https:" || !url.hostname.endsWith(suffix) || url.origin !== (value ?? "").replace(/\/$/, ""))
|
|
218
|
+
throw new Error();
|
|
219
|
+
return url.origin;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
throw new Error(`${provider} integration has an invalid trusted origin.`);
|
|
223
|
+
} }
|
|
224
|
+
function providerIdentifier(value, field) { if (!value || !/^[A-Za-z][A-Za-z0-9_]{0,99}$/.test(value))
|
|
225
|
+
throw new Error(`${field} is invalid.`); return value; }
|
|
226
|
+
function record(value, field) { if (!value || typeof value !== "object" || Array.isArray(value))
|
|
227
|
+
throw new Error(`${field} response is invalid.`); return value; }
|
|
228
|
+
function pick(value, fields) { return Object.fromEntries(fields.flatMap((field) => { const selected = field.split(".").reduce((current, key) => current && typeof current === "object" ? current[key] : undefined, value); return scalar(selected) ? [[field, selected]] : []; })); }
|
|
229
|
+
function assertCriterion(plan, observation) { if (observation[plan.generated.criterion.field] !== plan.generated.criterion.expected)
|
|
230
|
+
throw new Error("The provider sandbox record does not satisfy the approved business success definition."); }
|
|
231
|
+
function preflightResult(plan, now, provider, resourceId, observation) { const resultDigest = sha(canonical(observation)); return { acceptance: { kind: "READ_ONLY_PROVIDER_PREFLIGHT", passedAt: now.toISOString(), productionWrites: 0, observationDigestSha256: resultDigest }, scenario: { id: `${provider}:${sha(String(resourceId)).slice(0, 16)}`, source: "LIVE_SHADOW", sanitized: true, input: { resourceId }, inputDigestSha256: sha(canonical({ resourceId })), baseline: { resultDigestSha256: resultDigest, actionIntents: plan.generated.actionPathBindings.map((item) => ({ pathId: item.actionPathId, parametersDigestSha256: sha(String(resourceId)) })) } } }; }
|
|
96
232
|
function digest(value) { return typeof value === "string" && /^[a-f0-9]{64}$/.test(value); }
|
|
97
233
|
function canonical(value) { if (value === null || typeof value !== "object")
|
|
98
234
|
return JSON.stringify(value); if (Array.isArray(value))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-integration-packs.d.ts","sourceRoot":"","sources":["../../../../onegent-runtime/src/provider-integration-packs.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,KAAK,sCAAsC,EAC3C,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EACjC,MAAM,+BAA+B,CAAC;AAGvC,eAAO,MAAM,wCAAwC,EAAG,wCAAiD,CAAC;AAE1G,MAAM,MAAM,yBAAyB,GACjC,eAAe,GAAG,mBAAmB,GAAG,oBAAoB,GAAG,gBAAgB,GAAG,iBAAiB,GACnG,iBAAiB,GAAG,cAAc,GAAG,kBAAkB,GAAG,WAAW,GAAG,gBAAgB,GAAG,kBAAkB,CAAC;AAElH,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,OAAO,wCAAwC,CAAC;IAC/D,EAAE,EAAE,yBAAyB,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,2BAA2B,CAAC;IACtC,YAAY,EAAE,KAAK,CAAC,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC,CAAC;IAC1D,UAAU,EAAE;QAAE,MAAM,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,eAAe,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,cAAc,GAAG,iBAAiB,GAAG,eAAe,CAAA;KAAE,CAAC;IAClJ,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IAC1H,QAAQ,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE,CAAC;IACpF,UAAU,EAAE;QAAE,MAAM,EAAE,KAAK,CAAC;QAAC,SAAS,EAAE,KAAK,CAAC;QAAC,gBAAgB,EAAE,KAAK,CAAC;QAAC,mBAAmB,EAAE,KAAK,CAAA;KAAE,CAAC;IACrG,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,OAAO,CAAC,yBAAyB,EAAE,iBAAiB,GAAG,cAAc,GAAG,kBAAkB,CAAC,CAAC;IACpG,WAAW,EAAE,SAAS,GAAG,SAAS,GAAG,YAAY,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,8BAA8B,CAAC,mBAAmB,CAAC,CAAC;IACpJ,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-integration-packs.d.ts","sourceRoot":"","sources":["../../../../onegent-runtime/src/provider-integration-packs.ts"],"names":[],"mappings":"AAEA,OAAO,EASL,KAAK,sCAAsC,EAC3C,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EACjC,MAAM,+BAA+B,CAAC;AAGvC,eAAO,MAAM,wCAAwC,EAAG,wCAAiD,CAAC;AAE1G,MAAM,MAAM,yBAAyB,GACjC,eAAe,GAAG,mBAAmB,GAAG,oBAAoB,GAAG,gBAAgB,GAAG,iBAAiB,GACnG,iBAAiB,GAAG,cAAc,GAAG,kB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AAM,EAAE,yBAAyB,CAAC;IAClC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CAAC;IACtC,gBAAgB,EAAE,CAAC,CAAC;IACpB,yBAAyB,EAAE,IAAI,CAAC;IAChC,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,uBAAuB,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAgBD,wBAAgB,4BAA4B,IAAI,uBAAuB,EAAE,CAAsD;AAC/H,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,yBAAyB,GAAG,uBAAuB,CAEjG;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kCAAkC,GAAG,0BAA0B,CAsBnH;AAED,wBAAsB,4BAA4B,CAAC,KAAK,EAAE;IACxD,SAAS,EAAE,0BAA0B,CAAC;IACtC,MAAM,EAAE,yBAAyB,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC;CACtF,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAYvC"}
|
|
@@ -26,7 +26,8 @@ export function createProviderPackEvaluator(options) {
|
|
|
26
26
|
const spec = getProviderIntegrationPack(options.packId);
|
|
27
27
|
if (!spec.environments.includes(options.environment))
|
|
28
28
|
throw new Error("Provider pack does not support this environment.");
|
|
29
|
-
const
|
|
29
|
+
const selectFields = selector(spec.fieldAllowlist);
|
|
30
|
+
const select = (value) => selectFields(providerPayload(options.packId, value));
|
|
30
31
|
const common = { provider: spec.provider, environment: options.environment, credentialHandle: options.credentialHandle, resolveCredential: options.resolveCredential, select, timeoutMs: options.timeoutMs, now: options.now };
|
|
31
32
|
if (options.packId === "POSTGRES_RECORD" || options.packId === "MYSQL_RECORD")
|
|
32
33
|
return createDatabaseReadOnlyEvaluator({ ...common, statementId: options.statementId, executePrepared: options.executePrepared });
|
|
@@ -36,7 +37,8 @@ export function createProviderPackEvaluator(options) {
|
|
|
36
37
|
const origin = http.allowedOrigin ?? spec.endpoint.origin;
|
|
37
38
|
if (!origin)
|
|
38
39
|
throw new Error("Provider pack requires the customer-specific HTTPS origin discovered during local setup.");
|
|
39
|
-
|
|
40
|
+
validateProviderOrigin(options.packId, origin);
|
|
41
|
+
const resourcePath = resourcePathBuilder(options.packId, spec.endpoint.resourcePattern, providerResourceType(options.packId, http.resourceType), spec.fieldAllowlist);
|
|
40
42
|
const input = { ...common, allowedOrigin: origin, resourcePath, fetch: http.fetch };
|
|
41
43
|
switch (spec.template) {
|
|
42
44
|
case "CRM_RECORD_STATE": return createCrmRecordStateEvaluator(input);
|
|
@@ -71,6 +73,38 @@ function criterion(id, question, field, suggestedValues) { return { id, question
|
|
|
71
73
|
function selector(fields) {
|
|
72
74
|
return (value) => Object.fromEntries(fields.flatMap((field) => { const selected = field.split(".").reduce((current, key) => current && typeof current === "object" ? current[key] : undefined, value); return selected === undefined ? [] : [[field, selected]]; }));
|
|
73
75
|
}
|
|
74
|
-
function resourcePathBuilder(pattern) {
|
|
75
|
-
return (resourceId) =>
|
|
76
|
+
function resourcePathBuilder(packId, pattern, resourceType, fields) {
|
|
77
|
+
return (resourceId) => {
|
|
78
|
+
const path = pattern.replace("{resourceId}", encodeURIComponent(resourceId)).replace("{object}", encodeURIComponent(resourceType));
|
|
79
|
+
return packId === "HUBSPOT_CRM_RECORD" ? `${path}?${new URLSearchParams({ properties: fields.join(",") })}` : path;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function providerPayload(packId, value) {
|
|
83
|
+
if (packId === "ZENDESK_TICKET")
|
|
84
|
+
return nestedRecord(value, "ticket", "Zendesk ticket response");
|
|
85
|
+
if (packId === "HUBSPOT_CRM_RECORD")
|
|
86
|
+
return nestedRecord(value, "properties", "HubSpot record response");
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
function validateProviderOrigin(packId, value) {
|
|
90
|
+
const url = new URL(value);
|
|
91
|
+
if (packId === "ZENDESK_TICKET" && (url.protocol !== "https:" || !url.hostname.endsWith(".zendesk.com")))
|
|
92
|
+
throw new Error("Zendesk origin must be an HTTPS customer subdomain of zendesk.com.");
|
|
93
|
+
if (packId === "SALESFORCE_RECORD" && (url.protocol !== "https:" || !url.hostname.endsWith(".my.salesforce.com")))
|
|
94
|
+
throw new Error("Salesforce origin must be the customer's HTTPS my.salesforce.com domain.");
|
|
95
|
+
if (packId === "HUBSPOT_CRM_RECORD" && (url.protocol !== "https:" || url.hostname !== "api.hubapi.com"))
|
|
96
|
+
throw new Error("HubSpot origin must be the fixed HTTPS api.hubapi.com endpoint.");
|
|
97
|
+
}
|
|
98
|
+
function providerResourceType(packId, value) {
|
|
99
|
+
if (packId !== "SALESFORCE_RECORD" && packId !== "HUBSPOT_CRM_RECORD")
|
|
100
|
+
return "records";
|
|
101
|
+
if (!value || !/^[A-Za-z][A-Za-z0-9_]{0,99}$/.test(value))
|
|
102
|
+
throw new Error(`${packId === "SALESFORCE_RECORD" ? "Salesforce" : "HubSpot"} resource type is invalid.`);
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
function nestedRecord(value, key, field) {
|
|
106
|
+
const nested = value[key];
|
|
107
|
+
if (!nested || typeof nested !== "object" || Array.isArray(nested))
|
|
108
|
+
throw new Error(`${field} is missing.`);
|
|
109
|
+
return nested;
|
|
76
110
|
}
|