@microsoft/m365-spec-parser 0.1.1-alpha.2c983f96a.0 → 0.1.1-alpha.3bb446445.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/index.esm2017.js +8 -1
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +45 -66
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +8 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +45 -66
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +4 -1
- package/dist/src/interfaces.d.ts +4 -0
- package/dist/src/manifestUpdater.d.ts +2 -2
- package/package.json +3 -4
package/dist/index.esm2017.mjs
CHANGED
|
@@ -105,7 +105,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
105
105
|
ConstantString.TextBlockType = "TextBlock";
|
|
106
106
|
ConstantString.ImageType = "Image";
|
|
107
107
|
ConstantString.ContainerType = "Container";
|
|
108
|
-
ConstantString.RegistrationIdPostfix =
|
|
108
|
+
ConstantString.RegistrationIdPostfix = {
|
|
109
|
+
apiKey: "REGISTRATION_ID",
|
|
110
|
+
oauth2: "CONFIGURATION_ID",
|
|
111
|
+
http: "REGISTRATION_ID",
|
|
112
|
+
openIdConnect: "REGISTRATION_ID",
|
|
113
|
+
};
|
|
109
114
|
ConstantString.ResponseCodeFor20X = [
|
|
110
115
|
"200",
|
|
111
116
|
"201",
|
|
@@ -164,6 +169,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
|
|
|
164
169
|
ConstantString.FullDescriptionMaxLens = 4000;
|
|
165
170
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
166
171
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
172
|
+
ConstantString.ConversationStarterMaxLens = 50;
|
|
167
173
|
ConstantString.CommandTitleMaxLens = 32;
|
|
168
174
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
169
175
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
@@ -1361,14 +1367,17 @@ class ManifestUpdater {
|
|
|
1361
1367
|
static async updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authInfo) {
|
|
1362
1368
|
const manifest = await fs.readJSON(manifestPath);
|
|
1363
1369
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
1364
|
-
manifest.
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
+
// Insert plugins in manifest.json if it is plugin for Copilot.
|
|
1371
|
+
if (!options.isGptPlugin) {
|
|
1372
|
+
manifest.plugins = [
|
|
1373
|
+
{
|
|
1374
|
+
file: apiPluginRelativePath,
|
|
1375
|
+
id: ConstantString.DefaultPluginId,
|
|
1376
|
+
},
|
|
1377
|
+
];
|
|
1378
|
+
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1379
|
+
}
|
|
1370
1380
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1371
|
-
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1372
1381
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
1373
1382
|
const apiPlugin = await ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
|
|
1374
1383
|
return [manifest, apiPlugin];
|
|
@@ -1380,39 +1389,20 @@ class ManifestUpdater {
|
|
|
1380
1389
|
full: (_b = ((_a = spec.info.description) !== null && _a !== void 0 ? _a : manifest.description.full)) === null || _b === void 0 ? void 0 : _b.slice(0, ConstantString.FullDescriptionMaxLens),
|
|
1381
1390
|
};
|
|
1382
1391
|
}
|
|
1383
|
-
static
|
|
1384
|
-
let parameter;
|
|
1392
|
+
static checkSchema(schema, method, pathUrl) {
|
|
1385
1393
|
if (schema.type === "array") {
|
|
1386
1394
|
const items = schema.items;
|
|
1387
|
-
|
|
1388
|
-
type: "array",
|
|
1389
|
-
items: ManifestUpdater.mapOpenAPISchemaToFuncParam(items, method, pathUrl),
|
|
1390
|
-
};
|
|
1395
|
+
ManifestUpdater.checkSchema(items, method, pathUrl);
|
|
1391
1396
|
}
|
|
1392
|
-
else if (schema.type
|
|
1393
|
-
schema.type
|
|
1394
|
-
schema.type
|
|
1395
|
-
schema.type
|
|
1396
|
-
parameter = {
|
|
1397
|
-
type: schema.type,
|
|
1398
|
-
};
|
|
1399
|
-
}
|
|
1400
|
-
else {
|
|
1397
|
+
else if (schema.type !== "string" &&
|
|
1398
|
+
schema.type !== "boolean" &&
|
|
1399
|
+
schema.type !== "integer" &&
|
|
1400
|
+
schema.type !== "number") {
|
|
1401
1401
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), ErrorType.UpdateManifestFailed);
|
|
1402
1402
|
}
|
|
1403
|
-
if (schema.enum) {
|
|
1404
|
-
parameter.enum = schema.enum;
|
|
1405
|
-
}
|
|
1406
|
-
if (schema.description) {
|
|
1407
|
-
parameter.description = schema.description;
|
|
1408
|
-
}
|
|
1409
|
-
if (schema.default) {
|
|
1410
|
-
parameter.default = schema.default;
|
|
1411
|
-
}
|
|
1412
|
-
return parameter;
|
|
1413
1403
|
}
|
|
1414
1404
|
static async generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
|
|
1415
|
-
var _a, _b, _c, _d
|
|
1405
|
+
var _a, _b, _c, _d;
|
|
1416
1406
|
const functions = [];
|
|
1417
1407
|
const functionNames = [];
|
|
1418
1408
|
const conversationStarters = [];
|
|
@@ -1428,7 +1418,7 @@ class ManifestUpdater {
|
|
|
1428
1418
|
pluginAuthObj.type = "ApiKeyPluginVault";
|
|
1429
1419
|
}
|
|
1430
1420
|
if (pluginAuthObj.type !== "None") {
|
|
1431
|
-
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1421
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1432
1422
|
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
|
|
1433
1423
|
}
|
|
1434
1424
|
}
|
|
@@ -1443,37 +1433,24 @@ class ManifestUpdater {
|
|
|
1443
1433
|
if (operationItem) {
|
|
1444
1434
|
const operationId = operationItem.operationId;
|
|
1445
1435
|
const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
|
|
1436
|
+
const summary = operationItem.summary;
|
|
1446
1437
|
const paramObject = operationItem.parameters;
|
|
1447
1438
|
const requestBody = operationItem.requestBody;
|
|
1448
|
-
const parameters = {
|
|
1449
|
-
type: "object",
|
|
1450
|
-
properties: {},
|
|
1451
|
-
required: [],
|
|
1452
|
-
};
|
|
1453
1439
|
if (paramObject) {
|
|
1454
1440
|
for (let i = 0; i < paramObject.length; i++) {
|
|
1455
1441
|
const param = paramObject[i];
|
|
1456
1442
|
const schema = param.schema;
|
|
1457
|
-
|
|
1443
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1458
1444
|
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));
|
|
1459
|
-
if (param.required) {
|
|
1460
|
-
parameters.required.push(param.name);
|
|
1461
|
-
}
|
|
1462
|
-
if (!parameters.properties[param.name].description) {
|
|
1463
|
-
parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
|
|
1464
|
-
}
|
|
1465
1445
|
}
|
|
1466
1446
|
}
|
|
1467
1447
|
if (requestBody) {
|
|
1468
1448
|
const requestJsonBody = requestBody.content["application/json"];
|
|
1469
1449
|
const requestBodySchema = requestJsonBody.schema;
|
|
1470
1450
|
if (requestBodySchema.type === "object") {
|
|
1471
|
-
if (requestBodySchema.required) {
|
|
1472
|
-
parameters.required.push(...requestBodySchema.required);
|
|
1473
|
-
}
|
|
1474
1451
|
for (const property in requestBodySchema.properties) {
|
|
1475
1452
|
const schema = requestBodySchema.properties[property];
|
|
1476
|
-
|
|
1453
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1477
1454
|
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
|
|
1478
1455
|
}
|
|
1479
1456
|
}
|
|
@@ -1485,15 +1462,15 @@ class ManifestUpdater {
|
|
|
1485
1462
|
name: operationId,
|
|
1486
1463
|
description: description,
|
|
1487
1464
|
};
|
|
1488
|
-
if (paramObject || requestBody) {
|
|
1489
|
-
funcObj.parameters = parameters;
|
|
1490
|
-
}
|
|
1491
1465
|
if (options.allowResponseSemantics) {
|
|
1492
|
-
const
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1466
|
+
const { json } = Utils.getResponseJson(operationItem);
|
|
1467
|
+
if (json.schema) {
|
|
1468
|
+
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
|
|
1469
|
+
const responseSemantic = wrapResponseSemantics(card, jsonPath);
|
|
1470
|
+
funcObj.capabilities = {
|
|
1471
|
+
response_semantics: responseSemantic,
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1497
1474
|
}
|
|
1498
1475
|
if (options.allowConfirmation && method !== ConstantString.GetMethod) {
|
|
1499
1476
|
if (!funcObj.capabilities) {
|
|
@@ -1501,7 +1478,7 @@ class ManifestUpdater {
|
|
|
1501
1478
|
}
|
|
1502
1479
|
funcObj.capabilities.confirmation = {
|
|
1503
1480
|
type: "AdaptiveCard",
|
|
1504
|
-
title: (
|
|
1481
|
+
title: (_b = operationItem.summary) !== null && _b !== void 0 ? _b : description,
|
|
1505
1482
|
};
|
|
1506
1483
|
if (confirmationBodies.length > 0) {
|
|
1507
1484
|
funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
|
|
@@ -1509,8 +1486,9 @@ class ManifestUpdater {
|
|
|
1509
1486
|
}
|
|
1510
1487
|
functions.push(funcObj);
|
|
1511
1488
|
functionNames.push(operationId);
|
|
1512
|
-
|
|
1513
|
-
|
|
1489
|
+
const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
|
|
1490
|
+
if (conversationStarterStr) {
|
|
1491
|
+
conversationStarters.push(conversationStarterStr);
|
|
1514
1492
|
}
|
|
1515
1493
|
}
|
|
1516
1494
|
}
|
|
@@ -1533,7 +1511,7 @@ class ManifestUpdater {
|
|
|
1533
1511
|
}
|
|
1534
1512
|
apiPlugin.functions = apiPlugin.functions || [];
|
|
1535
1513
|
for (const func of functions) {
|
|
1536
|
-
const index = (
|
|
1514
|
+
const index = (_c = apiPlugin.functions) === null || _c === void 0 ? void 0 : _c.findIndex((f) => f.name === func.name);
|
|
1537
1515
|
if (index === -1) {
|
|
1538
1516
|
apiPlugin.functions.push(func);
|
|
1539
1517
|
}
|
|
@@ -1569,7 +1547,7 @@ class ManifestUpdater {
|
|
|
1569
1547
|
}
|
|
1570
1548
|
if (!apiPlugin.description_for_human) {
|
|
1571
1549
|
apiPlugin.description_for_human =
|
|
1572
|
-
(
|
|
1550
|
+
(_d = spec.info.description) !== null && _d !== void 0 ? _d : "<Please add description of the plugin>";
|
|
1573
1551
|
}
|
|
1574
1552
|
if (options.allowConversationStarters && conversationStarters.length > 0) {
|
|
1575
1553
|
if (!apiPlugin.capabilities) {
|
|
@@ -1602,9 +1580,9 @@ class ManifestUpdater {
|
|
|
1602
1580
|
};
|
|
1603
1581
|
if (authInfo) {
|
|
1604
1582
|
const auth = authInfo.authScheme;
|
|
1605
|
-
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1583
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1606
1584
|
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
|
|
1607
|
-
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1585
|
+
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1608
1586
|
composeExtension.authorization = {
|
|
1609
1587
|
authType: "apiSecretServiceAuth",
|
|
1610
1588
|
apiSecretServiceAuthConfiguration: {
|
|
@@ -1724,6 +1702,7 @@ class SpecParser {
|
|
|
1724
1702
|
allowResponseSemantics: false,
|
|
1725
1703
|
allowConfirmation: false,
|
|
1726
1704
|
projectType: ProjectType.SME,
|
|
1705
|
+
isGptPlugin: false,
|
|
1727
1706
|
};
|
|
1728
1707
|
this.pathOrSpec = pathOrDoc;
|
|
1729
1708
|
this.parser = new SwaggerParser();
|