@microsoft/m365-spec-parser 0.1.1-alpha.ded43fb2d.0 → 0.1.1-alpha.e1b11d5b2.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 +13 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +53 -73
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +13 -6
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +53 -73
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +5 -3
- package/dist/src/interfaces.d.ts +4 -0
- package/dist/src/manifestUpdater.d.ts +2 -2
- package/package.json +3 -4
package/dist/index.node.cjs.js
CHANGED
|
@@ -125,7 +125,7 @@ ConstantString.RemoteRefNotSupported = "Remote reference is not supported: %s.";
|
|
|
125
125
|
ConstantString.MissingOperationId = "Missing operationIds: %s.";
|
|
126
126
|
ConstantString.NoSupportedApi = "No supported API is found in the OpenAPI description document: only GET and POST methods are supported, additionally, there can be at most one required parameter, and no auth is allowed.";
|
|
127
127
|
ConstantString.AdditionalPropertiesNotSupported = "'additionalProperties' is not supported, and will be ignored.";
|
|
128
|
-
ConstantString.SchemaNotSupported = "'oneOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
128
|
+
ConstantString.SchemaNotSupported = "'oneOf', 'allOf', 'anyOf', and 'not' schema are not supported: %s.";
|
|
129
129
|
ConstantString.UnknownSchema = "Unknown schema: %s.";
|
|
130
130
|
ConstantString.UrlProtocolNotSupported = "Server url is not correct: protocol %s is not supported, you should use https protocol instead.";
|
|
131
131
|
ConstantString.RelativeServerUrlNotSupported = "Server url is not correct: relative server url is not supported.";
|
|
@@ -147,8 +147,12 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
147
147
|
ConstantString.TextBlockType = "TextBlock";
|
|
148
148
|
ConstantString.ImageType = "Image";
|
|
149
149
|
ConstantString.ContainerType = "Container";
|
|
150
|
-
ConstantString.RegistrationIdPostfix =
|
|
151
|
-
|
|
150
|
+
ConstantString.RegistrationIdPostfix = {
|
|
151
|
+
apiKey: "REGISTRATION_ID",
|
|
152
|
+
oauth2: "CONFIGURATION_ID",
|
|
153
|
+
http: "REGISTRATION_ID",
|
|
154
|
+
openIdConnect: "REGISTRATION_ID",
|
|
155
|
+
};
|
|
152
156
|
ConstantString.ResponseCodeFor20X = [
|
|
153
157
|
"200",
|
|
154
158
|
"201",
|
|
@@ -207,6 +211,7 @@ ConstantString.ShortDescriptionMaxLens = 80;
|
|
|
207
211
|
ConstantString.FullDescriptionMaxLens = 4000;
|
|
208
212
|
ConstantString.CommandDescriptionMaxLens = 128;
|
|
209
213
|
ConstantString.ParameterDescriptionMaxLens = 128;
|
|
214
|
+
ConstantString.ConversationStarterMaxLens = 50;
|
|
210
215
|
ConstantString.CommandTitleMaxLens = 32;
|
|
211
216
|
ConstantString.ParameterTitleMaxLens = 32;
|
|
212
217
|
ConstantString.SMERequiredParamsMaxNum = 5;
|
|
@@ -251,9 +256,10 @@ class Utils {
|
|
|
251
256
|
var _a;
|
|
252
257
|
const result = [];
|
|
253
258
|
const securitySchemas = (_a = spec.components) === null || _a === void 0 ? void 0 : _a.securitySchemes;
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
const securitiesArr = securities !== null && securities !== void 0 ? securities : spec.security;
|
|
260
|
+
if (securitiesArr && securitySchemas) {
|
|
261
|
+
for (let i = 0; i < securitiesArr.length; i++) {
|
|
262
|
+
const security = securitiesArr[i];
|
|
257
263
|
const authArray = [];
|
|
258
264
|
for (const name in security) {
|
|
259
265
|
const auth = securitySchemas[name];
|
|
@@ -1404,14 +1410,17 @@ class ManifestUpdater {
|
|
|
1404
1410
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1405
1411
|
const manifest = yield fs__default['default'].readJSON(manifestPath);
|
|
1406
1412
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
1407
|
-
manifest.
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
+
// Insert plugins in manifest.json if it is plugin for Copilot.
|
|
1414
|
+
if (!options.isGptPlugin) {
|
|
1415
|
+
manifest.plugins = [
|
|
1416
|
+
{
|
|
1417
|
+
file: apiPluginRelativePath,
|
|
1418
|
+
id: ConstantString.DefaultPluginId,
|
|
1419
|
+
},
|
|
1420
|
+
];
|
|
1421
|
+
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1422
|
+
}
|
|
1413
1423
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1414
|
-
ManifestUpdater.updateManifestDescription(manifest, spec);
|
|
1415
1424
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
1416
1425
|
const apiPlugin = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options);
|
|
1417
1426
|
return [manifest, apiPlugin];
|
|
@@ -1424,39 +1433,20 @@ class ManifestUpdater {
|
|
|
1424
1433
|
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),
|
|
1425
1434
|
};
|
|
1426
1435
|
}
|
|
1427
|
-
static
|
|
1428
|
-
let parameter;
|
|
1436
|
+
static checkSchema(schema, method, pathUrl) {
|
|
1429
1437
|
if (schema.type === "array") {
|
|
1430
1438
|
const items = schema.items;
|
|
1431
|
-
|
|
1432
|
-
type: "array",
|
|
1433
|
-
items: ManifestUpdater.mapOpenAPISchemaToFuncParam(items, method, pathUrl),
|
|
1434
|
-
};
|
|
1435
|
-
}
|
|
1436
|
-
else if (schema.type === "string" ||
|
|
1437
|
-
schema.type === "boolean" ||
|
|
1438
|
-
schema.type === "integer" ||
|
|
1439
|
-
schema.type === "number") {
|
|
1440
|
-
parameter = {
|
|
1441
|
-
type: schema.type,
|
|
1442
|
-
};
|
|
1439
|
+
ManifestUpdater.checkSchema(items, method, pathUrl);
|
|
1443
1440
|
}
|
|
1444
|
-
else
|
|
1441
|
+
else if (schema.type !== "string" &&
|
|
1442
|
+
schema.type !== "boolean" &&
|
|
1443
|
+
schema.type !== "integer" &&
|
|
1444
|
+
schema.type !== "number") {
|
|
1445
1445
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), exports.ErrorType.UpdateManifestFailed);
|
|
1446
1446
|
}
|
|
1447
|
-
if (schema.enum) {
|
|
1448
|
-
parameter.enum = schema.enum;
|
|
1449
|
-
}
|
|
1450
|
-
if (schema.description) {
|
|
1451
|
-
parameter.description = schema.description;
|
|
1452
|
-
}
|
|
1453
|
-
if (schema.default) {
|
|
1454
|
-
parameter.default = schema.default;
|
|
1455
|
-
}
|
|
1456
|
-
return parameter;
|
|
1457
1447
|
}
|
|
1458
1448
|
static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authInfo, options) {
|
|
1459
|
-
var _a, _b, _c, _d
|
|
1449
|
+
var _a, _b, _c, _d;
|
|
1460
1450
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1461
1451
|
const functions = [];
|
|
1462
1452
|
const functionNames = [];
|
|
@@ -1473,7 +1463,8 @@ class ManifestUpdater {
|
|
|
1473
1463
|
pluginAuthObj.type = "ApiKeyPluginVault";
|
|
1474
1464
|
}
|
|
1475
1465
|
if (pluginAuthObj.type !== "None") {
|
|
1476
|
-
|
|
1466
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1467
|
+
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
|
|
1477
1468
|
}
|
|
1478
1469
|
}
|
|
1479
1470
|
for (const pathUrl in paths) {
|
|
@@ -1487,37 +1478,24 @@ class ManifestUpdater {
|
|
|
1487
1478
|
if (operationItem) {
|
|
1488
1479
|
const operationId = operationItem.operationId;
|
|
1489
1480
|
const description = (_a = operationItem.description) !== null && _a !== void 0 ? _a : "";
|
|
1481
|
+
const summary = operationItem.summary;
|
|
1490
1482
|
const paramObject = operationItem.parameters;
|
|
1491
1483
|
const requestBody = operationItem.requestBody;
|
|
1492
|
-
const parameters = {
|
|
1493
|
-
type: "object",
|
|
1494
|
-
properties: {},
|
|
1495
|
-
required: [],
|
|
1496
|
-
};
|
|
1497
1484
|
if (paramObject) {
|
|
1498
1485
|
for (let i = 0; i < paramObject.length; i++) {
|
|
1499
1486
|
const param = paramObject[i];
|
|
1500
1487
|
const schema = param.schema;
|
|
1501
|
-
|
|
1488
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1502
1489
|
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(param.name));
|
|
1503
|
-
if (param.required) {
|
|
1504
|
-
parameters.required.push(param.name);
|
|
1505
|
-
}
|
|
1506
|
-
if (!parameters.properties[param.name].description) {
|
|
1507
|
-
parameters.properties[param.name].description = (_b = param.description) !== null && _b !== void 0 ? _b : "";
|
|
1508
|
-
}
|
|
1509
1490
|
}
|
|
1510
1491
|
}
|
|
1511
1492
|
if (requestBody) {
|
|
1512
1493
|
const requestJsonBody = requestBody.content["application/json"];
|
|
1513
1494
|
const requestBodySchema = requestJsonBody.schema;
|
|
1514
1495
|
if (requestBodySchema.type === "object") {
|
|
1515
|
-
if (requestBodySchema.required) {
|
|
1516
|
-
parameters.required.push(...requestBodySchema.required);
|
|
1517
|
-
}
|
|
1518
1496
|
for (const property in requestBodySchema.properties) {
|
|
1519
1497
|
const schema = requestBodySchema.properties[property];
|
|
1520
|
-
|
|
1498
|
+
ManifestUpdater.checkSchema(schema, method, pathUrl);
|
|
1521
1499
|
confirmationBodies.push(ManifestUpdater.getConfirmationBodyItem(property));
|
|
1522
1500
|
}
|
|
1523
1501
|
}
|
|
@@ -1529,15 +1507,15 @@ class ManifestUpdater {
|
|
|
1529
1507
|
name: operationId,
|
|
1530
1508
|
description: description,
|
|
1531
1509
|
};
|
|
1532
|
-
if (paramObject || requestBody) {
|
|
1533
|
-
funcObj.parameters = parameters;
|
|
1534
|
-
}
|
|
1535
1510
|
if (options.allowResponseSemantics) {
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1511
|
+
const { json } = Utils.getResponseJson(operationItem);
|
|
1512
|
+
if (json.schema) {
|
|
1513
|
+
const [card, jsonPath] = AdaptiveCardGenerator.generateAdaptiveCard(operationItem);
|
|
1514
|
+
const responseSemantic = wrapResponseSemantics(card, jsonPath);
|
|
1515
|
+
funcObj.capabilities = {
|
|
1516
|
+
response_semantics: responseSemantic,
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1541
1519
|
}
|
|
1542
1520
|
if (options.allowConfirmation && method !== ConstantString.GetMethod) {
|
|
1543
1521
|
if (!funcObj.capabilities) {
|
|
@@ -1545,7 +1523,7 @@ class ManifestUpdater {
|
|
|
1545
1523
|
}
|
|
1546
1524
|
funcObj.capabilities.confirmation = {
|
|
1547
1525
|
type: "AdaptiveCard",
|
|
1548
|
-
title: (
|
|
1526
|
+
title: (_b = operationItem.summary) !== null && _b !== void 0 ? _b : description,
|
|
1549
1527
|
};
|
|
1550
1528
|
if (confirmationBodies.length > 0) {
|
|
1551
1529
|
funcObj.capabilities.confirmation.body = confirmationBodies.join("\n");
|
|
@@ -1553,8 +1531,9 @@ class ManifestUpdater {
|
|
|
1553
1531
|
}
|
|
1554
1532
|
functions.push(funcObj);
|
|
1555
1533
|
functionNames.push(operationId);
|
|
1556
|
-
|
|
1557
|
-
|
|
1534
|
+
const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
|
|
1535
|
+
if (conversationStarterStr) {
|
|
1536
|
+
conversationStarters.push(conversationStarterStr);
|
|
1558
1537
|
}
|
|
1559
1538
|
}
|
|
1560
1539
|
}
|
|
@@ -1577,7 +1556,7 @@ class ManifestUpdater {
|
|
|
1577
1556
|
}
|
|
1578
1557
|
apiPlugin.functions = apiPlugin.functions || [];
|
|
1579
1558
|
for (const func of functions) {
|
|
1580
|
-
const index = (
|
|
1559
|
+
const index = (_c = apiPlugin.functions) === null || _c === void 0 ? void 0 : _c.findIndex((f) => f.name === func.name);
|
|
1581
1560
|
if (index === -1) {
|
|
1582
1561
|
apiPlugin.functions.push(func);
|
|
1583
1562
|
}
|
|
@@ -1613,7 +1592,7 @@ class ManifestUpdater {
|
|
|
1613
1592
|
}
|
|
1614
1593
|
if (!apiPlugin.description_for_human) {
|
|
1615
1594
|
apiPlugin.description_for_human =
|
|
1616
|
-
(
|
|
1595
|
+
(_d = spec.info.description) !== null && _d !== void 0 ? _d : "<Please add description of the plugin>";
|
|
1617
1596
|
}
|
|
1618
1597
|
if (options.allowConversationStarters && conversationStarters.length > 0) {
|
|
1619
1598
|
if (!apiPlugin.capabilities) {
|
|
@@ -1648,21 +1627,21 @@ class ManifestUpdater {
|
|
|
1648
1627
|
};
|
|
1649
1628
|
if (authInfo) {
|
|
1650
1629
|
const auth = authInfo.authScheme;
|
|
1630
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1651
1631
|
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
|
|
1652
|
-
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1632
|
+
const safeApiSecretRegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1653
1633
|
composeExtension.authorization = {
|
|
1654
1634
|
authType: "apiSecretServiceAuth",
|
|
1655
1635
|
apiSecretServiceAuthConfiguration: {
|
|
1656
|
-
apiSecretRegistrationId: `\${{${
|
|
1636
|
+
apiSecretRegistrationId: `\${{${safeRegistrationIdName}}}`,
|
|
1657
1637
|
},
|
|
1658
1638
|
};
|
|
1659
1639
|
}
|
|
1660
1640
|
else if (Utils.isOAuthWithAuthCodeFlow(auth)) {
|
|
1661
|
-
const safeOAuth2RegistrationId = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.OAuthRegistrationIdPostFix}`);
|
|
1662
1641
|
composeExtension.authorization = {
|
|
1663
1642
|
authType: "oAuth2.0",
|
|
1664
1643
|
oAuthConfiguration: {
|
|
1665
|
-
oauthConfigurationId: `\${{${
|
|
1644
|
+
oauthConfigurationId: `\${{${safeRegistrationIdName}}}`,
|
|
1666
1645
|
},
|
|
1667
1646
|
};
|
|
1668
1647
|
updatedPart.webApplicationInfo = {
|
|
@@ -1773,6 +1752,7 @@ class SpecParser {
|
|
|
1773
1752
|
allowResponseSemantics: false,
|
|
1774
1753
|
allowConfirmation: false,
|
|
1775
1754
|
projectType: exports.ProjectType.SME,
|
|
1755
|
+
isGptPlugin: false,
|
|
1776
1756
|
};
|
|
1777
1757
|
this.pathOrSpec = pathOrDoc;
|
|
1778
1758
|
this.parser = new SwaggerParser__default['default']();
|