@theholocron/postman-client 1.7.0 → 1.7.1
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.mjs +50 -50
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,54 +1,4 @@
|
|
|
1
1
|
import { createRestClient } from "@theholocron/http-client";
|
|
2
|
-
//#region src/errors.ts
|
|
3
|
-
/**
|
|
4
|
-
* Thrown when Postman returns a `limitReachedError` (e.g., a Free-tier
|
|
5
|
-
* account hitting the "0 APIs" cap).
|
|
6
|
-
*/
|
|
7
|
-
var PostmanPlanLimitError = class extends Error {
|
|
8
|
-
limitMessage;
|
|
9
|
-
body;
|
|
10
|
-
name = "PostmanPlanLimitError";
|
|
11
|
-
constructor(limitMessage, body) {
|
|
12
|
-
super(limitMessage);
|
|
13
|
-
this.limitMessage = limitMessage;
|
|
14
|
-
this.body = body;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
function detectPlanLimit(body) {
|
|
18
|
-
try {
|
|
19
|
-
const parsed = JSON.parse(body);
|
|
20
|
-
if (parsed.error?.name === "limitReachedError" && parsed.error.message) return parsed.error.message;
|
|
21
|
-
} catch {}
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/utils.ts
|
|
26
|
-
function createPostmanRestClient(opts) {
|
|
27
|
-
const base = createRestClient({
|
|
28
|
-
baseUrl: opts.baseUrl ?? "https://api.getpostman.com",
|
|
29
|
-
token: opts.token,
|
|
30
|
-
tokenScheme: "apikey",
|
|
31
|
-
apiKeyHeader: "x-api-key",
|
|
32
|
-
vendor: "Postman",
|
|
33
|
-
fetch: opts.fetch
|
|
34
|
-
});
|
|
35
|
-
return {
|
|
36
|
-
baseUrl: base.baseUrl,
|
|
37
|
-
async request(path, reqOpts) {
|
|
38
|
-
try {
|
|
39
|
-
return await base.request(path, reqOpts);
|
|
40
|
-
} catch (err) {
|
|
41
|
-
const details = err.details;
|
|
42
|
-
if (typeof details === "string") {
|
|
43
|
-
const limit = detectPlanLimit(details);
|
|
44
|
-
if (limit) throw new PostmanPlanLimitError(limit, details);
|
|
45
|
-
}
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
//#endregion
|
|
52
2
|
//#region src/collections/collections.ts
|
|
53
3
|
function collections(rest) {
|
|
54
4
|
return {
|
|
@@ -113,6 +63,56 @@ function specs(rest) {
|
|
|
113
63
|
};
|
|
114
64
|
}
|
|
115
65
|
//#endregion
|
|
66
|
+
//#region src/errors.ts
|
|
67
|
+
/**
|
|
68
|
+
* Thrown when Postman returns a `limitReachedError` (e.g., a Free-tier
|
|
69
|
+
* account hitting the "0 APIs" cap).
|
|
70
|
+
*/
|
|
71
|
+
var PostmanPlanLimitError = class extends Error {
|
|
72
|
+
limitMessage;
|
|
73
|
+
body;
|
|
74
|
+
name = "PostmanPlanLimitError";
|
|
75
|
+
constructor(limitMessage, body) {
|
|
76
|
+
super(limitMessage);
|
|
77
|
+
this.limitMessage = limitMessage;
|
|
78
|
+
this.body = body;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
function detectPlanLimit(body) {
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(body);
|
|
84
|
+
if (parsed.error?.name === "limitReachedError" && parsed.error.message) return parsed.error.message;
|
|
85
|
+
} catch {}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/utils.ts
|
|
90
|
+
function createPostmanRestClient(opts) {
|
|
91
|
+
const base = createRestClient({
|
|
92
|
+
baseUrl: opts.baseUrl ?? "https://api.getpostman.com",
|
|
93
|
+
token: opts.token,
|
|
94
|
+
tokenScheme: "apikey",
|
|
95
|
+
apiKeyHeader: "x-api-key",
|
|
96
|
+
vendor: "Postman",
|
|
97
|
+
fetch: opts.fetch
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
baseUrl: base.baseUrl,
|
|
101
|
+
async request(path, reqOpts) {
|
|
102
|
+
try {
|
|
103
|
+
return await base.request(path, reqOpts);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
const details = err.details;
|
|
106
|
+
if (typeof details === "string") {
|
|
107
|
+
const limit = detectPlanLimit(details);
|
|
108
|
+
if (limit) throw new PostmanPlanLimitError(limit, details);
|
|
109
|
+
}
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
116
|
//#region src/workspaces/workspaces.ts
|
|
117
117
|
function workspaces(rest) {
|
|
118
118
|
return { list: () => rest.request("/workspaces") };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/postman-client",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "A TypeScript client for the Postman API",
|
|
5
5
|
"homepage": "https://github.com/theholocron/clients/tree/main/packages/postman-client#readme",
|
|
6
6
|
"bugs": "https://github.com/theholocron/clients/issues",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@theholocron/http-client": "^1.7.
|
|
32
|
+
"@theholocron/http-client": "^1.7.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^26.2.0",
|