@microsoft/m365-spec-parser 0.1.1-alpha.78701ec6a.0 → 0.1.1-alpha.a277dba4e.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 +317 -67
- package/dist/index.esm2017.js.map +1 -1
- package/dist/index.esm2017.mjs +427 -150
- package/dist/index.esm2017.mjs.map +1 -1
- package/dist/index.esm5.js +321 -67
- package/dist/index.esm5.js.map +1 -1
- package/dist/index.node.cjs.js +433 -149
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/src/constants.d.ts +5 -1
- package/dist/src/index.browser.d.ts +2 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/interfaces.d.ts +47 -18
- package/dist/src/manifestUpdater.d.ts +8 -4
- package/dist/src/specFilter.d.ts +2 -1
- package/dist/src/specParser.browser.d.ts +15 -1
- package/dist/src/specParser.d.ts +15 -2
- package/dist/src/utils.d.ts +20 -16
- package/package.json +4 -4
package/dist/src/interfaces.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IParameter } from "@microsoft/teams-manifest";
|
|
1
2
|
import { OpenAPIV3 } from "openapi-types";
|
|
2
3
|
/**
|
|
3
4
|
* An interface that represents the result of validating an OpenAPI specification file.
|
|
@@ -67,7 +68,8 @@ export declare enum ErrorType {
|
|
|
67
68
|
NoExtraAPICanBeAdded = "no-extra-api-can-be-added",
|
|
68
69
|
ResolveServerUrlFailed = "resolve-server-url-failed",
|
|
69
70
|
SwaggerNotSupported = "swagger-not-supported",
|
|
70
|
-
|
|
71
|
+
MultipleAuthNotSupported = "multiple-auth-not-supported",
|
|
72
|
+
SpecVersionNotSupported = "spec-version-not-supported",
|
|
71
73
|
ListFailed = "list-failed",
|
|
72
74
|
listSupportedAPIInfoFailed = "list-supported-api-info-failed",
|
|
73
75
|
FilterSpecFailed = "filter-spec-failed",
|
|
@@ -75,6 +77,7 @@ export declare enum ErrorType {
|
|
|
75
77
|
GenerateAdaptiveCardFailed = "generate-adaptive-card-failed",
|
|
76
78
|
GenerateFailed = "generate-failed",
|
|
77
79
|
ValidateFailed = "validate-failed",
|
|
80
|
+
GetSpecFailed = "get-spec-failed",
|
|
78
81
|
Cancelled = "cancelled",
|
|
79
82
|
Unknown = "unknown"
|
|
80
83
|
}
|
|
@@ -134,46 +137,72 @@ export interface WrappedAdaptiveCard {
|
|
|
134
137
|
responseCardTemplate: AdaptiveCard;
|
|
135
138
|
previewCardTemplate: PreviewCardTemplate;
|
|
136
139
|
}
|
|
137
|
-
export interface ChoicesItem {
|
|
138
|
-
title: string;
|
|
139
|
-
value: string;
|
|
140
|
-
}
|
|
141
|
-
export interface Parameter {
|
|
142
|
-
name: string;
|
|
143
|
-
title: string;
|
|
144
|
-
description: string;
|
|
145
|
-
inputType?: "text" | "textarea" | "number" | "date" | "time" | "toggle" | "choiceset";
|
|
146
|
-
value?: string;
|
|
147
|
-
choices?: ChoicesItem[];
|
|
148
|
-
}
|
|
149
140
|
export interface CheckParamResult {
|
|
150
141
|
requiredNum: number;
|
|
151
142
|
optionalNum: number;
|
|
152
143
|
isValid: boolean;
|
|
153
144
|
}
|
|
154
145
|
export interface ParseOptions {
|
|
146
|
+
/**
|
|
147
|
+
* If true, the parser will not throw an error if an ID is missing the spec file.
|
|
148
|
+
*/
|
|
155
149
|
allowMissingId?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* If true, the parser will allow parsing of Swagger specifications.
|
|
152
|
+
*/
|
|
156
153
|
allowSwagger?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* If true, the parser will allow API Key authentication in the spec file.
|
|
156
|
+
*/
|
|
157
157
|
allowAPIKeyAuth?: boolean;
|
|
158
|
+
/**
|
|
159
|
+
* If true, the parser will allow Bearer Token authentication in the spec file.
|
|
160
|
+
*/
|
|
161
|
+
allowBearerTokenAuth?: boolean;
|
|
162
|
+
/**
|
|
163
|
+
* If true, the parser will allow multiple parameters in the spec file. Teams AI project would ignore this parameters and always true
|
|
164
|
+
*/
|
|
158
165
|
allowMultipleParameters?: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* If true, the parser will allow OAuth2 authentication in the spec file. Currently only support OAuth2 with auth code flow.
|
|
168
|
+
*/
|
|
159
169
|
allowOauth2?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* An array of HTTP methods that the parser will allow in the spec file.
|
|
172
|
+
*/
|
|
173
|
+
allowMethods?: string[];
|
|
174
|
+
/**
|
|
175
|
+
* The type of project that the parser is being used for.
|
|
176
|
+
* Project can be SME/Copilot/TeamsAi
|
|
177
|
+
*/
|
|
178
|
+
projectType?: ProjectType;
|
|
179
|
+
}
|
|
180
|
+
export declare enum ProjectType {
|
|
181
|
+
Copilot = 0,
|
|
182
|
+
SME = 1,
|
|
183
|
+
TeamsAi = 2
|
|
160
184
|
}
|
|
161
185
|
export interface APIInfo {
|
|
162
186
|
method: string;
|
|
163
187
|
path: string;
|
|
164
188
|
title: string;
|
|
165
189
|
id: string;
|
|
166
|
-
parameters:
|
|
190
|
+
parameters: IParameter[];
|
|
167
191
|
description: string;
|
|
168
192
|
warning?: WarningResult;
|
|
169
193
|
}
|
|
170
|
-
export interface
|
|
194
|
+
export interface ListAPIInfo {
|
|
171
195
|
api: string;
|
|
172
196
|
server: string;
|
|
173
197
|
operationId: string;
|
|
174
|
-
auth?:
|
|
198
|
+
auth?: AuthInfo;
|
|
199
|
+
}
|
|
200
|
+
export interface ListAPIResult {
|
|
201
|
+
allAPICount: number;
|
|
202
|
+
validAPICount: number;
|
|
203
|
+
validAPIs: ListAPIInfo[];
|
|
175
204
|
}
|
|
176
|
-
export interface
|
|
177
|
-
|
|
205
|
+
export interface AuthInfo {
|
|
206
|
+
authScheme: OpenAPIV3.SecuritySchemeObject;
|
|
178
207
|
name: string;
|
|
179
208
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
-
import { WarningResult } from "./interfaces";
|
|
3
|
-
import { IMessagingExtensionCommand, TeamsAppManifest } from "@microsoft/teams-manifest";
|
|
2
|
+
import { AuthInfo, ParseOptions, WarningResult } from "./interfaces";
|
|
3
|
+
import { IMessagingExtensionCommand, TeamsAppManifest, PluginManifestSchema, FunctionParameter } from "@microsoft/teams-manifest";
|
|
4
4
|
export declare class ManifestUpdater {
|
|
5
|
-
static
|
|
6
|
-
static
|
|
5
|
+
static updateManifestWithAiPlugin(manifestPath: string, outputSpecPath: string, apiPluginFilePath: string, spec: OpenAPIV3.Document, options: ParseOptions): Promise<[TeamsAppManifest, PluginManifestSchema]>;
|
|
6
|
+
static updateManifestDescription(manifest: TeamsAppManifest, spec: OpenAPIV3.Document): void;
|
|
7
|
+
static mapOpenAPISchemaToFuncParam(schema: OpenAPIV3.SchemaObject, method: string, pathUrl: string): FunctionParameter;
|
|
8
|
+
static generatePluginManifestSchema(spec: OpenAPIV3.Document, specRelativePath: string, options: ParseOptions): PluginManifestSchema;
|
|
9
|
+
static updateManifest(manifestPath: string, outputSpecPath: string, spec: OpenAPIV3.Document, options: ParseOptions, adaptiveCardFolder?: string, authInfo?: AuthInfo): Promise<[TeamsAppManifest, WarningResult[]]>;
|
|
10
|
+
static generateCommands(spec: OpenAPIV3.Document, manifestPath: string, options: ParseOptions, adaptiveCardFolder?: string): Promise<[IMessagingExtensionCommand[], WarningResult[]]>;
|
|
7
11
|
static getRelativePath(from: string, to: string): string;
|
|
8
12
|
}
|
package/dist/src/specFilter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import { ParseOptions } from "./interfaces";
|
|
2
3
|
export declare class SpecFilter {
|
|
3
|
-
static specFilter(filter: string[], unResolveSpec: OpenAPIV3.Document, resolvedSpec: OpenAPIV3.Document,
|
|
4
|
+
static specFilter(filter: string[], unResolveSpec: OpenAPIV3.Document, resolvedSpec: OpenAPIV3.Document, options: ParseOptions): OpenAPIV3.Document;
|
|
4
5
|
}
|
|
@@ -32,14 +32,28 @@ export declare class SpecParser {
|
|
|
32
32
|
* according to copilot plugin spec, only list get and post method without auth
|
|
33
33
|
*/
|
|
34
34
|
list(): Promise<ListAPIResult[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate specs according to the filters.
|
|
37
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
38
|
+
*/
|
|
39
|
+
getFilteredSpecs(filter: string[], signal?: AbortSignal): Promise<[OpenAPIV3.Document, OpenAPIV3.Document]>;
|
|
40
|
+
/**
|
|
41
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
42
|
+
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
43
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
44
|
+
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
45
|
+
* @param pluginFilePath File path of the api plugin file to generate.
|
|
46
|
+
*/
|
|
47
|
+
generateForCopilot(manifestPath: string, filter: string[], outputSpecPath: string, pluginFilePath: string, signal?: AbortSignal): Promise<GenerateResult>;
|
|
35
48
|
/**
|
|
36
49
|
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
37
50
|
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
38
51
|
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
39
52
|
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
40
53
|
* @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
|
|
54
|
+
* @param isMe Boolean that indicates whether the project is an Messaging Extension. For Messaging Extension, composeExtensions will be added in Teams app manifest.
|
|
41
55
|
*/
|
|
42
|
-
generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder
|
|
56
|
+
generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder?: string, signal?: AbortSignal): Promise<GenerateResult>;
|
|
43
57
|
private loadSpec;
|
|
44
58
|
private getAllSupportedAPIs;
|
|
45
59
|
}
|
package/dist/src/specParser.d.ts
CHANGED
|
@@ -31,7 +31,20 @@ export declare class SpecParser {
|
|
|
31
31
|
* @returns A string array that represents the HTTP method and path of each operation, such as ['GET /pets/{petId}', 'GET /user/{userId}']
|
|
32
32
|
* according to copilot plugin spec, only list get and post method without auth
|
|
33
33
|
*/
|
|
34
|
-
list(): Promise<ListAPIResult
|
|
34
|
+
list(): Promise<ListAPIResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Generate specs according to the filters.
|
|
37
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
38
|
+
*/
|
|
39
|
+
getFilteredSpecs(filter: string[], signal?: AbortSignal): Promise<[OpenAPIV3.Document, OpenAPIV3.Document]>;
|
|
40
|
+
/**
|
|
41
|
+
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
42
|
+
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
43
|
+
* @param filter An array of strings that represent the filters to apply when generating the artifacts. If filter is empty, it would process nothing.
|
|
44
|
+
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
45
|
+
* @param pluginFilePath File path of the api plugin file to generate.
|
|
46
|
+
*/
|
|
47
|
+
generateForCopilot(manifestPath: string, filter: string[], outputSpecPath: string, pluginFilePath: string, signal?: AbortSignal): Promise<GenerateResult>;
|
|
35
48
|
/**
|
|
36
49
|
* Generates and update artifacts from the OpenAPI specification file. Generate Adaptive Cards, update Teams app manifest, and generate a new OpenAPI specification file.
|
|
37
50
|
* @param manifestPath A file path of the Teams app manifest file to update.
|
|
@@ -39,7 +52,7 @@ export declare class SpecParser {
|
|
|
39
52
|
* @param outputSpecPath File path of the new OpenAPI specification file to generate. If not specified or empty, no spec file will be generated.
|
|
40
53
|
* @param adaptiveCardFolder Folder path where the Adaptive Card files will be generated. If not specified or empty, Adaptive Card files will not be generated.
|
|
41
54
|
*/
|
|
42
|
-
generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder
|
|
55
|
+
generate(manifestPath: string, filter: string[], outputSpecPath: string, adaptiveCardFolder?: string, signal?: AbortSignal): Promise<GenerateResult>;
|
|
43
56
|
private loadSpec;
|
|
44
57
|
private getAllSupportedAPIs;
|
|
45
58
|
}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { OpenAPIV3 } from "openapi-types";
|
|
2
2
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
3
|
-
import {
|
|
4
|
-
import { IMessagingExtensionCommand } from "@microsoft/teams-manifest";
|
|
3
|
+
import { AuthInfo, CheckParamResult, ErrorResult, ParseOptions, ValidateResult, WarningResult } from "./interfaces";
|
|
4
|
+
import { IMessagingExtensionCommand, IParameter } from "@microsoft/teams-manifest";
|
|
5
5
|
export declare class Utils {
|
|
6
|
-
static
|
|
7
|
-
static
|
|
6
|
+
static hasNestedObjectInSchema(schema: OpenAPIV3.SchemaObject): boolean;
|
|
7
|
+
static checkParameters(paramObject: OpenAPIV3.ParameterObject[], isCopilot: boolean): CheckParamResult;
|
|
8
|
+
static checkPostBody(schema: OpenAPIV3.SchemaObject, isRequired?: boolean, isCopilot?: boolean): CheckParamResult;
|
|
9
|
+
static containMultipleMediaTypes(bodyObject: OpenAPIV3.RequestBodyObject | OpenAPIV3.ResponseObject): boolean;
|
|
8
10
|
/**
|
|
9
11
|
* Checks if the given API is supported.
|
|
10
12
|
* @param {string} method - The HTTP method of the API.
|
|
@@ -19,26 +21,28 @@ export declare class Utils {
|
|
|
19
21
|
* 5. response body should be “application/json” and not empty, and response code should be 20X
|
|
20
22
|
* 6. only support request body with “application/json” content type
|
|
21
23
|
*/
|
|
22
|
-
static isSupportedApi(method: string, path: string, spec: OpenAPIV3.Document,
|
|
23
|
-
static isSupportedAuth(
|
|
24
|
-
static
|
|
25
|
-
static
|
|
26
|
-
static
|
|
24
|
+
static isSupportedApi(method: string, path: string, spec: OpenAPIV3.Document, options: ParseOptions): boolean;
|
|
25
|
+
static isSupportedAuth(authSchemeArray: AuthInfo[][], options: ParseOptions): boolean;
|
|
26
|
+
static isBearerTokenAuth(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
|
|
27
|
+
static isAPIKeyAuth(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
|
|
28
|
+
static isOAuthWithAuthCodeFlow(authScheme: OpenAPIV3.SecuritySchemeObject): boolean;
|
|
29
|
+
static getAuthArray(securities: OpenAPIV3.SecurityRequirementObject[] | undefined, spec: OpenAPIV3.Document): AuthInfo[][];
|
|
27
30
|
static updateFirstLetter(str: string): string;
|
|
28
|
-
static getResponseJson(operationObject: OpenAPIV3.OperationObject | undefined): OpenAPIV3.MediaTypeObject;
|
|
31
|
+
static getResponseJson(operationObject: OpenAPIV3.OperationObject | undefined, isTeamsAiProject?: boolean): OpenAPIV3.MediaTypeObject;
|
|
29
32
|
static convertPathToCamelCase(path: string): string;
|
|
30
33
|
static getUrlProtocol(urlString: string): string | undefined;
|
|
31
34
|
static resolveServerUrl(url: string): string;
|
|
32
35
|
static checkServerUrl(servers: OpenAPIV3.ServerObject[]): ErrorResult[];
|
|
33
|
-
static validateServer(spec: OpenAPIV3.Document,
|
|
36
|
+
static validateServer(spec: OpenAPIV3.Document, options: ParseOptions): ErrorResult[];
|
|
34
37
|
static isWellKnownName(name: string, wellknownNameList: string[]): boolean;
|
|
35
|
-
static generateParametersFromSchema(schema: OpenAPIV3.SchemaObject, name: string, allowMultipleParameters: boolean, isRequired?: boolean): [
|
|
36
|
-
static updateParameterWithInputType(schema: OpenAPIV3.SchemaObject, param:
|
|
37
|
-
static parseApiInfo(operationItem: OpenAPIV3.OperationObject,
|
|
38
|
-
static listSupportedAPIs(spec: OpenAPIV3.Document,
|
|
38
|
+
static generateParametersFromSchema(schema: OpenAPIV3.SchemaObject, name: string, allowMultipleParameters: boolean, isRequired?: boolean): [IParameter[], IParameter[]];
|
|
39
|
+
static updateParameterWithInputType(schema: OpenAPIV3.SchemaObject, param: IParameter): void;
|
|
40
|
+
static parseApiInfo(operationItem: OpenAPIV3.OperationObject, options: ParseOptions): [IMessagingExtensionCommand, WarningResult | undefined];
|
|
41
|
+
static listSupportedAPIs(spec: OpenAPIV3.Document, options: ParseOptions): {
|
|
39
42
|
[key: string]: OpenAPIV3.OperationObject;
|
|
40
43
|
};
|
|
41
|
-
static validateSpec(spec: OpenAPIV3.Document, parser: SwaggerParser, isSwaggerFile: boolean,
|
|
44
|
+
static validateSpec(spec: OpenAPIV3.Document, parser: SwaggerParser, isSwaggerFile: boolean, options: ParseOptions): ValidateResult;
|
|
42
45
|
static format(str: string, ...args: string[]): string;
|
|
43
46
|
static getSafeRegistrationIdEnvName(authName: string): string;
|
|
47
|
+
static getAllAPICount(spec: OpenAPIV3.Document): number;
|
|
44
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/m365-spec-parser",
|
|
3
|
-
"version": "0.1.1-alpha.
|
|
3
|
+
"version": "0.1.1-alpha.a277dba4e.0",
|
|
4
4
|
"description": "OpenAPI specification files Parser for M365 Apps",
|
|
5
5
|
"main": "dist/index.node.cjs.js",
|
|
6
6
|
"browser": "dist/index.esm2017.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"types": "dist/src/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "rollup -c",
|
|
12
|
-
"test:unit:node": "nyc --no-clean -- mocha
|
|
12
|
+
"test:unit:node": "nyc --no-clean -- mocha -r config/mocha.env.ts --config config/.mocharc.json",
|
|
13
13
|
"test:unit:browser": "karma start karma.conf.cjs --single-run --unit",
|
|
14
14
|
"test:unit": "npm run test:unit:node && npm run test:unit:browser ",
|
|
15
15
|
"lint:staged": "lint-staged",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"sideEffects": false,
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
42
|
-
"@microsoft/teams-manifest": "0.1.4-alpha.
|
|
42
|
+
"@microsoft/teams-manifest": "0.1.4-alpha.a277dba4e.0",
|
|
43
43
|
"fs-extra": "^11.2.0",
|
|
44
44
|
"js-yaml": "^4.1.0",
|
|
45
45
|
"openapi-types": "^7.2.3",
|
|
@@ -148,5 +148,5 @@
|
|
|
148
148
|
"npx eslint --cache --fix --quiet"
|
|
149
149
|
]
|
|
150
150
|
},
|
|
151
|
-
"gitHead": "
|
|
151
|
+
"gitHead": "fc43da6bdf04948555fc8c425324b475cc05bb95"
|
|
152
152
|
}
|