@microsoft/m365-spec-parser 0.2.4-alpha.ad0d7aa1a.0 → 0.2.4-alpha.db2563b3b.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 +15 -6
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +87 -56
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +15 -6
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +87 -56
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +1 -3
- package/dist/src/interfaces.d.ts +9 -0
- package/dist/src/manifestUpdater.d.ts +3 -3
- package/dist/src/utils.d.ts +2 -1
- package/package.json +3 -3
package/dist/index.node.cjs.js
CHANGED
|
@@ -156,12 +156,7 @@ ConstantString.AdaptiveCardType = "AdaptiveCard";
|
|
|
156
156
|
ConstantString.TextBlockType = "TextBlock";
|
|
157
157
|
ConstantString.ImageType = "Image";
|
|
158
158
|
ConstantString.ContainerType = "Container";
|
|
159
|
-
ConstantString.RegistrationIdPostfix =
|
|
160
|
-
apiKey: "REGISTRATION_ID",
|
|
161
|
-
oauth2: "CONFIGURATION_ID",
|
|
162
|
-
http: "REGISTRATION_ID",
|
|
163
|
-
openIdConnect: "REGISTRATION_ID",
|
|
164
|
-
};
|
|
159
|
+
ConstantString.RegistrationIdPostfix = "REGISTRATION_ID";
|
|
165
160
|
ConstantString.ResponseCodeFor20X = [
|
|
166
161
|
"200",
|
|
167
162
|
"201",
|
|
@@ -296,6 +291,20 @@ class Utils {
|
|
|
296
291
|
result.sort((a, b) => a[0].name.localeCompare(b[0].name));
|
|
297
292
|
return result;
|
|
298
293
|
}
|
|
294
|
+
static getAuthMap(spec) {
|
|
295
|
+
const authMap = {};
|
|
296
|
+
for (const url in spec.paths) {
|
|
297
|
+
for (const method in spec.paths[url]) {
|
|
298
|
+
const operation = spec.paths[url][method];
|
|
299
|
+
const authArray = Utils.getAuthArray(operation.security, spec);
|
|
300
|
+
if (authArray && authArray.length > 0) {
|
|
301
|
+
const currentAuth = authArray[0][0];
|
|
302
|
+
authMap[operation.operationId] = currentAuth;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return authMap;
|
|
307
|
+
}
|
|
299
308
|
static getAuthInfo(spec) {
|
|
300
309
|
let authInfo = undefined;
|
|
301
310
|
for (const url in spec.paths) {
|
|
@@ -1720,7 +1729,7 @@ function inferProperties(card) {
|
|
|
1720
1729
|
|
|
1721
1730
|
// Copyright (c) Microsoft Corporation.
|
|
1722
1731
|
class ManifestUpdater {
|
|
1723
|
-
static updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options,
|
|
1732
|
+
static updateManifestWithAiPlugin(manifestPath, outputSpecPath, apiPluginFilePath, spec, options, authMap, existingPluginManifestInfo) {
|
|
1724
1733
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1725
1734
|
const manifest = yield fs__default['default'].readJSON(manifestPath);
|
|
1726
1735
|
const apiPluginRelativePath = ManifestUpdater.getRelativePath(manifestPath, apiPluginFilePath);
|
|
@@ -1751,7 +1760,7 @@ class ManifestUpdater {
|
|
|
1751
1760
|
}
|
|
1752
1761
|
const appName = this.removeEnvs(manifest.name.short);
|
|
1753
1762
|
const specRelativePath = ManifestUpdater.getRelativePath(manifestPath, outputSpecPath);
|
|
1754
|
-
const [apiPlugin, warnings] = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName,
|
|
1763
|
+
const [apiPlugin, warnings] = yield ManifestUpdater.generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authMap, options, existingPluginManifestInfo);
|
|
1755
1764
|
return [manifest, apiPlugin, warnings];
|
|
1756
1765
|
});
|
|
1757
1766
|
}
|
|
@@ -1774,29 +1783,14 @@ class ManifestUpdater {
|
|
|
1774
1783
|
throw new SpecParserError(Utils.format(ConstantString.UnsupportedSchema, method, pathUrl, JSON.stringify(schema)), exports.ErrorType.UpdateManifestFailed);
|
|
1775
1784
|
}
|
|
1776
1785
|
}
|
|
1777
|
-
static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName,
|
|
1786
|
+
static generatePluginManifestSchema(spec, specRelativePath, apiPluginFilePath, appName, authMap, options, existingPluginManifestInfo) {
|
|
1778
1787
|
var _a, _b, _c, _d;
|
|
1779
1788
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1780
1789
|
const warnings = [];
|
|
1781
1790
|
const functions = [];
|
|
1782
|
-
const
|
|
1791
|
+
const functionNamesMap = {};
|
|
1783
1792
|
const conversationStarters = [];
|
|
1784
1793
|
const paths = spec.paths;
|
|
1785
|
-
const pluginAuthObj = {
|
|
1786
|
-
type: "None",
|
|
1787
|
-
};
|
|
1788
|
-
if (authInfo) {
|
|
1789
|
-
if (Utils.isOAuthWithAuthCodeFlow(authInfo.authScheme)) {
|
|
1790
|
-
pluginAuthObj.type = "OAuthPluginVault";
|
|
1791
|
-
}
|
|
1792
|
-
else if (Utils.isBearerTokenAuth(authInfo.authScheme)) {
|
|
1793
|
-
pluginAuthObj.type = "ApiKeyPluginVault";
|
|
1794
|
-
}
|
|
1795
|
-
if (pluginAuthObj.type !== "None") {
|
|
1796
|
-
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`);
|
|
1797
|
-
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
|
|
1798
|
-
}
|
|
1799
|
-
}
|
|
1800
1794
|
for (const pathUrl in paths) {
|
|
1801
1795
|
const pathItem = paths[pathUrl];
|
|
1802
1796
|
if (pathItem) {
|
|
@@ -1879,7 +1873,28 @@ class ManifestUpdater {
|
|
|
1879
1873
|
}
|
|
1880
1874
|
}
|
|
1881
1875
|
functions.push(funcObj);
|
|
1882
|
-
|
|
1876
|
+
const authInfo = authMap[operationId];
|
|
1877
|
+
let key = "None";
|
|
1878
|
+
let authName = "None";
|
|
1879
|
+
if (authInfo) {
|
|
1880
|
+
if (Utils.isOAuthWithAuthCodeFlow(authInfo.authScheme)) {
|
|
1881
|
+
key = "OAuthPluginVault";
|
|
1882
|
+
authName = authInfo.name;
|
|
1883
|
+
}
|
|
1884
|
+
else if (Utils.isBearerTokenAuth(authInfo.authScheme)) {
|
|
1885
|
+
key = "ApiKeyPluginVault";
|
|
1886
|
+
authName = authInfo.name;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
if (functionNamesMap[key]) {
|
|
1890
|
+
functionNamesMap[key].functionNames.push(safeFunctionName);
|
|
1891
|
+
}
|
|
1892
|
+
else {
|
|
1893
|
+
functionNamesMap[key] = {
|
|
1894
|
+
functionNames: [safeFunctionName],
|
|
1895
|
+
authName: authName,
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1883
1898
|
const conversationStarterStr = (summary !== null && summary !== void 0 ? summary : description).slice(0, ConstantString.ConversationStarterMaxLens);
|
|
1884
1899
|
if (conversationStarterStr) {
|
|
1885
1900
|
conversationStarters.push(conversationStarterStr);
|
|
@@ -1889,6 +1904,12 @@ class ManifestUpdater {
|
|
|
1889
1904
|
}
|
|
1890
1905
|
}
|
|
1891
1906
|
}
|
|
1907
|
+
if (Object.keys(functionNamesMap).length === 0) {
|
|
1908
|
+
functionNamesMap["None"] = {
|
|
1909
|
+
functionNames: [],
|
|
1910
|
+
authName: "None",
|
|
1911
|
+
};
|
|
1912
|
+
}
|
|
1892
1913
|
let apiPlugin;
|
|
1893
1914
|
if (yield fs__default['default'].pathExists(apiPluginFilePath)) {
|
|
1894
1915
|
apiPlugin = yield fs__default['default'].readJSON(apiPluginFilePath);
|
|
@@ -1924,24 +1945,35 @@ class ManifestUpdater {
|
|
|
1924
1945
|
const relativePath = ManifestUpdater.getRelativePath(existingPluginManifestInfo.manifestPath, existingPluginManifestInfo.specPath);
|
|
1925
1946
|
apiPlugin.runtimes = apiPlugin.runtimes.filter((runtime) => runtime.spec.url !== relativePath);
|
|
1926
1947
|
}
|
|
1927
|
-
const
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1948
|
+
for (const authType in functionNamesMap) {
|
|
1949
|
+
const pluginAuthObj = {
|
|
1950
|
+
type: authType,
|
|
1951
|
+
};
|
|
1952
|
+
const authName = functionNamesMap[authType].authName;
|
|
1953
|
+
if (pluginAuthObj.type !== "None") {
|
|
1954
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authName}_${ConstantString.RegistrationIdPostfix}`);
|
|
1955
|
+
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
|
|
1956
|
+
}
|
|
1957
|
+
const functionNamesInfo = functionNamesMap[authType];
|
|
1958
|
+
const index = apiPlugin.runtimes.findIndex((runtime) => {
|
|
1959
|
+
var _a, _b;
|
|
1960
|
+
return runtime.spec.url === specRelativePath &&
|
|
1961
|
+
runtime.type === "OpenApi" &&
|
|
1962
|
+
((_b = (_a = runtime.auth) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : "None") === authType;
|
|
1941
1963
|
});
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1964
|
+
if (index === -1) {
|
|
1965
|
+
apiPlugin.runtimes.push({
|
|
1966
|
+
type: "OpenApi",
|
|
1967
|
+
auth: pluginAuthObj,
|
|
1968
|
+
spec: {
|
|
1969
|
+
url: specRelativePath,
|
|
1970
|
+
},
|
|
1971
|
+
run_for_functions: functionNamesInfo.functionNames,
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
else {
|
|
1975
|
+
apiPlugin.runtimes[index].run_for_functions = functionNamesInfo.functionNames;
|
|
1976
|
+
}
|
|
1945
1977
|
}
|
|
1946
1978
|
if (!apiPlugin.name_for_human) {
|
|
1947
1979
|
apiPlugin.name_for_human = appName;
|
|
@@ -1984,7 +2016,7 @@ class ManifestUpdater {
|
|
|
1984
2016
|
};
|
|
1985
2017
|
if (authInfo) {
|
|
1986
2018
|
const auth = authInfo.authScheme;
|
|
1987
|
-
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix
|
|
2019
|
+
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(`${authInfo.name}_${ConstantString.RegistrationIdPostfix}`);
|
|
1988
2020
|
if (Utils.isAPIKeyAuth(auth) || Utils.isBearerTokenAuth(auth)) {
|
|
1989
2021
|
composeExtension.authorization = {
|
|
1990
2022
|
authType: "apiSecretServiceAuth",
|
|
@@ -2323,13 +2355,21 @@ class SpecParser {
|
|
|
2323
2355
|
const newSpecs = yield this.getFilteredSpecs(filter, signal);
|
|
2324
2356
|
const newUnResolvedSpec = newSpecs[0];
|
|
2325
2357
|
const newSpec = newSpecs[1];
|
|
2326
|
-
const authInfo = Utils.getAuthInfo(newSpec);
|
|
2327
2358
|
const paths = newUnResolvedSpec.paths;
|
|
2328
2359
|
for (const pathUrl in paths) {
|
|
2329
2360
|
const operations = paths[pathUrl];
|
|
2330
2361
|
for (const method in operations) {
|
|
2331
2362
|
const operationItem = operations[method];
|
|
2332
2363
|
const operationId = operationItem.operationId;
|
|
2364
|
+
const containsSpecialCharacters = /[^a-zA-Z0-9_]/.test(operationId);
|
|
2365
|
+
if (containsSpecialCharacters) {
|
|
2366
|
+
operationItem.operationId = operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2367
|
+
result.warnings.push({
|
|
2368
|
+
type: exports.WarningType.OperationIdContainsSpecialCharacters,
|
|
2369
|
+
content: Utils.format(ConstantString.OperationIdContainsSpecialCharacters, operationId, operationItem.operationId),
|
|
2370
|
+
data: operationId,
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2333
2373
|
const authArray = Utils.getAuthArray(operationItem.security, newSpec);
|
|
2334
2374
|
if (Utils.isNotSupportedAuth(authArray)) {
|
|
2335
2375
|
result.warnings.push({
|
|
@@ -2338,16 +2378,6 @@ class SpecParser {
|
|
|
2338
2378
|
data: operationId,
|
|
2339
2379
|
});
|
|
2340
2380
|
}
|
|
2341
|
-
const containsSpecialCharacters = /[^a-zA-Z0-9_]/.test(operationId);
|
|
2342
|
-
if (!containsSpecialCharacters) {
|
|
2343
|
-
continue;
|
|
2344
|
-
}
|
|
2345
|
-
operationItem.operationId = operationId.replace(/[^a-zA-Z0-9]/g, "_");
|
|
2346
|
-
result.warnings.push({
|
|
2347
|
-
type: exports.WarningType.OperationIdContainsSpecialCharacters,
|
|
2348
|
-
content: Utils.format(ConstantString.OperationIdContainsSpecialCharacters, operationId, operationItem.operationId),
|
|
2349
|
-
data: operationId,
|
|
2350
|
-
});
|
|
2351
2381
|
}
|
|
2352
2382
|
}
|
|
2353
2383
|
yield this.saveFilterSpec(outputSpecPath, newUnResolvedSpec);
|
|
@@ -2360,7 +2390,8 @@ class SpecParser {
|
|
|
2360
2390
|
specPath: this.pathOrSpec,
|
|
2361
2391
|
}
|
|
2362
2392
|
: undefined;
|
|
2363
|
-
const
|
|
2393
|
+
const authMap = Utils.getAuthMap(newSpec);
|
|
2394
|
+
const [updatedManifest, apiPlugin, warnings] = yield ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options, authMap, existingPluginManifestInfo);
|
|
2364
2395
|
result.warnings.push(...warnings);
|
|
2365
2396
|
yield fs__default['default'].outputJSON(manifestPath, updatedManifest, { spaces: 4 });
|
|
2366
2397
|
yield fs__default['default'].outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|