@microsoft/m365-spec-parser 0.2.6-beta.2025022507.0 → 0.2.6-rc.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 +36 -1
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +88 -9
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +36 -1
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +89 -8
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/interfaces.d.ts +6 -1
- package/dist/src/specParser.d.ts +3 -2
- package/dist/src/utils.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.esm2017.mjs
CHANGED
|
@@ -47,6 +47,7 @@ var ErrorType;
|
|
|
47
47
|
ErrorType["UrlPathNotExist"] = "url-path-not-exist";
|
|
48
48
|
ErrorType["Cancelled"] = "cancelled";
|
|
49
49
|
ErrorType["Unknown"] = "unknown";
|
|
50
|
+
ErrorType["AddAuthFailed"] = "add-auth-failed";
|
|
50
51
|
})(ErrorType || (ErrorType = {}));
|
|
51
52
|
/**
|
|
52
53
|
* An enum that represents the types of warnings that can occur during validation.
|
|
@@ -77,7 +78,12 @@ var ProjectType;
|
|
|
77
78
|
ProjectType[ProjectType["Copilot"] = 0] = "Copilot";
|
|
78
79
|
ProjectType[ProjectType["SME"] = 1] = "SME";
|
|
79
80
|
ProjectType[ProjectType["TeamsAi"] = 2] = "TeamsAi";
|
|
80
|
-
})(ProjectType || (ProjectType = {}));
|
|
81
|
+
})(ProjectType || (ProjectType = {}));
|
|
82
|
+
var AdaptiveCardUpdateStrategy;
|
|
83
|
+
(function (AdaptiveCardUpdateStrategy) {
|
|
84
|
+
AdaptiveCardUpdateStrategy[AdaptiveCardUpdateStrategy["CreateNew"] = 0] = "CreateNew";
|
|
85
|
+
AdaptiveCardUpdateStrategy[AdaptiveCardUpdateStrategy["KeepExisting"] = 1] = "KeepExisting";
|
|
86
|
+
})(AdaptiveCardUpdateStrategy || (AdaptiveCardUpdateStrategy = {}));
|
|
81
87
|
|
|
82
88
|
// Copyright (c) Microsoft Corporation.
|
|
83
89
|
class ConstantString {
|
|
@@ -578,6 +584,35 @@ class Utils {
|
|
|
578
584
|
const serverUrl = operationServer || methodServer || rootServer;
|
|
579
585
|
return serverUrl;
|
|
580
586
|
}
|
|
587
|
+
static getAuthSchemaObject(authType, authParameters) {
|
|
588
|
+
switch (authType) {
|
|
589
|
+
case "oauth":
|
|
590
|
+
case "microsoft-entra":
|
|
591
|
+
return {
|
|
592
|
+
type: "oauth2",
|
|
593
|
+
flows: {
|
|
594
|
+
authorizationCode: {
|
|
595
|
+
authorizationUrl: authParameters.authorizationUrl,
|
|
596
|
+
tokenUrl: authParameters.tokenUrl,
|
|
597
|
+
refreshUrl: authParameters.refreshUrl,
|
|
598
|
+
scopes: authParameters.scopes,
|
|
599
|
+
},
|
|
600
|
+
},
|
|
601
|
+
};
|
|
602
|
+
case "api-key":
|
|
603
|
+
return {
|
|
604
|
+
type: "apiKey",
|
|
605
|
+
in: authParameters.in,
|
|
606
|
+
name: authParameters.name,
|
|
607
|
+
};
|
|
608
|
+
case "bearer-token":
|
|
609
|
+
default:
|
|
610
|
+
return {
|
|
611
|
+
type: "http",
|
|
612
|
+
scheme: "bearer",
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
}
|
|
581
616
|
}
|
|
582
617
|
|
|
583
618
|
// Copyright (c) Microsoft Corporation.
|
|
@@ -2198,6 +2233,39 @@ class SpecParser {
|
|
|
2198
2233
|
async listSupportedAPIInfo() {
|
|
2199
2234
|
throw new Error("Method not implemented.");
|
|
2200
2235
|
}
|
|
2236
|
+
async addAuthScheme(authName, authType, authParameters, signal) {
|
|
2237
|
+
try {
|
|
2238
|
+
await this.loadSpec();
|
|
2239
|
+
const spec = this.spec;
|
|
2240
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
2241
|
+
throw new SpecParserError(ConstantString.CancelledMessage, ErrorType.Cancelled);
|
|
2242
|
+
}
|
|
2243
|
+
if (!spec.components) {
|
|
2244
|
+
spec.components = {};
|
|
2245
|
+
}
|
|
2246
|
+
if (!spec.components.securitySchemes) {
|
|
2247
|
+
spec.components.securitySchemes = {};
|
|
2248
|
+
}
|
|
2249
|
+
spec.components.securitySchemes[authName] = Utils.getAuthSchemaObject(authType, authParameters);
|
|
2250
|
+
const paths = spec.paths;
|
|
2251
|
+
for (const path in paths) {
|
|
2252
|
+
const methods = paths[path];
|
|
2253
|
+
for (const method in methods) {
|
|
2254
|
+
const operationId = methods[method].operationId;
|
|
2255
|
+
if (authParameters.apis.includes(operationId)) {
|
|
2256
|
+
methods[method].security = [{ [authName]: [] }];
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
await this.saveFilterSpec(this.pathOrSpec, this.spec);
|
|
2261
|
+
}
|
|
2262
|
+
catch (err) {
|
|
2263
|
+
if (err instanceof SpecParserError) {
|
|
2264
|
+
throw err;
|
|
2265
|
+
}
|
|
2266
|
+
throw new SpecParserError(err.toString(), ErrorType.AddAuthFailed);
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2201
2269
|
/**
|
|
2202
2270
|
* Lists all the OpenAPI operations in the specification file.
|
|
2203
2271
|
* @returns A string array that represents the HTTP method and path of each operation, such as ['GET /pets/{petId}', 'GET /user/{userId}']
|
|
@@ -2309,7 +2377,7 @@ class SpecParser {
|
|
|
2309
2377
|
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
2310
2378
|
* @param pluginFilePath File path of the api plugin file to generate.
|
|
2311
2379
|
*/
|
|
2312
|
-
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, existingPluginFilePath, signal) {
|
|
2380
|
+
async generateForCopilot(manifestPath, filter, outputSpecPath, pluginFilePath, existingPluginFilePath, signal, adaptiveCardUpdateStrategy) {
|
|
2313
2381
|
const result = {
|
|
2314
2382
|
allSuccess: true,
|
|
2315
2383
|
warnings: [],
|
|
@@ -2355,7 +2423,7 @@ class SpecParser {
|
|
|
2355
2423
|
: undefined;
|
|
2356
2424
|
const authMap = Utils.getAuthMap(newSpec);
|
|
2357
2425
|
const [updatedManifest, apiPlugin, warnings, jsonDataSet] = await ManifestUpdater.updateManifestWithAiPlugin(manifestPath, outputSpecPath, pluginFilePath, newSpec, this.options, authMap, existingPluginManifestInfo);
|
|
2358
|
-
await this.separateAdaptiveCards(apiPlugin, pluginFilePath, jsonDataSet);
|
|
2426
|
+
await this.separateAdaptiveCards(apiPlugin, pluginFilePath, jsonDataSet, adaptiveCardUpdateStrategy);
|
|
2359
2427
|
result.warnings.push(...warnings);
|
|
2360
2428
|
await fs.outputJSON(manifestPath, updatedManifest, { spaces: 4 });
|
|
2361
2429
|
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|
|
@@ -2486,9 +2554,12 @@ class SpecParser {
|
|
|
2486
2554
|
await this.separateAdaptiveCards(apiPlugin, pluginFilePath, jsonDataSet);
|
|
2487
2555
|
await fs.outputJSON(pluginFilePath, apiPlugin, { spaces: 4 });
|
|
2488
2556
|
}
|
|
2489
|
-
async separateAdaptiveCards(apiPlugin, pluginFilePath, jsonDataSet = {}) {
|
|
2557
|
+
async separateAdaptiveCards(apiPlugin, pluginFilePath, jsonDataSet = {}, adaptiveCardUpdateStrategy) {
|
|
2490
2558
|
var _a, _b;
|
|
2491
2559
|
const functions = apiPlugin.functions;
|
|
2560
|
+
if (!adaptiveCardUpdateStrategy) {
|
|
2561
|
+
adaptiveCardUpdateStrategy = AdaptiveCardUpdateStrategy.CreateNew;
|
|
2562
|
+
}
|
|
2492
2563
|
if (functions) {
|
|
2493
2564
|
const adaptiveCardFolder = path.join(path.dirname(pluginFilePath), "adaptiveCards");
|
|
2494
2565
|
for (const func of functions) {
|
|
@@ -2496,12 +2567,20 @@ class SpecParser {
|
|
|
2496
2567
|
const responseSemantic = func.capabilities.response_semantics;
|
|
2497
2568
|
const card = responseSemantic.static_template;
|
|
2498
2569
|
if (card && Object.keys(card).length !== 0) {
|
|
2499
|
-
|
|
2570
|
+
let cardName = func.name;
|
|
2571
|
+
if (adaptiveCardUpdateStrategy === AdaptiveCardUpdateStrategy.CreateNew) {
|
|
2572
|
+
cardName = this.findUniqueCardName(func.name, adaptiveCardFolder);
|
|
2573
|
+
}
|
|
2574
|
+
else {
|
|
2575
|
+
if (adaptiveCardUpdateStrategy === AdaptiveCardUpdateStrategy.KeepExisting &&
|
|
2576
|
+
fs.existsSync(path.join(adaptiveCardFolder, `${cardName}.json`))) {
|
|
2577
|
+
responseSemantic.static_template = { file: `adaptiveCards/${cardName}.json` };
|
|
2578
|
+
continue;
|
|
2579
|
+
}
|
|
2580
|
+
}
|
|
2500
2581
|
const cardPath = path.join(adaptiveCardFolder, `${cardName}.json`);
|
|
2501
2582
|
const dataPath = path.join(adaptiveCardFolder, `${cardName}.data.json`);
|
|
2502
|
-
responseSemantic.static_template = {
|
|
2503
|
-
file: `adaptiveCards/${cardName}.json`,
|
|
2504
|
-
};
|
|
2583
|
+
responseSemantic.static_template = { file: `adaptiveCards/${cardName}.json` };
|
|
2505
2584
|
await fs.outputJSON(cardPath, card, { spaces: 4 });
|
|
2506
2585
|
const data = (_b = jsonDataSet[cardName]) !== null && _b !== void 0 ? _b : {};
|
|
2507
2586
|
await fs.outputJSON(dataPath, data, { spaces: 4 });
|
|
@@ -2566,5 +2645,5 @@ class SpecParser {
|
|
|
2566
2645
|
}
|
|
2567
2646
|
}
|
|
2568
2647
|
|
|
2569
|
-
export { AdaptiveCardGenerator, ConstantString, ErrorType, ProjectType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
|
|
2648
|
+
export { AdaptiveCardGenerator, AdaptiveCardUpdateStrategy, ConstantString, ErrorType, ProjectType, SpecParser, SpecParserError, Utils, ValidationStatus, WarningType };
|
|
2570
2649
|
//# sourceMappingURL=index.esm2017.mjs.map
|