@postman-enricher/shared 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Caio Pizzol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './matcher.js';
3
+ export * from './walker.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './matcher.js';
3
+ export * from './walker.js';
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Endpoint matching utilities for filtering
3
+ */
4
+ /**
5
+ * Normalize a path for comparison
6
+ * Converts various path formats to a consistent format for matching
7
+ * @param path - URL path to normalize
8
+ * @param rules - Optional normalization rules mapping
9
+ * @returns Normalized path
10
+ */
11
+ export declare function normalizePath(path: string, rules?: Record<string, string>): string;
12
+ /**
13
+ * Check if an endpoint matches based on method and path
14
+ * @param method - HTTP method
15
+ * @param path - URL path
16
+ * @param endpoints - Map of endpoints to include
17
+ * @param rules - Optional normalization rules
18
+ * @returns True if endpoint should be included
19
+ */
20
+ export declare function shouldIncludeEndpoint(method: string, path: string, endpoints: Record<string, boolean>, rules?: Record<string, string>): boolean;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Endpoint matching utilities for filtering
3
+ */
4
+ /**
5
+ * Normalize a path for comparison
6
+ * Converts various path formats to a consistent format for matching
7
+ * @param path - URL path to normalize
8
+ * @param rules - Optional normalization rules mapping
9
+ * @returns Normalized path
10
+ */
11
+ export function normalizePath(path, rules = {}) {
12
+ let normalized = path.replace(/:(\w+)/g, ':$1'); // Keep :param format as is
13
+ // Apply custom normalization rules if provided
14
+ normalized = normalized.replace(/\{[^}]+\}/g, (match) => {
15
+ // Check custom rules first
16
+ for (const [pattern, replacement] of Object.entries(rules)) {
17
+ if (match.includes(pattern)) {
18
+ return replacement;
19
+ }
20
+ }
21
+ // Default: remove braces and keep content
22
+ return ':' + match.slice(1, -1);
23
+ });
24
+ return normalized;
25
+ }
26
+ /**
27
+ * Check if an endpoint matches based on method and path
28
+ * @param method - HTTP method
29
+ * @param path - URL path
30
+ * @param endpoints - Map of endpoints to include
31
+ * @param rules - Optional normalization rules
32
+ * @returns True if endpoint should be included
33
+ */
34
+ export function shouldIncludeEndpoint(method, path, endpoints, rules = {}) {
35
+ const normalizedPath = normalizePath(path, rules);
36
+ const endpointKey = `${method} ${normalizedPath}`;
37
+ return endpoints[endpointKey] || false;
38
+ }
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Postman Collection Types
3
+ */
4
+ export interface PostmanUrl {
5
+ raw?: string;
6
+ protocol?: string;
7
+ host?: string | string[];
8
+ path?: string | string[];
9
+ query?: PostmanQueryParam[];
10
+ variable?: PostmanVariable[];
11
+ }
12
+ export interface PostmanQueryParam {
13
+ key: string;
14
+ value: string;
15
+ disabled?: boolean;
16
+ description?: string | {
17
+ content: string;
18
+ type: string;
19
+ };
20
+ }
21
+ export interface PostmanVariable {
22
+ key: string;
23
+ value: string;
24
+ type?: string;
25
+ disabled?: boolean;
26
+ description?: string | {
27
+ content: string;
28
+ type: string;
29
+ };
30
+ }
31
+ export interface PostmanHeader {
32
+ key: string;
33
+ value: string;
34
+ disabled?: boolean;
35
+ description?: string | {
36
+ content: string;
37
+ type: string;
38
+ };
39
+ }
40
+ export interface PostmanBody {
41
+ mode: string;
42
+ raw?: string;
43
+ options?: {
44
+ raw?: {
45
+ language?: string;
46
+ headerFamily?: string;
47
+ };
48
+ };
49
+ }
50
+ export interface PostmanRequest {
51
+ name: string;
52
+ description?: string;
53
+ url: PostmanUrl;
54
+ method: string;
55
+ header?: PostmanHeader[];
56
+ body?: PostmanBody;
57
+ auth?: any;
58
+ }
59
+ export interface PostmanResponse {
60
+ id?: string;
61
+ name: string;
62
+ originalRequest?: PostmanRequest;
63
+ status: string;
64
+ code: number;
65
+ header?: PostmanHeader[];
66
+ body?: string;
67
+ _postman_previewlanguage?: string;
68
+ }
69
+ export interface PostmanItem {
70
+ id?: string;
71
+ name: string;
72
+ description?: string;
73
+ item?: PostmanItem[];
74
+ request?: PostmanRequest;
75
+ response?: PostmanResponse[];
76
+ event?: PostmanEvent[];
77
+ }
78
+ export interface PostmanEvent {
79
+ listen: string;
80
+ script: {
81
+ type: string;
82
+ exec: string[];
83
+ };
84
+ }
85
+ export interface PostmanInfo {
86
+ name: string;
87
+ description?: string;
88
+ schema: string;
89
+ _postman_id?: string;
90
+ }
91
+ export interface PostmanCollection {
92
+ info: PostmanInfo;
93
+ item: PostmanItem[];
94
+ variable?: PostmanVariable[];
95
+ event?: PostmanEvent[];
96
+ }
97
+ /**
98
+ * Configuration Types
99
+ */
100
+ export interface FilterConfig {
101
+ include?: Record<string, boolean>;
102
+ note?: string;
103
+ normalizationRules?: Record<string, string>;
104
+ }
105
+ export interface DescriptionConfig {
106
+ collection?: Record<string, {
107
+ name?: string;
108
+ description?: string;
109
+ }>;
110
+ folders?: Record<string, string>;
111
+ requests?: Record<string, string>;
112
+ }
113
+ export interface ExampleResponse {
114
+ name: string;
115
+ status: string;
116
+ code: number;
117
+ body?: any;
118
+ }
119
+ export interface ExampleConfig {
120
+ requests?: Record<string, {
121
+ body?: any;
122
+ }>;
123
+ responses?: Record<string, ExampleResponse>;
124
+ }
125
+ export interface VariableConfig {
126
+ path?: Record<string, string>;
127
+ query?: Record<string, string>;
128
+ environment?: Record<string, string>;
129
+ descriptions?: Record<string, string>;
130
+ baseUrlVar?: string;
131
+ }
132
+ export interface TestConfig {
133
+ auto?: boolean;
134
+ }
135
+ export interface EnrichmentConfig {
136
+ filter?: FilterConfig;
137
+ descriptions?: DescriptionConfig;
138
+ examples?: ExampleConfig;
139
+ variables?: VariableConfig;
140
+ tests?: TestConfig;
141
+ }
package/dist/types.js ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Postman Collection Types
3
+ */
4
+ export {};
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Collection traversal utilities
3
+ * Provides a single, reusable way to walk through Postman collection items
4
+ */
5
+ import type { PostmanItem, PostmanUrl } from './types.js';
6
+ /**
7
+ * Walk through all items in a collection recursively
8
+ * @param items - Collection items (requests and folders)
9
+ * @param handler - Function called for each item
10
+ */
11
+ export declare function walkCollection(items: PostmanItem[] | undefined, handler: (item: PostmanItem) => void): void;
12
+ /**
13
+ * Check if an item is a request (not a folder)
14
+ * @param item - Collection item
15
+ * @returns True if item is a request
16
+ */
17
+ export declare function isRequest(item: PostmanItem): boolean;
18
+ /**
19
+ * Check if an item is a folder
20
+ * @param item - Collection item
21
+ * @returns True if item is a folder
22
+ */
23
+ export declare function isFolder(item: PostmanItem): boolean;
24
+ /**
25
+ * Get the HTTP method from a request item
26
+ * @param item - Request item
27
+ * @returns HTTP method (GET, POST, etc.)
28
+ */
29
+ export declare function getRequestMethod(item: PostmanItem): string;
30
+ /**
31
+ * Extract the path from a Postman URL object
32
+ * @param url - Postman URL object or string
33
+ * @returns Path portion of the URL
34
+ */
35
+ export declare function getUrlPath(url: PostmanUrl | string): string;
package/dist/walker.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Collection traversal utilities
3
+ * Provides a single, reusable way to walk through Postman collection items
4
+ */
5
+ /**
6
+ * Walk through all items in a collection recursively
7
+ * @param items - Collection items (requests and folders)
8
+ * @param handler - Function called for each item
9
+ */
10
+ export function walkCollection(items, handler) {
11
+ if (!items || !Array.isArray(items))
12
+ return;
13
+ items.forEach((item) => {
14
+ // Call handler for this item
15
+ handler(item);
16
+ // Recurse into nested items (folders)
17
+ if (item.item && Array.isArray(item.item)) {
18
+ walkCollection(item.item, handler);
19
+ }
20
+ });
21
+ }
22
+ /**
23
+ * Check if an item is a request (not a folder)
24
+ * @param item - Collection item
25
+ * @returns True if item is a request
26
+ */
27
+ export function isRequest(item) {
28
+ return !!item.request;
29
+ }
30
+ /**
31
+ * Check if an item is a folder
32
+ * @param item - Collection item
33
+ * @returns True if item is a folder
34
+ */
35
+ export function isFolder(item) {
36
+ return !!item.item && !item.request;
37
+ }
38
+ /**
39
+ * Get the HTTP method from a request item
40
+ * @param item - Request item
41
+ * @returns HTTP method (GET, POST, etc.)
42
+ */
43
+ export function getRequestMethod(item) {
44
+ return item.request?.method || 'GET';
45
+ }
46
+ /**
47
+ * Extract the path from a Postman URL object
48
+ * @param url - Postman URL object or string
49
+ * @returns Path portion of the URL
50
+ */
51
+ export function getUrlPath(url) {
52
+ if (typeof url === 'string') {
53
+ return url;
54
+ }
55
+ if (url?.path) {
56
+ if (Array.isArray(url.path)) {
57
+ return '/' + url.path.join('/');
58
+ }
59
+ if (typeof url.path === 'string') {
60
+ return url.path;
61
+ }
62
+ }
63
+ if (url?.raw) {
64
+ return url.raw;
65
+ }
66
+ return '';
67
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@postman-enricher/shared",
3
+ "version": "1.0.0",
4
+ "description": "Shared types and utilities for Postman Enricher",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "devDependencies": {
18
+ "@anolilab/semantic-release-pnpm": "^3.0.0",
19
+ "@semantic-release/changelog": "^6.0.3",
20
+ "@semantic-release/commit-analyzer": "^13.0.1",
21
+ "@semantic-release/git": "^10.0.1",
22
+ "@semantic-release/github": "^12.0.2",
23
+ "@semantic-release/release-notes-generator": "^14.1.0",
24
+ "semantic-release": "^25.0.2",
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "engines": {
28
+ "node": ">=20.0.0"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/caiopizzol/openapi-to-postman-complete.git",
33
+ "directory": "packages/shared"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/caiopizzol/openapi-to-postman-complete/issues"
37
+ },
38
+ "homepage": "https://github.com/caiopizzol/openapi-to-postman-complete#readme",
39
+ "author": "Caio Pizzol",
40
+ "license": "MIT",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "scripts": {
45
+ "build": "tsc",
46
+ "typecheck": "tsc --noEmit"
47
+ }
48
+ }